]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.12.6-201401021726.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.12.6-201401021726.patch
CommitLineData
53f9dcd7
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 2b23383..a66cff0 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 define filechk_kernel.release
403@@ -838,6 +900,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -945,6 +1008,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -960,7 +1025,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1026,7 +1091,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1066,6 +1131,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1227,6 +1293,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1366,17 +1434,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1386,11 +1458,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index 78b03ef..da28a51 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index d8f9b7e..f6222fa 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index 1402fcc..0b1abd2 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 98838a0..b304fb4 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 1ad6fb6..9406b3d 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1832,7 +1832,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844@@ -2097,6 +2097,7 @@ config XIP_PHYS_ADDR
845 config KEXEC
846 bool "Kexec system call (EXPERIMENTAL)"
847 depends on (!SMP || PM_SLEEP_SMP)
848+ depends on !GRKERNSEC_KMEM
849 help
850 kexec is a system call that implements the ability to shutdown your
851 current kernel, and to start another kernel. It is like a reboot
852diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
853index da1c77d..2ee6056 100644
854--- a/arch/arm/include/asm/atomic.h
855+++ b/arch/arm/include/asm/atomic.h
856@@ -17,17 +17,35 @@
857 #include <asm/barrier.h>
858 #include <asm/cmpxchg.h>
859
860+#ifdef CONFIG_GENERIC_ATOMIC64
861+#include <asm-generic/atomic64.h>
862+#endif
863+
864 #define ATOMIC_INIT(i) { (i) }
865
866 #ifdef __KERNEL__
867
868+#define _ASM_EXTABLE(from, to) \
869+" .pushsection __ex_table,\"a\"\n"\
870+" .align 3\n" \
871+" .long " #from ", " #to"\n" \
872+" .popsection"
873+
874 /*
875 * On ARM, ordinary assignment (str instruction) doesn't clear the local
876 * strex/ldrex monitor on some implementations. The reason we can use it for
877 * atomic_set() is the clrex or dummy strex done on every exception return.
878 */
879 #define atomic_read(v) (*(volatile int *)&(v)->counter)
880+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
881+{
882+ return v->counter;
883+}
884 #define atomic_set(v,i) (((v)->counter) = (i))
885+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
886+{
887+ v->counter = i;
888+}
889
890 #if __LINUX_ARM_ARCH__ >= 6
891
892@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
893 int result;
894
895 __asm__ __volatile__("@ atomic_add\n"
896+"1: ldrex %1, [%3]\n"
897+" adds %0, %1, %4\n"
898+
899+#ifdef CONFIG_PAX_REFCOUNT
900+" bvc 3f\n"
901+"2: bkpt 0xf103\n"
902+"3:\n"
903+#endif
904+
905+" strex %1, %0, [%3]\n"
906+" teq %1, #0\n"
907+" bne 1b"
908+
909+#ifdef CONFIG_PAX_REFCOUNT
910+"\n4:\n"
911+ _ASM_EXTABLE(2b, 4b)
912+#endif
913+
914+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
915+ : "r" (&v->counter), "Ir" (i)
916+ : "cc");
917+}
918+
919+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
920+{
921+ unsigned long tmp;
922+ int result;
923+
924+ __asm__ __volatile__("@ atomic_add_unchecked\n"
925 "1: ldrex %0, [%3]\n"
926 " add %0, %0, %4\n"
927 " strex %1, %0, [%3]\n"
928@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
929 smp_mb();
930
931 __asm__ __volatile__("@ atomic_add_return\n"
932+"1: ldrex %1, [%3]\n"
933+" adds %0, %1, %4\n"
934+
935+#ifdef CONFIG_PAX_REFCOUNT
936+" bvc 3f\n"
937+" mov %0, %1\n"
938+"2: bkpt 0xf103\n"
939+"3:\n"
940+#endif
941+
942+" strex %1, %0, [%3]\n"
943+" teq %1, #0\n"
944+" bne 1b"
945+
946+#ifdef CONFIG_PAX_REFCOUNT
947+"\n4:\n"
948+ _ASM_EXTABLE(2b, 4b)
949+#endif
950+
951+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
952+ : "r" (&v->counter), "Ir" (i)
953+ : "cc");
954+
955+ smp_mb();
956+
957+ return result;
958+}
959+
960+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
961+{
962+ unsigned long tmp;
963+ int result;
964+
965+ smp_mb();
966+
967+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
968 "1: ldrex %0, [%3]\n"
969 " add %0, %0, %4\n"
970 " strex %1, %0, [%3]\n"
971@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
972 int result;
973
974 __asm__ __volatile__("@ atomic_sub\n"
975+"1: ldrex %1, [%3]\n"
976+" subs %0, %1, %4\n"
977+
978+#ifdef CONFIG_PAX_REFCOUNT
979+" bvc 3f\n"
980+"2: bkpt 0xf103\n"
981+"3:\n"
982+#endif
983+
984+" strex %1, %0, [%3]\n"
985+" teq %1, #0\n"
986+" bne 1b"
987+
988+#ifdef CONFIG_PAX_REFCOUNT
989+"\n4:\n"
990+ _ASM_EXTABLE(2b, 4b)
991+#endif
992+
993+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994+ : "r" (&v->counter), "Ir" (i)
995+ : "cc");
996+}
997+
998+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
999+{
1000+ unsigned long tmp;
1001+ int result;
1002+
1003+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1004 "1: ldrex %0, [%3]\n"
1005 " sub %0, %0, %4\n"
1006 " strex %1, %0, [%3]\n"
1007@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1008 smp_mb();
1009
1010 __asm__ __volatile__("@ atomic_sub_return\n"
1011-"1: ldrex %0, [%3]\n"
1012-" sub %0, %0, %4\n"
1013+"1: ldrex %1, [%3]\n"
1014+" subs %0, %1, %4\n"
1015+
1016+#ifdef CONFIG_PAX_REFCOUNT
1017+" bvc 3f\n"
1018+" mov %0, %1\n"
1019+"2: bkpt 0xf103\n"
1020+"3:\n"
1021+#endif
1022+
1023 " strex %1, %0, [%3]\n"
1024 " teq %1, #0\n"
1025 " bne 1b"
1026+
1027+#ifdef CONFIG_PAX_REFCOUNT
1028+"\n4:\n"
1029+ _ASM_EXTABLE(2b, 4b)
1030+#endif
1031+
1032 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1033 : "r" (&v->counter), "Ir" (i)
1034 : "cc");
1035@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1036 return oldval;
1037 }
1038
1039+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1040+{
1041+ unsigned long oldval, res;
1042+
1043+ smp_mb();
1044+
1045+ do {
1046+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1047+ "ldrex %1, [%3]\n"
1048+ "mov %0, #0\n"
1049+ "teq %1, %4\n"
1050+ "strexeq %0, %5, [%3]\n"
1051+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1052+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1053+ : "cc");
1054+ } while (res);
1055+
1056+ smp_mb();
1057+
1058+ return oldval;
1059+}
1060+
1061 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1062 {
1063 unsigned long tmp, tmp2;
1064@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065
1066 return val;
1067 }
1068+
1069+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1070+{
1071+ return atomic_add_return(i, v);
1072+}
1073+
1074 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1075+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1076+{
1077+ (void) atomic_add_return(i, v);
1078+}
1079
1080 static inline int atomic_sub_return(int i, atomic_t *v)
1081 {
1082@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1083 return val;
1084 }
1085 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1086+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1087+{
1088+ (void) atomic_sub_return(i, v);
1089+}
1090
1091 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1092 {
1093@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1094 return ret;
1095 }
1096
1097+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1098+{
1099+ return atomic_cmpxchg(v, old, new);
1100+}
1101+
1102 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1103 {
1104 unsigned long flags;
1105@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1106 #endif /* __LINUX_ARM_ARCH__ */
1107
1108 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1109+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1110+{
1111+ return xchg(&v->counter, new);
1112+}
1113
1114 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1115 {
1116@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1117 }
1118
1119 #define atomic_inc(v) atomic_add(1, v)
1120+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1121+{
1122+ atomic_add_unchecked(1, v);
1123+}
1124 #define atomic_dec(v) atomic_sub(1, v)
1125+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1126+{
1127+ atomic_sub_unchecked(1, v);
1128+}
1129
1130 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1131+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1132+{
1133+ return atomic_add_return_unchecked(1, v) == 0;
1134+}
1135 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1136 #define atomic_inc_return(v) (atomic_add_return(1, v))
1137+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1138+{
1139+ return atomic_add_return_unchecked(1, v);
1140+}
1141 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1142 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1143
1144@@ -241,6 +428,14 @@ typedef struct {
1145 u64 __aligned(8) counter;
1146 } atomic64_t;
1147
1148+#ifdef CONFIG_PAX_REFCOUNT
1149+typedef struct {
1150+ u64 __aligned(8) counter;
1151+} atomic64_unchecked_t;
1152+#else
1153+typedef atomic64_t atomic64_unchecked_t;
1154+#endif
1155+
1156 #define ATOMIC64_INIT(i) { (i) }
1157
1158 #ifdef CONFIG_ARM_LPAE
1159@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1160 return result;
1161 }
1162
1163+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1164+{
1165+ u64 result;
1166+
1167+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1168+" ldrd %0, %H0, [%1]"
1169+ : "=&r" (result)
1170+ : "r" (&v->counter), "Qo" (v->counter)
1171+ );
1172+
1173+ return result;
1174+}
1175+
1176 static inline void atomic64_set(atomic64_t *v, u64 i)
1177 {
1178 __asm__ __volatile__("@ atomic64_set\n"
1179@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1180 : "r" (&v->counter), "r" (i)
1181 );
1182 }
1183+
1184+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1185+{
1186+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1187+" strd %2, %H2, [%1]"
1188+ : "=Qo" (v->counter)
1189+ : "r" (&v->counter), "r" (i)
1190+ );
1191+}
1192 #else
1193 static inline u64 atomic64_read(const atomic64_t *v)
1194 {
1195@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1196 return result;
1197 }
1198
1199+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1200+{
1201+ u64 result;
1202+
1203+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1204+" ldrexd %0, %H0, [%1]"
1205+ : "=&r" (result)
1206+ : "r" (&v->counter), "Qo" (v->counter)
1207+ );
1208+
1209+ return result;
1210+}
1211+
1212 static inline void atomic64_set(atomic64_t *v, u64 i)
1213 {
1214 u64 tmp;
1215@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1216 : "r" (&v->counter), "r" (i)
1217 : "cc");
1218 }
1219+
1220+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1221+{
1222+ u64 tmp;
1223+
1224+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1225+"1: ldrexd %0, %H0, [%2]\n"
1226+" strexd %0, %3, %H3, [%2]\n"
1227+" teq %0, #0\n"
1228+" bne 1b"
1229+ : "=&r" (tmp), "=Qo" (v->counter)
1230+ : "r" (&v->counter), "r" (i)
1231+ : "cc");
1232+}
1233+
1234 #endif
1235
1236 static inline void atomic64_add(u64 i, atomic64_t *v)
1237@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_add\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " adds %0, %0, %4\n"
1241+" adcs %H0, %H0, %H4\n"
1242+
1243+#ifdef CONFIG_PAX_REFCOUNT
1244+" bvc 3f\n"
1245+"2: bkpt 0xf103\n"
1246+"3:\n"
1247+#endif
1248+
1249+" strexd %1, %0, %H0, [%3]\n"
1250+" teq %1, #0\n"
1251+" bne 1b"
1252+
1253+#ifdef CONFIG_PAX_REFCOUNT
1254+"\n4:\n"
1255+ _ASM_EXTABLE(2b, 4b)
1256+#endif
1257+
1258+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259+ : "r" (&v->counter), "r" (i)
1260+ : "cc");
1261+}
1262+
1263+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1264+{
1265+ u64 result;
1266+ unsigned long tmp;
1267+
1268+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1269+"1: ldrexd %0, %H0, [%3]\n"
1270+" adds %0, %0, %4\n"
1271 " adc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1277 {
1278- u64 result;
1279- unsigned long tmp;
1280+ u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_add_return\n"
1285+"1: ldrexd %1, %H1, [%3]\n"
1286+" adds %0, %1, %4\n"
1287+" adcs %H0, %H1, %H4\n"
1288+
1289+#ifdef CONFIG_PAX_REFCOUNT
1290+" bvc 3f\n"
1291+" mov %0, %1\n"
1292+" mov %H0, %H1\n"
1293+"2: bkpt 0xf103\n"
1294+"3:\n"
1295+#endif
1296+
1297+" strexd %1, %0, %H0, [%3]\n"
1298+" teq %1, #0\n"
1299+" bne 1b"
1300+
1301+#ifdef CONFIG_PAX_REFCOUNT
1302+"\n4:\n"
1303+ _ASM_EXTABLE(2b, 4b)
1304+#endif
1305+
1306+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1307+ : "r" (&v->counter), "r" (i)
1308+ : "cc");
1309+
1310+ smp_mb();
1311+
1312+ return result;
1313+}
1314+
1315+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1316+{
1317+ u64 result;
1318+ unsigned long tmp;
1319+
1320+ smp_mb();
1321+
1322+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1323 "1: ldrexd %0, %H0, [%3]\n"
1324 " adds %0, %0, %4\n"
1325 " adc %H0, %H0, %H4\n"
1326@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1327 __asm__ __volatile__("@ atomic64_sub\n"
1328 "1: ldrexd %0, %H0, [%3]\n"
1329 " subs %0, %0, %4\n"
1330+" sbcs %H0, %H0, %H4\n"
1331+
1332+#ifdef CONFIG_PAX_REFCOUNT
1333+" bvc 3f\n"
1334+"2: bkpt 0xf103\n"
1335+"3:\n"
1336+#endif
1337+
1338+" strexd %1, %0, %H0, [%3]\n"
1339+" teq %1, #0\n"
1340+" bne 1b"
1341+
1342+#ifdef CONFIG_PAX_REFCOUNT
1343+"\n4:\n"
1344+ _ASM_EXTABLE(2b, 4b)
1345+#endif
1346+
1347+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1348+ : "r" (&v->counter), "r" (i)
1349+ : "cc");
1350+}
1351+
1352+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1353+{
1354+ u64 result;
1355+ unsigned long tmp;
1356+
1357+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1358+"1: ldrexd %0, %H0, [%3]\n"
1359+" subs %0, %0, %4\n"
1360 " sbc %H0, %H0, %H4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1364
1365 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1366 {
1367- u64 result;
1368- unsigned long tmp;
1369+ u64 result, tmp;
1370
1371 smp_mb();
1372
1373 __asm__ __volatile__("@ atomic64_sub_return\n"
1374-"1: ldrexd %0, %H0, [%3]\n"
1375-" subs %0, %0, %4\n"
1376-" sbc %H0, %H0, %H4\n"
1377+"1: ldrexd %1, %H1, [%3]\n"
1378+" subs %0, %1, %4\n"
1379+" sbcs %H0, %H1, %H4\n"
1380+
1381+#ifdef CONFIG_PAX_REFCOUNT
1382+" bvc 3f\n"
1383+" mov %0, %1\n"
1384+" mov %H0, %H1\n"
1385+"2: bkpt 0xf103\n"
1386+"3:\n"
1387+#endif
1388+
1389 " strexd %1, %0, %H0, [%3]\n"
1390 " teq %1, #0\n"
1391 " bne 1b"
1392+
1393+#ifdef CONFIG_PAX_REFCOUNT
1394+"\n4:\n"
1395+ _ASM_EXTABLE(2b, 4b)
1396+#endif
1397+
1398 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1399 : "r" (&v->counter), "r" (i)
1400 : "cc");
1401@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1402 return oldval;
1403 }
1404
1405+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1406+{
1407+ u64 oldval;
1408+ unsigned long res;
1409+
1410+ smp_mb();
1411+
1412+ do {
1413+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1414+ "ldrexd %1, %H1, [%3]\n"
1415+ "mov %0, #0\n"
1416+ "teq %1, %4\n"
1417+ "teqeq %H1, %H4\n"
1418+ "strexdeq %0, %5, %H5, [%3]"
1419+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1420+ : "r" (&ptr->counter), "r" (old), "r" (new)
1421+ : "cc");
1422+ } while (res);
1423+
1424+ smp_mb();
1425+
1426+ return oldval;
1427+}
1428+
1429 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1430 {
1431 u64 result;
1432@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1433
1434 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1435 {
1436- u64 result;
1437- unsigned long tmp;
1438+ u64 result, tmp;
1439
1440 smp_mb();
1441
1442 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1443-"1: ldrexd %0, %H0, [%3]\n"
1444-" subs %0, %0, #1\n"
1445-" sbc %H0, %H0, #0\n"
1446+"1: ldrexd %1, %H1, [%3]\n"
1447+" subs %0, %1, #1\n"
1448+" sbcs %H0, %H1, #0\n"
1449+
1450+#ifdef CONFIG_PAX_REFCOUNT
1451+" bvc 3f\n"
1452+" mov %0, %1\n"
1453+" mov %H0, %H1\n"
1454+"2: bkpt 0xf103\n"
1455+"3:\n"
1456+#endif
1457+
1458 " teq %H0, #0\n"
1459-" bmi 2f\n"
1460+" bmi 4f\n"
1461 " strexd %1, %0, %H0, [%3]\n"
1462 " teq %1, #0\n"
1463 " bne 1b\n"
1464-"2:"
1465+"4:\n"
1466+
1467+#ifdef CONFIG_PAX_REFCOUNT
1468+ _ASM_EXTABLE(2b, 4b)
1469+#endif
1470+
1471 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1472 : "r" (&v->counter)
1473 : "cc");
1474@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1475 " teq %0, %5\n"
1476 " teqeq %H0, %H5\n"
1477 " moveq %1, #0\n"
1478-" beq 2f\n"
1479+" beq 4f\n"
1480 " adds %0, %0, %6\n"
1481-" adc %H0, %H0, %H6\n"
1482+" adcs %H0, %H0, %H6\n"
1483+
1484+#ifdef CONFIG_PAX_REFCOUNT
1485+" bvc 3f\n"
1486+"2: bkpt 0xf103\n"
1487+"3:\n"
1488+#endif
1489+
1490 " strexd %2, %0, %H0, [%4]\n"
1491 " teq %2, #0\n"
1492 " bne 1b\n"
1493-"2:"
1494+"4:\n"
1495+
1496+#ifdef CONFIG_PAX_REFCOUNT
1497+ _ASM_EXTABLE(2b, 4b)
1498+#endif
1499+
1500 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1501 : "r" (&v->counter), "r" (u), "r" (a)
1502 : "cc");
1503@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1504
1505 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1506 #define atomic64_inc(v) atomic64_add(1LL, (v))
1507+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1508 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1509+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1510 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1511 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1512 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1513+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1514 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1515 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1516 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1517diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1518index 75fe66b..ba3dee4 100644
1519--- a/arch/arm/include/asm/cache.h
1520+++ b/arch/arm/include/asm/cache.h
1521@@ -4,8 +4,10 @@
1522 #ifndef __ASMARM_CACHE_H
1523 #define __ASMARM_CACHE_H
1524
1525+#include <linux/const.h>
1526+
1527 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1528-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1529+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1530
1531 /*
1532 * Memory returned by kmalloc() may be used for DMA, so we must make
1533@@ -24,5 +26,6 @@
1534 #endif
1535
1536 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1537+#define __read_only __attribute__ ((__section__(".data..read_only")))
1538
1539 #endif
1540diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1541index 15f2d5b..43ffa53 100644
1542--- a/arch/arm/include/asm/cacheflush.h
1543+++ b/arch/arm/include/asm/cacheflush.h
1544@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1545 void (*dma_unmap_area)(const void *, size_t, int);
1546
1547 void (*dma_flush_range)(const void *, const void *);
1548-};
1549+} __no_const;
1550
1551 /*
1552 * Select the calling method
1553diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1554index 6dcc164..b14d917 100644
1555--- a/arch/arm/include/asm/checksum.h
1556+++ b/arch/arm/include/asm/checksum.h
1557@@ -37,7 +37,19 @@ __wsum
1558 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1559
1560 __wsum
1561-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1562+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1563+
1564+static inline __wsum
1565+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1566+{
1567+ __wsum ret;
1568+ pax_open_userland();
1569+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1570+ pax_close_userland();
1571+ return ret;
1572+}
1573+
1574+
1575
1576 /*
1577 * Fold a partial checksum without adding pseudo headers
1578diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1579index 4f009c1..466c59b 100644
1580--- a/arch/arm/include/asm/cmpxchg.h
1581+++ b/arch/arm/include/asm/cmpxchg.h
1582@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1583
1584 #define xchg(ptr,x) \
1585 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1586+#define xchg_unchecked(ptr,x) \
1587+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1588
1589 #include <asm-generic/cmpxchg-local.h>
1590
1591diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1592index 6ddbe44..b5e38b1 100644
1593--- a/arch/arm/include/asm/domain.h
1594+++ b/arch/arm/include/asm/domain.h
1595@@ -48,18 +48,37 @@
1596 * Domain types
1597 */
1598 #define DOMAIN_NOACCESS 0
1599-#define DOMAIN_CLIENT 1
1600 #ifdef CONFIG_CPU_USE_DOMAINS
1601+#define DOMAIN_USERCLIENT 1
1602+#define DOMAIN_KERNELCLIENT 1
1603 #define DOMAIN_MANAGER 3
1604+#define DOMAIN_VECTORS DOMAIN_USER
1605 #else
1606+
1607+#ifdef CONFIG_PAX_KERNEXEC
1608 #define DOMAIN_MANAGER 1
1609+#define DOMAIN_KERNEXEC 3
1610+#else
1611+#define DOMAIN_MANAGER 1
1612+#endif
1613+
1614+#ifdef CONFIG_PAX_MEMORY_UDEREF
1615+#define DOMAIN_USERCLIENT 0
1616+#define DOMAIN_UDEREF 1
1617+#define DOMAIN_VECTORS DOMAIN_KERNEL
1618+#else
1619+#define DOMAIN_USERCLIENT 1
1620+#define DOMAIN_VECTORS DOMAIN_USER
1621+#endif
1622+#define DOMAIN_KERNELCLIENT 1
1623+
1624 #endif
1625
1626 #define domain_val(dom,type) ((type) << (2*(dom)))
1627
1628 #ifndef __ASSEMBLY__
1629
1630-#ifdef CONFIG_CPU_USE_DOMAINS
1631+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1632 static inline void set_domain(unsigned val)
1633 {
1634 asm volatile(
1635@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1636 isb();
1637 }
1638
1639-#define modify_domain(dom,type) \
1640- do { \
1641- struct thread_info *thread = current_thread_info(); \
1642- unsigned int domain = thread->cpu_domain; \
1643- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1644- thread->cpu_domain = domain | domain_val(dom, type); \
1645- set_domain(thread->cpu_domain); \
1646- } while (0)
1647-
1648+extern void modify_domain(unsigned int dom, unsigned int type);
1649 #else
1650 static inline void set_domain(unsigned val) { }
1651 static inline void modify_domain(unsigned dom, unsigned type) { }
1652diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1653index f4b46d3..abc9b2b 100644
1654--- a/arch/arm/include/asm/elf.h
1655+++ b/arch/arm/include/asm/elf.h
1656@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1657 the loader. We need to make sure that it is out of the way of the program
1658 that it will "exec", and that there is sufficient room for the brk. */
1659
1660-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1661+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1662+
1663+#ifdef CONFIG_PAX_ASLR
1664+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1665+
1666+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1667+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1668+#endif
1669
1670 /* When the program starts, a1 contains a pointer to a function to be
1671 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1672@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1673 extern void elf_set_personality(const struct elf32_hdr *);
1674 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1675
1676-struct mm_struct;
1677-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1678-#define arch_randomize_brk arch_randomize_brk
1679-
1680 #ifdef CONFIG_MMU
1681 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1682 struct linux_binprm;
1683diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1684index de53547..52b9a28 100644
1685--- a/arch/arm/include/asm/fncpy.h
1686+++ b/arch/arm/include/asm/fncpy.h
1687@@ -81,7 +81,9 @@
1688 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1689 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1690 \
1691+ pax_open_kernel(); \
1692 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1693+ pax_close_kernel(); \
1694 flush_icache_range((unsigned long)(dest_buf), \
1695 (unsigned long)(dest_buf) + (size)); \
1696 \
1697diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1698index e42cf59..7b94b8f 100644
1699--- a/arch/arm/include/asm/futex.h
1700+++ b/arch/arm/include/asm/futex.h
1701@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1702 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1703 return -EFAULT;
1704
1705+ pax_open_userland();
1706+
1707 smp_mb();
1708 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1709 "1: ldrex %1, [%4]\n"
1710@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1711 : "cc", "memory");
1712 smp_mb();
1713
1714+ pax_close_userland();
1715+
1716 *uval = val;
1717 return ret;
1718 }
1719@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1720 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1721 return -EFAULT;
1722
1723+ pax_open_userland();
1724+
1725 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1726 "1: " TUSER(ldr) " %1, [%4]\n"
1727 " teq %1, %2\n"
1728@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1729 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1730 : "cc", "memory");
1731
1732+ pax_close_userland();
1733+
1734 *uval = val;
1735 return ret;
1736 }
1737@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 return -EFAULT;
1739
1740 pagefault_disable(); /* implies preempt_disable() */
1741+ pax_open_userland();
1742
1743 switch (op) {
1744 case FUTEX_OP_SET:
1745@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 ret = -ENOSYS;
1747 }
1748
1749+ pax_close_userland();
1750 pagefault_enable(); /* subsumes preempt_enable() */
1751
1752 if (!ret) {
1753diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1754index 83eb2f7..ed77159 100644
1755--- a/arch/arm/include/asm/kmap_types.h
1756+++ b/arch/arm/include/asm/kmap_types.h
1757@@ -4,6 +4,6 @@
1758 /*
1759 * This is the "bare minimum". AIO seems to require this.
1760 */
1761-#define KM_TYPE_NR 16
1762+#define KM_TYPE_NR 17
1763
1764 #endif
1765diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1766index 9e614a1..3302cca 100644
1767--- a/arch/arm/include/asm/mach/dma.h
1768+++ b/arch/arm/include/asm/mach/dma.h
1769@@ -22,7 +22,7 @@ struct dma_ops {
1770 int (*residue)(unsigned int, dma_t *); /* optional */
1771 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1772 const char *type;
1773-};
1774+} __do_const;
1775
1776 struct dma_struct {
1777 void *addr; /* single DMA address */
1778diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1779index 2fe141f..192dc01 100644
1780--- a/arch/arm/include/asm/mach/map.h
1781+++ b/arch/arm/include/asm/mach/map.h
1782@@ -27,13 +27,16 @@ struct map_desc {
1783 #define MT_MINICLEAN 6
1784 #define MT_LOW_VECTORS 7
1785 #define MT_HIGH_VECTORS 8
1786-#define MT_MEMORY 9
1787+#define MT_MEMORY_RWX 9
1788 #define MT_ROM 10
1789-#define MT_MEMORY_NONCACHED 11
1790+#define MT_MEMORY_NONCACHED_RX 11
1791 #define MT_MEMORY_DTCM 12
1792 #define MT_MEMORY_ITCM 13
1793 #define MT_MEMORY_SO 14
1794 #define MT_MEMORY_DMA_READY 15
1795+#define MT_MEMORY_RW 16
1796+#define MT_MEMORY_RX 17
1797+#define MT_MEMORY_NONCACHED_RW 18
1798
1799 #ifdef CONFIG_MMU
1800 extern void iotable_init(struct map_desc *, int);
1801diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1802index f94784f..9a09a4a 100644
1803--- a/arch/arm/include/asm/outercache.h
1804+++ b/arch/arm/include/asm/outercache.h
1805@@ -35,7 +35,7 @@ struct outer_cache_fns {
1806 #endif
1807 void (*set_debug)(unsigned long);
1808 void (*resume)(void);
1809-};
1810+} __no_const;
1811
1812 extern struct outer_cache_fns outer_cache;
1813
1814diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1815index 4355f0e..c229913 100644
1816--- a/arch/arm/include/asm/page.h
1817+++ b/arch/arm/include/asm/page.h
1818@@ -114,7 +114,7 @@ struct cpu_user_fns {
1819 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1820 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1821 unsigned long vaddr, struct vm_area_struct *vma);
1822-};
1823+} __no_const;
1824
1825 #ifdef MULTI_USER
1826 extern struct cpu_user_fns cpu_user;
1827diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1828index 943504f..c37a730 100644
1829--- a/arch/arm/include/asm/pgalloc.h
1830+++ b/arch/arm/include/asm/pgalloc.h
1831@@ -17,6 +17,7 @@
1832 #include <asm/processor.h>
1833 #include <asm/cacheflush.h>
1834 #include <asm/tlbflush.h>
1835+#include <asm/system_info.h>
1836
1837 #define check_pgt_cache() do { } while (0)
1838
1839@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1840 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1841 }
1842
1843+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844+{
1845+ pud_populate(mm, pud, pmd);
1846+}
1847+
1848 #else /* !CONFIG_ARM_LPAE */
1849
1850 /*
1851@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1852 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1853 #define pmd_free(mm, pmd) do { } while (0)
1854 #define pud_populate(mm,pmd,pte) BUG()
1855+#define pud_populate_kernel(mm,pmd,pte) BUG()
1856
1857 #endif /* CONFIG_ARM_LPAE */
1858
1859@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1860 __free_page(pte);
1861 }
1862
1863+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1864+{
1865+#ifdef CONFIG_ARM_LPAE
1866+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1867+#else
1868+ if (addr & SECTION_SIZE)
1869+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1870+ else
1871+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1872+#endif
1873+ flush_pmd_entry(pmdp);
1874+}
1875+
1876 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1877 pmdval_t prot)
1878 {
1879@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1880 static inline void
1881 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1882 {
1883- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1884+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1885 }
1886 #define pmd_pgtable(pmd) pmd_page(pmd)
1887
1888diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1889index 5cfba15..f415e1a 100644
1890--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1891+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1892@@ -20,12 +20,15 @@
1893 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1894 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1895 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1896+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1897 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1898 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1899 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1900+
1901 /*
1902 * - section
1903 */
1904+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1905 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1906 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1907 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1908@@ -37,6 +40,7 @@
1909 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1910 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1911 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1912+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1913
1914 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1915 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1916@@ -66,6 +70,7 @@
1917 * - extended small page/tiny page
1918 */
1919 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1920+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1921 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1922 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1923 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1924diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1925index f97ee02..cc9fe9e 100644
1926--- a/arch/arm/include/asm/pgtable-2level.h
1927+++ b/arch/arm/include/asm/pgtable-2level.h
1928@@ -126,6 +126,9 @@
1929 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1930 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1931
1932+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1933+#define L_PTE_PXN (_AT(pteval_t, 0))
1934+
1935 /*
1936 * These are the memory types, defined to be compatible with
1937 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1938diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1939index 626989f..9d67a33 100644
1940--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1941+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1942@@ -75,6 +75,7 @@
1943 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1944 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1945 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1946+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1947 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1948
1949 /*
1950diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1951index 5689c18..eea12f9 100644
1952--- a/arch/arm/include/asm/pgtable-3level.h
1953+++ b/arch/arm/include/asm/pgtable-3level.h
1954@@ -82,6 +82,7 @@
1955 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1956 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1957 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1958+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1959 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1960 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1961 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1962@@ -95,6 +96,7 @@
1963 /*
1964 * To be used in assembly code with the upper page attributes.
1965 */
1966+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1967 #define L_PTE_XN_HIGH (1 << (54 - 32))
1968 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1969
1970diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1971index 1571d12..b8a9b43 100644
1972--- a/arch/arm/include/asm/pgtable.h
1973+++ b/arch/arm/include/asm/pgtable.h
1974@@ -33,6 +33,9 @@
1975 #include <asm/pgtable-2level.h>
1976 #endif
1977
1978+#define ktla_ktva(addr) (addr)
1979+#define ktva_ktla(addr) (addr)
1980+
1981 /*
1982 * Just any arbitrary offset to the start of the vmalloc VM area: the
1983 * current 8MB value just means that there will be a 8MB "hole" after the
1984@@ -48,6 +51,9 @@
1985 #define LIBRARY_TEXT_START 0x0c000000
1986
1987 #ifndef __ASSEMBLY__
1988+extern pteval_t __supported_pte_mask;
1989+extern pmdval_t __supported_pmd_mask;
1990+
1991 extern void __pte_error(const char *file, int line, pte_t);
1992 extern void __pmd_error(const char *file, int line, pmd_t);
1993 extern void __pgd_error(const char *file, int line, pgd_t);
1994@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1995 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1996 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1997
1998+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1999+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2000+
2001+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2002+#include <asm/domain.h>
2003+#include <linux/thread_info.h>
2004+#include <linux/preempt.h>
2005+
2006+static inline int test_domain(int domain, int domaintype)
2007+{
2008+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2009+}
2010+#endif
2011+
2012+#ifdef CONFIG_PAX_KERNEXEC
2013+static inline unsigned long pax_open_kernel(void) {
2014+#ifdef CONFIG_ARM_LPAE
2015+ /* TODO */
2016+#else
2017+ preempt_disable();
2018+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2019+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2020+#endif
2021+ return 0;
2022+}
2023+
2024+static inline unsigned long pax_close_kernel(void) {
2025+#ifdef CONFIG_ARM_LPAE
2026+ /* TODO */
2027+#else
2028+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2029+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2030+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2031+ preempt_enable_no_resched();
2032+#endif
2033+ return 0;
2034+}
2035+#else
2036+static inline unsigned long pax_open_kernel(void) { return 0; }
2037+static inline unsigned long pax_close_kernel(void) { return 0; }
2038+#endif
2039+
2040 /*
2041 * This is the lowest virtual address we can permit any user space
2042 * mapping to be mapped at. This is particularly important for
2043@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2044 /*
2045 * The pgprot_* and protection_map entries will be fixed up in runtime
2046 * to include the cachable and bufferable bits based on memory policy,
2047- * as well as any architecture dependent bits like global/ASID and SMP
2048- * shared mapping bits.
2049+ * as well as any architecture dependent bits like global/ASID, PXN,
2050+ * and SMP shared mapping bits.
2051 */
2052 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2053
2054@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2055 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2056 {
2057 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2058- L_PTE_NONE | L_PTE_VALID;
2059+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2060 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2061 return pte;
2062 }
2063diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2064index 5324c11..bcae5f0 100644
2065--- a/arch/arm/include/asm/proc-fns.h
2066+++ b/arch/arm/include/asm/proc-fns.h
2067@@ -75,7 +75,7 @@ extern struct processor {
2068 unsigned int suspend_size;
2069 void (*do_suspend)(void *);
2070 void (*do_resume)(void *);
2071-} processor;
2072+} __do_const processor;
2073
2074 #ifndef MULTI_CPU
2075 extern void cpu_proc_init(void);
2076diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2077index c4ae171..ea0c0c2 100644
2078--- a/arch/arm/include/asm/psci.h
2079+++ b/arch/arm/include/asm/psci.h
2080@@ -29,7 +29,7 @@ struct psci_operations {
2081 int (*cpu_off)(struct psci_power_state state);
2082 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2083 int (*migrate)(unsigned long cpuid);
2084-};
2085+} __no_const;
2086
2087 extern struct psci_operations psci_ops;
2088 extern struct smp_operations psci_smp_ops;
2089diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2090index a8cae71c..65dd797 100644
2091--- a/arch/arm/include/asm/smp.h
2092+++ b/arch/arm/include/asm/smp.h
2093@@ -110,7 +110,7 @@ struct smp_operations {
2094 int (*cpu_disable)(unsigned int cpu);
2095 #endif
2096 #endif
2097-};
2098+} __no_const;
2099
2100 /*
2101 * set platform specific SMP operations
2102diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2103index df5e13d..97efb82 100644
2104--- a/arch/arm/include/asm/thread_info.h
2105+++ b/arch/arm/include/asm/thread_info.h
2106@@ -88,9 +88,9 @@ struct thread_info {
2107 .flags = 0, \
2108 .preempt_count = INIT_PREEMPT_COUNT, \
2109 .addr_limit = KERNEL_DS, \
2110- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2111- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2112- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2113+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2114+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2115+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2116 .restart_block = { \
2117 .fn = do_no_restart_syscall, \
2118 }, \
2119@@ -163,7 +163,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2120 #define TIF_SYSCALL_AUDIT 9
2121 #define TIF_SYSCALL_TRACEPOINT 10
2122 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2123-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2124+/* within 8 bits of TIF_SYSCALL_TRACE
2125+ * to meet flexible second operand requirements
2126+ */
2127+#define TIF_GRSEC_SETXID 12
2128+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2129 #define TIF_USING_IWMMXT 17
2130 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2131 #define TIF_RESTORE_SIGMASK 20
2132@@ -176,10 +180,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2134 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2135 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2136+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2137
2138 /* Checks for any syscall work in entry-common.S */
2139 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2140- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2141+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2142
2143 /*
2144 * Change these and you break ASM code in entry-common.S
2145diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2146index 72abdc5..9eba222 100644
2147--- a/arch/arm/include/asm/uaccess.h
2148+++ b/arch/arm/include/asm/uaccess.h
2149@@ -18,6 +18,7 @@
2150 #include <asm/domain.h>
2151 #include <asm/unified.h>
2152 #include <asm/compiler.h>
2153+#include <asm/pgtable.h>
2154
2155 #if __LINUX_ARM_ARCH__ < 6
2156 #include <asm-generic/uaccess-unaligned.h>
2157@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2158 static inline void set_fs(mm_segment_t fs)
2159 {
2160 current_thread_info()->addr_limit = fs;
2161- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2162+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2163 }
2164
2165 #define segment_eq(a,b) ((a) == (b))
2166
2167+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2168+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2169+
2170+static inline void pax_open_userland(void)
2171+{
2172+
2173+#ifdef CONFIG_PAX_MEMORY_UDEREF
2174+ if (segment_eq(get_fs(), USER_DS)) {
2175+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2176+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2177+ }
2178+#endif
2179+
2180+}
2181+
2182+static inline void pax_close_userland(void)
2183+{
2184+
2185+#ifdef CONFIG_PAX_MEMORY_UDEREF
2186+ if (segment_eq(get_fs(), USER_DS)) {
2187+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2188+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2189+ }
2190+#endif
2191+
2192+}
2193+
2194 #define __addr_ok(addr) ({ \
2195 unsigned long flag; \
2196 __asm__("cmp %2, %0; movlo %0, #0" \
2197@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2198
2199 #define get_user(x,p) \
2200 ({ \
2201+ int __e; \
2202 might_fault(); \
2203- __get_user_check(x,p); \
2204+ pax_open_userland(); \
2205+ __e = __get_user_check(x,p); \
2206+ pax_close_userland(); \
2207+ __e; \
2208 })
2209
2210 extern int __put_user_1(void *, unsigned int);
2211@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2212
2213 #define put_user(x,p) \
2214 ({ \
2215+ int __e; \
2216 might_fault(); \
2217- __put_user_check(x,p); \
2218+ pax_open_userland(); \
2219+ __e = __put_user_check(x,p); \
2220+ pax_close_userland(); \
2221+ __e; \
2222 })
2223
2224 #else /* CONFIG_MMU */
2225@@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2226 #define __get_user(x,ptr) \
2227 ({ \
2228 long __gu_err = 0; \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),__gu_err); \
2231+ pax_close_userland(); \
2232 __gu_err; \
2233 })
2234
2235 #define __get_user_error(x,ptr,err) \
2236 ({ \
2237+ pax_open_userland(); \
2238 __get_user_err((x),(ptr),err); \
2239+ pax_close_userland(); \
2240 (void) 0; \
2241 })
2242
2243@@ -319,13 +359,17 @@ do { \
2244 #define __put_user(x,ptr) \
2245 ({ \
2246 long __pu_err = 0; \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),__pu_err); \
2249+ pax_close_userland(); \
2250 __pu_err; \
2251 })
2252
2253 #define __put_user_error(x,ptr,err) \
2254 ({ \
2255+ pax_open_userland(); \
2256 __put_user_err((x),(ptr),err); \
2257+ pax_close_userland(); \
2258 (void) 0; \
2259 })
2260
2261@@ -425,11 +469,44 @@ do { \
2262
2263
2264 #ifdef CONFIG_MMU
2265-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2266-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2267+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2268+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2269+
2270+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2271+{
2272+ unsigned long ret;
2273+
2274+ check_object_size(to, n, false);
2275+ pax_open_userland();
2276+ ret = ___copy_from_user(to, from, n);
2277+ pax_close_userland();
2278+ return ret;
2279+}
2280+
2281+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2282+{
2283+ unsigned long ret;
2284+
2285+ check_object_size(from, n, true);
2286+ pax_open_userland();
2287+ ret = ___copy_to_user(to, from, n);
2288+ pax_close_userland();
2289+ return ret;
2290+}
2291+
2292 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2293-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2294+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2295 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2296+
2297+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2298+{
2299+ unsigned long ret;
2300+ pax_open_userland();
2301+ ret = ___clear_user(addr, n);
2302+ pax_close_userland();
2303+ return ret;
2304+}
2305+
2306 #else
2307 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2308 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2309@@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2310
2311 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2312 {
2313+ if ((long)n < 0)
2314+ return n;
2315+
2316 if (access_ok(VERIFY_READ, from, n))
2317 n = __copy_from_user(to, from, n);
2318 else /* security hole - plug it */
2319@@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2320
2321 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2322 {
2323+ if ((long)n < 0)
2324+ return n;
2325+
2326 if (access_ok(VERIFY_WRITE, to, n))
2327 n = __copy_to_user(to, from, n);
2328 return n;
2329diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2330index 5af0ed1..cea83883 100644
2331--- a/arch/arm/include/uapi/asm/ptrace.h
2332+++ b/arch/arm/include/uapi/asm/ptrace.h
2333@@ -92,7 +92,7 @@
2334 * ARMv7 groups of PSR bits
2335 */
2336 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2337-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2338+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2339 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2340 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2341
2342diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2343index 60d3b73..e5a0f22 100644
2344--- a/arch/arm/kernel/armksyms.c
2345+++ b/arch/arm/kernel/armksyms.c
2346@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2347
2348 /* networking */
2349 EXPORT_SYMBOL(csum_partial);
2350-EXPORT_SYMBOL(csum_partial_copy_from_user);
2351+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2352 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2353 EXPORT_SYMBOL(__csum_ipv6_magic);
2354
2355@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2356 #ifdef CONFIG_MMU
2357 EXPORT_SYMBOL(copy_page);
2358
2359-EXPORT_SYMBOL(__copy_from_user);
2360-EXPORT_SYMBOL(__copy_to_user);
2361-EXPORT_SYMBOL(__clear_user);
2362+EXPORT_SYMBOL(___copy_from_user);
2363+EXPORT_SYMBOL(___copy_to_user);
2364+EXPORT_SYMBOL(___clear_user);
2365
2366 EXPORT_SYMBOL(__get_user_1);
2367 EXPORT_SYMBOL(__get_user_2);
2368diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2369index ec3e5cf..b450ee3 100644
2370--- a/arch/arm/kernel/entry-armv.S
2371+++ b/arch/arm/kernel/entry-armv.S
2372@@ -47,6 +47,87 @@
2373 9997:
2374 .endm
2375
2376+ .macro pax_enter_kernel
2377+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2378+ @ make aligned space for saved DACR
2379+ sub sp, sp, #8
2380+ @ save regs
2381+ stmdb sp!, {r1, r2}
2382+ @ read DACR from cpu_domain into r1
2383+ mov r2, sp
2384+ @ assume 8K pages, since we have to split the immediate in two
2385+ bic r2, r2, #(0x1fc0)
2386+ bic r2, r2, #(0x3f)
2387+ ldr r1, [r2, #TI_CPU_DOMAIN]
2388+ @ store old DACR on stack
2389+ str r1, [sp, #8]
2390+#ifdef CONFIG_PAX_KERNEXEC
2391+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2392+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2393+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2394+#endif
2395+#ifdef CONFIG_PAX_MEMORY_UDEREF
2396+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2397+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2398+#endif
2399+ @ write r1 to current_thread_info()->cpu_domain
2400+ str r1, [r2, #TI_CPU_DOMAIN]
2401+ @ write r1 to DACR
2402+ mcr p15, 0, r1, c3, c0, 0
2403+ @ instruction sync
2404+ instr_sync
2405+ @ restore regs
2406+ ldmia sp!, {r1, r2}
2407+#endif
2408+ .endm
2409+
2410+ .macro pax_open_userland
2411+#ifdef CONFIG_PAX_MEMORY_UDEREF
2412+ @ save regs
2413+ stmdb sp!, {r0, r1}
2414+ @ read DACR from cpu_domain into r1
2415+ mov r0, sp
2416+ @ assume 8K pages, since we have to split the immediate in two
2417+ bic r0, r0, #(0x1fc0)
2418+ bic r0, r0, #(0x3f)
2419+ ldr r1, [r0, #TI_CPU_DOMAIN]
2420+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2421+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2422+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2423+ @ write r1 to current_thread_info()->cpu_domain
2424+ str r1, [r0, #TI_CPU_DOMAIN]
2425+ @ write r1 to DACR
2426+ mcr p15, 0, r1, c3, c0, 0
2427+ @ instruction sync
2428+ instr_sync
2429+ @ restore regs
2430+ ldmia sp!, {r0, r1}
2431+#endif
2432+ .endm
2433+
2434+ .macro pax_close_userland
2435+#ifdef CONFIG_PAX_MEMORY_UDEREF
2436+ @ save regs
2437+ stmdb sp!, {r0, r1}
2438+ @ read DACR from cpu_domain into r1
2439+ mov r0, sp
2440+ @ assume 8K pages, since we have to split the immediate in two
2441+ bic r0, r0, #(0x1fc0)
2442+ bic r0, r0, #(0x3f)
2443+ ldr r1, [r0, #TI_CPU_DOMAIN]
2444+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2445+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2446+ @ write r1 to current_thread_info()->cpu_domain
2447+ str r1, [r0, #TI_CPU_DOMAIN]
2448+ @ write r1 to DACR
2449+ mcr p15, 0, r1, c3, c0, 0
2450+ @ instruction sync
2451+ instr_sync
2452+ @ restore regs
2453+ ldmia sp!, {r0, r1}
2454+#endif
2455+ .endm
2456+
2457 .macro pabt_helper
2458 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2459 #ifdef MULTI_PABORT
2460@@ -89,11 +170,15 @@
2461 * Invalid mode handlers
2462 */
2463 .macro inv_entry, reason
2464+
2465+ pax_enter_kernel
2466+
2467 sub sp, sp, #S_FRAME_SIZE
2468 ARM( stmib sp, {r1 - lr} )
2469 THUMB( stmia sp, {r0 - r12} )
2470 THUMB( str sp, [sp, #S_SP] )
2471 THUMB( str lr, [sp, #S_LR] )
2472+
2473 mov r1, #\reason
2474 .endm
2475
2476@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2477 .macro svc_entry, stack_hole=0
2478 UNWIND(.fnstart )
2479 UNWIND(.save {r0 - pc} )
2480+
2481+ pax_enter_kernel
2482+
2483 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2484+
2485 #ifdef CONFIG_THUMB2_KERNEL
2486 SPFIX( str r0, [sp] ) @ temporarily saved
2487 SPFIX( mov r0, sp )
2488@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2489 ldmia r0, {r3 - r5}
2490 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2491 mov r6, #-1 @ "" "" "" ""
2492+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2493+ @ offset sp by 8 as done in pax_enter_kernel
2494+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2495+#else
2496 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2497+#endif
2498 SPFIX( addeq r2, r2, #4 )
2499 str r3, [sp, #-4]! @ save the "real" r0 copied
2500 @ from the exception stack
2501@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2502 .macro usr_entry
2503 UNWIND(.fnstart )
2504 UNWIND(.cantunwind ) @ don't unwind the user space
2505+
2506+ pax_enter_kernel_user
2507+
2508 sub sp, sp, #S_FRAME_SIZE
2509 ARM( stmib sp, {r1 - r12} )
2510 THUMB( stmia sp, {r0 - r12} )
2511@@ -416,7 +513,9 @@ __und_usr:
2512 tst r3, #PSR_T_BIT @ Thumb mode?
2513 bne __und_usr_thumb
2514 sub r4, r2, #4 @ ARM instr at LR - 4
2515+ pax_open_userland
2516 1: ldrt r0, [r4]
2517+ pax_close_userland
2518 #ifdef CONFIG_CPU_ENDIAN_BE8
2519 rev r0, r0 @ little endian instruction
2520 #endif
2521@@ -451,10 +550,14 @@ __und_usr_thumb:
2522 */
2523 .arch armv6t2
2524 #endif
2525+ pax_open_userland
2526 2: ldrht r5, [r4]
2527+ pax_close_userland
2528 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2529 blo __und_usr_fault_16 @ 16bit undefined instruction
2530+ pax_open_userland
2531 3: ldrht r0, [r2]
2532+ pax_close_userland
2533 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2534 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2535 orr r0, r0, r5, lsl #16
2536@@ -483,7 +586,8 @@ ENDPROC(__und_usr)
2537 */
2538 .pushsection .fixup, "ax"
2539 .align 2
2540-4: mov pc, r9
2541+4: pax_close_userland
2542+ mov pc, r9
2543 .popsection
2544 .pushsection __ex_table,"a"
2545 .long 1b, 4b
2546@@ -693,7 +797,7 @@ ENTRY(__switch_to)
2547 THUMB( str lr, [ip], #4 )
2548 ldr r4, [r2, #TI_TP_VALUE]
2549 ldr r5, [r2, #TI_TP_VALUE + 4]
2550-#ifdef CONFIG_CPU_USE_DOMAINS
2551+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2552 ldr r6, [r2, #TI_CPU_DOMAIN]
2553 #endif
2554 switch_tls r1, r4, r5, r3, r7
2555@@ -702,7 +806,7 @@ ENTRY(__switch_to)
2556 ldr r8, =__stack_chk_guard
2557 ldr r7, [r7, #TSK_STACK_CANARY]
2558 #endif
2559-#ifdef CONFIG_CPU_USE_DOMAINS
2560+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2561 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2562 #endif
2563 mov r5, r0
2564diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2565index bc6bd96..bd026cb 100644
2566--- a/arch/arm/kernel/entry-common.S
2567+++ b/arch/arm/kernel/entry-common.S
2568@@ -10,18 +10,46 @@
2569
2570 #include <asm/unistd.h>
2571 #include <asm/ftrace.h>
2572+#include <asm/domain.h>
2573 #include <asm/unwind.h>
2574
2575+#include "entry-header.S"
2576+
2577 #ifdef CONFIG_NEED_RET_TO_USER
2578 #include <mach/entry-macro.S>
2579 #else
2580 .macro arch_ret_to_user, tmp1, tmp2
2581+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2582+ @ save regs
2583+ stmdb sp!, {r1, r2}
2584+ @ read DACR from cpu_domain into r1
2585+ mov r2, sp
2586+ @ assume 8K pages, since we have to split the immediate in two
2587+ bic r2, r2, #(0x1fc0)
2588+ bic r2, r2, #(0x3f)
2589+ ldr r1, [r2, #TI_CPU_DOMAIN]
2590+#ifdef CONFIG_PAX_KERNEXEC
2591+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2592+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2593+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2594+#endif
2595+#ifdef CONFIG_PAX_MEMORY_UDEREF
2596+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2597+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2598+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2599+#endif
2600+ @ write r1 to current_thread_info()->cpu_domain
2601+ str r1, [r2, #TI_CPU_DOMAIN]
2602+ @ write r1 to DACR
2603+ mcr p15, 0, r1, c3, c0, 0
2604+ @ instruction sync
2605+ instr_sync
2606+ @ restore regs
2607+ ldmia sp!, {r1, r2}
2608+#endif
2609 .endm
2610 #endif
2611
2612-#include "entry-header.S"
2613-
2614-
2615 .align 5
2616 /*
2617 * This is the fast syscall return path. We do as little as
2618@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2619 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2620 #endif
2621
2622+ /*
2623+ * do this here to avoid a performance hit of wrapping the code above
2624+ * that directly dereferences userland to parse the SWI instruction
2625+ */
2626+ pax_enter_kernel_user
2627+
2628 adr tbl, sys_call_table @ load syscall table pointer
2629
2630 #if defined(CONFIG_OABI_COMPAT)
2631diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2632index 39f89fb..d612bd9 100644
2633--- a/arch/arm/kernel/entry-header.S
2634+++ b/arch/arm/kernel/entry-header.S
2635@@ -184,6 +184,60 @@
2636 msr cpsr_c, \rtemp @ switch back to the SVC mode
2637 .endm
2638
2639+ .macro pax_enter_kernel_user
2640+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2641+ @ save regs
2642+ stmdb sp!, {r0, r1}
2643+ @ read DACR from cpu_domain into r1
2644+ mov r0, sp
2645+ @ assume 8K pages, since we have to split the immediate in two
2646+ bic r0, r0, #(0x1fc0)
2647+ bic r0, r0, #(0x3f)
2648+ ldr r1, [r0, #TI_CPU_DOMAIN]
2649+#ifdef CONFIG_PAX_MEMORY_UDEREF
2650+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2651+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2652+#endif
2653+#ifdef CONFIG_PAX_KERNEXEC
2654+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2655+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2656+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2657+#endif
2658+ @ write r1 to current_thread_info()->cpu_domain
2659+ str r1, [r0, #TI_CPU_DOMAIN]
2660+ @ write r1 to DACR
2661+ mcr p15, 0, r1, c3, c0, 0
2662+ @ instruction sync
2663+ instr_sync
2664+ @ restore regs
2665+ ldmia sp!, {r0, r1}
2666+#endif
2667+ .endm
2668+
2669+ .macro pax_exit_kernel
2670+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2671+ @ save regs
2672+ stmdb sp!, {r0, r1}
2673+ @ read old DACR from stack into r1
2674+ ldr r1, [sp, #(8 + S_SP)]
2675+ sub r1, r1, #8
2676+ ldr r1, [r1]
2677+
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ mov r0, sp
2680+ @ assume 8K pages, since we have to split the immediate in two
2681+ bic r0, r0, #(0x1fc0)
2682+ bic r0, r0, #(0x3f)
2683+ str r1, [r0, #TI_CPU_DOMAIN]
2684+ @ write r1 to DACR
2685+ mcr p15, 0, r1, c3, c0, 0
2686+ @ instruction sync
2687+ instr_sync
2688+ @ restore regs
2689+ ldmia sp!, {r0, r1}
2690+#endif
2691+ .endm
2692+
2693 #ifndef CONFIG_THUMB2_KERNEL
2694 .macro svc_exit, rpsr, irq = 0
2695 .if \irq != 0
2696@@ -203,6 +257,9 @@
2697 blne trace_hardirqs_off
2698 #endif
2699 .endif
2700+
2701+ pax_exit_kernel
2702+
2703 msr spsr_cxsf, \rpsr
2704 #if defined(CONFIG_CPU_V6)
2705 ldr r0, [sp]
2706@@ -266,6 +323,9 @@
2707 blne trace_hardirqs_off
2708 #endif
2709 .endif
2710+
2711+ pax_exit_kernel
2712+
2713 ldr lr, [sp, #S_SP] @ top of the stack
2714 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2715 clrex @ clear the exclusive monitor
2716diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2717index 918875d..cd5fa27 100644
2718--- a/arch/arm/kernel/fiq.c
2719+++ b/arch/arm/kernel/fiq.c
2720@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2721 void *base = vectors_page;
2722 unsigned offset = FIQ_OFFSET;
2723
2724+ pax_open_kernel();
2725 memcpy(base + offset, start, length);
2726+ pax_close_kernel();
2727+
2728 if (!cache_is_vipt_nonaliasing())
2729 flush_icache_range((unsigned long)base + offset, offset +
2730 length);
2731diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2732index 476de57..4857a76 100644
2733--- a/arch/arm/kernel/head.S
2734+++ b/arch/arm/kernel/head.S
2735@@ -52,7 +52,9 @@
2736 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2737
2738 .macro pgtbl, rd, phys
2739- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2740+ mov \rd, #TEXT_OFFSET
2741+ sub \rd, #PG_DIR_SIZE
2742+ add \rd, \rd, \phys
2743 .endm
2744
2745 /*
2746@@ -432,7 +434,7 @@ __enable_mmu:
2747 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2748 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2749 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2750- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2751+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2752 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2753 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2754 #endif
2755diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2756index 084dc88..fce4e68 100644
2757--- a/arch/arm/kernel/module.c
2758+++ b/arch/arm/kernel/module.c
2759@@ -37,12 +37,39 @@
2760 #endif
2761
2762 #ifdef CONFIG_MMU
2763-void *module_alloc(unsigned long size)
2764+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2765 {
2766+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2767+ return NULL;
2768 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2769- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2770+ GFP_KERNEL, prot, -1,
2771 __builtin_return_address(0));
2772 }
2773+
2774+void *module_alloc(unsigned long size)
2775+{
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+ return __module_alloc(size, PAGE_KERNEL);
2779+#else
2780+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2781+#endif
2782+
2783+}
2784+
2785+#ifdef CONFIG_PAX_KERNEXEC
2786+void module_free_exec(struct module *mod, void *module_region)
2787+{
2788+ module_free(mod, module_region);
2789+}
2790+EXPORT_SYMBOL(module_free_exec);
2791+
2792+void *module_alloc_exec(unsigned long size)
2793+{
2794+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2795+}
2796+EXPORT_SYMBOL(module_alloc_exec);
2797+#endif
2798 #endif
2799
2800 int
2801diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2802index 07314af..c46655c 100644
2803--- a/arch/arm/kernel/patch.c
2804+++ b/arch/arm/kernel/patch.c
2805@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2807 int size;
2808
2809+ pax_open_kernel();
2810 if (thumb2 && __opcode_is_thumb16(insn)) {
2811 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2812 size = sizeof(u16);
2813@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2814 *(u32 *)addr = insn;
2815 size = sizeof(u32);
2816 }
2817+ pax_close_kernel();
2818
2819 flush_icache_range((uintptr_t)(addr),
2820 (uintptr_t)(addr) + size);
2821diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2822index 92f7b15..7048500 100644
2823--- a/arch/arm/kernel/process.c
2824+++ b/arch/arm/kernel/process.c
2825@@ -217,6 +217,7 @@ void machine_power_off(void)
2826
2827 if (pm_power_off)
2828 pm_power_off();
2829+ BUG();
2830 }
2831
2832 /*
2833@@ -230,7 +231,7 @@ void machine_power_off(void)
2834 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2835 * to use. Implementing such co-ordination would be essentially impossible.
2836 */
2837-void machine_restart(char *cmd)
2838+__noreturn void machine_restart(char *cmd)
2839 {
2840 local_irq_disable();
2841 smp_send_stop();
2842@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2843
2844 show_regs_print_info(KERN_DEFAULT);
2845
2846- print_symbol("PC is at %s\n", instruction_pointer(regs));
2847- print_symbol("LR is at %s\n", regs->ARM_lr);
2848+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2849+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2850 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2851 "sp : %08lx ip : %08lx fp : %08lx\n",
2852 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2853@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2854 return 0;
2855 }
2856
2857-unsigned long arch_randomize_brk(struct mm_struct *mm)
2858-{
2859- unsigned long range_end = mm->brk + 0x02000000;
2860- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2861-}
2862-
2863 #ifdef CONFIG_MMU
2864 #ifdef CONFIG_KUSER_HELPERS
2865 /*
2866@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2867
2868 static int __init gate_vma_init(void)
2869 {
2870- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2871+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2872 return 0;
2873 }
2874 arch_initcall(gate_vma_init);
2875@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2876
2877 const char *arch_vma_name(struct vm_area_struct *vma)
2878 {
2879- return is_gate_vma(vma) ? "[vectors]" :
2880- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2881- "[sigpage]" : NULL;
2882+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2883 }
2884
2885-static struct page *signal_page;
2886-extern struct page *get_signal_page(void);
2887-
2888 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2889 {
2890 struct mm_struct *mm = current->mm;
2891- unsigned long addr;
2892- int ret;
2893-
2894- if (!signal_page)
2895- signal_page = get_signal_page();
2896- if (!signal_page)
2897- return -ENOMEM;
2898
2899 down_write(&mm->mmap_sem);
2900- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2901- if (IS_ERR_VALUE(addr)) {
2902- ret = addr;
2903- goto up_fail;
2904- }
2905-
2906- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2907- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2908- &signal_page);
2909-
2910- if (ret == 0)
2911- mm->context.sigpage = addr;
2912-
2913- up_fail:
2914+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2915 up_write(&mm->mmap_sem);
2916- return ret;
2917+ return 0;
2918 }
2919 #endif
2920diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2921index 4693188..4596c5e 100644
2922--- a/arch/arm/kernel/psci.c
2923+++ b/arch/arm/kernel/psci.c
2924@@ -24,7 +24,7 @@
2925 #include <asm/opcodes-virt.h>
2926 #include <asm/psci.h>
2927
2928-struct psci_operations psci_ops;
2929+struct psci_operations psci_ops __read_only;
2930
2931 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2932
2933diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2934index 0dd3b79..e018f64 100644
2935--- a/arch/arm/kernel/ptrace.c
2936+++ b/arch/arm/kernel/ptrace.c
2937@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2938 return current_thread_info()->syscall;
2939 }
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+extern void gr_delayed_cred_worker(void);
2943+#endif
2944+
2945 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2946 {
2947 current_thread_info()->syscall = scno;
2948
2949+#ifdef CONFIG_GRKERNSEC_SETXID
2950+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2951+ gr_delayed_cred_worker();
2952+#endif
2953+
2954 /* Do the secure computing check first; failures should be fast. */
2955 if (secure_computing(scno) == -1)
2956 return -1;
2957diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2958index 0e1e2b3..c0e821d 100644
2959--- a/arch/arm/kernel/setup.c
2960+++ b/arch/arm/kernel/setup.c
2961@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2962 unsigned int elf_hwcap __read_mostly;
2963 EXPORT_SYMBOL(elf_hwcap);
2964
2965+pteval_t __supported_pte_mask __read_only;
2966+pmdval_t __supported_pmd_mask __read_only;
2967
2968 #ifdef MULTI_CPU
2969-struct processor processor __read_mostly;
2970+struct processor processor;
2971 #endif
2972 #ifdef MULTI_TLB
2973-struct cpu_tlb_fns cpu_tlb __read_mostly;
2974+struct cpu_tlb_fns cpu_tlb __read_only;
2975 #endif
2976 #ifdef MULTI_USER
2977-struct cpu_user_fns cpu_user __read_mostly;
2978+struct cpu_user_fns cpu_user __read_only;
2979 #endif
2980 #ifdef MULTI_CACHE
2981-struct cpu_cache_fns cpu_cache __read_mostly;
2982+struct cpu_cache_fns cpu_cache __read_only;
2983 #endif
2984 #ifdef CONFIG_OUTER_CACHE
2985-struct outer_cache_fns outer_cache __read_mostly;
2986+struct outer_cache_fns outer_cache __read_only;
2987 EXPORT_SYMBOL(outer_cache);
2988 #endif
2989
2990@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2991 asm("mrc p15, 0, %0, c0, c1, 4"
2992 : "=r" (mmfr0));
2993 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2994- (mmfr0 & 0x000000f0) >= 0x00000030)
2995+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2996 cpu_arch = CPU_ARCH_ARMv7;
2997- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2998+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2999+ __supported_pte_mask |= L_PTE_PXN;
3000+ __supported_pmd_mask |= PMD_PXNTABLE;
3001+ }
3002+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3003 (mmfr0 & 0x000000f0) == 0x00000020)
3004 cpu_arch = CPU_ARCH_ARMv6;
3005 else
3006@@ -571,7 +577,7 @@ static void __init setup_processor(void)
3007 __cpu_architecture = __get_cpu_architecture();
3008
3009 #ifdef MULTI_CPU
3010- processor = *list->proc;
3011+ memcpy((void *)&processor, list->proc, sizeof processor);
3012 #endif
3013 #ifdef MULTI_TLB
3014 cpu_tlb = *list->tlb;
3015diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016index ab33042..11248a8 100644
3017--- a/arch/arm/kernel/signal.c
3018+++ b/arch/arm/kernel/signal.c
3019@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3020 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3021 };
3022
3023-static unsigned long signal_return_offset;
3024-
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032- retcode = mm->context.sigpage + signal_return_offset +
3033- (idx << 2) + thumb;
3034+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042-
3043-struct page *get_signal_page(void)
3044-{
3045- unsigned long ptr;
3046- unsigned offset;
3047- struct page *page;
3048- void *addr;
3049-
3050- page = alloc_pages(GFP_KERNEL, 0);
3051-
3052- if (!page)
3053- return NULL;
3054-
3055- addr = page_address(page);
3056-
3057- /* Give the signal return code some randomness */
3058- offset = 0x200 + (get_random_int() & 0x7fc);
3059- signal_return_offset = offset;
3060-
3061- /*
3062- * Copy signal return handlers into the vector page, and
3063- * set sigreturn to be a pointer to these.
3064- */
3065- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066-
3067- ptr = (unsigned long)addr + offset;
3068- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069-
3070- return page;
3071-}
3072diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073index 72024ea..ae302dd 100644
3074--- a/arch/arm/kernel/smp.c
3075+++ b/arch/arm/kernel/smp.c
3076@@ -70,7 +70,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080-static struct smp_operations smp_ops;
3081+static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3086index 65ed63f..430c478 100644
3087--- a/arch/arm/kernel/traps.c
3088+++ b/arch/arm/kernel/traps.c
3089@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3090 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3091 {
3092 #ifdef CONFIG_KALLSYMS
3093- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3094+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3095 #else
3096 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3097 #endif
3098@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3099 static int die_owner = -1;
3100 static unsigned int die_nest_count;
3101
3102+extern void gr_handle_kernel_exploit(void);
3103+
3104 static unsigned long oops_begin(void)
3105 {
3106 int cpu;
3107@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3108 panic("Fatal exception in interrupt");
3109 if (panic_on_oops)
3110 panic("Fatal exception");
3111+
3112+ gr_handle_kernel_exploit();
3113+
3114 if (signr)
3115 do_exit(signr);
3116 }
3117@@ -629,7 +634,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3118 * The user helper at 0xffff0fe0 must be used instead.
3119 * (see entry-armv.S for details)
3120 */
3121+ pax_open_kernel();
3122 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3123+ pax_close_kernel();
3124 }
3125 return 0;
3126
3127@@ -886,7 +893,11 @@ void __init early_trap_init(void *vectors_base)
3128 kuser_init(vectors_base);
3129
3130 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3131- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3132+
3133+#ifndef CONFIG_PAX_MEMORY_UDEREF
3134+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3135+#endif
3136+
3137 #else /* ifndef CONFIG_CPU_V7M */
3138 /*
3139 * on V7-M there is no need to copy the vector table to a dedicated
3140diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3141index 7bcee5c..e2f3249 100644
3142--- a/arch/arm/kernel/vmlinux.lds.S
3143+++ b/arch/arm/kernel/vmlinux.lds.S
3144@@ -8,7 +8,11 @@
3145 #include <asm/thread_info.h>
3146 #include <asm/memory.h>
3147 #include <asm/page.h>
3148-
3149+
3150+#ifdef CONFIG_PAX_KERNEXEC
3151+#include <asm/pgtable.h>
3152+#endif
3153+
3154 #define PROC_INFO \
3155 . = ALIGN(4); \
3156 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3157@@ -34,7 +38,7 @@
3158 #endif
3159
3160 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3161- defined(CONFIG_GENERIC_BUG)
3162+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3163 #define ARM_EXIT_KEEP(x) x
3164 #define ARM_EXIT_DISCARD(x)
3165 #else
3166@@ -90,6 +94,11 @@ SECTIONS
3167 _text = .;
3168 HEAD_TEXT
3169 }
3170+
3171+#ifdef CONFIG_PAX_KERNEXEC
3172+ . = ALIGN(1<<SECTION_SHIFT);
3173+#endif
3174+
3175 .text : { /* Real text segment */
3176 _stext = .; /* Text and read-only data */
3177 __exception_text_start = .;
3178@@ -112,6 +121,8 @@ SECTIONS
3179 ARM_CPU_KEEP(PROC_INFO)
3180 }
3181
3182+ _etext = .; /* End of text section */
3183+
3184 RO_DATA(PAGE_SIZE)
3185
3186 . = ALIGN(4);
3187@@ -142,7 +153,9 @@ SECTIONS
3188
3189 NOTES
3190
3191- _etext = .; /* End of text and rodata section */
3192+#ifdef CONFIG_PAX_KERNEXEC
3193+ . = ALIGN(1<<SECTION_SHIFT);
3194+#endif
3195
3196 #ifndef CONFIG_XIP_KERNEL
3197 . = ALIGN(PAGE_SIZE);
3198@@ -220,6 +233,11 @@ SECTIONS
3199 . = PAGE_OFFSET + TEXT_OFFSET;
3200 #else
3201 __init_end = .;
3202+
3203+#ifdef CONFIG_PAX_KERNEXEC
3204+ . = ALIGN(1<<SECTION_SHIFT);
3205+#endif
3206+
3207 . = ALIGN(THREAD_SIZE);
3208 __data_loc = .;
3209 #endif
3210diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3211index 9c697db..115237f 100644
3212--- a/arch/arm/kvm/arm.c
3213+++ b/arch/arm/kvm/arm.c
3214@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3215 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3216
3217 /* The VMID used in the VTTBR */
3218-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3219+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3220 static u8 kvm_next_vmid;
3221 static DEFINE_SPINLOCK(kvm_vmid_lock);
3222
3223@@ -396,7 +396,7 @@ void force_vm_exit(const cpumask_t *mask)
3224 */
3225 static bool need_new_vmid_gen(struct kvm *kvm)
3226 {
3227- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3228+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3229 }
3230
3231 /**
3232@@ -429,7 +429,7 @@ static void update_vttbr(struct kvm *kvm)
3233
3234 /* First user of a new VMID generation? */
3235 if (unlikely(kvm_next_vmid == 0)) {
3236- atomic64_inc(&kvm_vmid_gen);
3237+ atomic64_inc_unchecked(&kvm_vmid_gen);
3238 kvm_next_vmid = 1;
3239
3240 /*
3241@@ -446,7 +446,7 @@ static void update_vttbr(struct kvm *kvm)
3242 kvm_call_hyp(__kvm_flush_vm_context);
3243 }
3244
3245- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3246+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3247 kvm->arch.vmid = kvm_next_vmid;
3248 kvm_next_vmid++;
3249
3250diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3251index 14a0d98..7771a7d 100644
3252--- a/arch/arm/lib/clear_user.S
3253+++ b/arch/arm/lib/clear_user.S
3254@@ -12,14 +12,14 @@
3255
3256 .text
3257
3258-/* Prototype: int __clear_user(void *addr, size_t sz)
3259+/* Prototype: int ___clear_user(void *addr, size_t sz)
3260 * Purpose : clear some user memory
3261 * Params : addr - user memory address to clear
3262 * : sz - number of bytes to clear
3263 * Returns : number of bytes NOT cleared
3264 */
3265 ENTRY(__clear_user_std)
3266-WEAK(__clear_user)
3267+WEAK(___clear_user)
3268 stmfd sp!, {r1, lr}
3269 mov r2, #0
3270 cmp r1, #4
3271@@ -44,7 +44,7 @@ WEAK(__clear_user)
3272 USER( strnebt r2, [r0])
3273 mov r0, #0
3274 ldmfd sp!, {r1, pc}
3275-ENDPROC(__clear_user)
3276+ENDPROC(___clear_user)
3277 ENDPROC(__clear_user_std)
3278
3279 .pushsection .fixup,"ax"
3280diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3281index 66a477a..bee61d3 100644
3282--- a/arch/arm/lib/copy_from_user.S
3283+++ b/arch/arm/lib/copy_from_user.S
3284@@ -16,7 +16,7 @@
3285 /*
3286 * Prototype:
3287 *
3288- * size_t __copy_from_user(void *to, const void *from, size_t n)
3289+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3290 *
3291 * Purpose:
3292 *
3293@@ -84,11 +84,11 @@
3294
3295 .text
3296
3297-ENTRY(__copy_from_user)
3298+ENTRY(___copy_from_user)
3299
3300 #include "copy_template.S"
3301
3302-ENDPROC(__copy_from_user)
3303+ENDPROC(___copy_from_user)
3304
3305 .pushsection .fixup,"ax"
3306 .align 0
3307diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3308index 6ee2f67..d1cce76 100644
3309--- a/arch/arm/lib/copy_page.S
3310+++ b/arch/arm/lib/copy_page.S
3311@@ -10,6 +10,7 @@
3312 * ASM optimised string functions
3313 */
3314 #include <linux/linkage.h>
3315+#include <linux/const.h>
3316 #include <asm/assembler.h>
3317 #include <asm/asm-offsets.h>
3318 #include <asm/cache.h>
3319diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3320index d066df6..df28194 100644
3321--- a/arch/arm/lib/copy_to_user.S
3322+++ b/arch/arm/lib/copy_to_user.S
3323@@ -16,7 +16,7 @@
3324 /*
3325 * Prototype:
3326 *
3327- * size_t __copy_to_user(void *to, const void *from, size_t n)
3328+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3329 *
3330 * Purpose:
3331 *
3332@@ -88,11 +88,11 @@
3333 .text
3334
3335 ENTRY(__copy_to_user_std)
3336-WEAK(__copy_to_user)
3337+WEAK(___copy_to_user)
3338
3339 #include "copy_template.S"
3340
3341-ENDPROC(__copy_to_user)
3342+ENDPROC(___copy_to_user)
3343 ENDPROC(__copy_to_user_std)
3344
3345 .pushsection .fixup,"ax"
3346diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3347index 7d08b43..f7ca7ea 100644
3348--- a/arch/arm/lib/csumpartialcopyuser.S
3349+++ b/arch/arm/lib/csumpartialcopyuser.S
3350@@ -57,8 +57,8 @@
3351 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3352 */
3353
3354-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3355-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3356+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3357+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3358
3359 #include "csumpartialcopygeneric.S"
3360
3361diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3362index 5306de3..aed6d03 100644
3363--- a/arch/arm/lib/delay.c
3364+++ b/arch/arm/lib/delay.c
3365@@ -28,7 +28,7 @@
3366 /*
3367 * Default to the loop-based delay implementation.
3368 */
3369-struct arm_delay_ops arm_delay_ops = {
3370+struct arm_delay_ops arm_delay_ops __read_only = {
3371 .delay = __loop_delay,
3372 .const_udelay = __loop_const_udelay,
3373 .udelay = __loop_udelay,
3374diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3375index 025f742..a9e5b3b 100644
3376--- a/arch/arm/lib/uaccess_with_memcpy.c
3377+++ b/arch/arm/lib/uaccess_with_memcpy.c
3378@@ -104,7 +104,7 @@ out:
3379 }
3380
3381 unsigned long
3382-__copy_to_user(void __user *to, const void *from, unsigned long n)
3383+___copy_to_user(void __user *to, const void *from, unsigned long n)
3384 {
3385 /*
3386 * This test is stubbed out of the main function above to keep
3387@@ -155,7 +155,7 @@ out:
3388 return n;
3389 }
3390
3391-unsigned long __clear_user(void __user *addr, unsigned long n)
3392+unsigned long ___clear_user(void __user *addr, unsigned long n)
3393 {
3394 /* See rational for this in __copy_to_user() above. */
3395 if (n < 64)
3396diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3397index 1767611..d2e7e24 100644
3398--- a/arch/arm/mach-kirkwood/common.c
3399+++ b/arch/arm/mach-kirkwood/common.c
3400@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3401 clk_gate_ops.disable(hw);
3402 }
3403
3404-static struct clk_ops clk_gate_fn_ops;
3405+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3406+{
3407+ return clk_gate_ops.is_enabled(hw);
3408+}
3409+
3410+static struct clk_ops clk_gate_fn_ops = {
3411+ .enable = clk_gate_fn_enable,
3412+ .disable = clk_gate_fn_disable,
3413+ .is_enabled = clk_gate_fn_is_enabled,
3414+};
3415
3416 static struct clk __init *clk_register_gate_fn(struct device *dev,
3417 const char *name,
3418@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3419 gate_fn->fn_en = fn_en;
3420 gate_fn->fn_dis = fn_dis;
3421
3422- /* ops is the gate ops, but with our enable/disable functions */
3423- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3424- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3425- clk_gate_fn_ops = clk_gate_ops;
3426- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3427- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3428- }
3429-
3430 clk = clk_register(dev, &gate_fn->gate.hw);
3431
3432 if (IS_ERR(clk))
3433diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3434index 827d1500..2885dc6 100644
3435--- a/arch/arm/mach-omap2/board-n8x0.c
3436+++ b/arch/arm/mach-omap2/board-n8x0.c
3437@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3438 }
3439 #endif
3440
3441-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3442+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3443 .late_init = n8x0_menelaus_late_init,
3444 };
3445
3446diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3447index 579697a..1d5a3b2 100644
3448--- a/arch/arm/mach-omap2/gpmc.c
3449+++ b/arch/arm/mach-omap2/gpmc.c
3450@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3451 };
3452
3453 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3454-static struct irq_chip gpmc_irq_chip;
3455 static int gpmc_irq_start;
3456
3457 static struct resource gpmc_mem_root;
3458@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3459
3460 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3461
3462+static struct irq_chip gpmc_irq_chip = {
3463+ .name = "gpmc",
3464+ .irq_startup = gpmc_irq_noop_ret,
3465+ .irq_enable = gpmc_irq_enable,
3466+ .irq_disable = gpmc_irq_disable,
3467+ .irq_shutdown = gpmc_irq_noop,
3468+ .irq_ack = gpmc_irq_noop,
3469+ .irq_mask = gpmc_irq_noop,
3470+ .irq_unmask = gpmc_irq_noop,
3471+
3472+};
3473+
3474 static int gpmc_setup_irq(void)
3475 {
3476 int i;
3477@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3478 return gpmc_irq_start;
3479 }
3480
3481- gpmc_irq_chip.name = "gpmc";
3482- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3483- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3484- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3485- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3486- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3487- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3488- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3489-
3490 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3491 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3492
3493diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3494index f991016..145ebeb 100644
3495--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3496+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3497@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3498 int (*finish_suspend)(unsigned long cpu_state);
3499 void (*resume)(void);
3500 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3501-};
3502+} __no_const;
3503
3504 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3505 static struct powerdomain *mpuss_pd;
3506@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3507 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3508 {}
3509
3510-struct cpu_pm_ops omap_pm_ops = {
3511+static struct cpu_pm_ops omap_pm_ops __read_only = {
3512 .finish_suspend = default_finish_suspend,
3513 .resume = dummy_cpu_resume,
3514 .scu_prepare = dummy_scu_prepare,
3515diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3516index 813c615..ce467c6 100644
3517--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3518+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3519@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3520 return NOTIFY_OK;
3521 }
3522
3523-static struct notifier_block __refdata irq_hotplug_notifier = {
3524+static struct notifier_block irq_hotplug_notifier = {
3525 .notifier_call = irq_cpu_hotplug_notify,
3526 };
3527
3528diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3529index 53f0735..5b54eb6 100644
3530--- a/arch/arm/mach-omap2/omap_device.c
3531+++ b/arch/arm/mach-omap2/omap_device.c
3532@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3533 struct platform_device __init *omap_device_build(const char *pdev_name,
3534 int pdev_id,
3535 struct omap_hwmod *oh,
3536- void *pdata, int pdata_len)
3537+ const void *pdata, int pdata_len)
3538 {
3539 struct omap_hwmod *ohs[] = { oh };
3540
3541@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3542 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3543 int pdev_id,
3544 struct omap_hwmod **ohs,
3545- int oh_cnt, void *pdata,
3546+ int oh_cnt, const void *pdata,
3547 int pdata_len)
3548 {
3549 int ret = -ENOMEM;
3550diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3551index 17ca1ae..beba869 100644
3552--- a/arch/arm/mach-omap2/omap_device.h
3553+++ b/arch/arm/mach-omap2/omap_device.h
3554@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3555 /* Core code interface */
3556
3557 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3558- struct omap_hwmod *oh, void *pdata,
3559+ struct omap_hwmod *oh, const void *pdata,
3560 int pdata_len);
3561
3562 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3563 struct omap_hwmod **oh, int oh_cnt,
3564- void *pdata, int pdata_len);
3565+ const void *pdata, int pdata_len);
3566
3567 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3568 struct omap_hwmod **ohs, int oh_cnt);
3569diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3570index 832adb1..49b62c4 100644
3571--- a/arch/arm/mach-omap2/omap_hwmod.c
3572+++ b/arch/arm/mach-omap2/omap_hwmod.c
3573@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3574 int (*init_clkdm)(struct omap_hwmod *oh);
3575 void (*update_context_lost)(struct omap_hwmod *oh);
3576 int (*get_context_lost)(struct omap_hwmod *oh);
3577-};
3578+} __no_const;
3579
3580 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3581-static struct omap_hwmod_soc_ops soc_ops;
3582+static struct omap_hwmod_soc_ops soc_ops __read_only;
3583
3584 /* omap_hwmod_list contains all registered struct omap_hwmods */
3585 static LIST_HEAD(omap_hwmod_list);
3586diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3587index d15c7bb..b2d1f0c 100644
3588--- a/arch/arm/mach-omap2/wd_timer.c
3589+++ b/arch/arm/mach-omap2/wd_timer.c
3590@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3591 struct omap_hwmod *oh;
3592 char *oh_name = "wd_timer2";
3593 char *dev_name = "omap_wdt";
3594- struct omap_wd_timer_platform_data pdata;
3595+ static struct omap_wd_timer_platform_data pdata = {
3596+ .read_reset_sources = prm_read_reset_sources
3597+ };
3598
3599 if (!cpu_class_is_omap2() || of_have_populated_dt())
3600 return 0;
3601@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3602 return -EINVAL;
3603 }
3604
3605- pdata.read_reset_sources = prm_read_reset_sources;
3606-
3607 pdev = omap_device_build(dev_name, id, oh, &pdata,
3608 sizeof(struct omap_wd_timer_platform_data));
3609 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3610diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3611index b82dcae..44ee5b6 100644
3612--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3613+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3614@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3615 bool entered_lp2 = false;
3616
3617 if (tegra_pending_sgi())
3618- ACCESS_ONCE(abort_flag) = true;
3619+ ACCESS_ONCE_RW(abort_flag) = true;
3620
3621 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3622
3623diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3624index 656324a..0beba28 100644
3625--- a/arch/arm/mach-ux500/setup.h
3626+++ b/arch/arm/mach-ux500/setup.h
3627@@ -40,13 +40,6 @@ extern void ux500_timer_init(void);
3628 .type = MT_DEVICE, \
3629 }
3630
3631-#define __MEM_DEV_DESC(x, sz) { \
3632- .virtual = IO_ADDRESS(x), \
3633- .pfn = __phys_to_pfn(x), \
3634- .length = sz, \
3635- .type = MT_MEMORY, \
3636-}
3637-
3638 extern struct smp_operations ux500_smp_ops;
3639 extern void ux500_cpu_die(unsigned int cpu);
3640
3641diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3642index cd2c88e..4dd9b67 100644
3643--- a/arch/arm/mm/Kconfig
3644+++ b/arch/arm/mm/Kconfig
3645@@ -446,7 +446,7 @@ config CPU_32v5
3646
3647 config CPU_32v6
3648 bool
3649- select CPU_USE_DOMAINS if CPU_V6 && MMU
3650+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3651 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3652
3653 config CPU_32v6K
3654@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3655
3656 config CPU_USE_DOMAINS
3657 bool
3658+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3659 help
3660 This option enables or disables the use of domain switching
3661 via the set_fs() function.
3662@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3663 config KUSER_HELPERS
3664 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3665 default y
3666+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3667 help
3668 Warning: disabling this option may break user programs.
3669
3670@@ -812,7 +814,7 @@ config KUSER_HELPERS
3671 See Documentation/arm/kernel_user_helpers.txt for details.
3672
3673 However, the fixed address nature of these helpers can be used
3674- by ROP (return orientated programming) authors when creating
3675+ by ROP (Return Oriented Programming) authors when creating
3676 exploits.
3677
3678 If all of the binaries and libraries which run on your platform
3679diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3680index 6f4585b..7b6f52b 100644
3681--- a/arch/arm/mm/alignment.c
3682+++ b/arch/arm/mm/alignment.c
3683@@ -211,10 +211,12 @@ union offset_union {
3684 #define __get16_unaligned_check(ins,val,addr) \
3685 do { \
3686 unsigned int err = 0, v, a = addr; \
3687+ pax_open_userland(); \
3688 __get8_unaligned_check(ins,v,a,err); \
3689 val = v << ((BE) ? 8 : 0); \
3690 __get8_unaligned_check(ins,v,a,err); \
3691 val |= v << ((BE) ? 0 : 8); \
3692+ pax_close_userland(); \
3693 if (err) \
3694 goto fault; \
3695 } while (0)
3696@@ -228,6 +230,7 @@ union offset_union {
3697 #define __get32_unaligned_check(ins,val,addr) \
3698 do { \
3699 unsigned int err = 0, v, a = addr; \
3700+ pax_open_userland(); \
3701 __get8_unaligned_check(ins,v,a,err); \
3702 val = v << ((BE) ? 24 : 0); \
3703 __get8_unaligned_check(ins,v,a,err); \
3704@@ -236,6 +239,7 @@ union offset_union {
3705 val |= v << ((BE) ? 8 : 16); \
3706 __get8_unaligned_check(ins,v,a,err); \
3707 val |= v << ((BE) ? 0 : 24); \
3708+ pax_close_userland(); \
3709 if (err) \
3710 goto fault; \
3711 } while (0)
3712@@ -249,6 +253,7 @@ union offset_union {
3713 #define __put16_unaligned_check(ins,val,addr) \
3714 do { \
3715 unsigned int err = 0, v = val, a = addr; \
3716+ pax_open_userland(); \
3717 __asm__( FIRST_BYTE_16 \
3718 ARM( "1: "ins" %1, [%2], #1\n" ) \
3719 THUMB( "1: "ins" %1, [%2]\n" ) \
3720@@ -268,6 +273,7 @@ union offset_union {
3721 " .popsection\n" \
3722 : "=r" (err), "=&r" (v), "=&r" (a) \
3723 : "0" (err), "1" (v), "2" (a)); \
3724+ pax_close_userland(); \
3725 if (err) \
3726 goto fault; \
3727 } while (0)
3728@@ -281,6 +287,7 @@ union offset_union {
3729 #define __put32_unaligned_check(ins,val,addr) \
3730 do { \
3731 unsigned int err = 0, v = val, a = addr; \
3732+ pax_open_userland(); \
3733 __asm__( FIRST_BYTE_32 \
3734 ARM( "1: "ins" %1, [%2], #1\n" ) \
3735 THUMB( "1: "ins" %1, [%2]\n" ) \
3736@@ -310,6 +317,7 @@ union offset_union {
3737 " .popsection\n" \
3738 : "=r" (err), "=&r" (v), "=&r" (a) \
3739 : "0" (err), "1" (v), "2" (a)); \
3740+ pax_close_userland(); \
3741 if (err) \
3742 goto fault; \
3743 } while (0)
3744diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3745index 447da6f..77a5057 100644
3746--- a/arch/arm/mm/cache-l2x0.c
3747+++ b/arch/arm/mm/cache-l2x0.c
3748@@ -45,7 +45,7 @@ struct l2x0_of_data {
3749 void (*setup)(const struct device_node *, u32 *, u32 *);
3750 void (*save)(void);
3751 struct outer_cache_fns outer_cache;
3752-};
3753+} __do_const;
3754
3755 static bool of_init = false;
3756
3757diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3758index 84e6f77..0b52f31 100644
3759--- a/arch/arm/mm/context.c
3760+++ b/arch/arm/mm/context.c
3761@@ -43,7 +43,7 @@
3762 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3763
3764 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3765-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3766+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3767 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3768
3769 static DEFINE_PER_CPU(atomic64_t, active_asids);
3770@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3771 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3772 {
3773 u64 asid = atomic64_read(&mm->context.id);
3774- u64 generation = atomic64_read(&asid_generation);
3775+ u64 generation = atomic64_read_unchecked(&asid_generation);
3776
3777 if (asid != 0 && is_reserved_asid(asid)) {
3778 /*
3779@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3780 */
3781 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3782 if (asid == NUM_USER_ASIDS) {
3783- generation = atomic64_add_return(ASID_FIRST_VERSION,
3784+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3785 &asid_generation);
3786 flush_context(cpu);
3787 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3788@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3789 cpu_set_reserved_ttbr0();
3790
3791 asid = atomic64_read(&mm->context.id);
3792- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3793+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3794 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3795 goto switch_mm_fastpath;
3796
3797 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3798 /* Check that our ASID belongs to the current generation. */
3799 asid = atomic64_read(&mm->context.id);
3800- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3801+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3802 asid = new_context(mm, cpu);
3803 atomic64_set(&mm->context.id, asid);
3804 }
3805diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3806index eb8830a..5360ce7 100644
3807--- a/arch/arm/mm/fault.c
3808+++ b/arch/arm/mm/fault.c
3809@@ -25,6 +25,7 @@
3810 #include <asm/system_misc.h>
3811 #include <asm/system_info.h>
3812 #include <asm/tlbflush.h>
3813+#include <asm/sections.h>
3814
3815 #include "fault.h"
3816
3817@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3818 if (fixup_exception(regs))
3819 return;
3820
3821+#ifdef CONFIG_PAX_MEMORY_UDEREF
3822+ if (addr < TASK_SIZE) {
3823+ if (current->signal->curr_ip)
3824+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3825+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3826+ else
3827+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3828+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3829+ }
3830+#endif
3831+
3832+#ifdef CONFIG_PAX_KERNEXEC
3833+ if ((fsr & FSR_WRITE) &&
3834+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3835+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3836+ {
3837+ if (current->signal->curr_ip)
3838+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3839+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3840+ else
3841+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3842+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3843+ }
3844+#endif
3845+
3846 /*
3847 * No handler, we'll have to terminate things with extreme prejudice.
3848 */
3849@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3850 }
3851 #endif
3852
3853+#ifdef CONFIG_PAX_PAGEEXEC
3854+ if (fsr & FSR_LNX_PF) {
3855+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3856+ do_group_exit(SIGKILL);
3857+ }
3858+#endif
3859+
3860 tsk->thread.address = addr;
3861 tsk->thread.error_code = fsr;
3862 tsk->thread.trap_no = 14;
3863@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3864 }
3865 #endif /* CONFIG_MMU */
3866
3867+#ifdef CONFIG_PAX_PAGEEXEC
3868+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3869+{
3870+ long i;
3871+
3872+ printk(KERN_ERR "PAX: bytes at PC: ");
3873+ for (i = 0; i < 20; i++) {
3874+ unsigned char c;
3875+ if (get_user(c, (__force unsigned char __user *)pc+i))
3876+ printk(KERN_CONT "?? ");
3877+ else
3878+ printk(KERN_CONT "%02x ", c);
3879+ }
3880+ printk("\n");
3881+
3882+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3883+ for (i = -1; i < 20; i++) {
3884+ unsigned long c;
3885+ if (get_user(c, (__force unsigned long __user *)sp+i))
3886+ printk(KERN_CONT "???????? ");
3887+ else
3888+ printk(KERN_CONT "%08lx ", c);
3889+ }
3890+ printk("\n");
3891+}
3892+#endif
3893+
3894 /*
3895 * First Level Translation Fault Handler
3896 *
3897@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3898 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3899 struct siginfo info;
3900
3901+#ifdef CONFIG_PAX_MEMORY_UDEREF
3902+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3903+ if (current->signal->curr_ip)
3904+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3905+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3906+ else
3907+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3908+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3909+ goto die;
3910+ }
3911+#endif
3912+
3913 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3914 return;
3915
3916+die:
3917 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3918 inf->name, fsr, addr);
3919
3920@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3921 ifsr_info[nr].name = name;
3922 }
3923
3924+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3925+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3926+
3927 asmlinkage void __exception
3928 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3929 {
3930 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3931 struct siginfo info;
3932+ unsigned long pc = instruction_pointer(regs);
3933+
3934+ if (user_mode(regs)) {
3935+ unsigned long sigpage = current->mm->context.sigpage;
3936+
3937+ if (sigpage <= pc && pc < sigpage + 7*4) {
3938+ if (pc < sigpage + 3*4)
3939+ sys_sigreturn(regs);
3940+ else
3941+ sys_rt_sigreturn(regs);
3942+ return;
3943+ }
3944+ if (pc == 0xffff0f60UL) {
3945+ /*
3946+ * PaX: __kuser_cmpxchg64 emulation
3947+ */
3948+ // TODO
3949+ //regs->ARM_pc = regs->ARM_lr;
3950+ //return;
3951+ }
3952+ if (pc == 0xffff0fa0UL) {
3953+ /*
3954+ * PaX: __kuser_memory_barrier emulation
3955+ */
3956+ // dmb(); implied by the exception
3957+ regs->ARM_pc = regs->ARM_lr;
3958+ return;
3959+ }
3960+ if (pc == 0xffff0fc0UL) {
3961+ /*
3962+ * PaX: __kuser_cmpxchg emulation
3963+ */
3964+ // TODO
3965+ //long new;
3966+ //int op;
3967+
3968+ //op = FUTEX_OP_SET << 28;
3969+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3970+ //regs->ARM_r0 = old != new;
3971+ //regs->ARM_pc = regs->ARM_lr;
3972+ //return;
3973+ }
3974+ if (pc == 0xffff0fe0UL) {
3975+ /*
3976+ * PaX: __kuser_get_tls emulation
3977+ */
3978+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3979+ regs->ARM_pc = regs->ARM_lr;
3980+ return;
3981+ }
3982+ }
3983+
3984+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3985+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3986+ if (current->signal->curr_ip)
3987+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3988+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3989+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3990+ else
3991+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3992+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3993+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3994+ goto die;
3995+ }
3996+#endif
3997+
3998+#ifdef CONFIG_PAX_REFCOUNT
3999+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4000+ unsigned int bkpt;
4001+
4002+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4003+ current->thread.error_code = ifsr;
4004+ current->thread.trap_no = 0;
4005+ pax_report_refcount_overflow(regs);
4006+ fixup_exception(regs);
4007+ return;
4008+ }
4009+ }
4010+#endif
4011
4012 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4013 return;
4014
4015+die:
4016 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4017 inf->name, ifsr, addr);
4018
4019diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4020index cf08bdf..772656c 100644
4021--- a/arch/arm/mm/fault.h
4022+++ b/arch/arm/mm/fault.h
4023@@ -3,6 +3,7 @@
4024
4025 /*
4026 * Fault status register encodings. We steal bit 31 for our own purposes.
4027+ * Set when the FSR value is from an instruction fault.
4028 */
4029 #define FSR_LNX_PF (1 << 31)
4030 #define FSR_WRITE (1 << 11)
4031@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4032 }
4033 #endif
4034
4035+/* valid for LPAE and !LPAE */
4036+static inline int is_xn_fault(unsigned int fsr)
4037+{
4038+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4039+}
4040+
4041+static inline int is_domain_fault(unsigned int fsr)
4042+{
4043+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4044+}
4045+
4046 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4047 unsigned long search_exception_table(unsigned long addr);
4048
4049diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4050index 18ec4c5..479bb6a 100644
4051--- a/arch/arm/mm/init.c
4052+++ b/arch/arm/mm/init.c
4053@@ -30,6 +30,8 @@
4054 #include <asm/setup.h>
4055 #include <asm/tlb.h>
4056 #include <asm/fixmap.h>
4057+#include <asm/system_info.h>
4058+#include <asm/cp15.h>
4059
4060 #include <asm/mach/arch.h>
4061 #include <asm/mach/map.h>
4062@@ -684,7 +686,46 @@ void free_initmem(void)
4063 {
4064 #ifdef CONFIG_HAVE_TCM
4065 extern char __tcm_start, __tcm_end;
4066+#endif
4067
4068+#ifdef CONFIG_PAX_KERNEXEC
4069+ unsigned long addr;
4070+ pgd_t *pgd;
4071+ pud_t *pud;
4072+ pmd_t *pmd;
4073+ int cpu_arch = cpu_architecture();
4074+ unsigned int cr = get_cr();
4075+
4076+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4077+ /* make pages tables, etc before .text NX */
4078+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4079+ pgd = pgd_offset_k(addr);
4080+ pud = pud_offset(pgd, addr);
4081+ pmd = pmd_offset(pud, addr);
4082+ __section_update(pmd, addr, PMD_SECT_XN);
4083+ }
4084+ /* make init NX */
4085+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4086+ pgd = pgd_offset_k(addr);
4087+ pud = pud_offset(pgd, addr);
4088+ pmd = pmd_offset(pud, addr);
4089+ __section_update(pmd, addr, PMD_SECT_XN);
4090+ }
4091+ /* make kernel code/rodata RX */
4092+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4093+ pgd = pgd_offset_k(addr);
4094+ pud = pud_offset(pgd, addr);
4095+ pmd = pmd_offset(pud, addr);
4096+#ifdef CONFIG_ARM_LPAE
4097+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4098+#else
4099+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4100+#endif
4101+ }
4102+ }
4103+#endif
4104+
4105+#ifdef CONFIG_HAVE_TCM
4106 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4107 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4108 #endif
4109diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4110index f123d6e..04bf569 100644
4111--- a/arch/arm/mm/ioremap.c
4112+++ b/arch/arm/mm/ioremap.c
4113@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4114 unsigned int mtype;
4115
4116 if (cached)
4117- mtype = MT_MEMORY;
4118+ mtype = MT_MEMORY_RX;
4119 else
4120- mtype = MT_MEMORY_NONCACHED;
4121+ mtype = MT_MEMORY_NONCACHED_RX;
4122
4123 return __arm_ioremap_caller(phys_addr, size, mtype,
4124 __builtin_return_address(0));
4125diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4126index 304661d..53a6b19 100644
4127--- a/arch/arm/mm/mmap.c
4128+++ b/arch/arm/mm/mmap.c
4129@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4130 struct vm_area_struct *vma;
4131 int do_align = 0;
4132 int aliasing = cache_is_vipt_aliasing();
4133+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4134 struct vm_unmapped_area_info info;
4135
4136 /*
4137@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4138 if (len > TASK_SIZE)
4139 return -ENOMEM;
4140
4141+#ifdef CONFIG_PAX_RANDMMAP
4142+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4143+#endif
4144+
4145 if (addr) {
4146 if (do_align)
4147 addr = COLOUR_ALIGN(addr, pgoff);
4148@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4149 addr = PAGE_ALIGN(addr);
4150
4151 vma = find_vma(mm, addr);
4152- if (TASK_SIZE - len >= addr &&
4153- (!vma || addr + len <= vma->vm_start))
4154+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4155 return addr;
4156 }
4157
4158@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4159 info.high_limit = TASK_SIZE;
4160 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4161 info.align_offset = pgoff << PAGE_SHIFT;
4162+ info.threadstack_offset = offset;
4163 return vm_unmapped_area(&info);
4164 }
4165
4166@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4167 unsigned long addr = addr0;
4168 int do_align = 0;
4169 int aliasing = cache_is_vipt_aliasing();
4170+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4171 struct vm_unmapped_area_info info;
4172
4173 /*
4174@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4175 return addr;
4176 }
4177
4178+#ifdef CONFIG_PAX_RANDMMAP
4179+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4180+#endif
4181+
4182 /* requesting a specific address */
4183 if (addr) {
4184 if (do_align)
4185@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4186 else
4187 addr = PAGE_ALIGN(addr);
4188 vma = find_vma(mm, addr);
4189- if (TASK_SIZE - len >= addr &&
4190- (!vma || addr + len <= vma->vm_start))
4191+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4192 return addr;
4193 }
4194
4195@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4196 info.high_limit = mm->mmap_base;
4197 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4198 info.align_offset = pgoff << PAGE_SHIFT;
4199+ info.threadstack_offset = offset;
4200 addr = vm_unmapped_area(&info);
4201
4202 /*
4203@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4204 {
4205 unsigned long random_factor = 0UL;
4206
4207+#ifdef CONFIG_PAX_RANDMMAP
4208+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4209+#endif
4210+
4211 /* 8 bits of randomness in 20 address space bits */
4212 if ((current->flags & PF_RANDOMIZE) &&
4213 !(current->personality & ADDR_NO_RANDOMIZE))
4214@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4215
4216 if (mmap_is_legacy()) {
4217 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4218+
4219+#ifdef CONFIG_PAX_RANDMMAP
4220+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4221+ mm->mmap_base += mm->delta_mmap;
4222+#endif
4223+
4224 mm->get_unmapped_area = arch_get_unmapped_area;
4225 } else {
4226 mm->mmap_base = mmap_base(random_factor);
4227+
4228+#ifdef CONFIG_PAX_RANDMMAP
4229+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4230+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4231+#endif
4232+
4233 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4234 }
4235 }
4236diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4237index b1d17ee..7a6f4d3 100644
4238--- a/arch/arm/mm/mmu.c
4239+++ b/arch/arm/mm/mmu.c
4240@@ -36,6 +36,22 @@
4241 #include "mm.h"
4242 #include "tcm.h"
4243
4244+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4245+void modify_domain(unsigned int dom, unsigned int type)
4246+{
4247+ struct thread_info *thread = current_thread_info();
4248+ unsigned int domain = thread->cpu_domain;
4249+ /*
4250+ * DOMAIN_MANAGER might be defined to some other value,
4251+ * use the arch-defined constant
4252+ */
4253+ domain &= ~domain_val(dom, 3);
4254+ thread->cpu_domain = domain | domain_val(dom, type);
4255+ set_domain(thread->cpu_domain);
4256+}
4257+EXPORT_SYMBOL(modify_domain);
4258+#endif
4259+
4260 /*
4261 * empty_zero_page is a special page that is used for
4262 * zero-initialized data and COW.
4263@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4264
4265 #endif /* ifdef CONFIG_CPU_CP15 / else */
4266
4267-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4268+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4269 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4270
4271-static struct mem_type mem_types[] = {
4272+#ifdef CONFIG_PAX_KERNEXEC
4273+#define L_PTE_KERNEXEC L_PTE_RDONLY
4274+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4275+#else
4276+#define L_PTE_KERNEXEC L_PTE_DIRTY
4277+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4278+#endif
4279+
4280+static struct mem_type mem_types[] __read_only = {
4281 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4282 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4283 L_PTE_SHARED,
4284@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4285 [MT_UNCACHED] = {
4286 .prot_pte = PROT_PTE_DEVICE,
4287 .prot_l1 = PMD_TYPE_TABLE,
4288- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4289+ .prot_sect = PROT_SECT_DEVICE,
4290 .domain = DOMAIN_IO,
4291 },
4292 [MT_CACHECLEAN] = {
4293- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4294+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4295 .domain = DOMAIN_KERNEL,
4296 },
4297 #ifndef CONFIG_ARM_LPAE
4298 [MT_MINICLEAN] = {
4299- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4300+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4301 .domain = DOMAIN_KERNEL,
4302 },
4303 #endif
4304@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4305 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4306 L_PTE_RDONLY,
4307 .prot_l1 = PMD_TYPE_TABLE,
4308- .domain = DOMAIN_USER,
4309+ .domain = DOMAIN_VECTORS,
4310 },
4311 [MT_HIGH_VECTORS] = {
4312 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4313 L_PTE_USER | L_PTE_RDONLY,
4314 .prot_l1 = PMD_TYPE_TABLE,
4315- .domain = DOMAIN_USER,
4316+ .domain = DOMAIN_VECTORS,
4317 },
4318- [MT_MEMORY] = {
4319+ [MT_MEMORY_RWX] = {
4320 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4321 .prot_l1 = PMD_TYPE_TABLE,
4322 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4323 .domain = DOMAIN_KERNEL,
4324 },
4325+ [MT_MEMORY_RW] = {
4326+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4327+ .prot_l1 = PMD_TYPE_TABLE,
4328+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4329+ .domain = DOMAIN_KERNEL,
4330+ },
4331+ [MT_MEMORY_RX] = {
4332+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4333+ .prot_l1 = PMD_TYPE_TABLE,
4334+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4335+ .domain = DOMAIN_KERNEL,
4336+ },
4337 [MT_ROM] = {
4338- .prot_sect = PMD_TYPE_SECT,
4339+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4340 .domain = DOMAIN_KERNEL,
4341 },
4342- [MT_MEMORY_NONCACHED] = {
4343+ [MT_MEMORY_NONCACHED_RW] = {
4344 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4345 L_PTE_MT_BUFFERABLE,
4346 .prot_l1 = PMD_TYPE_TABLE,
4347 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4348 .domain = DOMAIN_KERNEL,
4349 },
4350+ [MT_MEMORY_NONCACHED_RX] = {
4351+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4352+ L_PTE_MT_BUFFERABLE,
4353+ .prot_l1 = PMD_TYPE_TABLE,
4354+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4355+ .domain = DOMAIN_KERNEL,
4356+ },
4357 [MT_MEMORY_DTCM] = {
4358- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4359- L_PTE_XN,
4360+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4361 .prot_l1 = PMD_TYPE_TABLE,
4362- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4363+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4364 .domain = DOMAIN_KERNEL,
4365 },
4366 [MT_MEMORY_ITCM] = {
4367@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4368 },
4369 [MT_MEMORY_SO] = {
4370 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4371- L_PTE_MT_UNCACHED | L_PTE_XN,
4372+ L_PTE_MT_UNCACHED,
4373 .prot_l1 = PMD_TYPE_TABLE,
4374 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4375- PMD_SECT_UNCACHED | PMD_SECT_XN,
4376+ PMD_SECT_UNCACHED,
4377 .domain = DOMAIN_KERNEL,
4378 },
4379 [MT_MEMORY_DMA_READY] = {
4380@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4381 * to prevent speculative instruction fetches.
4382 */
4383 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4384+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4385 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4386+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4387 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4388+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4389 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4390+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4391+
4392+ /* Mark other regions on ARMv6+ as execute-never */
4393+
4394+#ifdef CONFIG_PAX_KERNEXEC
4395+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4396+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4397+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4398+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4399+#ifndef CONFIG_ARM_LPAE
4400+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4401+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4402+#endif
4403+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4404+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4405+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4406+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4407+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4408+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4409+#endif
4410+
4411+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4412+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4413 }
4414 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4415 /*
4416@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4417 * from SVC mode and no access from userspace.
4418 */
4419 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4420+#ifdef CONFIG_PAX_KERNEXEC
4421+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4422+#endif
4423 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4424 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4425 #endif
4426@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4427 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4428 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4429 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4430- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4431- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4432+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4433+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4434+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4435+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4436+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4437+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4438 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4439- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4440- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4441+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4442+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4443+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4444+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4445 }
4446 }
4447
4448@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4449 if (cpu_arch >= CPU_ARCH_ARMv6) {
4450 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4451 /* Non-cacheable Normal is XCB = 001 */
4452- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4453+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4454+ PMD_SECT_BUFFERED;
4455+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4456 PMD_SECT_BUFFERED;
4457 } else {
4458 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4459- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4460+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4461+ PMD_SECT_TEX(1);
4462+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4463 PMD_SECT_TEX(1);
4464 }
4465 } else {
4466- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4467+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4468+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4469 }
4470
4471 #ifdef CONFIG_ARM_LPAE
4472@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4473 vecs_pgprot |= PTE_EXT_AF;
4474 #endif
4475
4476+ user_pgprot |= __supported_pte_mask;
4477+
4478 for (i = 0; i < 16; i++) {
4479 pteval_t v = pgprot_val(protection_map[i]);
4480 protection_map[i] = __pgprot(v | user_pgprot);
4481@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4482
4483 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4484 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4485- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4486- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4487+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4488+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4489+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4490+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4491+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4492+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4493 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4494- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4495+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4496+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4497 mem_types[MT_ROM].prot_sect |= cp->pmd;
4498
4499 switch (cp->pmd) {
4500@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4501 * called function. This means you can't use any function or debugging
4502 * method which may touch any device, otherwise the kernel _will_ crash.
4503 */
4504+
4505+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4506+
4507 static void __init devicemaps_init(const struct machine_desc *mdesc)
4508 {
4509 struct map_desc map;
4510 unsigned long addr;
4511- void *vectors;
4512
4513- /*
4514- * Allocate the vector page early.
4515- */
4516- vectors = early_alloc(PAGE_SIZE * 2);
4517-
4518- early_trap_init(vectors);
4519+ early_trap_init(&vectors);
4520
4521 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4522 pmd_clear(pmd_off_k(addr));
4523@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4524 * location (0xffff0000). If we aren't using high-vectors, also
4525 * create a mapping at the low-vectors virtual address.
4526 */
4527- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4528+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4529 map.virtual = 0xffff0000;
4530 map.length = PAGE_SIZE;
4531 #ifdef CONFIG_KUSER_HELPERS
4532@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4533 map.pfn = __phys_to_pfn(start);
4534 map.virtual = __phys_to_virt(start);
4535 map.length = end - start;
4536- map.type = MT_MEMORY;
4537
4538+#ifdef CONFIG_PAX_KERNEXEC
4539+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4540+ struct map_desc kernel;
4541+ struct map_desc initmap;
4542+
4543+ /* when freeing initmem we will make this RW */
4544+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4545+ initmap.virtual = (unsigned long)__init_begin;
4546+ initmap.length = _sdata - __init_begin;
4547+ initmap.type = MT_MEMORY_RWX;
4548+ create_mapping(&initmap);
4549+
4550+ /* when freeing initmem we will make this RX */
4551+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4552+ kernel.virtual = (unsigned long)_stext;
4553+ kernel.length = __init_begin - _stext;
4554+ kernel.type = MT_MEMORY_RWX;
4555+ create_mapping(&kernel);
4556+
4557+ if (map.virtual < (unsigned long)_stext) {
4558+ map.length = (unsigned long)_stext - map.virtual;
4559+ map.type = MT_MEMORY_RWX;
4560+ create_mapping(&map);
4561+ }
4562+
4563+ map.pfn = __phys_to_pfn(__pa(_sdata));
4564+ map.virtual = (unsigned long)_sdata;
4565+ map.length = end - __pa(_sdata);
4566+ }
4567+#endif
4568+
4569+ map.type = MT_MEMORY_RW;
4570 create_mapping(&map);
4571 }
4572 }
4573diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4574index a5bc92d..0bb4730 100644
4575--- a/arch/arm/plat-omap/sram.c
4576+++ b/arch/arm/plat-omap/sram.c
4577@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4578 * Looks like we need to preserve some bootloader code at the
4579 * beginning of SRAM for jumping to flash for reboot to work...
4580 */
4581+ pax_open_kernel();
4582 memset_io(omap_sram_base + omap_sram_skip, 0,
4583 omap_sram_size - omap_sram_skip);
4584+ pax_close_kernel();
4585 }
4586diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4587index ce6d763..cfea917 100644
4588--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4589+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4590@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4591 int (*started)(unsigned ch);
4592 int (*flush)(unsigned ch);
4593 int (*stop)(unsigned ch);
4594-};
4595+} __no_const;
4596
4597 extern void *samsung_dmadev_get_ops(void);
4598 extern void *s3c_dma_get_ops(void);
4599diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4600index c3a58a1..78fbf54 100644
4601--- a/arch/avr32/include/asm/cache.h
4602+++ b/arch/avr32/include/asm/cache.h
4603@@ -1,8 +1,10 @@
4604 #ifndef __ASM_AVR32_CACHE_H
4605 #define __ASM_AVR32_CACHE_H
4606
4607+#include <linux/const.h>
4608+
4609 #define L1_CACHE_SHIFT 5
4610-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4611+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4612
4613 /*
4614 * Memory returned by kmalloc() may be used for DMA, so we must make
4615diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4616index d232888..87c8df1 100644
4617--- a/arch/avr32/include/asm/elf.h
4618+++ b/arch/avr32/include/asm/elf.h
4619@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4620 the loader. We need to make sure that it is out of the way of the program
4621 that it will "exec", and that there is sufficient room for the brk. */
4622
4623-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4624+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4625
4626+#ifdef CONFIG_PAX_ASLR
4627+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4628+
4629+#define PAX_DELTA_MMAP_LEN 15
4630+#define PAX_DELTA_STACK_LEN 15
4631+#endif
4632
4633 /* This yields a mask that user programs can use to figure out what
4634 instruction set this CPU supports. This could be done in user space,
4635diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4636index 479330b..53717a8 100644
4637--- a/arch/avr32/include/asm/kmap_types.h
4638+++ b/arch/avr32/include/asm/kmap_types.h
4639@@ -2,9 +2,9 @@
4640 #define __ASM_AVR32_KMAP_TYPES_H
4641
4642 #ifdef CONFIG_DEBUG_HIGHMEM
4643-# define KM_TYPE_NR 29
4644+# define KM_TYPE_NR 30
4645 #else
4646-# define KM_TYPE_NR 14
4647+# define KM_TYPE_NR 15
4648 #endif
4649
4650 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4651diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4652index 0eca933..eb78c7b 100644
4653--- a/arch/avr32/mm/fault.c
4654+++ b/arch/avr32/mm/fault.c
4655@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4656
4657 int exception_trace = 1;
4658
4659+#ifdef CONFIG_PAX_PAGEEXEC
4660+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4661+{
4662+ unsigned long i;
4663+
4664+ printk(KERN_ERR "PAX: bytes at PC: ");
4665+ for (i = 0; i < 20; i++) {
4666+ unsigned char c;
4667+ if (get_user(c, (unsigned char *)pc+i))
4668+ printk(KERN_CONT "???????? ");
4669+ else
4670+ printk(KERN_CONT "%02x ", c);
4671+ }
4672+ printk("\n");
4673+}
4674+#endif
4675+
4676 /*
4677 * This routine handles page faults. It determines the address and the
4678 * problem, and then passes it off to one of the appropriate routines.
4679@@ -176,6 +193,16 @@ bad_area:
4680 up_read(&mm->mmap_sem);
4681
4682 if (user_mode(regs)) {
4683+
4684+#ifdef CONFIG_PAX_PAGEEXEC
4685+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4686+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4687+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4688+ do_group_exit(SIGKILL);
4689+ }
4690+ }
4691+#endif
4692+
4693 if (exception_trace && printk_ratelimit())
4694 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4695 "sp %08lx ecr %lu\n",
4696diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4697index 568885a..f8008df 100644
4698--- a/arch/blackfin/include/asm/cache.h
4699+++ b/arch/blackfin/include/asm/cache.h
4700@@ -7,6 +7,7 @@
4701 #ifndef __ARCH_BLACKFIN_CACHE_H
4702 #define __ARCH_BLACKFIN_CACHE_H
4703
4704+#include <linux/const.h>
4705 #include <linux/linkage.h> /* for asmlinkage */
4706
4707 /*
4708@@ -14,7 +15,7 @@
4709 * Blackfin loads 32 bytes for cache
4710 */
4711 #define L1_CACHE_SHIFT 5
4712-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4713+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4715
4716 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4717diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4718index aea2718..3639a60 100644
4719--- a/arch/cris/include/arch-v10/arch/cache.h
4720+++ b/arch/cris/include/arch-v10/arch/cache.h
4721@@ -1,8 +1,9 @@
4722 #ifndef _ASM_ARCH_CACHE_H
4723 #define _ASM_ARCH_CACHE_H
4724
4725+#include <linux/const.h>
4726 /* Etrax 100LX have 32-byte cache-lines. */
4727-#define L1_CACHE_BYTES 32
4728 #define L1_CACHE_SHIFT 5
4729+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4730
4731 #endif /* _ASM_ARCH_CACHE_H */
4732diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4733index 7caf25d..ee65ac5 100644
4734--- a/arch/cris/include/arch-v32/arch/cache.h
4735+++ b/arch/cris/include/arch-v32/arch/cache.h
4736@@ -1,11 +1,12 @@
4737 #ifndef _ASM_CRIS_ARCH_CACHE_H
4738 #define _ASM_CRIS_ARCH_CACHE_H
4739
4740+#include <linux/const.h>
4741 #include <arch/hwregs/dma.h>
4742
4743 /* A cache-line is 32 bytes. */
4744-#define L1_CACHE_BYTES 32
4745 #define L1_CACHE_SHIFT 5
4746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4747
4748 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4749
4750diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4751index b86329d..6709906 100644
4752--- a/arch/frv/include/asm/atomic.h
4753+++ b/arch/frv/include/asm/atomic.h
4754@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4755 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4756 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4757
4758+#define atomic64_read_unchecked(v) atomic64_read(v)
4759+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4760+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4761+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4762+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4763+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4764+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4765+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4766+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4767+
4768 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4769 {
4770 int c, old;
4771diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4772index 2797163..c2a401d 100644
4773--- a/arch/frv/include/asm/cache.h
4774+++ b/arch/frv/include/asm/cache.h
4775@@ -12,10 +12,11 @@
4776 #ifndef __ASM_CACHE_H
4777 #define __ASM_CACHE_H
4778
4779+#include <linux/const.h>
4780
4781 /* bytes per L1 cache line */
4782 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4783-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4784+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4785
4786 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4787 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4788diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4789index 43901f2..0d8b865 100644
4790--- a/arch/frv/include/asm/kmap_types.h
4791+++ b/arch/frv/include/asm/kmap_types.h
4792@@ -2,6 +2,6 @@
4793 #ifndef _ASM_KMAP_TYPES_H
4794 #define _ASM_KMAP_TYPES_H
4795
4796-#define KM_TYPE_NR 17
4797+#define KM_TYPE_NR 18
4798
4799 #endif
4800diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4801index 836f147..4cf23f5 100644
4802--- a/arch/frv/mm/elf-fdpic.c
4803+++ b/arch/frv/mm/elf-fdpic.c
4804@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4805 {
4806 struct vm_area_struct *vma;
4807 struct vm_unmapped_area_info info;
4808+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4809
4810 if (len > TASK_SIZE)
4811 return -ENOMEM;
4812@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4813 if (addr) {
4814 addr = PAGE_ALIGN(addr);
4815 vma = find_vma(current->mm, addr);
4816- if (TASK_SIZE - len >= addr &&
4817- (!vma || addr + len <= vma->vm_start))
4818+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4819 goto success;
4820 }
4821
4822@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4823 info.high_limit = (current->mm->start_stack - 0x00200000);
4824 info.align_mask = 0;
4825 info.align_offset = 0;
4826+ info.threadstack_offset = offset;
4827 addr = vm_unmapped_area(&info);
4828 if (!(addr & ~PAGE_MASK))
4829 goto success;
4830diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4831index f4ca594..adc72fd6 100644
4832--- a/arch/hexagon/include/asm/cache.h
4833+++ b/arch/hexagon/include/asm/cache.h
4834@@ -21,9 +21,11 @@
4835 #ifndef __ASM_CACHE_H
4836 #define __ASM_CACHE_H
4837
4838+#include <linux/const.h>
4839+
4840 /* Bytes per L1 cache line */
4841-#define L1_CACHE_SHIFT (5)
4842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4843+#define L1_CACHE_SHIFT 5
4844+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4845
4846 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4847 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4848diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4849index 7740ab1..17fa8c5 100644
4850--- a/arch/ia64/Kconfig
4851+++ b/arch/ia64/Kconfig
4852@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4853 config KEXEC
4854 bool "kexec system call"
4855 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4856+ depends on !GRKERNSEC_KMEM
4857 help
4858 kexec is a system call that implements the ability to shutdown your
4859 current kernel, and to start another kernel. It is like a reboot
4860diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4861index 6e6fe18..a6ae668 100644
4862--- a/arch/ia64/include/asm/atomic.h
4863+++ b/arch/ia64/include/asm/atomic.h
4864@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4865 #define atomic64_inc(v) atomic64_add(1, (v))
4866 #define atomic64_dec(v) atomic64_sub(1, (v))
4867
4868+#define atomic64_read_unchecked(v) atomic64_read(v)
4869+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4870+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4871+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4872+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4873+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4874+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4875+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4876+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4877+
4878 /* Atomic operations are already serializing */
4879 #define smp_mb__before_atomic_dec() barrier()
4880 #define smp_mb__after_atomic_dec() barrier()
4881diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4882index 988254a..e1ee885 100644
4883--- a/arch/ia64/include/asm/cache.h
4884+++ b/arch/ia64/include/asm/cache.h
4885@@ -1,6 +1,7 @@
4886 #ifndef _ASM_IA64_CACHE_H
4887 #define _ASM_IA64_CACHE_H
4888
4889+#include <linux/const.h>
4890
4891 /*
4892 * Copyright (C) 1998-2000 Hewlett-Packard Co
4893@@ -9,7 +10,7 @@
4894
4895 /* Bytes per L1 (data) cache line. */
4896 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4897-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4898+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4899
4900 #ifdef CONFIG_SMP
4901 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4902diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4903index 5a83c5c..4d7f553 100644
4904--- a/arch/ia64/include/asm/elf.h
4905+++ b/arch/ia64/include/asm/elf.h
4906@@ -42,6 +42,13 @@
4907 */
4908 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4909
4910+#ifdef CONFIG_PAX_ASLR
4911+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4912+
4913+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4914+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4915+#endif
4916+
4917 #define PT_IA_64_UNWIND 0x70000001
4918
4919 /* IA-64 relocations: */
4920diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4921index 96a8d92..617a1cf 100644
4922--- a/arch/ia64/include/asm/pgalloc.h
4923+++ b/arch/ia64/include/asm/pgalloc.h
4924@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4925 pgd_val(*pgd_entry) = __pa(pud);
4926 }
4927
4928+static inline void
4929+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4930+{
4931+ pgd_populate(mm, pgd_entry, pud);
4932+}
4933+
4934 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4935 {
4936 return quicklist_alloc(0, GFP_KERNEL, NULL);
4937@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4938 pud_val(*pud_entry) = __pa(pmd);
4939 }
4940
4941+static inline void
4942+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4943+{
4944+ pud_populate(mm, pud_entry, pmd);
4945+}
4946+
4947 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4948 {
4949 return quicklist_alloc(0, GFP_KERNEL, NULL);
4950diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4951index 7935115..c0eca6a 100644
4952--- a/arch/ia64/include/asm/pgtable.h
4953+++ b/arch/ia64/include/asm/pgtable.h
4954@@ -12,7 +12,7 @@
4955 * David Mosberger-Tang <davidm@hpl.hp.com>
4956 */
4957
4958-
4959+#include <linux/const.h>
4960 #include <asm/mman.h>
4961 #include <asm/page.h>
4962 #include <asm/processor.h>
4963@@ -142,6 +142,17 @@
4964 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4965 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4966 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4967+
4968+#ifdef CONFIG_PAX_PAGEEXEC
4969+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4970+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4971+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4972+#else
4973+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4974+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4975+# define PAGE_COPY_NOEXEC PAGE_COPY
4976+#endif
4977+
4978 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4979 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4980 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4981diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4982index 45698cd..e8e2dbc 100644
4983--- a/arch/ia64/include/asm/spinlock.h
4984+++ b/arch/ia64/include/asm/spinlock.h
4985@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4986 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4987
4988 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4989- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4990+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4991 }
4992
4993 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4994diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4995index 449c8c0..18965fb 100644
4996--- a/arch/ia64/include/asm/uaccess.h
4997+++ b/arch/ia64/include/asm/uaccess.h
4998@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4999 static inline unsigned long
5000 __copy_to_user (void __user *to, const void *from, unsigned long count)
5001 {
5002+ if (count > INT_MAX)
5003+ return count;
5004+
5005+ if (!__builtin_constant_p(count))
5006+ check_object_size(from, count, true);
5007+
5008 return __copy_user(to, (__force void __user *) from, count);
5009 }
5010
5011 static inline unsigned long
5012 __copy_from_user (void *to, const void __user *from, unsigned long count)
5013 {
5014+ if (count > INT_MAX)
5015+ return count;
5016+
5017+ if (!__builtin_constant_p(count))
5018+ check_object_size(to, count, false);
5019+
5020 return __copy_user((__force void __user *) to, from, count);
5021 }
5022
5023@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5024 ({ \
5025 void __user *__cu_to = (to); \
5026 const void *__cu_from = (from); \
5027- long __cu_len = (n); \
5028+ unsigned long __cu_len = (n); \
5029 \
5030- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5031+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5032+ if (!__builtin_constant_p(n)) \
5033+ check_object_size(__cu_from, __cu_len, true); \
5034 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5035+ } \
5036 __cu_len; \
5037 })
5038
5039@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5040 ({ \
5041 void *__cu_to = (to); \
5042 const void __user *__cu_from = (from); \
5043- long __cu_len = (n); \
5044+ unsigned long __cu_len = (n); \
5045 \
5046 __chk_user_ptr(__cu_from); \
5047- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5048+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5049+ if (!__builtin_constant_p(n)) \
5050+ check_object_size(__cu_to, __cu_len, false); \
5051 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5052+ } \
5053 __cu_len; \
5054 })
5055
5056diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5057index 24603be..948052d 100644
5058--- a/arch/ia64/kernel/module.c
5059+++ b/arch/ia64/kernel/module.c
5060@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5061 void
5062 module_free (struct module *mod, void *module_region)
5063 {
5064- if (mod && mod->arch.init_unw_table &&
5065- module_region == mod->module_init) {
5066+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5067 unw_remove_unwind_table(mod->arch.init_unw_table);
5068 mod->arch.init_unw_table = NULL;
5069 }
5070@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5071 }
5072
5073 static inline int
5074+in_init_rx (const struct module *mod, uint64_t addr)
5075+{
5076+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5077+}
5078+
5079+static inline int
5080+in_init_rw (const struct module *mod, uint64_t addr)
5081+{
5082+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5083+}
5084+
5085+static inline int
5086 in_init (const struct module *mod, uint64_t addr)
5087 {
5088- return addr - (uint64_t) mod->module_init < mod->init_size;
5089+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5090+}
5091+
5092+static inline int
5093+in_core_rx (const struct module *mod, uint64_t addr)
5094+{
5095+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5096+}
5097+
5098+static inline int
5099+in_core_rw (const struct module *mod, uint64_t addr)
5100+{
5101+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5102 }
5103
5104 static inline int
5105 in_core (const struct module *mod, uint64_t addr)
5106 {
5107- return addr - (uint64_t) mod->module_core < mod->core_size;
5108+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5109 }
5110
5111 static inline int
5112@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5113 break;
5114
5115 case RV_BDREL:
5116- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5117+ if (in_init_rx(mod, val))
5118+ val -= (uint64_t) mod->module_init_rx;
5119+ else if (in_init_rw(mod, val))
5120+ val -= (uint64_t) mod->module_init_rw;
5121+ else if (in_core_rx(mod, val))
5122+ val -= (uint64_t) mod->module_core_rx;
5123+ else if (in_core_rw(mod, val))
5124+ val -= (uint64_t) mod->module_core_rw;
5125 break;
5126
5127 case RV_LTV:
5128@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5129 * addresses have been selected...
5130 */
5131 uint64_t gp;
5132- if (mod->core_size > MAX_LTOFF)
5133+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5134 /*
5135 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5136 * at the end of the module.
5137 */
5138- gp = mod->core_size - MAX_LTOFF / 2;
5139+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5140 else
5141- gp = mod->core_size / 2;
5142- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5143+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5144+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5145 mod->arch.gp = gp;
5146 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5147 }
5148diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5149index ab33328..f39506c 100644
5150--- a/arch/ia64/kernel/palinfo.c
5151+++ b/arch/ia64/kernel/palinfo.c
5152@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5153 return NOTIFY_OK;
5154 }
5155
5156-static struct notifier_block __refdata palinfo_cpu_notifier =
5157+static struct notifier_block palinfo_cpu_notifier =
5158 {
5159 .notifier_call = palinfo_cpu_callback,
5160 .priority = 0,
5161diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5162index 41e33f8..65180b2a 100644
5163--- a/arch/ia64/kernel/sys_ia64.c
5164+++ b/arch/ia64/kernel/sys_ia64.c
5165@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5166 unsigned long align_mask = 0;
5167 struct mm_struct *mm = current->mm;
5168 struct vm_unmapped_area_info info;
5169+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5170
5171 if (len > RGN_MAP_LIMIT)
5172 return -ENOMEM;
5173@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5174 if (REGION_NUMBER(addr) == RGN_HPAGE)
5175 addr = 0;
5176 #endif
5177+
5178+#ifdef CONFIG_PAX_RANDMMAP
5179+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5180+ addr = mm->free_area_cache;
5181+ else
5182+#endif
5183+
5184 if (!addr)
5185 addr = TASK_UNMAPPED_BASE;
5186
5187@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5188 info.high_limit = TASK_SIZE;
5189 info.align_mask = align_mask;
5190 info.align_offset = 0;
5191+ info.threadstack_offset = offset;
5192 return vm_unmapped_area(&info);
5193 }
5194
5195diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5196index 0ccb28f..8992469 100644
5197--- a/arch/ia64/kernel/vmlinux.lds.S
5198+++ b/arch/ia64/kernel/vmlinux.lds.S
5199@@ -198,7 +198,7 @@ SECTIONS {
5200 /* Per-cpu data: */
5201 . = ALIGN(PERCPU_PAGE_SIZE);
5202 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5203- __phys_per_cpu_start = __per_cpu_load;
5204+ __phys_per_cpu_start = per_cpu_load;
5205 /*
5206 * ensure percpu data fits
5207 * into percpu page size
5208diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5209index 7225dad..2a7c8256 100644
5210--- a/arch/ia64/mm/fault.c
5211+++ b/arch/ia64/mm/fault.c
5212@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5213 return pte_present(pte);
5214 }
5215
5216+#ifdef CONFIG_PAX_PAGEEXEC
5217+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5218+{
5219+ unsigned long i;
5220+
5221+ printk(KERN_ERR "PAX: bytes at PC: ");
5222+ for (i = 0; i < 8; i++) {
5223+ unsigned int c;
5224+ if (get_user(c, (unsigned int *)pc+i))
5225+ printk(KERN_CONT "???????? ");
5226+ else
5227+ printk(KERN_CONT "%08x ", c);
5228+ }
5229+ printk("\n");
5230+}
5231+#endif
5232+
5233 # define VM_READ_BIT 0
5234 # define VM_WRITE_BIT 1
5235 # define VM_EXEC_BIT 2
5236@@ -151,8 +168,21 @@ retry:
5237 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5238 goto bad_area;
5239
5240- if ((vma->vm_flags & mask) != mask)
5241+ if ((vma->vm_flags & mask) != mask) {
5242+
5243+#ifdef CONFIG_PAX_PAGEEXEC
5244+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5245+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5246+ goto bad_area;
5247+
5248+ up_read(&mm->mmap_sem);
5249+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5250+ do_group_exit(SIGKILL);
5251+ }
5252+#endif
5253+
5254 goto bad_area;
5255+ }
5256
5257 /*
5258 * If for any reason at all we couldn't handle the fault, make
5259diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5260index 68232db..6ca80af 100644
5261--- a/arch/ia64/mm/hugetlbpage.c
5262+++ b/arch/ia64/mm/hugetlbpage.c
5263@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5264 unsigned long pgoff, unsigned long flags)
5265 {
5266 struct vm_unmapped_area_info info;
5267+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5268
5269 if (len > RGN_MAP_LIMIT)
5270 return -ENOMEM;
5271@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5272 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5273 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5274 info.align_offset = 0;
5275+ info.threadstack_offset = offset;
5276 return vm_unmapped_area(&info);
5277 }
5278
5279diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5280index b6f7f43..c04320d 100644
5281--- a/arch/ia64/mm/init.c
5282+++ b/arch/ia64/mm/init.c
5283@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5284 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5285 vma->vm_end = vma->vm_start + PAGE_SIZE;
5286 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5287+
5288+#ifdef CONFIG_PAX_PAGEEXEC
5289+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5290+ vma->vm_flags &= ~VM_EXEC;
5291+
5292+#ifdef CONFIG_PAX_MPROTECT
5293+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5294+ vma->vm_flags &= ~VM_MAYEXEC;
5295+#endif
5296+
5297+ }
5298+#endif
5299+
5300 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5301 down_write(&current->mm->mmap_sem);
5302 if (insert_vm_struct(current->mm, vma)) {
5303diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5304index 40b3ee9..8c2c112 100644
5305--- a/arch/m32r/include/asm/cache.h
5306+++ b/arch/m32r/include/asm/cache.h
5307@@ -1,8 +1,10 @@
5308 #ifndef _ASM_M32R_CACHE_H
5309 #define _ASM_M32R_CACHE_H
5310
5311+#include <linux/const.h>
5312+
5313 /* L1 cache line size */
5314 #define L1_CACHE_SHIFT 4
5315-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5316+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5317
5318 #endif /* _ASM_M32R_CACHE_H */
5319diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5320index 82abd15..d95ae5d 100644
5321--- a/arch/m32r/lib/usercopy.c
5322+++ b/arch/m32r/lib/usercopy.c
5323@@ -14,6 +14,9 @@
5324 unsigned long
5325 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5326 {
5327+ if ((long)n < 0)
5328+ return n;
5329+
5330 prefetch(from);
5331 if (access_ok(VERIFY_WRITE, to, n))
5332 __copy_user(to,from,n);
5333@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5334 unsigned long
5335 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5336 {
5337+ if ((long)n < 0)
5338+ return n;
5339+
5340 prefetchw(to);
5341 if (access_ok(VERIFY_READ, from, n))
5342 __copy_user_zeroing(to,from,n);
5343diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5344index 0395c51..5f26031 100644
5345--- a/arch/m68k/include/asm/cache.h
5346+++ b/arch/m68k/include/asm/cache.h
5347@@ -4,9 +4,11 @@
5348 #ifndef __ARCH_M68K_CACHE_H
5349 #define __ARCH_M68K_CACHE_H
5350
5351+#include <linux/const.h>
5352+
5353 /* bytes per L1 cache line */
5354 #define L1_CACHE_SHIFT 4
5355-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5356+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5357
5358 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5359
5360diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5361index 0424315..defcca9 100644
5362--- a/arch/metag/mm/hugetlbpage.c
5363+++ b/arch/metag/mm/hugetlbpage.c
5364@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5365 info.high_limit = TASK_SIZE;
5366 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5367 info.align_offset = 0;
5368+ info.threadstack_offset = 0;
5369 return vm_unmapped_area(&info);
5370 }
5371
5372diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5373index 4efe96a..60e8699 100644
5374--- a/arch/microblaze/include/asm/cache.h
5375+++ b/arch/microblaze/include/asm/cache.h
5376@@ -13,11 +13,12 @@
5377 #ifndef _ASM_MICROBLAZE_CACHE_H
5378 #define _ASM_MICROBLAZE_CACHE_H
5379
5380+#include <linux/const.h>
5381 #include <asm/registers.h>
5382
5383 #define L1_CACHE_SHIFT 5
5384 /* word-granular cache in microblaze */
5385-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5386+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5387
5388 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5389
5390diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5391index f75ab4a..adc6968 100644
5392--- a/arch/mips/Kconfig
5393+++ b/arch/mips/Kconfig
5394@@ -2283,6 +2283,7 @@ source "kernel/Kconfig.preempt"
5395
5396 config KEXEC
5397 bool "Kexec system call"
5398+ depends on !GRKERNSEC_KMEM
5399 help
5400 kexec is a system call that implements the ability to shutdown your
5401 current kernel, and to start another kernel. It is like a reboot
5402diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5403index 08b6079..8b554d2 100644
5404--- a/arch/mips/include/asm/atomic.h
5405+++ b/arch/mips/include/asm/atomic.h
5406@@ -21,15 +21,39 @@
5407 #include <asm/cmpxchg.h>
5408 #include <asm/war.h>
5409
5410+#ifdef CONFIG_GENERIC_ATOMIC64
5411+#include <asm-generic/atomic64.h>
5412+#endif
5413+
5414 #define ATOMIC_INIT(i) { (i) }
5415
5416+#ifdef CONFIG_64BIT
5417+#define _ASM_EXTABLE(from, to) \
5418+" .section __ex_table,\"a\"\n" \
5419+" .dword " #from ", " #to"\n" \
5420+" .previous\n"
5421+#else
5422+#define _ASM_EXTABLE(from, to) \
5423+" .section __ex_table,\"a\"\n" \
5424+" .word " #from ", " #to"\n" \
5425+" .previous\n"
5426+#endif
5427+
5428 /*
5429 * atomic_read - read atomic variable
5430 * @v: pointer of type atomic_t
5431 *
5432 * Atomically reads the value of @v.
5433 */
5434-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5435+static inline int atomic_read(const atomic_t *v)
5436+{
5437+ return (*(volatile const int *) &v->counter);
5438+}
5439+
5440+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5441+{
5442+ return (*(volatile const int *) &v->counter);
5443+}
5444
5445 /*
5446 * atomic_set - set atomic variable
5447@@ -38,7 +62,15 @@
5448 *
5449 * Atomically sets the value of @v to @i.
5450 */
5451-#define atomic_set(v, i) ((v)->counter = (i))
5452+static inline void atomic_set(atomic_t *v, int i)
5453+{
5454+ v->counter = i;
5455+}
5456+
5457+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5458+{
5459+ v->counter = i;
5460+}
5461
5462 /*
5463 * atomic_add - add integer to atomic variable
5464@@ -47,7 +79,67 @@
5465 *
5466 * Atomically adds @i to @v.
5467 */
5468-static __inline__ void atomic_add(int i, atomic_t * v)
5469+static __inline__ void atomic_add(int i, atomic_t *v)
5470+{
5471+ int temp;
5472+
5473+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5474+ __asm__ __volatile__(
5475+ " .set mips3 \n"
5476+ "1: ll %0, %1 # atomic_add \n"
5477+#ifdef CONFIG_PAX_REFCOUNT
5478+ /* Exception on overflow. */
5479+ "2: add %0, %2 \n"
5480+#else
5481+ " addu %0, %2 \n"
5482+#endif
5483+ " sc %0, %1 \n"
5484+ " beqzl %0, 1b \n"
5485+#ifdef CONFIG_PAX_REFCOUNT
5486+ "3: \n"
5487+ _ASM_EXTABLE(2b, 3b)
5488+#endif
5489+ " .set mips0 \n"
5490+ : "=&r" (temp), "+m" (v->counter)
5491+ : "Ir" (i));
5492+ } else if (kernel_uses_llsc) {
5493+ __asm__ __volatile__(
5494+ " .set mips3 \n"
5495+ "1: ll %0, %1 # atomic_add \n"
5496+#ifdef CONFIG_PAX_REFCOUNT
5497+ /* Exception on overflow. */
5498+ "2: add %0, %2 \n"
5499+#else
5500+ " addu %0, %2 \n"
5501+#endif
5502+ " sc %0, %1 \n"
5503+ " beqz %0, 1b \n"
5504+#ifdef CONFIG_PAX_REFCOUNT
5505+ "3: \n"
5506+ _ASM_EXTABLE(2b, 3b)
5507+#endif
5508+ " .set mips0 \n"
5509+ : "=&r" (temp), "+m" (v->counter)
5510+ : "Ir" (i));
5511+ } else {
5512+ unsigned long flags;
5513+
5514+ raw_local_irq_save(flags);
5515+ __asm__ __volatile__(
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+ /* Exception on overflow. */
5518+ "1: add %0, %1 \n"
5519+ "2: \n"
5520+ _ASM_EXTABLE(1b, 2b)
5521+#else
5522+ " addu %0, %1 \n"
5523+#endif
5524+ : "+r" (v->counter) : "Ir" (i));
5525+ raw_local_irq_restore(flags);
5526+ }
5527+}
5528+
5529+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5530 {
5531 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5532 int temp;
5533@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5534 *
5535 * Atomically subtracts @i from @v.
5536 */
5537-static __inline__ void atomic_sub(int i, atomic_t * v)
5538+static __inline__ void atomic_sub(int i, atomic_t *v)
5539+{
5540+ int temp;
5541+
5542+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5543+ __asm__ __volatile__(
5544+ " .set mips3 \n"
5545+ "1: ll %0, %1 # atomic64_sub \n"
5546+#ifdef CONFIG_PAX_REFCOUNT
5547+ /* Exception on overflow. */
5548+ "2: sub %0, %2 \n"
5549+#else
5550+ " subu %0, %2 \n"
5551+#endif
5552+ " sc %0, %1 \n"
5553+ " beqzl %0, 1b \n"
5554+#ifdef CONFIG_PAX_REFCOUNT
5555+ "3: \n"
5556+ _ASM_EXTABLE(2b, 3b)
5557+#endif
5558+ " .set mips0 \n"
5559+ : "=&r" (temp), "+m" (v->counter)
5560+ : "Ir" (i));
5561+ } else if (kernel_uses_llsc) {
5562+ __asm__ __volatile__(
5563+ " .set mips3 \n"
5564+ "1: ll %0, %1 # atomic64_sub \n"
5565+#ifdef CONFIG_PAX_REFCOUNT
5566+ /* Exception on overflow. */
5567+ "2: sub %0, %2 \n"
5568+#else
5569+ " subu %0, %2 \n"
5570+#endif
5571+ " sc %0, %1 \n"
5572+ " beqz %0, 1b \n"
5573+#ifdef CONFIG_PAX_REFCOUNT
5574+ "3: \n"
5575+ _ASM_EXTABLE(2b, 3b)
5576+#endif
5577+ " .set mips0 \n"
5578+ : "=&r" (temp), "+m" (v->counter)
5579+ : "Ir" (i));
5580+ } else {
5581+ unsigned long flags;
5582+
5583+ raw_local_irq_save(flags);
5584+ __asm__ __volatile__(
5585+#ifdef CONFIG_PAX_REFCOUNT
5586+ /* Exception on overflow. */
5587+ "1: sub %0, %1 \n"
5588+ "2: \n"
5589+ _ASM_EXTABLE(1b, 2b)
5590+#else
5591+ " subu %0, %1 \n"
5592+#endif
5593+ : "+r" (v->counter) : "Ir" (i));
5594+ raw_local_irq_restore(flags);
5595+ }
5596+}
5597+
5598+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5599 {
5600 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5601 int temp;
5602@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5603 /*
5604 * Same as above, but return the result value
5605 */
5606-static __inline__ int atomic_add_return(int i, atomic_t * v)
5607+static __inline__ int atomic_add_return(int i, atomic_t *v)
5608+{
5609+ int result;
5610+ int temp;
5611+
5612+ smp_mb__before_llsc();
5613+
5614+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5615+ __asm__ __volatile__(
5616+ " .set mips3 \n"
5617+ "1: ll %1, %2 # atomic_add_return \n"
5618+#ifdef CONFIG_PAX_REFCOUNT
5619+ "2: add %0, %1, %3 \n"
5620+#else
5621+ " addu %0, %1, %3 \n"
5622+#endif
5623+ " sc %0, %2 \n"
5624+ " beqzl %0, 1b \n"
5625+#ifdef CONFIG_PAX_REFCOUNT
5626+ " b 4f \n"
5627+ " .set noreorder \n"
5628+ "3: b 5f \n"
5629+ " move %0, %1 \n"
5630+ " .set reorder \n"
5631+ _ASM_EXTABLE(2b, 3b)
5632+#endif
5633+ "4: addu %0, %1, %3 \n"
5634+#ifdef CONFIG_PAX_REFCOUNT
5635+ "5: \n"
5636+#endif
5637+ " .set mips0 \n"
5638+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5639+ : "Ir" (i));
5640+ } else if (kernel_uses_llsc) {
5641+ __asm__ __volatile__(
5642+ " .set mips3 \n"
5643+ "1: ll %1, %2 # atomic_add_return \n"
5644+#ifdef CONFIG_PAX_REFCOUNT
5645+ "2: add %0, %1, %3 \n"
5646+#else
5647+ " addu %0, %1, %3 \n"
5648+#endif
5649+ " sc %0, %2 \n"
5650+ " bnez %0, 4f \n"
5651+ " b 1b \n"
5652+#ifdef CONFIG_PAX_REFCOUNT
5653+ " .set noreorder \n"
5654+ "3: b 5f \n"
5655+ " move %0, %1 \n"
5656+ " .set reorder \n"
5657+ _ASM_EXTABLE(2b, 3b)
5658+#endif
5659+ "4: addu %0, %1, %3 \n"
5660+#ifdef CONFIG_PAX_REFCOUNT
5661+ "5: \n"
5662+#endif
5663+ " .set mips0 \n"
5664+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5665+ : "Ir" (i));
5666+ } else {
5667+ unsigned long flags;
5668+
5669+ raw_local_irq_save(flags);
5670+ __asm__ __volatile__(
5671+ " lw %0, %1 \n"
5672+#ifdef CONFIG_PAX_REFCOUNT
5673+ /* Exception on overflow. */
5674+ "1: add %0, %2 \n"
5675+#else
5676+ " addu %0, %2 \n"
5677+#endif
5678+ " sw %0, %1 \n"
5679+#ifdef CONFIG_PAX_REFCOUNT
5680+ /* Note: Dest reg is not modified on overflow */
5681+ "2: \n"
5682+ _ASM_EXTABLE(1b, 2b)
5683+#endif
5684+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5685+ raw_local_irq_restore(flags);
5686+ }
5687+
5688+ smp_llsc_mb();
5689+
5690+ return result;
5691+}
5692+
5693+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5694 {
5695 int result;
5696
5697@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5698 return result;
5699 }
5700
5701-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5702+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5703+{
5704+ int result;
5705+ int temp;
5706+
5707+ smp_mb__before_llsc();
5708+
5709+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5710+ __asm__ __volatile__(
5711+ " .set mips3 \n"
5712+ "1: ll %1, %2 # atomic_sub_return \n"
5713+#ifdef CONFIG_PAX_REFCOUNT
5714+ "2: sub %0, %1, %3 \n"
5715+#else
5716+ " subu %0, %1, %3 \n"
5717+#endif
5718+ " sc %0, %2 \n"
5719+ " beqzl %0, 1b \n"
5720+#ifdef CONFIG_PAX_REFCOUNT
5721+ " b 4f \n"
5722+ " .set noreorder \n"
5723+ "3: b 5f \n"
5724+ " move %0, %1 \n"
5725+ " .set reorder \n"
5726+ _ASM_EXTABLE(2b, 3b)
5727+#endif
5728+ "4: subu %0, %1, %3 \n"
5729+#ifdef CONFIG_PAX_REFCOUNT
5730+ "5: \n"
5731+#endif
5732+ " .set mips0 \n"
5733+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5734+ : "Ir" (i), "m" (v->counter)
5735+ : "memory");
5736+ } else if (kernel_uses_llsc) {
5737+ __asm__ __volatile__(
5738+ " .set mips3 \n"
5739+ "1: ll %1, %2 # atomic_sub_return \n"
5740+#ifdef CONFIG_PAX_REFCOUNT
5741+ "2: sub %0, %1, %3 \n"
5742+#else
5743+ " subu %0, %1, %3 \n"
5744+#endif
5745+ " sc %0, %2 \n"
5746+ " bnez %0, 4f \n"
5747+ " b 1b \n"
5748+#ifdef CONFIG_PAX_REFCOUNT
5749+ " .set noreorder \n"
5750+ "3: b 5f \n"
5751+ " move %0, %1 \n"
5752+ " .set reorder \n"
5753+ _ASM_EXTABLE(2b, 3b)
5754+#endif
5755+ "4: subu %0, %1, %3 \n"
5756+#ifdef CONFIG_PAX_REFCOUNT
5757+ "5: \n"
5758+#endif
5759+ " .set mips0 \n"
5760+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5761+ : "Ir" (i));
5762+ } else {
5763+ unsigned long flags;
5764+
5765+ raw_local_irq_save(flags);
5766+ __asm__ __volatile__(
5767+ " lw %0, %1 \n"
5768+#ifdef CONFIG_PAX_REFCOUNT
5769+ /* Exception on overflow. */
5770+ "1: sub %0, %2 \n"
5771+#else
5772+ " subu %0, %2 \n"
5773+#endif
5774+ " sw %0, %1 \n"
5775+#ifdef CONFIG_PAX_REFCOUNT
5776+ /* Note: Dest reg is not modified on overflow */
5777+ "2: \n"
5778+ _ASM_EXTABLE(1b, 2b)
5779+#endif
5780+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5781+ raw_local_irq_restore(flags);
5782+ }
5783+
5784+ smp_llsc_mb();
5785+
5786+ return result;
5787+}
5788+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5789 {
5790 int result;
5791
5792@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5793 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5794 * The function returns the old value of @v minus @i.
5795 */
5796-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5797+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5798 {
5799 int result;
5800
5801@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5802 return result;
5803 }
5804
5805-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5806-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5807+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5808+{
5809+ return cmpxchg(&v->counter, old, new);
5810+}
5811+
5812+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5813+ int new)
5814+{
5815+ return cmpxchg(&(v->counter), old, new);
5816+}
5817+
5818+static inline int atomic_xchg(atomic_t *v, int new)
5819+{
5820+ return xchg(&v->counter, new);
5821+}
5822+
5823+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5824+{
5825+ return xchg(&(v->counter), new);
5826+}
5827
5828 /**
5829 * __atomic_add_unless - add unless the number is a given value
5830@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5831
5832 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5833 #define atomic_inc_return(v) atomic_add_return(1, (v))
5834+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5835+{
5836+ return atomic_add_return_unchecked(1, v);
5837+}
5838
5839 /*
5840 * atomic_sub_and_test - subtract value from variable and test result
5841@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5842 * other cases.
5843 */
5844 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5845+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5846+{
5847+ return atomic_add_return_unchecked(1, v) == 0;
5848+}
5849
5850 /*
5851 * atomic_dec_and_test - decrement by 1 and test
5852@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5853 * Atomically increments @v by 1.
5854 */
5855 #define atomic_inc(v) atomic_add(1, (v))
5856+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5857+{
5858+ atomic_add_unchecked(1, v);
5859+}
5860
5861 /*
5862 * atomic_dec - decrement and test
5863@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5864 * Atomically decrements @v by 1.
5865 */
5866 #define atomic_dec(v) atomic_sub(1, (v))
5867+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5868+{
5869+ atomic_sub_unchecked(1, v);
5870+}
5871
5872 /*
5873 * atomic_add_negative - add and test if negative
5874@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5875 * @v: pointer of type atomic64_t
5876 *
5877 */
5878-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5879+static inline long atomic64_read(const atomic64_t *v)
5880+{
5881+ return (*(volatile const long *) &v->counter);
5882+}
5883+
5884+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5885+{
5886+ return (*(volatile const long *) &v->counter);
5887+}
5888
5889 /*
5890 * atomic64_set - set atomic variable
5891 * @v: pointer of type atomic64_t
5892 * @i: required value
5893 */
5894-#define atomic64_set(v, i) ((v)->counter = (i))
5895+static inline void atomic64_set(atomic64_t *v, long i)
5896+{
5897+ v->counter = i;
5898+}
5899+
5900+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5901+{
5902+ v->counter = i;
5903+}
5904
5905 /*
5906 * atomic64_add - add integer to atomic variable
5907@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5908 *
5909 * Atomically adds @i to @v.
5910 */
5911-static __inline__ void atomic64_add(long i, atomic64_t * v)
5912+static __inline__ void atomic64_add(long i, atomic64_t *v)
5913+{
5914+ long temp;
5915+
5916+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5917+ __asm__ __volatile__(
5918+ " .set mips3 \n"
5919+ "1: lld %0, %1 # atomic64_add \n"
5920+#ifdef CONFIG_PAX_REFCOUNT
5921+ /* Exception on overflow. */
5922+ "2: dadd %0, %2 \n"
5923+#else
5924+ " daddu %0, %2 \n"
5925+#endif
5926+ " scd %0, %1 \n"
5927+ " beqzl %0, 1b \n"
5928+#ifdef CONFIG_PAX_REFCOUNT
5929+ "3: \n"
5930+ _ASM_EXTABLE(2b, 3b)
5931+#endif
5932+ " .set mips0 \n"
5933+ : "=&r" (temp), "+m" (v->counter)
5934+ : "Ir" (i));
5935+ } else if (kernel_uses_llsc) {
5936+ __asm__ __volatile__(
5937+ " .set mips3 \n"
5938+ "1: lld %0, %1 # atomic64_add \n"
5939+#ifdef CONFIG_PAX_REFCOUNT
5940+ /* Exception on overflow. */
5941+ "2: dadd %0, %2 \n"
5942+#else
5943+ " daddu %0, %2 \n"
5944+#endif
5945+ " scd %0, %1 \n"
5946+ " beqz %0, 1b \n"
5947+#ifdef CONFIG_PAX_REFCOUNT
5948+ "3: \n"
5949+ _ASM_EXTABLE(2b, 3b)
5950+#endif
5951+ " .set mips0 \n"
5952+ : "=&r" (temp), "+m" (v->counter)
5953+ : "Ir" (i));
5954+ } else {
5955+ unsigned long flags;
5956+
5957+ raw_local_irq_save(flags);
5958+ __asm__ __volatile__(
5959+#ifdef CONFIG_PAX_REFCOUNT
5960+ /* Exception on overflow. */
5961+ "1: dadd %0, %1 \n"
5962+ "2: \n"
5963+ _ASM_EXTABLE(1b, 2b)
5964+#else
5965+ " daddu %0, %1 \n"
5966+#endif
5967+ : "+r" (v->counter) : "Ir" (i));
5968+ raw_local_irq_restore(flags);
5969+ }
5970+}
5971+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5972 {
5973 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5974 long temp;
5975@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5976 *
5977 * Atomically subtracts @i from @v.
5978 */
5979-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5980+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5981+{
5982+ long temp;
5983+
5984+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5985+ __asm__ __volatile__(
5986+ " .set mips3 \n"
5987+ "1: lld %0, %1 # atomic64_sub \n"
5988+#ifdef CONFIG_PAX_REFCOUNT
5989+ /* Exception on overflow. */
5990+ "2: dsub %0, %2 \n"
5991+#else
5992+ " dsubu %0, %2 \n"
5993+#endif
5994+ " scd %0, %1 \n"
5995+ " beqzl %0, 1b \n"
5996+#ifdef CONFIG_PAX_REFCOUNT
5997+ "3: \n"
5998+ _ASM_EXTABLE(2b, 3b)
5999+#endif
6000+ " .set mips0 \n"
6001+ : "=&r" (temp), "+m" (v->counter)
6002+ : "Ir" (i));
6003+ } else if (kernel_uses_llsc) {
6004+ __asm__ __volatile__(
6005+ " .set mips3 \n"
6006+ "1: lld %0, %1 # atomic64_sub \n"
6007+#ifdef CONFIG_PAX_REFCOUNT
6008+ /* Exception on overflow. */
6009+ "2: dsub %0, %2 \n"
6010+#else
6011+ " dsubu %0, %2 \n"
6012+#endif
6013+ " scd %0, %1 \n"
6014+ " beqz %0, 1b \n"
6015+#ifdef CONFIG_PAX_REFCOUNT
6016+ "3: \n"
6017+ _ASM_EXTABLE(2b, 3b)
6018+#endif
6019+ " .set mips0 \n"
6020+ : "=&r" (temp), "+m" (v->counter)
6021+ : "Ir" (i));
6022+ } else {
6023+ unsigned long flags;
6024+
6025+ raw_local_irq_save(flags);
6026+ __asm__ __volatile__(
6027+#ifdef CONFIG_PAX_REFCOUNT
6028+ /* Exception on overflow. */
6029+ "1: dsub %0, %1 \n"
6030+ "2: \n"
6031+ _ASM_EXTABLE(1b, 2b)
6032+#else
6033+ " dsubu %0, %1 \n"
6034+#endif
6035+ : "+r" (v->counter) : "Ir" (i));
6036+ raw_local_irq_restore(flags);
6037+ }
6038+}
6039+
6040+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6041 {
6042 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6043 long temp;
6044@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6045 /*
6046 * Same as above, but return the result value
6047 */
6048-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6049+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6050+{
6051+ long result;
6052+ long temp;
6053+
6054+ smp_mb__before_llsc();
6055+
6056+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6057+ __asm__ __volatile__(
6058+ " .set mips3 \n"
6059+ "1: lld %1, %2 # atomic64_add_return \n"
6060+#ifdef CONFIG_PAX_REFCOUNT
6061+ "2: dadd %0, %1, %3 \n"
6062+#else
6063+ " daddu %0, %1, %3 \n"
6064+#endif
6065+ " scd %0, %2 \n"
6066+ " beqzl %0, 1b \n"
6067+#ifdef CONFIG_PAX_REFCOUNT
6068+ " b 4f \n"
6069+ " .set noreorder \n"
6070+ "3: b 5f \n"
6071+ " move %0, %1 \n"
6072+ " .set reorder \n"
6073+ _ASM_EXTABLE(2b, 3b)
6074+#endif
6075+ "4: daddu %0, %1, %3 \n"
6076+#ifdef CONFIG_PAX_REFCOUNT
6077+ "5: \n"
6078+#endif
6079+ " .set mips0 \n"
6080+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6081+ : "Ir" (i));
6082+ } else if (kernel_uses_llsc) {
6083+ __asm__ __volatile__(
6084+ " .set mips3 \n"
6085+ "1: lld %1, %2 # atomic64_add_return \n"
6086+#ifdef CONFIG_PAX_REFCOUNT
6087+ "2: dadd %0, %1, %3 \n"
6088+#else
6089+ " daddu %0, %1, %3 \n"
6090+#endif
6091+ " scd %0, %2 \n"
6092+ " bnez %0, 4f \n"
6093+ " b 1b \n"
6094+#ifdef CONFIG_PAX_REFCOUNT
6095+ " .set noreorder \n"
6096+ "3: b 5f \n"
6097+ " move %0, %1 \n"
6098+ " .set reorder \n"
6099+ _ASM_EXTABLE(2b, 3b)
6100+#endif
6101+ "4: daddu %0, %1, %3 \n"
6102+#ifdef CONFIG_PAX_REFCOUNT
6103+ "5: \n"
6104+#endif
6105+ " .set mips0 \n"
6106+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6107+ : "Ir" (i), "m" (v->counter)
6108+ : "memory");
6109+ } else {
6110+ unsigned long flags;
6111+
6112+ raw_local_irq_save(flags);
6113+ __asm__ __volatile__(
6114+ " ld %0, %1 \n"
6115+#ifdef CONFIG_PAX_REFCOUNT
6116+ /* Exception on overflow. */
6117+ "1: dadd %0, %2 \n"
6118+#else
6119+ " daddu %0, %2 \n"
6120+#endif
6121+ " sd %0, %1 \n"
6122+#ifdef CONFIG_PAX_REFCOUNT
6123+ /* Note: Dest reg is not modified on overflow */
6124+ "2: \n"
6125+ _ASM_EXTABLE(1b, 2b)
6126+#endif
6127+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6128+ raw_local_irq_restore(flags);
6129+ }
6130+
6131+ smp_llsc_mb();
6132+
6133+ return result;
6134+}
6135+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6136 {
6137 long result;
6138
6139@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6140 return result;
6141 }
6142
6143-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6144+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6145+{
6146+ long result;
6147+ long temp;
6148+
6149+ smp_mb__before_llsc();
6150+
6151+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6152+ long temp;
6153+
6154+ __asm__ __volatile__(
6155+ " .set mips3 \n"
6156+ "1: lld %1, %2 # atomic64_sub_return \n"
6157+#ifdef CONFIG_PAX_REFCOUNT
6158+ "2: dsub %0, %1, %3 \n"
6159+#else
6160+ " dsubu %0, %1, %3 \n"
6161+#endif
6162+ " scd %0, %2 \n"
6163+ " beqzl %0, 1b \n"
6164+#ifdef CONFIG_PAX_REFCOUNT
6165+ " b 4f \n"
6166+ " .set noreorder \n"
6167+ "3: b 5f \n"
6168+ " move %0, %1 \n"
6169+ " .set reorder \n"
6170+ _ASM_EXTABLE(2b, 3b)
6171+#endif
6172+ "4: dsubu %0, %1, %3 \n"
6173+#ifdef CONFIG_PAX_REFCOUNT
6174+ "5: \n"
6175+#endif
6176+ " .set mips0 \n"
6177+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6178+ : "Ir" (i), "m" (v->counter)
6179+ : "memory");
6180+ } else if (kernel_uses_llsc) {
6181+ __asm__ __volatile__(
6182+ " .set mips3 \n"
6183+ "1: lld %1, %2 # atomic64_sub_return \n"
6184+#ifdef CONFIG_PAX_REFCOUNT
6185+ "2: dsub %0, %1, %3 \n"
6186+#else
6187+ " dsubu %0, %1, %3 \n"
6188+#endif
6189+ " scd %0, %2 \n"
6190+ " bnez %0, 4f \n"
6191+ " b 1b \n"
6192+#ifdef CONFIG_PAX_REFCOUNT
6193+ " .set noreorder \n"
6194+ "3: b 5f \n"
6195+ " move %0, %1 \n"
6196+ " .set reorder \n"
6197+ _ASM_EXTABLE(2b, 3b)
6198+#endif
6199+ "4: dsubu %0, %1, %3 \n"
6200+#ifdef CONFIG_PAX_REFCOUNT
6201+ "5: \n"
6202+#endif
6203+ " .set mips0 \n"
6204+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6205+ : "Ir" (i), "m" (v->counter)
6206+ : "memory");
6207+ } else {
6208+ unsigned long flags;
6209+
6210+ raw_local_irq_save(flags);
6211+ __asm__ __volatile__(
6212+ " ld %0, %1 \n"
6213+#ifdef CONFIG_PAX_REFCOUNT
6214+ /* Exception on overflow. */
6215+ "1: dsub %0, %2 \n"
6216+#else
6217+ " dsubu %0, %2 \n"
6218+#endif
6219+ " sd %0, %1 \n"
6220+#ifdef CONFIG_PAX_REFCOUNT
6221+ /* Note: Dest reg is not modified on overflow */
6222+ "2: \n"
6223+ _ASM_EXTABLE(1b, 2b)
6224+#endif
6225+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6226+ raw_local_irq_restore(flags);
6227+ }
6228+
6229+ smp_llsc_mb();
6230+
6231+ return result;
6232+}
6233+
6234+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6235 {
6236 long result;
6237
6238@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6239 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6240 * The function returns the old value of @v minus @i.
6241 */
6242-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6243+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6244 {
6245 long result;
6246
6247@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6248 return result;
6249 }
6250
6251-#define atomic64_cmpxchg(v, o, n) \
6252- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6253-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6254+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6255+{
6256+ return cmpxchg(&v->counter, old, new);
6257+}
6258+
6259+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6260+ long new)
6261+{
6262+ return cmpxchg(&(v->counter), old, new);
6263+}
6264+
6265+static inline long atomic64_xchg(atomic64_t *v, long new)
6266+{
6267+ return xchg(&v->counter, new);
6268+}
6269+
6270+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6271+{
6272+ return xchg(&(v->counter), new);
6273+}
6274
6275 /**
6276 * atomic64_add_unless - add unless the number is a given value
6277@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6278
6279 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6280 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6281+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6282
6283 /*
6284 * atomic64_sub_and_test - subtract value from variable and test result
6285@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6286 * other cases.
6287 */
6288 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6289+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6290
6291 /*
6292 * atomic64_dec_and_test - decrement by 1 and test
6293@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6294 * Atomically increments @v by 1.
6295 */
6296 #define atomic64_inc(v) atomic64_add(1, (v))
6297+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6298
6299 /*
6300 * atomic64_dec - decrement and test
6301@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6302 * Atomically decrements @v by 1.
6303 */
6304 #define atomic64_dec(v) atomic64_sub(1, (v))
6305+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6306
6307 /*
6308 * atomic64_add_negative - add and test if negative
6309diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6310index b4db69f..8f3b093 100644
6311--- a/arch/mips/include/asm/cache.h
6312+++ b/arch/mips/include/asm/cache.h
6313@@ -9,10 +9,11 @@
6314 #ifndef _ASM_CACHE_H
6315 #define _ASM_CACHE_H
6316
6317+#include <linux/const.h>
6318 #include <kmalloc.h>
6319
6320 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6321-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6322+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6323
6324 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6325 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6326diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6327index cf3ae24..238d22f 100644
6328--- a/arch/mips/include/asm/elf.h
6329+++ b/arch/mips/include/asm/elf.h
6330@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6331 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6332 #endif
6333
6334+#ifdef CONFIG_PAX_ASLR
6335+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6336+
6337+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6338+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6339+#endif
6340+
6341 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6342 struct linux_binprm;
6343 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6344 int uses_interp);
6345
6346-struct mm_struct;
6347-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6348-#define arch_randomize_brk arch_randomize_brk
6349-
6350 #endif /* _ASM_ELF_H */
6351diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6352index c1f6afa..38cc6e9 100644
6353--- a/arch/mips/include/asm/exec.h
6354+++ b/arch/mips/include/asm/exec.h
6355@@ -12,6 +12,6 @@
6356 #ifndef _ASM_EXEC_H
6357 #define _ASM_EXEC_H
6358
6359-extern unsigned long arch_align_stack(unsigned long sp);
6360+#define arch_align_stack(x) ((x) & ~0xfUL)
6361
6362 #endif /* _ASM_EXEC_H */
6363diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6364index d44622c..64990d2 100644
6365--- a/arch/mips/include/asm/local.h
6366+++ b/arch/mips/include/asm/local.h
6367@@ -12,15 +12,25 @@ typedef struct
6368 atomic_long_t a;
6369 } local_t;
6370
6371+typedef struct {
6372+ atomic_long_unchecked_t a;
6373+} local_unchecked_t;
6374+
6375 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6376
6377 #define local_read(l) atomic_long_read(&(l)->a)
6378+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6379 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6380+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6381
6382 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6383+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6384 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6385+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6386 #define local_inc(l) atomic_long_inc(&(l)->a)
6387+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6388 #define local_dec(l) atomic_long_dec(&(l)->a)
6389+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6390
6391 /*
6392 * Same as above, but return the result value
6393@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6394 return result;
6395 }
6396
6397+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6398+{
6399+ unsigned long result;
6400+
6401+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6402+ unsigned long temp;
6403+
6404+ __asm__ __volatile__(
6405+ " .set mips3 \n"
6406+ "1:" __LL "%1, %2 # local_add_return \n"
6407+ " addu %0, %1, %3 \n"
6408+ __SC "%0, %2 \n"
6409+ " beqzl %0, 1b \n"
6410+ " addu %0, %1, %3 \n"
6411+ " .set mips0 \n"
6412+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6413+ : "Ir" (i), "m" (l->a.counter)
6414+ : "memory");
6415+ } else if (kernel_uses_llsc) {
6416+ unsigned long temp;
6417+
6418+ __asm__ __volatile__(
6419+ " .set mips3 \n"
6420+ "1:" __LL "%1, %2 # local_add_return \n"
6421+ " addu %0, %1, %3 \n"
6422+ __SC "%0, %2 \n"
6423+ " beqz %0, 1b \n"
6424+ " addu %0, %1, %3 \n"
6425+ " .set mips0 \n"
6426+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6427+ : "Ir" (i), "m" (l->a.counter)
6428+ : "memory");
6429+ } else {
6430+ unsigned long flags;
6431+
6432+ local_irq_save(flags);
6433+ result = l->a.counter;
6434+ result += i;
6435+ l->a.counter = result;
6436+ local_irq_restore(flags);
6437+ }
6438+
6439+ return result;
6440+}
6441+
6442 static __inline__ long local_sub_return(long i, local_t * l)
6443 {
6444 unsigned long result;
6445@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6446
6447 #define local_cmpxchg(l, o, n) \
6448 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6449+#define local_cmpxchg_unchecked(l, o, n) \
6450+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6451 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6452
6453 /**
6454diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6455index f6be474..12ad554 100644
6456--- a/arch/mips/include/asm/page.h
6457+++ b/arch/mips/include/asm/page.h
6458@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6459 #ifdef CONFIG_CPU_MIPS32
6460 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6461 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6462- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6463+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6464 #else
6465 typedef struct { unsigned long long pte; } pte_t;
6466 #define pte_val(x) ((x).pte)
6467diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6468index 881d18b..cea38bc 100644
6469--- a/arch/mips/include/asm/pgalloc.h
6470+++ b/arch/mips/include/asm/pgalloc.h
6471@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6472 {
6473 set_pud(pud, __pud((unsigned long)pmd));
6474 }
6475+
6476+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6477+{
6478+ pud_populate(mm, pud, pmd);
6479+}
6480 #endif
6481
6482 /*
6483diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6484index 25da651..ae2a259 100644
6485--- a/arch/mips/include/asm/smtc_proc.h
6486+++ b/arch/mips/include/asm/smtc_proc.h
6487@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6488
6489 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6490
6491-extern atomic_t smtc_fpu_recoveries;
6492+extern atomic_unchecked_t smtc_fpu_recoveries;
6493
6494 #endif /* __ASM_SMTC_PROC_H */
6495diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6496index 61215a3..213ee0e 100644
6497--- a/arch/mips/include/asm/thread_info.h
6498+++ b/arch/mips/include/asm/thread_info.h
6499@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6500 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6501 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6502 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6503+/* li takes a 32bit immediate */
6504+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6505 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6506
6507 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6508@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6509 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6510 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6511 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6512+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6513
6514-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6515- _TIF_SYSCALL_AUDIT)
6516+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6517
6518 /* work to do in syscall_trace_leave() */
6519-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6520- _TIF_SYSCALL_AUDIT)
6521+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6522
6523 /* work to do on interrupt/exception return */
6524 #define _TIF_WORK_MASK \
6525 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6526 /* work to do on any return to u-space */
6527-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6528- _TIF_WORK_SYSCALL_EXIT)
6529+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6530
6531 #endif /* __KERNEL__ */
6532
6533diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6534index 1188e00..41cf144 100644
6535--- a/arch/mips/kernel/binfmt_elfn32.c
6536+++ b/arch/mips/kernel/binfmt_elfn32.c
6537@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6538 #undef ELF_ET_DYN_BASE
6539 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6540
6541+#ifdef CONFIG_PAX_ASLR
6542+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6543+
6544+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6545+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6546+#endif
6547+
6548 #include <asm/processor.h>
6549 #include <linux/module.h>
6550 #include <linux/elfcore.h>
6551diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6552index 202e581..689ca79 100644
6553--- a/arch/mips/kernel/binfmt_elfo32.c
6554+++ b/arch/mips/kernel/binfmt_elfo32.c
6555@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6556 #undef ELF_ET_DYN_BASE
6557 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6558
6559+#ifdef CONFIG_PAX_ASLR
6560+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6561+
6562+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6563+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6564+#endif
6565+
6566 #include <asm/processor.h>
6567
6568 /*
6569diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6570index d1fea7a..45602ea 100644
6571--- a/arch/mips/kernel/irq.c
6572+++ b/arch/mips/kernel/irq.c
6573@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6574 printk("unexpected IRQ # %d\n", irq);
6575 }
6576
6577-atomic_t irq_err_count;
6578+atomic_unchecked_t irq_err_count;
6579
6580 int arch_show_interrupts(struct seq_file *p, int prec)
6581 {
6582- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6583+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6584 return 0;
6585 }
6586
6587 asmlinkage void spurious_interrupt(void)
6588 {
6589- atomic_inc(&irq_err_count);
6590+ atomic_inc_unchecked(&irq_err_count);
6591 }
6592
6593 void __init init_IRQ(void)
6594diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6595index ddc7610..8c58f17 100644
6596--- a/arch/mips/kernel/process.c
6597+++ b/arch/mips/kernel/process.c
6598@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6599 out:
6600 return pc;
6601 }
6602-
6603-/*
6604- * Don't forget that the stack pointer must be aligned on a 8 bytes
6605- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6606- */
6607-unsigned long arch_align_stack(unsigned long sp)
6608-{
6609- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6610- sp -= get_random_int() & ~PAGE_MASK;
6611-
6612- return sp & ALMASK;
6613-}
6614diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6615index 8ae1ebe..1bcbf47 100644
6616--- a/arch/mips/kernel/ptrace.c
6617+++ b/arch/mips/kernel/ptrace.c
6618@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6619 return arch;
6620 }
6621
6622+#ifdef CONFIG_GRKERNSEC_SETXID
6623+extern void gr_delayed_cred_worker(void);
6624+#endif
6625+
6626 /*
6627 * Notification of system call entry/exit
6628 * - triggered by current->work.syscall_trace
6629@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6630 /* do the secure computing check first */
6631 secure_computing_strict(regs->regs[2]);
6632
6633+#ifdef CONFIG_GRKERNSEC_SETXID
6634+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6635+ gr_delayed_cred_worker();
6636+#endif
6637+
6638 if (!(current->ptrace & PT_PTRACED))
6639 goto out;
6640
6641diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6642index c10aa84..9ec2e60 100644
6643--- a/arch/mips/kernel/smtc-proc.c
6644+++ b/arch/mips/kernel/smtc-proc.c
6645@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6646
6647 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6648
6649-atomic_t smtc_fpu_recoveries;
6650+atomic_unchecked_t smtc_fpu_recoveries;
6651
6652 static int smtc_proc_show(struct seq_file *m, void *v)
6653 {
6654@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6655 for(i = 0; i < NR_CPUS; i++)
6656 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6657 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6658- atomic_read(&smtc_fpu_recoveries));
6659+ atomic_read_unchecked(&smtc_fpu_recoveries));
6660 return 0;
6661 }
6662
6663@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6664 smtc_cpu_stats[i].selfipis = 0;
6665 }
6666
6667- atomic_set(&smtc_fpu_recoveries, 0);
6668+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6669
6670 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6671 }
6672diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6673index dfc1b91..11a2c07 100644
6674--- a/arch/mips/kernel/smtc.c
6675+++ b/arch/mips/kernel/smtc.c
6676@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6677 }
6678 smtc_ipi_qdump();
6679 printk("%d Recoveries of \"stolen\" FPU\n",
6680- atomic_read(&smtc_fpu_recoveries));
6681+ atomic_read_unchecked(&smtc_fpu_recoveries));
6682 }
6683
6684
6685diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6686index 84536bf..79caa4d 100644
6687--- a/arch/mips/kernel/sync-r4k.c
6688+++ b/arch/mips/kernel/sync-r4k.c
6689@@ -21,8 +21,8 @@
6690 #include <asm/mipsregs.h>
6691
6692 static atomic_t count_start_flag = ATOMIC_INIT(0);
6693-static atomic_t count_count_start = ATOMIC_INIT(0);
6694-static atomic_t count_count_stop = ATOMIC_INIT(0);
6695+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6696+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6697 static atomic_t count_reference = ATOMIC_INIT(0);
6698
6699 #define COUNTON 100
6700@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6701
6702 for (i = 0; i < NR_LOOPS; i++) {
6703 /* slaves loop on '!= 2' */
6704- while (atomic_read(&count_count_start) != 1)
6705+ while (atomic_read_unchecked(&count_count_start) != 1)
6706 mb();
6707- atomic_set(&count_count_stop, 0);
6708+ atomic_set_unchecked(&count_count_stop, 0);
6709 smp_wmb();
6710
6711 /* this lets the slaves write their count register */
6712- atomic_inc(&count_count_start);
6713+ atomic_inc_unchecked(&count_count_start);
6714
6715 /*
6716 * Everyone initialises count in the last loop:
6717@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6718 /*
6719 * Wait for all slaves to leave the synchronization point:
6720 */
6721- while (atomic_read(&count_count_stop) != 1)
6722+ while (atomic_read_unchecked(&count_count_stop) != 1)
6723 mb();
6724- atomic_set(&count_count_start, 0);
6725+ atomic_set_unchecked(&count_count_start, 0);
6726 smp_wmb();
6727- atomic_inc(&count_count_stop);
6728+ atomic_inc_unchecked(&count_count_stop);
6729 }
6730 /* Arrange for an interrupt in a short while */
6731 write_c0_compare(read_c0_count() + COUNTON);
6732@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6733 initcount = atomic_read(&count_reference);
6734
6735 for (i = 0; i < NR_LOOPS; i++) {
6736- atomic_inc(&count_count_start);
6737- while (atomic_read(&count_count_start) != 2)
6738+ atomic_inc_unchecked(&count_count_start);
6739+ while (atomic_read_unchecked(&count_count_start) != 2)
6740 mb();
6741
6742 /*
6743@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6744 if (i == NR_LOOPS-1)
6745 write_c0_count(initcount);
6746
6747- atomic_inc(&count_count_stop);
6748- while (atomic_read(&count_count_stop) != 2)
6749+ atomic_inc_unchecked(&count_count_stop);
6750+ while (atomic_read_unchecked(&count_count_stop) != 2)
6751 mb();
6752 }
6753 /* Arrange for an interrupt in a short while */
6754diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6755index 524841f..3eef41e 100644
6756--- a/arch/mips/kernel/traps.c
6757+++ b/arch/mips/kernel/traps.c
6758@@ -684,7 +684,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6759 siginfo_t info;
6760
6761 prev_state = exception_enter();
6762- die_if_kernel("Integer overflow", regs);
6763+ if (unlikely(!user_mode(regs))) {
6764+
6765+#ifdef CONFIG_PAX_REFCOUNT
6766+ if (fixup_exception(regs)) {
6767+ pax_report_refcount_overflow(regs);
6768+ exception_exit(prev_state);
6769+ return;
6770+ }
6771+#endif
6772+
6773+ die("Integer overflow", regs);
6774+ }
6775
6776 info.si_code = FPE_INTOVF;
6777 info.si_signo = SIGFPE;
6778diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6779index becc42b..9e43d4b 100644
6780--- a/arch/mips/mm/fault.c
6781+++ b/arch/mips/mm/fault.c
6782@@ -28,6 +28,23 @@
6783 #include <asm/highmem.h> /* For VMALLOC_END */
6784 #include <linux/kdebug.h>
6785
6786+#ifdef CONFIG_PAX_PAGEEXEC
6787+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6788+{
6789+ unsigned long i;
6790+
6791+ printk(KERN_ERR "PAX: bytes at PC: ");
6792+ for (i = 0; i < 5; i++) {
6793+ unsigned int c;
6794+ if (get_user(c, (unsigned int *)pc+i))
6795+ printk(KERN_CONT "???????? ");
6796+ else
6797+ printk(KERN_CONT "%08x ", c);
6798+ }
6799+ printk("\n");
6800+}
6801+#endif
6802+
6803 /*
6804 * This routine handles page faults. It determines the address,
6805 * and the problem, and then passes it off to one of the appropriate
6806@@ -199,6 +216,14 @@ bad_area:
6807 bad_area_nosemaphore:
6808 /* User mode accesses just cause a SIGSEGV */
6809 if (user_mode(regs)) {
6810+
6811+#ifdef CONFIG_PAX_PAGEEXEC
6812+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6813+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6814+ do_group_exit(SIGKILL);
6815+ }
6816+#endif
6817+
6818 tsk->thread.cp0_badvaddr = address;
6819 tsk->thread.error_code = write;
6820 #if 0
6821diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6822index f1baadd..8537544 100644
6823--- a/arch/mips/mm/mmap.c
6824+++ b/arch/mips/mm/mmap.c
6825@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6826 struct vm_area_struct *vma;
6827 unsigned long addr = addr0;
6828 int do_color_align;
6829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6830 struct vm_unmapped_area_info info;
6831
6832 if (unlikely(len > TASK_SIZE))
6833@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6834 do_color_align = 1;
6835
6836 /* requesting a specific address */
6837+
6838+#ifdef CONFIG_PAX_RANDMMAP
6839+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6840+#endif
6841+
6842 if (addr) {
6843 if (do_color_align)
6844 addr = COLOUR_ALIGN(addr, pgoff);
6845@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6846 addr = PAGE_ALIGN(addr);
6847
6848 vma = find_vma(mm, addr);
6849- if (TASK_SIZE - len >= addr &&
6850- (!vma || addr + len <= vma->vm_start))
6851+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6852 return addr;
6853 }
6854
6855 info.length = len;
6856 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6857 info.align_offset = pgoff << PAGE_SHIFT;
6858+ info.threadstack_offset = offset;
6859
6860 if (dir == DOWN) {
6861 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6862@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6863 {
6864 unsigned long random_factor = 0UL;
6865
6866+#ifdef CONFIG_PAX_RANDMMAP
6867+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6868+#endif
6869+
6870 if (current->flags & PF_RANDOMIZE) {
6871 random_factor = get_random_int();
6872 random_factor = random_factor << PAGE_SHIFT;
6873@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6874
6875 if (mmap_is_legacy()) {
6876 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6877+
6878+#ifdef CONFIG_PAX_RANDMMAP
6879+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6880+ mm->mmap_base += mm->delta_mmap;
6881+#endif
6882+
6883 mm->get_unmapped_area = arch_get_unmapped_area;
6884 } else {
6885 mm->mmap_base = mmap_base(random_factor);
6886+
6887+#ifdef CONFIG_PAX_RANDMMAP
6888+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6889+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6890+#endif
6891+
6892 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6893 }
6894 }
6895
6896-static inline unsigned long brk_rnd(void)
6897-{
6898- unsigned long rnd = get_random_int();
6899-
6900- rnd = rnd << PAGE_SHIFT;
6901- /* 8MB for 32bit, 256MB for 64bit */
6902- if (TASK_IS_32BIT_ADDR)
6903- rnd = rnd & 0x7ffffful;
6904- else
6905- rnd = rnd & 0xffffffful;
6906-
6907- return rnd;
6908-}
6909-
6910-unsigned long arch_randomize_brk(struct mm_struct *mm)
6911-{
6912- unsigned long base = mm->brk;
6913- unsigned long ret;
6914-
6915- ret = PAGE_ALIGN(base + brk_rnd());
6916-
6917- if (ret < mm->brk)
6918- return mm->brk;
6919-
6920- return ret;
6921-}
6922-
6923 int __virt_addr_valid(const volatile void *kaddr)
6924 {
6925 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6926diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6927index a2358b4..7cead4f 100644
6928--- a/arch/mips/sgi-ip27/ip27-nmi.c
6929+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6930@@ -187,9 +187,9 @@ void
6931 cont_nmi_dump(void)
6932 {
6933 #ifndef REAL_NMI_SIGNAL
6934- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6935+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6936
6937- atomic_inc(&nmied_cpus);
6938+ atomic_inc_unchecked(&nmied_cpus);
6939 #endif
6940 /*
6941 * Only allow 1 cpu to proceed
6942@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6943 udelay(10000);
6944 }
6945 #else
6946- while (atomic_read(&nmied_cpus) != num_online_cpus());
6947+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6948 #endif
6949
6950 /*
6951diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6952index 967d144..db12197 100644
6953--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6954+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6955@@ -11,12 +11,14 @@
6956 #ifndef _ASM_PROC_CACHE_H
6957 #define _ASM_PROC_CACHE_H
6958
6959+#include <linux/const.h>
6960+
6961 /* L1 cache */
6962
6963 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6964 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6965-#define L1_CACHE_BYTES 16 /* bytes per entry */
6966 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6967+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6968 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6969
6970 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6971diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6972index bcb5df2..84fabd2 100644
6973--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6974+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6975@@ -16,13 +16,15 @@
6976 #ifndef _ASM_PROC_CACHE_H
6977 #define _ASM_PROC_CACHE_H
6978
6979+#include <linux/const.h>
6980+
6981 /*
6982 * L1 cache
6983 */
6984 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6985 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6986-#define L1_CACHE_BYTES 32 /* bytes per entry */
6987 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6988+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6989 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6990
6991 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6992diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6993index 4ce7a01..449202a 100644
6994--- a/arch/openrisc/include/asm/cache.h
6995+++ b/arch/openrisc/include/asm/cache.h
6996@@ -19,11 +19,13 @@
6997 #ifndef __ASM_OPENRISC_CACHE_H
6998 #define __ASM_OPENRISC_CACHE_H
6999
7000+#include <linux/const.h>
7001+
7002 /* FIXME: How can we replace these with values from the CPU...
7003 * they shouldn't be hard-coded!
7004 */
7005
7006-#define L1_CACHE_BYTES 16
7007 #define L1_CACHE_SHIFT 4
7008+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7009
7010 #endif /* __ASM_OPENRISC_CACHE_H */
7011diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7012index 472886c..00e7df9 100644
7013--- a/arch/parisc/include/asm/atomic.h
7014+++ b/arch/parisc/include/asm/atomic.h
7015@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7016 return dec;
7017 }
7018
7019+#define atomic64_read_unchecked(v) atomic64_read(v)
7020+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7021+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7022+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7023+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7024+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7025+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7026+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7027+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7028+
7029 #endif /* !CONFIG_64BIT */
7030
7031
7032diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7033index 47f11c7..3420df2 100644
7034--- a/arch/parisc/include/asm/cache.h
7035+++ b/arch/parisc/include/asm/cache.h
7036@@ -5,6 +5,7 @@
7037 #ifndef __ARCH_PARISC_CACHE_H
7038 #define __ARCH_PARISC_CACHE_H
7039
7040+#include <linux/const.h>
7041
7042 /*
7043 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7044@@ -15,13 +16,13 @@
7045 * just ruin performance.
7046 */
7047 #ifdef CONFIG_PA20
7048-#define L1_CACHE_BYTES 64
7049 #define L1_CACHE_SHIFT 6
7050 #else
7051-#define L1_CACHE_BYTES 32
7052 #define L1_CACHE_SHIFT 5
7053 #endif
7054
7055+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7056+
7057 #ifndef __ASSEMBLY__
7058
7059 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7060diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7061index ad2b503..bdf1651 100644
7062--- a/arch/parisc/include/asm/elf.h
7063+++ b/arch/parisc/include/asm/elf.h
7064@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7065
7066 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7067
7068+#ifdef CONFIG_PAX_ASLR
7069+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7070+
7071+#define PAX_DELTA_MMAP_LEN 16
7072+#define PAX_DELTA_STACK_LEN 16
7073+#endif
7074+
7075 /* This yields a mask that user programs can use to figure out what
7076 instruction set this CPU supports. This could be done in user space,
7077 but it's not easy, and we've already done it here. */
7078diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7079index fc987a1..6e068ef 100644
7080--- a/arch/parisc/include/asm/pgalloc.h
7081+++ b/arch/parisc/include/asm/pgalloc.h
7082@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7083 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7084 }
7085
7086+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7087+{
7088+ pgd_populate(mm, pgd, pmd);
7089+}
7090+
7091 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7092 {
7093 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7094@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7095 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7096 #define pmd_free(mm, x) do { } while (0)
7097 #define pgd_populate(mm, pmd, pte) BUG()
7098+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7099
7100 #endif
7101
7102diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7103index 34899b5..02dd060 100644
7104--- a/arch/parisc/include/asm/pgtable.h
7105+++ b/arch/parisc/include/asm/pgtable.h
7106@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7107 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7108 #define PAGE_COPY PAGE_EXECREAD
7109 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7110+
7111+#ifdef CONFIG_PAX_PAGEEXEC
7112+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7113+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7114+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7115+#else
7116+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7117+# define PAGE_COPY_NOEXEC PAGE_COPY
7118+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7119+#endif
7120+
7121 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7122 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7123 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7124diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7125index e0a8235..ce2f1e1 100644
7126--- a/arch/parisc/include/asm/uaccess.h
7127+++ b/arch/parisc/include/asm/uaccess.h
7128@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7129 const void __user *from,
7130 unsigned long n)
7131 {
7132- int sz = __compiletime_object_size(to);
7133+ size_t sz = __compiletime_object_size(to);
7134 int ret = -EFAULT;
7135
7136- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7137+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7138 ret = __copy_from_user(to, from, n);
7139 else
7140 copy_from_user_overflow();
7141diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7142index 2a625fb..9908930 100644
7143--- a/arch/parisc/kernel/module.c
7144+++ b/arch/parisc/kernel/module.c
7145@@ -98,16 +98,38 @@
7146
7147 /* three functions to determine where in the module core
7148 * or init pieces the location is */
7149+static inline int in_init_rx(struct module *me, void *loc)
7150+{
7151+ return (loc >= me->module_init_rx &&
7152+ loc < (me->module_init_rx + me->init_size_rx));
7153+}
7154+
7155+static inline int in_init_rw(struct module *me, void *loc)
7156+{
7157+ return (loc >= me->module_init_rw &&
7158+ loc < (me->module_init_rw + me->init_size_rw));
7159+}
7160+
7161 static inline int in_init(struct module *me, void *loc)
7162 {
7163- return (loc >= me->module_init &&
7164- loc <= (me->module_init + me->init_size));
7165+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7166+}
7167+
7168+static inline int in_core_rx(struct module *me, void *loc)
7169+{
7170+ return (loc >= me->module_core_rx &&
7171+ loc < (me->module_core_rx + me->core_size_rx));
7172+}
7173+
7174+static inline int in_core_rw(struct module *me, void *loc)
7175+{
7176+ return (loc >= me->module_core_rw &&
7177+ loc < (me->module_core_rw + me->core_size_rw));
7178 }
7179
7180 static inline int in_core(struct module *me, void *loc)
7181 {
7182- return (loc >= me->module_core &&
7183- loc <= (me->module_core + me->core_size));
7184+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7185 }
7186
7187 static inline int in_local(struct module *me, void *loc)
7188@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7189 }
7190
7191 /* align things a bit */
7192- me->core_size = ALIGN(me->core_size, 16);
7193- me->arch.got_offset = me->core_size;
7194- me->core_size += gots * sizeof(struct got_entry);
7195+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7196+ me->arch.got_offset = me->core_size_rw;
7197+ me->core_size_rw += gots * sizeof(struct got_entry);
7198
7199- me->core_size = ALIGN(me->core_size, 16);
7200- me->arch.fdesc_offset = me->core_size;
7201- me->core_size += fdescs * sizeof(Elf_Fdesc);
7202+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7203+ me->arch.fdesc_offset = me->core_size_rw;
7204+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7205
7206 me->arch.got_max = gots;
7207 me->arch.fdesc_max = fdescs;
7208@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7209
7210 BUG_ON(value == 0);
7211
7212- got = me->module_core + me->arch.got_offset;
7213+ got = me->module_core_rw + me->arch.got_offset;
7214 for (i = 0; got[i].addr; i++)
7215 if (got[i].addr == value)
7216 goto out;
7217@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7218 #ifdef CONFIG_64BIT
7219 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7220 {
7221- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7222+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7223
7224 if (!value) {
7225 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7226@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7227
7228 /* Create new one */
7229 fdesc->addr = value;
7230- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7231+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7232 return (Elf_Addr)fdesc;
7233 }
7234 #endif /* CONFIG_64BIT */
7235@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7236
7237 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7238 end = table + sechdrs[me->arch.unwind_section].sh_size;
7239- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7240+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7241
7242 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7243 me->arch.unwind_section, table, end, gp);
7244diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7245index 0d3a9d4..44975d0 100644
7246--- a/arch/parisc/kernel/sys_parisc.c
7247+++ b/arch/parisc/kernel/sys_parisc.c
7248@@ -33,9 +33,11 @@
7249 #include <linux/utsname.h>
7250 #include <linux/personality.h>
7251
7252-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7253+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7254+ unsigned long flags)
7255 {
7256 struct vm_unmapped_area_info info;
7257+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7258
7259 info.flags = 0;
7260 info.length = len;
7261@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7262 info.high_limit = TASK_SIZE;
7263 info.align_mask = 0;
7264 info.align_offset = 0;
7265+ info.threadstack_offset = offset;
7266 return vm_unmapped_area(&info);
7267 }
7268
7269@@ -69,15 +72,17 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7270 }
7271
7272 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7273- unsigned long len, unsigned long pgoff)
7274+ unsigned long len, unsigned long pgoff, unsigned long flags)
7275 {
7276 struct vm_unmapped_area_info info;
7277+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7278
7279 info.flags = 0;
7280 info.length = len;
7281 info.low_limit = PAGE_ALIGN(addr);
7282 info.high_limit = TASK_SIZE;
7283 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7284+ info.threadstack_offset = offset;
7285 info.align_offset = shared_align_offset(filp, pgoff);
7286 return vm_unmapped_area(&info);
7287 }
7288@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7289 return -EINVAL;
7290 return addr;
7291 }
7292- if (!addr)
7293+ if (!addr) {
7294 addr = TASK_UNMAPPED_BASE;
7295
7296+#ifdef CONFIG_PAX_RANDMMAP
7297+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7298+ addr += current->mm->delta_mmap;
7299+#endif
7300+
7301+ }
7302+
7303 if (filp || (flags & MAP_SHARED))
7304- addr = get_shared_area(filp, addr, len, pgoff);
7305+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7306 else
7307- addr = get_unshared_area(addr, len);
7308+ addr = get_unshared_area(addr, len, flags);
7309
7310 return addr;
7311 }
7312diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7313index 1cd1d0c..44ec918 100644
7314--- a/arch/parisc/kernel/traps.c
7315+++ b/arch/parisc/kernel/traps.c
7316@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7317
7318 down_read(&current->mm->mmap_sem);
7319 vma = find_vma(current->mm,regs->iaoq[0]);
7320- if (vma && (regs->iaoq[0] >= vma->vm_start)
7321- && (vma->vm_flags & VM_EXEC)) {
7322-
7323+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7324 fault_address = regs->iaoq[0];
7325 fault_space = regs->iasq[0];
7326
7327diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7328index 0293588..3b229aa 100644
7329--- a/arch/parisc/mm/fault.c
7330+++ b/arch/parisc/mm/fault.c
7331@@ -15,6 +15,7 @@
7332 #include <linux/sched.h>
7333 #include <linux/interrupt.h>
7334 #include <linux/module.h>
7335+#include <linux/unistd.h>
7336
7337 #include <asm/uaccess.h>
7338 #include <asm/traps.h>
7339@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7340 static unsigned long
7341 parisc_acctyp(unsigned long code, unsigned int inst)
7342 {
7343- if (code == 6 || code == 16)
7344+ if (code == 6 || code == 7 || code == 16)
7345 return VM_EXEC;
7346
7347 switch (inst & 0xf0000000) {
7348@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7349 }
7350 #endif
7351
7352+#ifdef CONFIG_PAX_PAGEEXEC
7353+/*
7354+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7355+ *
7356+ * returns 1 when task should be killed
7357+ * 2 when rt_sigreturn trampoline was detected
7358+ * 3 when unpatched PLT trampoline was detected
7359+ */
7360+static int pax_handle_fetch_fault(struct pt_regs *regs)
7361+{
7362+
7363+#ifdef CONFIG_PAX_EMUPLT
7364+ int err;
7365+
7366+ do { /* PaX: unpatched PLT emulation */
7367+ unsigned int bl, depwi;
7368+
7369+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7370+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7371+
7372+ if (err)
7373+ break;
7374+
7375+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7376+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7377+
7378+ err = get_user(ldw, (unsigned int *)addr);
7379+ err |= get_user(bv, (unsigned int *)(addr+4));
7380+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7381+
7382+ if (err)
7383+ break;
7384+
7385+ if (ldw == 0x0E801096U &&
7386+ bv == 0xEAC0C000U &&
7387+ ldw2 == 0x0E881095U)
7388+ {
7389+ unsigned int resolver, map;
7390+
7391+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7392+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7393+ if (err)
7394+ break;
7395+
7396+ regs->gr[20] = instruction_pointer(regs)+8;
7397+ regs->gr[21] = map;
7398+ regs->gr[22] = resolver;
7399+ regs->iaoq[0] = resolver | 3UL;
7400+ regs->iaoq[1] = regs->iaoq[0] + 4;
7401+ return 3;
7402+ }
7403+ }
7404+ } while (0);
7405+#endif
7406+
7407+#ifdef CONFIG_PAX_EMUTRAMP
7408+
7409+#ifndef CONFIG_PAX_EMUSIGRT
7410+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7411+ return 1;
7412+#endif
7413+
7414+ do { /* PaX: rt_sigreturn emulation */
7415+ unsigned int ldi1, ldi2, bel, nop;
7416+
7417+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7418+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7419+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7420+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7421+
7422+ if (err)
7423+ break;
7424+
7425+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7426+ ldi2 == 0x3414015AU &&
7427+ bel == 0xE4008200U &&
7428+ nop == 0x08000240U)
7429+ {
7430+ regs->gr[25] = (ldi1 & 2) >> 1;
7431+ regs->gr[20] = __NR_rt_sigreturn;
7432+ regs->gr[31] = regs->iaoq[1] + 16;
7433+ regs->sr[0] = regs->iasq[1];
7434+ regs->iaoq[0] = 0x100UL;
7435+ regs->iaoq[1] = regs->iaoq[0] + 4;
7436+ regs->iasq[0] = regs->sr[2];
7437+ regs->iasq[1] = regs->sr[2];
7438+ return 2;
7439+ }
7440+ } while (0);
7441+#endif
7442+
7443+ return 1;
7444+}
7445+
7446+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7447+{
7448+ unsigned long i;
7449+
7450+ printk(KERN_ERR "PAX: bytes at PC: ");
7451+ for (i = 0; i < 5; i++) {
7452+ unsigned int c;
7453+ if (get_user(c, (unsigned int *)pc+i))
7454+ printk(KERN_CONT "???????? ");
7455+ else
7456+ printk(KERN_CONT "%08x ", c);
7457+ }
7458+ printk("\n");
7459+}
7460+#endif
7461+
7462 int fixup_exception(struct pt_regs *regs)
7463 {
7464 const struct exception_table_entry *fix;
7465@@ -204,8 +315,33 @@ retry:
7466
7467 good_area:
7468
7469- if ((vma->vm_flags & acc_type) != acc_type)
7470+ if ((vma->vm_flags & acc_type) != acc_type) {
7471+
7472+#ifdef CONFIG_PAX_PAGEEXEC
7473+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7474+ (address & ~3UL) == instruction_pointer(regs))
7475+ {
7476+ up_read(&mm->mmap_sem);
7477+ switch (pax_handle_fetch_fault(regs)) {
7478+
7479+#ifdef CONFIG_PAX_EMUPLT
7480+ case 3:
7481+ return;
7482+#endif
7483+
7484+#ifdef CONFIG_PAX_EMUTRAMP
7485+ case 2:
7486+ return;
7487+#endif
7488+
7489+ }
7490+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7491+ do_group_exit(SIGKILL);
7492+ }
7493+#endif
7494+
7495 goto bad_area;
7496+ }
7497
7498 /*
7499 * If for any reason at all we couldn't handle the fault, make
7500diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7501index 38f3b7e..7e485c0 100644
7502--- a/arch/powerpc/Kconfig
7503+++ b/arch/powerpc/Kconfig
7504@@ -378,6 +378,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7505 config KEXEC
7506 bool "kexec system call"
7507 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7508+ depends on !GRKERNSEC_KMEM
7509 help
7510 kexec is a system call that implements the ability to shutdown your
7511 current kernel, and to start another kernel. It is like a reboot
7512diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7513index e3b1d41..8e81edf 100644
7514--- a/arch/powerpc/include/asm/atomic.h
7515+++ b/arch/powerpc/include/asm/atomic.h
7516@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7517 return t1;
7518 }
7519
7520+#define atomic64_read_unchecked(v) atomic64_read(v)
7521+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7522+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7523+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7524+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7525+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7526+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7527+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7528+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7529+
7530 #endif /* __powerpc64__ */
7531
7532 #endif /* __KERNEL__ */
7533diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7534index 9e495c9..b6878e5 100644
7535--- a/arch/powerpc/include/asm/cache.h
7536+++ b/arch/powerpc/include/asm/cache.h
7537@@ -3,6 +3,7 @@
7538
7539 #ifdef __KERNEL__
7540
7541+#include <linux/const.h>
7542
7543 /* bytes per L1 cache line */
7544 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7545@@ -22,7 +23,7 @@
7546 #define L1_CACHE_SHIFT 7
7547 #endif
7548
7549-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7550+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7551
7552 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7553
7554diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7555index cc0655a..13eac2e 100644
7556--- a/arch/powerpc/include/asm/elf.h
7557+++ b/arch/powerpc/include/asm/elf.h
7558@@ -28,8 +28,19 @@
7559 the loader. We need to make sure that it is out of the way of the program
7560 that it will "exec", and that there is sufficient room for the brk. */
7561
7562-extern unsigned long randomize_et_dyn(unsigned long base);
7563-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7564+#define ELF_ET_DYN_BASE (0x20000000)
7565+
7566+#ifdef CONFIG_PAX_ASLR
7567+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7568+
7569+#ifdef __powerpc64__
7570+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7571+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7572+#else
7573+#define PAX_DELTA_MMAP_LEN 15
7574+#define PAX_DELTA_STACK_LEN 15
7575+#endif
7576+#endif
7577
7578 /*
7579 * Our registers are always unsigned longs, whether we're a 32 bit
7580@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7581 (0x7ff >> (PAGE_SHIFT - 12)) : \
7582 (0x3ffff >> (PAGE_SHIFT - 12)))
7583
7584-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7585-#define arch_randomize_brk arch_randomize_brk
7586-
7587-
7588 #ifdef CONFIG_SPU_BASE
7589 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7590 #define NT_SPU 1
7591diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7592index 8196e9c..d83a9f3 100644
7593--- a/arch/powerpc/include/asm/exec.h
7594+++ b/arch/powerpc/include/asm/exec.h
7595@@ -4,6 +4,6 @@
7596 #ifndef _ASM_POWERPC_EXEC_H
7597 #define _ASM_POWERPC_EXEC_H
7598
7599-extern unsigned long arch_align_stack(unsigned long sp);
7600+#define arch_align_stack(x) ((x) & ~0xfUL)
7601
7602 #endif /* _ASM_POWERPC_EXEC_H */
7603diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7604index 5acabbd..7ea14fa 100644
7605--- a/arch/powerpc/include/asm/kmap_types.h
7606+++ b/arch/powerpc/include/asm/kmap_types.h
7607@@ -10,7 +10,7 @@
7608 * 2 of the License, or (at your option) any later version.
7609 */
7610
7611-#define KM_TYPE_NR 16
7612+#define KM_TYPE_NR 17
7613
7614 #endif /* __KERNEL__ */
7615 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7616diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7617index 8565c25..2865190 100644
7618--- a/arch/powerpc/include/asm/mman.h
7619+++ b/arch/powerpc/include/asm/mman.h
7620@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7621 }
7622 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7623
7624-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7625+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7626 {
7627 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7628 }
7629diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7630index b9f4262..dcf04f7 100644
7631--- a/arch/powerpc/include/asm/page.h
7632+++ b/arch/powerpc/include/asm/page.h
7633@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7634 * and needs to be executable. This means the whole heap ends
7635 * up being executable.
7636 */
7637-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7638- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7639+#define VM_DATA_DEFAULT_FLAGS32 \
7640+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7641+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7642
7643 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7644 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7645@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7646 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7647 #endif
7648
7649+#define ktla_ktva(addr) (addr)
7650+#define ktva_ktla(addr) (addr)
7651+
7652 #ifndef CONFIG_PPC_BOOK3S_64
7653 /*
7654 * Use the top bit of the higher-level page table entries to indicate whether
7655diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7656index 88693ce..ac6f9ab 100644
7657--- a/arch/powerpc/include/asm/page_64.h
7658+++ b/arch/powerpc/include/asm/page_64.h
7659@@ -153,15 +153,18 @@ do { \
7660 * stack by default, so in the absence of a PT_GNU_STACK program header
7661 * we turn execute permission off.
7662 */
7663-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7664- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7665+#define VM_STACK_DEFAULT_FLAGS32 \
7666+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7667+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7668
7669 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7670 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7671
7672+#ifndef CONFIG_PAX_PAGEEXEC
7673 #define VM_STACK_DEFAULT_FLAGS \
7674 (is_32bit_task() ? \
7675 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7676+#endif
7677
7678 #include <asm-generic/getorder.h>
7679
7680diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7681index 256d6f8..b0166a7 100644
7682--- a/arch/powerpc/include/asm/pgalloc-64.h
7683+++ b/arch/powerpc/include/asm/pgalloc-64.h
7684@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7685 #ifndef CONFIG_PPC_64K_PAGES
7686
7687 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7688+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7689
7690 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7691 {
7692@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7693 pud_set(pud, (unsigned long)pmd);
7694 }
7695
7696+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7697+{
7698+ pud_populate(mm, pud, pmd);
7699+}
7700+
7701 #define pmd_populate(mm, pmd, pte_page) \
7702 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7703 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7704@@ -169,6 +175,7 @@ extern void __tlb_remove_table(void *_table);
7705 #endif
7706
7707 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7708+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7709
7710 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7711 pte_t *pte)
7712diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7713index 7d6eacf..14c0240 100644
7714--- a/arch/powerpc/include/asm/pgtable.h
7715+++ b/arch/powerpc/include/asm/pgtable.h
7716@@ -2,6 +2,7 @@
7717 #define _ASM_POWERPC_PGTABLE_H
7718 #ifdef __KERNEL__
7719
7720+#include <linux/const.h>
7721 #ifndef __ASSEMBLY__
7722 #include <asm/processor.h> /* For TASK_SIZE */
7723 #include <asm/mmu.h>
7724diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7725index 4aad413..85d86bf 100644
7726--- a/arch/powerpc/include/asm/pte-hash32.h
7727+++ b/arch/powerpc/include/asm/pte-hash32.h
7728@@ -21,6 +21,7 @@
7729 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7730 #define _PAGE_USER 0x004 /* usermode access allowed */
7731 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7732+#define _PAGE_EXEC _PAGE_GUARDED
7733 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7734 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7735 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7736diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7737index 10d1ef0..8f83abc 100644
7738--- a/arch/powerpc/include/asm/reg.h
7739+++ b/arch/powerpc/include/asm/reg.h
7740@@ -234,6 +234,7 @@
7741 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7742 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7743 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7744+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7745 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7746 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7747 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7748diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7749index 98da78e..dc68271 100644
7750--- a/arch/powerpc/include/asm/smp.h
7751+++ b/arch/powerpc/include/asm/smp.h
7752@@ -50,7 +50,7 @@ struct smp_ops_t {
7753 int (*cpu_disable)(void);
7754 void (*cpu_die)(unsigned int nr);
7755 int (*cpu_bootable)(unsigned int nr);
7756-};
7757+} __no_const;
7758
7759 extern void smp_send_debugger_break(void);
7760 extern void start_secondary_resume(void);
7761diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7762index ba7b197..d292e26 100644
7763--- a/arch/powerpc/include/asm/thread_info.h
7764+++ b/arch/powerpc/include/asm/thread_info.h
7765@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7766 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7767 TIF_NEED_RESCHED */
7768 #define TIF_32BIT 4 /* 32 bit binary */
7769-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7770 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7771 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7772 #define TIF_SINGLESTEP 8 /* singlestepping active */
7773@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7774 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7775 for stack store? */
7776 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7777+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7778+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7779+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7780
7781 /* as above, but as bit values */
7782 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7783@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7784 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7785 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7786 #define _TIF_NOHZ (1<<TIF_NOHZ)
7787+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7788 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7789 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7790- _TIF_NOHZ)
7791+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7792
7793 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7794 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7795diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7796index 9485b43..4718d50 100644
7797--- a/arch/powerpc/include/asm/uaccess.h
7798+++ b/arch/powerpc/include/asm/uaccess.h
7799@@ -318,52 +318,6 @@ do { \
7800 extern unsigned long __copy_tofrom_user(void __user *to,
7801 const void __user *from, unsigned long size);
7802
7803-#ifndef __powerpc64__
7804-
7805-static inline unsigned long copy_from_user(void *to,
7806- const void __user *from, unsigned long n)
7807-{
7808- unsigned long over;
7809-
7810- if (access_ok(VERIFY_READ, from, n))
7811- return __copy_tofrom_user((__force void __user *)to, from, n);
7812- if ((unsigned long)from < TASK_SIZE) {
7813- over = (unsigned long)from + n - TASK_SIZE;
7814- return __copy_tofrom_user((__force void __user *)to, from,
7815- n - over) + over;
7816- }
7817- return n;
7818-}
7819-
7820-static inline unsigned long copy_to_user(void __user *to,
7821- const void *from, unsigned long n)
7822-{
7823- unsigned long over;
7824-
7825- if (access_ok(VERIFY_WRITE, to, n))
7826- return __copy_tofrom_user(to, (__force void __user *)from, n);
7827- if ((unsigned long)to < TASK_SIZE) {
7828- over = (unsigned long)to + n - TASK_SIZE;
7829- return __copy_tofrom_user(to, (__force void __user *)from,
7830- n - over) + over;
7831- }
7832- return n;
7833-}
7834-
7835-#else /* __powerpc64__ */
7836-
7837-#define __copy_in_user(to, from, size) \
7838- __copy_tofrom_user((to), (from), (size))
7839-
7840-extern unsigned long copy_from_user(void *to, const void __user *from,
7841- unsigned long n);
7842-extern unsigned long copy_to_user(void __user *to, const void *from,
7843- unsigned long n);
7844-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7845- unsigned long n);
7846-
7847-#endif /* __powerpc64__ */
7848-
7849 static inline unsigned long __copy_from_user_inatomic(void *to,
7850 const void __user *from, unsigned long n)
7851 {
7852@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7853 if (ret == 0)
7854 return 0;
7855 }
7856+
7857+ if (!__builtin_constant_p(n))
7858+ check_object_size(to, n, false);
7859+
7860 return __copy_tofrom_user((__force void __user *)to, from, n);
7861 }
7862
7863@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7864 if (ret == 0)
7865 return 0;
7866 }
7867+
7868+ if (!__builtin_constant_p(n))
7869+ check_object_size(from, n, true);
7870+
7871 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7872 }
7873
7874@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7875 return __copy_to_user_inatomic(to, from, size);
7876 }
7877
7878+#ifndef __powerpc64__
7879+
7880+static inline unsigned long __must_check copy_from_user(void *to,
7881+ const void __user *from, unsigned long n)
7882+{
7883+ unsigned long over;
7884+
7885+ if ((long)n < 0)
7886+ return n;
7887+
7888+ if (access_ok(VERIFY_READ, from, n)) {
7889+ if (!__builtin_constant_p(n))
7890+ check_object_size(to, n, false);
7891+ return __copy_tofrom_user((__force void __user *)to, from, n);
7892+ }
7893+ if ((unsigned long)from < TASK_SIZE) {
7894+ over = (unsigned long)from + n - TASK_SIZE;
7895+ if (!__builtin_constant_p(n - over))
7896+ check_object_size(to, n - over, false);
7897+ return __copy_tofrom_user((__force void __user *)to, from,
7898+ n - over) + over;
7899+ }
7900+ return n;
7901+}
7902+
7903+static inline unsigned long __must_check copy_to_user(void __user *to,
7904+ const void *from, unsigned long n)
7905+{
7906+ unsigned long over;
7907+
7908+ if ((long)n < 0)
7909+ return n;
7910+
7911+ if (access_ok(VERIFY_WRITE, to, n)) {
7912+ if (!__builtin_constant_p(n))
7913+ check_object_size(from, n, true);
7914+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7915+ }
7916+ if ((unsigned long)to < TASK_SIZE) {
7917+ over = (unsigned long)to + n - TASK_SIZE;
7918+ if (!__builtin_constant_p(n))
7919+ check_object_size(from, n - over, true);
7920+ return __copy_tofrom_user(to, (__force void __user *)from,
7921+ n - over) + over;
7922+ }
7923+ return n;
7924+}
7925+
7926+#else /* __powerpc64__ */
7927+
7928+#define __copy_in_user(to, from, size) \
7929+ __copy_tofrom_user((to), (from), (size))
7930+
7931+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7932+{
7933+ if ((long)n < 0 || n > INT_MAX)
7934+ return n;
7935+
7936+ if (!__builtin_constant_p(n))
7937+ check_object_size(to, n, false);
7938+
7939+ if (likely(access_ok(VERIFY_READ, from, n)))
7940+ n = __copy_from_user(to, from, n);
7941+ else
7942+ memset(to, 0, n);
7943+ return n;
7944+}
7945+
7946+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7947+{
7948+ if ((long)n < 0 || n > INT_MAX)
7949+ return n;
7950+
7951+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7952+ if (!__builtin_constant_p(n))
7953+ check_object_size(from, n, true);
7954+ n = __copy_to_user(to, from, n);
7955+ }
7956+ return n;
7957+}
7958+
7959+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7960+ unsigned long n);
7961+
7962+#endif /* __powerpc64__ */
7963+
7964 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7965
7966 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7967diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7968index 2d06704..1616f1b 100644
7969--- a/arch/powerpc/kernel/exceptions-64e.S
7970+++ b/arch/powerpc/kernel/exceptions-64e.S
7971@@ -757,6 +757,7 @@ storage_fault_common:
7972 std r14,_DAR(r1)
7973 std r15,_DSISR(r1)
7974 addi r3,r1,STACK_FRAME_OVERHEAD
7975+ bl .save_nvgprs
7976 mr r4,r14
7977 mr r5,r15
7978 ld r14,PACA_EXGEN+EX_R14(r13)
7979@@ -765,8 +766,7 @@ storage_fault_common:
7980 cmpdi r3,0
7981 bne- 1f
7982 b .ret_from_except_lite
7983-1: bl .save_nvgprs
7984- mr r5,r3
7985+1: mr r5,r3
7986 addi r3,r1,STACK_FRAME_OVERHEAD
7987 ld r4,_DAR(r1)
7988 bl .bad_page_fault
7989diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7990index 3a9ed6a..b534681 100644
7991--- a/arch/powerpc/kernel/exceptions-64s.S
7992+++ b/arch/powerpc/kernel/exceptions-64s.S
7993@@ -1364,10 +1364,10 @@ handle_page_fault:
7994 11: ld r4,_DAR(r1)
7995 ld r5,_DSISR(r1)
7996 addi r3,r1,STACK_FRAME_OVERHEAD
7997+ bl .save_nvgprs
7998 bl .do_page_fault
7999 cmpdi r3,0
8000 beq+ 12f
8001- bl .save_nvgprs
8002 mr r5,r3
8003 addi r3,r1,STACK_FRAME_OVERHEAD
8004 lwz r4,_DAR(r1)
8005diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8006index 2e3200c..72095ce 100644
8007--- a/arch/powerpc/kernel/module_32.c
8008+++ b/arch/powerpc/kernel/module_32.c
8009@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8010 me->arch.core_plt_section = i;
8011 }
8012 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8013- printk("Module doesn't contain .plt or .init.plt sections.\n");
8014+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8015 return -ENOEXEC;
8016 }
8017
8018@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
8019
8020 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8021 /* Init, or core PLT? */
8022- if (location >= mod->module_core
8023- && location < mod->module_core + mod->core_size)
8024+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8025+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8026 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8027- else
8028+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8029+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8030 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8031+ else {
8032+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8033+ return ~0UL;
8034+ }
8035
8036 /* Find this entry, or if that fails, the next avail. entry */
8037 while (entry->jump[0]) {
8038diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8039index 96d2fdf..f6d10c8 100644
8040--- a/arch/powerpc/kernel/process.c
8041+++ b/arch/powerpc/kernel/process.c
8042@@ -886,8 +886,8 @@ void show_regs(struct pt_regs * regs)
8043 * Lookup NIP late so we have the best change of getting the
8044 * above info out without failing
8045 */
8046- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8047- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8048+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8049+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8050 #endif
8051 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8052 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8053@@ -1352,10 +1352,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8054 newsp = stack[0];
8055 ip = stack[STACK_FRAME_LR_SAVE];
8056 if (!firstframe || ip != lr) {
8057- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8058+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8059 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8060 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8061- printk(" (%pS)",
8062+ printk(" (%pA)",
8063 (void *)current->ret_stack[curr_frame].ret);
8064 curr_frame--;
8065 }
8066@@ -1375,7 +1375,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8067 struct pt_regs *regs = (struct pt_regs *)
8068 (sp + STACK_FRAME_OVERHEAD);
8069 lr = regs->link;
8070- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8071+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8072 regs->trap, (void *)regs->nip, (void *)lr);
8073 firstframe = 1;
8074 }
8075@@ -1411,58 +1411,3 @@ void notrace __ppc64_runlatch_off(void)
8076 mtspr(SPRN_CTRLT, ctrl);
8077 }
8078 #endif /* CONFIG_PPC64 */
8079-
8080-unsigned long arch_align_stack(unsigned long sp)
8081-{
8082- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8083- sp -= get_random_int() & ~PAGE_MASK;
8084- return sp & ~0xf;
8085-}
8086-
8087-static inline unsigned long brk_rnd(void)
8088-{
8089- unsigned long rnd = 0;
8090-
8091- /* 8MB for 32bit, 1GB for 64bit */
8092- if (is_32bit_task())
8093- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8094- else
8095- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8096-
8097- return rnd << PAGE_SHIFT;
8098-}
8099-
8100-unsigned long arch_randomize_brk(struct mm_struct *mm)
8101-{
8102- unsigned long base = mm->brk;
8103- unsigned long ret;
8104-
8105-#ifdef CONFIG_PPC_STD_MMU_64
8106- /*
8107- * If we are using 1TB segments and we are allowed to randomise
8108- * the heap, we can put it above 1TB so it is backed by a 1TB
8109- * segment. Otherwise the heap will be in the bottom 1TB
8110- * which always uses 256MB segments and this may result in a
8111- * performance penalty.
8112- */
8113- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8114- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8115-#endif
8116-
8117- ret = PAGE_ALIGN(base + brk_rnd());
8118-
8119- if (ret < mm->brk)
8120- return mm->brk;
8121-
8122- return ret;
8123-}
8124-
8125-unsigned long randomize_et_dyn(unsigned long base)
8126-{
8127- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8128-
8129- if (ret < base)
8130- return base;
8131-
8132- return ret;
8133-}
8134diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8135index 9a0d24c..e7fbedf 100644
8136--- a/arch/powerpc/kernel/ptrace.c
8137+++ b/arch/powerpc/kernel/ptrace.c
8138@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8139 return ret;
8140 }
8141
8142+#ifdef CONFIG_GRKERNSEC_SETXID
8143+extern void gr_delayed_cred_worker(void);
8144+#endif
8145+
8146 /*
8147 * We must return the syscall number to actually look up in the table.
8148 * This can be -1L to skip running any syscall at all.
8149@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8150
8151 secure_computing_strict(regs->gpr[0]);
8152
8153+#ifdef CONFIG_GRKERNSEC_SETXID
8154+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8155+ gr_delayed_cred_worker();
8156+#endif
8157+
8158 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8159 tracehook_report_syscall_entry(regs))
8160 /*
8161@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8162 {
8163 int step;
8164
8165+#ifdef CONFIG_GRKERNSEC_SETXID
8166+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8167+ gr_delayed_cred_worker();
8168+#endif
8169+
8170 audit_syscall_exit(regs);
8171
8172 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8173diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8174index fea2dba..a779f6b 100644
8175--- a/arch/powerpc/kernel/signal_32.c
8176+++ b/arch/powerpc/kernel/signal_32.c
8177@@ -1002,7 +1002,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8178 /* Save user registers on the stack */
8179 frame = &rt_sf->uc.uc_mcontext;
8180 addr = frame;
8181- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8182+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8183 sigret = 0;
8184 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8185 } else {
8186diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8187index 1e7ba88..17afb1b 100644
8188--- a/arch/powerpc/kernel/signal_64.c
8189+++ b/arch/powerpc/kernel/signal_64.c
8190@@ -763,7 +763,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8191 #endif
8192
8193 /* Set up to return from userspace. */
8194- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8195+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8196 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8197 } else {
8198 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8199diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8200index f783c93..619baf1 100644
8201--- a/arch/powerpc/kernel/traps.c
8202+++ b/arch/powerpc/kernel/traps.c
8203@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8204 return flags;
8205 }
8206
8207+extern void gr_handle_kernel_exploit(void);
8208+
8209 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8210 int signr)
8211 {
8212@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8213 panic("Fatal exception in interrupt");
8214 if (panic_on_oops)
8215 panic("Fatal exception");
8216+
8217+ gr_handle_kernel_exploit();
8218+
8219 do_exit(signr);
8220 }
8221
8222diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8223index 1d9c926..25f4741 100644
8224--- a/arch/powerpc/kernel/vdso.c
8225+++ b/arch/powerpc/kernel/vdso.c
8226@@ -34,6 +34,7 @@
8227 #include <asm/firmware.h>
8228 #include <asm/vdso.h>
8229 #include <asm/vdso_datapage.h>
8230+#include <asm/mman.h>
8231
8232 #include "setup.h"
8233
8234@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8235 vdso_base = VDSO32_MBASE;
8236 #endif
8237
8238- current->mm->context.vdso_base = 0;
8239+ current->mm->context.vdso_base = ~0UL;
8240
8241 /* vDSO has a problem and was disabled, just don't "enable" it for the
8242 * process
8243@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8244 vdso_base = get_unmapped_area(NULL, vdso_base,
8245 (vdso_pages << PAGE_SHIFT) +
8246 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8247- 0, 0);
8248+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8249 if (IS_ERR_VALUE(vdso_base)) {
8250 rc = vdso_base;
8251 goto fail_mmapsem;
8252diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8253index 5eea6f3..5d10396 100644
8254--- a/arch/powerpc/lib/usercopy_64.c
8255+++ b/arch/powerpc/lib/usercopy_64.c
8256@@ -9,22 +9,6 @@
8257 #include <linux/module.h>
8258 #include <asm/uaccess.h>
8259
8260-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8261-{
8262- if (likely(access_ok(VERIFY_READ, from, n)))
8263- n = __copy_from_user(to, from, n);
8264- else
8265- memset(to, 0, n);
8266- return n;
8267-}
8268-
8269-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8270-{
8271- if (likely(access_ok(VERIFY_WRITE, to, n)))
8272- n = __copy_to_user(to, from, n);
8273- return n;
8274-}
8275-
8276 unsigned long copy_in_user(void __user *to, const void __user *from,
8277 unsigned long n)
8278 {
8279@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8280 return n;
8281 }
8282
8283-EXPORT_SYMBOL(copy_from_user);
8284-EXPORT_SYMBOL(copy_to_user);
8285 EXPORT_SYMBOL(copy_in_user);
8286
8287diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8288index 51ab9e7..7d3c78b 100644
8289--- a/arch/powerpc/mm/fault.c
8290+++ b/arch/powerpc/mm/fault.c
8291@@ -33,6 +33,10 @@
8292 #include <linux/magic.h>
8293 #include <linux/ratelimit.h>
8294 #include <linux/context_tracking.h>
8295+#include <linux/slab.h>
8296+#include <linux/pagemap.h>
8297+#include <linux/compiler.h>
8298+#include <linux/unistd.h>
8299
8300 #include <asm/firmware.h>
8301 #include <asm/page.h>
8302@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8303 }
8304 #endif
8305
8306+#ifdef CONFIG_PAX_PAGEEXEC
8307+/*
8308+ * PaX: decide what to do with offenders (regs->nip = fault address)
8309+ *
8310+ * returns 1 when task should be killed
8311+ */
8312+static int pax_handle_fetch_fault(struct pt_regs *regs)
8313+{
8314+ return 1;
8315+}
8316+
8317+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8318+{
8319+ unsigned long i;
8320+
8321+ printk(KERN_ERR "PAX: bytes at PC: ");
8322+ for (i = 0; i < 5; i++) {
8323+ unsigned int c;
8324+ if (get_user(c, (unsigned int __user *)pc+i))
8325+ printk(KERN_CONT "???????? ");
8326+ else
8327+ printk(KERN_CONT "%08x ", c);
8328+ }
8329+ printk("\n");
8330+}
8331+#endif
8332+
8333 /*
8334 * Check whether the instruction at regs->nip is a store using
8335 * an update addressing form which will update r1.
8336@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8337 * indicate errors in DSISR but can validly be set in SRR1.
8338 */
8339 if (trap == 0x400)
8340- error_code &= 0x48200000;
8341+ error_code &= 0x58200000;
8342 else
8343 is_write = error_code & DSISR_ISSTORE;
8344 #else
8345@@ -378,7 +409,7 @@ good_area:
8346 * "undefined". Of those that can be set, this is the only
8347 * one which seems bad.
8348 */
8349- if (error_code & 0x10000000)
8350+ if (error_code & DSISR_GUARDED)
8351 /* Guarded storage error. */
8352 goto bad_area;
8353 #endif /* CONFIG_8xx */
8354@@ -393,7 +424,7 @@ good_area:
8355 * processors use the same I/D cache coherency mechanism
8356 * as embedded.
8357 */
8358- if (error_code & DSISR_PROTFAULT)
8359+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8360 goto bad_area;
8361 #endif /* CONFIG_PPC_STD_MMU */
8362
8363@@ -483,6 +514,23 @@ bad_area:
8364 bad_area_nosemaphore:
8365 /* User mode accesses cause a SIGSEGV */
8366 if (user_mode(regs)) {
8367+
8368+#ifdef CONFIG_PAX_PAGEEXEC
8369+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8370+#ifdef CONFIG_PPC_STD_MMU
8371+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8372+#else
8373+ if (is_exec && regs->nip == address) {
8374+#endif
8375+ switch (pax_handle_fetch_fault(regs)) {
8376+ }
8377+
8378+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8379+ do_group_exit(SIGKILL);
8380+ }
8381+ }
8382+#endif
8383+
8384 _exception(SIGSEGV, regs, code, address);
8385 goto bail;
8386 }
8387diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8388index cb8bdbe..d770680 100644
8389--- a/arch/powerpc/mm/mmap.c
8390+++ b/arch/powerpc/mm/mmap.c
8391@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8392 {
8393 unsigned long rnd = 0;
8394
8395+#ifdef CONFIG_PAX_RANDMMAP
8396+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8397+#endif
8398+
8399 if (current->flags & PF_RANDOMIZE) {
8400 /* 8MB for 32bit, 1GB for 64bit */
8401 if (is_32bit_task())
8402@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8403 */
8404 if (mmap_is_legacy()) {
8405 mm->mmap_base = TASK_UNMAPPED_BASE;
8406+
8407+#ifdef CONFIG_PAX_RANDMMAP
8408+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8409+ mm->mmap_base += mm->delta_mmap;
8410+#endif
8411+
8412 mm->get_unmapped_area = arch_get_unmapped_area;
8413 } else {
8414 mm->mmap_base = mmap_base();
8415+
8416+#ifdef CONFIG_PAX_RANDMMAP
8417+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8418+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8419+#endif
8420+
8421 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8422 }
8423 }
8424diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8425index 7ce9cf3..a964087 100644
8426--- a/arch/powerpc/mm/slice.c
8427+++ b/arch/powerpc/mm/slice.c
8428@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8429 if ((mm->task_size - len) < addr)
8430 return 0;
8431 vma = find_vma(mm, addr);
8432- return (!vma || (addr + len) <= vma->vm_start);
8433+ return check_heap_stack_gap(vma, addr, len, 0);
8434 }
8435
8436 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8437@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8438 info.align_offset = 0;
8439
8440 addr = TASK_UNMAPPED_BASE;
8441+
8442+#ifdef CONFIG_PAX_RANDMMAP
8443+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8444+ addr += mm->delta_mmap;
8445+#endif
8446+
8447 while (addr < TASK_SIZE) {
8448 info.low_limit = addr;
8449 if (!slice_scan_available(addr, available, 1, &addr))
8450@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8451 if (fixed && addr > (mm->task_size - len))
8452 return -EINVAL;
8453
8454+#ifdef CONFIG_PAX_RANDMMAP
8455+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8456+ addr = 0;
8457+#endif
8458+
8459 /* If hint, make sure it matches our alignment restrictions */
8460 if (!fixed && addr) {
8461 addr = _ALIGN_UP(addr, 1ul << pshift);
8462diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8463index 9098692..3d54cd1 100644
8464--- a/arch/powerpc/platforms/cell/spufs/file.c
8465+++ b/arch/powerpc/platforms/cell/spufs/file.c
8466@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8467 return VM_FAULT_NOPAGE;
8468 }
8469
8470-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8471+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8472 unsigned long address,
8473- void *buf, int len, int write)
8474+ void *buf, size_t len, int write)
8475 {
8476 struct spu_context *ctx = vma->vm_file->private_data;
8477 unsigned long offset = address - vma->vm_start;
8478diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8479index c797832..ce575c8 100644
8480--- a/arch/s390/include/asm/atomic.h
8481+++ b/arch/s390/include/asm/atomic.h
8482@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8483 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8484 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8485
8486+#define atomic64_read_unchecked(v) atomic64_read(v)
8487+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8488+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8489+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8490+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8491+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8492+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8493+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8494+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8495+
8496 #define smp_mb__before_atomic_dec() smp_mb()
8497 #define smp_mb__after_atomic_dec() smp_mb()
8498 #define smp_mb__before_atomic_inc() smp_mb()
8499diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8500index 4d7ccac..d03d0ad 100644
8501--- a/arch/s390/include/asm/cache.h
8502+++ b/arch/s390/include/asm/cache.h
8503@@ -9,8 +9,10 @@
8504 #ifndef __ARCH_S390_CACHE_H
8505 #define __ARCH_S390_CACHE_H
8506
8507-#define L1_CACHE_BYTES 256
8508+#include <linux/const.h>
8509+
8510 #define L1_CACHE_SHIFT 8
8511+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8512 #define NET_SKB_PAD 32
8513
8514 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8515diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8516index 78f4f87..598ce39 100644
8517--- a/arch/s390/include/asm/elf.h
8518+++ b/arch/s390/include/asm/elf.h
8519@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8520 the loader. We need to make sure that it is out of the way of the program
8521 that it will "exec", and that there is sufficient room for the brk. */
8522
8523-extern unsigned long randomize_et_dyn(unsigned long base);
8524-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8525+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8526+
8527+#ifdef CONFIG_PAX_ASLR
8528+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8529+
8530+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8531+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8532+#endif
8533
8534 /* This yields a mask that user programs can use to figure out what
8535 instruction set this CPU supports. */
8536@@ -222,9 +228,6 @@ struct linux_binprm;
8537 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8538 int arch_setup_additional_pages(struct linux_binprm *, int);
8539
8540-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8541-#define arch_randomize_brk arch_randomize_brk
8542-
8543 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8544
8545 #endif
8546diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8547index c4a93d6..4d2a9b4 100644
8548--- a/arch/s390/include/asm/exec.h
8549+++ b/arch/s390/include/asm/exec.h
8550@@ -7,6 +7,6 @@
8551 #ifndef __ASM_EXEC_H
8552 #define __ASM_EXEC_H
8553
8554-extern unsigned long arch_align_stack(unsigned long sp);
8555+#define arch_align_stack(x) ((x) & ~0xfUL)
8556
8557 #endif /* __ASM_EXEC_H */
8558diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8559index 9c33ed4..e40cbef 100644
8560--- a/arch/s390/include/asm/uaccess.h
8561+++ b/arch/s390/include/asm/uaccess.h
8562@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8563 copy_to_user(void __user *to, const void *from, unsigned long n)
8564 {
8565 might_fault();
8566+
8567+ if ((long)n < 0)
8568+ return n;
8569+
8570 return __copy_to_user(to, from, n);
8571 }
8572
8573@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8574 static inline unsigned long __must_check
8575 __copy_from_user(void *to, const void __user *from, unsigned long n)
8576 {
8577+ if ((long)n < 0)
8578+ return n;
8579+
8580 if (__builtin_constant_p(n) && (n <= 256))
8581 return uaccess.copy_from_user_small(n, from, to);
8582 else
8583@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8584 static inline unsigned long __must_check
8585 copy_from_user(void *to, const void __user *from, unsigned long n)
8586 {
8587- unsigned int sz = __compiletime_object_size(to);
8588+ size_t sz = __compiletime_object_size(to);
8589
8590 might_fault();
8591- if (unlikely(sz != -1 && sz < n)) {
8592+
8593+ if ((long)n < 0)
8594+ return n;
8595+
8596+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8597 copy_from_user_overflow();
8598 return n;
8599 }
8600diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8601index 7845e15..59c4353 100644
8602--- a/arch/s390/kernel/module.c
8603+++ b/arch/s390/kernel/module.c
8604@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8605
8606 /* Increase core size by size of got & plt and set start
8607 offsets for got and plt. */
8608- me->core_size = ALIGN(me->core_size, 4);
8609- me->arch.got_offset = me->core_size;
8610- me->core_size += me->arch.got_size;
8611- me->arch.plt_offset = me->core_size;
8612- me->core_size += me->arch.plt_size;
8613+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8614+ me->arch.got_offset = me->core_size_rw;
8615+ me->core_size_rw += me->arch.got_size;
8616+ me->arch.plt_offset = me->core_size_rx;
8617+ me->core_size_rx += me->arch.plt_size;
8618 return 0;
8619 }
8620
8621@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8622 if (info->got_initialized == 0) {
8623 Elf_Addr *gotent;
8624
8625- gotent = me->module_core + me->arch.got_offset +
8626+ gotent = me->module_core_rw + me->arch.got_offset +
8627 info->got_offset;
8628 *gotent = val;
8629 info->got_initialized = 1;
8630@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8631 rc = apply_rela_bits(loc, val, 0, 64, 0);
8632 else if (r_type == R_390_GOTENT ||
8633 r_type == R_390_GOTPLTENT) {
8634- val += (Elf_Addr) me->module_core - loc;
8635+ val += (Elf_Addr) me->module_core_rw - loc;
8636 rc = apply_rela_bits(loc, val, 1, 32, 1);
8637 }
8638 break;
8639@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8640 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8641 if (info->plt_initialized == 0) {
8642 unsigned int *ip;
8643- ip = me->module_core + me->arch.plt_offset +
8644+ ip = me->module_core_rx + me->arch.plt_offset +
8645 info->plt_offset;
8646 #ifndef CONFIG_64BIT
8647 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8648@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8649 val - loc + 0xffffUL < 0x1ffffeUL) ||
8650 (r_type == R_390_PLT32DBL &&
8651 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8652- val = (Elf_Addr) me->module_core +
8653+ val = (Elf_Addr) me->module_core_rx +
8654 me->arch.plt_offset +
8655 info->plt_offset;
8656 val += rela->r_addend - loc;
8657@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8658 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8659 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8660 val = val + rela->r_addend -
8661- ((Elf_Addr) me->module_core + me->arch.got_offset);
8662+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8663 if (r_type == R_390_GOTOFF16)
8664 rc = apply_rela_bits(loc, val, 0, 16, 0);
8665 else if (r_type == R_390_GOTOFF32)
8666@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8667 break;
8668 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8669 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8670- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8671+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8672 rela->r_addend - loc;
8673 if (r_type == R_390_GOTPC)
8674 rc = apply_rela_bits(loc, val, 1, 32, 0);
8675diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8676index c5dbb33..b41f4ee 100644
8677--- a/arch/s390/kernel/process.c
8678+++ b/arch/s390/kernel/process.c
8679@@ -237,39 +237,3 @@ unsigned long get_wchan(struct task_struct *p)
8680 }
8681 return 0;
8682 }
8683-
8684-unsigned long arch_align_stack(unsigned long sp)
8685-{
8686- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8687- sp -= get_random_int() & ~PAGE_MASK;
8688- return sp & ~0xf;
8689-}
8690-
8691-static inline unsigned long brk_rnd(void)
8692-{
8693- /* 8MB for 32bit, 1GB for 64bit */
8694- if (is_32bit_task())
8695- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8696- else
8697- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8698-}
8699-
8700-unsigned long arch_randomize_brk(struct mm_struct *mm)
8701-{
8702- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8703-
8704- if (ret < mm->brk)
8705- return mm->brk;
8706- return ret;
8707-}
8708-
8709-unsigned long randomize_et_dyn(unsigned long base)
8710-{
8711- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8712-
8713- if (!(current->flags & PF_RANDOMIZE))
8714- return base;
8715- if (ret < base)
8716- return base;
8717- return ret;
8718-}
8719diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8720index 4002329..99b67cb 100644
8721--- a/arch/s390/mm/mmap.c
8722+++ b/arch/s390/mm/mmap.c
8723@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8724 */
8725 if (mmap_is_legacy()) {
8726 mm->mmap_base = TASK_UNMAPPED_BASE;
8727+
8728+#ifdef CONFIG_PAX_RANDMMAP
8729+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8730+ mm->mmap_base += mm->delta_mmap;
8731+#endif
8732+
8733 mm->get_unmapped_area = arch_get_unmapped_area;
8734 } else {
8735 mm->mmap_base = mmap_base();
8736+
8737+#ifdef CONFIG_PAX_RANDMMAP
8738+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8739+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8740+#endif
8741+
8742 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8743 }
8744 }
8745@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8746 */
8747 if (mmap_is_legacy()) {
8748 mm->mmap_base = TASK_UNMAPPED_BASE;
8749+
8750+#ifdef CONFIG_PAX_RANDMMAP
8751+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8752+ mm->mmap_base += mm->delta_mmap;
8753+#endif
8754+
8755 mm->get_unmapped_area = s390_get_unmapped_area;
8756 } else {
8757 mm->mmap_base = mmap_base();
8758+
8759+#ifdef CONFIG_PAX_RANDMMAP
8760+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8761+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8762+#endif
8763+
8764 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8765 }
8766 }
8767diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8768index ae3d59f..f65f075 100644
8769--- a/arch/score/include/asm/cache.h
8770+++ b/arch/score/include/asm/cache.h
8771@@ -1,7 +1,9 @@
8772 #ifndef _ASM_SCORE_CACHE_H
8773 #define _ASM_SCORE_CACHE_H
8774
8775+#include <linux/const.h>
8776+
8777 #define L1_CACHE_SHIFT 4
8778-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8779+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8780
8781 #endif /* _ASM_SCORE_CACHE_H */
8782diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8783index f9f3cd5..58ff438 100644
8784--- a/arch/score/include/asm/exec.h
8785+++ b/arch/score/include/asm/exec.h
8786@@ -1,6 +1,6 @@
8787 #ifndef _ASM_SCORE_EXEC_H
8788 #define _ASM_SCORE_EXEC_H
8789
8790-extern unsigned long arch_align_stack(unsigned long sp);
8791+#define arch_align_stack(x) (x)
8792
8793 #endif /* _ASM_SCORE_EXEC_H */
8794diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8795index a1519ad3..e8ac1ff 100644
8796--- a/arch/score/kernel/process.c
8797+++ b/arch/score/kernel/process.c
8798@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8799
8800 return task_pt_regs(task)->cp0_epc;
8801 }
8802-
8803-unsigned long arch_align_stack(unsigned long sp)
8804-{
8805- return sp;
8806-}
8807diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8808index ef9e555..331bd29 100644
8809--- a/arch/sh/include/asm/cache.h
8810+++ b/arch/sh/include/asm/cache.h
8811@@ -9,10 +9,11 @@
8812 #define __ASM_SH_CACHE_H
8813 #ifdef __KERNEL__
8814
8815+#include <linux/const.h>
8816 #include <linux/init.h>
8817 #include <cpu/cache.h>
8818
8819-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8820+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8821
8822 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8823
8824diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8825index 6777177..cb5e44f 100644
8826--- a/arch/sh/mm/mmap.c
8827+++ b/arch/sh/mm/mmap.c
8828@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8829 struct mm_struct *mm = current->mm;
8830 struct vm_area_struct *vma;
8831 int do_colour_align;
8832+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8833 struct vm_unmapped_area_info info;
8834
8835 if (flags & MAP_FIXED) {
8836@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8837 if (filp || (flags & MAP_SHARED))
8838 do_colour_align = 1;
8839
8840+#ifdef CONFIG_PAX_RANDMMAP
8841+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8842+#endif
8843+
8844 if (addr) {
8845 if (do_colour_align)
8846 addr = COLOUR_ALIGN(addr, pgoff);
8847@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8848 addr = PAGE_ALIGN(addr);
8849
8850 vma = find_vma(mm, addr);
8851- if (TASK_SIZE - len >= addr &&
8852- (!vma || addr + len <= vma->vm_start))
8853+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8854 return addr;
8855 }
8856
8857 info.flags = 0;
8858 info.length = len;
8859- info.low_limit = TASK_UNMAPPED_BASE;
8860+ info.low_limit = mm->mmap_base;
8861 info.high_limit = TASK_SIZE;
8862 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8863 info.align_offset = pgoff << PAGE_SHIFT;
8864@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8865 struct mm_struct *mm = current->mm;
8866 unsigned long addr = addr0;
8867 int do_colour_align;
8868+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8869 struct vm_unmapped_area_info info;
8870
8871 if (flags & MAP_FIXED) {
8872@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8873 if (filp || (flags & MAP_SHARED))
8874 do_colour_align = 1;
8875
8876+#ifdef CONFIG_PAX_RANDMMAP
8877+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8878+#endif
8879+
8880 /* requesting a specific address */
8881 if (addr) {
8882 if (do_colour_align)
8883@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8884 addr = PAGE_ALIGN(addr);
8885
8886 vma = find_vma(mm, addr);
8887- if (TASK_SIZE - len >= addr &&
8888- (!vma || addr + len <= vma->vm_start))
8889+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8890 return addr;
8891 }
8892
8893@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8894 VM_BUG_ON(addr != -ENOMEM);
8895 info.flags = 0;
8896 info.low_limit = TASK_UNMAPPED_BASE;
8897+
8898+#ifdef CONFIG_PAX_RANDMMAP
8899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8900+ info.low_limit += mm->delta_mmap;
8901+#endif
8902+
8903 info.high_limit = TASK_SIZE;
8904 addr = vm_unmapped_area(&info);
8905 }
8906diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8907index be56a24..443328f 100644
8908--- a/arch/sparc/include/asm/atomic_64.h
8909+++ b/arch/sparc/include/asm/atomic_64.h
8910@@ -14,18 +14,40 @@
8911 #define ATOMIC64_INIT(i) { (i) }
8912
8913 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8914+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8915+{
8916+ return v->counter;
8917+}
8918 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8919+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8920+{
8921+ return v->counter;
8922+}
8923
8924 #define atomic_set(v, i) (((v)->counter) = i)
8925+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8926+{
8927+ v->counter = i;
8928+}
8929 #define atomic64_set(v, i) (((v)->counter) = i)
8930+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8931+{
8932+ v->counter = i;
8933+}
8934
8935 extern void atomic_add(int, atomic_t *);
8936+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8937 extern void atomic64_add(long, atomic64_t *);
8938+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8939 extern void atomic_sub(int, atomic_t *);
8940+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8941 extern void atomic64_sub(long, atomic64_t *);
8942+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8943
8944 extern int atomic_add_ret(int, atomic_t *);
8945+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8946 extern long atomic64_add_ret(long, atomic64_t *);
8947+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8948 extern int atomic_sub_ret(int, atomic_t *);
8949 extern long atomic64_sub_ret(long, atomic64_t *);
8950
8951@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8952 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8953
8954 #define atomic_inc_return(v) atomic_add_ret(1, v)
8955+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8956+{
8957+ return atomic_add_ret_unchecked(1, v);
8958+}
8959 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8960+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8961+{
8962+ return atomic64_add_ret_unchecked(1, v);
8963+}
8964
8965 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8966 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8967
8968 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8969+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8970+{
8971+ return atomic_add_ret_unchecked(i, v);
8972+}
8973 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8974+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8975+{
8976+ return atomic64_add_ret_unchecked(i, v);
8977+}
8978
8979 /*
8980 * atomic_inc_and_test - increment and test
8981@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8982 * other cases.
8983 */
8984 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8985+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8986+{
8987+ return atomic_inc_return_unchecked(v) == 0;
8988+}
8989 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8990
8991 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8992@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8993 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8994
8995 #define atomic_inc(v) atomic_add(1, v)
8996+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8997+{
8998+ atomic_add_unchecked(1, v);
8999+}
9000 #define atomic64_inc(v) atomic64_add(1, v)
9001+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9002+{
9003+ atomic64_add_unchecked(1, v);
9004+}
9005
9006 #define atomic_dec(v) atomic_sub(1, v)
9007+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9008+{
9009+ atomic_sub_unchecked(1, v);
9010+}
9011 #define atomic64_dec(v) atomic64_sub(1, v)
9012+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9013+{
9014+ atomic64_sub_unchecked(1, v);
9015+}
9016
9017 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9018 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9019
9020 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9021+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9022+{
9023+ return cmpxchg(&v->counter, old, new);
9024+}
9025 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9026+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9027+{
9028+ return xchg(&v->counter, new);
9029+}
9030
9031 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9032 {
9033- int c, old;
9034+ int c, old, new;
9035 c = atomic_read(v);
9036 for (;;) {
9037- if (unlikely(c == (u)))
9038+ if (unlikely(c == u))
9039 break;
9040- old = atomic_cmpxchg((v), c, c + (a));
9041+
9042+ asm volatile("addcc %2, %0, %0\n"
9043+
9044+#ifdef CONFIG_PAX_REFCOUNT
9045+ "tvs %%icc, 6\n"
9046+#endif
9047+
9048+ : "=r" (new)
9049+ : "0" (c), "ir" (a)
9050+ : "cc");
9051+
9052+ old = atomic_cmpxchg(v, c, new);
9053 if (likely(old == c))
9054 break;
9055 c = old;
9056@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9057 #define atomic64_cmpxchg(v, o, n) \
9058 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9059 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9060+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9061+{
9062+ return xchg(&v->counter, new);
9063+}
9064
9065 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9066 {
9067- long c, old;
9068+ long c, old, new;
9069 c = atomic64_read(v);
9070 for (;;) {
9071- if (unlikely(c == (u)))
9072+ if (unlikely(c == u))
9073 break;
9074- old = atomic64_cmpxchg((v), c, c + (a));
9075+
9076+ asm volatile("addcc %2, %0, %0\n"
9077+
9078+#ifdef CONFIG_PAX_REFCOUNT
9079+ "tvs %%xcc, 6\n"
9080+#endif
9081+
9082+ : "=r" (new)
9083+ : "0" (c), "ir" (a)
9084+ : "cc");
9085+
9086+ old = atomic64_cmpxchg(v, c, new);
9087 if (likely(old == c))
9088 break;
9089 c = old;
9090 }
9091- return c != (u);
9092+ return c != u;
9093 }
9094
9095 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9096diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9097index 5bb6991..5c2132e 100644
9098--- a/arch/sparc/include/asm/cache.h
9099+++ b/arch/sparc/include/asm/cache.h
9100@@ -7,10 +7,12 @@
9101 #ifndef _SPARC_CACHE_H
9102 #define _SPARC_CACHE_H
9103
9104+#include <linux/const.h>
9105+
9106 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9107
9108 #define L1_CACHE_SHIFT 5
9109-#define L1_CACHE_BYTES 32
9110+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9111
9112 #ifdef CONFIG_SPARC32
9113 #define SMP_CACHE_BYTES_SHIFT 5
9114diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9115index a24e41f..47677ff 100644
9116--- a/arch/sparc/include/asm/elf_32.h
9117+++ b/arch/sparc/include/asm/elf_32.h
9118@@ -114,6 +114,13 @@ typedef struct {
9119
9120 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9121
9122+#ifdef CONFIG_PAX_ASLR
9123+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9124+
9125+#define PAX_DELTA_MMAP_LEN 16
9126+#define PAX_DELTA_STACK_LEN 16
9127+#endif
9128+
9129 /* This yields a mask that user programs can use to figure out what
9130 instruction set this cpu supports. This can NOT be done in userspace
9131 on Sparc. */
9132diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9133index 370ca1e..d4f4a98 100644
9134--- a/arch/sparc/include/asm/elf_64.h
9135+++ b/arch/sparc/include/asm/elf_64.h
9136@@ -189,6 +189,13 @@ typedef struct {
9137 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9138 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9139
9140+#ifdef CONFIG_PAX_ASLR
9141+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9142+
9143+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9144+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9145+#endif
9146+
9147 extern unsigned long sparc64_elf_hwcap;
9148 #define ELF_HWCAP sparc64_elf_hwcap
9149
9150diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9151index 9b1c36d..209298b 100644
9152--- a/arch/sparc/include/asm/pgalloc_32.h
9153+++ b/arch/sparc/include/asm/pgalloc_32.h
9154@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9155 }
9156
9157 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9158+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9159
9160 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9161 unsigned long address)
9162diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9163index bcfe063..b333142 100644
9164--- a/arch/sparc/include/asm/pgalloc_64.h
9165+++ b/arch/sparc/include/asm/pgalloc_64.h
9166@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9167 }
9168
9169 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9170+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9171
9172 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9173 {
9174diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9175index 502f632..da1917f 100644
9176--- a/arch/sparc/include/asm/pgtable_32.h
9177+++ b/arch/sparc/include/asm/pgtable_32.h
9178@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9179 #define PAGE_SHARED SRMMU_PAGE_SHARED
9180 #define PAGE_COPY SRMMU_PAGE_COPY
9181 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9182+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9183+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9184+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9185 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9186
9187 /* Top-level page directory - dummy used by init-mm.
9188@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9189
9190 /* xwr */
9191 #define __P000 PAGE_NONE
9192-#define __P001 PAGE_READONLY
9193-#define __P010 PAGE_COPY
9194-#define __P011 PAGE_COPY
9195+#define __P001 PAGE_READONLY_NOEXEC
9196+#define __P010 PAGE_COPY_NOEXEC
9197+#define __P011 PAGE_COPY_NOEXEC
9198 #define __P100 PAGE_READONLY
9199 #define __P101 PAGE_READONLY
9200 #define __P110 PAGE_COPY
9201 #define __P111 PAGE_COPY
9202
9203 #define __S000 PAGE_NONE
9204-#define __S001 PAGE_READONLY
9205-#define __S010 PAGE_SHARED
9206-#define __S011 PAGE_SHARED
9207+#define __S001 PAGE_READONLY_NOEXEC
9208+#define __S010 PAGE_SHARED_NOEXEC
9209+#define __S011 PAGE_SHARED_NOEXEC
9210 #define __S100 PAGE_READONLY
9211 #define __S101 PAGE_READONLY
9212 #define __S110 PAGE_SHARED
9213diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9214index 79da178..c2eede8 100644
9215--- a/arch/sparc/include/asm/pgtsrmmu.h
9216+++ b/arch/sparc/include/asm/pgtsrmmu.h
9217@@ -115,6 +115,11 @@
9218 SRMMU_EXEC | SRMMU_REF)
9219 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9220 SRMMU_EXEC | SRMMU_REF)
9221+
9222+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9223+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9224+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9225+
9226 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9227 SRMMU_DIRTY | SRMMU_REF)
9228
9229diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9230index 9689176..63c18ea 100644
9231--- a/arch/sparc/include/asm/spinlock_64.h
9232+++ b/arch/sparc/include/asm/spinlock_64.h
9233@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9234
9235 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9236
9237-static void inline arch_read_lock(arch_rwlock_t *lock)
9238+static inline void arch_read_lock(arch_rwlock_t *lock)
9239 {
9240 unsigned long tmp1, tmp2;
9241
9242 __asm__ __volatile__ (
9243 "1: ldsw [%2], %0\n"
9244 " brlz,pn %0, 2f\n"
9245-"4: add %0, 1, %1\n"
9246+"4: addcc %0, 1, %1\n"
9247+
9248+#ifdef CONFIG_PAX_REFCOUNT
9249+" tvs %%icc, 6\n"
9250+#endif
9251+
9252 " cas [%2], %0, %1\n"
9253 " cmp %0, %1\n"
9254 " bne,pn %%icc, 1b\n"
9255@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9256 " .previous"
9257 : "=&r" (tmp1), "=&r" (tmp2)
9258 : "r" (lock)
9259- : "memory");
9260+ : "memory", "cc");
9261 }
9262
9263-static int inline arch_read_trylock(arch_rwlock_t *lock)
9264+static inline int arch_read_trylock(arch_rwlock_t *lock)
9265 {
9266 int tmp1, tmp2;
9267
9268@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9269 "1: ldsw [%2], %0\n"
9270 " brlz,a,pn %0, 2f\n"
9271 " mov 0, %0\n"
9272-" add %0, 1, %1\n"
9273+" addcc %0, 1, %1\n"
9274+
9275+#ifdef CONFIG_PAX_REFCOUNT
9276+" tvs %%icc, 6\n"
9277+#endif
9278+
9279 " cas [%2], %0, %1\n"
9280 " cmp %0, %1\n"
9281 " bne,pn %%icc, 1b\n"
9282@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9283 return tmp1;
9284 }
9285
9286-static void inline arch_read_unlock(arch_rwlock_t *lock)
9287+static inline void arch_read_unlock(arch_rwlock_t *lock)
9288 {
9289 unsigned long tmp1, tmp2;
9290
9291 __asm__ __volatile__(
9292 "1: lduw [%2], %0\n"
9293-" sub %0, 1, %1\n"
9294+" subcc %0, 1, %1\n"
9295+
9296+#ifdef CONFIG_PAX_REFCOUNT
9297+" tvs %%icc, 6\n"
9298+#endif
9299+
9300 " cas [%2], %0, %1\n"
9301 " cmp %0, %1\n"
9302 " bne,pn %%xcc, 1b\n"
9303@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9304 : "memory");
9305 }
9306
9307-static void inline arch_write_lock(arch_rwlock_t *lock)
9308+static inline void arch_write_lock(arch_rwlock_t *lock)
9309 {
9310 unsigned long mask, tmp1, tmp2;
9311
9312@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9313 : "memory");
9314 }
9315
9316-static void inline arch_write_unlock(arch_rwlock_t *lock)
9317+static inline void arch_write_unlock(arch_rwlock_t *lock)
9318 {
9319 __asm__ __volatile__(
9320 " stw %%g0, [%0]"
9321@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9322 : "memory");
9323 }
9324
9325-static int inline arch_write_trylock(arch_rwlock_t *lock)
9326+static inline int arch_write_trylock(arch_rwlock_t *lock)
9327 {
9328 unsigned long mask, tmp1, tmp2, result;
9329
9330diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9331index dd38075..e7cac83 100644
9332--- a/arch/sparc/include/asm/thread_info_32.h
9333+++ b/arch/sparc/include/asm/thread_info_32.h
9334@@ -49,6 +49,8 @@ struct thread_info {
9335 unsigned long w_saved;
9336
9337 struct restart_block restart_block;
9338+
9339+ unsigned long lowest_stack;
9340 };
9341
9342 /*
9343diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9344index d5e5042..9bfee76 100644
9345--- a/arch/sparc/include/asm/thread_info_64.h
9346+++ b/arch/sparc/include/asm/thread_info_64.h
9347@@ -63,6 +63,8 @@ struct thread_info {
9348 struct pt_regs *kern_una_regs;
9349 unsigned int kern_una_insn;
9350
9351+ unsigned long lowest_stack;
9352+
9353 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9354 };
9355
9356@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9357 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9358 /* flag bit 6 is available */
9359 #define TIF_32BIT 7 /* 32-bit binary */
9360-/* flag bit 8 is available */
9361+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9362 #define TIF_SECCOMP 9 /* secure computing */
9363 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9364 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9365+
9366 /* NOTE: Thread flags >= 12 should be ones we have no interest
9367 * in using in assembly, else we can't use the mask as
9368 * an immediate value in instructions such as andcc.
9369@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9370 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9371 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9372 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9373+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9374
9375 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9376 _TIF_DO_NOTIFY_RESUME_MASK | \
9377 _TIF_NEED_RESCHED)
9378 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9379
9380+#define _TIF_WORK_SYSCALL \
9381+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9382+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9383+
9384+
9385 /*
9386 * Thread-synchronous status.
9387 *
9388diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9389index 0167d26..767bb0c 100644
9390--- a/arch/sparc/include/asm/uaccess.h
9391+++ b/arch/sparc/include/asm/uaccess.h
9392@@ -1,5 +1,6 @@
9393 #ifndef ___ASM_SPARC_UACCESS_H
9394 #define ___ASM_SPARC_UACCESS_H
9395+
9396 #if defined(__sparc__) && defined(__arch64__)
9397 #include <asm/uaccess_64.h>
9398 #else
9399diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9400index 53a28dd..50c38c3 100644
9401--- a/arch/sparc/include/asm/uaccess_32.h
9402+++ b/arch/sparc/include/asm/uaccess_32.h
9403@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9404
9405 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9406 {
9407- if (n && __access_ok((unsigned long) to, n))
9408+ if ((long)n < 0)
9409+ return n;
9410+
9411+ if (n && __access_ok((unsigned long) to, n)) {
9412+ if (!__builtin_constant_p(n))
9413+ check_object_size(from, n, true);
9414 return __copy_user(to, (__force void __user *) from, n);
9415- else
9416+ } else
9417 return n;
9418 }
9419
9420 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9421 {
9422+ if ((long)n < 0)
9423+ return n;
9424+
9425+ if (!__builtin_constant_p(n))
9426+ check_object_size(from, n, true);
9427+
9428 return __copy_user(to, (__force void __user *) from, n);
9429 }
9430
9431 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9432 {
9433- if (n && __access_ok((unsigned long) from, n))
9434+ if ((long)n < 0)
9435+ return n;
9436+
9437+ if (n && __access_ok((unsigned long) from, n)) {
9438+ if (!__builtin_constant_p(n))
9439+ check_object_size(to, n, false);
9440 return __copy_user((__force void __user *) to, from, n);
9441- else
9442+ } else
9443 return n;
9444 }
9445
9446 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9447 {
9448+ if ((long)n < 0)
9449+ return n;
9450+
9451 return __copy_user((__force void __user *) to, from, n);
9452 }
9453
9454diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9455index e562d3c..191f176 100644
9456--- a/arch/sparc/include/asm/uaccess_64.h
9457+++ b/arch/sparc/include/asm/uaccess_64.h
9458@@ -10,6 +10,7 @@
9459 #include <linux/compiler.h>
9460 #include <linux/string.h>
9461 #include <linux/thread_info.h>
9462+#include <linux/kernel.h>
9463 #include <asm/asi.h>
9464 #include <asm/spitfire.h>
9465 #include <asm-generic/uaccess-unaligned.h>
9466@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9467 static inline unsigned long __must_check
9468 copy_from_user(void *to, const void __user *from, unsigned long size)
9469 {
9470- unsigned long ret = ___copy_from_user(to, from, size);
9471+ unsigned long ret;
9472
9473+ if ((long)size < 0 || size > INT_MAX)
9474+ return size;
9475+
9476+ if (!__builtin_constant_p(size))
9477+ check_object_size(to, size, false);
9478+
9479+ ret = ___copy_from_user(to, from, size);
9480 if (unlikely(ret))
9481 ret = copy_from_user_fixup(to, from, size);
9482
9483@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9484 static inline unsigned long __must_check
9485 copy_to_user(void __user *to, const void *from, unsigned long size)
9486 {
9487- unsigned long ret = ___copy_to_user(to, from, size);
9488+ unsigned long ret;
9489
9490+ if ((long)size < 0 || size > INT_MAX)
9491+ return size;
9492+
9493+ if (!__builtin_constant_p(size))
9494+ check_object_size(from, size, true);
9495+
9496+ ret = ___copy_to_user(to, from, size);
9497 if (unlikely(ret))
9498 ret = copy_to_user_fixup(to, from, size);
9499 return ret;
9500diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9501index d15cc17..d0ae796 100644
9502--- a/arch/sparc/kernel/Makefile
9503+++ b/arch/sparc/kernel/Makefile
9504@@ -4,7 +4,7 @@
9505 #
9506
9507 asflags-y := -ansi
9508-ccflags-y := -Werror
9509+#ccflags-y := -Werror
9510
9511 extra-y := head_$(BITS).o
9512
9513diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9514index fdd819d..5af08c8 100644
9515--- a/arch/sparc/kernel/process_32.c
9516+++ b/arch/sparc/kernel/process_32.c
9517@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9518
9519 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9520 r->psr, r->pc, r->npc, r->y, print_tainted());
9521- printk("PC: <%pS>\n", (void *) r->pc);
9522+ printk("PC: <%pA>\n", (void *) r->pc);
9523 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9524 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9525 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9526 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9527 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9528 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9529- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9530+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9531
9532 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9533 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9534@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9535 rw = (struct reg_window32 *) fp;
9536 pc = rw->ins[7];
9537 printk("[%08lx : ", pc);
9538- printk("%pS ] ", (void *) pc);
9539+ printk("%pA ] ", (void *) pc);
9540 fp = rw->ins[6];
9541 } while (++count < 16);
9542 printk("\n");
9543diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9544index baebab2..9cd13b1 100644
9545--- a/arch/sparc/kernel/process_64.c
9546+++ b/arch/sparc/kernel/process_64.c
9547@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9548 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9549 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9550 if (regs->tstate & TSTATE_PRIV)
9551- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9552+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9553 }
9554
9555 void show_regs(struct pt_regs *regs)
9556@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9557
9558 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9559 regs->tpc, regs->tnpc, regs->y, print_tainted());
9560- printk("TPC: <%pS>\n", (void *) regs->tpc);
9561+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9562 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9563 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9564 regs->u_regs[3]);
9565@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9566 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9567 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9568 regs->u_regs[15]);
9569- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9570+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9571 show_regwindow(regs);
9572 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9573 }
9574@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9575 ((tp && tp->task) ? tp->task->pid : -1));
9576
9577 if (gp->tstate & TSTATE_PRIV) {
9578- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9579+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9580 (void *) gp->tpc,
9581 (void *) gp->o7,
9582 (void *) gp->i7,
9583diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9584index 79cc0d1..ec62734 100644
9585--- a/arch/sparc/kernel/prom_common.c
9586+++ b/arch/sparc/kernel/prom_common.c
9587@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9588
9589 unsigned int prom_early_allocated __initdata;
9590
9591-static struct of_pdt_ops prom_sparc_ops __initdata = {
9592+static struct of_pdt_ops prom_sparc_ops __initconst = {
9593 .nextprop = prom_common_nextprop,
9594 .getproplen = prom_getproplen,
9595 .getproperty = prom_getproperty,
9596diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9597index 773c1f2..a8bdd87 100644
9598--- a/arch/sparc/kernel/ptrace_64.c
9599+++ b/arch/sparc/kernel/ptrace_64.c
9600@@ -1059,6 +1059,10 @@ long arch_ptrace(struct task_struct *child, long request,
9601 return ret;
9602 }
9603
9604+#ifdef CONFIG_GRKERNSEC_SETXID
9605+extern void gr_delayed_cred_worker(void);
9606+#endif
9607+
9608 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9609 {
9610 int ret = 0;
9611@@ -1066,6 +1070,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9612 /* do the secure computing check first */
9613 secure_computing_strict(regs->u_regs[UREG_G1]);
9614
9615+#ifdef CONFIG_GRKERNSEC_SETXID
9616+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9617+ gr_delayed_cred_worker();
9618+#endif
9619+
9620 if (test_thread_flag(TIF_SYSCALL_TRACE))
9621 ret = tracehook_report_syscall_entry(regs);
9622
9623@@ -1086,6 +1095,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9624
9625 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9626 {
9627+#ifdef CONFIG_GRKERNSEC_SETXID
9628+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9629+ gr_delayed_cred_worker();
9630+#endif
9631+
9632 audit_syscall_exit(regs);
9633
9634 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9635diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9636index e142545..fd29654 100644
9637--- a/arch/sparc/kernel/smp_64.c
9638+++ b/arch/sparc/kernel/smp_64.c
9639@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9640 extern unsigned long xcall_flush_dcache_page_spitfire;
9641
9642 #ifdef CONFIG_DEBUG_DCFLUSH
9643-extern atomic_t dcpage_flushes;
9644-extern atomic_t dcpage_flushes_xcall;
9645+extern atomic_unchecked_t dcpage_flushes;
9646+extern atomic_unchecked_t dcpage_flushes_xcall;
9647 #endif
9648
9649 static inline void __local_flush_dcache_page(struct page *page)
9650@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9651 return;
9652
9653 #ifdef CONFIG_DEBUG_DCFLUSH
9654- atomic_inc(&dcpage_flushes);
9655+ atomic_inc_unchecked(&dcpage_flushes);
9656 #endif
9657
9658 this_cpu = get_cpu();
9659@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9660 xcall_deliver(data0, __pa(pg_addr),
9661 (u64) pg_addr, cpumask_of(cpu));
9662 #ifdef CONFIG_DEBUG_DCFLUSH
9663- atomic_inc(&dcpage_flushes_xcall);
9664+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9665 #endif
9666 }
9667 }
9668@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9669 preempt_disable();
9670
9671 #ifdef CONFIG_DEBUG_DCFLUSH
9672- atomic_inc(&dcpage_flushes);
9673+ atomic_inc_unchecked(&dcpage_flushes);
9674 #endif
9675 data0 = 0;
9676 pg_addr = page_address(page);
9677@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9678 xcall_deliver(data0, __pa(pg_addr),
9679 (u64) pg_addr, cpu_online_mask);
9680 #ifdef CONFIG_DEBUG_DCFLUSH
9681- atomic_inc(&dcpage_flushes_xcall);
9682+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9683 #endif
9684 }
9685 __local_flush_dcache_page(page);
9686diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9687index 3a8d184..49498a8 100644
9688--- a/arch/sparc/kernel/sys_sparc_32.c
9689+++ b/arch/sparc/kernel/sys_sparc_32.c
9690@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9691 if (len > TASK_SIZE - PAGE_SIZE)
9692 return -ENOMEM;
9693 if (!addr)
9694- addr = TASK_UNMAPPED_BASE;
9695+ addr = current->mm->mmap_base;
9696
9697 info.flags = 0;
9698 info.length = len;
9699diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9700index 51561b8..8256764 100644
9701--- a/arch/sparc/kernel/sys_sparc_64.c
9702+++ b/arch/sparc/kernel/sys_sparc_64.c
9703@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9704 struct vm_area_struct * vma;
9705 unsigned long task_size = TASK_SIZE;
9706 int do_color_align;
9707+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9708 struct vm_unmapped_area_info info;
9709
9710 if (flags & MAP_FIXED) {
9711 /* We do not accept a shared mapping if it would violate
9712 * cache aliasing constraints.
9713 */
9714- if ((flags & MAP_SHARED) &&
9715+ if ((filp || (flags & MAP_SHARED)) &&
9716 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9717 return -EINVAL;
9718 return addr;
9719@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9720 if (filp || (flags & MAP_SHARED))
9721 do_color_align = 1;
9722
9723+#ifdef CONFIG_PAX_RANDMMAP
9724+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9725+#endif
9726+
9727 if (addr) {
9728 if (do_color_align)
9729 addr = COLOR_ALIGN(addr, pgoff);
9730@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9731 addr = PAGE_ALIGN(addr);
9732
9733 vma = find_vma(mm, addr);
9734- if (task_size - len >= addr &&
9735- (!vma || addr + len <= vma->vm_start))
9736+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9737 return addr;
9738 }
9739
9740 info.flags = 0;
9741 info.length = len;
9742- info.low_limit = TASK_UNMAPPED_BASE;
9743+ info.low_limit = mm->mmap_base;
9744 info.high_limit = min(task_size, VA_EXCLUDE_START);
9745 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9746 info.align_offset = pgoff << PAGE_SHIFT;
9747+ info.threadstack_offset = offset;
9748 addr = vm_unmapped_area(&info);
9749
9750 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9751 VM_BUG_ON(addr != -ENOMEM);
9752 info.low_limit = VA_EXCLUDE_END;
9753+
9754+#ifdef CONFIG_PAX_RANDMMAP
9755+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9756+ info.low_limit += mm->delta_mmap;
9757+#endif
9758+
9759 info.high_limit = task_size;
9760 addr = vm_unmapped_area(&info);
9761 }
9762@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9763 unsigned long task_size = STACK_TOP32;
9764 unsigned long addr = addr0;
9765 int do_color_align;
9766+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9767 struct vm_unmapped_area_info info;
9768
9769 /* This should only ever run for 32-bit processes. */
9770@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9771 /* We do not accept a shared mapping if it would violate
9772 * cache aliasing constraints.
9773 */
9774- if ((flags & MAP_SHARED) &&
9775+ if ((filp || (flags & MAP_SHARED)) &&
9776 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9777 return -EINVAL;
9778 return addr;
9779@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9780 if (filp || (flags & MAP_SHARED))
9781 do_color_align = 1;
9782
9783+#ifdef CONFIG_PAX_RANDMMAP
9784+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9785+#endif
9786+
9787 /* requesting a specific address */
9788 if (addr) {
9789 if (do_color_align)
9790@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9791 addr = PAGE_ALIGN(addr);
9792
9793 vma = find_vma(mm, addr);
9794- if (task_size - len >= addr &&
9795- (!vma || addr + len <= vma->vm_start))
9796+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9797 return addr;
9798 }
9799
9800@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9801 info.high_limit = mm->mmap_base;
9802 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9803 info.align_offset = pgoff << PAGE_SHIFT;
9804+ info.threadstack_offset = offset;
9805 addr = vm_unmapped_area(&info);
9806
9807 /*
9808@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9809 VM_BUG_ON(addr != -ENOMEM);
9810 info.flags = 0;
9811 info.low_limit = TASK_UNMAPPED_BASE;
9812+
9813+#ifdef CONFIG_PAX_RANDMMAP
9814+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9815+ info.low_limit += mm->delta_mmap;
9816+#endif
9817+
9818 info.high_limit = STACK_TOP32;
9819 addr = vm_unmapped_area(&info);
9820 }
9821@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9822 EXPORT_SYMBOL(get_fb_unmapped_area);
9823
9824 /* Essentially the same as PowerPC. */
9825-static unsigned long mmap_rnd(void)
9826+static unsigned long mmap_rnd(struct mm_struct *mm)
9827 {
9828 unsigned long rnd = 0UL;
9829
9830+#ifdef CONFIG_PAX_RANDMMAP
9831+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9832+#endif
9833+
9834 if (current->flags & PF_RANDOMIZE) {
9835 unsigned long val = get_random_int();
9836 if (test_thread_flag(TIF_32BIT))
9837@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9838
9839 void arch_pick_mmap_layout(struct mm_struct *mm)
9840 {
9841- unsigned long random_factor = mmap_rnd();
9842+ unsigned long random_factor = mmap_rnd(mm);
9843 unsigned long gap;
9844
9845 /*
9846@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9847 gap == RLIM_INFINITY ||
9848 sysctl_legacy_va_layout) {
9849 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9850+
9851+#ifdef CONFIG_PAX_RANDMMAP
9852+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9853+ mm->mmap_base += mm->delta_mmap;
9854+#endif
9855+
9856 mm->get_unmapped_area = arch_get_unmapped_area;
9857 } else {
9858 /* We know it's 32-bit */
9859@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9860 gap = (task_size / 6 * 5);
9861
9862 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9863+
9864+#ifdef CONFIG_PAX_RANDMMAP
9865+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9866+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9867+#endif
9868+
9869 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9870 }
9871 }
9872diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9873index d950197..192f9d8 100644
9874--- a/arch/sparc/kernel/syscalls.S
9875+++ b/arch/sparc/kernel/syscalls.S
9876@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9877 #endif
9878 .align 32
9879 1: ldx [%g6 + TI_FLAGS], %l5
9880- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9881+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9882 be,pt %icc, rtrap
9883 nop
9884 call syscall_trace_leave
9885@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9886
9887 srl %i3, 0, %o3 ! IEU0
9888 srl %i2, 0, %o2 ! IEU0 Group
9889- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9890+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9891 bne,pn %icc, linux_syscall_trace32 ! CTI
9892 mov %i0, %l5 ! IEU1
9893 5: call %l7 ! CTI Group brk forced
9894@@ -207,7 +207,7 @@ linux_sparc_syscall:
9895
9896 mov %i3, %o3 ! IEU1
9897 mov %i4, %o4 ! IEU0 Group
9898- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9899+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9900 bne,pn %icc, linux_syscall_trace ! CTI Group
9901 mov %i0, %l5 ! IEU0
9902 2: call %l7 ! CTI Group brk forced
9903@@ -223,7 +223,7 @@ ret_sys_call:
9904
9905 cmp %o0, -ERESTART_RESTARTBLOCK
9906 bgeu,pn %xcc, 1f
9907- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9908+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9909 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9910
9911 2:
9912diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9913index 6629829..036032d 100644
9914--- a/arch/sparc/kernel/traps_32.c
9915+++ b/arch/sparc/kernel/traps_32.c
9916@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9917 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9918 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9919
9920+extern void gr_handle_kernel_exploit(void);
9921+
9922 void die_if_kernel(char *str, struct pt_regs *regs)
9923 {
9924 static int die_counter;
9925@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9926 count++ < 30 &&
9927 (((unsigned long) rw) >= PAGE_OFFSET) &&
9928 !(((unsigned long) rw) & 0x7)) {
9929- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9930+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9931 (void *) rw->ins[7]);
9932 rw = (struct reg_window32 *)rw->ins[6];
9933 }
9934 }
9935 printk("Instruction DUMP:");
9936 instruction_dump ((unsigned long *) regs->pc);
9937- if(regs->psr & PSR_PS)
9938+ if(regs->psr & PSR_PS) {
9939+ gr_handle_kernel_exploit();
9940 do_exit(SIGKILL);
9941+ }
9942 do_exit(SIGSEGV);
9943 }
9944
9945diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9946index b3f833a..f485f80 100644
9947--- a/arch/sparc/kernel/traps_64.c
9948+++ b/arch/sparc/kernel/traps_64.c
9949@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9950 i + 1,
9951 p->trapstack[i].tstate, p->trapstack[i].tpc,
9952 p->trapstack[i].tnpc, p->trapstack[i].tt);
9953- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9954+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9955 }
9956 }
9957
9958@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9959
9960 lvl -= 0x100;
9961 if (regs->tstate & TSTATE_PRIV) {
9962+
9963+#ifdef CONFIG_PAX_REFCOUNT
9964+ if (lvl == 6)
9965+ pax_report_refcount_overflow(regs);
9966+#endif
9967+
9968 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9969 die_if_kernel(buffer, regs);
9970 }
9971@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9972 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9973 {
9974 char buffer[32];
9975-
9976+
9977 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9978 0, lvl, SIGTRAP) == NOTIFY_STOP)
9979 return;
9980
9981+#ifdef CONFIG_PAX_REFCOUNT
9982+ if (lvl == 6)
9983+ pax_report_refcount_overflow(regs);
9984+#endif
9985+
9986 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9987
9988 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9989@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9990 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9991 printk("%s" "ERROR(%d): ",
9992 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9993- printk("TPC<%pS>\n", (void *) regs->tpc);
9994+ printk("TPC<%pA>\n", (void *) regs->tpc);
9995 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9996 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9997 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9998@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9999 smp_processor_id(),
10000 (type & 0x1) ? 'I' : 'D',
10001 regs->tpc);
10002- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10003+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10004 panic("Irrecoverable Cheetah+ parity error.");
10005 }
10006
10007@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10008 smp_processor_id(),
10009 (type & 0x1) ? 'I' : 'D',
10010 regs->tpc);
10011- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10012+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10013 }
10014
10015 struct sun4v_error_entry {
10016@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
10017 /*0x38*/u64 reserved_5;
10018 };
10019
10020-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10021-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10022+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10023+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10024
10025 static const char *sun4v_err_type_to_str(u8 type)
10026 {
10027@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10028 }
10029
10030 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10031- int cpu, const char *pfx, atomic_t *ocnt)
10032+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10033 {
10034 u64 *raw_ptr = (u64 *) ent;
10035 u32 attrs;
10036@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10037
10038 show_regs(regs);
10039
10040- if ((cnt = atomic_read(ocnt)) != 0) {
10041- atomic_set(ocnt, 0);
10042+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10043+ atomic_set_unchecked(ocnt, 0);
10044 wmb();
10045 printk("%s: Queue overflowed %d times.\n",
10046 pfx, cnt);
10047@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10048 */
10049 void sun4v_resum_overflow(struct pt_regs *regs)
10050 {
10051- atomic_inc(&sun4v_resum_oflow_cnt);
10052+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10053 }
10054
10055 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10056@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10057 /* XXX Actually even this can make not that much sense. Perhaps
10058 * XXX we should just pull the plug and panic directly from here?
10059 */
10060- atomic_inc(&sun4v_nonresum_oflow_cnt);
10061+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10062 }
10063
10064 unsigned long sun4v_err_itlb_vaddr;
10065@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10066
10067 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10068 regs->tpc, tl);
10069- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10070+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10071 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10072- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10073+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10074 (void *) regs->u_regs[UREG_I7]);
10075 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10076 "pte[%lx] error[%lx]\n",
10077@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10078
10079 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10080 regs->tpc, tl);
10081- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10082+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10083 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10084- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10085+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10086 (void *) regs->u_regs[UREG_I7]);
10087 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10088 "pte[%lx] error[%lx]\n",
10089@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10090 fp = (unsigned long)sf->fp + STACK_BIAS;
10091 }
10092
10093- printk(" [%016lx] %pS\n", pc, (void *) pc);
10094+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10095 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10096 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10097 int index = tsk->curr_ret_stack;
10098 if (tsk->ret_stack && index >= graph) {
10099 pc = tsk->ret_stack[index - graph].ret;
10100- printk(" [%016lx] %pS\n", pc, (void *) pc);
10101+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10102 graph++;
10103 }
10104 }
10105@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10106 return (struct reg_window *) (fp + STACK_BIAS);
10107 }
10108
10109+extern void gr_handle_kernel_exploit(void);
10110+
10111 void die_if_kernel(char *str, struct pt_regs *regs)
10112 {
10113 static int die_counter;
10114@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10115 while (rw &&
10116 count++ < 30 &&
10117 kstack_valid(tp, (unsigned long) rw)) {
10118- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10119+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10120 (void *) rw->ins[7]);
10121
10122 rw = kernel_stack_up(rw);
10123@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10124 }
10125 user_instruction_dump ((unsigned int __user *) regs->tpc);
10126 }
10127- if (regs->tstate & TSTATE_PRIV)
10128+ if (regs->tstate & TSTATE_PRIV) {
10129+ gr_handle_kernel_exploit();
10130 do_exit(SIGKILL);
10131+ }
10132 do_exit(SIGSEGV);
10133 }
10134 EXPORT_SYMBOL(die_if_kernel);
10135diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10136index 8201c25e..072a2a7 100644
10137--- a/arch/sparc/kernel/unaligned_64.c
10138+++ b/arch/sparc/kernel/unaligned_64.c
10139@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10140 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10141
10142 if (__ratelimit(&ratelimit)) {
10143- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10144+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10145 regs->tpc, (void *) regs->tpc);
10146 }
10147 }
10148diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10149index dbe119b..089c7c1 100644
10150--- a/arch/sparc/lib/Makefile
10151+++ b/arch/sparc/lib/Makefile
10152@@ -2,7 +2,7 @@
10153 #
10154
10155 asflags-y := -ansi -DST_DIV0=0x02
10156-ccflags-y := -Werror
10157+#ccflags-y := -Werror
10158
10159 lib-$(CONFIG_SPARC32) += ashrdi3.o
10160 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10161diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10162index 85c233d..68500e0 100644
10163--- a/arch/sparc/lib/atomic_64.S
10164+++ b/arch/sparc/lib/atomic_64.S
10165@@ -17,7 +17,12 @@
10166 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10167 BACKOFF_SETUP(%o2)
10168 1: lduw [%o1], %g1
10169- add %g1, %o0, %g7
10170+ addcc %g1, %o0, %g7
10171+
10172+#ifdef CONFIG_PAX_REFCOUNT
10173+ tvs %icc, 6
10174+#endif
10175+
10176 cas [%o1], %g1, %g7
10177 cmp %g1, %g7
10178 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10179@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10180 2: BACKOFF_SPIN(%o2, %o3, 1b)
10181 ENDPROC(atomic_add)
10182
10183+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10184+ BACKOFF_SETUP(%o2)
10185+1: lduw [%o1], %g1
10186+ add %g1, %o0, %g7
10187+ cas [%o1], %g1, %g7
10188+ cmp %g1, %g7
10189+ bne,pn %icc, 2f
10190+ nop
10191+ retl
10192+ nop
10193+2: BACKOFF_SPIN(%o2, %o3, 1b)
10194+ENDPROC(atomic_add_unchecked)
10195+
10196 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10197 BACKOFF_SETUP(%o2)
10198 1: lduw [%o1], %g1
10199- sub %g1, %o0, %g7
10200+ subcc %g1, %o0, %g7
10201+
10202+#ifdef CONFIG_PAX_REFCOUNT
10203+ tvs %icc, 6
10204+#endif
10205+
10206 cas [%o1], %g1, %g7
10207 cmp %g1, %g7
10208 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10209@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10210 2: BACKOFF_SPIN(%o2, %o3, 1b)
10211 ENDPROC(atomic_sub)
10212
10213+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10214+ BACKOFF_SETUP(%o2)
10215+1: lduw [%o1], %g1
10216+ sub %g1, %o0, %g7
10217+ cas [%o1], %g1, %g7
10218+ cmp %g1, %g7
10219+ bne,pn %icc, 2f
10220+ nop
10221+ retl
10222+ nop
10223+2: BACKOFF_SPIN(%o2, %o3, 1b)
10224+ENDPROC(atomic_sub_unchecked)
10225+
10226 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10227 BACKOFF_SETUP(%o2)
10228 1: lduw [%o1], %g1
10229- add %g1, %o0, %g7
10230+ addcc %g1, %o0, %g7
10231+
10232+#ifdef CONFIG_PAX_REFCOUNT
10233+ tvs %icc, 6
10234+#endif
10235+
10236 cas [%o1], %g1, %g7
10237 cmp %g1, %g7
10238 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10239@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10240 2: BACKOFF_SPIN(%o2, %o3, 1b)
10241 ENDPROC(atomic_add_ret)
10242
10243+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10244+ BACKOFF_SETUP(%o2)
10245+1: lduw [%o1], %g1
10246+ addcc %g1, %o0, %g7
10247+ cas [%o1], %g1, %g7
10248+ cmp %g1, %g7
10249+ bne,pn %icc, 2f
10250+ add %g7, %o0, %g7
10251+ sra %g7, 0, %o0
10252+ retl
10253+ nop
10254+2: BACKOFF_SPIN(%o2, %o3, 1b)
10255+ENDPROC(atomic_add_ret_unchecked)
10256+
10257 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10258 BACKOFF_SETUP(%o2)
10259 1: lduw [%o1], %g1
10260- sub %g1, %o0, %g7
10261+ subcc %g1, %o0, %g7
10262+
10263+#ifdef CONFIG_PAX_REFCOUNT
10264+ tvs %icc, 6
10265+#endif
10266+
10267 cas [%o1], %g1, %g7
10268 cmp %g1, %g7
10269 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10270@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10271 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10272 BACKOFF_SETUP(%o2)
10273 1: ldx [%o1], %g1
10274- add %g1, %o0, %g7
10275+ addcc %g1, %o0, %g7
10276+
10277+#ifdef CONFIG_PAX_REFCOUNT
10278+ tvs %xcc, 6
10279+#endif
10280+
10281 casx [%o1], %g1, %g7
10282 cmp %g1, %g7
10283 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10284@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10285 2: BACKOFF_SPIN(%o2, %o3, 1b)
10286 ENDPROC(atomic64_add)
10287
10288+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10289+ BACKOFF_SETUP(%o2)
10290+1: ldx [%o1], %g1
10291+ addcc %g1, %o0, %g7
10292+ casx [%o1], %g1, %g7
10293+ cmp %g1, %g7
10294+ bne,pn %xcc, 2f
10295+ nop
10296+ retl
10297+ nop
10298+2: BACKOFF_SPIN(%o2, %o3, 1b)
10299+ENDPROC(atomic64_add_unchecked)
10300+
10301 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10302 BACKOFF_SETUP(%o2)
10303 1: ldx [%o1], %g1
10304- sub %g1, %o0, %g7
10305+ subcc %g1, %o0, %g7
10306+
10307+#ifdef CONFIG_PAX_REFCOUNT
10308+ tvs %xcc, 6
10309+#endif
10310+
10311 casx [%o1], %g1, %g7
10312 cmp %g1, %g7
10313 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10314@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10315 2: BACKOFF_SPIN(%o2, %o3, 1b)
10316 ENDPROC(atomic64_sub)
10317
10318+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10319+ BACKOFF_SETUP(%o2)
10320+1: ldx [%o1], %g1
10321+ subcc %g1, %o0, %g7
10322+ casx [%o1], %g1, %g7
10323+ cmp %g1, %g7
10324+ bne,pn %xcc, 2f
10325+ nop
10326+ retl
10327+ nop
10328+2: BACKOFF_SPIN(%o2, %o3, 1b)
10329+ENDPROC(atomic64_sub_unchecked)
10330+
10331 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10332 BACKOFF_SETUP(%o2)
10333 1: ldx [%o1], %g1
10334- add %g1, %o0, %g7
10335+ addcc %g1, %o0, %g7
10336+
10337+#ifdef CONFIG_PAX_REFCOUNT
10338+ tvs %xcc, 6
10339+#endif
10340+
10341 casx [%o1], %g1, %g7
10342 cmp %g1, %g7
10343 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10344@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10345 2: BACKOFF_SPIN(%o2, %o3, 1b)
10346 ENDPROC(atomic64_add_ret)
10347
10348+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10349+ BACKOFF_SETUP(%o2)
10350+1: ldx [%o1], %g1
10351+ addcc %g1, %o0, %g7
10352+ casx [%o1], %g1, %g7
10353+ cmp %g1, %g7
10354+ bne,pn %xcc, 2f
10355+ add %g7, %o0, %g7
10356+ mov %g7, %o0
10357+ retl
10358+ nop
10359+2: BACKOFF_SPIN(%o2, %o3, 1b)
10360+ENDPROC(atomic64_add_ret_unchecked)
10361+
10362 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10363 BACKOFF_SETUP(%o2)
10364 1: ldx [%o1], %g1
10365- sub %g1, %o0, %g7
10366+ subcc %g1, %o0, %g7
10367+
10368+#ifdef CONFIG_PAX_REFCOUNT
10369+ tvs %xcc, 6
10370+#endif
10371+
10372 casx [%o1], %g1, %g7
10373 cmp %g1, %g7
10374 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10375diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10376index 323335b..ed85ea2 100644
10377--- a/arch/sparc/lib/ksyms.c
10378+++ b/arch/sparc/lib/ksyms.c
10379@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10380
10381 /* Atomic counter implementation. */
10382 EXPORT_SYMBOL(atomic_add);
10383+EXPORT_SYMBOL(atomic_add_unchecked);
10384 EXPORT_SYMBOL(atomic_add_ret);
10385+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10386 EXPORT_SYMBOL(atomic_sub);
10387+EXPORT_SYMBOL(atomic_sub_unchecked);
10388 EXPORT_SYMBOL(atomic_sub_ret);
10389 EXPORT_SYMBOL(atomic64_add);
10390+EXPORT_SYMBOL(atomic64_add_unchecked);
10391 EXPORT_SYMBOL(atomic64_add_ret);
10392+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10393 EXPORT_SYMBOL(atomic64_sub);
10394+EXPORT_SYMBOL(atomic64_sub_unchecked);
10395 EXPORT_SYMBOL(atomic64_sub_ret);
10396 EXPORT_SYMBOL(atomic64_dec_if_positive);
10397
10398diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10399index 30c3ecc..736f015 100644
10400--- a/arch/sparc/mm/Makefile
10401+++ b/arch/sparc/mm/Makefile
10402@@ -2,7 +2,7 @@
10403 #
10404
10405 asflags-y := -ansi
10406-ccflags-y := -Werror
10407+#ccflags-y := -Werror
10408
10409 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10410 obj-y += fault_$(BITS).o
10411diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10412index 59dbd46..1dd7f5e 100644
10413--- a/arch/sparc/mm/fault_32.c
10414+++ b/arch/sparc/mm/fault_32.c
10415@@ -21,6 +21,9 @@
10416 #include <linux/perf_event.h>
10417 #include <linux/interrupt.h>
10418 #include <linux/kdebug.h>
10419+#include <linux/slab.h>
10420+#include <linux/pagemap.h>
10421+#include <linux/compiler.h>
10422
10423 #include <asm/page.h>
10424 #include <asm/pgtable.h>
10425@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10426 return safe_compute_effective_address(regs, insn);
10427 }
10428
10429+#ifdef CONFIG_PAX_PAGEEXEC
10430+#ifdef CONFIG_PAX_DLRESOLVE
10431+static void pax_emuplt_close(struct vm_area_struct *vma)
10432+{
10433+ vma->vm_mm->call_dl_resolve = 0UL;
10434+}
10435+
10436+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10437+{
10438+ unsigned int *kaddr;
10439+
10440+ vmf->page = alloc_page(GFP_HIGHUSER);
10441+ if (!vmf->page)
10442+ return VM_FAULT_OOM;
10443+
10444+ kaddr = kmap(vmf->page);
10445+ memset(kaddr, 0, PAGE_SIZE);
10446+ kaddr[0] = 0x9DE3BFA8U; /* save */
10447+ flush_dcache_page(vmf->page);
10448+ kunmap(vmf->page);
10449+ return VM_FAULT_MAJOR;
10450+}
10451+
10452+static const struct vm_operations_struct pax_vm_ops = {
10453+ .close = pax_emuplt_close,
10454+ .fault = pax_emuplt_fault
10455+};
10456+
10457+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10458+{
10459+ int ret;
10460+
10461+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10462+ vma->vm_mm = current->mm;
10463+ vma->vm_start = addr;
10464+ vma->vm_end = addr + PAGE_SIZE;
10465+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10466+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10467+ vma->vm_ops = &pax_vm_ops;
10468+
10469+ ret = insert_vm_struct(current->mm, vma);
10470+ if (ret)
10471+ return ret;
10472+
10473+ ++current->mm->total_vm;
10474+ return 0;
10475+}
10476+#endif
10477+
10478+/*
10479+ * PaX: decide what to do with offenders (regs->pc = fault address)
10480+ *
10481+ * returns 1 when task should be killed
10482+ * 2 when patched PLT trampoline was detected
10483+ * 3 when unpatched PLT trampoline was detected
10484+ */
10485+static int pax_handle_fetch_fault(struct pt_regs *regs)
10486+{
10487+
10488+#ifdef CONFIG_PAX_EMUPLT
10489+ int err;
10490+
10491+ do { /* PaX: patched PLT emulation #1 */
10492+ unsigned int sethi1, sethi2, jmpl;
10493+
10494+ err = get_user(sethi1, (unsigned int *)regs->pc);
10495+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10496+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10497+
10498+ if (err)
10499+ break;
10500+
10501+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10502+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10503+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10504+ {
10505+ unsigned int addr;
10506+
10507+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10508+ addr = regs->u_regs[UREG_G1];
10509+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10510+ regs->pc = addr;
10511+ regs->npc = addr+4;
10512+ return 2;
10513+ }
10514+ } while (0);
10515+
10516+ do { /* PaX: patched PLT emulation #2 */
10517+ unsigned int ba;
10518+
10519+ err = get_user(ba, (unsigned int *)regs->pc);
10520+
10521+ if (err)
10522+ break;
10523+
10524+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10525+ unsigned int addr;
10526+
10527+ if ((ba & 0xFFC00000U) == 0x30800000U)
10528+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10529+ else
10530+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10531+ regs->pc = addr;
10532+ regs->npc = addr+4;
10533+ return 2;
10534+ }
10535+ } while (0);
10536+
10537+ do { /* PaX: patched PLT emulation #3 */
10538+ unsigned int sethi, bajmpl, nop;
10539+
10540+ err = get_user(sethi, (unsigned int *)regs->pc);
10541+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10542+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10543+
10544+ if (err)
10545+ break;
10546+
10547+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10548+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10549+ nop == 0x01000000U)
10550+ {
10551+ unsigned int addr;
10552+
10553+ addr = (sethi & 0x003FFFFFU) << 10;
10554+ regs->u_regs[UREG_G1] = addr;
10555+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10556+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10557+ else
10558+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10559+ regs->pc = addr;
10560+ regs->npc = addr+4;
10561+ return 2;
10562+ }
10563+ } while (0);
10564+
10565+ do { /* PaX: unpatched PLT emulation step 1 */
10566+ unsigned int sethi, ba, nop;
10567+
10568+ err = get_user(sethi, (unsigned int *)regs->pc);
10569+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10570+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10571+
10572+ if (err)
10573+ break;
10574+
10575+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10576+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10577+ nop == 0x01000000U)
10578+ {
10579+ unsigned int addr, save, call;
10580+
10581+ if ((ba & 0xFFC00000U) == 0x30800000U)
10582+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10583+ else
10584+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10585+
10586+ err = get_user(save, (unsigned int *)addr);
10587+ err |= get_user(call, (unsigned int *)(addr+4));
10588+ err |= get_user(nop, (unsigned int *)(addr+8));
10589+ if (err)
10590+ break;
10591+
10592+#ifdef CONFIG_PAX_DLRESOLVE
10593+ if (save == 0x9DE3BFA8U &&
10594+ (call & 0xC0000000U) == 0x40000000U &&
10595+ nop == 0x01000000U)
10596+ {
10597+ struct vm_area_struct *vma;
10598+ unsigned long call_dl_resolve;
10599+
10600+ down_read(&current->mm->mmap_sem);
10601+ call_dl_resolve = current->mm->call_dl_resolve;
10602+ up_read(&current->mm->mmap_sem);
10603+ if (likely(call_dl_resolve))
10604+ goto emulate;
10605+
10606+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10607+
10608+ down_write(&current->mm->mmap_sem);
10609+ if (current->mm->call_dl_resolve) {
10610+ call_dl_resolve = current->mm->call_dl_resolve;
10611+ up_write(&current->mm->mmap_sem);
10612+ if (vma)
10613+ kmem_cache_free(vm_area_cachep, vma);
10614+ goto emulate;
10615+ }
10616+
10617+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10618+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10619+ up_write(&current->mm->mmap_sem);
10620+ if (vma)
10621+ kmem_cache_free(vm_area_cachep, vma);
10622+ return 1;
10623+ }
10624+
10625+ if (pax_insert_vma(vma, call_dl_resolve)) {
10626+ up_write(&current->mm->mmap_sem);
10627+ kmem_cache_free(vm_area_cachep, vma);
10628+ return 1;
10629+ }
10630+
10631+ current->mm->call_dl_resolve = call_dl_resolve;
10632+ up_write(&current->mm->mmap_sem);
10633+
10634+emulate:
10635+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10636+ regs->pc = call_dl_resolve;
10637+ regs->npc = addr+4;
10638+ return 3;
10639+ }
10640+#endif
10641+
10642+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10643+ if ((save & 0xFFC00000U) == 0x05000000U &&
10644+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10645+ nop == 0x01000000U)
10646+ {
10647+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10648+ regs->u_regs[UREG_G2] = addr + 4;
10649+ addr = (save & 0x003FFFFFU) << 10;
10650+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10651+ regs->pc = addr;
10652+ regs->npc = addr+4;
10653+ return 3;
10654+ }
10655+ }
10656+ } while (0);
10657+
10658+ do { /* PaX: unpatched PLT emulation step 2 */
10659+ unsigned int save, call, nop;
10660+
10661+ err = get_user(save, (unsigned int *)(regs->pc-4));
10662+ err |= get_user(call, (unsigned int *)regs->pc);
10663+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10664+ if (err)
10665+ break;
10666+
10667+ if (save == 0x9DE3BFA8U &&
10668+ (call & 0xC0000000U) == 0x40000000U &&
10669+ nop == 0x01000000U)
10670+ {
10671+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10672+
10673+ regs->u_regs[UREG_RETPC] = regs->pc;
10674+ regs->pc = dl_resolve;
10675+ regs->npc = dl_resolve+4;
10676+ return 3;
10677+ }
10678+ } while (0);
10679+#endif
10680+
10681+ return 1;
10682+}
10683+
10684+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10685+{
10686+ unsigned long i;
10687+
10688+ printk(KERN_ERR "PAX: bytes at PC: ");
10689+ for (i = 0; i < 8; i++) {
10690+ unsigned int c;
10691+ if (get_user(c, (unsigned int *)pc+i))
10692+ printk(KERN_CONT "???????? ");
10693+ else
10694+ printk(KERN_CONT "%08x ", c);
10695+ }
10696+ printk("\n");
10697+}
10698+#endif
10699+
10700 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10701 int text_fault)
10702 {
10703@@ -229,6 +503,24 @@ good_area:
10704 if (!(vma->vm_flags & VM_WRITE))
10705 goto bad_area;
10706 } else {
10707+
10708+#ifdef CONFIG_PAX_PAGEEXEC
10709+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10710+ up_read(&mm->mmap_sem);
10711+ switch (pax_handle_fetch_fault(regs)) {
10712+
10713+#ifdef CONFIG_PAX_EMUPLT
10714+ case 2:
10715+ case 3:
10716+ return;
10717+#endif
10718+
10719+ }
10720+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10721+ do_group_exit(SIGKILL);
10722+ }
10723+#endif
10724+
10725 /* Allow reads even for write-only mappings */
10726 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10727 goto bad_area;
10728diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10729index 2ebec26..b212598 100644
10730--- a/arch/sparc/mm/fault_64.c
10731+++ b/arch/sparc/mm/fault_64.c
10732@@ -21,6 +21,9 @@
10733 #include <linux/kprobes.h>
10734 #include <linux/kdebug.h>
10735 #include <linux/percpu.h>
10736+#include <linux/slab.h>
10737+#include <linux/pagemap.h>
10738+#include <linux/compiler.h>
10739
10740 #include <asm/page.h>
10741 #include <asm/pgtable.h>
10742@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10743 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10744 regs->tpc);
10745 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10746- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10747+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10748 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10749 dump_stack();
10750 unhandled_fault(regs->tpc, current, regs);
10751@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10752 show_regs(regs);
10753 }
10754
10755+#ifdef CONFIG_PAX_PAGEEXEC
10756+#ifdef CONFIG_PAX_DLRESOLVE
10757+static void pax_emuplt_close(struct vm_area_struct *vma)
10758+{
10759+ vma->vm_mm->call_dl_resolve = 0UL;
10760+}
10761+
10762+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10763+{
10764+ unsigned int *kaddr;
10765+
10766+ vmf->page = alloc_page(GFP_HIGHUSER);
10767+ if (!vmf->page)
10768+ return VM_FAULT_OOM;
10769+
10770+ kaddr = kmap(vmf->page);
10771+ memset(kaddr, 0, PAGE_SIZE);
10772+ kaddr[0] = 0x9DE3BFA8U; /* save */
10773+ flush_dcache_page(vmf->page);
10774+ kunmap(vmf->page);
10775+ return VM_FAULT_MAJOR;
10776+}
10777+
10778+static const struct vm_operations_struct pax_vm_ops = {
10779+ .close = pax_emuplt_close,
10780+ .fault = pax_emuplt_fault
10781+};
10782+
10783+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10784+{
10785+ int ret;
10786+
10787+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10788+ vma->vm_mm = current->mm;
10789+ vma->vm_start = addr;
10790+ vma->vm_end = addr + PAGE_SIZE;
10791+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10792+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10793+ vma->vm_ops = &pax_vm_ops;
10794+
10795+ ret = insert_vm_struct(current->mm, vma);
10796+ if (ret)
10797+ return ret;
10798+
10799+ ++current->mm->total_vm;
10800+ return 0;
10801+}
10802+#endif
10803+
10804+/*
10805+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10806+ *
10807+ * returns 1 when task should be killed
10808+ * 2 when patched PLT trampoline was detected
10809+ * 3 when unpatched PLT trampoline was detected
10810+ */
10811+static int pax_handle_fetch_fault(struct pt_regs *regs)
10812+{
10813+
10814+#ifdef CONFIG_PAX_EMUPLT
10815+ int err;
10816+
10817+ do { /* PaX: patched PLT emulation #1 */
10818+ unsigned int sethi1, sethi2, jmpl;
10819+
10820+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10821+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10822+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10823+
10824+ if (err)
10825+ break;
10826+
10827+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10828+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10829+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10830+ {
10831+ unsigned long addr;
10832+
10833+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10834+ addr = regs->u_regs[UREG_G1];
10835+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10836+
10837+ if (test_thread_flag(TIF_32BIT))
10838+ addr &= 0xFFFFFFFFUL;
10839+
10840+ regs->tpc = addr;
10841+ regs->tnpc = addr+4;
10842+ return 2;
10843+ }
10844+ } while (0);
10845+
10846+ do { /* PaX: patched PLT emulation #2 */
10847+ unsigned int ba;
10848+
10849+ err = get_user(ba, (unsigned int *)regs->tpc);
10850+
10851+ if (err)
10852+ break;
10853+
10854+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10855+ unsigned long addr;
10856+
10857+ if ((ba & 0xFFC00000U) == 0x30800000U)
10858+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10859+ else
10860+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10861+
10862+ if (test_thread_flag(TIF_32BIT))
10863+ addr &= 0xFFFFFFFFUL;
10864+
10865+ regs->tpc = addr;
10866+ regs->tnpc = addr+4;
10867+ return 2;
10868+ }
10869+ } while (0);
10870+
10871+ do { /* PaX: patched PLT emulation #3 */
10872+ unsigned int sethi, bajmpl, nop;
10873+
10874+ err = get_user(sethi, (unsigned int *)regs->tpc);
10875+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10876+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10877+
10878+ if (err)
10879+ break;
10880+
10881+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10882+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10883+ nop == 0x01000000U)
10884+ {
10885+ unsigned long addr;
10886+
10887+ addr = (sethi & 0x003FFFFFU) << 10;
10888+ regs->u_regs[UREG_G1] = addr;
10889+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10890+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10891+ else
10892+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10893+
10894+ if (test_thread_flag(TIF_32BIT))
10895+ addr &= 0xFFFFFFFFUL;
10896+
10897+ regs->tpc = addr;
10898+ regs->tnpc = addr+4;
10899+ return 2;
10900+ }
10901+ } while (0);
10902+
10903+ do { /* PaX: patched PLT emulation #4 */
10904+ unsigned int sethi, mov1, call, mov2;
10905+
10906+ err = get_user(sethi, (unsigned int *)regs->tpc);
10907+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10908+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10909+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10910+
10911+ if (err)
10912+ break;
10913+
10914+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10915+ mov1 == 0x8210000FU &&
10916+ (call & 0xC0000000U) == 0x40000000U &&
10917+ mov2 == 0x9E100001U)
10918+ {
10919+ unsigned long addr;
10920+
10921+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10922+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10923+
10924+ if (test_thread_flag(TIF_32BIT))
10925+ addr &= 0xFFFFFFFFUL;
10926+
10927+ regs->tpc = addr;
10928+ regs->tnpc = addr+4;
10929+ return 2;
10930+ }
10931+ } while (0);
10932+
10933+ do { /* PaX: patched PLT emulation #5 */
10934+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10935+
10936+ err = get_user(sethi, (unsigned int *)regs->tpc);
10937+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10938+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10939+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10940+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10941+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10942+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10943+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10944+
10945+ if (err)
10946+ break;
10947+
10948+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10949+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10950+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10951+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10952+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10953+ sllx == 0x83287020U &&
10954+ jmpl == 0x81C04005U &&
10955+ nop == 0x01000000U)
10956+ {
10957+ unsigned long addr;
10958+
10959+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10960+ regs->u_regs[UREG_G1] <<= 32;
10961+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10962+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10963+ regs->tpc = addr;
10964+ regs->tnpc = addr+4;
10965+ return 2;
10966+ }
10967+ } while (0);
10968+
10969+ do { /* PaX: patched PLT emulation #6 */
10970+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10971+
10972+ err = get_user(sethi, (unsigned int *)regs->tpc);
10973+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10974+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10975+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10976+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10977+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10978+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10979+
10980+ if (err)
10981+ break;
10982+
10983+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10984+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10985+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10986+ sllx == 0x83287020U &&
10987+ (or & 0xFFFFE000U) == 0x8A116000U &&
10988+ jmpl == 0x81C04005U &&
10989+ nop == 0x01000000U)
10990+ {
10991+ unsigned long addr;
10992+
10993+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10994+ regs->u_regs[UREG_G1] <<= 32;
10995+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10996+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10997+ regs->tpc = addr;
10998+ regs->tnpc = addr+4;
10999+ return 2;
11000+ }
11001+ } while (0);
11002+
11003+ do { /* PaX: unpatched PLT emulation step 1 */
11004+ unsigned int sethi, ba, nop;
11005+
11006+ err = get_user(sethi, (unsigned int *)regs->tpc);
11007+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11008+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11009+
11010+ if (err)
11011+ break;
11012+
11013+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11014+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11015+ nop == 0x01000000U)
11016+ {
11017+ unsigned long addr;
11018+ unsigned int save, call;
11019+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11020+
11021+ if ((ba & 0xFFC00000U) == 0x30800000U)
11022+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11023+ else
11024+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11025+
11026+ if (test_thread_flag(TIF_32BIT))
11027+ addr &= 0xFFFFFFFFUL;
11028+
11029+ err = get_user(save, (unsigned int *)addr);
11030+ err |= get_user(call, (unsigned int *)(addr+4));
11031+ err |= get_user(nop, (unsigned int *)(addr+8));
11032+ if (err)
11033+ break;
11034+
11035+#ifdef CONFIG_PAX_DLRESOLVE
11036+ if (save == 0x9DE3BFA8U &&
11037+ (call & 0xC0000000U) == 0x40000000U &&
11038+ nop == 0x01000000U)
11039+ {
11040+ struct vm_area_struct *vma;
11041+ unsigned long call_dl_resolve;
11042+
11043+ down_read(&current->mm->mmap_sem);
11044+ call_dl_resolve = current->mm->call_dl_resolve;
11045+ up_read(&current->mm->mmap_sem);
11046+ if (likely(call_dl_resolve))
11047+ goto emulate;
11048+
11049+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11050+
11051+ down_write(&current->mm->mmap_sem);
11052+ if (current->mm->call_dl_resolve) {
11053+ call_dl_resolve = current->mm->call_dl_resolve;
11054+ up_write(&current->mm->mmap_sem);
11055+ if (vma)
11056+ kmem_cache_free(vm_area_cachep, vma);
11057+ goto emulate;
11058+ }
11059+
11060+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11061+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11062+ up_write(&current->mm->mmap_sem);
11063+ if (vma)
11064+ kmem_cache_free(vm_area_cachep, vma);
11065+ return 1;
11066+ }
11067+
11068+ if (pax_insert_vma(vma, call_dl_resolve)) {
11069+ up_write(&current->mm->mmap_sem);
11070+ kmem_cache_free(vm_area_cachep, vma);
11071+ return 1;
11072+ }
11073+
11074+ current->mm->call_dl_resolve = call_dl_resolve;
11075+ up_write(&current->mm->mmap_sem);
11076+
11077+emulate:
11078+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11079+ regs->tpc = call_dl_resolve;
11080+ regs->tnpc = addr+4;
11081+ return 3;
11082+ }
11083+#endif
11084+
11085+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11086+ if ((save & 0xFFC00000U) == 0x05000000U &&
11087+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11088+ nop == 0x01000000U)
11089+ {
11090+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11091+ regs->u_regs[UREG_G2] = addr + 4;
11092+ addr = (save & 0x003FFFFFU) << 10;
11093+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11094+
11095+ if (test_thread_flag(TIF_32BIT))
11096+ addr &= 0xFFFFFFFFUL;
11097+
11098+ regs->tpc = addr;
11099+ regs->tnpc = addr+4;
11100+ return 3;
11101+ }
11102+
11103+ /* PaX: 64-bit PLT stub */
11104+ err = get_user(sethi1, (unsigned int *)addr);
11105+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11106+ err |= get_user(or1, (unsigned int *)(addr+8));
11107+ err |= get_user(or2, (unsigned int *)(addr+12));
11108+ err |= get_user(sllx, (unsigned int *)(addr+16));
11109+ err |= get_user(add, (unsigned int *)(addr+20));
11110+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11111+ err |= get_user(nop, (unsigned int *)(addr+28));
11112+ if (err)
11113+ break;
11114+
11115+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11116+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11117+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11118+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11119+ sllx == 0x89293020U &&
11120+ add == 0x8A010005U &&
11121+ jmpl == 0x89C14000U &&
11122+ nop == 0x01000000U)
11123+ {
11124+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11125+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11126+ regs->u_regs[UREG_G4] <<= 32;
11127+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11128+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11129+ regs->u_regs[UREG_G4] = addr + 24;
11130+ addr = regs->u_regs[UREG_G5];
11131+ regs->tpc = addr;
11132+ regs->tnpc = addr+4;
11133+ return 3;
11134+ }
11135+ }
11136+ } while (0);
11137+
11138+#ifdef CONFIG_PAX_DLRESOLVE
11139+ do { /* PaX: unpatched PLT emulation step 2 */
11140+ unsigned int save, call, nop;
11141+
11142+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11143+ err |= get_user(call, (unsigned int *)regs->tpc);
11144+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11145+ if (err)
11146+ break;
11147+
11148+ if (save == 0x9DE3BFA8U &&
11149+ (call & 0xC0000000U) == 0x40000000U &&
11150+ nop == 0x01000000U)
11151+ {
11152+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11153+
11154+ if (test_thread_flag(TIF_32BIT))
11155+ dl_resolve &= 0xFFFFFFFFUL;
11156+
11157+ regs->u_regs[UREG_RETPC] = regs->tpc;
11158+ regs->tpc = dl_resolve;
11159+ regs->tnpc = dl_resolve+4;
11160+ return 3;
11161+ }
11162+ } while (0);
11163+#endif
11164+
11165+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11166+ unsigned int sethi, ba, nop;
11167+
11168+ err = get_user(sethi, (unsigned int *)regs->tpc);
11169+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11170+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11171+
11172+ if (err)
11173+ break;
11174+
11175+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11176+ (ba & 0xFFF00000U) == 0x30600000U &&
11177+ nop == 0x01000000U)
11178+ {
11179+ unsigned long addr;
11180+
11181+ addr = (sethi & 0x003FFFFFU) << 10;
11182+ regs->u_regs[UREG_G1] = addr;
11183+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11184+
11185+ if (test_thread_flag(TIF_32BIT))
11186+ addr &= 0xFFFFFFFFUL;
11187+
11188+ regs->tpc = addr;
11189+ regs->tnpc = addr+4;
11190+ return 2;
11191+ }
11192+ } while (0);
11193+
11194+#endif
11195+
11196+ return 1;
11197+}
11198+
11199+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11200+{
11201+ unsigned long i;
11202+
11203+ printk(KERN_ERR "PAX: bytes at PC: ");
11204+ for (i = 0; i < 8; i++) {
11205+ unsigned int c;
11206+ if (get_user(c, (unsigned int *)pc+i))
11207+ printk(KERN_CONT "???????? ");
11208+ else
11209+ printk(KERN_CONT "%08x ", c);
11210+ }
11211+ printk("\n");
11212+}
11213+#endif
11214+
11215 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11216 {
11217 struct mm_struct *mm = current->mm;
11218@@ -342,6 +805,29 @@ retry:
11219 if (!vma)
11220 goto bad_area;
11221
11222+#ifdef CONFIG_PAX_PAGEEXEC
11223+ /* PaX: detect ITLB misses on non-exec pages */
11224+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11225+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11226+ {
11227+ if (address != regs->tpc)
11228+ goto good_area;
11229+
11230+ up_read(&mm->mmap_sem);
11231+ switch (pax_handle_fetch_fault(regs)) {
11232+
11233+#ifdef CONFIG_PAX_EMUPLT
11234+ case 2:
11235+ case 3:
11236+ return;
11237+#endif
11238+
11239+ }
11240+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11241+ do_group_exit(SIGKILL);
11242+ }
11243+#endif
11244+
11245 /* Pure DTLB misses do not tell us whether the fault causing
11246 * load/store/atomic was a write or not, it only says that there
11247 * was no match. So in such a case we (carefully) read the
11248diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11249index 9639964..806cd0c 100644
11250--- a/arch/sparc/mm/hugetlbpage.c
11251+++ b/arch/sparc/mm/hugetlbpage.c
11252@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11253 unsigned long addr,
11254 unsigned long len,
11255 unsigned long pgoff,
11256- unsigned long flags)
11257+ unsigned long flags,
11258+ unsigned long offset)
11259 {
11260 unsigned long task_size = TASK_SIZE;
11261 struct vm_unmapped_area_info info;
11262@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11263
11264 info.flags = 0;
11265 info.length = len;
11266- info.low_limit = TASK_UNMAPPED_BASE;
11267+ info.low_limit = mm->mmap_base;
11268 info.high_limit = min(task_size, VA_EXCLUDE_START);
11269 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11270 info.align_offset = 0;
11271+ info.threadstack_offset = offset;
11272 addr = vm_unmapped_area(&info);
11273
11274 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11275 VM_BUG_ON(addr != -ENOMEM);
11276 info.low_limit = VA_EXCLUDE_END;
11277+
11278+#ifdef CONFIG_PAX_RANDMMAP
11279+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11280+ info.low_limit += mm->delta_mmap;
11281+#endif
11282+
11283 info.high_limit = task_size;
11284 addr = vm_unmapped_area(&info);
11285 }
11286@@ -58,7 +66,8 @@ static unsigned long
11287 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11288 const unsigned long len,
11289 const unsigned long pgoff,
11290- const unsigned long flags)
11291+ const unsigned long flags,
11292+ const unsigned long offset)
11293 {
11294 struct mm_struct *mm = current->mm;
11295 unsigned long addr = addr0;
11296@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11297 info.high_limit = mm->mmap_base;
11298 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11299 info.align_offset = 0;
11300+ info.threadstack_offset = offset;
11301 addr = vm_unmapped_area(&info);
11302
11303 /*
11304@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11305 VM_BUG_ON(addr != -ENOMEM);
11306 info.flags = 0;
11307 info.low_limit = TASK_UNMAPPED_BASE;
11308+
11309+#ifdef CONFIG_PAX_RANDMMAP
11310+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11311+ info.low_limit += mm->delta_mmap;
11312+#endif
11313+
11314 info.high_limit = STACK_TOP32;
11315 addr = vm_unmapped_area(&info);
11316 }
11317@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11318 struct mm_struct *mm = current->mm;
11319 struct vm_area_struct *vma;
11320 unsigned long task_size = TASK_SIZE;
11321+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11322
11323 if (test_thread_flag(TIF_32BIT))
11324 task_size = STACK_TOP32;
11325@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11326 return addr;
11327 }
11328
11329+#ifdef CONFIG_PAX_RANDMMAP
11330+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11331+#endif
11332+
11333 if (addr) {
11334 addr = ALIGN(addr, HPAGE_SIZE);
11335 vma = find_vma(mm, addr);
11336- if (task_size - len >= addr &&
11337- (!vma || addr + len <= vma->vm_start))
11338+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11339 return addr;
11340 }
11341 if (mm->get_unmapped_area == arch_get_unmapped_area)
11342 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11343- pgoff, flags);
11344+ pgoff, flags, offset);
11345 else
11346 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11347- pgoff, flags);
11348+ pgoff, flags, offset);
11349 }
11350
11351 pte_t *huge_pte_alloc(struct mm_struct *mm,
11352diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11353index ed82eda..0d80e77 100644
11354--- a/arch/sparc/mm/init_64.c
11355+++ b/arch/sparc/mm/init_64.c
11356@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11357 int num_kernel_image_mappings;
11358
11359 #ifdef CONFIG_DEBUG_DCFLUSH
11360-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11361+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11362 #ifdef CONFIG_SMP
11363-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11364+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11365 #endif
11366 #endif
11367
11368@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11369 {
11370 BUG_ON(tlb_type == hypervisor);
11371 #ifdef CONFIG_DEBUG_DCFLUSH
11372- atomic_inc(&dcpage_flushes);
11373+ atomic_inc_unchecked(&dcpage_flushes);
11374 #endif
11375
11376 #ifdef DCACHE_ALIASING_POSSIBLE
11377@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11378
11379 #ifdef CONFIG_DEBUG_DCFLUSH
11380 seq_printf(m, "DCPageFlushes\t: %d\n",
11381- atomic_read(&dcpage_flushes));
11382+ atomic_read_unchecked(&dcpage_flushes));
11383 #ifdef CONFIG_SMP
11384 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11385- atomic_read(&dcpage_flushes_xcall));
11386+ atomic_read_unchecked(&dcpage_flushes_xcall));
11387 #endif /* CONFIG_SMP */
11388 #endif /* CONFIG_DEBUG_DCFLUSH */
11389 }
11390diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11391index d45a2c4..3c05a78 100644
11392--- a/arch/tile/Kconfig
11393+++ b/arch/tile/Kconfig
11394@@ -185,6 +185,7 @@ source "kernel/Kconfig.hz"
11395
11396 config KEXEC
11397 bool "kexec system call"
11398+ depends on !GRKERNSEC_KMEM
11399 ---help---
11400 kexec is a system call that implements the ability to shutdown your
11401 current kernel, and to start another kernel. It is like a reboot
11402diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11403index ad220ee..2f537b3 100644
11404--- a/arch/tile/include/asm/atomic_64.h
11405+++ b/arch/tile/include/asm/atomic_64.h
11406@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11407
11408 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11409
11410+#define atomic64_read_unchecked(v) atomic64_read(v)
11411+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11412+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11413+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11414+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11415+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11416+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11417+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11418+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11419+
11420 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11421 #define smp_mb__before_atomic_dec() smp_mb()
11422 #define smp_mb__after_atomic_dec() smp_mb()
11423diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11424index 6160761..00cac88 100644
11425--- a/arch/tile/include/asm/cache.h
11426+++ b/arch/tile/include/asm/cache.h
11427@@ -15,11 +15,12 @@
11428 #ifndef _ASM_TILE_CACHE_H
11429 #define _ASM_TILE_CACHE_H
11430
11431+#include <linux/const.h>
11432 #include <arch/chip.h>
11433
11434 /* bytes per L1 data cache line */
11435 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11436-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11437+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11438
11439 /* bytes per L2 cache line */
11440 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11441diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11442index b6cde32..c0cb736 100644
11443--- a/arch/tile/include/asm/uaccess.h
11444+++ b/arch/tile/include/asm/uaccess.h
11445@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11446 const void __user *from,
11447 unsigned long n)
11448 {
11449- int sz = __compiletime_object_size(to);
11450+ size_t sz = __compiletime_object_size(to);
11451
11452- if (likely(sz == -1 || sz >= n))
11453+ if (likely(sz == (size_t)-1 || sz >= n))
11454 n = _copy_from_user(to, from, n);
11455 else
11456 copy_from_user_overflow();
11457diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11458index 0cb3bba..7338b2d 100644
11459--- a/arch/tile/mm/hugetlbpage.c
11460+++ b/arch/tile/mm/hugetlbpage.c
11461@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11462 info.high_limit = TASK_SIZE;
11463 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11464 info.align_offset = 0;
11465+ info.threadstack_offset = 0;
11466 return vm_unmapped_area(&info);
11467 }
11468
11469@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11470 info.high_limit = current->mm->mmap_base;
11471 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11472 info.align_offset = 0;
11473+ info.threadstack_offset = 0;
11474 addr = vm_unmapped_area(&info);
11475
11476 /*
11477diff --git a/arch/um/Makefile b/arch/um/Makefile
11478index 133f7de..1d6f2f1 100644
11479--- a/arch/um/Makefile
11480+++ b/arch/um/Makefile
11481@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11482 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11483 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11484
11485+ifdef CONSTIFY_PLUGIN
11486+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11487+endif
11488+
11489 #This will adjust *FLAGS accordingly to the platform.
11490 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11491
11492diff --git a/arch/um/defconfig b/arch/um/defconfig
11493index 2665e6b..3e3822b 100644
11494--- a/arch/um/defconfig
11495+++ b/arch/um/defconfig
11496@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11497 CONFIG_X86_L1_CACHE_SHIFT=5
11498 CONFIG_X86_XADD=y
11499 CONFIG_X86_PPRO_FENCE=y
11500-CONFIG_X86_WP_WORKS_OK=y
11501 CONFIG_X86_INVLPG=y
11502 CONFIG_X86_BSWAP=y
11503 CONFIG_X86_POPAD_OK=y
11504diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11505index 19e1bdd..3665b77 100644
11506--- a/arch/um/include/asm/cache.h
11507+++ b/arch/um/include/asm/cache.h
11508@@ -1,6 +1,7 @@
11509 #ifndef __UM_CACHE_H
11510 #define __UM_CACHE_H
11511
11512+#include <linux/const.h>
11513
11514 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11515 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11516@@ -12,6 +13,6 @@
11517 # define L1_CACHE_SHIFT 5
11518 #endif
11519
11520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11522
11523 #endif
11524diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11525index 2e0a6b1..a64d0f5 100644
11526--- a/arch/um/include/asm/kmap_types.h
11527+++ b/arch/um/include/asm/kmap_types.h
11528@@ -8,6 +8,6 @@
11529
11530 /* No more #include "asm/arch/kmap_types.h" ! */
11531
11532-#define KM_TYPE_NR 14
11533+#define KM_TYPE_NR 15
11534
11535 #endif
11536diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11537index 5ff53d9..5850cdf 100644
11538--- a/arch/um/include/asm/page.h
11539+++ b/arch/um/include/asm/page.h
11540@@ -14,6 +14,9 @@
11541 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11542 #define PAGE_MASK (~(PAGE_SIZE-1))
11543
11544+#define ktla_ktva(addr) (addr)
11545+#define ktva_ktla(addr) (addr)
11546+
11547 #ifndef __ASSEMBLY__
11548
11549 struct page;
11550diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11551index 0032f92..cd151e0 100644
11552--- a/arch/um/include/asm/pgtable-3level.h
11553+++ b/arch/um/include/asm/pgtable-3level.h
11554@@ -58,6 +58,7 @@
11555 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11556 #define pud_populate(mm, pud, pmd) \
11557 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11558+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11559
11560 #ifdef CONFIG_64BIT
11561 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11562diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11563index bbcef52..6a2a483 100644
11564--- a/arch/um/kernel/process.c
11565+++ b/arch/um/kernel/process.c
11566@@ -367,22 +367,6 @@ int singlestepping(void * t)
11567 return 2;
11568 }
11569
11570-/*
11571- * Only x86 and x86_64 have an arch_align_stack().
11572- * All other arches have "#define arch_align_stack(x) (x)"
11573- * in their asm/system.h
11574- * As this is included in UML from asm-um/system-generic.h,
11575- * we can use it to behave as the subarch does.
11576- */
11577-#ifndef arch_align_stack
11578-unsigned long arch_align_stack(unsigned long sp)
11579-{
11580- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11581- sp -= get_random_int() % 8192;
11582- return sp & ~0xf;
11583-}
11584-#endif
11585-
11586 unsigned long get_wchan(struct task_struct *p)
11587 {
11588 unsigned long stack_page, sp, ip;
11589diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11590index ad8f795..2c7eec6 100644
11591--- a/arch/unicore32/include/asm/cache.h
11592+++ b/arch/unicore32/include/asm/cache.h
11593@@ -12,8 +12,10 @@
11594 #ifndef __UNICORE_CACHE_H__
11595 #define __UNICORE_CACHE_H__
11596
11597-#define L1_CACHE_SHIFT (5)
11598-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11599+#include <linux/const.h>
11600+
11601+#define L1_CACHE_SHIFT 5
11602+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11603
11604 /*
11605 * Memory returned by kmalloc() may be used for DMA, so we must make
11606diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11607index f67e839..bfd4748 100644
11608--- a/arch/x86/Kconfig
11609+++ b/arch/x86/Kconfig
11610@@ -247,7 +247,7 @@ config X86_HT
11611
11612 config X86_32_LAZY_GS
11613 def_bool y
11614- depends on X86_32 && !CC_STACKPROTECTOR
11615+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11616
11617 config ARCH_HWEIGHT_CFLAGS
11618 string
11619@@ -1099,6 +1099,7 @@ config MICROCODE_EARLY
11620
11621 config X86_MSR
11622 tristate "/dev/cpu/*/msr - Model-specific register support"
11623+ depends on !GRKERNSEC_KMEM
11624 ---help---
11625 This device gives privileged processes access to the x86
11626 Model-Specific Registers (MSRs). It is a character device with
11627@@ -1122,7 +1123,7 @@ choice
11628
11629 config NOHIGHMEM
11630 bool "off"
11631- depends on !X86_NUMAQ
11632+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11633 ---help---
11634 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11635 However, the address space of 32-bit x86 processors is only 4
11636@@ -1159,7 +1160,7 @@ config NOHIGHMEM
11637
11638 config HIGHMEM4G
11639 bool "4GB"
11640- depends on !X86_NUMAQ
11641+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11642 ---help---
11643 Select this if you have a 32-bit processor and between 1 and 4
11644 gigabytes of physical RAM.
11645@@ -1212,7 +1213,7 @@ config PAGE_OFFSET
11646 hex
11647 default 0xB0000000 if VMSPLIT_3G_OPT
11648 default 0x80000000 if VMSPLIT_2G
11649- default 0x78000000 if VMSPLIT_2G_OPT
11650+ default 0x70000000 if VMSPLIT_2G_OPT
11651 default 0x40000000 if VMSPLIT_1G
11652 default 0xC0000000
11653 depends on X86_32
11654@@ -1614,6 +1615,7 @@ config SECCOMP
11655
11656 config CC_STACKPROTECTOR
11657 bool "Enable -fstack-protector buffer overflow detection"
11658+ depends on X86_64 || !PAX_MEMORY_UDEREF
11659 ---help---
11660 This option turns on the -fstack-protector GCC feature. This
11661 feature puts, at the beginning of functions, a canary value on
11662@@ -1632,6 +1634,7 @@ source kernel/Kconfig.hz
11663
11664 config KEXEC
11665 bool "kexec system call"
11666+ depends on !GRKERNSEC_KMEM
11667 ---help---
11668 kexec is a system call that implements the ability to shutdown your
11669 current kernel, and to start another kernel. It is like a reboot
11670@@ -1733,6 +1736,8 @@ config X86_NEED_RELOCS
11671 config PHYSICAL_ALIGN
11672 hex "Alignment value to which kernel should be aligned"
11673 default "0x1000000"
11674+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11675+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11676 range 0x2000 0x1000000 if X86_32
11677 range 0x200000 0x1000000 if X86_64
11678 ---help---
11679@@ -1812,9 +1817,10 @@ config DEBUG_HOTPLUG_CPU0
11680 If unsure, say N.
11681
11682 config COMPAT_VDSO
11683- def_bool y
11684+ def_bool n
11685 prompt "Compat VDSO support"
11686 depends on X86_32 || IA32_EMULATION
11687+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11688 ---help---
11689 Map the 32-bit VDSO to the predictable old-style address too.
11690
11691diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11692index c026cca..14657ae 100644
11693--- a/arch/x86/Kconfig.cpu
11694+++ b/arch/x86/Kconfig.cpu
11695@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11696
11697 config X86_F00F_BUG
11698 def_bool y
11699- depends on M586MMX || M586TSC || M586 || M486
11700+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11701
11702 config X86_INVD_BUG
11703 def_bool y
11704@@ -327,7 +327,7 @@ config X86_INVD_BUG
11705
11706 config X86_ALIGNMENT_16
11707 def_bool y
11708- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11709+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11710
11711 config X86_INTEL_USERCOPY
11712 def_bool y
11713@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11714 # generates cmov.
11715 config X86_CMOV
11716 def_bool y
11717- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11718+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11719
11720 config X86_MINIMUM_CPU_FAMILY
11721 int
11722diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11723index 78d91af..8ceb94b 100644
11724--- a/arch/x86/Kconfig.debug
11725+++ b/arch/x86/Kconfig.debug
11726@@ -74,7 +74,7 @@ config X86_PTDUMP
11727 config DEBUG_RODATA
11728 bool "Write protect kernel read-only data structures"
11729 default y
11730- depends on DEBUG_KERNEL
11731+ depends on DEBUG_KERNEL && BROKEN
11732 ---help---
11733 Mark the kernel read-only data as write-protected in the pagetables,
11734 in order to catch accidental (and incorrect) writes to such const
11735@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11736
11737 config DEBUG_SET_MODULE_RONX
11738 bool "Set loadable kernel module data as NX and text as RO"
11739- depends on MODULES
11740+ depends on MODULES && BROKEN
11741 ---help---
11742 This option helps catch unintended modifications to loadable
11743 kernel module's text and read-only data. It also prevents execution
11744diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11745index 57d0215..b4373fb 100644
11746--- a/arch/x86/Makefile
11747+++ b/arch/x86/Makefile
11748@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11749 # CPU-specific tuning. Anything which can be shared with UML should go here.
11750 include $(srctree)/arch/x86/Makefile_32.cpu
11751 KBUILD_CFLAGS += $(cflags-y)
11752-
11753- # temporary until string.h is fixed
11754- KBUILD_CFLAGS += -ffreestanding
11755 else
11756 BITS := 64
11757 UTS_MACHINE := x86_64
11758 CHECKFLAGS += -D__x86_64__ -m64
11759
11760+ biarch := $(call cc-option,-m64)
11761 KBUILD_AFLAGS += -m64
11762 KBUILD_CFLAGS += -m64
11763
11764@@ -89,6 +87,9 @@ else
11765 KBUILD_CFLAGS += -maccumulate-outgoing-args
11766 endif
11767
11768+# temporary until string.h is fixed
11769+KBUILD_CFLAGS += -ffreestanding
11770+
11771 ifdef CONFIG_CC_STACKPROTECTOR
11772 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11773 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11774@@ -247,3 +248,12 @@ define archhelp
11775 echo ' FDINITRD=file initrd for the booted kernel'
11776 echo ' kvmconfig - Enable additional options for guest kernel support'
11777 endef
11778+
11779+define OLD_LD
11780+
11781+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11782+*** Please upgrade your binutils to 2.18 or newer
11783+endef
11784+
11785+archprepare:
11786+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11787diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11788index 6cf0111..f2e2398 100644
11789--- a/arch/x86/boot/Makefile
11790+++ b/arch/x86/boot/Makefile
11791@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11792 $(call cc-option, -fno-unit-at-a-time)) \
11793 $(call cc-option, -fno-stack-protector) \
11794 $(call cc-option, -mpreferred-stack-boundary=2)
11795+ifdef CONSTIFY_PLUGIN
11796+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11797+endif
11798 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11799 GCOV_PROFILE := n
11800
11801diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11802index 878e4b9..20537ab 100644
11803--- a/arch/x86/boot/bitops.h
11804+++ b/arch/x86/boot/bitops.h
11805@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11806 u8 v;
11807 const u32 *p = (const u32 *)addr;
11808
11809- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11810+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11811 return v;
11812 }
11813
11814@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11815
11816 static inline void set_bit(int nr, void *addr)
11817 {
11818- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11819+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11820 }
11821
11822 #endif /* BOOT_BITOPS_H */
11823diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11824index ef72bae..353a184 100644
11825--- a/arch/x86/boot/boot.h
11826+++ b/arch/x86/boot/boot.h
11827@@ -85,7 +85,7 @@ static inline void io_delay(void)
11828 static inline u16 ds(void)
11829 {
11830 u16 seg;
11831- asm("movw %%ds,%0" : "=rm" (seg));
11832+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11833 return seg;
11834 }
11835
11836@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11837 static inline int memcmp(const void *s1, const void *s2, size_t len)
11838 {
11839 u8 diff;
11840- asm("repe; cmpsb; setnz %0"
11841+ asm volatile("repe; cmpsb; setnz %0"
11842 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11843 return diff;
11844 }
11845diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11846index c8a6792..2402765 100644
11847--- a/arch/x86/boot/compressed/Makefile
11848+++ b/arch/x86/boot/compressed/Makefile
11849@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11850 KBUILD_CFLAGS += -mno-mmx -mno-sse
11851 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11852 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11853+ifdef CONSTIFY_PLUGIN
11854+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11855+endif
11856
11857 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11858 GCOV_PROFILE := n
11859diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11860index b7388a4..03844ec 100644
11861--- a/arch/x86/boot/compressed/eboot.c
11862+++ b/arch/x86/boot/compressed/eboot.c
11863@@ -150,7 +150,6 @@ again:
11864 *addr = max_addr;
11865 }
11866
11867-free_pool:
11868 efi_call_phys1(sys_table->boottime->free_pool, map);
11869
11870 fail:
11871@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11872 if (i == map_size / desc_size)
11873 status = EFI_NOT_FOUND;
11874
11875-free_pool:
11876 efi_call_phys1(sys_table->boottime->free_pool, map);
11877 fail:
11878 return status;
11879diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11880index a53440e..c3dbf1e 100644
11881--- a/arch/x86/boot/compressed/efi_stub_32.S
11882+++ b/arch/x86/boot/compressed/efi_stub_32.S
11883@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11884 * parameter 2, ..., param n. To make things easy, we save the return
11885 * address of efi_call_phys in a global variable.
11886 */
11887- popl %ecx
11888- movl %ecx, saved_return_addr(%edx)
11889- /* get the function pointer into ECX*/
11890- popl %ecx
11891- movl %ecx, efi_rt_function_ptr(%edx)
11892+ popl saved_return_addr(%edx)
11893+ popl efi_rt_function_ptr(%edx)
11894
11895 /*
11896 * 3. Call the physical function.
11897 */
11898- call *%ecx
11899+ call *efi_rt_function_ptr(%edx)
11900
11901 /*
11902 * 4. Balance the stack. And because EAX contain the return value,
11903@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11904 1: popl %edx
11905 subl $1b, %edx
11906
11907- movl efi_rt_function_ptr(%edx), %ecx
11908- pushl %ecx
11909+ pushl efi_rt_function_ptr(%edx)
11910
11911 /*
11912 * 10. Push the saved return address onto the stack and return.
11913 */
11914- movl saved_return_addr(%edx), %ecx
11915- pushl %ecx
11916- ret
11917+ jmpl *saved_return_addr(%edx)
11918 ENDPROC(efi_call_phys)
11919 .previous
11920
11921diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11922index 5d6f689..9d06730 100644
11923--- a/arch/x86/boot/compressed/head_32.S
11924+++ b/arch/x86/boot/compressed/head_32.S
11925@@ -118,7 +118,7 @@ preferred_addr:
11926 notl %eax
11927 andl %eax, %ebx
11928 #else
11929- movl $LOAD_PHYSICAL_ADDR, %ebx
11930+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11931 #endif
11932
11933 /* Target address to relocate to for decompression */
11934diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11935index c337422..2c5be72 100644
11936--- a/arch/x86/boot/compressed/head_64.S
11937+++ b/arch/x86/boot/compressed/head_64.S
11938@@ -95,7 +95,7 @@ ENTRY(startup_32)
11939 notl %eax
11940 andl %eax, %ebx
11941 #else
11942- movl $LOAD_PHYSICAL_ADDR, %ebx
11943+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11944 #endif
11945
11946 /* Target address to relocate to for decompression */
11947@@ -270,7 +270,7 @@ preferred_addr:
11948 notq %rax
11949 andq %rax, %rbp
11950 #else
11951- movq $LOAD_PHYSICAL_ADDR, %rbp
11952+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11953 #endif
11954
11955 /* Target address to relocate to for decompression */
11956@@ -362,8 +362,8 @@ gdt:
11957 .long gdt
11958 .word 0
11959 .quad 0x0000000000000000 /* NULL descriptor */
11960- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11961- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11962+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11963+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11964 .quad 0x0080890000000000 /* TS descriptor */
11965 .quad 0x0000000000000000 /* TS continued */
11966 gdt_end:
11967diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11968index 434f077..b6b4b38 100644
11969--- a/arch/x86/boot/compressed/misc.c
11970+++ b/arch/x86/boot/compressed/misc.c
11971@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
11972 * Calculate the delta between where vmlinux was linked to load
11973 * and where it was actually loaded.
11974 */
11975- delta = min_addr - LOAD_PHYSICAL_ADDR;
11976+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
11977 if (!delta) {
11978 debug_putstr("No relocation needed... ");
11979 return;
11980@@ -380,7 +380,7 @@ static void parse_elf(void *output)
11981 case PT_LOAD:
11982 #ifdef CONFIG_RELOCATABLE
11983 dest = output;
11984- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11985+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11986 #else
11987 dest = (void *)(phdr->p_paddr);
11988 #endif
11989@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11990 error("Destination address too large");
11991 #endif
11992 #ifndef CONFIG_RELOCATABLE
11993- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11994+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11995 error("Wrong destination address");
11996 #endif
11997
11998diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11999index 4d3ff03..e4972ff 100644
12000--- a/arch/x86/boot/cpucheck.c
12001+++ b/arch/x86/boot/cpucheck.c
12002@@ -74,7 +74,7 @@ static int has_fpu(void)
12003 u16 fcw = -1, fsw = -1;
12004 u32 cr0;
12005
12006- asm("movl %%cr0,%0" : "=r" (cr0));
12007+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12008 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12009 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12010 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12011@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12012 {
12013 u32 f0, f1;
12014
12015- asm("pushfl ; "
12016+ asm volatile("pushfl ; "
12017 "pushfl ; "
12018 "popl %0 ; "
12019 "movl %0,%1 ; "
12020@@ -115,7 +115,7 @@ static void get_flags(void)
12021 set_bit(X86_FEATURE_FPU, cpu.flags);
12022
12023 if (has_eflag(X86_EFLAGS_ID)) {
12024- asm("cpuid"
12025+ asm volatile("cpuid"
12026 : "=a" (max_intel_level),
12027 "=b" (cpu_vendor[0]),
12028 "=d" (cpu_vendor[1]),
12029@@ -124,7 +124,7 @@ static void get_flags(void)
12030
12031 if (max_intel_level >= 0x00000001 &&
12032 max_intel_level <= 0x0000ffff) {
12033- asm("cpuid"
12034+ asm volatile("cpuid"
12035 : "=a" (tfms),
12036 "=c" (cpu.flags[4]),
12037 "=d" (cpu.flags[0])
12038@@ -136,7 +136,7 @@ static void get_flags(void)
12039 cpu.model += ((tfms >> 16) & 0xf) << 4;
12040 }
12041
12042- asm("cpuid"
12043+ asm volatile("cpuid"
12044 : "=a" (max_amd_level)
12045 : "a" (0x80000000)
12046 : "ebx", "ecx", "edx");
12047@@ -144,7 +144,7 @@ static void get_flags(void)
12048 if (max_amd_level >= 0x80000001 &&
12049 max_amd_level <= 0x8000ffff) {
12050 u32 eax = 0x80000001;
12051- asm("cpuid"
12052+ asm volatile("cpuid"
12053 : "+a" (eax),
12054 "=c" (cpu.flags[6]),
12055 "=d" (cpu.flags[1])
12056@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12057 u32 ecx = MSR_K7_HWCR;
12058 u32 eax, edx;
12059
12060- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12061+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12062 eax &= ~(1 << 15);
12063- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12064+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12065
12066 get_flags(); /* Make sure it really did something */
12067 err = check_flags();
12068@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12069 u32 ecx = MSR_VIA_FCR;
12070 u32 eax, edx;
12071
12072- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12073+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12074 eax |= (1<<1)|(1<<7);
12075- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12076+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12077
12078 set_bit(X86_FEATURE_CX8, cpu.flags);
12079 err = check_flags();
12080@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12081 u32 eax, edx;
12082 u32 level = 1;
12083
12084- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12085- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12086- asm("cpuid"
12087+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12088+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12089+ asm volatile("cpuid"
12090 : "+a" (level), "=d" (cpu.flags[0])
12091 : : "ecx", "ebx");
12092- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12093+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12094
12095 err = check_flags();
12096 }
12097diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12098index 9ec06a1..2c25e79 100644
12099--- a/arch/x86/boot/header.S
12100+++ b/arch/x86/boot/header.S
12101@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12102 # single linked list of
12103 # struct setup_data
12104
12105-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12106+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12107
12108 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12109+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12110+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12111+#else
12112 #define VO_INIT_SIZE (VO__end - VO__text)
12113+#endif
12114 #if ZO_INIT_SIZE > VO_INIT_SIZE
12115 #define INIT_SIZE ZO_INIT_SIZE
12116 #else
12117diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12118index db75d07..8e6d0af 100644
12119--- a/arch/x86/boot/memory.c
12120+++ b/arch/x86/boot/memory.c
12121@@ -19,7 +19,7 @@
12122
12123 static int detect_memory_e820(void)
12124 {
12125- int count = 0;
12126+ unsigned int count = 0;
12127 struct biosregs ireg, oreg;
12128 struct e820entry *desc = boot_params.e820_map;
12129 static struct e820entry buf; /* static so it is zeroed */
12130diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12131index 11e8c6e..fdbb1ed 100644
12132--- a/arch/x86/boot/video-vesa.c
12133+++ b/arch/x86/boot/video-vesa.c
12134@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12135
12136 boot_params.screen_info.vesapm_seg = oreg.es;
12137 boot_params.screen_info.vesapm_off = oreg.di;
12138+ boot_params.screen_info.vesapm_size = oreg.cx;
12139 }
12140
12141 /*
12142diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12143index 43eda28..5ab5fdb 100644
12144--- a/arch/x86/boot/video.c
12145+++ b/arch/x86/boot/video.c
12146@@ -96,7 +96,7 @@ static void store_mode_params(void)
12147 static unsigned int get_entry(void)
12148 {
12149 char entry_buf[4];
12150- int i, len = 0;
12151+ unsigned int i, len = 0;
12152 int key;
12153 unsigned int v;
12154
12155diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12156index 9105655..41779c1 100644
12157--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12158+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12159@@ -8,6 +8,8 @@
12160 * including this sentence is retained in full.
12161 */
12162
12163+#include <asm/alternative-asm.h>
12164+
12165 .extern crypto_ft_tab
12166 .extern crypto_it_tab
12167 .extern crypto_fl_tab
12168@@ -70,6 +72,8 @@
12169 je B192; \
12170 leaq 32(r9),r9;
12171
12172+#define ret pax_force_retaddr; ret
12173+
12174 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12175 movq r1,r2; \
12176 movq r3,r4; \
12177diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12178index 477e9d7..c92c7d8 100644
12179--- a/arch/x86/crypto/aesni-intel_asm.S
12180+++ b/arch/x86/crypto/aesni-intel_asm.S
12181@@ -31,6 +31,7 @@
12182
12183 #include <linux/linkage.h>
12184 #include <asm/inst.h>
12185+#include <asm/alternative-asm.h>
12186
12187 #ifdef __x86_64__
12188 .data
12189@@ -205,7 +206,7 @@ enc: .octa 0x2
12190 * num_initial_blocks = b mod 4
12191 * encrypt the initial num_initial_blocks blocks and apply ghash on
12192 * the ciphertext
12193-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12194+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12195 * are clobbered
12196 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12197 */
12198@@ -214,8 +215,8 @@ enc: .octa 0x2
12199 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12200 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12201 mov arg7, %r10 # %r10 = AAD
12202- mov arg8, %r12 # %r12 = aadLen
12203- mov %r12, %r11
12204+ mov arg8, %r15 # %r15 = aadLen
12205+ mov %r15, %r11
12206 pxor %xmm\i, %xmm\i
12207 _get_AAD_loop\num_initial_blocks\operation:
12208 movd (%r10), \TMP1
12209@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12210 psrldq $4, %xmm\i
12211 pxor \TMP1, %xmm\i
12212 add $4, %r10
12213- sub $4, %r12
12214+ sub $4, %r15
12215 jne _get_AAD_loop\num_initial_blocks\operation
12216 cmp $16, %r11
12217 je _get_AAD_loop2_done\num_initial_blocks\operation
12218- mov $16, %r12
12219+ mov $16, %r15
12220 _get_AAD_loop2\num_initial_blocks\operation:
12221 psrldq $4, %xmm\i
12222- sub $4, %r12
12223- cmp %r11, %r12
12224+ sub $4, %r15
12225+ cmp %r11, %r15
12226 jne _get_AAD_loop2\num_initial_blocks\operation
12227 _get_AAD_loop2_done\num_initial_blocks\operation:
12228 movdqa SHUF_MASK(%rip), %xmm14
12229@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12230 * num_initial_blocks = b mod 4
12231 * encrypt the initial num_initial_blocks blocks and apply ghash on
12232 * the ciphertext
12233-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12234+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12235 * are clobbered
12236 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12237 */
12238@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12239 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12240 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12241 mov arg7, %r10 # %r10 = AAD
12242- mov arg8, %r12 # %r12 = aadLen
12243- mov %r12, %r11
12244+ mov arg8, %r15 # %r15 = aadLen
12245+ mov %r15, %r11
12246 pxor %xmm\i, %xmm\i
12247 _get_AAD_loop\num_initial_blocks\operation:
12248 movd (%r10), \TMP1
12249@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12250 psrldq $4, %xmm\i
12251 pxor \TMP1, %xmm\i
12252 add $4, %r10
12253- sub $4, %r12
12254+ sub $4, %r15
12255 jne _get_AAD_loop\num_initial_blocks\operation
12256 cmp $16, %r11
12257 je _get_AAD_loop2_done\num_initial_blocks\operation
12258- mov $16, %r12
12259+ mov $16, %r15
12260 _get_AAD_loop2\num_initial_blocks\operation:
12261 psrldq $4, %xmm\i
12262- sub $4, %r12
12263- cmp %r11, %r12
12264+ sub $4, %r15
12265+ cmp %r11, %r15
12266 jne _get_AAD_loop2\num_initial_blocks\operation
12267 _get_AAD_loop2_done\num_initial_blocks\operation:
12268 movdqa SHUF_MASK(%rip), %xmm14
12269@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12270 *
12271 *****************************************************************************/
12272 ENTRY(aesni_gcm_dec)
12273- push %r12
12274+ push %r15
12275 push %r13
12276 push %r14
12277 mov %rsp, %r14
12278@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12279 */
12280 sub $VARIABLE_OFFSET, %rsp
12281 and $~63, %rsp # align rsp to 64 bytes
12282- mov %arg6, %r12
12283- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12284+ mov %arg6, %r15
12285+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12286 movdqa SHUF_MASK(%rip), %xmm2
12287 PSHUFB_XMM %xmm2, %xmm13
12288
12289@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12290 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12291 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12292 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12293- mov %r13, %r12
12294- and $(3<<4), %r12
12295+ mov %r13, %r15
12296+ and $(3<<4), %r15
12297 jz _initial_num_blocks_is_0_decrypt
12298- cmp $(2<<4), %r12
12299+ cmp $(2<<4), %r15
12300 jb _initial_num_blocks_is_1_decrypt
12301 je _initial_num_blocks_is_2_decrypt
12302 _initial_num_blocks_is_3_decrypt:
12303@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12304 sub $16, %r11
12305 add %r13, %r11
12306 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12307- lea SHIFT_MASK+16(%rip), %r12
12308- sub %r13, %r12
12309+ lea SHIFT_MASK+16(%rip), %r15
12310+ sub %r13, %r15
12311 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12312 # (%r13 is the number of bytes in plaintext mod 16)
12313- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12314+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12315 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12316
12317 movdqa %xmm1, %xmm2
12318 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12319- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12320+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12321 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12322 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12323 pand %xmm1, %xmm2
12324@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12325 sub $1, %r13
12326 jne _less_than_8_bytes_left_decrypt
12327 _multiple_of_16_bytes_decrypt:
12328- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12329- shl $3, %r12 # convert into number of bits
12330- movd %r12d, %xmm15 # len(A) in %xmm15
12331+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12332+ shl $3, %r15 # convert into number of bits
12333+ movd %r15d, %xmm15 # len(A) in %xmm15
12334 shl $3, %arg4 # len(C) in bits (*128)
12335 MOVQ_R64_XMM %arg4, %xmm1
12336 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12337@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12338 mov %r14, %rsp
12339 pop %r14
12340 pop %r13
12341- pop %r12
12342+ pop %r15
12343+ pax_force_retaddr
12344 ret
12345 ENDPROC(aesni_gcm_dec)
12346
12347@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12348 * poly = x^128 + x^127 + x^126 + x^121 + 1
12349 ***************************************************************************/
12350 ENTRY(aesni_gcm_enc)
12351- push %r12
12352+ push %r15
12353 push %r13
12354 push %r14
12355 mov %rsp, %r14
12356@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12357 #
12358 sub $VARIABLE_OFFSET, %rsp
12359 and $~63, %rsp
12360- mov %arg6, %r12
12361- movdqu (%r12), %xmm13
12362+ mov %arg6, %r15
12363+ movdqu (%r15), %xmm13
12364 movdqa SHUF_MASK(%rip), %xmm2
12365 PSHUFB_XMM %xmm2, %xmm13
12366
12367@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12368 movdqa %xmm13, HashKey(%rsp)
12369 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12370 and $-16, %r13
12371- mov %r13, %r12
12372+ mov %r13, %r15
12373
12374 # Encrypt first few blocks
12375
12376- and $(3<<4), %r12
12377+ and $(3<<4), %r15
12378 jz _initial_num_blocks_is_0_encrypt
12379- cmp $(2<<4), %r12
12380+ cmp $(2<<4), %r15
12381 jb _initial_num_blocks_is_1_encrypt
12382 je _initial_num_blocks_is_2_encrypt
12383 _initial_num_blocks_is_3_encrypt:
12384@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12385 sub $16, %r11
12386 add %r13, %r11
12387 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12388- lea SHIFT_MASK+16(%rip), %r12
12389- sub %r13, %r12
12390+ lea SHIFT_MASK+16(%rip), %r15
12391+ sub %r13, %r15
12392 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12393 # (%r13 is the number of bytes in plaintext mod 16)
12394- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12395+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12396 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12397 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12398- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12399+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12400 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12401 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12402 movdqa SHUF_MASK(%rip), %xmm10
12403@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12404 sub $1, %r13
12405 jne _less_than_8_bytes_left_encrypt
12406 _multiple_of_16_bytes_encrypt:
12407- mov arg8, %r12 # %r12 = addLen (number of bytes)
12408- shl $3, %r12
12409- movd %r12d, %xmm15 # len(A) in %xmm15
12410+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12411+ shl $3, %r15
12412+ movd %r15d, %xmm15 # len(A) in %xmm15
12413 shl $3, %arg4 # len(C) in bits (*128)
12414 MOVQ_R64_XMM %arg4, %xmm1
12415 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12416@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12417 mov %r14, %rsp
12418 pop %r14
12419 pop %r13
12420- pop %r12
12421+ pop %r15
12422+ pax_force_retaddr
12423 ret
12424 ENDPROC(aesni_gcm_enc)
12425
12426@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12427 pxor %xmm1, %xmm0
12428 movaps %xmm0, (TKEYP)
12429 add $0x10, TKEYP
12430+ pax_force_retaddr
12431 ret
12432 ENDPROC(_key_expansion_128)
12433 ENDPROC(_key_expansion_256a)
12434@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12435 shufps $0b01001110, %xmm2, %xmm1
12436 movaps %xmm1, 0x10(TKEYP)
12437 add $0x20, TKEYP
12438+ pax_force_retaddr
12439 ret
12440 ENDPROC(_key_expansion_192a)
12441
12442@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12443
12444 movaps %xmm0, (TKEYP)
12445 add $0x10, TKEYP
12446+ pax_force_retaddr
12447 ret
12448 ENDPROC(_key_expansion_192b)
12449
12450@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12451 pxor %xmm1, %xmm2
12452 movaps %xmm2, (TKEYP)
12453 add $0x10, TKEYP
12454+ pax_force_retaddr
12455 ret
12456 ENDPROC(_key_expansion_256b)
12457
12458@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12459 #ifndef __x86_64__
12460 popl KEYP
12461 #endif
12462+ pax_force_retaddr
12463 ret
12464 ENDPROC(aesni_set_key)
12465
12466@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12467 popl KLEN
12468 popl KEYP
12469 #endif
12470+ pax_force_retaddr
12471 ret
12472 ENDPROC(aesni_enc)
12473
12474@@ -1974,6 +1983,7 @@ _aesni_enc1:
12475 AESENC KEY STATE
12476 movaps 0x70(TKEYP), KEY
12477 AESENCLAST KEY STATE
12478+ pax_force_retaddr
12479 ret
12480 ENDPROC(_aesni_enc1)
12481
12482@@ -2083,6 +2093,7 @@ _aesni_enc4:
12483 AESENCLAST KEY STATE2
12484 AESENCLAST KEY STATE3
12485 AESENCLAST KEY STATE4
12486+ pax_force_retaddr
12487 ret
12488 ENDPROC(_aesni_enc4)
12489
12490@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12491 popl KLEN
12492 popl KEYP
12493 #endif
12494+ pax_force_retaddr
12495 ret
12496 ENDPROC(aesni_dec)
12497
12498@@ -2164,6 +2176,7 @@ _aesni_dec1:
12499 AESDEC KEY STATE
12500 movaps 0x70(TKEYP), KEY
12501 AESDECLAST KEY STATE
12502+ pax_force_retaddr
12503 ret
12504 ENDPROC(_aesni_dec1)
12505
12506@@ -2273,6 +2286,7 @@ _aesni_dec4:
12507 AESDECLAST KEY STATE2
12508 AESDECLAST KEY STATE3
12509 AESDECLAST KEY STATE4
12510+ pax_force_retaddr
12511 ret
12512 ENDPROC(_aesni_dec4)
12513
12514@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12515 popl KEYP
12516 popl LEN
12517 #endif
12518+ pax_force_retaddr
12519 ret
12520 ENDPROC(aesni_ecb_enc)
12521
12522@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12523 popl KEYP
12524 popl LEN
12525 #endif
12526+ pax_force_retaddr
12527 ret
12528 ENDPROC(aesni_ecb_dec)
12529
12530@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12531 popl LEN
12532 popl IVP
12533 #endif
12534+ pax_force_retaddr
12535 ret
12536 ENDPROC(aesni_cbc_enc)
12537
12538@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12539 popl LEN
12540 popl IVP
12541 #endif
12542+ pax_force_retaddr
12543 ret
12544 ENDPROC(aesni_cbc_dec)
12545
12546@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12547 mov $1, TCTR_LOW
12548 MOVQ_R64_XMM TCTR_LOW INC
12549 MOVQ_R64_XMM CTR TCTR_LOW
12550+ pax_force_retaddr
12551 ret
12552 ENDPROC(_aesni_inc_init)
12553
12554@@ -2579,6 +2598,7 @@ _aesni_inc:
12555 .Linc_low:
12556 movaps CTR, IV
12557 PSHUFB_XMM BSWAP_MASK IV
12558+ pax_force_retaddr
12559 ret
12560 ENDPROC(_aesni_inc)
12561
12562@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12563 .Lctr_enc_ret:
12564 movups IV, (IVP)
12565 .Lctr_enc_just_ret:
12566+ pax_force_retaddr
12567 ret
12568 ENDPROC(aesni_ctr_enc)
12569
12570@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12571 pxor INC, STATE4
12572 movdqu STATE4, 0x70(OUTP)
12573
12574+ pax_force_retaddr
12575 ret
12576 ENDPROC(aesni_xts_crypt8)
12577
12578diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12579index 246c670..466e2d6 100644
12580--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12581+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12582@@ -21,6 +21,7 @@
12583 */
12584
12585 #include <linux/linkage.h>
12586+#include <asm/alternative-asm.h>
12587
12588 .file "blowfish-x86_64-asm.S"
12589 .text
12590@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12591 jnz .L__enc_xor;
12592
12593 write_block();
12594+ pax_force_retaddr
12595 ret;
12596 .L__enc_xor:
12597 xor_block();
12598+ pax_force_retaddr
12599 ret;
12600 ENDPROC(__blowfish_enc_blk)
12601
12602@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12603
12604 movq %r11, %rbp;
12605
12606+ pax_force_retaddr
12607 ret;
12608 ENDPROC(blowfish_dec_blk)
12609
12610@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12611
12612 popq %rbx;
12613 popq %rbp;
12614+ pax_force_retaddr
12615 ret;
12616
12617 .L__enc_xor4:
12618@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12619
12620 popq %rbx;
12621 popq %rbp;
12622+ pax_force_retaddr
12623 ret;
12624 ENDPROC(__blowfish_enc_blk_4way)
12625
12626@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12627 popq %rbx;
12628 popq %rbp;
12629
12630+ pax_force_retaddr
12631 ret;
12632 ENDPROC(blowfish_dec_blk_4way)
12633diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12634index ce71f92..1dce7ec 100644
12635--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12636+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12637@@ -16,6 +16,7 @@
12638 */
12639
12640 #include <linux/linkage.h>
12641+#include <asm/alternative-asm.h>
12642
12643 #define CAMELLIA_TABLE_BYTE_LEN 272
12644
12645@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12646 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12647 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12648 %rcx, (%r9));
12649+ pax_force_retaddr
12650 ret;
12651 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12652
12653@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12654 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12655 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12656 %rax, (%r9));
12657+ pax_force_retaddr
12658 ret;
12659 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12660
12661@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12662 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12663 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12664
12665+ pax_force_retaddr
12666 ret;
12667
12668 .align 8
12669@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12670 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12671 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12672
12673+ pax_force_retaddr
12674 ret;
12675
12676 .align 8
12677@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12678 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12679 %xmm8, %rsi);
12680
12681+ pax_force_retaddr
12682 ret;
12683 ENDPROC(camellia_ecb_enc_16way)
12684
12685@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12686 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12687 %xmm8, %rsi);
12688
12689+ pax_force_retaddr
12690 ret;
12691 ENDPROC(camellia_ecb_dec_16way)
12692
12693@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12694 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12695 %xmm8, %rsi);
12696
12697+ pax_force_retaddr
12698 ret;
12699 ENDPROC(camellia_cbc_dec_16way)
12700
12701@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12702 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12703 %xmm8, %rsi);
12704
12705+ pax_force_retaddr
12706 ret;
12707 ENDPROC(camellia_ctr_16way)
12708
12709@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12710 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12711 %xmm8, %rsi);
12712
12713+ pax_force_retaddr
12714 ret;
12715 ENDPROC(camellia_xts_crypt_16way)
12716
12717diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12718index 0e0b886..5a3123c 100644
12719--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12720+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12721@@ -11,6 +11,7 @@
12722 */
12723
12724 #include <linux/linkage.h>
12725+#include <asm/alternative-asm.h>
12726
12727 #define CAMELLIA_TABLE_BYTE_LEN 272
12728
12729@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12730 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12731 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12732 %rcx, (%r9));
12733+ pax_force_retaddr
12734 ret;
12735 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12736
12737@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12738 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12739 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12740 %rax, (%r9));
12741+ pax_force_retaddr
12742 ret;
12743 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12744
12745@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12746 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12747 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12748
12749+ pax_force_retaddr
12750 ret;
12751
12752 .align 8
12753@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12754 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12755 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12756
12757+ pax_force_retaddr
12758 ret;
12759
12760 .align 8
12761@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12762
12763 vzeroupper;
12764
12765+ pax_force_retaddr
12766 ret;
12767 ENDPROC(camellia_ecb_enc_32way)
12768
12769@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12770
12771 vzeroupper;
12772
12773+ pax_force_retaddr
12774 ret;
12775 ENDPROC(camellia_ecb_dec_32way)
12776
12777@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12778
12779 vzeroupper;
12780
12781+ pax_force_retaddr
12782 ret;
12783 ENDPROC(camellia_cbc_dec_32way)
12784
12785@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12786
12787 vzeroupper;
12788
12789+ pax_force_retaddr
12790 ret;
12791 ENDPROC(camellia_ctr_32way)
12792
12793@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12794
12795 vzeroupper;
12796
12797+ pax_force_retaddr
12798 ret;
12799 ENDPROC(camellia_xts_crypt_32way)
12800
12801diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12802index 310319c..db3d7b5 100644
12803--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12804+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12805@@ -21,6 +21,7 @@
12806 */
12807
12808 #include <linux/linkage.h>
12809+#include <asm/alternative-asm.h>
12810
12811 .file "camellia-x86_64-asm_64.S"
12812 .text
12813@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12814 enc_outunpack(mov, RT1);
12815
12816 movq RRBP, %rbp;
12817+ pax_force_retaddr
12818 ret;
12819
12820 .L__enc_xor:
12821 enc_outunpack(xor, RT1);
12822
12823 movq RRBP, %rbp;
12824+ pax_force_retaddr
12825 ret;
12826 ENDPROC(__camellia_enc_blk)
12827
12828@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12829 dec_outunpack();
12830
12831 movq RRBP, %rbp;
12832+ pax_force_retaddr
12833 ret;
12834 ENDPROC(camellia_dec_blk)
12835
12836@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12837
12838 movq RRBP, %rbp;
12839 popq %rbx;
12840+ pax_force_retaddr
12841 ret;
12842
12843 .L__enc2_xor:
12844@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12845
12846 movq RRBP, %rbp;
12847 popq %rbx;
12848+ pax_force_retaddr
12849 ret;
12850 ENDPROC(__camellia_enc_blk_2way)
12851
12852@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12853
12854 movq RRBP, %rbp;
12855 movq RXOR, %rbx;
12856+ pax_force_retaddr
12857 ret;
12858 ENDPROC(camellia_dec_blk_2way)
12859diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12860index c35fd5d..2d8c7db 100644
12861--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12862+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12863@@ -24,6 +24,7 @@
12864 */
12865
12866 #include <linux/linkage.h>
12867+#include <asm/alternative-asm.h>
12868
12869 .file "cast5-avx-x86_64-asm_64.S"
12870
12871@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12872 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12873 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12874
12875+ pax_force_retaddr
12876 ret;
12877 ENDPROC(__cast5_enc_blk16)
12878
12879@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12880 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12881 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12882
12883+ pax_force_retaddr
12884 ret;
12885
12886 .L__skip_dec:
12887@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12888 vmovdqu RR4, (6*4*4)(%r11);
12889 vmovdqu RL4, (7*4*4)(%r11);
12890
12891+ pax_force_retaddr
12892 ret;
12893 ENDPROC(cast5_ecb_enc_16way)
12894
12895@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12896 vmovdqu RR4, (6*4*4)(%r11);
12897 vmovdqu RL4, (7*4*4)(%r11);
12898
12899+ pax_force_retaddr
12900 ret;
12901 ENDPROC(cast5_ecb_dec_16way)
12902
12903@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12904 * %rdx: src
12905 */
12906
12907- pushq %r12;
12908+ pushq %r14;
12909
12910 movq %rsi, %r11;
12911- movq %rdx, %r12;
12912+ movq %rdx, %r14;
12913
12914 vmovdqu (0*16)(%rdx), RL1;
12915 vmovdqu (1*16)(%rdx), RR1;
12916@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12917 call __cast5_dec_blk16;
12918
12919 /* xor with src */
12920- vmovq (%r12), RX;
12921+ vmovq (%r14), RX;
12922 vpshufd $0x4f, RX, RX;
12923 vpxor RX, RR1, RR1;
12924- vpxor 0*16+8(%r12), RL1, RL1;
12925- vpxor 1*16+8(%r12), RR2, RR2;
12926- vpxor 2*16+8(%r12), RL2, RL2;
12927- vpxor 3*16+8(%r12), RR3, RR3;
12928- vpxor 4*16+8(%r12), RL3, RL3;
12929- vpxor 5*16+8(%r12), RR4, RR4;
12930- vpxor 6*16+8(%r12), RL4, RL4;
12931+ vpxor 0*16+8(%r14), RL1, RL1;
12932+ vpxor 1*16+8(%r14), RR2, RR2;
12933+ vpxor 2*16+8(%r14), RL2, RL2;
12934+ vpxor 3*16+8(%r14), RR3, RR3;
12935+ vpxor 4*16+8(%r14), RL3, RL3;
12936+ vpxor 5*16+8(%r14), RR4, RR4;
12937+ vpxor 6*16+8(%r14), RL4, RL4;
12938
12939 vmovdqu RR1, (0*16)(%r11);
12940 vmovdqu RL1, (1*16)(%r11);
12941@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12942 vmovdqu RR4, (6*16)(%r11);
12943 vmovdqu RL4, (7*16)(%r11);
12944
12945- popq %r12;
12946+ popq %r14;
12947
12948+ pax_force_retaddr
12949 ret;
12950 ENDPROC(cast5_cbc_dec_16way)
12951
12952@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12953 * %rcx: iv (big endian, 64bit)
12954 */
12955
12956- pushq %r12;
12957+ pushq %r14;
12958
12959 movq %rsi, %r11;
12960- movq %rdx, %r12;
12961+ movq %rdx, %r14;
12962
12963 vpcmpeqd RTMP, RTMP, RTMP;
12964 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
12965@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
12966 call __cast5_enc_blk16;
12967
12968 /* dst = src ^ iv */
12969- vpxor (0*16)(%r12), RR1, RR1;
12970- vpxor (1*16)(%r12), RL1, RL1;
12971- vpxor (2*16)(%r12), RR2, RR2;
12972- vpxor (3*16)(%r12), RL2, RL2;
12973- vpxor (4*16)(%r12), RR3, RR3;
12974- vpxor (5*16)(%r12), RL3, RL3;
12975- vpxor (6*16)(%r12), RR4, RR4;
12976- vpxor (7*16)(%r12), RL4, RL4;
12977+ vpxor (0*16)(%r14), RR1, RR1;
12978+ vpxor (1*16)(%r14), RL1, RL1;
12979+ vpxor (2*16)(%r14), RR2, RR2;
12980+ vpxor (3*16)(%r14), RL2, RL2;
12981+ vpxor (4*16)(%r14), RR3, RR3;
12982+ vpxor (5*16)(%r14), RL3, RL3;
12983+ vpxor (6*16)(%r14), RR4, RR4;
12984+ vpxor (7*16)(%r14), RL4, RL4;
12985 vmovdqu RR1, (0*16)(%r11);
12986 vmovdqu RL1, (1*16)(%r11);
12987 vmovdqu RR2, (2*16)(%r11);
12988@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
12989 vmovdqu RR4, (6*16)(%r11);
12990 vmovdqu RL4, (7*16)(%r11);
12991
12992- popq %r12;
12993+ popq %r14;
12994
12995+ pax_force_retaddr
12996 ret;
12997 ENDPROC(cast5_ctr_16way)
12998diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12999index e3531f8..e123f35 100644
13000--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13001+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13002@@ -24,6 +24,7 @@
13003 */
13004
13005 #include <linux/linkage.h>
13006+#include <asm/alternative-asm.h>
13007 #include "glue_helper-asm-avx.S"
13008
13009 .file "cast6-avx-x86_64-asm_64.S"
13010@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13011 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13012 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13013
13014+ pax_force_retaddr
13015 ret;
13016 ENDPROC(__cast6_enc_blk8)
13017
13018@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13019 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13020 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13021
13022+ pax_force_retaddr
13023 ret;
13024 ENDPROC(__cast6_dec_blk8)
13025
13026@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13027
13028 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13029
13030+ pax_force_retaddr
13031 ret;
13032 ENDPROC(cast6_ecb_enc_8way)
13033
13034@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13035
13036 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13037
13038+ pax_force_retaddr
13039 ret;
13040 ENDPROC(cast6_ecb_dec_8way)
13041
13042@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13043 * %rdx: src
13044 */
13045
13046- pushq %r12;
13047+ pushq %r14;
13048
13049 movq %rsi, %r11;
13050- movq %rdx, %r12;
13051+ movq %rdx, %r14;
13052
13053 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13054
13055 call __cast6_dec_blk8;
13056
13057- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13058+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13059
13060- popq %r12;
13061+ popq %r14;
13062
13063+ pax_force_retaddr
13064 ret;
13065 ENDPROC(cast6_cbc_dec_8way)
13066
13067@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13068 * %rcx: iv (little endian, 128bit)
13069 */
13070
13071- pushq %r12;
13072+ pushq %r14;
13073
13074 movq %rsi, %r11;
13075- movq %rdx, %r12;
13076+ movq %rdx, %r14;
13077
13078 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13079 RD2, RX, RKR, RKM);
13080
13081 call __cast6_enc_blk8;
13082
13083- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13084+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13085
13086- popq %r12;
13087+ popq %r14;
13088
13089+ pax_force_retaddr
13090 ret;
13091 ENDPROC(cast6_ctr_8way)
13092
13093@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13094 /* dst <= regs xor IVs(in dst) */
13095 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13096
13097+ pax_force_retaddr
13098 ret;
13099 ENDPROC(cast6_xts_enc_8way)
13100
13101@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13102 /* dst <= regs xor IVs(in dst) */
13103 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13104
13105+ pax_force_retaddr
13106 ret;
13107 ENDPROC(cast6_xts_dec_8way)
13108diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13109index dbc4339..de6e120 100644
13110--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13111+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13112@@ -45,6 +45,7 @@
13113
13114 #include <asm/inst.h>
13115 #include <linux/linkage.h>
13116+#include <asm/alternative-asm.h>
13117
13118 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13119
13120@@ -312,6 +313,7 @@ do_return:
13121 popq %rsi
13122 popq %rdi
13123 popq %rbx
13124+ pax_force_retaddr
13125 ret
13126
13127 ################################################################
13128diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13129index 586f41a..d02851e 100644
13130--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13131+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13132@@ -18,6 +18,7 @@
13133
13134 #include <linux/linkage.h>
13135 #include <asm/inst.h>
13136+#include <asm/alternative-asm.h>
13137
13138 .data
13139
13140@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13141 psrlq $1, T2
13142 pxor T2, T1
13143 pxor T1, DATA
13144+ pax_force_retaddr
13145 ret
13146 ENDPROC(__clmul_gf128mul_ble)
13147
13148@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13149 call __clmul_gf128mul_ble
13150 PSHUFB_XMM BSWAP DATA
13151 movups DATA, (%rdi)
13152+ pax_force_retaddr
13153 ret
13154 ENDPROC(clmul_ghash_mul)
13155
13156@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13157 PSHUFB_XMM BSWAP DATA
13158 movups DATA, (%rdi)
13159 .Lupdate_just_ret:
13160+ pax_force_retaddr
13161 ret
13162 ENDPROC(clmul_ghash_update)
13163
13164@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13165 pand .Lpoly, %xmm1
13166 pxor %xmm1, %xmm0
13167 movups %xmm0, (%rdi)
13168+ pax_force_retaddr
13169 ret
13170 ENDPROC(clmul_ghash_setkey)
13171diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13172index 9279e0b..c4b3d2c 100644
13173--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13174+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13175@@ -1,4 +1,5 @@
13176 #include <linux/linkage.h>
13177+#include <asm/alternative-asm.h>
13178
13179 # enter salsa20_encrypt_bytes
13180 ENTRY(salsa20_encrypt_bytes)
13181@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13182 add %r11,%rsp
13183 mov %rdi,%rax
13184 mov %rsi,%rdx
13185+ pax_force_retaddr
13186 ret
13187 # bytesatleast65:
13188 ._bytesatleast65:
13189@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13190 add %r11,%rsp
13191 mov %rdi,%rax
13192 mov %rsi,%rdx
13193+ pax_force_retaddr
13194 ret
13195 ENDPROC(salsa20_keysetup)
13196
13197@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13198 add %r11,%rsp
13199 mov %rdi,%rax
13200 mov %rsi,%rdx
13201+ pax_force_retaddr
13202 ret
13203 ENDPROC(salsa20_ivsetup)
13204diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13205index 2f202f4..d9164d6 100644
13206--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13207+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13208@@ -24,6 +24,7 @@
13209 */
13210
13211 #include <linux/linkage.h>
13212+#include <asm/alternative-asm.h>
13213 #include "glue_helper-asm-avx.S"
13214
13215 .file "serpent-avx-x86_64-asm_64.S"
13216@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13217 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13218 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13219
13220+ pax_force_retaddr
13221 ret;
13222 ENDPROC(__serpent_enc_blk8_avx)
13223
13224@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13225 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13226 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13227
13228+ pax_force_retaddr
13229 ret;
13230 ENDPROC(__serpent_dec_blk8_avx)
13231
13232@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13233
13234 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13235
13236+ pax_force_retaddr
13237 ret;
13238 ENDPROC(serpent_ecb_enc_8way_avx)
13239
13240@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13241
13242 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13243
13244+ pax_force_retaddr
13245 ret;
13246 ENDPROC(serpent_ecb_dec_8way_avx)
13247
13248@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13249
13250 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13251
13252+ pax_force_retaddr
13253 ret;
13254 ENDPROC(serpent_cbc_dec_8way_avx)
13255
13256@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13257
13258 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13259
13260+ pax_force_retaddr
13261 ret;
13262 ENDPROC(serpent_ctr_8way_avx)
13263
13264@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13265 /* dst <= regs xor IVs(in dst) */
13266 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13267
13268+ pax_force_retaddr
13269 ret;
13270 ENDPROC(serpent_xts_enc_8way_avx)
13271
13272@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13273 /* dst <= regs xor IVs(in dst) */
13274 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13275
13276+ pax_force_retaddr
13277 ret;
13278 ENDPROC(serpent_xts_dec_8way_avx)
13279diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13280index b222085..abd483c 100644
13281--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13282+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13283@@ -15,6 +15,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287+#include <asm/alternative-asm.h>
13288 #include "glue_helper-asm-avx2.S"
13289
13290 .file "serpent-avx2-asm_64.S"
13291@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13292 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13293 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13294
13295+ pax_force_retaddr
13296 ret;
13297 ENDPROC(__serpent_enc_blk16)
13298
13299@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13300 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13301 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13302
13303+ pax_force_retaddr
13304 ret;
13305 ENDPROC(__serpent_dec_blk16)
13306
13307@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13308
13309 vzeroupper;
13310
13311+ pax_force_retaddr
13312 ret;
13313 ENDPROC(serpent_ecb_enc_16way)
13314
13315@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13316
13317 vzeroupper;
13318
13319+ pax_force_retaddr
13320 ret;
13321 ENDPROC(serpent_ecb_dec_16way)
13322
13323@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13324
13325 vzeroupper;
13326
13327+ pax_force_retaddr
13328 ret;
13329 ENDPROC(serpent_cbc_dec_16way)
13330
13331@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13332
13333 vzeroupper;
13334
13335+ pax_force_retaddr
13336 ret;
13337 ENDPROC(serpent_ctr_16way)
13338
13339@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13340
13341 vzeroupper;
13342
13343+ pax_force_retaddr
13344 ret;
13345 ENDPROC(serpent_xts_enc_16way)
13346
13347@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13348
13349 vzeroupper;
13350
13351+ pax_force_retaddr
13352 ret;
13353 ENDPROC(serpent_xts_dec_16way)
13354diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13355index acc066c..1559cc4 100644
13356--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13357+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13358@@ -25,6 +25,7 @@
13359 */
13360
13361 #include <linux/linkage.h>
13362+#include <asm/alternative-asm.h>
13363
13364 .file "serpent-sse2-x86_64-asm_64.S"
13365 .text
13366@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13367 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13368 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13369
13370+ pax_force_retaddr
13371 ret;
13372
13373 .L__enc_xor8:
13374 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13375 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13376
13377+ pax_force_retaddr
13378 ret;
13379 ENDPROC(__serpent_enc_blk_8way)
13380
13381@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13382 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13383 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13384
13385+ pax_force_retaddr
13386 ret;
13387 ENDPROC(serpent_dec_blk_8way)
13388diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13389index a410950..9dfe7ad 100644
13390--- a/arch/x86/crypto/sha1_ssse3_asm.S
13391+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13392@@ -29,6 +29,7 @@
13393 */
13394
13395 #include <linux/linkage.h>
13396+#include <asm/alternative-asm.h>
13397
13398 #define CTX %rdi // arg1
13399 #define BUF %rsi // arg2
13400@@ -75,9 +76,9 @@
13401
13402 push %rbx
13403 push %rbp
13404- push %r12
13405+ push %r14
13406
13407- mov %rsp, %r12
13408+ mov %rsp, %r14
13409 sub $64, %rsp # allocate workspace
13410 and $~15, %rsp # align stack
13411
13412@@ -99,11 +100,12 @@
13413 xor %rax, %rax
13414 rep stosq
13415
13416- mov %r12, %rsp # deallocate workspace
13417+ mov %r14, %rsp # deallocate workspace
13418
13419- pop %r12
13420+ pop %r14
13421 pop %rbp
13422 pop %rbx
13423+ pax_force_retaddr
13424 ret
13425
13426 ENDPROC(\name)
13427diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13428index 642f156..51a513c 100644
13429--- a/arch/x86/crypto/sha256-avx-asm.S
13430+++ b/arch/x86/crypto/sha256-avx-asm.S
13431@@ -49,6 +49,7 @@
13432
13433 #ifdef CONFIG_AS_AVX
13434 #include <linux/linkage.h>
13435+#include <asm/alternative-asm.h>
13436
13437 ## assume buffers not aligned
13438 #define VMOVDQ vmovdqu
13439@@ -460,6 +461,7 @@ done_hash:
13440 popq %r13
13441 popq %rbp
13442 popq %rbx
13443+ pax_force_retaddr
13444 ret
13445 ENDPROC(sha256_transform_avx)
13446
13447diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13448index 9e86944..3795e6a 100644
13449--- a/arch/x86/crypto/sha256-avx2-asm.S
13450+++ b/arch/x86/crypto/sha256-avx2-asm.S
13451@@ -50,6 +50,7 @@
13452
13453 #ifdef CONFIG_AS_AVX2
13454 #include <linux/linkage.h>
13455+#include <asm/alternative-asm.h>
13456
13457 ## assume buffers not aligned
13458 #define VMOVDQ vmovdqu
13459@@ -720,6 +721,7 @@ done_hash:
13460 popq %r12
13461 popq %rbp
13462 popq %rbx
13463+ pax_force_retaddr
13464 ret
13465 ENDPROC(sha256_transform_rorx)
13466
13467diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13468index f833b74..8c62a9e 100644
13469--- a/arch/x86/crypto/sha256-ssse3-asm.S
13470+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13471@@ -47,6 +47,7 @@
13472 ########################################################################
13473
13474 #include <linux/linkage.h>
13475+#include <asm/alternative-asm.h>
13476
13477 ## assume buffers not aligned
13478 #define MOVDQ movdqu
13479@@ -471,6 +472,7 @@ done_hash:
13480 popq %rbp
13481 popq %rbx
13482
13483+ pax_force_retaddr
13484 ret
13485 ENDPROC(sha256_transform_ssse3)
13486
13487diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13488index 974dde9..a823ff9 100644
13489--- a/arch/x86/crypto/sha512-avx-asm.S
13490+++ b/arch/x86/crypto/sha512-avx-asm.S
13491@@ -49,6 +49,7 @@
13492
13493 #ifdef CONFIG_AS_AVX
13494 #include <linux/linkage.h>
13495+#include <asm/alternative-asm.h>
13496
13497 .text
13498
13499@@ -364,6 +365,7 @@ updateblock:
13500 mov frame_RSPSAVE(%rsp), %rsp
13501
13502 nowork:
13503+ pax_force_retaddr
13504 ret
13505 ENDPROC(sha512_transform_avx)
13506
13507diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13508index 568b961..ed20c37 100644
13509--- a/arch/x86/crypto/sha512-avx2-asm.S
13510+++ b/arch/x86/crypto/sha512-avx2-asm.S
13511@@ -51,6 +51,7 @@
13512
13513 #ifdef CONFIG_AS_AVX2
13514 #include <linux/linkage.h>
13515+#include <asm/alternative-asm.h>
13516
13517 .text
13518
13519@@ -678,6 +679,7 @@ done_hash:
13520
13521 # Restore Stack Pointer
13522 mov frame_RSPSAVE(%rsp), %rsp
13523+ pax_force_retaddr
13524 ret
13525 ENDPROC(sha512_transform_rorx)
13526
13527diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13528index fb56855..6edd768 100644
13529--- a/arch/x86/crypto/sha512-ssse3-asm.S
13530+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13531@@ -48,6 +48,7 @@
13532 ########################################################################
13533
13534 #include <linux/linkage.h>
13535+#include <asm/alternative-asm.h>
13536
13537 .text
13538
13539@@ -363,6 +364,7 @@ updateblock:
13540 mov frame_RSPSAVE(%rsp), %rsp
13541
13542 nowork:
13543+ pax_force_retaddr
13544 ret
13545 ENDPROC(sha512_transform_ssse3)
13546
13547diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13548index 0505813..b067311 100644
13549--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13550+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13551@@ -24,6 +24,7 @@
13552 */
13553
13554 #include <linux/linkage.h>
13555+#include <asm/alternative-asm.h>
13556 #include "glue_helper-asm-avx.S"
13557
13558 .file "twofish-avx-x86_64-asm_64.S"
13559@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13560 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13561 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13562
13563+ pax_force_retaddr
13564 ret;
13565 ENDPROC(__twofish_enc_blk8)
13566
13567@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13568 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13569 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13570
13571+ pax_force_retaddr
13572 ret;
13573 ENDPROC(__twofish_dec_blk8)
13574
13575@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13576
13577 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13578
13579+ pax_force_retaddr
13580 ret;
13581 ENDPROC(twofish_ecb_enc_8way)
13582
13583@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13584
13585 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13586
13587+ pax_force_retaddr
13588 ret;
13589 ENDPROC(twofish_ecb_dec_8way)
13590
13591@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13592 * %rdx: src
13593 */
13594
13595- pushq %r12;
13596+ pushq %r14;
13597
13598 movq %rsi, %r11;
13599- movq %rdx, %r12;
13600+ movq %rdx, %r14;
13601
13602 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13603
13604 call __twofish_dec_blk8;
13605
13606- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13607+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13608
13609- popq %r12;
13610+ popq %r14;
13611
13612+ pax_force_retaddr
13613 ret;
13614 ENDPROC(twofish_cbc_dec_8way)
13615
13616@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13617 * %rcx: iv (little endian, 128bit)
13618 */
13619
13620- pushq %r12;
13621+ pushq %r14;
13622
13623 movq %rsi, %r11;
13624- movq %rdx, %r12;
13625+ movq %rdx, %r14;
13626
13627 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13628 RD2, RX0, RX1, RY0);
13629
13630 call __twofish_enc_blk8;
13631
13632- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13633+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13634
13635- popq %r12;
13636+ popq %r14;
13637
13638+ pax_force_retaddr
13639 ret;
13640 ENDPROC(twofish_ctr_8way)
13641
13642@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13643 /* dst <= regs xor IVs(in dst) */
13644 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13645
13646+ pax_force_retaddr
13647 ret;
13648 ENDPROC(twofish_xts_enc_8way)
13649
13650@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13651 /* dst <= regs xor IVs(in dst) */
13652 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13653
13654+ pax_force_retaddr
13655 ret;
13656 ENDPROC(twofish_xts_dec_8way)
13657diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13658index 1c3b7ce..02f578d 100644
13659--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13660+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13661@@ -21,6 +21,7 @@
13662 */
13663
13664 #include <linux/linkage.h>
13665+#include <asm/alternative-asm.h>
13666
13667 .file "twofish-x86_64-asm-3way.S"
13668 .text
13669@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13670 popq %r13;
13671 popq %r14;
13672 popq %r15;
13673+ pax_force_retaddr
13674 ret;
13675
13676 .L__enc_xor3:
13677@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13678 popq %r13;
13679 popq %r14;
13680 popq %r15;
13681+ pax_force_retaddr
13682 ret;
13683 ENDPROC(__twofish_enc_blk_3way)
13684
13685@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13686 popq %r13;
13687 popq %r14;
13688 popq %r15;
13689+ pax_force_retaddr
13690 ret;
13691 ENDPROC(twofish_dec_blk_3way)
13692diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13693index a039d21..524b8b2 100644
13694--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13695+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13696@@ -22,6 +22,7 @@
13697
13698 #include <linux/linkage.h>
13699 #include <asm/asm-offsets.h>
13700+#include <asm/alternative-asm.h>
13701
13702 #define a_offset 0
13703 #define b_offset 4
13704@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13705
13706 popq R1
13707 movq $1,%rax
13708+ pax_force_retaddr
13709 ret
13710 ENDPROC(twofish_enc_blk)
13711
13712@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13713
13714 popq R1
13715 movq $1,%rax
13716+ pax_force_retaddr
13717 ret
13718 ENDPROC(twofish_dec_blk)
13719diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13720index bae3aba..c1788c1 100644
13721--- a/arch/x86/ia32/ia32_aout.c
13722+++ b/arch/x86/ia32/ia32_aout.c
13723@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13724 unsigned long dump_start, dump_size;
13725 struct user32 dump;
13726
13727+ memset(&dump, 0, sizeof(dump));
13728+
13729 fs = get_fs();
13730 set_fs(KERNEL_DS);
13731 has_dumped = 1;
13732diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13733index 665a730..8e7a67a 100644
13734--- a/arch/x86/ia32/ia32_signal.c
13735+++ b/arch/x86/ia32/ia32_signal.c
13736@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13737 sp -= frame_size;
13738 /* Align the stack pointer according to the i386 ABI,
13739 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13740- sp = ((sp + 4) & -16ul) - 4;
13741+ sp = ((sp - 12) & -16ul) - 4;
13742 return (void __user *) sp;
13743 }
13744
13745@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13746 * These are actually not used anymore, but left because some
13747 * gdb versions depend on them as a marker.
13748 */
13749- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13750+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13751 } put_user_catch(err);
13752
13753 if (err)
13754@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13755 0xb8,
13756 __NR_ia32_rt_sigreturn,
13757 0x80cd,
13758- 0,
13759+ 0
13760 };
13761
13762 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13763@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13764
13765 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13766 restorer = ksig->ka.sa.sa_restorer;
13767+ else if (current->mm->context.vdso)
13768+ /* Return stub is in 32bit vsyscall page */
13769+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13770 else
13771- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13772- rt_sigreturn);
13773+ restorer = &frame->retcode;
13774 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13775
13776 /*
13777 * Not actually used anymore, but left because some gdb
13778 * versions need it.
13779 */
13780- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13781+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13782 } put_user_catch(err);
13783
13784 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13785diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13786index 4299eb0..c0687a7 100644
13787--- a/arch/x86/ia32/ia32entry.S
13788+++ b/arch/x86/ia32/ia32entry.S
13789@@ -15,8 +15,10 @@
13790 #include <asm/irqflags.h>
13791 #include <asm/asm.h>
13792 #include <asm/smap.h>
13793+#include <asm/pgtable.h>
13794 #include <linux/linkage.h>
13795 #include <linux/err.h>
13796+#include <asm/alternative-asm.h>
13797
13798 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13799 #include <linux/elf-em.h>
13800@@ -62,12 +64,12 @@
13801 */
13802 .macro LOAD_ARGS32 offset, _r9=0
13803 .if \_r9
13804- movl \offset+16(%rsp),%r9d
13805+ movl \offset+R9(%rsp),%r9d
13806 .endif
13807- movl \offset+40(%rsp),%ecx
13808- movl \offset+48(%rsp),%edx
13809- movl \offset+56(%rsp),%esi
13810- movl \offset+64(%rsp),%edi
13811+ movl \offset+RCX(%rsp),%ecx
13812+ movl \offset+RDX(%rsp),%edx
13813+ movl \offset+RSI(%rsp),%esi
13814+ movl \offset+RDI(%rsp),%edi
13815 movl %eax,%eax /* zero extension */
13816 .endm
13817
13818@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13819 ENDPROC(native_irq_enable_sysexit)
13820 #endif
13821
13822+ .macro pax_enter_kernel_user
13823+ pax_set_fptr_mask
13824+#ifdef CONFIG_PAX_MEMORY_UDEREF
13825+ call pax_enter_kernel_user
13826+#endif
13827+ .endm
13828+
13829+ .macro pax_exit_kernel_user
13830+#ifdef CONFIG_PAX_MEMORY_UDEREF
13831+ call pax_exit_kernel_user
13832+#endif
13833+#ifdef CONFIG_PAX_RANDKSTACK
13834+ pushq %rax
13835+ pushq %r11
13836+ call pax_randomize_kstack
13837+ popq %r11
13838+ popq %rax
13839+#endif
13840+ .endm
13841+
13842+ .macro pax_erase_kstack
13843+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13844+ call pax_erase_kstack
13845+#endif
13846+ .endm
13847+
13848 /*
13849 * 32bit SYSENTER instruction entry.
13850 *
13851@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13852 CFI_REGISTER rsp,rbp
13853 SWAPGS_UNSAFE_STACK
13854 movq PER_CPU_VAR(kernel_stack), %rsp
13855- addq $(KERNEL_STACK_OFFSET),%rsp
13856- /*
13857- * No need to follow this irqs on/off section: the syscall
13858- * disabled irqs, here we enable it straight after entry:
13859- */
13860- ENABLE_INTERRUPTS(CLBR_NONE)
13861 movl %ebp,%ebp /* zero extension */
13862 pushq_cfi $__USER32_DS
13863 /*CFI_REL_OFFSET ss,0*/
13864@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13865 CFI_REL_OFFSET rsp,0
13866 pushfq_cfi
13867 /*CFI_REL_OFFSET rflags,0*/
13868- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13869- CFI_REGISTER rip,r10
13870+ orl $X86_EFLAGS_IF,(%rsp)
13871+ GET_THREAD_INFO(%r11)
13872+ movl TI_sysenter_return(%r11), %r11d
13873+ CFI_REGISTER rip,r11
13874 pushq_cfi $__USER32_CS
13875 /*CFI_REL_OFFSET cs,0*/
13876 movl %eax, %eax
13877- pushq_cfi %r10
13878+ pushq_cfi %r11
13879 CFI_REL_OFFSET rip,0
13880 pushq_cfi %rax
13881 cld
13882 SAVE_ARGS 0,1,0
13883+ pax_enter_kernel_user
13884+
13885+#ifdef CONFIG_PAX_RANDKSTACK
13886+ pax_erase_kstack
13887+#endif
13888+
13889+ /*
13890+ * No need to follow this irqs on/off section: the syscall
13891+ * disabled irqs, here we enable it straight after entry:
13892+ */
13893+ ENABLE_INTERRUPTS(CLBR_NONE)
13894 /* no need to do an access_ok check here because rbp has been
13895 32bit zero extended */
13896+
13897+#ifdef CONFIG_PAX_MEMORY_UDEREF
13898+ addq pax_user_shadow_base,%rbp
13899+ ASM_PAX_OPEN_USERLAND
13900+#endif
13901+
13902 ASM_STAC
13903 1: movl (%rbp),%ebp
13904 _ASM_EXTABLE(1b,ia32_badarg)
13905 ASM_CLAC
13906- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13907- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13908+
13909+#ifdef CONFIG_PAX_MEMORY_UDEREF
13910+ ASM_PAX_CLOSE_USERLAND
13911+#endif
13912+
13913+ GET_THREAD_INFO(%r11)
13914+ orl $TS_COMPAT,TI_status(%r11)
13915+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13916 CFI_REMEMBER_STATE
13917 jnz sysenter_tracesys
13918 cmpq $(IA32_NR_syscalls-1),%rax
13919@@ -162,15 +209,18 @@ sysenter_do_call:
13920 sysenter_dispatch:
13921 call *ia32_sys_call_table(,%rax,8)
13922 movq %rax,RAX-ARGOFFSET(%rsp)
13923+ GET_THREAD_INFO(%r11)
13924 DISABLE_INTERRUPTS(CLBR_NONE)
13925 TRACE_IRQS_OFF
13926- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13927+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13928 jnz sysexit_audit
13929 sysexit_from_sys_call:
13930- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13931+ pax_exit_kernel_user
13932+ pax_erase_kstack
13933+ andl $~TS_COMPAT,TI_status(%r11)
13934 /* clear IF, that popfq doesn't enable interrupts early */
13935- andl $~0x200,EFLAGS-R11(%rsp)
13936- movl RIP-R11(%rsp),%edx /* User %eip */
13937+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13938+ movl RIP(%rsp),%edx /* User %eip */
13939 CFI_REGISTER rip,rdx
13940 RESTORE_ARGS 0,24,0,0,0,0
13941 xorq %r8,%r8
13942@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13943 movl %eax,%esi /* 2nd arg: syscall number */
13944 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13945 call __audit_syscall_entry
13946+
13947+ pax_erase_kstack
13948+
13949 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13950 cmpq $(IA32_NR_syscalls-1),%rax
13951 ja ia32_badsys
13952@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13953 .endm
13954
13955 .macro auditsys_exit exit
13956- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13957+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13958 jnz ia32_ret_from_sys_call
13959 TRACE_IRQS_ON
13960 ENABLE_INTERRUPTS(CLBR_NONE)
13961@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13962 1: setbe %al /* 1 if error, 0 if not */
13963 movzbl %al,%edi /* zero-extend that into %edi */
13964 call __audit_syscall_exit
13965+ GET_THREAD_INFO(%r11)
13966 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13967 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13968 DISABLE_INTERRUPTS(CLBR_NONE)
13969 TRACE_IRQS_OFF
13970- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13971+ testl %edi,TI_flags(%r11)
13972 jz \exit
13973 CLEAR_RREGS -ARGOFFSET
13974 jmp int_with_check
13975@@ -237,7 +291,7 @@ sysexit_audit:
13976
13977 sysenter_tracesys:
13978 #ifdef CONFIG_AUDITSYSCALL
13979- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13980+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13981 jz sysenter_auditsys
13982 #endif
13983 SAVE_REST
13984@@ -249,6 +303,9 @@ sysenter_tracesys:
13985 RESTORE_REST
13986 cmpq $(IA32_NR_syscalls-1),%rax
13987 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13988+
13989+ pax_erase_kstack
13990+
13991 jmp sysenter_do_call
13992 CFI_ENDPROC
13993 ENDPROC(ia32_sysenter_target)
13994@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13995 ENTRY(ia32_cstar_target)
13996 CFI_STARTPROC32 simple
13997 CFI_SIGNAL_FRAME
13998- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13999+ CFI_DEF_CFA rsp,0
14000 CFI_REGISTER rip,rcx
14001 /*CFI_REGISTER rflags,r11*/
14002 SWAPGS_UNSAFE_STACK
14003 movl %esp,%r8d
14004 CFI_REGISTER rsp,r8
14005 movq PER_CPU_VAR(kernel_stack),%rsp
14006+ SAVE_ARGS 8*6,0,0
14007+ pax_enter_kernel_user
14008+
14009+#ifdef CONFIG_PAX_RANDKSTACK
14010+ pax_erase_kstack
14011+#endif
14012+
14013 /*
14014 * No need to follow this irqs on/off section: the syscall
14015 * disabled irqs and here we enable it straight after entry:
14016 */
14017 ENABLE_INTERRUPTS(CLBR_NONE)
14018- SAVE_ARGS 8,0,0
14019 movl %eax,%eax /* zero extension */
14020 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14021 movq %rcx,RIP-ARGOFFSET(%rsp)
14022@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14023 /* no need to do an access_ok check here because r8 has been
14024 32bit zero extended */
14025 /* hardware stack frame is complete now */
14026+
14027+#ifdef CONFIG_PAX_MEMORY_UDEREF
14028+ ASM_PAX_OPEN_USERLAND
14029+ movq pax_user_shadow_base,%r8
14030+ addq RSP-ARGOFFSET(%rsp),%r8
14031+#endif
14032+
14033 ASM_STAC
14034 1: movl (%r8),%r9d
14035 _ASM_EXTABLE(1b,ia32_badarg)
14036 ASM_CLAC
14037- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14038- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14039+
14040+#ifdef CONFIG_PAX_MEMORY_UDEREF
14041+ ASM_PAX_CLOSE_USERLAND
14042+#endif
14043+
14044+ GET_THREAD_INFO(%r11)
14045+ orl $TS_COMPAT,TI_status(%r11)
14046+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14047 CFI_REMEMBER_STATE
14048 jnz cstar_tracesys
14049 cmpq $IA32_NR_syscalls-1,%rax
14050@@ -319,13 +395,16 @@ cstar_do_call:
14051 cstar_dispatch:
14052 call *ia32_sys_call_table(,%rax,8)
14053 movq %rax,RAX-ARGOFFSET(%rsp)
14054+ GET_THREAD_INFO(%r11)
14055 DISABLE_INTERRUPTS(CLBR_NONE)
14056 TRACE_IRQS_OFF
14057- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14058+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14059 jnz sysretl_audit
14060 sysretl_from_sys_call:
14061- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14062- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14063+ pax_exit_kernel_user
14064+ pax_erase_kstack
14065+ andl $~TS_COMPAT,TI_status(%r11)
14066+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14067 movl RIP-ARGOFFSET(%rsp),%ecx
14068 CFI_REGISTER rip,rcx
14069 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14070@@ -352,7 +431,7 @@ sysretl_audit:
14071
14072 cstar_tracesys:
14073 #ifdef CONFIG_AUDITSYSCALL
14074- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14075+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14076 jz cstar_auditsys
14077 #endif
14078 xchgl %r9d,%ebp
14079@@ -366,11 +445,19 @@ cstar_tracesys:
14080 xchgl %ebp,%r9d
14081 cmpq $(IA32_NR_syscalls-1),%rax
14082 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14083+
14084+ pax_erase_kstack
14085+
14086 jmp cstar_do_call
14087 END(ia32_cstar_target)
14088
14089 ia32_badarg:
14090 ASM_CLAC
14091+
14092+#ifdef CONFIG_PAX_MEMORY_UDEREF
14093+ ASM_PAX_CLOSE_USERLAND
14094+#endif
14095+
14096 movq $-EFAULT,%rax
14097 jmp ia32_sysret
14098 CFI_ENDPROC
14099@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14100 CFI_REL_OFFSET rip,RIP-RIP
14101 PARAVIRT_ADJUST_EXCEPTION_FRAME
14102 SWAPGS
14103- /*
14104- * No need to follow this irqs on/off section: the syscall
14105- * disabled irqs and here we enable it straight after entry:
14106- */
14107- ENABLE_INTERRUPTS(CLBR_NONE)
14108 movl %eax,%eax
14109 pushq_cfi %rax
14110 cld
14111 /* note the registers are not zero extended to the sf.
14112 this could be a problem. */
14113 SAVE_ARGS 0,1,0
14114- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14115- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14116+ pax_enter_kernel_user
14117+
14118+#ifdef CONFIG_PAX_RANDKSTACK
14119+ pax_erase_kstack
14120+#endif
14121+
14122+ /*
14123+ * No need to follow this irqs on/off section: the syscall
14124+ * disabled irqs and here we enable it straight after entry:
14125+ */
14126+ ENABLE_INTERRUPTS(CLBR_NONE)
14127+ GET_THREAD_INFO(%r11)
14128+ orl $TS_COMPAT,TI_status(%r11)
14129+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14130 jnz ia32_tracesys
14131 cmpq $(IA32_NR_syscalls-1),%rax
14132 ja ia32_badsys
14133@@ -442,6 +536,9 @@ ia32_tracesys:
14134 RESTORE_REST
14135 cmpq $(IA32_NR_syscalls-1),%rax
14136 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14137+
14138+ pax_erase_kstack
14139+
14140 jmp ia32_do_call
14141 END(ia32_syscall)
14142
14143diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14144index 8e0ceec..af13504 100644
14145--- a/arch/x86/ia32/sys_ia32.c
14146+++ b/arch/x86/ia32/sys_ia32.c
14147@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14148 */
14149 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14150 {
14151- typeof(ubuf->st_uid) uid = 0;
14152- typeof(ubuf->st_gid) gid = 0;
14153+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14154+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14155 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14156 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14157 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14158diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14159index 372231c..51b537d 100644
14160--- a/arch/x86/include/asm/alternative-asm.h
14161+++ b/arch/x86/include/asm/alternative-asm.h
14162@@ -18,6 +18,45 @@
14163 .endm
14164 #endif
14165
14166+#ifdef KERNEXEC_PLUGIN
14167+ .macro pax_force_retaddr_bts rip=0
14168+ btsq $63,\rip(%rsp)
14169+ .endm
14170+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14171+ .macro pax_force_retaddr rip=0, reload=0
14172+ btsq $63,\rip(%rsp)
14173+ .endm
14174+ .macro pax_force_fptr ptr
14175+ btsq $63,\ptr
14176+ .endm
14177+ .macro pax_set_fptr_mask
14178+ .endm
14179+#endif
14180+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14181+ .macro pax_force_retaddr rip=0, reload=0
14182+ .if \reload
14183+ pax_set_fptr_mask
14184+ .endif
14185+ orq %r12,\rip(%rsp)
14186+ .endm
14187+ .macro pax_force_fptr ptr
14188+ orq %r12,\ptr
14189+ .endm
14190+ .macro pax_set_fptr_mask
14191+ movabs $0x8000000000000000,%r12
14192+ .endm
14193+#endif
14194+#else
14195+ .macro pax_force_retaddr rip=0, reload=0
14196+ .endm
14197+ .macro pax_force_fptr ptr
14198+ .endm
14199+ .macro pax_force_retaddr_bts rip=0
14200+ .endm
14201+ .macro pax_set_fptr_mask
14202+ .endm
14203+#endif
14204+
14205 .macro altinstruction_entry orig alt feature orig_len alt_len
14206 .long \orig - .
14207 .long \alt - .
14208diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14209index 0a3f9c9..c9d081d 100644
14210--- a/arch/x86/include/asm/alternative.h
14211+++ b/arch/x86/include/asm/alternative.h
14212@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14213 ".pushsection .discard,\"aw\",@progbits\n" \
14214 DISCARD_ENTRY(1) \
14215 ".popsection\n" \
14216- ".pushsection .altinstr_replacement, \"ax\"\n" \
14217+ ".pushsection .altinstr_replacement, \"a\"\n" \
14218 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14219 ".popsection"
14220
14221@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14222 DISCARD_ENTRY(1) \
14223 DISCARD_ENTRY(2) \
14224 ".popsection\n" \
14225- ".pushsection .altinstr_replacement, \"ax\"\n" \
14226+ ".pushsection .altinstr_replacement, \"a\"\n" \
14227 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14228 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14229 ".popsection"
14230diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14231index 1d2091a..f5074c1 100644
14232--- a/arch/x86/include/asm/apic.h
14233+++ b/arch/x86/include/asm/apic.h
14234@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14235
14236 #ifdef CONFIG_X86_LOCAL_APIC
14237
14238-extern unsigned int apic_verbosity;
14239+extern int apic_verbosity;
14240 extern int local_apic_timer_c2_ok;
14241
14242 extern int disable_apic;
14243diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14244index 20370c6..a2eb9b0 100644
14245--- a/arch/x86/include/asm/apm.h
14246+++ b/arch/x86/include/asm/apm.h
14247@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14248 __asm__ __volatile__(APM_DO_ZERO_SEGS
14249 "pushl %%edi\n\t"
14250 "pushl %%ebp\n\t"
14251- "lcall *%%cs:apm_bios_entry\n\t"
14252+ "lcall *%%ss:apm_bios_entry\n\t"
14253 "setc %%al\n\t"
14254 "popl %%ebp\n\t"
14255 "popl %%edi\n\t"
14256@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14257 __asm__ __volatile__(APM_DO_ZERO_SEGS
14258 "pushl %%edi\n\t"
14259 "pushl %%ebp\n\t"
14260- "lcall *%%cs:apm_bios_entry\n\t"
14261+ "lcall *%%ss:apm_bios_entry\n\t"
14262 "setc %%bl\n\t"
14263 "popl %%ebp\n\t"
14264 "popl %%edi\n\t"
14265diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14266index 722aa3b..c392d85 100644
14267--- a/arch/x86/include/asm/atomic.h
14268+++ b/arch/x86/include/asm/atomic.h
14269@@ -22,7 +22,18 @@
14270 */
14271 static inline int atomic_read(const atomic_t *v)
14272 {
14273- return (*(volatile int *)&(v)->counter);
14274+ return (*(volatile const int *)&(v)->counter);
14275+}
14276+
14277+/**
14278+ * atomic_read_unchecked - read atomic variable
14279+ * @v: pointer of type atomic_unchecked_t
14280+ *
14281+ * Atomically reads the value of @v.
14282+ */
14283+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14284+{
14285+ return (*(volatile const int *)&(v)->counter);
14286 }
14287
14288 /**
14289@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
14290 }
14291
14292 /**
14293+ * atomic_set_unchecked - set atomic variable
14294+ * @v: pointer of type atomic_unchecked_t
14295+ * @i: required value
14296+ *
14297+ * Atomically sets the value of @v to @i.
14298+ */
14299+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14300+{
14301+ v->counter = i;
14302+}
14303+
14304+/**
14305 * atomic_add - add integer to atomic variable
14306 * @i: integer value to add
14307 * @v: pointer of type atomic_t
14308@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
14309 */
14310 static inline void atomic_add(int i, atomic_t *v)
14311 {
14312- asm volatile(LOCK_PREFIX "addl %1,%0"
14313+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14314+
14315+#ifdef CONFIG_PAX_REFCOUNT
14316+ "jno 0f\n"
14317+ LOCK_PREFIX "subl %1,%0\n"
14318+ "int $4\n0:\n"
14319+ _ASM_EXTABLE(0b, 0b)
14320+#endif
14321+
14322+ : "+m" (v->counter)
14323+ : "ir" (i));
14324+}
14325+
14326+/**
14327+ * atomic_add_unchecked - add integer to atomic variable
14328+ * @i: integer value to add
14329+ * @v: pointer of type atomic_unchecked_t
14330+ *
14331+ * Atomically adds @i to @v.
14332+ */
14333+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14334+{
14335+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14336 : "+m" (v->counter)
14337 : "ir" (i));
14338 }
14339@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
14340 */
14341 static inline void atomic_sub(int i, atomic_t *v)
14342 {
14343- asm volatile(LOCK_PREFIX "subl %1,%0"
14344+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14345+
14346+#ifdef CONFIG_PAX_REFCOUNT
14347+ "jno 0f\n"
14348+ LOCK_PREFIX "addl %1,%0\n"
14349+ "int $4\n0:\n"
14350+ _ASM_EXTABLE(0b, 0b)
14351+#endif
14352+
14353+ : "+m" (v->counter)
14354+ : "ir" (i));
14355+}
14356+
14357+/**
14358+ * atomic_sub_unchecked - subtract integer from atomic variable
14359+ * @i: integer value to subtract
14360+ * @v: pointer of type atomic_unchecked_t
14361+ *
14362+ * Atomically subtracts @i from @v.
14363+ */
14364+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14365+{
14366+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14367 : "+m" (v->counter)
14368 : "ir" (i));
14369 }
14370@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14371 {
14372 unsigned char c;
14373
14374- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
14375+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
14376+
14377+#ifdef CONFIG_PAX_REFCOUNT
14378+ "jno 0f\n"
14379+ LOCK_PREFIX "addl %2,%0\n"
14380+ "int $4\n0:\n"
14381+ _ASM_EXTABLE(0b, 0b)
14382+#endif
14383+
14384+ "sete %1\n"
14385 : "+m" (v->counter), "=qm" (c)
14386 : "ir" (i) : "memory");
14387 return c;
14388@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14389 */
14390 static inline void atomic_inc(atomic_t *v)
14391 {
14392- asm volatile(LOCK_PREFIX "incl %0"
14393+ asm volatile(LOCK_PREFIX "incl %0\n"
14394+
14395+#ifdef CONFIG_PAX_REFCOUNT
14396+ "jno 0f\n"
14397+ LOCK_PREFIX "decl %0\n"
14398+ "int $4\n0:\n"
14399+ _ASM_EXTABLE(0b, 0b)
14400+#endif
14401+
14402+ : "+m" (v->counter));
14403+}
14404+
14405+/**
14406+ * atomic_inc_unchecked - increment atomic variable
14407+ * @v: pointer of type atomic_unchecked_t
14408+ *
14409+ * Atomically increments @v by 1.
14410+ */
14411+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14412+{
14413+ asm volatile(LOCK_PREFIX "incl %0\n"
14414 : "+m" (v->counter));
14415 }
14416
14417@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
14418 */
14419 static inline void atomic_dec(atomic_t *v)
14420 {
14421- asm volatile(LOCK_PREFIX "decl %0"
14422+ asm volatile(LOCK_PREFIX "decl %0\n"
14423+
14424+#ifdef CONFIG_PAX_REFCOUNT
14425+ "jno 0f\n"
14426+ LOCK_PREFIX "incl %0\n"
14427+ "int $4\n0:\n"
14428+ _ASM_EXTABLE(0b, 0b)
14429+#endif
14430+
14431+ : "+m" (v->counter));
14432+}
14433+
14434+/**
14435+ * atomic_dec_unchecked - decrement atomic variable
14436+ * @v: pointer of type atomic_unchecked_t
14437+ *
14438+ * Atomically decrements @v by 1.
14439+ */
14440+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14441+{
14442+ asm volatile(LOCK_PREFIX "decl %0\n"
14443 : "+m" (v->counter));
14444 }
14445
14446@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
14447 {
14448 unsigned char c;
14449
14450- asm volatile(LOCK_PREFIX "decl %0; sete %1"
14451+ asm volatile(LOCK_PREFIX "decl %0\n"
14452+
14453+#ifdef CONFIG_PAX_REFCOUNT
14454+ "jno 0f\n"
14455+ LOCK_PREFIX "incl %0\n"
14456+ "int $4\n0:\n"
14457+ _ASM_EXTABLE(0b, 0b)
14458+#endif
14459+
14460+ "sete %1\n"
14461 : "+m" (v->counter), "=qm" (c)
14462 : : "memory");
14463 return c != 0;
14464@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
14465 {
14466 unsigned char c;
14467
14468- asm volatile(LOCK_PREFIX "incl %0; sete %1"
14469+ asm volatile(LOCK_PREFIX "incl %0\n"
14470+
14471+#ifdef CONFIG_PAX_REFCOUNT
14472+ "jno 0f\n"
14473+ LOCK_PREFIX "decl %0\n"
14474+ "int $4\n0:\n"
14475+ _ASM_EXTABLE(0b, 0b)
14476+#endif
14477+
14478+ "sete %1\n"
14479+ : "+m" (v->counter), "=qm" (c)
14480+ : : "memory");
14481+ return c != 0;
14482+}
14483+
14484+/**
14485+ * atomic_inc_and_test_unchecked - increment and test
14486+ * @v: pointer of type atomic_unchecked_t
14487+ *
14488+ * Atomically increments @v by 1
14489+ * and returns true if the result is zero, or false for all
14490+ * other cases.
14491+ */
14492+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14493+{
14494+ unsigned char c;
14495+
14496+ asm volatile(LOCK_PREFIX "incl %0\n"
14497+ "sete %1\n"
14498 : "+m" (v->counter), "=qm" (c)
14499 : : "memory");
14500 return c != 0;
14501@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14502 {
14503 unsigned char c;
14504
14505- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14506+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14507+
14508+#ifdef CONFIG_PAX_REFCOUNT
14509+ "jno 0f\n"
14510+ LOCK_PREFIX "subl %2,%0\n"
14511+ "int $4\n0:\n"
14512+ _ASM_EXTABLE(0b, 0b)
14513+#endif
14514+
14515+ "sets %1\n"
14516 : "+m" (v->counter), "=qm" (c)
14517 : "ir" (i) : "memory");
14518 return c;
14519@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14520 */
14521 static inline int atomic_add_return(int i, atomic_t *v)
14522 {
14523+ return i + xadd_check_overflow(&v->counter, i);
14524+}
14525+
14526+/**
14527+ * atomic_add_return_unchecked - add integer and return
14528+ * @i: integer value to add
14529+ * @v: pointer of type atomic_unchecked_t
14530+ *
14531+ * Atomically adds @i to @v and returns @i + @v
14532+ */
14533+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14534+{
14535 return i + xadd(&v->counter, i);
14536 }
14537
14538@@ -188,9 +362,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14539 }
14540
14541 #define atomic_inc_return(v) (atomic_add_return(1, v))
14542+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14543+{
14544+ return atomic_add_return_unchecked(1, v);
14545+}
14546 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14547
14548-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14549+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14550+{
14551+ return cmpxchg(&v->counter, old, new);
14552+}
14553+
14554+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14555 {
14556 return cmpxchg(&v->counter, old, new);
14557 }
14558@@ -200,6 +383,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14559 return xchg(&v->counter, new);
14560 }
14561
14562+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14563+{
14564+ return xchg(&v->counter, new);
14565+}
14566+
14567 /**
14568 * __atomic_add_unless - add unless the number is already a given value
14569 * @v: pointer of type atomic_t
14570@@ -209,14 +397,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14571 * Atomically adds @a to @v, so long as @v was not already @u.
14572 * Returns the old value of @v.
14573 */
14574-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14575+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14576 {
14577- int c, old;
14578+ int c, old, new;
14579 c = atomic_read(v);
14580 for (;;) {
14581- if (unlikely(c == (u)))
14582+ if (unlikely(c == u))
14583 break;
14584- old = atomic_cmpxchg((v), c, c + (a));
14585+
14586+ asm volatile("addl %2,%0\n"
14587+
14588+#ifdef CONFIG_PAX_REFCOUNT
14589+ "jno 0f\n"
14590+ "subl %2,%0\n"
14591+ "int $4\n0:\n"
14592+ _ASM_EXTABLE(0b, 0b)
14593+#endif
14594+
14595+ : "=r" (new)
14596+ : "0" (c), "ir" (a));
14597+
14598+ old = atomic_cmpxchg(v, c, new);
14599 if (likely(old == c))
14600 break;
14601 c = old;
14602@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14603 }
14604
14605 /**
14606+ * atomic_inc_not_zero_hint - increment if not null
14607+ * @v: pointer of type atomic_t
14608+ * @hint: probable value of the atomic before the increment
14609+ *
14610+ * This version of atomic_inc_not_zero() gives a hint of probable
14611+ * value of the atomic. This helps processor to not read the memory
14612+ * before doing the atomic read/modify/write cycle, lowering
14613+ * number of bus transactions on some arches.
14614+ *
14615+ * Returns: 0 if increment was not done, 1 otherwise.
14616+ */
14617+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14618+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14619+{
14620+ int val, c = hint, new;
14621+
14622+ /* sanity test, should be removed by compiler if hint is a constant */
14623+ if (!hint)
14624+ return __atomic_add_unless(v, 1, 0);
14625+
14626+ do {
14627+ asm volatile("incl %0\n"
14628+
14629+#ifdef CONFIG_PAX_REFCOUNT
14630+ "jno 0f\n"
14631+ "decl %0\n"
14632+ "int $4\n0:\n"
14633+ _ASM_EXTABLE(0b, 0b)
14634+#endif
14635+
14636+ : "=r" (new)
14637+ : "0" (c));
14638+
14639+ val = atomic_cmpxchg(v, c, new);
14640+ if (val == c)
14641+ return 1;
14642+ c = val;
14643+ } while (c);
14644+
14645+ return 0;
14646+}
14647+
14648+/**
14649 * atomic_inc_short - increment of a short integer
14650 * @v: pointer to type int
14651 *
14652@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14653 #endif
14654
14655 /* These are x86-specific, used by some header files */
14656-#define atomic_clear_mask(mask, addr) \
14657- asm volatile(LOCK_PREFIX "andl %0,%1" \
14658- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14659+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14660+{
14661+ asm volatile(LOCK_PREFIX "andl %1,%0"
14662+ : "+m" (v->counter)
14663+ : "r" (~(mask))
14664+ : "memory");
14665+}
14666
14667-#define atomic_set_mask(mask, addr) \
14668- asm volatile(LOCK_PREFIX "orl %0,%1" \
14669- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14670- : "memory")
14671+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14672+{
14673+ asm volatile(LOCK_PREFIX "andl %1,%0"
14674+ : "+m" (v->counter)
14675+ : "r" (~(mask))
14676+ : "memory");
14677+}
14678+
14679+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14680+{
14681+ asm volatile(LOCK_PREFIX "orl %1,%0"
14682+ : "+m" (v->counter)
14683+ : "r" (mask)
14684+ : "memory");
14685+}
14686+
14687+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14688+{
14689+ asm volatile(LOCK_PREFIX "orl %1,%0"
14690+ : "+m" (v->counter)
14691+ : "r" (mask)
14692+ : "memory");
14693+}
14694
14695 /* Atomic operations are already serializing on x86 */
14696 #define smp_mb__before_atomic_dec() barrier()
14697diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14698index b154de7..bf18a5a 100644
14699--- a/arch/x86/include/asm/atomic64_32.h
14700+++ b/arch/x86/include/asm/atomic64_32.h
14701@@ -12,6 +12,14 @@ typedef struct {
14702 u64 __aligned(8) counter;
14703 } atomic64_t;
14704
14705+#ifdef CONFIG_PAX_REFCOUNT
14706+typedef struct {
14707+ u64 __aligned(8) counter;
14708+} atomic64_unchecked_t;
14709+#else
14710+typedef atomic64_t atomic64_unchecked_t;
14711+#endif
14712+
14713 #define ATOMIC64_INIT(val) { (val) }
14714
14715 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14716@@ -37,21 +45,31 @@ typedef struct {
14717 ATOMIC64_DECL_ONE(sym##_386)
14718
14719 ATOMIC64_DECL_ONE(add_386);
14720+ATOMIC64_DECL_ONE(add_unchecked_386);
14721 ATOMIC64_DECL_ONE(sub_386);
14722+ATOMIC64_DECL_ONE(sub_unchecked_386);
14723 ATOMIC64_DECL_ONE(inc_386);
14724+ATOMIC64_DECL_ONE(inc_unchecked_386);
14725 ATOMIC64_DECL_ONE(dec_386);
14726+ATOMIC64_DECL_ONE(dec_unchecked_386);
14727 #endif
14728
14729 #define alternative_atomic64(f, out, in...) \
14730 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14731
14732 ATOMIC64_DECL(read);
14733+ATOMIC64_DECL(read_unchecked);
14734 ATOMIC64_DECL(set);
14735+ATOMIC64_DECL(set_unchecked);
14736 ATOMIC64_DECL(xchg);
14737 ATOMIC64_DECL(add_return);
14738+ATOMIC64_DECL(add_return_unchecked);
14739 ATOMIC64_DECL(sub_return);
14740+ATOMIC64_DECL(sub_return_unchecked);
14741 ATOMIC64_DECL(inc_return);
14742+ATOMIC64_DECL(inc_return_unchecked);
14743 ATOMIC64_DECL(dec_return);
14744+ATOMIC64_DECL(dec_return_unchecked);
14745 ATOMIC64_DECL(dec_if_positive);
14746 ATOMIC64_DECL(inc_not_zero);
14747 ATOMIC64_DECL(add_unless);
14748@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14749 }
14750
14751 /**
14752+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14753+ * @p: pointer to type atomic64_unchecked_t
14754+ * @o: expected value
14755+ * @n: new value
14756+ *
14757+ * Atomically sets @v to @n if it was equal to @o and returns
14758+ * the old value.
14759+ */
14760+
14761+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14762+{
14763+ return cmpxchg64(&v->counter, o, n);
14764+}
14765+
14766+/**
14767 * atomic64_xchg - xchg atomic64 variable
14768 * @v: pointer to type atomic64_t
14769 * @n: value to assign
14770@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14771 }
14772
14773 /**
14774+ * atomic64_set_unchecked - set atomic64 variable
14775+ * @v: pointer to type atomic64_unchecked_t
14776+ * @n: value to assign
14777+ *
14778+ * Atomically sets the value of @v to @n.
14779+ */
14780+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14781+{
14782+ unsigned high = (unsigned)(i >> 32);
14783+ unsigned low = (unsigned)i;
14784+ alternative_atomic64(set, /* no output */,
14785+ "S" (v), "b" (low), "c" (high)
14786+ : "eax", "edx", "memory");
14787+}
14788+
14789+/**
14790 * atomic64_read - read atomic64 variable
14791 * @v: pointer to type atomic64_t
14792 *
14793@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14794 }
14795
14796 /**
14797+ * atomic64_read_unchecked - read atomic64 variable
14798+ * @v: pointer to type atomic64_unchecked_t
14799+ *
14800+ * Atomically reads the value of @v and returns it.
14801+ */
14802+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14803+{
14804+ long long r;
14805+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14806+ return r;
14807+ }
14808+
14809+/**
14810 * atomic64_add_return - add and return
14811 * @i: integer value to add
14812 * @v: pointer to type atomic64_t
14813@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14814 return i;
14815 }
14816
14817+/**
14818+ * atomic64_add_return_unchecked - add and return
14819+ * @i: integer value to add
14820+ * @v: pointer to type atomic64_unchecked_t
14821+ *
14822+ * Atomically adds @i to @v and returns @i + *@v
14823+ */
14824+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14825+{
14826+ alternative_atomic64(add_return_unchecked,
14827+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14828+ ASM_NO_INPUT_CLOBBER("memory"));
14829+ return i;
14830+}
14831+
14832 /*
14833 * Other variants with different arithmetic operators:
14834 */
14835@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14836 return a;
14837 }
14838
14839+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14840+{
14841+ long long a;
14842+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14843+ "S" (v) : "memory", "ecx");
14844+ return a;
14845+}
14846+
14847 static inline long long atomic64_dec_return(atomic64_t *v)
14848 {
14849 long long a;
14850@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14851 }
14852
14853 /**
14854+ * atomic64_add_unchecked - add integer to atomic64 variable
14855+ * @i: integer value to add
14856+ * @v: pointer to type atomic64_unchecked_t
14857+ *
14858+ * Atomically adds @i to @v.
14859+ */
14860+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14861+{
14862+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14863+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14864+ ASM_NO_INPUT_CLOBBER("memory"));
14865+ return i;
14866+}
14867+
14868+/**
14869 * atomic64_sub - subtract the atomic64 variable
14870 * @i: integer value to subtract
14871 * @v: pointer to type atomic64_t
14872diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14873index 0e1cbfc..a891fc7 100644
14874--- a/arch/x86/include/asm/atomic64_64.h
14875+++ b/arch/x86/include/asm/atomic64_64.h
14876@@ -18,7 +18,19 @@
14877 */
14878 static inline long atomic64_read(const atomic64_t *v)
14879 {
14880- return (*(volatile long *)&(v)->counter);
14881+ return (*(volatile const long *)&(v)->counter);
14882+}
14883+
14884+/**
14885+ * atomic64_read_unchecked - read atomic64 variable
14886+ * @v: pointer of type atomic64_unchecked_t
14887+ *
14888+ * Atomically reads the value of @v.
14889+ * Doesn't imply a read memory barrier.
14890+ */
14891+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
14892+{
14893+ return (*(volatile const long *)&(v)->counter);
14894 }
14895
14896 /**
14897@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14898 }
14899
14900 /**
14901+ * atomic64_set_unchecked - set atomic64 variable
14902+ * @v: pointer to type atomic64_unchecked_t
14903+ * @i: required value
14904+ *
14905+ * Atomically sets the value of @v to @i.
14906+ */
14907+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14908+{
14909+ v->counter = i;
14910+}
14911+
14912+/**
14913 * atomic64_add - add integer to atomic64 variable
14914 * @i: integer value to add
14915 * @v: pointer to type atomic64_t
14916@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14917 */
14918 static inline void atomic64_add(long i, atomic64_t *v)
14919 {
14920+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14921+
14922+#ifdef CONFIG_PAX_REFCOUNT
14923+ "jno 0f\n"
14924+ LOCK_PREFIX "subq %1,%0\n"
14925+ "int $4\n0:\n"
14926+ _ASM_EXTABLE(0b, 0b)
14927+#endif
14928+
14929+ : "=m" (v->counter)
14930+ : "er" (i), "m" (v->counter));
14931+}
14932+
14933+/**
14934+ * atomic64_add_unchecked - add integer to atomic64 variable
14935+ * @i: integer value to add
14936+ * @v: pointer to type atomic64_unchecked_t
14937+ *
14938+ * Atomically adds @i to @v.
14939+ */
14940+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14941+{
14942 asm volatile(LOCK_PREFIX "addq %1,%0"
14943 : "=m" (v->counter)
14944 : "er" (i), "m" (v->counter));
14945@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14946 */
14947 static inline void atomic64_sub(long i, atomic64_t *v)
14948 {
14949- asm volatile(LOCK_PREFIX "subq %1,%0"
14950+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14951+
14952+#ifdef CONFIG_PAX_REFCOUNT
14953+ "jno 0f\n"
14954+ LOCK_PREFIX "addq %1,%0\n"
14955+ "int $4\n0:\n"
14956+ _ASM_EXTABLE(0b, 0b)
14957+#endif
14958+
14959+ : "=m" (v->counter)
14960+ : "er" (i), "m" (v->counter));
14961+}
14962+
14963+/**
14964+ * atomic64_sub_unchecked - subtract the atomic64 variable
14965+ * @i: integer value to subtract
14966+ * @v: pointer to type atomic64_unchecked_t
14967+ *
14968+ * Atomically subtracts @i from @v.
14969+ */
14970+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14971+{
14972+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14973 : "=m" (v->counter)
14974 : "er" (i), "m" (v->counter));
14975 }
14976@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14977 {
14978 unsigned char c;
14979
14980- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14981+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14982+
14983+#ifdef CONFIG_PAX_REFCOUNT
14984+ "jno 0f\n"
14985+ LOCK_PREFIX "addq %2,%0\n"
14986+ "int $4\n0:\n"
14987+ _ASM_EXTABLE(0b, 0b)
14988+#endif
14989+
14990+ "sete %1\n"
14991 : "=m" (v->counter), "=qm" (c)
14992 : "er" (i), "m" (v->counter) : "memory");
14993 return c;
14994@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14995 */
14996 static inline void atomic64_inc(atomic64_t *v)
14997 {
14998+ asm volatile(LOCK_PREFIX "incq %0\n"
14999+
15000+#ifdef CONFIG_PAX_REFCOUNT
15001+ "jno 0f\n"
15002+ LOCK_PREFIX "decq %0\n"
15003+ "int $4\n0:\n"
15004+ _ASM_EXTABLE(0b, 0b)
15005+#endif
15006+
15007+ : "=m" (v->counter)
15008+ : "m" (v->counter));
15009+}
15010+
15011+/**
15012+ * atomic64_inc_unchecked - increment atomic64 variable
15013+ * @v: pointer to type atomic64_unchecked_t
15014+ *
15015+ * Atomically increments @v by 1.
15016+ */
15017+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15018+{
15019 asm volatile(LOCK_PREFIX "incq %0"
15020 : "=m" (v->counter)
15021 : "m" (v->counter));
15022@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
15023 */
15024 static inline void atomic64_dec(atomic64_t *v)
15025 {
15026- asm volatile(LOCK_PREFIX "decq %0"
15027+ asm volatile(LOCK_PREFIX "decq %0\n"
15028+
15029+#ifdef CONFIG_PAX_REFCOUNT
15030+ "jno 0f\n"
15031+ LOCK_PREFIX "incq %0\n"
15032+ "int $4\n0:\n"
15033+ _ASM_EXTABLE(0b, 0b)
15034+#endif
15035+
15036+ : "=m" (v->counter)
15037+ : "m" (v->counter));
15038+}
15039+
15040+/**
15041+ * atomic64_dec_unchecked - decrement atomic64 variable
15042+ * @v: pointer to type atomic64_t
15043+ *
15044+ * Atomically decrements @v by 1.
15045+ */
15046+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15047+{
15048+ asm volatile(LOCK_PREFIX "decq %0\n"
15049 : "=m" (v->counter)
15050 : "m" (v->counter));
15051 }
15052@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15053 {
15054 unsigned char c;
15055
15056- asm volatile(LOCK_PREFIX "decq %0; sete %1"
15057+ asm volatile(LOCK_PREFIX "decq %0\n"
15058+
15059+#ifdef CONFIG_PAX_REFCOUNT
15060+ "jno 0f\n"
15061+ LOCK_PREFIX "incq %0\n"
15062+ "int $4\n0:\n"
15063+ _ASM_EXTABLE(0b, 0b)
15064+#endif
15065+
15066+ "sete %1\n"
15067 : "=m" (v->counter), "=qm" (c)
15068 : "m" (v->counter) : "memory");
15069 return c != 0;
15070@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15071 {
15072 unsigned char c;
15073
15074- asm volatile(LOCK_PREFIX "incq %0; sete %1"
15075+ asm volatile(LOCK_PREFIX "incq %0\n"
15076+
15077+#ifdef CONFIG_PAX_REFCOUNT
15078+ "jno 0f\n"
15079+ LOCK_PREFIX "decq %0\n"
15080+ "int $4\n0:\n"
15081+ _ASM_EXTABLE(0b, 0b)
15082+#endif
15083+
15084+ "sete %1\n"
15085 : "=m" (v->counter), "=qm" (c)
15086 : "m" (v->counter) : "memory");
15087 return c != 0;
15088@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15089 {
15090 unsigned char c;
15091
15092- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
15093+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
15094+
15095+#ifdef CONFIG_PAX_REFCOUNT
15096+ "jno 0f\n"
15097+ LOCK_PREFIX "subq %2,%0\n"
15098+ "int $4\n0:\n"
15099+ _ASM_EXTABLE(0b, 0b)
15100+#endif
15101+
15102+ "sets %1\n"
15103 : "=m" (v->counter), "=qm" (c)
15104 : "er" (i), "m" (v->counter) : "memory");
15105 return c;
15106@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15107 */
15108 static inline long atomic64_add_return(long i, atomic64_t *v)
15109 {
15110+ return i + xadd_check_overflow(&v->counter, i);
15111+}
15112+
15113+/**
15114+ * atomic64_add_return_unchecked - add and return
15115+ * @i: integer value to add
15116+ * @v: pointer to type atomic64_unchecked_t
15117+ *
15118+ * Atomically adds @i to @v and returns @i + @v
15119+ */
15120+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15121+{
15122 return i + xadd(&v->counter, i);
15123 }
15124
15125@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15126 }
15127
15128 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15129+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15130+{
15131+ return atomic64_add_return_unchecked(1, v);
15132+}
15133 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15134
15135 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15136@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15137 return cmpxchg(&v->counter, old, new);
15138 }
15139
15140+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15141+{
15142+ return cmpxchg(&v->counter, old, new);
15143+}
15144+
15145 static inline long atomic64_xchg(atomic64_t *v, long new)
15146 {
15147 return xchg(&v->counter, new);
15148@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15149 */
15150 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15151 {
15152- long c, old;
15153+ long c, old, new;
15154 c = atomic64_read(v);
15155 for (;;) {
15156- if (unlikely(c == (u)))
15157+ if (unlikely(c == u))
15158 break;
15159- old = atomic64_cmpxchg((v), c, c + (a));
15160+
15161+ asm volatile("add %2,%0\n"
15162+
15163+#ifdef CONFIG_PAX_REFCOUNT
15164+ "jno 0f\n"
15165+ "sub %2,%0\n"
15166+ "int $4\n0:\n"
15167+ _ASM_EXTABLE(0b, 0b)
15168+#endif
15169+
15170+ : "=r" (new)
15171+ : "0" (c), "ir" (a));
15172+
15173+ old = atomic64_cmpxchg(v, c, new);
15174 if (likely(old == c))
15175 break;
15176 c = old;
15177 }
15178- return c != (u);
15179+ return c != u;
15180 }
15181
15182 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15183diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15184index 41639ce..ebce552 100644
15185--- a/arch/x86/include/asm/bitops.h
15186+++ b/arch/x86/include/asm/bitops.h
15187@@ -48,7 +48,7 @@
15188 * a mask operation on a byte.
15189 */
15190 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15191-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15192+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15193 #define CONST_MASK(nr) (1 << ((nr) & 7))
15194
15195 /**
15196@@ -361,7 +361,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15197 *
15198 * Undefined if no bit exists, so code should check against 0 first.
15199 */
15200-static inline unsigned long __ffs(unsigned long word)
15201+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15202 {
15203 asm("rep; bsf %1,%0"
15204 : "=r" (word)
15205@@ -375,7 +375,7 @@ static inline unsigned long __ffs(unsigned long word)
15206 *
15207 * Undefined if no zero exists, so code should check against ~0UL first.
15208 */
15209-static inline unsigned long ffz(unsigned long word)
15210+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15211 {
15212 asm("rep; bsf %1,%0"
15213 : "=r" (word)
15214@@ -389,7 +389,7 @@ static inline unsigned long ffz(unsigned long word)
15215 *
15216 * Undefined if no set bit exists, so code should check against 0 first.
15217 */
15218-static inline unsigned long __fls(unsigned long word)
15219+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15220 {
15221 asm("bsr %1,%0"
15222 : "=r" (word)
15223@@ -452,7 +452,7 @@ static inline int ffs(int x)
15224 * set bit if value is nonzero. The last (most significant) bit is
15225 * at position 32.
15226 */
15227-static inline int fls(int x)
15228+static inline int __intentional_overflow(-1) fls(int x)
15229 {
15230 int r;
15231
15232@@ -494,7 +494,7 @@ static inline int fls(int x)
15233 * at position 64.
15234 */
15235 #ifdef CONFIG_X86_64
15236-static __always_inline int fls64(__u64 x)
15237+static __always_inline long fls64(__u64 x)
15238 {
15239 int bitpos = -1;
15240 /*
15241diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15242index 4fa687a..60f2d39 100644
15243--- a/arch/x86/include/asm/boot.h
15244+++ b/arch/x86/include/asm/boot.h
15245@@ -6,10 +6,15 @@
15246 #include <uapi/asm/boot.h>
15247
15248 /* Physical address where kernel should be loaded. */
15249-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15250+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15251 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15252 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15253
15254+#ifndef __ASSEMBLY__
15255+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15256+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15257+#endif
15258+
15259 /* Minimum kernel alignment, as a power of two */
15260 #ifdef CONFIG_X86_64
15261 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15262diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15263index 48f99f1..d78ebf9 100644
15264--- a/arch/x86/include/asm/cache.h
15265+++ b/arch/x86/include/asm/cache.h
15266@@ -5,12 +5,13 @@
15267
15268 /* L1 cache line size */
15269 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15270-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15271+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15272
15273 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15274+#define __read_only __attribute__((__section__(".data..read_only")))
15275
15276 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15277-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15278+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15279
15280 #ifdef CONFIG_X86_VSMP
15281 #ifdef CONFIG_SMP
15282diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15283index 9863ee3..4a1f8e1 100644
15284--- a/arch/x86/include/asm/cacheflush.h
15285+++ b/arch/x86/include/asm/cacheflush.h
15286@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15287 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15288
15289 if (pg_flags == _PGMT_DEFAULT)
15290- return -1;
15291+ return ~0UL;
15292 else if (pg_flags == _PGMT_WC)
15293 return _PAGE_CACHE_WC;
15294 else if (pg_flags == _PGMT_UC_MINUS)
15295diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15296index 0fa6750..cb7b2c3 100644
15297--- a/arch/x86/include/asm/calling.h
15298+++ b/arch/x86/include/asm/calling.h
15299@@ -80,103 +80,113 @@ For 32-bit we have the following conventions - kernel is built with
15300 #define RSP 152
15301 #define SS 160
15302
15303-#define ARGOFFSET R11
15304-#define SWFRAME ORIG_RAX
15305+#define ARGOFFSET R15
15306
15307 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15308- subq $9*8+\addskip, %rsp
15309- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15310- movq_cfi rdi, 8*8
15311- movq_cfi rsi, 7*8
15312- movq_cfi rdx, 6*8
15313+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15314+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15315+ movq_cfi rdi, RDI
15316+ movq_cfi rsi, RSI
15317+ movq_cfi rdx, RDX
15318
15319 .if \save_rcx
15320- movq_cfi rcx, 5*8
15321+ movq_cfi rcx, RCX
15322 .endif
15323
15324- movq_cfi rax, 4*8
15325+ movq_cfi rax, RAX
15326
15327 .if \save_r891011
15328- movq_cfi r8, 3*8
15329- movq_cfi r9, 2*8
15330- movq_cfi r10, 1*8
15331- movq_cfi r11, 0*8
15332+ movq_cfi r8, R8
15333+ movq_cfi r9, R9
15334+ movq_cfi r10, R10
15335+ movq_cfi r11, R11
15336 .endif
15337
15338+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15339+ movq_cfi r12, R12
15340+#endif
15341+
15342 .endm
15343
15344-#define ARG_SKIP (9*8)
15345+#define ARG_SKIP ORIG_RAX
15346
15347 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15348 rstor_r8910=1, rstor_rdx=1
15349+
15350+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15351+ movq_cfi_restore R12, r12
15352+#endif
15353+
15354 .if \rstor_r11
15355- movq_cfi_restore 0*8, r11
15356+ movq_cfi_restore R11, r11
15357 .endif
15358
15359 .if \rstor_r8910
15360- movq_cfi_restore 1*8, r10
15361- movq_cfi_restore 2*8, r9
15362- movq_cfi_restore 3*8, r8
15363+ movq_cfi_restore R10, r10
15364+ movq_cfi_restore R9, r9
15365+ movq_cfi_restore R8, r8
15366 .endif
15367
15368 .if \rstor_rax
15369- movq_cfi_restore 4*8, rax
15370+ movq_cfi_restore RAX, rax
15371 .endif
15372
15373 .if \rstor_rcx
15374- movq_cfi_restore 5*8, rcx
15375+ movq_cfi_restore RCX, rcx
15376 .endif
15377
15378 .if \rstor_rdx
15379- movq_cfi_restore 6*8, rdx
15380+ movq_cfi_restore RDX, rdx
15381 .endif
15382
15383- movq_cfi_restore 7*8, rsi
15384- movq_cfi_restore 8*8, rdi
15385+ movq_cfi_restore RSI, rsi
15386+ movq_cfi_restore RDI, rdi
15387
15388- .if ARG_SKIP+\addskip > 0
15389- addq $ARG_SKIP+\addskip, %rsp
15390- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15391+ .if ORIG_RAX+\addskip > 0
15392+ addq $ORIG_RAX+\addskip, %rsp
15393+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15394 .endif
15395 .endm
15396
15397- .macro LOAD_ARGS offset, skiprax=0
15398- movq \offset(%rsp), %r11
15399- movq \offset+8(%rsp), %r10
15400- movq \offset+16(%rsp), %r9
15401- movq \offset+24(%rsp), %r8
15402- movq \offset+40(%rsp), %rcx
15403- movq \offset+48(%rsp), %rdx
15404- movq \offset+56(%rsp), %rsi
15405- movq \offset+64(%rsp), %rdi
15406+ .macro LOAD_ARGS skiprax=0
15407+ movq R11(%rsp), %r11
15408+ movq R10(%rsp), %r10
15409+ movq R9(%rsp), %r9
15410+ movq R8(%rsp), %r8
15411+ movq RCX(%rsp), %rcx
15412+ movq RDX(%rsp), %rdx
15413+ movq RSI(%rsp), %rsi
15414+ movq RDI(%rsp), %rdi
15415 .if \skiprax
15416 .else
15417- movq \offset+72(%rsp), %rax
15418+ movq RAX(%rsp), %rax
15419 .endif
15420 .endm
15421
15422-#define REST_SKIP (6*8)
15423-
15424 .macro SAVE_REST
15425- subq $REST_SKIP, %rsp
15426- CFI_ADJUST_CFA_OFFSET REST_SKIP
15427- movq_cfi rbx, 5*8
15428- movq_cfi rbp, 4*8
15429- movq_cfi r12, 3*8
15430- movq_cfi r13, 2*8
15431- movq_cfi r14, 1*8
15432- movq_cfi r15, 0*8
15433+ movq_cfi rbx, RBX
15434+ movq_cfi rbp, RBP
15435+
15436+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15437+ movq_cfi r12, R12
15438+#endif
15439+
15440+ movq_cfi r13, R13
15441+ movq_cfi r14, R14
15442+ movq_cfi r15, R15
15443 .endm
15444
15445 .macro RESTORE_REST
15446- movq_cfi_restore 0*8, r15
15447- movq_cfi_restore 1*8, r14
15448- movq_cfi_restore 2*8, r13
15449- movq_cfi_restore 3*8, r12
15450- movq_cfi_restore 4*8, rbp
15451- movq_cfi_restore 5*8, rbx
15452- addq $REST_SKIP, %rsp
15453- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15454+ movq_cfi_restore R15, r15
15455+ movq_cfi_restore R14, r14
15456+ movq_cfi_restore R13, r13
15457+
15458+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15459+ movq_cfi_restore R12, r12
15460+#endif
15461+
15462+ movq_cfi_restore RBP, rbp
15463+ movq_cfi_restore RBX, rbx
15464 .endm
15465
15466 .macro SAVE_ALL
15467diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15468index f50de69..2b0a458 100644
15469--- a/arch/x86/include/asm/checksum_32.h
15470+++ b/arch/x86/include/asm/checksum_32.h
15471@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15472 int len, __wsum sum,
15473 int *src_err_ptr, int *dst_err_ptr);
15474
15475+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15476+ int len, __wsum sum,
15477+ int *src_err_ptr, int *dst_err_ptr);
15478+
15479+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15480+ int len, __wsum sum,
15481+ int *src_err_ptr, int *dst_err_ptr);
15482+
15483 /*
15484 * Note: when you get a NULL pointer exception here this means someone
15485 * passed in an incorrect kernel address to one of these functions.
15486@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15487
15488 might_sleep();
15489 stac();
15490- ret = csum_partial_copy_generic((__force void *)src, dst,
15491+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15492 len, sum, err_ptr, NULL);
15493 clac();
15494
15495@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15496 might_sleep();
15497 if (access_ok(VERIFY_WRITE, dst, len)) {
15498 stac();
15499- ret = csum_partial_copy_generic(src, (__force void *)dst,
15500+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15501 len, sum, NULL, err_ptr);
15502 clac();
15503 return ret;
15504diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15505index d47786a..ce1b05d 100644
15506--- a/arch/x86/include/asm/cmpxchg.h
15507+++ b/arch/x86/include/asm/cmpxchg.h
15508@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15509 __compiletime_error("Bad argument size for cmpxchg");
15510 extern void __xadd_wrong_size(void)
15511 __compiletime_error("Bad argument size for xadd");
15512+extern void __xadd_check_overflow_wrong_size(void)
15513+ __compiletime_error("Bad argument size for xadd_check_overflow");
15514 extern void __add_wrong_size(void)
15515 __compiletime_error("Bad argument size for add");
15516+extern void __add_check_overflow_wrong_size(void)
15517+ __compiletime_error("Bad argument size for add_check_overflow");
15518
15519 /*
15520 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15521@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15522 __ret; \
15523 })
15524
15525+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15526+ ({ \
15527+ __typeof__ (*(ptr)) __ret = (arg); \
15528+ switch (sizeof(*(ptr))) { \
15529+ case __X86_CASE_L: \
15530+ asm volatile (lock #op "l %0, %1\n" \
15531+ "jno 0f\n" \
15532+ "mov %0,%1\n" \
15533+ "int $4\n0:\n" \
15534+ _ASM_EXTABLE(0b, 0b) \
15535+ : "+r" (__ret), "+m" (*(ptr)) \
15536+ : : "memory", "cc"); \
15537+ break; \
15538+ case __X86_CASE_Q: \
15539+ asm volatile (lock #op "q %q0, %1\n" \
15540+ "jno 0f\n" \
15541+ "mov %0,%1\n" \
15542+ "int $4\n0:\n" \
15543+ _ASM_EXTABLE(0b, 0b) \
15544+ : "+r" (__ret), "+m" (*(ptr)) \
15545+ : : "memory", "cc"); \
15546+ break; \
15547+ default: \
15548+ __ ## op ## _check_overflow_wrong_size(); \
15549+ } \
15550+ __ret; \
15551+ })
15552+
15553 /*
15554 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15555 * Since this is generally used to protect other memory information, we
15556@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15557 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15558 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15559
15560+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15561+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15562+
15563 #define __add(ptr, inc, lock) \
15564 ({ \
15565 __typeof__ (*(ptr)) __ret = (inc); \
15566diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15567index 59c6c40..5e0b22c 100644
15568--- a/arch/x86/include/asm/compat.h
15569+++ b/arch/x86/include/asm/compat.h
15570@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15571 typedef u32 compat_uint_t;
15572 typedef u32 compat_ulong_t;
15573 typedef u64 __attribute__((aligned(4))) compat_u64;
15574-typedef u32 compat_uptr_t;
15575+typedef u32 __user compat_uptr_t;
15576
15577 struct compat_timespec {
15578 compat_time_t tv_sec;
15579diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15580index 89270b4..f0abf8e 100644
15581--- a/arch/x86/include/asm/cpufeature.h
15582+++ b/arch/x86/include/asm/cpufeature.h
15583@@ -203,7 +203,7 @@
15584 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15585 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15586 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15587-
15588+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15589
15590 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15591 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15592@@ -211,7 +211,7 @@
15593 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15594 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15595 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15596-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15597+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15598 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15599 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15600 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15601@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15602 #undef cpu_has_centaur_mcr
15603 #define cpu_has_centaur_mcr 0
15604
15605+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15606 #endif /* CONFIG_X86_64 */
15607
15608 #if __GNUC__ >= 4
15609@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15610
15611 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15612 t_warn:
15613- warn_pre_alternatives();
15614+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15615+ warn_pre_alternatives();
15616 return false;
15617 #endif
15618
15619@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15620 ".section .discard,\"aw\",@progbits\n"
15621 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15622 ".previous\n"
15623- ".section .altinstr_replacement,\"ax\"\n"
15624+ ".section .altinstr_replacement,\"a\"\n"
15625 "3: movb $1,%0\n"
15626 "4:\n"
15627 ".previous\n"
15628@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15629 " .byte 2b - 1b\n" /* src len */
15630 " .byte 4f - 3f\n" /* repl len */
15631 ".previous\n"
15632- ".section .altinstr_replacement,\"ax\"\n"
15633+ ".section .altinstr_replacement,\"a\"\n"
15634 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15635 "4:\n"
15636 ".previous\n"
15637@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15638 ".section .discard,\"aw\",@progbits\n"
15639 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15640 ".previous\n"
15641- ".section .altinstr_replacement,\"ax\"\n"
15642+ ".section .altinstr_replacement,\"a\"\n"
15643 "3: movb $0,%0\n"
15644 "4:\n"
15645 ".previous\n"
15646@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15647 ".section .discard,\"aw\",@progbits\n"
15648 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15649 ".previous\n"
15650- ".section .altinstr_replacement,\"ax\"\n"
15651+ ".section .altinstr_replacement,\"a\"\n"
15652 "5: movb $1,%0\n"
15653 "6:\n"
15654 ".previous\n"
15655diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15656index b90e5df..b462c91 100644
15657--- a/arch/x86/include/asm/desc.h
15658+++ b/arch/x86/include/asm/desc.h
15659@@ -4,6 +4,7 @@
15660 #include <asm/desc_defs.h>
15661 #include <asm/ldt.h>
15662 #include <asm/mmu.h>
15663+#include <asm/pgtable.h>
15664
15665 #include <linux/smp.h>
15666 #include <linux/percpu.h>
15667@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15668
15669 desc->type = (info->read_exec_only ^ 1) << 1;
15670 desc->type |= info->contents << 2;
15671+ desc->type |= info->seg_not_present ^ 1;
15672
15673 desc->s = 1;
15674 desc->dpl = 0x3;
15675@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15676 }
15677
15678 extern struct desc_ptr idt_descr;
15679-extern gate_desc idt_table[];
15680-extern struct desc_ptr debug_idt_descr;
15681-extern gate_desc debug_idt_table[];
15682-
15683-struct gdt_page {
15684- struct desc_struct gdt[GDT_ENTRIES];
15685-} __attribute__((aligned(PAGE_SIZE)));
15686-
15687-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15688+extern gate_desc idt_table[IDT_ENTRIES];
15689+extern const struct desc_ptr debug_idt_descr;
15690+extern gate_desc debug_idt_table[IDT_ENTRIES];
15691
15692+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15693 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15694 {
15695- return per_cpu(gdt_page, cpu).gdt;
15696+ return cpu_gdt_table[cpu];
15697 }
15698
15699 #ifdef CONFIG_X86_64
15700@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15701 unsigned long base, unsigned dpl, unsigned flags,
15702 unsigned short seg)
15703 {
15704- gate->a = (seg << 16) | (base & 0xffff);
15705- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15706+ gate->gate.offset_low = base;
15707+ gate->gate.seg = seg;
15708+ gate->gate.reserved = 0;
15709+ gate->gate.type = type;
15710+ gate->gate.s = 0;
15711+ gate->gate.dpl = dpl;
15712+ gate->gate.p = 1;
15713+ gate->gate.offset_high = base >> 16;
15714 }
15715
15716 #endif
15717@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15718
15719 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15720 {
15721+ pax_open_kernel();
15722 memcpy(&idt[entry], gate, sizeof(*gate));
15723+ pax_close_kernel();
15724 }
15725
15726 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15727 {
15728+ pax_open_kernel();
15729 memcpy(&ldt[entry], desc, 8);
15730+ pax_close_kernel();
15731 }
15732
15733 static inline void
15734@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15735 default: size = sizeof(*gdt); break;
15736 }
15737
15738+ pax_open_kernel();
15739 memcpy(&gdt[entry], desc, size);
15740+ pax_close_kernel();
15741 }
15742
15743 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15744@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15745
15746 static inline void native_load_tr_desc(void)
15747 {
15748+ pax_open_kernel();
15749 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15750+ pax_close_kernel();
15751 }
15752
15753 static inline void native_load_gdt(const struct desc_ptr *dtr)
15754@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15755 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15756 unsigned int i;
15757
15758+ pax_open_kernel();
15759 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15760 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15761+ pax_close_kernel();
15762 }
15763
15764 #define _LDT_empty(info) \
15765@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15766 preempt_enable();
15767 }
15768
15769-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15770+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15771 {
15772 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15773 }
15774@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15775 }
15776
15777 #ifdef CONFIG_X86_64
15778-static inline void set_nmi_gate(int gate, void *addr)
15779+static inline void set_nmi_gate(int gate, const void *addr)
15780 {
15781 gate_desc s;
15782
15783@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15784 #endif
15785
15786 #ifdef CONFIG_TRACING
15787-extern struct desc_ptr trace_idt_descr;
15788-extern gate_desc trace_idt_table[];
15789+extern const struct desc_ptr trace_idt_descr;
15790+extern gate_desc trace_idt_table[IDT_ENTRIES];
15791 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15792 {
15793 write_idt_entry(trace_idt_table, entry, gate);
15794@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15795 }
15796 #endif
15797
15798-static inline void _set_gate(int gate, unsigned type, void *addr,
15799+static inline void _set_gate(int gate, unsigned type, const void *addr,
15800 unsigned dpl, unsigned ist, unsigned seg)
15801 {
15802 gate_desc s;
15803@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15804 * Pentium F0 0F bugfix can have resulted in the mapped
15805 * IDT being write-protected.
15806 */
15807-static inline void set_intr_gate(unsigned int n, void *addr)
15808+static inline void set_intr_gate(unsigned int n, const void *addr)
15809 {
15810 BUG_ON((unsigned)n > 0xFF);
15811 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15812@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15813 /*
15814 * This routine sets up an interrupt gate at directory privilege level 3.
15815 */
15816-static inline void set_system_intr_gate(unsigned int n, void *addr)
15817+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15818 {
15819 BUG_ON((unsigned)n > 0xFF);
15820 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15821 }
15822
15823-static inline void set_system_trap_gate(unsigned int n, void *addr)
15824+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15825 {
15826 BUG_ON((unsigned)n > 0xFF);
15827 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15828 }
15829
15830-static inline void set_trap_gate(unsigned int n, void *addr)
15831+static inline void set_trap_gate(unsigned int n, const void *addr)
15832 {
15833 BUG_ON((unsigned)n > 0xFF);
15834 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15835@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15836 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15837 {
15838 BUG_ON((unsigned)n > 0xFF);
15839- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15840+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15841 }
15842
15843-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15844+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15845 {
15846 BUG_ON((unsigned)n > 0xFF);
15847 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15848 }
15849
15850-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15851+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15852 {
15853 BUG_ON((unsigned)n > 0xFF);
15854 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15855@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15856 else
15857 load_idt((const struct desc_ptr *)&idt_descr);
15858 }
15859+
15860+#ifdef CONFIG_X86_32
15861+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15862+{
15863+ struct desc_struct d;
15864+
15865+ if (likely(limit))
15866+ limit = (limit - 1UL) >> PAGE_SHIFT;
15867+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15868+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15869+}
15870+#endif
15871+
15872 #endif /* _ASM_X86_DESC_H */
15873diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15874index 278441f..b95a174 100644
15875--- a/arch/x86/include/asm/desc_defs.h
15876+++ b/arch/x86/include/asm/desc_defs.h
15877@@ -31,6 +31,12 @@ struct desc_struct {
15878 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15879 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15880 };
15881+ struct {
15882+ u16 offset_low;
15883+ u16 seg;
15884+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15885+ unsigned offset_high: 16;
15886+ } gate;
15887 };
15888 } __attribute__((packed));
15889
15890diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15891index ced283a..ffe04cc 100644
15892--- a/arch/x86/include/asm/div64.h
15893+++ b/arch/x86/include/asm/div64.h
15894@@ -39,7 +39,7 @@
15895 __mod; \
15896 })
15897
15898-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15899+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15900 {
15901 union {
15902 u64 v64;
15903diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15904index 9c999c1..3860cb8 100644
15905--- a/arch/x86/include/asm/elf.h
15906+++ b/arch/x86/include/asm/elf.h
15907@@ -243,7 +243,25 @@ extern int force_personality32;
15908 the loader. We need to make sure that it is out of the way of the program
15909 that it will "exec", and that there is sufficient room for the brk. */
15910
15911+#ifdef CONFIG_PAX_SEGMEXEC
15912+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15913+#else
15914 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15915+#endif
15916+
15917+#ifdef CONFIG_PAX_ASLR
15918+#ifdef CONFIG_X86_32
15919+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15920+
15921+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15922+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15923+#else
15924+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15925+
15926+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15927+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15928+#endif
15929+#endif
15930
15931 /* This yields a mask that user programs can use to figure out what
15932 instruction set this CPU supports. This could be done in user space,
15933@@ -296,16 +314,12 @@ do { \
15934
15935 #define ARCH_DLINFO \
15936 do { \
15937- if (vdso_enabled) \
15938- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15939- (unsigned long)current->mm->context.vdso); \
15940+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15941 } while (0)
15942
15943 #define ARCH_DLINFO_X32 \
15944 do { \
15945- if (vdso_enabled) \
15946- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15947- (unsigned long)current->mm->context.vdso); \
15948+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15949 } while (0)
15950
15951 #define AT_SYSINFO 32
15952@@ -320,7 +334,7 @@ else \
15953
15954 #endif /* !CONFIG_X86_32 */
15955
15956-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15957+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15958
15959 #define VDSO_ENTRY \
15960 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15961@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15962 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15963 #define compat_arch_setup_additional_pages syscall32_setup_pages
15964
15965-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15966-#define arch_randomize_brk arch_randomize_brk
15967-
15968 /*
15969 * True on X86_32 or when emulating IA32 on X86_64
15970 */
15971diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15972index 77a99ac..39ff7f5 100644
15973--- a/arch/x86/include/asm/emergency-restart.h
15974+++ b/arch/x86/include/asm/emergency-restart.h
15975@@ -1,6 +1,6 @@
15976 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15977 #define _ASM_X86_EMERGENCY_RESTART_H
15978
15979-extern void machine_emergency_restart(void);
15980+extern void machine_emergency_restart(void) __noreturn;
15981
15982 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15983diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15984index 4d0bda7..221da4d 100644
15985--- a/arch/x86/include/asm/fpu-internal.h
15986+++ b/arch/x86/include/asm/fpu-internal.h
15987@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15988 #define user_insn(insn, output, input...) \
15989 ({ \
15990 int err; \
15991+ pax_open_userland(); \
15992 asm volatile(ASM_STAC "\n" \
15993- "1:" #insn "\n\t" \
15994+ "1:" \
15995+ __copyuser_seg \
15996+ #insn "\n\t" \
15997 "2: " ASM_CLAC "\n" \
15998 ".section .fixup,\"ax\"\n" \
15999 "3: movl $-1,%[err]\n" \
16000@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16001 _ASM_EXTABLE(1b, 3b) \
16002 : [err] "=r" (err), output \
16003 : "0"(0), input); \
16004+ pax_close_userland(); \
16005 err; \
16006 })
16007
16008@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16009 "emms\n\t" /* clear stack tags */
16010 "fildl %P[addr]", /* set F?P to defined value */
16011 X86_FEATURE_FXSAVE_LEAK,
16012- [addr] "m" (tsk->thread.fpu.has_fpu));
16013+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16014
16015 return fpu_restore_checking(&tsk->thread.fpu);
16016 }
16017diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16018index be27ba1..04a8801 100644
16019--- a/arch/x86/include/asm/futex.h
16020+++ b/arch/x86/include/asm/futex.h
16021@@ -12,6 +12,7 @@
16022 #include <asm/smap.h>
16023
16024 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16025+ typecheck(u32 __user *, uaddr); \
16026 asm volatile("\t" ASM_STAC "\n" \
16027 "1:\t" insn "\n" \
16028 "2:\t" ASM_CLAC "\n" \
16029@@ -20,15 +21,16 @@
16030 "\tjmp\t2b\n" \
16031 "\t.previous\n" \
16032 _ASM_EXTABLE(1b, 3b) \
16033- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16034+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16035 : "i" (-EFAULT), "0" (oparg), "1" (0))
16036
16037 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16038+ typecheck(u32 __user *, uaddr); \
16039 asm volatile("\t" ASM_STAC "\n" \
16040 "1:\tmovl %2, %0\n" \
16041 "\tmovl\t%0, %3\n" \
16042 "\t" insn "\n" \
16043- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16044+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16045 "\tjnz\t1b\n" \
16046 "3:\t" ASM_CLAC "\n" \
16047 "\t.section .fixup,\"ax\"\n" \
16048@@ -38,7 +40,7 @@
16049 _ASM_EXTABLE(1b, 4b) \
16050 _ASM_EXTABLE(2b, 4b) \
16051 : "=&a" (oldval), "=&r" (ret), \
16052- "+m" (*uaddr), "=&r" (tem) \
16053+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16054 : "r" (oparg), "i" (-EFAULT), "1" (0))
16055
16056 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16057@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16058
16059 pagefault_disable();
16060
16061+ pax_open_userland();
16062 switch (op) {
16063 case FUTEX_OP_SET:
16064- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16065+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16066 break;
16067 case FUTEX_OP_ADD:
16068- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16069+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16070 uaddr, oparg);
16071 break;
16072 case FUTEX_OP_OR:
16073@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16074 default:
16075 ret = -ENOSYS;
16076 }
16077+ pax_close_userland();
16078
16079 pagefault_enable();
16080
16081@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16082 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16083 return -EFAULT;
16084
16085+ pax_open_userland();
16086 asm volatile("\t" ASM_STAC "\n"
16087- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16088+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16089 "2:\t" ASM_CLAC "\n"
16090 "\t.section .fixup, \"ax\"\n"
16091 "3:\tmov %3, %0\n"
16092 "\tjmp 2b\n"
16093 "\t.previous\n"
16094 _ASM_EXTABLE(1b, 3b)
16095- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16096+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16097 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16098 : "memory"
16099 );
16100+ pax_close_userland();
16101
16102 *uval = oldval;
16103 return ret;
16104diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16105index 92b3bae..3866449 100644
16106--- a/arch/x86/include/asm/hw_irq.h
16107+++ b/arch/x86/include/asm/hw_irq.h
16108@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16109 extern void enable_IO_APIC(void);
16110
16111 /* Statistics */
16112-extern atomic_t irq_err_count;
16113-extern atomic_t irq_mis_count;
16114+extern atomic_unchecked_t irq_err_count;
16115+extern atomic_unchecked_t irq_mis_count;
16116
16117 /* EISA */
16118 extern void eisa_set_level_irq(unsigned int irq);
16119diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16120index a203659..9889f1c 100644
16121--- a/arch/x86/include/asm/i8259.h
16122+++ b/arch/x86/include/asm/i8259.h
16123@@ -62,7 +62,7 @@ struct legacy_pic {
16124 void (*init)(int auto_eoi);
16125 int (*irq_pending)(unsigned int irq);
16126 void (*make_irq)(unsigned int irq);
16127-};
16128+} __do_const;
16129
16130 extern struct legacy_pic *legacy_pic;
16131 extern struct legacy_pic null_legacy_pic;
16132diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16133index 34f69cb..6d95446 100644
16134--- a/arch/x86/include/asm/io.h
16135+++ b/arch/x86/include/asm/io.h
16136@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16137 "m" (*(volatile type __force *)addr) barrier); }
16138
16139 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16140-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16141-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16142+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16143+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16144
16145 build_mmio_read(__readb, "b", unsigned char, "=q", )
16146-build_mmio_read(__readw, "w", unsigned short, "=r", )
16147-build_mmio_read(__readl, "l", unsigned int, "=r", )
16148+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16149+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16150
16151 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16152 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16153@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16154 return ioremap_nocache(offset, size);
16155 }
16156
16157-extern void iounmap(volatile void __iomem *addr);
16158+extern void iounmap(const volatile void __iomem *addr);
16159
16160 extern void set_iounmap_nonlazy(void);
16161
16162@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16163
16164 #include <linux/vmalloc.h>
16165
16166+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16167+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16168+{
16169+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16170+}
16171+
16172+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16173+{
16174+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16175+}
16176+
16177 /*
16178 * Convert a virtual cached pointer to an uncached pointer
16179 */
16180diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16181index bba3cf8..06bc8da 100644
16182--- a/arch/x86/include/asm/irqflags.h
16183+++ b/arch/x86/include/asm/irqflags.h
16184@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16185 sti; \
16186 sysexit
16187
16188+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16189+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16190+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16191+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16192+
16193 #else
16194 #define INTERRUPT_RETURN iret
16195 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16196diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16197index 9454c16..e4100e3 100644
16198--- a/arch/x86/include/asm/kprobes.h
16199+++ b/arch/x86/include/asm/kprobes.h
16200@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16201 #define RELATIVEJUMP_SIZE 5
16202 #define RELATIVECALL_OPCODE 0xe8
16203 #define RELATIVE_ADDR_SIZE 4
16204-#define MAX_STACK_SIZE 64
16205-#define MIN_STACK_SIZE(ADDR) \
16206- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16207- THREAD_SIZE - (unsigned long)(ADDR))) \
16208- ? (MAX_STACK_SIZE) \
16209- : (((unsigned long)current_thread_info()) + \
16210- THREAD_SIZE - (unsigned long)(ADDR)))
16211+#define MAX_STACK_SIZE 64UL
16212+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16213
16214 #define flush_insn_slot(p) do { } while (0)
16215
16216diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16217index 2d89e39..baee879 100644
16218--- a/arch/x86/include/asm/local.h
16219+++ b/arch/x86/include/asm/local.h
16220@@ -10,33 +10,97 @@ typedef struct {
16221 atomic_long_t a;
16222 } local_t;
16223
16224+typedef struct {
16225+ atomic_long_unchecked_t a;
16226+} local_unchecked_t;
16227+
16228 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16229
16230 #define local_read(l) atomic_long_read(&(l)->a)
16231+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16232 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16233+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16234
16235 static inline void local_inc(local_t *l)
16236 {
16237- asm volatile(_ASM_INC "%0"
16238+ asm volatile(_ASM_INC "%0\n"
16239+
16240+#ifdef CONFIG_PAX_REFCOUNT
16241+ "jno 0f\n"
16242+ _ASM_DEC "%0\n"
16243+ "int $4\n0:\n"
16244+ _ASM_EXTABLE(0b, 0b)
16245+#endif
16246+
16247+ : "+m" (l->a.counter));
16248+}
16249+
16250+static inline void local_inc_unchecked(local_unchecked_t *l)
16251+{
16252+ asm volatile(_ASM_INC "%0\n"
16253 : "+m" (l->a.counter));
16254 }
16255
16256 static inline void local_dec(local_t *l)
16257 {
16258- asm volatile(_ASM_DEC "%0"
16259+ asm volatile(_ASM_DEC "%0\n"
16260+
16261+#ifdef CONFIG_PAX_REFCOUNT
16262+ "jno 0f\n"
16263+ _ASM_INC "%0\n"
16264+ "int $4\n0:\n"
16265+ _ASM_EXTABLE(0b, 0b)
16266+#endif
16267+
16268+ : "+m" (l->a.counter));
16269+}
16270+
16271+static inline void local_dec_unchecked(local_unchecked_t *l)
16272+{
16273+ asm volatile(_ASM_DEC "%0\n"
16274 : "+m" (l->a.counter));
16275 }
16276
16277 static inline void local_add(long i, local_t *l)
16278 {
16279- asm volatile(_ASM_ADD "%1,%0"
16280+ asm volatile(_ASM_ADD "%1,%0\n"
16281+
16282+#ifdef CONFIG_PAX_REFCOUNT
16283+ "jno 0f\n"
16284+ _ASM_SUB "%1,%0\n"
16285+ "int $4\n0:\n"
16286+ _ASM_EXTABLE(0b, 0b)
16287+#endif
16288+
16289+ : "+m" (l->a.counter)
16290+ : "ir" (i));
16291+}
16292+
16293+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16294+{
16295+ asm volatile(_ASM_ADD "%1,%0\n"
16296 : "+m" (l->a.counter)
16297 : "ir" (i));
16298 }
16299
16300 static inline void local_sub(long i, local_t *l)
16301 {
16302- asm volatile(_ASM_SUB "%1,%0"
16303+ asm volatile(_ASM_SUB "%1,%0\n"
16304+
16305+#ifdef CONFIG_PAX_REFCOUNT
16306+ "jno 0f\n"
16307+ _ASM_ADD "%1,%0\n"
16308+ "int $4\n0:\n"
16309+ _ASM_EXTABLE(0b, 0b)
16310+#endif
16311+
16312+ : "+m" (l->a.counter)
16313+ : "ir" (i));
16314+}
16315+
16316+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16317+{
16318+ asm volatile(_ASM_SUB "%1,%0\n"
16319 : "+m" (l->a.counter)
16320 : "ir" (i));
16321 }
16322@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
16323 {
16324 unsigned char c;
16325
16326- asm volatile(_ASM_SUB "%2,%0; sete %1"
16327+ asm volatile(_ASM_SUB "%2,%0\n"
16328+
16329+#ifdef CONFIG_PAX_REFCOUNT
16330+ "jno 0f\n"
16331+ _ASM_ADD "%2,%0\n"
16332+ "int $4\n0:\n"
16333+ _ASM_EXTABLE(0b, 0b)
16334+#endif
16335+
16336+ "sete %1\n"
16337 : "+m" (l->a.counter), "=qm" (c)
16338 : "ir" (i) : "memory");
16339 return c;
16340@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
16341 {
16342 unsigned char c;
16343
16344- asm volatile(_ASM_DEC "%0; sete %1"
16345+ asm volatile(_ASM_DEC "%0\n"
16346+
16347+#ifdef CONFIG_PAX_REFCOUNT
16348+ "jno 0f\n"
16349+ _ASM_INC "%0\n"
16350+ "int $4\n0:\n"
16351+ _ASM_EXTABLE(0b, 0b)
16352+#endif
16353+
16354+ "sete %1\n"
16355 : "+m" (l->a.counter), "=qm" (c)
16356 : : "memory");
16357 return c != 0;
16358@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
16359 {
16360 unsigned char c;
16361
16362- asm volatile(_ASM_INC "%0; sete %1"
16363+ asm volatile(_ASM_INC "%0\n"
16364+
16365+#ifdef CONFIG_PAX_REFCOUNT
16366+ "jno 0f\n"
16367+ _ASM_DEC "%0\n"
16368+ "int $4\n0:\n"
16369+ _ASM_EXTABLE(0b, 0b)
16370+#endif
16371+
16372+ "sete %1\n"
16373 : "+m" (l->a.counter), "=qm" (c)
16374 : : "memory");
16375 return c != 0;
16376@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
16377 {
16378 unsigned char c;
16379
16380- asm volatile(_ASM_ADD "%2,%0; sets %1"
16381+ asm volatile(_ASM_ADD "%2,%0\n"
16382+
16383+#ifdef CONFIG_PAX_REFCOUNT
16384+ "jno 0f\n"
16385+ _ASM_SUB "%2,%0\n"
16386+ "int $4\n0:\n"
16387+ _ASM_EXTABLE(0b, 0b)
16388+#endif
16389+
16390+ "sets %1\n"
16391 : "+m" (l->a.counter), "=qm" (c)
16392 : "ir" (i) : "memory");
16393 return c;
16394@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
16395 static inline long local_add_return(long i, local_t *l)
16396 {
16397 long __i = i;
16398+ asm volatile(_ASM_XADD "%0, %1\n"
16399+
16400+#ifdef CONFIG_PAX_REFCOUNT
16401+ "jno 0f\n"
16402+ _ASM_MOV "%0,%1\n"
16403+ "int $4\n0:\n"
16404+ _ASM_EXTABLE(0b, 0b)
16405+#endif
16406+
16407+ : "+r" (i), "+m" (l->a.counter)
16408+ : : "memory");
16409+ return i + __i;
16410+}
16411+
16412+/**
16413+ * local_add_return_unchecked - add and return
16414+ * @i: integer value to add
16415+ * @l: pointer to type local_unchecked_t
16416+ *
16417+ * Atomically adds @i to @l and returns @i + @l
16418+ */
16419+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16420+{
16421+ long __i = i;
16422 asm volatile(_ASM_XADD "%0, %1;"
16423 : "+r" (i), "+m" (l->a.counter)
16424 : : "memory");
16425@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
16426
16427 #define local_cmpxchg(l, o, n) \
16428 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16429+#define local_cmpxchg_unchecked(l, o, n) \
16430+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16431 /* Always has a lock prefix */
16432 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16433
16434diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16435new file mode 100644
16436index 0000000..2bfd3ba
16437--- /dev/null
16438+++ b/arch/x86/include/asm/mman.h
16439@@ -0,0 +1,15 @@
16440+#ifndef _X86_MMAN_H
16441+#define _X86_MMAN_H
16442+
16443+#include <uapi/asm/mman.h>
16444+
16445+#ifdef __KERNEL__
16446+#ifndef __ASSEMBLY__
16447+#ifdef CONFIG_X86_32
16448+#define arch_mmap_check i386_mmap_check
16449+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16450+#endif
16451+#endif
16452+#endif
16453+
16454+#endif /* X86_MMAN_H */
16455diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16456index 5f55e69..e20bfb1 100644
16457--- a/arch/x86/include/asm/mmu.h
16458+++ b/arch/x86/include/asm/mmu.h
16459@@ -9,7 +9,7 @@
16460 * we put the segment information here.
16461 */
16462 typedef struct {
16463- void *ldt;
16464+ struct desc_struct *ldt;
16465 int size;
16466
16467 #ifdef CONFIG_X86_64
16468@@ -18,7 +18,19 @@ typedef struct {
16469 #endif
16470
16471 struct mutex lock;
16472- void *vdso;
16473+ unsigned long vdso;
16474+
16475+#ifdef CONFIG_X86_32
16476+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16477+ unsigned long user_cs_base;
16478+ unsigned long user_cs_limit;
16479+
16480+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16481+ cpumask_t cpu_user_cs_mask;
16482+#endif
16483+
16484+#endif
16485+#endif
16486 } mm_context_t;
16487
16488 #ifdef CONFIG_SMP
16489diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16490index be12c53..4d24039 100644
16491--- a/arch/x86/include/asm/mmu_context.h
16492+++ b/arch/x86/include/asm/mmu_context.h
16493@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16494
16495 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16496 {
16497+
16498+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16499+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16500+ unsigned int i;
16501+ pgd_t *pgd;
16502+
16503+ pax_open_kernel();
16504+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16505+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16506+ set_pgd_batched(pgd+i, native_make_pgd(0));
16507+ pax_close_kernel();
16508+ }
16509+#endif
16510+
16511 #ifdef CONFIG_SMP
16512 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16513 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16514@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16515 struct task_struct *tsk)
16516 {
16517 unsigned cpu = smp_processor_id();
16518+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16519+ int tlbstate = TLBSTATE_OK;
16520+#endif
16521
16522 if (likely(prev != next)) {
16523 #ifdef CONFIG_SMP
16524+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16525+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16526+#endif
16527 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16528 this_cpu_write(cpu_tlbstate.active_mm, next);
16529 #endif
16530 cpumask_set_cpu(cpu, mm_cpumask(next));
16531
16532 /* Re-load page tables */
16533+#ifdef CONFIG_PAX_PER_CPU_PGD
16534+ pax_open_kernel();
16535+
16536+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16537+ if (static_cpu_has(X86_FEATURE_PCID))
16538+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16539+ else
16540+#endif
16541+
16542+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16543+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16544+ pax_close_kernel();
16545+ 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));
16546+
16547+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16548+ if (static_cpu_has(X86_FEATURE_PCID)) {
16549+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16550+ u64 descriptor[2];
16551+ descriptor[0] = PCID_USER;
16552+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16553+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16554+ descriptor[0] = PCID_KERNEL;
16555+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16556+ }
16557+ } else {
16558+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16559+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16560+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16561+ else
16562+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16563+ }
16564+ } else
16565+#endif
16566+
16567+ load_cr3(get_cpu_pgd(cpu, kernel));
16568+#else
16569 load_cr3(next->pgd);
16570+#endif
16571
16572 /* Stop flush ipis for the previous mm */
16573 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16574@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16575 /* Load the LDT, if the LDT is different: */
16576 if (unlikely(prev->context.ldt != next->context.ldt))
16577 load_LDT_nolock(&next->context);
16578+
16579+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16580+ if (!(__supported_pte_mask & _PAGE_NX)) {
16581+ smp_mb__before_clear_bit();
16582+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16583+ smp_mb__after_clear_bit();
16584+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16585+ }
16586+#endif
16587+
16588+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16589+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16590+ prev->context.user_cs_limit != next->context.user_cs_limit))
16591+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16592+#ifdef CONFIG_SMP
16593+ else if (unlikely(tlbstate != TLBSTATE_OK))
16594+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16595+#endif
16596+#endif
16597+
16598 }
16599+ else {
16600+
16601+#ifdef CONFIG_PAX_PER_CPU_PGD
16602+ pax_open_kernel();
16603+
16604+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16605+ if (static_cpu_has(X86_FEATURE_PCID))
16606+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16607+ else
16608+#endif
16609+
16610+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16611+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16612+ pax_close_kernel();
16613+ 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));
16614+
16615+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16616+ if (static_cpu_has(X86_FEATURE_PCID)) {
16617+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16618+ u64 descriptor[2];
16619+ descriptor[0] = PCID_USER;
16620+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16621+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16622+ descriptor[0] = PCID_KERNEL;
16623+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16624+ }
16625+ } else {
16626+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16627+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16628+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16629+ else
16630+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16631+ }
16632+ } else
16633+#endif
16634+
16635+ load_cr3(get_cpu_pgd(cpu, kernel));
16636+#endif
16637+
16638 #ifdef CONFIG_SMP
16639- else {
16640 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16641 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16642
16643@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16644 * tlb flush IPI delivery. We must reload CR3
16645 * to make sure to use no freed page tables.
16646 */
16647+
16648+#ifndef CONFIG_PAX_PER_CPU_PGD
16649 load_cr3(next->pgd);
16650+#endif
16651+
16652 load_LDT_nolock(&next->context);
16653+
16654+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16655+ if (!(__supported_pte_mask & _PAGE_NX))
16656+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16657+#endif
16658+
16659+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16660+#ifdef CONFIG_PAX_PAGEEXEC
16661+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16662+#endif
16663+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16664+#endif
16665+
16666 }
16667+#endif
16668 }
16669-#endif
16670 }
16671
16672 #define activate_mm(prev, next) \
16673diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16674index e3b7819..b257c64 100644
16675--- a/arch/x86/include/asm/module.h
16676+++ b/arch/x86/include/asm/module.h
16677@@ -5,6 +5,7 @@
16678
16679 #ifdef CONFIG_X86_64
16680 /* X86_64 does not define MODULE_PROC_FAMILY */
16681+#define MODULE_PROC_FAMILY ""
16682 #elif defined CONFIG_M486
16683 #define MODULE_PROC_FAMILY "486 "
16684 #elif defined CONFIG_M586
16685@@ -57,8 +58,20 @@
16686 #error unknown processor family
16687 #endif
16688
16689-#ifdef CONFIG_X86_32
16690-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16691+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16692+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16693+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16694+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16695+#else
16696+#define MODULE_PAX_KERNEXEC ""
16697 #endif
16698
16699+#ifdef CONFIG_PAX_MEMORY_UDEREF
16700+#define MODULE_PAX_UDEREF "UDEREF "
16701+#else
16702+#define MODULE_PAX_UDEREF ""
16703+#endif
16704+
16705+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16706+
16707 #endif /* _ASM_X86_MODULE_H */
16708diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16709index 86f9301..b365cda 100644
16710--- a/arch/x86/include/asm/nmi.h
16711+++ b/arch/x86/include/asm/nmi.h
16712@@ -40,11 +40,11 @@ struct nmiaction {
16713 nmi_handler_t handler;
16714 unsigned long flags;
16715 const char *name;
16716-};
16717+} __do_const;
16718
16719 #define register_nmi_handler(t, fn, fg, n, init...) \
16720 ({ \
16721- static struct nmiaction init fn##_na = { \
16722+ static const struct nmiaction init fn##_na = { \
16723 .handler = (fn), \
16724 .name = (n), \
16725 .flags = (fg), \
16726@@ -52,7 +52,7 @@ struct nmiaction {
16727 __register_nmi_handler((t), &fn##_na); \
16728 })
16729
16730-int __register_nmi_handler(unsigned int, struct nmiaction *);
16731+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16732
16733 void unregister_nmi_handler(unsigned int, const char *);
16734
16735diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16736index c878924..21f4889 100644
16737--- a/arch/x86/include/asm/page.h
16738+++ b/arch/x86/include/asm/page.h
16739@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16740 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16741
16742 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16743+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16744
16745 #define __boot_va(x) __va(x)
16746 #define __boot_pa(x) __pa(x)
16747diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16748index 0f1ddee..e2fc3d1 100644
16749--- a/arch/x86/include/asm/page_64.h
16750+++ b/arch/x86/include/asm/page_64.h
16751@@ -7,9 +7,9 @@
16752
16753 /* duplicated to the one in bootmem.h */
16754 extern unsigned long max_pfn;
16755-extern unsigned long phys_base;
16756+extern const unsigned long phys_base;
16757
16758-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16759+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16760 {
16761 unsigned long y = x - __START_KERNEL_map;
16762
16763diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16764index 401f350..dee5d13 100644
16765--- a/arch/x86/include/asm/paravirt.h
16766+++ b/arch/x86/include/asm/paravirt.h
16767@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16768 return (pmd_t) { ret };
16769 }
16770
16771-static inline pmdval_t pmd_val(pmd_t pmd)
16772+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16773 {
16774 pmdval_t ret;
16775
16776@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16777 val);
16778 }
16779
16780+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16781+{
16782+ pgdval_t val = native_pgd_val(pgd);
16783+
16784+ if (sizeof(pgdval_t) > sizeof(long))
16785+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16786+ val, (u64)val >> 32);
16787+ else
16788+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16789+ val);
16790+}
16791+
16792 static inline void pgd_clear(pgd_t *pgdp)
16793 {
16794 set_pgd(pgdp, __pgd(0));
16795@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16796 pv_mmu_ops.set_fixmap(idx, phys, flags);
16797 }
16798
16799+#ifdef CONFIG_PAX_KERNEXEC
16800+static inline unsigned long pax_open_kernel(void)
16801+{
16802+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16803+}
16804+
16805+static inline unsigned long pax_close_kernel(void)
16806+{
16807+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16808+}
16809+#else
16810+static inline unsigned long pax_open_kernel(void) { return 0; }
16811+static inline unsigned long pax_close_kernel(void) { return 0; }
16812+#endif
16813+
16814 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16815
16816 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16817@@ -906,7 +933,7 @@ extern void default_banner(void);
16818
16819 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16820 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16821-#define PARA_INDIRECT(addr) *%cs:addr
16822+#define PARA_INDIRECT(addr) *%ss:addr
16823 #endif
16824
16825 #define INTERRUPT_RETURN \
16826@@ -981,6 +1008,21 @@ extern void default_banner(void);
16827 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16828 CLBR_NONE, \
16829 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16830+
16831+#define GET_CR0_INTO_RDI \
16832+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16833+ mov %rax,%rdi
16834+
16835+#define SET_RDI_INTO_CR0 \
16836+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16837+
16838+#define GET_CR3_INTO_RDI \
16839+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16840+ mov %rax,%rdi
16841+
16842+#define SET_RDI_INTO_CR3 \
16843+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16844+
16845 #endif /* CONFIG_X86_32 */
16846
16847 #endif /* __ASSEMBLY__ */
16848diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16849index aab8f67..2531748 100644
16850--- a/arch/x86/include/asm/paravirt_types.h
16851+++ b/arch/x86/include/asm/paravirt_types.h
16852@@ -84,7 +84,7 @@ struct pv_init_ops {
16853 */
16854 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16855 unsigned long addr, unsigned len);
16856-};
16857+} __no_const;
16858
16859
16860 struct pv_lazy_ops {
16861@@ -98,7 +98,7 @@ struct pv_time_ops {
16862 unsigned long long (*sched_clock)(void);
16863 unsigned long long (*steal_clock)(int cpu);
16864 unsigned long (*get_tsc_khz)(void);
16865-};
16866+} __no_const;
16867
16868 struct pv_cpu_ops {
16869 /* hooks for various privileged instructions */
16870@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16871
16872 void (*start_context_switch)(struct task_struct *prev);
16873 void (*end_context_switch)(struct task_struct *next);
16874-};
16875+} __no_const;
16876
16877 struct pv_irq_ops {
16878 /*
16879@@ -223,7 +223,7 @@ struct pv_apic_ops {
16880 unsigned long start_eip,
16881 unsigned long start_esp);
16882 #endif
16883-};
16884+} __no_const;
16885
16886 struct pv_mmu_ops {
16887 unsigned long (*read_cr2)(void);
16888@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16889 struct paravirt_callee_save make_pud;
16890
16891 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16892+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16893 #endif /* PAGETABLE_LEVELS == 4 */
16894 #endif /* PAGETABLE_LEVELS >= 3 */
16895
16896@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16897 an mfn. We can tell which is which from the index. */
16898 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16899 phys_addr_t phys, pgprot_t flags);
16900+
16901+#ifdef CONFIG_PAX_KERNEXEC
16902+ unsigned long (*pax_open_kernel)(void);
16903+ unsigned long (*pax_close_kernel)(void);
16904+#endif
16905+
16906 };
16907
16908 struct arch_spinlock;
16909diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16910index b4389a4..7024269 100644
16911--- a/arch/x86/include/asm/pgalloc.h
16912+++ b/arch/x86/include/asm/pgalloc.h
16913@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16914 pmd_t *pmd, pte_t *pte)
16915 {
16916 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16917+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16918+}
16919+
16920+static inline void pmd_populate_user(struct mm_struct *mm,
16921+ pmd_t *pmd, pte_t *pte)
16922+{
16923+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16924 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16925 }
16926
16927@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16928
16929 #ifdef CONFIG_X86_PAE
16930 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16931+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16932+{
16933+ pud_populate(mm, pudp, pmd);
16934+}
16935 #else /* !CONFIG_X86_PAE */
16936 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16937 {
16938 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16939 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16940 }
16941+
16942+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16943+{
16944+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16945+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16946+}
16947 #endif /* CONFIG_X86_PAE */
16948
16949 #if PAGETABLE_LEVELS > 3
16950@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16951 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16952 }
16953
16954+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16955+{
16956+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16957+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16958+}
16959+
16960 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16961 {
16962 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16963diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16964index 3bf2dd0..23d2a9f 100644
16965--- a/arch/x86/include/asm/pgtable-2level.h
16966+++ b/arch/x86/include/asm/pgtable-2level.h
16967@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16968
16969 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16970 {
16971+ pax_open_kernel();
16972 *pmdp = pmd;
16973+ pax_close_kernel();
16974 }
16975
16976 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16977diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16978index 81bb91b..9392125 100644
16979--- a/arch/x86/include/asm/pgtable-3level.h
16980+++ b/arch/x86/include/asm/pgtable-3level.h
16981@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16982
16983 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16984 {
16985+ pax_open_kernel();
16986 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16987+ pax_close_kernel();
16988 }
16989
16990 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16991 {
16992+ pax_open_kernel();
16993 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16994+ pax_close_kernel();
16995 }
16996
16997 /*
16998diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16999index 3d19994..732a48c 100644
17000--- a/arch/x86/include/asm/pgtable.h
17001+++ b/arch/x86/include/asm/pgtable.h
17002@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17003
17004 #ifndef __PAGETABLE_PUD_FOLDED
17005 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17006+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17007 #define pgd_clear(pgd) native_pgd_clear(pgd)
17008 #endif
17009
17010@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17011
17012 #define arch_end_context_switch(prev) do {} while(0)
17013
17014+#define pax_open_kernel() native_pax_open_kernel()
17015+#define pax_close_kernel() native_pax_close_kernel()
17016 #endif /* CONFIG_PARAVIRT */
17017
17018+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17019+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17020+
17021+#ifdef CONFIG_PAX_KERNEXEC
17022+static inline unsigned long native_pax_open_kernel(void)
17023+{
17024+ unsigned long cr0;
17025+
17026+ preempt_disable();
17027+ barrier();
17028+ cr0 = read_cr0() ^ X86_CR0_WP;
17029+ BUG_ON(cr0 & X86_CR0_WP);
17030+ write_cr0(cr0);
17031+ return cr0 ^ X86_CR0_WP;
17032+}
17033+
17034+static inline unsigned long native_pax_close_kernel(void)
17035+{
17036+ unsigned long cr0;
17037+
17038+ cr0 = read_cr0() ^ X86_CR0_WP;
17039+ BUG_ON(!(cr0 & X86_CR0_WP));
17040+ write_cr0(cr0);
17041+ barrier();
17042+ preempt_enable_no_resched();
17043+ return cr0 ^ X86_CR0_WP;
17044+}
17045+#else
17046+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17047+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17048+#endif
17049+
17050 /*
17051 * The following only work if pte_present() is true.
17052 * Undefined behaviour if not..
17053 */
17054+static inline int pte_user(pte_t pte)
17055+{
17056+ return pte_val(pte) & _PAGE_USER;
17057+}
17058+
17059 static inline int pte_dirty(pte_t pte)
17060 {
17061 return pte_flags(pte) & _PAGE_DIRTY;
17062@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17063 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17064 }
17065
17066+static inline unsigned long pgd_pfn(pgd_t pgd)
17067+{
17068+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17069+}
17070+
17071 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17072
17073 static inline int pmd_large(pmd_t pte)
17074@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17075 return pte_clear_flags(pte, _PAGE_RW);
17076 }
17077
17078+static inline pte_t pte_mkread(pte_t pte)
17079+{
17080+ return __pte(pte_val(pte) | _PAGE_USER);
17081+}
17082+
17083 static inline pte_t pte_mkexec(pte_t pte)
17084 {
17085- return pte_clear_flags(pte, _PAGE_NX);
17086+#ifdef CONFIG_X86_PAE
17087+ if (__supported_pte_mask & _PAGE_NX)
17088+ return pte_clear_flags(pte, _PAGE_NX);
17089+ else
17090+#endif
17091+ return pte_set_flags(pte, _PAGE_USER);
17092+}
17093+
17094+static inline pte_t pte_exprotect(pte_t pte)
17095+{
17096+#ifdef CONFIG_X86_PAE
17097+ if (__supported_pte_mask & _PAGE_NX)
17098+ return pte_set_flags(pte, _PAGE_NX);
17099+ else
17100+#endif
17101+ return pte_clear_flags(pte, _PAGE_USER);
17102 }
17103
17104 static inline pte_t pte_mkdirty(pte_t pte)
17105@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17106 #endif
17107
17108 #ifndef __ASSEMBLY__
17109+
17110+#ifdef CONFIG_PAX_PER_CPU_PGD
17111+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17112+enum cpu_pgd_type {kernel = 0, user = 1};
17113+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17114+{
17115+ return cpu_pgd[cpu][type];
17116+}
17117+#endif
17118+
17119 #include <linux/mm_types.h>
17120 #include <linux/mmdebug.h>
17121 #include <linux/log2.h>
17122@@ -563,7 +638,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17123 * Currently stuck as a macro due to indirect forward reference to
17124 * linux/mmzone.h's __section_mem_map_addr() definition:
17125 */
17126-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17127+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17128
17129 /* Find an entry in the second-level page table.. */
17130 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17131@@ -603,7 +678,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17132 * Currently stuck as a macro due to indirect forward reference to
17133 * linux/mmzone.h's __section_mem_map_addr() definition:
17134 */
17135-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17136+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17137
17138 /* to find an entry in a page-table-directory. */
17139 static inline unsigned long pud_index(unsigned long address)
17140@@ -618,7 +693,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17141
17142 static inline int pgd_bad(pgd_t pgd)
17143 {
17144- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17145+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17146 }
17147
17148 static inline int pgd_none(pgd_t pgd)
17149@@ -641,7 +716,12 @@ static inline int pgd_none(pgd_t pgd)
17150 * pgd_offset() returns a (pgd_t *)
17151 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17152 */
17153-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17154+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17155+
17156+#ifdef CONFIG_PAX_PER_CPU_PGD
17157+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17158+#endif
17159+
17160 /*
17161 * a shortcut which implies the use of the kernel's pgd, instead
17162 * of a process's
17163@@ -652,6 +732,23 @@ static inline int pgd_none(pgd_t pgd)
17164 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17165 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17166
17167+#ifdef CONFIG_X86_32
17168+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17169+#else
17170+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17171+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17172+
17173+#ifdef CONFIG_PAX_MEMORY_UDEREF
17174+#ifdef __ASSEMBLY__
17175+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17176+#else
17177+extern unsigned long pax_user_shadow_base;
17178+extern pgdval_t clone_pgd_mask;
17179+#endif
17180+#endif
17181+
17182+#endif
17183+
17184 #ifndef __ASSEMBLY__
17185
17186 extern int direct_gbpages;
17187@@ -818,11 +915,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17188 * dst and src can be on the same page, but the range must not overlap,
17189 * and must not cross a page boundary.
17190 */
17191-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17192+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17193 {
17194- memcpy(dst, src, count * sizeof(pgd_t));
17195+ pax_open_kernel();
17196+ while (count--)
17197+ *dst++ = *src++;
17198+ pax_close_kernel();
17199 }
17200
17201+#ifdef CONFIG_PAX_PER_CPU_PGD
17202+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17203+#endif
17204+
17205+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17206+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17207+#else
17208+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17209+#endif
17210+
17211 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17212 static inline int page_level_shift(enum pg_level level)
17213 {
17214diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17215index 9ee3221..b979c6b 100644
17216--- a/arch/x86/include/asm/pgtable_32.h
17217+++ b/arch/x86/include/asm/pgtable_32.h
17218@@ -25,9 +25,6 @@
17219 struct mm_struct;
17220 struct vm_area_struct;
17221
17222-extern pgd_t swapper_pg_dir[1024];
17223-extern pgd_t initial_page_table[1024];
17224-
17225 static inline void pgtable_cache_init(void) { }
17226 static inline void check_pgt_cache(void) { }
17227 void paging_init(void);
17228@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17229 # include <asm/pgtable-2level.h>
17230 #endif
17231
17232+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17233+extern pgd_t initial_page_table[PTRS_PER_PGD];
17234+#ifdef CONFIG_X86_PAE
17235+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17236+#endif
17237+
17238 #if defined(CONFIG_HIGHPTE)
17239 #define pte_offset_map(dir, address) \
17240 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17241@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17242 /* Clear a kernel PTE and flush it from the TLB */
17243 #define kpte_clear_flush(ptep, vaddr) \
17244 do { \
17245+ pax_open_kernel(); \
17246 pte_clear(&init_mm, (vaddr), (ptep)); \
17247+ pax_close_kernel(); \
17248 __flush_tlb_one((vaddr)); \
17249 } while (0)
17250
17251 #endif /* !__ASSEMBLY__ */
17252
17253+#define HAVE_ARCH_UNMAPPED_AREA
17254+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17255+
17256 /*
17257 * kern_addr_valid() is (1) for FLATMEM and (0) for
17258 * SPARSEMEM and DISCONTIGMEM
17259diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17260index ed5903b..c7fe163 100644
17261--- a/arch/x86/include/asm/pgtable_32_types.h
17262+++ b/arch/x86/include/asm/pgtable_32_types.h
17263@@ -8,7 +8,7 @@
17264 */
17265 #ifdef CONFIG_X86_PAE
17266 # include <asm/pgtable-3level_types.h>
17267-# define PMD_SIZE (1UL << PMD_SHIFT)
17268+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17269 # define PMD_MASK (~(PMD_SIZE - 1))
17270 #else
17271 # include <asm/pgtable-2level_types.h>
17272@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17273 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17274 #endif
17275
17276+#ifdef CONFIG_PAX_KERNEXEC
17277+#ifndef __ASSEMBLY__
17278+extern unsigned char MODULES_EXEC_VADDR[];
17279+extern unsigned char MODULES_EXEC_END[];
17280+#endif
17281+#include <asm/boot.h>
17282+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17283+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17284+#else
17285+#define ktla_ktva(addr) (addr)
17286+#define ktva_ktla(addr) (addr)
17287+#endif
17288+
17289 #define MODULES_VADDR VMALLOC_START
17290 #define MODULES_END VMALLOC_END
17291 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17292diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17293index e22c1db..23a625a 100644
17294--- a/arch/x86/include/asm/pgtable_64.h
17295+++ b/arch/x86/include/asm/pgtable_64.h
17296@@ -16,10 +16,14 @@
17297
17298 extern pud_t level3_kernel_pgt[512];
17299 extern pud_t level3_ident_pgt[512];
17300+extern pud_t level3_vmalloc_start_pgt[512];
17301+extern pud_t level3_vmalloc_end_pgt[512];
17302+extern pud_t level3_vmemmap_pgt[512];
17303+extern pud_t level2_vmemmap_pgt[512];
17304 extern pmd_t level2_kernel_pgt[512];
17305 extern pmd_t level2_fixmap_pgt[512];
17306-extern pmd_t level2_ident_pgt[512];
17307-extern pgd_t init_level4_pgt[];
17308+extern pmd_t level2_ident_pgt[512*2];
17309+extern pgd_t init_level4_pgt[512];
17310
17311 #define swapper_pg_dir init_level4_pgt
17312
17313@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17314
17315 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17316 {
17317+ pax_open_kernel();
17318 *pmdp = pmd;
17319+ pax_close_kernel();
17320 }
17321
17322 static inline void native_pmd_clear(pmd_t *pmd)
17323@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17324
17325 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17326 {
17327+ pax_open_kernel();
17328 *pudp = pud;
17329+ pax_close_kernel();
17330 }
17331
17332 static inline void native_pud_clear(pud_t *pud)
17333@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17334
17335 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17336 {
17337+ pax_open_kernel();
17338+ *pgdp = pgd;
17339+ pax_close_kernel();
17340+}
17341+
17342+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17343+{
17344 *pgdp = pgd;
17345 }
17346
17347diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17348index 2d88344..4679fc3 100644
17349--- a/arch/x86/include/asm/pgtable_64_types.h
17350+++ b/arch/x86/include/asm/pgtable_64_types.h
17351@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17352 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17353 #define MODULES_END _AC(0xffffffffff000000, UL)
17354 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17355+#define MODULES_EXEC_VADDR MODULES_VADDR
17356+#define MODULES_EXEC_END MODULES_END
17357+
17358+#define ktla_ktva(addr) (addr)
17359+#define ktva_ktla(addr) (addr)
17360
17361 #define EARLY_DYNAMIC_PAGE_TABLES 64
17362
17363diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17364index 0ecac25..306c276 100644
17365--- a/arch/x86/include/asm/pgtable_types.h
17366+++ b/arch/x86/include/asm/pgtable_types.h
17367@@ -16,13 +16,12 @@
17368 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17369 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17370 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17371-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17372+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17373 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17374 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17375 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17376-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17377-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17378-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17379+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17380+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17381 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17382
17383 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17384@@ -40,7 +39,6 @@
17385 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17386 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17387 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17388-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17389 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17390 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17391 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17392@@ -87,8 +85,10 @@
17393
17394 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17395 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17396-#else
17397+#elif defined(CONFIG_KMEMCHECK)
17398 #define _PAGE_NX (_AT(pteval_t, 0))
17399+#else
17400+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17401 #endif
17402
17403 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17404@@ -146,6 +146,9 @@
17405 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17406 _PAGE_ACCESSED)
17407
17408+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17409+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17410+
17411 #define __PAGE_KERNEL_EXEC \
17412 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17413 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17414@@ -156,7 +159,7 @@
17415 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17416 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17417 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17418-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17419+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17420 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17421 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17422 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17423@@ -218,8 +221,8 @@
17424 * bits are combined, this will alow user to access the high address mapped
17425 * VDSO in the presence of CONFIG_COMPAT_VDSO
17426 */
17427-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17428-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17429+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17430+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17431 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17432 #endif
17433
17434@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17435 {
17436 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17437 }
17438+#endif
17439
17440+#if PAGETABLE_LEVELS == 3
17441+#include <asm-generic/pgtable-nopud.h>
17442+#endif
17443+
17444+#if PAGETABLE_LEVELS == 2
17445+#include <asm-generic/pgtable-nopmd.h>
17446+#endif
17447+
17448+#ifndef __ASSEMBLY__
17449 #if PAGETABLE_LEVELS > 3
17450 typedef struct { pudval_t pud; } pud_t;
17451
17452@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17453 return pud.pud;
17454 }
17455 #else
17456-#include <asm-generic/pgtable-nopud.h>
17457-
17458 static inline pudval_t native_pud_val(pud_t pud)
17459 {
17460 return native_pgd_val(pud.pgd);
17461@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17462 return pmd.pmd;
17463 }
17464 #else
17465-#include <asm-generic/pgtable-nopmd.h>
17466-
17467 static inline pmdval_t native_pmd_val(pmd_t pmd)
17468 {
17469 return native_pgd_val(pmd.pud.pgd);
17470@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17471
17472 extern pteval_t __supported_pte_mask;
17473 extern void set_nx(void);
17474-extern int nx_enabled;
17475
17476 #define pgprot_writecombine pgprot_writecombine
17477 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17478diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17479index 987c75e..2723054 100644
17480--- a/arch/x86/include/asm/processor.h
17481+++ b/arch/x86/include/asm/processor.h
17482@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17483 : "memory");
17484 }
17485
17486+/* invpcid (%rdx),%rax */
17487+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17488+
17489+#define INVPCID_SINGLE_ADDRESS 0UL
17490+#define INVPCID_SINGLE_CONTEXT 1UL
17491+#define INVPCID_ALL_GLOBAL 2UL
17492+#define INVPCID_ALL_MONGLOBAL 3UL
17493+
17494+#define PCID_KERNEL 0UL
17495+#define PCID_USER 1UL
17496+#define PCID_NOFLUSH (1UL << 63)
17497+
17498 static inline void load_cr3(pgd_t *pgdir)
17499 {
17500- write_cr3(__pa(pgdir));
17501+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17502 }
17503
17504 #ifdef CONFIG_X86_32
17505@@ -283,7 +295,7 @@ struct tss_struct {
17506
17507 } ____cacheline_aligned;
17508
17509-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17510+extern struct tss_struct init_tss[NR_CPUS];
17511
17512 /*
17513 * Save the original ist values for checking stack pointers during debugging
17514@@ -453,6 +465,7 @@ struct thread_struct {
17515 unsigned short ds;
17516 unsigned short fsindex;
17517 unsigned short gsindex;
17518+ unsigned short ss;
17519 #endif
17520 #ifdef CONFIG_X86_32
17521 unsigned long ip;
17522@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
17523 extern unsigned long mmu_cr4_features;
17524 extern u32 *trampoline_cr4_features;
17525
17526-static inline void set_in_cr4(unsigned long mask)
17527-{
17528- unsigned long cr4;
17529-
17530- mmu_cr4_features |= mask;
17531- if (trampoline_cr4_features)
17532- *trampoline_cr4_features = mmu_cr4_features;
17533- cr4 = read_cr4();
17534- cr4 |= mask;
17535- write_cr4(cr4);
17536-}
17537-
17538-static inline void clear_in_cr4(unsigned long mask)
17539-{
17540- unsigned long cr4;
17541-
17542- mmu_cr4_features &= ~mask;
17543- if (trampoline_cr4_features)
17544- *trampoline_cr4_features = mmu_cr4_features;
17545- cr4 = read_cr4();
17546- cr4 &= ~mask;
17547- write_cr4(cr4);
17548-}
17549+extern void set_in_cr4(unsigned long mask);
17550+extern void clear_in_cr4(unsigned long mask);
17551
17552 typedef struct {
17553 unsigned long seg;
17554@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
17555 */
17556 #define TASK_SIZE PAGE_OFFSET
17557 #define TASK_SIZE_MAX TASK_SIZE
17558+
17559+#ifdef CONFIG_PAX_SEGMEXEC
17560+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17561+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17562+#else
17563 #define STACK_TOP TASK_SIZE
17564-#define STACK_TOP_MAX STACK_TOP
17565+#endif
17566+
17567+#define STACK_TOP_MAX TASK_SIZE
17568
17569 #define INIT_THREAD { \
17570- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17571+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17572 .vm86_info = NULL, \
17573 .sysenter_cs = __KERNEL_CS, \
17574 .io_bitmap_ptr = NULL, \
17575@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
17576 */
17577 #define INIT_TSS { \
17578 .x86_tss = { \
17579- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17580+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17581 .ss0 = __KERNEL_DS, \
17582 .ss1 = __KERNEL_CS, \
17583 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17584@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
17585 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17586
17587 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17588-#define KSTK_TOP(info) \
17589-({ \
17590- unsigned long *__ptr = (unsigned long *)(info); \
17591- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17592-})
17593+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17594
17595 /*
17596 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17597@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17598 #define task_pt_regs(task) \
17599 ({ \
17600 struct pt_regs *__regs__; \
17601- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17602+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17603 __regs__ - 1; \
17604 })
17605
17606@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17607 /*
17608 * User space process size. 47bits minus one guard page.
17609 */
17610-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17611+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17612
17613 /* This decides where the kernel will search for a free chunk of vm
17614 * space during mmap's.
17615 */
17616 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17617- 0xc0000000 : 0xFFFFe000)
17618+ 0xc0000000 : 0xFFFFf000)
17619
17620 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17621 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17622@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17623 #define STACK_TOP_MAX TASK_SIZE_MAX
17624
17625 #define INIT_THREAD { \
17626- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17627+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17628 }
17629
17630 #define INIT_TSS { \
17631- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17632+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17633 }
17634
17635 /*
17636@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17637 */
17638 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17639
17640+#ifdef CONFIG_PAX_SEGMEXEC
17641+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17642+#endif
17643+
17644 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17645
17646 /* Get/set a process' ability to use the timestamp counter instruction */
17647@@ -957,7 +956,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17648 return 0;
17649 }
17650
17651-extern unsigned long arch_align_stack(unsigned long sp);
17652+#define arch_align_stack(x) ((x) & ~0xfUL)
17653 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17654
17655 void default_idle(void);
17656@@ -967,6 +966,6 @@ bool xen_set_default_idle(void);
17657 #define xen_set_default_idle 0
17658 #endif
17659
17660-void stop_this_cpu(void *dummy);
17661+void stop_this_cpu(void *dummy) __noreturn;
17662 void df_debug(struct pt_regs *regs, long error_code);
17663 #endif /* _ASM_X86_PROCESSOR_H */
17664diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17665index 942a086..6c26446 100644
17666--- a/arch/x86/include/asm/ptrace.h
17667+++ b/arch/x86/include/asm/ptrace.h
17668@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17669 }
17670
17671 /*
17672- * user_mode_vm(regs) determines whether a register set came from user mode.
17673+ * user_mode(regs) determines whether a register set came from user mode.
17674 * This is true if V8086 mode was enabled OR if the register set was from
17675 * protected mode with RPL-3 CS value. This tricky test checks that with
17676 * one comparison. Many places in the kernel can bypass this full check
17677- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17678+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17679+ * be used.
17680 */
17681-static inline int user_mode(struct pt_regs *regs)
17682+static inline int user_mode_novm(struct pt_regs *regs)
17683 {
17684 #ifdef CONFIG_X86_32
17685 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17686 #else
17687- return !!(regs->cs & 3);
17688+ return !!(regs->cs & SEGMENT_RPL_MASK);
17689 #endif
17690 }
17691
17692-static inline int user_mode_vm(struct pt_regs *regs)
17693+static inline int user_mode(struct pt_regs *regs)
17694 {
17695 #ifdef CONFIG_X86_32
17696 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17697 USER_RPL;
17698 #else
17699- return user_mode(regs);
17700+ return user_mode_novm(regs);
17701 #endif
17702 }
17703
17704@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17705 #ifdef CONFIG_X86_64
17706 static inline bool user_64bit_mode(struct pt_regs *regs)
17707 {
17708+ unsigned long cs = regs->cs & 0xffff;
17709 #ifndef CONFIG_PARAVIRT
17710 /*
17711 * On non-paravirt systems, this is the only long mode CPL 3
17712 * selector. We do not allow long mode selectors in the LDT.
17713 */
17714- return regs->cs == __USER_CS;
17715+ return cs == __USER_CS;
17716 #else
17717 /* Headers are too twisted for this to go in paravirt.h. */
17718- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17719+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17720 #endif
17721 }
17722
17723@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17724 * Traps from the kernel do not save sp and ss.
17725 * Use the helper function to retrieve sp.
17726 */
17727- if (offset == offsetof(struct pt_regs, sp) &&
17728- regs->cs == __KERNEL_CS)
17729- return kernel_stack_pointer(regs);
17730+ if (offset == offsetof(struct pt_regs, sp)) {
17731+ unsigned long cs = regs->cs & 0xffff;
17732+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17733+ return kernel_stack_pointer(regs);
17734+ }
17735 #endif
17736 return *(unsigned long *)((unsigned long)regs + offset);
17737 }
17738diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17739index 9c6b890..5305f53 100644
17740--- a/arch/x86/include/asm/realmode.h
17741+++ b/arch/x86/include/asm/realmode.h
17742@@ -22,16 +22,14 @@ struct real_mode_header {
17743 #endif
17744 /* APM/BIOS reboot */
17745 u32 machine_real_restart_asm;
17746-#ifdef CONFIG_X86_64
17747 u32 machine_real_restart_seg;
17748-#endif
17749 };
17750
17751 /* This must match data at trampoline_32/64.S */
17752 struct trampoline_header {
17753 #ifdef CONFIG_X86_32
17754 u32 start;
17755- u16 gdt_pad;
17756+ u16 boot_cs;
17757 u16 gdt_limit;
17758 u32 gdt_base;
17759 #else
17760diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17761index a82c4f1..ac45053 100644
17762--- a/arch/x86/include/asm/reboot.h
17763+++ b/arch/x86/include/asm/reboot.h
17764@@ -6,13 +6,13 @@
17765 struct pt_regs;
17766
17767 struct machine_ops {
17768- void (*restart)(char *cmd);
17769- void (*halt)(void);
17770- void (*power_off)(void);
17771+ void (* __noreturn restart)(char *cmd);
17772+ void (* __noreturn halt)(void);
17773+ void (* __noreturn power_off)(void);
17774 void (*shutdown)(void);
17775 void (*crash_shutdown)(struct pt_regs *);
17776- void (*emergency_restart)(void);
17777-};
17778+ void (* __noreturn emergency_restart)(void);
17779+} __no_const;
17780
17781 extern struct machine_ops machine_ops;
17782
17783diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17784index cad82c9..2e5c5c1 100644
17785--- a/arch/x86/include/asm/rwsem.h
17786+++ b/arch/x86/include/asm/rwsem.h
17787@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17788 {
17789 asm volatile("# beginning down_read\n\t"
17790 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17791+
17792+#ifdef CONFIG_PAX_REFCOUNT
17793+ "jno 0f\n"
17794+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17795+ "int $4\n0:\n"
17796+ _ASM_EXTABLE(0b, 0b)
17797+#endif
17798+
17799 /* adds 0x00000001 */
17800 " jns 1f\n"
17801 " call call_rwsem_down_read_failed\n"
17802@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17803 "1:\n\t"
17804 " mov %1,%2\n\t"
17805 " add %3,%2\n\t"
17806+
17807+#ifdef CONFIG_PAX_REFCOUNT
17808+ "jno 0f\n"
17809+ "sub %3,%2\n"
17810+ "int $4\n0:\n"
17811+ _ASM_EXTABLE(0b, 0b)
17812+#endif
17813+
17814 " jle 2f\n\t"
17815 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17816 " jnz 1b\n\t"
17817@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17818 long tmp;
17819 asm volatile("# beginning down_write\n\t"
17820 LOCK_PREFIX " xadd %1,(%2)\n\t"
17821+
17822+#ifdef CONFIG_PAX_REFCOUNT
17823+ "jno 0f\n"
17824+ "mov %1,(%2)\n"
17825+ "int $4\n0:\n"
17826+ _ASM_EXTABLE(0b, 0b)
17827+#endif
17828+
17829 /* adds 0xffff0001, returns the old value */
17830 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17831 /* was the active mask 0 before? */
17832@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17833 long tmp;
17834 asm volatile("# beginning __up_read\n\t"
17835 LOCK_PREFIX " xadd %1,(%2)\n\t"
17836+
17837+#ifdef CONFIG_PAX_REFCOUNT
17838+ "jno 0f\n"
17839+ "mov %1,(%2)\n"
17840+ "int $4\n0:\n"
17841+ _ASM_EXTABLE(0b, 0b)
17842+#endif
17843+
17844 /* subtracts 1, returns the old value */
17845 " jns 1f\n\t"
17846 " call call_rwsem_wake\n" /* expects old value in %edx */
17847@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17848 long tmp;
17849 asm volatile("# beginning __up_write\n\t"
17850 LOCK_PREFIX " xadd %1,(%2)\n\t"
17851+
17852+#ifdef CONFIG_PAX_REFCOUNT
17853+ "jno 0f\n"
17854+ "mov %1,(%2)\n"
17855+ "int $4\n0:\n"
17856+ _ASM_EXTABLE(0b, 0b)
17857+#endif
17858+
17859 /* subtracts 0xffff0001, returns the old value */
17860 " jns 1f\n\t"
17861 " call call_rwsem_wake\n" /* expects old value in %edx */
17862@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17863 {
17864 asm volatile("# beginning __downgrade_write\n\t"
17865 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17866+
17867+#ifdef CONFIG_PAX_REFCOUNT
17868+ "jno 0f\n"
17869+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17870+ "int $4\n0:\n"
17871+ _ASM_EXTABLE(0b, 0b)
17872+#endif
17873+
17874 /*
17875 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17876 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17877@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17878 */
17879 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17880 {
17881- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17882+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17883+
17884+#ifdef CONFIG_PAX_REFCOUNT
17885+ "jno 0f\n"
17886+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17887+ "int $4\n0:\n"
17888+ _ASM_EXTABLE(0b, 0b)
17889+#endif
17890+
17891 : "+m" (sem->count)
17892 : "er" (delta));
17893 }
17894@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17895 */
17896 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17897 {
17898- return delta + xadd(&sem->count, delta);
17899+ return delta + xadd_check_overflow(&sem->count, delta);
17900 }
17901
17902 #endif /* __KERNEL__ */
17903diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17904index c48a950..bc40804 100644
17905--- a/arch/x86/include/asm/segment.h
17906+++ b/arch/x86/include/asm/segment.h
17907@@ -64,10 +64,15 @@
17908 * 26 - ESPFIX small SS
17909 * 27 - per-cpu [ offset to per-cpu data area ]
17910 * 28 - stack_canary-20 [ for stack protector ]
17911- * 29 - unused
17912- * 30 - unused
17913+ * 29 - PCI BIOS CS
17914+ * 30 - PCI BIOS DS
17915 * 31 - TSS for double fault handler
17916 */
17917+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17918+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17919+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17920+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17921+
17922 #define GDT_ENTRY_TLS_MIN 6
17923 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17924
17925@@ -79,6 +84,8 @@
17926
17927 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17928
17929+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17930+
17931 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17932
17933 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17934@@ -104,6 +111,12 @@
17935 #define __KERNEL_STACK_CANARY 0
17936 #endif
17937
17938+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17939+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17940+
17941+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17942+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17943+
17944 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17945
17946 /*
17947@@ -141,7 +154,7 @@
17948 */
17949
17950 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17951-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17952+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17953
17954
17955 #else
17956@@ -165,6 +178,8 @@
17957 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17958 #define __USER32_DS __USER_DS
17959
17960+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17961+
17962 #define GDT_ENTRY_TSS 8 /* needs two entries */
17963 #define GDT_ENTRY_LDT 10 /* needs two entries */
17964 #define GDT_ENTRY_TLS_MIN 12
17965@@ -173,6 +188,8 @@
17966 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17967 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17968
17969+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17970+
17971 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17972 #define FS_TLS 0
17973 #define GS_TLS 1
17974@@ -180,12 +197,14 @@
17975 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17976 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17977
17978-#define GDT_ENTRIES 16
17979+#define GDT_ENTRIES 17
17980
17981 #endif
17982
17983 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17984+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17985 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17986+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17987 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17988 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17989 #ifndef CONFIG_PARAVIRT
17990@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17991 {
17992 unsigned long __limit;
17993 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17994- return __limit + 1;
17995+ return __limit;
17996 }
17997
17998 #endif /* !__ASSEMBLY__ */
17999diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18000index 8d3120f..352b440 100644
18001--- a/arch/x86/include/asm/smap.h
18002+++ b/arch/x86/include/asm/smap.h
18003@@ -25,11 +25,40 @@
18004
18005 #include <asm/alternative-asm.h>
18006
18007+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18008+#define ASM_PAX_OPEN_USERLAND \
18009+ 661: jmp 663f; \
18010+ .pushsection .altinstr_replacement, "a" ; \
18011+ 662: pushq %rax; nop; \
18012+ .popsection ; \
18013+ .pushsection .altinstructions, "a" ; \
18014+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18015+ .popsection ; \
18016+ call __pax_open_userland; \
18017+ popq %rax; \
18018+ 663:
18019+
18020+#define ASM_PAX_CLOSE_USERLAND \
18021+ 661: jmp 663f; \
18022+ .pushsection .altinstr_replacement, "a" ; \
18023+ 662: pushq %rax; nop; \
18024+ .popsection; \
18025+ .pushsection .altinstructions, "a" ; \
18026+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18027+ .popsection; \
18028+ call __pax_close_userland; \
18029+ popq %rax; \
18030+ 663:
18031+#else
18032+#define ASM_PAX_OPEN_USERLAND
18033+#define ASM_PAX_CLOSE_USERLAND
18034+#endif
18035+
18036 #ifdef CONFIG_X86_SMAP
18037
18038 #define ASM_CLAC \
18039 661: ASM_NOP3 ; \
18040- .pushsection .altinstr_replacement, "ax" ; \
18041+ .pushsection .altinstr_replacement, "a" ; \
18042 662: __ASM_CLAC ; \
18043 .popsection ; \
18044 .pushsection .altinstructions, "a" ; \
18045@@ -38,7 +67,7 @@
18046
18047 #define ASM_STAC \
18048 661: ASM_NOP3 ; \
18049- .pushsection .altinstr_replacement, "ax" ; \
18050+ .pushsection .altinstr_replacement, "a" ; \
18051 662: __ASM_STAC ; \
18052 .popsection ; \
18053 .pushsection .altinstructions, "a" ; \
18054@@ -56,6 +85,37 @@
18055
18056 #include <asm/alternative.h>
18057
18058+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18059+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18060+
18061+extern void __pax_open_userland(void);
18062+static __always_inline unsigned long pax_open_userland(void)
18063+{
18064+
18065+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18066+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18067+ :
18068+ : [open] "i" (__pax_open_userland)
18069+ : "memory", "rax");
18070+#endif
18071+
18072+ return 0;
18073+}
18074+
18075+extern void __pax_close_userland(void);
18076+static __always_inline unsigned long pax_close_userland(void)
18077+{
18078+
18079+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18080+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18081+ :
18082+ : [close] "i" (__pax_close_userland)
18083+ : "memory", "rax");
18084+#endif
18085+
18086+ return 0;
18087+}
18088+
18089 #ifdef CONFIG_X86_SMAP
18090
18091 static __always_inline void clac(void)
18092diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18093index 4137890..03fa172 100644
18094--- a/arch/x86/include/asm/smp.h
18095+++ b/arch/x86/include/asm/smp.h
18096@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18097 /* cpus sharing the last level cache: */
18098 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18099 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18100-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18101+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18102
18103 static inline struct cpumask *cpu_sibling_mask(int cpu)
18104 {
18105@@ -79,7 +79,7 @@ struct smp_ops {
18106
18107 void (*send_call_func_ipi)(const struct cpumask *mask);
18108 void (*send_call_func_single_ipi)(int cpu);
18109-};
18110+} __no_const;
18111
18112 /* Globals due to paravirt */
18113 extern void set_cpu_sibling_map(int cpu);
18114@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18115 extern int safe_smp_processor_id(void);
18116
18117 #elif defined(CONFIG_X86_64_SMP)
18118-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18119-
18120-#define stack_smp_processor_id() \
18121-({ \
18122- struct thread_info *ti; \
18123- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18124- ti->cpu; \
18125-})
18126+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18127+#define stack_smp_processor_id() raw_smp_processor_id()
18128 #define safe_smp_processor_id() smp_processor_id()
18129
18130 #endif
18131diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18132index bf156de..1a782ab 100644
18133--- a/arch/x86/include/asm/spinlock.h
18134+++ b/arch/x86/include/asm/spinlock.h
18135@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18136 static inline void arch_read_lock(arch_rwlock_t *rw)
18137 {
18138 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18139+
18140+#ifdef CONFIG_PAX_REFCOUNT
18141+ "jno 0f\n"
18142+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18143+ "int $4\n0:\n"
18144+ _ASM_EXTABLE(0b, 0b)
18145+#endif
18146+
18147 "jns 1f\n"
18148 "call __read_lock_failed\n\t"
18149 "1:\n"
18150@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18151 static inline void arch_write_lock(arch_rwlock_t *rw)
18152 {
18153 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18154+
18155+#ifdef CONFIG_PAX_REFCOUNT
18156+ "jno 0f\n"
18157+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18158+ "int $4\n0:\n"
18159+ _ASM_EXTABLE(0b, 0b)
18160+#endif
18161+
18162 "jz 1f\n"
18163 "call __write_lock_failed\n\t"
18164 "1:\n"
18165@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18166
18167 static inline void arch_read_unlock(arch_rwlock_t *rw)
18168 {
18169- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18170+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18171+
18172+#ifdef CONFIG_PAX_REFCOUNT
18173+ "jno 0f\n"
18174+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18175+ "int $4\n0:\n"
18176+ _ASM_EXTABLE(0b, 0b)
18177+#endif
18178+
18179 :"+m" (rw->lock) : : "memory");
18180 }
18181
18182 static inline void arch_write_unlock(arch_rwlock_t *rw)
18183 {
18184- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18185+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18186+
18187+#ifdef CONFIG_PAX_REFCOUNT
18188+ "jno 0f\n"
18189+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18190+ "int $4\n0:\n"
18191+ _ASM_EXTABLE(0b, 0b)
18192+#endif
18193+
18194 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18195 }
18196
18197diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18198index 6a99859..03cb807 100644
18199--- a/arch/x86/include/asm/stackprotector.h
18200+++ b/arch/x86/include/asm/stackprotector.h
18201@@ -47,7 +47,7 @@
18202 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18203 */
18204 #define GDT_STACK_CANARY_INIT \
18205- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18206+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18207
18208 /*
18209 * Initialize the stackprotector canary value.
18210@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18211
18212 static inline void load_stack_canary_segment(void)
18213 {
18214-#ifdef CONFIG_X86_32
18215+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18216 asm volatile ("mov %0, %%gs" : : "r" (0));
18217 #endif
18218 }
18219diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18220index 70bbe39..4ae2bd4 100644
18221--- a/arch/x86/include/asm/stacktrace.h
18222+++ b/arch/x86/include/asm/stacktrace.h
18223@@ -11,28 +11,20 @@
18224
18225 extern int kstack_depth_to_print;
18226
18227-struct thread_info;
18228+struct task_struct;
18229 struct stacktrace_ops;
18230
18231-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18232- unsigned long *stack,
18233- unsigned long bp,
18234- const struct stacktrace_ops *ops,
18235- void *data,
18236- unsigned long *end,
18237- int *graph);
18238+typedef unsigned long walk_stack_t(struct task_struct *task,
18239+ void *stack_start,
18240+ unsigned long *stack,
18241+ unsigned long bp,
18242+ const struct stacktrace_ops *ops,
18243+ void *data,
18244+ unsigned long *end,
18245+ int *graph);
18246
18247-extern unsigned long
18248-print_context_stack(struct thread_info *tinfo,
18249- unsigned long *stack, unsigned long bp,
18250- const struct stacktrace_ops *ops, void *data,
18251- unsigned long *end, int *graph);
18252-
18253-extern unsigned long
18254-print_context_stack_bp(struct thread_info *tinfo,
18255- unsigned long *stack, unsigned long bp,
18256- const struct stacktrace_ops *ops, void *data,
18257- unsigned long *end, int *graph);
18258+extern walk_stack_t print_context_stack;
18259+extern walk_stack_t print_context_stack_bp;
18260
18261 /* Generic stack tracer with callbacks */
18262
18263@@ -40,7 +32,7 @@ struct stacktrace_ops {
18264 void (*address)(void *data, unsigned long address, int reliable);
18265 /* On negative return stop dumping */
18266 int (*stack)(void *data, char *name);
18267- walk_stack_t walk_stack;
18268+ walk_stack_t *walk_stack;
18269 };
18270
18271 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18272diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18273index d7f3b3b..3cc39f1 100644
18274--- a/arch/x86/include/asm/switch_to.h
18275+++ b/arch/x86/include/asm/switch_to.h
18276@@ -108,7 +108,7 @@ do { \
18277 "call __switch_to\n\t" \
18278 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18279 __switch_canary \
18280- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18281+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18282 "movq %%rax,%%rdi\n\t" \
18283 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18284 "jnz ret_from_fork\n\t" \
18285@@ -119,7 +119,7 @@ do { \
18286 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18287 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18288 [_tif_fork] "i" (_TIF_FORK), \
18289- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18290+ [thread_info] "m" (current_tinfo), \
18291 [current_task] "m" (current_task) \
18292 __switch_canary_iparam \
18293 : "memory", "cc" __EXTRA_CLOBBER)
18294diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18295index 2781119..618b59b 100644
18296--- a/arch/x86/include/asm/thread_info.h
18297+++ b/arch/x86/include/asm/thread_info.h
18298@@ -10,6 +10,7 @@
18299 #include <linux/compiler.h>
18300 #include <asm/page.h>
18301 #include <asm/types.h>
18302+#include <asm/percpu.h>
18303
18304 /*
18305 * low level task data that entry.S needs immediate access to
18306@@ -23,7 +24,6 @@ struct exec_domain;
18307 #include <linux/atomic.h>
18308
18309 struct thread_info {
18310- struct task_struct *task; /* main task structure */
18311 struct exec_domain *exec_domain; /* execution domain */
18312 __u32 flags; /* low level flags */
18313 __u32 status; /* thread synchronous flags */
18314@@ -33,19 +33,13 @@ struct thread_info {
18315 mm_segment_t addr_limit;
18316 struct restart_block restart_block;
18317 void __user *sysenter_return;
18318-#ifdef CONFIG_X86_32
18319- unsigned long previous_esp; /* ESP of the previous stack in
18320- case of nested (IRQ) stacks
18321- */
18322- __u8 supervisor_stack[0];
18323-#endif
18324+ unsigned long lowest_stack;
18325 unsigned int sig_on_uaccess_error:1;
18326 unsigned int uaccess_err:1; /* uaccess failed */
18327 };
18328
18329-#define INIT_THREAD_INFO(tsk) \
18330+#define INIT_THREAD_INFO \
18331 { \
18332- .task = &tsk, \
18333 .exec_domain = &default_exec_domain, \
18334 .flags = 0, \
18335 .cpu = 0, \
18336@@ -56,7 +50,7 @@ struct thread_info {
18337 }, \
18338 }
18339
18340-#define init_thread_info (init_thread_union.thread_info)
18341+#define init_thread_info (init_thread_union.stack)
18342 #define init_stack (init_thread_union.stack)
18343
18344 #else /* !__ASSEMBLY__ */
18345@@ -96,6 +90,7 @@ struct thread_info {
18346 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18347 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18348 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18349+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18350
18351 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18352 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18353@@ -119,17 +114,18 @@ struct thread_info {
18354 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18355 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18356 #define _TIF_X32 (1 << TIF_X32)
18357+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18358
18359 /* work to do in syscall_trace_enter() */
18360 #define _TIF_WORK_SYSCALL_ENTRY \
18361 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18362 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18363- _TIF_NOHZ)
18364+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18365
18366 /* work to do in syscall_trace_leave() */
18367 #define _TIF_WORK_SYSCALL_EXIT \
18368 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18369- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18370+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18371
18372 /* work to do on interrupt/exception return */
18373 #define _TIF_WORK_MASK \
18374@@ -140,7 +136,7 @@ struct thread_info {
18375 /* work to do on any return to user space */
18376 #define _TIF_ALLWORK_MASK \
18377 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18378- _TIF_NOHZ)
18379+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18380
18381 /* Only used for 64 bit */
18382 #define _TIF_DO_NOTIFY_MASK \
18383@@ -156,45 +152,40 @@ struct thread_info {
18384
18385 #define PREEMPT_ACTIVE 0x10000000
18386
18387-#ifdef CONFIG_X86_32
18388-
18389-#define STACK_WARN (THREAD_SIZE/8)
18390-/*
18391- * macros/functions for gaining access to the thread information structure
18392- *
18393- * preempt_count needs to be 1 initially, until the scheduler is functional.
18394- */
18395-#ifndef __ASSEMBLY__
18396-
18397-
18398-/* how to get the current stack pointer from C */
18399-register unsigned long current_stack_pointer asm("esp") __used;
18400-
18401-/* how to get the thread information struct from C */
18402-static inline struct thread_info *current_thread_info(void)
18403-{
18404- return (struct thread_info *)
18405- (current_stack_pointer & ~(THREAD_SIZE - 1));
18406-}
18407-
18408-#else /* !__ASSEMBLY__ */
18409-
18410+#ifdef __ASSEMBLY__
18411 /* how to get the thread information struct from ASM */
18412 #define GET_THREAD_INFO(reg) \
18413- movl $-THREAD_SIZE, reg; \
18414- andl %esp, reg
18415+ mov PER_CPU_VAR(current_tinfo), reg
18416
18417 /* use this one if reg already contains %esp */
18418-#define GET_THREAD_INFO_WITH_ESP(reg) \
18419- andl $-THREAD_SIZE, reg
18420+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18421+#else
18422+/* how to get the thread information struct from C */
18423+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18424+
18425+static __always_inline struct thread_info *current_thread_info(void)
18426+{
18427+ return this_cpu_read_stable(current_tinfo);
18428+}
18429+#endif
18430+
18431+#ifdef CONFIG_X86_32
18432+
18433+#define STACK_WARN (THREAD_SIZE/8)
18434+/*
18435+ * macros/functions for gaining access to the thread information structure
18436+ *
18437+ * preempt_count needs to be 1 initially, until the scheduler is functional.
18438+ */
18439+#ifndef __ASSEMBLY__
18440+
18441+/* how to get the current stack pointer from C */
18442+register unsigned long current_stack_pointer asm("esp") __used;
18443
18444 #endif
18445
18446 #else /* X86_32 */
18447
18448-#include <asm/percpu.h>
18449-#define KERNEL_STACK_OFFSET (5*8)
18450-
18451 /*
18452 * macros/functions for gaining access to the thread information structure
18453 * preempt_count needs to be 1 initially, until the scheduler is functional.
18454@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
18455 #ifndef __ASSEMBLY__
18456 DECLARE_PER_CPU(unsigned long, kernel_stack);
18457
18458-static inline struct thread_info *current_thread_info(void)
18459-{
18460- struct thread_info *ti;
18461- ti = (void *)(this_cpu_read_stable(kernel_stack) +
18462- KERNEL_STACK_OFFSET - THREAD_SIZE);
18463- return ti;
18464-}
18465-
18466-#else /* !__ASSEMBLY__ */
18467-
18468-/* how to get the thread information struct from ASM */
18469-#define GET_THREAD_INFO(reg) \
18470- movq PER_CPU_VAR(kernel_stack),reg ; \
18471- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18472-
18473-/*
18474- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18475- * a certain register (to be used in assembler memory operands).
18476- */
18477-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18478-
18479+/* how to get the current stack pointer from C */
18480+register unsigned long current_stack_pointer asm("rsp") __used;
18481 #endif
18482
18483 #endif /* !X86_32 */
18484@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
18485 extern void arch_task_cache_init(void);
18486 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18487 extern void arch_release_task_struct(struct task_struct *tsk);
18488+
18489+#define __HAVE_THREAD_FUNCTIONS
18490+#define task_thread_info(task) (&(task)->tinfo)
18491+#define task_stack_page(task) ((task)->stack)
18492+#define setup_thread_stack(p, org) do {} while (0)
18493+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18494+
18495 #endif
18496 #endif /* _ASM_X86_THREAD_INFO_H */
18497diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18498index e6d90ba..0897f44 100644
18499--- a/arch/x86/include/asm/tlbflush.h
18500+++ b/arch/x86/include/asm/tlbflush.h
18501@@ -17,18 +17,44 @@
18502
18503 static inline void __native_flush_tlb(void)
18504 {
18505+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18506+ u64 descriptor[2];
18507+
18508+ descriptor[0] = PCID_KERNEL;
18509+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18510+ return;
18511+ }
18512+
18513+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18514+ if (static_cpu_has(X86_FEATURE_PCID)) {
18515+ unsigned int cpu = raw_get_cpu();
18516+
18517+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18518+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18519+ raw_put_cpu_no_resched();
18520+ return;
18521+ }
18522+#endif
18523+
18524 native_write_cr3(native_read_cr3());
18525 }
18526
18527 static inline void __native_flush_tlb_global_irq_disabled(void)
18528 {
18529- unsigned long cr4;
18530+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18531+ u64 descriptor[2];
18532
18533- cr4 = native_read_cr4();
18534- /* clear PGE */
18535- native_write_cr4(cr4 & ~X86_CR4_PGE);
18536- /* write old PGE again and flush TLBs */
18537- native_write_cr4(cr4);
18538+ descriptor[0] = PCID_KERNEL;
18539+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18540+ } else {
18541+ unsigned long cr4;
18542+
18543+ cr4 = native_read_cr4();
18544+ /* clear PGE */
18545+ native_write_cr4(cr4 & ~X86_CR4_PGE);
18546+ /* write old PGE again and flush TLBs */
18547+ native_write_cr4(cr4);
18548+ }
18549 }
18550
18551 static inline void __native_flush_tlb_global(void)
18552@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
18553
18554 static inline void __native_flush_tlb_single(unsigned long addr)
18555 {
18556+
18557+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18558+ u64 descriptor[2];
18559+
18560+ descriptor[0] = PCID_KERNEL;
18561+ descriptor[1] = addr;
18562+
18563+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18564+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18565+ if (addr < TASK_SIZE_MAX)
18566+ descriptor[1] += pax_user_shadow_base;
18567+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18568+ }
18569+
18570+ descriptor[0] = PCID_USER;
18571+ descriptor[1] = addr;
18572+#endif
18573+
18574+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18575+ return;
18576+ }
18577+
18578+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18579+ if (static_cpu_has(X86_FEATURE_PCID)) {
18580+ unsigned int cpu = raw_get_cpu();
18581+
18582+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18583+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18584+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18585+ raw_put_cpu_no_resched();
18586+
18587+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18588+ addr += pax_user_shadow_base;
18589+ }
18590+#endif
18591+
18592 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18593 }
18594
18595diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18596index 5838fa9..f7ae572 100644
18597--- a/arch/x86/include/asm/uaccess.h
18598+++ b/arch/x86/include/asm/uaccess.h
18599@@ -7,6 +7,7 @@
18600 #include <linux/compiler.h>
18601 #include <linux/thread_info.h>
18602 #include <linux/string.h>
18603+#include <linux/sched.h>
18604 #include <asm/asm.h>
18605 #include <asm/page.h>
18606 #include <asm/smap.h>
18607@@ -29,7 +30,12 @@
18608
18609 #define get_ds() (KERNEL_DS)
18610 #define get_fs() (current_thread_info()->addr_limit)
18611+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18612+void __set_fs(mm_segment_t x);
18613+void set_fs(mm_segment_t x);
18614+#else
18615 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18616+#endif
18617
18618 #define segment_eq(a, b) ((a).seg == (b).seg)
18619
18620@@ -77,8 +83,33 @@
18621 * checks that the pointer is in the user space range - after calling
18622 * this function, memory access functions may still return -EFAULT.
18623 */
18624-#define access_ok(type, addr, size) \
18625- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18626+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18627+#define access_ok(type, addr, size) \
18628+({ \
18629+ long __size = size; \
18630+ unsigned long __addr = (unsigned long)addr; \
18631+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18632+ unsigned long __end_ao = __addr + __size - 1; \
18633+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18634+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18635+ while(__addr_ao <= __end_ao) { \
18636+ char __c_ao; \
18637+ __addr_ao += PAGE_SIZE; \
18638+ if (__size > PAGE_SIZE) \
18639+ cond_resched(); \
18640+ if (__get_user(__c_ao, (char __user *)__addr)) \
18641+ break; \
18642+ if (type != VERIFY_WRITE) { \
18643+ __addr = __addr_ao; \
18644+ continue; \
18645+ } \
18646+ if (__put_user(__c_ao, (char __user *)__addr)) \
18647+ break; \
18648+ __addr = __addr_ao; \
18649+ } \
18650+ } \
18651+ __ret_ao; \
18652+})
18653
18654 /*
18655 * The exception table consists of pairs of addresses relative to the
18656@@ -168,10 +199,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18657 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18658 __chk_user_ptr(ptr); \
18659 might_fault(); \
18660+ pax_open_userland(); \
18661 asm volatile("call __get_user_%P3" \
18662 : "=a" (__ret_gu), "=r" (__val_gu) \
18663 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18664 (x) = (__typeof__(*(ptr))) __val_gu; \
18665+ pax_close_userland(); \
18666 __ret_gu; \
18667 })
18668
18669@@ -179,13 +212,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18670 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18671 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18672
18673-
18674+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18675+#define __copyuser_seg "gs;"
18676+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18677+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18678+#else
18679+#define __copyuser_seg
18680+#define __COPYUSER_SET_ES
18681+#define __COPYUSER_RESTORE_ES
18682+#endif
18683
18684 #ifdef CONFIG_X86_32
18685 #define __put_user_asm_u64(x, addr, err, errret) \
18686 asm volatile(ASM_STAC "\n" \
18687- "1: movl %%eax,0(%2)\n" \
18688- "2: movl %%edx,4(%2)\n" \
18689+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18690+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18691 "3: " ASM_CLAC "\n" \
18692 ".section .fixup,\"ax\"\n" \
18693 "4: movl %3,%0\n" \
18694@@ -198,8 +239,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18695
18696 #define __put_user_asm_ex_u64(x, addr) \
18697 asm volatile(ASM_STAC "\n" \
18698- "1: movl %%eax,0(%1)\n" \
18699- "2: movl %%edx,4(%1)\n" \
18700+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18701+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18702 "3: " ASM_CLAC "\n" \
18703 _ASM_EXTABLE_EX(1b, 2b) \
18704 _ASM_EXTABLE_EX(2b, 3b) \
18705@@ -249,7 +290,8 @@ extern void __put_user_8(void);
18706 __typeof__(*(ptr)) __pu_val; \
18707 __chk_user_ptr(ptr); \
18708 might_fault(); \
18709- __pu_val = x; \
18710+ __pu_val = (x); \
18711+ pax_open_userland(); \
18712 switch (sizeof(*(ptr))) { \
18713 case 1: \
18714 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18715@@ -267,6 +309,7 @@ extern void __put_user_8(void);
18716 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18717 break; \
18718 } \
18719+ pax_close_userland(); \
18720 __ret_pu; \
18721 })
18722
18723@@ -347,8 +390,10 @@ do { \
18724 } while (0)
18725
18726 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18727+do { \
18728+ pax_open_userland(); \
18729 asm volatile(ASM_STAC "\n" \
18730- "1: mov"itype" %2,%"rtype"1\n" \
18731+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18732 "2: " ASM_CLAC "\n" \
18733 ".section .fixup,\"ax\"\n" \
18734 "3: mov %3,%0\n" \
18735@@ -356,8 +401,10 @@ do { \
18736 " jmp 2b\n" \
18737 ".previous\n" \
18738 _ASM_EXTABLE(1b, 3b) \
18739- : "=r" (err), ltype(x) \
18740- : "m" (__m(addr)), "i" (errret), "0" (err))
18741+ : "=r" (err), ltype (x) \
18742+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18743+ pax_close_userland(); \
18744+} while (0)
18745
18746 #define __get_user_size_ex(x, ptr, size) \
18747 do { \
18748@@ -381,7 +428,7 @@ do { \
18749 } while (0)
18750
18751 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18752- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18753+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18754 "2:\n" \
18755 _ASM_EXTABLE_EX(1b, 2b) \
18756 : ltype(x) : "m" (__m(addr)))
18757@@ -398,13 +445,24 @@ do { \
18758 int __gu_err; \
18759 unsigned long __gu_val; \
18760 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18761- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18762+ (x) = (__typeof__(*(ptr)))__gu_val; \
18763 __gu_err; \
18764 })
18765
18766 /* FIXME: this hack is definitely wrong -AK */
18767 struct __large_struct { unsigned long buf[100]; };
18768-#define __m(x) (*(struct __large_struct __user *)(x))
18769+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18770+#define ____m(x) \
18771+({ \
18772+ unsigned long ____x = (unsigned long)(x); \
18773+ if (____x < pax_user_shadow_base) \
18774+ ____x += pax_user_shadow_base; \
18775+ (typeof(x))____x; \
18776+})
18777+#else
18778+#define ____m(x) (x)
18779+#endif
18780+#define __m(x) (*(struct __large_struct __user *)____m(x))
18781
18782 /*
18783 * Tell gcc we read from memory instead of writing: this is because
18784@@ -412,8 +470,10 @@ struct __large_struct { unsigned long buf[100]; };
18785 * aliasing issues.
18786 */
18787 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18788+do { \
18789+ pax_open_userland(); \
18790 asm volatile(ASM_STAC "\n" \
18791- "1: mov"itype" %"rtype"1,%2\n" \
18792+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18793 "2: " ASM_CLAC "\n" \
18794 ".section .fixup,\"ax\"\n" \
18795 "3: mov %3,%0\n" \
18796@@ -421,10 +481,12 @@ struct __large_struct { unsigned long buf[100]; };
18797 ".previous\n" \
18798 _ASM_EXTABLE(1b, 3b) \
18799 : "=r"(err) \
18800- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18801+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18802+ pax_close_userland(); \
18803+} while (0)
18804
18805 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18806- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18807+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18808 "2:\n" \
18809 _ASM_EXTABLE_EX(1b, 2b) \
18810 : : ltype(x), "m" (__m(addr)))
18811@@ -434,11 +496,13 @@ struct __large_struct { unsigned long buf[100]; };
18812 */
18813 #define uaccess_try do { \
18814 current_thread_info()->uaccess_err = 0; \
18815+ pax_open_userland(); \
18816 stac(); \
18817 barrier();
18818
18819 #define uaccess_catch(err) \
18820 clac(); \
18821+ pax_close_userland(); \
18822 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18823 } while (0)
18824
18825@@ -463,8 +527,12 @@ struct __large_struct { unsigned long buf[100]; };
18826 * On error, the variable @x is set to zero.
18827 */
18828
18829+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18830+#define __get_user(x, ptr) get_user((x), (ptr))
18831+#else
18832 #define __get_user(x, ptr) \
18833 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18834+#endif
18835
18836 /**
18837 * __put_user: - Write a simple value into user space, with less checking.
18838@@ -486,8 +554,12 @@ struct __large_struct { unsigned long buf[100]; };
18839 * Returns zero on success, or -EFAULT on error.
18840 */
18841
18842+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18843+#define __put_user(x, ptr) put_user((x), (ptr))
18844+#else
18845 #define __put_user(x, ptr) \
18846 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18847+#endif
18848
18849 #define __get_user_unaligned __get_user
18850 #define __put_user_unaligned __put_user
18851@@ -505,7 +577,7 @@ struct __large_struct { unsigned long buf[100]; };
18852 #define get_user_ex(x, ptr) do { \
18853 unsigned long __gue_val; \
18854 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18855- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18856+ (x) = (__typeof__(*(ptr)))__gue_val; \
18857 } while (0)
18858
18859 #define put_user_try uaccess_try
18860diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18861index 7f760a9..b596b9a 100644
18862--- a/arch/x86/include/asm/uaccess_32.h
18863+++ b/arch/x86/include/asm/uaccess_32.h
18864@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18865 static __always_inline unsigned long __must_check
18866 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18867 {
18868+ if ((long)n < 0)
18869+ return n;
18870+
18871+ check_object_size(from, n, true);
18872+
18873 if (__builtin_constant_p(n)) {
18874 unsigned long ret;
18875
18876@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18877 __copy_to_user(void __user *to, const void *from, unsigned long n)
18878 {
18879 might_fault();
18880+
18881 return __copy_to_user_inatomic(to, from, n);
18882 }
18883
18884 static __always_inline unsigned long
18885 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18886 {
18887+ if ((long)n < 0)
18888+ return n;
18889+
18890 /* Avoid zeroing the tail if the copy fails..
18891 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18892 * but as the zeroing behaviour is only significant when n is not
18893@@ -137,6 +146,12 @@ static __always_inline unsigned long
18894 __copy_from_user(void *to, const void __user *from, unsigned long n)
18895 {
18896 might_fault();
18897+
18898+ if ((long)n < 0)
18899+ return n;
18900+
18901+ check_object_size(to, n, false);
18902+
18903 if (__builtin_constant_p(n)) {
18904 unsigned long ret;
18905
18906@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18907 const void __user *from, unsigned long n)
18908 {
18909 might_fault();
18910+
18911+ if ((long)n < 0)
18912+ return n;
18913+
18914 if (__builtin_constant_p(n)) {
18915 unsigned long ret;
18916
18917@@ -181,15 +200,19 @@ static __always_inline unsigned long
18918 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18919 unsigned long n)
18920 {
18921- return __copy_from_user_ll_nocache_nozero(to, from, n);
18922+ if ((long)n < 0)
18923+ return n;
18924+
18925+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18926 }
18927
18928-unsigned long __must_check copy_to_user(void __user *to,
18929- const void *from, unsigned long n);
18930-unsigned long __must_check _copy_from_user(void *to,
18931- const void __user *from,
18932- unsigned long n);
18933-
18934+extern void copy_to_user_overflow(void)
18935+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18936+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18937+#else
18938+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18939+#endif
18940+;
18941
18942 extern void copy_from_user_overflow(void)
18943 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18944@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18945 #endif
18946 ;
18947
18948-static inline unsigned long __must_check copy_from_user(void *to,
18949- const void __user *from,
18950- unsigned long n)
18951+/**
18952+ * copy_to_user: - Copy a block of data into user space.
18953+ * @to: Destination address, in user space.
18954+ * @from: Source address, in kernel space.
18955+ * @n: Number of bytes to copy.
18956+ *
18957+ * Context: User context only. This function may sleep.
18958+ *
18959+ * Copy data from kernel space to user space.
18960+ *
18961+ * Returns number of bytes that could not be copied.
18962+ * On success, this will be zero.
18963+ */
18964+static inline unsigned long __must_check
18965+copy_to_user(void __user *to, const void *from, unsigned long n)
18966 {
18967- int sz = __compiletime_object_size(to);
18968+ size_t sz = __compiletime_object_size(from);
18969
18970- if (likely(sz == -1 || sz >= n))
18971- n = _copy_from_user(to, from, n);
18972- else
18973+ if (unlikely(sz != (size_t)-1 && sz < n))
18974+ copy_to_user_overflow();
18975+ else if (access_ok(VERIFY_WRITE, to, n))
18976+ n = __copy_to_user(to, from, n);
18977+ return n;
18978+}
18979+
18980+/**
18981+ * copy_from_user: - Copy a block of data from user space.
18982+ * @to: Destination address, in kernel space.
18983+ * @from: Source address, in user space.
18984+ * @n: Number of bytes to copy.
18985+ *
18986+ * Context: User context only. This function may sleep.
18987+ *
18988+ * Copy data from user space to kernel space.
18989+ *
18990+ * Returns number of bytes that could not be copied.
18991+ * On success, this will be zero.
18992+ *
18993+ * If some data could not be copied, this function will pad the copied
18994+ * data to the requested size using zero bytes.
18995+ */
18996+static inline unsigned long __must_check
18997+copy_from_user(void *to, const void __user *from, unsigned long n)
18998+{
18999+ size_t sz = __compiletime_object_size(to);
19000+
19001+ check_object_size(to, n, false);
19002+
19003+ if (unlikely(sz != (size_t)-1 && sz < n))
19004 copy_from_user_overflow();
19005-
19006+ else if (access_ok(VERIFY_READ, from, n))
19007+ n = __copy_from_user(to, from, n);
19008+ else if ((long)n > 0)
19009+ memset(to, 0, n);
19010 return n;
19011 }
19012
19013diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19014index 4f7923d..201b58d 100644
19015--- a/arch/x86/include/asm/uaccess_64.h
19016+++ b/arch/x86/include/asm/uaccess_64.h
19017@@ -10,6 +10,9 @@
19018 #include <asm/alternative.h>
19019 #include <asm/cpufeature.h>
19020 #include <asm/page.h>
19021+#include <asm/pgtable.h>
19022+
19023+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19024
19025 /*
19026 * Copy To/From Userspace
19027@@ -17,14 +20,14 @@
19028
19029 /* Handles exceptions in both to and from, but doesn't do access_ok */
19030 __must_check unsigned long
19031-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19032+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19033 __must_check unsigned long
19034-copy_user_generic_string(void *to, const void *from, unsigned len);
19035+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19036 __must_check unsigned long
19037-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19038+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19039
19040-static __always_inline __must_check unsigned long
19041-copy_user_generic(void *to, const void *from, unsigned len)
19042+static __always_inline __must_check unsigned long
19043+copy_user_generic(void *to, const void *from, unsigned long len)
19044 {
19045 unsigned ret;
19046
19047@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
19048 return ret;
19049 }
19050
19051+static __always_inline __must_check unsigned long
19052+__copy_to_user(void __user *to, const void *from, unsigned long len);
19053+static __always_inline __must_check unsigned long
19054+__copy_from_user(void *to, const void __user *from, unsigned long len);
19055 __must_check unsigned long
19056-_copy_to_user(void __user *to, const void *from, unsigned len);
19057-__must_check unsigned long
19058-_copy_from_user(void *to, const void __user *from, unsigned len);
19059-__must_check unsigned long
19060-copy_in_user(void __user *to, const void __user *from, unsigned len);
19061+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19062+
19063+extern void copy_to_user_overflow(void)
19064+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19065+ __compiletime_error("copy_to_user() buffer size is not provably correct")
19066+#else
19067+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
19068+#endif
19069+;
19070+
19071+extern void copy_from_user_overflow(void)
19072+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19073+ __compiletime_error("copy_from_user() buffer size is not provably correct")
19074+#else
19075+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
19076+#endif
19077+;
19078
19079 static inline unsigned long __must_check copy_from_user(void *to,
19080 const void __user *from,
19081 unsigned long n)
19082 {
19083- int sz = __compiletime_object_size(to);
19084-
19085 might_fault();
19086- if (likely(sz == -1 || sz >= n))
19087- n = _copy_from_user(to, from, n);
19088-#ifdef CONFIG_DEBUG_VM
19089- else
19090- WARN(1, "Buffer overflow detected!\n");
19091-#endif
19092+
19093+ check_object_size(to, n, false);
19094+
19095+ if (access_ok(VERIFY_READ, from, n))
19096+ n = __copy_from_user(to, from, n);
19097+ else if (n < INT_MAX)
19098+ memset(to, 0, n);
19099 return n;
19100 }
19101
19102 static __always_inline __must_check
19103-int copy_to_user(void __user *dst, const void *src, unsigned size)
19104+int copy_to_user(void __user *dst, const void *src, unsigned long size)
19105 {
19106 might_fault();
19107
19108- return _copy_to_user(dst, src, size);
19109+ if (access_ok(VERIFY_WRITE, dst, size))
19110+ size = __copy_to_user(dst, src, size);
19111+ return size;
19112 }
19113
19114 static __always_inline __must_check
19115-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19116+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19117 {
19118- int ret = 0;
19119+ size_t sz = __compiletime_object_size(dst);
19120+ unsigned ret = 0;
19121
19122 might_fault();
19123+
19124+ if (size > INT_MAX)
19125+ return size;
19126+
19127+ check_object_size(dst, size, false);
19128+
19129+#ifdef CONFIG_PAX_MEMORY_UDEREF
19130+ if (!__access_ok(VERIFY_READ, src, size))
19131+ return size;
19132+#endif
19133+
19134+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19135+ copy_from_user_overflow();
19136+ return size;
19137+ }
19138+
19139 if (!__builtin_constant_p(size))
19140- return copy_user_generic(dst, (__force void *)src, size);
19141+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19142 switch (size) {
19143- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19144+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19145 ret, "b", "b", "=q", 1);
19146 return ret;
19147- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19148+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19149 ret, "w", "w", "=r", 2);
19150 return ret;
19151- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19152+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19153 ret, "l", "k", "=r", 4);
19154 return ret;
19155- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19156+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19157 ret, "q", "", "=r", 8);
19158 return ret;
19159 case 10:
19160- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19161+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19162 ret, "q", "", "=r", 10);
19163 if (unlikely(ret))
19164 return ret;
19165 __get_user_asm(*(u16 *)(8 + (char *)dst),
19166- (u16 __user *)(8 + (char __user *)src),
19167+ (const u16 __user *)(8 + (const char __user *)src),
19168 ret, "w", "w", "=r", 2);
19169 return ret;
19170 case 16:
19171- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19172+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19173 ret, "q", "", "=r", 16);
19174 if (unlikely(ret))
19175 return ret;
19176 __get_user_asm(*(u64 *)(8 + (char *)dst),
19177- (u64 __user *)(8 + (char __user *)src),
19178+ (const u64 __user *)(8 + (const char __user *)src),
19179 ret, "q", "", "=r", 8);
19180 return ret;
19181 default:
19182- return copy_user_generic(dst, (__force void *)src, size);
19183+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19184 }
19185 }
19186
19187 static __always_inline __must_check
19188-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19189+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19190 {
19191- int ret = 0;
19192+ size_t sz = __compiletime_object_size(src);
19193+ unsigned ret = 0;
19194
19195 might_fault();
19196+
19197+ if (size > INT_MAX)
19198+ return size;
19199+
19200+ check_object_size(src, size, true);
19201+
19202+#ifdef CONFIG_PAX_MEMORY_UDEREF
19203+ if (!__access_ok(VERIFY_WRITE, dst, size))
19204+ return size;
19205+#endif
19206+
19207+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19208+ copy_to_user_overflow();
19209+ return size;
19210+ }
19211+
19212 if (!__builtin_constant_p(size))
19213- return copy_user_generic((__force void *)dst, src, size);
19214+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19215 switch (size) {
19216- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19217+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19218 ret, "b", "b", "iq", 1);
19219 return ret;
19220- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19221+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19222 ret, "w", "w", "ir", 2);
19223 return ret;
19224- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19225+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19226 ret, "l", "k", "ir", 4);
19227 return ret;
19228- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19229+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19230 ret, "q", "", "er", 8);
19231 return ret;
19232 case 10:
19233- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19234+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19235 ret, "q", "", "er", 10);
19236 if (unlikely(ret))
19237 return ret;
19238 asm("":::"memory");
19239- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19240+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19241 ret, "w", "w", "ir", 2);
19242 return ret;
19243 case 16:
19244- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19245+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19246 ret, "q", "", "er", 16);
19247 if (unlikely(ret))
19248 return ret;
19249 asm("":::"memory");
19250- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19251+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19252 ret, "q", "", "er", 8);
19253 return ret;
19254 default:
19255- return copy_user_generic((__force void *)dst, src, size);
19256+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19257 }
19258 }
19259
19260 static __always_inline __must_check
19261-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19262+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
19263 {
19264- int ret = 0;
19265+ unsigned ret = 0;
19266
19267 might_fault();
19268+
19269+ if (size > INT_MAX)
19270+ return size;
19271+
19272+#ifdef CONFIG_PAX_MEMORY_UDEREF
19273+ if (!__access_ok(VERIFY_READ, src, size))
19274+ return size;
19275+ if (!__access_ok(VERIFY_WRITE, dst, size))
19276+ return size;
19277+#endif
19278+
19279 if (!__builtin_constant_p(size))
19280- return copy_user_generic((__force void *)dst,
19281- (__force void *)src, size);
19282+ return copy_user_generic((__force_kernel void *)____m(dst),
19283+ (__force_kernel const void *)____m(src), size);
19284 switch (size) {
19285 case 1: {
19286 u8 tmp;
19287- __get_user_asm(tmp, (u8 __user *)src,
19288+ __get_user_asm(tmp, (const u8 __user *)src,
19289 ret, "b", "b", "=q", 1);
19290 if (likely(!ret))
19291 __put_user_asm(tmp, (u8 __user *)dst,
19292@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19293 }
19294 case 2: {
19295 u16 tmp;
19296- __get_user_asm(tmp, (u16 __user *)src,
19297+ __get_user_asm(tmp, (const u16 __user *)src,
19298 ret, "w", "w", "=r", 2);
19299 if (likely(!ret))
19300 __put_user_asm(tmp, (u16 __user *)dst,
19301@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19302
19303 case 4: {
19304 u32 tmp;
19305- __get_user_asm(tmp, (u32 __user *)src,
19306+ __get_user_asm(tmp, (const u32 __user *)src,
19307 ret, "l", "k", "=r", 4);
19308 if (likely(!ret))
19309 __put_user_asm(tmp, (u32 __user *)dst,
19310@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19311 }
19312 case 8: {
19313 u64 tmp;
19314- __get_user_asm(tmp, (u64 __user *)src,
19315+ __get_user_asm(tmp, (const u64 __user *)src,
19316 ret, "q", "", "=r", 8);
19317 if (likely(!ret))
19318 __put_user_asm(tmp, (u64 __user *)dst,
19319@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19320 return ret;
19321 }
19322 default:
19323- return copy_user_generic((__force void *)dst,
19324- (__force void *)src, size);
19325+ return copy_user_generic((__force_kernel void *)____m(dst),
19326+ (__force_kernel const void *)____m(src), size);
19327 }
19328 }
19329
19330-static __must_check __always_inline int
19331-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19332+static __must_check __always_inline unsigned long
19333+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19334 {
19335- return copy_user_generic(dst, (__force const void *)src, size);
19336+ if (size > INT_MAX)
19337+ return size;
19338+
19339+#ifdef CONFIG_PAX_MEMORY_UDEREF
19340+ if (!__access_ok(VERIFY_READ, src, size))
19341+ return size;
19342+#endif
19343+
19344+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19345 }
19346
19347-static __must_check __always_inline int
19348-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19349+static __must_check __always_inline unsigned long
19350+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19351 {
19352- return copy_user_generic((__force void *)dst, src, size);
19353+ if (size > INT_MAX)
19354+ return size;
19355+
19356+#ifdef CONFIG_PAX_MEMORY_UDEREF
19357+ if (!__access_ok(VERIFY_WRITE, dst, size))
19358+ return size;
19359+#endif
19360+
19361+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19362 }
19363
19364-extern long __copy_user_nocache(void *dst, const void __user *src,
19365- unsigned size, int zerorest);
19366+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19367+ unsigned long size, int zerorest);
19368
19369-static inline int
19370-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19371+static inline unsigned long
19372+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19373 {
19374 might_fault();
19375+
19376+ if (size > INT_MAX)
19377+ return size;
19378+
19379+#ifdef CONFIG_PAX_MEMORY_UDEREF
19380+ if (!__access_ok(VERIFY_READ, src, size))
19381+ return size;
19382+#endif
19383+
19384 return __copy_user_nocache(dst, src, size, 1);
19385 }
19386
19387-static inline int
19388+static inline unsigned long
19389 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19390- unsigned size)
19391+ unsigned long size)
19392 {
19393+ if (size > INT_MAX)
19394+ return size;
19395+
19396+#ifdef CONFIG_PAX_MEMORY_UDEREF
19397+ if (!__access_ok(VERIFY_READ, src, size))
19398+ return size;
19399+#endif
19400+
19401 return __copy_user_nocache(dst, src, size, 0);
19402 }
19403
19404 unsigned long
19405-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19406+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19407
19408 #endif /* _ASM_X86_UACCESS_64_H */
19409diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19410index 5b238981..77fdd78 100644
19411--- a/arch/x86/include/asm/word-at-a-time.h
19412+++ b/arch/x86/include/asm/word-at-a-time.h
19413@@ -11,7 +11,7 @@
19414 * and shift, for example.
19415 */
19416 struct word_at_a_time {
19417- const unsigned long one_bits, high_bits;
19418+ unsigned long one_bits, high_bits;
19419 };
19420
19421 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19422diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19423index 828a156..650e625 100644
19424--- a/arch/x86/include/asm/x86_init.h
19425+++ b/arch/x86/include/asm/x86_init.h
19426@@ -129,7 +129,7 @@ struct x86_init_ops {
19427 struct x86_init_timers timers;
19428 struct x86_init_iommu iommu;
19429 struct x86_init_pci pci;
19430-};
19431+} __no_const;
19432
19433 /**
19434 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19435@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19436 void (*setup_percpu_clockev)(void);
19437 void (*early_percpu_clock_init)(void);
19438 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19439-};
19440+} __no_const;
19441
19442 struct timespec;
19443
19444@@ -168,7 +168,7 @@ struct x86_platform_ops {
19445 void (*save_sched_clock_state)(void);
19446 void (*restore_sched_clock_state)(void);
19447 void (*apic_post_init)(void);
19448-};
19449+} __no_const;
19450
19451 struct pci_dev;
19452 struct msi_msg;
19453@@ -182,7 +182,7 @@ struct x86_msi_ops {
19454 void (*teardown_msi_irqs)(struct pci_dev *dev);
19455 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
19456 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19457-};
19458+} __no_const;
19459
19460 struct IO_APIC_route_entry;
19461 struct io_apic_irq_attr;
19462@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
19463 unsigned int destination, int vector,
19464 struct io_apic_irq_attr *attr);
19465 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19466-};
19467+} __no_const;
19468
19469 extern struct x86_init_ops x86_init;
19470 extern struct x86_cpuinit_ops x86_cpuinit;
19471diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19472index b913915..4f5a581 100644
19473--- a/arch/x86/include/asm/xen/page.h
19474+++ b/arch/x86/include/asm/xen/page.h
19475@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19476 extern struct page *m2p_find_override(unsigned long mfn);
19477 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19478
19479-static inline unsigned long pfn_to_mfn(unsigned long pfn)
19480+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19481 {
19482 unsigned long mfn;
19483
19484diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19485index 0415cda..3b22adc 100644
19486--- a/arch/x86/include/asm/xsave.h
19487+++ b/arch/x86/include/asm/xsave.h
19488@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19489 if (unlikely(err))
19490 return -EFAULT;
19491
19492+ pax_open_userland();
19493 __asm__ __volatile__(ASM_STAC "\n"
19494- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19495+ "1:"
19496+ __copyuser_seg
19497+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19498 "2: " ASM_CLAC "\n"
19499 ".section .fixup,\"ax\"\n"
19500 "3: movl $-1,%[err]\n"
19501@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19502 : [err] "=r" (err)
19503 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19504 : "memory");
19505+ pax_close_userland();
19506 return err;
19507 }
19508
19509 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19510 {
19511 int err;
19512- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19513+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19514 u32 lmask = mask;
19515 u32 hmask = mask >> 32;
19516
19517+ pax_open_userland();
19518 __asm__ __volatile__(ASM_STAC "\n"
19519- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19520+ "1:"
19521+ __copyuser_seg
19522+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19523 "2: " ASM_CLAC "\n"
19524 ".section .fixup,\"ax\"\n"
19525 "3: movl $-1,%[err]\n"
19526@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19527 : [err] "=r" (err)
19528 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19529 : "memory"); /* memory required? */
19530+ pax_close_userland();
19531 return err;
19532 }
19533
19534diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19535index bbae024..e1528f9 100644
19536--- a/arch/x86/include/uapi/asm/e820.h
19537+++ b/arch/x86/include/uapi/asm/e820.h
19538@@ -63,7 +63,7 @@ struct e820map {
19539 #define ISA_START_ADDRESS 0xa0000
19540 #define ISA_END_ADDRESS 0x100000
19541
19542-#define BIOS_BEGIN 0x000a0000
19543+#define BIOS_BEGIN 0x000c0000
19544 #define BIOS_END 0x00100000
19545
19546 #define BIOS_ROM_BASE 0xffe00000
19547diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19548index 7b0a55a..ad115bf 100644
19549--- a/arch/x86/include/uapi/asm/ptrace-abi.h
19550+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19551@@ -49,7 +49,6 @@
19552 #define EFLAGS 144
19553 #define RSP 152
19554 #define SS 160
19555-#define ARGOFFSET R11
19556 #endif /* __ASSEMBLY__ */
19557
19558 /* top of stack page */
19559diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19560index a5408b9..5133813 100644
19561--- a/arch/x86/kernel/Makefile
19562+++ b/arch/x86/kernel/Makefile
19563@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19564 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19565 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19566 obj-y += probe_roms.o
19567-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19568+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19569 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19570 obj-y += syscall_$(BITS).o
19571 obj-$(CONFIG_X86_64) += vsyscall_64.o
19572diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19573index 40c7660..f709f4b 100644
19574--- a/arch/x86/kernel/acpi/boot.c
19575+++ b/arch/x86/kernel/acpi/boot.c
19576@@ -1365,7 +1365,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19577 * If your system is blacklisted here, but you find that acpi=force
19578 * works for you, please contact linux-acpi@vger.kernel.org
19579 */
19580-static struct dmi_system_id __initdata acpi_dmi_table[] = {
19581+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19582 /*
19583 * Boxes that need ACPI disabled
19584 */
19585@@ -1440,7 +1440,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19586 };
19587
19588 /* second table for DMI checks that should run after early-quirks */
19589-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19590+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19591 /*
19592 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19593 * which includes some code which overrides all temperature
19594diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19595index 3312010..a65ca7b 100644
19596--- a/arch/x86/kernel/acpi/sleep.c
19597+++ b/arch/x86/kernel/acpi/sleep.c
19598@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
19599 #else /* CONFIG_64BIT */
19600 #ifdef CONFIG_SMP
19601 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19602+
19603+ pax_open_kernel();
19604 early_gdt_descr.address =
19605 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19606+ pax_close_kernel();
19607+
19608 initial_gs = per_cpu_offset(smp_processor_id());
19609 #endif
19610 initial_code = (unsigned long)wakeup_long64;
19611diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19612index d1daa66..59fecba 100644
19613--- a/arch/x86/kernel/acpi/wakeup_32.S
19614+++ b/arch/x86/kernel/acpi/wakeup_32.S
19615@@ -29,13 +29,11 @@ wakeup_pmode_return:
19616 # and restore the stack ... but you need gdt for this to work
19617 movl saved_context_esp, %esp
19618
19619- movl %cs:saved_magic, %eax
19620- cmpl $0x12345678, %eax
19621+ cmpl $0x12345678, saved_magic
19622 jne bogus_magic
19623
19624 # jump to place where we left off
19625- movl saved_eip, %eax
19626- jmp *%eax
19627+ jmp *(saved_eip)
19628
19629 bogus_magic:
19630 jmp bogus_magic
19631diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19632index 15e8563..323cbe1 100644
19633--- a/arch/x86/kernel/alternative.c
19634+++ b/arch/x86/kernel/alternative.c
19635@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19636 */
19637 for (a = start; a < end; a++) {
19638 instr = (u8 *)&a->instr_offset + a->instr_offset;
19639+
19640+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19641+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19642+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19643+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19644+#endif
19645+
19646 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19647 BUG_ON(a->replacementlen > a->instrlen);
19648 BUG_ON(a->instrlen > sizeof(insnbuf));
19649@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19650 for (poff = start; poff < end; poff++) {
19651 u8 *ptr = (u8 *)poff + *poff;
19652
19653+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19654+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19655+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19656+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19657+#endif
19658+
19659 if (!*poff || ptr < text || ptr >= text_end)
19660 continue;
19661 /* turn DS segment override prefix into lock prefix */
19662- if (*ptr == 0x3e)
19663+ if (*ktla_ktva(ptr) == 0x3e)
19664 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19665 }
19666 mutex_unlock(&text_mutex);
19667@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19668 for (poff = start; poff < end; poff++) {
19669 u8 *ptr = (u8 *)poff + *poff;
19670
19671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19672+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19673+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19674+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19675+#endif
19676+
19677 if (!*poff || ptr < text || ptr >= text_end)
19678 continue;
19679 /* turn lock prefix into DS segment override prefix */
19680- if (*ptr == 0xf0)
19681+ if (*ktla_ktva(ptr) == 0xf0)
19682 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19683 }
19684 mutex_unlock(&text_mutex);
19685@@ -469,7 +488,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19686
19687 BUG_ON(p->len > MAX_PATCH_LEN);
19688 /* prep the buffer with the original instructions */
19689- memcpy(insnbuf, p->instr, p->len);
19690+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19691 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19692 (unsigned long)p->instr, p->len);
19693
19694@@ -516,7 +535,7 @@ void __init alternative_instructions(void)
19695 if (!uniproc_patched || num_possible_cpus() == 1)
19696 free_init_pages("SMP alternatives",
19697 (unsigned long)__smp_locks,
19698- (unsigned long)__smp_locks_end);
19699+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19700 #endif
19701
19702 apply_paravirt(__parainstructions, __parainstructions_end);
19703@@ -536,13 +555,17 @@ void __init alternative_instructions(void)
19704 * instructions. And on the local CPU you need to be protected again NMI or MCE
19705 * handlers seeing an inconsistent instruction while you patch.
19706 */
19707-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19708+void *__kprobes text_poke_early(void *addr, const void *opcode,
19709 size_t len)
19710 {
19711 unsigned long flags;
19712 local_irq_save(flags);
19713- memcpy(addr, opcode, len);
19714+
19715+ pax_open_kernel();
19716+ memcpy(ktla_ktva(addr), opcode, len);
19717 sync_core();
19718+ pax_close_kernel();
19719+
19720 local_irq_restore(flags);
19721 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19722 that causes hangs on some VIA CPUs. */
19723@@ -564,36 +587,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19724 */
19725 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19726 {
19727- unsigned long flags;
19728- char *vaddr;
19729+ unsigned char *vaddr = ktla_ktva(addr);
19730 struct page *pages[2];
19731- int i;
19732+ size_t i;
19733
19734 if (!core_kernel_text((unsigned long)addr)) {
19735- pages[0] = vmalloc_to_page(addr);
19736- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19737+ pages[0] = vmalloc_to_page(vaddr);
19738+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19739 } else {
19740- pages[0] = virt_to_page(addr);
19741+ pages[0] = virt_to_page(vaddr);
19742 WARN_ON(!PageReserved(pages[0]));
19743- pages[1] = virt_to_page(addr + PAGE_SIZE);
19744+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19745 }
19746 BUG_ON(!pages[0]);
19747- local_irq_save(flags);
19748- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19749- if (pages[1])
19750- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19751- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19752- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19753- clear_fixmap(FIX_TEXT_POKE0);
19754- if (pages[1])
19755- clear_fixmap(FIX_TEXT_POKE1);
19756- local_flush_tlb();
19757- sync_core();
19758- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19759- that causes hangs on some VIA CPUs. */
19760+ text_poke_early(addr, opcode, len);
19761 for (i = 0; i < len; i++)
19762- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19763- local_irq_restore(flags);
19764+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19765 return addr;
19766 }
19767
19768@@ -613,7 +622,7 @@ int poke_int3_handler(struct pt_regs *regs)
19769 if (likely(!bp_patching_in_progress))
19770 return 0;
19771
19772- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19773+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19774 return 0;
19775
19776 /* set up the specified breakpoint handler */
19777@@ -647,7 +656,7 @@ int poke_int3_handler(struct pt_regs *regs)
19778 */
19779 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19780 {
19781- unsigned char int3 = 0xcc;
19782+ const unsigned char int3 = 0xcc;
19783
19784 bp_int3_handler = handler;
19785 bp_int3_addr = (u8 *)addr + sizeof(int3);
19786diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19787index a7eb82d..f6e52d4 100644
19788--- a/arch/x86/kernel/apic/apic.c
19789+++ b/arch/x86/kernel/apic/apic.c
19790@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19791 /*
19792 * Debug level, exported for io_apic.c
19793 */
19794-unsigned int apic_verbosity;
19795+int apic_verbosity;
19796
19797 int pic_mode;
19798
19799@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19800 apic_write(APIC_ESR, 0);
19801 v1 = apic_read(APIC_ESR);
19802 ack_APIC_irq();
19803- atomic_inc(&irq_err_count);
19804+ atomic_inc_unchecked(&irq_err_count);
19805
19806 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19807 smp_processor_id(), v0 , v1);
19808diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19809index 00c77cf..2dc6a2d 100644
19810--- a/arch/x86/kernel/apic/apic_flat_64.c
19811+++ b/arch/x86/kernel/apic/apic_flat_64.c
19812@@ -157,7 +157,7 @@ static int flat_probe(void)
19813 return 1;
19814 }
19815
19816-static struct apic apic_flat = {
19817+static struct apic apic_flat __read_only = {
19818 .name = "flat",
19819 .probe = flat_probe,
19820 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19821@@ -271,7 +271,7 @@ static int physflat_probe(void)
19822 return 0;
19823 }
19824
19825-static struct apic apic_physflat = {
19826+static struct apic apic_physflat __read_only = {
19827
19828 .name = "physical flat",
19829 .probe = physflat_probe,
19830diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19831index e145f28..2752888 100644
19832--- a/arch/x86/kernel/apic/apic_noop.c
19833+++ b/arch/x86/kernel/apic/apic_noop.c
19834@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19835 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19836 }
19837
19838-struct apic apic_noop = {
19839+struct apic apic_noop __read_only = {
19840 .name = "noop",
19841 .probe = noop_probe,
19842 .acpi_madt_oem_check = NULL,
19843diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19844index d50e364..543bee3 100644
19845--- a/arch/x86/kernel/apic/bigsmp_32.c
19846+++ b/arch/x86/kernel/apic/bigsmp_32.c
19847@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19848 return dmi_bigsmp;
19849 }
19850
19851-static struct apic apic_bigsmp = {
19852+static struct apic apic_bigsmp __read_only = {
19853
19854 .name = "bigsmp",
19855 .probe = probe_bigsmp,
19856diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19857index c552247..587a316 100644
19858--- a/arch/x86/kernel/apic/es7000_32.c
19859+++ b/arch/x86/kernel/apic/es7000_32.c
19860@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19861 return ret && es7000_apic_is_cluster();
19862 }
19863
19864-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19865-static struct apic __refdata apic_es7000_cluster = {
19866+static struct apic apic_es7000_cluster __read_only = {
19867
19868 .name = "es7000",
19869 .probe = probe_es7000,
19870@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19871 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19872 };
19873
19874-static struct apic __refdata apic_es7000 = {
19875+static struct apic apic_es7000 __read_only = {
19876
19877 .name = "es7000",
19878 .probe = probe_es7000,
19879diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19880index e63a5bd..c0babf8 100644
19881--- a/arch/x86/kernel/apic/io_apic.c
19882+++ b/arch/x86/kernel/apic/io_apic.c
19883@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19884 }
19885 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19886
19887-void lock_vector_lock(void)
19888+void lock_vector_lock(void) __acquires(vector_lock)
19889 {
19890 /* Used to the online set of cpus does not change
19891 * during assign_irq_vector.
19892@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19893 raw_spin_lock(&vector_lock);
19894 }
19895
19896-void unlock_vector_lock(void)
19897+void unlock_vector_lock(void) __releases(vector_lock)
19898 {
19899 raw_spin_unlock(&vector_lock);
19900 }
19901@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
19902 ack_APIC_irq();
19903 }
19904
19905-atomic_t irq_mis_count;
19906+atomic_unchecked_t irq_mis_count;
19907
19908 #ifdef CONFIG_GENERIC_PENDING_IRQ
19909 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19910@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
19911 * at the cpu.
19912 */
19913 if (!(v & (1 << (i & 0x1f)))) {
19914- atomic_inc(&irq_mis_count);
19915+ atomic_inc_unchecked(&irq_mis_count);
19916
19917 eoi_ioapic_irq(irq, cfg);
19918 }
19919diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19920index 1e42e8f..daacf44 100644
19921--- a/arch/x86/kernel/apic/numaq_32.c
19922+++ b/arch/x86/kernel/apic/numaq_32.c
19923@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19924 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19925 }
19926
19927-/* Use __refdata to keep false positive warning calm. */
19928-static struct apic __refdata apic_numaq = {
19929+static struct apic apic_numaq __read_only = {
19930
19931 .name = "NUMAQ",
19932 .probe = probe_numaq,
19933diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19934index eb35ef9..f184a21 100644
19935--- a/arch/x86/kernel/apic/probe_32.c
19936+++ b/arch/x86/kernel/apic/probe_32.c
19937@@ -72,7 +72,7 @@ static int probe_default(void)
19938 return 1;
19939 }
19940
19941-static struct apic apic_default = {
19942+static struct apic apic_default __read_only = {
19943
19944 .name = "default",
19945 .probe = probe_default,
19946diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19947index 77c95c0..434f8a4 100644
19948--- a/arch/x86/kernel/apic/summit_32.c
19949+++ b/arch/x86/kernel/apic/summit_32.c
19950@@ -486,7 +486,7 @@ void setup_summit(void)
19951 }
19952 #endif
19953
19954-static struct apic apic_summit = {
19955+static struct apic apic_summit __read_only = {
19956
19957 .name = "summit",
19958 .probe = probe_summit,
19959diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19960index 140e29d..d88bc95 100644
19961--- a/arch/x86/kernel/apic/x2apic_cluster.c
19962+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19963@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19964 return notifier_from_errno(err);
19965 }
19966
19967-static struct notifier_block __refdata x2apic_cpu_notifier = {
19968+static struct notifier_block x2apic_cpu_notifier = {
19969 .notifier_call = update_clusterinfo,
19970 };
19971
19972@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19973 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19974 }
19975
19976-static struct apic apic_x2apic_cluster = {
19977+static struct apic apic_x2apic_cluster __read_only = {
19978
19979 .name = "cluster x2apic",
19980 .probe = x2apic_cluster_probe,
19981diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19982index 562a76d..a003c0f 100644
19983--- a/arch/x86/kernel/apic/x2apic_phys.c
19984+++ b/arch/x86/kernel/apic/x2apic_phys.c
19985@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19986 return apic == &apic_x2apic_phys;
19987 }
19988
19989-static struct apic apic_x2apic_phys = {
19990+static struct apic apic_x2apic_phys __read_only = {
19991
19992 .name = "physical x2apic",
19993 .probe = x2apic_phys_probe,
19994diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19995index a419814..1dd34a0 100644
19996--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19997+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19998@@ -357,7 +357,7 @@ static int uv_probe(void)
19999 return apic == &apic_x2apic_uv_x;
20000 }
20001
20002-static struct apic __refdata apic_x2apic_uv_x = {
20003+static struct apic apic_x2apic_uv_x __read_only = {
20004
20005 .name = "UV large system",
20006 .probe = uv_probe,
20007diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20008index 3ab0343..814c4787 100644
20009--- a/arch/x86/kernel/apm_32.c
20010+++ b/arch/x86/kernel/apm_32.c
20011@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20012 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20013 * even though they are called in protected mode.
20014 */
20015-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20016+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20017 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20018
20019 static const char driver_version[] = "1.16ac"; /* no spaces */
20020@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20021 BUG_ON(cpu != 0);
20022 gdt = get_cpu_gdt_table(cpu);
20023 save_desc_40 = gdt[0x40 / 8];
20024+
20025+ pax_open_kernel();
20026 gdt[0x40 / 8] = bad_bios_desc;
20027+ pax_close_kernel();
20028
20029 apm_irq_save(flags);
20030 APM_DO_SAVE_SEGS;
20031@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20032 &call->esi);
20033 APM_DO_RESTORE_SEGS;
20034 apm_irq_restore(flags);
20035+
20036+ pax_open_kernel();
20037 gdt[0x40 / 8] = save_desc_40;
20038+ pax_close_kernel();
20039+
20040 put_cpu();
20041
20042 return call->eax & 0xff;
20043@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20044 BUG_ON(cpu != 0);
20045 gdt = get_cpu_gdt_table(cpu);
20046 save_desc_40 = gdt[0x40 / 8];
20047+
20048+ pax_open_kernel();
20049 gdt[0x40 / 8] = bad_bios_desc;
20050+ pax_close_kernel();
20051
20052 apm_irq_save(flags);
20053 APM_DO_SAVE_SEGS;
20054@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20055 &call->eax);
20056 APM_DO_RESTORE_SEGS;
20057 apm_irq_restore(flags);
20058+
20059+ pax_open_kernel();
20060 gdt[0x40 / 8] = save_desc_40;
20061+ pax_close_kernel();
20062+
20063 put_cpu();
20064 return error;
20065 }
20066@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20067 * code to that CPU.
20068 */
20069 gdt = get_cpu_gdt_table(0);
20070+
20071+ pax_open_kernel();
20072 set_desc_base(&gdt[APM_CS >> 3],
20073 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20074 set_desc_base(&gdt[APM_CS_16 >> 3],
20075 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20076 set_desc_base(&gdt[APM_DS >> 3],
20077 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20078+ pax_close_kernel();
20079
20080 proc_create("apm", 0, NULL, &apm_file_ops);
20081
20082diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20083index 2861082..6d4718e 100644
20084--- a/arch/x86/kernel/asm-offsets.c
20085+++ b/arch/x86/kernel/asm-offsets.c
20086@@ -33,6 +33,8 @@ void common(void) {
20087 OFFSET(TI_status, thread_info, status);
20088 OFFSET(TI_addr_limit, thread_info, addr_limit);
20089 OFFSET(TI_preempt_count, thread_info, preempt_count);
20090+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20091+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20092
20093 BLANK();
20094 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20095@@ -53,8 +55,26 @@ void common(void) {
20096 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20097 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20098 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20099+
20100+#ifdef CONFIG_PAX_KERNEXEC
20101+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20102 #endif
20103
20104+#ifdef CONFIG_PAX_MEMORY_UDEREF
20105+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20106+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20107+#ifdef CONFIG_X86_64
20108+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20109+#endif
20110+#endif
20111+
20112+#endif
20113+
20114+ BLANK();
20115+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20116+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20117+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20118+
20119 #ifdef CONFIG_XEN
20120 BLANK();
20121 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20122diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20123index e7c798b..2b2019b 100644
20124--- a/arch/x86/kernel/asm-offsets_64.c
20125+++ b/arch/x86/kernel/asm-offsets_64.c
20126@@ -77,6 +77,7 @@ int main(void)
20127 BLANK();
20128 #undef ENTRY
20129
20130+ DEFINE(TSS_size, sizeof(struct tss_struct));
20131 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20132 BLANK();
20133
20134diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20135index 47b56a7..efc2bc6 100644
20136--- a/arch/x86/kernel/cpu/Makefile
20137+++ b/arch/x86/kernel/cpu/Makefile
20138@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20139 CFLAGS_REMOVE_perf_event.o = -pg
20140 endif
20141
20142-# Make sure load_percpu_segment has no stackprotector
20143-nostackp := $(call cc-option, -fno-stack-protector)
20144-CFLAGS_common.o := $(nostackp)
20145-
20146 obj-y := intel_cacheinfo.o scattered.o topology.o
20147 obj-y += proc.o capflags.o powerflags.o common.o
20148 obj-y += rdrand.o
20149diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20150index 903a264..fc955f3 100644
20151--- a/arch/x86/kernel/cpu/amd.c
20152+++ b/arch/x86/kernel/cpu/amd.c
20153@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20154 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20155 {
20156 /* AMD errata T13 (order #21922) */
20157- if ((c->x86 == 6)) {
20158+ if (c->x86 == 6) {
20159 /* Duron Rev A0 */
20160 if (c->x86_model == 3 && c->x86_mask == 0)
20161 size = 64;
20162diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20163index 2793d1f..b4f313a 100644
20164--- a/arch/x86/kernel/cpu/common.c
20165+++ b/arch/x86/kernel/cpu/common.c
20166@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20167
20168 static const struct cpu_dev *this_cpu = &default_cpu;
20169
20170-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20171-#ifdef CONFIG_X86_64
20172- /*
20173- * We need valid kernel segments for data and code in long mode too
20174- * IRET will check the segment types kkeil 2000/10/28
20175- * Also sysret mandates a special GDT layout
20176- *
20177- * TLS descriptors are currently at a different place compared to i386.
20178- * Hopefully nobody expects them at a fixed place (Wine?)
20179- */
20180- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20181- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20182- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20183- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20184- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20185- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20186-#else
20187- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20188- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20189- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20190- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20191- /*
20192- * Segments used for calling PnP BIOS have byte granularity.
20193- * They code segments and data segments have fixed 64k limits,
20194- * the transfer segment sizes are set at run time.
20195- */
20196- /* 32-bit code */
20197- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20198- /* 16-bit code */
20199- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20200- /* 16-bit data */
20201- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20202- /* 16-bit data */
20203- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20204- /* 16-bit data */
20205- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20206- /*
20207- * The APM segments have byte granularity and their bases
20208- * are set at run time. All have 64k limits.
20209- */
20210- /* 32-bit code */
20211- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20212- /* 16-bit code */
20213- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20214- /* data */
20215- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20216-
20217- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20218- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20219- GDT_STACK_CANARY_INIT
20220-#endif
20221-} };
20222-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20223-
20224 static int __init x86_xsave_setup(char *s)
20225 {
20226 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20227@@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20228 set_in_cr4(X86_CR4_SMAP);
20229 }
20230
20231+#ifdef CONFIG_X86_64
20232+static __init int setup_disable_pcid(char *arg)
20233+{
20234+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20235+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20236+
20237+#ifdef CONFIG_PAX_MEMORY_UDEREF
20238+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20239+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20240+#endif
20241+
20242+ return 1;
20243+}
20244+__setup("nopcid", setup_disable_pcid);
20245+
20246+static void setup_pcid(struct cpuinfo_x86 *c)
20247+{
20248+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20249+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20250+
20251+#ifdef CONFIG_PAX_MEMORY_UDEREF
20252+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20253+ pax_open_kernel();
20254+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20255+ pax_close_kernel();
20256+ printk("PAX: slow and weak UDEREF enabled\n");
20257+ } else
20258+ printk("PAX: UDEREF disabled\n");
20259+#endif
20260+
20261+ return;
20262+ }
20263+
20264+ printk("PAX: PCID detected\n");
20265+ set_in_cr4(X86_CR4_PCIDE);
20266+
20267+#ifdef CONFIG_PAX_MEMORY_UDEREF
20268+ pax_open_kernel();
20269+ clone_pgd_mask = ~(pgdval_t)0UL;
20270+ pax_close_kernel();
20271+ if (pax_user_shadow_base)
20272+ printk("PAX: weak UDEREF enabled\n");
20273+ else {
20274+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20275+ printk("PAX: strong UDEREF enabled\n");
20276+ }
20277+#endif
20278+
20279+ if (cpu_has(c, X86_FEATURE_INVPCID))
20280+ printk("PAX: INVPCID detected\n");
20281+}
20282+#endif
20283+
20284 /*
20285 * Some CPU features depend on higher CPUID levels, which may not always
20286 * be available due to CPUID level capping or broken virtualization
20287@@ -386,7 +385,7 @@ void switch_to_new_gdt(int cpu)
20288 {
20289 struct desc_ptr gdt_descr;
20290
20291- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20292+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20293 gdt_descr.size = GDT_SIZE - 1;
20294 load_gdt(&gdt_descr);
20295 /* Reload the per-cpu base */
20296@@ -875,6 +874,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20297 setup_smep(c);
20298 setup_smap(c);
20299
20300+#ifdef CONFIG_X86_64
20301+ setup_pcid(c);
20302+#endif
20303+
20304 /*
20305 * The vendor-specific functions might have changed features.
20306 * Now we do "generic changes."
20307@@ -883,6 +886,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20308 /* Filter out anything that depends on CPUID levels we don't have */
20309 filter_cpuid_features(c, true);
20310
20311+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20312+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20313+#endif
20314+
20315 /* If the model name is still unset, do table lookup. */
20316 if (!c->x86_model_id[0]) {
20317 const char *p;
20318@@ -1070,10 +1077,12 @@ static __init int setup_disablecpuid(char *arg)
20319 }
20320 __setup("clearcpuid=", setup_disablecpuid);
20321
20322+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20323+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20324+
20325 #ifdef CONFIG_X86_64
20326-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20327-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20328- (unsigned long) debug_idt_table };
20329+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20330+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20331
20332 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20333 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20334@@ -1087,7 +1096,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20335 EXPORT_PER_CPU_SYMBOL(current_task);
20336
20337 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20338- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20339+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20340 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20341
20342 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20343@@ -1232,7 +1241,7 @@ void cpu_init(void)
20344 load_ucode_ap();
20345
20346 cpu = stack_smp_processor_id();
20347- t = &per_cpu(init_tss, cpu);
20348+ t = init_tss + cpu;
20349 oist = &per_cpu(orig_ist, cpu);
20350
20351 #ifdef CONFIG_NUMA
20352@@ -1267,7 +1276,6 @@ void cpu_init(void)
20353 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20354 barrier();
20355
20356- x86_configure_nx();
20357 enable_x2apic();
20358
20359 /*
20360@@ -1319,7 +1327,7 @@ void cpu_init(void)
20361 {
20362 int cpu = smp_processor_id();
20363 struct task_struct *curr = current;
20364- struct tss_struct *t = &per_cpu(init_tss, cpu);
20365+ struct tss_struct *t = init_tss + cpu;
20366 struct thread_struct *thread = &curr->thread;
20367
20368 show_ucode_info_early();
20369diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20370index 1414c90..1159406 100644
20371--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20372+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20373@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20374 };
20375
20376 #ifdef CONFIG_AMD_NB
20377+static struct attribute *default_attrs_amd_nb[] = {
20378+ &type.attr,
20379+ &level.attr,
20380+ &coherency_line_size.attr,
20381+ &physical_line_partition.attr,
20382+ &ways_of_associativity.attr,
20383+ &number_of_sets.attr,
20384+ &size.attr,
20385+ &shared_cpu_map.attr,
20386+ &shared_cpu_list.attr,
20387+ NULL,
20388+ NULL,
20389+ NULL,
20390+ NULL
20391+};
20392+
20393 static struct attribute **amd_l3_attrs(void)
20394 {
20395 static struct attribute **attrs;
20396@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20397
20398 n = ARRAY_SIZE(default_attrs);
20399
20400- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20401- n += 2;
20402-
20403- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20404- n += 1;
20405-
20406- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20407- if (attrs == NULL)
20408- return attrs = default_attrs;
20409-
20410- for (n = 0; default_attrs[n]; n++)
20411- attrs[n] = default_attrs[n];
20412+ attrs = default_attrs_amd_nb;
20413
20414 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20415 attrs[n++] = &cache_disable_0.attr;
20416@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20417 .default_attrs = default_attrs,
20418 };
20419
20420+#ifdef CONFIG_AMD_NB
20421+static struct kobj_type ktype_cache_amd_nb = {
20422+ .sysfs_ops = &sysfs_ops,
20423+ .default_attrs = default_attrs_amd_nb,
20424+};
20425+#endif
20426+
20427 static struct kobj_type ktype_percpu_entry = {
20428 .sysfs_ops = &sysfs_ops,
20429 };
20430@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20431 return retval;
20432 }
20433
20434+#ifdef CONFIG_AMD_NB
20435+ amd_l3_attrs();
20436+#endif
20437+
20438 for (i = 0; i < num_cache_leaves; i++) {
20439+ struct kobj_type *ktype;
20440+
20441 this_object = INDEX_KOBJECT_PTR(cpu, i);
20442 this_object->cpu = cpu;
20443 this_object->index = i;
20444
20445 this_leaf = CPUID4_INFO_IDX(cpu, i);
20446
20447- ktype_cache.default_attrs = default_attrs;
20448+ ktype = &ktype_cache;
20449 #ifdef CONFIG_AMD_NB
20450 if (this_leaf->base.nb)
20451- ktype_cache.default_attrs = amd_l3_attrs();
20452+ ktype = &ktype_cache_amd_nb;
20453 #endif
20454 retval = kobject_init_and_add(&(this_object->kobj),
20455- &ktype_cache,
20456+ ktype,
20457 per_cpu(ici_cache_kobject, cpu),
20458 "index%1lu", i);
20459 if (unlikely(retval)) {
20460diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20461index b3218cd..99a75de 100644
20462--- a/arch/x86/kernel/cpu/mcheck/mce.c
20463+++ b/arch/x86/kernel/cpu/mcheck/mce.c
20464@@ -45,6 +45,7 @@
20465 #include <asm/processor.h>
20466 #include <asm/mce.h>
20467 #include <asm/msr.h>
20468+#include <asm/local.h>
20469
20470 #include "mce-internal.h"
20471
20472@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20473 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20474 m->cs, m->ip);
20475
20476- if (m->cs == __KERNEL_CS)
20477+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20478 print_symbol("{%s}", m->ip);
20479 pr_cont("\n");
20480 }
20481@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20482
20483 #define PANIC_TIMEOUT 5 /* 5 seconds */
20484
20485-static atomic_t mce_paniced;
20486+static atomic_unchecked_t mce_paniced;
20487
20488 static int fake_panic;
20489-static atomic_t mce_fake_paniced;
20490+static atomic_unchecked_t mce_fake_paniced;
20491
20492 /* Panic in progress. Enable interrupts and wait for final IPI */
20493 static void wait_for_panic(void)
20494@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20495 /*
20496 * Make sure only one CPU runs in machine check panic
20497 */
20498- if (atomic_inc_return(&mce_paniced) > 1)
20499+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20500 wait_for_panic();
20501 barrier();
20502
20503@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20504 console_verbose();
20505 } else {
20506 /* Don't log too much for fake panic */
20507- if (atomic_inc_return(&mce_fake_paniced) > 1)
20508+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20509 return;
20510 }
20511 /* First print corrected ones that are still unlogged */
20512@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20513 if (!fake_panic) {
20514 if (panic_timeout == 0)
20515 panic_timeout = mca_cfg.panic_timeout;
20516- panic(msg);
20517+ panic("%s", msg);
20518 } else
20519 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20520 }
20521@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20522 * might have been modified by someone else.
20523 */
20524 rmb();
20525- if (atomic_read(&mce_paniced))
20526+ if (atomic_read_unchecked(&mce_paniced))
20527 wait_for_panic();
20528 if (!mca_cfg.monarch_timeout)
20529 goto out;
20530@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20531 }
20532
20533 /* Call the installed machine check handler for this CPU setup. */
20534-void (*machine_check_vector)(struct pt_regs *, long error_code) =
20535+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20536 unexpected_machine_check;
20537
20538 /*
20539@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20540 return;
20541 }
20542
20543+ pax_open_kernel();
20544 machine_check_vector = do_machine_check;
20545+ pax_close_kernel();
20546
20547 __mcheck_cpu_init_generic();
20548 __mcheck_cpu_init_vendor(c);
20549@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20550 */
20551
20552 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20553-static int mce_chrdev_open_count; /* #times opened */
20554+static local_t mce_chrdev_open_count; /* #times opened */
20555 static int mce_chrdev_open_exclu; /* already open exclusive? */
20556
20557 static int mce_chrdev_open(struct inode *inode, struct file *file)
20558@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20559 spin_lock(&mce_chrdev_state_lock);
20560
20561 if (mce_chrdev_open_exclu ||
20562- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20563+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20564 spin_unlock(&mce_chrdev_state_lock);
20565
20566 return -EBUSY;
20567@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20568
20569 if (file->f_flags & O_EXCL)
20570 mce_chrdev_open_exclu = 1;
20571- mce_chrdev_open_count++;
20572+ local_inc(&mce_chrdev_open_count);
20573
20574 spin_unlock(&mce_chrdev_state_lock);
20575
20576@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20577 {
20578 spin_lock(&mce_chrdev_state_lock);
20579
20580- mce_chrdev_open_count--;
20581+ local_dec(&mce_chrdev_open_count);
20582 mce_chrdev_open_exclu = 0;
20583
20584 spin_unlock(&mce_chrdev_state_lock);
20585@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20586
20587 for (i = 0; i < mca_cfg.banks; i++) {
20588 struct mce_bank *b = &mce_banks[i];
20589- struct device_attribute *a = &b->attr;
20590+ device_attribute_no_const *a = &b->attr;
20591
20592 sysfs_attr_init(&a->attr);
20593 a->attr.name = b->attrname;
20594@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20595 static void mce_reset(void)
20596 {
20597 cpu_missing = 0;
20598- atomic_set(&mce_fake_paniced, 0);
20599+ atomic_set_unchecked(&mce_fake_paniced, 0);
20600 atomic_set(&mce_executing, 0);
20601 atomic_set(&mce_callin, 0);
20602 atomic_set(&global_nwo, 0);
20603diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20604index 1c044b1..37a2a43 100644
20605--- a/arch/x86/kernel/cpu/mcheck/p5.c
20606+++ b/arch/x86/kernel/cpu/mcheck/p5.c
20607@@ -11,6 +11,7 @@
20608 #include <asm/processor.h>
20609 #include <asm/mce.h>
20610 #include <asm/msr.h>
20611+#include <asm/pgtable.h>
20612
20613 /* By default disabled */
20614 int mce_p5_enabled __read_mostly;
20615@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20616 if (!cpu_has(c, X86_FEATURE_MCE))
20617 return;
20618
20619+ pax_open_kernel();
20620 machine_check_vector = pentium_machine_check;
20621+ pax_close_kernel();
20622 /* Make sure the vector pointer is visible before we enable MCEs: */
20623 wmb();
20624
20625diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20626index e9a701a..35317d6 100644
20627--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20628+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20629@@ -10,6 +10,7 @@
20630 #include <asm/processor.h>
20631 #include <asm/mce.h>
20632 #include <asm/msr.h>
20633+#include <asm/pgtable.h>
20634
20635 /* Machine check handler for WinChip C6: */
20636 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20637@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20638 {
20639 u32 lo, hi;
20640
20641+ pax_open_kernel();
20642 machine_check_vector = winchip_machine_check;
20643+ pax_close_kernel();
20644 /* Make sure the vector pointer is visible before we enable MCEs: */
20645 wmb();
20646
20647diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20648index f961de9..8a9d332 100644
20649--- a/arch/x86/kernel/cpu/mtrr/main.c
20650+++ b/arch/x86/kernel/cpu/mtrr/main.c
20651@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20652 u64 size_or_mask, size_and_mask;
20653 static bool mtrr_aps_delayed_init;
20654
20655-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20656+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20657
20658 const struct mtrr_ops *mtrr_if;
20659
20660diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20661index df5e41f..816c719 100644
20662--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20663+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20664@@ -25,7 +25,7 @@ struct mtrr_ops {
20665 int (*validate_add_page)(unsigned long base, unsigned long size,
20666 unsigned int type);
20667 int (*have_wrcomb)(void);
20668-};
20669+} __do_const;
20670
20671 extern int generic_get_free_region(unsigned long base, unsigned long size,
20672 int replace_reg);
20673diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20674index 8a87a32..682a22a 100644
20675--- a/arch/x86/kernel/cpu/perf_event.c
20676+++ b/arch/x86/kernel/cpu/perf_event.c
20677@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20678 pr_info("no hardware sampling interrupt available.\n");
20679 }
20680
20681-static struct attribute_group x86_pmu_format_group = {
20682+static attribute_group_no_const x86_pmu_format_group = {
20683 .name = "format",
20684 .attrs = NULL,
20685 };
20686@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20687 NULL,
20688 };
20689
20690-static struct attribute_group x86_pmu_events_group = {
20691+static attribute_group_no_const x86_pmu_events_group = {
20692 .name = "events",
20693 .attrs = events_attr,
20694 };
20695@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20696 if (idx > GDT_ENTRIES)
20697 return 0;
20698
20699- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20700+ desc = get_cpu_gdt_table(smp_processor_id());
20701 }
20702
20703 return get_desc_base(desc + idx);
20704@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20705 break;
20706
20707 perf_callchain_store(entry, frame.return_address);
20708- fp = frame.next_frame;
20709+ fp = (const void __force_user *)frame.next_frame;
20710 }
20711 }
20712
20713diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20714index 639d128..e92d7e5 100644
20715--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20716+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20717@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20718 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20719 {
20720 struct attribute **attrs;
20721- struct attribute_group *attr_group;
20722+ attribute_group_no_const *attr_group;
20723 int i = 0, j;
20724
20725 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20726diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20727index f31a165..7b46cd8 100644
20728--- a/arch/x86/kernel/cpu/perf_event_intel.c
20729+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20730@@ -2247,10 +2247,10 @@ __init int intel_pmu_init(void)
20731 * v2 and above have a perf capabilities MSR
20732 */
20733 if (version > 1) {
20734- u64 capabilities;
20735+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20736
20737- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20738- x86_pmu.intel_cap.capabilities = capabilities;
20739+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20740+ x86_pmu.intel_cap.capabilities = capabilities;
20741 }
20742
20743 intel_ds_init();
20744diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20745index 4118f9f..f91d0ab 100644
20746--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20747+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20748@@ -3204,7 +3204,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20749 static int __init uncore_type_init(struct intel_uncore_type *type)
20750 {
20751 struct intel_uncore_pmu *pmus;
20752- struct attribute_group *attr_group;
20753+ attribute_group_no_const *attr_group;
20754 struct attribute **attrs;
20755 int i, j;
20756
20757diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20758index a80ab71..4089da5 100644
20759--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20760+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20761@@ -498,7 +498,7 @@ struct intel_uncore_box {
20762 struct uncore_event_desc {
20763 struct kobj_attribute attr;
20764 const char *config;
20765-};
20766+} __do_const;
20767
20768 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20769 { \
20770diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20771index 7d9481c..99c7e4b 100644
20772--- a/arch/x86/kernel/cpuid.c
20773+++ b/arch/x86/kernel/cpuid.c
20774@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20775 return notifier_from_errno(err);
20776 }
20777
20778-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20779+static struct notifier_block cpuid_class_cpu_notifier =
20780 {
20781 .notifier_call = cpuid_class_cpu_callback,
20782 };
20783diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20784index 18677a9..f67c45b 100644
20785--- a/arch/x86/kernel/crash.c
20786+++ b/arch/x86/kernel/crash.c
20787@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20788 {
20789 #ifdef CONFIG_X86_32
20790 struct pt_regs fixed_regs;
20791-#endif
20792
20793-#ifdef CONFIG_X86_32
20794- if (!user_mode_vm(regs)) {
20795+ if (!user_mode(regs)) {
20796 crash_fixup_ss_esp(&fixed_regs, regs);
20797 regs = &fixed_regs;
20798 }
20799diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20800index afa64ad..dce67dd 100644
20801--- a/arch/x86/kernel/crash_dump_64.c
20802+++ b/arch/x86/kernel/crash_dump_64.c
20803@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20804 return -ENOMEM;
20805
20806 if (userbuf) {
20807- if (copy_to_user(buf, vaddr + offset, csize)) {
20808+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20809 iounmap(vaddr);
20810 return -EFAULT;
20811 }
20812diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20813index 5d3fe8d..02e1429 100644
20814--- a/arch/x86/kernel/doublefault.c
20815+++ b/arch/x86/kernel/doublefault.c
20816@@ -13,7 +13,7 @@
20817
20818 #define DOUBLEFAULT_STACKSIZE (1024)
20819 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20820-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20821+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20822
20823 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20824
20825@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20826 unsigned long gdt, tss;
20827
20828 native_store_gdt(&gdt_desc);
20829- gdt = gdt_desc.address;
20830+ gdt = (unsigned long)gdt_desc.address;
20831
20832 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20833
20834@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20835 /* 0x2 bit is always set */
20836 .flags = X86_EFLAGS_SF | 0x2,
20837 .sp = STACK_START,
20838- .es = __USER_DS,
20839+ .es = __KERNEL_DS,
20840 .cs = __KERNEL_CS,
20841 .ss = __KERNEL_DS,
20842- .ds = __USER_DS,
20843+ .ds = __KERNEL_DS,
20844 .fs = __KERNEL_PERCPU,
20845
20846 .__cr3 = __pa_nodebug(swapper_pg_dir),
20847diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20848index deb6421..76bbc12 100644
20849--- a/arch/x86/kernel/dumpstack.c
20850+++ b/arch/x86/kernel/dumpstack.c
20851@@ -2,6 +2,9 @@
20852 * Copyright (C) 1991, 1992 Linus Torvalds
20853 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20854 */
20855+#ifdef CONFIG_GRKERNSEC_HIDESYM
20856+#define __INCLUDED_BY_HIDESYM 1
20857+#endif
20858 #include <linux/kallsyms.h>
20859 #include <linux/kprobes.h>
20860 #include <linux/uaccess.h>
20861@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20862 static void
20863 print_ftrace_graph_addr(unsigned long addr, void *data,
20864 const struct stacktrace_ops *ops,
20865- struct thread_info *tinfo, int *graph)
20866+ struct task_struct *task, int *graph)
20867 {
20868- struct task_struct *task;
20869 unsigned long ret_addr;
20870 int index;
20871
20872 if (addr != (unsigned long)return_to_handler)
20873 return;
20874
20875- task = tinfo->task;
20876 index = task->curr_ret_stack;
20877
20878 if (!task->ret_stack || index < *graph)
20879@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20880 static inline void
20881 print_ftrace_graph_addr(unsigned long addr, void *data,
20882 const struct stacktrace_ops *ops,
20883- struct thread_info *tinfo, int *graph)
20884+ struct task_struct *task, int *graph)
20885 { }
20886 #endif
20887
20888@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20889 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20890 */
20891
20892-static inline int valid_stack_ptr(struct thread_info *tinfo,
20893- void *p, unsigned int size, void *end)
20894+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20895 {
20896- void *t = tinfo;
20897 if (end) {
20898 if (p < end && p >= (end-THREAD_SIZE))
20899 return 1;
20900@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20901 }
20902
20903 unsigned long
20904-print_context_stack(struct thread_info *tinfo,
20905+print_context_stack(struct task_struct *task, void *stack_start,
20906 unsigned long *stack, unsigned long bp,
20907 const struct stacktrace_ops *ops, void *data,
20908 unsigned long *end, int *graph)
20909 {
20910 struct stack_frame *frame = (struct stack_frame *)bp;
20911
20912- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20913+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20914 unsigned long addr;
20915
20916 addr = *stack;
20917@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20918 } else {
20919 ops->address(data, addr, 0);
20920 }
20921- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20922+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20923 }
20924 stack++;
20925 }
20926@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20927 EXPORT_SYMBOL_GPL(print_context_stack);
20928
20929 unsigned long
20930-print_context_stack_bp(struct thread_info *tinfo,
20931+print_context_stack_bp(struct task_struct *task, void *stack_start,
20932 unsigned long *stack, unsigned long bp,
20933 const struct stacktrace_ops *ops, void *data,
20934 unsigned long *end, int *graph)
20935@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20936 struct stack_frame *frame = (struct stack_frame *)bp;
20937 unsigned long *ret_addr = &frame->return_address;
20938
20939- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20940+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20941 unsigned long addr = *ret_addr;
20942
20943 if (!__kernel_text_address(addr))
20944@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20945 ops->address(data, addr, 1);
20946 frame = frame->next_frame;
20947 ret_addr = &frame->return_address;
20948- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20949+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20950 }
20951
20952 return (unsigned long)frame;
20953@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20954 static void print_trace_address(void *data, unsigned long addr, int reliable)
20955 {
20956 touch_nmi_watchdog();
20957- printk(data);
20958+ printk("%s", (char *)data);
20959 printk_address(addr, reliable);
20960 }
20961
20962@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20963 }
20964 EXPORT_SYMBOL_GPL(oops_begin);
20965
20966+extern void gr_handle_kernel_exploit(void);
20967+
20968 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20969 {
20970 if (regs && kexec_should_crash(current))
20971@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20972 panic("Fatal exception in interrupt");
20973 if (panic_on_oops)
20974 panic("Fatal exception");
20975- do_exit(signr);
20976+
20977+ gr_handle_kernel_exploit();
20978+
20979+ do_group_exit(signr);
20980 }
20981
20982 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20983@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20984 print_modules();
20985 show_regs(regs);
20986 #ifdef CONFIG_X86_32
20987- if (user_mode_vm(regs)) {
20988+ if (user_mode(regs)) {
20989 sp = regs->sp;
20990 ss = regs->ss & 0xffff;
20991 } else {
20992@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20993 unsigned long flags = oops_begin();
20994 int sig = SIGSEGV;
20995
20996- if (!user_mode_vm(regs))
20997+ if (!user_mode(regs))
20998 report_bug(regs->ip, regs);
20999
21000 if (__die(str, regs, err))
21001diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21002index f2a1770..540657f 100644
21003--- a/arch/x86/kernel/dumpstack_32.c
21004+++ b/arch/x86/kernel/dumpstack_32.c
21005@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21006 bp = stack_frame(task, regs);
21007
21008 for (;;) {
21009- struct thread_info *context;
21010+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21011
21012- context = (struct thread_info *)
21013- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21014- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21015+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21016
21017- stack = (unsigned long *)context->previous_esp;
21018- if (!stack)
21019+ if (stack_start == task_stack_page(task))
21020 break;
21021+ stack = *(unsigned long **)stack_start;
21022 if (ops->stack(data, "IRQ") < 0)
21023 break;
21024 touch_nmi_watchdog();
21025@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21026 int i;
21027
21028 show_regs_print_info(KERN_EMERG);
21029- __show_regs(regs, !user_mode_vm(regs));
21030+ __show_regs(regs, !user_mode(regs));
21031
21032 /*
21033 * When in-kernel, we also print out the stack and code at the
21034 * time of the fault..
21035 */
21036- if (!user_mode_vm(regs)) {
21037+ if (!user_mode(regs)) {
21038 unsigned int code_prologue = code_bytes * 43 / 64;
21039 unsigned int code_len = code_bytes;
21040 unsigned char c;
21041 u8 *ip;
21042+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21043
21044 pr_emerg("Stack:\n");
21045 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21046
21047 pr_emerg("Code:");
21048
21049- ip = (u8 *)regs->ip - code_prologue;
21050+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21051 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21052 /* try starting at IP */
21053- ip = (u8 *)regs->ip;
21054+ ip = (u8 *)regs->ip + cs_base;
21055 code_len = code_len - code_prologue + 1;
21056 }
21057 for (i = 0; i < code_len; i++, ip++) {
21058@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21059 pr_cont(" Bad EIP value.");
21060 break;
21061 }
21062- if (ip == (u8 *)regs->ip)
21063+ if (ip == (u8 *)regs->ip + cs_base)
21064 pr_cont(" <%02x>", c);
21065 else
21066 pr_cont(" %02x", c);
21067@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21068 {
21069 unsigned short ud2;
21070
21071+ ip = ktla_ktva(ip);
21072 if (ip < PAGE_OFFSET)
21073 return 0;
21074 if (probe_kernel_address((unsigned short *)ip, ud2))
21075@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21076
21077 return ud2 == 0x0b0f;
21078 }
21079+
21080+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21081+void pax_check_alloca(unsigned long size)
21082+{
21083+ unsigned long sp = (unsigned long)&sp, stack_left;
21084+
21085+ /* all kernel stacks are of the same size */
21086+ stack_left = sp & (THREAD_SIZE - 1);
21087+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21088+}
21089+EXPORT_SYMBOL(pax_check_alloca);
21090+#endif
21091diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21092index addb207..99635fa 100644
21093--- a/arch/x86/kernel/dumpstack_64.c
21094+++ b/arch/x86/kernel/dumpstack_64.c
21095@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21096 unsigned long *irq_stack_end =
21097 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21098 unsigned used = 0;
21099- struct thread_info *tinfo;
21100 int graph = 0;
21101 unsigned long dummy;
21102+ void *stack_start;
21103
21104 if (!task)
21105 task = current;
21106@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21107 * current stack address. If the stacks consist of nested
21108 * exceptions
21109 */
21110- tinfo = task_thread_info(task);
21111 for (;;) {
21112 char *id;
21113 unsigned long *estack_end;
21114+
21115 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21116 &used, &id);
21117
21118@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21119 if (ops->stack(data, id) < 0)
21120 break;
21121
21122- bp = ops->walk_stack(tinfo, stack, bp, ops,
21123+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21124 data, estack_end, &graph);
21125 ops->stack(data, "<EOE>");
21126 /*
21127@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21128 * second-to-last pointer (index -2 to end) in the
21129 * exception stack:
21130 */
21131+ if ((u16)estack_end[-1] != __KERNEL_DS)
21132+ goto out;
21133 stack = (unsigned long *) estack_end[-2];
21134 continue;
21135 }
21136@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21137 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21138 if (ops->stack(data, "IRQ") < 0)
21139 break;
21140- bp = ops->walk_stack(tinfo, stack, bp,
21141+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21142 ops, data, irq_stack_end, &graph);
21143 /*
21144 * We link to the next stack (which would be
21145@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21146 /*
21147 * This handles the process stack:
21148 */
21149- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21150+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21151+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21152+out:
21153 put_cpu();
21154 }
21155 EXPORT_SYMBOL(dump_trace);
21156@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21157
21158 return ud2 == 0x0b0f;
21159 }
21160+
21161+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21162+void pax_check_alloca(unsigned long size)
21163+{
21164+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21165+ unsigned cpu, used;
21166+ char *id;
21167+
21168+ /* check the process stack first */
21169+ stack_start = (unsigned long)task_stack_page(current);
21170+ stack_end = stack_start + THREAD_SIZE;
21171+ if (likely(stack_start <= sp && sp < stack_end)) {
21172+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21173+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21174+ return;
21175+ }
21176+
21177+ cpu = get_cpu();
21178+
21179+ /* check the irq stacks */
21180+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21181+ stack_start = stack_end - IRQ_STACK_SIZE;
21182+ if (stack_start <= sp && sp < stack_end) {
21183+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21184+ put_cpu();
21185+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21186+ return;
21187+ }
21188+
21189+ /* check the exception stacks */
21190+ used = 0;
21191+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21192+ stack_start = stack_end - EXCEPTION_STKSZ;
21193+ if (stack_end && stack_start <= sp && sp < stack_end) {
21194+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21195+ put_cpu();
21196+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21197+ return;
21198+ }
21199+
21200+ put_cpu();
21201+
21202+ /* unknown stack */
21203+ BUG();
21204+}
21205+EXPORT_SYMBOL(pax_check_alloca);
21206+#endif
21207diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21208index 174da5f..5e55606 100644
21209--- a/arch/x86/kernel/e820.c
21210+++ b/arch/x86/kernel/e820.c
21211@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21212
21213 static void early_panic(char *msg)
21214 {
21215- early_printk(msg);
21216- panic(msg);
21217+ early_printk("%s", msg);
21218+ panic("%s", msg);
21219 }
21220
21221 static int userdef __initdata;
21222diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21223index d15f575..d692043 100644
21224--- a/arch/x86/kernel/early_printk.c
21225+++ b/arch/x86/kernel/early_printk.c
21226@@ -7,6 +7,7 @@
21227 #include <linux/pci_regs.h>
21228 #include <linux/pci_ids.h>
21229 #include <linux/errno.h>
21230+#include <linux/sched.h>
21231 #include <asm/io.h>
21232 #include <asm/processor.h>
21233 #include <asm/fcntl.h>
21234diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21235index f0dcb0c..9f39b80 100644
21236--- a/arch/x86/kernel/entry_32.S
21237+++ b/arch/x86/kernel/entry_32.S
21238@@ -177,13 +177,153 @@
21239 /*CFI_REL_OFFSET gs, PT_GS*/
21240 .endm
21241 .macro SET_KERNEL_GS reg
21242+
21243+#ifdef CONFIG_CC_STACKPROTECTOR
21244 movl $(__KERNEL_STACK_CANARY), \reg
21245+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21246+ movl $(__USER_DS), \reg
21247+#else
21248+ xorl \reg, \reg
21249+#endif
21250+
21251 movl \reg, %gs
21252 .endm
21253
21254 #endif /* CONFIG_X86_32_LAZY_GS */
21255
21256-.macro SAVE_ALL
21257+.macro pax_enter_kernel
21258+#ifdef CONFIG_PAX_KERNEXEC
21259+ call pax_enter_kernel
21260+#endif
21261+.endm
21262+
21263+.macro pax_exit_kernel
21264+#ifdef CONFIG_PAX_KERNEXEC
21265+ call pax_exit_kernel
21266+#endif
21267+.endm
21268+
21269+#ifdef CONFIG_PAX_KERNEXEC
21270+ENTRY(pax_enter_kernel)
21271+#ifdef CONFIG_PARAVIRT
21272+ pushl %eax
21273+ pushl %ecx
21274+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21275+ mov %eax, %esi
21276+#else
21277+ mov %cr0, %esi
21278+#endif
21279+ bts $16, %esi
21280+ jnc 1f
21281+ mov %cs, %esi
21282+ cmp $__KERNEL_CS, %esi
21283+ jz 3f
21284+ ljmp $__KERNEL_CS, $3f
21285+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21286+2:
21287+#ifdef CONFIG_PARAVIRT
21288+ mov %esi, %eax
21289+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21290+#else
21291+ mov %esi, %cr0
21292+#endif
21293+3:
21294+#ifdef CONFIG_PARAVIRT
21295+ popl %ecx
21296+ popl %eax
21297+#endif
21298+ ret
21299+ENDPROC(pax_enter_kernel)
21300+
21301+ENTRY(pax_exit_kernel)
21302+#ifdef CONFIG_PARAVIRT
21303+ pushl %eax
21304+ pushl %ecx
21305+#endif
21306+ mov %cs, %esi
21307+ cmp $__KERNEXEC_KERNEL_CS, %esi
21308+ jnz 2f
21309+#ifdef CONFIG_PARAVIRT
21310+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21311+ mov %eax, %esi
21312+#else
21313+ mov %cr0, %esi
21314+#endif
21315+ btr $16, %esi
21316+ ljmp $__KERNEL_CS, $1f
21317+1:
21318+#ifdef CONFIG_PARAVIRT
21319+ mov %esi, %eax
21320+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21321+#else
21322+ mov %esi, %cr0
21323+#endif
21324+2:
21325+#ifdef CONFIG_PARAVIRT
21326+ popl %ecx
21327+ popl %eax
21328+#endif
21329+ ret
21330+ENDPROC(pax_exit_kernel)
21331+#endif
21332+
21333+ .macro pax_erase_kstack
21334+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21335+ call pax_erase_kstack
21336+#endif
21337+ .endm
21338+
21339+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21340+/*
21341+ * ebp: thread_info
21342+ */
21343+ENTRY(pax_erase_kstack)
21344+ pushl %edi
21345+ pushl %ecx
21346+ pushl %eax
21347+
21348+ mov TI_lowest_stack(%ebp), %edi
21349+ mov $-0xBEEF, %eax
21350+ std
21351+
21352+1: mov %edi, %ecx
21353+ and $THREAD_SIZE_asm - 1, %ecx
21354+ shr $2, %ecx
21355+ repne scasl
21356+ jecxz 2f
21357+
21358+ cmp $2*16, %ecx
21359+ jc 2f
21360+
21361+ mov $2*16, %ecx
21362+ repe scasl
21363+ jecxz 2f
21364+ jne 1b
21365+
21366+2: cld
21367+ mov %esp, %ecx
21368+ sub %edi, %ecx
21369+
21370+ cmp $THREAD_SIZE_asm, %ecx
21371+ jb 3f
21372+ ud2
21373+3:
21374+
21375+ shr $2, %ecx
21376+ rep stosl
21377+
21378+ mov TI_task_thread_sp0(%ebp), %edi
21379+ sub $128, %edi
21380+ mov %edi, TI_lowest_stack(%ebp)
21381+
21382+ popl %eax
21383+ popl %ecx
21384+ popl %edi
21385+ ret
21386+ENDPROC(pax_erase_kstack)
21387+#endif
21388+
21389+.macro __SAVE_ALL _DS
21390 cld
21391 PUSH_GS
21392 pushl_cfi %fs
21393@@ -206,7 +346,7 @@
21394 CFI_REL_OFFSET ecx, 0
21395 pushl_cfi %ebx
21396 CFI_REL_OFFSET ebx, 0
21397- movl $(__USER_DS), %edx
21398+ movl $\_DS, %edx
21399 movl %edx, %ds
21400 movl %edx, %es
21401 movl $(__KERNEL_PERCPU), %edx
21402@@ -214,6 +354,15 @@
21403 SET_KERNEL_GS %edx
21404 .endm
21405
21406+.macro SAVE_ALL
21407+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21408+ __SAVE_ALL __KERNEL_DS
21409+ pax_enter_kernel
21410+#else
21411+ __SAVE_ALL __USER_DS
21412+#endif
21413+.endm
21414+
21415 .macro RESTORE_INT_REGS
21416 popl_cfi %ebx
21417 CFI_RESTORE ebx
21418@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21419 popfl_cfi
21420 jmp syscall_exit
21421 CFI_ENDPROC
21422-END(ret_from_fork)
21423+ENDPROC(ret_from_fork)
21424
21425 ENTRY(ret_from_kernel_thread)
21426 CFI_STARTPROC
21427@@ -344,7 +493,15 @@ ret_from_intr:
21428 andl $SEGMENT_RPL_MASK, %eax
21429 #endif
21430 cmpl $USER_RPL, %eax
21431+
21432+#ifdef CONFIG_PAX_KERNEXEC
21433+ jae resume_userspace
21434+
21435+ pax_exit_kernel
21436+ jmp resume_kernel
21437+#else
21438 jb resume_kernel # not returning to v8086 or userspace
21439+#endif
21440
21441 ENTRY(resume_userspace)
21442 LOCKDEP_SYS_EXIT
21443@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21444 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21445 # int/exception return?
21446 jne work_pending
21447- jmp restore_all
21448-END(ret_from_exception)
21449+ jmp restore_all_pax
21450+ENDPROC(ret_from_exception)
21451
21452 #ifdef CONFIG_PREEMPT
21453 ENTRY(resume_kernel)
21454@@ -372,7 +529,7 @@ need_resched:
21455 jz restore_all
21456 call preempt_schedule_irq
21457 jmp need_resched
21458-END(resume_kernel)
21459+ENDPROC(resume_kernel)
21460 #endif
21461 CFI_ENDPROC
21462 /*
21463@@ -406,30 +563,45 @@ sysenter_past_esp:
21464 /*CFI_REL_OFFSET cs, 0*/
21465 /*
21466 * Push current_thread_info()->sysenter_return to the stack.
21467- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21468- * pushed above; +8 corresponds to copy_thread's esp0 setting.
21469 */
21470- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21471+ pushl_cfi $0
21472 CFI_REL_OFFSET eip, 0
21473
21474 pushl_cfi %eax
21475 SAVE_ALL
21476+ GET_THREAD_INFO(%ebp)
21477+ movl TI_sysenter_return(%ebp),%ebp
21478+ movl %ebp,PT_EIP(%esp)
21479 ENABLE_INTERRUPTS(CLBR_NONE)
21480
21481 /*
21482 * Load the potential sixth argument from user stack.
21483 * Careful about security.
21484 */
21485+ movl PT_OLDESP(%esp),%ebp
21486+
21487+#ifdef CONFIG_PAX_MEMORY_UDEREF
21488+ mov PT_OLDSS(%esp),%ds
21489+1: movl %ds:(%ebp),%ebp
21490+ push %ss
21491+ pop %ds
21492+#else
21493 cmpl $__PAGE_OFFSET-3,%ebp
21494 jae syscall_fault
21495 ASM_STAC
21496 1: movl (%ebp),%ebp
21497 ASM_CLAC
21498+#endif
21499+
21500 movl %ebp,PT_EBP(%esp)
21501 _ASM_EXTABLE(1b,syscall_fault)
21502
21503 GET_THREAD_INFO(%ebp)
21504
21505+#ifdef CONFIG_PAX_RANDKSTACK
21506+ pax_erase_kstack
21507+#endif
21508+
21509 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21510 jnz sysenter_audit
21511 sysenter_do_call:
21512@@ -444,12 +616,24 @@ sysenter_do_call:
21513 testl $_TIF_ALLWORK_MASK, %ecx
21514 jne sysexit_audit
21515 sysenter_exit:
21516+
21517+#ifdef CONFIG_PAX_RANDKSTACK
21518+ pushl_cfi %eax
21519+ movl %esp, %eax
21520+ call pax_randomize_kstack
21521+ popl_cfi %eax
21522+#endif
21523+
21524+ pax_erase_kstack
21525+
21526 /* if something modifies registers it must also disable sysexit */
21527 movl PT_EIP(%esp), %edx
21528 movl PT_OLDESP(%esp), %ecx
21529 xorl %ebp,%ebp
21530 TRACE_IRQS_ON
21531 1: mov PT_FS(%esp), %fs
21532+2: mov PT_DS(%esp), %ds
21533+3: mov PT_ES(%esp), %es
21534 PTGS_TO_GS
21535 ENABLE_INTERRUPTS_SYSEXIT
21536
21537@@ -466,6 +650,9 @@ sysenter_audit:
21538 movl %eax,%edx /* 2nd arg: syscall number */
21539 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21540 call __audit_syscall_entry
21541+
21542+ pax_erase_kstack
21543+
21544 pushl_cfi %ebx
21545 movl PT_EAX(%esp),%eax /* reload syscall number */
21546 jmp sysenter_do_call
21547@@ -491,10 +678,16 @@ sysexit_audit:
21548
21549 CFI_ENDPROC
21550 .pushsection .fixup,"ax"
21551-2: movl $0,PT_FS(%esp)
21552+4: movl $0,PT_FS(%esp)
21553+ jmp 1b
21554+5: movl $0,PT_DS(%esp)
21555+ jmp 1b
21556+6: movl $0,PT_ES(%esp)
21557 jmp 1b
21558 .popsection
21559- _ASM_EXTABLE(1b,2b)
21560+ _ASM_EXTABLE(1b,4b)
21561+ _ASM_EXTABLE(2b,5b)
21562+ _ASM_EXTABLE(3b,6b)
21563 PTGS_TO_GS_EX
21564 ENDPROC(ia32_sysenter_target)
21565
21566@@ -509,6 +702,11 @@ ENTRY(system_call)
21567 pushl_cfi %eax # save orig_eax
21568 SAVE_ALL
21569 GET_THREAD_INFO(%ebp)
21570+
21571+#ifdef CONFIG_PAX_RANDKSTACK
21572+ pax_erase_kstack
21573+#endif
21574+
21575 # system call tracing in operation / emulation
21576 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21577 jnz syscall_trace_entry
21578@@ -527,6 +725,15 @@ syscall_exit:
21579 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21580 jne syscall_exit_work
21581
21582+restore_all_pax:
21583+
21584+#ifdef CONFIG_PAX_RANDKSTACK
21585+ movl %esp, %eax
21586+ call pax_randomize_kstack
21587+#endif
21588+
21589+ pax_erase_kstack
21590+
21591 restore_all:
21592 TRACE_IRQS_IRET
21593 restore_all_notrace:
21594@@ -583,14 +790,34 @@ ldt_ss:
21595 * compensating for the offset by changing to the ESPFIX segment with
21596 * a base address that matches for the difference.
21597 */
21598-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21599+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21600 mov %esp, %edx /* load kernel esp */
21601 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21602 mov %dx, %ax /* eax: new kernel esp */
21603 sub %eax, %edx /* offset (low word is 0) */
21604+#ifdef CONFIG_SMP
21605+ movl PER_CPU_VAR(cpu_number), %ebx
21606+ shll $PAGE_SHIFT_asm, %ebx
21607+ addl $cpu_gdt_table, %ebx
21608+#else
21609+ movl $cpu_gdt_table, %ebx
21610+#endif
21611 shr $16, %edx
21612- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21613- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21614+
21615+#ifdef CONFIG_PAX_KERNEXEC
21616+ mov %cr0, %esi
21617+ btr $16, %esi
21618+ mov %esi, %cr0
21619+#endif
21620+
21621+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21622+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21623+
21624+#ifdef CONFIG_PAX_KERNEXEC
21625+ bts $16, %esi
21626+ mov %esi, %cr0
21627+#endif
21628+
21629 pushl_cfi $__ESPFIX_SS
21630 pushl_cfi %eax /* new kernel esp */
21631 /* Disable interrupts, but do not irqtrace this section: we
21632@@ -619,20 +846,18 @@ work_resched:
21633 movl TI_flags(%ebp), %ecx
21634 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21635 # than syscall tracing?
21636- jz restore_all
21637+ jz restore_all_pax
21638 testb $_TIF_NEED_RESCHED, %cl
21639 jnz work_resched
21640
21641 work_notifysig: # deal with pending signals and
21642 # notify-resume requests
21643+ movl %esp, %eax
21644 #ifdef CONFIG_VM86
21645 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21646- movl %esp, %eax
21647 jne work_notifysig_v86 # returning to kernel-space or
21648 # vm86-space
21649 1:
21650-#else
21651- movl %esp, %eax
21652 #endif
21653 TRACE_IRQS_ON
21654 ENABLE_INTERRUPTS(CLBR_NONE)
21655@@ -653,7 +878,7 @@ work_notifysig_v86:
21656 movl %eax, %esp
21657 jmp 1b
21658 #endif
21659-END(work_pending)
21660+ENDPROC(work_pending)
21661
21662 # perform syscall exit tracing
21663 ALIGN
21664@@ -661,11 +886,14 @@ syscall_trace_entry:
21665 movl $-ENOSYS,PT_EAX(%esp)
21666 movl %esp, %eax
21667 call syscall_trace_enter
21668+
21669+ pax_erase_kstack
21670+
21671 /* What it returned is what we'll actually use. */
21672 cmpl $(NR_syscalls), %eax
21673 jnae syscall_call
21674 jmp syscall_exit
21675-END(syscall_trace_entry)
21676+ENDPROC(syscall_trace_entry)
21677
21678 # perform syscall exit tracing
21679 ALIGN
21680@@ -678,21 +906,25 @@ syscall_exit_work:
21681 movl %esp, %eax
21682 call syscall_trace_leave
21683 jmp resume_userspace
21684-END(syscall_exit_work)
21685+ENDPROC(syscall_exit_work)
21686 CFI_ENDPROC
21687
21688 RING0_INT_FRAME # can't unwind into user space anyway
21689 syscall_fault:
21690+#ifdef CONFIG_PAX_MEMORY_UDEREF
21691+ push %ss
21692+ pop %ds
21693+#endif
21694 ASM_CLAC
21695 GET_THREAD_INFO(%ebp)
21696 movl $-EFAULT,PT_EAX(%esp)
21697 jmp resume_userspace
21698-END(syscall_fault)
21699+ENDPROC(syscall_fault)
21700
21701 syscall_badsys:
21702 movl $-ENOSYS,PT_EAX(%esp)
21703 jmp resume_userspace
21704-END(syscall_badsys)
21705+ENDPROC(syscall_badsys)
21706 CFI_ENDPROC
21707 /*
21708 * End of kprobes section
21709@@ -708,8 +940,15 @@ END(syscall_badsys)
21710 * normal stack and adjusts ESP with the matching offset.
21711 */
21712 /* fixup the stack */
21713- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21714- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21715+#ifdef CONFIG_SMP
21716+ movl PER_CPU_VAR(cpu_number), %ebx
21717+ shll $PAGE_SHIFT_asm, %ebx
21718+ addl $cpu_gdt_table, %ebx
21719+#else
21720+ movl $cpu_gdt_table, %ebx
21721+#endif
21722+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21723+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21724 shl $16, %eax
21725 addl %esp, %eax /* the adjusted stack pointer */
21726 pushl_cfi $__KERNEL_DS
21727@@ -762,7 +1001,7 @@ vector=vector+1
21728 .endr
21729 2: jmp common_interrupt
21730 .endr
21731-END(irq_entries_start)
21732+ENDPROC(irq_entries_start)
21733
21734 .previous
21735 END(interrupt)
21736@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21737 pushl_cfi $do_coprocessor_error
21738 jmp error_code
21739 CFI_ENDPROC
21740-END(coprocessor_error)
21741+ENDPROC(coprocessor_error)
21742
21743 ENTRY(simd_coprocessor_error)
21744 RING0_INT_FRAME
21745@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21746 .section .altinstructions,"a"
21747 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21748 .previous
21749-.section .altinstr_replacement,"ax"
21750+.section .altinstr_replacement,"a"
21751 663: pushl $do_simd_coprocessor_error
21752 664:
21753 .previous
21754@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21755 #endif
21756 jmp error_code
21757 CFI_ENDPROC
21758-END(simd_coprocessor_error)
21759+ENDPROC(simd_coprocessor_error)
21760
21761 ENTRY(device_not_available)
21762 RING0_INT_FRAME
21763@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21764 pushl_cfi $do_device_not_available
21765 jmp error_code
21766 CFI_ENDPROC
21767-END(device_not_available)
21768+ENDPROC(device_not_available)
21769
21770 #ifdef CONFIG_PARAVIRT
21771 ENTRY(native_iret)
21772 iret
21773 _ASM_EXTABLE(native_iret, iret_exc)
21774-END(native_iret)
21775+ENDPROC(native_iret)
21776
21777 ENTRY(native_irq_enable_sysexit)
21778 sti
21779 sysexit
21780-END(native_irq_enable_sysexit)
21781+ENDPROC(native_irq_enable_sysexit)
21782 #endif
21783
21784 ENTRY(overflow)
21785@@ -875,7 +1114,7 @@ ENTRY(overflow)
21786 pushl_cfi $do_overflow
21787 jmp error_code
21788 CFI_ENDPROC
21789-END(overflow)
21790+ENDPROC(overflow)
21791
21792 ENTRY(bounds)
21793 RING0_INT_FRAME
21794@@ -884,7 +1123,7 @@ ENTRY(bounds)
21795 pushl_cfi $do_bounds
21796 jmp error_code
21797 CFI_ENDPROC
21798-END(bounds)
21799+ENDPROC(bounds)
21800
21801 ENTRY(invalid_op)
21802 RING0_INT_FRAME
21803@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21804 pushl_cfi $do_invalid_op
21805 jmp error_code
21806 CFI_ENDPROC
21807-END(invalid_op)
21808+ENDPROC(invalid_op)
21809
21810 ENTRY(coprocessor_segment_overrun)
21811 RING0_INT_FRAME
21812@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21813 pushl_cfi $do_coprocessor_segment_overrun
21814 jmp error_code
21815 CFI_ENDPROC
21816-END(coprocessor_segment_overrun)
21817+ENDPROC(coprocessor_segment_overrun)
21818
21819 ENTRY(invalid_TSS)
21820 RING0_EC_FRAME
21821@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21822 pushl_cfi $do_invalid_TSS
21823 jmp error_code
21824 CFI_ENDPROC
21825-END(invalid_TSS)
21826+ENDPROC(invalid_TSS)
21827
21828 ENTRY(segment_not_present)
21829 RING0_EC_FRAME
21830@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21831 pushl_cfi $do_segment_not_present
21832 jmp error_code
21833 CFI_ENDPROC
21834-END(segment_not_present)
21835+ENDPROC(segment_not_present)
21836
21837 ENTRY(stack_segment)
21838 RING0_EC_FRAME
21839@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21840 pushl_cfi $do_stack_segment
21841 jmp error_code
21842 CFI_ENDPROC
21843-END(stack_segment)
21844+ENDPROC(stack_segment)
21845
21846 ENTRY(alignment_check)
21847 RING0_EC_FRAME
21848@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21849 pushl_cfi $do_alignment_check
21850 jmp error_code
21851 CFI_ENDPROC
21852-END(alignment_check)
21853+ENDPROC(alignment_check)
21854
21855 ENTRY(divide_error)
21856 RING0_INT_FRAME
21857@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21858 pushl_cfi $do_divide_error
21859 jmp error_code
21860 CFI_ENDPROC
21861-END(divide_error)
21862+ENDPROC(divide_error)
21863
21864 #ifdef CONFIG_X86_MCE
21865 ENTRY(machine_check)
21866@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21867 pushl_cfi machine_check_vector
21868 jmp error_code
21869 CFI_ENDPROC
21870-END(machine_check)
21871+ENDPROC(machine_check)
21872 #endif
21873
21874 ENTRY(spurious_interrupt_bug)
21875@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21876 pushl_cfi $do_spurious_interrupt_bug
21877 jmp error_code
21878 CFI_ENDPROC
21879-END(spurious_interrupt_bug)
21880+ENDPROC(spurious_interrupt_bug)
21881 /*
21882 * End of kprobes section
21883 */
21884@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21885
21886 ENTRY(mcount)
21887 ret
21888-END(mcount)
21889+ENDPROC(mcount)
21890
21891 ENTRY(ftrace_caller)
21892 cmpl $0, function_trace_stop
21893@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21894 .globl ftrace_stub
21895 ftrace_stub:
21896 ret
21897-END(ftrace_caller)
21898+ENDPROC(ftrace_caller)
21899
21900 ENTRY(ftrace_regs_caller)
21901 pushf /* push flags before compare (in cs location) */
21902@@ -1210,7 +1449,7 @@ trace:
21903 popl %ecx
21904 popl %eax
21905 jmp ftrace_stub
21906-END(mcount)
21907+ENDPROC(mcount)
21908 #endif /* CONFIG_DYNAMIC_FTRACE */
21909 #endif /* CONFIG_FUNCTION_TRACER */
21910
21911@@ -1228,7 +1467,7 @@ ENTRY(ftrace_graph_caller)
21912 popl %ecx
21913 popl %eax
21914 ret
21915-END(ftrace_graph_caller)
21916+ENDPROC(ftrace_graph_caller)
21917
21918 .globl return_to_handler
21919 return_to_handler:
21920@@ -1284,15 +1523,18 @@ error_code:
21921 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21922 REG_TO_PTGS %ecx
21923 SET_KERNEL_GS %ecx
21924- movl $(__USER_DS), %ecx
21925+ movl $(__KERNEL_DS), %ecx
21926 movl %ecx, %ds
21927 movl %ecx, %es
21928+
21929+ pax_enter_kernel
21930+
21931 TRACE_IRQS_OFF
21932 movl %esp,%eax # pt_regs pointer
21933 call *%edi
21934 jmp ret_from_exception
21935 CFI_ENDPROC
21936-END(page_fault)
21937+ENDPROC(page_fault)
21938
21939 /*
21940 * Debug traps and NMI can happen at the one SYSENTER instruction
21941@@ -1335,7 +1577,7 @@ debug_stack_correct:
21942 call do_debug
21943 jmp ret_from_exception
21944 CFI_ENDPROC
21945-END(debug)
21946+ENDPROC(debug)
21947
21948 /*
21949 * NMI is doubly nasty. It can happen _while_ we're handling
21950@@ -1373,6 +1615,9 @@ nmi_stack_correct:
21951 xorl %edx,%edx # zero error code
21952 movl %esp,%eax # pt_regs pointer
21953 call do_nmi
21954+
21955+ pax_exit_kernel
21956+
21957 jmp restore_all_notrace
21958 CFI_ENDPROC
21959
21960@@ -1409,12 +1654,15 @@ nmi_espfix_stack:
21961 FIXUP_ESPFIX_STACK # %eax == %esp
21962 xorl %edx,%edx # zero error code
21963 call do_nmi
21964+
21965+ pax_exit_kernel
21966+
21967 RESTORE_REGS
21968 lss 12+4(%esp), %esp # back to espfix stack
21969 CFI_ADJUST_CFA_OFFSET -24
21970 jmp irq_return
21971 CFI_ENDPROC
21972-END(nmi)
21973+ENDPROC(nmi)
21974
21975 ENTRY(int3)
21976 RING0_INT_FRAME
21977@@ -1427,14 +1675,14 @@ ENTRY(int3)
21978 call do_int3
21979 jmp ret_from_exception
21980 CFI_ENDPROC
21981-END(int3)
21982+ENDPROC(int3)
21983
21984 ENTRY(general_protection)
21985 RING0_EC_FRAME
21986 pushl_cfi $do_general_protection
21987 jmp error_code
21988 CFI_ENDPROC
21989-END(general_protection)
21990+ENDPROC(general_protection)
21991
21992 #ifdef CONFIG_KVM_GUEST
21993 ENTRY(async_page_fault)
21994@@ -1443,7 +1691,7 @@ ENTRY(async_page_fault)
21995 pushl_cfi $do_async_page_fault
21996 jmp error_code
21997 CFI_ENDPROC
21998-END(async_page_fault)
21999+ENDPROC(async_page_fault)
22000 #endif
22001
22002 /*
22003diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22004index b077f4c..8e0df9f 100644
22005--- a/arch/x86/kernel/entry_64.S
22006+++ b/arch/x86/kernel/entry_64.S
22007@@ -59,6 +59,8 @@
22008 #include <asm/context_tracking.h>
22009 #include <asm/smap.h>
22010 #include <linux/err.h>
22011+#include <asm/pgtable.h>
22012+#include <asm/alternative-asm.h>
22013
22014 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22015 #include <linux/elf-em.h>
22016@@ -80,8 +82,9 @@
22017 #ifdef CONFIG_DYNAMIC_FTRACE
22018
22019 ENTRY(function_hook)
22020+ pax_force_retaddr
22021 retq
22022-END(function_hook)
22023+ENDPROC(function_hook)
22024
22025 /* skip is set if stack has been adjusted */
22026 .macro ftrace_caller_setup skip=0
22027@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22028 #endif
22029
22030 GLOBAL(ftrace_stub)
22031+ pax_force_retaddr
22032 retq
22033-END(ftrace_caller)
22034+ENDPROC(ftrace_caller)
22035
22036 ENTRY(ftrace_regs_caller)
22037 /* Save the current flags before compare (in SS location)*/
22038@@ -191,7 +195,7 @@ ftrace_restore_flags:
22039 popfq
22040 jmp ftrace_stub
22041
22042-END(ftrace_regs_caller)
22043+ENDPROC(ftrace_regs_caller)
22044
22045
22046 #else /* ! CONFIG_DYNAMIC_FTRACE */
22047@@ -212,6 +216,7 @@ ENTRY(function_hook)
22048 #endif
22049
22050 GLOBAL(ftrace_stub)
22051+ pax_force_retaddr
22052 retq
22053
22054 trace:
22055@@ -225,12 +230,13 @@ trace:
22056 #endif
22057 subq $MCOUNT_INSN_SIZE, %rdi
22058
22059+ pax_force_fptr ftrace_trace_function
22060 call *ftrace_trace_function
22061
22062 MCOUNT_RESTORE_FRAME
22063
22064 jmp ftrace_stub
22065-END(function_hook)
22066+ENDPROC(function_hook)
22067 #endif /* CONFIG_DYNAMIC_FTRACE */
22068 #endif /* CONFIG_FUNCTION_TRACER */
22069
22070@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22071
22072 MCOUNT_RESTORE_FRAME
22073
22074+ pax_force_retaddr
22075 retq
22076-END(ftrace_graph_caller)
22077+ENDPROC(ftrace_graph_caller)
22078
22079 GLOBAL(return_to_handler)
22080 subq $24, %rsp
22081@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22082 movq 8(%rsp), %rdx
22083 movq (%rsp), %rax
22084 addq $24, %rsp
22085+ pax_force_fptr %rdi
22086 jmp *%rdi
22087+ENDPROC(return_to_handler)
22088 #endif
22089
22090
22091@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22092 ENDPROC(native_usergs_sysret64)
22093 #endif /* CONFIG_PARAVIRT */
22094
22095+ .macro ljmpq sel, off
22096+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22097+ .byte 0x48; ljmp *1234f(%rip)
22098+ .pushsection .rodata
22099+ .align 16
22100+ 1234: .quad \off; .word \sel
22101+ .popsection
22102+#else
22103+ pushq $\sel
22104+ pushq $\off
22105+ lretq
22106+#endif
22107+ .endm
22108+
22109+ .macro pax_enter_kernel
22110+ pax_set_fptr_mask
22111+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22112+ call pax_enter_kernel
22113+#endif
22114+ .endm
22115+
22116+ .macro pax_exit_kernel
22117+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22118+ call pax_exit_kernel
22119+#endif
22120+
22121+ .endm
22122+
22123+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22124+ENTRY(pax_enter_kernel)
22125+ pushq %rdi
22126+
22127+#ifdef CONFIG_PARAVIRT
22128+ PV_SAVE_REGS(CLBR_RDI)
22129+#endif
22130+
22131+#ifdef CONFIG_PAX_KERNEXEC
22132+ GET_CR0_INTO_RDI
22133+ bts $16,%rdi
22134+ jnc 3f
22135+ mov %cs,%edi
22136+ cmp $__KERNEL_CS,%edi
22137+ jnz 2f
22138+1:
22139+#endif
22140+
22141+#ifdef CONFIG_PAX_MEMORY_UDEREF
22142+ 661: jmp 111f
22143+ .pushsection .altinstr_replacement, "a"
22144+ 662: ASM_NOP2
22145+ .popsection
22146+ .pushsection .altinstructions, "a"
22147+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22148+ .popsection
22149+ GET_CR3_INTO_RDI
22150+ cmp $0,%dil
22151+ jnz 112f
22152+ mov $__KERNEL_DS,%edi
22153+ mov %edi,%ss
22154+ jmp 111f
22155+112: cmp $1,%dil
22156+ jz 113f
22157+ ud2
22158+113: sub $4097,%rdi
22159+ bts $63,%rdi
22160+ SET_RDI_INTO_CR3
22161+ mov $__UDEREF_KERNEL_DS,%edi
22162+ mov %edi,%ss
22163+111:
22164+#endif
22165+
22166+#ifdef CONFIG_PARAVIRT
22167+ PV_RESTORE_REGS(CLBR_RDI)
22168+#endif
22169+
22170+ popq %rdi
22171+ pax_force_retaddr
22172+ retq
22173+
22174+#ifdef CONFIG_PAX_KERNEXEC
22175+2: ljmpq __KERNEL_CS,1b
22176+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22177+4: SET_RDI_INTO_CR0
22178+ jmp 1b
22179+#endif
22180+ENDPROC(pax_enter_kernel)
22181+
22182+ENTRY(pax_exit_kernel)
22183+ pushq %rdi
22184+
22185+#ifdef CONFIG_PARAVIRT
22186+ PV_SAVE_REGS(CLBR_RDI)
22187+#endif
22188+
22189+#ifdef CONFIG_PAX_KERNEXEC
22190+ mov %cs,%rdi
22191+ cmp $__KERNEXEC_KERNEL_CS,%edi
22192+ jz 2f
22193+ GET_CR0_INTO_RDI
22194+ bts $16,%rdi
22195+ jnc 4f
22196+1:
22197+#endif
22198+
22199+#ifdef CONFIG_PAX_MEMORY_UDEREF
22200+ 661: jmp 111f
22201+ .pushsection .altinstr_replacement, "a"
22202+ 662: ASM_NOP2
22203+ .popsection
22204+ .pushsection .altinstructions, "a"
22205+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22206+ .popsection
22207+ mov %ss,%edi
22208+ cmp $__UDEREF_KERNEL_DS,%edi
22209+ jnz 111f
22210+ GET_CR3_INTO_RDI
22211+ cmp $0,%dil
22212+ jz 112f
22213+ ud2
22214+112: add $4097,%rdi
22215+ bts $63,%rdi
22216+ SET_RDI_INTO_CR3
22217+ mov $__KERNEL_DS,%edi
22218+ mov %edi,%ss
22219+111:
22220+#endif
22221+
22222+#ifdef CONFIG_PARAVIRT
22223+ PV_RESTORE_REGS(CLBR_RDI);
22224+#endif
22225+
22226+ popq %rdi
22227+ pax_force_retaddr
22228+ retq
22229+
22230+#ifdef CONFIG_PAX_KERNEXEC
22231+2: GET_CR0_INTO_RDI
22232+ btr $16,%rdi
22233+ jnc 4f
22234+ ljmpq __KERNEL_CS,3f
22235+3: SET_RDI_INTO_CR0
22236+ jmp 1b
22237+4: ud2
22238+ jmp 4b
22239+#endif
22240+ENDPROC(pax_exit_kernel)
22241+#endif
22242+
22243+ .macro pax_enter_kernel_user
22244+ pax_set_fptr_mask
22245+#ifdef CONFIG_PAX_MEMORY_UDEREF
22246+ call pax_enter_kernel_user
22247+#endif
22248+ .endm
22249+
22250+ .macro pax_exit_kernel_user
22251+#ifdef CONFIG_PAX_MEMORY_UDEREF
22252+ call pax_exit_kernel_user
22253+#endif
22254+#ifdef CONFIG_PAX_RANDKSTACK
22255+ pushq %rax
22256+ pushq %r11
22257+ call pax_randomize_kstack
22258+ popq %r11
22259+ popq %rax
22260+#endif
22261+ .endm
22262+
22263+#ifdef CONFIG_PAX_MEMORY_UDEREF
22264+ENTRY(pax_enter_kernel_user)
22265+ pushq %rdi
22266+ pushq %rbx
22267+
22268+#ifdef CONFIG_PARAVIRT
22269+ PV_SAVE_REGS(CLBR_RDI)
22270+#endif
22271+
22272+ 661: jmp 111f
22273+ .pushsection .altinstr_replacement, "a"
22274+ 662: ASM_NOP2
22275+ .popsection
22276+ .pushsection .altinstructions, "a"
22277+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22278+ .popsection
22279+ GET_CR3_INTO_RDI
22280+ cmp $1,%dil
22281+ jnz 4f
22282+ sub $4097,%rdi
22283+ bts $63,%rdi
22284+ SET_RDI_INTO_CR3
22285+ jmp 3f
22286+111:
22287+
22288+ GET_CR3_INTO_RDI
22289+ mov %rdi,%rbx
22290+ add $__START_KERNEL_map,%rbx
22291+ sub phys_base(%rip),%rbx
22292+
22293+#ifdef CONFIG_PARAVIRT
22294+ cmpl $0, pv_info+PARAVIRT_enabled
22295+ jz 1f
22296+ pushq %rdi
22297+ i = 0
22298+ .rept USER_PGD_PTRS
22299+ mov i*8(%rbx),%rsi
22300+ mov $0,%sil
22301+ lea i*8(%rbx),%rdi
22302+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22303+ i = i + 1
22304+ .endr
22305+ popq %rdi
22306+ jmp 2f
22307+1:
22308+#endif
22309+
22310+ i = 0
22311+ .rept USER_PGD_PTRS
22312+ movb $0,i*8(%rbx)
22313+ i = i + 1
22314+ .endr
22315+
22316+2: SET_RDI_INTO_CR3
22317+
22318+#ifdef CONFIG_PAX_KERNEXEC
22319+ GET_CR0_INTO_RDI
22320+ bts $16,%rdi
22321+ SET_RDI_INTO_CR0
22322+#endif
22323+
22324+3:
22325+
22326+#ifdef CONFIG_PARAVIRT
22327+ PV_RESTORE_REGS(CLBR_RDI)
22328+#endif
22329+
22330+ popq %rbx
22331+ popq %rdi
22332+ pax_force_retaddr
22333+ retq
22334+4: ud2
22335+ENDPROC(pax_enter_kernel_user)
22336+
22337+ENTRY(pax_exit_kernel_user)
22338+ pushq %rdi
22339+ pushq %rbx
22340+
22341+#ifdef CONFIG_PARAVIRT
22342+ PV_SAVE_REGS(CLBR_RDI)
22343+#endif
22344+
22345+ GET_CR3_INTO_RDI
22346+ 661: jmp 1f
22347+ .pushsection .altinstr_replacement, "a"
22348+ 662: ASM_NOP2
22349+ .popsection
22350+ .pushsection .altinstructions, "a"
22351+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22352+ .popsection
22353+ cmp $0,%dil
22354+ jnz 3f
22355+ add $4097,%rdi
22356+ bts $63,%rdi
22357+ SET_RDI_INTO_CR3
22358+ jmp 2f
22359+1:
22360+
22361+ mov %rdi,%rbx
22362+
22363+#ifdef CONFIG_PAX_KERNEXEC
22364+ GET_CR0_INTO_RDI
22365+ btr $16,%rdi
22366+ jnc 3f
22367+ SET_RDI_INTO_CR0
22368+#endif
22369+
22370+ add $__START_KERNEL_map,%rbx
22371+ sub phys_base(%rip),%rbx
22372+
22373+#ifdef CONFIG_PARAVIRT
22374+ cmpl $0, pv_info+PARAVIRT_enabled
22375+ jz 1f
22376+ i = 0
22377+ .rept USER_PGD_PTRS
22378+ mov i*8(%rbx),%rsi
22379+ mov $0x67,%sil
22380+ lea i*8(%rbx),%rdi
22381+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22382+ i = i + 1
22383+ .endr
22384+ jmp 2f
22385+1:
22386+#endif
22387+
22388+ i = 0
22389+ .rept USER_PGD_PTRS
22390+ movb $0x67,i*8(%rbx)
22391+ i = i + 1
22392+ .endr
22393+2:
22394+
22395+#ifdef CONFIG_PARAVIRT
22396+ PV_RESTORE_REGS(CLBR_RDI)
22397+#endif
22398+
22399+ popq %rbx
22400+ popq %rdi
22401+ pax_force_retaddr
22402+ retq
22403+3: ud2
22404+ENDPROC(pax_exit_kernel_user)
22405+#endif
22406+
22407+ .macro pax_enter_kernel_nmi
22408+ pax_set_fptr_mask
22409+
22410+#ifdef CONFIG_PAX_KERNEXEC
22411+ GET_CR0_INTO_RDI
22412+ bts $16,%rdi
22413+ jc 110f
22414+ SET_RDI_INTO_CR0
22415+ or $2,%ebx
22416+110:
22417+#endif
22418+
22419+#ifdef CONFIG_PAX_MEMORY_UDEREF
22420+ 661: jmp 111f
22421+ .pushsection .altinstr_replacement, "a"
22422+ 662: ASM_NOP2
22423+ .popsection
22424+ .pushsection .altinstructions, "a"
22425+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22426+ .popsection
22427+ GET_CR3_INTO_RDI
22428+ cmp $0,%dil
22429+ jz 111f
22430+ sub $4097,%rdi
22431+ or $4,%ebx
22432+ bts $63,%rdi
22433+ SET_RDI_INTO_CR3
22434+ mov $__UDEREF_KERNEL_DS,%edi
22435+ mov %edi,%ss
22436+111:
22437+#endif
22438+ .endm
22439+
22440+ .macro pax_exit_kernel_nmi
22441+#ifdef CONFIG_PAX_KERNEXEC
22442+ btr $1,%ebx
22443+ jnc 110f
22444+ GET_CR0_INTO_RDI
22445+ btr $16,%rdi
22446+ SET_RDI_INTO_CR0
22447+110:
22448+#endif
22449+
22450+#ifdef CONFIG_PAX_MEMORY_UDEREF
22451+ btr $2,%ebx
22452+ jnc 111f
22453+ GET_CR3_INTO_RDI
22454+ add $4097,%rdi
22455+ bts $63,%rdi
22456+ SET_RDI_INTO_CR3
22457+ mov $__KERNEL_DS,%edi
22458+ mov %edi,%ss
22459+111:
22460+#endif
22461+ .endm
22462+
22463+ .macro pax_erase_kstack
22464+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22465+ call pax_erase_kstack
22466+#endif
22467+ .endm
22468+
22469+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22470+ENTRY(pax_erase_kstack)
22471+ pushq %rdi
22472+ pushq %rcx
22473+ pushq %rax
22474+ pushq %r11
22475+
22476+ GET_THREAD_INFO(%r11)
22477+ mov TI_lowest_stack(%r11), %rdi
22478+ mov $-0xBEEF, %rax
22479+ std
22480+
22481+1: mov %edi, %ecx
22482+ and $THREAD_SIZE_asm - 1, %ecx
22483+ shr $3, %ecx
22484+ repne scasq
22485+ jecxz 2f
22486+
22487+ cmp $2*8, %ecx
22488+ jc 2f
22489+
22490+ mov $2*8, %ecx
22491+ repe scasq
22492+ jecxz 2f
22493+ jne 1b
22494+
22495+2: cld
22496+ mov %esp, %ecx
22497+ sub %edi, %ecx
22498+
22499+ cmp $THREAD_SIZE_asm, %rcx
22500+ jb 3f
22501+ ud2
22502+3:
22503+
22504+ shr $3, %ecx
22505+ rep stosq
22506+
22507+ mov TI_task_thread_sp0(%r11), %rdi
22508+ sub $256, %rdi
22509+ mov %rdi, TI_lowest_stack(%r11)
22510+
22511+ popq %r11
22512+ popq %rax
22513+ popq %rcx
22514+ popq %rdi
22515+ pax_force_retaddr
22516+ ret
22517+ENDPROC(pax_erase_kstack)
22518+#endif
22519
22520 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22521 #ifdef CONFIG_TRACE_IRQFLAGS
22522@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22523 .endm
22524
22525 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22526- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22527+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22528 jnc 1f
22529 TRACE_IRQS_ON_DEBUG
22530 1:
22531@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22532 movq \tmp,R11+\offset(%rsp)
22533 .endm
22534
22535- .macro FAKE_STACK_FRAME child_rip
22536- /* push in order ss, rsp, eflags, cs, rip */
22537- xorl %eax, %eax
22538- pushq_cfi $__KERNEL_DS /* ss */
22539- /*CFI_REL_OFFSET ss,0*/
22540- pushq_cfi %rax /* rsp */
22541- CFI_REL_OFFSET rsp,0
22542- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22543- /*CFI_REL_OFFSET rflags,0*/
22544- pushq_cfi $__KERNEL_CS /* cs */
22545- /*CFI_REL_OFFSET cs,0*/
22546- pushq_cfi \child_rip /* rip */
22547- CFI_REL_OFFSET rip,0
22548- pushq_cfi %rax /* orig rax */
22549- .endm
22550-
22551- .macro UNFAKE_STACK_FRAME
22552- addq $8*6, %rsp
22553- CFI_ADJUST_CFA_OFFSET -(6*8)
22554- .endm
22555-
22556 /*
22557 * initial frame state for interrupts (and exceptions without error code)
22558 */
22559@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22560 /* save partial stack frame */
22561 .macro SAVE_ARGS_IRQ
22562 cld
22563- /* start from rbp in pt_regs and jump over */
22564- movq_cfi rdi, (RDI-RBP)
22565- movq_cfi rsi, (RSI-RBP)
22566- movq_cfi rdx, (RDX-RBP)
22567- movq_cfi rcx, (RCX-RBP)
22568- movq_cfi rax, (RAX-RBP)
22569- movq_cfi r8, (R8-RBP)
22570- movq_cfi r9, (R9-RBP)
22571- movq_cfi r10, (R10-RBP)
22572- movq_cfi r11, (R11-RBP)
22573+ /* start from r15 in pt_regs and jump over */
22574+ movq_cfi rdi, RDI
22575+ movq_cfi rsi, RSI
22576+ movq_cfi rdx, RDX
22577+ movq_cfi rcx, RCX
22578+ movq_cfi rax, RAX
22579+ movq_cfi r8, R8
22580+ movq_cfi r9, R9
22581+ movq_cfi r10, R10
22582+ movq_cfi r11, R11
22583+ movq_cfi r12, R12
22584
22585 /* Save rbp so that we can unwind from get_irq_regs() */
22586- movq_cfi rbp, 0
22587+ movq_cfi rbp, RBP
22588
22589 /* Save previous stack value */
22590 movq %rsp, %rsi
22591
22592- leaq -RBP(%rsp),%rdi /* arg1 for handler */
22593- testl $3, CS-RBP(%rsi)
22594+ movq %rsp,%rdi /* arg1 for handler */
22595+ testb $3, CS(%rsi)
22596 je 1f
22597 SWAPGS
22598 /*
22599@@ -514,9 +927,10 @@ ENTRY(save_paranoid)
22600 js 1f /* negative -> in kernel */
22601 SWAPGS
22602 xorl %ebx,%ebx
22603-1: ret
22604+1: pax_force_retaddr_bts
22605+ ret
22606 CFI_ENDPROC
22607-END(save_paranoid)
22608+ENDPROC(save_paranoid)
22609 .popsection
22610
22611 /*
22612@@ -538,7 +952,7 @@ ENTRY(ret_from_fork)
22613
22614 RESTORE_REST
22615
22616- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22617+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22618 jz 1f
22619
22620 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22621@@ -548,15 +962,13 @@ ENTRY(ret_from_fork)
22622 jmp ret_from_sys_call # go to the SYSRET fastpath
22623
22624 1:
22625- subq $REST_SKIP, %rsp # leave space for volatiles
22626- CFI_ADJUST_CFA_OFFSET REST_SKIP
22627 movq %rbp, %rdi
22628 call *%rbx
22629 movl $0, RAX(%rsp)
22630 RESTORE_REST
22631 jmp int_ret_from_sys_call
22632 CFI_ENDPROC
22633-END(ret_from_fork)
22634+ENDPROC(ret_from_fork)
22635
22636 /*
22637 * System call entry. Up to 6 arguments in registers are supported.
22638@@ -593,7 +1005,7 @@ END(ret_from_fork)
22639 ENTRY(system_call)
22640 CFI_STARTPROC simple
22641 CFI_SIGNAL_FRAME
22642- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22643+ CFI_DEF_CFA rsp,0
22644 CFI_REGISTER rip,rcx
22645 /*CFI_REGISTER rflags,r11*/
22646 SWAPGS_UNSAFE_STACK
22647@@ -606,16 +1018,23 @@ GLOBAL(system_call_after_swapgs)
22648
22649 movq %rsp,PER_CPU_VAR(old_rsp)
22650 movq PER_CPU_VAR(kernel_stack),%rsp
22651+ SAVE_ARGS 8*6,0
22652+ pax_enter_kernel_user
22653+
22654+#ifdef CONFIG_PAX_RANDKSTACK
22655+ pax_erase_kstack
22656+#endif
22657+
22658 /*
22659 * No need to follow this irqs off/on section - it's straight
22660 * and short:
22661 */
22662 ENABLE_INTERRUPTS(CLBR_NONE)
22663- SAVE_ARGS 8,0
22664 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22665 movq %rcx,RIP-ARGOFFSET(%rsp)
22666 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22667- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22668+ GET_THREAD_INFO(%rcx)
22669+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22670 jnz tracesys
22671 system_call_fastpath:
22672 #if __SYSCALL_MASK == ~0
22673@@ -639,10 +1058,13 @@ sysret_check:
22674 LOCKDEP_SYS_EXIT
22675 DISABLE_INTERRUPTS(CLBR_NONE)
22676 TRACE_IRQS_OFF
22677- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22678+ GET_THREAD_INFO(%rcx)
22679+ movl TI_flags(%rcx),%edx
22680 andl %edi,%edx
22681 jnz sysret_careful
22682 CFI_REMEMBER_STATE
22683+ pax_exit_kernel_user
22684+ pax_erase_kstack
22685 /*
22686 * sysretq will re-enable interrupts:
22687 */
22688@@ -701,6 +1123,9 @@ auditsys:
22689 movq %rax,%rsi /* 2nd arg: syscall number */
22690 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22691 call __audit_syscall_entry
22692+
22693+ pax_erase_kstack
22694+
22695 LOAD_ARGS 0 /* reload call-clobbered registers */
22696 jmp system_call_fastpath
22697
22698@@ -722,7 +1147,7 @@ sysret_audit:
22699 /* Do syscall tracing */
22700 tracesys:
22701 #ifdef CONFIG_AUDITSYSCALL
22702- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22703+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22704 jz auditsys
22705 #endif
22706 SAVE_REST
22707@@ -730,12 +1155,15 @@ tracesys:
22708 FIXUP_TOP_OF_STACK %rdi
22709 movq %rsp,%rdi
22710 call syscall_trace_enter
22711+
22712+ pax_erase_kstack
22713+
22714 /*
22715 * Reload arg registers from stack in case ptrace changed them.
22716 * We don't reload %rax because syscall_trace_enter() returned
22717 * the value it wants us to use in the table lookup.
22718 */
22719- LOAD_ARGS ARGOFFSET, 1
22720+ LOAD_ARGS 1
22721 RESTORE_REST
22722 #if __SYSCALL_MASK == ~0
22723 cmpq $__NR_syscall_max,%rax
22724@@ -765,7 +1193,9 @@ GLOBAL(int_with_check)
22725 andl %edi,%edx
22726 jnz int_careful
22727 andl $~TS_COMPAT,TI_status(%rcx)
22728- jmp retint_swapgs
22729+ pax_exit_kernel_user
22730+ pax_erase_kstack
22731+ jmp retint_swapgs_pax
22732
22733 /* Either reschedule or signal or syscall exit tracking needed. */
22734 /* First do a reschedule test. */
22735@@ -811,7 +1241,7 @@ int_restore_rest:
22736 TRACE_IRQS_OFF
22737 jmp int_with_check
22738 CFI_ENDPROC
22739-END(system_call)
22740+ENDPROC(system_call)
22741
22742 .macro FORK_LIKE func
22743 ENTRY(stub_\func)
22744@@ -824,9 +1254,10 @@ ENTRY(stub_\func)
22745 DEFAULT_FRAME 0 8 /* offset 8: return address */
22746 call sys_\func
22747 RESTORE_TOP_OF_STACK %r11, 8
22748- ret $REST_SKIP /* pop extended registers */
22749+ pax_force_retaddr
22750+ ret
22751 CFI_ENDPROC
22752-END(stub_\func)
22753+ENDPROC(stub_\func)
22754 .endm
22755
22756 .macro FIXED_FRAME label,func
22757@@ -836,9 +1267,10 @@ ENTRY(\label)
22758 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22759 call \func
22760 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22761+ pax_force_retaddr
22762 ret
22763 CFI_ENDPROC
22764-END(\label)
22765+ENDPROC(\label)
22766 .endm
22767
22768 FORK_LIKE clone
22769@@ -846,19 +1278,6 @@ END(\label)
22770 FORK_LIKE vfork
22771 FIXED_FRAME stub_iopl, sys_iopl
22772
22773-ENTRY(ptregscall_common)
22774- DEFAULT_FRAME 1 8 /* offset 8: return address */
22775- RESTORE_TOP_OF_STACK %r11, 8
22776- movq_cfi_restore R15+8, r15
22777- movq_cfi_restore R14+8, r14
22778- movq_cfi_restore R13+8, r13
22779- movq_cfi_restore R12+8, r12
22780- movq_cfi_restore RBP+8, rbp
22781- movq_cfi_restore RBX+8, rbx
22782- ret $REST_SKIP /* pop extended registers */
22783- CFI_ENDPROC
22784-END(ptregscall_common)
22785-
22786 ENTRY(stub_execve)
22787 CFI_STARTPROC
22788 addq $8, %rsp
22789@@ -870,7 +1289,7 @@ ENTRY(stub_execve)
22790 RESTORE_REST
22791 jmp int_ret_from_sys_call
22792 CFI_ENDPROC
22793-END(stub_execve)
22794+ENDPROC(stub_execve)
22795
22796 /*
22797 * sigreturn is special because it needs to restore all registers on return.
22798@@ -887,7 +1306,7 @@ ENTRY(stub_rt_sigreturn)
22799 RESTORE_REST
22800 jmp int_ret_from_sys_call
22801 CFI_ENDPROC
22802-END(stub_rt_sigreturn)
22803+ENDPROC(stub_rt_sigreturn)
22804
22805 #ifdef CONFIG_X86_X32_ABI
22806 ENTRY(stub_x32_rt_sigreturn)
22807@@ -901,7 +1320,7 @@ ENTRY(stub_x32_rt_sigreturn)
22808 RESTORE_REST
22809 jmp int_ret_from_sys_call
22810 CFI_ENDPROC
22811-END(stub_x32_rt_sigreturn)
22812+ENDPROC(stub_x32_rt_sigreturn)
22813
22814 ENTRY(stub_x32_execve)
22815 CFI_STARTPROC
22816@@ -915,7 +1334,7 @@ ENTRY(stub_x32_execve)
22817 RESTORE_REST
22818 jmp int_ret_from_sys_call
22819 CFI_ENDPROC
22820-END(stub_x32_execve)
22821+ENDPROC(stub_x32_execve)
22822
22823 #endif
22824
22825@@ -952,7 +1371,7 @@ vector=vector+1
22826 2: jmp common_interrupt
22827 .endr
22828 CFI_ENDPROC
22829-END(irq_entries_start)
22830+ENDPROC(irq_entries_start)
22831
22832 .previous
22833 END(interrupt)
22834@@ -969,9 +1388,19 @@ END(interrupt)
22835 /* 0(%rsp): ~(interrupt number) */
22836 .macro interrupt func
22837 /* reserve pt_regs for scratch regs and rbp */
22838- subq $ORIG_RAX-RBP, %rsp
22839- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22840+ subq $ORIG_RAX, %rsp
22841+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
22842 SAVE_ARGS_IRQ
22843+#ifdef CONFIG_PAX_MEMORY_UDEREF
22844+ testb $3, CS(%rdi)
22845+ jnz 1f
22846+ pax_enter_kernel
22847+ jmp 2f
22848+1: pax_enter_kernel_user
22849+2:
22850+#else
22851+ pax_enter_kernel
22852+#endif
22853 call \func
22854 .endm
22855
22856@@ -997,14 +1426,14 @@ ret_from_intr:
22857
22858 /* Restore saved previous stack */
22859 popq %rsi
22860- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
22861- leaq ARGOFFSET-RBP(%rsi), %rsp
22862+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
22863+ movq %rsi, %rsp
22864 CFI_DEF_CFA_REGISTER rsp
22865- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
22866+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
22867
22868 exit_intr:
22869 GET_THREAD_INFO(%rcx)
22870- testl $3,CS-ARGOFFSET(%rsp)
22871+ testb $3,CS-ARGOFFSET(%rsp)
22872 je retint_kernel
22873
22874 /* Interrupt came from user space */
22875@@ -1026,12 +1455,16 @@ retint_swapgs: /* return to user-space */
22876 * The iretq could re-enable interrupts:
22877 */
22878 DISABLE_INTERRUPTS(CLBR_ANY)
22879+ pax_exit_kernel_user
22880+retint_swapgs_pax:
22881 TRACE_IRQS_IRETQ
22882 SWAPGS
22883 jmp restore_args
22884
22885 retint_restore_args: /* return to kernel space */
22886 DISABLE_INTERRUPTS(CLBR_ANY)
22887+ pax_exit_kernel
22888+ pax_force_retaddr (RIP-ARGOFFSET)
22889 /*
22890 * The iretq could re-enable interrupts:
22891 */
22892@@ -1114,7 +1547,7 @@ ENTRY(retint_kernel)
22893 #endif
22894
22895 CFI_ENDPROC
22896-END(common_interrupt)
22897+ENDPROC(common_interrupt)
22898 /*
22899 * End of kprobes section
22900 */
22901@@ -1132,7 +1565,7 @@ ENTRY(\sym)
22902 interrupt \do_sym
22903 jmp ret_from_intr
22904 CFI_ENDPROC
22905-END(\sym)
22906+ENDPROC(\sym)
22907 .endm
22908
22909 #ifdef CONFIG_TRACING
22910@@ -1215,12 +1648,22 @@ ENTRY(\sym)
22911 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22912 call error_entry
22913 DEFAULT_FRAME 0
22914+#ifdef CONFIG_PAX_MEMORY_UDEREF
22915+ testb $3, CS(%rsp)
22916+ jnz 1f
22917+ pax_enter_kernel
22918+ jmp 2f
22919+1: pax_enter_kernel_user
22920+2:
22921+#else
22922+ pax_enter_kernel
22923+#endif
22924 movq %rsp,%rdi /* pt_regs pointer */
22925 xorl %esi,%esi /* no error code */
22926 call \do_sym
22927 jmp error_exit /* %ebx: no swapgs flag */
22928 CFI_ENDPROC
22929-END(\sym)
22930+ENDPROC(\sym)
22931 .endm
22932
22933 .macro paranoidzeroentry sym do_sym
22934@@ -1233,15 +1676,25 @@ ENTRY(\sym)
22935 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22936 call save_paranoid
22937 TRACE_IRQS_OFF
22938+#ifdef CONFIG_PAX_MEMORY_UDEREF
22939+ testb $3, CS(%rsp)
22940+ jnz 1f
22941+ pax_enter_kernel
22942+ jmp 2f
22943+1: pax_enter_kernel_user
22944+2:
22945+#else
22946+ pax_enter_kernel
22947+#endif
22948 movq %rsp,%rdi /* pt_regs pointer */
22949 xorl %esi,%esi /* no error code */
22950 call \do_sym
22951 jmp paranoid_exit /* %ebx: no swapgs flag */
22952 CFI_ENDPROC
22953-END(\sym)
22954+ENDPROC(\sym)
22955 .endm
22956
22957-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22958+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
22959 .macro paranoidzeroentry_ist sym do_sym ist
22960 ENTRY(\sym)
22961 INTR_FRAME
22962@@ -1252,14 +1705,30 @@ ENTRY(\sym)
22963 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22964 call save_paranoid
22965 TRACE_IRQS_OFF_DEBUG
22966+#ifdef CONFIG_PAX_MEMORY_UDEREF
22967+ testb $3, CS(%rsp)
22968+ jnz 1f
22969+ pax_enter_kernel
22970+ jmp 2f
22971+1: pax_enter_kernel_user
22972+2:
22973+#else
22974+ pax_enter_kernel
22975+#endif
22976 movq %rsp,%rdi /* pt_regs pointer */
22977 xorl %esi,%esi /* no error code */
22978+#ifdef CONFIG_SMP
22979+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
22980+ lea init_tss(%r13), %r13
22981+#else
22982+ lea init_tss(%rip), %r13
22983+#endif
22984 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22985 call \do_sym
22986 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22987 jmp paranoid_exit /* %ebx: no swapgs flag */
22988 CFI_ENDPROC
22989-END(\sym)
22990+ENDPROC(\sym)
22991 .endm
22992
22993 .macro errorentry sym do_sym
22994@@ -1271,13 +1740,23 @@ ENTRY(\sym)
22995 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22996 call error_entry
22997 DEFAULT_FRAME 0
22998+#ifdef CONFIG_PAX_MEMORY_UDEREF
22999+ testb $3, CS(%rsp)
23000+ jnz 1f
23001+ pax_enter_kernel
23002+ jmp 2f
23003+1: pax_enter_kernel_user
23004+2:
23005+#else
23006+ pax_enter_kernel
23007+#endif
23008 movq %rsp,%rdi /* pt_regs pointer */
23009 movq ORIG_RAX(%rsp),%rsi /* get error code */
23010 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
23011 call \do_sym
23012 jmp error_exit /* %ebx: no swapgs flag */
23013 CFI_ENDPROC
23014-END(\sym)
23015+ENDPROC(\sym)
23016 .endm
23017
23018 /* error code is on the stack already */
23019@@ -1291,13 +1770,23 @@ ENTRY(\sym)
23020 call save_paranoid
23021 DEFAULT_FRAME 0
23022 TRACE_IRQS_OFF
23023+#ifdef CONFIG_PAX_MEMORY_UDEREF
23024+ testb $3, CS(%rsp)
23025+ jnz 1f
23026+ pax_enter_kernel
23027+ jmp 2f
23028+1: pax_enter_kernel_user
23029+2:
23030+#else
23031+ pax_enter_kernel
23032+#endif
23033 movq %rsp,%rdi /* pt_regs pointer */
23034 movq ORIG_RAX(%rsp),%rsi /* get error code */
23035 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
23036 call \do_sym
23037 jmp paranoid_exit /* %ebx: no swapgs flag */
23038 CFI_ENDPROC
23039-END(\sym)
23040+ENDPROC(\sym)
23041 .endm
23042
23043 zeroentry divide_error do_divide_error
23044@@ -1327,9 +1816,10 @@ gs_change:
23045 2: mfence /* workaround */
23046 SWAPGS
23047 popfq_cfi
23048+ pax_force_retaddr
23049 ret
23050 CFI_ENDPROC
23051-END(native_load_gs_index)
23052+ENDPROC(native_load_gs_index)
23053
23054 _ASM_EXTABLE(gs_change,bad_gs)
23055 .section .fixup,"ax"
23056@@ -1357,9 +1847,10 @@ ENTRY(call_softirq)
23057 CFI_DEF_CFA_REGISTER rsp
23058 CFI_ADJUST_CFA_OFFSET -8
23059 decl PER_CPU_VAR(irq_count)
23060+ pax_force_retaddr
23061 ret
23062 CFI_ENDPROC
23063-END(call_softirq)
23064+ENDPROC(call_softirq)
23065
23066 #ifdef CONFIG_XEN
23067 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23068@@ -1397,7 +1888,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23069 decl PER_CPU_VAR(irq_count)
23070 jmp error_exit
23071 CFI_ENDPROC
23072-END(xen_do_hypervisor_callback)
23073+ENDPROC(xen_do_hypervisor_callback)
23074
23075 /*
23076 * Hypervisor uses this for application faults while it executes.
23077@@ -1456,7 +1947,7 @@ ENTRY(xen_failsafe_callback)
23078 SAVE_ALL
23079 jmp error_exit
23080 CFI_ENDPROC
23081-END(xen_failsafe_callback)
23082+ENDPROC(xen_failsafe_callback)
23083
23084 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23085 xen_hvm_callback_vector xen_evtchn_do_upcall
23086@@ -1508,18 +1999,33 @@ ENTRY(paranoid_exit)
23087 DEFAULT_FRAME
23088 DISABLE_INTERRUPTS(CLBR_NONE)
23089 TRACE_IRQS_OFF_DEBUG
23090- testl %ebx,%ebx /* swapgs needed? */
23091+ testl $1,%ebx /* swapgs needed? */
23092 jnz paranoid_restore
23093- testl $3,CS(%rsp)
23094+ testb $3,CS(%rsp)
23095 jnz paranoid_userspace
23096+#ifdef CONFIG_PAX_MEMORY_UDEREF
23097+ pax_exit_kernel
23098+ TRACE_IRQS_IRETQ 0
23099+ SWAPGS_UNSAFE_STACK
23100+ RESTORE_ALL 8
23101+ pax_force_retaddr_bts
23102+ jmp irq_return
23103+#endif
23104 paranoid_swapgs:
23105+#ifdef CONFIG_PAX_MEMORY_UDEREF
23106+ pax_exit_kernel_user
23107+#else
23108+ pax_exit_kernel
23109+#endif
23110 TRACE_IRQS_IRETQ 0
23111 SWAPGS_UNSAFE_STACK
23112 RESTORE_ALL 8
23113 jmp irq_return
23114 paranoid_restore:
23115+ pax_exit_kernel
23116 TRACE_IRQS_IRETQ_DEBUG 0
23117 RESTORE_ALL 8
23118+ pax_force_retaddr_bts
23119 jmp irq_return
23120 paranoid_userspace:
23121 GET_THREAD_INFO(%rcx)
23122@@ -1548,7 +2054,7 @@ paranoid_schedule:
23123 TRACE_IRQS_OFF
23124 jmp paranoid_userspace
23125 CFI_ENDPROC
23126-END(paranoid_exit)
23127+ENDPROC(paranoid_exit)
23128
23129 /*
23130 * Exception entry point. This expects an error code/orig_rax on the stack.
23131@@ -1575,12 +2081,13 @@ ENTRY(error_entry)
23132 movq_cfi r14, R14+8
23133 movq_cfi r15, R15+8
23134 xorl %ebx,%ebx
23135- testl $3,CS+8(%rsp)
23136+ testb $3,CS+8(%rsp)
23137 je error_kernelspace
23138 error_swapgs:
23139 SWAPGS
23140 error_sti:
23141 TRACE_IRQS_OFF
23142+ pax_force_retaddr_bts
23143 ret
23144
23145 /*
23146@@ -1607,7 +2114,7 @@ bstep_iret:
23147 movq %rcx,RIP+8(%rsp)
23148 jmp error_swapgs
23149 CFI_ENDPROC
23150-END(error_entry)
23151+ENDPROC(error_entry)
23152
23153
23154 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23155@@ -1618,7 +2125,7 @@ ENTRY(error_exit)
23156 DISABLE_INTERRUPTS(CLBR_NONE)
23157 TRACE_IRQS_OFF
23158 GET_THREAD_INFO(%rcx)
23159- testl %eax,%eax
23160+ testl $1,%eax
23161 jne retint_kernel
23162 LOCKDEP_SYS_EXIT_IRQ
23163 movl TI_flags(%rcx),%edx
23164@@ -1627,7 +2134,7 @@ ENTRY(error_exit)
23165 jnz retint_careful
23166 jmp retint_swapgs
23167 CFI_ENDPROC
23168-END(error_exit)
23169+ENDPROC(error_exit)
23170
23171 /*
23172 * Test if a given stack is an NMI stack or not.
23173@@ -1685,9 +2192,11 @@ ENTRY(nmi)
23174 * If %cs was not the kernel segment, then the NMI triggered in user
23175 * space, which means it is definitely not nested.
23176 */
23177+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23178+ je 1f
23179 cmpl $__KERNEL_CS, 16(%rsp)
23180 jne first_nmi
23181-
23182+1:
23183 /*
23184 * Check the special variable on the stack to see if NMIs are
23185 * executing.
23186@@ -1721,8 +2230,7 @@ nested_nmi:
23187
23188 1:
23189 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23190- leaq -1*8(%rsp), %rdx
23191- movq %rdx, %rsp
23192+ subq $8, %rsp
23193 CFI_ADJUST_CFA_OFFSET 1*8
23194 leaq -10*8(%rsp), %rdx
23195 pushq_cfi $__KERNEL_DS
23196@@ -1740,6 +2248,7 @@ nested_nmi_out:
23197 CFI_RESTORE rdx
23198
23199 /* No need to check faults here */
23200+# pax_force_retaddr_bts
23201 INTERRUPT_RETURN
23202
23203 CFI_RESTORE_STATE
23204@@ -1852,9 +2361,11 @@ end_repeat_nmi:
23205 * NMI itself takes a page fault, the page fault that was preempted
23206 * will read the information from the NMI page fault and not the
23207 * origin fault. Save it off and restore it if it changes.
23208- * Use the r12 callee-saved register.
23209+ * Use the r13 callee-saved register.
23210 */
23211- movq %cr2, %r12
23212+ movq %cr2, %r13
23213+
23214+ pax_enter_kernel_nmi
23215
23216 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23217 movq %rsp,%rdi
23218@@ -1863,31 +2374,36 @@ end_repeat_nmi:
23219
23220 /* Did the NMI take a page fault? Restore cr2 if it did */
23221 movq %cr2, %rcx
23222- cmpq %rcx, %r12
23223+ cmpq %rcx, %r13
23224 je 1f
23225- movq %r12, %cr2
23226+ movq %r13, %cr2
23227 1:
23228
23229- testl %ebx,%ebx /* swapgs needed? */
23230+ testl $1,%ebx /* swapgs needed? */
23231 jnz nmi_restore
23232 nmi_swapgs:
23233 SWAPGS_UNSAFE_STACK
23234 nmi_restore:
23235+ pax_exit_kernel_nmi
23236 /* Pop the extra iret frame at once */
23237 RESTORE_ALL 6*8
23238+ testb $3, 8(%rsp)
23239+ jnz 1f
23240+ pax_force_retaddr_bts
23241+1:
23242
23243 /* Clear the NMI executing stack variable */
23244 movq $0, 5*8(%rsp)
23245 jmp irq_return
23246 CFI_ENDPROC
23247-END(nmi)
23248+ENDPROC(nmi)
23249
23250 ENTRY(ignore_sysret)
23251 CFI_STARTPROC
23252 mov $-ENOSYS,%eax
23253 sysret
23254 CFI_ENDPROC
23255-END(ignore_sysret)
23256+ENDPROC(ignore_sysret)
23257
23258 /*
23259 * End of kprobes section
23260diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23261index d4bdd25..912664c 100644
23262--- a/arch/x86/kernel/ftrace.c
23263+++ b/arch/x86/kernel/ftrace.c
23264@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23265 {
23266 unsigned char replaced[MCOUNT_INSN_SIZE];
23267
23268+ ip = ktla_ktva(ip);
23269+
23270 /*
23271 * Note: Due to modules and __init, code can
23272 * disappear and change, we need to protect against faulting
23273@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23274 unsigned char old[MCOUNT_INSN_SIZE], *new;
23275 int ret;
23276
23277- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23278+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23279 new = ftrace_call_replace(ip, (unsigned long)func);
23280
23281 /* See comment above by declaration of modifying_ftrace_code */
23282@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23283 /* Also update the regs callback function */
23284 if (!ret) {
23285 ip = (unsigned long)(&ftrace_regs_call);
23286- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23287+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23288 new = ftrace_call_replace(ip, (unsigned long)func);
23289 ret = ftrace_modify_code(ip, old, new);
23290 }
23291@@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23292 * kernel identity mapping to modify code.
23293 */
23294 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23295- ip = (unsigned long)__va(__pa_symbol(ip));
23296+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23297
23298 return probe_kernel_write((void *)ip, val, size);
23299 }
23300@@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23301 unsigned char replaced[MCOUNT_INSN_SIZE];
23302 unsigned char brk = BREAKPOINT_INSTRUCTION;
23303
23304- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23305+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23306 return -EFAULT;
23307
23308 /* Make sure it is what we expect it to be */
23309@@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23310 return ret;
23311
23312 fail_update:
23313- probe_kernel_write((void *)ip, &old_code[0], 1);
23314+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23315 goto out;
23316 }
23317
23318@@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23319 {
23320 unsigned char code[MCOUNT_INSN_SIZE];
23321
23322+ ip = ktla_ktva(ip);
23323+
23324 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23325 return -EFAULT;
23326
23327diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23328index 1be8e43..d9b9ef6 100644
23329--- a/arch/x86/kernel/head64.c
23330+++ b/arch/x86/kernel/head64.c
23331@@ -67,12 +67,12 @@ again:
23332 pgd = *pgd_p;
23333
23334 /*
23335- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23336- * critical -- __PAGE_OFFSET would point us back into the dynamic
23337+ * The use of __early_va rather than __va here is critical:
23338+ * __va would point us back into the dynamic
23339 * range and we might end up looping forever...
23340 */
23341 if (pgd)
23342- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23343+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23344 else {
23345 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23346 reset_early_page_tables();
23347@@ -82,13 +82,13 @@ again:
23348 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23349 for (i = 0; i < PTRS_PER_PUD; i++)
23350 pud_p[i] = 0;
23351- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23352+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23353 }
23354 pud_p += pud_index(address);
23355 pud = *pud_p;
23356
23357 if (pud)
23358- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23359+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23360 else {
23361 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23362 reset_early_page_tables();
23363@@ -98,7 +98,7 @@ again:
23364 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23365 for (i = 0; i < PTRS_PER_PMD; i++)
23366 pmd_p[i] = 0;
23367- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23368+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23369 }
23370 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23371 pmd_p[pmd_index(address)] = pmd;
23372@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23373 if (console_loglevel == 10)
23374 early_printk("Kernel alive\n");
23375
23376- clear_page(init_level4_pgt);
23377 /* set init_level4_pgt kernel high mapping*/
23378 init_level4_pgt[511] = early_level4_pgt[511];
23379
23380diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23381index 81ba276..30c5411 100644
23382--- a/arch/x86/kernel/head_32.S
23383+++ b/arch/x86/kernel/head_32.S
23384@@ -26,6 +26,12 @@
23385 /* Physical address */
23386 #define pa(X) ((X) - __PAGE_OFFSET)
23387
23388+#ifdef CONFIG_PAX_KERNEXEC
23389+#define ta(X) (X)
23390+#else
23391+#define ta(X) ((X) - __PAGE_OFFSET)
23392+#endif
23393+
23394 /*
23395 * References to members of the new_cpu_data structure.
23396 */
23397@@ -55,11 +61,7 @@
23398 * and small than max_low_pfn, otherwise will waste some page table entries
23399 */
23400
23401-#if PTRS_PER_PMD > 1
23402-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23403-#else
23404-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23405-#endif
23406+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23407
23408 /* Number of possible pages in the lowmem region */
23409 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23410@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23411 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23412
23413 /*
23414+ * Real beginning of normal "text" segment
23415+ */
23416+ENTRY(stext)
23417+ENTRY(_stext)
23418+
23419+/*
23420 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23421 * %esi points to the real-mode code as a 32-bit pointer.
23422 * CS and DS must be 4 GB flat segments, but we don't depend on
23423@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23424 * can.
23425 */
23426 __HEAD
23427+
23428+#ifdef CONFIG_PAX_KERNEXEC
23429+ jmp startup_32
23430+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23431+.fill PAGE_SIZE-5,1,0xcc
23432+#endif
23433+
23434 ENTRY(startup_32)
23435 movl pa(stack_start),%ecx
23436
23437@@ -106,6 +121,59 @@ ENTRY(startup_32)
23438 2:
23439 leal -__PAGE_OFFSET(%ecx),%esp
23440
23441+#ifdef CONFIG_SMP
23442+ movl $pa(cpu_gdt_table),%edi
23443+ movl $__per_cpu_load,%eax
23444+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23445+ rorl $16,%eax
23446+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23447+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23448+ movl $__per_cpu_end - 1,%eax
23449+ subl $__per_cpu_start,%eax
23450+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23451+#endif
23452+
23453+#ifdef CONFIG_PAX_MEMORY_UDEREF
23454+ movl $NR_CPUS,%ecx
23455+ movl $pa(cpu_gdt_table),%edi
23456+1:
23457+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23458+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23459+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23460+ addl $PAGE_SIZE_asm,%edi
23461+ loop 1b
23462+#endif
23463+
23464+#ifdef CONFIG_PAX_KERNEXEC
23465+ movl $pa(boot_gdt),%edi
23466+ movl $__LOAD_PHYSICAL_ADDR,%eax
23467+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23468+ rorl $16,%eax
23469+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23470+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23471+ rorl $16,%eax
23472+
23473+ ljmp $(__BOOT_CS),$1f
23474+1:
23475+
23476+ movl $NR_CPUS,%ecx
23477+ movl $pa(cpu_gdt_table),%edi
23478+ addl $__PAGE_OFFSET,%eax
23479+1:
23480+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23481+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23482+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23483+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23484+ rorl $16,%eax
23485+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23486+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23487+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23488+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23489+ rorl $16,%eax
23490+ addl $PAGE_SIZE_asm,%edi
23491+ loop 1b
23492+#endif
23493+
23494 /*
23495 * Clear BSS first so that there are no surprises...
23496 */
23497@@ -201,8 +269,11 @@ ENTRY(startup_32)
23498 movl %eax, pa(max_pfn_mapped)
23499
23500 /* Do early initialization of the fixmap area */
23501- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23502- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23503+#ifdef CONFIG_COMPAT_VDSO
23504+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23505+#else
23506+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23507+#endif
23508 #else /* Not PAE */
23509
23510 page_pde_offset = (__PAGE_OFFSET >> 20);
23511@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23512 movl %eax, pa(max_pfn_mapped)
23513
23514 /* Do early initialization of the fixmap area */
23515- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23516- movl %eax,pa(initial_page_table+0xffc)
23517+#ifdef CONFIG_COMPAT_VDSO
23518+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23519+#else
23520+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23521+#endif
23522 #endif
23523
23524 #ifdef CONFIG_PARAVIRT
23525@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23526 cmpl $num_subarch_entries, %eax
23527 jae bad_subarch
23528
23529- movl pa(subarch_entries)(,%eax,4), %eax
23530- subl $__PAGE_OFFSET, %eax
23531- jmp *%eax
23532+ jmp *pa(subarch_entries)(,%eax,4)
23533
23534 bad_subarch:
23535 WEAK(lguest_entry)
23536@@ -261,10 +333,10 @@ WEAK(xen_entry)
23537 __INITDATA
23538
23539 subarch_entries:
23540- .long default_entry /* normal x86/PC */
23541- .long lguest_entry /* lguest hypervisor */
23542- .long xen_entry /* Xen hypervisor */
23543- .long default_entry /* Moorestown MID */
23544+ .long ta(default_entry) /* normal x86/PC */
23545+ .long ta(lguest_entry) /* lguest hypervisor */
23546+ .long ta(xen_entry) /* Xen hypervisor */
23547+ .long ta(default_entry) /* Moorestown MID */
23548 num_subarch_entries = (. - subarch_entries) / 4
23549 .previous
23550 #else
23551@@ -354,6 +426,7 @@ default_entry:
23552 movl pa(mmu_cr4_features),%eax
23553 movl %eax,%cr4
23554
23555+#ifdef CONFIG_X86_PAE
23556 testb $X86_CR4_PAE, %al # check if PAE is enabled
23557 jz enable_paging
23558
23559@@ -382,6 +455,9 @@ default_entry:
23560 /* Make changes effective */
23561 wrmsr
23562
23563+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23564+#endif
23565+
23566 enable_paging:
23567
23568 /*
23569@@ -449,14 +525,20 @@ is486:
23570 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23571 movl %eax,%ss # after changing gdt.
23572
23573- movl $(__USER_DS),%eax # DS/ES contains default USER segment
23574+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23575 movl %eax,%ds
23576 movl %eax,%es
23577
23578 movl $(__KERNEL_PERCPU), %eax
23579 movl %eax,%fs # set this cpu's percpu
23580
23581+#ifdef CONFIG_CC_STACKPROTECTOR
23582 movl $(__KERNEL_STACK_CANARY),%eax
23583+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23584+ movl $(__USER_DS),%eax
23585+#else
23586+ xorl %eax,%eax
23587+#endif
23588 movl %eax,%gs
23589
23590 xorl %eax,%eax # Clear LDT
23591@@ -512,8 +594,11 @@ setup_once:
23592 * relocation. Manually set base address in stack canary
23593 * segment descriptor.
23594 */
23595- movl $gdt_page,%eax
23596+ movl $cpu_gdt_table,%eax
23597 movl $stack_canary,%ecx
23598+#ifdef CONFIG_SMP
23599+ addl $__per_cpu_load,%ecx
23600+#endif
23601 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23602 shrl $16, %ecx
23603 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23604@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23605 /* This is global to keep gas from relaxing the jumps */
23606 ENTRY(early_idt_handler)
23607 cld
23608- cmpl $2,%ss:early_recursion_flag
23609+ cmpl $1,%ss:early_recursion_flag
23610 je hlt_loop
23611 incl %ss:early_recursion_flag
23612
23613@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23614 pushl (20+6*4)(%esp) /* trapno */
23615 pushl $fault_msg
23616 call printk
23617-#endif
23618 call dump_stack
23619+#endif
23620 hlt_loop:
23621 hlt
23622 jmp hlt_loop
23623@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23624 /* This is the default interrupt "handler" :-) */
23625 ALIGN
23626 ignore_int:
23627- cld
23628 #ifdef CONFIG_PRINTK
23629+ cmpl $2,%ss:early_recursion_flag
23630+ je hlt_loop
23631+ incl %ss:early_recursion_flag
23632+ cld
23633 pushl %eax
23634 pushl %ecx
23635 pushl %edx
23636@@ -612,9 +700,6 @@ ignore_int:
23637 movl $(__KERNEL_DS),%eax
23638 movl %eax,%ds
23639 movl %eax,%es
23640- cmpl $2,early_recursion_flag
23641- je hlt_loop
23642- incl early_recursion_flag
23643 pushl 16(%esp)
23644 pushl 24(%esp)
23645 pushl 32(%esp)
23646@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23647 /*
23648 * BSS section
23649 */
23650-__PAGE_ALIGNED_BSS
23651- .align PAGE_SIZE
23652 #ifdef CONFIG_X86_PAE
23653+.section .initial_pg_pmd,"a",@progbits
23654 initial_pg_pmd:
23655 .fill 1024*KPMDS,4,0
23656 #else
23657+.section .initial_page_table,"a",@progbits
23658 ENTRY(initial_page_table)
23659 .fill 1024,4,0
23660 #endif
23661+.section .initial_pg_fixmap,"a",@progbits
23662 initial_pg_fixmap:
23663 .fill 1024,4,0
23664+.section .empty_zero_page,"a",@progbits
23665 ENTRY(empty_zero_page)
23666 .fill 4096,1,0
23667+.section .swapper_pg_dir,"a",@progbits
23668 ENTRY(swapper_pg_dir)
23669+#ifdef CONFIG_X86_PAE
23670+ .fill 4,8,0
23671+#else
23672 .fill 1024,4,0
23673+#endif
23674
23675 /*
23676 * This starts the data section.
23677 */
23678 #ifdef CONFIG_X86_PAE
23679-__PAGE_ALIGNED_DATA
23680- /* Page-aligned for the benefit of paravirt? */
23681- .align PAGE_SIZE
23682+.section .initial_page_table,"a",@progbits
23683 ENTRY(initial_page_table)
23684 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23685 # if KPMDS == 3
23686@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23687 # error "Kernel PMDs should be 1, 2 or 3"
23688 # endif
23689 .align PAGE_SIZE /* needs to be page-sized too */
23690+
23691+#ifdef CONFIG_PAX_PER_CPU_PGD
23692+ENTRY(cpu_pgd)
23693+ .rept 2*NR_CPUS
23694+ .fill 4,8,0
23695+ .endr
23696+#endif
23697+
23698 #endif
23699
23700 .data
23701 .balign 4
23702 ENTRY(stack_start)
23703- .long init_thread_union+THREAD_SIZE
23704+ .long init_thread_union+THREAD_SIZE-8
23705
23706 __INITRODATA
23707 int_msg:
23708@@ -722,7 +820,7 @@ fault_msg:
23709 * segment size, and 32-bit linear address value:
23710 */
23711
23712- .data
23713+.section .rodata,"a",@progbits
23714 .globl boot_gdt_descr
23715 .globl idt_descr
23716
23717@@ -731,7 +829,7 @@ fault_msg:
23718 .word 0 # 32 bit align gdt_desc.address
23719 boot_gdt_descr:
23720 .word __BOOT_DS+7
23721- .long boot_gdt - __PAGE_OFFSET
23722+ .long pa(boot_gdt)
23723
23724 .word 0 # 32-bit align idt_desc.address
23725 idt_descr:
23726@@ -742,7 +840,7 @@ idt_descr:
23727 .word 0 # 32 bit align gdt_desc.address
23728 ENTRY(early_gdt_descr)
23729 .word GDT_ENTRIES*8-1
23730- .long gdt_page /* Overwritten for secondary CPUs */
23731+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23732
23733 /*
23734 * The boot_gdt must mirror the equivalent in setup.S and is
23735@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23736 .align L1_CACHE_BYTES
23737 ENTRY(boot_gdt)
23738 .fill GDT_ENTRY_BOOT_CS,8,0
23739- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23740- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23741+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23742+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23743+
23744+ .align PAGE_SIZE_asm
23745+ENTRY(cpu_gdt_table)
23746+ .rept NR_CPUS
23747+ .quad 0x0000000000000000 /* NULL descriptor */
23748+ .quad 0x0000000000000000 /* 0x0b reserved */
23749+ .quad 0x0000000000000000 /* 0x13 reserved */
23750+ .quad 0x0000000000000000 /* 0x1b reserved */
23751+
23752+#ifdef CONFIG_PAX_KERNEXEC
23753+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23754+#else
23755+ .quad 0x0000000000000000 /* 0x20 unused */
23756+#endif
23757+
23758+ .quad 0x0000000000000000 /* 0x28 unused */
23759+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23760+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23761+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23762+ .quad 0x0000000000000000 /* 0x4b reserved */
23763+ .quad 0x0000000000000000 /* 0x53 reserved */
23764+ .quad 0x0000000000000000 /* 0x5b reserved */
23765+
23766+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23767+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23768+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23769+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23770+
23771+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23772+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23773+
23774+ /*
23775+ * Segments used for calling PnP BIOS have byte granularity.
23776+ * The code segments and data segments have fixed 64k limits,
23777+ * the transfer segment sizes are set at run time.
23778+ */
23779+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23780+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23781+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23782+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23783+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23784+
23785+ /*
23786+ * The APM segments have byte granularity and their bases
23787+ * are set at run time. All have 64k limits.
23788+ */
23789+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23790+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23791+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23792+
23793+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23794+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23795+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23796+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23797+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23798+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23799+
23800+ /* Be sure this is zeroed to avoid false validations in Xen */
23801+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23802+ .endr
23803diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23804index e1aabdb..fee4fee 100644
23805--- a/arch/x86/kernel/head_64.S
23806+++ b/arch/x86/kernel/head_64.S
23807@@ -20,6 +20,8 @@
23808 #include <asm/processor-flags.h>
23809 #include <asm/percpu.h>
23810 #include <asm/nops.h>
23811+#include <asm/cpufeature.h>
23812+#include <asm/alternative-asm.h>
23813
23814 #ifdef CONFIG_PARAVIRT
23815 #include <asm/asm-offsets.h>
23816@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23817 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23818 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23819 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23820+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23821+L3_VMALLOC_START = pud_index(VMALLOC_START)
23822+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23823+L3_VMALLOC_END = pud_index(VMALLOC_END)
23824+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23825+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23826
23827 .text
23828 __HEAD
23829@@ -89,11 +97,24 @@ startup_64:
23830 * Fixup the physical addresses in the page table
23831 */
23832 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23833+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23834+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23835+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23836+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23837+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23838
23839- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23840- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23841+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23842+#ifndef CONFIG_XEN
23843+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23844+#endif
23845+
23846+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23847+
23848+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23849+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23850
23851 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23852+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23853
23854 /*
23855 * Set up the identity mapping for the switchover. These
23856@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
23857 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23858 1:
23859
23860- /* Enable PAE mode and PGE */
23861- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23862+ /* Enable PAE mode and PSE/PGE */
23863+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23864 movq %rcx, %cr4
23865
23866 /* Setup early boot stage 4 level pagetables. */
23867@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
23868 movl $MSR_EFER, %ecx
23869 rdmsr
23870 btsl $_EFER_SCE, %eax /* Enable System Call */
23871- btl $20,%edi /* No Execute supported? */
23872+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23873 jnc 1f
23874 btsl $_EFER_NX, %eax
23875 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23876+#ifndef CONFIG_EFI
23877+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
23878+#endif
23879+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
23880+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
23881+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
23882+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
23883+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
23884+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23885 1: wrmsr /* Make changes effective */
23886
23887 /* Setup cr0 */
23888@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
23889 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23890 * address given in m16:64.
23891 */
23892+ pax_set_fptr_mask
23893 movq initial_code(%rip),%rax
23894 pushq $0 # fake return address to stop unwinder
23895 pushq $__KERNEL_CS # set correct cs
23896@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
23897 call dump_stack
23898 #ifdef CONFIG_KALLSYMS
23899 leaq early_idt_ripmsg(%rip),%rdi
23900- movq 40(%rsp),%rsi # %rip again
23901+ movq 88(%rsp),%rsi # %rip again
23902 call __print_symbol
23903 #endif
23904 #endif /* EARLY_PRINTK */
23905@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
23906 early_recursion_flag:
23907 .long 0
23908
23909+ .section .rodata,"a",@progbits
23910 #ifdef CONFIG_EARLY_PRINTK
23911 early_idt_msg:
23912 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23913@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
23914 NEXT_PAGE(early_dynamic_pgts)
23915 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23916
23917- .data
23918+ .section .rodata,"a",@progbits
23919
23920-#ifndef CONFIG_XEN
23921 NEXT_PAGE(init_level4_pgt)
23922- .fill 512,8,0
23923-#else
23924-NEXT_PAGE(init_level4_pgt)
23925- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23926 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23927 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23928+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23929+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23930+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23931+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23932+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23933+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23934 .org init_level4_pgt + L4_START_KERNEL*8, 0
23935 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23936 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23937
23938+#ifdef CONFIG_PAX_PER_CPU_PGD
23939+NEXT_PAGE(cpu_pgd)
23940+ .rept 2*NR_CPUS
23941+ .fill 512,8,0
23942+ .endr
23943+#endif
23944+
23945 NEXT_PAGE(level3_ident_pgt)
23946 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23947+#ifdef CONFIG_XEN
23948 .fill 511, 8, 0
23949+#else
23950+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23951+ .fill 510,8,0
23952+#endif
23953+
23954+NEXT_PAGE(level3_vmalloc_start_pgt)
23955+ .fill 512,8,0
23956+
23957+NEXT_PAGE(level3_vmalloc_end_pgt)
23958+ .fill 512,8,0
23959+
23960+NEXT_PAGE(level3_vmemmap_pgt)
23961+ .fill L3_VMEMMAP_START,8,0
23962+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23963+
23964 NEXT_PAGE(level2_ident_pgt)
23965- /* Since I easily can, map the first 1G.
23966+ /* Since I easily can, map the first 2G.
23967 * Don't set NX because code runs from these pages.
23968 */
23969- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23970-#endif
23971+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23972
23973 NEXT_PAGE(level3_kernel_pgt)
23974 .fill L3_START_KERNEL,8,0
23975@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
23976 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23977 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23978
23979+NEXT_PAGE(level2_vmemmap_pgt)
23980+ .fill 512,8,0
23981+
23982 NEXT_PAGE(level2_kernel_pgt)
23983 /*
23984 * 512 MB kernel mapping. We spend a full page on this pagetable
23985@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
23986 NEXT_PAGE(level2_fixmap_pgt)
23987 .fill 506,8,0
23988 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23989- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23990- .fill 5,8,0
23991+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23992+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23993+ .fill 4,8,0
23994
23995 NEXT_PAGE(level1_fixmap_pgt)
23996 .fill 512,8,0
23997
23998+NEXT_PAGE(level1_vsyscall_pgt)
23999+ .fill 512,8,0
24000+
24001 #undef PMDS
24002
24003- .data
24004+ .align PAGE_SIZE
24005+ENTRY(cpu_gdt_table)
24006+ .rept NR_CPUS
24007+ .quad 0x0000000000000000 /* NULL descriptor */
24008+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24009+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24010+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24011+ .quad 0x00cffb000000ffff /* __USER32_CS */
24012+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24013+ .quad 0x00affb000000ffff /* __USER_CS */
24014+
24015+#ifdef CONFIG_PAX_KERNEXEC
24016+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24017+#else
24018+ .quad 0x0 /* unused */
24019+#endif
24020+
24021+ .quad 0,0 /* TSS */
24022+ .quad 0,0 /* LDT */
24023+ .quad 0,0,0 /* three TLS descriptors */
24024+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24025+ /* asm/segment.h:GDT_ENTRIES must match this */
24026+
24027+#ifdef CONFIG_PAX_MEMORY_UDEREF
24028+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24029+#else
24030+ .quad 0x0 /* unused */
24031+#endif
24032+
24033+ /* zero the remaining page */
24034+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24035+ .endr
24036+
24037 .align 16
24038 .globl early_gdt_descr
24039 early_gdt_descr:
24040 .word GDT_ENTRIES*8-1
24041 early_gdt_descr_base:
24042- .quad INIT_PER_CPU_VAR(gdt_page)
24043+ .quad cpu_gdt_table
24044
24045 ENTRY(phys_base)
24046 /* This must match the first entry in level2_kernel_pgt */
24047 .quad 0x0000000000000000
24048
24049 #include "../../x86/xen/xen-head.S"
24050-
24051- __PAGE_ALIGNED_BSS
24052+
24053+ .section .rodata,"a",@progbits
24054 NEXT_PAGE(empty_zero_page)
24055 .skip PAGE_SIZE
24056diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24057index 0fa6912..b37438b 100644
24058--- a/arch/x86/kernel/i386_ksyms_32.c
24059+++ b/arch/x86/kernel/i386_ksyms_32.c
24060@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24061 EXPORT_SYMBOL(cmpxchg8b_emu);
24062 #endif
24063
24064+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24065+
24066 /* Networking helper routines. */
24067 EXPORT_SYMBOL(csum_partial_copy_generic);
24068+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24069+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24070
24071 EXPORT_SYMBOL(__get_user_1);
24072 EXPORT_SYMBOL(__get_user_2);
24073@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
24074
24075 EXPORT_SYMBOL(csum_partial);
24076 EXPORT_SYMBOL(empty_zero_page);
24077+
24078+#ifdef CONFIG_PAX_KERNEXEC
24079+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24080+#endif
24081+
24082+#ifdef CONFIG_PAX_PER_CPU_PGD
24083+EXPORT_SYMBOL(cpu_pgd);
24084+#endif
24085diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24086index 5d576ab..1403a03 100644
24087--- a/arch/x86/kernel/i387.c
24088+++ b/arch/x86/kernel/i387.c
24089@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24090 static inline bool interrupted_user_mode(void)
24091 {
24092 struct pt_regs *regs = get_irq_regs();
24093- return regs && user_mode_vm(regs);
24094+ return regs && user_mode(regs);
24095 }
24096
24097 /*
24098diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24099index 9a5c460..84868423 100644
24100--- a/arch/x86/kernel/i8259.c
24101+++ b/arch/x86/kernel/i8259.c
24102@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24103 static void make_8259A_irq(unsigned int irq)
24104 {
24105 disable_irq_nosync(irq);
24106- io_apic_irqs &= ~(1<<irq);
24107+ io_apic_irqs &= ~(1UL<<irq);
24108 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24109 i8259A_chip.name);
24110 enable_irq(irq);
24111@@ -209,7 +209,7 @@ spurious_8259A_irq:
24112 "spurious 8259A interrupt: IRQ%d.\n", irq);
24113 spurious_irq_mask |= irqmask;
24114 }
24115- atomic_inc(&irq_err_count);
24116+ atomic_inc_unchecked(&irq_err_count);
24117 /*
24118 * Theoretically we do not have to handle this IRQ,
24119 * but in Linux this does not cause problems and is
24120@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
24121 /* (slave's support for AEOI in flat mode is to be investigated) */
24122 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24123
24124+ pax_open_kernel();
24125 if (auto_eoi)
24126 /*
24127 * In AEOI mode we just have to mask the interrupt
24128 * when acking.
24129 */
24130- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24131+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24132 else
24133- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24134+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24135+ pax_close_kernel();
24136
24137 udelay(100); /* wait for 8259A to initialize */
24138
24139diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24140index a979b5b..1d6db75 100644
24141--- a/arch/x86/kernel/io_delay.c
24142+++ b/arch/x86/kernel/io_delay.c
24143@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24144 * Quirk table for systems that misbehave (lock up, etc.) if port
24145 * 0x80 is used:
24146 */
24147-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24148+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24149 {
24150 .callback = dmi_io_delay_0xed_port,
24151 .ident = "Compaq Presario V6000",
24152diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24153index 4ddaf66..49d5c18 100644
24154--- a/arch/x86/kernel/ioport.c
24155+++ b/arch/x86/kernel/ioport.c
24156@@ -6,6 +6,7 @@
24157 #include <linux/sched.h>
24158 #include <linux/kernel.h>
24159 #include <linux/capability.h>
24160+#include <linux/security.h>
24161 #include <linux/errno.h>
24162 #include <linux/types.h>
24163 #include <linux/ioport.h>
24164@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24165 return -EINVAL;
24166 if (turn_on && !capable(CAP_SYS_RAWIO))
24167 return -EPERM;
24168+#ifdef CONFIG_GRKERNSEC_IO
24169+ if (turn_on && grsec_disable_privio) {
24170+ gr_handle_ioperm();
24171+ return -ENODEV;
24172+ }
24173+#endif
24174
24175 /*
24176 * If it's the first ioperm() call in this thread's lifetime, set the
24177@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24178 * because the ->io_bitmap_max value must match the bitmap
24179 * contents:
24180 */
24181- tss = &per_cpu(init_tss, get_cpu());
24182+ tss = init_tss + get_cpu();
24183
24184 if (turn_on)
24185 bitmap_clear(t->io_bitmap_ptr, from, num);
24186@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24187 if (level > old) {
24188 if (!capable(CAP_SYS_RAWIO))
24189 return -EPERM;
24190+#ifdef CONFIG_GRKERNSEC_IO
24191+ if (grsec_disable_privio) {
24192+ gr_handle_iopl();
24193+ return -ENODEV;
24194+ }
24195+#endif
24196 }
24197 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24198 t->iopl = level << 12;
24199diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24200index 22d0687..e07b2a5 100644
24201--- a/arch/x86/kernel/irq.c
24202+++ b/arch/x86/kernel/irq.c
24203@@ -21,7 +21,7 @@
24204 #define CREATE_TRACE_POINTS
24205 #include <asm/trace/irq_vectors.h>
24206
24207-atomic_t irq_err_count;
24208+atomic_unchecked_t irq_err_count;
24209
24210 /* Function pointer for generic interrupt vector handling */
24211 void (*x86_platform_ipi_callback)(void) = NULL;
24212@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24213 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24214 seq_printf(p, " Machine check polls\n");
24215 #endif
24216- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24217+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24218 #if defined(CONFIG_X86_IO_APIC)
24219- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24220+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24221 #endif
24222 return 0;
24223 }
24224@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24225
24226 u64 arch_irq_stat(void)
24227 {
24228- u64 sum = atomic_read(&irq_err_count);
24229+ u64 sum = atomic_read_unchecked(&irq_err_count);
24230 return sum;
24231 }
24232
24233diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24234index 4186755..784efa0 100644
24235--- a/arch/x86/kernel/irq_32.c
24236+++ b/arch/x86/kernel/irq_32.c
24237@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24238 __asm__ __volatile__("andl %%esp,%0" :
24239 "=r" (sp) : "0" (THREAD_SIZE - 1));
24240
24241- return sp < (sizeof(struct thread_info) + STACK_WARN);
24242+ return sp < STACK_WARN;
24243 }
24244
24245 static void print_stack_overflow(void)
24246@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24247 * per-CPU IRQ handling contexts (thread information and stack)
24248 */
24249 union irq_ctx {
24250- struct thread_info tinfo;
24251- u32 stack[THREAD_SIZE/sizeof(u32)];
24252+ unsigned long previous_esp;
24253+ u32 stack[THREAD_SIZE/sizeof(u32)];
24254 } __attribute__((aligned(THREAD_SIZE)));
24255
24256 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24257@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24258 static inline int
24259 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24260 {
24261- union irq_ctx *curctx, *irqctx;
24262+ union irq_ctx *irqctx;
24263 u32 *isp, arg1, arg2;
24264
24265- curctx = (union irq_ctx *) current_thread_info();
24266 irqctx = __this_cpu_read(hardirq_ctx);
24267
24268 /*
24269@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24270 * handler) we can't do that and just have to keep using the
24271 * current stack (which is the irq stack already after all)
24272 */
24273- if (unlikely(curctx == irqctx))
24274+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24275 return 0;
24276
24277 /* build the stack frame on the IRQ stack */
24278- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24279- irqctx->tinfo.task = curctx->tinfo.task;
24280- irqctx->tinfo.previous_esp = current_stack_pointer;
24281+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24282+ irqctx->previous_esp = current_stack_pointer;
24283
24284- /* Copy the preempt_count so that the [soft]irq checks work. */
24285- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
24286+#ifdef CONFIG_PAX_MEMORY_UDEREF
24287+ __set_fs(MAKE_MM_SEG(0));
24288+#endif
24289
24290 if (unlikely(overflow))
24291 call_on_stack(print_stack_overflow, isp);
24292@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24293 : "0" (irq), "1" (desc), "2" (isp),
24294 "D" (desc->handle_irq)
24295 : "memory", "cc", "ecx");
24296+
24297+#ifdef CONFIG_PAX_MEMORY_UDEREF
24298+ __set_fs(current_thread_info()->addr_limit);
24299+#endif
24300+
24301 return 1;
24302 }
24303
24304@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24305 */
24306 void irq_ctx_init(int cpu)
24307 {
24308- union irq_ctx *irqctx;
24309-
24310 if (per_cpu(hardirq_ctx, cpu))
24311 return;
24312
24313- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24314- THREADINFO_GFP,
24315- THREAD_SIZE_ORDER));
24316- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24317- irqctx->tinfo.cpu = cpu;
24318- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
24319- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24320+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24321+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24322
24323- per_cpu(hardirq_ctx, cpu) = irqctx;
24324-
24325- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24326- THREADINFO_GFP,
24327- THREAD_SIZE_ORDER));
24328- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24329- irqctx->tinfo.cpu = cpu;
24330- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24331-
24332- per_cpu(softirq_ctx, cpu) = irqctx;
24333+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24334+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24335
24336 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24337 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24338@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
24339 asmlinkage void do_softirq(void)
24340 {
24341 unsigned long flags;
24342- struct thread_info *curctx;
24343 union irq_ctx *irqctx;
24344 u32 *isp;
24345
24346@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
24347 local_irq_save(flags);
24348
24349 if (local_softirq_pending()) {
24350- curctx = current_thread_info();
24351 irqctx = __this_cpu_read(softirq_ctx);
24352- irqctx->tinfo.task = curctx->task;
24353- irqctx->tinfo.previous_esp = current_stack_pointer;
24354+ irqctx->previous_esp = current_stack_pointer;
24355
24356 /* build the stack frame on the softirq stack */
24357- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24358+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24359+
24360+#ifdef CONFIG_PAX_MEMORY_UDEREF
24361+ __set_fs(MAKE_MM_SEG(0));
24362+#endif
24363
24364 call_on_stack(__do_softirq, isp);
24365+
24366+#ifdef CONFIG_PAX_MEMORY_UDEREF
24367+ __set_fs(current_thread_info()->addr_limit);
24368+#endif
24369+
24370 /*
24371 * Shouldn't happen, we returned above if in_interrupt():
24372 */
24373@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24374 if (unlikely(!desc))
24375 return false;
24376
24377- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24378+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24379 if (unlikely(overflow))
24380 print_stack_overflow();
24381 desc->handle_irq(irq, desc);
24382diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24383index d04d3ec..ea4b374 100644
24384--- a/arch/x86/kernel/irq_64.c
24385+++ b/arch/x86/kernel/irq_64.c
24386@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24387 u64 estack_top, estack_bottom;
24388 u64 curbase = (u64)task_stack_page(current);
24389
24390- if (user_mode_vm(regs))
24391+ if (user_mode(regs))
24392 return;
24393
24394 if (regs->sp >= curbase + sizeof(struct thread_info) +
24395diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24396index ee11b7d..4df4d0c 100644
24397--- a/arch/x86/kernel/jump_label.c
24398+++ b/arch/x86/kernel/jump_label.c
24399@@ -49,7 +49,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24400 * We are enabling this jump label. If it is not a nop
24401 * then something must have gone wrong.
24402 */
24403- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) != 0))
24404+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5) != 0))
24405 bug_at((void *)entry->code, __LINE__);
24406
24407 code.jump = 0xe9;
24408@@ -64,13 +64,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24409 */
24410 if (init) {
24411 const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
24412- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24413+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24414 bug_at((void *)entry->code, __LINE__);
24415 } else {
24416 code.jump = 0xe9;
24417 code.offset = entry->target -
24418 (entry->code + JUMP_LABEL_NOP_SIZE);
24419- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24420+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24421 bug_at((void *)entry->code, __LINE__);
24422 }
24423 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24424diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24425index 836f832..a8bda67 100644
24426--- a/arch/x86/kernel/kgdb.c
24427+++ b/arch/x86/kernel/kgdb.c
24428@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24429 #ifdef CONFIG_X86_32
24430 switch (regno) {
24431 case GDB_SS:
24432- if (!user_mode_vm(regs))
24433+ if (!user_mode(regs))
24434 *(unsigned long *)mem = __KERNEL_DS;
24435 break;
24436 case GDB_SP:
24437- if (!user_mode_vm(regs))
24438+ if (!user_mode(regs))
24439 *(unsigned long *)mem = kernel_stack_pointer(regs);
24440 break;
24441 case GDB_GS:
24442@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24443 bp->attr.bp_addr = breakinfo[breakno].addr;
24444 bp->attr.bp_len = breakinfo[breakno].len;
24445 bp->attr.bp_type = breakinfo[breakno].type;
24446- info->address = breakinfo[breakno].addr;
24447+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24448+ info->address = ktla_ktva(breakinfo[breakno].addr);
24449+ else
24450+ info->address = breakinfo[breakno].addr;
24451 info->len = breakinfo[breakno].len;
24452 info->type = breakinfo[breakno].type;
24453 val = arch_install_hw_breakpoint(bp);
24454@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24455 case 'k':
24456 /* clear the trace bit */
24457 linux_regs->flags &= ~X86_EFLAGS_TF;
24458- atomic_set(&kgdb_cpu_doing_single_step, -1);
24459+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24460
24461 /* set the trace bit if we're stepping */
24462 if (remcomInBuffer[0] == 's') {
24463 linux_regs->flags |= X86_EFLAGS_TF;
24464- atomic_set(&kgdb_cpu_doing_single_step,
24465+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24466 raw_smp_processor_id());
24467 }
24468
24469@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24470
24471 switch (cmd) {
24472 case DIE_DEBUG:
24473- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24474+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24475 if (user_mode(regs))
24476 return single_step_cont(regs, args);
24477 break;
24478@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24479 #endif /* CONFIG_DEBUG_RODATA */
24480
24481 bpt->type = BP_BREAKPOINT;
24482- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24483+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24484 BREAK_INSTR_SIZE);
24485 if (err)
24486 return err;
24487- err = probe_kernel_write((char *)bpt->bpt_addr,
24488+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24489 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24490 #ifdef CONFIG_DEBUG_RODATA
24491 if (!err)
24492@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24493 return -EBUSY;
24494 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24495 BREAK_INSTR_SIZE);
24496- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24497+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24498 if (err)
24499 return err;
24500 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24501@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24502 if (mutex_is_locked(&text_mutex))
24503 goto knl_write;
24504 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24505- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24506+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24507 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24508 goto knl_write;
24509 return err;
24510 knl_write:
24511 #endif /* CONFIG_DEBUG_RODATA */
24512- return probe_kernel_write((char *)bpt->bpt_addr,
24513+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24514 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24515 }
24516
24517diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24518index 79a3f96..6ba030a 100644
24519--- a/arch/x86/kernel/kprobes/core.c
24520+++ b/arch/x86/kernel/kprobes/core.c
24521@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24522 s32 raddr;
24523 } __packed *insn;
24524
24525- insn = (struct __arch_relative_insn *)from;
24526+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
24527+
24528+ pax_open_kernel();
24529 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24530 insn->op = op;
24531+ pax_close_kernel();
24532 }
24533
24534 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24535@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24536 kprobe_opcode_t opcode;
24537 kprobe_opcode_t *orig_opcodes = opcodes;
24538
24539- if (search_exception_tables((unsigned long)opcodes))
24540+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24541 return 0; /* Page fault may occur on this address. */
24542
24543 retry:
24544@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24545 * for the first byte, we can recover the original instruction
24546 * from it and kp->opcode.
24547 */
24548- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24549+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24550 buf[0] = kp->opcode;
24551- return (unsigned long)buf;
24552+ return ktva_ktla((unsigned long)buf);
24553 }
24554
24555 /*
24556@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24557 /* Another subsystem puts a breakpoint, failed to recover */
24558 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24559 return 0;
24560+ pax_open_kernel();
24561 memcpy(dest, insn.kaddr, insn.length);
24562+ pax_close_kernel();
24563
24564 #ifdef CONFIG_X86_64
24565 if (insn_rip_relative(&insn)) {
24566@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24567 return 0;
24568 }
24569 disp = (u8 *) dest + insn_offset_displacement(&insn);
24570+ pax_open_kernel();
24571 *(s32 *) disp = (s32) newdisp;
24572+ pax_close_kernel();
24573 }
24574 #endif
24575 return insn.length;
24576@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24577 * nor set current_kprobe, because it doesn't use single
24578 * stepping.
24579 */
24580- regs->ip = (unsigned long)p->ainsn.insn;
24581+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24582 preempt_enable_no_resched();
24583 return;
24584 }
24585@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24586 regs->flags &= ~X86_EFLAGS_IF;
24587 /* single step inline if the instruction is an int3 */
24588 if (p->opcode == BREAKPOINT_INSTRUCTION)
24589- regs->ip = (unsigned long)p->addr;
24590+ regs->ip = ktla_ktva((unsigned long)p->addr);
24591 else
24592- regs->ip = (unsigned long)p->ainsn.insn;
24593+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24594 }
24595
24596 /*
24597@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24598 setup_singlestep(p, regs, kcb, 0);
24599 return 1;
24600 }
24601- } else if (*addr != BREAKPOINT_INSTRUCTION) {
24602+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24603 /*
24604 * The breakpoint instruction was removed right
24605 * after we hit it. Another cpu has removed
24606@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24607 " movq %rax, 152(%rsp)\n"
24608 RESTORE_REGS_STRING
24609 " popfq\n"
24610+#ifdef KERNEXEC_PLUGIN
24611+ " btsq $63,(%rsp)\n"
24612+#endif
24613 #else
24614 " pushf\n"
24615 SAVE_REGS_STRING
24616@@ -779,7 +789,7 @@ static void __kprobes
24617 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24618 {
24619 unsigned long *tos = stack_addr(regs);
24620- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24621+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24622 unsigned long orig_ip = (unsigned long)p->addr;
24623 kprobe_opcode_t *insn = p->ainsn.insn;
24624
24625@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24626 struct die_args *args = data;
24627 int ret = NOTIFY_DONE;
24628
24629- if (args->regs && user_mode_vm(args->regs))
24630+ if (args->regs && user_mode(args->regs))
24631 return ret;
24632
24633 switch (val) {
24634diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24635index 898160b..758cde8 100644
24636--- a/arch/x86/kernel/kprobes/opt.c
24637+++ b/arch/x86/kernel/kprobes/opt.c
24638@@ -79,6 +79,7 @@ found:
24639 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24640 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24641 {
24642+ pax_open_kernel();
24643 #ifdef CONFIG_X86_64
24644 *addr++ = 0x48;
24645 *addr++ = 0xbf;
24646@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24647 *addr++ = 0xb8;
24648 #endif
24649 *(unsigned long *)addr = val;
24650+ pax_close_kernel();
24651 }
24652
24653 asm (
24654@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24655 * Verify if the address gap is in 2GB range, because this uses
24656 * a relative jump.
24657 */
24658- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24659+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24660 if (abs(rel) > 0x7fffffff)
24661 return -ERANGE;
24662
24663@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24664 op->optinsn.size = ret;
24665
24666 /* Copy arch-dep-instance from template */
24667- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24668+ pax_open_kernel();
24669+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24670+ pax_close_kernel();
24671
24672 /* Set probe information */
24673 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24674
24675 /* Set probe function call */
24676- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24677+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24678
24679 /* Set returning jmp instruction at the tail of out-of-line buffer */
24680- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24681+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24682 (u8 *)op->kp.addr + op->optinsn.size);
24683
24684 flush_icache_range((unsigned long) buf,
24685@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24686 WARN_ON(kprobe_disabled(&op->kp));
24687
24688 /* Backup instructions which will be replaced by jump address */
24689- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24690+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24691 RELATIVE_ADDR_SIZE);
24692
24693 insn_buf[0] = RELATIVEJUMP_OPCODE;
24694@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24695 /* This kprobe is really able to run optimized path. */
24696 op = container_of(p, struct optimized_kprobe, kp);
24697 /* Detour through copied instructions */
24698- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24699+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24700 if (!reenter)
24701 reset_current_kprobe();
24702 preempt_enable_no_resched();
24703diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24704index ebc9873..1b9724b 100644
24705--- a/arch/x86/kernel/ldt.c
24706+++ b/arch/x86/kernel/ldt.c
24707@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24708 if (reload) {
24709 #ifdef CONFIG_SMP
24710 preempt_disable();
24711- load_LDT(pc);
24712+ load_LDT_nolock(pc);
24713 if (!cpumask_equal(mm_cpumask(current->mm),
24714 cpumask_of(smp_processor_id())))
24715 smp_call_function(flush_ldt, current->mm, 1);
24716 preempt_enable();
24717 #else
24718- load_LDT(pc);
24719+ load_LDT_nolock(pc);
24720 #endif
24721 }
24722 if (oldsize) {
24723@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24724 return err;
24725
24726 for (i = 0; i < old->size; i++)
24727- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24728+ write_ldt_entry(new->ldt, i, old->ldt + i);
24729 return 0;
24730 }
24731
24732@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24733 retval = copy_ldt(&mm->context, &old_mm->context);
24734 mutex_unlock(&old_mm->context.lock);
24735 }
24736+
24737+ if (tsk == current) {
24738+ mm->context.vdso = 0;
24739+
24740+#ifdef CONFIG_X86_32
24741+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24742+ mm->context.user_cs_base = 0UL;
24743+ mm->context.user_cs_limit = ~0UL;
24744+
24745+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24746+ cpus_clear(mm->context.cpu_user_cs_mask);
24747+#endif
24748+
24749+#endif
24750+#endif
24751+
24752+ }
24753+
24754 return retval;
24755 }
24756
24757@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24758 }
24759 }
24760
24761+#ifdef CONFIG_PAX_SEGMEXEC
24762+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24763+ error = -EINVAL;
24764+ goto out_unlock;
24765+ }
24766+#endif
24767+
24768 fill_ldt(&ldt, &ldt_info);
24769 if (oldmode)
24770 ldt.avl = 0;
24771diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24772index 5b19e4d..6476a76 100644
24773--- a/arch/x86/kernel/machine_kexec_32.c
24774+++ b/arch/x86/kernel/machine_kexec_32.c
24775@@ -26,7 +26,7 @@
24776 #include <asm/cacheflush.h>
24777 #include <asm/debugreg.h>
24778
24779-static void set_idt(void *newidt, __u16 limit)
24780+static void set_idt(struct desc_struct *newidt, __u16 limit)
24781 {
24782 struct desc_ptr curidt;
24783
24784@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24785 }
24786
24787
24788-static void set_gdt(void *newgdt, __u16 limit)
24789+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24790 {
24791 struct desc_ptr curgdt;
24792
24793@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24794 }
24795
24796 control_page = page_address(image->control_code_page);
24797- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24798+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24799
24800 relocate_kernel_ptr = control_page;
24801 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24802diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24803index 15c9876..0a43909 100644
24804--- a/arch/x86/kernel/microcode_core.c
24805+++ b/arch/x86/kernel/microcode_core.c
24806@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24807 return NOTIFY_OK;
24808 }
24809
24810-static struct notifier_block __refdata mc_cpu_notifier = {
24811+static struct notifier_block mc_cpu_notifier = {
24812 .notifier_call = mc_cpu_callback,
24813 };
24814
24815diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24816index 5fb2ceb..3ae90bb 100644
24817--- a/arch/x86/kernel/microcode_intel.c
24818+++ b/arch/x86/kernel/microcode_intel.c
24819@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24820
24821 static int get_ucode_user(void *to, const void *from, size_t n)
24822 {
24823- return copy_from_user(to, from, n);
24824+ return copy_from_user(to, (const void __force_user *)from, n);
24825 }
24826
24827 static enum ucode_state
24828 request_microcode_user(int cpu, const void __user *buf, size_t size)
24829 {
24830- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24831+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24832 }
24833
24834 static void microcode_fini_cpu(int cpu)
24835diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24836index 216a4d7..228255a 100644
24837--- a/arch/x86/kernel/module.c
24838+++ b/arch/x86/kernel/module.c
24839@@ -43,15 +43,60 @@ do { \
24840 } while (0)
24841 #endif
24842
24843-void *module_alloc(unsigned long size)
24844+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24845 {
24846- if (PAGE_ALIGN(size) > MODULES_LEN)
24847+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24848 return NULL;
24849 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24850- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24851+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24852 -1, __builtin_return_address(0));
24853 }
24854
24855+void *module_alloc(unsigned long size)
24856+{
24857+
24858+#ifdef CONFIG_PAX_KERNEXEC
24859+ return __module_alloc(size, PAGE_KERNEL);
24860+#else
24861+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24862+#endif
24863+
24864+}
24865+
24866+#ifdef CONFIG_PAX_KERNEXEC
24867+#ifdef CONFIG_X86_32
24868+void *module_alloc_exec(unsigned long size)
24869+{
24870+ struct vm_struct *area;
24871+
24872+ if (size == 0)
24873+ return NULL;
24874+
24875+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24876+ return area ? area->addr : NULL;
24877+}
24878+EXPORT_SYMBOL(module_alloc_exec);
24879+
24880+void module_free_exec(struct module *mod, void *module_region)
24881+{
24882+ vunmap(module_region);
24883+}
24884+EXPORT_SYMBOL(module_free_exec);
24885+#else
24886+void module_free_exec(struct module *mod, void *module_region)
24887+{
24888+ module_free(mod, module_region);
24889+}
24890+EXPORT_SYMBOL(module_free_exec);
24891+
24892+void *module_alloc_exec(unsigned long size)
24893+{
24894+ return __module_alloc(size, PAGE_KERNEL_RX);
24895+}
24896+EXPORT_SYMBOL(module_alloc_exec);
24897+#endif
24898+#endif
24899+
24900 #ifdef CONFIG_X86_32
24901 int apply_relocate(Elf32_Shdr *sechdrs,
24902 const char *strtab,
24903@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24904 unsigned int i;
24905 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24906 Elf32_Sym *sym;
24907- uint32_t *location;
24908+ uint32_t *plocation, location;
24909
24910 DEBUGP("Applying relocate section %u to %u\n",
24911 relsec, sechdrs[relsec].sh_info);
24912 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24913 /* This is where to make the change */
24914- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24915- + rel[i].r_offset;
24916+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24917+ location = (uint32_t)plocation;
24918+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24919+ plocation = ktla_ktva((void *)plocation);
24920 /* This is the symbol it is referring to. Note that all
24921 undefined symbols have been resolved. */
24922 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24923@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24924 switch (ELF32_R_TYPE(rel[i].r_info)) {
24925 case R_386_32:
24926 /* We add the value into the location given */
24927- *location += sym->st_value;
24928+ pax_open_kernel();
24929+ *plocation += sym->st_value;
24930+ pax_close_kernel();
24931 break;
24932 case R_386_PC32:
24933 /* Add the value, subtract its position */
24934- *location += sym->st_value - (uint32_t)location;
24935+ pax_open_kernel();
24936+ *plocation += sym->st_value - location;
24937+ pax_close_kernel();
24938 break;
24939 default:
24940 pr_err("%s: Unknown relocation: %u\n",
24941@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24942 case R_X86_64_NONE:
24943 break;
24944 case R_X86_64_64:
24945+ pax_open_kernel();
24946 *(u64 *)loc = val;
24947+ pax_close_kernel();
24948 break;
24949 case R_X86_64_32:
24950+ pax_open_kernel();
24951 *(u32 *)loc = val;
24952+ pax_close_kernel();
24953 if (val != *(u32 *)loc)
24954 goto overflow;
24955 break;
24956 case R_X86_64_32S:
24957+ pax_open_kernel();
24958 *(s32 *)loc = val;
24959+ pax_close_kernel();
24960 if ((s64)val != *(s32 *)loc)
24961 goto overflow;
24962 break;
24963 case R_X86_64_PC32:
24964 val -= (u64)loc;
24965+ pax_open_kernel();
24966 *(u32 *)loc = val;
24967+ pax_close_kernel();
24968+
24969 #if 0
24970 if ((s64)val != *(s32 *)loc)
24971 goto overflow;
24972diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24973index 88458fa..349f7a4 100644
24974--- a/arch/x86/kernel/msr.c
24975+++ b/arch/x86/kernel/msr.c
24976@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24977 return notifier_from_errno(err);
24978 }
24979
24980-static struct notifier_block __refdata msr_class_cpu_notifier = {
24981+static struct notifier_block msr_class_cpu_notifier = {
24982 .notifier_call = msr_class_cpu_callback,
24983 };
24984
24985diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24986index 6fcb49c..5b3f4ff 100644
24987--- a/arch/x86/kernel/nmi.c
24988+++ b/arch/x86/kernel/nmi.c
24989@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24990 return handled;
24991 }
24992
24993-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24994+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24995 {
24996 struct nmi_desc *desc = nmi_to_desc(type);
24997 unsigned long flags;
24998@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24999 * event confuses some handlers (kdump uses this flag)
25000 */
25001 if (action->flags & NMI_FLAG_FIRST)
25002- list_add_rcu(&action->list, &desc->head);
25003+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25004 else
25005- list_add_tail_rcu(&action->list, &desc->head);
25006+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25007
25008 spin_unlock_irqrestore(&desc->lock, flags);
25009 return 0;
25010@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25011 if (!strcmp(n->name, name)) {
25012 WARN(in_nmi(),
25013 "Trying to free NMI (%s) from NMI context!\n", n->name);
25014- list_del_rcu(&n->list);
25015+ pax_list_del_rcu((struct list_head *)&n->list);
25016 break;
25017 }
25018 }
25019@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25020 dotraplinkage notrace __kprobes void
25021 do_nmi(struct pt_regs *regs, long error_code)
25022 {
25023+
25024+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25025+ if (!user_mode(regs)) {
25026+ unsigned long cs = regs->cs & 0xFFFF;
25027+ unsigned long ip = ktva_ktla(regs->ip);
25028+
25029+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25030+ regs->ip = ip;
25031+ }
25032+#endif
25033+
25034 nmi_nesting_preprocess(regs);
25035
25036 nmi_enter();
25037diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25038index 6d9582e..f746287 100644
25039--- a/arch/x86/kernel/nmi_selftest.c
25040+++ b/arch/x86/kernel/nmi_selftest.c
25041@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25042 {
25043 /* trap all the unknown NMIs we may generate */
25044 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25045- __initdata);
25046+ __initconst);
25047 }
25048
25049 static void __init cleanup_nmi_testsuite(void)
25050@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25051 unsigned long timeout;
25052
25053 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25054- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25055+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25056 nmi_fail = FAILURE;
25057 return;
25058 }
25059diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25060index bbb6c73..24a58ef 100644
25061--- a/arch/x86/kernel/paravirt-spinlocks.c
25062+++ b/arch/x86/kernel/paravirt-spinlocks.c
25063@@ -8,7 +8,7 @@
25064
25065 #include <asm/paravirt.h>
25066
25067-struct pv_lock_ops pv_lock_ops = {
25068+struct pv_lock_ops pv_lock_ops __read_only = {
25069 #ifdef CONFIG_SMP
25070 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25071 .unlock_kick = paravirt_nop,
25072diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25073index 1b10af8..0b58cbc 100644
25074--- a/arch/x86/kernel/paravirt.c
25075+++ b/arch/x86/kernel/paravirt.c
25076@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25077 {
25078 return x;
25079 }
25080+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25081+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25082+#endif
25083
25084 void __init default_banner(void)
25085 {
25086@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25087 if (opfunc == NULL)
25088 /* If there's no function, patch it with a ud2a (BUG) */
25089 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25090- else if (opfunc == _paravirt_nop)
25091+ else if (opfunc == (void *)_paravirt_nop)
25092 /* If the operation is a nop, then nop the callsite */
25093 ret = paravirt_patch_nop();
25094
25095 /* identity functions just return their single argument */
25096- else if (opfunc == _paravirt_ident_32)
25097+ else if (opfunc == (void *)_paravirt_ident_32)
25098 ret = paravirt_patch_ident_32(insnbuf, len);
25099- else if (opfunc == _paravirt_ident_64)
25100+ else if (opfunc == (void *)_paravirt_ident_64)
25101 ret = paravirt_patch_ident_64(insnbuf, len);
25102+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25103+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25104+ ret = paravirt_patch_ident_64(insnbuf, len);
25105+#endif
25106
25107 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25108 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25109@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25110 if (insn_len > len || start == NULL)
25111 insn_len = len;
25112 else
25113- memcpy(insnbuf, start, insn_len);
25114+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25115
25116 return insn_len;
25117 }
25118@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25119 return this_cpu_read(paravirt_lazy_mode);
25120 }
25121
25122-struct pv_info pv_info = {
25123+struct pv_info pv_info __read_only = {
25124 .name = "bare hardware",
25125 .paravirt_enabled = 0,
25126 .kernel_rpl = 0,
25127@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25128 #endif
25129 };
25130
25131-struct pv_init_ops pv_init_ops = {
25132+struct pv_init_ops pv_init_ops __read_only = {
25133 .patch = native_patch,
25134 };
25135
25136-struct pv_time_ops pv_time_ops = {
25137+struct pv_time_ops pv_time_ops __read_only = {
25138 .sched_clock = native_sched_clock,
25139 .steal_clock = native_steal_clock,
25140 };
25141
25142-__visible struct pv_irq_ops pv_irq_ops = {
25143+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25144 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25145 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25146 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25147@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25148 #endif
25149 };
25150
25151-__visible struct pv_cpu_ops pv_cpu_ops = {
25152+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25153 .cpuid = native_cpuid,
25154 .get_debugreg = native_get_debugreg,
25155 .set_debugreg = native_set_debugreg,
25156@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25157 .end_context_switch = paravirt_nop,
25158 };
25159
25160-struct pv_apic_ops pv_apic_ops = {
25161+struct pv_apic_ops pv_apic_ops __read_only= {
25162 #ifdef CONFIG_X86_LOCAL_APIC
25163 .startup_ipi_hook = paravirt_nop,
25164 #endif
25165 };
25166
25167-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25168+#ifdef CONFIG_X86_32
25169+#ifdef CONFIG_X86_PAE
25170+/* 64-bit pagetable entries */
25171+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25172+#else
25173 /* 32-bit pagetable entries */
25174 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25175+#endif
25176 #else
25177 /* 64-bit pagetable entries */
25178 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25179 #endif
25180
25181-struct pv_mmu_ops pv_mmu_ops = {
25182+struct pv_mmu_ops pv_mmu_ops __read_only = {
25183
25184 .read_cr2 = native_read_cr2,
25185 .write_cr2 = native_write_cr2,
25186@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25187 .make_pud = PTE_IDENT,
25188
25189 .set_pgd = native_set_pgd,
25190+ .set_pgd_batched = native_set_pgd_batched,
25191 #endif
25192 #endif /* PAGETABLE_LEVELS >= 3 */
25193
25194@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25195 },
25196
25197 .set_fixmap = native_set_fixmap,
25198+
25199+#ifdef CONFIG_PAX_KERNEXEC
25200+ .pax_open_kernel = native_pax_open_kernel,
25201+ .pax_close_kernel = native_pax_close_kernel,
25202+#endif
25203+
25204 };
25205
25206 EXPORT_SYMBOL_GPL(pv_time_ops);
25207diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25208index 299d493..2ccb0ee 100644
25209--- a/arch/x86/kernel/pci-calgary_64.c
25210+++ b/arch/x86/kernel/pci-calgary_64.c
25211@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25212 tce_space = be64_to_cpu(readq(target));
25213 tce_space = tce_space & TAR_SW_BITS;
25214
25215- tce_space = tce_space & (~specified_table_size);
25216+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25217 info->tce_space = (u64 *)__va(tce_space);
25218 }
25219 }
25220diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25221index 35ccf75..7a15747 100644
25222--- a/arch/x86/kernel/pci-iommu_table.c
25223+++ b/arch/x86/kernel/pci-iommu_table.c
25224@@ -2,7 +2,7 @@
25225 #include <asm/iommu_table.h>
25226 #include <linux/string.h>
25227 #include <linux/kallsyms.h>
25228-
25229+#include <linux/sched.h>
25230
25231 #define DEBUG 1
25232
25233diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25234index 6c483ba..d10ce2f 100644
25235--- a/arch/x86/kernel/pci-swiotlb.c
25236+++ b/arch/x86/kernel/pci-swiotlb.c
25237@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25238 void *vaddr, dma_addr_t dma_addr,
25239 struct dma_attrs *attrs)
25240 {
25241- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25242+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25243 }
25244
25245 static struct dma_map_ops swiotlb_dma_ops = {
25246diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25247index 3fb8d95..254dc51 100644
25248--- a/arch/x86/kernel/process.c
25249+++ b/arch/x86/kernel/process.c
25250@@ -36,7 +36,8 @@
25251 * section. Since TSS's are completely CPU-local, we want them
25252 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25253 */
25254-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25255+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25256+EXPORT_SYMBOL(init_tss);
25257
25258 #ifdef CONFIG_X86_64
25259 static DEFINE_PER_CPU(unsigned char, is_idle);
25260@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25261 task_xstate_cachep =
25262 kmem_cache_create("task_xstate", xstate_size,
25263 __alignof__(union thread_xstate),
25264- SLAB_PANIC | SLAB_NOTRACK, NULL);
25265+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25266 }
25267
25268 /*
25269@@ -105,7 +106,7 @@ void exit_thread(void)
25270 unsigned long *bp = t->io_bitmap_ptr;
25271
25272 if (bp) {
25273- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25274+ struct tss_struct *tss = init_tss + get_cpu();
25275
25276 t->io_bitmap_ptr = NULL;
25277 clear_thread_flag(TIF_IO_BITMAP);
25278@@ -125,6 +126,9 @@ void flush_thread(void)
25279 {
25280 struct task_struct *tsk = current;
25281
25282+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25283+ loadsegment(gs, 0);
25284+#endif
25285 flush_ptrace_hw_breakpoint(tsk);
25286 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25287 drop_init_fpu(tsk);
25288@@ -271,7 +275,7 @@ static void __exit_idle(void)
25289 void exit_idle(void)
25290 {
25291 /* idle loop has pid 0 */
25292- if (current->pid)
25293+ if (task_pid_nr(current))
25294 return;
25295 __exit_idle();
25296 }
25297@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25298 return ret;
25299 }
25300 #endif
25301-void stop_this_cpu(void *dummy)
25302+__noreturn void stop_this_cpu(void *dummy)
25303 {
25304 local_irq_disable();
25305 /*
25306@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25307 }
25308 early_param("idle", idle_setup);
25309
25310-unsigned long arch_align_stack(unsigned long sp)
25311+#ifdef CONFIG_PAX_RANDKSTACK
25312+void pax_randomize_kstack(struct pt_regs *regs)
25313 {
25314- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25315- sp -= get_random_int() % 8192;
25316- return sp & ~0xf;
25317-}
25318+ struct thread_struct *thread = &current->thread;
25319+ unsigned long time;
25320
25321-unsigned long arch_randomize_brk(struct mm_struct *mm)
25322-{
25323- unsigned long range_end = mm->brk + 0x02000000;
25324- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25325-}
25326+ if (!randomize_va_space)
25327+ return;
25328+
25329+ if (v8086_mode(regs))
25330+ return;
25331
25332+ rdtscl(time);
25333+
25334+ /* P4 seems to return a 0 LSB, ignore it */
25335+#ifdef CONFIG_MPENTIUM4
25336+ time &= 0x3EUL;
25337+ time <<= 2;
25338+#elif defined(CONFIG_X86_64)
25339+ time &= 0xFUL;
25340+ time <<= 4;
25341+#else
25342+ time &= 0x1FUL;
25343+ time <<= 3;
25344+#endif
25345+
25346+ thread->sp0 ^= time;
25347+ load_sp0(init_tss + smp_processor_id(), thread);
25348+
25349+#ifdef CONFIG_X86_64
25350+ this_cpu_write(kernel_stack, thread->sp0);
25351+#endif
25352+}
25353+#endif
25354diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25355index 884f98f..ec23e04 100644
25356--- a/arch/x86/kernel/process_32.c
25357+++ b/arch/x86/kernel/process_32.c
25358@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25359 unsigned long thread_saved_pc(struct task_struct *tsk)
25360 {
25361 return ((unsigned long *)tsk->thread.sp)[3];
25362+//XXX return tsk->thread.eip;
25363 }
25364
25365 void __show_regs(struct pt_regs *regs, int all)
25366@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25367 unsigned long sp;
25368 unsigned short ss, gs;
25369
25370- if (user_mode_vm(regs)) {
25371+ if (user_mode(regs)) {
25372 sp = regs->sp;
25373 ss = regs->ss & 0xffff;
25374- gs = get_user_gs(regs);
25375 } else {
25376 sp = kernel_stack_pointer(regs);
25377 savesegment(ss, ss);
25378- savesegment(gs, gs);
25379 }
25380+ gs = get_user_gs(regs);
25381
25382 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25383 (u16)regs->cs, regs->ip, regs->flags,
25384- smp_processor_id());
25385+ raw_smp_processor_id());
25386 print_symbol("EIP is at %s\n", regs->ip);
25387
25388 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25389@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25390 int copy_thread(unsigned long clone_flags, unsigned long sp,
25391 unsigned long arg, struct task_struct *p)
25392 {
25393- struct pt_regs *childregs = task_pt_regs(p);
25394+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25395 struct task_struct *tsk;
25396 int err;
25397
25398 p->thread.sp = (unsigned long) childregs;
25399 p->thread.sp0 = (unsigned long) (childregs+1);
25400+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25401
25402 if (unlikely(p->flags & PF_KTHREAD)) {
25403 /* kernel thread */
25404 memset(childregs, 0, sizeof(struct pt_regs));
25405 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25406- task_user_gs(p) = __KERNEL_STACK_CANARY;
25407- childregs->ds = __USER_DS;
25408- childregs->es = __USER_DS;
25409+ savesegment(gs, childregs->gs);
25410+ childregs->ds = __KERNEL_DS;
25411+ childregs->es = __KERNEL_DS;
25412 childregs->fs = __KERNEL_PERCPU;
25413 childregs->bx = sp; /* function */
25414 childregs->bp = arg;
25415@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25416 struct thread_struct *prev = &prev_p->thread,
25417 *next = &next_p->thread;
25418 int cpu = smp_processor_id();
25419- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25420+ struct tss_struct *tss = init_tss + cpu;
25421 fpu_switch_t fpu;
25422
25423 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25424@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25425 */
25426 lazy_save_gs(prev->gs);
25427
25428+#ifdef CONFIG_PAX_MEMORY_UDEREF
25429+ __set_fs(task_thread_info(next_p)->addr_limit);
25430+#endif
25431+
25432 /*
25433 * Load the per-thread Thread-Local Storage descriptor.
25434 */
25435@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25436 */
25437 arch_end_context_switch(next_p);
25438
25439+ this_cpu_write(current_task, next_p);
25440+ this_cpu_write(current_tinfo, &next_p->tinfo);
25441+
25442 /*
25443 * Restore %gs if needed (which is common)
25444 */
25445@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25446
25447 switch_fpu_finish(next_p, fpu);
25448
25449- this_cpu_write(current_task, next_p);
25450-
25451 return prev_p;
25452 }
25453
25454@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
25455 } while (count++ < 16);
25456 return 0;
25457 }
25458-
25459diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25460index bb1dc51..08dda7f 100644
25461--- a/arch/x86/kernel/process_64.c
25462+++ b/arch/x86/kernel/process_64.c
25463@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25464 struct pt_regs *childregs;
25465 struct task_struct *me = current;
25466
25467- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25468+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25469 childregs = task_pt_regs(p);
25470 p->thread.sp = (unsigned long) childregs;
25471 p->thread.usersp = me->thread.usersp;
25472+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25473 set_tsk_thread_flag(p, TIF_FORK);
25474 p->fpu_counter = 0;
25475 p->thread.io_bitmap_ptr = NULL;
25476@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25477 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25478 savesegment(es, p->thread.es);
25479 savesegment(ds, p->thread.ds);
25480+ savesegment(ss, p->thread.ss);
25481+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25482 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25483
25484 if (unlikely(p->flags & PF_KTHREAD)) {
25485@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25486 struct thread_struct *prev = &prev_p->thread;
25487 struct thread_struct *next = &next_p->thread;
25488 int cpu = smp_processor_id();
25489- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25490+ struct tss_struct *tss = init_tss + cpu;
25491 unsigned fsindex, gsindex;
25492 fpu_switch_t fpu;
25493
25494@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25495 if (unlikely(next->ds | prev->ds))
25496 loadsegment(ds, next->ds);
25497
25498+ savesegment(ss, prev->ss);
25499+ if (unlikely(next->ss != prev->ss))
25500+ loadsegment(ss, next->ss);
25501
25502 /* We must save %fs and %gs before load_TLS() because
25503 * %fs and %gs may be cleared by load_TLS().
25504@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25505 prev->usersp = this_cpu_read(old_rsp);
25506 this_cpu_write(old_rsp, next->usersp);
25507 this_cpu_write(current_task, next_p);
25508+ this_cpu_write(current_tinfo, &next_p->tinfo);
25509
25510- this_cpu_write(kernel_stack,
25511- (unsigned long)task_stack_page(next_p) +
25512- THREAD_SIZE - KERNEL_STACK_OFFSET);
25513+ this_cpu_write(kernel_stack, next->sp0);
25514
25515 /*
25516 * Now maybe reload the debug registers and handle I/O bitmaps
25517@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
25518 if (!p || p == current || p->state == TASK_RUNNING)
25519 return 0;
25520 stack = (unsigned long)task_stack_page(p);
25521- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25522+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25523 return 0;
25524 fp = *(u64 *)(p->thread.sp);
25525 do {
25526- if (fp < (unsigned long)stack ||
25527- fp >= (unsigned long)stack+THREAD_SIZE)
25528+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25529 return 0;
25530 ip = *(u64 *)(fp+8);
25531 if (!in_sched_functions(ip))
25532diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25533index 7461f50..1334029 100644
25534--- a/arch/x86/kernel/ptrace.c
25535+++ b/arch/x86/kernel/ptrace.c
25536@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25537 {
25538 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25539 unsigned long sp = (unsigned long)&regs->sp;
25540- struct thread_info *tinfo;
25541
25542- if (context == (sp & ~(THREAD_SIZE - 1)))
25543+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25544 return sp;
25545
25546- tinfo = (struct thread_info *)context;
25547- if (tinfo->previous_esp)
25548- return tinfo->previous_esp;
25549+ sp = *(unsigned long *)context;
25550+ if (sp)
25551+ return sp;
25552
25553 return (unsigned long)regs;
25554 }
25555@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25556 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25557 {
25558 int i;
25559- int dr7 = 0;
25560+ unsigned long dr7 = 0;
25561 struct arch_hw_breakpoint *info;
25562
25563 for (i = 0; i < HBP_NUM; i++) {
25564@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25565 unsigned long addr, unsigned long data)
25566 {
25567 int ret;
25568- unsigned long __user *datap = (unsigned long __user *)data;
25569+ unsigned long __user *datap = (__force unsigned long __user *)data;
25570
25571 switch (request) {
25572 /* read the word at location addr in the USER area. */
25573@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25574 if ((int) addr < 0)
25575 return -EIO;
25576 ret = do_get_thread_area(child, addr,
25577- (struct user_desc __user *)data);
25578+ (__force struct user_desc __user *) data);
25579 break;
25580
25581 case PTRACE_SET_THREAD_AREA:
25582 if ((int) addr < 0)
25583 return -EIO;
25584 ret = do_set_thread_area(child, addr,
25585- (struct user_desc __user *)data, 0);
25586+ (__force struct user_desc __user *) data, 0);
25587 break;
25588 #endif
25589
25590@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25591
25592 #ifdef CONFIG_X86_64
25593
25594-static struct user_regset x86_64_regsets[] __read_mostly = {
25595+static user_regset_no_const x86_64_regsets[] __read_only = {
25596 [REGSET_GENERAL] = {
25597 .core_note_type = NT_PRSTATUS,
25598 .n = sizeof(struct user_regs_struct) / sizeof(long),
25599@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25600 #endif /* CONFIG_X86_64 */
25601
25602 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25603-static struct user_regset x86_32_regsets[] __read_mostly = {
25604+static user_regset_no_const x86_32_regsets[] __read_only = {
25605 [REGSET_GENERAL] = {
25606 .core_note_type = NT_PRSTATUS,
25607 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25608@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25609 */
25610 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25611
25612-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25613+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25614 {
25615 #ifdef CONFIG_X86_64
25616 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25617@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25618 memset(info, 0, sizeof(*info));
25619 info->si_signo = SIGTRAP;
25620 info->si_code = si_code;
25621- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25622+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25623 }
25624
25625 void user_single_step_siginfo(struct task_struct *tsk,
25626@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25627 # define IS_IA32 0
25628 #endif
25629
25630+#ifdef CONFIG_GRKERNSEC_SETXID
25631+extern void gr_delayed_cred_worker(void);
25632+#endif
25633+
25634 /*
25635 * We must return the syscall number to actually look up in the table.
25636 * This can be -1L to skip running any syscall at all.
25637@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25638
25639 user_exit();
25640
25641+#ifdef CONFIG_GRKERNSEC_SETXID
25642+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25643+ gr_delayed_cred_worker();
25644+#endif
25645+
25646 /*
25647 * If we stepped into a sysenter/syscall insn, it trapped in
25648 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25649@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25650 */
25651 user_exit();
25652
25653+#ifdef CONFIG_GRKERNSEC_SETXID
25654+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25655+ gr_delayed_cred_worker();
25656+#endif
25657+
25658 audit_syscall_exit(regs);
25659
25660 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25661diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25662index a16bae3..1f65f25 100644
25663--- a/arch/x86/kernel/pvclock.c
25664+++ b/arch/x86/kernel/pvclock.c
25665@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
25666 return pv_tsc_khz;
25667 }
25668
25669-static atomic64_t last_value = ATOMIC64_INIT(0);
25670+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25671
25672 void pvclock_resume(void)
25673 {
25674- atomic64_set(&last_value, 0);
25675+ atomic64_set_unchecked(&last_value, 0);
25676 }
25677
25678 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25679@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25680 * updating at the same time, and one of them could be slightly behind,
25681 * making the assumption that last_value always go forward fail to hold.
25682 */
25683- last = atomic64_read(&last_value);
25684+ last = atomic64_read_unchecked(&last_value);
25685 do {
25686 if (ret < last)
25687 return last;
25688- last = atomic64_cmpxchg(&last_value, last, ret);
25689+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25690 } while (unlikely(last != ret));
25691
25692 return ret;
25693diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25694index 618ce26..ec7e21c 100644
25695--- a/arch/x86/kernel/reboot.c
25696+++ b/arch/x86/kernel/reboot.c
25697@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25698
25699 void __noreturn machine_real_restart(unsigned int type)
25700 {
25701+
25702+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25703+ struct desc_struct *gdt;
25704+#endif
25705+
25706 local_irq_disable();
25707
25708 /*
25709@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25710
25711 /* Jump to the identity-mapped low memory code */
25712 #ifdef CONFIG_X86_32
25713- asm volatile("jmpl *%0" : :
25714+
25715+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25716+ gdt = get_cpu_gdt_table(smp_processor_id());
25717+ pax_open_kernel();
25718+#ifdef CONFIG_PAX_MEMORY_UDEREF
25719+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25720+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25721+ loadsegment(ds, __KERNEL_DS);
25722+ loadsegment(es, __KERNEL_DS);
25723+ loadsegment(ss, __KERNEL_DS);
25724+#endif
25725+#ifdef CONFIG_PAX_KERNEXEC
25726+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25727+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25728+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25729+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25730+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25731+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25732+#endif
25733+ pax_close_kernel();
25734+#endif
25735+
25736+ asm volatile("ljmpl *%0" : :
25737 "rm" (real_mode_header->machine_real_restart_asm),
25738 "a" (type));
25739 #else
25740@@ -466,7 +493,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25741 * try to force a triple fault and then cycle between hitting the keyboard
25742 * controller and doing that
25743 */
25744-static void native_machine_emergency_restart(void)
25745+static void __noreturn native_machine_emergency_restart(void)
25746 {
25747 int i;
25748 int attempt = 0;
25749@@ -575,13 +602,13 @@ void native_machine_shutdown(void)
25750 #endif
25751 }
25752
25753-static void __machine_emergency_restart(int emergency)
25754+static void __noreturn __machine_emergency_restart(int emergency)
25755 {
25756 reboot_emergency = emergency;
25757 machine_ops.emergency_restart();
25758 }
25759
25760-static void native_machine_restart(char *__unused)
25761+static void __noreturn native_machine_restart(char *__unused)
25762 {
25763 pr_notice("machine restart\n");
25764
25765@@ -590,7 +617,7 @@ static void native_machine_restart(char *__unused)
25766 __machine_emergency_restart(0);
25767 }
25768
25769-static void native_machine_halt(void)
25770+static void __noreturn native_machine_halt(void)
25771 {
25772 /* Stop other cpus and apics */
25773 machine_shutdown();
25774@@ -600,7 +627,7 @@ static void native_machine_halt(void)
25775 stop_this_cpu(NULL);
25776 }
25777
25778-static void native_machine_power_off(void)
25779+static void __noreturn native_machine_power_off(void)
25780 {
25781 if (pm_power_off) {
25782 if (!reboot_force)
25783@@ -609,9 +636,10 @@ static void native_machine_power_off(void)
25784 }
25785 /* A fallback in case there is no PM info available */
25786 tboot_shutdown(TB_SHUTDOWN_HALT);
25787+ unreachable();
25788 }
25789
25790-struct machine_ops machine_ops = {
25791+struct machine_ops machine_ops __read_only = {
25792 .power_off = native_machine_power_off,
25793 .shutdown = native_machine_shutdown,
25794 .emergency_restart = native_machine_emergency_restart,
25795diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25796index c8e41e9..64049ef 100644
25797--- a/arch/x86/kernel/reboot_fixups_32.c
25798+++ b/arch/x86/kernel/reboot_fixups_32.c
25799@@ -57,7 +57,7 @@ struct device_fixup {
25800 unsigned int vendor;
25801 unsigned int device;
25802 void (*reboot_fixup)(struct pci_dev *);
25803-};
25804+} __do_const;
25805
25806 /*
25807 * PCI ids solely used for fixups_table go here
25808diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25809index 3fd2c69..16ef367 100644
25810--- a/arch/x86/kernel/relocate_kernel_64.S
25811+++ b/arch/x86/kernel/relocate_kernel_64.S
25812@@ -11,6 +11,7 @@
25813 #include <asm/kexec.h>
25814 #include <asm/processor-flags.h>
25815 #include <asm/pgtable_types.h>
25816+#include <asm/alternative-asm.h>
25817
25818 /*
25819 * Must be relocatable PIC code callable as a C function
25820@@ -96,8 +97,7 @@ relocate_kernel:
25821
25822 /* jump to identity mapped page */
25823 addq $(identity_mapped - relocate_kernel), %r8
25824- pushq %r8
25825- ret
25826+ jmp *%r8
25827
25828 identity_mapped:
25829 /* set return address to 0 if not preserving context */
25830@@ -167,6 +167,7 @@ identity_mapped:
25831 xorl %r14d, %r14d
25832 xorl %r15d, %r15d
25833
25834+ pax_force_retaddr 0, 1
25835 ret
25836
25837 1:
25838diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25839index f0de629..a4978a8f 100644
25840--- a/arch/x86/kernel/setup.c
25841+++ b/arch/x86/kernel/setup.c
25842@@ -110,6 +110,7 @@
25843 #include <asm/mce.h>
25844 #include <asm/alternative.h>
25845 #include <asm/prom.h>
25846+#include <asm/boot.h>
25847
25848 /*
25849 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25850@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25851 #endif
25852
25853
25854-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25855-__visible unsigned long mmu_cr4_features;
25856+#ifdef CONFIG_X86_64
25857+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25858+#elif defined(CONFIG_X86_PAE)
25859+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25860 #else
25861-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
25862+__visible unsigned long mmu_cr4_features __read_only;
25863 #endif
25864
25865+void set_in_cr4(unsigned long mask)
25866+{
25867+ unsigned long cr4 = read_cr4();
25868+
25869+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25870+ return;
25871+
25872+ pax_open_kernel();
25873+ mmu_cr4_features |= mask;
25874+ pax_close_kernel();
25875+
25876+ if (trampoline_cr4_features)
25877+ *trampoline_cr4_features = mmu_cr4_features;
25878+ cr4 |= mask;
25879+ write_cr4(cr4);
25880+}
25881+EXPORT_SYMBOL(set_in_cr4);
25882+
25883+void clear_in_cr4(unsigned long mask)
25884+{
25885+ unsigned long cr4 = read_cr4();
25886+
25887+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25888+ return;
25889+
25890+ pax_open_kernel();
25891+ mmu_cr4_features &= ~mask;
25892+ pax_close_kernel();
25893+
25894+ if (trampoline_cr4_features)
25895+ *trampoline_cr4_features = mmu_cr4_features;
25896+ cr4 &= ~mask;
25897+ write_cr4(cr4);
25898+}
25899+EXPORT_SYMBOL(clear_in_cr4);
25900+
25901 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25902 int bootloader_type, bootloader_version;
25903
25904@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25905 * area (640->1Mb) as ram even though it is not.
25906 * take them out.
25907 */
25908- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25909+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25910
25911 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25912 }
25913@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25914 /* called before trim_bios_range() to spare extra sanitize */
25915 static void __init e820_add_kernel_range(void)
25916 {
25917- u64 start = __pa_symbol(_text);
25918+ u64 start = __pa_symbol(ktla_ktva(_text));
25919 u64 size = __pa_symbol(_end) - start;
25920
25921 /*
25922@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25923
25924 void __init setup_arch(char **cmdline_p)
25925 {
25926+#ifdef CONFIG_X86_32
25927+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25928+#else
25929 memblock_reserve(__pa_symbol(_text),
25930 (unsigned long)__bss_stop - (unsigned long)_text);
25931+#endif
25932
25933 early_reserve_initrd();
25934
25935@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25936
25937 if (!boot_params.hdr.root_flags)
25938 root_mountflags &= ~MS_RDONLY;
25939- init_mm.start_code = (unsigned long) _text;
25940- init_mm.end_code = (unsigned long) _etext;
25941+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25942+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25943 init_mm.end_data = (unsigned long) _edata;
25944 init_mm.brk = _brk_end;
25945
25946- code_resource.start = __pa_symbol(_text);
25947- code_resource.end = __pa_symbol(_etext)-1;
25948- data_resource.start = __pa_symbol(_etext);
25949+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25950+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25951+ data_resource.start = __pa_symbol(_sdata);
25952 data_resource.end = __pa_symbol(_edata)-1;
25953 bss_resource.start = __pa_symbol(__bss_start);
25954 bss_resource.end = __pa_symbol(__bss_stop)-1;
25955diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25956index 5cdff03..80fa283 100644
25957--- a/arch/x86/kernel/setup_percpu.c
25958+++ b/arch/x86/kernel/setup_percpu.c
25959@@ -21,19 +21,17 @@
25960 #include <asm/cpu.h>
25961 #include <asm/stackprotector.h>
25962
25963-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25964+#ifdef CONFIG_SMP
25965+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25966 EXPORT_PER_CPU_SYMBOL(cpu_number);
25967+#endif
25968
25969-#ifdef CONFIG_X86_64
25970 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25971-#else
25972-#define BOOT_PERCPU_OFFSET 0
25973-#endif
25974
25975 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25976 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25977
25978-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25979+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25980 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25981 };
25982 EXPORT_SYMBOL(__per_cpu_offset);
25983@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25984 {
25985 #ifdef CONFIG_NEED_MULTIPLE_NODES
25986 pg_data_t *last = NULL;
25987- unsigned int cpu;
25988+ int cpu;
25989
25990 for_each_possible_cpu(cpu) {
25991 int node = early_cpu_to_node(cpu);
25992@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25993 {
25994 #ifdef CONFIG_X86_32
25995 struct desc_struct gdt;
25996+ unsigned long base = per_cpu_offset(cpu);
25997
25998- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25999- 0x2 | DESCTYPE_S, 0x8);
26000- gdt.s = 1;
26001+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26002+ 0x83 | DESCTYPE_S, 0xC);
26003 write_gdt_entry(get_cpu_gdt_table(cpu),
26004 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26005 #endif
26006@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26007 /* alrighty, percpu areas up and running */
26008 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26009 for_each_possible_cpu(cpu) {
26010+#ifdef CONFIG_CC_STACKPROTECTOR
26011+#ifdef CONFIG_X86_32
26012+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26013+#endif
26014+#endif
26015 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26016 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26017 per_cpu(cpu_number, cpu) = cpu;
26018@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26019 */
26020 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26021 #endif
26022+#ifdef CONFIG_CC_STACKPROTECTOR
26023+#ifdef CONFIG_X86_32
26024+ if (!cpu)
26025+ per_cpu(stack_canary.canary, cpu) = canary;
26026+#endif
26027+#endif
26028 /*
26029 * Up to this point, the boot CPU has been using .init.data
26030 * area. Reload any changed state for the boot CPU.
26031diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26032index 9e5de68..16c53cb 100644
26033--- a/arch/x86/kernel/signal.c
26034+++ b/arch/x86/kernel/signal.c
26035@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26036 * Align the stack pointer according to the i386 ABI,
26037 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26038 */
26039- sp = ((sp + 4) & -16ul) - 4;
26040+ sp = ((sp - 12) & -16ul) - 4;
26041 #else /* !CONFIG_X86_32 */
26042 sp = round_down(sp, 16) - 8;
26043 #endif
26044@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26045 }
26046
26047 if (current->mm->context.vdso)
26048- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26049+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26050 else
26051- restorer = &frame->retcode;
26052+ restorer = (void __user *)&frame->retcode;
26053 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26054 restorer = ksig->ka.sa.sa_restorer;
26055
26056@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26057 * reasons and because gdb uses it as a signature to notice
26058 * signal handler stack frames.
26059 */
26060- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26061+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26062
26063 if (err)
26064 return -EFAULT;
26065@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26066 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26067
26068 /* Set up to return from userspace. */
26069- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26070+ if (current->mm->context.vdso)
26071+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26072+ else
26073+ restorer = (void __user *)&frame->retcode;
26074 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26075 restorer = ksig->ka.sa.sa_restorer;
26076 put_user_ex(restorer, &frame->pretcode);
26077@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26078 * reasons and because gdb uses it as a signature to notice
26079 * signal handler stack frames.
26080 */
26081- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26082+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26083 } put_user_catch(err);
26084
26085 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26086@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26087 {
26088 int usig = signr_convert(ksig->sig);
26089 sigset_t *set = sigmask_to_save();
26090- compat_sigset_t *cset = (compat_sigset_t *) set;
26091+ sigset_t sigcopy;
26092+ compat_sigset_t *cset;
26093+
26094+ sigcopy = *set;
26095+
26096+ cset = (compat_sigset_t *) &sigcopy;
26097
26098 /* Set up the stack frame */
26099 if (is_ia32_frame()) {
26100@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26101 } else if (is_x32_frame()) {
26102 return x32_setup_rt_frame(ksig, cset, regs);
26103 } else {
26104- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26105+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26106 }
26107 }
26108
26109diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26110index 7c3a5a6..f0a8961 100644
26111--- a/arch/x86/kernel/smp.c
26112+++ b/arch/x86/kernel/smp.c
26113@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26114
26115 __setup("nonmi_ipi", nonmi_ipi_setup);
26116
26117-struct smp_ops smp_ops = {
26118+struct smp_ops smp_ops __read_only = {
26119 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26120 .smp_prepare_cpus = native_smp_prepare_cpus,
26121 .smp_cpus_done = native_smp_cpus_done,
26122diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26123index 6cacab6..750636a 100644
26124--- a/arch/x86/kernel/smpboot.c
26125+++ b/arch/x86/kernel/smpboot.c
26126@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
26127
26128 enable_start_cpu0 = 0;
26129
26130-#ifdef CONFIG_X86_32
26131- /* switch away from the initial page table */
26132- load_cr3(swapper_pg_dir);
26133- __flush_tlb_all();
26134-#endif
26135-
26136 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26137 barrier();
26138+
26139+ /* switch away from the initial page table */
26140+#ifdef CONFIG_PAX_PER_CPU_PGD
26141+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26142+ __flush_tlb_all();
26143+#elif defined(CONFIG_X86_32)
26144+ load_cr3(swapper_pg_dir);
26145+ __flush_tlb_all();
26146+#endif
26147+
26148 /*
26149 * Check TSC synchronization with the BP:
26150 */
26151@@ -749,6 +753,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26152 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26153 (THREAD_SIZE + task_stack_page(idle))) - 1);
26154 per_cpu(current_task, cpu) = idle;
26155+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26156
26157 #ifdef CONFIG_X86_32
26158 /* Stack for startup_32 can be just as for start_secondary onwards */
26159@@ -756,11 +761,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26160 #else
26161 clear_tsk_thread_flag(idle, TIF_FORK);
26162 initial_gs = per_cpu_offset(cpu);
26163- per_cpu(kernel_stack, cpu) =
26164- (unsigned long)task_stack_page(idle) -
26165- KERNEL_STACK_OFFSET + THREAD_SIZE;
26166+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26167 #endif
26168+
26169+ pax_open_kernel();
26170 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26171+ pax_close_kernel();
26172+
26173 initial_code = (unsigned long)start_secondary;
26174 stack_start = idle->thread.sp;
26175
26176@@ -909,6 +916,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26177 /* the FPU context is blank, nobody can own it */
26178 __cpu_disable_lazy_restore(cpu);
26179
26180+#ifdef CONFIG_PAX_PER_CPU_PGD
26181+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26182+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26183+ KERNEL_PGD_PTRS);
26184+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26185+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26186+ KERNEL_PGD_PTRS);
26187+#endif
26188+
26189 err = do_boot_cpu(apicid, cpu, tidle);
26190 if (err) {
26191 pr_debug("do_boot_cpu failed %d\n", err);
26192diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26193index 9b4d51d..5d28b58 100644
26194--- a/arch/x86/kernel/step.c
26195+++ b/arch/x86/kernel/step.c
26196@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26197 struct desc_struct *desc;
26198 unsigned long base;
26199
26200- seg &= ~7UL;
26201+ seg >>= 3;
26202
26203 mutex_lock(&child->mm->context.lock);
26204- if (unlikely((seg >> 3) >= child->mm->context.size))
26205+ if (unlikely(seg >= child->mm->context.size))
26206 addr = -1L; /* bogus selector, access would fault */
26207 else {
26208 desc = child->mm->context.ldt + seg;
26209@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26210 addr += base;
26211 }
26212 mutex_unlock(&child->mm->context.lock);
26213- }
26214+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26215+ addr = ktla_ktva(addr);
26216
26217 return addr;
26218 }
26219@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26220 unsigned char opcode[15];
26221 unsigned long addr = convert_ip_to_linear(child, regs);
26222
26223+ if (addr == -EINVAL)
26224+ return 0;
26225+
26226 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26227 for (i = 0; i < copied; i++) {
26228 switch (opcode[i]) {
26229diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26230new file mode 100644
26231index 0000000..5877189
26232--- /dev/null
26233+++ b/arch/x86/kernel/sys_i386_32.c
26234@@ -0,0 +1,189 @@
26235+/*
26236+ * This file contains various random system calls that
26237+ * have a non-standard calling sequence on the Linux/i386
26238+ * platform.
26239+ */
26240+
26241+#include <linux/errno.h>
26242+#include <linux/sched.h>
26243+#include <linux/mm.h>
26244+#include <linux/fs.h>
26245+#include <linux/smp.h>
26246+#include <linux/sem.h>
26247+#include <linux/msg.h>
26248+#include <linux/shm.h>
26249+#include <linux/stat.h>
26250+#include <linux/syscalls.h>
26251+#include <linux/mman.h>
26252+#include <linux/file.h>
26253+#include <linux/utsname.h>
26254+#include <linux/ipc.h>
26255+#include <linux/elf.h>
26256+
26257+#include <linux/uaccess.h>
26258+#include <linux/unistd.h>
26259+
26260+#include <asm/syscalls.h>
26261+
26262+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26263+{
26264+ unsigned long pax_task_size = TASK_SIZE;
26265+
26266+#ifdef CONFIG_PAX_SEGMEXEC
26267+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26268+ pax_task_size = SEGMEXEC_TASK_SIZE;
26269+#endif
26270+
26271+ if (flags & MAP_FIXED)
26272+ if (len > pax_task_size || addr > pax_task_size - len)
26273+ return -EINVAL;
26274+
26275+ return 0;
26276+}
26277+
26278+/*
26279+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26280+ */
26281+static unsigned long get_align_mask(void)
26282+{
26283+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26284+ return 0;
26285+
26286+ if (!(current->flags & PF_RANDOMIZE))
26287+ return 0;
26288+
26289+ return va_align.mask;
26290+}
26291+
26292+unsigned long
26293+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26294+ unsigned long len, unsigned long pgoff, unsigned long flags)
26295+{
26296+ struct mm_struct *mm = current->mm;
26297+ struct vm_area_struct *vma;
26298+ unsigned long pax_task_size = TASK_SIZE;
26299+ struct vm_unmapped_area_info info;
26300+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26301+
26302+#ifdef CONFIG_PAX_SEGMEXEC
26303+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26304+ pax_task_size = SEGMEXEC_TASK_SIZE;
26305+#endif
26306+
26307+ pax_task_size -= PAGE_SIZE;
26308+
26309+ if (len > pax_task_size)
26310+ return -ENOMEM;
26311+
26312+ if (flags & MAP_FIXED)
26313+ return addr;
26314+
26315+#ifdef CONFIG_PAX_RANDMMAP
26316+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26317+#endif
26318+
26319+ if (addr) {
26320+ addr = PAGE_ALIGN(addr);
26321+ if (pax_task_size - len >= addr) {
26322+ vma = find_vma(mm, addr);
26323+ if (check_heap_stack_gap(vma, addr, len, offset))
26324+ return addr;
26325+ }
26326+ }
26327+
26328+ info.flags = 0;
26329+ info.length = len;
26330+ info.align_mask = filp ? get_align_mask() : 0;
26331+ info.align_offset = pgoff << PAGE_SHIFT;
26332+ info.threadstack_offset = offset;
26333+
26334+#ifdef CONFIG_PAX_PAGEEXEC
26335+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26336+ info.low_limit = 0x00110000UL;
26337+ info.high_limit = mm->start_code;
26338+
26339+#ifdef CONFIG_PAX_RANDMMAP
26340+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26341+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26342+#endif
26343+
26344+ if (info.low_limit < info.high_limit) {
26345+ addr = vm_unmapped_area(&info);
26346+ if (!IS_ERR_VALUE(addr))
26347+ return addr;
26348+ }
26349+ } else
26350+#endif
26351+
26352+ info.low_limit = mm->mmap_base;
26353+ info.high_limit = pax_task_size;
26354+
26355+ return vm_unmapped_area(&info);
26356+}
26357+
26358+unsigned long
26359+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26360+ const unsigned long len, const unsigned long pgoff,
26361+ const unsigned long flags)
26362+{
26363+ struct vm_area_struct *vma;
26364+ struct mm_struct *mm = current->mm;
26365+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26366+ struct vm_unmapped_area_info info;
26367+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26368+
26369+#ifdef CONFIG_PAX_SEGMEXEC
26370+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26371+ pax_task_size = SEGMEXEC_TASK_SIZE;
26372+#endif
26373+
26374+ pax_task_size -= PAGE_SIZE;
26375+
26376+ /* requested length too big for entire address space */
26377+ if (len > pax_task_size)
26378+ return -ENOMEM;
26379+
26380+ if (flags & MAP_FIXED)
26381+ return addr;
26382+
26383+#ifdef CONFIG_PAX_PAGEEXEC
26384+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26385+ goto bottomup;
26386+#endif
26387+
26388+#ifdef CONFIG_PAX_RANDMMAP
26389+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26390+#endif
26391+
26392+ /* requesting a specific address */
26393+ if (addr) {
26394+ addr = PAGE_ALIGN(addr);
26395+ if (pax_task_size - len >= addr) {
26396+ vma = find_vma(mm, addr);
26397+ if (check_heap_stack_gap(vma, addr, len, offset))
26398+ return addr;
26399+ }
26400+ }
26401+
26402+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26403+ info.length = len;
26404+ info.low_limit = PAGE_SIZE;
26405+ info.high_limit = mm->mmap_base;
26406+ info.align_mask = filp ? get_align_mask() : 0;
26407+ info.align_offset = pgoff << PAGE_SHIFT;
26408+ info.threadstack_offset = offset;
26409+
26410+ addr = vm_unmapped_area(&info);
26411+ if (!(addr & ~PAGE_MASK))
26412+ return addr;
26413+ VM_BUG_ON(addr != -ENOMEM);
26414+
26415+bottomup:
26416+ /*
26417+ * A failed mmap() very likely causes application failure,
26418+ * so fall back to the bottom-up function here. This scenario
26419+ * can happen with large stack limits and large mmap()
26420+ * allocations.
26421+ */
26422+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26423+}
26424diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26425index 30277e2..5664a29 100644
26426--- a/arch/x86/kernel/sys_x86_64.c
26427+++ b/arch/x86/kernel/sys_x86_64.c
26428@@ -81,8 +81,8 @@ out:
26429 return error;
26430 }
26431
26432-static void find_start_end(unsigned long flags, unsigned long *begin,
26433- unsigned long *end)
26434+static void find_start_end(struct mm_struct *mm, unsigned long flags,
26435+ unsigned long *begin, unsigned long *end)
26436 {
26437 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26438 unsigned long new_begin;
26439@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26440 *begin = new_begin;
26441 }
26442 } else {
26443- *begin = current->mm->mmap_legacy_base;
26444+ *begin = mm->mmap_legacy_base;
26445 *end = TASK_SIZE;
26446 }
26447 }
26448@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26449 struct vm_area_struct *vma;
26450 struct vm_unmapped_area_info info;
26451 unsigned long begin, end;
26452+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26453
26454 if (flags & MAP_FIXED)
26455 return addr;
26456
26457- find_start_end(flags, &begin, &end);
26458+ find_start_end(mm, flags, &begin, &end);
26459
26460 if (len > end)
26461 return -ENOMEM;
26462
26463+#ifdef CONFIG_PAX_RANDMMAP
26464+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26465+#endif
26466+
26467 if (addr) {
26468 addr = PAGE_ALIGN(addr);
26469 vma = find_vma(mm, addr);
26470- if (end - len >= addr &&
26471- (!vma || addr + len <= vma->vm_start))
26472+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26473 return addr;
26474 }
26475
26476@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26477 info.high_limit = end;
26478 info.align_mask = filp ? get_align_mask() : 0;
26479 info.align_offset = pgoff << PAGE_SHIFT;
26480+ info.threadstack_offset = offset;
26481 return vm_unmapped_area(&info);
26482 }
26483
26484@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26485 struct mm_struct *mm = current->mm;
26486 unsigned long addr = addr0;
26487 struct vm_unmapped_area_info info;
26488+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26489
26490 /* requested length too big for entire address space */
26491 if (len > TASK_SIZE)
26492@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26493 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26494 goto bottomup;
26495
26496+#ifdef CONFIG_PAX_RANDMMAP
26497+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26498+#endif
26499+
26500 /* requesting a specific address */
26501 if (addr) {
26502 addr = PAGE_ALIGN(addr);
26503 vma = find_vma(mm, addr);
26504- if (TASK_SIZE - len >= addr &&
26505- (!vma || addr + len <= vma->vm_start))
26506+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26507 return addr;
26508 }
26509
26510@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26511 info.high_limit = mm->mmap_base;
26512 info.align_mask = filp ? get_align_mask() : 0;
26513 info.align_offset = pgoff << PAGE_SHIFT;
26514+ info.threadstack_offset = offset;
26515 addr = vm_unmapped_area(&info);
26516 if (!(addr & ~PAGE_MASK))
26517 return addr;
26518diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26519index 91a4496..1730bff 100644
26520--- a/arch/x86/kernel/tboot.c
26521+++ b/arch/x86/kernel/tboot.c
26522@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26523
26524 void tboot_shutdown(u32 shutdown_type)
26525 {
26526- void (*shutdown)(void);
26527+ void (* __noreturn shutdown)(void);
26528
26529 if (!tboot_enabled())
26530 return;
26531@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26532
26533 switch_to_tboot_pt();
26534
26535- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26536+ shutdown = (void *)tboot->shutdown_entry;
26537 shutdown();
26538
26539 /* should not reach here */
26540@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26541 return -ENODEV;
26542 }
26543
26544-static atomic_t ap_wfs_count;
26545+static atomic_unchecked_t ap_wfs_count;
26546
26547 static int tboot_wait_for_aps(int num_aps)
26548 {
26549@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26550 {
26551 switch (action) {
26552 case CPU_DYING:
26553- atomic_inc(&ap_wfs_count);
26554+ atomic_inc_unchecked(&ap_wfs_count);
26555 if (num_online_cpus() == 1)
26556- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26557+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26558 return NOTIFY_BAD;
26559 break;
26560 }
26561@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26562
26563 tboot_create_trampoline();
26564
26565- atomic_set(&ap_wfs_count, 0);
26566+ atomic_set_unchecked(&ap_wfs_count, 0);
26567 register_hotcpu_notifier(&tboot_cpu_notifier);
26568
26569 #ifdef CONFIG_DEBUG_FS
26570diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26571index 24d3c91..d06b473 100644
26572--- a/arch/x86/kernel/time.c
26573+++ b/arch/x86/kernel/time.c
26574@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26575 {
26576 unsigned long pc = instruction_pointer(regs);
26577
26578- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26579+ if (!user_mode(regs) && in_lock_functions(pc)) {
26580 #ifdef CONFIG_FRAME_POINTER
26581- return *(unsigned long *)(regs->bp + sizeof(long));
26582+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26583 #else
26584 unsigned long *sp =
26585 (unsigned long *)kernel_stack_pointer(regs);
26586@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26587 * or above a saved flags. Eflags has bits 22-31 zero,
26588 * kernel addresses don't.
26589 */
26590+
26591+#ifdef CONFIG_PAX_KERNEXEC
26592+ return ktla_ktva(sp[0]);
26593+#else
26594 if (sp[0] >> 22)
26595 return sp[0];
26596 if (sp[1] >> 22)
26597 return sp[1];
26598 #endif
26599+
26600+#endif
26601 }
26602 return pc;
26603 }
26604diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26605index f7fec09..9991981 100644
26606--- a/arch/x86/kernel/tls.c
26607+++ b/arch/x86/kernel/tls.c
26608@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26609 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26610 return -EINVAL;
26611
26612+#ifdef CONFIG_PAX_SEGMEXEC
26613+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26614+ return -EINVAL;
26615+#endif
26616+
26617 set_tls_desc(p, idx, &info, 1);
26618
26619 return 0;
26620@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26621
26622 if (kbuf)
26623 info = kbuf;
26624- else if (__copy_from_user(infobuf, ubuf, count))
26625+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26626 return -EFAULT;
26627 else
26628 info = infobuf;
26629diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26630index 1c113db..287b42e 100644
26631--- a/arch/x86/kernel/tracepoint.c
26632+++ b/arch/x86/kernel/tracepoint.c
26633@@ -9,11 +9,11 @@
26634 #include <linux/atomic.h>
26635
26636 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26637-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26638+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26639 (unsigned long) trace_idt_table };
26640
26641 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26642-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26643+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26644
26645 static int trace_irq_vector_refcount;
26646 static DEFINE_MUTEX(irq_vector_mutex);
26647diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26648index 8c8093b..c93f581 100644
26649--- a/arch/x86/kernel/traps.c
26650+++ b/arch/x86/kernel/traps.c
26651@@ -66,7 +66,7 @@
26652 #include <asm/proto.h>
26653
26654 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26655-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26656+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26657 #else
26658 #include <asm/processor-flags.h>
26659 #include <asm/setup.h>
26660@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26661 #endif
26662
26663 /* Must be page-aligned because the real IDT is used in a fixmap. */
26664-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26665+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26666
26667 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26668 EXPORT_SYMBOL_GPL(used_vectors);
26669@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26670 }
26671
26672 static int __kprobes
26673-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26674+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26675 struct pt_regs *regs, long error_code)
26676 {
26677 #ifdef CONFIG_X86_32
26678- if (regs->flags & X86_VM_MASK) {
26679+ if (v8086_mode(regs)) {
26680 /*
26681 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26682 * On nmi (interrupt 2), do_trap should not be called.
26683@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26684 return -1;
26685 }
26686 #endif
26687- if (!user_mode(regs)) {
26688+ if (!user_mode_novm(regs)) {
26689 if (!fixup_exception(regs)) {
26690 tsk->thread.error_code = error_code;
26691 tsk->thread.trap_nr = trapnr;
26692+
26693+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26694+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26695+ str = "PAX: suspicious stack segment fault";
26696+#endif
26697+
26698 die(str, regs, error_code);
26699 }
26700+
26701+#ifdef CONFIG_PAX_REFCOUNT
26702+ if (trapnr == 4)
26703+ pax_report_refcount_overflow(regs);
26704+#endif
26705+
26706 return 0;
26707 }
26708
26709@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26710 }
26711
26712 static void __kprobes
26713-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26714+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26715 long error_code, siginfo_t *info)
26716 {
26717 struct task_struct *tsk = current;
26718@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26719 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26720 printk_ratelimit()) {
26721 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26722- tsk->comm, tsk->pid, str,
26723+ tsk->comm, task_pid_nr(tsk), str,
26724 regs->ip, regs->sp, error_code);
26725 print_vma_addr(" in ", regs->ip);
26726 pr_cont("\n");
26727@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26728 conditional_sti(regs);
26729
26730 #ifdef CONFIG_X86_32
26731- if (regs->flags & X86_VM_MASK) {
26732+ if (v8086_mode(regs)) {
26733 local_irq_enable();
26734 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26735 goto exit;
26736@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26737 #endif
26738
26739 tsk = current;
26740- if (!user_mode(regs)) {
26741+ if (!user_mode_novm(regs)) {
26742 if (fixup_exception(regs))
26743 goto exit;
26744
26745 tsk->thread.error_code = error_code;
26746 tsk->thread.trap_nr = X86_TRAP_GP;
26747 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26748- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26749+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26750+
26751+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26752+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26753+ die("PAX: suspicious general protection fault", regs, error_code);
26754+ else
26755+#endif
26756+
26757 die("general protection fault", regs, error_code);
26758+ }
26759 goto exit;
26760 }
26761
26762+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26763+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26764+ struct mm_struct *mm = tsk->mm;
26765+ unsigned long limit;
26766+
26767+ down_write(&mm->mmap_sem);
26768+ limit = mm->context.user_cs_limit;
26769+ if (limit < TASK_SIZE) {
26770+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26771+ up_write(&mm->mmap_sem);
26772+ return;
26773+ }
26774+ up_write(&mm->mmap_sem);
26775+ }
26776+#endif
26777+
26778 tsk->thread.error_code = error_code;
26779 tsk->thread.trap_nr = X86_TRAP_GP;
26780
26781@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26782 /* It's safe to allow irq's after DR6 has been saved */
26783 preempt_conditional_sti(regs);
26784
26785- if (regs->flags & X86_VM_MASK) {
26786+ if (v8086_mode(regs)) {
26787 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26788 X86_TRAP_DB);
26789 preempt_conditional_cli(regs);
26790@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26791 * We already checked v86 mode above, so we can check for kernel mode
26792 * by just checking the CPL of CS.
26793 */
26794- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26795+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26796 tsk->thread.debugreg6 &= ~DR_STEP;
26797 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26798 regs->flags &= ~X86_EFLAGS_TF;
26799@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26800 return;
26801 conditional_sti(regs);
26802
26803- if (!user_mode_vm(regs))
26804+ if (!user_mode(regs))
26805 {
26806 if (!fixup_exception(regs)) {
26807 task->thread.error_code = error_code;
26808diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26809index 2ed8459..7cf329f 100644
26810--- a/arch/x86/kernel/uprobes.c
26811+++ b/arch/x86/kernel/uprobes.c
26812@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26813 int ret = NOTIFY_DONE;
26814
26815 /* We are only interested in userspace traps */
26816- if (regs && !user_mode_vm(regs))
26817+ if (regs && !user_mode(regs))
26818 return NOTIFY_DONE;
26819
26820 switch (val) {
26821@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26822
26823 if (ncopied != rasize) {
26824 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26825- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26826+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26827
26828 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26829 }
26830diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26831index b9242ba..50c5edd 100644
26832--- a/arch/x86/kernel/verify_cpu.S
26833+++ b/arch/x86/kernel/verify_cpu.S
26834@@ -20,6 +20,7 @@
26835 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26836 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26837 * arch/x86/kernel/head_32.S: processor startup
26838+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26839 *
26840 * verify_cpu, returns the status of longmode and SSE in register %eax.
26841 * 0: Success 1: Failure
26842diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26843index e8edcf5..27f9344 100644
26844--- a/arch/x86/kernel/vm86_32.c
26845+++ b/arch/x86/kernel/vm86_32.c
26846@@ -44,6 +44,7 @@
26847 #include <linux/ptrace.h>
26848 #include <linux/audit.h>
26849 #include <linux/stddef.h>
26850+#include <linux/grsecurity.h>
26851
26852 #include <asm/uaccess.h>
26853 #include <asm/io.h>
26854@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26855 do_exit(SIGSEGV);
26856 }
26857
26858- tss = &per_cpu(init_tss, get_cpu());
26859+ tss = init_tss + get_cpu();
26860 current->thread.sp0 = current->thread.saved_sp0;
26861 current->thread.sysenter_cs = __KERNEL_CS;
26862 load_sp0(tss, &current->thread);
26863@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26864
26865 if (tsk->thread.saved_sp0)
26866 return -EPERM;
26867+
26868+#ifdef CONFIG_GRKERNSEC_VM86
26869+ if (!capable(CAP_SYS_RAWIO)) {
26870+ gr_handle_vm86();
26871+ return -EPERM;
26872+ }
26873+#endif
26874+
26875 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26876 offsetof(struct kernel_vm86_struct, vm86plus) -
26877 sizeof(info.regs));
26878@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26879 int tmp;
26880 struct vm86plus_struct __user *v86;
26881
26882+#ifdef CONFIG_GRKERNSEC_VM86
26883+ if (!capable(CAP_SYS_RAWIO)) {
26884+ gr_handle_vm86();
26885+ return -EPERM;
26886+ }
26887+#endif
26888+
26889 tsk = current;
26890 switch (cmd) {
26891 case VM86_REQUEST_IRQ:
26892@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26893 tsk->thread.saved_fs = info->regs32->fs;
26894 tsk->thread.saved_gs = get_user_gs(info->regs32);
26895
26896- tss = &per_cpu(init_tss, get_cpu());
26897+ tss = init_tss + get_cpu();
26898 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26899 if (cpu_has_sep)
26900 tsk->thread.sysenter_cs = 0;
26901@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26902 goto cannot_handle;
26903 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26904 goto cannot_handle;
26905- intr_ptr = (unsigned long __user *) (i << 2);
26906+ intr_ptr = (__force unsigned long __user *) (i << 2);
26907 if (get_user(segoffs, intr_ptr))
26908 goto cannot_handle;
26909 if ((segoffs >> 16) == BIOSSEG)
26910diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26911index 10c4f30..65408b9 100644
26912--- a/arch/x86/kernel/vmlinux.lds.S
26913+++ b/arch/x86/kernel/vmlinux.lds.S
26914@@ -26,6 +26,13 @@
26915 #include <asm/page_types.h>
26916 #include <asm/cache.h>
26917 #include <asm/boot.h>
26918+#include <asm/segment.h>
26919+
26920+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26921+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26922+#else
26923+#define __KERNEL_TEXT_OFFSET 0
26924+#endif
26925
26926 #undef i386 /* in case the preprocessor is a 32bit one */
26927
26928@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26929
26930 PHDRS {
26931 text PT_LOAD FLAGS(5); /* R_E */
26932+#ifdef CONFIG_X86_32
26933+ module PT_LOAD FLAGS(5); /* R_E */
26934+#endif
26935+#ifdef CONFIG_XEN
26936+ rodata PT_LOAD FLAGS(5); /* R_E */
26937+#else
26938+ rodata PT_LOAD FLAGS(4); /* R__ */
26939+#endif
26940 data PT_LOAD FLAGS(6); /* RW_ */
26941-#ifdef CONFIG_X86_64
26942+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26943 #ifdef CONFIG_SMP
26944 percpu PT_LOAD FLAGS(6); /* RW_ */
26945 #endif
26946+ text.init PT_LOAD FLAGS(5); /* R_E */
26947+ text.exit PT_LOAD FLAGS(5); /* R_E */
26948 init PT_LOAD FLAGS(7); /* RWE */
26949-#endif
26950 note PT_NOTE FLAGS(0); /* ___ */
26951 }
26952
26953 SECTIONS
26954 {
26955 #ifdef CONFIG_X86_32
26956- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26957- phys_startup_32 = startup_32 - LOAD_OFFSET;
26958+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26959 #else
26960- . = __START_KERNEL;
26961- phys_startup_64 = startup_64 - LOAD_OFFSET;
26962+ . = __START_KERNEL;
26963 #endif
26964
26965 /* Text and read-only data */
26966- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26967- _text = .;
26968+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26969 /* bootstrapping code */
26970+#ifdef CONFIG_X86_32
26971+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26972+#else
26973+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26974+#endif
26975+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26976+ _text = .;
26977 HEAD_TEXT
26978 . = ALIGN(8);
26979 _stext = .;
26980@@ -104,13 +124,47 @@ SECTIONS
26981 IRQENTRY_TEXT
26982 *(.fixup)
26983 *(.gnu.warning)
26984- /* End of text section */
26985- _etext = .;
26986 } :text = 0x9090
26987
26988- NOTES :text :note
26989+ . += __KERNEL_TEXT_OFFSET;
26990
26991- EXCEPTION_TABLE(16) :text = 0x9090
26992+#ifdef CONFIG_X86_32
26993+ . = ALIGN(PAGE_SIZE);
26994+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26995+
26996+#ifdef CONFIG_PAX_KERNEXEC
26997+ MODULES_EXEC_VADDR = .;
26998+ BYTE(0)
26999+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27000+ . = ALIGN(HPAGE_SIZE) - 1;
27001+ MODULES_EXEC_END = .;
27002+#endif
27003+
27004+ } :module
27005+#endif
27006+
27007+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27008+ /* End of text section */
27009+ BYTE(0)
27010+ _etext = . - __KERNEL_TEXT_OFFSET;
27011+ }
27012+
27013+#ifdef CONFIG_X86_32
27014+ . = ALIGN(PAGE_SIZE);
27015+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27016+ . = ALIGN(PAGE_SIZE);
27017+ *(.empty_zero_page)
27018+ *(.initial_pg_fixmap)
27019+ *(.initial_pg_pmd)
27020+ *(.initial_page_table)
27021+ *(.swapper_pg_dir)
27022+ } :rodata
27023+#endif
27024+
27025+ . = ALIGN(PAGE_SIZE);
27026+ NOTES :rodata :note
27027+
27028+ EXCEPTION_TABLE(16) :rodata
27029
27030 #if defined(CONFIG_DEBUG_RODATA)
27031 /* .text should occupy whole number of pages */
27032@@ -122,16 +176,20 @@ SECTIONS
27033
27034 /* Data */
27035 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27036+
27037+#ifdef CONFIG_PAX_KERNEXEC
27038+ . = ALIGN(HPAGE_SIZE);
27039+#else
27040+ . = ALIGN(PAGE_SIZE);
27041+#endif
27042+
27043 /* Start of data section */
27044 _sdata = .;
27045
27046 /* init_task */
27047 INIT_TASK_DATA(THREAD_SIZE)
27048
27049-#ifdef CONFIG_X86_32
27050- /* 32 bit has nosave before _edata */
27051 NOSAVE_DATA
27052-#endif
27053
27054 PAGE_ALIGNED_DATA(PAGE_SIZE)
27055
27056@@ -172,12 +230,19 @@ SECTIONS
27057 #endif /* CONFIG_X86_64 */
27058
27059 /* Init code and data - will be freed after init */
27060- . = ALIGN(PAGE_SIZE);
27061 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27062+ BYTE(0)
27063+
27064+#ifdef CONFIG_PAX_KERNEXEC
27065+ . = ALIGN(HPAGE_SIZE);
27066+#else
27067+ . = ALIGN(PAGE_SIZE);
27068+#endif
27069+
27070 __init_begin = .; /* paired with __init_end */
27071- }
27072+ } :init.begin
27073
27074-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27075+#ifdef CONFIG_SMP
27076 /*
27077 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27078 * output PHDR, so the next output section - .init.text - should
27079@@ -186,12 +251,27 @@ SECTIONS
27080 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27081 #endif
27082
27083- INIT_TEXT_SECTION(PAGE_SIZE)
27084-#ifdef CONFIG_X86_64
27085- :init
27086-#endif
27087+ . = ALIGN(PAGE_SIZE);
27088+ init_begin = .;
27089+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27090+ VMLINUX_SYMBOL(_sinittext) = .;
27091+ INIT_TEXT
27092+ VMLINUX_SYMBOL(_einittext) = .;
27093+ . = ALIGN(PAGE_SIZE);
27094+ } :text.init
27095
27096- INIT_DATA_SECTION(16)
27097+ /*
27098+ * .exit.text is discard at runtime, not link time, to deal with
27099+ * references from .altinstructions and .eh_frame
27100+ */
27101+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27102+ EXIT_TEXT
27103+ . = ALIGN(16);
27104+ } :text.exit
27105+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27106+
27107+ . = ALIGN(PAGE_SIZE);
27108+ INIT_DATA_SECTION(16) :init
27109
27110 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27111 __x86_cpu_dev_start = .;
27112@@ -253,19 +333,12 @@ SECTIONS
27113 }
27114
27115 . = ALIGN(8);
27116- /*
27117- * .exit.text is discard at runtime, not link time, to deal with
27118- * references from .altinstructions and .eh_frame
27119- */
27120- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27121- EXIT_TEXT
27122- }
27123
27124 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27125 EXIT_DATA
27126 }
27127
27128-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27129+#ifndef CONFIG_SMP
27130 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27131 #endif
27132
27133@@ -284,16 +357,10 @@ SECTIONS
27134 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27135 __smp_locks = .;
27136 *(.smp_locks)
27137- . = ALIGN(PAGE_SIZE);
27138 __smp_locks_end = .;
27139+ . = ALIGN(PAGE_SIZE);
27140 }
27141
27142-#ifdef CONFIG_X86_64
27143- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27144- NOSAVE_DATA
27145- }
27146-#endif
27147-
27148 /* BSS */
27149 . = ALIGN(PAGE_SIZE);
27150 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27151@@ -309,6 +376,7 @@ SECTIONS
27152 __brk_base = .;
27153 . += 64 * 1024; /* 64k alignment slop space */
27154 *(.brk_reservation) /* areas brk users have reserved */
27155+ . = ALIGN(HPAGE_SIZE);
27156 __brk_limit = .;
27157 }
27158
27159@@ -335,13 +403,12 @@ SECTIONS
27160 * for the boot processor.
27161 */
27162 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27163-INIT_PER_CPU(gdt_page);
27164 INIT_PER_CPU(irq_stack_union);
27165
27166 /*
27167 * Build-time check on the image size:
27168 */
27169-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27170+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27171 "kernel image bigger than KERNEL_IMAGE_SIZE");
27172
27173 #ifdef CONFIG_SMP
27174diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27175index 1f96f93..d5c8f7a 100644
27176--- a/arch/x86/kernel/vsyscall_64.c
27177+++ b/arch/x86/kernel/vsyscall_64.c
27178@@ -56,15 +56,13 @@
27179 DEFINE_VVAR(int, vgetcpu_mode);
27180 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27181
27182-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27183+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27184
27185 static int __init vsyscall_setup(char *str)
27186 {
27187 if (str) {
27188 if (!strcmp("emulate", str))
27189 vsyscall_mode = EMULATE;
27190- else if (!strcmp("native", str))
27191- vsyscall_mode = NATIVE;
27192 else if (!strcmp("none", str))
27193 vsyscall_mode = NONE;
27194 else
27195@@ -323,8 +321,7 @@ do_ret:
27196 return true;
27197
27198 sigsegv:
27199- force_sig(SIGSEGV, current);
27200- return true;
27201+ do_group_exit(SIGKILL);
27202 }
27203
27204 /*
27205@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27206 extern char __vvar_page;
27207 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27208
27209- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27210- vsyscall_mode == NATIVE
27211- ? PAGE_KERNEL_VSYSCALL
27212- : PAGE_KERNEL_VVAR);
27213+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27214 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27215 (unsigned long)VSYSCALL_START);
27216
27217diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27218index b014d94..e775258 100644
27219--- a/arch/x86/kernel/x8664_ksyms_64.c
27220+++ b/arch/x86/kernel/x8664_ksyms_64.c
27221@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27222 EXPORT_SYMBOL(copy_user_generic_unrolled);
27223 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27224 EXPORT_SYMBOL(__copy_user_nocache);
27225-EXPORT_SYMBOL(_copy_from_user);
27226-EXPORT_SYMBOL(_copy_to_user);
27227
27228 EXPORT_SYMBOL(copy_page);
27229 EXPORT_SYMBOL(clear_page);
27230@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
27231 #ifndef CONFIG_PARAVIRT
27232 EXPORT_SYMBOL(native_load_gs_index);
27233 #endif
27234+
27235+#ifdef CONFIG_PAX_PER_CPU_PGD
27236+EXPORT_SYMBOL(cpu_pgd);
27237+#endif
27238diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27239index 8ce0072..431a0e7 100644
27240--- a/arch/x86/kernel/x86_init.c
27241+++ b/arch/x86/kernel/x86_init.c
27242@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27243 static void default_nmi_init(void) { };
27244 static int default_i8042_detect(void) { return 1; };
27245
27246-struct x86_platform_ops x86_platform = {
27247+struct x86_platform_ops x86_platform __read_only = {
27248 .calibrate_tsc = native_calibrate_tsc,
27249 .get_wallclock = mach_get_cmos_time,
27250 .set_wallclock = mach_set_rtc_mmss,
27251@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27252 EXPORT_SYMBOL_GPL(x86_platform);
27253
27254 #if defined(CONFIG_PCI_MSI)
27255-struct x86_msi_ops x86_msi = {
27256+struct x86_msi_ops x86_msi __read_only = {
27257 .setup_msi_irqs = native_setup_msi_irqs,
27258 .compose_msi_msg = native_compose_msi_msg,
27259 .teardown_msi_irq = native_teardown_msi_irq,
27260@@ -140,7 +140,7 @@ void arch_restore_msi_irqs(struct pci_dev *dev, int irq)
27261 }
27262 #endif
27263
27264-struct x86_io_apic_ops x86_io_apic_ops = {
27265+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27266 .init = native_io_apic_init_mappings,
27267 .read = native_io_apic_read,
27268 .write = native_io_apic_write,
27269diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27270index 422fd82..c3687ca 100644
27271--- a/arch/x86/kernel/xsave.c
27272+++ b/arch/x86/kernel/xsave.c
27273@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27274 {
27275 int err;
27276
27277+ buf = (struct xsave_struct __user *)____m(buf);
27278 if (use_xsave())
27279 err = xsave_user(buf);
27280 else if (use_fxsr())
27281@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27282 */
27283 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27284 {
27285+ buf = (void __user *)____m(buf);
27286 if (use_xsave()) {
27287 if ((unsigned long)buf % 64 || fx_only) {
27288 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27289diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27290index b110fe6..d9c19f2 100644
27291--- a/arch/x86/kvm/cpuid.c
27292+++ b/arch/x86/kvm/cpuid.c
27293@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27294 struct kvm_cpuid2 *cpuid,
27295 struct kvm_cpuid_entry2 __user *entries)
27296 {
27297- int r;
27298+ int r, i;
27299
27300 r = -E2BIG;
27301 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27302 goto out;
27303 r = -EFAULT;
27304- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27305- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27306+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27307 goto out;
27308+ for (i = 0; i < cpuid->nent; ++i) {
27309+ struct kvm_cpuid_entry2 cpuid_entry;
27310+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27311+ goto out;
27312+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
27313+ }
27314 vcpu->arch.cpuid_nent = cpuid->nent;
27315 kvm_apic_set_version(vcpu);
27316 kvm_x86_ops->cpuid_update(vcpu);
27317@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27318 struct kvm_cpuid2 *cpuid,
27319 struct kvm_cpuid_entry2 __user *entries)
27320 {
27321- int r;
27322+ int r, i;
27323
27324 r = -E2BIG;
27325 if (cpuid->nent < vcpu->arch.cpuid_nent)
27326 goto out;
27327 r = -EFAULT;
27328- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27329- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27330+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27331 goto out;
27332+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27333+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27334+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27335+ goto out;
27336+ }
27337 return 0;
27338
27339 out:
27340diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27341index dec48bf..f4d21f7 100644
27342--- a/arch/x86/kvm/lapic.c
27343+++ b/arch/x86/kvm/lapic.c
27344@@ -55,7 +55,7 @@
27345 #define APIC_BUS_CYCLE_NS 1
27346
27347 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27348-#define apic_debug(fmt, arg...)
27349+#define apic_debug(fmt, arg...) do {} while (0)
27350
27351 #define APIC_LVT_NUM 6
27352 /* 14 is the version for Xeon and Pentium 8.4.8*/
27353diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27354index ad75d77..a679d32 100644
27355--- a/arch/x86/kvm/paging_tmpl.h
27356+++ b/arch/x86/kvm/paging_tmpl.h
27357@@ -331,7 +331,7 @@ retry_walk:
27358 if (unlikely(kvm_is_error_hva(host_addr)))
27359 goto error;
27360
27361- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27362+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27363 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27364 goto error;
27365 walker->ptep_user[walker->level - 1] = ptep_user;
27366diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27367index c0bc803..6837a50 100644
27368--- a/arch/x86/kvm/svm.c
27369+++ b/arch/x86/kvm/svm.c
27370@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27371 int cpu = raw_smp_processor_id();
27372
27373 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27374+
27375+ pax_open_kernel();
27376 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27377+ pax_close_kernel();
27378+
27379 load_TR_desc();
27380 }
27381
27382@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27383 #endif
27384 #endif
27385
27386+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27387+ __set_fs(current_thread_info()->addr_limit);
27388+#endif
27389+
27390 reload_tss(vcpu);
27391
27392 local_irq_disable();
27393diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27394index 2b2fce1..da76be4 100644
27395--- a/arch/x86/kvm/vmx.c
27396+++ b/arch/x86/kvm/vmx.c
27397@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27398 #endif
27399 }
27400
27401-static void vmcs_clear_bits(unsigned long field, u32 mask)
27402+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27403 {
27404 vmcs_writel(field, vmcs_readl(field) & ~mask);
27405 }
27406
27407-static void vmcs_set_bits(unsigned long field, u32 mask)
27408+static void vmcs_set_bits(unsigned long field, unsigned long mask)
27409 {
27410 vmcs_writel(field, vmcs_readl(field) | mask);
27411 }
27412@@ -1522,7 +1522,11 @@ static void reload_tss(void)
27413 struct desc_struct *descs;
27414
27415 descs = (void *)gdt->address;
27416+
27417+ pax_open_kernel();
27418 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27419+ pax_close_kernel();
27420+
27421 load_TR_desc();
27422 }
27423
27424@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27425 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27426 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27427
27428+#ifdef CONFIG_PAX_PER_CPU_PGD
27429+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27430+#endif
27431+
27432 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27433 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27434 vmx->loaded_vmcs->cpu = cpu;
27435@@ -2037,7 +2045,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27436 * reads and returns guest's timestamp counter "register"
27437 * guest_tsc = host_tsc + tsc_offset -- 21.3
27438 */
27439-static u64 guest_read_tsc(void)
27440+static u64 __intentional_overflow(-1) guest_read_tsc(void)
27441 {
27442 u64 host_tsc, tsc_offset;
27443
27444@@ -2982,8 +2990,11 @@ static __init int hardware_setup(void)
27445 if (!cpu_has_vmx_flexpriority())
27446 flexpriority_enabled = 0;
27447
27448- if (!cpu_has_vmx_tpr_shadow())
27449- kvm_x86_ops->update_cr8_intercept = NULL;
27450+ if (!cpu_has_vmx_tpr_shadow()) {
27451+ pax_open_kernel();
27452+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27453+ pax_close_kernel();
27454+ }
27455
27456 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27457 kvm_disable_largepages();
27458@@ -2994,13 +3005,15 @@ static __init int hardware_setup(void)
27459 if (!cpu_has_vmx_apicv())
27460 enable_apicv = 0;
27461
27462+ pax_open_kernel();
27463 if (enable_apicv)
27464- kvm_x86_ops->update_cr8_intercept = NULL;
27465+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27466 else {
27467- kvm_x86_ops->hwapic_irr_update = NULL;
27468- kvm_x86_ops->deliver_posted_interrupt = NULL;
27469- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27470+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27471+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27472+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27473 }
27474+ pax_close_kernel();
27475
27476 if (nested)
27477 nested_vmx_setup_ctls_msrs();
27478@@ -4127,7 +4140,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27479
27480 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27481 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27482+
27483+#ifndef CONFIG_PAX_PER_CPU_PGD
27484 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27485+#endif
27486
27487 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27488 #ifdef CONFIG_X86_64
27489@@ -4149,7 +4165,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27490 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27491 vmx->host_idt_base = dt.address;
27492
27493- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27494+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27495
27496 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27497 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27498@@ -7191,6 +7207,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27499 "jmp 2f \n\t"
27500 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27501 "2: "
27502+
27503+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27504+ "ljmp %[cs],$3f\n\t"
27505+ "3: "
27506+#endif
27507+
27508 /* Save guest registers, load host registers, keep flags */
27509 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27510 "pop %0 \n\t"
27511@@ -7243,6 +7265,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27512 #endif
27513 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27514 [wordsize]"i"(sizeof(ulong))
27515+
27516+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27517+ ,[cs]"i"(__KERNEL_CS)
27518+#endif
27519+
27520 : "cc", "memory"
27521 #ifdef CONFIG_X86_64
27522 , "rax", "rbx", "rdi", "rsi"
27523@@ -7256,7 +7283,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27524 if (debugctlmsr)
27525 update_debugctlmsr(debugctlmsr);
27526
27527-#ifndef CONFIG_X86_64
27528+#ifdef CONFIG_X86_32
27529 /*
27530 * The sysexit path does not restore ds/es, so we must set them to
27531 * a reasonable value ourselves.
27532@@ -7265,8 +7292,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27533 * may be executed in interrupt context, which saves and restore segments
27534 * around it, nullifying its effect.
27535 */
27536- loadsegment(ds, __USER_DS);
27537- loadsegment(es, __USER_DS);
27538+ loadsegment(ds, __KERNEL_DS);
27539+ loadsegment(es, __KERNEL_DS);
27540+ loadsegment(ss, __KERNEL_DS);
27541+
27542+#ifdef CONFIG_PAX_KERNEXEC
27543+ loadsegment(fs, __KERNEL_PERCPU);
27544+#endif
27545+
27546+#ifdef CONFIG_PAX_MEMORY_UDEREF
27547+ __set_fs(current_thread_info()->addr_limit);
27548+#endif
27549+
27550 #endif
27551
27552 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27553diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27554index eb9b9c9..0f30b12 100644
27555--- a/arch/x86/kvm/x86.c
27556+++ b/arch/x86/kvm/x86.c
27557@@ -1779,8 +1779,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27558 {
27559 struct kvm *kvm = vcpu->kvm;
27560 int lm = is_long_mode(vcpu);
27561- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27562- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27563+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27564+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27565 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27566 : kvm->arch.xen_hvm_config.blob_size_32;
27567 u32 page_num = data & ~PAGE_MASK;
27568@@ -2663,6 +2663,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27569 if (n < msr_list.nmsrs)
27570 goto out;
27571 r = -EFAULT;
27572+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27573+ goto out;
27574 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27575 num_msrs_to_save * sizeof(u32)))
27576 goto out;
27577@@ -5461,7 +5463,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27578 };
27579 #endif
27580
27581-int kvm_arch_init(void *opaque)
27582+int kvm_arch_init(const void *opaque)
27583 {
27584 int r;
27585 struct kvm_x86_ops *ops = opaque;
27586diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27587index bdf8532..f63c587 100644
27588--- a/arch/x86/lguest/boot.c
27589+++ b/arch/x86/lguest/boot.c
27590@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27591 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27592 * Launcher to reboot us.
27593 */
27594-static void lguest_restart(char *reason)
27595+static __noreturn void lguest_restart(char *reason)
27596 {
27597 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27598+ BUG();
27599 }
27600
27601 /*G:050
27602diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27603index 00933d5..3a64af9 100644
27604--- a/arch/x86/lib/atomic64_386_32.S
27605+++ b/arch/x86/lib/atomic64_386_32.S
27606@@ -48,6 +48,10 @@ BEGIN(read)
27607 movl (v), %eax
27608 movl 4(v), %edx
27609 RET_ENDP
27610+BEGIN(read_unchecked)
27611+ movl (v), %eax
27612+ movl 4(v), %edx
27613+RET_ENDP
27614 #undef v
27615
27616 #define v %esi
27617@@ -55,6 +59,10 @@ BEGIN(set)
27618 movl %ebx, (v)
27619 movl %ecx, 4(v)
27620 RET_ENDP
27621+BEGIN(set_unchecked)
27622+ movl %ebx, (v)
27623+ movl %ecx, 4(v)
27624+RET_ENDP
27625 #undef v
27626
27627 #define v %esi
27628@@ -70,6 +78,20 @@ RET_ENDP
27629 BEGIN(add)
27630 addl %eax, (v)
27631 adcl %edx, 4(v)
27632+
27633+#ifdef CONFIG_PAX_REFCOUNT
27634+ jno 0f
27635+ subl %eax, (v)
27636+ sbbl %edx, 4(v)
27637+ int $4
27638+0:
27639+ _ASM_EXTABLE(0b, 0b)
27640+#endif
27641+
27642+RET_ENDP
27643+BEGIN(add_unchecked)
27644+ addl %eax, (v)
27645+ adcl %edx, 4(v)
27646 RET_ENDP
27647 #undef v
27648
27649@@ -77,6 +99,24 @@ RET_ENDP
27650 BEGIN(add_return)
27651 addl (v), %eax
27652 adcl 4(v), %edx
27653+
27654+#ifdef CONFIG_PAX_REFCOUNT
27655+ into
27656+1234:
27657+ _ASM_EXTABLE(1234b, 2f)
27658+#endif
27659+
27660+ movl %eax, (v)
27661+ movl %edx, 4(v)
27662+
27663+#ifdef CONFIG_PAX_REFCOUNT
27664+2:
27665+#endif
27666+
27667+RET_ENDP
27668+BEGIN(add_return_unchecked)
27669+ addl (v), %eax
27670+ adcl 4(v), %edx
27671 movl %eax, (v)
27672 movl %edx, 4(v)
27673 RET_ENDP
27674@@ -86,6 +126,20 @@ RET_ENDP
27675 BEGIN(sub)
27676 subl %eax, (v)
27677 sbbl %edx, 4(v)
27678+
27679+#ifdef CONFIG_PAX_REFCOUNT
27680+ jno 0f
27681+ addl %eax, (v)
27682+ adcl %edx, 4(v)
27683+ int $4
27684+0:
27685+ _ASM_EXTABLE(0b, 0b)
27686+#endif
27687+
27688+RET_ENDP
27689+BEGIN(sub_unchecked)
27690+ subl %eax, (v)
27691+ sbbl %edx, 4(v)
27692 RET_ENDP
27693 #undef v
27694
27695@@ -96,6 +150,27 @@ BEGIN(sub_return)
27696 sbbl $0, %edx
27697 addl (v), %eax
27698 adcl 4(v), %edx
27699+
27700+#ifdef CONFIG_PAX_REFCOUNT
27701+ into
27702+1234:
27703+ _ASM_EXTABLE(1234b, 2f)
27704+#endif
27705+
27706+ movl %eax, (v)
27707+ movl %edx, 4(v)
27708+
27709+#ifdef CONFIG_PAX_REFCOUNT
27710+2:
27711+#endif
27712+
27713+RET_ENDP
27714+BEGIN(sub_return_unchecked)
27715+ negl %edx
27716+ negl %eax
27717+ sbbl $0, %edx
27718+ addl (v), %eax
27719+ adcl 4(v), %edx
27720 movl %eax, (v)
27721 movl %edx, 4(v)
27722 RET_ENDP
27723@@ -105,6 +180,20 @@ RET_ENDP
27724 BEGIN(inc)
27725 addl $1, (v)
27726 adcl $0, 4(v)
27727+
27728+#ifdef CONFIG_PAX_REFCOUNT
27729+ jno 0f
27730+ subl $1, (v)
27731+ sbbl $0, 4(v)
27732+ int $4
27733+0:
27734+ _ASM_EXTABLE(0b, 0b)
27735+#endif
27736+
27737+RET_ENDP
27738+BEGIN(inc_unchecked)
27739+ addl $1, (v)
27740+ adcl $0, 4(v)
27741 RET_ENDP
27742 #undef v
27743
27744@@ -114,6 +203,26 @@ BEGIN(inc_return)
27745 movl 4(v), %edx
27746 addl $1, %eax
27747 adcl $0, %edx
27748+
27749+#ifdef CONFIG_PAX_REFCOUNT
27750+ into
27751+1234:
27752+ _ASM_EXTABLE(1234b, 2f)
27753+#endif
27754+
27755+ movl %eax, (v)
27756+ movl %edx, 4(v)
27757+
27758+#ifdef CONFIG_PAX_REFCOUNT
27759+2:
27760+#endif
27761+
27762+RET_ENDP
27763+BEGIN(inc_return_unchecked)
27764+ movl (v), %eax
27765+ movl 4(v), %edx
27766+ addl $1, %eax
27767+ adcl $0, %edx
27768 movl %eax, (v)
27769 movl %edx, 4(v)
27770 RET_ENDP
27771@@ -123,6 +232,20 @@ RET_ENDP
27772 BEGIN(dec)
27773 subl $1, (v)
27774 sbbl $0, 4(v)
27775+
27776+#ifdef CONFIG_PAX_REFCOUNT
27777+ jno 0f
27778+ addl $1, (v)
27779+ adcl $0, 4(v)
27780+ int $4
27781+0:
27782+ _ASM_EXTABLE(0b, 0b)
27783+#endif
27784+
27785+RET_ENDP
27786+BEGIN(dec_unchecked)
27787+ subl $1, (v)
27788+ sbbl $0, 4(v)
27789 RET_ENDP
27790 #undef v
27791
27792@@ -132,6 +255,26 @@ BEGIN(dec_return)
27793 movl 4(v), %edx
27794 subl $1, %eax
27795 sbbl $0, %edx
27796+
27797+#ifdef CONFIG_PAX_REFCOUNT
27798+ into
27799+1234:
27800+ _ASM_EXTABLE(1234b, 2f)
27801+#endif
27802+
27803+ movl %eax, (v)
27804+ movl %edx, 4(v)
27805+
27806+#ifdef CONFIG_PAX_REFCOUNT
27807+2:
27808+#endif
27809+
27810+RET_ENDP
27811+BEGIN(dec_return_unchecked)
27812+ movl (v), %eax
27813+ movl 4(v), %edx
27814+ subl $1, %eax
27815+ sbbl $0, %edx
27816 movl %eax, (v)
27817 movl %edx, 4(v)
27818 RET_ENDP
27819@@ -143,6 +286,13 @@ BEGIN(add_unless)
27820 adcl %edx, %edi
27821 addl (v), %eax
27822 adcl 4(v), %edx
27823+
27824+#ifdef CONFIG_PAX_REFCOUNT
27825+ into
27826+1234:
27827+ _ASM_EXTABLE(1234b, 2f)
27828+#endif
27829+
27830 cmpl %eax, %ecx
27831 je 3f
27832 1:
27833@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27834 1:
27835 addl $1, %eax
27836 adcl $0, %edx
27837+
27838+#ifdef CONFIG_PAX_REFCOUNT
27839+ into
27840+1234:
27841+ _ASM_EXTABLE(1234b, 2f)
27842+#endif
27843+
27844 movl %eax, (v)
27845 movl %edx, 4(v)
27846 movl $1, %eax
27847@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27848 movl 4(v), %edx
27849 subl $1, %eax
27850 sbbl $0, %edx
27851+
27852+#ifdef CONFIG_PAX_REFCOUNT
27853+ into
27854+1234:
27855+ _ASM_EXTABLE(1234b, 1f)
27856+#endif
27857+
27858 js 1f
27859 movl %eax, (v)
27860 movl %edx, 4(v)
27861diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27862index f5cc9eb..51fa319 100644
27863--- a/arch/x86/lib/atomic64_cx8_32.S
27864+++ b/arch/x86/lib/atomic64_cx8_32.S
27865@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27866 CFI_STARTPROC
27867
27868 read64 %ecx
27869+ pax_force_retaddr
27870 ret
27871 CFI_ENDPROC
27872 ENDPROC(atomic64_read_cx8)
27873
27874+ENTRY(atomic64_read_unchecked_cx8)
27875+ CFI_STARTPROC
27876+
27877+ read64 %ecx
27878+ pax_force_retaddr
27879+ ret
27880+ CFI_ENDPROC
27881+ENDPROC(atomic64_read_unchecked_cx8)
27882+
27883 ENTRY(atomic64_set_cx8)
27884 CFI_STARTPROC
27885
27886@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27887 cmpxchg8b (%esi)
27888 jne 1b
27889
27890+ pax_force_retaddr
27891 ret
27892 CFI_ENDPROC
27893 ENDPROC(atomic64_set_cx8)
27894
27895+ENTRY(atomic64_set_unchecked_cx8)
27896+ CFI_STARTPROC
27897+
27898+1:
27899+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27900+ * are atomic on 586 and newer */
27901+ cmpxchg8b (%esi)
27902+ jne 1b
27903+
27904+ pax_force_retaddr
27905+ ret
27906+ CFI_ENDPROC
27907+ENDPROC(atomic64_set_unchecked_cx8)
27908+
27909 ENTRY(atomic64_xchg_cx8)
27910 CFI_STARTPROC
27911
27912@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27913 cmpxchg8b (%esi)
27914 jne 1b
27915
27916+ pax_force_retaddr
27917 ret
27918 CFI_ENDPROC
27919 ENDPROC(atomic64_xchg_cx8)
27920
27921-.macro addsub_return func ins insc
27922-ENTRY(atomic64_\func\()_return_cx8)
27923+.macro addsub_return func ins insc unchecked=""
27924+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27925 CFI_STARTPROC
27926 SAVE ebp
27927 SAVE ebx
27928@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27929 movl %edx, %ecx
27930 \ins\()l %esi, %ebx
27931 \insc\()l %edi, %ecx
27932+
27933+.ifb \unchecked
27934+#ifdef CONFIG_PAX_REFCOUNT
27935+ into
27936+2:
27937+ _ASM_EXTABLE(2b, 3f)
27938+#endif
27939+.endif
27940+
27941 LOCK_PREFIX
27942 cmpxchg8b (%ebp)
27943 jne 1b
27944-
27945-10:
27946 movl %ebx, %eax
27947 movl %ecx, %edx
27948+
27949+.ifb \unchecked
27950+#ifdef CONFIG_PAX_REFCOUNT
27951+3:
27952+#endif
27953+.endif
27954+
27955 RESTORE edi
27956 RESTORE esi
27957 RESTORE ebx
27958 RESTORE ebp
27959+ pax_force_retaddr
27960 ret
27961 CFI_ENDPROC
27962-ENDPROC(atomic64_\func\()_return_cx8)
27963+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27964 .endm
27965
27966 addsub_return add add adc
27967 addsub_return sub sub sbb
27968+addsub_return add add adc _unchecked
27969+addsub_return sub sub sbb _unchecked
27970
27971-.macro incdec_return func ins insc
27972-ENTRY(atomic64_\func\()_return_cx8)
27973+.macro incdec_return func ins insc unchecked=""
27974+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27975 CFI_STARTPROC
27976 SAVE ebx
27977
27978@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27979 movl %edx, %ecx
27980 \ins\()l $1, %ebx
27981 \insc\()l $0, %ecx
27982+
27983+.ifb \unchecked
27984+#ifdef CONFIG_PAX_REFCOUNT
27985+ into
27986+2:
27987+ _ASM_EXTABLE(2b, 3f)
27988+#endif
27989+.endif
27990+
27991 LOCK_PREFIX
27992 cmpxchg8b (%esi)
27993 jne 1b
27994
27995-10:
27996 movl %ebx, %eax
27997 movl %ecx, %edx
27998+
27999+.ifb \unchecked
28000+#ifdef CONFIG_PAX_REFCOUNT
28001+3:
28002+#endif
28003+.endif
28004+
28005 RESTORE ebx
28006+ pax_force_retaddr
28007 ret
28008 CFI_ENDPROC
28009-ENDPROC(atomic64_\func\()_return_cx8)
28010+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28011 .endm
28012
28013 incdec_return inc add adc
28014 incdec_return dec sub sbb
28015+incdec_return inc add adc _unchecked
28016+incdec_return dec sub sbb _unchecked
28017
28018 ENTRY(atomic64_dec_if_positive_cx8)
28019 CFI_STARTPROC
28020@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28021 movl %edx, %ecx
28022 subl $1, %ebx
28023 sbb $0, %ecx
28024+
28025+#ifdef CONFIG_PAX_REFCOUNT
28026+ into
28027+1234:
28028+ _ASM_EXTABLE(1234b, 2f)
28029+#endif
28030+
28031 js 2f
28032 LOCK_PREFIX
28033 cmpxchg8b (%esi)
28034@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28035 movl %ebx, %eax
28036 movl %ecx, %edx
28037 RESTORE ebx
28038+ pax_force_retaddr
28039 ret
28040 CFI_ENDPROC
28041 ENDPROC(atomic64_dec_if_positive_cx8)
28042@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28043 movl %edx, %ecx
28044 addl %ebp, %ebx
28045 adcl %edi, %ecx
28046+
28047+#ifdef CONFIG_PAX_REFCOUNT
28048+ into
28049+1234:
28050+ _ASM_EXTABLE(1234b, 3f)
28051+#endif
28052+
28053 LOCK_PREFIX
28054 cmpxchg8b (%esi)
28055 jne 1b
28056@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28057 CFI_ADJUST_CFA_OFFSET -8
28058 RESTORE ebx
28059 RESTORE ebp
28060+ pax_force_retaddr
28061 ret
28062 4:
28063 cmpl %edx, 4(%esp)
28064@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28065 xorl %ecx, %ecx
28066 addl $1, %ebx
28067 adcl %edx, %ecx
28068+
28069+#ifdef CONFIG_PAX_REFCOUNT
28070+ into
28071+1234:
28072+ _ASM_EXTABLE(1234b, 3f)
28073+#endif
28074+
28075 LOCK_PREFIX
28076 cmpxchg8b (%esi)
28077 jne 1b
28078@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28079 movl $1, %eax
28080 3:
28081 RESTORE ebx
28082+ pax_force_retaddr
28083 ret
28084 CFI_ENDPROC
28085 ENDPROC(atomic64_inc_not_zero_cx8)
28086diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28087index e78b8ee..7e173a8 100644
28088--- a/arch/x86/lib/checksum_32.S
28089+++ b/arch/x86/lib/checksum_32.S
28090@@ -29,7 +29,8 @@
28091 #include <asm/dwarf2.h>
28092 #include <asm/errno.h>
28093 #include <asm/asm.h>
28094-
28095+#include <asm/segment.h>
28096+
28097 /*
28098 * computes a partial checksum, e.g. for TCP/UDP fragments
28099 */
28100@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28101
28102 #define ARGBASE 16
28103 #define FP 12
28104-
28105-ENTRY(csum_partial_copy_generic)
28106+
28107+ENTRY(csum_partial_copy_generic_to_user)
28108 CFI_STARTPROC
28109+
28110+#ifdef CONFIG_PAX_MEMORY_UDEREF
28111+ pushl_cfi %gs
28112+ popl_cfi %es
28113+ jmp csum_partial_copy_generic
28114+#endif
28115+
28116+ENTRY(csum_partial_copy_generic_from_user)
28117+
28118+#ifdef CONFIG_PAX_MEMORY_UDEREF
28119+ pushl_cfi %gs
28120+ popl_cfi %ds
28121+#endif
28122+
28123+ENTRY(csum_partial_copy_generic)
28124 subl $4,%esp
28125 CFI_ADJUST_CFA_OFFSET 4
28126 pushl_cfi %edi
28127@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28128 jmp 4f
28129 SRC(1: movw (%esi), %bx )
28130 addl $2, %esi
28131-DST( movw %bx, (%edi) )
28132+DST( movw %bx, %es:(%edi) )
28133 addl $2, %edi
28134 addw %bx, %ax
28135 adcl $0, %eax
28136@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28137 SRC(1: movl (%esi), %ebx )
28138 SRC( movl 4(%esi), %edx )
28139 adcl %ebx, %eax
28140-DST( movl %ebx, (%edi) )
28141+DST( movl %ebx, %es:(%edi) )
28142 adcl %edx, %eax
28143-DST( movl %edx, 4(%edi) )
28144+DST( movl %edx, %es:4(%edi) )
28145
28146 SRC( movl 8(%esi), %ebx )
28147 SRC( movl 12(%esi), %edx )
28148 adcl %ebx, %eax
28149-DST( movl %ebx, 8(%edi) )
28150+DST( movl %ebx, %es:8(%edi) )
28151 adcl %edx, %eax
28152-DST( movl %edx, 12(%edi) )
28153+DST( movl %edx, %es:12(%edi) )
28154
28155 SRC( movl 16(%esi), %ebx )
28156 SRC( movl 20(%esi), %edx )
28157 adcl %ebx, %eax
28158-DST( movl %ebx, 16(%edi) )
28159+DST( movl %ebx, %es:16(%edi) )
28160 adcl %edx, %eax
28161-DST( movl %edx, 20(%edi) )
28162+DST( movl %edx, %es:20(%edi) )
28163
28164 SRC( movl 24(%esi), %ebx )
28165 SRC( movl 28(%esi), %edx )
28166 adcl %ebx, %eax
28167-DST( movl %ebx, 24(%edi) )
28168+DST( movl %ebx, %es:24(%edi) )
28169 adcl %edx, %eax
28170-DST( movl %edx, 28(%edi) )
28171+DST( movl %edx, %es:28(%edi) )
28172
28173 lea 32(%esi), %esi
28174 lea 32(%edi), %edi
28175@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28176 shrl $2, %edx # This clears CF
28177 SRC(3: movl (%esi), %ebx )
28178 adcl %ebx, %eax
28179-DST( movl %ebx, (%edi) )
28180+DST( movl %ebx, %es:(%edi) )
28181 lea 4(%esi), %esi
28182 lea 4(%edi), %edi
28183 dec %edx
28184@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28185 jb 5f
28186 SRC( movw (%esi), %cx )
28187 leal 2(%esi), %esi
28188-DST( movw %cx, (%edi) )
28189+DST( movw %cx, %es:(%edi) )
28190 leal 2(%edi), %edi
28191 je 6f
28192 shll $16,%ecx
28193 SRC(5: movb (%esi), %cl )
28194-DST( movb %cl, (%edi) )
28195+DST( movb %cl, %es:(%edi) )
28196 6: addl %ecx, %eax
28197 adcl $0, %eax
28198 7:
28199@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28200
28201 6001:
28202 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28203- movl $-EFAULT, (%ebx)
28204+ movl $-EFAULT, %ss:(%ebx)
28205
28206 # zero the complete destination - computing the rest
28207 # is too much work
28208@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28209
28210 6002:
28211 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28212- movl $-EFAULT,(%ebx)
28213+ movl $-EFAULT,%ss:(%ebx)
28214 jmp 5000b
28215
28216 .previous
28217
28218+ pushl_cfi %ss
28219+ popl_cfi %ds
28220+ pushl_cfi %ss
28221+ popl_cfi %es
28222 popl_cfi %ebx
28223 CFI_RESTORE ebx
28224 popl_cfi %esi
28225@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28226 popl_cfi %ecx # equivalent to addl $4,%esp
28227 ret
28228 CFI_ENDPROC
28229-ENDPROC(csum_partial_copy_generic)
28230+ENDPROC(csum_partial_copy_generic_to_user)
28231
28232 #else
28233
28234 /* Version for PentiumII/PPro */
28235
28236 #define ROUND1(x) \
28237+ nop; nop; nop; \
28238 SRC(movl x(%esi), %ebx ) ; \
28239 addl %ebx, %eax ; \
28240- DST(movl %ebx, x(%edi) ) ;
28241+ DST(movl %ebx, %es:x(%edi)) ;
28242
28243 #define ROUND(x) \
28244+ nop; nop; nop; \
28245 SRC(movl x(%esi), %ebx ) ; \
28246 adcl %ebx, %eax ; \
28247- DST(movl %ebx, x(%edi) ) ;
28248+ DST(movl %ebx, %es:x(%edi)) ;
28249
28250 #define ARGBASE 12
28251-
28252-ENTRY(csum_partial_copy_generic)
28253+
28254+ENTRY(csum_partial_copy_generic_to_user)
28255 CFI_STARTPROC
28256+
28257+#ifdef CONFIG_PAX_MEMORY_UDEREF
28258+ pushl_cfi %gs
28259+ popl_cfi %es
28260+ jmp csum_partial_copy_generic
28261+#endif
28262+
28263+ENTRY(csum_partial_copy_generic_from_user)
28264+
28265+#ifdef CONFIG_PAX_MEMORY_UDEREF
28266+ pushl_cfi %gs
28267+ popl_cfi %ds
28268+#endif
28269+
28270+ENTRY(csum_partial_copy_generic)
28271 pushl_cfi %ebx
28272 CFI_REL_OFFSET ebx, 0
28273 pushl_cfi %edi
28274@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28275 subl %ebx, %edi
28276 lea -1(%esi),%edx
28277 andl $-32,%edx
28278- lea 3f(%ebx,%ebx), %ebx
28279+ lea 3f(%ebx,%ebx,2), %ebx
28280 testl %esi, %esi
28281 jmp *%ebx
28282 1: addl $64,%esi
28283@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28284 jb 5f
28285 SRC( movw (%esi), %dx )
28286 leal 2(%esi), %esi
28287-DST( movw %dx, (%edi) )
28288+DST( movw %dx, %es:(%edi) )
28289 leal 2(%edi), %edi
28290 je 6f
28291 shll $16,%edx
28292 5:
28293 SRC( movb (%esi), %dl )
28294-DST( movb %dl, (%edi) )
28295+DST( movb %dl, %es:(%edi) )
28296 6: addl %edx, %eax
28297 adcl $0, %eax
28298 7:
28299 .section .fixup, "ax"
28300 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28301- movl $-EFAULT, (%ebx)
28302+ movl $-EFAULT, %ss:(%ebx)
28303 # zero the complete destination (computing the rest is too much work)
28304 movl ARGBASE+8(%esp),%edi # dst
28305 movl ARGBASE+12(%esp),%ecx # len
28306@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28307 rep; stosb
28308 jmp 7b
28309 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28310- movl $-EFAULT, (%ebx)
28311+ movl $-EFAULT, %ss:(%ebx)
28312 jmp 7b
28313 .previous
28314
28315+#ifdef CONFIG_PAX_MEMORY_UDEREF
28316+ pushl_cfi %ss
28317+ popl_cfi %ds
28318+ pushl_cfi %ss
28319+ popl_cfi %es
28320+#endif
28321+
28322 popl_cfi %esi
28323 CFI_RESTORE esi
28324 popl_cfi %edi
28325@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28326 CFI_RESTORE ebx
28327 ret
28328 CFI_ENDPROC
28329-ENDPROC(csum_partial_copy_generic)
28330+ENDPROC(csum_partial_copy_generic_to_user)
28331
28332 #undef ROUND
28333 #undef ROUND1
28334diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28335index f2145cf..cea889d 100644
28336--- a/arch/x86/lib/clear_page_64.S
28337+++ b/arch/x86/lib/clear_page_64.S
28338@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28339 movl $4096/8,%ecx
28340 xorl %eax,%eax
28341 rep stosq
28342+ pax_force_retaddr
28343 ret
28344 CFI_ENDPROC
28345 ENDPROC(clear_page_c)
28346@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28347 movl $4096,%ecx
28348 xorl %eax,%eax
28349 rep stosb
28350+ pax_force_retaddr
28351 ret
28352 CFI_ENDPROC
28353 ENDPROC(clear_page_c_e)
28354@@ -43,6 +45,7 @@ ENTRY(clear_page)
28355 leaq 64(%rdi),%rdi
28356 jnz .Lloop
28357 nop
28358+ pax_force_retaddr
28359 ret
28360 CFI_ENDPROC
28361 .Lclear_page_end:
28362@@ -58,7 +61,7 @@ ENDPROC(clear_page)
28363
28364 #include <asm/cpufeature.h>
28365
28366- .section .altinstr_replacement,"ax"
28367+ .section .altinstr_replacement,"a"
28368 1: .byte 0xeb /* jmp <disp8> */
28369 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28370 2: .byte 0xeb /* jmp <disp8> */
28371diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28372index 1e572c5..2a162cd 100644
28373--- a/arch/x86/lib/cmpxchg16b_emu.S
28374+++ b/arch/x86/lib/cmpxchg16b_emu.S
28375@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28376
28377 popf
28378 mov $1, %al
28379+ pax_force_retaddr
28380 ret
28381
28382 not_same:
28383 popf
28384 xor %al,%al
28385+ pax_force_retaddr
28386 ret
28387
28388 CFI_ENDPROC
28389diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28390index 176cca6..e0d658e 100644
28391--- a/arch/x86/lib/copy_page_64.S
28392+++ b/arch/x86/lib/copy_page_64.S
28393@@ -9,6 +9,7 @@ copy_page_rep:
28394 CFI_STARTPROC
28395 movl $4096/8, %ecx
28396 rep movsq
28397+ pax_force_retaddr
28398 ret
28399 CFI_ENDPROC
28400 ENDPROC(copy_page_rep)
28401@@ -24,8 +25,8 @@ ENTRY(copy_page)
28402 CFI_ADJUST_CFA_OFFSET 2*8
28403 movq %rbx, (%rsp)
28404 CFI_REL_OFFSET rbx, 0
28405- movq %r12, 1*8(%rsp)
28406- CFI_REL_OFFSET r12, 1*8
28407+ movq %r13, 1*8(%rsp)
28408+ CFI_REL_OFFSET r13, 1*8
28409
28410 movl $(4096/64)-5, %ecx
28411 .p2align 4
28412@@ -38,7 +39,7 @@ ENTRY(copy_page)
28413 movq 0x8*4(%rsi), %r9
28414 movq 0x8*5(%rsi), %r10
28415 movq 0x8*6(%rsi), %r11
28416- movq 0x8*7(%rsi), %r12
28417+ movq 0x8*7(%rsi), %r13
28418
28419 prefetcht0 5*64(%rsi)
28420
28421@@ -49,7 +50,7 @@ ENTRY(copy_page)
28422 movq %r9, 0x8*4(%rdi)
28423 movq %r10, 0x8*5(%rdi)
28424 movq %r11, 0x8*6(%rdi)
28425- movq %r12, 0x8*7(%rdi)
28426+ movq %r13, 0x8*7(%rdi)
28427
28428 leaq 64 (%rsi), %rsi
28429 leaq 64 (%rdi), %rdi
28430@@ -68,7 +69,7 @@ ENTRY(copy_page)
28431 movq 0x8*4(%rsi), %r9
28432 movq 0x8*5(%rsi), %r10
28433 movq 0x8*6(%rsi), %r11
28434- movq 0x8*7(%rsi), %r12
28435+ movq 0x8*7(%rsi), %r13
28436
28437 movq %rax, 0x8*0(%rdi)
28438 movq %rbx, 0x8*1(%rdi)
28439@@ -77,7 +78,7 @@ ENTRY(copy_page)
28440 movq %r9, 0x8*4(%rdi)
28441 movq %r10, 0x8*5(%rdi)
28442 movq %r11, 0x8*6(%rdi)
28443- movq %r12, 0x8*7(%rdi)
28444+ movq %r13, 0x8*7(%rdi)
28445
28446 leaq 64(%rdi), %rdi
28447 leaq 64(%rsi), %rsi
28448@@ -85,10 +86,11 @@ ENTRY(copy_page)
28449
28450 movq (%rsp), %rbx
28451 CFI_RESTORE rbx
28452- movq 1*8(%rsp), %r12
28453- CFI_RESTORE r12
28454+ movq 1*8(%rsp), %r13
28455+ CFI_RESTORE r13
28456 addq $2*8, %rsp
28457 CFI_ADJUST_CFA_OFFSET -2*8
28458+ pax_force_retaddr
28459 ret
28460 .Lcopy_page_end:
28461 CFI_ENDPROC
28462@@ -99,7 +101,7 @@ ENDPROC(copy_page)
28463
28464 #include <asm/cpufeature.h>
28465
28466- .section .altinstr_replacement,"ax"
28467+ .section .altinstr_replacement,"a"
28468 1: .byte 0xeb /* jmp <disp8> */
28469 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28470 2:
28471diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28472index a30ca15..407412b 100644
28473--- a/arch/x86/lib/copy_user_64.S
28474+++ b/arch/x86/lib/copy_user_64.S
28475@@ -18,31 +18,7 @@
28476 #include <asm/alternative-asm.h>
28477 #include <asm/asm.h>
28478 #include <asm/smap.h>
28479-
28480-/*
28481- * By placing feature2 after feature1 in altinstructions section, we logically
28482- * implement:
28483- * If CPU has feature2, jmp to alt2 is used
28484- * else if CPU has feature1, jmp to alt1 is used
28485- * else jmp to orig is used.
28486- */
28487- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28488-0:
28489- .byte 0xe9 /* 32bit jump */
28490- .long \orig-1f /* by default jump to orig */
28491-1:
28492- .section .altinstr_replacement,"ax"
28493-2: .byte 0xe9 /* near jump with 32bit immediate */
28494- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28495-3: .byte 0xe9 /* near jump with 32bit immediate */
28496- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28497- .previous
28498-
28499- .section .altinstructions,"a"
28500- altinstruction_entry 0b,2b,\feature1,5,5
28501- altinstruction_entry 0b,3b,\feature2,5,5
28502- .previous
28503- .endm
28504+#include <asm/pgtable.h>
28505
28506 .macro ALIGN_DESTINATION
28507 #ifdef FIX_ALIGNMENT
28508@@ -70,52 +46,6 @@
28509 #endif
28510 .endm
28511
28512-/* Standard copy_to_user with segment limit checking */
28513-ENTRY(_copy_to_user)
28514- CFI_STARTPROC
28515- GET_THREAD_INFO(%rax)
28516- movq %rdi,%rcx
28517- addq %rdx,%rcx
28518- jc bad_to_user
28519- cmpq TI_addr_limit(%rax),%rcx
28520- ja bad_to_user
28521- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28522- copy_user_generic_unrolled,copy_user_generic_string, \
28523- copy_user_enhanced_fast_string
28524- CFI_ENDPROC
28525-ENDPROC(_copy_to_user)
28526-
28527-/* Standard copy_from_user with segment limit checking */
28528-ENTRY(_copy_from_user)
28529- CFI_STARTPROC
28530- GET_THREAD_INFO(%rax)
28531- movq %rsi,%rcx
28532- addq %rdx,%rcx
28533- jc bad_from_user
28534- cmpq TI_addr_limit(%rax),%rcx
28535- ja bad_from_user
28536- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28537- copy_user_generic_unrolled,copy_user_generic_string, \
28538- copy_user_enhanced_fast_string
28539- CFI_ENDPROC
28540-ENDPROC(_copy_from_user)
28541-
28542- .section .fixup,"ax"
28543- /* must zero dest */
28544-ENTRY(bad_from_user)
28545-bad_from_user:
28546- CFI_STARTPROC
28547- movl %edx,%ecx
28548- xorl %eax,%eax
28549- rep
28550- stosb
28551-bad_to_user:
28552- movl %edx,%eax
28553- ret
28554- CFI_ENDPROC
28555-ENDPROC(bad_from_user)
28556- .previous
28557-
28558 /*
28559 * copy_user_generic_unrolled - memory copy with exception handling.
28560 * This version is for CPUs like P4 that don't have efficient micro
28561@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28562 */
28563 ENTRY(copy_user_generic_unrolled)
28564 CFI_STARTPROC
28565+ ASM_PAX_OPEN_USERLAND
28566 ASM_STAC
28567 cmpl $8,%edx
28568 jb 20f /* less then 8 bytes, go to byte copy loop */
28569@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28570 jnz 21b
28571 23: xor %eax,%eax
28572 ASM_CLAC
28573+ ASM_PAX_CLOSE_USERLAND
28574+ pax_force_retaddr
28575 ret
28576
28577 .section .fixup,"ax"
28578@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28579 */
28580 ENTRY(copy_user_generic_string)
28581 CFI_STARTPROC
28582+ ASM_PAX_OPEN_USERLAND
28583 ASM_STAC
28584 andl %edx,%edx
28585 jz 4f
28586@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28587 movsb
28588 4: xorl %eax,%eax
28589 ASM_CLAC
28590+ ASM_PAX_CLOSE_USERLAND
28591+ pax_force_retaddr
28592 ret
28593
28594 .section .fixup,"ax"
28595@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28596 */
28597 ENTRY(copy_user_enhanced_fast_string)
28598 CFI_STARTPROC
28599+ ASM_PAX_OPEN_USERLAND
28600 ASM_STAC
28601 andl %edx,%edx
28602 jz 2f
28603@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28604 movsb
28605 2: xorl %eax,%eax
28606 ASM_CLAC
28607+ ASM_PAX_CLOSE_USERLAND
28608+ pax_force_retaddr
28609 ret
28610
28611 .section .fixup,"ax"
28612diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28613index 6a4f43c..c70fb52 100644
28614--- a/arch/x86/lib/copy_user_nocache_64.S
28615+++ b/arch/x86/lib/copy_user_nocache_64.S
28616@@ -8,6 +8,7 @@
28617
28618 #include <linux/linkage.h>
28619 #include <asm/dwarf2.h>
28620+#include <asm/alternative-asm.h>
28621
28622 #define FIX_ALIGNMENT 1
28623
28624@@ -16,6 +17,7 @@
28625 #include <asm/thread_info.h>
28626 #include <asm/asm.h>
28627 #include <asm/smap.h>
28628+#include <asm/pgtable.h>
28629
28630 .macro ALIGN_DESTINATION
28631 #ifdef FIX_ALIGNMENT
28632@@ -49,6 +51,16 @@
28633 */
28634 ENTRY(__copy_user_nocache)
28635 CFI_STARTPROC
28636+
28637+#ifdef CONFIG_PAX_MEMORY_UDEREF
28638+ mov pax_user_shadow_base,%rcx
28639+ cmp %rcx,%rsi
28640+ jae 1f
28641+ add %rcx,%rsi
28642+1:
28643+#endif
28644+
28645+ ASM_PAX_OPEN_USERLAND
28646 ASM_STAC
28647 cmpl $8,%edx
28648 jb 20f /* less then 8 bytes, go to byte copy loop */
28649@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28650 jnz 21b
28651 23: xorl %eax,%eax
28652 ASM_CLAC
28653+ ASM_PAX_CLOSE_USERLAND
28654 sfence
28655+ pax_force_retaddr
28656 ret
28657
28658 .section .fixup,"ax"
28659diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28660index 2419d5f..fe52d0e 100644
28661--- a/arch/x86/lib/csum-copy_64.S
28662+++ b/arch/x86/lib/csum-copy_64.S
28663@@ -9,6 +9,7 @@
28664 #include <asm/dwarf2.h>
28665 #include <asm/errno.h>
28666 #include <asm/asm.h>
28667+#include <asm/alternative-asm.h>
28668
28669 /*
28670 * Checksum copy with exception handling.
28671@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28672 CFI_ADJUST_CFA_OFFSET 7*8
28673 movq %rbx, 2*8(%rsp)
28674 CFI_REL_OFFSET rbx, 2*8
28675- movq %r12, 3*8(%rsp)
28676- CFI_REL_OFFSET r12, 3*8
28677+ movq %r15, 3*8(%rsp)
28678+ CFI_REL_OFFSET r15, 3*8
28679 movq %r14, 4*8(%rsp)
28680 CFI_REL_OFFSET r14, 4*8
28681 movq %r13, 5*8(%rsp)
28682@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28683 movl %edx, %ecx
28684
28685 xorl %r9d, %r9d
28686- movq %rcx, %r12
28687+ movq %rcx, %r15
28688
28689- shrq $6, %r12
28690+ shrq $6, %r15
28691 jz .Lhandle_tail /* < 64 */
28692
28693 clc
28694
28695 /* main loop. clear in 64 byte blocks */
28696 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28697- /* r11: temp3, rdx: temp4, r12 loopcnt */
28698+ /* r11: temp3, rdx: temp4, r15 loopcnt */
28699 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28700 .p2align 4
28701 .Lloop:
28702@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28703 adcq %r14, %rax
28704 adcq %r13, %rax
28705
28706- decl %r12d
28707+ decl %r15d
28708
28709 dest
28710 movq %rbx, (%rsi)
28711@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28712 .Lende:
28713 movq 2*8(%rsp), %rbx
28714 CFI_RESTORE rbx
28715- movq 3*8(%rsp), %r12
28716- CFI_RESTORE r12
28717+ movq 3*8(%rsp), %r15
28718+ CFI_RESTORE r15
28719 movq 4*8(%rsp), %r14
28720 CFI_RESTORE r14
28721 movq 5*8(%rsp), %r13
28722@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28723 CFI_RESTORE rbp
28724 addq $7*8, %rsp
28725 CFI_ADJUST_CFA_OFFSET -7*8
28726+ pax_force_retaddr
28727 ret
28728 CFI_RESTORE_STATE
28729
28730diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28731index 7609e0e..b449b98 100644
28732--- a/arch/x86/lib/csum-wrappers_64.c
28733+++ b/arch/x86/lib/csum-wrappers_64.c
28734@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28735 len -= 2;
28736 }
28737 }
28738+ pax_open_userland();
28739 stac();
28740- isum = csum_partial_copy_generic((__force const void *)src,
28741+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28742 dst, len, isum, errp, NULL);
28743 clac();
28744+ pax_close_userland();
28745 if (unlikely(*errp))
28746 goto out_err;
28747
28748@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28749 }
28750
28751 *errp = 0;
28752+ pax_open_userland();
28753 stac();
28754- ret = csum_partial_copy_generic(src, (void __force *)dst,
28755+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28756 len, isum, NULL, errp);
28757 clac();
28758+ pax_close_userland();
28759 return ret;
28760 }
28761 EXPORT_SYMBOL(csum_partial_copy_to_user);
28762diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28763index a451235..1daa956 100644
28764--- a/arch/x86/lib/getuser.S
28765+++ b/arch/x86/lib/getuser.S
28766@@ -33,17 +33,40 @@
28767 #include <asm/thread_info.h>
28768 #include <asm/asm.h>
28769 #include <asm/smap.h>
28770+#include <asm/segment.h>
28771+#include <asm/pgtable.h>
28772+#include <asm/alternative-asm.h>
28773+
28774+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28775+#define __copyuser_seg gs;
28776+#else
28777+#define __copyuser_seg
28778+#endif
28779
28780 .text
28781 ENTRY(__get_user_1)
28782 CFI_STARTPROC
28783+
28784+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28785 GET_THREAD_INFO(%_ASM_DX)
28786 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28787 jae bad_get_user
28788 ASM_STAC
28789-1: movzbl (%_ASM_AX),%edx
28790+
28791+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28792+ mov pax_user_shadow_base,%_ASM_DX
28793+ cmp %_ASM_DX,%_ASM_AX
28794+ jae 1234f
28795+ add %_ASM_DX,%_ASM_AX
28796+1234:
28797+#endif
28798+
28799+#endif
28800+
28801+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28802 xor %eax,%eax
28803 ASM_CLAC
28804+ pax_force_retaddr
28805 ret
28806 CFI_ENDPROC
28807 ENDPROC(__get_user_1)
28808@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28809 ENTRY(__get_user_2)
28810 CFI_STARTPROC
28811 add $1,%_ASM_AX
28812+
28813+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28814 jc bad_get_user
28815 GET_THREAD_INFO(%_ASM_DX)
28816 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28817 jae bad_get_user
28818 ASM_STAC
28819-2: movzwl -1(%_ASM_AX),%edx
28820+
28821+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28822+ mov pax_user_shadow_base,%_ASM_DX
28823+ cmp %_ASM_DX,%_ASM_AX
28824+ jae 1234f
28825+ add %_ASM_DX,%_ASM_AX
28826+1234:
28827+#endif
28828+
28829+#endif
28830+
28831+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28832 xor %eax,%eax
28833 ASM_CLAC
28834+ pax_force_retaddr
28835 ret
28836 CFI_ENDPROC
28837 ENDPROC(__get_user_2)
28838@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28839 ENTRY(__get_user_4)
28840 CFI_STARTPROC
28841 add $3,%_ASM_AX
28842+
28843+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28844 jc bad_get_user
28845 GET_THREAD_INFO(%_ASM_DX)
28846 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28847 jae bad_get_user
28848 ASM_STAC
28849-3: movl -3(%_ASM_AX),%edx
28850+
28851+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28852+ mov pax_user_shadow_base,%_ASM_DX
28853+ cmp %_ASM_DX,%_ASM_AX
28854+ jae 1234f
28855+ add %_ASM_DX,%_ASM_AX
28856+1234:
28857+#endif
28858+
28859+#endif
28860+
28861+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28862 xor %eax,%eax
28863 ASM_CLAC
28864+ pax_force_retaddr
28865 ret
28866 CFI_ENDPROC
28867 ENDPROC(__get_user_4)
28868@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28869 GET_THREAD_INFO(%_ASM_DX)
28870 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28871 jae bad_get_user
28872+
28873+#ifdef CONFIG_PAX_MEMORY_UDEREF
28874+ mov pax_user_shadow_base,%_ASM_DX
28875+ cmp %_ASM_DX,%_ASM_AX
28876+ jae 1234f
28877+ add %_ASM_DX,%_ASM_AX
28878+1234:
28879+#endif
28880+
28881 ASM_STAC
28882 4: movq -7(%_ASM_AX),%rdx
28883 xor %eax,%eax
28884 ASM_CLAC
28885+ pax_force_retaddr
28886 ret
28887 #else
28888 add $7,%_ASM_AX
28889@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28890 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28891 jae bad_get_user_8
28892 ASM_STAC
28893-4: movl -7(%_ASM_AX),%edx
28894-5: movl -3(%_ASM_AX),%ecx
28895+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28896+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28897 xor %eax,%eax
28898 ASM_CLAC
28899+ pax_force_retaddr
28900 ret
28901 #endif
28902 CFI_ENDPROC
28903@@ -113,6 +175,7 @@ bad_get_user:
28904 xor %edx,%edx
28905 mov $(-EFAULT),%_ASM_AX
28906 ASM_CLAC
28907+ pax_force_retaddr
28908 ret
28909 CFI_ENDPROC
28910 END(bad_get_user)
28911@@ -124,6 +187,7 @@ bad_get_user_8:
28912 xor %ecx,%ecx
28913 mov $(-EFAULT),%_ASM_AX
28914 ASM_CLAC
28915+ pax_force_retaddr
28916 ret
28917 CFI_ENDPROC
28918 END(bad_get_user_8)
28919diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28920index 54fcffe..7be149e 100644
28921--- a/arch/x86/lib/insn.c
28922+++ b/arch/x86/lib/insn.c
28923@@ -20,8 +20,10 @@
28924
28925 #ifdef __KERNEL__
28926 #include <linux/string.h>
28927+#include <asm/pgtable_types.h>
28928 #else
28929 #include <string.h>
28930+#define ktla_ktva(addr) addr
28931 #endif
28932 #include <asm/inat.h>
28933 #include <asm/insn.h>
28934@@ -53,8 +55,8 @@
28935 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28936 {
28937 memset(insn, 0, sizeof(*insn));
28938- insn->kaddr = kaddr;
28939- insn->next_byte = kaddr;
28940+ insn->kaddr = ktla_ktva(kaddr);
28941+ insn->next_byte = ktla_ktva(kaddr);
28942 insn->x86_64 = x86_64 ? 1 : 0;
28943 insn->opnd_bytes = 4;
28944 if (x86_64)
28945diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28946index 05a95e7..326f2fa 100644
28947--- a/arch/x86/lib/iomap_copy_64.S
28948+++ b/arch/x86/lib/iomap_copy_64.S
28949@@ -17,6 +17,7 @@
28950
28951 #include <linux/linkage.h>
28952 #include <asm/dwarf2.h>
28953+#include <asm/alternative-asm.h>
28954
28955 /*
28956 * override generic version in lib/iomap_copy.c
28957@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28958 CFI_STARTPROC
28959 movl %edx,%ecx
28960 rep movsd
28961+ pax_force_retaddr
28962 ret
28963 CFI_ENDPROC
28964 ENDPROC(__iowrite32_copy)
28965diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28966index 56313a3..0db417e 100644
28967--- a/arch/x86/lib/memcpy_64.S
28968+++ b/arch/x86/lib/memcpy_64.S
28969@@ -24,7 +24,7 @@
28970 * This gets patched over the unrolled variant (below) via the
28971 * alternative instructions framework:
28972 */
28973- .section .altinstr_replacement, "ax", @progbits
28974+ .section .altinstr_replacement, "a", @progbits
28975 .Lmemcpy_c:
28976 movq %rdi, %rax
28977 movq %rdx, %rcx
28978@@ -33,6 +33,7 @@
28979 rep movsq
28980 movl %edx, %ecx
28981 rep movsb
28982+ pax_force_retaddr
28983 ret
28984 .Lmemcpy_e:
28985 .previous
28986@@ -44,11 +45,12 @@
28987 * This gets patched over the unrolled variant (below) via the
28988 * alternative instructions framework:
28989 */
28990- .section .altinstr_replacement, "ax", @progbits
28991+ .section .altinstr_replacement, "a", @progbits
28992 .Lmemcpy_c_e:
28993 movq %rdi, %rax
28994 movq %rdx, %rcx
28995 rep movsb
28996+ pax_force_retaddr
28997 ret
28998 .Lmemcpy_e_e:
28999 .previous
29000@@ -136,6 +138,7 @@ ENTRY(memcpy)
29001 movq %r9, 1*8(%rdi)
29002 movq %r10, -2*8(%rdi, %rdx)
29003 movq %r11, -1*8(%rdi, %rdx)
29004+ pax_force_retaddr
29005 retq
29006 .p2align 4
29007 .Lless_16bytes:
29008@@ -148,6 +151,7 @@ ENTRY(memcpy)
29009 movq -1*8(%rsi, %rdx), %r9
29010 movq %r8, 0*8(%rdi)
29011 movq %r9, -1*8(%rdi, %rdx)
29012+ pax_force_retaddr
29013 retq
29014 .p2align 4
29015 .Lless_8bytes:
29016@@ -161,6 +165,7 @@ ENTRY(memcpy)
29017 movl -4(%rsi, %rdx), %r8d
29018 movl %ecx, (%rdi)
29019 movl %r8d, -4(%rdi, %rdx)
29020+ pax_force_retaddr
29021 retq
29022 .p2align 4
29023 .Lless_3bytes:
29024@@ -179,6 +184,7 @@ ENTRY(memcpy)
29025 movb %cl, (%rdi)
29026
29027 .Lend:
29028+ pax_force_retaddr
29029 retq
29030 CFI_ENDPROC
29031 ENDPROC(memcpy)
29032diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29033index 65268a6..dd1de11 100644
29034--- a/arch/x86/lib/memmove_64.S
29035+++ b/arch/x86/lib/memmove_64.S
29036@@ -202,14 +202,16 @@ ENTRY(memmove)
29037 movb (%rsi), %r11b
29038 movb %r11b, (%rdi)
29039 13:
29040+ pax_force_retaddr
29041 retq
29042 CFI_ENDPROC
29043
29044- .section .altinstr_replacement,"ax"
29045+ .section .altinstr_replacement,"a"
29046 .Lmemmove_begin_forward_efs:
29047 /* Forward moving data. */
29048 movq %rdx, %rcx
29049 rep movsb
29050+ pax_force_retaddr
29051 retq
29052 .Lmemmove_end_forward_efs:
29053 .previous
29054diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29055index 2dcb380..2eb79fe 100644
29056--- a/arch/x86/lib/memset_64.S
29057+++ b/arch/x86/lib/memset_64.S
29058@@ -16,7 +16,7 @@
29059 *
29060 * rax original destination
29061 */
29062- .section .altinstr_replacement, "ax", @progbits
29063+ .section .altinstr_replacement, "a", @progbits
29064 .Lmemset_c:
29065 movq %rdi,%r9
29066 movq %rdx,%rcx
29067@@ -30,6 +30,7 @@
29068 movl %edx,%ecx
29069 rep stosb
29070 movq %r9,%rax
29071+ pax_force_retaddr
29072 ret
29073 .Lmemset_e:
29074 .previous
29075@@ -45,13 +46,14 @@
29076 *
29077 * rax original destination
29078 */
29079- .section .altinstr_replacement, "ax", @progbits
29080+ .section .altinstr_replacement, "a", @progbits
29081 .Lmemset_c_e:
29082 movq %rdi,%r9
29083 movb %sil,%al
29084 movq %rdx,%rcx
29085 rep stosb
29086 movq %r9,%rax
29087+ pax_force_retaddr
29088 ret
29089 .Lmemset_e_e:
29090 .previous
29091@@ -118,6 +120,7 @@ ENTRY(__memset)
29092
29093 .Lende:
29094 movq %r10,%rax
29095+ pax_force_retaddr
29096 ret
29097
29098 CFI_RESTORE_STATE
29099diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29100index c9f2d9b..e7fd2c0 100644
29101--- a/arch/x86/lib/mmx_32.c
29102+++ b/arch/x86/lib/mmx_32.c
29103@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29104 {
29105 void *p;
29106 int i;
29107+ unsigned long cr0;
29108
29109 if (unlikely(in_interrupt()))
29110 return __memcpy(to, from, len);
29111@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29112 kernel_fpu_begin();
29113
29114 __asm__ __volatile__ (
29115- "1: prefetch (%0)\n" /* This set is 28 bytes */
29116- " prefetch 64(%0)\n"
29117- " prefetch 128(%0)\n"
29118- " prefetch 192(%0)\n"
29119- " prefetch 256(%0)\n"
29120+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29121+ " prefetch 64(%1)\n"
29122+ " prefetch 128(%1)\n"
29123+ " prefetch 192(%1)\n"
29124+ " prefetch 256(%1)\n"
29125 "2: \n"
29126 ".section .fixup, \"ax\"\n"
29127- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29128+ "3: \n"
29129+
29130+#ifdef CONFIG_PAX_KERNEXEC
29131+ " movl %%cr0, %0\n"
29132+ " movl %0, %%eax\n"
29133+ " andl $0xFFFEFFFF, %%eax\n"
29134+ " movl %%eax, %%cr0\n"
29135+#endif
29136+
29137+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29138+
29139+#ifdef CONFIG_PAX_KERNEXEC
29140+ " movl %0, %%cr0\n"
29141+#endif
29142+
29143 " jmp 2b\n"
29144 ".previous\n"
29145 _ASM_EXTABLE(1b, 3b)
29146- : : "r" (from));
29147+ : "=&r" (cr0) : "r" (from) : "ax");
29148
29149 for ( ; i > 5; i--) {
29150 __asm__ __volatile__ (
29151- "1: prefetch 320(%0)\n"
29152- "2: movq (%0), %%mm0\n"
29153- " movq 8(%0), %%mm1\n"
29154- " movq 16(%0), %%mm2\n"
29155- " movq 24(%0), %%mm3\n"
29156- " movq %%mm0, (%1)\n"
29157- " movq %%mm1, 8(%1)\n"
29158- " movq %%mm2, 16(%1)\n"
29159- " movq %%mm3, 24(%1)\n"
29160- " movq 32(%0), %%mm0\n"
29161- " movq 40(%0), %%mm1\n"
29162- " movq 48(%0), %%mm2\n"
29163- " movq 56(%0), %%mm3\n"
29164- " movq %%mm0, 32(%1)\n"
29165- " movq %%mm1, 40(%1)\n"
29166- " movq %%mm2, 48(%1)\n"
29167- " movq %%mm3, 56(%1)\n"
29168+ "1: prefetch 320(%1)\n"
29169+ "2: movq (%1), %%mm0\n"
29170+ " movq 8(%1), %%mm1\n"
29171+ " movq 16(%1), %%mm2\n"
29172+ " movq 24(%1), %%mm3\n"
29173+ " movq %%mm0, (%2)\n"
29174+ " movq %%mm1, 8(%2)\n"
29175+ " movq %%mm2, 16(%2)\n"
29176+ " movq %%mm3, 24(%2)\n"
29177+ " movq 32(%1), %%mm0\n"
29178+ " movq 40(%1), %%mm1\n"
29179+ " movq 48(%1), %%mm2\n"
29180+ " movq 56(%1), %%mm3\n"
29181+ " movq %%mm0, 32(%2)\n"
29182+ " movq %%mm1, 40(%2)\n"
29183+ " movq %%mm2, 48(%2)\n"
29184+ " movq %%mm3, 56(%2)\n"
29185 ".section .fixup, \"ax\"\n"
29186- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29187+ "3:\n"
29188+
29189+#ifdef CONFIG_PAX_KERNEXEC
29190+ " movl %%cr0, %0\n"
29191+ " movl %0, %%eax\n"
29192+ " andl $0xFFFEFFFF, %%eax\n"
29193+ " movl %%eax, %%cr0\n"
29194+#endif
29195+
29196+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29197+
29198+#ifdef CONFIG_PAX_KERNEXEC
29199+ " movl %0, %%cr0\n"
29200+#endif
29201+
29202 " jmp 2b\n"
29203 ".previous\n"
29204 _ASM_EXTABLE(1b, 3b)
29205- : : "r" (from), "r" (to) : "memory");
29206+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29207
29208 from += 64;
29209 to += 64;
29210@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29211 static void fast_copy_page(void *to, void *from)
29212 {
29213 int i;
29214+ unsigned long cr0;
29215
29216 kernel_fpu_begin();
29217
29218@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29219 * but that is for later. -AV
29220 */
29221 __asm__ __volatile__(
29222- "1: prefetch (%0)\n"
29223- " prefetch 64(%0)\n"
29224- " prefetch 128(%0)\n"
29225- " prefetch 192(%0)\n"
29226- " prefetch 256(%0)\n"
29227+ "1: prefetch (%1)\n"
29228+ " prefetch 64(%1)\n"
29229+ " prefetch 128(%1)\n"
29230+ " prefetch 192(%1)\n"
29231+ " prefetch 256(%1)\n"
29232 "2: \n"
29233 ".section .fixup, \"ax\"\n"
29234- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29235+ "3: \n"
29236+
29237+#ifdef CONFIG_PAX_KERNEXEC
29238+ " movl %%cr0, %0\n"
29239+ " movl %0, %%eax\n"
29240+ " andl $0xFFFEFFFF, %%eax\n"
29241+ " movl %%eax, %%cr0\n"
29242+#endif
29243+
29244+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29245+
29246+#ifdef CONFIG_PAX_KERNEXEC
29247+ " movl %0, %%cr0\n"
29248+#endif
29249+
29250 " jmp 2b\n"
29251 ".previous\n"
29252- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29253+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29254
29255 for (i = 0; i < (4096-320)/64; i++) {
29256 __asm__ __volatile__ (
29257- "1: prefetch 320(%0)\n"
29258- "2: movq (%0), %%mm0\n"
29259- " movntq %%mm0, (%1)\n"
29260- " movq 8(%0), %%mm1\n"
29261- " movntq %%mm1, 8(%1)\n"
29262- " movq 16(%0), %%mm2\n"
29263- " movntq %%mm2, 16(%1)\n"
29264- " movq 24(%0), %%mm3\n"
29265- " movntq %%mm3, 24(%1)\n"
29266- " movq 32(%0), %%mm4\n"
29267- " movntq %%mm4, 32(%1)\n"
29268- " movq 40(%0), %%mm5\n"
29269- " movntq %%mm5, 40(%1)\n"
29270- " movq 48(%0), %%mm6\n"
29271- " movntq %%mm6, 48(%1)\n"
29272- " movq 56(%0), %%mm7\n"
29273- " movntq %%mm7, 56(%1)\n"
29274+ "1: prefetch 320(%1)\n"
29275+ "2: movq (%1), %%mm0\n"
29276+ " movntq %%mm0, (%2)\n"
29277+ " movq 8(%1), %%mm1\n"
29278+ " movntq %%mm1, 8(%2)\n"
29279+ " movq 16(%1), %%mm2\n"
29280+ " movntq %%mm2, 16(%2)\n"
29281+ " movq 24(%1), %%mm3\n"
29282+ " movntq %%mm3, 24(%2)\n"
29283+ " movq 32(%1), %%mm4\n"
29284+ " movntq %%mm4, 32(%2)\n"
29285+ " movq 40(%1), %%mm5\n"
29286+ " movntq %%mm5, 40(%2)\n"
29287+ " movq 48(%1), %%mm6\n"
29288+ " movntq %%mm6, 48(%2)\n"
29289+ " movq 56(%1), %%mm7\n"
29290+ " movntq %%mm7, 56(%2)\n"
29291 ".section .fixup, \"ax\"\n"
29292- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29293+ "3:\n"
29294+
29295+#ifdef CONFIG_PAX_KERNEXEC
29296+ " movl %%cr0, %0\n"
29297+ " movl %0, %%eax\n"
29298+ " andl $0xFFFEFFFF, %%eax\n"
29299+ " movl %%eax, %%cr0\n"
29300+#endif
29301+
29302+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29303+
29304+#ifdef CONFIG_PAX_KERNEXEC
29305+ " movl %0, %%cr0\n"
29306+#endif
29307+
29308 " jmp 2b\n"
29309 ".previous\n"
29310- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29311+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29312
29313 from += 64;
29314 to += 64;
29315@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29316 static void fast_copy_page(void *to, void *from)
29317 {
29318 int i;
29319+ unsigned long cr0;
29320
29321 kernel_fpu_begin();
29322
29323 __asm__ __volatile__ (
29324- "1: prefetch (%0)\n"
29325- " prefetch 64(%0)\n"
29326- " prefetch 128(%0)\n"
29327- " prefetch 192(%0)\n"
29328- " prefetch 256(%0)\n"
29329+ "1: prefetch (%1)\n"
29330+ " prefetch 64(%1)\n"
29331+ " prefetch 128(%1)\n"
29332+ " prefetch 192(%1)\n"
29333+ " prefetch 256(%1)\n"
29334 "2: \n"
29335 ".section .fixup, \"ax\"\n"
29336- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29337+ "3: \n"
29338+
29339+#ifdef CONFIG_PAX_KERNEXEC
29340+ " movl %%cr0, %0\n"
29341+ " movl %0, %%eax\n"
29342+ " andl $0xFFFEFFFF, %%eax\n"
29343+ " movl %%eax, %%cr0\n"
29344+#endif
29345+
29346+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29347+
29348+#ifdef CONFIG_PAX_KERNEXEC
29349+ " movl %0, %%cr0\n"
29350+#endif
29351+
29352 " jmp 2b\n"
29353 ".previous\n"
29354- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29355+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29356
29357 for (i = 0; i < 4096/64; i++) {
29358 __asm__ __volatile__ (
29359- "1: prefetch 320(%0)\n"
29360- "2: movq (%0), %%mm0\n"
29361- " movq 8(%0), %%mm1\n"
29362- " movq 16(%0), %%mm2\n"
29363- " movq 24(%0), %%mm3\n"
29364- " movq %%mm0, (%1)\n"
29365- " movq %%mm1, 8(%1)\n"
29366- " movq %%mm2, 16(%1)\n"
29367- " movq %%mm3, 24(%1)\n"
29368- " movq 32(%0), %%mm0\n"
29369- " movq 40(%0), %%mm1\n"
29370- " movq 48(%0), %%mm2\n"
29371- " movq 56(%0), %%mm3\n"
29372- " movq %%mm0, 32(%1)\n"
29373- " movq %%mm1, 40(%1)\n"
29374- " movq %%mm2, 48(%1)\n"
29375- " movq %%mm3, 56(%1)\n"
29376+ "1: prefetch 320(%1)\n"
29377+ "2: movq (%1), %%mm0\n"
29378+ " movq 8(%1), %%mm1\n"
29379+ " movq 16(%1), %%mm2\n"
29380+ " movq 24(%1), %%mm3\n"
29381+ " movq %%mm0, (%2)\n"
29382+ " movq %%mm1, 8(%2)\n"
29383+ " movq %%mm2, 16(%2)\n"
29384+ " movq %%mm3, 24(%2)\n"
29385+ " movq 32(%1), %%mm0\n"
29386+ " movq 40(%1), %%mm1\n"
29387+ " movq 48(%1), %%mm2\n"
29388+ " movq 56(%1), %%mm3\n"
29389+ " movq %%mm0, 32(%2)\n"
29390+ " movq %%mm1, 40(%2)\n"
29391+ " movq %%mm2, 48(%2)\n"
29392+ " movq %%mm3, 56(%2)\n"
29393 ".section .fixup, \"ax\"\n"
29394- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29395+ "3:\n"
29396+
29397+#ifdef CONFIG_PAX_KERNEXEC
29398+ " movl %%cr0, %0\n"
29399+ " movl %0, %%eax\n"
29400+ " andl $0xFFFEFFFF, %%eax\n"
29401+ " movl %%eax, %%cr0\n"
29402+#endif
29403+
29404+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29405+
29406+#ifdef CONFIG_PAX_KERNEXEC
29407+ " movl %0, %%cr0\n"
29408+#endif
29409+
29410 " jmp 2b\n"
29411 ".previous\n"
29412 _ASM_EXTABLE(1b, 3b)
29413- : : "r" (from), "r" (to) : "memory");
29414+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29415
29416 from += 64;
29417 to += 64;
29418diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29419index f6d13ee..d789440 100644
29420--- a/arch/x86/lib/msr-reg.S
29421+++ b/arch/x86/lib/msr-reg.S
29422@@ -3,6 +3,7 @@
29423 #include <asm/dwarf2.h>
29424 #include <asm/asm.h>
29425 #include <asm/msr.h>
29426+#include <asm/alternative-asm.h>
29427
29428 #ifdef CONFIG_X86_64
29429 /*
29430@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29431 movl %edi, 28(%r10)
29432 popq_cfi %rbp
29433 popq_cfi %rbx
29434+ pax_force_retaddr
29435 ret
29436 3:
29437 CFI_RESTORE_STATE
29438diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29439index fc6ba17..d4d989d 100644
29440--- a/arch/x86/lib/putuser.S
29441+++ b/arch/x86/lib/putuser.S
29442@@ -16,7 +16,9 @@
29443 #include <asm/errno.h>
29444 #include <asm/asm.h>
29445 #include <asm/smap.h>
29446-
29447+#include <asm/segment.h>
29448+#include <asm/pgtable.h>
29449+#include <asm/alternative-asm.h>
29450
29451 /*
29452 * __put_user_X
29453@@ -30,57 +32,125 @@
29454 * as they get called from within inline assembly.
29455 */
29456
29457-#define ENTER CFI_STARTPROC ; \
29458- GET_THREAD_INFO(%_ASM_BX)
29459-#define EXIT ASM_CLAC ; \
29460- ret ; \
29461+#define ENTER CFI_STARTPROC
29462+#define EXIT ASM_CLAC ; \
29463+ pax_force_retaddr ; \
29464+ ret ; \
29465 CFI_ENDPROC
29466
29467+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29468+#define _DEST %_ASM_CX,%_ASM_BX
29469+#else
29470+#define _DEST %_ASM_CX
29471+#endif
29472+
29473+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29474+#define __copyuser_seg gs;
29475+#else
29476+#define __copyuser_seg
29477+#endif
29478+
29479 .text
29480 ENTRY(__put_user_1)
29481 ENTER
29482+
29483+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29484+ GET_THREAD_INFO(%_ASM_BX)
29485 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29486 jae bad_put_user
29487 ASM_STAC
29488-1: movb %al,(%_ASM_CX)
29489+
29490+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29491+ mov pax_user_shadow_base,%_ASM_BX
29492+ cmp %_ASM_BX,%_ASM_CX
29493+ jb 1234f
29494+ xor %ebx,%ebx
29495+1234:
29496+#endif
29497+
29498+#endif
29499+
29500+1: __copyuser_seg movb %al,(_DEST)
29501 xor %eax,%eax
29502 EXIT
29503 ENDPROC(__put_user_1)
29504
29505 ENTRY(__put_user_2)
29506 ENTER
29507+
29508+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29509+ GET_THREAD_INFO(%_ASM_BX)
29510 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29511 sub $1,%_ASM_BX
29512 cmp %_ASM_BX,%_ASM_CX
29513 jae bad_put_user
29514 ASM_STAC
29515-2: movw %ax,(%_ASM_CX)
29516+
29517+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29518+ mov pax_user_shadow_base,%_ASM_BX
29519+ cmp %_ASM_BX,%_ASM_CX
29520+ jb 1234f
29521+ xor %ebx,%ebx
29522+1234:
29523+#endif
29524+
29525+#endif
29526+
29527+2: __copyuser_seg movw %ax,(_DEST)
29528 xor %eax,%eax
29529 EXIT
29530 ENDPROC(__put_user_2)
29531
29532 ENTRY(__put_user_4)
29533 ENTER
29534+
29535+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29536+ GET_THREAD_INFO(%_ASM_BX)
29537 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29538 sub $3,%_ASM_BX
29539 cmp %_ASM_BX,%_ASM_CX
29540 jae bad_put_user
29541 ASM_STAC
29542-3: movl %eax,(%_ASM_CX)
29543+
29544+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29545+ mov pax_user_shadow_base,%_ASM_BX
29546+ cmp %_ASM_BX,%_ASM_CX
29547+ jb 1234f
29548+ xor %ebx,%ebx
29549+1234:
29550+#endif
29551+
29552+#endif
29553+
29554+3: __copyuser_seg movl %eax,(_DEST)
29555 xor %eax,%eax
29556 EXIT
29557 ENDPROC(__put_user_4)
29558
29559 ENTRY(__put_user_8)
29560 ENTER
29561+
29562+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29563+ GET_THREAD_INFO(%_ASM_BX)
29564 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29565 sub $7,%_ASM_BX
29566 cmp %_ASM_BX,%_ASM_CX
29567 jae bad_put_user
29568 ASM_STAC
29569-4: mov %_ASM_AX,(%_ASM_CX)
29570+
29571+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29572+ mov pax_user_shadow_base,%_ASM_BX
29573+ cmp %_ASM_BX,%_ASM_CX
29574+ jb 1234f
29575+ xor %ebx,%ebx
29576+1234:
29577+#endif
29578+
29579+#endif
29580+
29581+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29582 #ifdef CONFIG_X86_32
29583-5: movl %edx,4(%_ASM_CX)
29584+5: __copyuser_seg movl %edx,4(_DEST)
29585 #endif
29586 xor %eax,%eax
29587 EXIT
29588diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29589index 1cad221..de671ee 100644
29590--- a/arch/x86/lib/rwlock.S
29591+++ b/arch/x86/lib/rwlock.S
29592@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29593 FRAME
29594 0: LOCK_PREFIX
29595 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29596+
29597+#ifdef CONFIG_PAX_REFCOUNT
29598+ jno 1234f
29599+ LOCK_PREFIX
29600+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29601+ int $4
29602+1234:
29603+ _ASM_EXTABLE(1234b, 1234b)
29604+#endif
29605+
29606 1: rep; nop
29607 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29608 jne 1b
29609 LOCK_PREFIX
29610 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29611+
29612+#ifdef CONFIG_PAX_REFCOUNT
29613+ jno 1234f
29614+ LOCK_PREFIX
29615+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29616+ int $4
29617+1234:
29618+ _ASM_EXTABLE(1234b, 1234b)
29619+#endif
29620+
29621 jnz 0b
29622 ENDFRAME
29623+ pax_force_retaddr
29624 ret
29625 CFI_ENDPROC
29626 END(__write_lock_failed)
29627@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29628 FRAME
29629 0: LOCK_PREFIX
29630 READ_LOCK_SIZE(inc) (%__lock_ptr)
29631+
29632+#ifdef CONFIG_PAX_REFCOUNT
29633+ jno 1234f
29634+ LOCK_PREFIX
29635+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29636+ int $4
29637+1234:
29638+ _ASM_EXTABLE(1234b, 1234b)
29639+#endif
29640+
29641 1: rep; nop
29642 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29643 js 1b
29644 LOCK_PREFIX
29645 READ_LOCK_SIZE(dec) (%__lock_ptr)
29646+
29647+#ifdef CONFIG_PAX_REFCOUNT
29648+ jno 1234f
29649+ LOCK_PREFIX
29650+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29651+ int $4
29652+1234:
29653+ _ASM_EXTABLE(1234b, 1234b)
29654+#endif
29655+
29656 js 0b
29657 ENDFRAME
29658+ pax_force_retaddr
29659 ret
29660 CFI_ENDPROC
29661 END(__read_lock_failed)
29662diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29663index 5dff5f0..cadebf4 100644
29664--- a/arch/x86/lib/rwsem.S
29665+++ b/arch/x86/lib/rwsem.S
29666@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29667 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29668 CFI_RESTORE __ASM_REG(dx)
29669 restore_common_regs
29670+ pax_force_retaddr
29671 ret
29672 CFI_ENDPROC
29673 ENDPROC(call_rwsem_down_read_failed)
29674@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29675 movq %rax,%rdi
29676 call rwsem_down_write_failed
29677 restore_common_regs
29678+ pax_force_retaddr
29679 ret
29680 CFI_ENDPROC
29681 ENDPROC(call_rwsem_down_write_failed)
29682@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29683 movq %rax,%rdi
29684 call rwsem_wake
29685 restore_common_regs
29686-1: ret
29687+1: pax_force_retaddr
29688+ ret
29689 CFI_ENDPROC
29690 ENDPROC(call_rwsem_wake)
29691
29692@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29693 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29694 CFI_RESTORE __ASM_REG(dx)
29695 restore_common_regs
29696+ pax_force_retaddr
29697 ret
29698 CFI_ENDPROC
29699 ENDPROC(call_rwsem_downgrade_wake)
29700diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29701index a63efd6..8149fbe 100644
29702--- a/arch/x86/lib/thunk_64.S
29703+++ b/arch/x86/lib/thunk_64.S
29704@@ -8,6 +8,7 @@
29705 #include <linux/linkage.h>
29706 #include <asm/dwarf2.h>
29707 #include <asm/calling.h>
29708+#include <asm/alternative-asm.h>
29709
29710 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29711 .macro THUNK name, func, put_ret_addr_in_rdi=0
29712@@ -15,11 +16,11 @@
29713 \name:
29714 CFI_STARTPROC
29715
29716- /* this one pushes 9 elems, the next one would be %rIP */
29717- SAVE_ARGS
29718+ /* this one pushes 15+1 elems, the next one would be %rIP */
29719+ SAVE_ARGS 8
29720
29721 .if \put_ret_addr_in_rdi
29722- movq_cfi_restore 9*8, rdi
29723+ movq_cfi_restore RIP, rdi
29724 .endif
29725
29726 call \func
29727@@ -38,8 +39,9 @@
29728
29729 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29730 CFI_STARTPROC
29731- SAVE_ARGS
29732+ SAVE_ARGS 8
29733 restore:
29734- RESTORE_ARGS
29735+ RESTORE_ARGS 1,8
29736+ pax_force_retaddr
29737 ret
29738 CFI_ENDPROC
29739diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29740index 3eb18ac..4b22130 100644
29741--- a/arch/x86/lib/usercopy_32.c
29742+++ b/arch/x86/lib/usercopy_32.c
29743@@ -42,11 +42,13 @@ do { \
29744 int __d0; \
29745 might_fault(); \
29746 __asm__ __volatile__( \
29747+ __COPYUSER_SET_ES \
29748 ASM_STAC "\n" \
29749 "0: rep; stosl\n" \
29750 " movl %2,%0\n" \
29751 "1: rep; stosb\n" \
29752 "2: " ASM_CLAC "\n" \
29753+ __COPYUSER_RESTORE_ES \
29754 ".section .fixup,\"ax\"\n" \
29755 "3: lea 0(%2,%0,4),%0\n" \
29756 " jmp 2b\n" \
29757@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29758
29759 #ifdef CONFIG_X86_INTEL_USERCOPY
29760 static unsigned long
29761-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29762+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29763 {
29764 int d0, d1;
29765 __asm__ __volatile__(
29766@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29767 " .align 2,0x90\n"
29768 "3: movl 0(%4), %%eax\n"
29769 "4: movl 4(%4), %%edx\n"
29770- "5: movl %%eax, 0(%3)\n"
29771- "6: movl %%edx, 4(%3)\n"
29772+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29773+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29774 "7: movl 8(%4), %%eax\n"
29775 "8: movl 12(%4),%%edx\n"
29776- "9: movl %%eax, 8(%3)\n"
29777- "10: movl %%edx, 12(%3)\n"
29778+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29779+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29780 "11: movl 16(%4), %%eax\n"
29781 "12: movl 20(%4), %%edx\n"
29782- "13: movl %%eax, 16(%3)\n"
29783- "14: movl %%edx, 20(%3)\n"
29784+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29785+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29786 "15: movl 24(%4), %%eax\n"
29787 "16: movl 28(%4), %%edx\n"
29788- "17: movl %%eax, 24(%3)\n"
29789- "18: movl %%edx, 28(%3)\n"
29790+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29791+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29792 "19: movl 32(%4), %%eax\n"
29793 "20: movl 36(%4), %%edx\n"
29794- "21: movl %%eax, 32(%3)\n"
29795- "22: movl %%edx, 36(%3)\n"
29796+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29797+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29798 "23: movl 40(%4), %%eax\n"
29799 "24: movl 44(%4), %%edx\n"
29800- "25: movl %%eax, 40(%3)\n"
29801- "26: movl %%edx, 44(%3)\n"
29802+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29803+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29804 "27: movl 48(%4), %%eax\n"
29805 "28: movl 52(%4), %%edx\n"
29806- "29: movl %%eax, 48(%3)\n"
29807- "30: movl %%edx, 52(%3)\n"
29808+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29809+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29810 "31: movl 56(%4), %%eax\n"
29811 "32: movl 60(%4), %%edx\n"
29812- "33: movl %%eax, 56(%3)\n"
29813- "34: movl %%edx, 60(%3)\n"
29814+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29815+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29816 " addl $-64, %0\n"
29817 " addl $64, %4\n"
29818 " addl $64, %3\n"
29819@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29820 " shrl $2, %0\n"
29821 " andl $3, %%eax\n"
29822 " cld\n"
29823+ __COPYUSER_SET_ES
29824 "99: rep; movsl\n"
29825 "36: movl %%eax, %0\n"
29826 "37: rep; movsb\n"
29827 "100:\n"
29828+ __COPYUSER_RESTORE_ES
29829+ ".section .fixup,\"ax\"\n"
29830+ "101: lea 0(%%eax,%0,4),%0\n"
29831+ " jmp 100b\n"
29832+ ".previous\n"
29833+ _ASM_EXTABLE(1b,100b)
29834+ _ASM_EXTABLE(2b,100b)
29835+ _ASM_EXTABLE(3b,100b)
29836+ _ASM_EXTABLE(4b,100b)
29837+ _ASM_EXTABLE(5b,100b)
29838+ _ASM_EXTABLE(6b,100b)
29839+ _ASM_EXTABLE(7b,100b)
29840+ _ASM_EXTABLE(8b,100b)
29841+ _ASM_EXTABLE(9b,100b)
29842+ _ASM_EXTABLE(10b,100b)
29843+ _ASM_EXTABLE(11b,100b)
29844+ _ASM_EXTABLE(12b,100b)
29845+ _ASM_EXTABLE(13b,100b)
29846+ _ASM_EXTABLE(14b,100b)
29847+ _ASM_EXTABLE(15b,100b)
29848+ _ASM_EXTABLE(16b,100b)
29849+ _ASM_EXTABLE(17b,100b)
29850+ _ASM_EXTABLE(18b,100b)
29851+ _ASM_EXTABLE(19b,100b)
29852+ _ASM_EXTABLE(20b,100b)
29853+ _ASM_EXTABLE(21b,100b)
29854+ _ASM_EXTABLE(22b,100b)
29855+ _ASM_EXTABLE(23b,100b)
29856+ _ASM_EXTABLE(24b,100b)
29857+ _ASM_EXTABLE(25b,100b)
29858+ _ASM_EXTABLE(26b,100b)
29859+ _ASM_EXTABLE(27b,100b)
29860+ _ASM_EXTABLE(28b,100b)
29861+ _ASM_EXTABLE(29b,100b)
29862+ _ASM_EXTABLE(30b,100b)
29863+ _ASM_EXTABLE(31b,100b)
29864+ _ASM_EXTABLE(32b,100b)
29865+ _ASM_EXTABLE(33b,100b)
29866+ _ASM_EXTABLE(34b,100b)
29867+ _ASM_EXTABLE(35b,100b)
29868+ _ASM_EXTABLE(36b,100b)
29869+ _ASM_EXTABLE(37b,100b)
29870+ _ASM_EXTABLE(99b,101b)
29871+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29872+ : "1"(to), "2"(from), "0"(size)
29873+ : "eax", "edx", "memory");
29874+ return size;
29875+}
29876+
29877+static unsigned long
29878+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29879+{
29880+ int d0, d1;
29881+ __asm__ __volatile__(
29882+ " .align 2,0x90\n"
29883+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29884+ " cmpl $67, %0\n"
29885+ " jbe 3f\n"
29886+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29887+ " .align 2,0x90\n"
29888+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29889+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29890+ "5: movl %%eax, 0(%3)\n"
29891+ "6: movl %%edx, 4(%3)\n"
29892+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29893+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29894+ "9: movl %%eax, 8(%3)\n"
29895+ "10: movl %%edx, 12(%3)\n"
29896+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29897+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29898+ "13: movl %%eax, 16(%3)\n"
29899+ "14: movl %%edx, 20(%3)\n"
29900+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29901+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29902+ "17: movl %%eax, 24(%3)\n"
29903+ "18: movl %%edx, 28(%3)\n"
29904+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29905+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29906+ "21: movl %%eax, 32(%3)\n"
29907+ "22: movl %%edx, 36(%3)\n"
29908+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29909+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29910+ "25: movl %%eax, 40(%3)\n"
29911+ "26: movl %%edx, 44(%3)\n"
29912+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29913+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29914+ "29: movl %%eax, 48(%3)\n"
29915+ "30: movl %%edx, 52(%3)\n"
29916+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29917+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29918+ "33: movl %%eax, 56(%3)\n"
29919+ "34: movl %%edx, 60(%3)\n"
29920+ " addl $-64, %0\n"
29921+ " addl $64, %4\n"
29922+ " addl $64, %3\n"
29923+ " cmpl $63, %0\n"
29924+ " ja 1b\n"
29925+ "35: movl %0, %%eax\n"
29926+ " shrl $2, %0\n"
29927+ " andl $3, %%eax\n"
29928+ " cld\n"
29929+ "99: rep; "__copyuser_seg" movsl\n"
29930+ "36: movl %%eax, %0\n"
29931+ "37: rep; "__copyuser_seg" movsb\n"
29932+ "100:\n"
29933 ".section .fixup,\"ax\"\n"
29934 "101: lea 0(%%eax,%0,4),%0\n"
29935 " jmp 100b\n"
29936@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29937 int d0, d1;
29938 __asm__ __volatile__(
29939 " .align 2,0x90\n"
29940- "0: movl 32(%4), %%eax\n"
29941+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29942 " cmpl $67, %0\n"
29943 " jbe 2f\n"
29944- "1: movl 64(%4), %%eax\n"
29945+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29946 " .align 2,0x90\n"
29947- "2: movl 0(%4), %%eax\n"
29948- "21: movl 4(%4), %%edx\n"
29949+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29950+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29951 " movl %%eax, 0(%3)\n"
29952 " movl %%edx, 4(%3)\n"
29953- "3: movl 8(%4), %%eax\n"
29954- "31: movl 12(%4),%%edx\n"
29955+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29956+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29957 " movl %%eax, 8(%3)\n"
29958 " movl %%edx, 12(%3)\n"
29959- "4: movl 16(%4), %%eax\n"
29960- "41: movl 20(%4), %%edx\n"
29961+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29962+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29963 " movl %%eax, 16(%3)\n"
29964 " movl %%edx, 20(%3)\n"
29965- "10: movl 24(%4), %%eax\n"
29966- "51: movl 28(%4), %%edx\n"
29967+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29968+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29969 " movl %%eax, 24(%3)\n"
29970 " movl %%edx, 28(%3)\n"
29971- "11: movl 32(%4), %%eax\n"
29972- "61: movl 36(%4), %%edx\n"
29973+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29974+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29975 " movl %%eax, 32(%3)\n"
29976 " movl %%edx, 36(%3)\n"
29977- "12: movl 40(%4), %%eax\n"
29978- "71: movl 44(%4), %%edx\n"
29979+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29980+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29981 " movl %%eax, 40(%3)\n"
29982 " movl %%edx, 44(%3)\n"
29983- "13: movl 48(%4), %%eax\n"
29984- "81: movl 52(%4), %%edx\n"
29985+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29986+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29987 " movl %%eax, 48(%3)\n"
29988 " movl %%edx, 52(%3)\n"
29989- "14: movl 56(%4), %%eax\n"
29990- "91: movl 60(%4), %%edx\n"
29991+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29992+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29993 " movl %%eax, 56(%3)\n"
29994 " movl %%edx, 60(%3)\n"
29995 " addl $-64, %0\n"
29996@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29997 " shrl $2, %0\n"
29998 " andl $3, %%eax\n"
29999 " cld\n"
30000- "6: rep; movsl\n"
30001+ "6: rep; "__copyuser_seg" movsl\n"
30002 " movl %%eax,%0\n"
30003- "7: rep; movsb\n"
30004+ "7: rep; "__copyuser_seg" movsb\n"
30005 "8:\n"
30006 ".section .fixup,\"ax\"\n"
30007 "9: lea 0(%%eax,%0,4),%0\n"
30008@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30009
30010 __asm__ __volatile__(
30011 " .align 2,0x90\n"
30012- "0: movl 32(%4), %%eax\n"
30013+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30014 " cmpl $67, %0\n"
30015 " jbe 2f\n"
30016- "1: movl 64(%4), %%eax\n"
30017+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30018 " .align 2,0x90\n"
30019- "2: movl 0(%4), %%eax\n"
30020- "21: movl 4(%4), %%edx\n"
30021+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30022+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30023 " movnti %%eax, 0(%3)\n"
30024 " movnti %%edx, 4(%3)\n"
30025- "3: movl 8(%4), %%eax\n"
30026- "31: movl 12(%4),%%edx\n"
30027+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30028+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30029 " movnti %%eax, 8(%3)\n"
30030 " movnti %%edx, 12(%3)\n"
30031- "4: movl 16(%4), %%eax\n"
30032- "41: movl 20(%4), %%edx\n"
30033+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30034+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30035 " movnti %%eax, 16(%3)\n"
30036 " movnti %%edx, 20(%3)\n"
30037- "10: movl 24(%4), %%eax\n"
30038- "51: movl 28(%4), %%edx\n"
30039+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30040+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30041 " movnti %%eax, 24(%3)\n"
30042 " movnti %%edx, 28(%3)\n"
30043- "11: movl 32(%4), %%eax\n"
30044- "61: movl 36(%4), %%edx\n"
30045+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30046+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30047 " movnti %%eax, 32(%3)\n"
30048 " movnti %%edx, 36(%3)\n"
30049- "12: movl 40(%4), %%eax\n"
30050- "71: movl 44(%4), %%edx\n"
30051+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30052+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30053 " movnti %%eax, 40(%3)\n"
30054 " movnti %%edx, 44(%3)\n"
30055- "13: movl 48(%4), %%eax\n"
30056- "81: movl 52(%4), %%edx\n"
30057+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30058+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30059 " movnti %%eax, 48(%3)\n"
30060 " movnti %%edx, 52(%3)\n"
30061- "14: movl 56(%4), %%eax\n"
30062- "91: movl 60(%4), %%edx\n"
30063+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30064+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30065 " movnti %%eax, 56(%3)\n"
30066 " movnti %%edx, 60(%3)\n"
30067 " addl $-64, %0\n"
30068@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30069 " shrl $2, %0\n"
30070 " andl $3, %%eax\n"
30071 " cld\n"
30072- "6: rep; movsl\n"
30073+ "6: rep; "__copyuser_seg" movsl\n"
30074 " movl %%eax,%0\n"
30075- "7: rep; movsb\n"
30076+ "7: rep; "__copyuser_seg" movsb\n"
30077 "8:\n"
30078 ".section .fixup,\"ax\"\n"
30079 "9: lea 0(%%eax,%0,4),%0\n"
30080@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30081
30082 __asm__ __volatile__(
30083 " .align 2,0x90\n"
30084- "0: movl 32(%4), %%eax\n"
30085+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30086 " cmpl $67, %0\n"
30087 " jbe 2f\n"
30088- "1: movl 64(%4), %%eax\n"
30089+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30090 " .align 2,0x90\n"
30091- "2: movl 0(%4), %%eax\n"
30092- "21: movl 4(%4), %%edx\n"
30093+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30094+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30095 " movnti %%eax, 0(%3)\n"
30096 " movnti %%edx, 4(%3)\n"
30097- "3: movl 8(%4), %%eax\n"
30098- "31: movl 12(%4),%%edx\n"
30099+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30100+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30101 " movnti %%eax, 8(%3)\n"
30102 " movnti %%edx, 12(%3)\n"
30103- "4: movl 16(%4), %%eax\n"
30104- "41: movl 20(%4), %%edx\n"
30105+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30106+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30107 " movnti %%eax, 16(%3)\n"
30108 " movnti %%edx, 20(%3)\n"
30109- "10: movl 24(%4), %%eax\n"
30110- "51: movl 28(%4), %%edx\n"
30111+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30112+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30113 " movnti %%eax, 24(%3)\n"
30114 " movnti %%edx, 28(%3)\n"
30115- "11: movl 32(%4), %%eax\n"
30116- "61: movl 36(%4), %%edx\n"
30117+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30118+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30119 " movnti %%eax, 32(%3)\n"
30120 " movnti %%edx, 36(%3)\n"
30121- "12: movl 40(%4), %%eax\n"
30122- "71: movl 44(%4), %%edx\n"
30123+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30124+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30125 " movnti %%eax, 40(%3)\n"
30126 " movnti %%edx, 44(%3)\n"
30127- "13: movl 48(%4), %%eax\n"
30128- "81: movl 52(%4), %%edx\n"
30129+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30130+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30131 " movnti %%eax, 48(%3)\n"
30132 " movnti %%edx, 52(%3)\n"
30133- "14: movl 56(%4), %%eax\n"
30134- "91: movl 60(%4), %%edx\n"
30135+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30136+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30137 " movnti %%eax, 56(%3)\n"
30138 " movnti %%edx, 60(%3)\n"
30139 " addl $-64, %0\n"
30140@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30141 " shrl $2, %0\n"
30142 " andl $3, %%eax\n"
30143 " cld\n"
30144- "6: rep; movsl\n"
30145+ "6: rep; "__copyuser_seg" movsl\n"
30146 " movl %%eax,%0\n"
30147- "7: rep; movsb\n"
30148+ "7: rep; "__copyuser_seg" movsb\n"
30149 "8:\n"
30150 ".section .fixup,\"ax\"\n"
30151 "9: lea 0(%%eax,%0,4),%0\n"
30152@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30153 */
30154 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30155 unsigned long size);
30156-unsigned long __copy_user_intel(void __user *to, const void *from,
30157+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30158+ unsigned long size);
30159+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30160 unsigned long size);
30161 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30162 const void __user *from, unsigned long size);
30163 #endif /* CONFIG_X86_INTEL_USERCOPY */
30164
30165 /* Generic arbitrary sized copy. */
30166-#define __copy_user(to, from, size) \
30167+#define __copy_user(to, from, size, prefix, set, restore) \
30168 do { \
30169 int __d0, __d1, __d2; \
30170 __asm__ __volatile__( \
30171+ set \
30172 " cmp $7,%0\n" \
30173 " jbe 1f\n" \
30174 " movl %1,%0\n" \
30175 " negl %0\n" \
30176 " andl $7,%0\n" \
30177 " subl %0,%3\n" \
30178- "4: rep; movsb\n" \
30179+ "4: rep; "prefix"movsb\n" \
30180 " movl %3,%0\n" \
30181 " shrl $2,%0\n" \
30182 " andl $3,%3\n" \
30183 " .align 2,0x90\n" \
30184- "0: rep; movsl\n" \
30185+ "0: rep; "prefix"movsl\n" \
30186 " movl %3,%0\n" \
30187- "1: rep; movsb\n" \
30188+ "1: rep; "prefix"movsb\n" \
30189 "2:\n" \
30190+ restore \
30191 ".section .fixup,\"ax\"\n" \
30192 "5: addl %3,%0\n" \
30193 " jmp 2b\n" \
30194@@ -538,14 +650,14 @@ do { \
30195 " negl %0\n" \
30196 " andl $7,%0\n" \
30197 " subl %0,%3\n" \
30198- "4: rep; movsb\n" \
30199+ "4: rep; "__copyuser_seg"movsb\n" \
30200 " movl %3,%0\n" \
30201 " shrl $2,%0\n" \
30202 " andl $3,%3\n" \
30203 " .align 2,0x90\n" \
30204- "0: rep; movsl\n" \
30205+ "0: rep; "__copyuser_seg"movsl\n" \
30206 " movl %3,%0\n" \
30207- "1: rep; movsb\n" \
30208+ "1: rep; "__copyuser_seg"movsb\n" \
30209 "2:\n" \
30210 ".section .fixup,\"ax\"\n" \
30211 "5: addl %3,%0\n" \
30212@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30213 {
30214 stac();
30215 if (movsl_is_ok(to, from, n))
30216- __copy_user(to, from, n);
30217+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30218 else
30219- n = __copy_user_intel(to, from, n);
30220+ n = __generic_copy_to_user_intel(to, from, n);
30221 clac();
30222 return n;
30223 }
30224@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30225 {
30226 stac();
30227 if (movsl_is_ok(to, from, n))
30228- __copy_user(to, from, n);
30229+ __copy_user(to, from, n, __copyuser_seg, "", "");
30230 else
30231- n = __copy_user_intel((void __user *)to,
30232- (const void *)from, n);
30233+ n = __generic_copy_from_user_intel(to, from, n);
30234 clac();
30235 return n;
30236 }
30237@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30238 if (n > 64 && cpu_has_xmm2)
30239 n = __copy_user_intel_nocache(to, from, n);
30240 else
30241- __copy_user(to, from, n);
30242+ __copy_user(to, from, n, __copyuser_seg, "", "");
30243 #else
30244- __copy_user(to, from, n);
30245+ __copy_user(to, from, n, __copyuser_seg, "", "");
30246 #endif
30247 clac();
30248 return n;
30249 }
30250 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30251
30252-/**
30253- * copy_to_user: - Copy a block of data into user space.
30254- * @to: Destination address, in user space.
30255- * @from: Source address, in kernel space.
30256- * @n: Number of bytes to copy.
30257- *
30258- * Context: User context only. This function may sleep.
30259- *
30260- * Copy data from kernel space to user space.
30261- *
30262- * Returns number of bytes that could not be copied.
30263- * On success, this will be zero.
30264- */
30265-unsigned long
30266-copy_to_user(void __user *to, const void *from, unsigned long n)
30267+#ifdef CONFIG_PAX_MEMORY_UDEREF
30268+void __set_fs(mm_segment_t x)
30269 {
30270- if (access_ok(VERIFY_WRITE, to, n))
30271- n = __copy_to_user(to, from, n);
30272- return n;
30273+ switch (x.seg) {
30274+ case 0:
30275+ loadsegment(gs, 0);
30276+ break;
30277+ case TASK_SIZE_MAX:
30278+ loadsegment(gs, __USER_DS);
30279+ break;
30280+ case -1UL:
30281+ loadsegment(gs, __KERNEL_DS);
30282+ break;
30283+ default:
30284+ BUG();
30285+ }
30286 }
30287-EXPORT_SYMBOL(copy_to_user);
30288+EXPORT_SYMBOL(__set_fs);
30289
30290-/**
30291- * copy_from_user: - Copy a block of data from user space.
30292- * @to: Destination address, in kernel space.
30293- * @from: Source address, in user space.
30294- * @n: Number of bytes to copy.
30295- *
30296- * Context: User context only. This function may sleep.
30297- *
30298- * Copy data from user space to kernel space.
30299- *
30300- * Returns number of bytes that could not be copied.
30301- * On success, this will be zero.
30302- *
30303- * If some data could not be copied, this function will pad the copied
30304- * data to the requested size using zero bytes.
30305- */
30306-unsigned long
30307-_copy_from_user(void *to, const void __user *from, unsigned long n)
30308+void set_fs(mm_segment_t x)
30309 {
30310- if (access_ok(VERIFY_READ, from, n))
30311- n = __copy_from_user(to, from, n);
30312- else
30313- memset(to, 0, n);
30314- return n;
30315+ current_thread_info()->addr_limit = x;
30316+ __set_fs(x);
30317 }
30318-EXPORT_SYMBOL(_copy_from_user);
30319+EXPORT_SYMBOL(set_fs);
30320+#endif
30321diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30322index c905e89..01ab928 100644
30323--- a/arch/x86/lib/usercopy_64.c
30324+++ b/arch/x86/lib/usercopy_64.c
30325@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30326 might_fault();
30327 /* no memory constraint because it doesn't change any memory gcc knows
30328 about */
30329+ pax_open_userland();
30330 stac();
30331 asm volatile(
30332 " testq %[size8],%[size8]\n"
30333@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30334 _ASM_EXTABLE(0b,3b)
30335 _ASM_EXTABLE(1b,2b)
30336 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30337- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30338+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30339 [zero] "r" (0UL), [eight] "r" (8UL));
30340 clac();
30341+ pax_close_userland();
30342 return size;
30343 }
30344 EXPORT_SYMBOL(__clear_user);
30345@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30346 }
30347 EXPORT_SYMBOL(clear_user);
30348
30349-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30350+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30351 {
30352- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30353- return copy_user_generic((__force void *)to, (__force void *)from, len);
30354- }
30355- return len;
30356+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30357+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30358+ return len;
30359 }
30360 EXPORT_SYMBOL(copy_in_user);
30361
30362@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30363 * it is not necessary to optimize tail handling.
30364 */
30365 __visible unsigned long
30366-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30367+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30368 {
30369 char c;
30370 unsigned zero_len;
30371
30372+ clac();
30373+ pax_close_userland();
30374 for (; len; --len, to++) {
30375 if (__get_user_nocheck(c, from++, sizeof(char)))
30376 break;
30377@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30378 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30379 if (__put_user_nocheck(c, to++, sizeof(char)))
30380 break;
30381- clac();
30382 return len;
30383 }
30384diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30385index 23d8e5f..9ccc13a 100644
30386--- a/arch/x86/mm/Makefile
30387+++ b/arch/x86/mm/Makefile
30388@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30389 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30390
30391 obj-$(CONFIG_MEMTEST) += memtest.o
30392+
30393+quote:="
30394+obj-$(CONFIG_X86_64) += uderef_64.o
30395+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30396diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30397index 903ec1e..c4166b2 100644
30398--- a/arch/x86/mm/extable.c
30399+++ b/arch/x86/mm/extable.c
30400@@ -6,12 +6,24 @@
30401 static inline unsigned long
30402 ex_insn_addr(const struct exception_table_entry *x)
30403 {
30404- return (unsigned long)&x->insn + x->insn;
30405+ unsigned long reloc = 0;
30406+
30407+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30408+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30409+#endif
30410+
30411+ return (unsigned long)&x->insn + x->insn + reloc;
30412 }
30413 static inline unsigned long
30414 ex_fixup_addr(const struct exception_table_entry *x)
30415 {
30416- return (unsigned long)&x->fixup + x->fixup;
30417+ unsigned long reloc = 0;
30418+
30419+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30420+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30421+#endif
30422+
30423+ return (unsigned long)&x->fixup + x->fixup + reloc;
30424 }
30425
30426 int fixup_exception(struct pt_regs *regs)
30427@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30428 unsigned long new_ip;
30429
30430 #ifdef CONFIG_PNPBIOS
30431- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30432+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30433 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30434 extern u32 pnp_bios_is_utter_crap;
30435 pnp_bios_is_utter_crap = 1;
30436@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30437 i += 4;
30438 p->fixup -= i;
30439 i += 4;
30440+
30441+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30442+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30443+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30444+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30445+#endif
30446+
30447 }
30448 }
30449
30450diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30451index 3aaeffc..42ea9fb 100644
30452--- a/arch/x86/mm/fault.c
30453+++ b/arch/x86/mm/fault.c
30454@@ -14,11 +14,18 @@
30455 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30456 #include <linux/prefetch.h> /* prefetchw */
30457 #include <linux/context_tracking.h> /* exception_enter(), ... */
30458+#include <linux/unistd.h>
30459+#include <linux/compiler.h>
30460
30461 #include <asm/traps.h> /* dotraplinkage, ... */
30462 #include <asm/pgalloc.h> /* pgd_*(), ... */
30463 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30464 #include <asm/fixmap.h> /* VSYSCALL_START */
30465+#include <asm/tlbflush.h>
30466+
30467+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30468+#include <asm/stacktrace.h>
30469+#endif
30470
30471 /*
30472 * Page fault error code bits:
30473@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
30474 int ret = 0;
30475
30476 /* kprobe_running() needs smp_processor_id() */
30477- if (kprobes_built_in() && !user_mode_vm(regs)) {
30478+ if (kprobes_built_in() && !user_mode(regs)) {
30479 preempt_disable();
30480 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30481 ret = 1;
30482@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30483 return !instr_lo || (instr_lo>>1) == 1;
30484 case 0x00:
30485 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30486- if (probe_kernel_address(instr, opcode))
30487+ if (user_mode(regs)) {
30488+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30489+ return 0;
30490+ } else if (probe_kernel_address(instr, opcode))
30491 return 0;
30492
30493 *prefetch = (instr_lo == 0xF) &&
30494@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30495 while (instr < max_instr) {
30496 unsigned char opcode;
30497
30498- if (probe_kernel_address(instr, opcode))
30499+ if (user_mode(regs)) {
30500+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30501+ break;
30502+ } else if (probe_kernel_address(instr, opcode))
30503 break;
30504
30505 instr++;
30506@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30507 force_sig_info(si_signo, &info, tsk);
30508 }
30509
30510+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30511+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30512+#endif
30513+
30514+#ifdef CONFIG_PAX_EMUTRAMP
30515+static int pax_handle_fetch_fault(struct pt_regs *regs);
30516+#endif
30517+
30518+#ifdef CONFIG_PAX_PAGEEXEC
30519+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30520+{
30521+ pgd_t *pgd;
30522+ pud_t *pud;
30523+ pmd_t *pmd;
30524+
30525+ pgd = pgd_offset(mm, address);
30526+ if (!pgd_present(*pgd))
30527+ return NULL;
30528+ pud = pud_offset(pgd, address);
30529+ if (!pud_present(*pud))
30530+ return NULL;
30531+ pmd = pmd_offset(pud, address);
30532+ if (!pmd_present(*pmd))
30533+ return NULL;
30534+ return pmd;
30535+}
30536+#endif
30537+
30538 DEFINE_SPINLOCK(pgd_lock);
30539 LIST_HEAD(pgd_list);
30540
30541@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
30542 for (address = VMALLOC_START & PMD_MASK;
30543 address >= TASK_SIZE && address < FIXADDR_TOP;
30544 address += PMD_SIZE) {
30545+
30546+#ifdef CONFIG_PAX_PER_CPU_PGD
30547+ unsigned long cpu;
30548+#else
30549 struct page *page;
30550+#endif
30551
30552 spin_lock(&pgd_lock);
30553+
30554+#ifdef CONFIG_PAX_PER_CPU_PGD
30555+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30556+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30557+ pmd_t *ret;
30558+
30559+ ret = vmalloc_sync_one(pgd, address);
30560+ if (!ret)
30561+ break;
30562+ pgd = get_cpu_pgd(cpu, kernel);
30563+#else
30564 list_for_each_entry(page, &pgd_list, lru) {
30565+ pgd_t *pgd;
30566 spinlock_t *pgt_lock;
30567 pmd_t *ret;
30568
30569@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
30570 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30571
30572 spin_lock(pgt_lock);
30573- ret = vmalloc_sync_one(page_address(page), address);
30574+ pgd = page_address(page);
30575+#endif
30576+
30577+ ret = vmalloc_sync_one(pgd, address);
30578+
30579+#ifndef CONFIG_PAX_PER_CPU_PGD
30580 spin_unlock(pgt_lock);
30581+#endif
30582
30583 if (!ret)
30584 break;
30585@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30586 * an interrupt in the middle of a task switch..
30587 */
30588 pgd_paddr = read_cr3();
30589+
30590+#ifdef CONFIG_PAX_PER_CPU_PGD
30591+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30592+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30593+#endif
30594+
30595 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30596 if (!pmd_k)
30597 return -1;
30598@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30599 * happen within a race in page table update. In the later
30600 * case just flush:
30601 */
30602- pgd = pgd_offset(current->active_mm, address);
30603+
30604 pgd_ref = pgd_offset_k(address);
30605 if (pgd_none(*pgd_ref))
30606 return -1;
30607
30608+#ifdef CONFIG_PAX_PER_CPU_PGD
30609+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30610+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30611+ if (pgd_none(*pgd)) {
30612+ set_pgd(pgd, *pgd_ref);
30613+ arch_flush_lazy_mmu_mode();
30614+ } else {
30615+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30616+ }
30617+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30618+#else
30619+ pgd = pgd_offset(current->active_mm, address);
30620+#endif
30621+
30622 if (pgd_none(*pgd)) {
30623 set_pgd(pgd, *pgd_ref);
30624 arch_flush_lazy_mmu_mode();
30625@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30626 static int is_errata100(struct pt_regs *regs, unsigned long address)
30627 {
30628 #ifdef CONFIG_X86_64
30629- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30630+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30631 return 1;
30632 #endif
30633 return 0;
30634@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30635 }
30636
30637 static const char nx_warning[] = KERN_CRIT
30638-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30639+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30640
30641 static void
30642 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30643@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30644 if (!oops_may_print())
30645 return;
30646
30647- if (error_code & PF_INSTR) {
30648+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30649 unsigned int level;
30650
30651 pte_t *pte = lookup_address(address, &level);
30652
30653 if (pte && pte_present(*pte) && !pte_exec(*pte))
30654- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30655+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30656 }
30657
30658+#ifdef CONFIG_PAX_KERNEXEC
30659+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30660+ if (current->signal->curr_ip)
30661+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30662+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30663+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30664+ else
30665+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30666+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30667+ }
30668+#endif
30669+
30670 printk(KERN_ALERT "BUG: unable to handle kernel ");
30671 if (address < PAGE_SIZE)
30672 printk(KERN_CONT "NULL pointer dereference");
30673@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30674 return;
30675 }
30676 #endif
30677+
30678+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30679+ if (pax_is_fetch_fault(regs, error_code, address)) {
30680+
30681+#ifdef CONFIG_PAX_EMUTRAMP
30682+ switch (pax_handle_fetch_fault(regs)) {
30683+ case 2:
30684+ return;
30685+ }
30686+#endif
30687+
30688+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30689+ do_group_exit(SIGKILL);
30690+ }
30691+#endif
30692+
30693 /* Kernel addresses are always protection faults: */
30694 if (address >= TASK_SIZE)
30695 error_code |= PF_PROT;
30696@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30697 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30698 printk(KERN_ERR
30699 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30700- tsk->comm, tsk->pid, address);
30701+ tsk->comm, task_pid_nr(tsk), address);
30702 code = BUS_MCEERR_AR;
30703 }
30704 #endif
30705@@ -889,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30706 return 1;
30707 }
30708
30709+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30710+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30711+{
30712+ pte_t *pte;
30713+ pmd_t *pmd;
30714+ spinlock_t *ptl;
30715+ unsigned char pte_mask;
30716+
30717+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30718+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30719+ return 0;
30720+
30721+ /* PaX: it's our fault, let's handle it if we can */
30722+
30723+ /* PaX: take a look at read faults before acquiring any locks */
30724+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30725+ /* instruction fetch attempt from a protected page in user mode */
30726+ up_read(&mm->mmap_sem);
30727+
30728+#ifdef CONFIG_PAX_EMUTRAMP
30729+ switch (pax_handle_fetch_fault(regs)) {
30730+ case 2:
30731+ return 1;
30732+ }
30733+#endif
30734+
30735+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30736+ do_group_exit(SIGKILL);
30737+ }
30738+
30739+ pmd = pax_get_pmd(mm, address);
30740+ if (unlikely(!pmd))
30741+ return 0;
30742+
30743+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30744+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30745+ pte_unmap_unlock(pte, ptl);
30746+ return 0;
30747+ }
30748+
30749+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30750+ /* write attempt to a protected page in user mode */
30751+ pte_unmap_unlock(pte, ptl);
30752+ return 0;
30753+ }
30754+
30755+#ifdef CONFIG_SMP
30756+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30757+#else
30758+ if (likely(address > get_limit(regs->cs)))
30759+#endif
30760+ {
30761+ set_pte(pte, pte_mkread(*pte));
30762+ __flush_tlb_one(address);
30763+ pte_unmap_unlock(pte, ptl);
30764+ up_read(&mm->mmap_sem);
30765+ return 1;
30766+ }
30767+
30768+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30769+
30770+ /*
30771+ * PaX: fill DTLB with user rights and retry
30772+ */
30773+ __asm__ __volatile__ (
30774+ "orb %2,(%1)\n"
30775+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30776+/*
30777+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30778+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30779+ * page fault when examined during a TLB load attempt. this is true not only
30780+ * for PTEs holding a non-present entry but also present entries that will
30781+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30782+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30783+ * for our target pages since their PTEs are simply not in the TLBs at all.
30784+
30785+ * the best thing in omitting it is that we gain around 15-20% speed in the
30786+ * fast path of the page fault handler and can get rid of tracing since we
30787+ * can no longer flush unintended entries.
30788+ */
30789+ "invlpg (%0)\n"
30790+#endif
30791+ __copyuser_seg"testb $0,(%0)\n"
30792+ "xorb %3,(%1)\n"
30793+ :
30794+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30795+ : "memory", "cc");
30796+ pte_unmap_unlock(pte, ptl);
30797+ up_read(&mm->mmap_sem);
30798+ return 1;
30799+}
30800+#endif
30801+
30802 /*
30803 * Handle a spurious fault caused by a stale TLB entry.
30804 *
30805@@ -955,6 +1160,9 @@ int show_unhandled_signals = 1;
30806 static inline int
30807 access_error(unsigned long error_code, struct vm_area_struct *vma)
30808 {
30809+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30810+ return 1;
30811+
30812 if (error_code & PF_WRITE) {
30813 /* write, present and write, not present: */
30814 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30815@@ -983,7 +1191,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30816 if (error_code & PF_USER)
30817 return false;
30818
30819- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30820+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30821 return false;
30822
30823 return true;
30824@@ -1010,6 +1218,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30825 /* Get the faulting address: */
30826 address = read_cr2();
30827
30828+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30829+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30830+ if (!search_exception_tables(regs->ip)) {
30831+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30832+ bad_area_nosemaphore(regs, error_code, address);
30833+ return;
30834+ }
30835+ if (address < pax_user_shadow_base) {
30836+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30837+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30838+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30839+ } else
30840+ address -= pax_user_shadow_base;
30841+ }
30842+#endif
30843+
30844 /*
30845 * Detect and handle instructions that would cause a page fault for
30846 * both a tracked kernel page and a userspace page.
30847@@ -1069,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30848 * User-mode registers count as a user access even for any
30849 * potential system fault or CPU buglet:
30850 */
30851- if (user_mode_vm(regs)) {
30852+ if (user_mode(regs)) {
30853 local_irq_enable();
30854 error_code |= PF_USER;
30855 flags |= FAULT_FLAG_USER;
30856@@ -1135,6 +1359,11 @@ retry:
30857 might_sleep();
30858 }
30859
30860+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30861+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30862+ return;
30863+#endif
30864+
30865 vma = find_vma(mm, address);
30866 if (unlikely(!vma)) {
30867 bad_area(regs, error_code, address);
30868@@ -1146,18 +1375,24 @@ retry:
30869 bad_area(regs, error_code, address);
30870 return;
30871 }
30872- if (error_code & PF_USER) {
30873- /*
30874- * Accessing the stack below %sp is always a bug.
30875- * The large cushion allows instructions like enter
30876- * and pusha to work. ("enter $65535, $31" pushes
30877- * 32 pointers and then decrements %sp by 65535.)
30878- */
30879- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30880- bad_area(regs, error_code, address);
30881- return;
30882- }
30883+ /*
30884+ * Accessing the stack below %sp is always a bug.
30885+ * The large cushion allows instructions like enter
30886+ * and pusha to work. ("enter $65535, $31" pushes
30887+ * 32 pointers and then decrements %sp by 65535.)
30888+ */
30889+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30890+ bad_area(regs, error_code, address);
30891+ return;
30892 }
30893+
30894+#ifdef CONFIG_PAX_SEGMEXEC
30895+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30896+ bad_area(regs, error_code, address);
30897+ return;
30898+ }
30899+#endif
30900+
30901 if (unlikely(expand_stack(vma, address))) {
30902 bad_area(regs, error_code, address);
30903 return;
30904@@ -1231,3 +1466,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30905 __do_page_fault(regs, error_code);
30906 exception_exit(prev_state);
30907 }
30908+
30909+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30910+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30911+{
30912+ struct mm_struct *mm = current->mm;
30913+ unsigned long ip = regs->ip;
30914+
30915+ if (v8086_mode(regs))
30916+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30917+
30918+#ifdef CONFIG_PAX_PAGEEXEC
30919+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30920+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30921+ return true;
30922+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30923+ return true;
30924+ return false;
30925+ }
30926+#endif
30927+
30928+#ifdef CONFIG_PAX_SEGMEXEC
30929+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30930+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30931+ return true;
30932+ return false;
30933+ }
30934+#endif
30935+
30936+ return false;
30937+}
30938+#endif
30939+
30940+#ifdef CONFIG_PAX_EMUTRAMP
30941+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30942+{
30943+ int err;
30944+
30945+ do { /* PaX: libffi trampoline emulation */
30946+ unsigned char mov, jmp;
30947+ unsigned int addr1, addr2;
30948+
30949+#ifdef CONFIG_X86_64
30950+ if ((regs->ip + 9) >> 32)
30951+ break;
30952+#endif
30953+
30954+ err = get_user(mov, (unsigned char __user *)regs->ip);
30955+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30956+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30957+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30958+
30959+ if (err)
30960+ break;
30961+
30962+ if (mov == 0xB8 && jmp == 0xE9) {
30963+ regs->ax = addr1;
30964+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30965+ return 2;
30966+ }
30967+ } while (0);
30968+
30969+ do { /* PaX: gcc trampoline emulation #1 */
30970+ unsigned char mov1, mov2;
30971+ unsigned short jmp;
30972+ unsigned int addr1, addr2;
30973+
30974+#ifdef CONFIG_X86_64
30975+ if ((regs->ip + 11) >> 32)
30976+ break;
30977+#endif
30978+
30979+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30980+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30981+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30982+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30983+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30984+
30985+ if (err)
30986+ break;
30987+
30988+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30989+ regs->cx = addr1;
30990+ regs->ax = addr2;
30991+ regs->ip = addr2;
30992+ return 2;
30993+ }
30994+ } while (0);
30995+
30996+ do { /* PaX: gcc trampoline emulation #2 */
30997+ unsigned char mov, jmp;
30998+ unsigned int addr1, addr2;
30999+
31000+#ifdef CONFIG_X86_64
31001+ if ((regs->ip + 9) >> 32)
31002+ break;
31003+#endif
31004+
31005+ err = get_user(mov, (unsigned char __user *)regs->ip);
31006+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31007+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31008+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31009+
31010+ if (err)
31011+ break;
31012+
31013+ if (mov == 0xB9 && jmp == 0xE9) {
31014+ regs->cx = addr1;
31015+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31016+ return 2;
31017+ }
31018+ } while (0);
31019+
31020+ return 1; /* PaX in action */
31021+}
31022+
31023+#ifdef CONFIG_X86_64
31024+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31025+{
31026+ int err;
31027+
31028+ do { /* PaX: libffi trampoline emulation */
31029+ unsigned short mov1, mov2, jmp1;
31030+ unsigned char stcclc, jmp2;
31031+ unsigned long addr1, addr2;
31032+
31033+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31034+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31035+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31036+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31037+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31038+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31039+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31040+
31041+ if (err)
31042+ break;
31043+
31044+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31045+ regs->r11 = addr1;
31046+ regs->r10 = addr2;
31047+ if (stcclc == 0xF8)
31048+ regs->flags &= ~X86_EFLAGS_CF;
31049+ else
31050+ regs->flags |= X86_EFLAGS_CF;
31051+ regs->ip = addr1;
31052+ return 2;
31053+ }
31054+ } while (0);
31055+
31056+ do { /* PaX: gcc trampoline emulation #1 */
31057+ unsigned short mov1, mov2, jmp1;
31058+ unsigned char jmp2;
31059+ unsigned int addr1;
31060+ unsigned long addr2;
31061+
31062+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31063+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31064+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31065+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31066+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31067+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31068+
31069+ if (err)
31070+ break;
31071+
31072+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31073+ regs->r11 = addr1;
31074+ regs->r10 = addr2;
31075+ regs->ip = addr1;
31076+ return 2;
31077+ }
31078+ } while (0);
31079+
31080+ do { /* PaX: gcc trampoline emulation #2 */
31081+ unsigned short mov1, mov2, jmp1;
31082+ unsigned char jmp2;
31083+ unsigned long addr1, addr2;
31084+
31085+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31086+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31087+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31088+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31089+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31090+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31091+
31092+ if (err)
31093+ break;
31094+
31095+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31096+ regs->r11 = addr1;
31097+ regs->r10 = addr2;
31098+ regs->ip = addr1;
31099+ return 2;
31100+ }
31101+ } while (0);
31102+
31103+ return 1; /* PaX in action */
31104+}
31105+#endif
31106+
31107+/*
31108+ * PaX: decide what to do with offenders (regs->ip = fault address)
31109+ *
31110+ * returns 1 when task should be killed
31111+ * 2 when gcc trampoline was detected
31112+ */
31113+static int pax_handle_fetch_fault(struct pt_regs *regs)
31114+{
31115+ if (v8086_mode(regs))
31116+ return 1;
31117+
31118+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31119+ return 1;
31120+
31121+#ifdef CONFIG_X86_32
31122+ return pax_handle_fetch_fault_32(regs);
31123+#else
31124+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31125+ return pax_handle_fetch_fault_32(regs);
31126+ else
31127+ return pax_handle_fetch_fault_64(regs);
31128+#endif
31129+}
31130+#endif
31131+
31132+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31133+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31134+{
31135+ long i;
31136+
31137+ printk(KERN_ERR "PAX: bytes at PC: ");
31138+ for (i = 0; i < 20; i++) {
31139+ unsigned char c;
31140+ if (get_user(c, (unsigned char __force_user *)pc+i))
31141+ printk(KERN_CONT "?? ");
31142+ else
31143+ printk(KERN_CONT "%02x ", c);
31144+ }
31145+ printk("\n");
31146+
31147+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31148+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31149+ unsigned long c;
31150+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31151+#ifdef CONFIG_X86_32
31152+ printk(KERN_CONT "???????? ");
31153+#else
31154+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31155+ printk(KERN_CONT "???????? ???????? ");
31156+ else
31157+ printk(KERN_CONT "???????????????? ");
31158+#endif
31159+ } else {
31160+#ifdef CONFIG_X86_64
31161+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31162+ printk(KERN_CONT "%08x ", (unsigned int)c);
31163+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31164+ } else
31165+#endif
31166+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31167+ }
31168+ }
31169+ printk("\n");
31170+}
31171+#endif
31172+
31173+/**
31174+ * probe_kernel_write(): safely attempt to write to a location
31175+ * @dst: address to write to
31176+ * @src: pointer to the data that shall be written
31177+ * @size: size of the data chunk
31178+ *
31179+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31180+ * happens, handle that and return -EFAULT.
31181+ */
31182+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31183+{
31184+ long ret;
31185+ mm_segment_t old_fs = get_fs();
31186+
31187+ set_fs(KERNEL_DS);
31188+ pagefault_disable();
31189+ pax_open_kernel();
31190+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31191+ pax_close_kernel();
31192+ pagefault_enable();
31193+ set_fs(old_fs);
31194+
31195+ return ret ? -EFAULT : 0;
31196+}
31197diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31198index dd74e46..0970b01 100644
31199--- a/arch/x86/mm/gup.c
31200+++ b/arch/x86/mm/gup.c
31201@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31202 addr = start;
31203 len = (unsigned long) nr_pages << PAGE_SHIFT;
31204 end = start + len;
31205- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31206+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31207 (void __user *)start, len)))
31208 return 0;
31209
31210@@ -331,6 +331,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31211 goto slow_irqon;
31212 #endif
31213
31214+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31215+ (void __user *)start, len)))
31216+ return 0;
31217+
31218 /*
31219 * XXX: batch / limit 'nr', to avoid large irq off latency
31220 * needs some instrumenting to determine the common sizes used by
31221diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31222index 4500142..53a363c 100644
31223--- a/arch/x86/mm/highmem_32.c
31224+++ b/arch/x86/mm/highmem_32.c
31225@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31226 idx = type + KM_TYPE_NR*smp_processor_id();
31227 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31228 BUG_ON(!pte_none(*(kmap_pte-idx)));
31229+
31230+ pax_open_kernel();
31231 set_pte(kmap_pte-idx, mk_pte(page, prot));
31232+ pax_close_kernel();
31233+
31234 arch_flush_lazy_mmu_mode();
31235
31236 return (void *)vaddr;
31237diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31238index 9d980d8..6bbfacb 100644
31239--- a/arch/x86/mm/hugetlbpage.c
31240+++ b/arch/x86/mm/hugetlbpage.c
31241@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31242 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31243 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31244 unsigned long addr, unsigned long len,
31245- unsigned long pgoff, unsigned long flags)
31246+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31247 {
31248 struct hstate *h = hstate_file(file);
31249 struct vm_unmapped_area_info info;
31250-
31251+
31252 info.flags = 0;
31253 info.length = len;
31254 info.low_limit = TASK_UNMAPPED_BASE;
31255+
31256+#ifdef CONFIG_PAX_RANDMMAP
31257+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31258+ info.low_limit += current->mm->delta_mmap;
31259+#endif
31260+
31261 info.high_limit = TASK_SIZE;
31262 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31263 info.align_offset = 0;
31264+ info.threadstack_offset = offset;
31265 return vm_unmapped_area(&info);
31266 }
31267
31268 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31269 unsigned long addr0, unsigned long len,
31270- unsigned long pgoff, unsigned long flags)
31271+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31272 {
31273 struct hstate *h = hstate_file(file);
31274 struct vm_unmapped_area_info info;
31275@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31276 info.high_limit = current->mm->mmap_base;
31277 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31278 info.align_offset = 0;
31279+ info.threadstack_offset = offset;
31280 addr = vm_unmapped_area(&info);
31281
31282 /*
31283@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31284 VM_BUG_ON(addr != -ENOMEM);
31285 info.flags = 0;
31286 info.low_limit = TASK_UNMAPPED_BASE;
31287+
31288+#ifdef CONFIG_PAX_RANDMMAP
31289+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31290+ info.low_limit += current->mm->delta_mmap;
31291+#endif
31292+
31293 info.high_limit = TASK_SIZE;
31294 addr = vm_unmapped_area(&info);
31295 }
31296@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31297 struct hstate *h = hstate_file(file);
31298 struct mm_struct *mm = current->mm;
31299 struct vm_area_struct *vma;
31300+ unsigned long pax_task_size = TASK_SIZE;
31301+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31302
31303 if (len & ~huge_page_mask(h))
31304 return -EINVAL;
31305- if (len > TASK_SIZE)
31306+
31307+#ifdef CONFIG_PAX_SEGMEXEC
31308+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31309+ pax_task_size = SEGMEXEC_TASK_SIZE;
31310+#endif
31311+
31312+ pax_task_size -= PAGE_SIZE;
31313+
31314+ if (len > pax_task_size)
31315 return -ENOMEM;
31316
31317 if (flags & MAP_FIXED) {
31318@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31319 return addr;
31320 }
31321
31322+#ifdef CONFIG_PAX_RANDMMAP
31323+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31324+#endif
31325+
31326 if (addr) {
31327 addr = ALIGN(addr, huge_page_size(h));
31328 vma = find_vma(mm, addr);
31329- if (TASK_SIZE - len >= addr &&
31330- (!vma || addr + len <= vma->vm_start))
31331+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31332 return addr;
31333 }
31334 if (mm->get_unmapped_area == arch_get_unmapped_area)
31335 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31336- pgoff, flags);
31337+ pgoff, flags, offset);
31338 else
31339 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31340- pgoff, flags);
31341+ pgoff, flags, offset);
31342 }
31343
31344 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31345diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31346index 04664cd..dae6e5d 100644
31347--- a/arch/x86/mm/init.c
31348+++ b/arch/x86/mm/init.c
31349@@ -4,6 +4,7 @@
31350 #include <linux/swap.h>
31351 #include <linux/memblock.h>
31352 #include <linux/bootmem.h> /* for max_low_pfn */
31353+#include <linux/tboot.h>
31354
31355 #include <asm/cacheflush.h>
31356 #include <asm/e820.h>
31357@@ -17,6 +18,8 @@
31358 #include <asm/proto.h>
31359 #include <asm/dma.h> /* for MAX_DMA_PFN */
31360 #include <asm/microcode.h>
31361+#include <asm/desc.h>
31362+#include <asm/bios_ebda.h>
31363
31364 #include "mm_internal.h"
31365
31366@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
31367 early_ioremap_page_table_range_init();
31368 #endif
31369
31370+#ifdef CONFIG_PAX_PER_CPU_PGD
31371+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31372+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31373+ KERNEL_PGD_PTRS);
31374+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31375+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31376+ KERNEL_PGD_PTRS);
31377+ load_cr3(get_cpu_pgd(0, kernel));
31378+#else
31379 load_cr3(swapper_pg_dir);
31380+#endif
31381+
31382 __flush_tlb_all();
31383
31384 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31385@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
31386 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31387 * mmio resources as well as potential bios/acpi data regions.
31388 */
31389+
31390+#ifdef CONFIG_GRKERNSEC_KMEM
31391+static unsigned int ebda_start __read_only;
31392+static unsigned int ebda_end __read_only;
31393+#endif
31394+
31395 int devmem_is_allowed(unsigned long pagenr)
31396 {
31397- if (pagenr < 256)
31398+#ifdef CONFIG_GRKERNSEC_KMEM
31399+ /* allow BDA */
31400+ if (!pagenr)
31401 return 1;
31402+ /* allow EBDA */
31403+ if (pagenr >= ebda_start && pagenr < ebda_end)
31404+ return 1;
31405+ /* if tboot is in use, allow access to its hardcoded serial log range */
31406+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31407+ return 1;
31408+#else
31409+ if (!pagenr)
31410+ return 1;
31411+#ifdef CONFIG_VM86
31412+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31413+ return 1;
31414+#endif
31415+#endif
31416+
31417+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31418+ return 1;
31419+#ifdef CONFIG_GRKERNSEC_KMEM
31420+ /* throw out everything else below 1MB */
31421+ if (pagenr <= 256)
31422+ return 0;
31423+#endif
31424 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31425 return 0;
31426 if (!page_is_ram(pagenr))
31427@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31428 #endif
31429 }
31430
31431+#ifdef CONFIG_GRKERNSEC_KMEM
31432+static inline void gr_init_ebda(void)
31433+{
31434+ unsigned int ebda_addr;
31435+ unsigned int ebda_size = 0;
31436+
31437+ ebda_addr = get_bios_ebda();
31438+ if (ebda_addr) {
31439+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31440+ ebda_size <<= 10;
31441+ }
31442+ if (ebda_addr && ebda_size) {
31443+ ebda_start = ebda_addr >> PAGE_SHIFT;
31444+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31445+ } else {
31446+ ebda_start = 0x9f000 >> PAGE_SHIFT;
31447+ ebda_end = 0xa0000 >> PAGE_SHIFT;
31448+ }
31449+}
31450+#else
31451+static inline void gr_init_ebda(void) { }
31452+#endif
31453+
31454 void free_initmem(void)
31455 {
31456+#ifdef CONFIG_PAX_KERNEXEC
31457+#ifdef CONFIG_X86_32
31458+ /* PaX: limit KERNEL_CS to actual size */
31459+ unsigned long addr, limit;
31460+ struct desc_struct d;
31461+ int cpu;
31462+#else
31463+ pgd_t *pgd;
31464+ pud_t *pud;
31465+ pmd_t *pmd;
31466+ unsigned long addr, end;
31467+#endif
31468+#endif
31469+
31470+ gr_init_ebda();
31471+
31472+#ifdef CONFIG_PAX_KERNEXEC
31473+#ifdef CONFIG_X86_32
31474+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31475+ limit = (limit - 1UL) >> PAGE_SHIFT;
31476+
31477+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31478+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31479+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31480+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31481+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31482+ }
31483+
31484+ /* PaX: make KERNEL_CS read-only */
31485+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31486+ if (!paravirt_enabled())
31487+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31488+/*
31489+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31490+ pgd = pgd_offset_k(addr);
31491+ pud = pud_offset(pgd, addr);
31492+ pmd = pmd_offset(pud, addr);
31493+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31494+ }
31495+*/
31496+#ifdef CONFIG_X86_PAE
31497+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31498+/*
31499+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31500+ pgd = pgd_offset_k(addr);
31501+ pud = pud_offset(pgd, addr);
31502+ pmd = pmd_offset(pud, addr);
31503+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31504+ }
31505+*/
31506+#endif
31507+
31508+#ifdef CONFIG_MODULES
31509+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31510+#endif
31511+
31512+#else
31513+ /* PaX: make kernel code/rodata read-only, rest non-executable */
31514+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31515+ pgd = pgd_offset_k(addr);
31516+ pud = pud_offset(pgd, addr);
31517+ pmd = pmd_offset(pud, addr);
31518+ if (!pmd_present(*pmd))
31519+ continue;
31520+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31521+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31522+ else
31523+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31524+ }
31525+
31526+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31527+ end = addr + KERNEL_IMAGE_SIZE;
31528+ for (; addr < end; addr += PMD_SIZE) {
31529+ pgd = pgd_offset_k(addr);
31530+ pud = pud_offset(pgd, addr);
31531+ pmd = pmd_offset(pud, addr);
31532+ if (!pmd_present(*pmd))
31533+ continue;
31534+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31535+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31536+ }
31537+#endif
31538+
31539+ flush_tlb_all();
31540+#endif
31541+
31542 free_init_pages("unused kernel",
31543 (unsigned long)(&__init_begin),
31544 (unsigned long)(&__init_end));
31545diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31546index 4287f1f..3b99c71 100644
31547--- a/arch/x86/mm/init_32.c
31548+++ b/arch/x86/mm/init_32.c
31549@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31550 bool __read_mostly __vmalloc_start_set = false;
31551
31552 /*
31553- * Creates a middle page table and puts a pointer to it in the
31554- * given global directory entry. This only returns the gd entry
31555- * in non-PAE compilation mode, since the middle layer is folded.
31556- */
31557-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31558-{
31559- pud_t *pud;
31560- pmd_t *pmd_table;
31561-
31562-#ifdef CONFIG_X86_PAE
31563- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31564- pmd_table = (pmd_t *)alloc_low_page();
31565- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31566- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31567- pud = pud_offset(pgd, 0);
31568- BUG_ON(pmd_table != pmd_offset(pud, 0));
31569-
31570- return pmd_table;
31571- }
31572-#endif
31573- pud = pud_offset(pgd, 0);
31574- pmd_table = pmd_offset(pud, 0);
31575-
31576- return pmd_table;
31577-}
31578-
31579-/*
31580 * Create a page table and place a pointer to it in a middle page
31581 * directory entry:
31582 */
31583@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31584 pte_t *page_table = (pte_t *)alloc_low_page();
31585
31586 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31587+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31588+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31589+#else
31590 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31591+#endif
31592 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31593 }
31594
31595 return pte_offset_kernel(pmd, 0);
31596 }
31597
31598+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31599+{
31600+ pud_t *pud;
31601+ pmd_t *pmd_table;
31602+
31603+ pud = pud_offset(pgd, 0);
31604+ pmd_table = pmd_offset(pud, 0);
31605+
31606+ return pmd_table;
31607+}
31608+
31609 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31610 {
31611 int pgd_idx = pgd_index(vaddr);
31612@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31613 int pgd_idx, pmd_idx;
31614 unsigned long vaddr;
31615 pgd_t *pgd;
31616+ pud_t *pud;
31617 pmd_t *pmd;
31618 pte_t *pte = NULL;
31619 unsigned long count = page_table_range_init_count(start, end);
31620@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31621 pgd = pgd_base + pgd_idx;
31622
31623 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31624- pmd = one_md_table_init(pgd);
31625- pmd = pmd + pmd_index(vaddr);
31626+ pud = pud_offset(pgd, vaddr);
31627+ pmd = pmd_offset(pud, vaddr);
31628+
31629+#ifdef CONFIG_X86_PAE
31630+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31631+#endif
31632+
31633 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31634 pmd++, pmd_idx++) {
31635 pte = page_table_kmap_check(one_page_table_init(pmd),
31636@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31637 }
31638 }
31639
31640-static inline int is_kernel_text(unsigned long addr)
31641+static inline int is_kernel_text(unsigned long start, unsigned long end)
31642 {
31643- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31644- return 1;
31645- return 0;
31646+ if ((start > ktla_ktva((unsigned long)_etext) ||
31647+ end <= ktla_ktva((unsigned long)_stext)) &&
31648+ (start > ktla_ktva((unsigned long)_einittext) ||
31649+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31650+
31651+#ifdef CONFIG_ACPI_SLEEP
31652+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31653+#endif
31654+
31655+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31656+ return 0;
31657+ return 1;
31658 }
31659
31660 /*
31661@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31662 unsigned long last_map_addr = end;
31663 unsigned long start_pfn, end_pfn;
31664 pgd_t *pgd_base = swapper_pg_dir;
31665- int pgd_idx, pmd_idx, pte_ofs;
31666+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31667 unsigned long pfn;
31668 pgd_t *pgd;
31669+ pud_t *pud;
31670 pmd_t *pmd;
31671 pte_t *pte;
31672 unsigned pages_2m, pages_4k;
31673@@ -291,8 +295,13 @@ repeat:
31674 pfn = start_pfn;
31675 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31676 pgd = pgd_base + pgd_idx;
31677- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31678- pmd = one_md_table_init(pgd);
31679+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31680+ pud = pud_offset(pgd, 0);
31681+ pmd = pmd_offset(pud, 0);
31682+
31683+#ifdef CONFIG_X86_PAE
31684+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31685+#endif
31686
31687 if (pfn >= end_pfn)
31688 continue;
31689@@ -304,14 +313,13 @@ repeat:
31690 #endif
31691 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31692 pmd++, pmd_idx++) {
31693- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31694+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31695
31696 /*
31697 * Map with big pages if possible, otherwise
31698 * create normal page tables:
31699 */
31700 if (use_pse) {
31701- unsigned int addr2;
31702 pgprot_t prot = PAGE_KERNEL_LARGE;
31703 /*
31704 * first pass will use the same initial
31705@@ -322,11 +330,7 @@ repeat:
31706 _PAGE_PSE);
31707
31708 pfn &= PMD_MASK >> PAGE_SHIFT;
31709- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31710- PAGE_OFFSET + PAGE_SIZE-1;
31711-
31712- if (is_kernel_text(addr) ||
31713- is_kernel_text(addr2))
31714+ if (is_kernel_text(address, address + PMD_SIZE))
31715 prot = PAGE_KERNEL_LARGE_EXEC;
31716
31717 pages_2m++;
31718@@ -343,7 +347,7 @@ repeat:
31719 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31720 pte += pte_ofs;
31721 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31722- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31723+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31724 pgprot_t prot = PAGE_KERNEL;
31725 /*
31726 * first pass will use the same initial
31727@@ -351,7 +355,7 @@ repeat:
31728 */
31729 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31730
31731- if (is_kernel_text(addr))
31732+ if (is_kernel_text(address, address + PAGE_SIZE))
31733 prot = PAGE_KERNEL_EXEC;
31734
31735 pages_4k++;
31736@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31737
31738 pud = pud_offset(pgd, va);
31739 pmd = pmd_offset(pud, va);
31740- if (!pmd_present(*pmd))
31741+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31742 break;
31743
31744 /* should not be large page here */
31745@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31746
31747 static void __init pagetable_init(void)
31748 {
31749- pgd_t *pgd_base = swapper_pg_dir;
31750-
31751- permanent_kmaps_init(pgd_base);
31752+ permanent_kmaps_init(swapper_pg_dir);
31753 }
31754
31755-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31756+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31757 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31758
31759 /* user-defined highmem size */
31760@@ -787,10 +789,10 @@ void __init mem_init(void)
31761 ((unsigned long)&__init_end -
31762 (unsigned long)&__init_begin) >> 10,
31763
31764- (unsigned long)&_etext, (unsigned long)&_edata,
31765- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31766+ (unsigned long)&_sdata, (unsigned long)&_edata,
31767+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31768
31769- (unsigned long)&_text, (unsigned long)&_etext,
31770+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31771 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31772
31773 /*
31774@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31775 if (!kernel_set_to_readonly)
31776 return;
31777
31778+ start = ktla_ktva(start);
31779 pr_debug("Set kernel text: %lx - %lx for read write\n",
31780 start, start+size);
31781
31782@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31783 if (!kernel_set_to_readonly)
31784 return;
31785
31786+ start = ktla_ktva(start);
31787 pr_debug("Set kernel text: %lx - %lx for read only\n",
31788 start, start+size);
31789
31790@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31791 unsigned long start = PFN_ALIGN(_text);
31792 unsigned long size = PFN_ALIGN(_etext) - start;
31793
31794+ start = ktla_ktva(start);
31795 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31796 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31797 size >> 10);
31798diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31799index 104d56a..62ba13f1 100644
31800--- a/arch/x86/mm/init_64.c
31801+++ b/arch/x86/mm/init_64.c
31802@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31803 * around without checking the pgd every time.
31804 */
31805
31806-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31807+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31808 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31809
31810 int force_personality32;
31811@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31812
31813 for (address = start; address <= end; address += PGDIR_SIZE) {
31814 const pgd_t *pgd_ref = pgd_offset_k(address);
31815+
31816+#ifdef CONFIG_PAX_PER_CPU_PGD
31817+ unsigned long cpu;
31818+#else
31819 struct page *page;
31820+#endif
31821
31822 if (pgd_none(*pgd_ref))
31823 continue;
31824
31825 spin_lock(&pgd_lock);
31826+
31827+#ifdef CONFIG_PAX_PER_CPU_PGD
31828+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31829+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31830+
31831+ if (pgd_none(*pgd))
31832+ set_pgd(pgd, *pgd_ref);
31833+ else
31834+ BUG_ON(pgd_page_vaddr(*pgd)
31835+ != pgd_page_vaddr(*pgd_ref));
31836+ pgd = pgd_offset_cpu(cpu, kernel, address);
31837+#else
31838 list_for_each_entry(page, &pgd_list, lru) {
31839 pgd_t *pgd;
31840 spinlock_t *pgt_lock;
31841@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31842 /* the pgt_lock only for Xen */
31843 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31844 spin_lock(pgt_lock);
31845+#endif
31846
31847 if (pgd_none(*pgd))
31848 set_pgd(pgd, *pgd_ref);
31849@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31850 BUG_ON(pgd_page_vaddr(*pgd)
31851 != pgd_page_vaddr(*pgd_ref));
31852
31853+#ifndef CONFIG_PAX_PER_CPU_PGD
31854 spin_unlock(pgt_lock);
31855+#endif
31856+
31857 }
31858 spin_unlock(&pgd_lock);
31859 }
31860@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31861 {
31862 if (pgd_none(*pgd)) {
31863 pud_t *pud = (pud_t *)spp_getpage();
31864- pgd_populate(&init_mm, pgd, pud);
31865+ pgd_populate_kernel(&init_mm, pgd, pud);
31866 if (pud != pud_offset(pgd, 0))
31867 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31868 pud, pud_offset(pgd, 0));
31869@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31870 {
31871 if (pud_none(*pud)) {
31872 pmd_t *pmd = (pmd_t *) spp_getpage();
31873- pud_populate(&init_mm, pud, pmd);
31874+ pud_populate_kernel(&init_mm, pud, pmd);
31875 if (pmd != pmd_offset(pud, 0))
31876 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31877 pmd, pmd_offset(pud, 0));
31878@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31879 pmd = fill_pmd(pud, vaddr);
31880 pte = fill_pte(pmd, vaddr);
31881
31882+ pax_open_kernel();
31883 set_pte(pte, new_pte);
31884+ pax_close_kernel();
31885
31886 /*
31887 * It's enough to flush this one mapping.
31888@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31889 pgd = pgd_offset_k((unsigned long)__va(phys));
31890 if (pgd_none(*pgd)) {
31891 pud = (pud_t *) spp_getpage();
31892- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31893- _PAGE_USER));
31894+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31895 }
31896 pud = pud_offset(pgd, (unsigned long)__va(phys));
31897 if (pud_none(*pud)) {
31898 pmd = (pmd_t *) spp_getpage();
31899- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31900- _PAGE_USER));
31901+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31902 }
31903 pmd = pmd_offset(pud, phys);
31904 BUG_ON(!pmd_none(*pmd));
31905@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31906 prot);
31907
31908 spin_lock(&init_mm.page_table_lock);
31909- pud_populate(&init_mm, pud, pmd);
31910+ pud_populate_kernel(&init_mm, pud, pmd);
31911 spin_unlock(&init_mm.page_table_lock);
31912 }
31913 __flush_tlb_all();
31914@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31915 page_size_mask);
31916
31917 spin_lock(&init_mm.page_table_lock);
31918- pgd_populate(&init_mm, pgd, pud);
31919+ pgd_populate_kernel(&init_mm, pgd, pud);
31920 spin_unlock(&init_mm.page_table_lock);
31921 pgd_changed = true;
31922 }
31923@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31924 static struct vm_area_struct gate_vma = {
31925 .vm_start = VSYSCALL_START,
31926 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31927- .vm_page_prot = PAGE_READONLY_EXEC,
31928- .vm_flags = VM_READ | VM_EXEC
31929+ .vm_page_prot = PAGE_READONLY,
31930+ .vm_flags = VM_READ
31931 };
31932
31933 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31934@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31935
31936 const char *arch_vma_name(struct vm_area_struct *vma)
31937 {
31938- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31939+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31940 return "[vdso]";
31941 if (vma == &gate_vma)
31942 return "[vsyscall]";
31943diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31944index 7b179b4..6bd17777 100644
31945--- a/arch/x86/mm/iomap_32.c
31946+++ b/arch/x86/mm/iomap_32.c
31947@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31948 type = kmap_atomic_idx_push();
31949 idx = type + KM_TYPE_NR * smp_processor_id();
31950 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31951+
31952+ pax_open_kernel();
31953 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31954+ pax_close_kernel();
31955+
31956 arch_flush_lazy_mmu_mode();
31957
31958 return (void *)vaddr;
31959diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31960index 799580c..72f9fe0 100644
31961--- a/arch/x86/mm/ioremap.c
31962+++ b/arch/x86/mm/ioremap.c
31963@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31964 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31965 int is_ram = page_is_ram(pfn);
31966
31967- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31968+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31969 return NULL;
31970 WARN_ON_ONCE(is_ram);
31971 }
31972@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31973 *
31974 * Caller must ensure there is only one unmapping for the same pointer.
31975 */
31976-void iounmap(volatile void __iomem *addr)
31977+void iounmap(const volatile void __iomem *addr)
31978 {
31979 struct vm_struct *p, *o;
31980
31981@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31982
31983 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31984 if (page_is_ram(start >> PAGE_SHIFT))
31985+#ifdef CONFIG_HIGHMEM
31986+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31987+#endif
31988 return __va(phys);
31989
31990 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31991@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31992 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31993 {
31994 if (page_is_ram(phys >> PAGE_SHIFT))
31995+#ifdef CONFIG_HIGHMEM
31996+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31997+#endif
31998 return;
31999
32000 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32001@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32002 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32003
32004 static __initdata int after_paging_init;
32005-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32006+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32007
32008 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32009 {
32010@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32011 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32012
32013 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32014- memset(bm_pte, 0, sizeof(bm_pte));
32015- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32016+ pmd_populate_user(&init_mm, pmd, bm_pte);
32017
32018 /*
32019 * The boot-ioremap range spans multiple pmds, for which
32020diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32021index d87dd6d..bf3fa66 100644
32022--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32023+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32024@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32025 * memory (e.g. tracked pages)? For now, we need this to avoid
32026 * invoking kmemcheck for PnP BIOS calls.
32027 */
32028- if (regs->flags & X86_VM_MASK)
32029+ if (v8086_mode(regs))
32030 return false;
32031- if (regs->cs != __KERNEL_CS)
32032+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32033 return false;
32034
32035 pte = kmemcheck_pte_lookup(address);
32036diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32037index 25e7e13..1964579 100644
32038--- a/arch/x86/mm/mmap.c
32039+++ b/arch/x86/mm/mmap.c
32040@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32041 * Leave an at least ~128 MB hole with possible stack randomization.
32042 */
32043 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32044-#define MAX_GAP (TASK_SIZE/6*5)
32045+#define MAX_GAP (pax_task_size/6*5)
32046
32047 static int mmap_is_legacy(void)
32048 {
32049@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32050 return rnd << PAGE_SHIFT;
32051 }
32052
32053-static unsigned long mmap_base(void)
32054+static unsigned long mmap_base(struct mm_struct *mm)
32055 {
32056 unsigned long gap = rlimit(RLIMIT_STACK);
32057+ unsigned long pax_task_size = TASK_SIZE;
32058+
32059+#ifdef CONFIG_PAX_SEGMEXEC
32060+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32061+ pax_task_size = SEGMEXEC_TASK_SIZE;
32062+#endif
32063
32064 if (gap < MIN_GAP)
32065 gap = MIN_GAP;
32066 else if (gap > MAX_GAP)
32067 gap = MAX_GAP;
32068
32069- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32070+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32071 }
32072
32073 /*
32074 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32075 * does, but not when emulating X86_32
32076 */
32077-static unsigned long mmap_legacy_base(void)
32078+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32079 {
32080- if (mmap_is_ia32())
32081+ if (mmap_is_ia32()) {
32082+
32083+#ifdef CONFIG_PAX_SEGMEXEC
32084+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32085+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32086+ else
32087+#endif
32088+
32089 return TASK_UNMAPPED_BASE;
32090- else
32091+ } else
32092 return TASK_UNMAPPED_BASE + mmap_rnd();
32093 }
32094
32095@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32096 */
32097 void arch_pick_mmap_layout(struct mm_struct *mm)
32098 {
32099- mm->mmap_legacy_base = mmap_legacy_base();
32100- mm->mmap_base = mmap_base();
32101+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32102+ mm->mmap_base = mmap_base(mm);
32103+
32104+#ifdef CONFIG_PAX_RANDMMAP
32105+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32106+ mm->mmap_legacy_base += mm->delta_mmap;
32107+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32108+ }
32109+#endif
32110
32111 if (mmap_is_legacy()) {
32112 mm->mmap_base = mm->mmap_legacy_base;
32113diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32114index 0057a7a..95c7edd 100644
32115--- a/arch/x86/mm/mmio-mod.c
32116+++ b/arch/x86/mm/mmio-mod.c
32117@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32118 break;
32119 default:
32120 {
32121- unsigned char *ip = (unsigned char *)instptr;
32122+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32123 my_trace->opcode = MMIO_UNKNOWN_OP;
32124 my_trace->width = 0;
32125 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32126@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32127 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32128 void __iomem *addr)
32129 {
32130- static atomic_t next_id;
32131+ static atomic_unchecked_t next_id;
32132 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32133 /* These are page-unaligned. */
32134 struct mmiotrace_map map = {
32135@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32136 .private = trace
32137 },
32138 .phys = offset,
32139- .id = atomic_inc_return(&next_id)
32140+ .id = atomic_inc_return_unchecked(&next_id)
32141 };
32142 map.map_id = trace->id;
32143
32144@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32145 ioremap_trace_core(offset, size, addr);
32146 }
32147
32148-static void iounmap_trace_core(volatile void __iomem *addr)
32149+static void iounmap_trace_core(const volatile void __iomem *addr)
32150 {
32151 struct mmiotrace_map map = {
32152 .phys = 0,
32153@@ -328,7 +328,7 @@ not_enabled:
32154 }
32155 }
32156
32157-void mmiotrace_iounmap(volatile void __iomem *addr)
32158+void mmiotrace_iounmap(const volatile void __iomem *addr)
32159 {
32160 might_sleep();
32161 if (is_enabled()) /* recheck and proper locking in *_core() */
32162diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32163index 8bf93ba..dbcd670 100644
32164--- a/arch/x86/mm/numa.c
32165+++ b/arch/x86/mm/numa.c
32166@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32167 return true;
32168 }
32169
32170-static int __init numa_register_memblks(struct numa_meminfo *mi)
32171+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32172 {
32173 unsigned long uninitialized_var(pfn_align);
32174 int i, nid;
32175diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32176index d0b1773..4c3327c 100644
32177--- a/arch/x86/mm/pageattr-test.c
32178+++ b/arch/x86/mm/pageattr-test.c
32179@@ -36,7 +36,7 @@ enum {
32180
32181 static int pte_testbit(pte_t pte)
32182 {
32183- return pte_flags(pte) & _PAGE_UNUSED1;
32184+ return pte_flags(pte) & _PAGE_CPA_TEST;
32185 }
32186
32187 struct split_state {
32188diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32189index bb32480..75f2f5e 100644
32190--- a/arch/x86/mm/pageattr.c
32191+++ b/arch/x86/mm/pageattr.c
32192@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32193 */
32194 #ifdef CONFIG_PCI_BIOS
32195 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32196- pgprot_val(forbidden) |= _PAGE_NX;
32197+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32198 #endif
32199
32200 /*
32201@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32202 * Does not cover __inittext since that is gone later on. On
32203 * 64bit we do not enforce !NX on the low mapping
32204 */
32205- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32206- pgprot_val(forbidden) |= _PAGE_NX;
32207+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32208+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32209
32210+#ifdef CONFIG_DEBUG_RODATA
32211 /*
32212 * The .rodata section needs to be read-only. Using the pfn
32213 * catches all aliases.
32214@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32215 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32216 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32217 pgprot_val(forbidden) |= _PAGE_RW;
32218+#endif
32219
32220 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32221 /*
32222@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32223 }
32224 #endif
32225
32226+#ifdef CONFIG_PAX_KERNEXEC
32227+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32228+ pgprot_val(forbidden) |= _PAGE_RW;
32229+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32230+ }
32231+#endif
32232+
32233 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32234
32235 return prot;
32236@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32237 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32238 {
32239 /* change init_mm */
32240+ pax_open_kernel();
32241 set_pte_atomic(kpte, pte);
32242+
32243 #ifdef CONFIG_X86_32
32244 if (!SHARED_KERNEL_PMD) {
32245+
32246+#ifdef CONFIG_PAX_PER_CPU_PGD
32247+ unsigned long cpu;
32248+#else
32249 struct page *page;
32250+#endif
32251
32252+#ifdef CONFIG_PAX_PER_CPU_PGD
32253+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32254+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32255+#else
32256 list_for_each_entry(page, &pgd_list, lru) {
32257- pgd_t *pgd;
32258+ pgd_t *pgd = (pgd_t *)page_address(page);
32259+#endif
32260+
32261 pud_t *pud;
32262 pmd_t *pmd;
32263
32264- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32265+ pgd += pgd_index(address);
32266 pud = pud_offset(pgd, address);
32267 pmd = pmd_offset(pud, address);
32268 set_pte_atomic((pte_t *)pmd, pte);
32269 }
32270 }
32271 #endif
32272+ pax_close_kernel();
32273 }
32274
32275 static int
32276diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32277index 6574388..87e9bef 100644
32278--- a/arch/x86/mm/pat.c
32279+++ b/arch/x86/mm/pat.c
32280@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32281
32282 if (!entry) {
32283 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32284- current->comm, current->pid, start, end - 1);
32285+ current->comm, task_pid_nr(current), start, end - 1);
32286 return -EINVAL;
32287 }
32288
32289@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32290
32291 while (cursor < to) {
32292 if (!devmem_is_allowed(pfn)) {
32293- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32294- current->comm, from, to - 1);
32295+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32296+ current->comm, from, to - 1, cursor);
32297 return 0;
32298 }
32299 cursor += PAGE_SIZE;
32300@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32301 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32302 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32303 "for [mem %#010Lx-%#010Lx]\n",
32304- current->comm, current->pid,
32305+ current->comm, task_pid_nr(current),
32306 cattr_name(flags),
32307 base, (unsigned long long)(base + size-1));
32308 return -EINVAL;
32309@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32310 flags = lookup_memtype(paddr);
32311 if (want_flags != flags) {
32312 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32313- current->comm, current->pid,
32314+ current->comm, task_pid_nr(current),
32315 cattr_name(want_flags),
32316 (unsigned long long)paddr,
32317 (unsigned long long)(paddr + size - 1),
32318@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32319 free_memtype(paddr, paddr + size);
32320 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32321 " for [mem %#010Lx-%#010Lx], got %s\n",
32322- current->comm, current->pid,
32323+ current->comm, task_pid_nr(current),
32324 cattr_name(want_flags),
32325 (unsigned long long)paddr,
32326 (unsigned long long)(paddr + size - 1),
32327diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32328index 415f6c4..d319983 100644
32329--- a/arch/x86/mm/pat_rbtree.c
32330+++ b/arch/x86/mm/pat_rbtree.c
32331@@ -160,7 +160,7 @@ success:
32332
32333 failure:
32334 printk(KERN_INFO "%s:%d conflicting memory types "
32335- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32336+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32337 end, cattr_name(found_type), cattr_name(match->type));
32338 return -EBUSY;
32339 }
32340diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32341index 9f0614d..92ae64a 100644
32342--- a/arch/x86/mm/pf_in.c
32343+++ b/arch/x86/mm/pf_in.c
32344@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32345 int i;
32346 enum reason_type rv = OTHERS;
32347
32348- p = (unsigned char *)ins_addr;
32349+ p = (unsigned char *)ktla_ktva(ins_addr);
32350 p += skip_prefix(p, &prf);
32351 p += get_opcode(p, &opcode);
32352
32353@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32354 struct prefix_bits prf;
32355 int i;
32356
32357- p = (unsigned char *)ins_addr;
32358+ p = (unsigned char *)ktla_ktva(ins_addr);
32359 p += skip_prefix(p, &prf);
32360 p += get_opcode(p, &opcode);
32361
32362@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32363 struct prefix_bits prf;
32364 int i;
32365
32366- p = (unsigned char *)ins_addr;
32367+ p = (unsigned char *)ktla_ktva(ins_addr);
32368 p += skip_prefix(p, &prf);
32369 p += get_opcode(p, &opcode);
32370
32371@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32372 struct prefix_bits prf;
32373 int i;
32374
32375- p = (unsigned char *)ins_addr;
32376+ p = (unsigned char *)ktla_ktva(ins_addr);
32377 p += skip_prefix(p, &prf);
32378 p += get_opcode(p, &opcode);
32379 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32380@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32381 struct prefix_bits prf;
32382 int i;
32383
32384- p = (unsigned char *)ins_addr;
32385+ p = (unsigned char *)ktla_ktva(ins_addr);
32386 p += skip_prefix(p, &prf);
32387 p += get_opcode(p, &opcode);
32388 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32389diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32390index dfa537a..fd45c64 100644
32391--- a/arch/x86/mm/pgtable.c
32392+++ b/arch/x86/mm/pgtable.c
32393@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
32394 list_del(&page->lru);
32395 }
32396
32397-#define UNSHARED_PTRS_PER_PGD \
32398- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32399+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32400+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32401
32402+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32403+{
32404+ unsigned int count = USER_PGD_PTRS;
32405
32406+ if (!pax_user_shadow_base)
32407+ return;
32408+
32409+ while (count--)
32410+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32411+}
32412+#endif
32413+
32414+#ifdef CONFIG_PAX_PER_CPU_PGD
32415+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32416+{
32417+ unsigned int count = USER_PGD_PTRS;
32418+
32419+ while (count--) {
32420+ pgd_t pgd;
32421+
32422+#ifdef CONFIG_X86_64
32423+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32424+#else
32425+ pgd = *src++;
32426+#endif
32427+
32428+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32429+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32430+#endif
32431+
32432+ *dst++ = pgd;
32433+ }
32434+
32435+}
32436+#endif
32437+
32438+#ifdef CONFIG_X86_64
32439+#define pxd_t pud_t
32440+#define pyd_t pgd_t
32441+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32442+#define pxd_free(mm, pud) pud_free((mm), (pud))
32443+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32444+#define pyd_offset(mm, address) pgd_offset((mm), (address))
32445+#define PYD_SIZE PGDIR_SIZE
32446+#else
32447+#define pxd_t pmd_t
32448+#define pyd_t pud_t
32449+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32450+#define pxd_free(mm, pud) pmd_free((mm), (pud))
32451+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32452+#define pyd_offset(mm, address) pud_offset((mm), (address))
32453+#define PYD_SIZE PUD_SIZE
32454+#endif
32455+
32456+#ifdef CONFIG_PAX_PER_CPU_PGD
32457+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32458+static inline void pgd_dtor(pgd_t *pgd) {}
32459+#else
32460 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32461 {
32462 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32463@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
32464 pgd_list_del(pgd);
32465 spin_unlock(&pgd_lock);
32466 }
32467+#endif
32468
32469 /*
32470 * List of all pgd's needed for non-PAE so it can invalidate entries
32471@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
32472 * -- nyc
32473 */
32474
32475-#ifdef CONFIG_X86_PAE
32476+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32477 /*
32478 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32479 * updating the top-level pagetable entries to guarantee the
32480@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
32481 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32482 * and initialize the kernel pmds here.
32483 */
32484-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32485+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32486
32487 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32488 {
32489@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32490 */
32491 flush_tlb_mm(mm);
32492 }
32493+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32494+#define PREALLOCATED_PXDS USER_PGD_PTRS
32495 #else /* !CONFIG_X86_PAE */
32496
32497 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32498-#define PREALLOCATED_PMDS 0
32499+#define PREALLOCATED_PXDS 0
32500
32501 #endif /* CONFIG_X86_PAE */
32502
32503-static void free_pmds(pmd_t *pmds[])
32504+static void free_pxds(pxd_t *pxds[])
32505 {
32506 int i;
32507
32508- for(i = 0; i < PREALLOCATED_PMDS; i++)
32509- if (pmds[i])
32510- free_page((unsigned long)pmds[i]);
32511+ for(i = 0; i < PREALLOCATED_PXDS; i++)
32512+ if (pxds[i])
32513+ free_page((unsigned long)pxds[i]);
32514 }
32515
32516-static int preallocate_pmds(pmd_t *pmds[])
32517+static int preallocate_pxds(pxd_t *pxds[])
32518 {
32519 int i;
32520 bool failed = false;
32521
32522- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32523- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32524- if (pmd == NULL)
32525+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32526+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32527+ if (pxd == NULL)
32528 failed = true;
32529- pmds[i] = pmd;
32530+ pxds[i] = pxd;
32531 }
32532
32533 if (failed) {
32534- free_pmds(pmds);
32535+ free_pxds(pxds);
32536 return -ENOMEM;
32537 }
32538
32539@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32540 * preallocate which never got a corresponding vma will need to be
32541 * freed manually.
32542 */
32543-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32544+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32545 {
32546 int i;
32547
32548- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32549+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32550 pgd_t pgd = pgdp[i];
32551
32552 if (pgd_val(pgd) != 0) {
32553- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32554+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32555
32556- pgdp[i] = native_make_pgd(0);
32557+ set_pgd(pgdp + i, native_make_pgd(0));
32558
32559- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32560- pmd_free(mm, pmd);
32561+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32562+ pxd_free(mm, pxd);
32563 }
32564 }
32565 }
32566
32567-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32568+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32569 {
32570- pud_t *pud;
32571+ pyd_t *pyd;
32572 int i;
32573
32574- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32575+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32576 return;
32577
32578- pud = pud_offset(pgd, 0);
32579-
32580- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32581- pmd_t *pmd = pmds[i];
32582+#ifdef CONFIG_X86_64
32583+ pyd = pyd_offset(mm, 0L);
32584+#else
32585+ pyd = pyd_offset(pgd, 0L);
32586+#endif
32587
32588+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32589+ pxd_t *pxd = pxds[i];
32590 if (i >= KERNEL_PGD_BOUNDARY)
32591- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32592- sizeof(pmd_t) * PTRS_PER_PMD);
32593+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32594+ sizeof(pxd_t) * PTRS_PER_PMD);
32595
32596- pud_populate(mm, pud, pmd);
32597+ pyd_populate(mm, pyd, pxd);
32598 }
32599 }
32600
32601 pgd_t *pgd_alloc(struct mm_struct *mm)
32602 {
32603 pgd_t *pgd;
32604- pmd_t *pmds[PREALLOCATED_PMDS];
32605+ pxd_t *pxds[PREALLOCATED_PXDS];
32606
32607 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32608
32609@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32610
32611 mm->pgd = pgd;
32612
32613- if (preallocate_pmds(pmds) != 0)
32614+ if (preallocate_pxds(pxds) != 0)
32615 goto out_free_pgd;
32616
32617 if (paravirt_pgd_alloc(mm) != 0)
32618- goto out_free_pmds;
32619+ goto out_free_pxds;
32620
32621 /*
32622 * Make sure that pre-populating the pmds is atomic with
32623@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32624 spin_lock(&pgd_lock);
32625
32626 pgd_ctor(mm, pgd);
32627- pgd_prepopulate_pmd(mm, pgd, pmds);
32628+ pgd_prepopulate_pxd(mm, pgd, pxds);
32629
32630 spin_unlock(&pgd_lock);
32631
32632 return pgd;
32633
32634-out_free_pmds:
32635- free_pmds(pmds);
32636+out_free_pxds:
32637+ free_pxds(pxds);
32638 out_free_pgd:
32639 free_page((unsigned long)pgd);
32640 out:
32641@@ -300,7 +363,7 @@ out:
32642
32643 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32644 {
32645- pgd_mop_up_pmds(mm, pgd);
32646+ pgd_mop_up_pxds(mm, pgd);
32647 pgd_dtor(pgd);
32648 paravirt_pgd_free(mm, pgd);
32649 free_page((unsigned long)pgd);
32650diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32651index a69bcb8..19068ab 100644
32652--- a/arch/x86/mm/pgtable_32.c
32653+++ b/arch/x86/mm/pgtable_32.c
32654@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32655 return;
32656 }
32657 pte = pte_offset_kernel(pmd, vaddr);
32658+
32659+ pax_open_kernel();
32660 if (pte_val(pteval))
32661 set_pte_at(&init_mm, vaddr, pte, pteval);
32662 else
32663 pte_clear(&init_mm, vaddr, pte);
32664+ pax_close_kernel();
32665
32666 /*
32667 * It's enough to flush this one mapping.
32668diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32669index e666cbb..61788c45 100644
32670--- a/arch/x86/mm/physaddr.c
32671+++ b/arch/x86/mm/physaddr.c
32672@@ -10,7 +10,7 @@
32673 #ifdef CONFIG_X86_64
32674
32675 #ifdef CONFIG_DEBUG_VIRTUAL
32676-unsigned long __phys_addr(unsigned long x)
32677+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32678 {
32679 unsigned long y = x - __START_KERNEL_map;
32680
32681@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32682 #else
32683
32684 #ifdef CONFIG_DEBUG_VIRTUAL
32685-unsigned long __phys_addr(unsigned long x)
32686+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32687 {
32688 unsigned long phys_addr = x - PAGE_OFFSET;
32689 /* VMALLOC_* aren't constants */
32690diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32691index 90555bf..f5f1828 100644
32692--- a/arch/x86/mm/setup_nx.c
32693+++ b/arch/x86/mm/setup_nx.c
32694@@ -5,8 +5,10 @@
32695 #include <asm/pgtable.h>
32696 #include <asm/proto.h>
32697
32698+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32699 static int disable_nx;
32700
32701+#ifndef CONFIG_PAX_PAGEEXEC
32702 /*
32703 * noexec = on|off
32704 *
32705@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32706 return 0;
32707 }
32708 early_param("noexec", noexec_setup);
32709+#endif
32710+
32711+#endif
32712
32713 void x86_configure_nx(void)
32714 {
32715+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32716 if (cpu_has_nx && !disable_nx)
32717 __supported_pte_mask |= _PAGE_NX;
32718 else
32719+#endif
32720 __supported_pte_mask &= ~_PAGE_NX;
32721 }
32722
32723diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32724index ae699b3..f1b2ad2 100644
32725--- a/arch/x86/mm/tlb.c
32726+++ b/arch/x86/mm/tlb.c
32727@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32728 BUG();
32729 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32730 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32731+
32732+#ifndef CONFIG_PAX_PER_CPU_PGD
32733 load_cr3(swapper_pg_dir);
32734+#endif
32735+
32736 }
32737 }
32738 EXPORT_SYMBOL_GPL(leave_mm);
32739diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32740new file mode 100644
32741index 0000000..dace51c
32742--- /dev/null
32743+++ b/arch/x86/mm/uderef_64.c
32744@@ -0,0 +1,37 @@
32745+#include <linux/mm.h>
32746+#include <asm/pgtable.h>
32747+#include <asm/uaccess.h>
32748+
32749+#ifdef CONFIG_PAX_MEMORY_UDEREF
32750+/* PaX: due to the special call convention these functions must
32751+ * - remain leaf functions under all configurations,
32752+ * - never be called directly, only dereferenced from the wrappers.
32753+ */
32754+void __pax_open_userland(void)
32755+{
32756+ unsigned int cpu;
32757+
32758+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32759+ return;
32760+
32761+ cpu = raw_get_cpu();
32762+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32763+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32764+ raw_put_cpu_no_resched();
32765+}
32766+EXPORT_SYMBOL(__pax_open_userland);
32767+
32768+void __pax_close_userland(void)
32769+{
32770+ unsigned int cpu;
32771+
32772+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32773+ return;
32774+
32775+ cpu = raw_get_cpu();
32776+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32777+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32778+ raw_put_cpu_no_resched();
32779+}
32780+EXPORT_SYMBOL(__pax_close_userland);
32781+#endif
32782diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32783index 877b9a1..a8ecf42 100644
32784--- a/arch/x86/net/bpf_jit.S
32785+++ b/arch/x86/net/bpf_jit.S
32786@@ -9,6 +9,7 @@
32787 */
32788 #include <linux/linkage.h>
32789 #include <asm/dwarf2.h>
32790+#include <asm/alternative-asm.h>
32791
32792 /*
32793 * Calling convention :
32794@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32795 jle bpf_slow_path_word
32796 mov (SKBDATA,%rsi),%eax
32797 bswap %eax /* ntohl() */
32798+ pax_force_retaddr
32799 ret
32800
32801 sk_load_half:
32802@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32803 jle bpf_slow_path_half
32804 movzwl (SKBDATA,%rsi),%eax
32805 rol $8,%ax # ntohs()
32806+ pax_force_retaddr
32807 ret
32808
32809 sk_load_byte:
32810@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32811 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32812 jle bpf_slow_path_byte
32813 movzbl (SKBDATA,%rsi),%eax
32814+ pax_force_retaddr
32815 ret
32816
32817 /**
32818@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32819 movzbl (SKBDATA,%rsi),%ebx
32820 and $15,%bl
32821 shl $2,%bl
32822+ pax_force_retaddr
32823 ret
32824
32825 /* rsi contains offset and can be scratched */
32826@@ -109,6 +114,7 @@ bpf_slow_path_word:
32827 js bpf_error
32828 mov -12(%rbp),%eax
32829 bswap %eax
32830+ pax_force_retaddr
32831 ret
32832
32833 bpf_slow_path_half:
32834@@ -117,12 +123,14 @@ bpf_slow_path_half:
32835 mov -12(%rbp),%ax
32836 rol $8,%ax
32837 movzwl %ax,%eax
32838+ pax_force_retaddr
32839 ret
32840
32841 bpf_slow_path_byte:
32842 bpf_slow_path_common(1)
32843 js bpf_error
32844 movzbl -12(%rbp),%eax
32845+ pax_force_retaddr
32846 ret
32847
32848 bpf_slow_path_byte_msh:
32849@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32850 and $15,%al
32851 shl $2,%al
32852 xchg %eax,%ebx
32853+ pax_force_retaddr
32854 ret
32855
32856 #define sk_negative_common(SIZE) \
32857@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32858 sk_negative_common(4)
32859 mov (%rax), %eax
32860 bswap %eax
32861+ pax_force_retaddr
32862 ret
32863
32864 bpf_slow_path_half_neg:
32865@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32866 mov (%rax),%ax
32867 rol $8,%ax
32868 movzwl %ax,%eax
32869+ pax_force_retaddr
32870 ret
32871
32872 bpf_slow_path_byte_neg:
32873@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32874 .globl sk_load_byte_negative_offset
32875 sk_negative_common(1)
32876 movzbl (%rax), %eax
32877+ pax_force_retaddr
32878 ret
32879
32880 bpf_slow_path_byte_msh_neg:
32881@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32882 and $15,%al
32883 shl $2,%al
32884 xchg %eax,%ebx
32885+ pax_force_retaddr
32886 ret
32887
32888 bpf_error:
32889@@ -197,4 +210,5 @@ bpf_error:
32890 xor %eax,%eax
32891 mov -8(%rbp),%rbx
32892 leaveq
32893+ pax_force_retaddr
32894 ret
32895diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32896index 26328e8..5f96c25 100644
32897--- a/arch/x86/net/bpf_jit_comp.c
32898+++ b/arch/x86/net/bpf_jit_comp.c
32899@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32900 return ptr + len;
32901 }
32902
32903+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32904+#define MAX_INSTR_CODE_SIZE 96
32905+#else
32906+#define MAX_INSTR_CODE_SIZE 64
32907+#endif
32908+
32909 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32910
32911 #define EMIT1(b1) EMIT(b1, 1)
32912 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32913 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32914 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32915+
32916+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32917+/* original constant will appear in ecx */
32918+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32919+do { \
32920+ /* mov ecx, randkey */ \
32921+ EMIT1(0xb9); \
32922+ EMIT(_key, 4); \
32923+ /* xor ecx, randkey ^ off */ \
32924+ EMIT2(0x81, 0xf1); \
32925+ EMIT((_key) ^ (_off), 4); \
32926+} while (0)
32927+
32928+#define EMIT1_off32(b1, _off) \
32929+do { \
32930+ switch (b1) { \
32931+ case 0x05: /* add eax, imm32 */ \
32932+ case 0x2d: /* sub eax, imm32 */ \
32933+ case 0x25: /* and eax, imm32 */ \
32934+ case 0x0d: /* or eax, imm32 */ \
32935+ case 0xb8: /* mov eax, imm32 */ \
32936+ case 0x35: /* xor eax, imm32 */ \
32937+ case 0x3d: /* cmp eax, imm32 */ \
32938+ case 0xa9: /* test eax, imm32 */ \
32939+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32940+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32941+ break; \
32942+ case 0xbb: /* mov ebx, imm32 */ \
32943+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32944+ /* mov ebx, ecx */ \
32945+ EMIT2(0x89, 0xcb); \
32946+ break; \
32947+ case 0xbe: /* mov esi, imm32 */ \
32948+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32949+ /* mov esi, ecx */ \
32950+ EMIT2(0x89, 0xce); \
32951+ break; \
32952+ case 0xe8: /* call rel imm32, always to known funcs */ \
32953+ EMIT1(b1); \
32954+ EMIT(_off, 4); \
32955+ break; \
32956+ case 0xe9: /* jmp rel imm32 */ \
32957+ EMIT1(b1); \
32958+ EMIT(_off, 4); \
32959+ /* prevent fall-through, we're not called if off = 0 */ \
32960+ EMIT(0xcccccccc, 4); \
32961+ EMIT(0xcccccccc, 4); \
32962+ break; \
32963+ default: \
32964+ BUILD_BUG(); \
32965+ } \
32966+} while (0)
32967+
32968+#define EMIT2_off32(b1, b2, _off) \
32969+do { \
32970+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32971+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32972+ EMIT(randkey, 4); \
32973+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32974+ EMIT((_off) - randkey, 4); \
32975+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32976+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32977+ /* imul eax, ecx */ \
32978+ EMIT3(0x0f, 0xaf, 0xc1); \
32979+ } else { \
32980+ BUILD_BUG(); \
32981+ } \
32982+} while (0)
32983+#else
32984 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32985+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32986+#endif
32987
32988 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32989 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32990@@ -91,6 +168,24 @@ do { \
32991 #define X86_JBE 0x76
32992 #define X86_JA 0x77
32993
32994+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32995+#define APPEND_FLOW_VERIFY() \
32996+do { \
32997+ /* mov ecx, randkey */ \
32998+ EMIT1(0xb9); \
32999+ EMIT(randkey, 4); \
33000+ /* cmp ecx, randkey */ \
33001+ EMIT2(0x81, 0xf9); \
33002+ EMIT(randkey, 4); \
33003+ /* jz after 8 int 3s */ \
33004+ EMIT2(0x74, 0x08); \
33005+ EMIT(0xcccccccc, 4); \
33006+ EMIT(0xcccccccc, 4); \
33007+} while (0)
33008+#else
33009+#define APPEND_FLOW_VERIFY() do { } while (0)
33010+#endif
33011+
33012 #define EMIT_COND_JMP(op, offset) \
33013 do { \
33014 if (is_near(offset)) \
33015@@ -98,6 +193,7 @@ do { \
33016 else { \
33017 EMIT2(0x0f, op + 0x10); \
33018 EMIT(offset, 4); /* jxx .+off32 */ \
33019+ APPEND_FLOW_VERIFY(); \
33020 } \
33021 } while (0)
33022
33023@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33024 return -1;
33025 }
33026
33027-struct bpf_binary_header {
33028- unsigned int pages;
33029- /* Note : for security reasons, bpf code will follow a randomly
33030- * sized amount of int3 instructions
33031- */
33032- u8 image[];
33033-};
33034-
33035-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33036+/* Note : for security reasons, bpf code will follow a randomly
33037+ * sized amount of int3 instructions
33038+ */
33039+static u8 *bpf_alloc_binary(unsigned int proglen,
33040 u8 **image_ptr)
33041 {
33042 unsigned int sz, hole;
33043- struct bpf_binary_header *header;
33044+ u8 *header;
33045
33046 /* Most of BPF filters are really small,
33047 * but if some of them fill a page, allow at least
33048 * 128 extra bytes to insert a random section of int3
33049 */
33050- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33051- header = module_alloc(sz);
33052+ sz = round_up(proglen + 128, PAGE_SIZE);
33053+ header = module_alloc_exec(sz);
33054 if (!header)
33055 return NULL;
33056
33057+ pax_open_kernel();
33058 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33059+ pax_close_kernel();
33060
33061- header->pages = sz / PAGE_SIZE;
33062- hole = sz - (proglen + sizeof(*header));
33063+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33064
33065 /* insert a random number of int3 instructions before BPF code */
33066- *image_ptr = &header->image[prandom_u32() % hole];
33067+ *image_ptr = &header[prandom_u32() % hole];
33068 return header;
33069 }
33070
33071 void bpf_jit_compile(struct sk_filter *fp)
33072 {
33073- u8 temp[64];
33074+ u8 temp[MAX_INSTR_CODE_SIZE];
33075 u8 *prog;
33076 unsigned int proglen, oldproglen = 0;
33077 int ilen, i;
33078 int t_offset, f_offset;
33079 u8 t_op, f_op, seen = 0, pass;
33080 u8 *image = NULL;
33081- struct bpf_binary_header *header = NULL;
33082+ u8 *header = NULL;
33083 u8 *func;
33084 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33085 unsigned int cleanup_addr; /* epilogue code offset */
33086 unsigned int *addrs;
33087 const struct sock_filter *filter = fp->insns;
33088 int flen = fp->len;
33089+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33090+ unsigned int randkey;
33091+#endif
33092
33093 if (!bpf_jit_enable)
33094 return;
33095@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33096 if (addrs == NULL)
33097 return;
33098
33099+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33100+ randkey = get_random_int();
33101+#endif
33102+
33103 /* Before first pass, make a rough estimation of addrs[]
33104- * each bpf instruction is translated to less than 64 bytes
33105+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33106 */
33107 for (proglen = 0, i = 0; i < flen; i++) {
33108- proglen += 64;
33109+ proglen += MAX_INSTR_CODE_SIZE;
33110 addrs[i] = proglen;
33111 }
33112 cleanup_addr = proglen; /* epilogue address */
33113@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33114 case BPF_S_ALU_MUL_K: /* A *= K */
33115 if (is_imm8(K))
33116 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33117- else {
33118- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33119- EMIT(K, 4);
33120- }
33121+ else
33122+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33123 break;
33124 case BPF_S_ALU_DIV_X: /* A /= X; */
33125 seen |= SEEN_XREG;
33126@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
33127 break;
33128 case BPF_S_ALU_MOD_K: /* A %= K; */
33129 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33130+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33131+ DILUTE_CONST_SEQUENCE(K, randkey);
33132+#else
33133 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33134+#endif
33135 EMIT2(0xf7, 0xf1); /* div %ecx */
33136 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33137 break;
33138 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
33139+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33140+ DILUTE_CONST_SEQUENCE(K, randkey);
33141+ // imul rax, rcx
33142+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
33143+#else
33144 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
33145 EMIT(K, 4);
33146+#endif
33147 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
33148 break;
33149 case BPF_S_ALU_AND_X:
33150@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33151 if (is_imm8(K)) {
33152 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33153 } else {
33154- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33155- EMIT(K, 4);
33156+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33157 }
33158 } else {
33159 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33160@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33161 if (unlikely(proglen + ilen > oldproglen)) {
33162 pr_err("bpb_jit_compile fatal error\n");
33163 kfree(addrs);
33164- module_free(NULL, header);
33165+ module_free_exec(NULL, image);
33166 return;
33167 }
33168+ pax_open_kernel();
33169 memcpy(image + proglen, temp, ilen);
33170+ pax_close_kernel();
33171 }
33172 proglen += ilen;
33173 addrs[i] = proglen;
33174@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33175
33176 if (image) {
33177 bpf_flush_icache(header, image + proglen);
33178- set_memory_ro((unsigned long)header, header->pages);
33179 fp->bpf_func = (void *)image;
33180 }
33181 out:
33182@@ -776,10 +883,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33183 {
33184 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33185 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33186- struct bpf_binary_header *header = (void *)addr;
33187
33188- set_memory_rw(addr, header->pages);
33189- module_free(NULL, header);
33190+ set_memory_rw(addr, 1);
33191+ module_free_exec(NULL, (void *)addr);
33192 kfree(fp);
33193 }
33194
33195diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33196index d6aa6e8..266395a 100644
33197--- a/arch/x86/oprofile/backtrace.c
33198+++ b/arch/x86/oprofile/backtrace.c
33199@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33200 struct stack_frame_ia32 *fp;
33201 unsigned long bytes;
33202
33203- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33204+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33205 if (bytes != sizeof(bufhead))
33206 return NULL;
33207
33208- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33209+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33210
33211 oprofile_add_trace(bufhead[0].return_address);
33212
33213@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33214 struct stack_frame bufhead[2];
33215 unsigned long bytes;
33216
33217- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33218+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33219 if (bytes != sizeof(bufhead))
33220 return NULL;
33221
33222@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33223 {
33224 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33225
33226- if (!user_mode_vm(regs)) {
33227+ if (!user_mode(regs)) {
33228 unsigned long stack = kernel_stack_pointer(regs);
33229 if (depth)
33230 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33231diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33232index 6890d84..1dad1f1 100644
33233--- a/arch/x86/oprofile/nmi_int.c
33234+++ b/arch/x86/oprofile/nmi_int.c
33235@@ -23,6 +23,7 @@
33236 #include <asm/nmi.h>
33237 #include <asm/msr.h>
33238 #include <asm/apic.h>
33239+#include <asm/pgtable.h>
33240
33241 #include "op_counter.h"
33242 #include "op_x86_model.h"
33243@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33244 if (ret)
33245 return ret;
33246
33247- if (!model->num_virt_counters)
33248- model->num_virt_counters = model->num_counters;
33249+ if (!model->num_virt_counters) {
33250+ pax_open_kernel();
33251+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33252+ pax_close_kernel();
33253+ }
33254
33255 mux_init(ops);
33256
33257diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33258index 50d86c0..7985318 100644
33259--- a/arch/x86/oprofile/op_model_amd.c
33260+++ b/arch/x86/oprofile/op_model_amd.c
33261@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33262 num_counters = AMD64_NUM_COUNTERS;
33263 }
33264
33265- op_amd_spec.num_counters = num_counters;
33266- op_amd_spec.num_controls = num_counters;
33267- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33268+ pax_open_kernel();
33269+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33270+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33271+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33272+ pax_close_kernel();
33273
33274 return 0;
33275 }
33276diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33277index d90528e..0127e2b 100644
33278--- a/arch/x86/oprofile/op_model_ppro.c
33279+++ b/arch/x86/oprofile/op_model_ppro.c
33280@@ -19,6 +19,7 @@
33281 #include <asm/msr.h>
33282 #include <asm/apic.h>
33283 #include <asm/nmi.h>
33284+#include <asm/pgtable.h>
33285
33286 #include "op_x86_model.h"
33287 #include "op_counter.h"
33288@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33289
33290 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33291
33292- op_arch_perfmon_spec.num_counters = num_counters;
33293- op_arch_perfmon_spec.num_controls = num_counters;
33294+ pax_open_kernel();
33295+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33296+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33297+ pax_close_kernel();
33298 }
33299
33300 static int arch_perfmon_init(struct oprofile_operations *ignore)
33301diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33302index 71e8a67..6a313bb 100644
33303--- a/arch/x86/oprofile/op_x86_model.h
33304+++ b/arch/x86/oprofile/op_x86_model.h
33305@@ -52,7 +52,7 @@ struct op_x86_model_spec {
33306 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33307 struct op_msrs const * const msrs);
33308 #endif
33309-};
33310+} __do_const;
33311
33312 struct op_counter_config;
33313
33314diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33315index 372e9b8..e775a6c 100644
33316--- a/arch/x86/pci/irq.c
33317+++ b/arch/x86/pci/irq.c
33318@@ -50,7 +50,7 @@ struct irq_router {
33319 struct irq_router_handler {
33320 u16 vendor;
33321 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33322-};
33323+} __do_const;
33324
33325 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33326 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33327@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33328 return 0;
33329 }
33330
33331-static __initdata struct irq_router_handler pirq_routers[] = {
33332+static __initconst const struct irq_router_handler pirq_routers[] = {
33333 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33334 { PCI_VENDOR_ID_AL, ali_router_probe },
33335 { PCI_VENDOR_ID_ITE, ite_router_probe },
33336@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33337 static void __init pirq_find_router(struct irq_router *r)
33338 {
33339 struct irq_routing_table *rt = pirq_table;
33340- struct irq_router_handler *h;
33341+ const struct irq_router_handler *h;
33342
33343 #ifdef CONFIG_PCI_BIOS
33344 if (!rt->signature) {
33345@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33346 return 0;
33347 }
33348
33349-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33350+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33351 {
33352 .callback = fix_broken_hp_bios_irq9,
33353 .ident = "HP Pavilion N5400 Series Laptop",
33354diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
33355index 903fded..94b0d88 100644
33356--- a/arch/x86/pci/mrst.c
33357+++ b/arch/x86/pci/mrst.c
33358@@ -241,7 +241,9 @@ int __init pci_mrst_init(void)
33359 pr_info("Intel MID platform detected, using MID PCI ops\n");
33360 pci_mmcfg_late_init();
33361 pcibios_enable_irq = mrst_pci_irq_enable;
33362- pci_root_ops = pci_mrst_ops;
33363+ pax_open_kernel();
33364+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
33365+ pax_close_kernel();
33366 pci_soc_mode = 1;
33367 /* Continue with standard init */
33368 return 1;
33369diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33370index c77b24a..c979855 100644
33371--- a/arch/x86/pci/pcbios.c
33372+++ b/arch/x86/pci/pcbios.c
33373@@ -79,7 +79,7 @@ union bios32 {
33374 static struct {
33375 unsigned long address;
33376 unsigned short segment;
33377-} bios32_indirect = { 0, __KERNEL_CS };
33378+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33379
33380 /*
33381 * Returns the entry point for the given service, NULL on error
33382@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33383 unsigned long length; /* %ecx */
33384 unsigned long entry; /* %edx */
33385 unsigned long flags;
33386+ struct desc_struct d, *gdt;
33387
33388 local_irq_save(flags);
33389- __asm__("lcall *(%%edi); cld"
33390+
33391+ gdt = get_cpu_gdt_table(smp_processor_id());
33392+
33393+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33394+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33395+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33396+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33397+
33398+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33399 : "=a" (return_code),
33400 "=b" (address),
33401 "=c" (length),
33402 "=d" (entry)
33403 : "0" (service),
33404 "1" (0),
33405- "D" (&bios32_indirect));
33406+ "D" (&bios32_indirect),
33407+ "r"(__PCIBIOS_DS)
33408+ : "memory");
33409+
33410+ pax_open_kernel();
33411+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33412+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33413+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33414+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33415+ pax_close_kernel();
33416+
33417 local_irq_restore(flags);
33418
33419 switch (return_code) {
33420- case 0:
33421- return address + entry;
33422- case 0x80: /* Not present */
33423- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33424- return 0;
33425- default: /* Shouldn't happen */
33426- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33427- service, return_code);
33428+ case 0: {
33429+ int cpu;
33430+ unsigned char flags;
33431+
33432+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33433+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33434+ printk(KERN_WARNING "bios32_service: not valid\n");
33435 return 0;
33436+ }
33437+ address = address + PAGE_OFFSET;
33438+ length += 16UL; /* some BIOSs underreport this... */
33439+ flags = 4;
33440+ if (length >= 64*1024*1024) {
33441+ length >>= PAGE_SHIFT;
33442+ flags |= 8;
33443+ }
33444+
33445+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33446+ gdt = get_cpu_gdt_table(cpu);
33447+ pack_descriptor(&d, address, length, 0x9b, flags);
33448+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33449+ pack_descriptor(&d, address, length, 0x93, flags);
33450+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33451+ }
33452+ return entry;
33453+ }
33454+ case 0x80: /* Not present */
33455+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33456+ return 0;
33457+ default: /* Shouldn't happen */
33458+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33459+ service, return_code);
33460+ return 0;
33461 }
33462 }
33463
33464 static struct {
33465 unsigned long address;
33466 unsigned short segment;
33467-} pci_indirect = { 0, __KERNEL_CS };
33468+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33469
33470-static int pci_bios_present;
33471+static int pci_bios_present __read_only;
33472
33473 static int check_pcibios(void)
33474 {
33475@@ -131,11 +174,13 @@ static int check_pcibios(void)
33476 unsigned long flags, pcibios_entry;
33477
33478 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33479- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33480+ pci_indirect.address = pcibios_entry;
33481
33482 local_irq_save(flags);
33483- __asm__(
33484- "lcall *(%%edi); cld\n\t"
33485+ __asm__("movw %w6, %%ds\n\t"
33486+ "lcall *%%ss:(%%edi); cld\n\t"
33487+ "push %%ss\n\t"
33488+ "pop %%ds\n\t"
33489 "jc 1f\n\t"
33490 "xor %%ah, %%ah\n"
33491 "1:"
33492@@ -144,7 +189,8 @@ static int check_pcibios(void)
33493 "=b" (ebx),
33494 "=c" (ecx)
33495 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33496- "D" (&pci_indirect)
33497+ "D" (&pci_indirect),
33498+ "r" (__PCIBIOS_DS)
33499 : "memory");
33500 local_irq_restore(flags);
33501
33502@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33503
33504 switch (len) {
33505 case 1:
33506- __asm__("lcall *(%%esi); cld\n\t"
33507+ __asm__("movw %w6, %%ds\n\t"
33508+ "lcall *%%ss:(%%esi); cld\n\t"
33509+ "push %%ss\n\t"
33510+ "pop %%ds\n\t"
33511 "jc 1f\n\t"
33512 "xor %%ah, %%ah\n"
33513 "1:"
33514@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33515 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33516 "b" (bx),
33517 "D" ((long)reg),
33518- "S" (&pci_indirect));
33519+ "S" (&pci_indirect),
33520+ "r" (__PCIBIOS_DS));
33521 /*
33522 * Zero-extend the result beyond 8 bits, do not trust the
33523 * BIOS having done it:
33524@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33525 *value &= 0xff;
33526 break;
33527 case 2:
33528- __asm__("lcall *(%%esi); cld\n\t"
33529+ __asm__("movw %w6, %%ds\n\t"
33530+ "lcall *%%ss:(%%esi); cld\n\t"
33531+ "push %%ss\n\t"
33532+ "pop %%ds\n\t"
33533 "jc 1f\n\t"
33534 "xor %%ah, %%ah\n"
33535 "1:"
33536@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33537 : "1" (PCIBIOS_READ_CONFIG_WORD),
33538 "b" (bx),
33539 "D" ((long)reg),
33540- "S" (&pci_indirect));
33541+ "S" (&pci_indirect),
33542+ "r" (__PCIBIOS_DS));
33543 /*
33544 * Zero-extend the result beyond 16 bits, do not trust the
33545 * BIOS having done it:
33546@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33547 *value &= 0xffff;
33548 break;
33549 case 4:
33550- __asm__("lcall *(%%esi); cld\n\t"
33551+ __asm__("movw %w6, %%ds\n\t"
33552+ "lcall *%%ss:(%%esi); cld\n\t"
33553+ "push %%ss\n\t"
33554+ "pop %%ds\n\t"
33555 "jc 1f\n\t"
33556 "xor %%ah, %%ah\n"
33557 "1:"
33558@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33559 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33560 "b" (bx),
33561 "D" ((long)reg),
33562- "S" (&pci_indirect));
33563+ "S" (&pci_indirect),
33564+ "r" (__PCIBIOS_DS));
33565 break;
33566 }
33567
33568@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33569
33570 switch (len) {
33571 case 1:
33572- __asm__("lcall *(%%esi); cld\n\t"
33573+ __asm__("movw %w6, %%ds\n\t"
33574+ "lcall *%%ss:(%%esi); cld\n\t"
33575+ "push %%ss\n\t"
33576+ "pop %%ds\n\t"
33577 "jc 1f\n\t"
33578 "xor %%ah, %%ah\n"
33579 "1:"
33580@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33581 "c" (value),
33582 "b" (bx),
33583 "D" ((long)reg),
33584- "S" (&pci_indirect));
33585+ "S" (&pci_indirect),
33586+ "r" (__PCIBIOS_DS));
33587 break;
33588 case 2:
33589- __asm__("lcall *(%%esi); cld\n\t"
33590+ __asm__("movw %w6, %%ds\n\t"
33591+ "lcall *%%ss:(%%esi); cld\n\t"
33592+ "push %%ss\n\t"
33593+ "pop %%ds\n\t"
33594 "jc 1f\n\t"
33595 "xor %%ah, %%ah\n"
33596 "1:"
33597@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33598 "c" (value),
33599 "b" (bx),
33600 "D" ((long)reg),
33601- "S" (&pci_indirect));
33602+ "S" (&pci_indirect),
33603+ "r" (__PCIBIOS_DS));
33604 break;
33605 case 4:
33606- __asm__("lcall *(%%esi); cld\n\t"
33607+ __asm__("movw %w6, %%ds\n\t"
33608+ "lcall *%%ss:(%%esi); cld\n\t"
33609+ "push %%ss\n\t"
33610+ "pop %%ds\n\t"
33611 "jc 1f\n\t"
33612 "xor %%ah, %%ah\n"
33613 "1:"
33614@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33615 "c" (value),
33616 "b" (bx),
33617 "D" ((long)reg),
33618- "S" (&pci_indirect));
33619+ "S" (&pci_indirect),
33620+ "r" (__PCIBIOS_DS));
33621 break;
33622 }
33623
33624@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33625
33626 DBG("PCI: Fetching IRQ routing table... ");
33627 __asm__("push %%es\n\t"
33628+ "movw %w8, %%ds\n\t"
33629 "push %%ds\n\t"
33630 "pop %%es\n\t"
33631- "lcall *(%%esi); cld\n\t"
33632+ "lcall *%%ss:(%%esi); cld\n\t"
33633 "pop %%es\n\t"
33634+ "push %%ss\n\t"
33635+ "pop %%ds\n"
33636 "jc 1f\n\t"
33637 "xor %%ah, %%ah\n"
33638 "1:"
33639@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33640 "1" (0),
33641 "D" ((long) &opt),
33642 "S" (&pci_indirect),
33643- "m" (opt)
33644+ "m" (opt),
33645+ "r" (__PCIBIOS_DS)
33646 : "memory");
33647 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33648 if (ret & 0xff00)
33649@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33650 {
33651 int ret;
33652
33653- __asm__("lcall *(%%esi); cld\n\t"
33654+ __asm__("movw %w5, %%ds\n\t"
33655+ "lcall *%%ss:(%%esi); cld\n\t"
33656+ "push %%ss\n\t"
33657+ "pop %%ds\n"
33658 "jc 1f\n\t"
33659 "xor %%ah, %%ah\n"
33660 "1:"
33661@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33662 : "0" (PCIBIOS_SET_PCI_HW_INT),
33663 "b" ((dev->bus->number << 8) | dev->devfn),
33664 "c" ((irq << 8) | (pin + 10)),
33665- "S" (&pci_indirect));
33666+ "S" (&pci_indirect),
33667+ "r" (__PCIBIOS_DS));
33668 return !(ret & 0xff00);
33669 }
33670 EXPORT_SYMBOL(pcibios_set_irq_routing);
33671diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33672index 40e4469..d915bf9 100644
33673--- a/arch/x86/platform/efi/efi_32.c
33674+++ b/arch/x86/platform/efi/efi_32.c
33675@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33676 {
33677 struct desc_ptr gdt_descr;
33678
33679+#ifdef CONFIG_PAX_KERNEXEC
33680+ struct desc_struct d;
33681+#endif
33682+
33683 local_irq_save(efi_rt_eflags);
33684
33685 load_cr3(initial_page_table);
33686 __flush_tlb_all();
33687
33688+#ifdef CONFIG_PAX_KERNEXEC
33689+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33690+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33691+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33692+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33693+#endif
33694+
33695 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33696 gdt_descr.size = GDT_SIZE - 1;
33697 load_gdt(&gdt_descr);
33698@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33699 {
33700 struct desc_ptr gdt_descr;
33701
33702+#ifdef CONFIG_PAX_KERNEXEC
33703+ struct desc_struct d;
33704+
33705+ memset(&d, 0, sizeof d);
33706+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33707+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33708+#endif
33709+
33710 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33711 gdt_descr.size = GDT_SIZE - 1;
33712 load_gdt(&gdt_descr);
33713
33714+#ifdef CONFIG_PAX_PER_CPU_PGD
33715+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33716+#else
33717 load_cr3(swapper_pg_dir);
33718+#endif
33719+
33720 __flush_tlb_all();
33721
33722 local_irq_restore(efi_rt_eflags);
33723diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33724index 39a0e7f1..872396e 100644
33725--- a/arch/x86/platform/efi/efi_64.c
33726+++ b/arch/x86/platform/efi/efi_64.c
33727@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33728 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33729 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33730 }
33731+
33732+#ifdef CONFIG_PAX_PER_CPU_PGD
33733+ load_cr3(swapper_pg_dir);
33734+#endif
33735+
33736 __flush_tlb_all();
33737 }
33738
33739@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33740 for (pgd = 0; pgd < n_pgds; pgd++)
33741 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33742 kfree(save_pgd);
33743+
33744+#ifdef CONFIG_PAX_PER_CPU_PGD
33745+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33746+#endif
33747+
33748 __flush_tlb_all();
33749 local_irq_restore(efi_flags);
33750 early_code_mapping_set_exec(0);
33751diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33752index fbe66e6..eae5e38 100644
33753--- a/arch/x86/platform/efi/efi_stub_32.S
33754+++ b/arch/x86/platform/efi/efi_stub_32.S
33755@@ -6,7 +6,9 @@
33756 */
33757
33758 #include <linux/linkage.h>
33759+#include <linux/init.h>
33760 #include <asm/page_types.h>
33761+#include <asm/segment.h>
33762
33763 /*
33764 * efi_call_phys(void *, ...) is a function with variable parameters.
33765@@ -20,7 +22,7 @@
33766 * service functions will comply with gcc calling convention, too.
33767 */
33768
33769-.text
33770+__INIT
33771 ENTRY(efi_call_phys)
33772 /*
33773 * 0. The function can only be called in Linux kernel. So CS has been
33774@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33775 * The mapping of lower virtual memory has been created in prelog and
33776 * epilog.
33777 */
33778- movl $1f, %edx
33779- subl $__PAGE_OFFSET, %edx
33780- jmp *%edx
33781+#ifdef CONFIG_PAX_KERNEXEC
33782+ movl $(__KERNEXEC_EFI_DS), %edx
33783+ mov %edx, %ds
33784+ mov %edx, %es
33785+ mov %edx, %ss
33786+ addl $2f,(1f)
33787+ ljmp *(1f)
33788+
33789+__INITDATA
33790+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33791+.previous
33792+
33793+2:
33794+ subl $2b,(1b)
33795+#else
33796+ jmp 1f-__PAGE_OFFSET
33797 1:
33798+#endif
33799
33800 /*
33801 * 2. Now on the top of stack is the return
33802@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33803 * parameter 2, ..., param n. To make things easy, we save the return
33804 * address of efi_call_phys in a global variable.
33805 */
33806- popl %edx
33807- movl %edx, saved_return_addr
33808- /* get the function pointer into ECX*/
33809- popl %ecx
33810- movl %ecx, efi_rt_function_ptr
33811- movl $2f, %edx
33812- subl $__PAGE_OFFSET, %edx
33813- pushl %edx
33814+ popl (saved_return_addr)
33815+ popl (efi_rt_function_ptr)
33816
33817 /*
33818 * 3. Clear PG bit in %CR0.
33819@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33820 /*
33821 * 5. Call the physical function.
33822 */
33823- jmp *%ecx
33824+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33825
33826-2:
33827 /*
33828 * 6. After EFI runtime service returns, control will return to
33829 * following instruction. We'd better readjust stack pointer first.
33830@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33831 movl %cr0, %edx
33832 orl $0x80000000, %edx
33833 movl %edx, %cr0
33834- jmp 1f
33835-1:
33836+
33837 /*
33838 * 8. Now restore the virtual mode from flat mode by
33839 * adding EIP with PAGE_OFFSET.
33840 */
33841- movl $1f, %edx
33842- jmp *%edx
33843+#ifdef CONFIG_PAX_KERNEXEC
33844+ movl $(__KERNEL_DS), %edx
33845+ mov %edx, %ds
33846+ mov %edx, %es
33847+ mov %edx, %ss
33848+ ljmp $(__KERNEL_CS),$1f
33849+#else
33850+ jmp 1f+__PAGE_OFFSET
33851+#endif
33852 1:
33853
33854 /*
33855 * 9. Balance the stack. And because EAX contain the return value,
33856 * we'd better not clobber it.
33857 */
33858- leal efi_rt_function_ptr, %edx
33859- movl (%edx), %ecx
33860- pushl %ecx
33861+ pushl (efi_rt_function_ptr)
33862
33863 /*
33864- * 10. Push the saved return address onto the stack and return.
33865+ * 10. Return to the saved return address.
33866 */
33867- leal saved_return_addr, %edx
33868- movl (%edx), %ecx
33869- pushl %ecx
33870- ret
33871+ jmpl *(saved_return_addr)
33872 ENDPROC(efi_call_phys)
33873 .previous
33874
33875-.data
33876+__INITDATA
33877 saved_return_addr:
33878 .long 0
33879 efi_rt_function_ptr:
33880diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33881index 4c07cca..2c8427d 100644
33882--- a/arch/x86/platform/efi/efi_stub_64.S
33883+++ b/arch/x86/platform/efi/efi_stub_64.S
33884@@ -7,6 +7,7 @@
33885 */
33886
33887 #include <linux/linkage.h>
33888+#include <asm/alternative-asm.h>
33889
33890 #define SAVE_XMM \
33891 mov %rsp, %rax; \
33892@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33893 call *%rdi
33894 addq $32, %rsp
33895 RESTORE_XMM
33896+ pax_force_retaddr 0, 1
33897 ret
33898 ENDPROC(efi_call0)
33899
33900@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33901 call *%rdi
33902 addq $32, %rsp
33903 RESTORE_XMM
33904+ pax_force_retaddr 0, 1
33905 ret
33906 ENDPROC(efi_call1)
33907
33908@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33909 call *%rdi
33910 addq $32, %rsp
33911 RESTORE_XMM
33912+ pax_force_retaddr 0, 1
33913 ret
33914 ENDPROC(efi_call2)
33915
33916@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33917 call *%rdi
33918 addq $32, %rsp
33919 RESTORE_XMM
33920+ pax_force_retaddr 0, 1
33921 ret
33922 ENDPROC(efi_call3)
33923
33924@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33925 call *%rdi
33926 addq $32, %rsp
33927 RESTORE_XMM
33928+ pax_force_retaddr 0, 1
33929 ret
33930 ENDPROC(efi_call4)
33931
33932@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33933 call *%rdi
33934 addq $48, %rsp
33935 RESTORE_XMM
33936+ pax_force_retaddr 0, 1
33937 ret
33938 ENDPROC(efi_call5)
33939
33940@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33941 call *%rdi
33942 addq $48, %rsp
33943 RESTORE_XMM
33944+ pax_force_retaddr 0, 1
33945 ret
33946 ENDPROC(efi_call6)
33947diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33948index 3ca5957..7909c18 100644
33949--- a/arch/x86/platform/mrst/mrst.c
33950+++ b/arch/x86/platform/mrst/mrst.c
33951@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33952 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33953 int sfi_mrtc_num;
33954
33955-static void mrst_power_off(void)
33956+static __noreturn void mrst_power_off(void)
33957 {
33958+ BUG();
33959 }
33960
33961-static void mrst_reboot(void)
33962+static __noreturn void mrst_reboot(void)
33963 {
33964 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33965+ BUG();
33966 }
33967
33968 /* parse all the mtimer info to a static mtimer array */
33969diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33970index d6ee929..3637cb5 100644
33971--- a/arch/x86/platform/olpc/olpc_dt.c
33972+++ b/arch/x86/platform/olpc/olpc_dt.c
33973@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33974 return res;
33975 }
33976
33977-static struct of_pdt_ops prom_olpc_ops __initdata = {
33978+static struct of_pdt_ops prom_olpc_ops __initconst = {
33979 .nextprop = olpc_dt_nextprop,
33980 .getproplen = olpc_dt_getproplen,
33981 .getproperty = olpc_dt_getproperty,
33982diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33983index 424f4c9..f2a2988 100644
33984--- a/arch/x86/power/cpu.c
33985+++ b/arch/x86/power/cpu.c
33986@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33987 static void fix_processor_context(void)
33988 {
33989 int cpu = smp_processor_id();
33990- struct tss_struct *t = &per_cpu(init_tss, cpu);
33991-#ifdef CONFIG_X86_64
33992- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33993- tss_desc tss;
33994-#endif
33995+ struct tss_struct *t = init_tss + cpu;
33996+
33997 set_tss_desc(cpu, t); /*
33998 * This just modifies memory; should not be
33999 * necessary. But... This is necessary, because
34000@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34001 */
34002
34003 #ifdef CONFIG_X86_64
34004- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34005- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34006- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34007-
34008 syscall_init(); /* This sets MSR_*STAR and related */
34009 #endif
34010 load_TR_desc(); /* This does ltr */
34011diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34012index a44f457..9140171 100644
34013--- a/arch/x86/realmode/init.c
34014+++ b/arch/x86/realmode/init.c
34015@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34016 __va(real_mode_header->trampoline_header);
34017
34018 #ifdef CONFIG_X86_32
34019- trampoline_header->start = __pa_symbol(startup_32_smp);
34020+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34021+
34022+#ifdef CONFIG_PAX_KERNEXEC
34023+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34024+#endif
34025+
34026+ trampoline_header->boot_cs = __BOOT_CS;
34027 trampoline_header->gdt_limit = __BOOT_DS + 7;
34028 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34029 #else
34030@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34031 *trampoline_cr4_features = read_cr4();
34032
34033 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34034- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34035+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34036 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34037 #endif
34038 }
34039diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34040index 9cac825..4890b25 100644
34041--- a/arch/x86/realmode/rm/Makefile
34042+++ b/arch/x86/realmode/rm/Makefile
34043@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34044 $(call cc-option, -fno-unit-at-a-time)) \
34045 $(call cc-option, -fno-stack-protector) \
34046 $(call cc-option, -mpreferred-stack-boundary=2)
34047+ifdef CONSTIFY_PLUGIN
34048+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34049+endif
34050 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34051 GCOV_PROFILE := n
34052diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34053index a28221d..93c40f1 100644
34054--- a/arch/x86/realmode/rm/header.S
34055+++ b/arch/x86/realmode/rm/header.S
34056@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34057 #endif
34058 /* APM/BIOS reboot */
34059 .long pa_machine_real_restart_asm
34060-#ifdef CONFIG_X86_64
34061+#ifdef CONFIG_X86_32
34062+ .long __KERNEL_CS
34063+#else
34064 .long __KERNEL32_CS
34065 #endif
34066 END(real_mode_header)
34067diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34068index c1b2791..f9e31c7 100644
34069--- a/arch/x86/realmode/rm/trampoline_32.S
34070+++ b/arch/x86/realmode/rm/trampoline_32.S
34071@@ -25,6 +25,12 @@
34072 #include <asm/page_types.h>
34073 #include "realmode.h"
34074
34075+#ifdef CONFIG_PAX_KERNEXEC
34076+#define ta(X) (X)
34077+#else
34078+#define ta(X) (pa_ ## X)
34079+#endif
34080+
34081 .text
34082 .code16
34083
34084@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34085
34086 cli # We should be safe anyway
34087
34088- movl tr_start, %eax # where we need to go
34089-
34090 movl $0xA5A5A5A5, trampoline_status
34091 # write marker for master knows we're running
34092
34093@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34094 movw $1, %dx # protected mode (PE) bit
34095 lmsw %dx # into protected mode
34096
34097- ljmpl $__BOOT_CS, $pa_startup_32
34098+ ljmpl *(trampoline_header)
34099
34100 .section ".text32","ax"
34101 .code32
34102@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34103 .balign 8
34104 GLOBAL(trampoline_header)
34105 tr_start: .space 4
34106- tr_gdt_pad: .space 2
34107+ tr_boot_cs: .space 2
34108 tr_gdt: .space 6
34109 END(trampoline_header)
34110
34111diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34112index bb360dc..d0fd8f8 100644
34113--- a/arch/x86/realmode/rm/trampoline_64.S
34114+++ b/arch/x86/realmode/rm/trampoline_64.S
34115@@ -94,6 +94,7 @@ ENTRY(startup_32)
34116 movl %edx, %gs
34117
34118 movl pa_tr_cr4, %eax
34119+ andl $~X86_CR4_PCIDE, %eax
34120 movl %eax, %cr4 # Enable PAE mode
34121
34122 # Setup trampoline 4 level pagetables
34123@@ -107,7 +108,7 @@ ENTRY(startup_32)
34124 wrmsr
34125
34126 # Enable paging and in turn activate Long Mode
34127- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34128+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34129 movl %eax, %cr0
34130
34131 /*
34132diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34133index e812034..c747134 100644
34134--- a/arch/x86/tools/Makefile
34135+++ b/arch/x86/tools/Makefile
34136@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34137
34138 $(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
34139
34140-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34141+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34142 hostprogs-y += relocs
34143 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34144 relocs: $(obj)/relocs
34145diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34146index f7bab68..b6d9886 100644
34147--- a/arch/x86/tools/relocs.c
34148+++ b/arch/x86/tools/relocs.c
34149@@ -1,5 +1,7 @@
34150 /* This is included from relocs_32/64.c */
34151
34152+#include "../../../include/generated/autoconf.h"
34153+
34154 #define ElfW(type) _ElfW(ELF_BITS, type)
34155 #define _ElfW(bits, type) __ElfW(bits, type)
34156 #define __ElfW(bits, type) Elf##bits##_##type
34157@@ -11,6 +13,7 @@
34158 #define Elf_Sym ElfW(Sym)
34159
34160 static Elf_Ehdr ehdr;
34161+static Elf_Phdr *phdr;
34162
34163 struct relocs {
34164 uint32_t *offset;
34165@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34166 }
34167 }
34168
34169+static void read_phdrs(FILE *fp)
34170+{
34171+ unsigned int i;
34172+
34173+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34174+ if (!phdr) {
34175+ die("Unable to allocate %d program headers\n",
34176+ ehdr.e_phnum);
34177+ }
34178+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34179+ die("Seek to %d failed: %s\n",
34180+ ehdr.e_phoff, strerror(errno));
34181+ }
34182+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34183+ die("Cannot read ELF program headers: %s\n",
34184+ strerror(errno));
34185+ }
34186+ for(i = 0; i < ehdr.e_phnum; i++) {
34187+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34188+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34189+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34190+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34191+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34192+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34193+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34194+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34195+ }
34196+
34197+}
34198+
34199 static void read_shdrs(FILE *fp)
34200 {
34201- int i;
34202+ unsigned int i;
34203 Elf_Shdr shdr;
34204
34205 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34206@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34207
34208 static void read_strtabs(FILE *fp)
34209 {
34210- int i;
34211+ unsigned int i;
34212 for (i = 0; i < ehdr.e_shnum; i++) {
34213 struct section *sec = &secs[i];
34214 if (sec->shdr.sh_type != SHT_STRTAB) {
34215@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34216
34217 static void read_symtabs(FILE *fp)
34218 {
34219- int i,j;
34220+ unsigned int i,j;
34221 for (i = 0; i < ehdr.e_shnum; i++) {
34222 struct section *sec = &secs[i];
34223 if (sec->shdr.sh_type != SHT_SYMTAB) {
34224@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34225 }
34226
34227
34228-static void read_relocs(FILE *fp)
34229+static void read_relocs(FILE *fp, int use_real_mode)
34230 {
34231- int i,j;
34232+ unsigned int i,j;
34233+ uint32_t base;
34234+
34235 for (i = 0; i < ehdr.e_shnum; i++) {
34236 struct section *sec = &secs[i];
34237 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34238@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34239 die("Cannot read symbol table: %s\n",
34240 strerror(errno));
34241 }
34242+ base = 0;
34243+
34244+#ifdef CONFIG_X86_32
34245+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34246+ if (phdr[j].p_type != PT_LOAD )
34247+ continue;
34248+ 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)
34249+ continue;
34250+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34251+ break;
34252+ }
34253+#endif
34254+
34255 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34256 Elf_Rel *rel = &sec->reltab[j];
34257- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34258+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34259 rel->r_info = elf_xword_to_cpu(rel->r_info);
34260 #if (SHT_REL_TYPE == SHT_RELA)
34261 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34262@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34263
34264 static void print_absolute_symbols(void)
34265 {
34266- int i;
34267+ unsigned int i;
34268 const char *format;
34269
34270 if (ELF_BITS == 64)
34271@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34272 for (i = 0; i < ehdr.e_shnum; i++) {
34273 struct section *sec = &secs[i];
34274 char *sym_strtab;
34275- int j;
34276+ unsigned int j;
34277
34278 if (sec->shdr.sh_type != SHT_SYMTAB) {
34279 continue;
34280@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34281
34282 static void print_absolute_relocs(void)
34283 {
34284- int i, printed = 0;
34285+ unsigned int i, printed = 0;
34286 const char *format;
34287
34288 if (ELF_BITS == 64)
34289@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34290 struct section *sec_applies, *sec_symtab;
34291 char *sym_strtab;
34292 Elf_Sym *sh_symtab;
34293- int j;
34294+ unsigned int j;
34295 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34296 continue;
34297 }
34298@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34299 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34300 Elf_Sym *sym, const char *symname))
34301 {
34302- int i;
34303+ unsigned int i;
34304 /* Walk through the relocations */
34305 for (i = 0; i < ehdr.e_shnum; i++) {
34306 char *sym_strtab;
34307 Elf_Sym *sh_symtab;
34308 struct section *sec_applies, *sec_symtab;
34309- int j;
34310+ unsigned int j;
34311 struct section *sec = &secs[i];
34312
34313 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34314@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34315 {
34316 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34317 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34318+ char *sym_strtab = sec->link->link->strtab;
34319+
34320+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34321+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34322+ return 0;
34323+
34324+#ifdef CONFIG_PAX_KERNEXEC
34325+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34326+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34327+ return 0;
34328+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34329+ return 0;
34330+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34331+ return 0;
34332+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34333+ return 0;
34334+#endif
34335
34336 switch (r_type) {
34337 case R_386_NONE:
34338@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34339
34340 static void emit_relocs(int as_text, int use_real_mode)
34341 {
34342- int i;
34343+ unsigned int i;
34344 int (*write_reloc)(uint32_t, FILE *) = write32;
34345 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34346 const char *symname);
34347@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34348 {
34349 regex_init(use_real_mode);
34350 read_ehdr(fp);
34351+ read_phdrs(fp);
34352 read_shdrs(fp);
34353 read_strtabs(fp);
34354 read_symtabs(fp);
34355- read_relocs(fp);
34356+ read_relocs(fp, use_real_mode);
34357 if (ELF_BITS == 64)
34358 percpu_init();
34359 if (show_absolute_syms) {
34360diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34361index 80ffa5b..a33bd15 100644
34362--- a/arch/x86/um/tls_32.c
34363+++ b/arch/x86/um/tls_32.c
34364@@ -260,7 +260,7 @@ out:
34365 if (unlikely(task == current &&
34366 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34367 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34368- "without flushed TLS.", current->pid);
34369+ "without flushed TLS.", task_pid_nr(current));
34370 }
34371
34372 return 0;
34373diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34374index fd14be1..e3c79c0 100644
34375--- a/arch/x86/vdso/Makefile
34376+++ b/arch/x86/vdso/Makefile
34377@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34378 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34379 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34380
34381-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34382+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34383 GCOV_PROFILE := n
34384
34385 #
34386diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34387index d6bfb87..876ee18 100644
34388--- a/arch/x86/vdso/vdso32-setup.c
34389+++ b/arch/x86/vdso/vdso32-setup.c
34390@@ -25,6 +25,7 @@
34391 #include <asm/tlbflush.h>
34392 #include <asm/vdso.h>
34393 #include <asm/proto.h>
34394+#include <asm/mman.h>
34395
34396 enum {
34397 VDSO_DISABLED = 0,
34398@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34399 void enable_sep_cpu(void)
34400 {
34401 int cpu = get_cpu();
34402- struct tss_struct *tss = &per_cpu(init_tss, cpu);
34403+ struct tss_struct *tss = init_tss + cpu;
34404
34405 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34406 put_cpu();
34407@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34408 gate_vma.vm_start = FIXADDR_USER_START;
34409 gate_vma.vm_end = FIXADDR_USER_END;
34410 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34411- gate_vma.vm_page_prot = __P101;
34412+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34413
34414 return 0;
34415 }
34416@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34417 if (compat)
34418 addr = VDSO_HIGH_BASE;
34419 else {
34420- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34421+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34422 if (IS_ERR_VALUE(addr)) {
34423 ret = addr;
34424 goto up_fail;
34425 }
34426 }
34427
34428- current->mm->context.vdso = (void *)addr;
34429+ current->mm->context.vdso = addr;
34430
34431 if (compat_uses_vma || !compat) {
34432 /*
34433@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34434 }
34435
34436 current_thread_info()->sysenter_return =
34437- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34438+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34439
34440 up_fail:
34441 if (ret)
34442- current->mm->context.vdso = NULL;
34443+ current->mm->context.vdso = 0;
34444
34445 up_write(&mm->mmap_sem);
34446
34447@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34448
34449 const char *arch_vma_name(struct vm_area_struct *vma)
34450 {
34451- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34452+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34453 return "[vdso]";
34454+
34455+#ifdef CONFIG_PAX_SEGMEXEC
34456+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34457+ return "[vdso]";
34458+#endif
34459+
34460 return NULL;
34461 }
34462
34463@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34464 * Check to see if the corresponding task was created in compat vdso
34465 * mode.
34466 */
34467- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34468+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34469 return &gate_vma;
34470 return NULL;
34471 }
34472diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34473index 431e875..cbb23f3 100644
34474--- a/arch/x86/vdso/vma.c
34475+++ b/arch/x86/vdso/vma.c
34476@@ -16,8 +16,6 @@
34477 #include <asm/vdso.h>
34478 #include <asm/page.h>
34479
34480-unsigned int __read_mostly vdso_enabled = 1;
34481-
34482 extern char vdso_start[], vdso_end[];
34483 extern unsigned short vdso_sync_cpuid;
34484
34485@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34486 * unaligned here as a result of stack start randomization.
34487 */
34488 addr = PAGE_ALIGN(addr);
34489- addr = align_vdso_addr(addr);
34490
34491 return addr;
34492 }
34493@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34494 unsigned size)
34495 {
34496 struct mm_struct *mm = current->mm;
34497- unsigned long addr;
34498+ unsigned long addr = 0;
34499 int ret;
34500
34501- if (!vdso_enabled)
34502- return 0;
34503-
34504 down_write(&mm->mmap_sem);
34505+
34506+#ifdef CONFIG_PAX_RANDMMAP
34507+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34508+#endif
34509+
34510 addr = vdso_addr(mm->start_stack, size);
34511+ addr = align_vdso_addr(addr);
34512 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34513 if (IS_ERR_VALUE(addr)) {
34514 ret = addr;
34515 goto up_fail;
34516 }
34517
34518- current->mm->context.vdso = (void *)addr;
34519+ mm->context.vdso = addr;
34520
34521 ret = install_special_mapping(mm, addr, size,
34522 VM_READ|VM_EXEC|
34523 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34524 pages);
34525- if (ret) {
34526- current->mm->context.vdso = NULL;
34527- goto up_fail;
34528- }
34529+ if (ret)
34530+ mm->context.vdso = 0;
34531
34532 up_fail:
34533 up_write(&mm->mmap_sem);
34534@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34535 vdsox32_size);
34536 }
34537 #endif
34538-
34539-static __init int vdso_setup(char *s)
34540-{
34541- vdso_enabled = simple_strtoul(s, NULL, 0);
34542- return 0;
34543-}
34544-__setup("vdso=", vdso_setup);
34545diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34546index fa6ade7..73da73a5 100644
34547--- a/arch/x86/xen/enlighten.c
34548+++ b/arch/x86/xen/enlighten.c
34549@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34550
34551 struct shared_info xen_dummy_shared_info;
34552
34553-void *xen_initial_gdt;
34554-
34555 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34556 __read_mostly int xen_have_vector_callback;
34557 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34558@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34559 {
34560 unsigned long va = dtr->address;
34561 unsigned int size = dtr->size + 1;
34562- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34563- unsigned long frames[pages];
34564+ unsigned long frames[65536 / PAGE_SIZE];
34565 int f;
34566
34567 /*
34568@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34569 {
34570 unsigned long va = dtr->address;
34571 unsigned int size = dtr->size + 1;
34572- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34573- unsigned long frames[pages];
34574+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34575 int f;
34576
34577 /*
34578@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34579 * 8-byte entries, or 16 4k pages..
34580 */
34581
34582- BUG_ON(size > 65536);
34583+ BUG_ON(size > GDT_SIZE);
34584 BUG_ON(va & ~PAGE_MASK);
34585
34586 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34587@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34588 return 0;
34589 }
34590
34591-static void set_xen_basic_apic_ops(void)
34592+static void __init set_xen_basic_apic_ops(void)
34593 {
34594 apic->read = xen_apic_read;
34595 apic->write = xen_apic_write;
34596@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34597 #endif
34598 };
34599
34600-static void xen_reboot(int reason)
34601+static __noreturn void xen_reboot(int reason)
34602 {
34603 struct sched_shutdown r = { .reason = reason };
34604
34605- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34606- BUG();
34607+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34608+ BUG();
34609 }
34610
34611-static void xen_restart(char *msg)
34612+static __noreturn void xen_restart(char *msg)
34613 {
34614 xen_reboot(SHUTDOWN_reboot);
34615 }
34616
34617-static void xen_emergency_restart(void)
34618+static __noreturn void xen_emergency_restart(void)
34619 {
34620 xen_reboot(SHUTDOWN_reboot);
34621 }
34622
34623-static void xen_machine_halt(void)
34624+static __noreturn void xen_machine_halt(void)
34625 {
34626 xen_reboot(SHUTDOWN_poweroff);
34627 }
34628
34629-static void xen_machine_power_off(void)
34630+static __noreturn void xen_machine_power_off(void)
34631 {
34632 if (pm_power_off)
34633 pm_power_off();
34634@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34635 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34636
34637 /* Work out if we support NX */
34638- x86_configure_nx();
34639+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34640+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34641+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34642+ unsigned l, h;
34643+
34644+ __supported_pte_mask |= _PAGE_NX;
34645+ rdmsr(MSR_EFER, l, h);
34646+ l |= EFER_NX;
34647+ wrmsr(MSR_EFER, l, h);
34648+ }
34649+#endif
34650
34651 xen_setup_features();
34652
34653@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34654
34655 machine_ops = xen_machine_ops;
34656
34657- /*
34658- * The only reliable way to retain the initial address of the
34659- * percpu gdt_page is to remember it here, so we can go and
34660- * mark it RW later, when the initial percpu area is freed.
34661- */
34662- xen_initial_gdt = &per_cpu(gdt_page, 0);
34663-
34664 xen_smp_init();
34665
34666 #ifdef CONFIG_ACPI_NUMA
34667diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34668index fdc3ba2..23cae00 100644
34669--- a/arch/x86/xen/mmu.c
34670+++ b/arch/x86/xen/mmu.c
34671@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34672 return val;
34673 }
34674
34675-static pteval_t pte_pfn_to_mfn(pteval_t val)
34676+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34677 {
34678 if (val & _PAGE_PRESENT) {
34679 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34680@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34681 /* L3_k[510] -> level2_kernel_pgt
34682 * L3_i[511] -> level2_fixmap_pgt */
34683 convert_pfn_mfn(level3_kernel_pgt);
34684+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34685+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34686+ convert_pfn_mfn(level3_vmemmap_pgt);
34687
34688 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34689 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34690@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34691 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34692 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34693 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34694+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34695+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34696+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34697 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34698 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34699+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34700 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34701 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34702
34703@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34704 pv_mmu_ops.set_pud = xen_set_pud;
34705 #if PAGETABLE_LEVELS == 4
34706 pv_mmu_ops.set_pgd = xen_set_pgd;
34707+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34708 #endif
34709
34710 /* This will work as long as patching hasn't happened yet
34711@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34712 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34713 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34714 .set_pgd = xen_set_pgd_hyper,
34715+ .set_pgd_batched = xen_set_pgd_hyper,
34716
34717 .alloc_pud = xen_alloc_pmd_init,
34718 .release_pud = xen_release_pmd_init,
34719diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34720index 31d0475..51af671 100644
34721--- a/arch/x86/xen/smp.c
34722+++ b/arch/x86/xen/smp.c
34723@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34724 native_smp_prepare_boot_cpu();
34725
34726 if (xen_pv_domain()) {
34727- /* We've switched to the "real" per-cpu gdt, so make sure the
34728- old memory can be recycled */
34729- make_lowmem_page_readwrite(xen_initial_gdt);
34730-
34731 #ifdef CONFIG_X86_32
34732 /*
34733 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34734 * expects __USER_DS
34735 */
34736- loadsegment(ds, __USER_DS);
34737- loadsegment(es, __USER_DS);
34738+ loadsegment(ds, __KERNEL_DS);
34739+ loadsegment(es, __KERNEL_DS);
34740 #endif
34741
34742 xen_filter_cpu_maps();
34743@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34744 ctxt->user_regs.ss = __KERNEL_DS;
34745 #ifdef CONFIG_X86_32
34746 ctxt->user_regs.fs = __KERNEL_PERCPU;
34747- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34748+ savesegment(gs, ctxt->user_regs.gs);
34749 #else
34750 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34751 #endif
34752@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34753
34754 {
34755 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34756- ctxt->user_regs.ds = __USER_DS;
34757- ctxt->user_regs.es = __USER_DS;
34758+ ctxt->user_regs.ds = __KERNEL_DS;
34759+ ctxt->user_regs.es = __KERNEL_DS;
34760
34761 xen_copy_trap_info(ctxt->trap_ctxt);
34762
34763@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34764 int rc;
34765
34766 per_cpu(current_task, cpu) = idle;
34767+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34768 #ifdef CONFIG_X86_32
34769 irq_ctx_init(cpu);
34770 #else
34771 clear_tsk_thread_flag(idle, TIF_FORK);
34772- per_cpu(kernel_stack, cpu) =
34773- (unsigned long)task_stack_page(idle) -
34774- KERNEL_STACK_OFFSET + THREAD_SIZE;
34775+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34776 #endif
34777 xen_setup_runstate_info(cpu);
34778 xen_setup_timer(cpu);
34779@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34780
34781 void __init xen_smp_init(void)
34782 {
34783- smp_ops = xen_smp_ops;
34784+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34785 xen_fill_possible_map();
34786 }
34787
34788diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34789index 33ca6e4..0ded929 100644
34790--- a/arch/x86/xen/xen-asm_32.S
34791+++ b/arch/x86/xen/xen-asm_32.S
34792@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34793 ESP_OFFSET=4 # bytes pushed onto stack
34794
34795 /*
34796- * Store vcpu_info pointer for easy access. Do it this way to
34797- * avoid having to reload %fs
34798+ * Store vcpu_info pointer for easy access.
34799 */
34800 #ifdef CONFIG_SMP
34801- GET_THREAD_INFO(%eax)
34802- movl %ss:TI_cpu(%eax), %eax
34803- movl %ss:__per_cpu_offset(,%eax,4), %eax
34804- mov %ss:xen_vcpu(%eax), %eax
34805+ push %fs
34806+ mov $(__KERNEL_PERCPU), %eax
34807+ mov %eax, %fs
34808+ mov PER_CPU_VAR(xen_vcpu), %eax
34809+ pop %fs
34810 #else
34811 movl %ss:xen_vcpu, %eax
34812 #endif
34813diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34814index 7faed58..ba4427c 100644
34815--- a/arch/x86/xen/xen-head.S
34816+++ b/arch/x86/xen/xen-head.S
34817@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34818 #ifdef CONFIG_X86_32
34819 mov %esi,xen_start_info
34820 mov $init_thread_union+THREAD_SIZE,%esp
34821+#ifdef CONFIG_SMP
34822+ movl $cpu_gdt_table,%edi
34823+ movl $__per_cpu_load,%eax
34824+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34825+ rorl $16,%eax
34826+ movb %al,__KERNEL_PERCPU + 4(%edi)
34827+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34828+ movl $__per_cpu_end - 1,%eax
34829+ subl $__per_cpu_start,%eax
34830+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34831+#endif
34832 #else
34833 mov %rsi,xen_start_info
34834 mov $init_thread_union+THREAD_SIZE,%rsp
34835diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34836index 95f8c61..611d6e8 100644
34837--- a/arch/x86/xen/xen-ops.h
34838+++ b/arch/x86/xen/xen-ops.h
34839@@ -10,8 +10,6 @@
34840 extern const char xen_hypervisor_callback[];
34841 extern const char xen_failsafe_callback[];
34842
34843-extern void *xen_initial_gdt;
34844-
34845 struct trap_info;
34846 void xen_copy_trap_info(struct trap_info *traps);
34847
34848diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34849index 525bd3d..ef888b1 100644
34850--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34851+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34852@@ -119,9 +119,9 @@
34853 ----------------------------------------------------------------------*/
34854
34855 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34856-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34857 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34858 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34859+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34860
34861 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34862 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34863diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34864index 2f33760..835e50a 100644
34865--- a/arch/xtensa/variants/fsf/include/variant/core.h
34866+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34867@@ -11,6 +11,7 @@
34868 #ifndef _XTENSA_CORE_H
34869 #define _XTENSA_CORE_H
34870
34871+#include <linux/const.h>
34872
34873 /****************************************************************************
34874 Parameters Useful for Any Code, USER or PRIVILEGED
34875@@ -112,9 +113,9 @@
34876 ----------------------------------------------------------------------*/
34877
34878 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34879-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34880 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34881 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34882+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34883
34884 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34885 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34886diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34887index af00795..2bb8105 100644
34888--- a/arch/xtensa/variants/s6000/include/variant/core.h
34889+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34890@@ -11,6 +11,7 @@
34891 #ifndef _XTENSA_CORE_CONFIGURATION_H
34892 #define _XTENSA_CORE_CONFIGURATION_H
34893
34894+#include <linux/const.h>
34895
34896 /****************************************************************************
34897 Parameters Useful for Any Code, USER or PRIVILEGED
34898@@ -118,9 +119,9 @@
34899 ----------------------------------------------------------------------*/
34900
34901 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34902-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34903 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34904 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34905+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34906
34907 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34908 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34909diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34910index 4e491d9..c8e18e4 100644
34911--- a/block/blk-cgroup.c
34912+++ b/block/blk-cgroup.c
34913@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
34914 static struct cgroup_subsys_state *
34915 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
34916 {
34917- static atomic64_t id_seq = ATOMIC64_INIT(0);
34918+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34919 struct blkcg *blkcg;
34920
34921 if (!parent_css) {
34922@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
34923
34924 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34925 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34926- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34927+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34928 done:
34929 spin_lock_init(&blkcg->lock);
34930 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34931diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34932index 4b8d9b54..a7178c0 100644
34933--- a/block/blk-iopoll.c
34934+++ b/block/blk-iopoll.c
34935@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34936 }
34937 EXPORT_SYMBOL(blk_iopoll_complete);
34938
34939-static void blk_iopoll_softirq(struct softirq_action *h)
34940+static __latent_entropy void blk_iopoll_softirq(void)
34941 {
34942 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34943 int rearm = 0, budget = blk_iopoll_budget;
34944diff --git a/block/blk-map.c b/block/blk-map.c
34945index 623e1cd..ca1e109 100644
34946--- a/block/blk-map.c
34947+++ b/block/blk-map.c
34948@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34949 if (!len || !kbuf)
34950 return -EINVAL;
34951
34952- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34953+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34954 if (do_copy)
34955 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34956 else
34957diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34958index ec9e606..3f38839 100644
34959--- a/block/blk-softirq.c
34960+++ b/block/blk-softirq.c
34961@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34962 * Softirq action handler - move entries to local list and loop over them
34963 * while passing them to the queue registered handler.
34964 */
34965-static void blk_done_softirq(struct softirq_action *h)
34966+static __latent_entropy void blk_done_softirq(void)
34967 {
34968 struct list_head *cpu_list, local_list;
34969
34970diff --git a/block/bsg.c b/block/bsg.c
34971index 420a5a9..23834aa 100644
34972--- a/block/bsg.c
34973+++ b/block/bsg.c
34974@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34975 struct sg_io_v4 *hdr, struct bsg_device *bd,
34976 fmode_t has_write_perm)
34977 {
34978+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34979+ unsigned char *cmdptr;
34980+
34981 if (hdr->request_len > BLK_MAX_CDB) {
34982 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34983 if (!rq->cmd)
34984 return -ENOMEM;
34985- }
34986+ cmdptr = rq->cmd;
34987+ } else
34988+ cmdptr = tmpcmd;
34989
34990- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34991+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34992 hdr->request_len))
34993 return -EFAULT;
34994
34995+ if (cmdptr != rq->cmd)
34996+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34997+
34998 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34999 if (blk_verify_command(rq->cmd, has_write_perm))
35000 return -EPERM;
35001diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35002index fbd5a67..5d631b5 100644
35003--- a/block/compat_ioctl.c
35004+++ b/block/compat_ioctl.c
35005@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35006 err |= __get_user(f->spec1, &uf->spec1);
35007 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35008 err |= __get_user(name, &uf->name);
35009- f->name = compat_ptr(name);
35010+ f->name = (void __force_kernel *)compat_ptr(name);
35011 if (err) {
35012 err = -EFAULT;
35013 goto out;
35014diff --git a/block/genhd.c b/block/genhd.c
35015index 791f419..89f21c4 100644
35016--- a/block/genhd.c
35017+++ b/block/genhd.c
35018@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35019
35020 /*
35021 * Register device numbers dev..(dev+range-1)
35022- * range must be nonzero
35023+ * Noop if @range is zero.
35024 * The hash chain is sorted on range, so that subranges can override.
35025 */
35026 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35027 struct kobject *(*probe)(dev_t, int *, void *),
35028 int (*lock)(dev_t, void *), void *data)
35029 {
35030- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35031+ if (range)
35032+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35033 }
35034
35035 EXPORT_SYMBOL(blk_register_region);
35036
35037+/* undo blk_register_region(), noop if @range is zero */
35038 void blk_unregister_region(dev_t devt, unsigned long range)
35039 {
35040- kobj_unmap(bdev_map, devt, range);
35041+ if (range)
35042+ kobj_unmap(bdev_map, devt, range);
35043 }
35044
35045 EXPORT_SYMBOL(blk_unregister_region);
35046diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35047index a8287b4..241a48e 100644
35048--- a/block/partitions/efi.c
35049+++ b/block/partitions/efi.c
35050@@ -292,14 +292,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35051 if (!gpt)
35052 return NULL;
35053
35054+ if (!le32_to_cpu(gpt->num_partition_entries))
35055+ return NULL;
35056+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35057+ if (!pte)
35058+ return NULL;
35059+
35060 count = le32_to_cpu(gpt->num_partition_entries) *
35061 le32_to_cpu(gpt->sizeof_partition_entry);
35062- if (!count)
35063- return NULL;
35064- pte = kmalloc(count, GFP_KERNEL);
35065- if (!pte)
35066- return NULL;
35067-
35068 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35069 (u8 *) pte, count) < count) {
35070 kfree(pte);
35071diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35072index a5ffcc9..e057498 100644
35073--- a/block/scsi_ioctl.c
35074+++ b/block/scsi_ioctl.c
35075@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35076 return put_user(0, p);
35077 }
35078
35079-static int sg_get_timeout(struct request_queue *q)
35080+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35081 {
35082 return jiffies_to_clock_t(q->sg_timeout);
35083 }
35084@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35085 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35086 struct sg_io_hdr *hdr, fmode_t mode)
35087 {
35088- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35089+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35090+ unsigned char *cmdptr;
35091+
35092+ if (rq->cmd != rq->__cmd)
35093+ cmdptr = rq->cmd;
35094+ else
35095+ cmdptr = tmpcmd;
35096+
35097+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35098 return -EFAULT;
35099+
35100+ if (cmdptr != rq->cmd)
35101+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35102+
35103 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35104 return -EPERM;
35105
35106@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35107 int err;
35108 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35109 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35110+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35111+ unsigned char *cmdptr;
35112
35113 if (!sic)
35114 return -EINVAL;
35115@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35116 */
35117 err = -EFAULT;
35118 rq->cmd_len = cmdlen;
35119- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35120+
35121+ if (rq->cmd != rq->__cmd)
35122+ cmdptr = rq->cmd;
35123+ else
35124+ cmdptr = tmpcmd;
35125+
35126+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35127 goto error;
35128
35129+ if (rq->cmd != cmdptr)
35130+ memcpy(rq->cmd, cmdptr, cmdlen);
35131+
35132 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35133 goto error;
35134
35135diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35136index 7bdd61b..afec999 100644
35137--- a/crypto/cryptd.c
35138+++ b/crypto/cryptd.c
35139@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35140
35141 struct cryptd_blkcipher_request_ctx {
35142 crypto_completion_t complete;
35143-};
35144+} __no_const;
35145
35146 struct cryptd_hash_ctx {
35147 struct crypto_shash *child;
35148@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35149
35150 struct cryptd_aead_request_ctx {
35151 crypto_completion_t complete;
35152-};
35153+} __no_const;
35154
35155 static void cryptd_queue_worker(struct work_struct *work);
35156
35157diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35158index f8c920c..ab2cb5a 100644
35159--- a/crypto/pcrypt.c
35160+++ b/crypto/pcrypt.c
35161@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35162 int ret;
35163
35164 pinst->kobj.kset = pcrypt_kset;
35165- ret = kobject_add(&pinst->kobj, NULL, name);
35166+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35167 if (!ret)
35168 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35169
35170diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35171index f220d64..d359ad6 100644
35172--- a/drivers/acpi/apei/apei-internal.h
35173+++ b/drivers/acpi/apei/apei-internal.h
35174@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35175 struct apei_exec_ins_type {
35176 u32 flags;
35177 apei_exec_ins_func_t run;
35178-};
35179+} __do_const;
35180
35181 struct apei_exec_context {
35182 u32 ip;
35183diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
35184index 33dc6a0..4b24b47 100644
35185--- a/drivers/acpi/apei/cper.c
35186+++ b/drivers/acpi/apei/cper.c
35187@@ -39,12 +39,12 @@
35188 */
35189 u64 cper_next_record_id(void)
35190 {
35191- static atomic64_t seq;
35192+ static atomic64_unchecked_t seq;
35193
35194- if (!atomic64_read(&seq))
35195- atomic64_set(&seq, ((u64)get_seconds()) << 32);
35196+ if (!atomic64_read_unchecked(&seq))
35197+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
35198
35199- return atomic64_inc_return(&seq);
35200+ return atomic64_inc_return_unchecked(&seq);
35201 }
35202 EXPORT_SYMBOL_GPL(cper_next_record_id);
35203
35204diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35205index 8ec37bb..b0716e5 100644
35206--- a/drivers/acpi/apei/ghes.c
35207+++ b/drivers/acpi/apei/ghes.c
35208@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35209 const struct acpi_hest_generic *generic,
35210 const struct acpi_hest_generic_status *estatus)
35211 {
35212- static atomic_t seqno;
35213+ static atomic_unchecked_t seqno;
35214 unsigned int curr_seqno;
35215 char pfx_seq[64];
35216
35217@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35218 else
35219 pfx = KERN_ERR;
35220 }
35221- curr_seqno = atomic_inc_return(&seqno);
35222+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35223 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35224 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35225 pfx_seq, generic->header.source_id);
35226diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35227index a83e3c6..c3d617f 100644
35228--- a/drivers/acpi/bgrt.c
35229+++ b/drivers/acpi/bgrt.c
35230@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35231 if (!bgrt_image)
35232 return -ENODEV;
35233
35234- bin_attr_image.private = bgrt_image;
35235- bin_attr_image.size = bgrt_image_size;
35236+ pax_open_kernel();
35237+ *(void **)&bin_attr_image.private = bgrt_image;
35238+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
35239+ pax_close_kernel();
35240
35241 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35242 if (!bgrt_kobj)
35243diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35244index 9515f18..4b149c9 100644
35245--- a/drivers/acpi/blacklist.c
35246+++ b/drivers/acpi/blacklist.c
35247@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35248 u32 is_critical_error;
35249 };
35250
35251-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35252+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35253
35254 /*
35255 * POLICY: If *anything* doesn't work, put it on the blacklist.
35256@@ -199,7 +199,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35257 return 0;
35258 }
35259
35260-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35261+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35262 {
35263 .callback = dmi_disable_osi_vista,
35264 .ident = "Fujitsu Siemens",
35265diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35266index 12b62f2..dc2aac8 100644
35267--- a/drivers/acpi/custom_method.c
35268+++ b/drivers/acpi/custom_method.c
35269@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35270 struct acpi_table_header table;
35271 acpi_status status;
35272
35273+#ifdef CONFIG_GRKERNSEC_KMEM
35274+ return -EPERM;
35275+#endif
35276+
35277 if (!(*ppos)) {
35278 /* parse the table header to get the table length */
35279 if (count <= sizeof(struct acpi_table_header))
35280diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35281index c7414a5..d5afd71 100644
35282--- a/drivers/acpi/processor_idle.c
35283+++ b/drivers/acpi/processor_idle.c
35284@@ -966,7 +966,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35285 {
35286 int i, count = CPUIDLE_DRIVER_STATE_START;
35287 struct acpi_processor_cx *cx;
35288- struct cpuidle_state *state;
35289+ cpuidle_state_no_const *state;
35290 struct cpuidle_driver *drv = &acpi_idle_driver;
35291
35292 if (!pr->flags.power_setup_done)
35293diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35294index 05306a5..733d1f0 100644
35295--- a/drivers/acpi/sysfs.c
35296+++ b/drivers/acpi/sysfs.c
35297@@ -423,11 +423,11 @@ static u32 num_counters;
35298 static struct attribute **all_attrs;
35299 static u32 acpi_gpe_count;
35300
35301-static struct attribute_group interrupt_stats_attr_group = {
35302+static attribute_group_no_const interrupt_stats_attr_group = {
35303 .name = "interrupts",
35304 };
35305
35306-static struct kobj_attribute *counter_attrs;
35307+static kobj_attribute_no_const *counter_attrs;
35308
35309 static void delete_gpe_attr_array(void)
35310 {
35311diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35312index cfb7447..98f2149 100644
35313--- a/drivers/ata/libahci.c
35314+++ b/drivers/ata/libahci.c
35315@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35316 }
35317 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35318
35319-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35320+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35321 struct ata_taskfile *tf, int is_cmd, u16 flags,
35322 unsigned long timeout_msec)
35323 {
35324diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35325index 81a94a3..b711c74 100644
35326--- a/drivers/ata/libata-core.c
35327+++ b/drivers/ata/libata-core.c
35328@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35329 static void ata_dev_xfermask(struct ata_device *dev);
35330 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35331
35332-atomic_t ata_print_id = ATOMIC_INIT(0);
35333+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35334
35335 struct ata_force_param {
35336 const char *name;
35337@@ -4809,7 +4809,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35338 struct ata_port *ap;
35339 unsigned int tag;
35340
35341- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35342+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35343 ap = qc->ap;
35344
35345 qc->flags = 0;
35346@@ -4825,7 +4825,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35347 struct ata_port *ap;
35348 struct ata_link *link;
35349
35350- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35351+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35352 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35353 ap = qc->ap;
35354 link = qc->dev->link;
35355@@ -5944,6 +5944,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35356 return;
35357
35358 spin_lock(&lock);
35359+ pax_open_kernel();
35360
35361 for (cur = ops->inherits; cur; cur = cur->inherits) {
35362 void **inherit = (void **)cur;
35363@@ -5957,8 +5958,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35364 if (IS_ERR(*pp))
35365 *pp = NULL;
35366
35367- ops->inherits = NULL;
35368+ *(struct ata_port_operations **)&ops->inherits = NULL;
35369
35370+ pax_close_kernel();
35371 spin_unlock(&lock);
35372 }
35373
35374@@ -6151,7 +6153,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35375
35376 /* give ports names and add SCSI hosts */
35377 for (i = 0; i < host->n_ports; i++) {
35378- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35379+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35380 host->ports[i]->local_port_no = i + 1;
35381 }
35382
35383diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35384index ab58556..ed19dd2 100644
35385--- a/drivers/ata/libata-scsi.c
35386+++ b/drivers/ata/libata-scsi.c
35387@@ -4114,7 +4114,7 @@ int ata_sas_port_init(struct ata_port *ap)
35388
35389 if (rc)
35390 return rc;
35391- ap->print_id = atomic_inc_return(&ata_print_id);
35392+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35393 return 0;
35394 }
35395 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35396diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35397index 45b5ab3..98446b8 100644
35398--- a/drivers/ata/libata.h
35399+++ b/drivers/ata/libata.h
35400@@ -53,7 +53,7 @@ enum {
35401 ATA_DNXFER_QUIET = (1 << 31),
35402 };
35403
35404-extern atomic_t ata_print_id;
35405+extern atomic_unchecked_t ata_print_id;
35406 extern int atapi_passthru16;
35407 extern int libata_fua;
35408 extern int libata_noacpi;
35409diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35410index 853f610..97d24da 100644
35411--- a/drivers/ata/pata_arasan_cf.c
35412+++ b/drivers/ata/pata_arasan_cf.c
35413@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35414 /* Handle platform specific quirks */
35415 if (quirk) {
35416 if (quirk & CF_BROKEN_PIO) {
35417- ap->ops->set_piomode = NULL;
35418+ pax_open_kernel();
35419+ *(void **)&ap->ops->set_piomode = NULL;
35420+ pax_close_kernel();
35421 ap->pio_mask = 0;
35422 }
35423 if (quirk & CF_BROKEN_MWDMA)
35424diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35425index f9b983a..887b9d8 100644
35426--- a/drivers/atm/adummy.c
35427+++ b/drivers/atm/adummy.c
35428@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35429 vcc->pop(vcc, skb);
35430 else
35431 dev_kfree_skb_any(skb);
35432- atomic_inc(&vcc->stats->tx);
35433+ atomic_inc_unchecked(&vcc->stats->tx);
35434
35435 return 0;
35436 }
35437diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35438index 62a7607..cc4be104 100644
35439--- a/drivers/atm/ambassador.c
35440+++ b/drivers/atm/ambassador.c
35441@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35442 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35443
35444 // VC layer stats
35445- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35446+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35447
35448 // free the descriptor
35449 kfree (tx_descr);
35450@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35451 dump_skb ("<<<", vc, skb);
35452
35453 // VC layer stats
35454- atomic_inc(&atm_vcc->stats->rx);
35455+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35456 __net_timestamp(skb);
35457 // end of our responsibility
35458 atm_vcc->push (atm_vcc, skb);
35459@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35460 } else {
35461 PRINTK (KERN_INFO, "dropped over-size frame");
35462 // should we count this?
35463- atomic_inc(&atm_vcc->stats->rx_drop);
35464+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35465 }
35466
35467 } else {
35468@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35469 }
35470
35471 if (check_area (skb->data, skb->len)) {
35472- atomic_inc(&atm_vcc->stats->tx_err);
35473+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35474 return -ENOMEM; // ?
35475 }
35476
35477diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35478index 0e3f8f9..765a7a5 100644
35479--- a/drivers/atm/atmtcp.c
35480+++ b/drivers/atm/atmtcp.c
35481@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35482 if (vcc->pop) vcc->pop(vcc,skb);
35483 else dev_kfree_skb(skb);
35484 if (dev_data) return 0;
35485- atomic_inc(&vcc->stats->tx_err);
35486+ atomic_inc_unchecked(&vcc->stats->tx_err);
35487 return -ENOLINK;
35488 }
35489 size = skb->len+sizeof(struct atmtcp_hdr);
35490@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35491 if (!new_skb) {
35492 if (vcc->pop) vcc->pop(vcc,skb);
35493 else dev_kfree_skb(skb);
35494- atomic_inc(&vcc->stats->tx_err);
35495+ atomic_inc_unchecked(&vcc->stats->tx_err);
35496 return -ENOBUFS;
35497 }
35498 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35499@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35500 if (vcc->pop) vcc->pop(vcc,skb);
35501 else dev_kfree_skb(skb);
35502 out_vcc->push(out_vcc,new_skb);
35503- atomic_inc(&vcc->stats->tx);
35504- atomic_inc(&out_vcc->stats->rx);
35505+ atomic_inc_unchecked(&vcc->stats->tx);
35506+ atomic_inc_unchecked(&out_vcc->stats->rx);
35507 return 0;
35508 }
35509
35510@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35511 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35512 read_unlock(&vcc_sklist_lock);
35513 if (!out_vcc) {
35514- atomic_inc(&vcc->stats->tx_err);
35515+ atomic_inc_unchecked(&vcc->stats->tx_err);
35516 goto done;
35517 }
35518 skb_pull(skb,sizeof(struct atmtcp_hdr));
35519@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35520 __net_timestamp(new_skb);
35521 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35522 out_vcc->push(out_vcc,new_skb);
35523- atomic_inc(&vcc->stats->tx);
35524- atomic_inc(&out_vcc->stats->rx);
35525+ atomic_inc_unchecked(&vcc->stats->tx);
35526+ atomic_inc_unchecked(&out_vcc->stats->rx);
35527 done:
35528 if (vcc->pop) vcc->pop(vcc,skb);
35529 else dev_kfree_skb(skb);
35530diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35531index b1955ba..b179940 100644
35532--- a/drivers/atm/eni.c
35533+++ b/drivers/atm/eni.c
35534@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35535 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35536 vcc->dev->number);
35537 length = 0;
35538- atomic_inc(&vcc->stats->rx_err);
35539+ atomic_inc_unchecked(&vcc->stats->rx_err);
35540 }
35541 else {
35542 length = ATM_CELL_SIZE-1; /* no HEC */
35543@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35544 size);
35545 }
35546 eff = length = 0;
35547- atomic_inc(&vcc->stats->rx_err);
35548+ atomic_inc_unchecked(&vcc->stats->rx_err);
35549 }
35550 else {
35551 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35552@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35553 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35554 vcc->dev->number,vcc->vci,length,size << 2,descr);
35555 length = eff = 0;
35556- atomic_inc(&vcc->stats->rx_err);
35557+ atomic_inc_unchecked(&vcc->stats->rx_err);
35558 }
35559 }
35560 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35561@@ -767,7 +767,7 @@ rx_dequeued++;
35562 vcc->push(vcc,skb);
35563 pushed++;
35564 }
35565- atomic_inc(&vcc->stats->rx);
35566+ atomic_inc_unchecked(&vcc->stats->rx);
35567 }
35568 wake_up(&eni_dev->rx_wait);
35569 }
35570@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35571 PCI_DMA_TODEVICE);
35572 if (vcc->pop) vcc->pop(vcc,skb);
35573 else dev_kfree_skb_irq(skb);
35574- atomic_inc(&vcc->stats->tx);
35575+ atomic_inc_unchecked(&vcc->stats->tx);
35576 wake_up(&eni_dev->tx_wait);
35577 dma_complete++;
35578 }
35579diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35580index b41c948..a002b17 100644
35581--- a/drivers/atm/firestream.c
35582+++ b/drivers/atm/firestream.c
35583@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35584 }
35585 }
35586
35587- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35588+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35589
35590 fs_dprintk (FS_DEBUG_TXMEM, "i");
35591 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35592@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35593 #endif
35594 skb_put (skb, qe->p1 & 0xffff);
35595 ATM_SKB(skb)->vcc = atm_vcc;
35596- atomic_inc(&atm_vcc->stats->rx);
35597+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35598 __net_timestamp(skb);
35599 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35600 atm_vcc->push (atm_vcc, skb);
35601@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35602 kfree (pe);
35603 }
35604 if (atm_vcc)
35605- atomic_inc(&atm_vcc->stats->rx_drop);
35606+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35607 break;
35608 case 0x1f: /* Reassembly abort: no buffers. */
35609 /* Silently increment error counter. */
35610 if (atm_vcc)
35611- atomic_inc(&atm_vcc->stats->rx_drop);
35612+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35613 break;
35614 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35615 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35616diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35617index 204814e..cede831 100644
35618--- a/drivers/atm/fore200e.c
35619+++ b/drivers/atm/fore200e.c
35620@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35621 #endif
35622 /* check error condition */
35623 if (*entry->status & STATUS_ERROR)
35624- atomic_inc(&vcc->stats->tx_err);
35625+ atomic_inc_unchecked(&vcc->stats->tx_err);
35626 else
35627- atomic_inc(&vcc->stats->tx);
35628+ atomic_inc_unchecked(&vcc->stats->tx);
35629 }
35630 }
35631
35632@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35633 if (skb == NULL) {
35634 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35635
35636- atomic_inc(&vcc->stats->rx_drop);
35637+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35638 return -ENOMEM;
35639 }
35640
35641@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35642
35643 dev_kfree_skb_any(skb);
35644
35645- atomic_inc(&vcc->stats->rx_drop);
35646+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35647 return -ENOMEM;
35648 }
35649
35650 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35651
35652 vcc->push(vcc, skb);
35653- atomic_inc(&vcc->stats->rx);
35654+ atomic_inc_unchecked(&vcc->stats->rx);
35655
35656 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35657
35658@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35659 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35660 fore200e->atm_dev->number,
35661 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35662- atomic_inc(&vcc->stats->rx_err);
35663+ atomic_inc_unchecked(&vcc->stats->rx_err);
35664 }
35665 }
35666
35667@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35668 goto retry_here;
35669 }
35670
35671- atomic_inc(&vcc->stats->tx_err);
35672+ atomic_inc_unchecked(&vcc->stats->tx_err);
35673
35674 fore200e->tx_sat++;
35675 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35676diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35677index 8557adc..3fb5d55 100644
35678--- a/drivers/atm/he.c
35679+++ b/drivers/atm/he.c
35680@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35681
35682 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35683 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35684- atomic_inc(&vcc->stats->rx_drop);
35685+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35686 goto return_host_buffers;
35687 }
35688
35689@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35690 RBRQ_LEN_ERR(he_dev->rbrq_head)
35691 ? "LEN_ERR" : "",
35692 vcc->vpi, vcc->vci);
35693- atomic_inc(&vcc->stats->rx_err);
35694+ atomic_inc_unchecked(&vcc->stats->rx_err);
35695 goto return_host_buffers;
35696 }
35697
35698@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35699 vcc->push(vcc, skb);
35700 spin_lock(&he_dev->global_lock);
35701
35702- atomic_inc(&vcc->stats->rx);
35703+ atomic_inc_unchecked(&vcc->stats->rx);
35704
35705 return_host_buffers:
35706 ++pdus_assembled;
35707@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35708 tpd->vcc->pop(tpd->vcc, tpd->skb);
35709 else
35710 dev_kfree_skb_any(tpd->skb);
35711- atomic_inc(&tpd->vcc->stats->tx_err);
35712+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35713 }
35714 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35715 return;
35716@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35717 vcc->pop(vcc, skb);
35718 else
35719 dev_kfree_skb_any(skb);
35720- atomic_inc(&vcc->stats->tx_err);
35721+ atomic_inc_unchecked(&vcc->stats->tx_err);
35722 return -EINVAL;
35723 }
35724
35725@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35726 vcc->pop(vcc, skb);
35727 else
35728 dev_kfree_skb_any(skb);
35729- atomic_inc(&vcc->stats->tx_err);
35730+ atomic_inc_unchecked(&vcc->stats->tx_err);
35731 return -EINVAL;
35732 }
35733 #endif
35734@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35735 vcc->pop(vcc, skb);
35736 else
35737 dev_kfree_skb_any(skb);
35738- atomic_inc(&vcc->stats->tx_err);
35739+ atomic_inc_unchecked(&vcc->stats->tx_err);
35740 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35741 return -ENOMEM;
35742 }
35743@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35744 vcc->pop(vcc, skb);
35745 else
35746 dev_kfree_skb_any(skb);
35747- atomic_inc(&vcc->stats->tx_err);
35748+ atomic_inc_unchecked(&vcc->stats->tx_err);
35749 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35750 return -ENOMEM;
35751 }
35752@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35753 __enqueue_tpd(he_dev, tpd, cid);
35754 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35755
35756- atomic_inc(&vcc->stats->tx);
35757+ atomic_inc_unchecked(&vcc->stats->tx);
35758
35759 return 0;
35760 }
35761diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35762index 1dc0519..1aadaf7 100644
35763--- a/drivers/atm/horizon.c
35764+++ b/drivers/atm/horizon.c
35765@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35766 {
35767 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35768 // VC layer stats
35769- atomic_inc(&vcc->stats->rx);
35770+ atomic_inc_unchecked(&vcc->stats->rx);
35771 __net_timestamp(skb);
35772 // end of our responsibility
35773 vcc->push (vcc, skb);
35774@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35775 dev->tx_iovec = NULL;
35776
35777 // VC layer stats
35778- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35779+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35780
35781 // free the skb
35782 hrz_kfree_skb (skb);
35783diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35784index 1bdf104..9dc44b1 100644
35785--- a/drivers/atm/idt77252.c
35786+++ b/drivers/atm/idt77252.c
35787@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35788 else
35789 dev_kfree_skb(skb);
35790
35791- atomic_inc(&vcc->stats->tx);
35792+ atomic_inc_unchecked(&vcc->stats->tx);
35793 }
35794
35795 atomic_dec(&scq->used);
35796@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35797 if ((sb = dev_alloc_skb(64)) == NULL) {
35798 printk("%s: Can't allocate buffers for aal0.\n",
35799 card->name);
35800- atomic_add(i, &vcc->stats->rx_drop);
35801+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35802 break;
35803 }
35804 if (!atm_charge(vcc, sb->truesize)) {
35805 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35806 card->name);
35807- atomic_add(i - 1, &vcc->stats->rx_drop);
35808+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35809 dev_kfree_skb(sb);
35810 break;
35811 }
35812@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35813 ATM_SKB(sb)->vcc = vcc;
35814 __net_timestamp(sb);
35815 vcc->push(vcc, sb);
35816- atomic_inc(&vcc->stats->rx);
35817+ atomic_inc_unchecked(&vcc->stats->rx);
35818
35819 cell += ATM_CELL_PAYLOAD;
35820 }
35821@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35822 "(CDC: %08x)\n",
35823 card->name, len, rpp->len, readl(SAR_REG_CDC));
35824 recycle_rx_pool_skb(card, rpp);
35825- atomic_inc(&vcc->stats->rx_err);
35826+ atomic_inc_unchecked(&vcc->stats->rx_err);
35827 return;
35828 }
35829 if (stat & SAR_RSQE_CRC) {
35830 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35831 recycle_rx_pool_skb(card, rpp);
35832- atomic_inc(&vcc->stats->rx_err);
35833+ atomic_inc_unchecked(&vcc->stats->rx_err);
35834 return;
35835 }
35836 if (skb_queue_len(&rpp->queue) > 1) {
35837@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35838 RXPRINTK("%s: Can't alloc RX skb.\n",
35839 card->name);
35840 recycle_rx_pool_skb(card, rpp);
35841- atomic_inc(&vcc->stats->rx_err);
35842+ atomic_inc_unchecked(&vcc->stats->rx_err);
35843 return;
35844 }
35845 if (!atm_charge(vcc, skb->truesize)) {
35846@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35847 __net_timestamp(skb);
35848
35849 vcc->push(vcc, skb);
35850- atomic_inc(&vcc->stats->rx);
35851+ atomic_inc_unchecked(&vcc->stats->rx);
35852
35853 return;
35854 }
35855@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35856 __net_timestamp(skb);
35857
35858 vcc->push(vcc, skb);
35859- atomic_inc(&vcc->stats->rx);
35860+ atomic_inc_unchecked(&vcc->stats->rx);
35861
35862 if (skb->truesize > SAR_FB_SIZE_3)
35863 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35864@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35865 if (vcc->qos.aal != ATM_AAL0) {
35866 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35867 card->name, vpi, vci);
35868- atomic_inc(&vcc->stats->rx_drop);
35869+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35870 goto drop;
35871 }
35872
35873 if ((sb = dev_alloc_skb(64)) == NULL) {
35874 printk("%s: Can't allocate buffers for AAL0.\n",
35875 card->name);
35876- atomic_inc(&vcc->stats->rx_err);
35877+ atomic_inc_unchecked(&vcc->stats->rx_err);
35878 goto drop;
35879 }
35880
35881@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35882 ATM_SKB(sb)->vcc = vcc;
35883 __net_timestamp(sb);
35884 vcc->push(vcc, sb);
35885- atomic_inc(&vcc->stats->rx);
35886+ atomic_inc_unchecked(&vcc->stats->rx);
35887
35888 drop:
35889 skb_pull(queue, 64);
35890@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35891
35892 if (vc == NULL) {
35893 printk("%s: NULL connection in send().\n", card->name);
35894- atomic_inc(&vcc->stats->tx_err);
35895+ atomic_inc_unchecked(&vcc->stats->tx_err);
35896 dev_kfree_skb(skb);
35897 return -EINVAL;
35898 }
35899 if (!test_bit(VCF_TX, &vc->flags)) {
35900 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35901- atomic_inc(&vcc->stats->tx_err);
35902+ atomic_inc_unchecked(&vcc->stats->tx_err);
35903 dev_kfree_skb(skb);
35904 return -EINVAL;
35905 }
35906@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35907 break;
35908 default:
35909 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35910- atomic_inc(&vcc->stats->tx_err);
35911+ atomic_inc_unchecked(&vcc->stats->tx_err);
35912 dev_kfree_skb(skb);
35913 return -EINVAL;
35914 }
35915
35916 if (skb_shinfo(skb)->nr_frags != 0) {
35917 printk("%s: No scatter-gather yet.\n", card->name);
35918- atomic_inc(&vcc->stats->tx_err);
35919+ atomic_inc_unchecked(&vcc->stats->tx_err);
35920 dev_kfree_skb(skb);
35921 return -EINVAL;
35922 }
35923@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35924
35925 err = queue_skb(card, vc, skb, oam);
35926 if (err) {
35927- atomic_inc(&vcc->stats->tx_err);
35928+ atomic_inc_unchecked(&vcc->stats->tx_err);
35929 dev_kfree_skb(skb);
35930 return err;
35931 }
35932@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35933 skb = dev_alloc_skb(64);
35934 if (!skb) {
35935 printk("%s: Out of memory in send_oam().\n", card->name);
35936- atomic_inc(&vcc->stats->tx_err);
35937+ atomic_inc_unchecked(&vcc->stats->tx_err);
35938 return -ENOMEM;
35939 }
35940 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35941diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35942index 4217f29..88f547a 100644
35943--- a/drivers/atm/iphase.c
35944+++ b/drivers/atm/iphase.c
35945@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35946 status = (u_short) (buf_desc_ptr->desc_mode);
35947 if (status & (RX_CER | RX_PTE | RX_OFL))
35948 {
35949- atomic_inc(&vcc->stats->rx_err);
35950+ atomic_inc_unchecked(&vcc->stats->rx_err);
35951 IF_ERR(printk("IA: bad packet, dropping it");)
35952 if (status & RX_CER) {
35953 IF_ERR(printk(" cause: packet CRC error\n");)
35954@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35955 len = dma_addr - buf_addr;
35956 if (len > iadev->rx_buf_sz) {
35957 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35958- atomic_inc(&vcc->stats->rx_err);
35959+ atomic_inc_unchecked(&vcc->stats->rx_err);
35960 goto out_free_desc;
35961 }
35962
35963@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35964 ia_vcc = INPH_IA_VCC(vcc);
35965 if (ia_vcc == NULL)
35966 {
35967- atomic_inc(&vcc->stats->rx_err);
35968+ atomic_inc_unchecked(&vcc->stats->rx_err);
35969 atm_return(vcc, skb->truesize);
35970 dev_kfree_skb_any(skb);
35971 goto INCR_DLE;
35972@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35973 if ((length > iadev->rx_buf_sz) || (length >
35974 (skb->len - sizeof(struct cpcs_trailer))))
35975 {
35976- atomic_inc(&vcc->stats->rx_err);
35977+ atomic_inc_unchecked(&vcc->stats->rx_err);
35978 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35979 length, skb->len);)
35980 atm_return(vcc, skb->truesize);
35981@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35982
35983 IF_RX(printk("rx_dle_intr: skb push");)
35984 vcc->push(vcc,skb);
35985- atomic_inc(&vcc->stats->rx);
35986+ atomic_inc_unchecked(&vcc->stats->rx);
35987 iadev->rx_pkt_cnt++;
35988 }
35989 INCR_DLE:
35990@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35991 {
35992 struct k_sonet_stats *stats;
35993 stats = &PRIV(_ia_dev[board])->sonet_stats;
35994- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35995- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35996- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35997- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35998- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35999- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36000- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36001- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36002- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36003+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36004+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36005+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36006+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36007+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36008+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36009+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36010+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36011+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36012 }
36013 ia_cmds.status = 0;
36014 break;
36015@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36016 if ((desc == 0) || (desc > iadev->num_tx_desc))
36017 {
36018 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36019- atomic_inc(&vcc->stats->tx);
36020+ atomic_inc_unchecked(&vcc->stats->tx);
36021 if (vcc->pop)
36022 vcc->pop(vcc, skb);
36023 else
36024@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36025 ATM_DESC(skb) = vcc->vci;
36026 skb_queue_tail(&iadev->tx_dma_q, skb);
36027
36028- atomic_inc(&vcc->stats->tx);
36029+ atomic_inc_unchecked(&vcc->stats->tx);
36030 iadev->tx_pkt_cnt++;
36031 /* Increment transaction counter */
36032 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36033
36034 #if 0
36035 /* add flow control logic */
36036- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36037+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36038 if (iavcc->vc_desc_cnt > 10) {
36039 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36040 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36041diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36042index fa7d701..1e404c7 100644
36043--- a/drivers/atm/lanai.c
36044+++ b/drivers/atm/lanai.c
36045@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36046 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36047 lanai_endtx(lanai, lvcc);
36048 lanai_free_skb(lvcc->tx.atmvcc, skb);
36049- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36050+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36051 }
36052
36053 /* Try to fill the buffer - don't call unless there is backlog */
36054@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36055 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36056 __net_timestamp(skb);
36057 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36058- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36059+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36060 out:
36061 lvcc->rx.buf.ptr = end;
36062 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36063@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36064 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36065 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36066 lanai->stats.service_rxnotaal5++;
36067- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36068+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36069 return 0;
36070 }
36071 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36072@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36073 int bytes;
36074 read_unlock(&vcc_sklist_lock);
36075 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36076- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36077+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36078 lvcc->stats.x.aal5.service_trash++;
36079 bytes = (SERVICE_GET_END(s) * 16) -
36080 (((unsigned long) lvcc->rx.buf.ptr) -
36081@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36082 }
36083 if (s & SERVICE_STREAM) {
36084 read_unlock(&vcc_sklist_lock);
36085- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36086+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36087 lvcc->stats.x.aal5.service_stream++;
36088 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36089 "PDU on VCI %d!\n", lanai->number, vci);
36090@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36091 return 0;
36092 }
36093 DPRINTK("got rx crc error on vci %d\n", vci);
36094- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36095+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36096 lvcc->stats.x.aal5.service_rxcrc++;
36097 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36098 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36099diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36100index 5aca5f4..ce3a6b0 100644
36101--- a/drivers/atm/nicstar.c
36102+++ b/drivers/atm/nicstar.c
36103@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36104 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36105 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36106 card->index);
36107- atomic_inc(&vcc->stats->tx_err);
36108+ atomic_inc_unchecked(&vcc->stats->tx_err);
36109 dev_kfree_skb_any(skb);
36110 return -EINVAL;
36111 }
36112@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36113 if (!vc->tx) {
36114 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36115 card->index);
36116- atomic_inc(&vcc->stats->tx_err);
36117+ atomic_inc_unchecked(&vcc->stats->tx_err);
36118 dev_kfree_skb_any(skb);
36119 return -EINVAL;
36120 }
36121@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36122 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36123 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36124 card->index);
36125- atomic_inc(&vcc->stats->tx_err);
36126+ atomic_inc_unchecked(&vcc->stats->tx_err);
36127 dev_kfree_skb_any(skb);
36128 return -EINVAL;
36129 }
36130
36131 if (skb_shinfo(skb)->nr_frags != 0) {
36132 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36133- atomic_inc(&vcc->stats->tx_err);
36134+ atomic_inc_unchecked(&vcc->stats->tx_err);
36135 dev_kfree_skb_any(skb);
36136 return -EINVAL;
36137 }
36138@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36139 }
36140
36141 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36142- atomic_inc(&vcc->stats->tx_err);
36143+ atomic_inc_unchecked(&vcc->stats->tx_err);
36144 dev_kfree_skb_any(skb);
36145 return -EIO;
36146 }
36147- atomic_inc(&vcc->stats->tx);
36148+ atomic_inc_unchecked(&vcc->stats->tx);
36149
36150 return 0;
36151 }
36152@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36153 printk
36154 ("nicstar%d: Can't allocate buffers for aal0.\n",
36155 card->index);
36156- atomic_add(i, &vcc->stats->rx_drop);
36157+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36158 break;
36159 }
36160 if (!atm_charge(vcc, sb->truesize)) {
36161 RXPRINTK
36162 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36163 card->index);
36164- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36165+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36166 dev_kfree_skb_any(sb);
36167 break;
36168 }
36169@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36170 ATM_SKB(sb)->vcc = vcc;
36171 __net_timestamp(sb);
36172 vcc->push(vcc, sb);
36173- atomic_inc(&vcc->stats->rx);
36174+ atomic_inc_unchecked(&vcc->stats->rx);
36175 cell += ATM_CELL_PAYLOAD;
36176 }
36177
36178@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36179 if (iovb == NULL) {
36180 printk("nicstar%d: Out of iovec buffers.\n",
36181 card->index);
36182- atomic_inc(&vcc->stats->rx_drop);
36183+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36184 recycle_rx_buf(card, skb);
36185 return;
36186 }
36187@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36188 small or large buffer itself. */
36189 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36190 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36191- atomic_inc(&vcc->stats->rx_err);
36192+ atomic_inc_unchecked(&vcc->stats->rx_err);
36193 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36194 NS_MAX_IOVECS);
36195 NS_PRV_IOVCNT(iovb) = 0;
36196@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36197 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36198 card->index);
36199 which_list(card, skb);
36200- atomic_inc(&vcc->stats->rx_err);
36201+ atomic_inc_unchecked(&vcc->stats->rx_err);
36202 recycle_rx_buf(card, skb);
36203 vc->rx_iov = NULL;
36204 recycle_iov_buf(card, iovb);
36205@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36206 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36207 card->index);
36208 which_list(card, skb);
36209- atomic_inc(&vcc->stats->rx_err);
36210+ atomic_inc_unchecked(&vcc->stats->rx_err);
36211 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36212 NS_PRV_IOVCNT(iovb));
36213 vc->rx_iov = NULL;
36214@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36215 printk(" - PDU size mismatch.\n");
36216 else
36217 printk(".\n");
36218- atomic_inc(&vcc->stats->rx_err);
36219+ atomic_inc_unchecked(&vcc->stats->rx_err);
36220 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36221 NS_PRV_IOVCNT(iovb));
36222 vc->rx_iov = NULL;
36223@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36224 /* skb points to a small buffer */
36225 if (!atm_charge(vcc, skb->truesize)) {
36226 push_rxbufs(card, skb);
36227- atomic_inc(&vcc->stats->rx_drop);
36228+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36229 } else {
36230 skb_put(skb, len);
36231 dequeue_sm_buf(card, skb);
36232@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36233 ATM_SKB(skb)->vcc = vcc;
36234 __net_timestamp(skb);
36235 vcc->push(vcc, skb);
36236- atomic_inc(&vcc->stats->rx);
36237+ atomic_inc_unchecked(&vcc->stats->rx);
36238 }
36239 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36240 struct sk_buff *sb;
36241@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36242 if (len <= NS_SMBUFSIZE) {
36243 if (!atm_charge(vcc, sb->truesize)) {
36244 push_rxbufs(card, sb);
36245- atomic_inc(&vcc->stats->rx_drop);
36246+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36247 } else {
36248 skb_put(sb, len);
36249 dequeue_sm_buf(card, sb);
36250@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36251 ATM_SKB(sb)->vcc = vcc;
36252 __net_timestamp(sb);
36253 vcc->push(vcc, sb);
36254- atomic_inc(&vcc->stats->rx);
36255+ atomic_inc_unchecked(&vcc->stats->rx);
36256 }
36257
36258 push_rxbufs(card, skb);
36259@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36260
36261 if (!atm_charge(vcc, skb->truesize)) {
36262 push_rxbufs(card, skb);
36263- atomic_inc(&vcc->stats->rx_drop);
36264+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36265 } else {
36266 dequeue_lg_buf(card, skb);
36267 #ifdef NS_USE_DESTRUCTORS
36268@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36269 ATM_SKB(skb)->vcc = vcc;
36270 __net_timestamp(skb);
36271 vcc->push(vcc, skb);
36272- atomic_inc(&vcc->stats->rx);
36273+ atomic_inc_unchecked(&vcc->stats->rx);
36274 }
36275
36276 push_rxbufs(card, sb);
36277@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36278 printk
36279 ("nicstar%d: Out of huge buffers.\n",
36280 card->index);
36281- atomic_inc(&vcc->stats->rx_drop);
36282+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36283 recycle_iovec_rx_bufs(card,
36284 (struct iovec *)
36285 iovb->data,
36286@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36287 card->hbpool.count++;
36288 } else
36289 dev_kfree_skb_any(hb);
36290- atomic_inc(&vcc->stats->rx_drop);
36291+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36292 } else {
36293 /* Copy the small buffer to the huge buffer */
36294 sb = (struct sk_buff *)iov->iov_base;
36295@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36296 #endif /* NS_USE_DESTRUCTORS */
36297 __net_timestamp(hb);
36298 vcc->push(vcc, hb);
36299- atomic_inc(&vcc->stats->rx);
36300+ atomic_inc_unchecked(&vcc->stats->rx);
36301 }
36302 }
36303
36304diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36305index 32784d1..4a8434a 100644
36306--- a/drivers/atm/solos-pci.c
36307+++ b/drivers/atm/solos-pci.c
36308@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36309 }
36310 atm_charge(vcc, skb->truesize);
36311 vcc->push(vcc, skb);
36312- atomic_inc(&vcc->stats->rx);
36313+ atomic_inc_unchecked(&vcc->stats->rx);
36314 break;
36315
36316 case PKT_STATUS:
36317@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36318 vcc = SKB_CB(oldskb)->vcc;
36319
36320 if (vcc) {
36321- atomic_inc(&vcc->stats->tx);
36322+ atomic_inc_unchecked(&vcc->stats->tx);
36323 solos_pop(vcc, oldskb);
36324 } else {
36325 dev_kfree_skb_irq(oldskb);
36326diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36327index 0215934..ce9f5b1 100644
36328--- a/drivers/atm/suni.c
36329+++ b/drivers/atm/suni.c
36330@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36331
36332
36333 #define ADD_LIMITED(s,v) \
36334- atomic_add((v),&stats->s); \
36335- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36336+ atomic_add_unchecked((v),&stats->s); \
36337+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36338
36339
36340 static void suni_hz(unsigned long from_timer)
36341diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36342index 5120a96..e2572bd 100644
36343--- a/drivers/atm/uPD98402.c
36344+++ b/drivers/atm/uPD98402.c
36345@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36346 struct sonet_stats tmp;
36347 int error = 0;
36348
36349- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36350+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36351 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36352 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36353 if (zero && !error) {
36354@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36355
36356
36357 #define ADD_LIMITED(s,v) \
36358- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36359- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36360- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36361+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36362+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36363+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36364
36365
36366 static void stat_event(struct atm_dev *dev)
36367@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36368 if (reason & uPD98402_INT_PFM) stat_event(dev);
36369 if (reason & uPD98402_INT_PCO) {
36370 (void) GET(PCOCR); /* clear interrupt cause */
36371- atomic_add(GET(HECCT),
36372+ atomic_add_unchecked(GET(HECCT),
36373 &PRIV(dev)->sonet_stats.uncorr_hcs);
36374 }
36375 if ((reason & uPD98402_INT_RFO) &&
36376@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36377 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36378 uPD98402_INT_LOS),PIMR); /* enable them */
36379 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36380- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36381- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36382- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36383+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36384+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36385+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36386 return 0;
36387 }
36388
36389diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36390index 969c3c2..9b72956 100644
36391--- a/drivers/atm/zatm.c
36392+++ b/drivers/atm/zatm.c
36393@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36394 }
36395 if (!size) {
36396 dev_kfree_skb_irq(skb);
36397- if (vcc) atomic_inc(&vcc->stats->rx_err);
36398+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36399 continue;
36400 }
36401 if (!atm_charge(vcc,skb->truesize)) {
36402@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36403 skb->len = size;
36404 ATM_SKB(skb)->vcc = vcc;
36405 vcc->push(vcc,skb);
36406- atomic_inc(&vcc->stats->rx);
36407+ atomic_inc_unchecked(&vcc->stats->rx);
36408 }
36409 zout(pos & 0xffff,MTA(mbx));
36410 #if 0 /* probably a stupid idea */
36411@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36412 skb_queue_head(&zatm_vcc->backlog,skb);
36413 break;
36414 }
36415- atomic_inc(&vcc->stats->tx);
36416+ atomic_inc_unchecked(&vcc->stats->tx);
36417 wake_up(&zatm_vcc->tx_wait);
36418 }
36419
36420diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36421index 4c289ab..de1c333 100644
36422--- a/drivers/base/bus.c
36423+++ b/drivers/base/bus.c
36424@@ -1193,7 +1193,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36425 return -EINVAL;
36426
36427 mutex_lock(&subsys->p->mutex);
36428- list_add_tail(&sif->node, &subsys->p->interfaces);
36429+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36430 if (sif->add_dev) {
36431 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36432 while ((dev = subsys_dev_iter_next(&iter)))
36433@@ -1218,7 +1218,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36434 subsys = sif->subsys;
36435
36436 mutex_lock(&subsys->p->mutex);
36437- list_del_init(&sif->node);
36438+ pax_list_del_init((struct list_head *)&sif->node);
36439 if (sif->remove_dev) {
36440 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36441 while ((dev = subsys_dev_iter_next(&iter)))
36442diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36443index 7413d06..79155fa 100644
36444--- a/drivers/base/devtmpfs.c
36445+++ b/drivers/base/devtmpfs.c
36446@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36447 if (!thread)
36448 return 0;
36449
36450- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36451+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36452 if (err)
36453 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36454 else
36455@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36456 *err = sys_unshare(CLONE_NEWNS);
36457 if (*err)
36458 goto out;
36459- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36460+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36461 if (*err)
36462 goto out;
36463- sys_chdir("/.."); /* will traverse into overmounted root */
36464- sys_chroot(".");
36465+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36466+ sys_chroot((char __force_user *)".");
36467 complete(&setup_done);
36468 while (1) {
36469 spin_lock(&req_lock);
36470diff --git a/drivers/base/node.c b/drivers/base/node.c
36471index bc9f43b..29703b8 100644
36472--- a/drivers/base/node.c
36473+++ b/drivers/base/node.c
36474@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36475 struct node_attr {
36476 struct device_attribute attr;
36477 enum node_states state;
36478-};
36479+} __do_const;
36480
36481 static ssize_t show_node_state(struct device *dev,
36482 struct device_attribute *attr, char *buf)
36483diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36484index bfb8955..42c9b9a 100644
36485--- a/drivers/base/power/domain.c
36486+++ b/drivers/base/power/domain.c
36487@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36488 {
36489 struct cpuidle_driver *cpuidle_drv;
36490 struct gpd_cpu_data *cpu_data;
36491- struct cpuidle_state *idle_state;
36492+ cpuidle_state_no_const *idle_state;
36493 int ret = 0;
36494
36495 if (IS_ERR_OR_NULL(genpd) || state < 0)
36496@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36497 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36498 {
36499 struct gpd_cpu_data *cpu_data;
36500- struct cpuidle_state *idle_state;
36501+ cpuidle_state_no_const *idle_state;
36502 int ret = 0;
36503
36504 if (IS_ERR_OR_NULL(genpd))
36505diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36506index 03e089a..0e9560c 100644
36507--- a/drivers/base/power/sysfs.c
36508+++ b/drivers/base/power/sysfs.c
36509@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36510 return -EIO;
36511 }
36512 }
36513- return sprintf(buf, p);
36514+ return sprintf(buf, "%s", p);
36515 }
36516
36517 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36518diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36519index 2d56f41..8830f19 100644
36520--- a/drivers/base/power/wakeup.c
36521+++ b/drivers/base/power/wakeup.c
36522@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36523 * They need to be modified together atomically, so it's better to use one
36524 * atomic variable to hold them both.
36525 */
36526-static atomic_t combined_event_count = ATOMIC_INIT(0);
36527+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36528
36529 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36530 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36531
36532 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36533 {
36534- unsigned int comb = atomic_read(&combined_event_count);
36535+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
36536
36537 *cnt = (comb >> IN_PROGRESS_BITS);
36538 *inpr = comb & MAX_IN_PROGRESS;
36539@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36540 ws->start_prevent_time = ws->last_time;
36541
36542 /* Increment the counter of events in progress. */
36543- cec = atomic_inc_return(&combined_event_count);
36544+ cec = atomic_inc_return_unchecked(&combined_event_count);
36545
36546 trace_wakeup_source_activate(ws->name, cec);
36547 }
36548@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36549 * Increment the counter of registered wakeup events and decrement the
36550 * couter of wakeup events in progress simultaneously.
36551 */
36552- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36553+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36554 trace_wakeup_source_deactivate(ws->name, cec);
36555
36556 split_counters(&cnt, &inpr);
36557diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36558index e8d11b6..7b1b36f 100644
36559--- a/drivers/base/syscore.c
36560+++ b/drivers/base/syscore.c
36561@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36562 void register_syscore_ops(struct syscore_ops *ops)
36563 {
36564 mutex_lock(&syscore_ops_lock);
36565- list_add_tail(&ops->node, &syscore_ops_list);
36566+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36567 mutex_unlock(&syscore_ops_lock);
36568 }
36569 EXPORT_SYMBOL_GPL(register_syscore_ops);
36570@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36571 void unregister_syscore_ops(struct syscore_ops *ops)
36572 {
36573 mutex_lock(&syscore_ops_lock);
36574- list_del(&ops->node);
36575+ pax_list_del((struct list_head *)&ops->node);
36576 mutex_unlock(&syscore_ops_lock);
36577 }
36578 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36579diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36580index edfa251..1734d4d 100644
36581--- a/drivers/block/cciss.c
36582+++ b/drivers/block/cciss.c
36583@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36584 while (!list_empty(&h->reqQ)) {
36585 c = list_entry(h->reqQ.next, CommandList_struct, list);
36586 /* can't do anything if fifo is full */
36587- if ((h->access.fifo_full(h))) {
36588+ if ((h->access->fifo_full(h))) {
36589 dev_warn(&h->pdev->dev, "fifo full\n");
36590 break;
36591 }
36592@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36593 h->Qdepth--;
36594
36595 /* Tell the controller execute command */
36596- h->access.submit_command(h, c);
36597+ h->access->submit_command(h, c);
36598
36599 /* Put job onto the completed Q */
36600 addQ(&h->cmpQ, c);
36601@@ -3447,17 +3447,17 @@ startio:
36602
36603 static inline unsigned long get_next_completion(ctlr_info_t *h)
36604 {
36605- return h->access.command_completed(h);
36606+ return h->access->command_completed(h);
36607 }
36608
36609 static inline int interrupt_pending(ctlr_info_t *h)
36610 {
36611- return h->access.intr_pending(h);
36612+ return h->access->intr_pending(h);
36613 }
36614
36615 static inline long interrupt_not_for_us(ctlr_info_t *h)
36616 {
36617- return ((h->access.intr_pending(h) == 0) ||
36618+ return ((h->access->intr_pending(h) == 0) ||
36619 (h->interrupts_enabled == 0));
36620 }
36621
36622@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36623 u32 a;
36624
36625 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36626- return h->access.command_completed(h);
36627+ return h->access->command_completed(h);
36628
36629 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36630 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36631@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36632 trans_support & CFGTBL_Trans_use_short_tags);
36633
36634 /* Change the access methods to the performant access methods */
36635- h->access = SA5_performant_access;
36636+ h->access = &SA5_performant_access;
36637 h->transMethod = CFGTBL_Trans_Performant;
36638
36639 return;
36640@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36641 if (prod_index < 0)
36642 return -ENODEV;
36643 h->product_name = products[prod_index].product_name;
36644- h->access = *(products[prod_index].access);
36645+ h->access = products[prod_index].access;
36646
36647 if (cciss_board_disabled(h)) {
36648 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36649@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36650 }
36651
36652 /* make sure the board interrupts are off */
36653- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36654+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36655 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36656 if (rc)
36657 goto clean2;
36658@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36659 * fake ones to scoop up any residual completions.
36660 */
36661 spin_lock_irqsave(&h->lock, flags);
36662- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36663+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36664 spin_unlock_irqrestore(&h->lock, flags);
36665 free_irq(h->intr[h->intr_mode], h);
36666 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36667@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36668 dev_info(&h->pdev->dev, "Board READY.\n");
36669 dev_info(&h->pdev->dev,
36670 "Waiting for stale completions to drain.\n");
36671- h->access.set_intr_mask(h, CCISS_INTR_ON);
36672+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36673 msleep(10000);
36674- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36675+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36676
36677 rc = controller_reset_failed(h->cfgtable);
36678 if (rc)
36679@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36680 cciss_scsi_setup(h);
36681
36682 /* Turn the interrupts on so we can service requests */
36683- h->access.set_intr_mask(h, CCISS_INTR_ON);
36684+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36685
36686 /* Get the firmware version */
36687 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36688@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36689 kfree(flush_buf);
36690 if (return_code != IO_OK)
36691 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36692- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36693+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36694 free_irq(h->intr[h->intr_mode], h);
36695 }
36696
36697diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36698index 7fda30e..eb5dfe0 100644
36699--- a/drivers/block/cciss.h
36700+++ b/drivers/block/cciss.h
36701@@ -101,7 +101,7 @@ struct ctlr_info
36702 /* information about each logical volume */
36703 drive_info_struct *drv[CISS_MAX_LUN];
36704
36705- struct access_method access;
36706+ struct access_method *access;
36707
36708 /* queue and queue Info */
36709 struct list_head reqQ;
36710diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36711index 2b94403..fd6ad1f 100644
36712--- a/drivers/block/cpqarray.c
36713+++ b/drivers/block/cpqarray.c
36714@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36715 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36716 goto Enomem4;
36717 }
36718- hba[i]->access.set_intr_mask(hba[i], 0);
36719+ hba[i]->access->set_intr_mask(hba[i], 0);
36720 if (request_irq(hba[i]->intr, do_ida_intr,
36721 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36722 {
36723@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36724 add_timer(&hba[i]->timer);
36725
36726 /* Enable IRQ now that spinlock and rate limit timer are set up */
36727- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36728+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36729
36730 for(j=0; j<NWD; j++) {
36731 struct gendisk *disk = ida_gendisk[i][j];
36732@@ -694,7 +694,7 @@ DBGINFO(
36733 for(i=0; i<NR_PRODUCTS; i++) {
36734 if (board_id == products[i].board_id) {
36735 c->product_name = products[i].product_name;
36736- c->access = *(products[i].access);
36737+ c->access = products[i].access;
36738 break;
36739 }
36740 }
36741@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36742 hba[ctlr]->intr = intr;
36743 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36744 hba[ctlr]->product_name = products[j].product_name;
36745- hba[ctlr]->access = *(products[j].access);
36746+ hba[ctlr]->access = products[j].access;
36747 hba[ctlr]->ctlr = ctlr;
36748 hba[ctlr]->board_id = board_id;
36749 hba[ctlr]->pci_dev = NULL; /* not PCI */
36750@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36751
36752 while((c = h->reqQ) != NULL) {
36753 /* Can't do anything if we're busy */
36754- if (h->access.fifo_full(h) == 0)
36755+ if (h->access->fifo_full(h) == 0)
36756 return;
36757
36758 /* Get the first entry from the request Q */
36759@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36760 h->Qdepth--;
36761
36762 /* Tell the controller to do our bidding */
36763- h->access.submit_command(h, c);
36764+ h->access->submit_command(h, c);
36765
36766 /* Get onto the completion Q */
36767 addQ(&h->cmpQ, c);
36768@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36769 unsigned long flags;
36770 __u32 a,a1;
36771
36772- istat = h->access.intr_pending(h);
36773+ istat = h->access->intr_pending(h);
36774 /* Is this interrupt for us? */
36775 if (istat == 0)
36776 return IRQ_NONE;
36777@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36778 */
36779 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36780 if (istat & FIFO_NOT_EMPTY) {
36781- while((a = h->access.command_completed(h))) {
36782+ while((a = h->access->command_completed(h))) {
36783 a1 = a; a &= ~3;
36784 if ((c = h->cmpQ) == NULL)
36785 {
36786@@ -1448,11 +1448,11 @@ static int sendcmd(
36787 /*
36788 * Disable interrupt
36789 */
36790- info_p->access.set_intr_mask(info_p, 0);
36791+ info_p->access->set_intr_mask(info_p, 0);
36792 /* Make sure there is room in the command FIFO */
36793 /* Actually it should be completely empty at this time. */
36794 for (i = 200000; i > 0; i--) {
36795- temp = info_p->access.fifo_full(info_p);
36796+ temp = info_p->access->fifo_full(info_p);
36797 if (temp != 0) {
36798 break;
36799 }
36800@@ -1465,7 +1465,7 @@ DBG(
36801 /*
36802 * Send the cmd
36803 */
36804- info_p->access.submit_command(info_p, c);
36805+ info_p->access->submit_command(info_p, c);
36806 complete = pollcomplete(ctlr);
36807
36808 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36809@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36810 * we check the new geometry. Then turn interrupts back on when
36811 * we're done.
36812 */
36813- host->access.set_intr_mask(host, 0);
36814+ host->access->set_intr_mask(host, 0);
36815 getgeometry(ctlr);
36816- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36817+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36818
36819 for(i=0; i<NWD; i++) {
36820 struct gendisk *disk = ida_gendisk[ctlr][i];
36821@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36822 /* Wait (up to 2 seconds) for a command to complete */
36823
36824 for (i = 200000; i > 0; i--) {
36825- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36826+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36827 if (done == 0) {
36828 udelay(10); /* a short fixed delay */
36829 } else
36830diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36831index be73e9d..7fbf140 100644
36832--- a/drivers/block/cpqarray.h
36833+++ b/drivers/block/cpqarray.h
36834@@ -99,7 +99,7 @@ struct ctlr_info {
36835 drv_info_t drv[NWD];
36836 struct proc_dir_entry *proc;
36837
36838- struct access_method access;
36839+ struct access_method *access;
36840
36841 cmdlist_t *reqQ;
36842 cmdlist_t *cmpQ;
36843diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36844index 2d7f608..11245fe 100644
36845--- a/drivers/block/drbd/drbd_int.h
36846+++ b/drivers/block/drbd/drbd_int.h
36847@@ -582,7 +582,7 @@ struct drbd_epoch {
36848 struct drbd_tconn *tconn;
36849 struct list_head list;
36850 unsigned int barrier_nr;
36851- atomic_t epoch_size; /* increased on every request added. */
36852+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36853 atomic_t active; /* increased on every req. added, and dec on every finished. */
36854 unsigned long flags;
36855 };
36856@@ -1022,7 +1022,7 @@ struct drbd_conf {
36857 unsigned int al_tr_number;
36858 int al_tr_cycle;
36859 wait_queue_head_t seq_wait;
36860- atomic_t packet_seq;
36861+ atomic_unchecked_t packet_seq;
36862 unsigned int peer_seq;
36863 spinlock_t peer_seq_lock;
36864 unsigned int minor;
36865@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36866 char __user *uoptval;
36867 int err;
36868
36869- uoptval = (char __user __force *)optval;
36870+ uoptval = (char __force_user *)optval;
36871
36872 set_fs(KERNEL_DS);
36873 if (level == SOL_SOCKET)
36874diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36875index 55635ed..40e837c 100644
36876--- a/drivers/block/drbd/drbd_main.c
36877+++ b/drivers/block/drbd/drbd_main.c
36878@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36879 p->sector = sector;
36880 p->block_id = block_id;
36881 p->blksize = blksize;
36882- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36883+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36884 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36885 }
36886
36887@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36888 return -EIO;
36889 p->sector = cpu_to_be64(req->i.sector);
36890 p->block_id = (unsigned long)req;
36891- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36892+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36893 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36894 if (mdev->state.conn >= C_SYNC_SOURCE &&
36895 mdev->state.conn <= C_PAUSED_SYNC_T)
36896@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36897 {
36898 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36899
36900- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36901- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36902+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36903+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36904 kfree(tconn->current_epoch);
36905
36906 idr_destroy(&tconn->volumes);
36907diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36908index 8cc1e64..ba7ffa9 100644
36909--- a/drivers/block/drbd/drbd_nl.c
36910+++ b/drivers/block/drbd/drbd_nl.c
36911@@ -3440,7 +3440,7 @@ out:
36912
36913 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36914 {
36915- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36916+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36917 struct sk_buff *msg;
36918 struct drbd_genlmsghdr *d_out;
36919 unsigned seq;
36920@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36921 return;
36922 }
36923
36924- seq = atomic_inc_return(&drbd_genl_seq);
36925+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36926 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36927 if (!msg)
36928 goto failed;
36929diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36930index cc29cd3..d4b058b 100644
36931--- a/drivers/block/drbd/drbd_receiver.c
36932+++ b/drivers/block/drbd/drbd_receiver.c
36933@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36934 {
36935 int err;
36936
36937- atomic_set(&mdev->packet_seq, 0);
36938+ atomic_set_unchecked(&mdev->packet_seq, 0);
36939 mdev->peer_seq = 0;
36940
36941 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36942@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36943 do {
36944 next_epoch = NULL;
36945
36946- epoch_size = atomic_read(&epoch->epoch_size);
36947+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36948
36949 switch (ev & ~EV_CLEANUP) {
36950 case EV_PUT:
36951@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36952 rv = FE_DESTROYED;
36953 } else {
36954 epoch->flags = 0;
36955- atomic_set(&epoch->epoch_size, 0);
36956+ atomic_set_unchecked(&epoch->epoch_size, 0);
36957 /* atomic_set(&epoch->active, 0); is already zero */
36958 if (rv == FE_STILL_LIVE)
36959 rv = FE_RECYCLED;
36960@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36961 conn_wait_active_ee_empty(tconn);
36962 drbd_flush(tconn);
36963
36964- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36965+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36966 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36967 if (epoch)
36968 break;
36969@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36970 }
36971
36972 epoch->flags = 0;
36973- atomic_set(&epoch->epoch_size, 0);
36974+ atomic_set_unchecked(&epoch->epoch_size, 0);
36975 atomic_set(&epoch->active, 0);
36976
36977 spin_lock(&tconn->epoch_lock);
36978- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36979+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36980 list_add(&epoch->list, &tconn->current_epoch->list);
36981 tconn->current_epoch = epoch;
36982 tconn->epochs++;
36983@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36984
36985 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36986 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36987- atomic_inc(&tconn->current_epoch->epoch_size);
36988+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36989 err2 = drbd_drain_block(mdev, pi->size);
36990 if (!err)
36991 err = err2;
36992@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36993
36994 spin_lock(&tconn->epoch_lock);
36995 peer_req->epoch = tconn->current_epoch;
36996- atomic_inc(&peer_req->epoch->epoch_size);
36997+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36998 atomic_inc(&peer_req->epoch->active);
36999 spin_unlock(&tconn->epoch_lock);
37000
37001@@ -4347,7 +4347,7 @@ struct data_cmd {
37002 int expect_payload;
37003 size_t pkt_size;
37004 int (*fn)(struct drbd_tconn *, struct packet_info *);
37005-};
37006+} __do_const;
37007
37008 static struct data_cmd drbd_cmd_handler[] = {
37009 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37010@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37011 if (!list_empty(&tconn->current_epoch->list))
37012 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37013 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37014- atomic_set(&tconn->current_epoch->epoch_size, 0);
37015+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37016 tconn->send.seen_any_write_yet = false;
37017
37018 conn_info(tconn, "Connection closed\n");
37019@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37020 struct asender_cmd {
37021 size_t pkt_size;
37022 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37023-};
37024+} __do_const;
37025
37026 static struct asender_cmd asender_tbl[] = {
37027 [P_PING] = { 0, got_Ping },
37028diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37029index c8dac73..1800093 100644
37030--- a/drivers/block/loop.c
37031+++ b/drivers/block/loop.c
37032@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37033
37034 file_start_write(file);
37035 set_fs(get_ds());
37036- bw = file->f_op->write(file, buf, len, &pos);
37037+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37038 set_fs(old_fs);
37039 file_end_write(file);
37040 if (likely(bw == len))
37041diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37042index 5618847..5a46f3b 100644
37043--- a/drivers/block/pktcdvd.c
37044+++ b/drivers/block/pktcdvd.c
37045@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37046
37047 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37048 {
37049- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37050+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37051 }
37052
37053 /*
37054@@ -1897,7 +1897,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37055 return -EROFS;
37056 }
37057 pd->settings.fp = ti.fp;
37058- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37059+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37060
37061 if (ti.nwa_v) {
37062 pd->nwa = be32_to_cpu(ti.next_writable);
37063diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37064index 60abf59..80789e1 100644
37065--- a/drivers/bluetooth/btwilink.c
37066+++ b/drivers/bluetooth/btwilink.c
37067@@ -293,7 +293,7 @@ static int ti_st_send_frame(struct sk_buff *skb)
37068
37069 static int bt_ti_probe(struct platform_device *pdev)
37070 {
37071- static struct ti_st *hst;
37072+ struct ti_st *hst;
37073 struct hci_dev *hdev;
37074 int err;
37075
37076diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37077index 2009266..7be9ca2 100644
37078--- a/drivers/bus/arm-cci.c
37079+++ b/drivers/bus/arm-cci.c
37080@@ -405,7 +405,7 @@ static int __init cci_probe(void)
37081
37082 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37083
37084- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37085+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37086 if (!ports)
37087 return -ENOMEM;
37088
37089diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37090index 8a3aff7..d7538c2 100644
37091--- a/drivers/cdrom/cdrom.c
37092+++ b/drivers/cdrom/cdrom.c
37093@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37094 ENSURE(reset, CDC_RESET);
37095 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37096 cdi->mc_flags = 0;
37097- cdo->n_minors = 0;
37098 cdi->options = CDO_USE_FFLAGS;
37099
37100 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37101@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37102 else
37103 cdi->cdda_method = CDDA_OLD;
37104
37105- if (!cdo->generic_packet)
37106- cdo->generic_packet = cdrom_dummy_generic_packet;
37107+ if (!cdo->generic_packet) {
37108+ pax_open_kernel();
37109+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37110+ pax_close_kernel();
37111+ }
37112
37113 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37114 mutex_lock(&cdrom_mutex);
37115@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37116 if (cdi->exit)
37117 cdi->exit(cdi);
37118
37119- cdi->ops->n_minors--;
37120 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37121 }
37122
37123@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37124 */
37125 nr = nframes;
37126 do {
37127- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37128+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37129 if (cgc.buffer)
37130 break;
37131
37132@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37133 struct cdrom_device_info *cdi;
37134 int ret;
37135
37136- ret = scnprintf(info + *pos, max_size - *pos, header);
37137+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37138 if (!ret)
37139 return 1;
37140
37141diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37142index 5980cb9..6d7bd7e 100644
37143--- a/drivers/cdrom/gdrom.c
37144+++ b/drivers/cdrom/gdrom.c
37145@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37146 .audio_ioctl = gdrom_audio_ioctl,
37147 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37148 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37149- .n_minors = 1,
37150 };
37151
37152 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37153diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37154index 1421997..33f5d6d 100644
37155--- a/drivers/char/Kconfig
37156+++ b/drivers/char/Kconfig
37157@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37158
37159 config DEVKMEM
37160 bool "/dev/kmem virtual device support"
37161- default y
37162+ default n
37163+ depends on !GRKERNSEC_KMEM
37164 help
37165 Say Y here if you want to support the /dev/kmem device. The
37166 /dev/kmem device is rarely used, but can be used for certain
37167@@ -570,6 +571,7 @@ config DEVPORT
37168 bool
37169 depends on !M68K
37170 depends on ISA || PCI
37171+ depends on !GRKERNSEC_KMEM
37172 default y
37173
37174 source "drivers/s390/char/Kconfig"
37175diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37176index a48e05b..6bac831 100644
37177--- a/drivers/char/agp/compat_ioctl.c
37178+++ b/drivers/char/agp/compat_ioctl.c
37179@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37180 return -ENOMEM;
37181 }
37182
37183- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37184+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37185 sizeof(*usegment) * ureserve.seg_count)) {
37186 kfree(usegment);
37187 kfree(ksegment);
37188diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37189index 1b19239..b87b143 100644
37190--- a/drivers/char/agp/frontend.c
37191+++ b/drivers/char/agp/frontend.c
37192@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37193 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37194 return -EFAULT;
37195
37196- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37197+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37198 return -EFAULT;
37199
37200 client = agp_find_client_by_pid(reserve.pid);
37201@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37202 if (segment == NULL)
37203 return -ENOMEM;
37204
37205- if (copy_from_user(segment, (void __user *) reserve.seg_list,
37206+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37207 sizeof(struct agp_segment) * reserve.seg_count)) {
37208 kfree(segment);
37209 return -EFAULT;
37210diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37211index 4f94375..413694e 100644
37212--- a/drivers/char/genrtc.c
37213+++ b/drivers/char/genrtc.c
37214@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37215 switch (cmd) {
37216
37217 case RTC_PLL_GET:
37218+ memset(&pll, 0, sizeof(pll));
37219 if (get_rtc_pll(&pll))
37220 return -EINVAL;
37221 else
37222diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37223index 448ce5e..3a76625 100644
37224--- a/drivers/char/hpet.c
37225+++ b/drivers/char/hpet.c
37226@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37227 }
37228
37229 static int
37230-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37231+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37232 struct hpet_info *info)
37233 {
37234 struct hpet_timer __iomem *timer;
37235diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37236index 86fe45c..c0ea948 100644
37237--- a/drivers/char/hw_random/intel-rng.c
37238+++ b/drivers/char/hw_random/intel-rng.c
37239@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37240
37241 if (no_fwh_detect)
37242 return -ENODEV;
37243- printk(warning);
37244+ printk("%s", warning);
37245 return -EBUSY;
37246 }
37247
37248diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37249index ec4e10f..f2a763b 100644
37250--- a/drivers/char/ipmi/ipmi_msghandler.c
37251+++ b/drivers/char/ipmi/ipmi_msghandler.c
37252@@ -420,7 +420,7 @@ struct ipmi_smi {
37253 struct proc_dir_entry *proc_dir;
37254 char proc_dir_name[10];
37255
37256- atomic_t stats[IPMI_NUM_STATS];
37257+ atomic_unchecked_t stats[IPMI_NUM_STATS];
37258
37259 /*
37260 * run_to_completion duplicate of smb_info, smi_info
37261@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37262
37263
37264 #define ipmi_inc_stat(intf, stat) \
37265- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37266+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37267 #define ipmi_get_stat(intf, stat) \
37268- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37269+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37270
37271 static int is_lan_addr(struct ipmi_addr *addr)
37272 {
37273@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37274 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37275 init_waitqueue_head(&intf->waitq);
37276 for (i = 0; i < IPMI_NUM_STATS; i++)
37277- atomic_set(&intf->stats[i], 0);
37278+ atomic_set_unchecked(&intf->stats[i], 0);
37279
37280 intf->proc_dir = NULL;
37281
37282diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37283index 15e4a60..b046093 100644
37284--- a/drivers/char/ipmi/ipmi_si_intf.c
37285+++ b/drivers/char/ipmi/ipmi_si_intf.c
37286@@ -280,7 +280,7 @@ struct smi_info {
37287 unsigned char slave_addr;
37288
37289 /* Counters and things for the proc filesystem. */
37290- atomic_t stats[SI_NUM_STATS];
37291+ atomic_unchecked_t stats[SI_NUM_STATS];
37292
37293 struct task_struct *thread;
37294
37295@@ -289,9 +289,9 @@ struct smi_info {
37296 };
37297
37298 #define smi_inc_stat(smi, stat) \
37299- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37300+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37301 #define smi_get_stat(smi, stat) \
37302- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37303+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37304
37305 #define SI_MAX_PARMS 4
37306
37307@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37308 atomic_set(&new_smi->req_events, 0);
37309 new_smi->run_to_completion = 0;
37310 for (i = 0; i < SI_NUM_STATS; i++)
37311- atomic_set(&new_smi->stats[i], 0);
37312+ atomic_set_unchecked(&new_smi->stats[i], 0);
37313
37314 new_smi->interrupt_disabled = 1;
37315 atomic_set(&new_smi->stop_operation, 0);
37316diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37317index f895a8c..2bc9147 100644
37318--- a/drivers/char/mem.c
37319+++ b/drivers/char/mem.c
37320@@ -18,6 +18,7 @@
37321 #include <linux/raw.h>
37322 #include <linux/tty.h>
37323 #include <linux/capability.h>
37324+#include <linux/security.h>
37325 #include <linux/ptrace.h>
37326 #include <linux/device.h>
37327 #include <linux/highmem.h>
37328@@ -37,6 +38,10 @@
37329
37330 #define DEVPORT_MINOR 4
37331
37332+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37333+extern const struct file_operations grsec_fops;
37334+#endif
37335+
37336 static inline unsigned long size_inside_page(unsigned long start,
37337 unsigned long size)
37338 {
37339@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37340
37341 while (cursor < to) {
37342 if (!devmem_is_allowed(pfn)) {
37343+#ifdef CONFIG_GRKERNSEC_KMEM
37344+ gr_handle_mem_readwrite(from, to);
37345+#else
37346 printk(KERN_INFO
37347 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37348 current->comm, from, to);
37349+#endif
37350 return 0;
37351 }
37352 cursor += PAGE_SIZE;
37353@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37354 }
37355 return 1;
37356 }
37357+#elif defined(CONFIG_GRKERNSEC_KMEM)
37358+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37359+{
37360+ return 0;
37361+}
37362 #else
37363 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37364 {
37365@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37366
37367 while (count > 0) {
37368 unsigned long remaining;
37369+ char *temp;
37370
37371 sz = size_inside_page(p, count);
37372
37373@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37374 if (!ptr)
37375 return -EFAULT;
37376
37377- remaining = copy_to_user(buf, ptr, sz);
37378+#ifdef CONFIG_PAX_USERCOPY
37379+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37380+ if (!temp) {
37381+ unxlate_dev_mem_ptr(p, ptr);
37382+ return -ENOMEM;
37383+ }
37384+ memcpy(temp, ptr, sz);
37385+#else
37386+ temp = ptr;
37387+#endif
37388+
37389+ remaining = copy_to_user(buf, temp, sz);
37390+
37391+#ifdef CONFIG_PAX_USERCOPY
37392+ kfree(temp);
37393+#endif
37394+
37395 unxlate_dev_mem_ptr(p, ptr);
37396 if (remaining)
37397 return -EFAULT;
37398@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37399 size_t count, loff_t *ppos)
37400 {
37401 unsigned long p = *ppos;
37402- ssize_t low_count, read, sz;
37403+ ssize_t low_count, read, sz, err = 0;
37404 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37405- int err = 0;
37406
37407 read = 0;
37408 if (p < (unsigned long) high_memory) {
37409@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37410 }
37411 #endif
37412 while (low_count > 0) {
37413+ char *temp;
37414+
37415 sz = size_inside_page(p, low_count);
37416
37417 /*
37418@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37419 */
37420 kbuf = xlate_dev_kmem_ptr((char *)p);
37421
37422- if (copy_to_user(buf, kbuf, sz))
37423+#ifdef CONFIG_PAX_USERCOPY
37424+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37425+ if (!temp)
37426+ return -ENOMEM;
37427+ memcpy(temp, kbuf, sz);
37428+#else
37429+ temp = kbuf;
37430+#endif
37431+
37432+ err = copy_to_user(buf, temp, sz);
37433+
37434+#ifdef CONFIG_PAX_USERCOPY
37435+ kfree(temp);
37436+#endif
37437+
37438+ if (err)
37439 return -EFAULT;
37440 buf += sz;
37441 p += sz;
37442@@ -822,6 +869,9 @@ static const struct memdev {
37443 #ifdef CONFIG_PRINTK
37444 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37445 #endif
37446+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37447+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37448+#endif
37449 };
37450
37451 static int memory_open(struct inode *inode, struct file *filp)
37452@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37453 continue;
37454
37455 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37456- NULL, devlist[minor].name);
37457+ NULL, "%s", devlist[minor].name);
37458 }
37459
37460 return tty_init();
37461diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37462index 9df78e2..01ba9ae 100644
37463--- a/drivers/char/nvram.c
37464+++ b/drivers/char/nvram.c
37465@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37466
37467 spin_unlock_irq(&rtc_lock);
37468
37469- if (copy_to_user(buf, contents, tmp - contents))
37470+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37471 return -EFAULT;
37472
37473 *ppos = i;
37474diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37475index d39cca6..8c1e269 100644
37476--- a/drivers/char/pcmcia/synclink_cs.c
37477+++ b/drivers/char/pcmcia/synclink_cs.c
37478@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37479
37480 if (debug_level >= DEBUG_LEVEL_INFO)
37481 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37482- __FILE__, __LINE__, info->device_name, port->count);
37483+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37484
37485- WARN_ON(!port->count);
37486+ WARN_ON(!atomic_read(&port->count));
37487
37488 if (tty_port_close_start(port, tty, filp) == 0)
37489 goto cleanup;
37490@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37491 cleanup:
37492 if (debug_level >= DEBUG_LEVEL_INFO)
37493 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37494- tty->driver->name, port->count);
37495+ tty->driver->name, atomic_read(&port->count));
37496 }
37497
37498 /* Wait until the transmitter is empty.
37499@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37500
37501 if (debug_level >= DEBUG_LEVEL_INFO)
37502 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37503- __FILE__, __LINE__, tty->driver->name, port->count);
37504+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37505
37506 /* If port is closing, signal caller to try again */
37507 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37508@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37509 goto cleanup;
37510 }
37511 spin_lock(&port->lock);
37512- port->count++;
37513+ atomic_inc(&port->count);
37514 spin_unlock(&port->lock);
37515 spin_unlock_irqrestore(&info->netlock, flags);
37516
37517- if (port->count == 1) {
37518+ if (atomic_read(&port->count) == 1) {
37519 /* 1st open on this device, init hardware */
37520 retval = startup(info, tty);
37521 if (retval < 0)
37522@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37523 unsigned short new_crctype;
37524
37525 /* return error if TTY interface open */
37526- if (info->port.count)
37527+ if (atomic_read(&info->port.count))
37528 return -EBUSY;
37529
37530 switch (encoding)
37531@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37532
37533 /* arbitrate between network and tty opens */
37534 spin_lock_irqsave(&info->netlock, flags);
37535- if (info->port.count != 0 || info->netcount != 0) {
37536+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37537 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37538 spin_unlock_irqrestore(&info->netlock, flags);
37539 return -EBUSY;
37540@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37541 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37542
37543 /* return error if TTY interface open */
37544- if (info->port.count)
37545+ if (atomic_read(&info->port.count))
37546 return -EBUSY;
37547
37548 if (cmd != SIOCWANDEV)
37549diff --git a/drivers/char/random.c b/drivers/char/random.c
37550index 7a744d3..35a177ee 100644
37551--- a/drivers/char/random.c
37552+++ b/drivers/char/random.c
37553@@ -269,8 +269,13 @@
37554 /*
37555 * Configuration information
37556 */
37557+#ifdef CONFIG_GRKERNSEC_RANDNET
37558+#define INPUT_POOL_WORDS 512
37559+#define OUTPUT_POOL_WORDS 128
37560+#else
37561 #define INPUT_POOL_WORDS 128
37562 #define OUTPUT_POOL_WORDS 32
37563+#endif
37564 #define SEC_XFER_SIZE 512
37565 #define EXTRACT_SIZE 10
37566
37567@@ -310,10 +315,17 @@ static struct poolinfo {
37568 int poolwords;
37569 int tap1, tap2, tap3, tap4, tap5;
37570 } poolinfo_table[] = {
37571+#ifdef CONFIG_GRKERNSEC_RANDNET
37572+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37573+ { 512, 411, 308, 208, 104, 1 },
37574+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37575+ { 128, 103, 76, 51, 25, 1 },
37576+#else
37577 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
37578 { 128, 103, 76, 51, 25, 1 },
37579 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
37580 { 32, 26, 20, 14, 7, 1 },
37581+#endif
37582 #if 0
37583 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37584 { 2048, 1638, 1231, 819, 411, 1 },
37585@@ -521,8 +533,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37586 input_rotate += i ? 7 : 14;
37587 }
37588
37589- ACCESS_ONCE(r->input_rotate) = input_rotate;
37590- ACCESS_ONCE(r->add_ptr) = i;
37591+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37592+ ACCESS_ONCE_RW(r->add_ptr) = i;
37593 smp_wmb();
37594
37595 if (out)
37596@@ -1029,7 +1041,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37597
37598 extract_buf(r, tmp);
37599 i = min_t(int, nbytes, EXTRACT_SIZE);
37600- if (copy_to_user(buf, tmp, i)) {
37601+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37602 ret = -EFAULT;
37603 break;
37604 }
37605@@ -1365,7 +1377,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37606 #include <linux/sysctl.h>
37607
37608 static int min_read_thresh = 8, min_write_thresh;
37609-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37610+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37611 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37612 static char sysctl_bootid[16];
37613
37614@@ -1381,7 +1393,7 @@ static char sysctl_bootid[16];
37615 static int proc_do_uuid(struct ctl_table *table, int write,
37616 void __user *buffer, size_t *lenp, loff_t *ppos)
37617 {
37618- struct ctl_table fake_table;
37619+ ctl_table_no_const fake_table;
37620 unsigned char buf[64], tmp_uuid[16], *uuid;
37621
37622 uuid = table->data;
37623diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37624index 7cc1fe22..b602d6b 100644
37625--- a/drivers/char/sonypi.c
37626+++ b/drivers/char/sonypi.c
37627@@ -54,6 +54,7 @@
37628
37629 #include <asm/uaccess.h>
37630 #include <asm/io.h>
37631+#include <asm/local.h>
37632
37633 #include <linux/sonypi.h>
37634
37635@@ -490,7 +491,7 @@ static struct sonypi_device {
37636 spinlock_t fifo_lock;
37637 wait_queue_head_t fifo_proc_list;
37638 struct fasync_struct *fifo_async;
37639- int open_count;
37640+ local_t open_count;
37641 int model;
37642 struct input_dev *input_jog_dev;
37643 struct input_dev *input_key_dev;
37644@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37645 static int sonypi_misc_release(struct inode *inode, struct file *file)
37646 {
37647 mutex_lock(&sonypi_device.lock);
37648- sonypi_device.open_count--;
37649+ local_dec(&sonypi_device.open_count);
37650 mutex_unlock(&sonypi_device.lock);
37651 return 0;
37652 }
37653@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37654 {
37655 mutex_lock(&sonypi_device.lock);
37656 /* Flush input queue on first open */
37657- if (!sonypi_device.open_count)
37658+ if (!local_read(&sonypi_device.open_count))
37659 kfifo_reset(&sonypi_device.fifo);
37660- sonypi_device.open_count++;
37661+ local_inc(&sonypi_device.open_count);
37662 mutex_unlock(&sonypi_device.lock);
37663
37664 return 0;
37665diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37666index 64420b3..5c40b56 100644
37667--- a/drivers/char/tpm/tpm_acpi.c
37668+++ b/drivers/char/tpm/tpm_acpi.c
37669@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37670 virt = acpi_os_map_memory(start, len);
37671 if (!virt) {
37672 kfree(log->bios_event_log);
37673+ log->bios_event_log = NULL;
37674 printk("%s: ERROR - Unable to map memory\n", __func__);
37675 return -EIO;
37676 }
37677
37678- memcpy_fromio(log->bios_event_log, virt, len);
37679+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37680
37681 acpi_os_unmap_memory(virt, len);
37682 return 0;
37683diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37684index 84ddc55..1d32f1e 100644
37685--- a/drivers/char/tpm/tpm_eventlog.c
37686+++ b/drivers/char/tpm/tpm_eventlog.c
37687@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37688 event = addr;
37689
37690 if ((event->event_type == 0 && event->event_size == 0) ||
37691- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37692+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37693 return NULL;
37694
37695 return addr;
37696@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37697 return NULL;
37698
37699 if ((event->event_type == 0 && event->event_size == 0) ||
37700- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37701+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37702 return NULL;
37703
37704 (*pos)++;
37705@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37706 int i;
37707
37708 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37709- seq_putc(m, data[i]);
37710+ if (!seq_putc(m, data[i]))
37711+ return -EFAULT;
37712
37713 return 0;
37714 }
37715diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37716index b79cf3e..de172d64f 100644
37717--- a/drivers/char/virtio_console.c
37718+++ b/drivers/char/virtio_console.c
37719@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37720 if (to_user) {
37721 ssize_t ret;
37722
37723- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37724+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37725 if (ret)
37726 return -EFAULT;
37727 } else {
37728@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37729 if (!port_has_data(port) && !port->host_connected)
37730 return 0;
37731
37732- return fill_readbuf(port, ubuf, count, true);
37733+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37734 }
37735
37736 static int wait_port_writable(struct port *port, bool nonblock)
37737diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37738index a33f46f..a720eed 100644
37739--- a/drivers/clk/clk-composite.c
37740+++ b/drivers/clk/clk-composite.c
37741@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37742 struct clk *clk;
37743 struct clk_init_data init;
37744 struct clk_composite *composite;
37745- struct clk_ops *clk_composite_ops;
37746+ clk_ops_no_const *clk_composite_ops;
37747
37748 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37749 if (!composite) {
37750diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37751index 81dd31a..ef5c542 100644
37752--- a/drivers/clk/socfpga/clk.c
37753+++ b/drivers/clk/socfpga/clk.c
37754@@ -22,6 +22,7 @@
37755 #include <linux/clk-provider.h>
37756 #include <linux/io.h>
37757 #include <linux/of.h>
37758+#include <asm/pgtable.h>
37759
37760 /* Clock Manager offsets */
37761 #define CLKMGR_CTRL 0x0
37762@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37763 streq(clk_name, "periph_pll") ||
37764 streq(clk_name, "sdram_pll")) {
37765 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37766- clk_pll_ops.enable = clk_gate_ops.enable;
37767- clk_pll_ops.disable = clk_gate_ops.disable;
37768+ pax_open_kernel();
37769+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37770+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37771+ pax_close_kernel();
37772 }
37773
37774 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37775@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37776 return parent_rate / div;
37777 }
37778
37779-static struct clk_ops gateclk_ops = {
37780+static clk_ops_no_const gateclk_ops __read_only = {
37781 .recalc_rate = socfpga_clk_recalc_rate,
37782 .get_parent = socfpga_clk_get_parent,
37783 .set_parent = socfpga_clk_set_parent,
37784diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37785index 506fd23..01a593f 100644
37786--- a/drivers/cpufreq/acpi-cpufreq.c
37787+++ b/drivers/cpufreq/acpi-cpufreq.c
37788@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37789 return sprintf(buf, "%u\n", boost_enabled);
37790 }
37791
37792-static struct global_attr global_boost = __ATTR(boost, 0644,
37793+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37794 show_global_boost,
37795 store_global_boost);
37796
37797@@ -721,8 +721,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37798 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37799 per_cpu(acfreq_data, cpu) = data;
37800
37801- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37802- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37803+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37804+ pax_open_kernel();
37805+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37806+ pax_close_kernel();
37807+ }
37808
37809 result = acpi_processor_register_performance(data->acpi_data, cpu);
37810 if (result)
37811@@ -850,7 +853,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37812 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37813 break;
37814 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37815- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37816+ pax_open_kernel();
37817+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37818+ pax_close_kernel();
37819 policy->cur = get_cur_freq_on_cpu(cpu);
37820 break;
37821 default:
37822diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37823index 04548f7..457a342 100644
37824--- a/drivers/cpufreq/cpufreq.c
37825+++ b/drivers/cpufreq/cpufreq.c
37826@@ -2069,7 +2069,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37827 return NOTIFY_OK;
37828 }
37829
37830-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37831+static struct notifier_block cpufreq_cpu_notifier = {
37832 .notifier_call = cpufreq_cpu_callback,
37833 };
37834
37835@@ -2101,8 +2101,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37836
37837 pr_debug("trying to register driver %s\n", driver_data->name);
37838
37839- if (driver_data->setpolicy)
37840- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37841+ if (driver_data->setpolicy) {
37842+ pax_open_kernel();
37843+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37844+ pax_close_kernel();
37845+ }
37846
37847 write_lock_irqsave(&cpufreq_driver_lock, flags);
37848 if (cpufreq_driver) {
37849diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37850index 0806c31..6a73276 100644
37851--- a/drivers/cpufreq/cpufreq_governor.c
37852+++ b/drivers/cpufreq/cpufreq_governor.c
37853@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37854 struct dbs_data *dbs_data;
37855 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37856 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37857- struct od_ops *od_ops = NULL;
37858+ const struct od_ops *od_ops = NULL;
37859 struct od_dbs_tuners *od_tuners = NULL;
37860 struct cs_dbs_tuners *cs_tuners = NULL;
37861 struct cpu_dbs_common_info *cpu_cdbs;
37862@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37863
37864 if ((cdata->governor == GOV_CONSERVATIVE) &&
37865 (!policy->governor->initialized)) {
37866- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37867+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37868
37869 cpufreq_register_notifier(cs_ops->notifier_block,
37870 CPUFREQ_TRANSITION_NOTIFIER);
37871@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37872
37873 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37874 (policy->governor->initialized == 1)) {
37875- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37876+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37877
37878 cpufreq_unregister_notifier(cs_ops->notifier_block,
37879 CPUFREQ_TRANSITION_NOTIFIER);
37880diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37881index 88cd39f..87f0393 100644
37882--- a/drivers/cpufreq/cpufreq_governor.h
37883+++ b/drivers/cpufreq/cpufreq_governor.h
37884@@ -202,7 +202,7 @@ struct common_dbs_data {
37885 void (*exit)(struct dbs_data *dbs_data);
37886
37887 /* Governor specific ops, see below */
37888- void *gov_ops;
37889+ const void *gov_ops;
37890 };
37891
37892 /* Governor Per policy data */
37893@@ -222,7 +222,7 @@ struct od_ops {
37894 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37895 unsigned int freq_next, unsigned int relation);
37896 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
37897-};
37898+} __no_const;
37899
37900 struct cs_ops {
37901 struct notifier_block *notifier_block;
37902diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37903index 32f26f6..feb657b 100644
37904--- a/drivers/cpufreq/cpufreq_ondemand.c
37905+++ b/drivers/cpufreq/cpufreq_ondemand.c
37906@@ -522,7 +522,7 @@ static void od_exit(struct dbs_data *dbs_data)
37907
37908 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37909
37910-static struct od_ops od_ops = {
37911+static struct od_ops od_ops __read_only = {
37912 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37913 .powersave_bias_target = generic_powersave_bias_target,
37914 .freq_increase = dbs_freq_increase,
37915@@ -577,14 +577,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37916 (struct cpufreq_policy *, unsigned int, unsigned int),
37917 unsigned int powersave_bias)
37918 {
37919- od_ops.powersave_bias_target = f;
37920+ pax_open_kernel();
37921+ *(void **)&od_ops.powersave_bias_target = f;
37922+ pax_close_kernel();
37923 od_set_powersave_bias(powersave_bias);
37924 }
37925 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37926
37927 void od_unregister_powersave_bias_handler(void)
37928 {
37929- od_ops.powersave_bias_target = generic_powersave_bias_target;
37930+ pax_open_kernel();
37931+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37932+ pax_close_kernel();
37933 od_set_powersave_bias(0);
37934 }
37935 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37936diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37937index 4cf0d28..5830372 100644
37938--- a/drivers/cpufreq/cpufreq_stats.c
37939+++ b/drivers/cpufreq/cpufreq_stats.c
37940@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37941 }
37942
37943 /* priority=1 so this will get called before cpufreq_remove_dev */
37944-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37945+static struct notifier_block cpufreq_stat_cpu_notifier = {
37946 .notifier_call = cpufreq_stat_cpu_callback,
37947 .priority = 1,
37948 };
37949diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37950index 2f0a2a6..93d728e 100644
37951--- a/drivers/cpufreq/p4-clockmod.c
37952+++ b/drivers/cpufreq/p4-clockmod.c
37953@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37954 case 0x0F: /* Core Duo */
37955 case 0x16: /* Celeron Core */
37956 case 0x1C: /* Atom */
37957- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37958+ pax_open_kernel();
37959+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37960+ pax_close_kernel();
37961 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37962 case 0x0D: /* Pentium M (Dothan) */
37963- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37964+ pax_open_kernel();
37965+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37966+ pax_close_kernel();
37967 /* fall through */
37968 case 0x09: /* Pentium M (Banias) */
37969 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37970@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37971
37972 /* on P-4s, the TSC runs with constant frequency independent whether
37973 * throttling is active or not. */
37974- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37975+ pax_open_kernel();
37976+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37977+ pax_close_kernel();
37978
37979 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37980 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37981diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37982index ac76b48..2445bc6 100644
37983--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37984+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37985@@ -18,14 +18,12 @@
37986 #include <asm/head.h>
37987 #include <asm/timer.h>
37988
37989-static struct cpufreq_driver *cpufreq_us3_driver;
37990-
37991 struct us3_freq_percpu_info {
37992 struct cpufreq_frequency_table table[4];
37993 };
37994
37995 /* Indexed by cpu number. */
37996-static struct us3_freq_percpu_info *us3_freq_table;
37997+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37998
37999 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38000 * in the Safari config register.
38001@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38002
38003 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38004 {
38005- if (cpufreq_us3_driver)
38006- us3_set_cpu_divider_index(policy, 0);
38007+ us3_set_cpu_divider_index(policy->cpu, 0);
38008
38009 return 0;
38010 }
38011
38012+static int __init us3_freq_init(void);
38013+static void __exit us3_freq_exit(void);
38014+
38015+static struct cpufreq_driver cpufreq_us3_driver = {
38016+ .init = us3_freq_cpu_init,
38017+ .verify = us3_freq_verify,
38018+ .target = us3_freq_target,
38019+ .get = us3_freq_get,
38020+ .exit = us3_freq_cpu_exit,
38021+ .owner = THIS_MODULE,
38022+ .name = "UltraSPARC-III",
38023+
38024+};
38025+
38026 static int __init us3_freq_init(void)
38027 {
38028 unsigned long manuf, impl, ver;
38029@@ -208,55 +219,15 @@ static int __init us3_freq_init(void)
38030 (impl == CHEETAH_IMPL ||
38031 impl == CHEETAH_PLUS_IMPL ||
38032 impl == JAGUAR_IMPL ||
38033- impl == PANTHER_IMPL)) {
38034- struct cpufreq_driver *driver;
38035-
38036- ret = -ENOMEM;
38037- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38038- if (!driver)
38039- goto err_out;
38040-
38041- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38042- GFP_KERNEL);
38043- if (!us3_freq_table)
38044- goto err_out;
38045-
38046- driver->init = us3_freq_cpu_init;
38047- driver->verify = us3_freq_verify;
38048- driver->target = us3_freq_target;
38049- driver->get = us3_freq_get;
38050- driver->exit = us3_freq_cpu_exit;
38051- strcpy(driver->name, "UltraSPARC-III");
38052-
38053- cpufreq_us3_driver = driver;
38054- ret = cpufreq_register_driver(driver);
38055- if (ret)
38056- goto err_out;
38057-
38058- return 0;
38059-
38060-err_out:
38061- if (driver) {
38062- kfree(driver);
38063- cpufreq_us3_driver = NULL;
38064- }
38065- kfree(us3_freq_table);
38066- us3_freq_table = NULL;
38067- return ret;
38068- }
38069+ impl == PANTHER_IMPL))
38070+ return cpufreq_register_driver(&cpufreq_us3_driver);
38071
38072 return -ENODEV;
38073 }
38074
38075 static void __exit us3_freq_exit(void)
38076 {
38077- if (cpufreq_us3_driver) {
38078- cpufreq_unregister_driver(cpufreq_us3_driver);
38079- kfree(cpufreq_us3_driver);
38080- cpufreq_us3_driver = NULL;
38081- kfree(us3_freq_table);
38082- us3_freq_table = NULL;
38083- }
38084+ cpufreq_unregister_driver(&cpufreq_us3_driver);
38085 }
38086
38087 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38088diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38089index f897d51..15da295 100644
38090--- a/drivers/cpufreq/speedstep-centrino.c
38091+++ b/drivers/cpufreq/speedstep-centrino.c
38092@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38093 !cpu_has(cpu, X86_FEATURE_EST))
38094 return -ENODEV;
38095
38096- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38097- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38098+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38099+ pax_open_kernel();
38100+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38101+ pax_close_kernel();
38102+ }
38103
38104 if (policy->cpu != 0)
38105 return -ENODEV;
38106diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
38107index 22c07fb..9dff5ac 100644
38108--- a/drivers/cpuidle/cpuidle.c
38109+++ b/drivers/cpuidle/cpuidle.c
38110@@ -252,7 +252,7 @@ static int poll_idle(struct cpuidle_device *dev,
38111
38112 static void poll_idle_init(struct cpuidle_driver *drv)
38113 {
38114- struct cpuidle_state *state = &drv->states[0];
38115+ cpuidle_state_no_const *state = &drv->states[0];
38116
38117 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38118 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38119diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38120index ea2f8e7..70ac501 100644
38121--- a/drivers/cpuidle/governor.c
38122+++ b/drivers/cpuidle/governor.c
38123@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38124 mutex_lock(&cpuidle_lock);
38125 if (__cpuidle_find_governor(gov->name) == NULL) {
38126 ret = 0;
38127- list_add_tail(&gov->governor_list, &cpuidle_governors);
38128+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38129 if (!cpuidle_curr_governor ||
38130 cpuidle_curr_governor->rating < gov->rating)
38131 cpuidle_switch_governor(gov);
38132@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
38133 new_gov = cpuidle_replace_governor(gov->rating);
38134 cpuidle_switch_governor(new_gov);
38135 }
38136- list_del(&gov->governor_list);
38137+ pax_list_del((struct list_head *)&gov->governor_list);
38138 mutex_unlock(&cpuidle_lock);
38139 }
38140
38141diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38142index 8739cc0..dc859d0 100644
38143--- a/drivers/cpuidle/sysfs.c
38144+++ b/drivers/cpuidle/sysfs.c
38145@@ -134,7 +134,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38146 NULL
38147 };
38148
38149-static struct attribute_group cpuidle_attr_group = {
38150+static attribute_group_no_const cpuidle_attr_group = {
38151 .attrs = cpuidle_default_attrs,
38152 .name = "cpuidle",
38153 };
38154diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38155index 12fea3e..1e28f47 100644
38156--- a/drivers/crypto/hifn_795x.c
38157+++ b/drivers/crypto/hifn_795x.c
38158@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38159 MODULE_PARM_DESC(hifn_pll_ref,
38160 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38161
38162-static atomic_t hifn_dev_number;
38163+static atomic_unchecked_t hifn_dev_number;
38164
38165 #define ACRYPTO_OP_DECRYPT 0
38166 #define ACRYPTO_OP_ENCRYPT 1
38167@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38168 goto err_out_disable_pci_device;
38169
38170 snprintf(name, sizeof(name), "hifn%d",
38171- atomic_inc_return(&hifn_dev_number)-1);
38172+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
38173
38174 err = pci_request_regions(pdev, name);
38175 if (err)
38176diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38177index c99c00d..990a4b2 100644
38178--- a/drivers/devfreq/devfreq.c
38179+++ b/drivers/devfreq/devfreq.c
38180@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38181 goto err_out;
38182 }
38183
38184- list_add(&governor->node, &devfreq_governor_list);
38185+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38186
38187 list_for_each_entry(devfreq, &devfreq_list, node) {
38188 int ret = 0;
38189@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38190 }
38191 }
38192
38193- list_del(&governor->node);
38194+ pax_list_del((struct list_head *)&governor->node);
38195 err_out:
38196 mutex_unlock(&devfreq_list_lock);
38197
38198diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38199index 1069e88..dfcd642 100644
38200--- a/drivers/dma/sh/shdmac.c
38201+++ b/drivers/dma/sh/shdmac.c
38202@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38203 return ret;
38204 }
38205
38206-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38207+static struct notifier_block sh_dmae_nmi_notifier = {
38208 .notifier_call = sh_dmae_nmi_handler,
38209
38210 /* Run before NMI debug handler and KGDB */
38211diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38212index 211021d..201d47f 100644
38213--- a/drivers/edac/edac_device.c
38214+++ b/drivers/edac/edac_device.c
38215@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38216 */
38217 int edac_device_alloc_index(void)
38218 {
38219- static atomic_t device_indexes = ATOMIC_INIT(0);
38220+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38221
38222- return atomic_inc_return(&device_indexes) - 1;
38223+ return atomic_inc_return_unchecked(&device_indexes) - 1;
38224 }
38225 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38226
38227diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38228index 9f7e0e60..348c875 100644
38229--- a/drivers/edac/edac_mc_sysfs.c
38230+++ b/drivers/edac/edac_mc_sysfs.c
38231@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38232 struct dev_ch_attribute {
38233 struct device_attribute attr;
38234 int channel;
38235-};
38236+} __do_const;
38237
38238 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38239 struct dev_ch_attribute dev_attr_legacy_##_name = \
38240@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38241 }
38242
38243 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38244+ pax_open_kernel();
38245 if (mci->get_sdram_scrub_rate) {
38246- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38247- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38248+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38249+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38250 }
38251 if (mci->set_sdram_scrub_rate) {
38252- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38253- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38254+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38255+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38256 }
38257+ pax_close_kernel();
38258 err = device_create_file(&mci->dev,
38259 &dev_attr_sdram_scrub_rate);
38260 if (err) {
38261diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38262index dd370f9..0281629 100644
38263--- a/drivers/edac/edac_pci.c
38264+++ b/drivers/edac/edac_pci.c
38265@@ -29,7 +29,7 @@
38266
38267 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38268 static LIST_HEAD(edac_pci_list);
38269-static atomic_t pci_indexes = ATOMIC_INIT(0);
38270+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38271
38272 /*
38273 * edac_pci_alloc_ctl_info
38274@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38275 */
38276 int edac_pci_alloc_index(void)
38277 {
38278- return atomic_inc_return(&pci_indexes) - 1;
38279+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
38280 }
38281 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38282
38283diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38284index e8658e4..22746d6 100644
38285--- a/drivers/edac/edac_pci_sysfs.c
38286+++ b/drivers/edac/edac_pci_sysfs.c
38287@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38288 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38289 static int edac_pci_poll_msec = 1000; /* one second workq period */
38290
38291-static atomic_t pci_parity_count = ATOMIC_INIT(0);
38292-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38293+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38294+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38295
38296 static struct kobject *edac_pci_top_main_kobj;
38297 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38298@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38299 void *value;
38300 ssize_t(*show) (void *, char *);
38301 ssize_t(*store) (void *, const char *, size_t);
38302-};
38303+} __do_const;
38304
38305 /* Set of show/store abstract level functions for PCI Parity object */
38306 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38307@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38308 edac_printk(KERN_CRIT, EDAC_PCI,
38309 "Signaled System Error on %s\n",
38310 pci_name(dev));
38311- atomic_inc(&pci_nonparity_count);
38312+ atomic_inc_unchecked(&pci_nonparity_count);
38313 }
38314
38315 if (status & (PCI_STATUS_PARITY)) {
38316@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38317 "Master Data Parity Error on %s\n",
38318 pci_name(dev));
38319
38320- atomic_inc(&pci_parity_count);
38321+ atomic_inc_unchecked(&pci_parity_count);
38322 }
38323
38324 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38325@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38326 "Detected Parity Error on %s\n",
38327 pci_name(dev));
38328
38329- atomic_inc(&pci_parity_count);
38330+ atomic_inc_unchecked(&pci_parity_count);
38331 }
38332 }
38333
38334@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38335 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38336 "Signaled System Error on %s\n",
38337 pci_name(dev));
38338- atomic_inc(&pci_nonparity_count);
38339+ atomic_inc_unchecked(&pci_nonparity_count);
38340 }
38341
38342 if (status & (PCI_STATUS_PARITY)) {
38343@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38344 "Master Data Parity Error on "
38345 "%s\n", pci_name(dev));
38346
38347- atomic_inc(&pci_parity_count);
38348+ atomic_inc_unchecked(&pci_parity_count);
38349 }
38350
38351 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38352@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38353 "Detected Parity Error on %s\n",
38354 pci_name(dev));
38355
38356- atomic_inc(&pci_parity_count);
38357+ atomic_inc_unchecked(&pci_parity_count);
38358 }
38359 }
38360 }
38361@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38362 if (!check_pci_errors)
38363 return;
38364
38365- before_count = atomic_read(&pci_parity_count);
38366+ before_count = atomic_read_unchecked(&pci_parity_count);
38367
38368 /* scan all PCI devices looking for a Parity Error on devices and
38369 * bridges.
38370@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38371 /* Only if operator has selected panic on PCI Error */
38372 if (edac_pci_get_panic_on_pe()) {
38373 /* If the count is different 'after' from 'before' */
38374- if (before_count != atomic_read(&pci_parity_count))
38375+ if (before_count != atomic_read_unchecked(&pci_parity_count))
38376 panic("EDAC: PCI Parity Error");
38377 }
38378 }
38379diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38380index 51b7e3a..aa8a3e8 100644
38381--- a/drivers/edac/mce_amd.h
38382+++ b/drivers/edac/mce_amd.h
38383@@ -77,7 +77,7 @@ struct amd_decoder_ops {
38384 bool (*mc0_mce)(u16, u8);
38385 bool (*mc1_mce)(u16, u8);
38386 bool (*mc2_mce)(u16, u8);
38387-};
38388+} __no_const;
38389
38390 void amd_report_gart_errors(bool);
38391 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38392diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38393index 57ea7f4..af06b76 100644
38394--- a/drivers/firewire/core-card.c
38395+++ b/drivers/firewire/core-card.c
38396@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38397 const struct fw_card_driver *driver,
38398 struct device *device)
38399 {
38400- static atomic_t index = ATOMIC_INIT(-1);
38401+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
38402
38403- card->index = atomic_inc_return(&index);
38404+ card->index = atomic_inc_return_unchecked(&index);
38405 card->driver = driver;
38406 card->device = device;
38407 card->current_tlabel = 0;
38408@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38409
38410 void fw_core_remove_card(struct fw_card *card)
38411 {
38412- struct fw_card_driver dummy_driver = dummy_driver_template;
38413+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38414
38415 card->driver->update_phy_reg(card, 4,
38416 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38417diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38418index de4aa40..49ab1f2 100644
38419--- a/drivers/firewire/core-device.c
38420+++ b/drivers/firewire/core-device.c
38421@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38422 struct config_rom_attribute {
38423 struct device_attribute attr;
38424 u32 key;
38425-};
38426+} __do_const;
38427
38428 static ssize_t show_immediate(struct device *dev,
38429 struct device_attribute *dattr, char *buf)
38430diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38431index e5af0e3..d318058 100644
38432--- a/drivers/firewire/core-transaction.c
38433+++ b/drivers/firewire/core-transaction.c
38434@@ -38,6 +38,7 @@
38435 #include <linux/timer.h>
38436 #include <linux/types.h>
38437 #include <linux/workqueue.h>
38438+#include <linux/sched.h>
38439
38440 #include <asm/byteorder.h>
38441
38442diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38443index 515a42c..5ecf3ba 100644
38444--- a/drivers/firewire/core.h
38445+++ b/drivers/firewire/core.h
38446@@ -111,6 +111,7 @@ struct fw_card_driver {
38447
38448 int (*stop_iso)(struct fw_iso_context *ctx);
38449 };
38450+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38451
38452 void fw_card_initialize(struct fw_card *card,
38453 const struct fw_card_driver *driver, struct device *device);
38454diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38455index 94a58a0..f5eba42 100644
38456--- a/drivers/firmware/dmi-id.c
38457+++ b/drivers/firmware/dmi-id.c
38458@@ -16,7 +16,7 @@
38459 struct dmi_device_attribute{
38460 struct device_attribute dev_attr;
38461 int field;
38462-};
38463+} __do_const;
38464 #define to_dmi_dev_attr(_dev_attr) \
38465 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38466
38467diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38468index fa0affb..aa448eb 100644
38469--- a/drivers/firmware/dmi_scan.c
38470+++ b/drivers/firmware/dmi_scan.c
38471@@ -791,7 +791,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38472 if (buf == NULL)
38473 return -1;
38474
38475- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38476+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38477
38478 iounmap(buf);
38479 return 0;
38480diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38481index 5145fa3..0d3babd 100644
38482--- a/drivers/firmware/efi/efi.c
38483+++ b/drivers/firmware/efi/efi.c
38484@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38485 };
38486
38487 static struct efivars generic_efivars;
38488-static struct efivar_operations generic_ops;
38489+static efivar_operations_no_const generic_ops __read_only;
38490
38491 static int generic_ops_register(void)
38492 {
38493- generic_ops.get_variable = efi.get_variable;
38494- generic_ops.set_variable = efi.set_variable;
38495- generic_ops.get_next_variable = efi.get_next_variable;
38496- generic_ops.query_variable_store = efi_query_variable_store;
38497+ pax_open_kernel();
38498+ *(void **)&generic_ops.get_variable = efi.get_variable;
38499+ *(void **)&generic_ops.set_variable = efi.set_variable;
38500+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38501+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38502+ pax_close_kernel();
38503
38504 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38505 }
38506diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38507index 8c5a61a..cf07bd0 100644
38508--- a/drivers/firmware/efi/efivars.c
38509+++ b/drivers/firmware/efi/efivars.c
38510@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38511 static int
38512 create_efivars_bin_attributes(void)
38513 {
38514- struct bin_attribute *attr;
38515+ bin_attribute_no_const *attr;
38516 int error;
38517
38518 /* new_var */
38519diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38520index 2a90ba6..07f3733 100644
38521--- a/drivers/firmware/google/memconsole.c
38522+++ b/drivers/firmware/google/memconsole.c
38523@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38524 if (!found_memconsole())
38525 return -ENODEV;
38526
38527- memconsole_bin_attr.size = memconsole_length;
38528+ pax_open_kernel();
38529+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38530+ pax_close_kernel();
38531
38532 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38533
38534diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38535index 814addb..0937d7f 100644
38536--- a/drivers/gpio/gpio-ich.c
38537+++ b/drivers/gpio/gpio-ich.c
38538@@ -71,7 +71,7 @@ struct ichx_desc {
38539 /* Some chipsets have quirks, let these use their own request/get */
38540 int (*request)(struct gpio_chip *chip, unsigned offset);
38541 int (*get)(struct gpio_chip *chip, unsigned offset);
38542-};
38543+} __do_const;
38544
38545 static struct {
38546 spinlock_t lock;
38547diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38548index 9902732..64b62dd 100644
38549--- a/drivers/gpio/gpio-vr41xx.c
38550+++ b/drivers/gpio/gpio-vr41xx.c
38551@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38552 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38553 maskl, pendl, maskh, pendh);
38554
38555- atomic_inc(&irq_err_count);
38556+ atomic_inc_unchecked(&irq_err_count);
38557
38558 return -EINVAL;
38559 }
38560diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38561index c722c3b..2ec6040 100644
38562--- a/drivers/gpu/drm/drm_crtc_helper.c
38563+++ b/drivers/gpu/drm/drm_crtc_helper.c
38564@@ -328,7 +328,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38565 struct drm_crtc *tmp;
38566 int crtc_mask = 1;
38567
38568- WARN(!crtc, "checking null crtc?\n");
38569+ BUG_ON(!crtc);
38570
38571 dev = crtc->dev;
38572
38573diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38574index fe58d08..07bc38e 100644
38575--- a/drivers/gpu/drm/drm_drv.c
38576+++ b/drivers/gpu/drm/drm_drv.c
38577@@ -186,7 +186,7 @@ static void drm_legacy_dev_reinit(struct drm_device *dev)
38578 atomic_set(&dev->vma_count, 0);
38579
38580 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38581- atomic_set(&dev->counts[i], 0);
38582+ atomic_set_unchecked(&dev->counts[i], 0);
38583
38584 dev->sigdata.lock = NULL;
38585
38586@@ -302,7 +302,7 @@ module_exit(drm_core_exit);
38587 /**
38588 * Copy and IOCTL return string to user space
38589 */
38590-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38591+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38592 {
38593 int len;
38594
38595@@ -372,7 +372,7 @@ long drm_ioctl(struct file *filp,
38596 struct drm_file *file_priv = filp->private_data;
38597 struct drm_device *dev;
38598 const struct drm_ioctl_desc *ioctl = NULL;
38599- drm_ioctl_t *func;
38600+ drm_ioctl_no_const_t func;
38601 unsigned int nr = DRM_IOCTL_NR(cmd);
38602 int retcode = -EINVAL;
38603 char stack_kdata[128];
38604@@ -385,7 +385,7 @@ long drm_ioctl(struct file *filp,
38605 return -ENODEV;
38606
38607 atomic_inc(&dev->ioctl_count);
38608- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38609+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38610 ++file_priv->ioctl_count;
38611
38612 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38613diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38614index 3f84277..c627c54 100644
38615--- a/drivers/gpu/drm/drm_fops.c
38616+++ b/drivers/gpu/drm/drm_fops.c
38617@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
38618 if (drm_device_is_unplugged(dev))
38619 return -ENODEV;
38620
38621- if (!dev->open_count++)
38622+ if (local_inc_return(&dev->open_count) == 1)
38623 need_setup = 1;
38624 mutex_lock(&dev->struct_mutex);
38625 old_imapping = inode->i_mapping;
38626@@ -113,7 +113,7 @@ int drm_open(struct inode *inode, struct file *filp)
38627 retcode = drm_open_helper(inode, filp, dev);
38628 if (retcode)
38629 goto err_undo;
38630- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38631+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38632 if (need_setup) {
38633 retcode = drm_setup(dev);
38634 if (retcode)
38635@@ -128,7 +128,7 @@ err_undo:
38636 iput(container_of(dev->dev_mapping, struct inode, i_data));
38637 dev->dev_mapping = old_mapping;
38638 mutex_unlock(&dev->struct_mutex);
38639- dev->open_count--;
38640+ local_dec(&dev->open_count);
38641 return retcode;
38642 }
38643 EXPORT_SYMBOL(drm_open);
38644@@ -405,7 +405,7 @@ int drm_release(struct inode *inode, struct file *filp)
38645
38646 mutex_lock(&drm_global_mutex);
38647
38648- DRM_DEBUG("open_count = %d\n", dev->open_count);
38649+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38650
38651 if (dev->driver->preclose)
38652 dev->driver->preclose(dev, file_priv);
38653@@ -414,10 +414,10 @@ int drm_release(struct inode *inode, struct file *filp)
38654 * Begin inline drm_release
38655 */
38656
38657- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38658+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38659 task_pid_nr(current),
38660 (long)old_encode_dev(file_priv->minor->device),
38661- dev->open_count);
38662+ local_read(&dev->open_count));
38663
38664 /* Release any auth tokens that might point to this file_priv,
38665 (do that under the drm_global_mutex) */
38666@@ -516,8 +516,8 @@ int drm_release(struct inode *inode, struct file *filp)
38667 * End inline drm_release
38668 */
38669
38670- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38671- if (!--dev->open_count) {
38672+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38673+ if (local_dec_and_test(&dev->open_count)) {
38674 if (atomic_read(&dev->ioctl_count)) {
38675 DRM_ERROR("Device busy: %d\n",
38676 atomic_read(&dev->ioctl_count));
38677diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38678index f731116..629842c 100644
38679--- a/drivers/gpu/drm/drm_global.c
38680+++ b/drivers/gpu/drm/drm_global.c
38681@@ -36,7 +36,7 @@
38682 struct drm_global_item {
38683 struct mutex mutex;
38684 void *object;
38685- int refcount;
38686+ atomic_t refcount;
38687 };
38688
38689 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38690@@ -49,7 +49,7 @@ void drm_global_init(void)
38691 struct drm_global_item *item = &glob[i];
38692 mutex_init(&item->mutex);
38693 item->object = NULL;
38694- item->refcount = 0;
38695+ atomic_set(&item->refcount, 0);
38696 }
38697 }
38698
38699@@ -59,7 +59,7 @@ void drm_global_release(void)
38700 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38701 struct drm_global_item *item = &glob[i];
38702 BUG_ON(item->object != NULL);
38703- BUG_ON(item->refcount != 0);
38704+ BUG_ON(atomic_read(&item->refcount) != 0);
38705 }
38706 }
38707
38708@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38709 void *object;
38710
38711 mutex_lock(&item->mutex);
38712- if (item->refcount == 0) {
38713+ if (atomic_read(&item->refcount) == 0) {
38714 item->object = kzalloc(ref->size, GFP_KERNEL);
38715 if (unlikely(item->object == NULL)) {
38716 ret = -ENOMEM;
38717@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38718 goto out_err;
38719
38720 }
38721- ++item->refcount;
38722+ atomic_inc(&item->refcount);
38723 ref->object = item->object;
38724 object = item->object;
38725 mutex_unlock(&item->mutex);
38726@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38727 struct drm_global_item *item = &glob[ref->global_type];
38728
38729 mutex_lock(&item->mutex);
38730- BUG_ON(item->refcount == 0);
38731+ BUG_ON(atomic_read(&item->refcount) == 0);
38732 BUG_ON(ref->object != item->object);
38733- if (--item->refcount == 0) {
38734+ if (atomic_dec_and_test(&item->refcount)) {
38735 ref->release(ref);
38736 item->object = NULL;
38737 }
38738diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38739index 5329832..b503f49 100644
38740--- a/drivers/gpu/drm/drm_info.c
38741+++ b/drivers/gpu/drm/drm_info.c
38742@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38743 struct drm_local_map *map;
38744 struct drm_map_list *r_list;
38745
38746- /* Hardcoded from _DRM_FRAME_BUFFER,
38747- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38748- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38749- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38750+ static const char * const types[] = {
38751+ [_DRM_FRAME_BUFFER] = "FB",
38752+ [_DRM_REGISTERS] = "REG",
38753+ [_DRM_SHM] = "SHM",
38754+ [_DRM_AGP] = "AGP",
38755+ [_DRM_SCATTER_GATHER] = "SG",
38756+ [_DRM_CONSISTENT] = "PCI",
38757+ [_DRM_GEM] = "GEM" };
38758 const char *type;
38759 int i;
38760
38761@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38762 map = r_list->map;
38763 if (!map)
38764 continue;
38765- if (map->type < 0 || map->type > 5)
38766+ if (map->type >= ARRAY_SIZE(types))
38767 type = "??";
38768 else
38769 type = types[map->type];
38770@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38771 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38772 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38773 vma->vm_flags & VM_IO ? 'i' : '-',
38774+#ifdef CONFIG_GRKERNSEC_HIDESYM
38775+ 0);
38776+#else
38777 vma->vm_pgoff);
38778+#endif
38779
38780 #if defined(__i386__)
38781 pgprot = pgprot_val(vma->vm_page_prot);
38782diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38783index 2f4c434..dd12cd2 100644
38784--- a/drivers/gpu/drm/drm_ioc32.c
38785+++ b/drivers/gpu/drm/drm_ioc32.c
38786@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38787 request = compat_alloc_user_space(nbytes);
38788 if (!access_ok(VERIFY_WRITE, request, nbytes))
38789 return -EFAULT;
38790- list = (struct drm_buf_desc *) (request + 1);
38791+ list = (struct drm_buf_desc __user *) (request + 1);
38792
38793 if (__put_user(count, &request->count)
38794 || __put_user(list, &request->list))
38795@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38796 request = compat_alloc_user_space(nbytes);
38797 if (!access_ok(VERIFY_WRITE, request, nbytes))
38798 return -EFAULT;
38799- list = (struct drm_buf_pub *) (request + 1);
38800+ list = (struct drm_buf_pub __user *) (request + 1);
38801
38802 if (__put_user(count, &request->count)
38803 || __put_user(list, &request->list))
38804@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38805 return 0;
38806 }
38807
38808-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38809+drm_ioctl_compat_t drm_compat_ioctls[] = {
38810 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38811 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38812 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38813@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38814 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38815 {
38816 unsigned int nr = DRM_IOCTL_NR(cmd);
38817- drm_ioctl_compat_t *fn;
38818 int ret;
38819
38820 /* Assume that ioctls without an explicit compat routine will just
38821@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38822 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38823 return drm_ioctl(filp, cmd, arg);
38824
38825- fn = drm_compat_ioctls[nr];
38826-
38827- if (fn != NULL)
38828- ret = (*fn) (filp, cmd, arg);
38829+ if (drm_compat_ioctls[nr] != NULL)
38830+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38831 else
38832 ret = drm_ioctl(filp, cmd, arg);
38833
38834diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38835index d752c96..fe08455 100644
38836--- a/drivers/gpu/drm/drm_lock.c
38837+++ b/drivers/gpu/drm/drm_lock.c
38838@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38839 if (drm_lock_take(&master->lock, lock->context)) {
38840 master->lock.file_priv = file_priv;
38841 master->lock.lock_time = jiffies;
38842- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38843+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38844 break; /* Got lock */
38845 }
38846
38847@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38848 return -EINVAL;
38849 }
38850
38851- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38852+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38853
38854 if (drm_lock_free(&master->lock, lock->context)) {
38855 /* FIXME: Should really bail out here. */
38856diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38857index 39d8645..59e06fa 100644
38858--- a/drivers/gpu/drm/drm_stub.c
38859+++ b/drivers/gpu/drm/drm_stub.c
38860@@ -484,7 +484,7 @@ void drm_unplug_dev(struct drm_device *dev)
38861
38862 drm_device_set_unplugged(dev);
38863
38864- if (dev->open_count == 0) {
38865+ if (local_read(&dev->open_count) == 0) {
38866 drm_put_dev(dev);
38867 }
38868 mutex_unlock(&drm_global_mutex);
38869diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38870index 2290b3b..22056a1 100644
38871--- a/drivers/gpu/drm/drm_sysfs.c
38872+++ b/drivers/gpu/drm/drm_sysfs.c
38873@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38874 int drm_sysfs_device_add(struct drm_minor *minor)
38875 {
38876 int err;
38877- char *minor_str;
38878+ const char *minor_str;
38879
38880 minor->kdev.parent = minor->dev->dev;
38881
38882diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38883index ab1892eb..d7009ca 100644
38884--- a/drivers/gpu/drm/i810/i810_dma.c
38885+++ b/drivers/gpu/drm/i810/i810_dma.c
38886@@ -944,8 +944,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38887 dma->buflist[vertex->idx],
38888 vertex->discard, vertex->used);
38889
38890- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38891- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38892+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38893+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38894 sarea_priv->last_enqueue = dev_priv->counter - 1;
38895 sarea_priv->last_dispatch = (int)hw_status[5];
38896
38897@@ -1105,8 +1105,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38898 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38899 mc->last_render);
38900
38901- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38902- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38903+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38904+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38905 sarea_priv->last_enqueue = dev_priv->counter - 1;
38906 sarea_priv->last_dispatch = (int)hw_status[5];
38907
38908diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38909index d4d16ed..8fb0b51 100644
38910--- a/drivers/gpu/drm/i810/i810_drv.h
38911+++ b/drivers/gpu/drm/i810/i810_drv.h
38912@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38913 int page_flipping;
38914
38915 wait_queue_head_t irq_queue;
38916- atomic_t irq_received;
38917- atomic_t irq_emitted;
38918+ atomic_unchecked_t irq_received;
38919+ atomic_unchecked_t irq_emitted;
38920
38921 int front_offset;
38922 } drm_i810_private_t;
38923diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38924index a6f4cb5..6b2beb2 100644
38925--- a/drivers/gpu/drm/i915/i915_debugfs.c
38926+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38927@@ -624,7 +624,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38928 I915_READ(GTIMR));
38929 }
38930 seq_printf(m, "Interrupts received: %d\n",
38931- atomic_read(&dev_priv->irq_received));
38932+ atomic_read_unchecked(&dev_priv->irq_received));
38933 for_each_ring(ring, dev_priv, i) {
38934 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38935 seq_printf(m,
38936diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38937index d5c784d..06e5c36 100644
38938--- a/drivers/gpu/drm/i915/i915_dma.c
38939+++ b/drivers/gpu/drm/i915/i915_dma.c
38940@@ -1263,7 +1263,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38941 bool can_switch;
38942
38943 spin_lock(&dev->count_lock);
38944- can_switch = (dev->open_count == 0);
38945+ can_switch = (local_read(&dev->open_count) == 0);
38946 spin_unlock(&dev->count_lock);
38947 return can_switch;
38948 }
38949diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38950index ab0f2c0..53c1bda 100644
38951--- a/drivers/gpu/drm/i915/i915_drv.h
38952+++ b/drivers/gpu/drm/i915/i915_drv.h
38953@@ -1181,7 +1181,7 @@ typedef struct drm_i915_private {
38954 drm_dma_handle_t *status_page_dmah;
38955 struct resource mch_res;
38956
38957- atomic_t irq_received;
38958+ atomic_unchecked_t irq_received;
38959
38960 /* protects the irq masks */
38961 spinlock_t irq_lock;
38962diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38963index bf34577..3fd2ffa 100644
38964--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38965+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38966@@ -768,9 +768,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38967
38968 static int
38969 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38970- int count)
38971+ unsigned int count)
38972 {
38973- int i;
38974+ unsigned int i;
38975 int relocs_total = 0;
38976 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38977
38978diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38979index 3c59584..500f2e9 100644
38980--- a/drivers/gpu/drm/i915/i915_ioc32.c
38981+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38982@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38983 (unsigned long)request);
38984 }
38985
38986-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38987+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38988 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38989 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38990 [DRM_I915_GETPARAM] = compat_i915_getparam,
38991@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38992 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38993 {
38994 unsigned int nr = DRM_IOCTL_NR(cmd);
38995- drm_ioctl_compat_t *fn = NULL;
38996 int ret;
38997
38998 if (nr < DRM_COMMAND_BASE)
38999 return drm_compat_ioctl(filp, cmd, arg);
39000
39001- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39002- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39003-
39004- if (fn != NULL)
39005+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39006+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39007 ret = (*fn) (filp, cmd, arg);
39008- else
39009+ } else
39010 ret = drm_ioctl(filp, cmd, arg);
39011
39012 return ret;
39013diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39014index 4b91228..590c643 100644
39015--- a/drivers/gpu/drm/i915/i915_irq.c
39016+++ b/drivers/gpu/drm/i915/i915_irq.c
39017@@ -1085,7 +1085,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39018 int pipe;
39019 u32 pipe_stats[I915_MAX_PIPES];
39020
39021- atomic_inc(&dev_priv->irq_received);
39022+ atomic_inc_unchecked(&dev_priv->irq_received);
39023
39024 while (true) {
39025 iir = I915_READ(VLV_IIR);
39026@@ -1390,7 +1390,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39027 irqreturn_t ret = IRQ_NONE;
39028 bool err_int_reenable = false;
39029
39030- atomic_inc(&dev_priv->irq_received);
39031+ atomic_inc_unchecked(&dev_priv->irq_received);
39032
39033 /* We get interrupts on unclaimed registers, so check for this before we
39034 * do any I915_{READ,WRITE}. */
39035@@ -2146,7 +2146,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39036 {
39037 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39038
39039- atomic_set(&dev_priv->irq_received, 0);
39040+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39041
39042 I915_WRITE(HWSTAM, 0xeffe);
39043
39044@@ -2164,7 +2164,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39045 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39046 int pipe;
39047
39048- atomic_set(&dev_priv->irq_received, 0);
39049+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39050
39051 /* VLV magic */
39052 I915_WRITE(VLV_IMR, 0);
39053@@ -2452,7 +2452,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39054 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39055 int pipe;
39056
39057- atomic_set(&dev_priv->irq_received, 0);
39058+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39059
39060 for_each_pipe(pipe)
39061 I915_WRITE(PIPESTAT(pipe), 0);
39062@@ -2530,7 +2530,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39063 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39064 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39065
39066- atomic_inc(&dev_priv->irq_received);
39067+ atomic_inc_unchecked(&dev_priv->irq_received);
39068
39069 iir = I915_READ16(IIR);
39070 if (iir == 0)
39071@@ -2604,7 +2604,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39072 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39073 int pipe;
39074
39075- atomic_set(&dev_priv->irq_received, 0);
39076+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39077
39078 if (I915_HAS_HOTPLUG(dev)) {
39079 I915_WRITE(PORT_HOTPLUG_EN, 0);
39080@@ -2703,7 +2703,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39081 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39082 int pipe, ret = IRQ_NONE;
39083
39084- atomic_inc(&dev_priv->irq_received);
39085+ atomic_inc_unchecked(&dev_priv->irq_received);
39086
39087 iir = I915_READ(IIR);
39088 do {
39089@@ -2827,7 +2827,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39090 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39091 int pipe;
39092
39093- atomic_set(&dev_priv->irq_received, 0);
39094+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39095
39096 I915_WRITE(PORT_HOTPLUG_EN, 0);
39097 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39098@@ -2941,7 +2941,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39099 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39100 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39101
39102- atomic_inc(&dev_priv->irq_received);
39103+ atomic_inc_unchecked(&dev_priv->irq_received);
39104
39105 iir = I915_READ(IIR);
39106
39107diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39108index f535670..bde09e2 100644
39109--- a/drivers/gpu/drm/i915/intel_display.c
39110+++ b/drivers/gpu/drm/i915/intel_display.c
39111@@ -10019,13 +10019,13 @@ struct intel_quirk {
39112 int subsystem_vendor;
39113 int subsystem_device;
39114 void (*hook)(struct drm_device *dev);
39115-};
39116+} __do_const;
39117
39118 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39119 struct intel_dmi_quirk {
39120 void (*hook)(struct drm_device *dev);
39121 const struct dmi_system_id (*dmi_id_list)[];
39122-};
39123+} __do_const;
39124
39125 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39126 {
39127@@ -10033,18 +10033,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39128 return 1;
39129 }
39130
39131-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39132+static const struct dmi_system_id intel_dmi_quirks_table[] = {
39133 {
39134- .dmi_id_list = &(const struct dmi_system_id[]) {
39135- {
39136- .callback = intel_dmi_reverse_brightness,
39137- .ident = "NCR Corporation",
39138- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39139- DMI_MATCH(DMI_PRODUCT_NAME, ""),
39140- },
39141- },
39142- { } /* terminating entry */
39143+ .callback = intel_dmi_reverse_brightness,
39144+ .ident = "NCR Corporation",
39145+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39146+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
39147 },
39148+ },
39149+ { } /* terminating entry */
39150+};
39151+
39152+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39153+ {
39154+ .dmi_id_list = &intel_dmi_quirks_table,
39155 .hook = quirk_invert_brightness,
39156 },
39157 };
39158diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39159index ca4bc54..ee598a2 100644
39160--- a/drivers/gpu/drm/mga/mga_drv.h
39161+++ b/drivers/gpu/drm/mga/mga_drv.h
39162@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39163 u32 clear_cmd;
39164 u32 maccess;
39165
39166- atomic_t vbl_received; /**< Number of vblanks received. */
39167+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39168 wait_queue_head_t fence_queue;
39169- atomic_t last_fence_retired;
39170+ atomic_unchecked_t last_fence_retired;
39171 u32 next_fence_to_post;
39172
39173 unsigned int fb_cpp;
39174diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39175index 709e90d..89a1c0d 100644
39176--- a/drivers/gpu/drm/mga/mga_ioc32.c
39177+++ b/drivers/gpu/drm/mga/mga_ioc32.c
39178@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39179 return 0;
39180 }
39181
39182-drm_ioctl_compat_t *mga_compat_ioctls[] = {
39183+drm_ioctl_compat_t mga_compat_ioctls[] = {
39184 [DRM_MGA_INIT] = compat_mga_init,
39185 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39186 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39187@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39188 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39189 {
39190 unsigned int nr = DRM_IOCTL_NR(cmd);
39191- drm_ioctl_compat_t *fn = NULL;
39192 int ret;
39193
39194 if (nr < DRM_COMMAND_BASE)
39195 return drm_compat_ioctl(filp, cmd, arg);
39196
39197- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39198- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39199-
39200- if (fn != NULL)
39201+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39202+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39203 ret = (*fn) (filp, cmd, arg);
39204- else
39205+ } else
39206 ret = drm_ioctl(filp, cmd, arg);
39207
39208 return ret;
39209diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39210index 598c281..60d590e 100644
39211--- a/drivers/gpu/drm/mga/mga_irq.c
39212+++ b/drivers/gpu/drm/mga/mga_irq.c
39213@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39214 if (crtc != 0)
39215 return 0;
39216
39217- return atomic_read(&dev_priv->vbl_received);
39218+ return atomic_read_unchecked(&dev_priv->vbl_received);
39219 }
39220
39221
39222@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39223 /* VBLANK interrupt */
39224 if (status & MGA_VLINEPEN) {
39225 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39226- atomic_inc(&dev_priv->vbl_received);
39227+ atomic_inc_unchecked(&dev_priv->vbl_received);
39228 drm_handle_vblank(dev, 0);
39229 handled = 1;
39230 }
39231@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39232 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39233 MGA_WRITE(MGA_PRIMEND, prim_end);
39234
39235- atomic_inc(&dev_priv->last_fence_retired);
39236+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
39237 DRM_WAKEUP(&dev_priv->fence_queue);
39238 handled = 1;
39239 }
39240@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39241 * using fences.
39242 */
39243 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39244- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39245+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39246 - *sequence) <= (1 << 23)));
39247
39248 *sequence = cur_fence;
39249diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39250index 3e72876..d1c15ad 100644
39251--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39252+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39253@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39254 struct bit_table {
39255 const char id;
39256 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39257-};
39258+} __no_const;
39259
39260 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39261
39262diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39263index 994fd6e..6e12565 100644
39264--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39265+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39266@@ -94,7 +94,6 @@ struct nouveau_drm {
39267 struct drm_global_reference mem_global_ref;
39268 struct ttm_bo_global_ref bo_global_ref;
39269 struct ttm_bo_device bdev;
39270- atomic_t validate_sequence;
39271 int (*move)(struct nouveau_channel *,
39272 struct ttm_buffer_object *,
39273 struct ttm_mem_reg *, struct ttm_mem_reg *);
39274diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39275index c1a7e5a..38b8539 100644
39276--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39277+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39278@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39279 unsigned long arg)
39280 {
39281 unsigned int nr = DRM_IOCTL_NR(cmd);
39282- drm_ioctl_compat_t *fn = NULL;
39283+ drm_ioctl_compat_t fn = NULL;
39284 int ret;
39285
39286 if (nr < DRM_COMMAND_BASE)
39287diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39288index 81638d7..2e45854 100644
39289--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39290+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39291@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39292 bool can_switch;
39293
39294 spin_lock(&dev->count_lock);
39295- can_switch = (dev->open_count == 0);
39296+ can_switch = (local_read(&dev->open_count) == 0);
39297 spin_unlock(&dev->count_lock);
39298 return can_switch;
39299 }
39300diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39301index eb89653..613cf71 100644
39302--- a/drivers/gpu/drm/qxl/qxl_cmd.c
39303+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39304@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39305 int ret;
39306
39307 mutex_lock(&qdev->async_io_mutex);
39308- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39309+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39310 if (qdev->last_sent_io_cmd > irq_num) {
39311 if (intr)
39312 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39313- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39314+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39315 else
39316 ret = wait_event_timeout(qdev->io_cmd_event,
39317- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39318+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39319 /* 0 is timeout, just bail the "hw" has gone away */
39320 if (ret <= 0)
39321 goto out;
39322- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39323+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39324 }
39325 outb(val, addr);
39326 qdev->last_sent_io_cmd = irq_num + 1;
39327 if (intr)
39328 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39329- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39330+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39331 else
39332 ret = wait_event_timeout(qdev->io_cmd_event,
39333- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39334+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39335 out:
39336 if (ret > 0)
39337 ret = 0;
39338diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39339index c3c2bbd..bc3c0fb 100644
39340--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39341+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39342@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39343 struct drm_info_node *node = (struct drm_info_node *) m->private;
39344 struct qxl_device *qdev = node->minor->dev->dev_private;
39345
39346- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39347- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39348- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39349- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39350+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39351+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39352+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39353+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39354 seq_printf(m, "%d\n", qdev->irq_received_error);
39355 return 0;
39356 }
39357diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39358index f7c9add..fb971d2 100644
39359--- a/drivers/gpu/drm/qxl/qxl_drv.h
39360+++ b/drivers/gpu/drm/qxl/qxl_drv.h
39361@@ -290,10 +290,10 @@ struct qxl_device {
39362 unsigned int last_sent_io_cmd;
39363
39364 /* interrupt handling */
39365- atomic_t irq_received;
39366- atomic_t irq_received_display;
39367- atomic_t irq_received_cursor;
39368- atomic_t irq_received_io_cmd;
39369+ atomic_unchecked_t irq_received;
39370+ atomic_unchecked_t irq_received_display;
39371+ atomic_unchecked_t irq_received_cursor;
39372+ atomic_unchecked_t irq_received_io_cmd;
39373 unsigned irq_received_error;
39374 wait_queue_head_t display_event;
39375 wait_queue_head_t cursor_event;
39376diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39377index 21393dc..329f3a9 100644
39378--- a/drivers/gpu/drm/qxl/qxl_irq.c
39379+++ b/drivers/gpu/drm/qxl/qxl_irq.c
39380@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39381
39382 pending = xchg(&qdev->ram_header->int_pending, 0);
39383
39384- atomic_inc(&qdev->irq_received);
39385+ atomic_inc_unchecked(&qdev->irq_received);
39386
39387 if (pending & QXL_INTERRUPT_DISPLAY) {
39388- atomic_inc(&qdev->irq_received_display);
39389+ atomic_inc_unchecked(&qdev->irq_received_display);
39390 wake_up_all(&qdev->display_event);
39391 qxl_queue_garbage_collect(qdev, false);
39392 }
39393 if (pending & QXL_INTERRUPT_CURSOR) {
39394- atomic_inc(&qdev->irq_received_cursor);
39395+ atomic_inc_unchecked(&qdev->irq_received_cursor);
39396 wake_up_all(&qdev->cursor_event);
39397 }
39398 if (pending & QXL_INTERRUPT_IO_CMD) {
39399- atomic_inc(&qdev->irq_received_io_cmd);
39400+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
39401 wake_up_all(&qdev->io_cmd_event);
39402 }
39403 if (pending & QXL_INTERRUPT_ERROR) {
39404@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
39405 init_waitqueue_head(&qdev->io_cmd_event);
39406 INIT_WORK(&qdev->client_monitors_config_work,
39407 qxl_client_monitors_config_work_func);
39408- atomic_set(&qdev->irq_received, 0);
39409- atomic_set(&qdev->irq_received_display, 0);
39410- atomic_set(&qdev->irq_received_cursor, 0);
39411- atomic_set(&qdev->irq_received_io_cmd, 0);
39412+ atomic_set_unchecked(&qdev->irq_received, 0);
39413+ atomic_set_unchecked(&qdev->irq_received_display, 0);
39414+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
39415+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
39416 qdev->irq_received_error = 0;
39417 ret = drm_irq_install(qdev->ddev);
39418 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
39419diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
39420index 037786d..2a95e33 100644
39421--- a/drivers/gpu/drm/qxl/qxl_ttm.c
39422+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
39423@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
39424 }
39425 }
39426
39427-static struct vm_operations_struct qxl_ttm_vm_ops;
39428+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
39429 static const struct vm_operations_struct *ttm_vm_ops;
39430
39431 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39432@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
39433 return r;
39434 if (unlikely(ttm_vm_ops == NULL)) {
39435 ttm_vm_ops = vma->vm_ops;
39436+ pax_open_kernel();
39437 qxl_ttm_vm_ops = *ttm_vm_ops;
39438 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
39439+ pax_close_kernel();
39440 }
39441 vma->vm_ops = &qxl_ttm_vm_ops;
39442 return 0;
39443@@ -558,25 +560,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
39444 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
39445 {
39446 #if defined(CONFIG_DEBUG_FS)
39447- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
39448- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
39449- unsigned i;
39450+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
39451+ {
39452+ .name = "qxl_mem_mm",
39453+ .show = &qxl_mm_dump_table,
39454+ },
39455+ {
39456+ .name = "qxl_surf_mm",
39457+ .show = &qxl_mm_dump_table,
39458+ }
39459+ };
39460
39461- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
39462- if (i == 0)
39463- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
39464- else
39465- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
39466- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
39467- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
39468- qxl_mem_types_list[i].driver_features = 0;
39469- if (i == 0)
39470- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39471- else
39472- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39473+ pax_open_kernel();
39474+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39475+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39476+ pax_close_kernel();
39477
39478- }
39479- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
39480+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
39481 #else
39482 return 0;
39483 #endif
39484diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
39485index c451257..0ad2134 100644
39486--- a/drivers/gpu/drm/r128/r128_cce.c
39487+++ b/drivers/gpu/drm/r128/r128_cce.c
39488@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
39489
39490 /* GH: Simple idle check.
39491 */
39492- atomic_set(&dev_priv->idle_count, 0);
39493+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39494
39495 /* We don't support anything other than bus-mastering ring mode,
39496 * but the ring can be in either AGP or PCI space for the ring
39497diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
39498index 56eb5e3..c4ec43d 100644
39499--- a/drivers/gpu/drm/r128/r128_drv.h
39500+++ b/drivers/gpu/drm/r128/r128_drv.h
39501@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
39502 int is_pci;
39503 unsigned long cce_buffers_offset;
39504
39505- atomic_t idle_count;
39506+ atomic_unchecked_t idle_count;
39507
39508 int page_flipping;
39509 int current_page;
39510 u32 crtc_offset;
39511 u32 crtc_offset_cntl;
39512
39513- atomic_t vbl_received;
39514+ atomic_unchecked_t vbl_received;
39515
39516 u32 color_fmt;
39517 unsigned int front_offset;
39518diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
39519index a954c54..9cc595c 100644
39520--- a/drivers/gpu/drm/r128/r128_ioc32.c
39521+++ b/drivers/gpu/drm/r128/r128_ioc32.c
39522@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
39523 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
39524 }
39525
39526-drm_ioctl_compat_t *r128_compat_ioctls[] = {
39527+drm_ioctl_compat_t r128_compat_ioctls[] = {
39528 [DRM_R128_INIT] = compat_r128_init,
39529 [DRM_R128_DEPTH] = compat_r128_depth,
39530 [DRM_R128_STIPPLE] = compat_r128_stipple,
39531@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39532 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39533 {
39534 unsigned int nr = DRM_IOCTL_NR(cmd);
39535- drm_ioctl_compat_t *fn = NULL;
39536 int ret;
39537
39538 if (nr < DRM_COMMAND_BASE)
39539 return drm_compat_ioctl(filp, cmd, arg);
39540
39541- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39542- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39543-
39544- if (fn != NULL)
39545+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39546+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39547 ret = (*fn) (filp, cmd, arg);
39548- else
39549+ } else
39550 ret = drm_ioctl(filp, cmd, arg);
39551
39552 return ret;
39553diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39554index 2ea4f09..d391371 100644
39555--- a/drivers/gpu/drm/r128/r128_irq.c
39556+++ b/drivers/gpu/drm/r128/r128_irq.c
39557@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39558 if (crtc != 0)
39559 return 0;
39560
39561- return atomic_read(&dev_priv->vbl_received);
39562+ return atomic_read_unchecked(&dev_priv->vbl_received);
39563 }
39564
39565 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39566@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39567 /* VBLANK interrupt */
39568 if (status & R128_CRTC_VBLANK_INT) {
39569 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39570- atomic_inc(&dev_priv->vbl_received);
39571+ atomic_inc_unchecked(&dev_priv->vbl_received);
39572 drm_handle_vblank(dev, 0);
39573 return IRQ_HANDLED;
39574 }
39575diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39576index 01dd9ae..6352f04 100644
39577--- a/drivers/gpu/drm/r128/r128_state.c
39578+++ b/drivers/gpu/drm/r128/r128_state.c
39579@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39580
39581 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39582 {
39583- if (atomic_read(&dev_priv->idle_count) == 0)
39584+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39585 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39586 else
39587- atomic_set(&dev_priv->idle_count, 0);
39588+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39589 }
39590
39591 #endif
39592diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39593index af85299..ed9ac8d 100644
39594--- a/drivers/gpu/drm/radeon/mkregtable.c
39595+++ b/drivers/gpu/drm/radeon/mkregtable.c
39596@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
39597 regex_t mask_rex;
39598 regmatch_t match[4];
39599 char buf[1024];
39600- size_t end;
39601+ long end;
39602 int len;
39603 int done = 0;
39604 int r;
39605 unsigned o;
39606 struct offset *offset;
39607 char last_reg_s[10];
39608- int last_reg;
39609+ unsigned long last_reg;
39610
39611 if (regcomp
39612 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39613diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39614index 841d0e0..9eaa268 100644
39615--- a/drivers/gpu/drm/radeon/radeon_device.c
39616+++ b/drivers/gpu/drm/radeon/radeon_device.c
39617@@ -1117,7 +1117,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39618 bool can_switch;
39619
39620 spin_lock(&dev->count_lock);
39621- can_switch = (dev->open_count == 0);
39622+ can_switch = (local_read(&dev->open_count) == 0);
39623 spin_unlock(&dev->count_lock);
39624 return can_switch;
39625 }
39626diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39627index b369d42..8dd04eb 100644
39628--- a/drivers/gpu/drm/radeon/radeon_drv.h
39629+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39630@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39631
39632 /* SW interrupt */
39633 wait_queue_head_t swi_queue;
39634- atomic_t swi_emitted;
39635+ atomic_unchecked_t swi_emitted;
39636 int vblank_crtc;
39637 uint32_t irq_enable_reg;
39638 uint32_t r500_disp_irq_reg;
39639diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39640index c180df8..5fd8186 100644
39641--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39642+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39643@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39644 request = compat_alloc_user_space(sizeof(*request));
39645 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39646 || __put_user(req32.param, &request->param)
39647- || __put_user((void __user *)(unsigned long)req32.value,
39648+ || __put_user((unsigned long)req32.value,
39649 &request->value))
39650 return -EFAULT;
39651
39652@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39653 #define compat_radeon_cp_setparam NULL
39654 #endif /* X86_64 || IA64 */
39655
39656-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39657+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39658 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39659 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39660 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39661@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39662 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39663 {
39664 unsigned int nr = DRM_IOCTL_NR(cmd);
39665- drm_ioctl_compat_t *fn = NULL;
39666 int ret;
39667
39668 if (nr < DRM_COMMAND_BASE)
39669 return drm_compat_ioctl(filp, cmd, arg);
39670
39671- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39672- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39673-
39674- if (fn != NULL)
39675+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39676+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39677 ret = (*fn) (filp, cmd, arg);
39678- else
39679+ } else
39680 ret = drm_ioctl(filp, cmd, arg);
39681
39682 return ret;
39683diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39684index 8d68e97..9dcfed8 100644
39685--- a/drivers/gpu/drm/radeon/radeon_irq.c
39686+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39687@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39688 unsigned int ret;
39689 RING_LOCALS;
39690
39691- atomic_inc(&dev_priv->swi_emitted);
39692- ret = atomic_read(&dev_priv->swi_emitted);
39693+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39694+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39695
39696 BEGIN_RING(4);
39697 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39698@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39699 drm_radeon_private_t *dev_priv =
39700 (drm_radeon_private_t *) dev->dev_private;
39701
39702- atomic_set(&dev_priv->swi_emitted, 0);
39703+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39704 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39705
39706 dev->max_vblank_count = 0x001fffff;
39707diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39708index 4d20910..6726b6d 100644
39709--- a/drivers/gpu/drm/radeon/radeon_state.c
39710+++ b/drivers/gpu/drm/radeon/radeon_state.c
39711@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39712 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39713 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39714
39715- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39716+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39717 sarea_priv->nbox * sizeof(depth_boxes[0])))
39718 return -EFAULT;
39719
39720@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39721 {
39722 drm_radeon_private_t *dev_priv = dev->dev_private;
39723 drm_radeon_getparam_t *param = data;
39724- int value;
39725+ int value = 0;
39726
39727 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39728
39729diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39730index 71245d6..94c556d 100644
39731--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39732+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39733@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39734 man->size = size >> PAGE_SHIFT;
39735 }
39736
39737-static struct vm_operations_struct radeon_ttm_vm_ops;
39738+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39739 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39740
39741 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39742@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39743 }
39744 if (unlikely(ttm_vm_ops == NULL)) {
39745 ttm_vm_ops = vma->vm_ops;
39746+ pax_open_kernel();
39747 radeon_ttm_vm_ops = *ttm_vm_ops;
39748 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39749+ pax_close_kernel();
39750 }
39751 vma->vm_ops = &radeon_ttm_vm_ops;
39752 return 0;
39753@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39754 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39755 {
39756 #if defined(CONFIG_DEBUG_FS)
39757- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39758- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39759- unsigned i;
39760+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39761+ {
39762+ .name = "radeon_vram_mm",
39763+ .show = &radeon_mm_dump_table,
39764+ },
39765+ {
39766+ .name = "radeon_gtt_mm",
39767+ .show = &radeon_mm_dump_table,
39768+ },
39769+ {
39770+ .name = "ttm_page_pool",
39771+ .show = &ttm_page_alloc_debugfs,
39772+ },
39773+ {
39774+ .name = "ttm_dma_page_pool",
39775+ .show = &ttm_dma_page_alloc_debugfs,
39776+ },
39777+ };
39778+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
39779
39780- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39781- if (i == 0)
39782- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39783- else
39784- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39785- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39786- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39787- radeon_mem_types_list[i].driver_features = 0;
39788- if (i == 0)
39789- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39790- else
39791- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39792-
39793- }
39794- /* Add ttm page pool to debugfs */
39795- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39796- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39797- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39798- radeon_mem_types_list[i].driver_features = 0;
39799- radeon_mem_types_list[i++].data = NULL;
39800+ pax_open_kernel();
39801+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39802+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39803+ pax_close_kernel();
39804 #ifdef CONFIG_SWIOTLB
39805- if (swiotlb_nr_tbl()) {
39806- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39807- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39808- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39809- radeon_mem_types_list[i].driver_features = 0;
39810- radeon_mem_types_list[i++].data = NULL;
39811- }
39812+ if (swiotlb_nr_tbl())
39813+ i++;
39814 #endif
39815 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39816
39817diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39818index 1447d79..40b2a5b 100644
39819--- a/drivers/gpu/drm/radeon/rs690.c
39820+++ b/drivers/gpu/drm/radeon/rs690.c
39821@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39822 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39823 rdev->pm.sideport_bandwidth.full)
39824 max_bandwidth = rdev->pm.sideport_bandwidth;
39825- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39826+ read_delay_latency.full = dfixed_const(800 * 1000);
39827 read_delay_latency.full = dfixed_div(read_delay_latency,
39828 rdev->pm.igp_sideport_mclk);
39829+ a.full = dfixed_const(370);
39830+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39831 } else {
39832 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39833 rdev->pm.k8_bandwidth.full)
39834diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39835index dbc2def..0a9f710 100644
39836--- a/drivers/gpu/drm/ttm/ttm_memory.c
39837+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39838@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39839 zone->glob = glob;
39840 glob->zone_kernel = zone;
39841 ret = kobject_init_and_add(
39842- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39843+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39844 if (unlikely(ret != 0)) {
39845 kobject_put(&zone->kobj);
39846 return ret;
39847@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39848 zone->glob = glob;
39849 glob->zone_dma32 = zone;
39850 ret = kobject_init_and_add(
39851- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39852+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39853 if (unlikely(ret != 0)) {
39854 kobject_put(&zone->kobj);
39855 return ret;
39856diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39857index 863bef9..cba15cf 100644
39858--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39859+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39860@@ -391,9 +391,9 @@ out:
39861 static unsigned long
39862 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
39863 {
39864- static atomic_t start_pool = ATOMIC_INIT(0);
39865+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39866 unsigned i;
39867- unsigned pool_offset = atomic_add_return(1, &start_pool);
39868+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39869 struct ttm_page_pool *pool;
39870 int shrink_pages = sc->nr_to_scan;
39871 unsigned long freed = 0;
39872diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39873index 97e9d61..bf23c461 100644
39874--- a/drivers/gpu/drm/udl/udl_fb.c
39875+++ b/drivers/gpu/drm/udl/udl_fb.c
39876@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39877 fb_deferred_io_cleanup(info);
39878 kfree(info->fbdefio);
39879 info->fbdefio = NULL;
39880- info->fbops->fb_mmap = udl_fb_mmap;
39881 }
39882
39883 pr_warn("released /dev/fb%d user=%d count=%d\n",
39884diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39885index a811ef2..ff99b05 100644
39886--- a/drivers/gpu/drm/via/via_drv.h
39887+++ b/drivers/gpu/drm/via/via_drv.h
39888@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39889 typedef uint32_t maskarray_t[5];
39890
39891 typedef struct drm_via_irq {
39892- atomic_t irq_received;
39893+ atomic_unchecked_t irq_received;
39894 uint32_t pending_mask;
39895 uint32_t enable_mask;
39896 wait_queue_head_t irq_queue;
39897@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39898 struct timeval last_vblank;
39899 int last_vblank_valid;
39900 unsigned usec_per_vblank;
39901- atomic_t vbl_received;
39902+ atomic_unchecked_t vbl_received;
39903 drm_via_state_t hc_state;
39904 char pci_buf[VIA_PCI_BUF_SIZE];
39905 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39906diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39907index ac98964..5dbf512 100644
39908--- a/drivers/gpu/drm/via/via_irq.c
39909+++ b/drivers/gpu/drm/via/via_irq.c
39910@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39911 if (crtc != 0)
39912 return 0;
39913
39914- return atomic_read(&dev_priv->vbl_received);
39915+ return atomic_read_unchecked(&dev_priv->vbl_received);
39916 }
39917
39918 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39919@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39920
39921 status = VIA_READ(VIA_REG_INTERRUPT);
39922 if (status & VIA_IRQ_VBLANK_PENDING) {
39923- atomic_inc(&dev_priv->vbl_received);
39924- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39925+ atomic_inc_unchecked(&dev_priv->vbl_received);
39926+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39927 do_gettimeofday(&cur_vblank);
39928 if (dev_priv->last_vblank_valid) {
39929 dev_priv->usec_per_vblank =
39930@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39931 dev_priv->last_vblank = cur_vblank;
39932 dev_priv->last_vblank_valid = 1;
39933 }
39934- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39935+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39936 DRM_DEBUG("US per vblank is: %u\n",
39937 dev_priv->usec_per_vblank);
39938 }
39939@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39940
39941 for (i = 0; i < dev_priv->num_irqs; ++i) {
39942 if (status & cur_irq->pending_mask) {
39943- atomic_inc(&cur_irq->irq_received);
39944+ atomic_inc_unchecked(&cur_irq->irq_received);
39945 DRM_WAKEUP(&cur_irq->irq_queue);
39946 handled = 1;
39947 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39948@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39949 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39950 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39951 masks[irq][4]));
39952- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39953+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39954 } else {
39955 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39956 (((cur_irq_sequence =
39957- atomic_read(&cur_irq->irq_received)) -
39958+ atomic_read_unchecked(&cur_irq->irq_received)) -
39959 *sequence) <= (1 << 23)));
39960 }
39961 *sequence = cur_irq_sequence;
39962@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39963 }
39964
39965 for (i = 0; i < dev_priv->num_irqs; ++i) {
39966- atomic_set(&cur_irq->irq_received, 0);
39967+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39968 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39969 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39970 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39971@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39972 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39973 case VIA_IRQ_RELATIVE:
39974 irqwait->request.sequence +=
39975- atomic_read(&cur_irq->irq_received);
39976+ atomic_read_unchecked(&cur_irq->irq_received);
39977 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39978 case VIA_IRQ_ABSOLUTE:
39979 break;
39980diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39981index 150ec64..f5165f2 100644
39982--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39983+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39984@@ -290,7 +290,7 @@ struct vmw_private {
39985 * Fencing and IRQs.
39986 */
39987
39988- atomic_t marker_seq;
39989+ atomic_unchecked_t marker_seq;
39990 wait_queue_head_t fence_queue;
39991 wait_queue_head_t fifo_queue;
39992 int fence_queue_waiters; /* Protected by hw_mutex */
39993diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39994index 3eb1486..0a47ee9 100644
39995--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39996+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39997@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39998 (unsigned int) min,
39999 (unsigned int) fifo->capabilities);
40000
40001- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40002+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40003 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40004 vmw_marker_queue_init(&fifo->marker_queue);
40005 return vmw_fifo_send_fence(dev_priv, &dummy);
40006@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40007 if (reserveable)
40008 iowrite32(bytes, fifo_mem +
40009 SVGA_FIFO_RESERVED);
40010- return fifo_mem + (next_cmd >> 2);
40011+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40012 } else {
40013 need_bounce = true;
40014 }
40015@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40016
40017 fm = vmw_fifo_reserve(dev_priv, bytes);
40018 if (unlikely(fm == NULL)) {
40019- *seqno = atomic_read(&dev_priv->marker_seq);
40020+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40021 ret = -ENOMEM;
40022 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40023 false, 3*HZ);
40024@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40025 }
40026
40027 do {
40028- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40029+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40030 } while (*seqno == 0);
40031
40032 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40033diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40034index c509d40..3b640c3 100644
40035--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40036+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40037@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40038 int ret;
40039
40040 num_clips = arg->num_clips;
40041- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40042+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40043
40044 if (unlikely(num_clips == 0))
40045 return 0;
40046@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40047 int ret;
40048
40049 num_clips = arg->num_clips;
40050- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40051+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40052
40053 if (unlikely(num_clips == 0))
40054 return 0;
40055diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40056index 4640adb..e1384ed 100644
40057--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40058+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40059@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40060 * emitted. Then the fence is stale and signaled.
40061 */
40062
40063- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40064+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40065 > VMW_FENCE_WRAP);
40066
40067 return ret;
40068@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40069
40070 if (fifo_idle)
40071 down_read(&fifo_state->rwsem);
40072- signal_seq = atomic_read(&dev_priv->marker_seq);
40073+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40074 ret = 0;
40075
40076 for (;;) {
40077diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40078index 8a8725c2..afed796 100644
40079--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40080+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40081@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40082 while (!vmw_lag_lt(queue, us)) {
40083 spin_lock(&queue->lock);
40084 if (list_empty(&queue->head))
40085- seqno = atomic_read(&dev_priv->marker_seq);
40086+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40087 else {
40088 marker = list_first_entry(&queue->head,
40089 struct vmw_marker, head);
40090diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
40091index b1a05ad..1c9d899 100644
40092--- a/drivers/gpu/host1x/drm/dc.c
40093+++ b/drivers/gpu/host1x/drm/dc.c
40094@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40095 }
40096
40097 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40098- dc->debugfs_files[i].data = dc;
40099+ *(void **)&dc->debugfs_files[i].data = dc;
40100
40101 err = drm_debugfs_create_files(dc->debugfs_files,
40102 ARRAY_SIZE(debugfs_files),
40103diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40104index ec0ae2d..dc0780b 100644
40105--- a/drivers/gpu/vga/vga_switcheroo.c
40106+++ b/drivers/gpu/vga/vga_switcheroo.c
40107@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40108
40109 /* this version is for the case where the power switch is separate
40110 to the device being powered down. */
40111-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40112+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40113 {
40114 /* copy over all the bus versions */
40115 if (dev->bus && dev->bus->pm) {
40116@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40117 return ret;
40118 }
40119
40120-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40121+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40122 {
40123 /* copy over all the bus versions */
40124 if (dev->bus && dev->bus->pm) {
40125diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40126index aedfe50..1dc929b 100644
40127--- a/drivers/hid/hid-core.c
40128+++ b/drivers/hid/hid-core.c
40129@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40130
40131 int hid_add_device(struct hid_device *hdev)
40132 {
40133- static atomic_t id = ATOMIC_INIT(0);
40134+ static atomic_unchecked_t id = ATOMIC_INIT(0);
40135 int ret;
40136
40137 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40138@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40139 /* XXX hack, any other cleaner solution after the driver core
40140 * is converted to allow more than 20 bytes as the device name? */
40141 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40142- hdev->vendor, hdev->product, atomic_inc_return(&id));
40143+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40144
40145 hid_debug_register(hdev, dev_name(&hdev->dev));
40146 ret = device_add(&hdev->dev);
40147diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40148index c13fb5b..55a3802 100644
40149--- a/drivers/hid/hid-wiimote-debug.c
40150+++ b/drivers/hid/hid-wiimote-debug.c
40151@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40152 else if (size == 0)
40153 return -EIO;
40154
40155- if (copy_to_user(u, buf, size))
40156+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
40157 return -EFAULT;
40158
40159 *off += size;
40160diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40161index cedc6da..2c3da2a 100644
40162--- a/drivers/hid/uhid.c
40163+++ b/drivers/hid/uhid.c
40164@@ -47,7 +47,7 @@ struct uhid_device {
40165 struct mutex report_lock;
40166 wait_queue_head_t report_wait;
40167 atomic_t report_done;
40168- atomic_t report_id;
40169+ atomic_unchecked_t report_id;
40170 struct uhid_event report_buf;
40171 };
40172
40173@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40174
40175 spin_lock_irqsave(&uhid->qlock, flags);
40176 ev->type = UHID_FEATURE;
40177- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40178+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40179 ev->u.feature.rnum = rnum;
40180 ev->u.feature.rtype = report_type;
40181
40182@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40183 spin_lock_irqsave(&uhid->qlock, flags);
40184
40185 /* id for old report; drop it silently */
40186- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40187+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40188 goto unlock;
40189 if (atomic_read(&uhid->report_done))
40190 goto unlock;
40191diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40192index 6de6c98..18319e9 100644
40193--- a/drivers/hv/channel.c
40194+++ b/drivers/hv/channel.c
40195@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40196 int ret = 0;
40197 int t;
40198
40199- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40200- atomic_inc(&vmbus_connection.next_gpadl_handle);
40201+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40202+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40203
40204 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40205 if (ret)
40206diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40207index 88f4096..e50452e 100644
40208--- a/drivers/hv/hv.c
40209+++ b/drivers/hv/hv.c
40210@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40211 u64 output_address = (output) ? virt_to_phys(output) : 0;
40212 u32 output_address_hi = output_address >> 32;
40213 u32 output_address_lo = output_address & 0xFFFFFFFF;
40214- void *hypercall_page = hv_context.hypercall_page;
40215+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40216
40217 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40218 "=a"(hv_status_lo) : "d" (control_hi),
40219diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40220index 7e17a54..a50a33d 100644
40221--- a/drivers/hv/hv_balloon.c
40222+++ b/drivers/hv/hv_balloon.c
40223@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40224
40225 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40226 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40227-static atomic_t trans_id = ATOMIC_INIT(0);
40228+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40229
40230 static int dm_ring_size = (5 * PAGE_SIZE);
40231
40232@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40233 pr_info("Memory hot add failed\n");
40234
40235 dm->state = DM_INITIALIZED;
40236- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40237+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40238 vmbus_sendpacket(dm->dev->channel, &resp,
40239 sizeof(struct dm_hot_add_response),
40240 (unsigned long)NULL,
40241@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40242 memset(&status, 0, sizeof(struct dm_status));
40243 status.hdr.type = DM_STATUS_REPORT;
40244 status.hdr.size = sizeof(struct dm_status);
40245- status.hdr.trans_id = atomic_inc_return(&trans_id);
40246+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40247
40248 /*
40249 * The host expects the guest to report free memory.
40250@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40251 * send the status. This can happen if we were interrupted
40252 * after we picked our transaction ID.
40253 */
40254- if (status.hdr.trans_id != atomic_read(&trans_id))
40255+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40256 return;
40257
40258 vmbus_sendpacket(dm->dev->channel, &status,
40259@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40260 */
40261
40262 do {
40263- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40264+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40265 ret = vmbus_sendpacket(dm_device.dev->channel,
40266 bl_resp,
40267 bl_resp->hdr.size,
40268@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40269
40270 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40271 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40272- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40273+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40274 resp.hdr.size = sizeof(struct dm_unballoon_response);
40275
40276 vmbus_sendpacket(dm_device.dev->channel, &resp,
40277@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40278 memset(&version_req, 0, sizeof(struct dm_version_request));
40279 version_req.hdr.type = DM_VERSION_REQUEST;
40280 version_req.hdr.size = sizeof(struct dm_version_request);
40281- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40282+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40283 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40284 version_req.is_last_attempt = 1;
40285
40286@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40287 memset(&version_req, 0, sizeof(struct dm_version_request));
40288 version_req.hdr.type = DM_VERSION_REQUEST;
40289 version_req.hdr.size = sizeof(struct dm_version_request);
40290- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40291+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40292 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40293 version_req.is_last_attempt = 0;
40294
40295@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40296 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40297 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40298 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40299- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40300+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40301
40302 cap_msg.caps.cap_bits.balloon = 1;
40303 cap_msg.caps.cap_bits.hot_add = 1;
40304diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40305index d84918f..7f38f9f 100644
40306--- a/drivers/hv/hyperv_vmbus.h
40307+++ b/drivers/hv/hyperv_vmbus.h
40308@@ -595,7 +595,7 @@ enum vmbus_connect_state {
40309 struct vmbus_connection {
40310 enum vmbus_connect_state conn_state;
40311
40312- atomic_t next_gpadl_handle;
40313+ atomic_unchecked_t next_gpadl_handle;
40314
40315 /*
40316 * Represents channel interrupts. Each bit position represents a
40317diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40318index f9fe46f..356b119 100644
40319--- a/drivers/hv/vmbus_drv.c
40320+++ b/drivers/hv/vmbus_drv.c
40321@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40322 {
40323 int ret = 0;
40324
40325- static atomic_t device_num = ATOMIC_INIT(0);
40326+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40327
40328 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40329- atomic_inc_return(&device_num));
40330+ atomic_inc_return_unchecked(&device_num));
40331
40332 child_device_obj->device.bus = &hv_bus;
40333 child_device_obj->device.parent = &hv_acpi_dev->dev;
40334diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40335index a9e3d01..9dd246e 100644
40336--- a/drivers/hwmon/acpi_power_meter.c
40337+++ b/drivers/hwmon/acpi_power_meter.c
40338@@ -117,7 +117,7 @@ struct sensor_template {
40339 struct device_attribute *devattr,
40340 const char *buf, size_t count);
40341 int index;
40342-};
40343+} __do_const;
40344
40345 /* Averaging interval */
40346 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40347@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40348 struct sensor_template *attrs)
40349 {
40350 struct device *dev = &resource->acpi_dev->dev;
40351- struct sensor_device_attribute *sensors =
40352+ sensor_device_attribute_no_const *sensors =
40353 &resource->sensors[resource->num_sensors];
40354 int res = 0;
40355
40356diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40357index 3288f13..71cfb4e 100644
40358--- a/drivers/hwmon/applesmc.c
40359+++ b/drivers/hwmon/applesmc.c
40360@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40361 {
40362 struct applesmc_node_group *grp;
40363 struct applesmc_dev_attr *node;
40364- struct attribute *attr;
40365+ attribute_no_const *attr;
40366 int ret, i;
40367
40368 for (grp = groups; grp->format; grp++) {
40369diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40370index b25c643..a13460d 100644
40371--- a/drivers/hwmon/asus_atk0110.c
40372+++ b/drivers/hwmon/asus_atk0110.c
40373@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40374 struct atk_sensor_data {
40375 struct list_head list;
40376 struct atk_data *data;
40377- struct device_attribute label_attr;
40378- struct device_attribute input_attr;
40379- struct device_attribute limit1_attr;
40380- struct device_attribute limit2_attr;
40381+ device_attribute_no_const label_attr;
40382+ device_attribute_no_const input_attr;
40383+ device_attribute_no_const limit1_attr;
40384+ device_attribute_no_const limit2_attr;
40385 char label_attr_name[ATTR_NAME_SIZE];
40386 char input_attr_name[ATTR_NAME_SIZE];
40387 char limit1_attr_name[ATTR_NAME_SIZE];
40388@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40389 static struct device_attribute atk_name_attr =
40390 __ATTR(name, 0444, atk_name_show, NULL);
40391
40392-static void atk_init_attribute(struct device_attribute *attr, char *name,
40393+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40394 sysfs_show_func show)
40395 {
40396 sysfs_attr_init(&attr->attr);
40397diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40398index 78be661..4dd032f 100644
40399--- a/drivers/hwmon/coretemp.c
40400+++ b/drivers/hwmon/coretemp.c
40401@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40402 return NOTIFY_OK;
40403 }
40404
40405-static struct notifier_block coretemp_cpu_notifier __refdata = {
40406+static struct notifier_block coretemp_cpu_notifier = {
40407 .notifier_call = coretemp_cpu_callback,
40408 };
40409
40410diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40411index 632f1dc..57e6a58 100644
40412--- a/drivers/hwmon/ibmaem.c
40413+++ b/drivers/hwmon/ibmaem.c
40414@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40415 struct aem_rw_sensor_template *rw)
40416 {
40417 struct device *dev = &data->pdev->dev;
40418- struct sensor_device_attribute *sensors = data->sensors;
40419+ sensor_device_attribute_no_const *sensors = data->sensors;
40420 int err;
40421
40422 /* Set up read-only sensors */
40423diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40424index 708081b..fe2d4ab 100644
40425--- a/drivers/hwmon/iio_hwmon.c
40426+++ b/drivers/hwmon/iio_hwmon.c
40427@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40428 {
40429 struct device *dev = &pdev->dev;
40430 struct iio_hwmon_state *st;
40431- struct sensor_device_attribute *a;
40432+ sensor_device_attribute_no_const *a;
40433 int ret, i;
40434 int in_i = 1, temp_i = 1, curr_i = 1;
40435 enum iio_chan_type type;
40436diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
40437index 6eb03ce..bea7e3e 100644
40438--- a/drivers/hwmon/nct6775.c
40439+++ b/drivers/hwmon/nct6775.c
40440@@ -936,10 +936,10 @@ static struct attribute_group *
40441 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
40442 int repeat)
40443 {
40444- struct attribute_group *group;
40445+ attribute_group_no_const *group;
40446 struct sensor_device_attr_u *su;
40447- struct sensor_device_attribute *a;
40448- struct sensor_device_attribute_2 *a2;
40449+ sensor_device_attribute_no_const *a;
40450+ sensor_device_attribute_2_no_const *a2;
40451 struct attribute **attrs;
40452 struct sensor_device_template **t;
40453 int err, i, j, count;
40454diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40455index 9319fcf..189ff45 100644
40456--- a/drivers/hwmon/pmbus/pmbus_core.c
40457+++ b/drivers/hwmon/pmbus/pmbus_core.c
40458@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40459 return 0;
40460 }
40461
40462-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40463+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40464 const char *name,
40465 umode_t mode,
40466 ssize_t (*show)(struct device *dev,
40467@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40468 dev_attr->store = store;
40469 }
40470
40471-static void pmbus_attr_init(struct sensor_device_attribute *a,
40472+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40473 const char *name,
40474 umode_t mode,
40475 ssize_t (*show)(struct device *dev,
40476@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40477 u16 reg, u8 mask)
40478 {
40479 struct pmbus_boolean *boolean;
40480- struct sensor_device_attribute *a;
40481+ sensor_device_attribute_no_const *a;
40482
40483 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40484 if (!boolean)
40485@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40486 bool update, bool readonly)
40487 {
40488 struct pmbus_sensor *sensor;
40489- struct device_attribute *a;
40490+ device_attribute_no_const *a;
40491
40492 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40493 if (!sensor)
40494@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40495 const char *lstring, int index)
40496 {
40497 struct pmbus_label *label;
40498- struct device_attribute *a;
40499+ device_attribute_no_const *a;
40500
40501 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40502 if (!label)
40503diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40504index 97cd45a..ac54d8b 100644
40505--- a/drivers/hwmon/sht15.c
40506+++ b/drivers/hwmon/sht15.c
40507@@ -169,7 +169,7 @@ struct sht15_data {
40508 int supply_uv;
40509 bool supply_uv_valid;
40510 struct work_struct update_supply_work;
40511- atomic_t interrupt_handled;
40512+ atomic_unchecked_t interrupt_handled;
40513 };
40514
40515 /**
40516@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40517 ret = gpio_direction_input(data->pdata->gpio_data);
40518 if (ret)
40519 return ret;
40520- atomic_set(&data->interrupt_handled, 0);
40521+ atomic_set_unchecked(&data->interrupt_handled, 0);
40522
40523 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40524 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40525 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40526 /* Only relevant if the interrupt hasn't occurred. */
40527- if (!atomic_read(&data->interrupt_handled))
40528+ if (!atomic_read_unchecked(&data->interrupt_handled))
40529 schedule_work(&data->read_work);
40530 }
40531 ret = wait_event_timeout(data->wait_queue,
40532@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40533
40534 /* First disable the interrupt */
40535 disable_irq_nosync(irq);
40536- atomic_inc(&data->interrupt_handled);
40537+ atomic_inc_unchecked(&data->interrupt_handled);
40538 /* Then schedule a reading work struct */
40539 if (data->state != SHT15_READING_NOTHING)
40540 schedule_work(&data->read_work);
40541@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40542 * If not, then start the interrupt again - care here as could
40543 * have gone low in meantime so verify it hasn't!
40544 */
40545- atomic_set(&data->interrupt_handled, 0);
40546+ atomic_set_unchecked(&data->interrupt_handled, 0);
40547 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40548 /* If still not occurred or another handler was scheduled */
40549 if (gpio_get_value(data->pdata->gpio_data)
40550- || atomic_read(&data->interrupt_handled))
40551+ || atomic_read_unchecked(&data->interrupt_handled))
40552 return;
40553 }
40554
40555diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40556index 38944e9..ae9e5ed 100644
40557--- a/drivers/hwmon/via-cputemp.c
40558+++ b/drivers/hwmon/via-cputemp.c
40559@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40560 return NOTIFY_OK;
40561 }
40562
40563-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40564+static struct notifier_block via_cputemp_cpu_notifier = {
40565 .notifier_call = via_cputemp_cpu_callback,
40566 };
40567
40568diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40569index 07f01ac..d79ad3d 100644
40570--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40571+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40572@@ -43,7 +43,7 @@
40573 extern struct i2c_adapter amd756_smbus;
40574
40575 static struct i2c_adapter *s4882_adapter;
40576-static struct i2c_algorithm *s4882_algo;
40577+static i2c_algorithm_no_const *s4882_algo;
40578
40579 /* Wrapper access functions for multiplexed SMBus */
40580 static DEFINE_MUTEX(amd756_lock);
40581diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
40582index dae3ddf..26e21d1 100644
40583--- a/drivers/i2c/busses/i2c-diolan-u2c.c
40584+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
40585@@ -99,7 +99,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
40586 /* usb layer */
40587
40588 /* Send command to device, and get response. */
40589-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
40590+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
40591 {
40592 int ret = 0;
40593 int actual;
40594diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40595index 2ca268d..c6acbdf 100644
40596--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40597+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40598@@ -41,7 +41,7 @@
40599 extern struct i2c_adapter *nforce2_smbus;
40600
40601 static struct i2c_adapter *s4985_adapter;
40602-static struct i2c_algorithm *s4985_algo;
40603+static i2c_algorithm_no_const *s4985_algo;
40604
40605 /* Wrapper access functions for multiplexed SMBus */
40606 static DEFINE_MUTEX(nforce2_lock);
40607diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40608index c3ccdea..5b3dc1a 100644
40609--- a/drivers/i2c/i2c-dev.c
40610+++ b/drivers/i2c/i2c-dev.c
40611@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40612 break;
40613 }
40614
40615- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40616+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40617 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40618 if (IS_ERR(rdwr_pa[i].buf)) {
40619 res = PTR_ERR(rdwr_pa[i].buf);
40620diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40621index 0b510ba..4fbb5085 100644
40622--- a/drivers/ide/ide-cd.c
40623+++ b/drivers/ide/ide-cd.c
40624@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40625 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40626 if ((unsigned long)buf & alignment
40627 || blk_rq_bytes(rq) & q->dma_pad_mask
40628- || object_is_on_stack(buf))
40629+ || object_starts_on_stack(buf))
40630 drive->dma = 0;
40631 }
40632 }
40633diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40634index f95c697..0a1b05c 100644
40635--- a/drivers/iio/industrialio-core.c
40636+++ b/drivers/iio/industrialio-core.c
40637@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40638 }
40639
40640 static
40641-int __iio_device_attr_init(struct device_attribute *dev_attr,
40642+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40643 const char *postfix,
40644 struct iio_chan_spec const *chan,
40645 ssize_t (*readfunc)(struct device *dev,
40646diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40647index 784b97c..c9ceadf 100644
40648--- a/drivers/infiniband/core/cm.c
40649+++ b/drivers/infiniband/core/cm.c
40650@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40651
40652 struct cm_counter_group {
40653 struct kobject obj;
40654- atomic_long_t counter[CM_ATTR_COUNT];
40655+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40656 };
40657
40658 struct cm_counter_attribute {
40659@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40660 struct ib_mad_send_buf *msg = NULL;
40661 int ret;
40662
40663- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40664+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40665 counter[CM_REQ_COUNTER]);
40666
40667 /* Quick state check to discard duplicate REQs. */
40668@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40669 if (!cm_id_priv)
40670 return;
40671
40672- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40673+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40674 counter[CM_REP_COUNTER]);
40675 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40676 if (ret)
40677@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40678 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40679 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40680 spin_unlock_irq(&cm_id_priv->lock);
40681- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40682+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40683 counter[CM_RTU_COUNTER]);
40684 goto out;
40685 }
40686@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40687 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40688 dreq_msg->local_comm_id);
40689 if (!cm_id_priv) {
40690- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40691+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40692 counter[CM_DREQ_COUNTER]);
40693 cm_issue_drep(work->port, work->mad_recv_wc);
40694 return -EINVAL;
40695@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40696 case IB_CM_MRA_REP_RCVD:
40697 break;
40698 case IB_CM_TIMEWAIT:
40699- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40700+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40701 counter[CM_DREQ_COUNTER]);
40702 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40703 goto unlock;
40704@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40705 cm_free_msg(msg);
40706 goto deref;
40707 case IB_CM_DREQ_RCVD:
40708- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40709+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40710 counter[CM_DREQ_COUNTER]);
40711 goto unlock;
40712 default:
40713@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40714 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40715 cm_id_priv->msg, timeout)) {
40716 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40717- atomic_long_inc(&work->port->
40718+ atomic_long_inc_unchecked(&work->port->
40719 counter_group[CM_RECV_DUPLICATES].
40720 counter[CM_MRA_COUNTER]);
40721 goto out;
40722@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40723 break;
40724 case IB_CM_MRA_REQ_RCVD:
40725 case IB_CM_MRA_REP_RCVD:
40726- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40727+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40728 counter[CM_MRA_COUNTER]);
40729 /* fall through */
40730 default:
40731@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40732 case IB_CM_LAP_IDLE:
40733 break;
40734 case IB_CM_MRA_LAP_SENT:
40735- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40736+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40737 counter[CM_LAP_COUNTER]);
40738 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40739 goto unlock;
40740@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40741 cm_free_msg(msg);
40742 goto deref;
40743 case IB_CM_LAP_RCVD:
40744- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40745+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40746 counter[CM_LAP_COUNTER]);
40747 goto unlock;
40748 default:
40749@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40750 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40751 if (cur_cm_id_priv) {
40752 spin_unlock_irq(&cm.lock);
40753- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40754+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40755 counter[CM_SIDR_REQ_COUNTER]);
40756 goto out; /* Duplicate message. */
40757 }
40758@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40759 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40760 msg->retries = 1;
40761
40762- atomic_long_add(1 + msg->retries,
40763+ atomic_long_add_unchecked(1 + msg->retries,
40764 &port->counter_group[CM_XMIT].counter[attr_index]);
40765 if (msg->retries)
40766- atomic_long_add(msg->retries,
40767+ atomic_long_add_unchecked(msg->retries,
40768 &port->counter_group[CM_XMIT_RETRIES].
40769 counter[attr_index]);
40770
40771@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40772 }
40773
40774 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40775- atomic_long_inc(&port->counter_group[CM_RECV].
40776+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40777 counter[attr_id - CM_ATTR_ID_OFFSET]);
40778
40779 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40780@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40781 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40782
40783 return sprintf(buf, "%ld\n",
40784- atomic_long_read(&group->counter[cm_attr->index]));
40785+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40786 }
40787
40788 static const struct sysfs_ops cm_counter_ops = {
40789diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40790index 9f5ad7c..588cd84 100644
40791--- a/drivers/infiniband/core/fmr_pool.c
40792+++ b/drivers/infiniband/core/fmr_pool.c
40793@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40794
40795 struct task_struct *thread;
40796
40797- atomic_t req_ser;
40798- atomic_t flush_ser;
40799+ atomic_unchecked_t req_ser;
40800+ atomic_unchecked_t flush_ser;
40801
40802 wait_queue_head_t force_wait;
40803 };
40804@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40805 struct ib_fmr_pool *pool = pool_ptr;
40806
40807 do {
40808- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40809+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40810 ib_fmr_batch_release(pool);
40811
40812- atomic_inc(&pool->flush_ser);
40813+ atomic_inc_unchecked(&pool->flush_ser);
40814 wake_up_interruptible(&pool->force_wait);
40815
40816 if (pool->flush_function)
40817@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40818 }
40819
40820 set_current_state(TASK_INTERRUPTIBLE);
40821- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40822+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40823 !kthread_should_stop())
40824 schedule();
40825 __set_current_state(TASK_RUNNING);
40826@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40827 pool->dirty_watermark = params->dirty_watermark;
40828 pool->dirty_len = 0;
40829 spin_lock_init(&pool->pool_lock);
40830- atomic_set(&pool->req_ser, 0);
40831- atomic_set(&pool->flush_ser, 0);
40832+ atomic_set_unchecked(&pool->req_ser, 0);
40833+ atomic_set_unchecked(&pool->flush_ser, 0);
40834 init_waitqueue_head(&pool->force_wait);
40835
40836 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40837@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40838 }
40839 spin_unlock_irq(&pool->pool_lock);
40840
40841- serial = atomic_inc_return(&pool->req_ser);
40842+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40843 wake_up_process(pool->thread);
40844
40845 if (wait_event_interruptible(pool->force_wait,
40846- atomic_read(&pool->flush_ser) - serial >= 0))
40847+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40848 return -EINTR;
40849
40850 return 0;
40851@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40852 } else {
40853 list_add_tail(&fmr->list, &pool->dirty_list);
40854 if (++pool->dirty_len >= pool->dirty_watermark) {
40855- atomic_inc(&pool->req_ser);
40856+ atomic_inc_unchecked(&pool->req_ser);
40857 wake_up_process(pool->thread);
40858 }
40859 }
40860diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40861index 4cb8eb2..146bf60 100644
40862--- a/drivers/infiniband/hw/cxgb4/mem.c
40863+++ b/drivers/infiniband/hw/cxgb4/mem.c
40864@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40865 int err;
40866 struct fw_ri_tpte tpt;
40867 u32 stag_idx;
40868- static atomic_t key;
40869+ static atomic_unchecked_t key;
40870
40871 if (c4iw_fatal_error(rdev))
40872 return -EIO;
40873@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40874 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40875 rdev->stats.stag.max = rdev->stats.stag.cur;
40876 mutex_unlock(&rdev->stats.lock);
40877- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40878+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40879 }
40880 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40881 __func__, stag_state, type, pdid, stag_idx);
40882diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40883index 79b3dbc..96e5fcc 100644
40884--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40885+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40886@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40887 struct ib_atomic_eth *ateth;
40888 struct ipath_ack_entry *e;
40889 u64 vaddr;
40890- atomic64_t *maddr;
40891+ atomic64_unchecked_t *maddr;
40892 u64 sdata;
40893 u32 rkey;
40894 u8 next;
40895@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40896 IB_ACCESS_REMOTE_ATOMIC)))
40897 goto nack_acc_unlck;
40898 /* Perform atomic OP and save result. */
40899- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40900+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40901 sdata = be64_to_cpu(ateth->swap_data);
40902 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40903 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40904- (u64) atomic64_add_return(sdata, maddr) - sdata :
40905+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40906 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40907 be64_to_cpu(ateth->compare_data),
40908 sdata);
40909diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40910index 1f95bba..9530f87 100644
40911--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40912+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40913@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40914 unsigned long flags;
40915 struct ib_wc wc;
40916 u64 sdata;
40917- atomic64_t *maddr;
40918+ atomic64_unchecked_t *maddr;
40919 enum ib_wc_status send_status;
40920
40921 /*
40922@@ -382,11 +382,11 @@ again:
40923 IB_ACCESS_REMOTE_ATOMIC)))
40924 goto acc_err;
40925 /* Perform atomic OP and save result. */
40926- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40927+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40928 sdata = wqe->wr.wr.atomic.compare_add;
40929 *(u64 *) sqp->s_sge.sge.vaddr =
40930 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40931- (u64) atomic64_add_return(sdata, maddr) - sdata :
40932+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40933 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40934 sdata, wqe->wr.wr.atomic.swap);
40935 goto send_comp;
40936diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40937index f2a3f48..673ec79 100644
40938--- a/drivers/infiniband/hw/mlx4/mad.c
40939+++ b/drivers/infiniband/hw/mlx4/mad.c
40940@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40941
40942 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40943 {
40944- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40945+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40946 cpu_to_be64(0xff00000000000000LL);
40947 }
40948
40949diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40950index 25b2cdf..099ff97 100644
40951--- a/drivers/infiniband/hw/mlx4/mcg.c
40952+++ b/drivers/infiniband/hw/mlx4/mcg.c
40953@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40954 {
40955 char name[20];
40956
40957- atomic_set(&ctx->tid, 0);
40958+ atomic_set_unchecked(&ctx->tid, 0);
40959 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40960 ctx->mcg_wq = create_singlethread_workqueue(name);
40961 if (!ctx->mcg_wq)
40962diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40963index 036b663..c9a8c73 100644
40964--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40965+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40966@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
40967 struct list_head mcg_mgid0_list;
40968 struct workqueue_struct *mcg_wq;
40969 struct mlx4_ib_demux_pv_ctx **tun;
40970- atomic_t tid;
40971+ atomic_unchecked_t tid;
40972 int flushing; /* flushing the work queue */
40973 };
40974
40975diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40976index 9d3e5c1..6f166df 100644
40977--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40978+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40979@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40980 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40981 }
40982
40983-int mthca_QUERY_FW(struct mthca_dev *dev)
40984+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40985 {
40986 struct mthca_mailbox *mailbox;
40987 u32 *outbox;
40988@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40989 CMD_TIME_CLASS_B);
40990 }
40991
40992-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40993+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40994 int num_mtt)
40995 {
40996 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
40997@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
40998 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
40999 }
41000
41001-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41002+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41003 int eq_num)
41004 {
41005 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41006@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41007 CMD_TIME_CLASS_B);
41008 }
41009
41010-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41011+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41012 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41013 void *in_mad, void *response_mad)
41014 {
41015diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41016index 87897b9..7e79542 100644
41017--- a/drivers/infiniband/hw/mthca/mthca_main.c
41018+++ b/drivers/infiniband/hw/mthca/mthca_main.c
41019@@ -692,7 +692,7 @@ err_close:
41020 return err;
41021 }
41022
41023-static int mthca_setup_hca(struct mthca_dev *dev)
41024+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41025 {
41026 int err;
41027
41028diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41029index ed9a989..6aa5dc2 100644
41030--- a/drivers/infiniband/hw/mthca/mthca_mr.c
41031+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41032@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41033 * through the bitmaps)
41034 */
41035
41036-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41037+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41038 {
41039 int o;
41040 int m;
41041@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41042 return key;
41043 }
41044
41045-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41046+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41047 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41048 {
41049 struct mthca_mailbox *mailbox;
41050@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41051 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41052 }
41053
41054-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41055+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41056 u64 *buffer_list, int buffer_size_shift,
41057 int list_len, u64 iova, u64 total_size,
41058 u32 access, struct mthca_mr *mr)
41059diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41060index 5b71d43..35a9e14 100644
41061--- a/drivers/infiniband/hw/mthca/mthca_provider.c
41062+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41063@@ -763,7 +763,7 @@ unlock:
41064 return 0;
41065 }
41066
41067-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41068+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41069 {
41070 struct mthca_dev *dev = to_mdev(ibcq->device);
41071 struct mthca_cq *cq = to_mcq(ibcq);
41072diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41073index 4291410..d2ab1fb 100644
41074--- a/drivers/infiniband/hw/nes/nes.c
41075+++ b/drivers/infiniband/hw/nes/nes.c
41076@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41077 LIST_HEAD(nes_adapter_list);
41078 static LIST_HEAD(nes_dev_list);
41079
41080-atomic_t qps_destroyed;
41081+atomic_unchecked_t qps_destroyed;
41082
41083 static unsigned int ee_flsh_adapter;
41084 static unsigned int sysfs_nonidx_addr;
41085@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41086 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41087 struct nes_adapter *nesadapter = nesdev->nesadapter;
41088
41089- atomic_inc(&qps_destroyed);
41090+ atomic_inc_unchecked(&qps_destroyed);
41091
41092 /* Free the control structures */
41093
41094diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41095index 33cc589..3bd6538 100644
41096--- a/drivers/infiniband/hw/nes/nes.h
41097+++ b/drivers/infiniband/hw/nes/nes.h
41098@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41099 extern unsigned int wqm_quanta;
41100 extern struct list_head nes_adapter_list;
41101
41102-extern atomic_t cm_connects;
41103-extern atomic_t cm_accepts;
41104-extern atomic_t cm_disconnects;
41105-extern atomic_t cm_closes;
41106-extern atomic_t cm_connecteds;
41107-extern atomic_t cm_connect_reqs;
41108-extern atomic_t cm_rejects;
41109-extern atomic_t mod_qp_timouts;
41110-extern atomic_t qps_created;
41111-extern atomic_t qps_destroyed;
41112-extern atomic_t sw_qps_destroyed;
41113+extern atomic_unchecked_t cm_connects;
41114+extern atomic_unchecked_t cm_accepts;
41115+extern atomic_unchecked_t cm_disconnects;
41116+extern atomic_unchecked_t cm_closes;
41117+extern atomic_unchecked_t cm_connecteds;
41118+extern atomic_unchecked_t cm_connect_reqs;
41119+extern atomic_unchecked_t cm_rejects;
41120+extern atomic_unchecked_t mod_qp_timouts;
41121+extern atomic_unchecked_t qps_created;
41122+extern atomic_unchecked_t qps_destroyed;
41123+extern atomic_unchecked_t sw_qps_destroyed;
41124 extern u32 mh_detected;
41125 extern u32 mh_pauses_sent;
41126 extern u32 cm_packets_sent;
41127@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41128 extern u32 cm_packets_received;
41129 extern u32 cm_packets_dropped;
41130 extern u32 cm_packets_retrans;
41131-extern atomic_t cm_listens_created;
41132-extern atomic_t cm_listens_destroyed;
41133+extern atomic_unchecked_t cm_listens_created;
41134+extern atomic_unchecked_t cm_listens_destroyed;
41135 extern u32 cm_backlog_drops;
41136-extern atomic_t cm_loopbacks;
41137-extern atomic_t cm_nodes_created;
41138-extern atomic_t cm_nodes_destroyed;
41139-extern atomic_t cm_accel_dropped_pkts;
41140-extern atomic_t cm_resets_recvd;
41141-extern atomic_t pau_qps_created;
41142-extern atomic_t pau_qps_destroyed;
41143+extern atomic_unchecked_t cm_loopbacks;
41144+extern atomic_unchecked_t cm_nodes_created;
41145+extern atomic_unchecked_t cm_nodes_destroyed;
41146+extern atomic_unchecked_t cm_accel_dropped_pkts;
41147+extern atomic_unchecked_t cm_resets_recvd;
41148+extern atomic_unchecked_t pau_qps_created;
41149+extern atomic_unchecked_t pau_qps_destroyed;
41150
41151 extern u32 int_mod_timer_init;
41152 extern u32 int_mod_cq_depth_256;
41153diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41154index 6b29249..57081dd 100644
41155--- a/drivers/infiniband/hw/nes/nes_cm.c
41156+++ b/drivers/infiniband/hw/nes/nes_cm.c
41157@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41158 u32 cm_packets_retrans;
41159 u32 cm_packets_created;
41160 u32 cm_packets_received;
41161-atomic_t cm_listens_created;
41162-atomic_t cm_listens_destroyed;
41163+atomic_unchecked_t cm_listens_created;
41164+atomic_unchecked_t cm_listens_destroyed;
41165 u32 cm_backlog_drops;
41166-atomic_t cm_loopbacks;
41167-atomic_t cm_nodes_created;
41168-atomic_t cm_nodes_destroyed;
41169-atomic_t cm_accel_dropped_pkts;
41170-atomic_t cm_resets_recvd;
41171+atomic_unchecked_t cm_loopbacks;
41172+atomic_unchecked_t cm_nodes_created;
41173+atomic_unchecked_t cm_nodes_destroyed;
41174+atomic_unchecked_t cm_accel_dropped_pkts;
41175+atomic_unchecked_t cm_resets_recvd;
41176
41177 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41178 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41179@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
41180
41181 static struct nes_cm_core *g_cm_core;
41182
41183-atomic_t cm_connects;
41184-atomic_t cm_accepts;
41185-atomic_t cm_disconnects;
41186-atomic_t cm_closes;
41187-atomic_t cm_connecteds;
41188-atomic_t cm_connect_reqs;
41189-atomic_t cm_rejects;
41190+atomic_unchecked_t cm_connects;
41191+atomic_unchecked_t cm_accepts;
41192+atomic_unchecked_t cm_disconnects;
41193+atomic_unchecked_t cm_closes;
41194+atomic_unchecked_t cm_connecteds;
41195+atomic_unchecked_t cm_connect_reqs;
41196+atomic_unchecked_t cm_rejects;
41197
41198 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41199 {
41200@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41201 kfree(listener);
41202 listener = NULL;
41203 ret = 0;
41204- atomic_inc(&cm_listens_destroyed);
41205+ atomic_inc_unchecked(&cm_listens_destroyed);
41206 } else {
41207 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41208 }
41209@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41210 cm_node->rem_mac);
41211
41212 add_hte_node(cm_core, cm_node);
41213- atomic_inc(&cm_nodes_created);
41214+ atomic_inc_unchecked(&cm_nodes_created);
41215
41216 return cm_node;
41217 }
41218@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41219 }
41220
41221 atomic_dec(&cm_core->node_cnt);
41222- atomic_inc(&cm_nodes_destroyed);
41223+ atomic_inc_unchecked(&cm_nodes_destroyed);
41224 nesqp = cm_node->nesqp;
41225 if (nesqp) {
41226 nesqp->cm_node = NULL;
41227@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41228
41229 static void drop_packet(struct sk_buff *skb)
41230 {
41231- atomic_inc(&cm_accel_dropped_pkts);
41232+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41233 dev_kfree_skb_any(skb);
41234 }
41235
41236@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41237 {
41238
41239 int reset = 0; /* whether to send reset in case of err.. */
41240- atomic_inc(&cm_resets_recvd);
41241+ atomic_inc_unchecked(&cm_resets_recvd);
41242 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41243 " refcnt=%d\n", cm_node, cm_node->state,
41244 atomic_read(&cm_node->ref_count));
41245@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41246 rem_ref_cm_node(cm_node->cm_core, cm_node);
41247 return NULL;
41248 }
41249- atomic_inc(&cm_loopbacks);
41250+ atomic_inc_unchecked(&cm_loopbacks);
41251 loopbackremotenode->loopbackpartner = cm_node;
41252 loopbackremotenode->tcp_cntxt.rcv_wscale =
41253 NES_CM_DEFAULT_RCV_WND_SCALE;
41254@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41255 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41256 else {
41257 rem_ref_cm_node(cm_core, cm_node);
41258- atomic_inc(&cm_accel_dropped_pkts);
41259+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41260 dev_kfree_skb_any(skb);
41261 }
41262 break;
41263@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41264
41265 if ((cm_id) && (cm_id->event_handler)) {
41266 if (issue_disconn) {
41267- atomic_inc(&cm_disconnects);
41268+ atomic_inc_unchecked(&cm_disconnects);
41269 cm_event.event = IW_CM_EVENT_DISCONNECT;
41270 cm_event.status = disconn_status;
41271 cm_event.local_addr = cm_id->local_addr;
41272@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41273 }
41274
41275 if (issue_close) {
41276- atomic_inc(&cm_closes);
41277+ atomic_inc_unchecked(&cm_closes);
41278 nes_disconnect(nesqp, 1);
41279
41280 cm_id->provider_data = nesqp;
41281@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41282
41283 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41284 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41285- atomic_inc(&cm_accepts);
41286+ atomic_inc_unchecked(&cm_accepts);
41287
41288 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41289 netdev_refcnt_read(nesvnic->netdev));
41290@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41291 struct nes_cm_core *cm_core;
41292 u8 *start_buff;
41293
41294- atomic_inc(&cm_rejects);
41295+ atomic_inc_unchecked(&cm_rejects);
41296 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41297 loopback = cm_node->loopbackpartner;
41298 cm_core = cm_node->cm_core;
41299@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41300 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
41301 ntohs(laddr->sin_port));
41302
41303- atomic_inc(&cm_connects);
41304+ atomic_inc_unchecked(&cm_connects);
41305 nesqp->active_conn = 1;
41306
41307 /* cache the cm_id in the qp */
41308@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41309 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41310 return err;
41311 }
41312- atomic_inc(&cm_listens_created);
41313+ atomic_inc_unchecked(&cm_listens_created);
41314 }
41315
41316 cm_id->add_ref(cm_id);
41317@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41318
41319 if (nesqp->destroyed)
41320 return;
41321- atomic_inc(&cm_connecteds);
41322+ atomic_inc_unchecked(&cm_connecteds);
41323 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41324 " local port 0x%04X. jiffies = %lu.\n",
41325 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
41326@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41327
41328 cm_id->add_ref(cm_id);
41329 ret = cm_id->event_handler(cm_id, &cm_event);
41330- atomic_inc(&cm_closes);
41331+ atomic_inc_unchecked(&cm_closes);
41332 cm_event.event = IW_CM_EVENT_CLOSE;
41333 cm_event.status = 0;
41334 cm_event.provider_data = cm_id->provider_data;
41335@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41336 return;
41337 cm_id = cm_node->cm_id;
41338
41339- atomic_inc(&cm_connect_reqs);
41340+ atomic_inc_unchecked(&cm_connect_reqs);
41341 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41342 cm_node, cm_id, jiffies);
41343
41344@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41345 return;
41346 cm_id = cm_node->cm_id;
41347
41348- atomic_inc(&cm_connect_reqs);
41349+ atomic_inc_unchecked(&cm_connect_reqs);
41350 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41351 cm_node, cm_id, jiffies);
41352
41353diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41354index 4166452..fc952c3 100644
41355--- a/drivers/infiniband/hw/nes/nes_mgt.c
41356+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41357@@ -40,8 +40,8 @@
41358 #include "nes.h"
41359 #include "nes_mgt.h"
41360
41361-atomic_t pau_qps_created;
41362-atomic_t pau_qps_destroyed;
41363+atomic_unchecked_t pau_qps_created;
41364+atomic_unchecked_t pau_qps_destroyed;
41365
41366 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41367 {
41368@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41369 {
41370 struct sk_buff *skb;
41371 unsigned long flags;
41372- atomic_inc(&pau_qps_destroyed);
41373+ atomic_inc_unchecked(&pau_qps_destroyed);
41374
41375 /* Free packets that have not yet been forwarded */
41376 /* Lock is acquired by skb_dequeue when removing the skb */
41377@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41378 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41379 skb_queue_head_init(&nesqp->pau_list);
41380 spin_lock_init(&nesqp->pau_lock);
41381- atomic_inc(&pau_qps_created);
41382+ atomic_inc_unchecked(&pau_qps_created);
41383 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41384 }
41385
41386diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41387index 49eb511..a774366 100644
41388--- a/drivers/infiniband/hw/nes/nes_nic.c
41389+++ b/drivers/infiniband/hw/nes/nes_nic.c
41390@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41391 target_stat_values[++index] = mh_detected;
41392 target_stat_values[++index] = mh_pauses_sent;
41393 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41394- target_stat_values[++index] = atomic_read(&cm_connects);
41395- target_stat_values[++index] = atomic_read(&cm_accepts);
41396- target_stat_values[++index] = atomic_read(&cm_disconnects);
41397- target_stat_values[++index] = atomic_read(&cm_connecteds);
41398- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41399- target_stat_values[++index] = atomic_read(&cm_rejects);
41400- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41401- target_stat_values[++index] = atomic_read(&qps_created);
41402- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41403- target_stat_values[++index] = atomic_read(&qps_destroyed);
41404- target_stat_values[++index] = atomic_read(&cm_closes);
41405+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41406+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41407+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41408+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41409+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41410+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41411+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41412+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41413+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41414+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41415+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41416 target_stat_values[++index] = cm_packets_sent;
41417 target_stat_values[++index] = cm_packets_bounced;
41418 target_stat_values[++index] = cm_packets_created;
41419 target_stat_values[++index] = cm_packets_received;
41420 target_stat_values[++index] = cm_packets_dropped;
41421 target_stat_values[++index] = cm_packets_retrans;
41422- target_stat_values[++index] = atomic_read(&cm_listens_created);
41423- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41424+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41425+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41426 target_stat_values[++index] = cm_backlog_drops;
41427- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41428- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41429- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41430- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41431- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41432+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41433+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41434+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41435+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41436+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41437 target_stat_values[++index] = nesadapter->free_4kpbl;
41438 target_stat_values[++index] = nesadapter->free_256pbl;
41439 target_stat_values[++index] = int_mod_timer_init;
41440 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41441 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41442 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41443- target_stat_values[++index] = atomic_read(&pau_qps_created);
41444- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41445+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41446+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41447 }
41448
41449 /**
41450diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41451index 5b53ca5..443da3c 100644
41452--- a/drivers/infiniband/hw/nes/nes_verbs.c
41453+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41454@@ -46,9 +46,9 @@
41455
41456 #include <rdma/ib_umem.h>
41457
41458-atomic_t mod_qp_timouts;
41459-atomic_t qps_created;
41460-atomic_t sw_qps_destroyed;
41461+atomic_unchecked_t mod_qp_timouts;
41462+atomic_unchecked_t qps_created;
41463+atomic_unchecked_t sw_qps_destroyed;
41464
41465 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41466
41467@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41468 if (init_attr->create_flags)
41469 return ERR_PTR(-EINVAL);
41470
41471- atomic_inc(&qps_created);
41472+ atomic_inc_unchecked(&qps_created);
41473 switch (init_attr->qp_type) {
41474 case IB_QPT_RC:
41475 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41476@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41477 struct iw_cm_event cm_event;
41478 int ret = 0;
41479
41480- atomic_inc(&sw_qps_destroyed);
41481+ atomic_inc_unchecked(&sw_qps_destroyed);
41482 nesqp->destroyed = 1;
41483
41484 /* Blow away the connection if it exists. */
41485diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41486index 1946101..09766d2 100644
41487--- a/drivers/infiniband/hw/qib/qib.h
41488+++ b/drivers/infiniband/hw/qib/qib.h
41489@@ -52,6 +52,7 @@
41490 #include <linux/kref.h>
41491 #include <linux/sched.h>
41492 #include <linux/kthread.h>
41493+#include <linux/slab.h>
41494
41495 #include "qib_common.h"
41496 #include "qib_verbs.h"
41497diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41498index 922a7fe..bb035db 100644
41499--- a/drivers/input/gameport/gameport.c
41500+++ b/drivers/input/gameport/gameport.c
41501@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41502 */
41503 static void gameport_init_port(struct gameport *gameport)
41504 {
41505- static atomic_t gameport_no = ATOMIC_INIT(0);
41506+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41507
41508 __module_get(THIS_MODULE);
41509
41510 mutex_init(&gameport->drv_mutex);
41511 device_initialize(&gameport->dev);
41512 dev_set_name(&gameport->dev, "gameport%lu",
41513- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41514+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41515 gameport->dev.bus = &gameport_bus;
41516 gameport->dev.release = gameport_release_port;
41517 if (gameport->parent)
41518diff --git a/drivers/input/input.c b/drivers/input/input.c
41519index e75d015..57d1c28 100644
41520--- a/drivers/input/input.c
41521+++ b/drivers/input/input.c
41522@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
41523 */
41524 struct input_dev *input_allocate_device(void)
41525 {
41526- static atomic_t input_no = ATOMIC_INIT(0);
41527+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41528 struct input_dev *dev;
41529
41530 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
41531@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
41532 INIT_LIST_HEAD(&dev->node);
41533
41534 dev_set_name(&dev->dev, "input%ld",
41535- (unsigned long) atomic_inc_return(&input_no) - 1);
41536+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41537
41538 __module_get(THIS_MODULE);
41539 }
41540diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41541index 04c69af..5f92d00 100644
41542--- a/drivers/input/joystick/sidewinder.c
41543+++ b/drivers/input/joystick/sidewinder.c
41544@@ -30,6 +30,7 @@
41545 #include <linux/kernel.h>
41546 #include <linux/module.h>
41547 #include <linux/slab.h>
41548+#include <linux/sched.h>
41549 #include <linux/init.h>
41550 #include <linux/input.h>
41551 #include <linux/gameport.h>
41552diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41553index 75e3b10..fb390fd 100644
41554--- a/drivers/input/joystick/xpad.c
41555+++ b/drivers/input/joystick/xpad.c
41556@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41557
41558 static int xpad_led_probe(struct usb_xpad *xpad)
41559 {
41560- static atomic_t led_seq = ATOMIC_INIT(0);
41561+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41562 long led_no;
41563 struct xpad_led *led;
41564 struct led_classdev *led_cdev;
41565@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41566 if (!led)
41567 return -ENOMEM;
41568
41569- led_no = (long)atomic_inc_return(&led_seq) - 1;
41570+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41571
41572 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41573 led->xpad = xpad;
41574diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41575index e204f26..8459f15 100644
41576--- a/drivers/input/misc/ims-pcu.c
41577+++ b/drivers/input/misc/ims-pcu.c
41578@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41579
41580 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41581 {
41582- static atomic_t device_no = ATOMIC_INIT(0);
41583+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41584
41585 const struct ims_pcu_device_info *info;
41586 u8 device_id;
41587@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41588 }
41589
41590 /* Device appears to be operable, complete initialization */
41591- pcu->device_no = atomic_inc_return(&device_no) - 1;
41592+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41593
41594 error = ims_pcu_setup_backlight(pcu);
41595 if (error)
41596diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41597index 2f0b39d..7370f13 100644
41598--- a/drivers/input/mouse/psmouse.h
41599+++ b/drivers/input/mouse/psmouse.h
41600@@ -116,7 +116,7 @@ struct psmouse_attribute {
41601 ssize_t (*set)(struct psmouse *psmouse, void *data,
41602 const char *buf, size_t count);
41603 bool protect;
41604-};
41605+} __do_const;
41606 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41607
41608 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41609diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41610index 4c842c3..590b0bf 100644
41611--- a/drivers/input/mousedev.c
41612+++ b/drivers/input/mousedev.c
41613@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41614
41615 spin_unlock_irq(&client->packet_lock);
41616
41617- if (copy_to_user(buffer, data, count))
41618+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41619 return -EFAULT;
41620
41621 return count;
41622diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41623index 2b56855..5a55837 100644
41624--- a/drivers/input/serio/serio.c
41625+++ b/drivers/input/serio/serio.c
41626@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41627 */
41628 static void serio_init_port(struct serio *serio)
41629 {
41630- static atomic_t serio_no = ATOMIC_INIT(0);
41631+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41632
41633 __module_get(THIS_MODULE);
41634
41635@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41636 mutex_init(&serio->drv_mutex);
41637 device_initialize(&serio->dev);
41638 dev_set_name(&serio->dev, "serio%ld",
41639- (long)atomic_inc_return(&serio_no) - 1);
41640+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41641 serio->dev.bus = &serio_bus;
41642 serio->dev.release = serio_release_port;
41643 serio->dev.groups = serio_device_attr_groups;
41644diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41645index 59df2e7..8f1cafb 100644
41646--- a/drivers/input/serio/serio_raw.c
41647+++ b/drivers/input/serio/serio_raw.c
41648@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41649
41650 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41651 {
41652- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41653+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41654 struct serio_raw *serio_raw;
41655 int err;
41656
41657@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41658 }
41659
41660 snprintf(serio_raw->name, sizeof(serio_raw->name),
41661- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41662+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41663 kref_init(&serio_raw->kref);
41664 INIT_LIST_HEAD(&serio_raw->client_list);
41665 init_waitqueue_head(&serio_raw->wait);
41666diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41667index fbe9ca7..dbee61d 100644
41668--- a/drivers/iommu/iommu.c
41669+++ b/drivers/iommu/iommu.c
41670@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41671 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41672 {
41673 bus_register_notifier(bus, &iommu_bus_nb);
41674- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41675+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41676 }
41677
41678 /**
41679diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41680index 39f81ae..2660096 100644
41681--- a/drivers/iommu/irq_remapping.c
41682+++ b/drivers/iommu/irq_remapping.c
41683@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41684 void panic_if_irq_remap(const char *msg)
41685 {
41686 if (irq_remapping_enabled)
41687- panic(msg);
41688+ panic("%s", msg);
41689 }
41690
41691 static void ir_ack_apic_edge(struct irq_data *data)
41692@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41693
41694 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41695 {
41696- chip->irq_print_chip = ir_print_prefix;
41697- chip->irq_ack = ir_ack_apic_edge;
41698- chip->irq_eoi = ir_ack_apic_level;
41699- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41700+ pax_open_kernel();
41701+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41702+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41703+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41704+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41705+ pax_close_kernel();
41706 }
41707
41708 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41709diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41710index d0e9480..d2b6340 100644
41711--- a/drivers/irqchip/irq-gic.c
41712+++ b/drivers/irqchip/irq-gic.c
41713@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41714 * Supported arch specific GIC irq extension.
41715 * Default make them NULL.
41716 */
41717-struct irq_chip gic_arch_extn = {
41718+irq_chip_no_const gic_arch_extn = {
41719 .irq_eoi = NULL,
41720 .irq_mask = NULL,
41721 .irq_unmask = NULL,
41722@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41723 chained_irq_exit(chip, desc);
41724 }
41725
41726-static struct irq_chip gic_chip = {
41727+static irq_chip_no_const gic_chip __read_only = {
41728 .name = "GIC",
41729 .irq_mask = gic_mask_irq,
41730 .irq_unmask = gic_unmask_irq,
41731diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41732index ac6f72b..81150f2 100644
41733--- a/drivers/isdn/capi/capi.c
41734+++ b/drivers/isdn/capi/capi.c
41735@@ -81,8 +81,8 @@ struct capiminor {
41736
41737 struct capi20_appl *ap;
41738 u32 ncci;
41739- atomic_t datahandle;
41740- atomic_t msgid;
41741+ atomic_unchecked_t datahandle;
41742+ atomic_unchecked_t msgid;
41743
41744 struct tty_port port;
41745 int ttyinstop;
41746@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41747 capimsg_setu16(s, 2, mp->ap->applid);
41748 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41749 capimsg_setu8 (s, 5, CAPI_RESP);
41750- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41751+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41752 capimsg_setu32(s, 8, mp->ncci);
41753 capimsg_setu16(s, 12, datahandle);
41754 }
41755@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41756 mp->outbytes -= len;
41757 spin_unlock_bh(&mp->outlock);
41758
41759- datahandle = atomic_inc_return(&mp->datahandle);
41760+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41761 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41762 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41763 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41764 capimsg_setu16(skb->data, 2, mp->ap->applid);
41765 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41766 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41767- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41768+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41769 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41770 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41771 capimsg_setu16(skb->data, 16, len); /* Data length */
41772diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41773index 600c79b..3752bab 100644
41774--- a/drivers/isdn/gigaset/interface.c
41775+++ b/drivers/isdn/gigaset/interface.c
41776@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41777 }
41778 tty->driver_data = cs;
41779
41780- ++cs->port.count;
41781+ atomic_inc(&cs->port.count);
41782
41783- if (cs->port.count == 1) {
41784+ if (atomic_read(&cs->port.count) == 1) {
41785 tty_port_tty_set(&cs->port, tty);
41786 cs->port.low_latency = 1;
41787 }
41788@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41789
41790 if (!cs->connected)
41791 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41792- else if (!cs->port.count)
41793+ else if (!atomic_read(&cs->port.count))
41794 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41795- else if (!--cs->port.count)
41796+ else if (!atomic_dec_return(&cs->port.count))
41797 tty_port_tty_set(&cs->port, NULL);
41798
41799 mutex_unlock(&cs->mutex);
41800diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41801index d0a41cb..f0cdb8c 100644
41802--- a/drivers/isdn/gigaset/usb-gigaset.c
41803+++ b/drivers/isdn/gigaset/usb-gigaset.c
41804@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41805 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41806 memcpy(cs->hw.usb->bchars, buf, 6);
41807 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41808- 0, 0, &buf, 6, 2000);
41809+ 0, 0, buf, 6, 2000);
41810 }
41811
41812 static void gigaset_freebcshw(struct bc_state *bcs)
41813diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41814index 4d9b195..455075c 100644
41815--- a/drivers/isdn/hardware/avm/b1.c
41816+++ b/drivers/isdn/hardware/avm/b1.c
41817@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41818 }
41819 if (left) {
41820 if (t4file->user) {
41821- if (copy_from_user(buf, dp, left))
41822+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41823 return -EFAULT;
41824 } else {
41825 memcpy(buf, dp, left);
41826@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41827 }
41828 if (left) {
41829 if (config->user) {
41830- if (copy_from_user(buf, dp, left))
41831+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41832 return -EFAULT;
41833 } else {
41834 memcpy(buf, dp, left);
41835diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41836index 9bb12ba..d4262f7 100644
41837--- a/drivers/isdn/i4l/isdn_common.c
41838+++ b/drivers/isdn/i4l/isdn_common.c
41839@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41840 } else
41841 return -EINVAL;
41842 case IIOCDBGVAR:
41843+ if (!capable(CAP_SYS_RAWIO))
41844+ return -EPERM;
41845 if (arg) {
41846 if (copy_to_user(argp, &dev, sizeof(ulong)))
41847 return -EFAULT;
41848diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41849index 3c5f249..5fac4d0 100644
41850--- a/drivers/isdn/i4l/isdn_tty.c
41851+++ b/drivers/isdn/i4l/isdn_tty.c
41852@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41853
41854 #ifdef ISDN_DEBUG_MODEM_OPEN
41855 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41856- port->count);
41857+ atomic_read(&port->count));
41858 #endif
41859- port->count++;
41860+ atomic_inc(&port->count);
41861 port->tty = tty;
41862 /*
41863 * Start up serial port
41864@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41865 #endif
41866 return;
41867 }
41868- if ((tty->count == 1) && (port->count != 1)) {
41869+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41870 /*
41871 * Uh, oh. tty->count is 1, which means that the tty
41872 * structure will be freed. Info->count should always
41873@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41874 * serial port won't be shutdown.
41875 */
41876 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41877- "info->count is %d\n", port->count);
41878- port->count = 1;
41879+ "info->count is %d\n", atomic_read(&port->count));
41880+ atomic_set(&port->count, 1);
41881 }
41882- if (--port->count < 0) {
41883+ if (atomic_dec_return(&port->count) < 0) {
41884 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41885- info->line, port->count);
41886- port->count = 0;
41887+ info->line, atomic_read(&port->count));
41888+ atomic_set(&port->count, 0);
41889 }
41890- if (port->count) {
41891+ if (atomic_read(&port->count)) {
41892 #ifdef ISDN_DEBUG_MODEM_OPEN
41893 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41894 #endif
41895@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41896 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41897 return;
41898 isdn_tty_shutdown(info);
41899- port->count = 0;
41900+ atomic_set(&port->count, 0);
41901 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41902 port->tty = NULL;
41903 wake_up_interruptible(&port->open_wait);
41904@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41905 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41906 modem_info *info = &dev->mdm.info[i];
41907
41908- if (info->port.count == 0)
41909+ if (atomic_read(&info->port.count) == 0)
41910 continue;
41911 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41912 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41913diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41914index e74df7c..03a03ba 100644
41915--- a/drivers/isdn/icn/icn.c
41916+++ b/drivers/isdn/icn/icn.c
41917@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41918 if (count > len)
41919 count = len;
41920 if (user) {
41921- if (copy_from_user(msg, buf, count))
41922+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41923 return -EFAULT;
41924 } else
41925 memcpy(msg, buf, count);
41926diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
41927index a4f05c5..1433bc5 100644
41928--- a/drivers/isdn/mISDN/dsp_cmx.c
41929+++ b/drivers/isdn/mISDN/dsp_cmx.c
41930@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
41931 static u16 dsp_count; /* last sample count */
41932 static int dsp_count_valid; /* if we have last sample count */
41933
41934-void
41935+void __intentional_overflow(-1)
41936 dsp_cmx_send(void *arg)
41937 {
41938 struct dsp_conf *conf;
41939diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41940index d93e245..e7ece6b 100644
41941--- a/drivers/leds/leds-clevo-mail.c
41942+++ b/drivers/leds/leds-clevo-mail.c
41943@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41944 * detected as working, but in reality it is not) as low as
41945 * possible.
41946 */
41947-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
41948+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
41949 {
41950 .callback = clevo_mail_led_dmi_callback,
41951 .ident = "Clevo D410J",
41952diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41953index 5b8f938..b73d657 100644
41954--- a/drivers/leds/leds-ss4200.c
41955+++ b/drivers/leds/leds-ss4200.c
41956@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41957 * detected as working, but in reality it is not) as low as
41958 * possible.
41959 */
41960-static struct dmi_system_id nas_led_whitelist[] __initdata = {
41961+static struct dmi_system_id nas_led_whitelist[] __initconst = {
41962 {
41963 .callback = ss4200_led_dmi_callback,
41964 .ident = "Intel SS4200-E",
41965diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41966index 0bf1e4e..b4bf44e 100644
41967--- a/drivers/lguest/core.c
41968+++ b/drivers/lguest/core.c
41969@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41970 * The end address needs +1 because __get_vm_area allocates an
41971 * extra guard page, so we need space for that.
41972 */
41973+
41974+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41975+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41976+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41977+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41978+#else
41979 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41980 VM_ALLOC, switcher_addr, switcher_addr
41981 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41982+#endif
41983+
41984 if (!switcher_vma) {
41985 err = -ENOMEM;
41986 printk("lguest: could not map switcher pages high\n");
41987@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41988 * Now the Switcher is mapped at the right address, we can't fail!
41989 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41990 */
41991- memcpy(switcher_vma->addr, start_switcher_text,
41992+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41993 end_switcher_text - start_switcher_text);
41994
41995 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41996diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41997index bfb39bb..08a603b 100644
41998--- a/drivers/lguest/page_tables.c
41999+++ b/drivers/lguest/page_tables.c
42000@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42001 /*:*/
42002
42003 #ifdef CONFIG_X86_PAE
42004-static void release_pmd(pmd_t *spmd)
42005+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42006 {
42007 /* If the entry's not present, there's nothing to release. */
42008 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42009diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42010index 5169239..47cb4db 100644
42011--- a/drivers/lguest/x86/core.c
42012+++ b/drivers/lguest/x86/core.c
42013@@ -59,7 +59,7 @@ static struct {
42014 /* Offset from where switcher.S was compiled to where we've copied it */
42015 static unsigned long switcher_offset(void)
42016 {
42017- return switcher_addr - (unsigned long)start_switcher_text;
42018+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42019 }
42020
42021 /* This cpu's struct lguest_pages (after the Switcher text page) */
42022@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42023 * These copies are pretty cheap, so we do them unconditionally: */
42024 /* Save the current Host top-level page directory.
42025 */
42026+
42027+#ifdef CONFIG_PAX_PER_CPU_PGD
42028+ pages->state.host_cr3 = read_cr3();
42029+#else
42030 pages->state.host_cr3 = __pa(current->mm->pgd);
42031+#endif
42032+
42033 /*
42034 * Set up the Guest's page tables to see this CPU's pages (and no
42035 * other CPU's pages).
42036@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42037 * compiled-in switcher code and the high-mapped copy we just made.
42038 */
42039 for (i = 0; i < IDT_ENTRIES; i++)
42040- default_idt_entries[i] += switcher_offset();
42041+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42042
42043 /*
42044 * Set up the Switcher's per-cpu areas.
42045@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42046 * it will be undisturbed when we switch. To change %cs and jump we
42047 * need this structure to feed to Intel's "lcall" instruction.
42048 */
42049- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42050+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42051 lguest_entry.segment = LGUEST_CS;
42052
42053 /*
42054diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42055index 40634b0..4f5855e 100644
42056--- a/drivers/lguest/x86/switcher_32.S
42057+++ b/drivers/lguest/x86/switcher_32.S
42058@@ -87,6 +87,7 @@
42059 #include <asm/page.h>
42060 #include <asm/segment.h>
42061 #include <asm/lguest.h>
42062+#include <asm/processor-flags.h>
42063
42064 // We mark the start of the code to copy
42065 // It's placed in .text tho it's never run here
42066@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42067 // Changes type when we load it: damn Intel!
42068 // For after we switch over our page tables
42069 // That entry will be read-only: we'd crash.
42070+
42071+#ifdef CONFIG_PAX_KERNEXEC
42072+ mov %cr0, %edx
42073+ xor $X86_CR0_WP, %edx
42074+ mov %edx, %cr0
42075+#endif
42076+
42077 movl $(GDT_ENTRY_TSS*8), %edx
42078 ltr %dx
42079
42080@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42081 // Let's clear it again for our return.
42082 // The GDT descriptor of the Host
42083 // Points to the table after two "size" bytes
42084- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42085+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42086 // Clear "used" from type field (byte 5, bit 2)
42087- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42088+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42089+
42090+#ifdef CONFIG_PAX_KERNEXEC
42091+ mov %cr0, %eax
42092+ xor $X86_CR0_WP, %eax
42093+ mov %eax, %cr0
42094+#endif
42095
42096 // Once our page table's switched, the Guest is live!
42097 // The Host fades as we run this final step.
42098@@ -295,13 +309,12 @@ deliver_to_host:
42099 // I consulted gcc, and it gave
42100 // These instructions, which I gladly credit:
42101 leal (%edx,%ebx,8), %eax
42102- movzwl (%eax),%edx
42103- movl 4(%eax), %eax
42104- xorw %ax, %ax
42105- orl %eax, %edx
42106+ movl 4(%eax), %edx
42107+ movw (%eax), %dx
42108 // Now the address of the handler's in %edx
42109 // We call it now: its "iret" drops us home.
42110- jmp *%edx
42111+ ljmp $__KERNEL_CS, $1f
42112+1: jmp *%edx
42113
42114 // Every interrupt can come to us here
42115 // But we must truly tell each apart.
42116diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42117index 0003992..854bbce 100644
42118--- a/drivers/md/bcache/closure.h
42119+++ b/drivers/md/bcache/closure.h
42120@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42121 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42122 struct workqueue_struct *wq)
42123 {
42124- BUG_ON(object_is_on_stack(cl));
42125+ BUG_ON(object_starts_on_stack(cl));
42126 closure_set_ip(cl);
42127 cl->fn = fn;
42128 cl->wq = wq;
42129diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42130index 547c4c5..5be1de4 100644
42131--- a/drivers/md/bcache/super.c
42132+++ b/drivers/md/bcache/super.c
42133@@ -1644,7 +1644,7 @@ err_unlock_gc:
42134 err:
42135 closure_sync(&op.cl);
42136 /* XXX: test this, it's broken */
42137- bch_cache_set_error(c, err);
42138+ bch_cache_set_error(c, "%s", err);
42139 }
42140
42141 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42142diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42143index a7fd821..9dcf6c3 100644
42144--- a/drivers/md/bitmap.c
42145+++ b/drivers/md/bitmap.c
42146@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42147 chunk_kb ? "KB" : "B");
42148 if (bitmap->storage.file) {
42149 seq_printf(seq, ", file: ");
42150- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42151+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42152 }
42153
42154 seq_printf(seq, "\n");
42155diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42156index afe0814..8cf3794 100644
42157--- a/drivers/md/dm-ioctl.c
42158+++ b/drivers/md/dm-ioctl.c
42159@@ -1745,7 +1745,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42160 cmd == DM_LIST_VERSIONS_CMD)
42161 return 0;
42162
42163- if ((cmd == DM_DEV_CREATE_CMD)) {
42164+ if (cmd == DM_DEV_CREATE_CMD) {
42165 if (!*param->name) {
42166 DMWARN("name not supplied when creating device");
42167 return -EINVAL;
42168diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42169index 9584443..9fc9ac9 100644
42170--- a/drivers/md/dm-raid1.c
42171+++ b/drivers/md/dm-raid1.c
42172@@ -40,7 +40,7 @@ enum dm_raid1_error {
42173
42174 struct mirror {
42175 struct mirror_set *ms;
42176- atomic_t error_count;
42177+ atomic_unchecked_t error_count;
42178 unsigned long error_type;
42179 struct dm_dev *dev;
42180 sector_t offset;
42181@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42182 struct mirror *m;
42183
42184 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42185- if (!atomic_read(&m->error_count))
42186+ if (!atomic_read_unchecked(&m->error_count))
42187 return m;
42188
42189 return NULL;
42190@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42191 * simple way to tell if a device has encountered
42192 * errors.
42193 */
42194- atomic_inc(&m->error_count);
42195+ atomic_inc_unchecked(&m->error_count);
42196
42197 if (test_and_set_bit(error_type, &m->error_type))
42198 return;
42199@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42200 struct mirror *m = get_default_mirror(ms);
42201
42202 do {
42203- if (likely(!atomic_read(&m->error_count)))
42204+ if (likely(!atomic_read_unchecked(&m->error_count)))
42205 return m;
42206
42207 if (m-- == ms->mirror)
42208@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42209 {
42210 struct mirror *default_mirror = get_default_mirror(m->ms);
42211
42212- return !atomic_read(&default_mirror->error_count);
42213+ return !atomic_read_unchecked(&default_mirror->error_count);
42214 }
42215
42216 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42217@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42218 */
42219 if (likely(region_in_sync(ms, region, 1)))
42220 m = choose_mirror(ms, bio->bi_sector);
42221- else if (m && atomic_read(&m->error_count))
42222+ else if (m && atomic_read_unchecked(&m->error_count))
42223 m = NULL;
42224
42225 if (likely(m))
42226@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42227 }
42228
42229 ms->mirror[mirror].ms = ms;
42230- atomic_set(&(ms->mirror[mirror].error_count), 0);
42231+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42232 ms->mirror[mirror].error_type = 0;
42233 ms->mirror[mirror].offset = offset;
42234
42235@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
42236 */
42237 static char device_status_char(struct mirror *m)
42238 {
42239- if (!atomic_read(&(m->error_count)))
42240+ if (!atomic_read_unchecked(&(m->error_count)))
42241 return 'A';
42242
42243 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42244diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
42245index 28a9012..9c0f6a5 100644
42246--- a/drivers/md/dm-stats.c
42247+++ b/drivers/md/dm-stats.c
42248@@ -382,7 +382,7 @@ do_sync_free:
42249 synchronize_rcu_expedited();
42250 dm_stat_free(&s->rcu_head);
42251 } else {
42252- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
42253+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
42254 call_rcu(&s->rcu_head, dm_stat_free);
42255 }
42256 return 0;
42257@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
42258 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
42259 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
42260 ));
42261- ACCESS_ONCE(last->last_sector) = end_sector;
42262- ACCESS_ONCE(last->last_rw) = bi_rw;
42263+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
42264+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
42265 }
42266
42267 rcu_read_lock();
42268diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42269index 73c1712..7347292 100644
42270--- a/drivers/md/dm-stripe.c
42271+++ b/drivers/md/dm-stripe.c
42272@@ -21,7 +21,7 @@ struct stripe {
42273 struct dm_dev *dev;
42274 sector_t physical_start;
42275
42276- atomic_t error_count;
42277+ atomic_unchecked_t error_count;
42278 };
42279
42280 struct stripe_c {
42281@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42282 kfree(sc);
42283 return r;
42284 }
42285- atomic_set(&(sc->stripe[i].error_count), 0);
42286+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42287 }
42288
42289 ti->private = sc;
42290@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42291 DMEMIT("%d ", sc->stripes);
42292 for (i = 0; i < sc->stripes; i++) {
42293 DMEMIT("%s ", sc->stripe[i].dev->name);
42294- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42295+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42296 'D' : 'A';
42297 }
42298 buffer[i] = '\0';
42299@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42300 */
42301 for (i = 0; i < sc->stripes; i++)
42302 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42303- atomic_inc(&(sc->stripe[i].error_count));
42304- if (atomic_read(&(sc->stripe[i].error_count)) <
42305+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42306+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42307 DM_IO_ERROR_THRESHOLD)
42308 schedule_work(&sc->trigger_event);
42309 }
42310diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42311index 20a8cc0..5447b11 100644
42312--- a/drivers/md/dm-table.c
42313+++ b/drivers/md/dm-table.c
42314@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
42315 static int open_dev(struct dm_dev_internal *d, dev_t dev,
42316 struct mapped_device *md)
42317 {
42318- static char *_claim_ptr = "I belong to device-mapper";
42319+ static char _claim_ptr[] = "I belong to device-mapper";
42320 struct block_device *bdev;
42321
42322 int r;
42323@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42324 if (!dev_size)
42325 return 0;
42326
42327- if ((start >= dev_size) || (start + len > dev_size)) {
42328+ if ((start >= dev_size) || (len > dev_size - start)) {
42329 DMWARN("%s: %s too small for target: "
42330 "start=%llu, len=%llu, dev_size=%llu",
42331 dm_device_name(ti->table->md), bdevname(bdev, b),
42332diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42333index 8a30ad5..72792d3 100644
42334--- a/drivers/md/dm-thin-metadata.c
42335+++ b/drivers/md/dm-thin-metadata.c
42336@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42337 {
42338 pmd->info.tm = pmd->tm;
42339 pmd->info.levels = 2;
42340- pmd->info.value_type.context = pmd->data_sm;
42341+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42342 pmd->info.value_type.size = sizeof(__le64);
42343 pmd->info.value_type.inc = data_block_inc;
42344 pmd->info.value_type.dec = data_block_dec;
42345@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42346
42347 pmd->bl_info.tm = pmd->tm;
42348 pmd->bl_info.levels = 1;
42349- pmd->bl_info.value_type.context = pmd->data_sm;
42350+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42351 pmd->bl_info.value_type.size = sizeof(__le64);
42352 pmd->bl_info.value_type.inc = data_block_inc;
42353 pmd->bl_info.value_type.dec = data_block_dec;
42354diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42355index b3e26c7..1efca94 100644
42356--- a/drivers/md/dm.c
42357+++ b/drivers/md/dm.c
42358@@ -179,9 +179,9 @@ struct mapped_device {
42359 /*
42360 * Event handling.
42361 */
42362- atomic_t event_nr;
42363+ atomic_unchecked_t event_nr;
42364 wait_queue_head_t eventq;
42365- atomic_t uevent_seq;
42366+ atomic_unchecked_t uevent_seq;
42367 struct list_head uevent_list;
42368 spinlock_t uevent_lock; /* Protect access to uevent_list */
42369
42370@@ -1985,8 +1985,8 @@ static struct mapped_device *alloc_dev(int minor)
42371 spin_lock_init(&md->deferred_lock);
42372 atomic_set(&md->holders, 1);
42373 atomic_set(&md->open_count, 0);
42374- atomic_set(&md->event_nr, 0);
42375- atomic_set(&md->uevent_seq, 0);
42376+ atomic_set_unchecked(&md->event_nr, 0);
42377+ atomic_set_unchecked(&md->uevent_seq, 0);
42378 INIT_LIST_HEAD(&md->uevent_list);
42379 spin_lock_init(&md->uevent_lock);
42380
42381@@ -2139,7 +2139,7 @@ static void event_callback(void *context)
42382
42383 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42384
42385- atomic_inc(&md->event_nr);
42386+ atomic_inc_unchecked(&md->event_nr);
42387 wake_up(&md->eventq);
42388 }
42389
42390@@ -2832,18 +2832,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42391
42392 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42393 {
42394- return atomic_add_return(1, &md->uevent_seq);
42395+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42396 }
42397
42398 uint32_t dm_get_event_nr(struct mapped_device *md)
42399 {
42400- return atomic_read(&md->event_nr);
42401+ return atomic_read_unchecked(&md->event_nr);
42402 }
42403
42404 int dm_wait_event(struct mapped_device *md, int event_nr)
42405 {
42406 return wait_event_interruptible(md->eventq,
42407- (event_nr != atomic_read(&md->event_nr)));
42408+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42409 }
42410
42411 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42412diff --git a/drivers/md/md.c b/drivers/md/md.c
42413index ba46d97..f8f5019 100644
42414--- a/drivers/md/md.c
42415+++ b/drivers/md/md.c
42416@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42417 * start build, activate spare
42418 */
42419 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42420-static atomic_t md_event_count;
42421+static atomic_unchecked_t md_event_count;
42422 void md_new_event(struct mddev *mddev)
42423 {
42424- atomic_inc(&md_event_count);
42425+ atomic_inc_unchecked(&md_event_count);
42426 wake_up(&md_event_waiters);
42427 }
42428 EXPORT_SYMBOL_GPL(md_new_event);
42429@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42430 */
42431 static void md_new_event_inintr(struct mddev *mddev)
42432 {
42433- atomic_inc(&md_event_count);
42434+ atomic_inc_unchecked(&md_event_count);
42435 wake_up(&md_event_waiters);
42436 }
42437
42438@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42439 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42440 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42441 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42442- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42443+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42444
42445 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42446 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42447@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42448 else
42449 sb->resync_offset = cpu_to_le64(0);
42450
42451- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42452+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42453
42454 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42455 sb->size = cpu_to_le64(mddev->dev_sectors);
42456@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42457 static ssize_t
42458 errors_show(struct md_rdev *rdev, char *page)
42459 {
42460- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42461+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42462 }
42463
42464 static ssize_t
42465@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42466 char *e;
42467 unsigned long n = simple_strtoul(buf, &e, 10);
42468 if (*buf && (*e == 0 || *e == '\n')) {
42469- atomic_set(&rdev->corrected_errors, n);
42470+ atomic_set_unchecked(&rdev->corrected_errors, n);
42471 return len;
42472 }
42473 return -EINVAL;
42474@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42475 rdev->sb_loaded = 0;
42476 rdev->bb_page = NULL;
42477 atomic_set(&rdev->nr_pending, 0);
42478- atomic_set(&rdev->read_errors, 0);
42479- atomic_set(&rdev->corrected_errors, 0);
42480+ atomic_set_unchecked(&rdev->read_errors, 0);
42481+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42482
42483 INIT_LIST_HEAD(&rdev->same_set);
42484 init_waitqueue_head(&rdev->blocked_wait);
42485@@ -7043,7 +7043,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42486
42487 spin_unlock(&pers_lock);
42488 seq_printf(seq, "\n");
42489- seq->poll_event = atomic_read(&md_event_count);
42490+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42491 return 0;
42492 }
42493 if (v == (void*)2) {
42494@@ -7146,7 +7146,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42495 return error;
42496
42497 seq = file->private_data;
42498- seq->poll_event = atomic_read(&md_event_count);
42499+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42500 return error;
42501 }
42502
42503@@ -7160,7 +7160,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42504 /* always allow read */
42505 mask = POLLIN | POLLRDNORM;
42506
42507- if (seq->poll_event != atomic_read(&md_event_count))
42508+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42509 mask |= POLLERR | POLLPRI;
42510 return mask;
42511 }
42512@@ -7204,7 +7204,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42513 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42514 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42515 (int)part_stat_read(&disk->part0, sectors[1]) -
42516- atomic_read(&disk->sync_io);
42517+ atomic_read_unchecked(&disk->sync_io);
42518 /* sync IO will cause sync_io to increase before the disk_stats
42519 * as sync_io is counted when a request starts, and
42520 * disk_stats is counted when it completes.
42521diff --git a/drivers/md/md.h b/drivers/md/md.h
42522index 608050c..6e77db5d 100644
42523--- a/drivers/md/md.h
42524+++ b/drivers/md/md.h
42525@@ -94,13 +94,13 @@ struct md_rdev {
42526 * only maintained for arrays that
42527 * support hot removal
42528 */
42529- atomic_t read_errors; /* number of consecutive read errors that
42530+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42531 * we have tried to ignore.
42532 */
42533 struct timespec last_read_error; /* monotonic time since our
42534 * last read error
42535 */
42536- atomic_t corrected_errors; /* number of corrected read errors,
42537+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42538 * for reporting to userspace and storing
42539 * in superblock.
42540 */
42541@@ -446,7 +446,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42542
42543 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42544 {
42545- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42546+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42547 }
42548
42549 struct md_personality
42550diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42551index 3e6d115..ffecdeb 100644
42552--- a/drivers/md/persistent-data/dm-space-map.h
42553+++ b/drivers/md/persistent-data/dm-space-map.h
42554@@ -71,6 +71,7 @@ struct dm_space_map {
42555 dm_sm_threshold_fn fn,
42556 void *context);
42557 };
42558+typedef struct dm_space_map __no_const dm_space_map_no_const;
42559
42560 /*----------------------------------------------------------------*/
42561
42562diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42563index aacf6bf..67d63f2 100644
42564--- a/drivers/md/raid1.c
42565+++ b/drivers/md/raid1.c
42566@@ -1824,7 +1824,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42567 if (r1_sync_page_io(rdev, sect, s,
42568 bio->bi_io_vec[idx].bv_page,
42569 READ) != 0)
42570- atomic_add(s, &rdev->corrected_errors);
42571+ atomic_add_unchecked(s, &rdev->corrected_errors);
42572 }
42573 sectors -= s;
42574 sect += s;
42575@@ -2051,7 +2051,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42576 test_bit(In_sync, &rdev->flags)) {
42577 if (r1_sync_page_io(rdev, sect, s,
42578 conf->tmppage, READ)) {
42579- atomic_add(s, &rdev->corrected_errors);
42580+ atomic_add_unchecked(s, &rdev->corrected_errors);
42581 printk(KERN_INFO
42582 "md/raid1:%s: read error corrected "
42583 "(%d sectors at %llu on %s)\n",
42584diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42585index 73dc8a3..bdd515a 100644
42586--- a/drivers/md/raid10.c
42587+++ b/drivers/md/raid10.c
42588@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
42589 /* The write handler will notice the lack of
42590 * R10BIO_Uptodate and record any errors etc
42591 */
42592- atomic_add(r10_bio->sectors,
42593+ atomic_add_unchecked(r10_bio->sectors,
42594 &conf->mirrors[d].rdev->corrected_errors);
42595
42596 /* for reconstruct, we always reschedule after a read.
42597@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42598 {
42599 struct timespec cur_time_mon;
42600 unsigned long hours_since_last;
42601- unsigned int read_errors = atomic_read(&rdev->read_errors);
42602+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42603
42604 ktime_get_ts(&cur_time_mon);
42605
42606@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42607 * overflowing the shift of read_errors by hours_since_last.
42608 */
42609 if (hours_since_last >= 8 * sizeof(read_errors))
42610- atomic_set(&rdev->read_errors, 0);
42611+ atomic_set_unchecked(&rdev->read_errors, 0);
42612 else
42613- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42614+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42615 }
42616
42617 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42618@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42619 return;
42620
42621 check_decay_read_errors(mddev, rdev);
42622- atomic_inc(&rdev->read_errors);
42623- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42624+ atomic_inc_unchecked(&rdev->read_errors);
42625+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42626 char b[BDEVNAME_SIZE];
42627 bdevname(rdev->bdev, b);
42628
42629@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42630 "md/raid10:%s: %s: Raid device exceeded "
42631 "read_error threshold [cur %d:max %d]\n",
42632 mdname(mddev), b,
42633- atomic_read(&rdev->read_errors), max_read_errors);
42634+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42635 printk(KERN_NOTICE
42636 "md/raid10:%s: %s: Failing raid device\n",
42637 mdname(mddev), b);
42638@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42639 sect +
42640 choose_data_offset(r10_bio, rdev)),
42641 bdevname(rdev->bdev, b));
42642- atomic_add(s, &rdev->corrected_errors);
42643+ atomic_add_unchecked(s, &rdev->corrected_errors);
42644 }
42645
42646 rdev_dec_pending(rdev, mddev);
42647diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42648index 8a0665d..984c46d 100644
42649--- a/drivers/md/raid5.c
42650+++ b/drivers/md/raid5.c
42651@@ -1887,21 +1887,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42652 mdname(conf->mddev), STRIPE_SECTORS,
42653 (unsigned long long)s,
42654 bdevname(rdev->bdev, b));
42655- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42656+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42657 clear_bit(R5_ReadError, &sh->dev[i].flags);
42658 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42659 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42660 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42661
42662- if (atomic_read(&rdev->read_errors))
42663- atomic_set(&rdev->read_errors, 0);
42664+ if (atomic_read_unchecked(&rdev->read_errors))
42665+ atomic_set_unchecked(&rdev->read_errors, 0);
42666 } else {
42667 const char *bdn = bdevname(rdev->bdev, b);
42668 int retry = 0;
42669 int set_bad = 0;
42670
42671 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42672- atomic_inc(&rdev->read_errors);
42673+ atomic_inc_unchecked(&rdev->read_errors);
42674 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42675 printk_ratelimited(
42676 KERN_WARNING
42677@@ -1929,7 +1929,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42678 mdname(conf->mddev),
42679 (unsigned long long)s,
42680 bdn);
42681- } else if (atomic_read(&rdev->read_errors)
42682+ } else if (atomic_read_unchecked(&rdev->read_errors)
42683 > conf->max_nr_stripes)
42684 printk(KERN_WARNING
42685 "md/raid:%s: Too many read errors, failing device %s.\n",
42686diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42687index 401ef64..836e563 100644
42688--- a/drivers/media/dvb-core/dvbdev.c
42689+++ b/drivers/media/dvb-core/dvbdev.c
42690@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42691 const struct dvb_device *template, void *priv, int type)
42692 {
42693 struct dvb_device *dvbdev;
42694- struct file_operations *dvbdevfops;
42695+ file_operations_no_const *dvbdevfops;
42696 struct device *clsdev;
42697 int minor;
42698 int id;
42699diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42700index 9b6c3bb..baeb5c7 100644
42701--- a/drivers/media/dvb-frontends/dib3000.h
42702+++ b/drivers/media/dvb-frontends/dib3000.h
42703@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42704 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42705 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42706 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42707-};
42708+} __no_const;
42709
42710 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42711 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42712diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42713index ecf21d9..b992428d 100644
42714--- a/drivers/media/pci/cx88/cx88-video.c
42715+++ b/drivers/media/pci/cx88/cx88-video.c
42716@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42717
42718 /* ------------------------------------------------------------------ */
42719
42720-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42721-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42722-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42723+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42724+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42725+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42726
42727 module_param_array(video_nr, int, NULL, 0444);
42728 module_param_array(vbi_nr, int, NULL, 0444);
42729diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42730index c08ae3e..eb59af1 100644
42731--- a/drivers/media/pci/ivtv/ivtv-driver.c
42732+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42733@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42734 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42735
42736 /* ivtv instance counter */
42737-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42738+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42739
42740 /* Parameter declarations */
42741 static int cardtype[IVTV_MAX_CARDS];
42742diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42743index dfd0a21..6bbb465 100644
42744--- a/drivers/media/platform/omap/omap_vout.c
42745+++ b/drivers/media/platform/omap/omap_vout.c
42746@@ -63,7 +63,6 @@ enum omap_vout_channels {
42747 OMAP_VIDEO2,
42748 };
42749
42750-static struct videobuf_queue_ops video_vbq_ops;
42751 /* Variables configurable through module params*/
42752 static u32 video1_numbuffers = 3;
42753 static u32 video2_numbuffers = 3;
42754@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42755 {
42756 struct videobuf_queue *q;
42757 struct omap_vout_device *vout = NULL;
42758+ static struct videobuf_queue_ops video_vbq_ops = {
42759+ .buf_setup = omap_vout_buffer_setup,
42760+ .buf_prepare = omap_vout_buffer_prepare,
42761+ .buf_release = omap_vout_buffer_release,
42762+ .buf_queue = omap_vout_buffer_queue,
42763+ };
42764
42765 vout = video_drvdata(file);
42766 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42767@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42768 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42769
42770 q = &vout->vbq;
42771- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42772- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42773- video_vbq_ops.buf_release = omap_vout_buffer_release;
42774- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42775 spin_lock_init(&vout->vbq_lock);
42776
42777 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42778diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42779index 04e6490..2df65bf 100644
42780--- a/drivers/media/platform/s5p-tv/mixer.h
42781+++ b/drivers/media/platform/s5p-tv/mixer.h
42782@@ -156,7 +156,7 @@ struct mxr_layer {
42783 /** layer index (unique identifier) */
42784 int idx;
42785 /** callbacks for layer methods */
42786- struct mxr_layer_ops ops;
42787+ struct mxr_layer_ops *ops;
42788 /** format array */
42789 const struct mxr_format **fmt_array;
42790 /** size of format array */
42791diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42792index b93a21f..2535195 100644
42793--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42794+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42795@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42796 {
42797 struct mxr_layer *layer;
42798 int ret;
42799- struct mxr_layer_ops ops = {
42800+ static struct mxr_layer_ops ops = {
42801 .release = mxr_graph_layer_release,
42802 .buffer_set = mxr_graph_buffer_set,
42803 .stream_set = mxr_graph_stream_set,
42804diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42805index b713403..53cb5ad 100644
42806--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42807+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42808@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42809 layer->update_buf = next;
42810 }
42811
42812- layer->ops.buffer_set(layer, layer->update_buf);
42813+ layer->ops->buffer_set(layer, layer->update_buf);
42814
42815 if (done && done != layer->shadow_buf)
42816 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42817diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42818index 641b1f0..49cff30 100644
42819--- a/drivers/media/platform/s5p-tv/mixer_video.c
42820+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42821@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42822 layer->geo.src.height = layer->geo.src.full_height;
42823
42824 mxr_geometry_dump(mdev, &layer->geo);
42825- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42826+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42827 mxr_geometry_dump(mdev, &layer->geo);
42828 }
42829
42830@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42831 layer->geo.dst.full_width = mbus_fmt.width;
42832 layer->geo.dst.full_height = mbus_fmt.height;
42833 layer->geo.dst.field = mbus_fmt.field;
42834- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42835+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42836
42837 mxr_geometry_dump(mdev, &layer->geo);
42838 }
42839@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42840 /* set source size to highest accepted value */
42841 geo->src.full_width = max(geo->dst.full_width, pix->width);
42842 geo->src.full_height = max(geo->dst.full_height, pix->height);
42843- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42844+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42845 mxr_geometry_dump(mdev, &layer->geo);
42846 /* set cropping to total visible screen */
42847 geo->src.width = pix->width;
42848@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42849 geo->src.x_offset = 0;
42850 geo->src.y_offset = 0;
42851 /* assure consistency of geometry */
42852- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42853+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42854 mxr_geometry_dump(mdev, &layer->geo);
42855 /* set full size to lowest possible value */
42856 geo->src.full_width = 0;
42857 geo->src.full_height = 0;
42858- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42859+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42860 mxr_geometry_dump(mdev, &layer->geo);
42861
42862 /* returning results */
42863@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42864 target->width = s->r.width;
42865 target->height = s->r.height;
42866
42867- layer->ops.fix_geometry(layer, stage, s->flags);
42868+ layer->ops->fix_geometry(layer, stage, s->flags);
42869
42870 /* retrieve update selection rectangle */
42871 res.left = target->x_offset;
42872@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42873 mxr_output_get(mdev);
42874
42875 mxr_layer_update_output(layer);
42876- layer->ops.format_set(layer);
42877+ layer->ops->format_set(layer);
42878 /* enabling layer in hardware */
42879 spin_lock_irqsave(&layer->enq_slock, flags);
42880 layer->state = MXR_LAYER_STREAMING;
42881 spin_unlock_irqrestore(&layer->enq_slock, flags);
42882
42883- layer->ops.stream_set(layer, MXR_ENABLE);
42884+ layer->ops->stream_set(layer, MXR_ENABLE);
42885 mxr_streamer_get(mdev);
42886
42887 return 0;
42888@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42889 spin_unlock_irqrestore(&layer->enq_slock, flags);
42890
42891 /* disabling layer in hardware */
42892- layer->ops.stream_set(layer, MXR_DISABLE);
42893+ layer->ops->stream_set(layer, MXR_DISABLE);
42894 /* remove one streamer */
42895 mxr_streamer_put(mdev);
42896 /* allow changes in output configuration */
42897@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42898
42899 void mxr_layer_release(struct mxr_layer *layer)
42900 {
42901- if (layer->ops.release)
42902- layer->ops.release(layer);
42903+ if (layer->ops->release)
42904+ layer->ops->release(layer);
42905 }
42906
42907 void mxr_base_layer_release(struct mxr_layer *layer)
42908@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42909
42910 layer->mdev = mdev;
42911 layer->idx = idx;
42912- layer->ops = *ops;
42913+ layer->ops = ops;
42914
42915 spin_lock_init(&layer->enq_slock);
42916 INIT_LIST_HEAD(&layer->enq_list);
42917diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42918index 3d13a63..da31bf1 100644
42919--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42920+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42921@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42922 {
42923 struct mxr_layer *layer;
42924 int ret;
42925- struct mxr_layer_ops ops = {
42926+ static struct mxr_layer_ops ops = {
42927 .release = mxr_vp_layer_release,
42928 .buffer_set = mxr_vp_buffer_set,
42929 .stream_set = mxr_vp_stream_set,
42930diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42931index 545c04c..a14bded 100644
42932--- a/drivers/media/radio/radio-cadet.c
42933+++ b/drivers/media/radio/radio-cadet.c
42934@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42935 unsigned char readbuf[RDS_BUFFER];
42936 int i = 0;
42937
42938+ if (count > RDS_BUFFER)
42939+ return -EFAULT;
42940 mutex_lock(&dev->lock);
42941 if (dev->rdsstat == 0)
42942 cadet_start_rds(dev);
42943@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42944 while (i < count && dev->rdsin != dev->rdsout)
42945 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42946
42947- if (i && copy_to_user(data, readbuf, i))
42948+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42949 i = -EFAULT;
42950 unlock:
42951 mutex_unlock(&dev->lock);
42952diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42953index 5236035..c622c74 100644
42954--- a/drivers/media/radio/radio-maxiradio.c
42955+++ b/drivers/media/radio/radio-maxiradio.c
42956@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42957 /* TEA5757 pin mappings */
42958 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42959
42960-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42961+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42962
42963 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42964 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42965diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42966index b914772..7ddbf9b 100644
42967--- a/drivers/media/radio/radio-shark.c
42968+++ b/drivers/media/radio/radio-shark.c
42969@@ -79,7 +79,7 @@ struct shark_device {
42970 u32 last_val;
42971 };
42972
42973-static atomic_t shark_instance = ATOMIC_INIT(0);
42974+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42975
42976 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42977 {
42978diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42979index 9fb6697..f167415 100644
42980--- a/drivers/media/radio/radio-shark2.c
42981+++ b/drivers/media/radio/radio-shark2.c
42982@@ -74,7 +74,7 @@ struct shark_device {
42983 u8 *transfer_buffer;
42984 };
42985
42986-static atomic_t shark_instance = ATOMIC_INIT(0);
42987+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42988
42989 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42990 {
42991diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42992index 9c9084c..a9e8dfb 100644
42993--- a/drivers/media/radio/radio-si476x.c
42994+++ b/drivers/media/radio/radio-si476x.c
42995@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42996 struct si476x_radio *radio;
42997 struct v4l2_ctrl *ctrl;
42998
42999- static atomic_t instance = ATOMIC_INIT(0);
43000+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43001
43002 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43003 if (!radio)
43004diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43005index 46da365..3ba4206 100644
43006--- a/drivers/media/rc/rc-main.c
43007+++ b/drivers/media/rc/rc-main.c
43008@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43009 int rc_register_device(struct rc_dev *dev)
43010 {
43011 static bool raw_init = false; /* raw decoders loaded? */
43012- static atomic_t devno = ATOMIC_INIT(0);
43013+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43014 struct rc_map *rc_map;
43015 const char *path;
43016 int rc;
43017@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43018 */
43019 mutex_lock(&dev->lock);
43020
43021- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43022+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43023 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43024 dev_set_drvdata(&dev->dev, dev);
43025 rc = device_add(&dev->dev);
43026diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43027index 20e345d..da56fe4 100644
43028--- a/drivers/media/usb/dvb-usb/cxusb.c
43029+++ b/drivers/media/usb/dvb-usb/cxusb.c
43030@@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43031
43032 struct dib0700_adapter_state {
43033 int (*set_param_save) (struct dvb_frontend *);
43034-};
43035+} __no_const;
43036
43037 static int dib7070_set_param_override(struct dvb_frontend *fe)
43038 {
43039diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43040index 71b22f5..a63b33f 100644
43041--- a/drivers/media/usb/dvb-usb/dw2102.c
43042+++ b/drivers/media/usb/dvb-usb/dw2102.c
43043@@ -121,7 +121,7 @@ struct su3000_state {
43044
43045 struct s6x0_state {
43046 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43047-};
43048+} __no_const;
43049
43050 /* debug */
43051 static int dvb_usb_dw2102_debug;
43052diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43053index 8f7a6a4..59502dd 100644
43054--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43055+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43056@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43057 __u32 reserved;
43058 };
43059
43060-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43061+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43062 enum v4l2_memory memory)
43063 {
43064 void __user *up_pln;
43065@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43066 return 0;
43067 }
43068
43069-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43070+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43071 enum v4l2_memory memory)
43072 {
43073 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43074@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43075 put_user(kp->start_block, &up->start_block) ||
43076 put_user(kp->blocks, &up->blocks) ||
43077 put_user(tmp, &up->edid) ||
43078- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43079+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43080 return -EFAULT;
43081 return 0;
43082 }
43083diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43084index 02d1b63..5fd6b16 100644
43085--- a/drivers/media/v4l2-core/v4l2-device.c
43086+++ b/drivers/media/v4l2-core/v4l2-device.c
43087@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43088 EXPORT_SYMBOL_GPL(v4l2_device_put);
43089
43090 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43091- atomic_t *instance)
43092+ atomic_unchecked_t *instance)
43093 {
43094- int num = atomic_inc_return(instance) - 1;
43095+ int num = atomic_inc_return_unchecked(instance) - 1;
43096 int len = strlen(basename);
43097
43098 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43099diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43100index 68e6b5e..d8b923e 100644
43101--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43102+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43103@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43104 struct file *file, void *fh, void *p);
43105 } u;
43106 void (*debug)(const void *arg, bool write_only);
43107-};
43108+} __do_const;
43109+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43110
43111 /* This control needs a priority check */
43112 #define INFO_FL_PRIO (1 << 0)
43113@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43114 struct video_device *vfd = video_devdata(file);
43115 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43116 bool write_only = false;
43117- struct v4l2_ioctl_info default_info;
43118+ v4l2_ioctl_info_no_const default_info;
43119 const struct v4l2_ioctl_info *info;
43120 void *fh = file->private_data;
43121 struct v4l2_fh *vfh = NULL;
43122@@ -2194,7 +2195,7 @@ done:
43123 }
43124
43125 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43126- void * __user *user_ptr, void ***kernel_ptr)
43127+ void __user **user_ptr, void ***kernel_ptr)
43128 {
43129 int ret = 0;
43130
43131@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43132 ret = -EINVAL;
43133 break;
43134 }
43135- *user_ptr = (void __user *)buf->m.planes;
43136+ *user_ptr = (void __force_user *)buf->m.planes;
43137 *kernel_ptr = (void *)&buf->m.planes;
43138 *array_size = sizeof(struct v4l2_plane) * buf->length;
43139 ret = 1;
43140@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43141 ret = -EINVAL;
43142 break;
43143 }
43144- *user_ptr = (void __user *)ctrls->controls;
43145+ *user_ptr = (void __force_user *)ctrls->controls;
43146 *kernel_ptr = (void *)&ctrls->controls;
43147 *array_size = sizeof(struct v4l2_ext_control)
43148 * ctrls->count;
43149diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43150index 767ff4d..c69d259 100644
43151--- a/drivers/message/fusion/mptbase.c
43152+++ b/drivers/message/fusion/mptbase.c
43153@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43154 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43155 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43156
43157+#ifdef CONFIG_GRKERNSEC_HIDESYM
43158+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43159+#else
43160 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43161 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43162+#endif
43163+
43164 /*
43165 * Rounding UP to nearest 4-kB boundary here...
43166 */
43167@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43168 ioc->facts.GlobalCredits);
43169
43170 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43171+#ifdef CONFIG_GRKERNSEC_HIDESYM
43172+ NULL, NULL);
43173+#else
43174 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43175+#endif
43176 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43177 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43178 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43179diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43180index dd239bd..689c4f7 100644
43181--- a/drivers/message/fusion/mptsas.c
43182+++ b/drivers/message/fusion/mptsas.c
43183@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43184 return 0;
43185 }
43186
43187+static inline void
43188+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43189+{
43190+ if (phy_info->port_details) {
43191+ phy_info->port_details->rphy = rphy;
43192+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43193+ ioc->name, rphy));
43194+ }
43195+
43196+ if (rphy) {
43197+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43198+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43199+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43200+ ioc->name, rphy, rphy->dev.release));
43201+ }
43202+}
43203+
43204 /* no mutex */
43205 static void
43206 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43207@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43208 return NULL;
43209 }
43210
43211-static inline void
43212-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43213-{
43214- if (phy_info->port_details) {
43215- phy_info->port_details->rphy = rphy;
43216- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43217- ioc->name, rphy));
43218- }
43219-
43220- if (rphy) {
43221- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43222- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43223- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43224- ioc->name, rphy, rphy->dev.release));
43225- }
43226-}
43227-
43228 static inline struct sas_port *
43229 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43230 {
43231diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43232index 727819c..ad74694 100644
43233--- a/drivers/message/fusion/mptscsih.c
43234+++ b/drivers/message/fusion/mptscsih.c
43235@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43236
43237 h = shost_priv(SChost);
43238
43239- if (h) {
43240- if (h->info_kbuf == NULL)
43241- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43242- return h->info_kbuf;
43243- h->info_kbuf[0] = '\0';
43244+ if (!h)
43245+ return NULL;
43246
43247- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43248- h->info_kbuf[size-1] = '\0';
43249- }
43250+ if (h->info_kbuf == NULL)
43251+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43252+ return h->info_kbuf;
43253+ h->info_kbuf[0] = '\0';
43254+
43255+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43256+ h->info_kbuf[size-1] = '\0';
43257
43258 return h->info_kbuf;
43259 }
43260diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43261index b7d87cd..3fb36da 100644
43262--- a/drivers/message/i2o/i2o_proc.c
43263+++ b/drivers/message/i2o/i2o_proc.c
43264@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43265 "Array Controller Device"
43266 };
43267
43268-static char *chtostr(char *tmp, u8 *chars, int n)
43269-{
43270- tmp[0] = 0;
43271- return strncat(tmp, (char *)chars, n);
43272-}
43273-
43274 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43275 char *group)
43276 {
43277@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
43278 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
43279 {
43280 struct i2o_controller *c = (struct i2o_controller *)seq->private;
43281- static u32 work32[5];
43282- static u8 *work8 = (u8 *) work32;
43283- static u16 *work16 = (u16 *) work32;
43284+ u32 work32[5];
43285+ u8 *work8 = (u8 *) work32;
43286+ u16 *work16 = (u16 *) work32;
43287 int token;
43288 u32 hwcap;
43289
43290@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43291 } *result;
43292
43293 i2o_exec_execute_ddm_table ddm_table;
43294- char tmp[28 + 1];
43295
43296 result = kmalloc(sizeof(*result), GFP_KERNEL);
43297 if (!result)
43298@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43299
43300 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43301 seq_printf(seq, "%-#8x", ddm_table.module_id);
43302- seq_printf(seq, "%-29s",
43303- chtostr(tmp, ddm_table.module_name_version, 28));
43304+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43305 seq_printf(seq, "%9d ", ddm_table.data_size);
43306 seq_printf(seq, "%8d", ddm_table.code_size);
43307
43308@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43309
43310 i2o_driver_result_table *result;
43311 i2o_driver_store_table *dst;
43312- char tmp[28 + 1];
43313
43314 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43315 if (result == NULL)
43316@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43317
43318 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43319 seq_printf(seq, "%-#8x", dst->module_id);
43320- seq_printf(seq, "%-29s",
43321- chtostr(tmp, dst->module_name_version, 28));
43322- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43323+ seq_printf(seq, "%-.28s", dst->module_name_version);
43324+ seq_printf(seq, "%-.8s", dst->date);
43325 seq_printf(seq, "%8d ", dst->module_size);
43326 seq_printf(seq, "%8d ", dst->mpb_size);
43327 seq_printf(seq, "0x%04x", dst->module_flags);
43328@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
43329 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43330 {
43331 struct i2o_device *d = (struct i2o_device *)seq->private;
43332- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
43333+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
43334 // == (allow) 512d bytes (max)
43335- static u16 *work16 = (u16 *) work32;
43336+ u16 *work16 = (u16 *) work32;
43337 int token;
43338- char tmp[16 + 1];
43339
43340 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43341
43342@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43343 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43344 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43345 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43346- seq_printf(seq, "Vendor info : %s\n",
43347- chtostr(tmp, (u8 *) (work32 + 2), 16));
43348- seq_printf(seq, "Product info : %s\n",
43349- chtostr(tmp, (u8 *) (work32 + 6), 16));
43350- seq_printf(seq, "Description : %s\n",
43351- chtostr(tmp, (u8 *) (work32 + 10), 16));
43352- seq_printf(seq, "Product rev. : %s\n",
43353- chtostr(tmp, (u8 *) (work32 + 14), 8));
43354+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43355+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43356+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43357+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43358
43359 seq_printf(seq, "Serial number : ");
43360 print_serial_number(seq, (u8 *) (work32 + 16),
43361@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43362 u8 pad[256]; // allow up to 256 byte (max) serial number
43363 } result;
43364
43365- char tmp[24 + 1];
43366-
43367 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43368
43369 if (token < 0) {
43370@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43371 }
43372
43373 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43374- seq_printf(seq, "Module name : %s\n",
43375- chtostr(tmp, result.module_name, 24));
43376- seq_printf(seq, "Module revision : %s\n",
43377- chtostr(tmp, result.module_rev, 8));
43378+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43379+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43380
43381 seq_printf(seq, "Serial number : ");
43382 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43383@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43384 u8 instance_number[4];
43385 } result;
43386
43387- char tmp[64 + 1];
43388-
43389 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43390
43391 if (token < 0) {
43392@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43393 return 0;
43394 }
43395
43396- seq_printf(seq, "Device name : %s\n",
43397- chtostr(tmp, result.device_name, 64));
43398- seq_printf(seq, "Service name : %s\n",
43399- chtostr(tmp, result.service_name, 64));
43400- seq_printf(seq, "Physical name : %s\n",
43401- chtostr(tmp, result.physical_location, 64));
43402- seq_printf(seq, "Instance number : %s\n",
43403- chtostr(tmp, result.instance_number, 4));
43404+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43405+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43406+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43407+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43408
43409 return 0;
43410 }
43411@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43412 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
43413 {
43414 struct i2o_device *d = (struct i2o_device *)seq->private;
43415- static u32 work32[12];
43416- static u16 *work16 = (u16 *) work32;
43417- static u8 *work8 = (u8 *) work32;
43418+ u32 work32[12];
43419+ u16 *work16 = (u16 *) work32;
43420+ u8 *work8 = (u8 *) work32;
43421 int token;
43422
43423 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
43424diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43425index a8c08f3..155fe3d 100644
43426--- a/drivers/message/i2o/iop.c
43427+++ b/drivers/message/i2o/iop.c
43428@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43429
43430 spin_lock_irqsave(&c->context_list_lock, flags);
43431
43432- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43433- atomic_inc(&c->context_list_counter);
43434+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43435+ atomic_inc_unchecked(&c->context_list_counter);
43436
43437- entry->context = atomic_read(&c->context_list_counter);
43438+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43439
43440 list_add(&entry->list, &c->context_list);
43441
43442@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43443
43444 #if BITS_PER_LONG == 64
43445 spin_lock_init(&c->context_list_lock);
43446- atomic_set(&c->context_list_counter, 0);
43447+ atomic_set_unchecked(&c->context_list_counter, 0);
43448 INIT_LIST_HEAD(&c->context_list);
43449 #endif
43450
43451diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43452index fcbb2e9..2635e11 100644
43453--- a/drivers/mfd/janz-cmodio.c
43454+++ b/drivers/mfd/janz-cmodio.c
43455@@ -13,6 +13,7 @@
43456
43457 #include <linux/kernel.h>
43458 #include <linux/module.h>
43459+#include <linux/slab.h>
43460 #include <linux/init.h>
43461 #include <linux/pci.h>
43462 #include <linux/interrupt.h>
43463diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
43464index de7fb80..7c1b931 100644
43465--- a/drivers/mfd/max8925-i2c.c
43466+++ b/drivers/mfd/max8925-i2c.c
43467@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
43468 const struct i2c_device_id *id)
43469 {
43470 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
43471- static struct max8925_chip *chip;
43472+ struct max8925_chip *chip;
43473 struct device_node *node = client->dev.of_node;
43474
43475 if (node && !pdata) {
43476diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
43477index d792772..cd73ba3 100644
43478--- a/drivers/mfd/tps65910.c
43479+++ b/drivers/mfd/tps65910.c
43480@@ -229,7 +229,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
43481 struct tps65910_platform_data *pdata)
43482 {
43483 int ret = 0;
43484- static struct regmap_irq_chip *tps6591x_irqs_chip;
43485+ struct regmap_irq_chip *tps6591x_irqs_chip;
43486
43487 if (!irq) {
43488 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
43489diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43490index 9aa6d1e..1631bfc 100644
43491--- a/drivers/mfd/twl4030-irq.c
43492+++ b/drivers/mfd/twl4030-irq.c
43493@@ -35,6 +35,7 @@
43494 #include <linux/of.h>
43495 #include <linux/irqdomain.h>
43496 #include <linux/i2c/twl.h>
43497+#include <asm/pgtable.h>
43498
43499 #include "twl-core.h"
43500
43501@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43502 * Install an irq handler for each of the SIH modules;
43503 * clone dummy irq_chip since PIH can't *do* anything
43504 */
43505- twl4030_irq_chip = dummy_irq_chip;
43506- twl4030_irq_chip.name = "twl4030";
43507+ pax_open_kernel();
43508+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43509+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43510
43511- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43512+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43513+ pax_close_kernel();
43514
43515 for (i = irq_base; i < irq_end; i++) {
43516 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43517diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43518index 464419b..64bae8d 100644
43519--- a/drivers/misc/c2port/core.c
43520+++ b/drivers/misc/c2port/core.c
43521@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
43522 goto error_idr_alloc;
43523 c2dev->id = ret;
43524
43525- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
43526+ pax_open_kernel();
43527+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
43528+ pax_close_kernel();
43529
43530 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
43531 "c2port%d", c2dev->id);
43532diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43533index 36f5d52..32311c3 100644
43534--- a/drivers/misc/kgdbts.c
43535+++ b/drivers/misc/kgdbts.c
43536@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43537 char before[BREAK_INSTR_SIZE];
43538 char after[BREAK_INSTR_SIZE];
43539
43540- probe_kernel_read(before, (char *)kgdbts_break_test,
43541+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43542 BREAK_INSTR_SIZE);
43543 init_simple_test();
43544 ts.tst = plant_and_detach_test;
43545@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43546 /* Activate test with initial breakpoint */
43547 if (!is_early)
43548 kgdb_breakpoint();
43549- probe_kernel_read(after, (char *)kgdbts_break_test,
43550+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43551 BREAK_INSTR_SIZE);
43552 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43553 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43554diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43555index 036effe..b3a6336 100644
43556--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43557+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43558@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43559 * the lid is closed. This leads to interrupts as soon as a little move
43560 * is done.
43561 */
43562- atomic_inc(&lis3->count);
43563+ atomic_inc_unchecked(&lis3->count);
43564
43565 wake_up_interruptible(&lis3->misc_wait);
43566 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43567@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43568 if (lis3->pm_dev)
43569 pm_runtime_get_sync(lis3->pm_dev);
43570
43571- atomic_set(&lis3->count, 0);
43572+ atomic_set_unchecked(&lis3->count, 0);
43573 return 0;
43574 }
43575
43576@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43577 add_wait_queue(&lis3->misc_wait, &wait);
43578 while (true) {
43579 set_current_state(TASK_INTERRUPTIBLE);
43580- data = atomic_xchg(&lis3->count, 0);
43581+ data = atomic_xchg_unchecked(&lis3->count, 0);
43582 if (data)
43583 break;
43584
43585@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43586 struct lis3lv02d, miscdev);
43587
43588 poll_wait(file, &lis3->misc_wait, wait);
43589- if (atomic_read(&lis3->count))
43590+ if (atomic_read_unchecked(&lis3->count))
43591 return POLLIN | POLLRDNORM;
43592 return 0;
43593 }
43594diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43595index c439c82..1f20f57 100644
43596--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43597+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43598@@ -297,7 +297,7 @@ struct lis3lv02d {
43599 struct input_polled_dev *idev; /* input device */
43600 struct platform_device *pdev; /* platform device */
43601 struct regulator_bulk_data regulators[2];
43602- atomic_t count; /* interrupt count after last read */
43603+ atomic_unchecked_t count; /* interrupt count after last read */
43604 union axis_conversion ac; /* hw -> logical axis */
43605 int mapped_btns[3];
43606
43607diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43608index 2f30bad..c4c13d0 100644
43609--- a/drivers/misc/sgi-gru/gruhandles.c
43610+++ b/drivers/misc/sgi-gru/gruhandles.c
43611@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43612 unsigned long nsec;
43613
43614 nsec = CLKS2NSEC(clks);
43615- atomic_long_inc(&mcs_op_statistics[op].count);
43616- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43617+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43618+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43619 if (mcs_op_statistics[op].max < nsec)
43620 mcs_op_statistics[op].max = nsec;
43621 }
43622diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43623index 4f76359..cdfcb2e 100644
43624--- a/drivers/misc/sgi-gru/gruprocfs.c
43625+++ b/drivers/misc/sgi-gru/gruprocfs.c
43626@@ -32,9 +32,9 @@
43627
43628 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43629
43630-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43631+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43632 {
43633- unsigned long val = atomic_long_read(v);
43634+ unsigned long val = atomic_long_read_unchecked(v);
43635
43636 seq_printf(s, "%16lu %s\n", val, id);
43637 }
43638@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43639
43640 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43641 for (op = 0; op < mcsop_last; op++) {
43642- count = atomic_long_read(&mcs_op_statistics[op].count);
43643- total = atomic_long_read(&mcs_op_statistics[op].total);
43644+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43645+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43646 max = mcs_op_statistics[op].max;
43647 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43648 count ? total / count : 0, max);
43649diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43650index 5c3ce24..4915ccb 100644
43651--- a/drivers/misc/sgi-gru/grutables.h
43652+++ b/drivers/misc/sgi-gru/grutables.h
43653@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43654 * GRU statistics.
43655 */
43656 struct gru_stats_s {
43657- atomic_long_t vdata_alloc;
43658- atomic_long_t vdata_free;
43659- atomic_long_t gts_alloc;
43660- atomic_long_t gts_free;
43661- atomic_long_t gms_alloc;
43662- atomic_long_t gms_free;
43663- atomic_long_t gts_double_allocate;
43664- atomic_long_t assign_context;
43665- atomic_long_t assign_context_failed;
43666- atomic_long_t free_context;
43667- atomic_long_t load_user_context;
43668- atomic_long_t load_kernel_context;
43669- atomic_long_t lock_kernel_context;
43670- atomic_long_t unlock_kernel_context;
43671- atomic_long_t steal_user_context;
43672- atomic_long_t steal_kernel_context;
43673- atomic_long_t steal_context_failed;
43674- atomic_long_t nopfn;
43675- atomic_long_t asid_new;
43676- atomic_long_t asid_next;
43677- atomic_long_t asid_wrap;
43678- atomic_long_t asid_reuse;
43679- atomic_long_t intr;
43680- atomic_long_t intr_cbr;
43681- atomic_long_t intr_tfh;
43682- atomic_long_t intr_spurious;
43683- atomic_long_t intr_mm_lock_failed;
43684- atomic_long_t call_os;
43685- atomic_long_t call_os_wait_queue;
43686- atomic_long_t user_flush_tlb;
43687- atomic_long_t user_unload_context;
43688- atomic_long_t user_exception;
43689- atomic_long_t set_context_option;
43690- atomic_long_t check_context_retarget_intr;
43691- atomic_long_t check_context_unload;
43692- atomic_long_t tlb_dropin;
43693- atomic_long_t tlb_preload_page;
43694- atomic_long_t tlb_dropin_fail_no_asid;
43695- atomic_long_t tlb_dropin_fail_upm;
43696- atomic_long_t tlb_dropin_fail_invalid;
43697- atomic_long_t tlb_dropin_fail_range_active;
43698- atomic_long_t tlb_dropin_fail_idle;
43699- atomic_long_t tlb_dropin_fail_fmm;
43700- atomic_long_t tlb_dropin_fail_no_exception;
43701- atomic_long_t tfh_stale_on_fault;
43702- atomic_long_t mmu_invalidate_range;
43703- atomic_long_t mmu_invalidate_page;
43704- atomic_long_t flush_tlb;
43705- atomic_long_t flush_tlb_gru;
43706- atomic_long_t flush_tlb_gru_tgh;
43707- atomic_long_t flush_tlb_gru_zero_asid;
43708+ atomic_long_unchecked_t vdata_alloc;
43709+ atomic_long_unchecked_t vdata_free;
43710+ atomic_long_unchecked_t gts_alloc;
43711+ atomic_long_unchecked_t gts_free;
43712+ atomic_long_unchecked_t gms_alloc;
43713+ atomic_long_unchecked_t gms_free;
43714+ atomic_long_unchecked_t gts_double_allocate;
43715+ atomic_long_unchecked_t assign_context;
43716+ atomic_long_unchecked_t assign_context_failed;
43717+ atomic_long_unchecked_t free_context;
43718+ atomic_long_unchecked_t load_user_context;
43719+ atomic_long_unchecked_t load_kernel_context;
43720+ atomic_long_unchecked_t lock_kernel_context;
43721+ atomic_long_unchecked_t unlock_kernel_context;
43722+ atomic_long_unchecked_t steal_user_context;
43723+ atomic_long_unchecked_t steal_kernel_context;
43724+ atomic_long_unchecked_t steal_context_failed;
43725+ atomic_long_unchecked_t nopfn;
43726+ atomic_long_unchecked_t asid_new;
43727+ atomic_long_unchecked_t asid_next;
43728+ atomic_long_unchecked_t asid_wrap;
43729+ atomic_long_unchecked_t asid_reuse;
43730+ atomic_long_unchecked_t intr;
43731+ atomic_long_unchecked_t intr_cbr;
43732+ atomic_long_unchecked_t intr_tfh;
43733+ atomic_long_unchecked_t intr_spurious;
43734+ atomic_long_unchecked_t intr_mm_lock_failed;
43735+ atomic_long_unchecked_t call_os;
43736+ atomic_long_unchecked_t call_os_wait_queue;
43737+ atomic_long_unchecked_t user_flush_tlb;
43738+ atomic_long_unchecked_t user_unload_context;
43739+ atomic_long_unchecked_t user_exception;
43740+ atomic_long_unchecked_t set_context_option;
43741+ atomic_long_unchecked_t check_context_retarget_intr;
43742+ atomic_long_unchecked_t check_context_unload;
43743+ atomic_long_unchecked_t tlb_dropin;
43744+ atomic_long_unchecked_t tlb_preload_page;
43745+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43746+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43747+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43748+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43749+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43750+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43751+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43752+ atomic_long_unchecked_t tfh_stale_on_fault;
43753+ atomic_long_unchecked_t mmu_invalidate_range;
43754+ atomic_long_unchecked_t mmu_invalidate_page;
43755+ atomic_long_unchecked_t flush_tlb;
43756+ atomic_long_unchecked_t flush_tlb_gru;
43757+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43758+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43759
43760- atomic_long_t copy_gpa;
43761- atomic_long_t read_gpa;
43762+ atomic_long_unchecked_t copy_gpa;
43763+ atomic_long_unchecked_t read_gpa;
43764
43765- atomic_long_t mesq_receive;
43766- atomic_long_t mesq_receive_none;
43767- atomic_long_t mesq_send;
43768- atomic_long_t mesq_send_failed;
43769- atomic_long_t mesq_noop;
43770- atomic_long_t mesq_send_unexpected_error;
43771- atomic_long_t mesq_send_lb_overflow;
43772- atomic_long_t mesq_send_qlimit_reached;
43773- atomic_long_t mesq_send_amo_nacked;
43774- atomic_long_t mesq_send_put_nacked;
43775- atomic_long_t mesq_page_overflow;
43776- atomic_long_t mesq_qf_locked;
43777- atomic_long_t mesq_qf_noop_not_full;
43778- atomic_long_t mesq_qf_switch_head_failed;
43779- atomic_long_t mesq_qf_unexpected_error;
43780- atomic_long_t mesq_noop_unexpected_error;
43781- atomic_long_t mesq_noop_lb_overflow;
43782- atomic_long_t mesq_noop_qlimit_reached;
43783- atomic_long_t mesq_noop_amo_nacked;
43784- atomic_long_t mesq_noop_put_nacked;
43785- atomic_long_t mesq_noop_page_overflow;
43786+ atomic_long_unchecked_t mesq_receive;
43787+ atomic_long_unchecked_t mesq_receive_none;
43788+ atomic_long_unchecked_t mesq_send;
43789+ atomic_long_unchecked_t mesq_send_failed;
43790+ atomic_long_unchecked_t mesq_noop;
43791+ atomic_long_unchecked_t mesq_send_unexpected_error;
43792+ atomic_long_unchecked_t mesq_send_lb_overflow;
43793+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43794+ atomic_long_unchecked_t mesq_send_amo_nacked;
43795+ atomic_long_unchecked_t mesq_send_put_nacked;
43796+ atomic_long_unchecked_t mesq_page_overflow;
43797+ atomic_long_unchecked_t mesq_qf_locked;
43798+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43799+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43800+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43801+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43802+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43803+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43804+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43805+ atomic_long_unchecked_t mesq_noop_put_nacked;
43806+ atomic_long_unchecked_t mesq_noop_page_overflow;
43807
43808 };
43809
43810@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43811 tghop_invalidate, mcsop_last};
43812
43813 struct mcs_op_statistic {
43814- atomic_long_t count;
43815- atomic_long_t total;
43816+ atomic_long_unchecked_t count;
43817+ atomic_long_unchecked_t total;
43818 unsigned long max;
43819 };
43820
43821@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43822
43823 #define STAT(id) do { \
43824 if (gru_options & OPT_STATS) \
43825- atomic_long_inc(&gru_stats.id); \
43826+ atomic_long_inc_unchecked(&gru_stats.id); \
43827 } while (0)
43828
43829 #ifdef CONFIG_SGI_GRU_DEBUG
43830diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43831index c862cd4..0d176fe 100644
43832--- a/drivers/misc/sgi-xp/xp.h
43833+++ b/drivers/misc/sgi-xp/xp.h
43834@@ -288,7 +288,7 @@ struct xpc_interface {
43835 xpc_notify_func, void *);
43836 void (*received) (short, int, void *);
43837 enum xp_retval (*partid_to_nasids) (short, void *);
43838-};
43839+} __no_const;
43840
43841 extern struct xpc_interface xpc_interface;
43842
43843diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43844index b94d5f7..7f494c5 100644
43845--- a/drivers/misc/sgi-xp/xpc.h
43846+++ b/drivers/misc/sgi-xp/xpc.h
43847@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43848 void (*received_payload) (struct xpc_channel *, void *);
43849 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43850 };
43851+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43852
43853 /* struct xpc_partition act_state values (for XPC HB) */
43854
43855@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43856 /* found in xpc_main.c */
43857 extern struct device *xpc_part;
43858 extern struct device *xpc_chan;
43859-extern struct xpc_arch_operations xpc_arch_ops;
43860+extern xpc_arch_operations_no_const xpc_arch_ops;
43861 extern int xpc_disengage_timelimit;
43862 extern int xpc_disengage_timedout;
43863 extern int xpc_activate_IRQ_rcvd;
43864diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43865index 82dc574..8539ab2 100644
43866--- a/drivers/misc/sgi-xp/xpc_main.c
43867+++ b/drivers/misc/sgi-xp/xpc_main.c
43868@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43869 .notifier_call = xpc_system_die,
43870 };
43871
43872-struct xpc_arch_operations xpc_arch_ops;
43873+xpc_arch_operations_no_const xpc_arch_ops;
43874
43875 /*
43876 * Timer function to enforce the timelimit on the partition disengage.
43877@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43878
43879 if (((die_args->trapnr == X86_TRAP_MF) ||
43880 (die_args->trapnr == X86_TRAP_XF)) &&
43881- !user_mode_vm(die_args->regs))
43882+ !user_mode(die_args->regs))
43883 xpc_die_deactivate();
43884
43885 break;
43886diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43887index ef18348..1b53cf0 100644
43888--- a/drivers/mmc/core/mmc_ops.c
43889+++ b/drivers/mmc/core/mmc_ops.c
43890@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43891 void *data_buf;
43892 int is_on_stack;
43893
43894- is_on_stack = object_is_on_stack(buf);
43895+ is_on_stack = object_starts_on_stack(buf);
43896 if (is_on_stack) {
43897 /*
43898 * dma onto stack is unsafe/nonportable, but callers to this
43899diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43900index 81b2994..dce857e 100644
43901--- a/drivers/mmc/host/dw_mmc.h
43902+++ b/drivers/mmc/host/dw_mmc.h
43903@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43904 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43905 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43906 int (*parse_dt)(struct dw_mci *host);
43907-};
43908+} __do_const;
43909 #endif /* _DW_MMC_H_ */
43910diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43911index c3785ed..1984c44 100644
43912--- a/drivers/mmc/host/mmci.c
43913+++ b/drivers/mmc/host/mmci.c
43914@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43915 }
43916
43917 if (variant->busy_detect) {
43918- mmci_ops.card_busy = mmci_card_busy;
43919+ pax_open_kernel();
43920+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43921+ pax_close_kernel();
43922 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43923 }
43924
43925diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43926index 6debda9..2ba7427 100644
43927--- a/drivers/mmc/host/sdhci-s3c.c
43928+++ b/drivers/mmc/host/sdhci-s3c.c
43929@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43930 * we can use overriding functions instead of default.
43931 */
43932 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43933- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43934- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43935- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43936+ pax_open_kernel();
43937+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43938+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43939+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43940+ pax_close_kernel();
43941 }
43942
43943 /* It supports additional host capabilities if needed */
43944diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
43945index 096993f..f02c23b 100644
43946--- a/drivers/mtd/chips/cfi_cmdset_0020.c
43947+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
43948@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
43949 size_t totlen = 0, thislen;
43950 int ret = 0;
43951 size_t buflen = 0;
43952- static char *buffer;
43953+ char *buffer;
43954
43955 if (!ECCBUF_SIZE) {
43956 /* We should fall back to a general writev implementation.
43957diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43958index 2ed2bb3..2d0b82e 100644
43959--- a/drivers/mtd/nand/denali.c
43960+++ b/drivers/mtd/nand/denali.c
43961@@ -24,6 +24,7 @@
43962 #include <linux/slab.h>
43963 #include <linux/mtd/mtd.h>
43964 #include <linux/module.h>
43965+#include <linux/slab.h>
43966
43967 #include "denali.h"
43968
43969diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43970index 51b9d6a..52af9a7 100644
43971--- a/drivers/mtd/nftlmount.c
43972+++ b/drivers/mtd/nftlmount.c
43973@@ -24,6 +24,7 @@
43974 #include <asm/errno.h>
43975 #include <linux/delay.h>
43976 #include <linux/slab.h>
43977+#include <linux/sched.h>
43978 #include <linux/mtd/mtd.h>
43979 #include <linux/mtd/nand.h>
43980 #include <linux/mtd/nftl.h>
43981diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43982index 4b8e895..6b3c498 100644
43983--- a/drivers/mtd/sm_ftl.c
43984+++ b/drivers/mtd/sm_ftl.c
43985@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43986 #define SM_CIS_VENDOR_OFFSET 0x59
43987 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43988 {
43989- struct attribute_group *attr_group;
43990+ attribute_group_no_const *attr_group;
43991 struct attribute **attributes;
43992 struct sm_sysfs_attribute *vendor_attribute;
43993
43994diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43995index dd8057d..22aaf36 100644
43996--- a/drivers/net/bonding/bond_main.c
43997+++ b/drivers/net/bonding/bond_main.c
43998@@ -4511,7 +4511,7 @@ static unsigned int bond_get_num_tx_queues(void)
43999 return tx_queues;
44000 }
44001
44002-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44003+static struct rtnl_link_ops bond_link_ops = {
44004 .kind = "bond",
44005 .priv_size = sizeof(struct bonding),
44006 .setup = bond_setup,
44007@@ -4636,8 +4636,8 @@ static void __exit bonding_exit(void)
44008
44009 bond_destroy_debugfs();
44010
44011- rtnl_link_unregister(&bond_link_ops);
44012 unregister_pernet_subsys(&bond_net_ops);
44013+ rtnl_link_unregister(&bond_link_ops);
44014
44015 #ifdef CONFIG_NET_POLL_CONTROLLER
44016 /*
44017diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44018index f92f001..0b2f9bf 100644
44019--- a/drivers/net/ethernet/8390/ax88796.c
44020+++ b/drivers/net/ethernet/8390/ax88796.c
44021@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44022 if (ax->plat->reg_offsets)
44023 ei_local->reg_offset = ax->plat->reg_offsets;
44024 else {
44025+ resource_size_t _mem_size = mem_size;
44026+ do_div(_mem_size, 0x18);
44027 ei_local->reg_offset = ax->reg_offsets;
44028 for (ret = 0; ret < 0x18; ret++)
44029- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44030+ ax->reg_offsets[ret] = _mem_size * ret;
44031 }
44032
44033 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44034diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44035index da8fcaa..f4b5d3b 100644
44036--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44037+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44038@@ -1138,7 +1138,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44039 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44040 {
44041 /* RX_MODE controlling object */
44042- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44043+ bnx2x_init_rx_mode_obj(bp);
44044
44045 /* multicast configuration controlling object */
44046 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44047diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44048index 9fbeee5..5e3e37a 100644
44049--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44050+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44051@@ -2590,15 +2590,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44052 return rc;
44053 }
44054
44055-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44056- struct bnx2x_rx_mode_obj *o)
44057+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44058 {
44059 if (CHIP_IS_E1x(bp)) {
44060- o->wait_comp = bnx2x_empty_rx_mode_wait;
44061- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44062+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44063+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44064 } else {
44065- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44066- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44067+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44068+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44069 }
44070 }
44071
44072diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44073index 658f4e3..15074a6 100644
44074--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44075+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44076@@ -1325,8 +1325,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44077
44078 /********************* RX MODE ****************/
44079
44080-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44081- struct bnx2x_rx_mode_obj *o);
44082+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44083
44084 /**
44085 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44086diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44087index 7025780..e55a71c 100644
44088--- a/drivers/net/ethernet/broadcom/tg3.h
44089+++ b/drivers/net/ethernet/broadcom/tg3.h
44090@@ -147,6 +147,7 @@
44091 #define CHIPREV_ID_5750_A0 0x4000
44092 #define CHIPREV_ID_5750_A1 0x4001
44093 #define CHIPREV_ID_5750_A3 0x4003
44094+#define CHIPREV_ID_5750_C1 0x4201
44095 #define CHIPREV_ID_5750_C2 0x4202
44096 #define CHIPREV_ID_5752_A0_HW 0x5000
44097 #define CHIPREV_ID_5752_A0 0x6000
44098diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44099index 8cffcdf..aadf043 100644
44100--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44101+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44102@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44103 */
44104 struct l2t_skb_cb {
44105 arp_failure_handler_func arp_failure_handler;
44106-};
44107+} __no_const;
44108
44109 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44110
44111diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44112index c73cabd..cd278b1 100644
44113--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44114+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44115@@ -2186,7 +2186,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
44116
44117 int i;
44118 struct adapter *ap = netdev2adap(dev);
44119- static const unsigned int *reg_ranges;
44120+ const unsigned int *reg_ranges;
44121 int arr_size = 0, buf_size = 0;
44122
44123 if (is_t4(ap->chip)) {
44124diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44125index 263b92c..f05134b 100644
44126--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44127+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44128@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44129 for (i=0; i<ETH_ALEN; i++) {
44130 tmp.addr[i] = dev->dev_addr[i];
44131 }
44132- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44133+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44134 break;
44135
44136 case DE4X5_SET_HWADDR: /* Set the hardware address */
44137@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44138 spin_lock_irqsave(&lp->lock, flags);
44139 memcpy(&statbuf, &lp->pktStats, ioc->len);
44140 spin_unlock_irqrestore(&lp->lock, flags);
44141- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44142+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44143 return -EFAULT;
44144 break;
44145 }
44146diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44147index 2c38cc4..0323f6e 100644
44148--- a/drivers/net/ethernet/emulex/benet/be_main.c
44149+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44150@@ -470,7 +470,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44151
44152 if (wrapped)
44153 newacc += 65536;
44154- ACCESS_ONCE(*acc) = newacc;
44155+ ACCESS_ONCE_RW(*acc) = newacc;
44156 }
44157
44158 static void populate_erx_stats(struct be_adapter *adapter,
44159diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44160index 212f44b..fb69959 100644
44161--- a/drivers/net/ethernet/faraday/ftgmac100.c
44162+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44163@@ -31,6 +31,8 @@
44164 #include <linux/netdevice.h>
44165 #include <linux/phy.h>
44166 #include <linux/platform_device.h>
44167+#include <linux/interrupt.h>
44168+#include <linux/irqreturn.h>
44169 #include <net/ip.h>
44170
44171 #include "ftgmac100.h"
44172diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44173index 8be5b40..081bc1b 100644
44174--- a/drivers/net/ethernet/faraday/ftmac100.c
44175+++ b/drivers/net/ethernet/faraday/ftmac100.c
44176@@ -31,6 +31,8 @@
44177 #include <linux/module.h>
44178 #include <linux/netdevice.h>
44179 #include <linux/platform_device.h>
44180+#include <linux/interrupt.h>
44181+#include <linux/irqreturn.h>
44182
44183 #include "ftmac100.h"
44184
44185diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44186index 5184e2a..acb28c3 100644
44187--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44188+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44189@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44190 }
44191
44192 /* update the base incval used to calculate frequency adjustment */
44193- ACCESS_ONCE(adapter->base_incval) = incval;
44194+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44195 smp_mb();
44196
44197 /* need lock to prevent incorrect read while modifying cyclecounter */
44198diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44199index fbe5363..266b4e3 100644
44200--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44201+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44202@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44203 struct __vxge_hw_fifo *fifo;
44204 struct vxge_hw_fifo_config *config;
44205 u32 txdl_size, txdl_per_memblock;
44206- struct vxge_hw_mempool_cbs fifo_mp_callback;
44207+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44208+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44209+ };
44210+
44211 struct __vxge_hw_virtualpath *vpath;
44212
44213 if ((vp == NULL) || (attr == NULL)) {
44214@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44215 goto exit;
44216 }
44217
44218- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44219-
44220 fifo->mempool =
44221 __vxge_hw_mempool_create(vpath->hldev,
44222 fifo->config->memblock_size,
44223diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44224index f09e787..f3916a8 100644
44225--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44226+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44227@@ -2055,7 +2055,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
44228
44229 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
44230 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
44231- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44232+ pax_open_kernel();
44233+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44234+ pax_close_kernel();
44235 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44236 } else {
44237 return -EIO;
44238diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44239index 0248a4c..9648d96 100644
44240--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44241+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44242@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44243 case QLCNIC_NON_PRIV_FUNC:
44244 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44245 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44246- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44247+ pax_open_kernel();
44248+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44249+ pax_close_kernel();
44250 break;
44251 case QLCNIC_PRIV_FUNC:
44252 ahw->op_mode = QLCNIC_PRIV_FUNC;
44253 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44254- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44255+ pax_open_kernel();
44256+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44257+ pax_close_kernel();
44258 break;
44259 case QLCNIC_MGMT_FUNC:
44260 ahw->op_mode = QLCNIC_MGMT_FUNC;
44261 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44262- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44263+ pax_open_kernel();
44264+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44265+ pax_close_kernel();
44266 break;
44267 default:
44268 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44269diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
44270index 1551360..ed6510f 100644
44271--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
44272+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
44273@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
44274 struct qlcnic_dump_entry *entry;
44275 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
44276 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
44277- static const struct qlcnic_dump_operations *fw_dump_ops;
44278+ const struct qlcnic_dump_operations *fw_dump_ops;
44279 struct device *dev = &adapter->pdev->dev;
44280 struct qlcnic_hardware_context *ahw;
44281 void *temp_buffer;
44282diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44283index fb3f8dc..9d2ff38 100644
44284--- a/drivers/net/ethernet/realtek/r8169.c
44285+++ b/drivers/net/ethernet/realtek/r8169.c
44286@@ -759,22 +759,22 @@ struct rtl8169_private {
44287 struct mdio_ops {
44288 void (*write)(struct rtl8169_private *, int, int);
44289 int (*read)(struct rtl8169_private *, int);
44290- } mdio_ops;
44291+ } __no_const mdio_ops;
44292
44293 struct pll_power_ops {
44294 void (*down)(struct rtl8169_private *);
44295 void (*up)(struct rtl8169_private *);
44296- } pll_power_ops;
44297+ } __no_const pll_power_ops;
44298
44299 struct jumbo_ops {
44300 void (*enable)(struct rtl8169_private *);
44301 void (*disable)(struct rtl8169_private *);
44302- } jumbo_ops;
44303+ } __no_const jumbo_ops;
44304
44305 struct csi_ops {
44306 void (*write)(struct rtl8169_private *, int, int);
44307 u32 (*read)(struct rtl8169_private *, int);
44308- } csi_ops;
44309+ } __no_const csi_ops;
44310
44311 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44312 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44313diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44314index 03acf57..e1251ff 100644
44315--- a/drivers/net/ethernet/sfc/ptp.c
44316+++ b/drivers/net/ethernet/sfc/ptp.c
44317@@ -539,7 +539,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44318 ptp->start.dma_addr);
44319
44320 /* Clear flag that signals MC ready */
44321- ACCESS_ONCE(*start) = 0;
44322+ ACCESS_ONCE_RW(*start) = 0;
44323 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44324 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44325 EFX_BUG_ON_PARANOID(rc);
44326diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44327index 50617c5..b13724c 100644
44328--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44329+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44330@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44331
44332 writel(value, ioaddr + MMC_CNTRL);
44333
44334- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44335- MMC_CNTRL, value);
44336+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44337+// MMC_CNTRL, value);
44338 }
44339
44340 /* To mask all all interrupts.*/
44341diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
44342index 3169252..5d78c1d 100644
44343--- a/drivers/net/hamradio/hdlcdrv.c
44344+++ b/drivers/net/hamradio/hdlcdrv.c
44345@@ -571,6 +571,8 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44346 case HDLCDRVCTL_CALIBRATE:
44347 if(!capable(CAP_SYS_RAWIO))
44348 return -EPERM;
44349+ if (bi.data.calibrate > INT_MAX / s->par.bitrate)
44350+ return -EINVAL;
44351 s->hdlctx.calibrate = bi.data.calibrate * s->par.bitrate / 16;
44352 return 0;
44353
44354diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44355index e6fe0d8..2b7d752 100644
44356--- a/drivers/net/hyperv/hyperv_net.h
44357+++ b/drivers/net/hyperv/hyperv_net.h
44358@@ -101,7 +101,7 @@ struct rndis_device {
44359
44360 enum rndis_device_state state;
44361 bool link_state;
44362- atomic_t new_req_id;
44363+ atomic_unchecked_t new_req_id;
44364
44365 spinlock_t request_lock;
44366 struct list_head req_list;
44367diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44368index 0775f0a..d4fb316 100644
44369--- a/drivers/net/hyperv/rndis_filter.c
44370+++ b/drivers/net/hyperv/rndis_filter.c
44371@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44372 * template
44373 */
44374 set = &rndis_msg->msg.set_req;
44375- set->req_id = atomic_inc_return(&dev->new_req_id);
44376+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44377
44378 /* Add to the request list */
44379 spin_lock_irqsave(&dev->request_lock, flags);
44380@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44381
44382 /* Setup the rndis set */
44383 halt = &request->request_msg.msg.halt_req;
44384- halt->req_id = atomic_inc_return(&dev->new_req_id);
44385+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44386
44387 /* Ignore return since this msg is optional. */
44388 rndis_filter_send_request(dev, request);
44389diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44390index bf0d55e..82bcfbd1 100644
44391--- a/drivers/net/ieee802154/fakehard.c
44392+++ b/drivers/net/ieee802154/fakehard.c
44393@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44394 phy->transmit_power = 0xbf;
44395
44396 dev->netdev_ops = &fake_ops;
44397- dev->ml_priv = &fake_mlme;
44398+ dev->ml_priv = (void *)&fake_mlme;
44399
44400 priv = netdev_priv(dev);
44401 priv->phy = phy;
44402diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44403index 9bf46bd..bfdaa84 100644
44404--- a/drivers/net/macvlan.c
44405+++ b/drivers/net/macvlan.c
44406@@ -939,13 +939,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44407 int macvlan_link_register(struct rtnl_link_ops *ops)
44408 {
44409 /* common fields */
44410- ops->priv_size = sizeof(struct macvlan_dev);
44411- ops->validate = macvlan_validate;
44412- ops->maxtype = IFLA_MACVLAN_MAX;
44413- ops->policy = macvlan_policy;
44414- ops->changelink = macvlan_changelink;
44415- ops->get_size = macvlan_get_size;
44416- ops->fill_info = macvlan_fill_info;
44417+ pax_open_kernel();
44418+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44419+ *(void **)&ops->validate = macvlan_validate;
44420+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44421+ *(const void **)&ops->policy = macvlan_policy;
44422+ *(void **)&ops->changelink = macvlan_changelink;
44423+ *(void **)&ops->get_size = macvlan_get_size;
44424+ *(void **)&ops->fill_info = macvlan_fill_info;
44425+ pax_close_kernel();
44426
44427 return rtnl_link_register(ops);
44428 };
44429@@ -1001,7 +1003,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44430 return NOTIFY_DONE;
44431 }
44432
44433-static struct notifier_block macvlan_notifier_block __read_mostly = {
44434+static struct notifier_block macvlan_notifier_block = {
44435 .notifier_call = macvlan_device_event,
44436 };
44437
44438diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44439index dc76670..e18f39c 100644
44440--- a/drivers/net/macvtap.c
44441+++ b/drivers/net/macvtap.c
44442@@ -1189,7 +1189,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44443 return NOTIFY_DONE;
44444 }
44445
44446-static struct notifier_block macvtap_notifier_block __read_mostly = {
44447+static struct notifier_block macvtap_notifier_block = {
44448 .notifier_call = macvtap_device_event,
44449 };
44450
44451diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44452index daec9b0..6428fcb 100644
44453--- a/drivers/net/phy/mdio-bitbang.c
44454+++ b/drivers/net/phy/mdio-bitbang.c
44455@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44456 struct mdiobb_ctrl *ctrl = bus->priv;
44457
44458 module_put(ctrl->ops->owner);
44459+ mdiobus_unregister(bus);
44460 mdiobus_free(bus);
44461 }
44462 EXPORT_SYMBOL(free_mdio_bitbang);
44463diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44464index 72ff14b..11d442d 100644
44465--- a/drivers/net/ppp/ppp_generic.c
44466+++ b/drivers/net/ppp/ppp_generic.c
44467@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44468 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44469 struct ppp_stats stats;
44470 struct ppp_comp_stats cstats;
44471- char *vers;
44472
44473 switch (cmd) {
44474 case SIOCGPPPSTATS:
44475@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44476 break;
44477
44478 case SIOCGPPPVER:
44479- vers = PPP_VERSION;
44480- if (copy_to_user(addr, vers, strlen(vers) + 1))
44481+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44482 break;
44483 err = 0;
44484 break;
44485diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44486index 1252d9c..80e660b 100644
44487--- a/drivers/net/slip/slhc.c
44488+++ b/drivers/net/slip/slhc.c
44489@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44490 register struct tcphdr *thp;
44491 register struct iphdr *ip;
44492 register struct cstate *cs;
44493- int len, hdrlen;
44494+ long len, hdrlen;
44495 unsigned char *cp = icp;
44496
44497 /* We've got a compressed packet; read the change byte */
44498diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44499index 6327df2..e6e1ebe 100644
44500--- a/drivers/net/team/team.c
44501+++ b/drivers/net/team/team.c
44502@@ -2873,7 +2873,7 @@ static int team_device_event(struct notifier_block *unused,
44503 return NOTIFY_DONE;
44504 }
44505
44506-static struct notifier_block team_notifier_block __read_mostly = {
44507+static struct notifier_block team_notifier_block = {
44508 .notifier_call = team_device_event,
44509 };
44510
44511diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44512index 782e38b..d076fdc 100644
44513--- a/drivers/net/tun.c
44514+++ b/drivers/net/tun.c
44515@@ -1834,7 +1834,7 @@ unlock:
44516 }
44517
44518 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44519- unsigned long arg, int ifreq_len)
44520+ unsigned long arg, size_t ifreq_len)
44521 {
44522 struct tun_file *tfile = file->private_data;
44523 struct tun_struct *tun;
44524@@ -1847,6 +1847,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44525 unsigned int ifindex;
44526 int ret;
44527
44528+ if (ifreq_len > sizeof ifr)
44529+ return -EFAULT;
44530+
44531 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44532 if (copy_from_user(&ifr, argp, ifreq_len))
44533 return -EFAULT;
44534diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44535index 86292e6..8d34433 100644
44536--- a/drivers/net/usb/hso.c
44537+++ b/drivers/net/usb/hso.c
44538@@ -71,7 +71,7 @@
44539 #include <asm/byteorder.h>
44540 #include <linux/serial_core.h>
44541 #include <linux/serial.h>
44542-
44543+#include <asm/local.h>
44544
44545 #define MOD_AUTHOR "Option Wireless"
44546 #define MOD_DESCRIPTION "USB High Speed Option driver"
44547@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44548 struct urb *urb;
44549
44550 urb = serial->rx_urb[0];
44551- if (serial->port.count > 0) {
44552+ if (atomic_read(&serial->port.count) > 0) {
44553 count = put_rxbuf_data(urb, serial);
44554 if (count == -1)
44555 return;
44556@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44557 DUMP1(urb->transfer_buffer, urb->actual_length);
44558
44559 /* Anyone listening? */
44560- if (serial->port.count == 0)
44561+ if (atomic_read(&serial->port.count) == 0)
44562 return;
44563
44564 if (status == 0) {
44565@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44566 tty_port_tty_set(&serial->port, tty);
44567
44568 /* check for port already opened, if not set the termios */
44569- serial->port.count++;
44570- if (serial->port.count == 1) {
44571+ if (atomic_inc_return(&serial->port.count) == 1) {
44572 serial->rx_state = RX_IDLE;
44573 /* Force default termio settings */
44574 _hso_serial_set_termios(tty, NULL);
44575@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44576 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44577 if (result) {
44578 hso_stop_serial_device(serial->parent);
44579- serial->port.count--;
44580+ atomic_dec(&serial->port.count);
44581 kref_put(&serial->parent->ref, hso_serial_ref_free);
44582 }
44583 } else {
44584@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44585
44586 /* reset the rts and dtr */
44587 /* do the actual close */
44588- serial->port.count--;
44589+ atomic_dec(&serial->port.count);
44590
44591- if (serial->port.count <= 0) {
44592- serial->port.count = 0;
44593+ if (atomic_read(&serial->port.count) <= 0) {
44594+ atomic_set(&serial->port.count, 0);
44595 tty_port_tty_set(&serial->port, NULL);
44596 if (!usb_gone)
44597 hso_stop_serial_device(serial->parent);
44598@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44599
44600 /* the actual setup */
44601 spin_lock_irqsave(&serial->serial_lock, flags);
44602- if (serial->port.count)
44603+ if (atomic_read(&serial->port.count))
44604 _hso_serial_set_termios(tty, old);
44605 else
44606 tty->termios = *old;
44607@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44608 D1("Pending read interrupt on port %d\n", i);
44609 spin_lock(&serial->serial_lock);
44610 if (serial->rx_state == RX_IDLE &&
44611- serial->port.count > 0) {
44612+ atomic_read(&serial->port.count) > 0) {
44613 /* Setup and send a ctrl req read on
44614 * port i */
44615 if (!serial->rx_urb_filled[0]) {
44616@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44617 /* Start all serial ports */
44618 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44619 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44620- if (dev2ser(serial_table[i])->port.count) {
44621+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44622 result =
44623 hso_start_serial_device(serial_table[i], GFP_NOIO);
44624 hso_kick_transmit(dev2ser(serial_table[i]));
44625diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44626index a79e9d3..78cd4fa 100644
44627--- a/drivers/net/usb/sierra_net.c
44628+++ b/drivers/net/usb/sierra_net.c
44629@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44630 /* atomic counter partially included in MAC address to make sure 2 devices
44631 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44632 */
44633-static atomic_t iface_counter = ATOMIC_INIT(0);
44634+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44635
44636 /*
44637 * SYNC Timer Delay definition used to set the expiry time
44638@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44639 dev->net->netdev_ops = &sierra_net_device_ops;
44640
44641 /* change MAC addr to include, ifacenum, and to be unique */
44642- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44643+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44644 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44645
44646 /* we will have to manufacture ethernet headers, prepare template */
44647diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44648index 2ef5b62..6fa0ec3 100644
44649--- a/drivers/net/vxlan.c
44650+++ b/drivers/net/vxlan.c
44651@@ -2615,7 +2615,7 @@ nla_put_failure:
44652 return -EMSGSIZE;
44653 }
44654
44655-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44656+static struct rtnl_link_ops vxlan_link_ops = {
44657 .kind = "vxlan",
44658 .maxtype = IFLA_VXLAN_MAX,
44659 .policy = vxlan_policy,
44660diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44661index 0b60295..b8bfa5b 100644
44662--- a/drivers/net/wimax/i2400m/rx.c
44663+++ b/drivers/net/wimax/i2400m/rx.c
44664@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44665 if (i2400m->rx_roq == NULL)
44666 goto error_roq_alloc;
44667
44668- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44669+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44670 GFP_KERNEL);
44671 if (rd == NULL) {
44672 result = -ENOMEM;
44673diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
44674index 7fe1964..7016de0 100644
44675--- a/drivers/net/wireless/airo.c
44676+++ b/drivers/net/wireless/airo.c
44677@@ -7844,7 +7844,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
44678 struct airo_info *ai = dev->ml_priv;
44679 int ridcode;
44680 int enabled;
44681- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44682+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44683 unsigned char *iobuf;
44684
44685 /* Only super-user can write RIDs */
44686diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44687index 34c8a33..3261fdc 100644
44688--- a/drivers/net/wireless/at76c50x-usb.c
44689+++ b/drivers/net/wireless/at76c50x-usb.c
44690@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44691 }
44692
44693 /* Convert timeout from the DFU status to jiffies */
44694-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44695+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44696 {
44697 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44698 | (s->poll_timeout[1] << 8)
44699diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44700index ef3329e..c28ff5d 100644
44701--- a/drivers/net/wireless/ath/ath10k/htc.c
44702+++ b/drivers/net/wireless/ath/ath10k/htc.c
44703@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44704 /* registered target arrival callback from the HIF layer */
44705 int ath10k_htc_init(struct ath10k *ar)
44706 {
44707- struct ath10k_hif_cb htc_callbacks;
44708+ static struct ath10k_hif_cb htc_callbacks = {
44709+ .rx_completion = ath10k_htc_rx_completion_handler,
44710+ .tx_completion = ath10k_htc_tx_completion_handler,
44711+ };
44712 struct ath10k_htc_ep *ep = NULL;
44713 struct ath10k_htc *htc = &ar->htc;
44714
44715@@ -973,8 +976,6 @@ int ath10k_htc_init(struct ath10k *ar)
44716 ath10k_htc_reset_endpoint_states(htc);
44717
44718 /* setup HIF layer callbacks */
44719- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44720- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44721 htc->ar = ar;
44722
44723 /* Get HIF default pipe for HTC message exchange */
44724diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
44725index e1dd8c7..9f91b3f 100644
44726--- a/drivers/net/wireless/ath/ath10k/htc.h
44727+++ b/drivers/net/wireless/ath/ath10k/htc.h
44728@@ -271,12 +271,12 @@ enum ath10k_htc_ep_id {
44729
44730 struct ath10k_htc_ops {
44731 void (*target_send_suspend_complete)(struct ath10k *ar);
44732-};
44733+} __no_const;
44734
44735 struct ath10k_htc_ep_ops {
44736 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
44737 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
44738-};
44739+} __no_const;
44740
44741 /* service connection information */
44742 struct ath10k_htc_svc_conn_req {
44743diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44744index 8d78253..bebbb68 100644
44745--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44746+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44747@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44748 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44749 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44750
44751- ACCESS_ONCE(ads->ds_link) = i->link;
44752- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44753+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44754+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44755
44756 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44757 ctl6 = SM(i->keytype, AR_EncrType);
44758@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44759
44760 if ((i->is_first || i->is_last) &&
44761 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44762- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44763+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44764 | set11nTries(i->rates, 1)
44765 | set11nTries(i->rates, 2)
44766 | set11nTries(i->rates, 3)
44767 | (i->dur_update ? AR_DurUpdateEna : 0)
44768 | SM(0, AR_BurstDur);
44769
44770- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44771+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44772 | set11nRate(i->rates, 1)
44773 | set11nRate(i->rates, 2)
44774 | set11nRate(i->rates, 3);
44775 } else {
44776- ACCESS_ONCE(ads->ds_ctl2) = 0;
44777- ACCESS_ONCE(ads->ds_ctl3) = 0;
44778+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44779+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44780 }
44781
44782 if (!i->is_first) {
44783- ACCESS_ONCE(ads->ds_ctl0) = 0;
44784- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44785- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44786+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44787+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44788+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44789 return;
44790 }
44791
44792@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44793 break;
44794 }
44795
44796- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44797+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44798 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44799 | SM(i->txpower, AR_XmitPower)
44800 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44801@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44802 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44803 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44804
44805- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44806- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44807+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44808+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44809
44810 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44811 return;
44812
44813- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44814+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44815 | set11nPktDurRTSCTS(i->rates, 1);
44816
44817- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44818+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44819 | set11nPktDurRTSCTS(i->rates, 3);
44820
44821- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44822+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44823 | set11nRateFlags(i->rates, 1)
44824 | set11nRateFlags(i->rates, 2)
44825 | set11nRateFlags(i->rates, 3)
44826diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44827index f6c5c1b..6058354 100644
44828--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44829+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44830@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44831 (i->qcu << AR_TxQcuNum_S) | desc_len;
44832
44833 checksum += val;
44834- ACCESS_ONCE(ads->info) = val;
44835+ ACCESS_ONCE_RW(ads->info) = val;
44836
44837 checksum += i->link;
44838- ACCESS_ONCE(ads->link) = i->link;
44839+ ACCESS_ONCE_RW(ads->link) = i->link;
44840
44841 checksum += i->buf_addr[0];
44842- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44843+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44844 checksum += i->buf_addr[1];
44845- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44846+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44847 checksum += i->buf_addr[2];
44848- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44849+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44850 checksum += i->buf_addr[3];
44851- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44852+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44853
44854 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44855- ACCESS_ONCE(ads->ctl3) = val;
44856+ ACCESS_ONCE_RW(ads->ctl3) = val;
44857 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44858- ACCESS_ONCE(ads->ctl5) = val;
44859+ ACCESS_ONCE_RW(ads->ctl5) = val;
44860 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44861- ACCESS_ONCE(ads->ctl7) = val;
44862+ ACCESS_ONCE_RW(ads->ctl7) = val;
44863 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44864- ACCESS_ONCE(ads->ctl9) = val;
44865+ ACCESS_ONCE_RW(ads->ctl9) = val;
44866
44867 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44868- ACCESS_ONCE(ads->ctl10) = checksum;
44869+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44870
44871 if (i->is_first || i->is_last) {
44872- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44873+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44874 | set11nTries(i->rates, 1)
44875 | set11nTries(i->rates, 2)
44876 | set11nTries(i->rates, 3)
44877 | (i->dur_update ? AR_DurUpdateEna : 0)
44878 | SM(0, AR_BurstDur);
44879
44880- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44881+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44882 | set11nRate(i->rates, 1)
44883 | set11nRate(i->rates, 2)
44884 | set11nRate(i->rates, 3);
44885 } else {
44886- ACCESS_ONCE(ads->ctl13) = 0;
44887- ACCESS_ONCE(ads->ctl14) = 0;
44888+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44889+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44890 }
44891
44892 ads->ctl20 = 0;
44893@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44894
44895 ctl17 = SM(i->keytype, AR_EncrType);
44896 if (!i->is_first) {
44897- ACCESS_ONCE(ads->ctl11) = 0;
44898- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44899- ACCESS_ONCE(ads->ctl15) = 0;
44900- ACCESS_ONCE(ads->ctl16) = 0;
44901- ACCESS_ONCE(ads->ctl17) = ctl17;
44902- ACCESS_ONCE(ads->ctl18) = 0;
44903- ACCESS_ONCE(ads->ctl19) = 0;
44904+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44905+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44906+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44907+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44908+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44909+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44910+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44911 return;
44912 }
44913
44914- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44915+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44916 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44917 | SM(i->txpower, AR_XmitPower)
44918 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44919@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44920 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44921 ctl12 |= SM(val, AR_PAPRDChainMask);
44922
44923- ACCESS_ONCE(ads->ctl12) = ctl12;
44924- ACCESS_ONCE(ads->ctl17) = ctl17;
44925+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44926+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44927
44928- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44929+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44930 | set11nPktDurRTSCTS(i->rates, 1);
44931
44932- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44933+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44934 | set11nPktDurRTSCTS(i->rates, 3);
44935
44936- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44937+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44938 | set11nRateFlags(i->rates, 1)
44939 | set11nRateFlags(i->rates, 2)
44940 | set11nRateFlags(i->rates, 3)
44941 | SM(i->rtscts_rate, AR_RTSCTSRate);
44942
44943- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44944+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44945 }
44946
44947 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44948diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44949index 69a907b..91e071c 100644
44950--- a/drivers/net/wireless/ath/ath9k/hw.h
44951+++ b/drivers/net/wireless/ath/ath9k/hw.h
44952@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
44953
44954 /* ANI */
44955 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44956-};
44957+} __no_const;
44958
44959 /**
44960 * struct ath_spec_scan - parameters for Atheros spectral scan
44961@@ -729,7 +729,7 @@ struct ath_hw_ops {
44962 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
44963 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
44964 #endif
44965-};
44966+} __no_const;
44967
44968 struct ath_nf_limits {
44969 s16 max;
44970diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
44971index 92190da..f3a4c4c 100644
44972--- a/drivers/net/wireless/b43/phy_lp.c
44973+++ b/drivers/net/wireless/b43/phy_lp.c
44974@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
44975 {
44976 struct ssb_bus *bus = dev->dev->sdev->bus;
44977
44978- static const struct b206x_channel *chandata = NULL;
44979+ const struct b206x_channel *chandata = NULL;
44980 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
44981 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
44982 u16 old_comm15, scale;
44983diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44984index 9581d07..84f6a76 100644
44985--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44986+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44987@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44988 */
44989 if (il3945_mod_params.disable_hw_scan) {
44990 D_INFO("Disabling hw_scan\n");
44991- il3945_mac_ops.hw_scan = NULL;
44992+ pax_open_kernel();
44993+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44994+ pax_close_kernel();
44995 }
44996
44997 D_INFO("*** LOAD DRIVER ***\n");
44998diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44999index d94f8ab..5b568c8 100644
45000--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45001+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45002@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45003 {
45004 struct iwl_priv *priv = file->private_data;
45005 char buf[64];
45006- int buf_size;
45007+ size_t buf_size;
45008 u32 offset, len;
45009
45010 memset(buf, 0, sizeof(buf));
45011@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45012 struct iwl_priv *priv = file->private_data;
45013
45014 char buf[8];
45015- int buf_size;
45016+ size_t buf_size;
45017 u32 reset_flag;
45018
45019 memset(buf, 0, sizeof(buf));
45020@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45021 {
45022 struct iwl_priv *priv = file->private_data;
45023 char buf[8];
45024- int buf_size;
45025+ size_t buf_size;
45026 int ht40;
45027
45028 memset(buf, 0, sizeof(buf));
45029@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45030 {
45031 struct iwl_priv *priv = file->private_data;
45032 char buf[8];
45033- int buf_size;
45034+ size_t buf_size;
45035 int value;
45036
45037 memset(buf, 0, sizeof(buf));
45038@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45039 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45040 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45041
45042-static const char *fmt_value = " %-30s %10u\n";
45043-static const char *fmt_hex = " %-30s 0x%02X\n";
45044-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45045-static const char *fmt_header =
45046+static const char fmt_value[] = " %-30s %10u\n";
45047+static const char fmt_hex[] = " %-30s 0x%02X\n";
45048+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45049+static const char fmt_header[] =
45050 "%-32s current cumulative delta max\n";
45051
45052 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45053@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45054 {
45055 struct iwl_priv *priv = file->private_data;
45056 char buf[8];
45057- int buf_size;
45058+ size_t buf_size;
45059 int clear;
45060
45061 memset(buf, 0, sizeof(buf));
45062@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45063 {
45064 struct iwl_priv *priv = file->private_data;
45065 char buf[8];
45066- int buf_size;
45067+ size_t buf_size;
45068 int trace;
45069
45070 memset(buf, 0, sizeof(buf));
45071@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45072 {
45073 struct iwl_priv *priv = file->private_data;
45074 char buf[8];
45075- int buf_size;
45076+ size_t buf_size;
45077 int missed;
45078
45079 memset(buf, 0, sizeof(buf));
45080@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45081
45082 struct iwl_priv *priv = file->private_data;
45083 char buf[8];
45084- int buf_size;
45085+ size_t buf_size;
45086 int plcp;
45087
45088 memset(buf, 0, sizeof(buf));
45089@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45090
45091 struct iwl_priv *priv = file->private_data;
45092 char buf[8];
45093- int buf_size;
45094+ size_t buf_size;
45095 int flush;
45096
45097 memset(buf, 0, sizeof(buf));
45098@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45099
45100 struct iwl_priv *priv = file->private_data;
45101 char buf[8];
45102- int buf_size;
45103+ size_t buf_size;
45104 int rts;
45105
45106 if (!priv->cfg->ht_params)
45107@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45108 {
45109 struct iwl_priv *priv = file->private_data;
45110 char buf[8];
45111- int buf_size;
45112+ size_t buf_size;
45113
45114 memset(buf, 0, sizeof(buf));
45115 buf_size = min(count, sizeof(buf) - 1);
45116@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45117 struct iwl_priv *priv = file->private_data;
45118 u32 event_log_flag;
45119 char buf[8];
45120- int buf_size;
45121+ size_t buf_size;
45122
45123 /* check that the interface is up */
45124 if (!iwl_is_ready(priv))
45125@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45126 struct iwl_priv *priv = file->private_data;
45127 char buf[8];
45128 u32 calib_disabled;
45129- int buf_size;
45130+ size_t buf_size;
45131
45132 memset(buf, 0, sizeof(buf));
45133 buf_size = min(count, sizeof(buf) - 1);
45134diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45135index 7aad766..06addb4 100644
45136--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45137+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45138@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45139 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45140 {
45141 struct iwl_nvm_data *data = priv->nvm_data;
45142- char *debug_msg;
45143+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45144
45145 if (data->sku_cap_11n_enable &&
45146 !priv->cfg->ht_params) {
45147@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45148 return -EINVAL;
45149 }
45150
45151- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45152 IWL_DEBUG_INFO(priv, debug_msg,
45153 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45154 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45155diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45156index 6bc3100..dd1b80d 100644
45157--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45158+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45159@@ -1249,7 +1249,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45160 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45161
45162 char buf[8];
45163- int buf_size;
45164+ size_t buf_size;
45165 u32 reset_flag;
45166
45167 memset(buf, 0, sizeof(buf));
45168@@ -1270,7 +1270,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45169 {
45170 struct iwl_trans *trans = file->private_data;
45171 char buf[8];
45172- int buf_size;
45173+ size_t buf_size;
45174 int csr;
45175
45176 memset(buf, 0, sizeof(buf));
45177diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45178index 2cd3f54..e936f90 100644
45179--- a/drivers/net/wireless/mac80211_hwsim.c
45180+++ b/drivers/net/wireless/mac80211_hwsim.c
45181@@ -2196,25 +2196,19 @@ static int __init init_mac80211_hwsim(void)
45182
45183 if (channels > 1) {
45184 hwsim_if_comb.num_different_channels = channels;
45185- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45186- mac80211_hwsim_ops.cancel_hw_scan =
45187- mac80211_hwsim_cancel_hw_scan;
45188- mac80211_hwsim_ops.sw_scan_start = NULL;
45189- mac80211_hwsim_ops.sw_scan_complete = NULL;
45190- mac80211_hwsim_ops.remain_on_channel =
45191- mac80211_hwsim_roc;
45192- mac80211_hwsim_ops.cancel_remain_on_channel =
45193- mac80211_hwsim_croc;
45194- mac80211_hwsim_ops.add_chanctx =
45195- mac80211_hwsim_add_chanctx;
45196- mac80211_hwsim_ops.remove_chanctx =
45197- mac80211_hwsim_remove_chanctx;
45198- mac80211_hwsim_ops.change_chanctx =
45199- mac80211_hwsim_change_chanctx;
45200- mac80211_hwsim_ops.assign_vif_chanctx =
45201- mac80211_hwsim_assign_vif_chanctx;
45202- mac80211_hwsim_ops.unassign_vif_chanctx =
45203- mac80211_hwsim_unassign_vif_chanctx;
45204+ pax_open_kernel();
45205+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45206+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45207+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45208+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45209+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45210+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45211+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45212+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45213+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45214+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45215+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45216+ pax_close_kernel();
45217 }
45218
45219 spin_lock_init(&hwsim_radio_lock);
45220diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45221index 8169a85..7fa3b47 100644
45222--- a/drivers/net/wireless/rndis_wlan.c
45223+++ b/drivers/net/wireless/rndis_wlan.c
45224@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45225
45226 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45227
45228- if (rts_threshold < 0 || rts_threshold > 2347)
45229+ if (rts_threshold > 2347)
45230 rts_threshold = 2347;
45231
45232 tmp = cpu_to_le32(rts_threshold);
45233diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45234index fe4c572..99dedfa 100644
45235--- a/drivers/net/wireless/rt2x00/rt2x00.h
45236+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45237@@ -387,7 +387,7 @@ struct rt2x00_intf {
45238 * for hardware which doesn't support hardware
45239 * sequence counting.
45240 */
45241- atomic_t seqno;
45242+ atomic_unchecked_t seqno;
45243 };
45244
45245 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45246diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45247index 66a2db8..70cad04 100644
45248--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45249+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45250@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45251 * sequence counter given by mac80211.
45252 */
45253 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45254- seqno = atomic_add_return(0x10, &intf->seqno);
45255+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45256 else
45257- seqno = atomic_read(&intf->seqno);
45258+ seqno = atomic_read_unchecked(&intf->seqno);
45259
45260 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45261 hdr->seq_ctrl |= cpu_to_le16(seqno);
45262diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45263index e2b3d9c..67a5184 100644
45264--- a/drivers/net/wireless/ti/wl1251/sdio.c
45265+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45266@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45267
45268 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45269
45270- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45271- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45272+ pax_open_kernel();
45273+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45274+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45275+ pax_close_kernel();
45276
45277 wl1251_info("using dedicated interrupt line");
45278 } else {
45279- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45280- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45281+ pax_open_kernel();
45282+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45283+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45284+ pax_close_kernel();
45285
45286 wl1251_info("using SDIO interrupt");
45287 }
45288diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45289index 1c627da..69f7d17 100644
45290--- a/drivers/net/wireless/ti/wl12xx/main.c
45291+++ b/drivers/net/wireless/ti/wl12xx/main.c
45292@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45293 sizeof(wl->conf.mem));
45294
45295 /* read data preparation is only needed by wl127x */
45296- wl->ops->prepare_read = wl127x_prepare_read;
45297+ pax_open_kernel();
45298+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45299+ pax_close_kernel();
45300
45301 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45302 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45303@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45304 sizeof(wl->conf.mem));
45305
45306 /* read data preparation is only needed by wl127x */
45307- wl->ops->prepare_read = wl127x_prepare_read;
45308+ pax_open_kernel();
45309+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45310+ pax_close_kernel();
45311
45312 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45313 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45314diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45315index 7aa0eb8..5a9ef38 100644
45316--- a/drivers/net/wireless/ti/wl18xx/main.c
45317+++ b/drivers/net/wireless/ti/wl18xx/main.c
45318@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45319 }
45320
45321 if (!checksum_param) {
45322- wl18xx_ops.set_rx_csum = NULL;
45323- wl18xx_ops.init_vif = NULL;
45324+ pax_open_kernel();
45325+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45326+ *(void **)&wl18xx_ops.init_vif = NULL;
45327+ pax_close_kernel();
45328 }
45329
45330 /* Enable 11a Band only if we have 5G antennas */
45331diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45332index 7ef0b4a..ff65c28 100644
45333--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45334+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45335@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45336 {
45337 struct zd_usb *usb = urb->context;
45338 struct zd_usb_interrupt *intr = &usb->intr;
45339- int len;
45340+ unsigned int len;
45341 u16 int_num;
45342
45343 ZD_ASSERT(in_interrupt());
45344diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
45345index 59f95d8..53e0e7f 100644
45346--- a/drivers/nfc/nfcwilink.c
45347+++ b/drivers/nfc/nfcwilink.c
45348@@ -513,7 +513,7 @@ static struct nci_ops nfcwilink_ops = {
45349
45350 static int nfcwilink_probe(struct platform_device *pdev)
45351 {
45352- static struct nfcwilink *drv;
45353+ struct nfcwilink *drv;
45354 int rc;
45355 __u32 protocols;
45356
45357diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45358index d93b2b6..ae50401 100644
45359--- a/drivers/oprofile/buffer_sync.c
45360+++ b/drivers/oprofile/buffer_sync.c
45361@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45362 if (cookie == NO_COOKIE)
45363 offset = pc;
45364 if (cookie == INVALID_COOKIE) {
45365- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45366+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45367 offset = pc;
45368 }
45369 if (cookie != last_cookie) {
45370@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45371 /* add userspace sample */
45372
45373 if (!mm) {
45374- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45375+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45376 return 0;
45377 }
45378
45379 cookie = lookup_dcookie(mm, s->eip, &offset);
45380
45381 if (cookie == INVALID_COOKIE) {
45382- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45383+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45384 return 0;
45385 }
45386
45387@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45388 /* ignore backtraces if failed to add a sample */
45389 if (state == sb_bt_start) {
45390 state = sb_bt_ignore;
45391- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45392+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45393 }
45394 }
45395 release_mm(mm);
45396diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45397index c0cc4e7..44d4e54 100644
45398--- a/drivers/oprofile/event_buffer.c
45399+++ b/drivers/oprofile/event_buffer.c
45400@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45401 }
45402
45403 if (buffer_pos == buffer_size) {
45404- atomic_inc(&oprofile_stats.event_lost_overflow);
45405+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45406 return;
45407 }
45408
45409diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45410index ed2c3ec..deda85a 100644
45411--- a/drivers/oprofile/oprof.c
45412+++ b/drivers/oprofile/oprof.c
45413@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45414 if (oprofile_ops.switch_events())
45415 return;
45416
45417- atomic_inc(&oprofile_stats.multiplex_counter);
45418+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45419 start_switch_worker();
45420 }
45421
45422diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45423index ee2cfce..7f8f699 100644
45424--- a/drivers/oprofile/oprofile_files.c
45425+++ b/drivers/oprofile/oprofile_files.c
45426@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45427
45428 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45429
45430-static ssize_t timeout_read(struct file *file, char __user *buf,
45431+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45432 size_t count, loff_t *offset)
45433 {
45434 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45435diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45436index 59659ce..6c860a0 100644
45437--- a/drivers/oprofile/oprofile_stats.c
45438+++ b/drivers/oprofile/oprofile_stats.c
45439@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45440 cpu_buf->sample_invalid_eip = 0;
45441 }
45442
45443- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45444- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45445- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45446- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45447- atomic_set(&oprofile_stats.multiplex_counter, 0);
45448+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45449+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45450+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45451+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45452+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45453 }
45454
45455
45456diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45457index 1fc622b..8c48fc3 100644
45458--- a/drivers/oprofile/oprofile_stats.h
45459+++ b/drivers/oprofile/oprofile_stats.h
45460@@ -13,11 +13,11 @@
45461 #include <linux/atomic.h>
45462
45463 struct oprofile_stat_struct {
45464- atomic_t sample_lost_no_mm;
45465- atomic_t sample_lost_no_mapping;
45466- atomic_t bt_lost_no_mapping;
45467- atomic_t event_lost_overflow;
45468- atomic_t multiplex_counter;
45469+ atomic_unchecked_t sample_lost_no_mm;
45470+ atomic_unchecked_t sample_lost_no_mapping;
45471+ atomic_unchecked_t bt_lost_no_mapping;
45472+ atomic_unchecked_t event_lost_overflow;
45473+ atomic_unchecked_t multiplex_counter;
45474 };
45475
45476 extern struct oprofile_stat_struct oprofile_stats;
45477diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45478index 3f49345..c750d0b 100644
45479--- a/drivers/oprofile/oprofilefs.c
45480+++ b/drivers/oprofile/oprofilefs.c
45481@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
45482
45483 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
45484 {
45485- atomic_t *val = file->private_data;
45486- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
45487+ atomic_unchecked_t *val = file->private_data;
45488+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
45489 }
45490
45491
45492@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
45493
45494
45495 int oprofilefs_create_ro_atomic(struct dentry *root,
45496- char const *name, atomic_t *val)
45497+ char const *name, atomic_unchecked_t *val)
45498 {
45499 return __oprofilefs_create_file(root, name,
45500 &atomic_ro_fops, 0444, val);
45501diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45502index 61be1d9..dec05d7 100644
45503--- a/drivers/oprofile/timer_int.c
45504+++ b/drivers/oprofile/timer_int.c
45505@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45506 return NOTIFY_OK;
45507 }
45508
45509-static struct notifier_block __refdata oprofile_cpu_notifier = {
45510+static struct notifier_block oprofile_cpu_notifier = {
45511 .notifier_call = oprofile_cpu_notify,
45512 };
45513
45514diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45515index 92ed045..62d39bd7 100644
45516--- a/drivers/parport/procfs.c
45517+++ b/drivers/parport/procfs.c
45518@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45519
45520 *ppos += len;
45521
45522- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45523+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45524 }
45525
45526 #ifdef CONFIG_PARPORT_1284
45527@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45528
45529 *ppos += len;
45530
45531- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45532+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45533 }
45534 #endif /* IEEE1284.3 support. */
45535
45536diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45537index 2f5786c..61ab4d1 100644
45538--- a/drivers/pci/hotplug/acpiphp_ibm.c
45539+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45540@@ -463,7 +463,9 @@ static int __init ibm_acpiphp_init(void)
45541 goto init_cleanup;
45542 }
45543
45544- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45545+ pax_open_kernel();
45546+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45547+ pax_close_kernel();
45548 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45549
45550 return retval;
45551diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45552index a6a71c4..c91097b 100644
45553--- a/drivers/pci/hotplug/cpcihp_generic.c
45554+++ b/drivers/pci/hotplug/cpcihp_generic.c
45555@@ -73,7 +73,6 @@ static u16 port;
45556 static unsigned int enum_bit;
45557 static u8 enum_mask;
45558
45559-static struct cpci_hp_controller_ops generic_hpc_ops;
45560 static struct cpci_hp_controller generic_hpc;
45561
45562 static int __init validate_parameters(void)
45563@@ -139,6 +138,10 @@ static int query_enum(void)
45564 return ((value & enum_mask) == enum_mask);
45565 }
45566
45567+static struct cpci_hp_controller_ops generic_hpc_ops = {
45568+ .query_enum = query_enum,
45569+};
45570+
45571 static int __init cpcihp_generic_init(void)
45572 {
45573 int status;
45574@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45575 pci_dev_put(dev);
45576
45577 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45578- generic_hpc_ops.query_enum = query_enum;
45579 generic_hpc.ops = &generic_hpc_ops;
45580
45581 status = cpci_hp_register_controller(&generic_hpc);
45582diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45583index 449b4bb..257e2e8 100644
45584--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45585+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45586@@ -59,7 +59,6 @@
45587 /* local variables */
45588 static bool debug;
45589 static bool poll;
45590-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45591 static struct cpci_hp_controller zt5550_hpc;
45592
45593 /* Primary cPCI bus bridge device */
45594@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45595 return 0;
45596 }
45597
45598+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45599+ .query_enum = zt5550_hc_query_enum,
45600+};
45601+
45602 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45603 {
45604 int status;
45605@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45606 dbg("returned from zt5550_hc_config");
45607
45608 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45609- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45610 zt5550_hpc.ops = &zt5550_hpc_ops;
45611 if(!poll) {
45612 zt5550_hpc.irq = hc_dev->irq;
45613 zt5550_hpc.irq_flags = IRQF_SHARED;
45614 zt5550_hpc.dev_id = hc_dev;
45615
45616- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45617- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45618- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45619+ pax_open_kernel();
45620+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45621+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45622+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45623+ pax_open_kernel();
45624 } else {
45625 info("using ENUM# polling mode");
45626 }
45627diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45628index 76ba8a1..20ca857 100644
45629--- a/drivers/pci/hotplug/cpqphp_nvram.c
45630+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45631@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45632
45633 void compaq_nvram_init (void __iomem *rom_start)
45634 {
45635+
45636+#ifndef CONFIG_PAX_KERNEXEC
45637 if (rom_start) {
45638 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45639 }
45640+#endif
45641+
45642 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45643
45644 /* initialize our int15 lock */
45645diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45646index ec20f74..c1d961e 100644
45647--- a/drivers/pci/hotplug/pci_hotplug_core.c
45648+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45649@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45650 return -EINVAL;
45651 }
45652
45653- slot->ops->owner = owner;
45654- slot->ops->mod_name = mod_name;
45655+ pax_open_kernel();
45656+ *(struct module **)&slot->ops->owner = owner;
45657+ *(const char **)&slot->ops->mod_name = mod_name;
45658+ pax_close_kernel();
45659
45660 mutex_lock(&pci_hp_mutex);
45661 /*
45662diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45663index f4a18f5..ff2463c 100644
45664--- a/drivers/pci/hotplug/pciehp_core.c
45665+++ b/drivers/pci/hotplug/pciehp_core.c
45666@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
45667 struct slot *slot = ctrl->slot;
45668 struct hotplug_slot *hotplug = NULL;
45669 struct hotplug_slot_info *info = NULL;
45670- struct hotplug_slot_ops *ops = NULL;
45671+ hotplug_slot_ops_no_const *ops = NULL;
45672 char name[SLOT_NAME_SIZE];
45673 int retval = -ENOMEM;
45674
45675diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45676index 7128cfd..6fdc261 100644
45677--- a/drivers/pci/pci-sysfs.c
45678+++ b/drivers/pci/pci-sysfs.c
45679@@ -634,6 +634,9 @@ pci_write_config(struct file* filp, struct kobject *kobj,
45680 loff_t init_off = off;
45681 u8 *data = (u8*) buf;
45682
45683+ if (!capable(CAP_SYS_RAWIO))
45684+ return -EPERM;
45685+
45686 if (off > dev->cfg_size)
45687 return 0;
45688 if (off + count > dev->cfg_size) {
45689@@ -940,6 +943,9 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
45690 resource_size_t start, end;
45691 int i;
45692
45693+ if (!capable(CAP_SYS_RAWIO))
45694+ return -EPERM;
45695+
45696 for (i = 0; i < PCI_ROM_RESOURCE; i++)
45697 if (res == &pdev->resource[i])
45698 break;
45699@@ -997,6 +1003,9 @@ pci_resource_io(struct file *filp, struct kobject *kobj,
45700 unsigned long port = off;
45701 int i;
45702
45703+ if (!capable(CAP_SYS_RAWIO))
45704+ return -EPERM;
45705+
45706 for (i = 0; i < PCI_ROM_RESOURCE; i++)
45707 if (res == &pdev->resource[i])
45708 break;
45709@@ -1083,7 +1092,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45710 {
45711 /* allocate attribute structure, piggyback attribute name */
45712 int name_len = write_combine ? 13 : 10;
45713- struct bin_attribute *res_attr;
45714+ bin_attribute_no_const *res_attr;
45715 int retval;
45716
45717 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45718@@ -1268,7 +1277,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45719 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45720 {
45721 int retval;
45722- struct bin_attribute *attr;
45723+ bin_attribute_no_const *attr;
45724
45725 /* If the device has VPD, try to expose it in sysfs. */
45726 if (dev->vpd) {
45727@@ -1315,7 +1324,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45728 {
45729 int retval;
45730 int rom_size = 0;
45731- struct bin_attribute *attr;
45732+ bin_attribute_no_const *attr;
45733
45734 if (!sysfs_initialized)
45735 return -EACCES;
45736diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45737index 8a00c06..18a9715 100644
45738--- a/drivers/pci/pci.h
45739+++ b/drivers/pci/pci.h
45740@@ -95,7 +95,7 @@ struct pci_vpd_ops {
45741 struct pci_vpd {
45742 unsigned int len;
45743 const struct pci_vpd_ops *ops;
45744- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45745+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45746 };
45747
45748 int pci_vpd_pci22_init(struct pci_dev *dev);
45749diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45750index 403a443..034e050 100644
45751--- a/drivers/pci/pcie/aspm.c
45752+++ b/drivers/pci/pcie/aspm.c
45753@@ -27,9 +27,9 @@
45754 #define MODULE_PARAM_PREFIX "pcie_aspm."
45755
45756 /* Note: those are not register definitions */
45757-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45758-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45759-#define ASPM_STATE_L1 (4) /* L1 state */
45760+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45761+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45762+#define ASPM_STATE_L1 (4U) /* L1 state */
45763 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45764 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45765
45766diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45767index 7ef0f86..17b710f 100644
45768--- a/drivers/pci/probe.c
45769+++ b/drivers/pci/probe.c
45770@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45771 struct pci_bus_region region, inverted_region;
45772 bool bar_too_big = false, bar_disabled = false;
45773
45774- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45775+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45776
45777 /* No printks while decoding is disabled! */
45778 if (!dev->mmio_always_on) {
45779diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45780index cdc7836..0c964c9 100644
45781--- a/drivers/pci/proc.c
45782+++ b/drivers/pci/proc.c
45783@@ -117,6 +117,9 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
45784 int size = dev->cfg_size;
45785 int cnt;
45786
45787+ if (!capable(CAP_SYS_RAWIO))
45788+ return -EPERM;
45789+
45790 if (pos >= size)
45791 return 0;
45792 if (nbytes >= size)
45793@@ -434,7 +437,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45794 static int __init pci_proc_init(void)
45795 {
45796 struct pci_dev *dev = NULL;
45797+
45798+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45799+#ifdef CONFIG_GRKERNSEC_PROC_USER
45800+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45801+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45802+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45803+#endif
45804+#else
45805 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45806+#endif
45807 proc_create("devices", 0, proc_bus_pci_dir,
45808 &proc_bus_pci_dev_operations);
45809 proc_initialized = 1;
45810diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
45811index 19c313b..ed28b38 100644
45812--- a/drivers/platform/x86/asus-wmi.c
45813+++ b/drivers/platform/x86/asus-wmi.c
45814@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
45815 int err;
45816 u32 retval = -1;
45817
45818+#ifdef CONFIG_GRKERNSEC_KMEM
45819+ return -EPERM;
45820+#endif
45821+
45822 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
45823
45824 if (err < 0)
45825@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
45826 int err;
45827 u32 retval = -1;
45828
45829+#ifdef CONFIG_GRKERNSEC_KMEM
45830+ return -EPERM;
45831+#endif
45832+
45833 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
45834 &retval);
45835
45836@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
45837 union acpi_object *obj;
45838 acpi_status status;
45839
45840+#ifdef CONFIG_GRKERNSEC_KMEM
45841+ return -EPERM;
45842+#endif
45843+
45844 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
45845 1, asus->debug.method_id,
45846 &input, &output);
45847diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45848index 3e5b4497..dcdfb70 100644
45849--- a/drivers/platform/x86/chromeos_laptop.c
45850+++ b/drivers/platform/x86/chromeos_laptop.c
45851@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45852 return 0;
45853 }
45854
45855-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45856+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45857 {
45858 .ident = "Samsung Series 5 550 - Touchpad",
45859 .matches = {
45860diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45861index 62f8030..c7f2a45 100644
45862--- a/drivers/platform/x86/msi-laptop.c
45863+++ b/drivers/platform/x86/msi-laptop.c
45864@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45865
45866 if (!quirks->ec_read_only) {
45867 /* allow userland write sysfs file */
45868- dev_attr_bluetooth.store = store_bluetooth;
45869- dev_attr_wlan.store = store_wlan;
45870- dev_attr_threeg.store = store_threeg;
45871- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45872- dev_attr_wlan.attr.mode |= S_IWUSR;
45873- dev_attr_threeg.attr.mode |= S_IWUSR;
45874+ pax_open_kernel();
45875+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45876+ *(void **)&dev_attr_wlan.store = store_wlan;
45877+ *(void **)&dev_attr_threeg.store = store_threeg;
45878+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45879+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45880+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45881+ pax_close_kernel();
45882 }
45883
45884 /* disable hardware control by fn key */
45885diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
45886index 70222f2..8c8ce66 100644
45887--- a/drivers/platform/x86/msi-wmi.c
45888+++ b/drivers/platform/x86/msi-wmi.c
45889@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
45890 static void msi_wmi_notify(u32 value, void *context)
45891 {
45892 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
45893- static struct key_entry *key;
45894+ struct key_entry *key;
45895 union acpi_object *obj;
45896 acpi_status status;
45897
45898diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45899index 3484dd2..13ee730 100644
45900--- a/drivers/platform/x86/sony-laptop.c
45901+++ b/drivers/platform/x86/sony-laptop.c
45902@@ -2448,7 +2448,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45903 }
45904
45905 /* High speed charging function */
45906-static struct device_attribute *hsc_handle;
45907+static device_attribute_no_const *hsc_handle;
45908
45909 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45910 struct device_attribute *attr,
45911diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45912index 4e86e97..04d50d1 100644
45913--- a/drivers/platform/x86/thinkpad_acpi.c
45914+++ b/drivers/platform/x86/thinkpad_acpi.c
45915@@ -2091,7 +2091,7 @@ static int hotkey_mask_get(void)
45916 return 0;
45917 }
45918
45919-void static hotkey_mask_warn_incomplete_mask(void)
45920+static void hotkey_mask_warn_incomplete_mask(void)
45921 {
45922 /* log only what the user can fix... */
45923 const u32 wantedmask = hotkey_driver_mask &
45924@@ -2318,11 +2318,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45925 }
45926 }
45927
45928-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45929- struct tp_nvram_state *newn,
45930- const u32 event_mask)
45931-{
45932-
45933 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45934 do { \
45935 if ((event_mask & (1 << __scancode)) && \
45936@@ -2336,36 +2331,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45937 tpacpi_hotkey_send_key(__scancode); \
45938 } while (0)
45939
45940- void issue_volchange(const unsigned int oldvol,
45941- const unsigned int newvol)
45942- {
45943- unsigned int i = oldvol;
45944+static void issue_volchange(const unsigned int oldvol,
45945+ const unsigned int newvol,
45946+ const u32 event_mask)
45947+{
45948+ unsigned int i = oldvol;
45949
45950- while (i > newvol) {
45951- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45952- i--;
45953- }
45954- while (i < newvol) {
45955- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45956- i++;
45957- }
45958+ while (i > newvol) {
45959+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45960+ i--;
45961 }
45962+ while (i < newvol) {
45963+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45964+ i++;
45965+ }
45966+}
45967
45968- void issue_brightnesschange(const unsigned int oldbrt,
45969- const unsigned int newbrt)
45970- {
45971- unsigned int i = oldbrt;
45972+static void issue_brightnesschange(const unsigned int oldbrt,
45973+ const unsigned int newbrt,
45974+ const u32 event_mask)
45975+{
45976+ unsigned int i = oldbrt;
45977
45978- while (i > newbrt) {
45979- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45980- i--;
45981- }
45982- while (i < newbrt) {
45983- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45984- i++;
45985- }
45986+ while (i > newbrt) {
45987+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45988+ i--;
45989+ }
45990+ while (i < newbrt) {
45991+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45992+ i++;
45993 }
45994+}
45995
45996+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45997+ struct tp_nvram_state *newn,
45998+ const u32 event_mask)
45999+{
46000 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
46001 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
46002 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
46003@@ -2399,7 +2400,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46004 oldn->volume_level != newn->volume_level) {
46005 /* recently muted, or repeated mute keypress, or
46006 * multiple presses ending in mute */
46007- issue_volchange(oldn->volume_level, newn->volume_level);
46008+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46009 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
46010 }
46011 } else {
46012@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46013 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46014 }
46015 if (oldn->volume_level != newn->volume_level) {
46016- issue_volchange(oldn->volume_level, newn->volume_level);
46017+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46018 } else if (oldn->volume_toggle != newn->volume_toggle) {
46019 /* repeated vol up/down keypress at end of scale ? */
46020 if (newn->volume_level == 0)
46021@@ -2422,7 +2423,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46022 /* handle brightness */
46023 if (oldn->brightness_level != newn->brightness_level) {
46024 issue_brightnesschange(oldn->brightness_level,
46025- newn->brightness_level);
46026+ newn->brightness_level,
46027+ event_mask);
46028 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46029 /* repeated key presses that didn't change state */
46030 if (newn->brightness_level == 0)
46031@@ -2431,10 +2433,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46032 && !tp_features.bright_unkfw)
46033 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46034 }
46035+}
46036
46037 #undef TPACPI_COMPARE_KEY
46038 #undef TPACPI_MAY_SEND_KEY
46039-}
46040
46041 /*
46042 * Polling driver
46043diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46044index 769d265..a3a05ca 100644
46045--- a/drivers/pnp/pnpbios/bioscalls.c
46046+++ b/drivers/pnp/pnpbios/bioscalls.c
46047@@ -58,7 +58,7 @@ do { \
46048 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46049 } while(0)
46050
46051-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46052+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46053 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46054
46055 /*
46056@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46057
46058 cpu = get_cpu();
46059 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46060+
46061+ pax_open_kernel();
46062 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46063+ pax_close_kernel();
46064
46065 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46066 spin_lock_irqsave(&pnp_bios_lock, flags);
46067@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46068 :"memory");
46069 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46070
46071+ pax_open_kernel();
46072 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46073+ pax_close_kernel();
46074+
46075 put_cpu();
46076
46077 /* If we get here and this is set then the PnP BIOS faulted on us. */
46078@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46079 return status;
46080 }
46081
46082-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46083+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46084 {
46085 int i;
46086
46087@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46088 pnp_bios_callpoint.offset = header->fields.pm16offset;
46089 pnp_bios_callpoint.segment = PNP_CS16;
46090
46091+ pax_open_kernel();
46092+
46093 for_each_possible_cpu(i) {
46094 struct desc_struct *gdt = get_cpu_gdt_table(i);
46095 if (!gdt)
46096@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46097 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46098 (unsigned long)__va(header->fields.pm16dseg));
46099 }
46100+
46101+ pax_close_kernel();
46102 }
46103diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46104index d95e101..67f0c3f 100644
46105--- a/drivers/pnp/resource.c
46106+++ b/drivers/pnp/resource.c
46107@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46108 return 1;
46109
46110 /* check if the resource is valid */
46111- if (*irq < 0 || *irq > 15)
46112+ if (*irq > 15)
46113 return 0;
46114
46115 /* check if the resource is reserved */
46116@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46117 return 1;
46118
46119 /* check if the resource is valid */
46120- if (*dma < 0 || *dma == 4 || *dma > 7)
46121+ if (*dma == 4 || *dma > 7)
46122 return 0;
46123
46124 /* check if the resource is reserved */
46125diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46126index 0c52e2a..3421ab7 100644
46127--- a/drivers/power/pda_power.c
46128+++ b/drivers/power/pda_power.c
46129@@ -37,7 +37,11 @@ static int polling;
46130
46131 #if IS_ENABLED(CONFIG_USB_PHY)
46132 static struct usb_phy *transceiver;
46133-static struct notifier_block otg_nb;
46134+static int otg_handle_notification(struct notifier_block *nb,
46135+ unsigned long event, void *unused);
46136+static struct notifier_block otg_nb = {
46137+ .notifier_call = otg_handle_notification
46138+};
46139 #endif
46140
46141 static struct regulator *ac_draw;
46142@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46143
46144 #if IS_ENABLED(CONFIG_USB_PHY)
46145 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46146- otg_nb.notifier_call = otg_handle_notification;
46147 ret = usb_register_notifier(transceiver, &otg_nb);
46148 if (ret) {
46149 dev_err(dev, "failure to register otg notifier\n");
46150diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46151index cc439fd..8fa30df 100644
46152--- a/drivers/power/power_supply.h
46153+++ b/drivers/power/power_supply.h
46154@@ -16,12 +16,12 @@ struct power_supply;
46155
46156 #ifdef CONFIG_SYSFS
46157
46158-extern void power_supply_init_attrs(struct device_type *dev_type);
46159+extern void power_supply_init_attrs(void);
46160 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46161
46162 #else
46163
46164-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46165+static inline void power_supply_init_attrs(void) {}
46166 #define power_supply_uevent NULL
46167
46168 #endif /* CONFIG_SYSFS */
46169diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46170index 00e6672..2642c08 100644
46171--- a/drivers/power/power_supply_core.c
46172+++ b/drivers/power/power_supply_core.c
46173@@ -24,7 +24,10 @@
46174 struct class *power_supply_class;
46175 EXPORT_SYMBOL_GPL(power_supply_class);
46176
46177-static struct device_type power_supply_dev_type;
46178+extern const struct attribute_group *power_supply_attr_groups[];
46179+static struct device_type power_supply_dev_type = {
46180+ .groups = power_supply_attr_groups,
46181+};
46182
46183 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46184 struct power_supply *supply)
46185@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
46186 return PTR_ERR(power_supply_class);
46187
46188 power_supply_class->dev_uevent = power_supply_uevent;
46189- power_supply_init_attrs(&power_supply_dev_type);
46190+ power_supply_init_attrs();
46191
46192 return 0;
46193 }
46194diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46195index 44420d1..967126e 100644
46196--- a/drivers/power/power_supply_sysfs.c
46197+++ b/drivers/power/power_supply_sysfs.c
46198@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46199 .is_visible = power_supply_attr_is_visible,
46200 };
46201
46202-static const struct attribute_group *power_supply_attr_groups[] = {
46203+const struct attribute_group *power_supply_attr_groups[] = {
46204 &power_supply_attr_group,
46205 NULL,
46206 };
46207
46208-void power_supply_init_attrs(struct device_type *dev_type)
46209+void power_supply_init_attrs(void)
46210 {
46211 int i;
46212
46213- dev_type->groups = power_supply_attr_groups;
46214-
46215 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46216 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46217 }
46218diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46219index a01b8b3..37c2afe 100644
46220--- a/drivers/regulator/core.c
46221+++ b/drivers/regulator/core.c
46222@@ -3307,7 +3307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46223 {
46224 const struct regulation_constraints *constraints = NULL;
46225 const struct regulator_init_data *init_data;
46226- static atomic_t regulator_no = ATOMIC_INIT(0);
46227+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46228 struct regulator_dev *rdev;
46229 struct device *dev;
46230 int ret, i;
46231@@ -3377,7 +3377,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46232 rdev->dev.of_node = config->of_node;
46233 rdev->dev.parent = dev;
46234 dev_set_name(&rdev->dev, "regulator.%d",
46235- atomic_inc_return(&regulator_no) - 1);
46236+ atomic_inc_return_unchecked(&regulator_no) - 1);
46237 ret = device_register(&rdev->dev);
46238 if (ret != 0) {
46239 put_device(&rdev->dev);
46240diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46241index 144bcac..d20e7db 100644
46242--- a/drivers/regulator/max8660.c
46243+++ b/drivers/regulator/max8660.c
46244@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
46245 max8660->shadow_regs[MAX8660_OVER1] = 5;
46246 } else {
46247 /* Otherwise devices can be toggled via software */
46248- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46249- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46250+ pax_open_kernel();
46251+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46252+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46253+ pax_close_kernel();
46254 }
46255
46256 /*
46257diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46258index 5b77ab7..a62f061 100644
46259--- a/drivers/regulator/max8973-regulator.c
46260+++ b/drivers/regulator/max8973-regulator.c
46261@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46262 if (!pdata || !pdata->enable_ext_control) {
46263 max->desc.enable_reg = MAX8973_VOUT;
46264 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46265- max->ops.enable = regulator_enable_regmap;
46266- max->ops.disable = regulator_disable_regmap;
46267- max->ops.is_enabled = regulator_is_enabled_regmap;
46268+ pax_open_kernel();
46269+ *(void **)&max->ops.enable = regulator_enable_regmap;
46270+ *(void **)&max->ops.disable = regulator_disable_regmap;
46271+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46272+ pax_close_kernel();
46273 }
46274
46275 if (pdata) {
46276diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46277index 1037e07..e64dea1 100644
46278--- a/drivers/regulator/mc13892-regulator.c
46279+++ b/drivers/regulator/mc13892-regulator.c
46280@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46281 }
46282 mc13xxx_unlock(mc13892);
46283
46284- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46285+ pax_open_kernel();
46286+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46287 = mc13892_vcam_set_mode;
46288- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46289+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46290 = mc13892_vcam_get_mode;
46291+ pax_close_kernel();
46292
46293 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46294 ARRAY_SIZE(mc13892_regulators));
46295diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46296index 24e733c..bfbaa3e 100644
46297--- a/drivers/rtc/rtc-cmos.c
46298+++ b/drivers/rtc/rtc-cmos.c
46299@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46300 hpet_rtc_timer_init();
46301
46302 /* export at least the first block of NVRAM */
46303- nvram.size = address_space - NVRAM_OFFSET;
46304+ pax_open_kernel();
46305+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46306+ pax_close_kernel();
46307 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46308 if (retval < 0) {
46309 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46310diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46311index d049393..bb20be0 100644
46312--- a/drivers/rtc/rtc-dev.c
46313+++ b/drivers/rtc/rtc-dev.c
46314@@ -16,6 +16,7 @@
46315 #include <linux/module.h>
46316 #include <linux/rtc.h>
46317 #include <linux/sched.h>
46318+#include <linux/grsecurity.h>
46319 #include "rtc-core.h"
46320
46321 static dev_t rtc_devt;
46322@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46323 if (copy_from_user(&tm, uarg, sizeof(tm)))
46324 return -EFAULT;
46325
46326+ gr_log_timechange();
46327+
46328 return rtc_set_time(rtc, &tm);
46329
46330 case RTC_PIE_ON:
46331diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46332index ca18fd1..055e42d 100644
46333--- a/drivers/rtc/rtc-ds1307.c
46334+++ b/drivers/rtc/rtc-ds1307.c
46335@@ -107,7 +107,7 @@ struct ds1307 {
46336 u8 offset; /* register's offset */
46337 u8 regs[11];
46338 u16 nvram_offset;
46339- struct bin_attribute *nvram;
46340+ bin_attribute_no_const *nvram;
46341 enum ds_type type;
46342 unsigned long flags;
46343 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46344diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46345index fcb0329..d77b7f2 100644
46346--- a/drivers/rtc/rtc-m48t59.c
46347+++ b/drivers/rtc/rtc-m48t59.c
46348@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46349 if (IS_ERR(m48t59->rtc))
46350 return PTR_ERR(m48t59->rtc);
46351
46352- m48t59_nvram_attr.size = pdata->offset;
46353+ pax_open_kernel();
46354+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46355+ pax_close_kernel();
46356
46357 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46358 if (ret)
46359diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
46360index 14b5f8d..cc9bd26 100644
46361--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
46362+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
46363@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
46364 for (bit = 0; bit < 8; bit++) {
46365
46366 if ((pci_status[i] & (0x1 << bit)) != 0) {
46367- static const char *s;
46368+ const char *s;
46369
46370 s = pci_status_strings[bit];
46371 if (i == 7/*TARG*/ && bit == 3)
46372@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
46373
46374 for (bit = 0; bit < 8; bit++) {
46375
46376- if ((split_status[i] & (0x1 << bit)) != 0) {
46377- static const char *s;
46378-
46379- s = split_status_strings[bit];
46380- printk(s, ahd_name(ahd),
46381+ if ((split_status[i] & (0x1 << bit)) != 0)
46382+ printk(split_status_strings[bit], ahd_name(ahd),
46383 split_status_source[i]);
46384- }
46385
46386 if (i > 1)
46387 continue;
46388
46389- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
46390- static const char *s;
46391-
46392- s = split_status_strings[bit];
46393- printk(s, ahd_name(ahd), "SG");
46394- }
46395+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
46396+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
46397 }
46398 }
46399 /*
46400diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46401index e693af6..2e525b6 100644
46402--- a/drivers/scsi/bfa/bfa_fcpim.h
46403+++ b/drivers/scsi/bfa/bfa_fcpim.h
46404@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46405
46406 struct bfa_itn_s {
46407 bfa_isr_func_t isr;
46408-};
46409+} __no_const;
46410
46411 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46412 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46413diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46414index 90814fe..4384138 100644
46415--- a/drivers/scsi/bfa/bfa_ioc.h
46416+++ b/drivers/scsi/bfa/bfa_ioc.h
46417@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46418 bfa_ioc_disable_cbfn_t disable_cbfn;
46419 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46420 bfa_ioc_reset_cbfn_t reset_cbfn;
46421-};
46422+} __no_const;
46423
46424 /*
46425 * IOC event notification mechanism.
46426@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46427 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46428 enum bfi_ioc_state fwstate);
46429 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46430-};
46431+} __no_const;
46432
46433 /*
46434 * Queue element to wait for room in request queue. FIFO order is
46435diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46436index c9382d6..6619864 100644
46437--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46438+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46439@@ -33,8 +33,8 @@
46440 */
46441 #include "libfcoe.h"
46442
46443-static atomic_t ctlr_num;
46444-static atomic_t fcf_num;
46445+static atomic_unchecked_t ctlr_num;
46446+static atomic_unchecked_t fcf_num;
46447
46448 /*
46449 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46450@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46451 if (!ctlr)
46452 goto out;
46453
46454- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46455+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46456 ctlr->f = f;
46457 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46458 INIT_LIST_HEAD(&ctlr->fcfs);
46459@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46460 fcf->dev.parent = &ctlr->dev;
46461 fcf->dev.bus = &fcoe_bus_type;
46462 fcf->dev.type = &fcoe_fcf_device_type;
46463- fcf->id = atomic_inc_return(&fcf_num) - 1;
46464+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46465 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46466
46467 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46468@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46469 {
46470 int error;
46471
46472- atomic_set(&ctlr_num, 0);
46473- atomic_set(&fcf_num, 0);
46474+ atomic_set_unchecked(&ctlr_num, 0);
46475+ atomic_set_unchecked(&fcf_num, 0);
46476
46477 error = bus_register(&fcoe_bus_type);
46478 if (error)
46479diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46480index 3cafe0d..f1e87f8 100644
46481--- a/drivers/scsi/hosts.c
46482+++ b/drivers/scsi/hosts.c
46483@@ -42,7 +42,7 @@
46484 #include "scsi_logging.h"
46485
46486
46487-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46488+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46489
46490
46491 static void scsi_host_cls_release(struct device *dev)
46492@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46493 * subtract one because we increment first then return, but we need to
46494 * know what the next host number was before increment
46495 */
46496- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46497+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46498 shost->dma_channel = 0xff;
46499
46500 /* These three are default values which can be overridden */
46501diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46502index 0eb0940..3ca9b79 100644
46503--- a/drivers/scsi/hpsa.c
46504+++ b/drivers/scsi/hpsa.c
46505@@ -579,7 +579,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46506 unsigned long flags;
46507
46508 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46509- return h->access.command_completed(h, q);
46510+ return h->access->command_completed(h, q);
46511
46512 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46513 a = rq->head[rq->current_entry];
46514@@ -3445,7 +3445,7 @@ static void start_io(struct ctlr_info *h)
46515 while (!list_empty(&h->reqQ)) {
46516 c = list_entry(h->reqQ.next, struct CommandList, list);
46517 /* can't do anything if fifo is full */
46518- if ((h->access.fifo_full(h))) {
46519+ if ((h->access->fifo_full(h))) {
46520 dev_warn(&h->pdev->dev, "fifo full\n");
46521 break;
46522 }
46523@@ -3467,7 +3467,7 @@ static void start_io(struct ctlr_info *h)
46524
46525 /* Tell the controller execute command */
46526 spin_unlock_irqrestore(&h->lock, flags);
46527- h->access.submit_command(h, c);
46528+ h->access->submit_command(h, c);
46529 spin_lock_irqsave(&h->lock, flags);
46530 }
46531 spin_unlock_irqrestore(&h->lock, flags);
46532@@ -3475,17 +3475,17 @@ static void start_io(struct ctlr_info *h)
46533
46534 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46535 {
46536- return h->access.command_completed(h, q);
46537+ return h->access->command_completed(h, q);
46538 }
46539
46540 static inline bool interrupt_pending(struct ctlr_info *h)
46541 {
46542- return h->access.intr_pending(h);
46543+ return h->access->intr_pending(h);
46544 }
46545
46546 static inline long interrupt_not_for_us(struct ctlr_info *h)
46547 {
46548- return (h->access.intr_pending(h) == 0) ||
46549+ return (h->access->intr_pending(h) == 0) ||
46550 (h->interrupts_enabled == 0);
46551 }
46552
46553@@ -4387,7 +4387,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46554 if (prod_index < 0)
46555 return -ENODEV;
46556 h->product_name = products[prod_index].product_name;
46557- h->access = *(products[prod_index].access);
46558+ h->access = products[prod_index].access;
46559
46560 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46561 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46562@@ -4669,7 +4669,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46563
46564 assert_spin_locked(&lockup_detector_lock);
46565 remove_ctlr_from_lockup_detector_list(h);
46566- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46567+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46568 spin_lock_irqsave(&h->lock, flags);
46569 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46570 spin_unlock_irqrestore(&h->lock, flags);
46571@@ -4846,7 +4846,7 @@ reinit_after_soft_reset:
46572 }
46573
46574 /* make sure the board interrupts are off */
46575- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46576+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46577
46578 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46579 goto clean2;
46580@@ -4880,7 +4880,7 @@ reinit_after_soft_reset:
46581 * fake ones to scoop up any residual completions.
46582 */
46583 spin_lock_irqsave(&h->lock, flags);
46584- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46585+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46586 spin_unlock_irqrestore(&h->lock, flags);
46587 free_irqs(h);
46588 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46589@@ -4899,9 +4899,9 @@ reinit_after_soft_reset:
46590 dev_info(&h->pdev->dev, "Board READY.\n");
46591 dev_info(&h->pdev->dev,
46592 "Waiting for stale completions to drain.\n");
46593- h->access.set_intr_mask(h, HPSA_INTR_ON);
46594+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46595 msleep(10000);
46596- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46597+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46598
46599 rc = controller_reset_failed(h->cfgtable);
46600 if (rc)
46601@@ -4922,7 +4922,7 @@ reinit_after_soft_reset:
46602 }
46603
46604 /* Turn the interrupts on so we can service requests */
46605- h->access.set_intr_mask(h, HPSA_INTR_ON);
46606+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46607
46608 hpsa_hba_inquiry(h);
46609 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46610@@ -4977,7 +4977,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46611 * To write all data in the battery backed cache to disks
46612 */
46613 hpsa_flush_cache(h);
46614- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46615+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46616 hpsa_free_irqs_and_disable_msix(h);
46617 }
46618
46619@@ -5145,7 +5145,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46620 return;
46621 }
46622 /* Change the access methods to the performant access methods */
46623- h->access = SA5_performant_access;
46624+ h->access = &SA5_performant_access;
46625 h->transMethod = CFGTBL_Trans_Performant;
46626 }
46627
46628diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46629index bc85e72..ae04a39 100644
46630--- a/drivers/scsi/hpsa.h
46631+++ b/drivers/scsi/hpsa.h
46632@@ -79,7 +79,7 @@ struct ctlr_info {
46633 unsigned int msix_vector;
46634 unsigned int msi_vector;
46635 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46636- struct access_method access;
46637+ struct access_method *access;
46638
46639 /* queue and queue Info */
46640 struct list_head reqQ;
46641diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46642index 5879929..32b241d 100644
46643--- a/drivers/scsi/libfc/fc_exch.c
46644+++ b/drivers/scsi/libfc/fc_exch.c
46645@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46646 u16 pool_max_index;
46647
46648 struct {
46649- atomic_t no_free_exch;
46650- atomic_t no_free_exch_xid;
46651- atomic_t xid_not_found;
46652- atomic_t xid_busy;
46653- atomic_t seq_not_found;
46654- atomic_t non_bls_resp;
46655+ atomic_unchecked_t no_free_exch;
46656+ atomic_unchecked_t no_free_exch_xid;
46657+ atomic_unchecked_t xid_not_found;
46658+ atomic_unchecked_t xid_busy;
46659+ atomic_unchecked_t seq_not_found;
46660+ atomic_unchecked_t non_bls_resp;
46661 } stats;
46662 };
46663
46664@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46665 /* allocate memory for exchange */
46666 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46667 if (!ep) {
46668- atomic_inc(&mp->stats.no_free_exch);
46669+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46670 goto out;
46671 }
46672 memset(ep, 0, sizeof(*ep));
46673@@ -797,7 +797,7 @@ out:
46674 return ep;
46675 err:
46676 spin_unlock_bh(&pool->lock);
46677- atomic_inc(&mp->stats.no_free_exch_xid);
46678+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46679 mempool_free(ep, mp->ep_pool);
46680 return NULL;
46681 }
46682@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46683 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46684 ep = fc_exch_find(mp, xid);
46685 if (!ep) {
46686- atomic_inc(&mp->stats.xid_not_found);
46687+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46688 reject = FC_RJT_OX_ID;
46689 goto out;
46690 }
46691@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46692 ep = fc_exch_find(mp, xid);
46693 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46694 if (ep) {
46695- atomic_inc(&mp->stats.xid_busy);
46696+ atomic_inc_unchecked(&mp->stats.xid_busy);
46697 reject = FC_RJT_RX_ID;
46698 goto rel;
46699 }
46700@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46701 }
46702 xid = ep->xid; /* get our XID */
46703 } else if (!ep) {
46704- atomic_inc(&mp->stats.xid_not_found);
46705+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46706 reject = FC_RJT_RX_ID; /* XID not found */
46707 goto out;
46708 }
46709@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46710 } else {
46711 sp = &ep->seq;
46712 if (sp->id != fh->fh_seq_id) {
46713- atomic_inc(&mp->stats.seq_not_found);
46714+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46715 if (f_ctl & FC_FC_END_SEQ) {
46716 /*
46717 * Update sequence_id based on incoming last
46718@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46719
46720 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46721 if (!ep) {
46722- atomic_inc(&mp->stats.xid_not_found);
46723+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46724 goto out;
46725 }
46726 if (ep->esb_stat & ESB_ST_COMPLETE) {
46727- atomic_inc(&mp->stats.xid_not_found);
46728+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46729 goto rel;
46730 }
46731 if (ep->rxid == FC_XID_UNKNOWN)
46732 ep->rxid = ntohs(fh->fh_rx_id);
46733 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46734- atomic_inc(&mp->stats.xid_not_found);
46735+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46736 goto rel;
46737 }
46738 if (ep->did != ntoh24(fh->fh_s_id) &&
46739 ep->did != FC_FID_FLOGI) {
46740- atomic_inc(&mp->stats.xid_not_found);
46741+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46742 goto rel;
46743 }
46744 sof = fr_sof(fp);
46745@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46746 sp->ssb_stat |= SSB_ST_RESP;
46747 sp->id = fh->fh_seq_id;
46748 } else if (sp->id != fh->fh_seq_id) {
46749- atomic_inc(&mp->stats.seq_not_found);
46750+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46751 goto rel;
46752 }
46753
46754@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46755 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46756
46757 if (!sp)
46758- atomic_inc(&mp->stats.xid_not_found);
46759+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46760 else
46761- atomic_inc(&mp->stats.non_bls_resp);
46762+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46763
46764 fc_frame_free(fp);
46765 }
46766@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46767
46768 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46769 mp = ema->mp;
46770- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46771+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46772 st->fc_no_free_exch_xid +=
46773- atomic_read(&mp->stats.no_free_exch_xid);
46774- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46775- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46776- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46777- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46778+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46779+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46780+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46781+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46782+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46783 }
46784 }
46785 EXPORT_SYMBOL(fc_exch_update_stats);
46786diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46787index d289583..b745eec 100644
46788--- a/drivers/scsi/libsas/sas_ata.c
46789+++ b/drivers/scsi/libsas/sas_ata.c
46790@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46791 .postreset = ata_std_postreset,
46792 .error_handler = ata_std_error_handler,
46793 .post_internal_cmd = sas_ata_post_internal,
46794- .qc_defer = ata_std_qc_defer,
46795+ .qc_defer = ata_std_qc_defer,
46796 .qc_prep = ata_noop_qc_prep,
46797 .qc_issue = sas_ata_qc_issue,
46798 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46799diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46800index 4e1b75c..0bbdfa9 100644
46801--- a/drivers/scsi/lpfc/lpfc.h
46802+++ b/drivers/scsi/lpfc/lpfc.h
46803@@ -432,7 +432,7 @@ struct lpfc_vport {
46804 struct dentry *debug_nodelist;
46805 struct dentry *vport_debugfs_root;
46806 struct lpfc_debugfs_trc *disc_trc;
46807- atomic_t disc_trc_cnt;
46808+ atomic_unchecked_t disc_trc_cnt;
46809 #endif
46810 uint8_t stat_data_enabled;
46811 uint8_t stat_data_blocked;
46812@@ -865,8 +865,8 @@ struct lpfc_hba {
46813 struct timer_list fabric_block_timer;
46814 unsigned long bit_flags;
46815 #define FABRIC_COMANDS_BLOCKED 0
46816- atomic_t num_rsrc_err;
46817- atomic_t num_cmd_success;
46818+ atomic_unchecked_t num_rsrc_err;
46819+ atomic_unchecked_t num_cmd_success;
46820 unsigned long last_rsrc_error_time;
46821 unsigned long last_ramp_down_time;
46822 unsigned long last_ramp_up_time;
46823@@ -902,7 +902,7 @@ struct lpfc_hba {
46824
46825 struct dentry *debug_slow_ring_trc;
46826 struct lpfc_debugfs_trc *slow_ring_trc;
46827- atomic_t slow_ring_trc_cnt;
46828+ atomic_unchecked_t slow_ring_trc_cnt;
46829 /* iDiag debugfs sub-directory */
46830 struct dentry *idiag_root;
46831 struct dentry *idiag_pci_cfg;
46832diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46833index 60084e6..0e2e700 100644
46834--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46835+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46836@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46837
46838 #include <linux/debugfs.h>
46839
46840-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46841+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46842 static unsigned long lpfc_debugfs_start_time = 0L;
46843
46844 /* iDiag */
46845@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46846 lpfc_debugfs_enable = 0;
46847
46848 len = 0;
46849- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46850+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46851 (lpfc_debugfs_max_disc_trc - 1);
46852 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46853 dtp = vport->disc_trc + i;
46854@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46855 lpfc_debugfs_enable = 0;
46856
46857 len = 0;
46858- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46859+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46860 (lpfc_debugfs_max_slow_ring_trc - 1);
46861 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46862 dtp = phba->slow_ring_trc + i;
46863@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46864 !vport || !vport->disc_trc)
46865 return;
46866
46867- index = atomic_inc_return(&vport->disc_trc_cnt) &
46868+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46869 (lpfc_debugfs_max_disc_trc - 1);
46870 dtp = vport->disc_trc + index;
46871 dtp->fmt = fmt;
46872 dtp->data1 = data1;
46873 dtp->data2 = data2;
46874 dtp->data3 = data3;
46875- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46876+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46877 dtp->jif = jiffies;
46878 #endif
46879 return;
46880@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46881 !phba || !phba->slow_ring_trc)
46882 return;
46883
46884- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46885+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46886 (lpfc_debugfs_max_slow_ring_trc - 1);
46887 dtp = phba->slow_ring_trc + index;
46888 dtp->fmt = fmt;
46889 dtp->data1 = data1;
46890 dtp->data2 = data2;
46891 dtp->data3 = data3;
46892- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46893+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46894 dtp->jif = jiffies;
46895 #endif
46896 return;
46897@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46898 "slow_ring buffer\n");
46899 goto debug_failed;
46900 }
46901- atomic_set(&phba->slow_ring_trc_cnt, 0);
46902+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46903 memset(phba->slow_ring_trc, 0,
46904 (sizeof(struct lpfc_debugfs_trc) *
46905 lpfc_debugfs_max_slow_ring_trc));
46906@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46907 "buffer\n");
46908 goto debug_failed;
46909 }
46910- atomic_set(&vport->disc_trc_cnt, 0);
46911+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46912
46913 snprintf(name, sizeof(name), "discovery_trace");
46914 vport->debug_disc_trc =
46915diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46916index 647f5bf..d0068b9 100644
46917--- a/drivers/scsi/lpfc/lpfc_init.c
46918+++ b/drivers/scsi/lpfc/lpfc_init.c
46919@@ -10952,8 +10952,10 @@ lpfc_init(void)
46920 "misc_register returned with status %d", error);
46921
46922 if (lpfc_enable_npiv) {
46923- lpfc_transport_functions.vport_create = lpfc_vport_create;
46924- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46925+ pax_open_kernel();
46926+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46927+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46928+ pax_close_kernel();
46929 }
46930 lpfc_transport_template =
46931 fc_attach_transport(&lpfc_transport_functions);
46932diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46933index c913e8c..d34a119 100644
46934--- a/drivers/scsi/lpfc/lpfc_scsi.c
46935+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46936@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46937 uint32_t evt_posted;
46938
46939 spin_lock_irqsave(&phba->hbalock, flags);
46940- atomic_inc(&phba->num_rsrc_err);
46941+ atomic_inc_unchecked(&phba->num_rsrc_err);
46942 phba->last_rsrc_error_time = jiffies;
46943
46944 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46945@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46946 unsigned long flags;
46947 struct lpfc_hba *phba = vport->phba;
46948 uint32_t evt_posted;
46949- atomic_inc(&phba->num_cmd_success);
46950+ atomic_inc_unchecked(&phba->num_cmd_success);
46951
46952 if (vport->cfg_lun_queue_depth <= queue_depth)
46953 return;
46954@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46955 unsigned long num_rsrc_err, num_cmd_success;
46956 int i;
46957
46958- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46959- num_cmd_success = atomic_read(&phba->num_cmd_success);
46960+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46961+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46962
46963 /*
46964 * The error and success command counters are global per
46965@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46966 }
46967 }
46968 lpfc_destroy_vport_work_array(phba, vports);
46969- atomic_set(&phba->num_rsrc_err, 0);
46970- atomic_set(&phba->num_cmd_success, 0);
46971+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46972+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46973 }
46974
46975 /**
46976@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46977 }
46978 }
46979 lpfc_destroy_vport_work_array(phba, vports);
46980- atomic_set(&phba->num_rsrc_err, 0);
46981- atomic_set(&phba->num_cmd_success, 0);
46982+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46983+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46984 }
46985
46986 /**
46987diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46988index 7f0af4f..193ac3e 100644
46989--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46990+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46991@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
46992 {
46993 struct scsi_device *sdev = to_scsi_device(dev);
46994 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
46995- static struct _raid_device *raid_device;
46996+ struct _raid_device *raid_device;
46997 unsigned long flags;
46998 Mpi2RaidVolPage0_t vol_pg0;
46999 Mpi2ConfigReply_t mpi_reply;
47000@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
47001 {
47002 struct scsi_device *sdev = to_scsi_device(dev);
47003 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
47004- static struct _raid_device *raid_device;
47005+ struct _raid_device *raid_device;
47006 unsigned long flags;
47007 Mpi2RaidVolPage0_t vol_pg0;
47008 Mpi2ConfigReply_t mpi_reply;
47009@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
47010 struct fw_event_work *fw_event)
47011 {
47012 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
47013- static struct _raid_device *raid_device;
47014+ struct _raid_device *raid_device;
47015 unsigned long flags;
47016 u16 handle;
47017
47018@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
47019 u64 sas_address;
47020 struct _sas_device *sas_device;
47021 struct _sas_node *expander_device;
47022- static struct _raid_device *raid_device;
47023+ struct _raid_device *raid_device;
47024 u8 retry_count;
47025 unsigned long flags;
47026
47027diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
47028index a38f71b..f3bc572 100644
47029--- a/drivers/scsi/pmcraid.c
47030+++ b/drivers/scsi/pmcraid.c
47031@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
47032 res->scsi_dev = scsi_dev;
47033 scsi_dev->hostdata = res;
47034 res->change_detected = 0;
47035- atomic_set(&res->read_failures, 0);
47036- atomic_set(&res->write_failures, 0);
47037+ atomic_set_unchecked(&res->read_failures, 0);
47038+ atomic_set_unchecked(&res->write_failures, 0);
47039 rc = 0;
47040 }
47041 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
47042@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
47043
47044 /* If this was a SCSI read/write command keep count of errors */
47045 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
47046- atomic_inc(&res->read_failures);
47047+ atomic_inc_unchecked(&res->read_failures);
47048 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
47049- atomic_inc(&res->write_failures);
47050+ atomic_inc_unchecked(&res->write_failures);
47051
47052 if (!RES_IS_GSCSI(res->cfg_entry) &&
47053 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
47054@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
47055 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47056 * hrrq_id assigned here in queuecommand
47057 */
47058- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47059+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47060 pinstance->num_hrrq;
47061 cmd->cmd_done = pmcraid_io_done;
47062
47063@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
47064 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47065 * hrrq_id assigned here in queuecommand
47066 */
47067- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47068+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47069 pinstance->num_hrrq;
47070
47071 if (request_size) {
47072@@ -4484,7 +4484,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
47073
47074 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
47075 /* add resources only after host is added into system */
47076- if (!atomic_read(&pinstance->expose_resources))
47077+ if (!atomic_read_unchecked(&pinstance->expose_resources))
47078 return;
47079
47080 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
47081@@ -5311,8 +5311,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
47082 init_waitqueue_head(&pinstance->reset_wait_q);
47083
47084 atomic_set(&pinstance->outstanding_cmds, 0);
47085- atomic_set(&pinstance->last_message_id, 0);
47086- atomic_set(&pinstance->expose_resources, 0);
47087+ atomic_set_unchecked(&pinstance->last_message_id, 0);
47088+ atomic_set_unchecked(&pinstance->expose_resources, 0);
47089
47090 INIT_LIST_HEAD(&pinstance->free_res_q);
47091 INIT_LIST_HEAD(&pinstance->used_res_q);
47092@@ -6025,7 +6025,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
47093 /* Schedule worker thread to handle CCN and take care of adding and
47094 * removing devices to OS
47095 */
47096- atomic_set(&pinstance->expose_resources, 1);
47097+ atomic_set_unchecked(&pinstance->expose_resources, 1);
47098 schedule_work(&pinstance->worker_q);
47099 return rc;
47100
47101diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
47102index e1d150f..6c6df44 100644
47103--- a/drivers/scsi/pmcraid.h
47104+++ b/drivers/scsi/pmcraid.h
47105@@ -748,7 +748,7 @@ struct pmcraid_instance {
47106 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
47107
47108 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
47109- atomic_t last_message_id;
47110+ atomic_unchecked_t last_message_id;
47111
47112 /* configuration table */
47113 struct pmcraid_config_table *cfg_table;
47114@@ -777,7 +777,7 @@ struct pmcraid_instance {
47115 atomic_t outstanding_cmds;
47116
47117 /* should add/delete resources to mid-layer now ?*/
47118- atomic_t expose_resources;
47119+ atomic_unchecked_t expose_resources;
47120
47121
47122
47123@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47124 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47125 };
47126 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47127- atomic_t read_failures; /* count of failed READ commands */
47128- atomic_t write_failures; /* count of failed WRITE commands */
47129+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47130+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47131
47132 /* To indicate add/delete/modify during CCN */
47133 u8 change_detected;
47134diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47135index 5f174b8..98d32b0 100644
47136--- a/drivers/scsi/qla2xxx/qla_attr.c
47137+++ b/drivers/scsi/qla2xxx/qla_attr.c
47138@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47139 return 0;
47140 }
47141
47142-struct fc_function_template qla2xxx_transport_functions = {
47143+fc_function_template_no_const qla2xxx_transport_functions = {
47144
47145 .show_host_node_name = 1,
47146 .show_host_port_name = 1,
47147@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47148 .bsg_timeout = qla24xx_bsg_timeout,
47149 };
47150
47151-struct fc_function_template qla2xxx_transport_vport_functions = {
47152+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47153
47154 .show_host_node_name = 1,
47155 .show_host_port_name = 1,
47156diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47157index 4446bf5..9a3574d 100644
47158--- a/drivers/scsi/qla2xxx/qla_gbl.h
47159+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47160@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47161 struct device_attribute;
47162 extern struct device_attribute *qla2x00_host_attrs[];
47163 struct fc_function_template;
47164-extern struct fc_function_template qla2xxx_transport_functions;
47165-extern struct fc_function_template qla2xxx_transport_vport_functions;
47166+extern fc_function_template_no_const qla2xxx_transport_functions;
47167+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47168 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47169 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47170 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47171diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47172index 9f01bbb..5e1dcee 100644
47173--- a/drivers/scsi/qla2xxx/qla_os.c
47174+++ b/drivers/scsi/qla2xxx/qla_os.c
47175@@ -1572,8 +1572,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47176 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47177 /* Ok, a 64bit DMA mask is applicable. */
47178 ha->flags.enable_64bit_addressing = 1;
47179- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47180- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47181+ pax_open_kernel();
47182+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47183+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47184+ pax_close_kernel();
47185 return;
47186 }
47187 }
47188diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47189index 41327d4..feb03d479 100644
47190--- a/drivers/scsi/qla4xxx/ql4_def.h
47191+++ b/drivers/scsi/qla4xxx/ql4_def.h
47192@@ -296,7 +296,7 @@ struct ddb_entry {
47193 * (4000 only) */
47194 atomic_t relogin_timer; /* Max Time to wait for
47195 * relogin to complete */
47196- atomic_t relogin_retry_count; /* Num of times relogin has been
47197+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47198 * retried */
47199 uint32_t default_time2wait; /* Default Min time between
47200 * relogins (+aens) */
47201diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47202index f8a0a26..ec03cee 100644
47203--- a/drivers/scsi/qla4xxx/ql4_os.c
47204+++ b/drivers/scsi/qla4xxx/ql4_os.c
47205@@ -3066,12 +3066,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47206 */
47207 if (!iscsi_is_session_online(cls_sess)) {
47208 /* Reset retry relogin timer */
47209- atomic_inc(&ddb_entry->relogin_retry_count);
47210+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47211 DEBUG2(ql4_printk(KERN_INFO, ha,
47212 "%s: index[%d] relogin timed out-retrying"
47213 " relogin (%d), retry (%d)\n", __func__,
47214 ddb_entry->fw_ddb_index,
47215- atomic_read(&ddb_entry->relogin_retry_count),
47216+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47217 ddb_entry->default_time2wait + 4));
47218 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47219 atomic_set(&ddb_entry->retry_relogin_timer,
47220@@ -5209,7 +5209,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47221
47222 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47223 atomic_set(&ddb_entry->relogin_timer, 0);
47224- atomic_set(&ddb_entry->relogin_retry_count, 0);
47225+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47226 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47227 ddb_entry->default_relogin_timeout =
47228 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47229diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47230index eaa808e..95f8841 100644
47231--- a/drivers/scsi/scsi.c
47232+++ b/drivers/scsi/scsi.c
47233@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47234 unsigned long timeout;
47235 int rtn = 0;
47236
47237- atomic_inc(&cmd->device->iorequest_cnt);
47238+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47239
47240 /* check if the device is still usable */
47241 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47242diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47243index d1549b7..2f60767 100644
47244--- a/drivers/scsi/scsi_lib.c
47245+++ b/drivers/scsi/scsi_lib.c
47246@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47247 shost = sdev->host;
47248 scsi_init_cmd_errh(cmd);
47249 cmd->result = DID_NO_CONNECT << 16;
47250- atomic_inc(&cmd->device->iorequest_cnt);
47251+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47252
47253 /*
47254 * SCSI request completion path will do scsi_device_unbusy(),
47255@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47256
47257 INIT_LIST_HEAD(&cmd->eh_entry);
47258
47259- atomic_inc(&cmd->device->iodone_cnt);
47260+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47261 if (cmd->result)
47262- atomic_inc(&cmd->device->ioerr_cnt);
47263+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47264
47265 disposition = scsi_decide_disposition(cmd);
47266 if (disposition != SUCCESS &&
47267diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47268index 40c6394..62356c2 100644
47269--- a/drivers/scsi/scsi_sysfs.c
47270+++ b/drivers/scsi/scsi_sysfs.c
47271@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47272 char *buf) \
47273 { \
47274 struct scsi_device *sdev = to_scsi_device(dev); \
47275- unsigned long long count = atomic_read(&sdev->field); \
47276+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47277 return snprintf(buf, 20, "0x%llx\n", count); \
47278 } \
47279 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47280diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47281index 84a1fdf..693b0d6 100644
47282--- a/drivers/scsi/scsi_tgt_lib.c
47283+++ b/drivers/scsi/scsi_tgt_lib.c
47284@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47285 int err;
47286
47287 dprintk("%lx %u\n", uaddr, len);
47288- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47289+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47290 if (err) {
47291 /*
47292 * TODO: need to fixup sg_tablesize, max_segment_size,
47293diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47294index 4628fd5..a94a1c2 100644
47295--- a/drivers/scsi/scsi_transport_fc.c
47296+++ b/drivers/scsi/scsi_transport_fc.c
47297@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47298 * Netlink Infrastructure
47299 */
47300
47301-static atomic_t fc_event_seq;
47302+static atomic_unchecked_t fc_event_seq;
47303
47304 /**
47305 * fc_get_event_number - Obtain the next sequential FC event number
47306@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47307 u32
47308 fc_get_event_number(void)
47309 {
47310- return atomic_add_return(1, &fc_event_seq);
47311+ return atomic_add_return_unchecked(1, &fc_event_seq);
47312 }
47313 EXPORT_SYMBOL(fc_get_event_number);
47314
47315@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47316 {
47317 int error;
47318
47319- atomic_set(&fc_event_seq, 0);
47320+ atomic_set_unchecked(&fc_event_seq, 0);
47321
47322 error = transport_class_register(&fc_host_class);
47323 if (error)
47324@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47325 char *cp;
47326
47327 *val = simple_strtoul(buf, &cp, 0);
47328- if ((*cp && (*cp != '\n')) || (*val < 0))
47329+ if (*cp && (*cp != '\n'))
47330 return -EINVAL;
47331 /*
47332 * Check for overflow; dev_loss_tmo is u32
47333diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47334index e4a989f..293090c 100644
47335--- a/drivers/scsi/scsi_transport_iscsi.c
47336+++ b/drivers/scsi/scsi_transport_iscsi.c
47337@@ -79,7 +79,7 @@ struct iscsi_internal {
47338 struct transport_container session_cont;
47339 };
47340
47341-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47342+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47343 static struct workqueue_struct *iscsi_eh_timer_workq;
47344
47345 static DEFINE_IDA(iscsi_sess_ida);
47346@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47347 int err;
47348
47349 ihost = shost->shost_data;
47350- session->sid = atomic_add_return(1, &iscsi_session_nr);
47351+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47352
47353 if (target_id == ISCSI_MAX_TARGET) {
47354 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47355@@ -4077,7 +4077,7 @@ static __init int iscsi_transport_init(void)
47356 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47357 ISCSI_TRANSPORT_VERSION);
47358
47359- atomic_set(&iscsi_session_nr, 0);
47360+ atomic_set_unchecked(&iscsi_session_nr, 0);
47361
47362 err = class_register(&iscsi_transport_class);
47363 if (err)
47364diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47365index f379c7f..e8fc69c 100644
47366--- a/drivers/scsi/scsi_transport_srp.c
47367+++ b/drivers/scsi/scsi_transport_srp.c
47368@@ -33,7 +33,7 @@
47369 #include "scsi_transport_srp_internal.h"
47370
47371 struct srp_host_attrs {
47372- atomic_t next_port_id;
47373+ atomic_unchecked_t next_port_id;
47374 };
47375 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47376
47377@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47378 struct Scsi_Host *shost = dev_to_shost(dev);
47379 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47380
47381- atomic_set(&srp_host->next_port_id, 0);
47382+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47383 return 0;
47384 }
47385
47386@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47387 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47388 rport->roles = ids->roles;
47389
47390- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47391+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47392 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47393
47394 transport_setup_device(&rport->dev);
47395diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47396index 2634d69..fcf7a81 100644
47397--- a/drivers/scsi/sd.c
47398+++ b/drivers/scsi/sd.c
47399@@ -2940,7 +2940,7 @@ static int sd_probe(struct device *dev)
47400 sdkp->disk = gd;
47401 sdkp->index = index;
47402 atomic_set(&sdkp->openers, 0);
47403- atomic_set(&sdkp->device->ioerr_cnt, 0);
47404+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47405
47406 if (!sdp->request_queue->rq_timeout) {
47407 if (sdp->type != TYPE_MOD)
47408diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47409index df5e961..df6b97f 100644
47410--- a/drivers/scsi/sg.c
47411+++ b/drivers/scsi/sg.c
47412@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47413 sdp->disk->disk_name,
47414 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47415 NULL,
47416- (char *)arg);
47417+ (char __user *)arg);
47418 case BLKTRACESTART:
47419 return blk_trace_startstop(sdp->device->request_queue, 1);
47420 case BLKTRACESTOP:
47421diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47422index 9e039c6..ae9e800 100644
47423--- a/drivers/spi/spi.c
47424+++ b/drivers/spi/spi.c
47425@@ -1762,7 +1762,7 @@ int spi_bus_unlock(struct spi_master *master)
47426 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47427
47428 /* portable code must never pass more than 32 bytes */
47429-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47430+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47431
47432 static u8 *buf;
47433
47434diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47435index 2c61783..4d49e4e 100644
47436--- a/drivers/staging/android/timed_output.c
47437+++ b/drivers/staging/android/timed_output.c
47438@@ -25,7 +25,7 @@
47439 #include "timed_output.h"
47440
47441 static struct class *timed_output_class;
47442-static atomic_t device_count;
47443+static atomic_unchecked_t device_count;
47444
47445 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47446 char *buf)
47447@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
47448 timed_output_class = class_create(THIS_MODULE, "timed_output");
47449 if (IS_ERR(timed_output_class))
47450 return PTR_ERR(timed_output_class);
47451- atomic_set(&device_count, 0);
47452+ atomic_set_unchecked(&device_count, 0);
47453 timed_output_class->dev_groups = timed_output_groups;
47454 }
47455
47456@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47457 if (ret < 0)
47458 return ret;
47459
47460- tdev->index = atomic_inc_return(&device_count);
47461+ tdev->index = atomic_inc_return_unchecked(&device_count);
47462 tdev->dev = device_create(timed_output_class, NULL,
47463 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47464 if (IS_ERR(tdev->dev))
47465diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
47466index 0247a20..cb9595c 100644
47467--- a/drivers/staging/gdm724x/gdm_tty.c
47468+++ b/drivers/staging/gdm724x/gdm_tty.c
47469@@ -45,7 +45,7 @@
47470 #define gdm_tty_send_control(n, r, v, d, l) (\
47471 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
47472
47473-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
47474+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
47475
47476 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
47477 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
47478diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
47479index ef5064e..fce01db 100644
47480--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
47481+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
47482@@ -478,13 +478,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
47483 return 0;
47484 }
47485
47486-sfw_test_client_ops_t brw_test_client;
47487-void brw_init_test_client(void)
47488-{
47489- brw_test_client.tso_init = brw_client_init;
47490- brw_test_client.tso_fini = brw_client_fini;
47491- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
47492- brw_test_client.tso_done_rpc = brw_client_done_rpc;
47493+sfw_test_client_ops_t brw_test_client = {
47494+ .tso_init = brw_client_init,
47495+ .tso_fini = brw_client_fini,
47496+ .tso_prep_rpc = brw_client_prep_rpc,
47497+ .tso_done_rpc = brw_client_done_rpc,
47498 };
47499
47500 srpc_service_t brw_test_service;
47501diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
47502index 483c785..e1a2a7b 100644
47503--- a/drivers/staging/lustre/lnet/selftest/framework.c
47504+++ b/drivers/staging/lustre/lnet/selftest/framework.c
47505@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
47506
47507 extern sfw_test_client_ops_t ping_test_client;
47508 extern srpc_service_t ping_test_service;
47509-extern void ping_init_test_client(void);
47510 extern void ping_init_test_service(void);
47511
47512 extern sfw_test_client_ops_t brw_test_client;
47513 extern srpc_service_t brw_test_service;
47514-extern void brw_init_test_client(void);
47515 extern void brw_init_test_service(void);
47516
47517
47518@@ -1684,12 +1682,10 @@ sfw_startup (void)
47519 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
47520 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
47521
47522- brw_init_test_client();
47523 brw_init_test_service();
47524 rc = sfw_register_test(&brw_test_service, &brw_test_client);
47525 LASSERT (rc == 0);
47526
47527- ping_init_test_client();
47528 ping_init_test_service();
47529 rc = sfw_register_test(&ping_test_service, &ping_test_client);
47530 LASSERT (rc == 0);
47531diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
47532index f0f9194..b589047 100644
47533--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
47534+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
47535@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
47536 return 0;
47537 }
47538
47539-sfw_test_client_ops_t ping_test_client;
47540-void ping_init_test_client(void)
47541-{
47542- ping_test_client.tso_init = ping_client_init;
47543- ping_test_client.tso_fini = ping_client_fini;
47544- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
47545- ping_test_client.tso_done_rpc = ping_client_done_rpc;
47546-}
47547+sfw_test_client_ops_t ping_test_client = {
47548+ .tso_init = ping_client_init,
47549+ .tso_fini = ping_client_fini,
47550+ .tso_prep_rpc = ping_client_prep_rpc,
47551+ .tso_done_rpc = ping_client_done_rpc,
47552+};
47553
47554 srpc_service_t ping_test_service;
47555 void ping_init_test_service(void)
47556diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
47557index 7020d9c..0d3b580 100644
47558--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
47559+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
47560@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
47561 ldlm_completion_callback lcs_completion;
47562 ldlm_blocking_callback lcs_blocking;
47563 ldlm_glimpse_callback lcs_glimpse;
47564-};
47565+} __no_const;
47566
47567 /* ldlm_lockd.c */
47568 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
47569diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
47570index a612255..9a9e2dd 100644
47571--- a/drivers/staging/lustre/lustre/include/obd.h
47572+++ b/drivers/staging/lustre/lustre/include/obd.h
47573@@ -1417,7 +1417,7 @@ struct md_ops {
47574 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
47575 * wrapper function in include/linux/obd_class.h.
47576 */
47577-};
47578+} __no_const;
47579
47580 struct lsm_operations {
47581 void (*lsm_free)(struct lov_stripe_md *);
47582diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
47583index fc6c977..df1f956 100644
47584--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
47585+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
47586@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
47587 int LL_PROC_PROTO(proc_console_max_delay_cs)
47588 {
47589 int rc, max_delay_cs;
47590- ctl_table_t dummy = *table;
47591+ ctl_table_no_const dummy = *table;
47592 cfs_duration_t d;
47593
47594 dummy.data = &max_delay_cs;
47595@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
47596 int LL_PROC_PROTO(proc_console_min_delay_cs)
47597 {
47598 int rc, min_delay_cs;
47599- ctl_table_t dummy = *table;
47600+ ctl_table_no_const dummy = *table;
47601 cfs_duration_t d;
47602
47603 dummy.data = &min_delay_cs;
47604@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
47605 int LL_PROC_PROTO(proc_console_backoff)
47606 {
47607 int rc, backoff;
47608- ctl_table_t dummy = *table;
47609+ ctl_table_no_const dummy = *table;
47610
47611 dummy.data = &backoff;
47612 dummy.proc_handler = &proc_dointvec;
47613diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47614index 3675020..e80d92c 100644
47615--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47616+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47617@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47618
47619 static int solo_sysfs_init(struct solo_dev *solo_dev)
47620 {
47621- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47622+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47623 struct device *dev = &solo_dev->dev;
47624 const char *driver;
47625 int i;
47626diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47627index 3335941..2b26186 100644
47628--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47629+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47630@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47631
47632 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47633 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47634- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47635+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47636 if (p2m_id < 0)
47637 p2m_id = -p2m_id;
47638 }
47639diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47640index 6f91d2e..3f011d2 100644
47641--- a/drivers/staging/media/solo6x10/solo6x10.h
47642+++ b/drivers/staging/media/solo6x10/solo6x10.h
47643@@ -238,7 +238,7 @@ struct solo_dev {
47644
47645 /* P2M DMA Engine */
47646 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47647- atomic_t p2m_count;
47648+ atomic_unchecked_t p2m_count;
47649 int p2m_jiffies;
47650 unsigned int p2m_timeouts;
47651
47652diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47653index e14a1bb..9cb9bbe 100644
47654--- a/drivers/staging/octeon/ethernet-rx.c
47655+++ b/drivers/staging/octeon/ethernet-rx.c
47656@@ -419,11 +419,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47657 /* Increment RX stats for virtual ports */
47658 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47659 #ifdef CONFIG_64BIT
47660- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47661- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47662+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47663+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47664 #else
47665- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47666- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47667+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47668+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47669 #endif
47670 }
47671 netif_receive_skb(skb);
47672@@ -434,9 +434,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47673 dev->name);
47674 */
47675 #ifdef CONFIG_64BIT
47676- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47677+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47678 #else
47679- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47680+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47681 #endif
47682 dev_kfree_skb_irq(skb);
47683 }
47684diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47685index c3a90e7..023619a 100644
47686--- a/drivers/staging/octeon/ethernet.c
47687+++ b/drivers/staging/octeon/ethernet.c
47688@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47689 * since the RX tasklet also increments it.
47690 */
47691 #ifdef CONFIG_64BIT
47692- atomic64_add(rx_status.dropped_packets,
47693- (atomic64_t *)&priv->stats.rx_dropped);
47694+ atomic64_add_unchecked(rx_status.dropped_packets,
47695+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47696 #else
47697- atomic_add(rx_status.dropped_packets,
47698- (atomic_t *)&priv->stats.rx_dropped);
47699+ atomic_add_unchecked(rx_status.dropped_packets,
47700+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47701 #endif
47702 }
47703
47704diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
47705index 439c3c9..2d74293 100644
47706--- a/drivers/staging/rtl8188eu/include/hal_intf.h
47707+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
47708@@ -271,7 +271,7 @@ struct hal_ops {
47709 s32 (*c2h_handler)(struct adapter *padapter,
47710 struct c2h_evt_hdr *c2h_evt);
47711 c2h_id_filter c2h_id_filter_ccx;
47712-};
47713+} __no_const;
47714
47715 enum rt_eeprom_type {
47716 EEPROM_93C46,
47717diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
47718index eb6f0e5..e6a0958 100644
47719--- a/drivers/staging/rtl8188eu/include/rtw_io.h
47720+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
47721@@ -126,7 +126,7 @@ struct _io_ops {
47722 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
47723 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
47724 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
47725-};
47726+} __no_const;
47727
47728 struct io_req {
47729 struct list_head list;
47730diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47731index dc23395..cf7e9b1 100644
47732--- a/drivers/staging/rtl8712/rtl871x_io.h
47733+++ b/drivers/staging/rtl8712/rtl871x_io.h
47734@@ -108,7 +108,7 @@ struct _io_ops {
47735 u8 *pmem);
47736 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47737 u8 *pmem);
47738-};
47739+} __no_const;
47740
47741 struct io_req {
47742 struct list_head list;
47743diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47744index 1f5088b..0e59820 100644
47745--- a/drivers/staging/sbe-2t3e3/netdev.c
47746+++ b/drivers/staging/sbe-2t3e3/netdev.c
47747@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47748 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47749
47750 if (rlen)
47751- if (copy_to_user(data, &resp, rlen))
47752+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47753 return -EFAULT;
47754
47755 return 0;
47756diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47757index a863a98..d272795 100644
47758--- a/drivers/staging/usbip/vhci.h
47759+++ b/drivers/staging/usbip/vhci.h
47760@@ -83,7 +83,7 @@ struct vhci_hcd {
47761 unsigned resuming:1;
47762 unsigned long re_timeout;
47763
47764- atomic_t seqnum;
47765+ atomic_unchecked_t seqnum;
47766
47767 /*
47768 * NOTE:
47769diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47770index d7974cb..d78076b 100644
47771--- a/drivers/staging/usbip/vhci_hcd.c
47772+++ b/drivers/staging/usbip/vhci_hcd.c
47773@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47774
47775 spin_lock(&vdev->priv_lock);
47776
47777- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47778+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47779 if (priv->seqnum == 0xffff)
47780 dev_info(&urb->dev->dev, "seqnum max\n");
47781
47782@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47783 return -ENOMEM;
47784 }
47785
47786- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47787+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47788 if (unlink->seqnum == 0xffff)
47789 pr_info("seqnum max\n");
47790
47791@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47792 vdev->rhport = rhport;
47793 }
47794
47795- atomic_set(&vhci->seqnum, 0);
47796+ atomic_set_unchecked(&vhci->seqnum, 0);
47797 spin_lock_init(&vhci->lock);
47798
47799 hcd->power_budget = 0; /* no limit */
47800diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47801index d07fcb5..358e1e1 100644
47802--- a/drivers/staging/usbip/vhci_rx.c
47803+++ b/drivers/staging/usbip/vhci_rx.c
47804@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47805 if (!urb) {
47806 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47807 pr_info("max seqnum %d\n",
47808- atomic_read(&the_controller->seqnum));
47809+ atomic_read_unchecked(&the_controller->seqnum));
47810 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47811 return;
47812 }
47813diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47814index 8acff44..bdb2fca 100644
47815--- a/drivers/staging/vt6655/hostap.c
47816+++ b/drivers/staging/vt6655/hostap.c
47817@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47818 *
47819 */
47820
47821+static net_device_ops_no_const apdev_netdev_ops;
47822+
47823 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47824 {
47825 PSDevice apdev_priv;
47826 struct net_device *dev = pDevice->dev;
47827 int ret;
47828- const struct net_device_ops apdev_netdev_ops = {
47829- .ndo_start_xmit = pDevice->tx_80211,
47830- };
47831
47832 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47833
47834@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47835 *apdev_priv = *pDevice;
47836 eth_hw_addr_inherit(pDevice->apdev, dev);
47837
47838+ /* only half broken now */
47839+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47840 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47841
47842 pDevice->apdev->type = ARPHRD_IEEE80211;
47843diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47844index c699a30..b90a5fd 100644
47845--- a/drivers/staging/vt6656/hostap.c
47846+++ b/drivers/staging/vt6656/hostap.c
47847@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47848 *
47849 */
47850
47851+static net_device_ops_no_const apdev_netdev_ops;
47852+
47853 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47854 {
47855 struct vnt_private *apdev_priv;
47856 struct net_device *dev = pDevice->dev;
47857 int ret;
47858- const struct net_device_ops apdev_netdev_ops = {
47859- .ndo_start_xmit = pDevice->tx_80211,
47860- };
47861
47862 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47863
47864@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47865 *apdev_priv = *pDevice;
47866 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47867
47868+ /* only half broken now */
47869+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47870 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47871
47872 pDevice->apdev->type = ARPHRD_IEEE80211;
47873diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47874index e51b09a..5ebac31 100644
47875--- a/drivers/target/sbp/sbp_target.c
47876+++ b/drivers/target/sbp/sbp_target.c
47877@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47878
47879 #define SESSION_MAINTENANCE_INTERVAL HZ
47880
47881-static atomic_t login_id = ATOMIC_INIT(0);
47882+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47883
47884 static void session_maintenance_work(struct work_struct *);
47885 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47886@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47887 login->lun = se_lun;
47888 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47889 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47890- login->login_id = atomic_inc_return(&login_id);
47891+ login->login_id = atomic_inc_return_unchecked(&login_id);
47892
47893 login->tgt_agt = sbp_target_agent_register(login);
47894 if (IS_ERR(login->tgt_agt)) {
47895diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47896index d90dbb0..6cbe585 100644
47897--- a/drivers/target/target_core_device.c
47898+++ b/drivers/target/target_core_device.c
47899@@ -1431,7 +1431,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47900 spin_lock_init(&dev->se_tmr_lock);
47901 spin_lock_init(&dev->qf_cmd_lock);
47902 sema_init(&dev->caw_sem, 1);
47903- atomic_set(&dev->dev_ordered_id, 0);
47904+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47905 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47906 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47907 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47908diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47909index 0b0009b..215e88e 100644
47910--- a/drivers/target/target_core_transport.c
47911+++ b/drivers/target/target_core_transport.c
47912@@ -1137,7 +1137,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47913 * Used to determine when ORDERED commands should go from
47914 * Dormant to Active status.
47915 */
47916- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47917+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47918 smp_mb__after_atomic_inc();
47919 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47920 cmd->se_ordered_id, cmd->sam_task_attr,
47921diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47922index 33f83fe..d80f8e1 100644
47923--- a/drivers/tty/cyclades.c
47924+++ b/drivers/tty/cyclades.c
47925@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47926 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47927 info->port.count);
47928 #endif
47929- info->port.count++;
47930+ atomic_inc(&info->port.count);
47931 #ifdef CY_DEBUG_COUNT
47932 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47933- current->pid, info->port.count);
47934+ current->pid, atomic_read(&info->port.count));
47935 #endif
47936
47937 /*
47938@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47939 for (j = 0; j < cy_card[i].nports; j++) {
47940 info = &cy_card[i].ports[j];
47941
47942- if (info->port.count) {
47943+ if (atomic_read(&info->port.count)) {
47944 /* XXX is the ldisc num worth this? */
47945 struct tty_struct *tty;
47946 struct tty_ldisc *ld;
47947diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47948index 9eba119..5070303 100644
47949--- a/drivers/tty/hvc/hvc_console.c
47950+++ b/drivers/tty/hvc/hvc_console.c
47951@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47952
47953 spin_lock_irqsave(&hp->port.lock, flags);
47954 /* Check and then increment for fast path open. */
47955- if (hp->port.count++ > 0) {
47956+ if (atomic_inc_return(&hp->port.count) > 1) {
47957 spin_unlock_irqrestore(&hp->port.lock, flags);
47958 hvc_kick();
47959 return 0;
47960@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47961
47962 spin_lock_irqsave(&hp->port.lock, flags);
47963
47964- if (--hp->port.count == 0) {
47965+ if (atomic_dec_return(&hp->port.count) == 0) {
47966 spin_unlock_irqrestore(&hp->port.lock, flags);
47967 /* We are done with the tty pointer now. */
47968 tty_port_tty_set(&hp->port, NULL);
47969@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47970 */
47971 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47972 } else {
47973- if (hp->port.count < 0)
47974+ if (atomic_read(&hp->port.count) < 0)
47975 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47976- hp->vtermno, hp->port.count);
47977+ hp->vtermno, atomic_read(&hp->port.count));
47978 spin_unlock_irqrestore(&hp->port.lock, flags);
47979 }
47980 }
47981@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
47982 * open->hangup case this can be called after the final close so prevent
47983 * that from happening for now.
47984 */
47985- if (hp->port.count <= 0) {
47986+ if (atomic_read(&hp->port.count) <= 0) {
47987 spin_unlock_irqrestore(&hp->port.lock, flags);
47988 return;
47989 }
47990
47991- hp->port.count = 0;
47992+ atomic_set(&hp->port.count, 0);
47993 spin_unlock_irqrestore(&hp->port.lock, flags);
47994 tty_port_tty_set(&hp->port, NULL);
47995
47996@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47997 return -EPIPE;
47998
47999 /* FIXME what's this (unprotected) check for? */
48000- if (hp->port.count <= 0)
48001+ if (atomic_read(&hp->port.count) <= 0)
48002 return -EIO;
48003
48004 spin_lock_irqsave(&hp->lock, flags);
48005diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
48006index 81e939e..95ead10 100644
48007--- a/drivers/tty/hvc/hvcs.c
48008+++ b/drivers/tty/hvc/hvcs.c
48009@@ -83,6 +83,7 @@
48010 #include <asm/hvcserver.h>
48011 #include <asm/uaccess.h>
48012 #include <asm/vio.h>
48013+#include <asm/local.h>
48014
48015 /*
48016 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
48017@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
48018
48019 spin_lock_irqsave(&hvcsd->lock, flags);
48020
48021- if (hvcsd->port.count > 0) {
48022+ if (atomic_read(&hvcsd->port.count) > 0) {
48023 spin_unlock_irqrestore(&hvcsd->lock, flags);
48024 printk(KERN_INFO "HVCS: vterm state unchanged. "
48025 "The hvcs device node is still in use.\n");
48026@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
48027 }
48028 }
48029
48030- hvcsd->port.count = 0;
48031+ atomic_set(&hvcsd->port.count, 0);
48032 hvcsd->port.tty = tty;
48033 tty->driver_data = hvcsd;
48034
48035@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
48036 unsigned long flags;
48037
48038 spin_lock_irqsave(&hvcsd->lock, flags);
48039- hvcsd->port.count++;
48040+ atomic_inc(&hvcsd->port.count);
48041 hvcsd->todo_mask |= HVCS_SCHED_READ;
48042 spin_unlock_irqrestore(&hvcsd->lock, flags);
48043
48044@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
48045 hvcsd = tty->driver_data;
48046
48047 spin_lock_irqsave(&hvcsd->lock, flags);
48048- if (--hvcsd->port.count == 0) {
48049+ if (atomic_dec_and_test(&hvcsd->port.count)) {
48050
48051 vio_disable_interrupts(hvcsd->vdev);
48052
48053@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
48054
48055 free_irq(irq, hvcsd);
48056 return;
48057- } else if (hvcsd->port.count < 0) {
48058+ } else if (atomic_read(&hvcsd->port.count) < 0) {
48059 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
48060 " is missmanaged.\n",
48061- hvcsd->vdev->unit_address, hvcsd->port.count);
48062+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
48063 }
48064
48065 spin_unlock_irqrestore(&hvcsd->lock, flags);
48066@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
48067
48068 spin_lock_irqsave(&hvcsd->lock, flags);
48069 /* Preserve this so that we know how many kref refs to put */
48070- temp_open_count = hvcsd->port.count;
48071+ temp_open_count = atomic_read(&hvcsd->port.count);
48072
48073 /*
48074 * Don't kref put inside the spinlock because the destruction
48075@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
48076 tty->driver_data = NULL;
48077 hvcsd->port.tty = NULL;
48078
48079- hvcsd->port.count = 0;
48080+ atomic_set(&hvcsd->port.count, 0);
48081
48082 /* This will drop any buffered data on the floor which is OK in a hangup
48083 * scenario. */
48084@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
48085 * the middle of a write operation? This is a crummy place to do this
48086 * but we want to keep it all in the spinlock.
48087 */
48088- if (hvcsd->port.count <= 0) {
48089+ if (atomic_read(&hvcsd->port.count) <= 0) {
48090 spin_unlock_irqrestore(&hvcsd->lock, flags);
48091 return -ENODEV;
48092 }
48093@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
48094 {
48095 struct hvcs_struct *hvcsd = tty->driver_data;
48096
48097- if (!hvcsd || hvcsd->port.count <= 0)
48098+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
48099 return 0;
48100
48101 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
48102diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
48103index 4190199..48f2920 100644
48104--- a/drivers/tty/hvc/hvsi.c
48105+++ b/drivers/tty/hvc/hvsi.c
48106@@ -85,7 +85,7 @@ struct hvsi_struct {
48107 int n_outbuf;
48108 uint32_t vtermno;
48109 uint32_t virq;
48110- atomic_t seqno; /* HVSI packet sequence number */
48111+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
48112 uint16_t mctrl;
48113 uint8_t state; /* HVSI protocol state */
48114 uint8_t flags;
48115@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
48116
48117 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
48118 packet.hdr.len = sizeof(struct hvsi_query_response);
48119- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48120+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48121 packet.verb = VSV_SEND_VERSION_NUMBER;
48122 packet.u.version = HVSI_VERSION;
48123 packet.query_seqno = query_seqno+1;
48124@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
48125
48126 packet.hdr.type = VS_QUERY_PACKET_HEADER;
48127 packet.hdr.len = sizeof(struct hvsi_query);
48128- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48129+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48130 packet.verb = verb;
48131
48132 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
48133@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
48134 int wrote;
48135
48136 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
48137- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48138+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48139 packet.hdr.len = sizeof(struct hvsi_control);
48140 packet.verb = VSV_SET_MODEM_CTL;
48141 packet.mask = HVSI_TSDTR;
48142@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
48143 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
48144
48145 packet.hdr.type = VS_DATA_PACKET_HEADER;
48146- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48147+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48148 packet.hdr.len = count + sizeof(struct hvsi_header);
48149 memcpy(&packet.data, buf, count);
48150
48151@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
48152 struct hvsi_control packet __ALIGNED__;
48153
48154 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
48155- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48156+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48157 packet.hdr.len = 6;
48158 packet.verb = VSV_CLOSE_PROTOCOL;
48159
48160diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
48161index ac27671..0f627ee 100644
48162--- a/drivers/tty/hvc/hvsi_lib.c
48163+++ b/drivers/tty/hvc/hvsi_lib.c
48164@@ -9,7 +9,7 @@
48165
48166 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
48167 {
48168- packet->seqno = atomic_inc_return(&pv->seqno);
48169+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
48170
48171 /* Assumes that always succeeds, works in practice */
48172 return pv->put_chars(pv->termno, (char *)packet, packet->len);
48173@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
48174
48175 /* Reset state */
48176 pv->established = 0;
48177- atomic_set(&pv->seqno, 0);
48178+ atomic_set_unchecked(&pv->seqno, 0);
48179
48180 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
48181
48182@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
48183 pv->mctrl_update = 0;
48184 q.hdr.type = VS_QUERY_PACKET_HEADER;
48185 q.hdr.len = sizeof(struct hvsi_query);
48186- q.hdr.seqno = atomic_inc_return(&pv->seqno);
48187+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
48188 q.verb = VSV_SEND_MODEM_CTL_STATUS;
48189 rc = hvsi_send_packet(pv, &q.hdr);
48190 if (rc <= 0) {
48191diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
48192index 8fd72ff..34a0bed 100644
48193--- a/drivers/tty/ipwireless/tty.c
48194+++ b/drivers/tty/ipwireless/tty.c
48195@@ -29,6 +29,7 @@
48196 #include <linux/tty_driver.h>
48197 #include <linux/tty_flip.h>
48198 #include <linux/uaccess.h>
48199+#include <asm/local.h>
48200
48201 #include "tty.h"
48202 #include "network.h"
48203@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48204 mutex_unlock(&tty->ipw_tty_mutex);
48205 return -ENODEV;
48206 }
48207- if (tty->port.count == 0)
48208+ if (atomic_read(&tty->port.count) == 0)
48209 tty->tx_bytes_queued = 0;
48210
48211- tty->port.count++;
48212+ atomic_inc(&tty->port.count);
48213
48214 tty->port.tty = linux_tty;
48215 linux_tty->driver_data = tty;
48216@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48217
48218 static void do_ipw_close(struct ipw_tty *tty)
48219 {
48220- tty->port.count--;
48221-
48222- if (tty->port.count == 0) {
48223+ if (atomic_dec_return(&tty->port.count) == 0) {
48224 struct tty_struct *linux_tty = tty->port.tty;
48225
48226 if (linux_tty != NULL) {
48227@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
48228 return;
48229
48230 mutex_lock(&tty->ipw_tty_mutex);
48231- if (tty->port.count == 0) {
48232+ if (atomic_read(&tty->port.count) == 0) {
48233 mutex_unlock(&tty->ipw_tty_mutex);
48234 return;
48235 }
48236@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
48237
48238 mutex_lock(&tty->ipw_tty_mutex);
48239
48240- if (!tty->port.count) {
48241+ if (!atomic_read(&tty->port.count)) {
48242 mutex_unlock(&tty->ipw_tty_mutex);
48243 return;
48244 }
48245@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
48246 return -ENODEV;
48247
48248 mutex_lock(&tty->ipw_tty_mutex);
48249- if (!tty->port.count) {
48250+ if (!atomic_read(&tty->port.count)) {
48251 mutex_unlock(&tty->ipw_tty_mutex);
48252 return -EINVAL;
48253 }
48254@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
48255 if (!tty)
48256 return -ENODEV;
48257
48258- if (!tty->port.count)
48259+ if (!atomic_read(&tty->port.count))
48260 return -EINVAL;
48261
48262 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
48263@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
48264 if (!tty)
48265 return 0;
48266
48267- if (!tty->port.count)
48268+ if (!atomic_read(&tty->port.count))
48269 return 0;
48270
48271 return tty->tx_bytes_queued;
48272@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48273 if (!tty)
48274 return -ENODEV;
48275
48276- if (!tty->port.count)
48277+ if (!atomic_read(&tty->port.count))
48278 return -EINVAL;
48279
48280 return get_control_lines(tty);
48281@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48282 if (!tty)
48283 return -ENODEV;
48284
48285- if (!tty->port.count)
48286+ if (!atomic_read(&tty->port.count))
48287 return -EINVAL;
48288
48289 return set_control_lines(tty, set, clear);
48290@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
48291 if (!tty)
48292 return -ENODEV;
48293
48294- if (!tty->port.count)
48295+ if (!atomic_read(&tty->port.count))
48296 return -EINVAL;
48297
48298 /* FIXME: Exactly how is the tty object locked here .. */
48299@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48300 * are gone */
48301 mutex_lock(&ttyj->ipw_tty_mutex);
48302 }
48303- while (ttyj->port.count)
48304+ while (atomic_read(&ttyj->port.count))
48305 do_ipw_close(ttyj);
48306 ipwireless_disassociate_network_ttys(network,
48307 ttyj->channel_idx);
48308diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48309index 1deaca4..c8582d4 100644
48310--- a/drivers/tty/moxa.c
48311+++ b/drivers/tty/moxa.c
48312@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48313 }
48314
48315 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48316- ch->port.count++;
48317+ atomic_inc(&ch->port.count);
48318 tty->driver_data = ch;
48319 tty_port_tty_set(&ch->port, tty);
48320 mutex_lock(&ch->port.mutex);
48321diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48322index c0f76da..d974c32 100644
48323--- a/drivers/tty/n_gsm.c
48324+++ b/drivers/tty/n_gsm.c
48325@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48326 spin_lock_init(&dlci->lock);
48327 mutex_init(&dlci->mutex);
48328 dlci->fifo = &dlci->_fifo;
48329- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48330+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48331 kfree(dlci);
48332 return NULL;
48333 }
48334@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48335 struct gsm_dlci *dlci = tty->driver_data;
48336 struct tty_port *port = &dlci->port;
48337
48338- port->count++;
48339+ atomic_inc(&port->count);
48340 dlci_get(dlci);
48341 dlci_get(dlci->gsm->dlci[0]);
48342 mux_get(dlci->gsm);
48343diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48344index 4d6f430..0810fa9 100644
48345--- a/drivers/tty/n_tty.c
48346+++ b/drivers/tty/n_tty.c
48347@@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48348 {
48349 *ops = tty_ldisc_N_TTY;
48350 ops->owner = NULL;
48351- ops->refcount = ops->flags = 0;
48352+ atomic_set(&ops->refcount, 0);
48353+ ops->flags = 0;
48354 }
48355 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48356diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48357index 25c9bc7..24077b7 100644
48358--- a/drivers/tty/pty.c
48359+++ b/drivers/tty/pty.c
48360@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
48361 panic("Couldn't register Unix98 pts driver");
48362
48363 /* Now create the /dev/ptmx special device */
48364+ pax_open_kernel();
48365 tty_default_fops(&ptmx_fops);
48366- ptmx_fops.open = ptmx_open;
48367+ *(void **)&ptmx_fops.open = ptmx_open;
48368+ pax_close_kernel();
48369
48370 cdev_init(&ptmx_cdev, &ptmx_fops);
48371 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48372diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48373index 354564e..fe50d9a 100644
48374--- a/drivers/tty/rocket.c
48375+++ b/drivers/tty/rocket.c
48376@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48377 tty->driver_data = info;
48378 tty_port_tty_set(port, tty);
48379
48380- if (port->count++ == 0) {
48381+ if (atomic_inc_return(&port->count) == 1) {
48382 atomic_inc(&rp_num_ports_open);
48383
48384 #ifdef ROCKET_DEBUG_OPEN
48385@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48386 #endif
48387 }
48388 #ifdef ROCKET_DEBUG_OPEN
48389- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48390+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48391 #endif
48392
48393 /*
48394@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48395 spin_unlock_irqrestore(&info->port.lock, flags);
48396 return;
48397 }
48398- if (info->port.count)
48399+ if (atomic_read(&info->port.count))
48400 atomic_dec(&rp_num_ports_open);
48401 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48402 spin_unlock_irqrestore(&info->port.lock, flags);
48403diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48404index 1274499..f541382 100644
48405--- a/drivers/tty/serial/ioc4_serial.c
48406+++ b/drivers/tty/serial/ioc4_serial.c
48407@@ -437,7 +437,7 @@ struct ioc4_soft {
48408 } is_intr_info[MAX_IOC4_INTR_ENTS];
48409
48410 /* Number of entries active in the above array */
48411- atomic_t is_num_intrs;
48412+ atomic_unchecked_t is_num_intrs;
48413 } is_intr_type[IOC4_NUM_INTR_TYPES];
48414
48415 /* is_ir_lock must be held while
48416@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48417 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48418 || (type == IOC4_OTHER_INTR_TYPE)));
48419
48420- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48421+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48422 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48423
48424 /* Save off the lower level interrupt handler */
48425@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48426
48427 soft = arg;
48428 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48429- num_intrs = (int)atomic_read(
48430+ num_intrs = (int)atomic_read_unchecked(
48431 &soft->is_intr_type[intr_type].is_num_intrs);
48432
48433 this_mir = this_ir = pending_intrs(soft, intr_type);
48434diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48435index a260cde..6b2b5ce 100644
48436--- a/drivers/tty/serial/kgdboc.c
48437+++ b/drivers/tty/serial/kgdboc.c
48438@@ -24,8 +24,9 @@
48439 #define MAX_CONFIG_LEN 40
48440
48441 static struct kgdb_io kgdboc_io_ops;
48442+static struct kgdb_io kgdboc_io_ops_console;
48443
48444-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48445+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48446 static int configured = -1;
48447
48448 static char config[MAX_CONFIG_LEN];
48449@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48450 kgdboc_unregister_kbd();
48451 if (configured == 1)
48452 kgdb_unregister_io_module(&kgdboc_io_ops);
48453+ else if (configured == 2)
48454+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48455 }
48456
48457 static int configure_kgdboc(void)
48458@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48459 int err;
48460 char *cptr = config;
48461 struct console *cons;
48462+ int is_console = 0;
48463
48464 err = kgdboc_option_setup(config);
48465 if (err || !strlen(config) || isspace(config[0]))
48466 goto noconfig;
48467
48468 err = -ENODEV;
48469- kgdboc_io_ops.is_console = 0;
48470 kgdb_tty_driver = NULL;
48471
48472 kgdboc_use_kms = 0;
48473@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48474 int idx;
48475 if (cons->device && cons->device(cons, &idx) == p &&
48476 idx == tty_line) {
48477- kgdboc_io_ops.is_console = 1;
48478+ is_console = 1;
48479 break;
48480 }
48481 cons = cons->next;
48482@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48483 kgdb_tty_line = tty_line;
48484
48485 do_register:
48486- err = kgdb_register_io_module(&kgdboc_io_ops);
48487+ if (is_console) {
48488+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48489+ configured = 2;
48490+ } else {
48491+ err = kgdb_register_io_module(&kgdboc_io_ops);
48492+ configured = 1;
48493+ }
48494 if (err)
48495 goto noconfig;
48496
48497@@ -205,8 +214,6 @@ do_register:
48498 if (err)
48499 goto nmi_con_failed;
48500
48501- configured = 1;
48502-
48503 return 0;
48504
48505 nmi_con_failed:
48506@@ -223,7 +230,7 @@ noconfig:
48507 static int __init init_kgdboc(void)
48508 {
48509 /* Already configured? */
48510- if (configured == 1)
48511+ if (configured >= 1)
48512 return 0;
48513
48514 return configure_kgdboc();
48515@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48516 if (config[len - 1] == '\n')
48517 config[len - 1] = '\0';
48518
48519- if (configured == 1)
48520+ if (configured >= 1)
48521 cleanup_kgdboc();
48522
48523 /* Go and configure with the new params. */
48524@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48525 .post_exception = kgdboc_post_exp_handler,
48526 };
48527
48528+static struct kgdb_io kgdboc_io_ops_console = {
48529+ .name = "kgdboc",
48530+ .read_char = kgdboc_get_char,
48531+ .write_char = kgdboc_put_char,
48532+ .pre_exception = kgdboc_pre_exp_handler,
48533+ .post_exception = kgdboc_post_exp_handler,
48534+ .is_console = 1
48535+};
48536+
48537 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48538 /* This is only available if kgdboc is a built in for early debugging */
48539 static int __init kgdboc_early_init(char *opt)
48540diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48541index b5d779c..3622cfe 100644
48542--- a/drivers/tty/serial/msm_serial.c
48543+++ b/drivers/tty/serial/msm_serial.c
48544@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
48545 .cons = MSM_CONSOLE,
48546 };
48547
48548-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48549+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48550
48551 static const struct of_device_id msm_uartdm_table[] = {
48552 { .compatible = "qcom,msm-uartdm" },
48553@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48554 int irq;
48555
48556 if (pdev->id == -1)
48557- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48558+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48559
48560 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48561 return -ENXIO;
48562diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48563index f3dfa19..342f2ff 100644
48564--- a/drivers/tty/serial/samsung.c
48565+++ b/drivers/tty/serial/samsung.c
48566@@ -456,11 +456,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48567 }
48568 }
48569
48570+static int s3c64xx_serial_startup(struct uart_port *port);
48571 static int s3c24xx_serial_startup(struct uart_port *port)
48572 {
48573 struct s3c24xx_uart_port *ourport = to_ourport(port);
48574 int ret;
48575
48576+ /* Startup sequence is different for s3c64xx and higher SoC's */
48577+ if (s3c24xx_serial_has_interrupt_mask(port))
48578+ return s3c64xx_serial_startup(port);
48579+
48580 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48581 port->mapbase, port->membase);
48582
48583@@ -1127,10 +1132,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48584 /* setup info for port */
48585 port->dev = &platdev->dev;
48586
48587- /* Startup sequence is different for s3c64xx and higher SoC's */
48588- if (s3c24xx_serial_has_interrupt_mask(port))
48589- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48590-
48591 port->uartclk = 1;
48592
48593 if (cfg->uart_flags & UPF_CONS_FLOW) {
48594diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48595index 0f02351..07c59c5 100644
48596--- a/drivers/tty/serial/serial_core.c
48597+++ b/drivers/tty/serial/serial_core.c
48598@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48599 uart_flush_buffer(tty);
48600 uart_shutdown(tty, state);
48601 spin_lock_irqsave(&port->lock, flags);
48602- port->count = 0;
48603+ atomic_set(&port->count, 0);
48604 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48605 spin_unlock_irqrestore(&port->lock, flags);
48606 tty_port_tty_set(port, NULL);
48607@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48608 goto end;
48609 }
48610
48611- port->count++;
48612+ atomic_inc(&port->count);
48613 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48614 retval = -ENXIO;
48615 goto err_dec_count;
48616@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48617 /*
48618 * Make sure the device is in D0 state.
48619 */
48620- if (port->count == 1)
48621+ if (atomic_read(&port->count) == 1)
48622 uart_change_pm(state, UART_PM_STATE_ON);
48623
48624 /*
48625@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48626 end:
48627 return retval;
48628 err_dec_count:
48629- port->count--;
48630+ atomic_inc(&port->count);
48631 mutex_unlock(&port->mutex);
48632 goto end;
48633 }
48634diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48635index e1ce141..6d4ed80 100644
48636--- a/drivers/tty/synclink.c
48637+++ b/drivers/tty/synclink.c
48638@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48639
48640 if (debug_level >= DEBUG_LEVEL_INFO)
48641 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48642- __FILE__,__LINE__, info->device_name, info->port.count);
48643+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48644
48645 if (tty_port_close_start(&info->port, tty, filp) == 0)
48646 goto cleanup;
48647@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48648 cleanup:
48649 if (debug_level >= DEBUG_LEVEL_INFO)
48650 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48651- tty->driver->name, info->port.count);
48652+ tty->driver->name, atomic_read(&info->port.count));
48653
48654 } /* end of mgsl_close() */
48655
48656@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48657
48658 mgsl_flush_buffer(tty);
48659 shutdown(info);
48660-
48661- info->port.count = 0;
48662+
48663+ atomic_set(&info->port.count, 0);
48664 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48665 info->port.tty = NULL;
48666
48667@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48668
48669 if (debug_level >= DEBUG_LEVEL_INFO)
48670 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48671- __FILE__,__LINE__, tty->driver->name, port->count );
48672+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48673
48674 spin_lock_irqsave(&info->irq_spinlock, flags);
48675 if (!tty_hung_up_p(filp)) {
48676 extra_count = true;
48677- port->count--;
48678+ atomic_dec(&port->count);
48679 }
48680 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48681 port->blocked_open++;
48682@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48683
48684 if (debug_level >= DEBUG_LEVEL_INFO)
48685 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48686- __FILE__,__LINE__, tty->driver->name, port->count );
48687+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48688
48689 tty_unlock(tty);
48690 schedule();
48691@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48692
48693 /* FIXME: Racy on hangup during close wait */
48694 if (extra_count)
48695- port->count++;
48696+ atomic_inc(&port->count);
48697 port->blocked_open--;
48698
48699 if (debug_level >= DEBUG_LEVEL_INFO)
48700 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48701- __FILE__,__LINE__, tty->driver->name, port->count );
48702+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48703
48704 if (!retval)
48705 port->flags |= ASYNC_NORMAL_ACTIVE;
48706@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48707
48708 if (debug_level >= DEBUG_LEVEL_INFO)
48709 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48710- __FILE__,__LINE__,tty->driver->name, info->port.count);
48711+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48712
48713 /* If port is closing, signal caller to try again */
48714 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48715@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48716 spin_unlock_irqrestore(&info->netlock, flags);
48717 goto cleanup;
48718 }
48719- info->port.count++;
48720+ atomic_inc(&info->port.count);
48721 spin_unlock_irqrestore(&info->netlock, flags);
48722
48723- if (info->port.count == 1) {
48724+ if (atomic_read(&info->port.count) == 1) {
48725 /* 1st open on this device, init hardware */
48726 retval = startup(info);
48727 if (retval < 0)
48728@@ -3446,8 +3446,8 @@ cleanup:
48729 if (retval) {
48730 if (tty->count == 1)
48731 info->port.tty = NULL; /* tty layer will release tty struct */
48732- if(info->port.count)
48733- info->port.count--;
48734+ if (atomic_read(&info->port.count))
48735+ atomic_dec(&info->port.count);
48736 }
48737
48738 return retval;
48739@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48740 unsigned short new_crctype;
48741
48742 /* return error if TTY interface open */
48743- if (info->port.count)
48744+ if (atomic_read(&info->port.count))
48745 return -EBUSY;
48746
48747 switch (encoding)
48748@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48749
48750 /* arbitrate between network and tty opens */
48751 spin_lock_irqsave(&info->netlock, flags);
48752- if (info->port.count != 0 || info->netcount != 0) {
48753+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48754 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48755 spin_unlock_irqrestore(&info->netlock, flags);
48756 return -EBUSY;
48757@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48758 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48759
48760 /* return error if TTY interface open */
48761- if (info->port.count)
48762+ if (atomic_read(&info->port.count))
48763 return -EBUSY;
48764
48765 if (cmd != SIOCWANDEV)
48766diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48767index 1abf946..1ee34fc 100644
48768--- a/drivers/tty/synclink_gt.c
48769+++ b/drivers/tty/synclink_gt.c
48770@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48771 tty->driver_data = info;
48772 info->port.tty = tty;
48773
48774- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48775+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48776
48777 /* If port is closing, signal caller to try again */
48778 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48779@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48780 mutex_unlock(&info->port.mutex);
48781 goto cleanup;
48782 }
48783- info->port.count++;
48784+ atomic_inc(&info->port.count);
48785 spin_unlock_irqrestore(&info->netlock, flags);
48786
48787- if (info->port.count == 1) {
48788+ if (atomic_read(&info->port.count) == 1) {
48789 /* 1st open on this device, init hardware */
48790 retval = startup(info);
48791 if (retval < 0) {
48792@@ -715,8 +715,8 @@ cleanup:
48793 if (retval) {
48794 if (tty->count == 1)
48795 info->port.tty = NULL; /* tty layer will release tty struct */
48796- if(info->port.count)
48797- info->port.count--;
48798+ if(atomic_read(&info->port.count))
48799+ atomic_dec(&info->port.count);
48800 }
48801
48802 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48803@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48804
48805 if (sanity_check(info, tty->name, "close"))
48806 return;
48807- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48808+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48809
48810 if (tty_port_close_start(&info->port, tty, filp) == 0)
48811 goto cleanup;
48812@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48813 tty_port_close_end(&info->port, tty);
48814 info->port.tty = NULL;
48815 cleanup:
48816- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48817+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48818 }
48819
48820 static void hangup(struct tty_struct *tty)
48821@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48822 shutdown(info);
48823
48824 spin_lock_irqsave(&info->port.lock, flags);
48825- info->port.count = 0;
48826+ atomic_set(&info->port.count, 0);
48827 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48828 info->port.tty = NULL;
48829 spin_unlock_irqrestore(&info->port.lock, flags);
48830@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48831 unsigned short new_crctype;
48832
48833 /* return error if TTY interface open */
48834- if (info->port.count)
48835+ if (atomic_read(&info->port.count))
48836 return -EBUSY;
48837
48838 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48839@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48840
48841 /* arbitrate between network and tty opens */
48842 spin_lock_irqsave(&info->netlock, flags);
48843- if (info->port.count != 0 || info->netcount != 0) {
48844+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48845 DBGINFO(("%s hdlc_open busy\n", dev->name));
48846 spin_unlock_irqrestore(&info->netlock, flags);
48847 return -EBUSY;
48848@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48849 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48850
48851 /* return error if TTY interface open */
48852- if (info->port.count)
48853+ if (atomic_read(&info->port.count))
48854 return -EBUSY;
48855
48856 if (cmd != SIOCWANDEV)
48857@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48858 if (port == NULL)
48859 continue;
48860 spin_lock(&port->lock);
48861- if ((port->port.count || port->netcount) &&
48862+ if ((atomic_read(&port->port.count) || port->netcount) &&
48863 port->pending_bh && !port->bh_running &&
48864 !port->bh_requested) {
48865 DBGISR(("%s bh queued\n", port->device_name));
48866@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48867 spin_lock_irqsave(&info->lock, flags);
48868 if (!tty_hung_up_p(filp)) {
48869 extra_count = true;
48870- port->count--;
48871+ atomic_dec(&port->count);
48872 }
48873 spin_unlock_irqrestore(&info->lock, flags);
48874 port->blocked_open++;
48875@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48876 remove_wait_queue(&port->open_wait, &wait);
48877
48878 if (extra_count)
48879- port->count++;
48880+ atomic_inc(&port->count);
48881 port->blocked_open--;
48882
48883 if (!retval)
48884diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48885index dc6e969..5dc8786 100644
48886--- a/drivers/tty/synclinkmp.c
48887+++ b/drivers/tty/synclinkmp.c
48888@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48889
48890 if (debug_level >= DEBUG_LEVEL_INFO)
48891 printk("%s(%d):%s open(), old ref count = %d\n",
48892- __FILE__,__LINE__,tty->driver->name, info->port.count);
48893+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48894
48895 /* If port is closing, signal caller to try again */
48896 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48897@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48898 spin_unlock_irqrestore(&info->netlock, flags);
48899 goto cleanup;
48900 }
48901- info->port.count++;
48902+ atomic_inc(&info->port.count);
48903 spin_unlock_irqrestore(&info->netlock, flags);
48904
48905- if (info->port.count == 1) {
48906+ if (atomic_read(&info->port.count) == 1) {
48907 /* 1st open on this device, init hardware */
48908 retval = startup(info);
48909 if (retval < 0)
48910@@ -796,8 +796,8 @@ cleanup:
48911 if (retval) {
48912 if (tty->count == 1)
48913 info->port.tty = NULL; /* tty layer will release tty struct */
48914- if(info->port.count)
48915- info->port.count--;
48916+ if(atomic_read(&info->port.count))
48917+ atomic_dec(&info->port.count);
48918 }
48919
48920 return retval;
48921@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48922
48923 if (debug_level >= DEBUG_LEVEL_INFO)
48924 printk("%s(%d):%s close() entry, count=%d\n",
48925- __FILE__,__LINE__, info->device_name, info->port.count);
48926+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48927
48928 if (tty_port_close_start(&info->port, tty, filp) == 0)
48929 goto cleanup;
48930@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48931 cleanup:
48932 if (debug_level >= DEBUG_LEVEL_INFO)
48933 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48934- tty->driver->name, info->port.count);
48935+ tty->driver->name, atomic_read(&info->port.count));
48936 }
48937
48938 /* Called by tty_hangup() when a hangup is signaled.
48939@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48940 shutdown(info);
48941
48942 spin_lock_irqsave(&info->port.lock, flags);
48943- info->port.count = 0;
48944+ atomic_set(&info->port.count, 0);
48945 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48946 info->port.tty = NULL;
48947 spin_unlock_irqrestore(&info->port.lock, flags);
48948@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48949 unsigned short new_crctype;
48950
48951 /* return error if TTY interface open */
48952- if (info->port.count)
48953+ if (atomic_read(&info->port.count))
48954 return -EBUSY;
48955
48956 switch (encoding)
48957@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48958
48959 /* arbitrate between network and tty opens */
48960 spin_lock_irqsave(&info->netlock, flags);
48961- if (info->port.count != 0 || info->netcount != 0) {
48962+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48963 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48964 spin_unlock_irqrestore(&info->netlock, flags);
48965 return -EBUSY;
48966@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48967 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48968
48969 /* return error if TTY interface open */
48970- if (info->port.count)
48971+ if (atomic_read(&info->port.count))
48972 return -EBUSY;
48973
48974 if (cmd != SIOCWANDEV)
48975@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48976 * do not request bottom half processing if the
48977 * device is not open in a normal mode.
48978 */
48979- if ( port && (port->port.count || port->netcount) &&
48980+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48981 port->pending_bh && !port->bh_running &&
48982 !port->bh_requested ) {
48983 if ( debug_level >= DEBUG_LEVEL_ISR )
48984@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48985
48986 if (debug_level >= DEBUG_LEVEL_INFO)
48987 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48988- __FILE__,__LINE__, tty->driver->name, port->count );
48989+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48990
48991 spin_lock_irqsave(&info->lock, flags);
48992 if (!tty_hung_up_p(filp)) {
48993 extra_count = true;
48994- port->count--;
48995+ atomic_dec(&port->count);
48996 }
48997 spin_unlock_irqrestore(&info->lock, flags);
48998 port->blocked_open++;
48999@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49000
49001 if (debug_level >= DEBUG_LEVEL_INFO)
49002 printk("%s(%d):%s block_til_ready() count=%d\n",
49003- __FILE__,__LINE__, tty->driver->name, port->count );
49004+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49005
49006 tty_unlock(tty);
49007 schedule();
49008@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49009 remove_wait_queue(&port->open_wait, &wait);
49010
49011 if (extra_count)
49012- port->count++;
49013+ atomic_inc(&port->count);
49014 port->blocked_open--;
49015
49016 if (debug_level >= DEBUG_LEVEL_INFO)
49017 printk("%s(%d):%s block_til_ready() after, count=%d\n",
49018- __FILE__,__LINE__, tty->driver->name, port->count );
49019+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49020
49021 if (!retval)
49022 port->flags |= ASYNC_NORMAL_ACTIVE;
49023diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
49024index 40a9fe9..a3f10cc 100644
49025--- a/drivers/tty/sysrq.c
49026+++ b/drivers/tty/sysrq.c
49027@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
49028 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
49029 size_t count, loff_t *ppos)
49030 {
49031- if (count) {
49032+ if (count && capable(CAP_SYS_ADMIN)) {
49033 char c;
49034
49035 if (get_user(c, buf))
49036diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
49037index c74a00a..02cf211a 100644
49038--- a/drivers/tty/tty_io.c
49039+++ b/drivers/tty/tty_io.c
49040@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
49041
49042 void tty_default_fops(struct file_operations *fops)
49043 {
49044- *fops = tty_fops;
49045+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
49046 }
49047
49048 /*
49049diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
49050index 6458e11..6cfc218 100644
49051--- a/drivers/tty/tty_ldisc.c
49052+++ b/drivers/tty/tty_ldisc.c
49053@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
49054 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
49055 tty_ldiscs[disc] = new_ldisc;
49056 new_ldisc->num = disc;
49057- new_ldisc->refcount = 0;
49058+ atomic_set(&new_ldisc->refcount, 0);
49059 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
49060
49061 return ret;
49062@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
49063 return -EINVAL;
49064
49065 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
49066- if (tty_ldiscs[disc]->refcount)
49067+ if (atomic_read(&tty_ldiscs[disc]->refcount))
49068 ret = -EBUSY;
49069 else
49070 tty_ldiscs[disc] = NULL;
49071@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
49072 if (ldops) {
49073 ret = ERR_PTR(-EAGAIN);
49074 if (try_module_get(ldops->owner)) {
49075- ldops->refcount++;
49076+ atomic_inc(&ldops->refcount);
49077 ret = ldops;
49078 }
49079 }
49080@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
49081 unsigned long flags;
49082
49083 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
49084- ldops->refcount--;
49085+ atomic_dec(&ldops->refcount);
49086 module_put(ldops->owner);
49087 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
49088 }
49089diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
49090index f597e88..b7f68ed 100644
49091--- a/drivers/tty/tty_port.c
49092+++ b/drivers/tty/tty_port.c
49093@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
49094 unsigned long flags;
49095
49096 spin_lock_irqsave(&port->lock, flags);
49097- port->count = 0;
49098+ atomic_set(&port->count, 0);
49099 port->flags &= ~ASYNC_NORMAL_ACTIVE;
49100 tty = port->tty;
49101 if (tty)
49102@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
49103 /* The port lock protects the port counts */
49104 spin_lock_irqsave(&port->lock, flags);
49105 if (!tty_hung_up_p(filp))
49106- port->count--;
49107+ atomic_dec(&port->count);
49108 port->blocked_open++;
49109 spin_unlock_irqrestore(&port->lock, flags);
49110
49111@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
49112 we must not mess that up further */
49113 spin_lock_irqsave(&port->lock, flags);
49114 if (!tty_hung_up_p(filp))
49115- port->count++;
49116+ atomic_inc(&port->count);
49117 port->blocked_open--;
49118 if (retval == 0)
49119 port->flags |= ASYNC_NORMAL_ACTIVE;
49120@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
49121 return 0;
49122 }
49123
49124- if (tty->count == 1 && port->count != 1) {
49125+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
49126 printk(KERN_WARNING
49127 "tty_port_close_start: tty->count = 1 port count = %d.\n",
49128- port->count);
49129- port->count = 1;
49130+ atomic_read(&port->count));
49131+ atomic_set(&port->count, 1);
49132 }
49133- if (--port->count < 0) {
49134+ if (atomic_dec_return(&port->count) < 0) {
49135 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
49136- port->count);
49137- port->count = 0;
49138+ atomic_read(&port->count));
49139+ atomic_set(&port->count, 0);
49140 }
49141
49142- if (port->count) {
49143+ if (atomic_read(&port->count)) {
49144 spin_unlock_irqrestore(&port->lock, flags);
49145 if (port->ops->drop)
49146 port->ops->drop(port);
49147@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
49148 {
49149 spin_lock_irq(&port->lock);
49150 if (!tty_hung_up_p(filp))
49151- ++port->count;
49152+ atomic_inc(&port->count);
49153 spin_unlock_irq(&port->lock);
49154 tty_port_tty_set(port, tty);
49155
49156diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
49157index d0e3a44..5f8b754 100644
49158--- a/drivers/tty/vt/keyboard.c
49159+++ b/drivers/tty/vt/keyboard.c
49160@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
49161 kbd->kbdmode == VC_OFF) &&
49162 value != KVAL(K_SAK))
49163 return; /* SAK is allowed even in raw mode */
49164+
49165+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49166+ {
49167+ void *func = fn_handler[value];
49168+ if (func == fn_show_state || func == fn_show_ptregs ||
49169+ func == fn_show_mem)
49170+ return;
49171+ }
49172+#endif
49173+
49174 fn_handler[value](vc);
49175 }
49176
49177@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49178 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
49179 return -EFAULT;
49180
49181- if (!capable(CAP_SYS_TTY_CONFIG))
49182- perm = 0;
49183-
49184 switch (cmd) {
49185 case KDGKBENT:
49186 /* Ensure another thread doesn't free it under us */
49187@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49188 spin_unlock_irqrestore(&kbd_event_lock, flags);
49189 return put_user(val, &user_kbe->kb_value);
49190 case KDSKBENT:
49191+ if (!capable(CAP_SYS_TTY_CONFIG))
49192+ perm = 0;
49193+
49194 if (!perm)
49195 return -EPERM;
49196 if (!i && v == K_NOSUCHMAP) {
49197@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49198 int i, j, k;
49199 int ret;
49200
49201- if (!capable(CAP_SYS_TTY_CONFIG))
49202- perm = 0;
49203-
49204 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
49205 if (!kbs) {
49206 ret = -ENOMEM;
49207@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49208 kfree(kbs);
49209 return ((p && *p) ? -EOVERFLOW : 0);
49210 case KDSKBSENT:
49211+ if (!capable(CAP_SYS_TTY_CONFIG))
49212+ perm = 0;
49213+
49214 if (!perm) {
49215 ret = -EPERM;
49216 goto reterr;
49217diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
49218index 0e808cf..d7d274b 100644
49219--- a/drivers/uio/uio.c
49220+++ b/drivers/uio/uio.c
49221@@ -25,6 +25,7 @@
49222 #include <linux/kobject.h>
49223 #include <linux/cdev.h>
49224 #include <linux/uio_driver.h>
49225+#include <asm/local.h>
49226
49227 #define UIO_MAX_DEVICES (1U << MINORBITS)
49228
49229@@ -32,7 +33,7 @@ struct uio_device {
49230 struct module *owner;
49231 struct device *dev;
49232 int minor;
49233- atomic_t event;
49234+ atomic_unchecked_t event;
49235 struct fasync_struct *async_queue;
49236 wait_queue_head_t wait;
49237 struct uio_info *info;
49238@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
49239 struct device_attribute *attr, char *buf)
49240 {
49241 struct uio_device *idev = dev_get_drvdata(dev);
49242- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
49243+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
49244 }
49245 static DEVICE_ATTR_RO(event);
49246
49247@@ -401,7 +402,7 @@ void uio_event_notify(struct uio_info *info)
49248 {
49249 struct uio_device *idev = info->uio_dev;
49250
49251- atomic_inc(&idev->event);
49252+ atomic_inc_unchecked(&idev->event);
49253 wake_up_interruptible(&idev->wait);
49254 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
49255 }
49256@@ -454,7 +455,7 @@ static int uio_open(struct inode *inode, struct file *filep)
49257 }
49258
49259 listener->dev = idev;
49260- listener->event_count = atomic_read(&idev->event);
49261+ listener->event_count = atomic_read_unchecked(&idev->event);
49262 filep->private_data = listener;
49263
49264 if (idev->info->open) {
49265@@ -505,7 +506,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49266 return -EIO;
49267
49268 poll_wait(filep, &idev->wait, wait);
49269- if (listener->event_count != atomic_read(&idev->event))
49270+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49271 return POLLIN | POLLRDNORM;
49272 return 0;
49273 }
49274@@ -530,7 +531,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49275 do {
49276 set_current_state(TASK_INTERRUPTIBLE);
49277
49278- event_count = atomic_read(&idev->event);
49279+ event_count = atomic_read_unchecked(&idev->event);
49280 if (event_count != listener->event_count) {
49281 if (copy_to_user(buf, &event_count, count))
49282 retval = -EFAULT;
49283@@ -587,9 +588,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
49284 static int uio_find_mem_index(struct vm_area_struct *vma)
49285 {
49286 struct uio_device *idev = vma->vm_private_data;
49287+ unsigned long size;
49288
49289 if (vma->vm_pgoff < MAX_UIO_MAPS) {
49290- if (idev->info->mem[vma->vm_pgoff].size == 0)
49291+ size = idev->info->mem[vma->vm_pgoff].size;
49292+ if (size == 0)
49293+ return -1;
49294+ if (vma->vm_end - vma->vm_start > size)
49295 return -1;
49296 return (int)vma->vm_pgoff;
49297 }
49298@@ -647,6 +652,8 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
49299 return -EINVAL;
49300 mem = idev->info->mem + mi;
49301
49302+ if (mem->addr & ~PAGE_MASK)
49303+ return -ENODEV;
49304 if (vma->vm_end - vma->vm_start > mem->size)
49305 return -EINVAL;
49306
49307@@ -818,7 +825,7 @@ int __uio_register_device(struct module *owner,
49308 idev->owner = owner;
49309 idev->info = info;
49310 init_waitqueue_head(&idev->wait);
49311- atomic_set(&idev->event, 0);
49312+ atomic_set_unchecked(&idev->event, 0);
49313
49314 ret = uio_get_minor(idev);
49315 if (ret)
49316diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49317index 8a7eb77..c00402f 100644
49318--- a/drivers/usb/atm/cxacru.c
49319+++ b/drivers/usb/atm/cxacru.c
49320@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49321 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49322 if (ret < 2)
49323 return -EINVAL;
49324- if (index < 0 || index > 0x7f)
49325+ if (index > 0x7f)
49326 return -EINVAL;
49327 pos += tmp;
49328
49329diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49330index 25a7bfc..57f3cf5 100644
49331--- a/drivers/usb/atm/usbatm.c
49332+++ b/drivers/usb/atm/usbatm.c
49333@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49334 if (printk_ratelimit())
49335 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49336 __func__, vpi, vci);
49337- atomic_inc(&vcc->stats->rx_err);
49338+ atomic_inc_unchecked(&vcc->stats->rx_err);
49339 return;
49340 }
49341
49342@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49343 if (length > ATM_MAX_AAL5_PDU) {
49344 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49345 __func__, length, vcc);
49346- atomic_inc(&vcc->stats->rx_err);
49347+ atomic_inc_unchecked(&vcc->stats->rx_err);
49348 goto out;
49349 }
49350
49351@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49352 if (sarb->len < pdu_length) {
49353 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49354 __func__, pdu_length, sarb->len, vcc);
49355- atomic_inc(&vcc->stats->rx_err);
49356+ atomic_inc_unchecked(&vcc->stats->rx_err);
49357 goto out;
49358 }
49359
49360 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49361 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49362 __func__, vcc);
49363- atomic_inc(&vcc->stats->rx_err);
49364+ atomic_inc_unchecked(&vcc->stats->rx_err);
49365 goto out;
49366 }
49367
49368@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49369 if (printk_ratelimit())
49370 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49371 __func__, length);
49372- atomic_inc(&vcc->stats->rx_drop);
49373+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49374 goto out;
49375 }
49376
49377@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49378
49379 vcc->push(vcc, skb);
49380
49381- atomic_inc(&vcc->stats->rx);
49382+ atomic_inc_unchecked(&vcc->stats->rx);
49383 out:
49384 skb_trim(sarb, 0);
49385 }
49386@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
49387 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49388
49389 usbatm_pop(vcc, skb);
49390- atomic_inc(&vcc->stats->tx);
49391+ atomic_inc_unchecked(&vcc->stats->tx);
49392
49393 skb = skb_dequeue(&instance->sndqueue);
49394 }
49395@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49396 if (!left--)
49397 return sprintf(page,
49398 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49399- atomic_read(&atm_dev->stats.aal5.tx),
49400- atomic_read(&atm_dev->stats.aal5.tx_err),
49401- atomic_read(&atm_dev->stats.aal5.rx),
49402- atomic_read(&atm_dev->stats.aal5.rx_err),
49403- atomic_read(&atm_dev->stats.aal5.rx_drop));
49404+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49405+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49406+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49407+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49408+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49409
49410 if (!left--) {
49411 if (instance->disconnected)
49412diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49413index 2a3bbdf..91d72cf 100644
49414--- a/drivers/usb/core/devices.c
49415+++ b/drivers/usb/core/devices.c
49416@@ -126,7 +126,7 @@ static const char format_endpt[] =
49417 * time it gets called.
49418 */
49419 static struct device_connect_event {
49420- atomic_t count;
49421+ atomic_unchecked_t count;
49422 wait_queue_head_t wait;
49423 } device_event = {
49424 .count = ATOMIC_INIT(1),
49425@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49426
49427 void usbfs_conn_disc_event(void)
49428 {
49429- atomic_add(2, &device_event.count);
49430+ atomic_add_unchecked(2, &device_event.count);
49431 wake_up(&device_event.wait);
49432 }
49433
49434@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49435
49436 poll_wait(file, &device_event.wait, wait);
49437
49438- event_count = atomic_read(&device_event.count);
49439+ event_count = atomic_read_unchecked(&device_event.count);
49440 if (file->f_version != event_count) {
49441 file->f_version = event_count;
49442 return POLLIN | POLLRDNORM;
49443diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
49444index 71dc5d7..300db0e 100644
49445--- a/drivers/usb/core/devio.c
49446+++ b/drivers/usb/core/devio.c
49447@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
49448 struct dev_state *ps = file->private_data;
49449 struct usb_device *dev = ps->dev;
49450 ssize_t ret = 0;
49451- unsigned len;
49452+ size_t len;
49453 loff_t pos;
49454 int i;
49455
49456@@ -229,16 +229,16 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
49457 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
49458 struct usb_config_descriptor *config =
49459 (struct usb_config_descriptor *)dev->rawdescriptors[i];
49460- unsigned int length = le16_to_cpu(config->wTotalLength);
49461+ size_t length = le16_to_cpu(config->wTotalLength);
49462
49463 if (*ppos < pos + length) {
49464
49465 /* The descriptor may claim to be longer than it
49466 * really is. Here is the actual allocated length. */
49467- unsigned alloclen =
49468+ size_t alloclen =
49469 le16_to_cpu(dev->config[i].desc.wTotalLength);
49470
49471- len = length - (*ppos - pos);
49472+ len = length + pos - *ppos;
49473 if (len > nbytes)
49474 len = nbytes;
49475
49476diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49477index f20a044..d1059aa 100644
49478--- a/drivers/usb/core/hcd.c
49479+++ b/drivers/usb/core/hcd.c
49480@@ -1552,7 +1552,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49481 */
49482 usb_get_urb(urb);
49483 atomic_inc(&urb->use_count);
49484- atomic_inc(&urb->dev->urbnum);
49485+ atomic_inc_unchecked(&urb->dev->urbnum);
49486 usbmon_urb_submit(&hcd->self, urb);
49487
49488 /* NOTE requirements on root-hub callers (usbfs and the hub
49489@@ -1579,7 +1579,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49490 urb->hcpriv = NULL;
49491 INIT_LIST_HEAD(&urb->urb_list);
49492 atomic_dec(&urb->use_count);
49493- atomic_dec(&urb->dev->urbnum);
49494+ atomic_dec_unchecked(&urb->dev->urbnum);
49495 if (atomic_read(&urb->reject))
49496 wake_up(&usb_kill_urb_queue);
49497 usb_put_urb(urb);
49498diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49499index c5c3667..e54e5cd 100644
49500--- a/drivers/usb/core/hub.c
49501+++ b/drivers/usb/core/hub.c
49502@@ -27,6 +27,7 @@
49503 #include <linux/freezer.h>
49504 #include <linux/random.h>
49505 #include <linux/pm_qos.h>
49506+#include <linux/grsecurity.h>
49507
49508 #include <asm/uaccess.h>
49509 #include <asm/byteorder.h>
49510@@ -4467,6 +4468,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49511 goto done;
49512 return;
49513 }
49514+
49515+ if (gr_handle_new_usb())
49516+ goto done;
49517+
49518 if (hub_is_superspeed(hub->hdev))
49519 unit_load = 150;
49520 else
49521diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49522index 82927e1..4993dbf 100644
49523--- a/drivers/usb/core/message.c
49524+++ b/drivers/usb/core/message.c
49525@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49526 * Return: If successful, the number of bytes transferred. Otherwise, a negative
49527 * error number.
49528 */
49529-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49530+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49531 __u8 requesttype, __u16 value, __u16 index, void *data,
49532 __u16 size, int timeout)
49533 {
49534@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
49535 * If successful, 0. Otherwise a negative error number. The number of actual
49536 * bytes transferred will be stored in the @actual_length paramater.
49537 */
49538-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
49539+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
49540 void *data, int len, int *actual_length, int timeout)
49541 {
49542 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
49543@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
49544 * bytes transferred will be stored in the @actual_length paramater.
49545 *
49546 */
49547-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
49548+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
49549 void *data, int len, int *actual_length, int timeout)
49550 {
49551 struct urb *urb;
49552diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49553index ca516ac..6c36ee4 100644
49554--- a/drivers/usb/core/sysfs.c
49555+++ b/drivers/usb/core/sysfs.c
49556@@ -236,7 +236,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
49557 struct usb_device *udev;
49558
49559 udev = to_usb_device(dev);
49560- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49561+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49562 }
49563 static DEVICE_ATTR_RO(urbnum);
49564
49565diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49566index 0a6ee2e..6f8d7e8 100644
49567--- a/drivers/usb/core/usb.c
49568+++ b/drivers/usb/core/usb.c
49569@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49570 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49571 dev->state = USB_STATE_ATTACHED;
49572 dev->lpm_disable_count = 1;
49573- atomic_set(&dev->urbnum, 0);
49574+ atomic_set_unchecked(&dev->urbnum, 0);
49575
49576 INIT_LIST_HEAD(&dev->ep0.urb_list);
49577 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49578diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49579index 02e44fc..3c4fe64 100644
49580--- a/drivers/usb/dwc3/gadget.c
49581+++ b/drivers/usb/dwc3/gadget.c
49582@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49583 if (!usb_endpoint_xfer_isoc(desc))
49584 return 0;
49585
49586- memset(&trb_link, 0, sizeof(trb_link));
49587-
49588 /* Link TRB for ISOC. The HWO bit is never reset */
49589 trb_st_hw = &dep->trb_pool[0];
49590
49591diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49592index 5e29dde..eca992f 100644
49593--- a/drivers/usb/early/ehci-dbgp.c
49594+++ b/drivers/usb/early/ehci-dbgp.c
49595@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49596
49597 #ifdef CONFIG_KGDB
49598 static struct kgdb_io kgdbdbgp_io_ops;
49599-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49600+static struct kgdb_io kgdbdbgp_io_ops_console;
49601+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49602 #else
49603 #define dbgp_kgdb_mode (0)
49604 #endif
49605@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49606 .write_char = kgdbdbgp_write_char,
49607 };
49608
49609+static struct kgdb_io kgdbdbgp_io_ops_console = {
49610+ .name = "kgdbdbgp",
49611+ .read_char = kgdbdbgp_read_char,
49612+ .write_char = kgdbdbgp_write_char,
49613+ .is_console = 1
49614+};
49615+
49616 static int kgdbdbgp_wait_time;
49617
49618 static int __init kgdbdbgp_parse_config(char *str)
49619@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49620 ptr++;
49621 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49622 }
49623- kgdb_register_io_module(&kgdbdbgp_io_ops);
49624- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49625+ if (early_dbgp_console.index != -1)
49626+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49627+ else
49628+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49629
49630 return 0;
49631 }
49632diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49633index b369292..9f3ba40 100644
49634--- a/drivers/usb/gadget/u_serial.c
49635+++ b/drivers/usb/gadget/u_serial.c
49636@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49637 spin_lock_irq(&port->port_lock);
49638
49639 /* already open? Great. */
49640- if (port->port.count) {
49641+ if (atomic_read(&port->port.count)) {
49642 status = 0;
49643- port->port.count++;
49644+ atomic_inc(&port->port.count);
49645
49646 /* currently opening/closing? wait ... */
49647 } else if (port->openclose) {
49648@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49649 tty->driver_data = port;
49650 port->port.tty = tty;
49651
49652- port->port.count = 1;
49653+ atomic_set(&port->port.count, 1);
49654 port->openclose = false;
49655
49656 /* if connected, start the I/O stream */
49657@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49658
49659 spin_lock_irq(&port->port_lock);
49660
49661- if (port->port.count != 1) {
49662- if (port->port.count == 0)
49663+ if (atomic_read(&port->port.count) != 1) {
49664+ if (atomic_read(&port->port.count) == 0)
49665 WARN_ON(1);
49666 else
49667- --port->port.count;
49668+ atomic_dec(&port->port.count);
49669 goto exit;
49670 }
49671
49672@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49673 * and sleep if necessary
49674 */
49675 port->openclose = true;
49676- port->port.count = 0;
49677+ atomic_set(&port->port.count, 0);
49678
49679 gser = port->port_usb;
49680 if (gser && gser->disconnect)
49681@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49682 int cond;
49683
49684 spin_lock_irq(&port->port_lock);
49685- cond = (port->port.count == 0) && !port->openclose;
49686+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49687 spin_unlock_irq(&port->port_lock);
49688 return cond;
49689 }
49690@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49691 /* if it's already open, start I/O ... and notify the serial
49692 * protocol about open/close status (connect/disconnect).
49693 */
49694- if (port->port.count) {
49695+ if (atomic_read(&port->port.count)) {
49696 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49697 gs_start_io(port);
49698 if (gser->connect)
49699@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49700
49701 port->port_usb = NULL;
49702 gser->ioport = NULL;
49703- if (port->port.count > 0 || port->openclose) {
49704+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49705 wake_up_interruptible(&port->drain_wait);
49706 if (port->port.tty)
49707 tty_hangup(port->port.tty);
49708@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49709
49710 /* finally, free any unused/unusable I/O buffers */
49711 spin_lock_irqsave(&port->port_lock, flags);
49712- if (port->port.count == 0 && !port->openclose)
49713+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49714 gs_buf_free(&port->port_write_buf);
49715 gs_free_requests(gser->out, &port->read_pool, NULL);
49716 gs_free_requests(gser->out, &port->read_queue, NULL);
49717diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
49718index 835fc08..f8b22bf 100644
49719--- a/drivers/usb/host/ehci-hub.c
49720+++ b/drivers/usb/host/ehci-hub.c
49721@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
49722 urb->transfer_flags = URB_DIR_IN;
49723 usb_get_urb(urb);
49724 atomic_inc(&urb->use_count);
49725- atomic_inc(&urb->dev->urbnum);
49726+ atomic_inc_unchecked(&urb->dev->urbnum);
49727 urb->setup_dma = dma_map_single(
49728 hcd->self.controller,
49729 urb->setup_packet,
49730@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
49731 urb->status = -EINPROGRESS;
49732 usb_get_urb(urb);
49733 atomic_inc(&urb->use_count);
49734- atomic_inc(&urb->dev->urbnum);
49735+ atomic_inc_unchecked(&urb->dev->urbnum);
49736 retval = submit_single_step_set_feature(hcd, urb, 0);
49737 if (!retval && !wait_for_completion_timeout(&done,
49738 msecs_to_jiffies(2000))) {
49739diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49740index ba6a5d6..f88f7f3 100644
49741--- a/drivers/usb/misc/appledisplay.c
49742+++ b/drivers/usb/misc/appledisplay.c
49743@@ -83,7 +83,7 @@ struct appledisplay {
49744 spinlock_t lock;
49745 };
49746
49747-static atomic_t count_displays = ATOMIC_INIT(0);
49748+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49749 static struct workqueue_struct *wq;
49750
49751 static void appledisplay_complete(struct urb *urb)
49752@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49753
49754 /* Register backlight device */
49755 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49756- atomic_inc_return(&count_displays) - 1);
49757+ atomic_inc_return_unchecked(&count_displays) - 1);
49758 memset(&props, 0, sizeof(struct backlight_properties));
49759 props.type = BACKLIGHT_RAW;
49760 props.max_brightness = 0xff;
49761diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49762index c69bb50..215ef37 100644
49763--- a/drivers/usb/serial/console.c
49764+++ b/drivers/usb/serial/console.c
49765@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49766
49767 info->port = port;
49768
49769- ++port->port.count;
49770+ atomic_inc(&port->port.count);
49771 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49772 if (serial->type->set_termios) {
49773 /*
49774@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
49775 }
49776 /* Now that any required fake tty operations are completed restore
49777 * the tty port count */
49778- --port->port.count;
49779+ atomic_dec(&port->port.count);
49780 /* The console is special in terms of closing the device so
49781 * indicate this port is now acting as a system console. */
49782 port->port.console = 1;
49783@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
49784 free_tty:
49785 kfree(tty);
49786 reset_open_count:
49787- port->port.count = 0;
49788+ atomic_set(&port->port.count, 0);
49789 usb_autopm_put_interface(serial->interface);
49790 error_get_interface:
49791 usb_serial_put(serial);
49792@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
49793 static void usb_console_write(struct console *co,
49794 const char *buf, unsigned count)
49795 {
49796- static struct usbcons_info *info = &usbcons_info;
49797+ struct usbcons_info *info = &usbcons_info;
49798 struct usb_serial_port *port = info->port;
49799 struct usb_serial *serial;
49800 int retval = -ENODEV;
49801diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49802index 75f70f0..d467e1a 100644
49803--- a/drivers/usb/storage/usb.h
49804+++ b/drivers/usb/storage/usb.h
49805@@ -63,7 +63,7 @@ struct us_unusual_dev {
49806 __u8 useProtocol;
49807 __u8 useTransport;
49808 int (*initFunction)(struct us_data *);
49809-};
49810+} __do_const;
49811
49812
49813 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49814diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49815index cf250c2..ad9d904 100644
49816--- a/drivers/usb/wusbcore/wa-hc.h
49817+++ b/drivers/usb/wusbcore/wa-hc.h
49818@@ -199,7 +199,7 @@ struct wahc {
49819 spinlock_t xfer_list_lock;
49820 struct work_struct xfer_enqueue_work;
49821 struct work_struct xfer_error_work;
49822- atomic_t xfer_id_count;
49823+ atomic_unchecked_t xfer_id_count;
49824 };
49825
49826
49827@@ -255,7 +255,7 @@ static inline void wa_init(struct wahc *wa)
49828 spin_lock_init(&wa->xfer_list_lock);
49829 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
49830 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
49831- atomic_set(&wa->xfer_id_count, 1);
49832+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49833 }
49834
49835 /**
49836diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49837index 3dcf66f..8faaf6e 100644
49838--- a/drivers/usb/wusbcore/wa-xfer.c
49839+++ b/drivers/usb/wusbcore/wa-xfer.c
49840@@ -300,7 +300,7 @@ out:
49841 */
49842 static void wa_xfer_id_init(struct wa_xfer *xfer)
49843 {
49844- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49845+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49846 }
49847
49848 /*
49849diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49850index 1eab4ac..e21efc9 100644
49851--- a/drivers/vfio/vfio.c
49852+++ b/drivers/vfio/vfio.c
49853@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49854 return 0;
49855
49856 /* TODO Prevent device auto probing */
49857- WARN("Device %s added to live group %d!\n", dev_name(dev),
49858+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49859 iommu_group_id(group->iommu_group));
49860
49861 return 0;
49862diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49863index 5174eba..86e764a 100644
49864--- a/drivers/vhost/vringh.c
49865+++ b/drivers/vhost/vringh.c
49866@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49867
49868 static inline int putu16_kern(u16 *p, u16 val)
49869 {
49870- ACCESS_ONCE(*p) = val;
49871+ ACCESS_ONCE_RW(*p) = val;
49872 return 0;
49873 }
49874
49875diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
49876index e43401a..dd49b3f 100644
49877--- a/drivers/video/arcfb.c
49878+++ b/drivers/video/arcfb.c
49879@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
49880 return -ENOSPC;
49881
49882 err = 0;
49883- if ((count + p) > fbmemlength) {
49884+ if (count > (fbmemlength - p)) {
49885 count = fbmemlength - p;
49886 err = -ENOSPC;
49887 }
49888diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49889index a4dfe8c..297ddd9 100644
49890--- a/drivers/video/aty/aty128fb.c
49891+++ b/drivers/video/aty/aty128fb.c
49892@@ -149,7 +149,7 @@ enum {
49893 };
49894
49895 /* Must match above enum */
49896-static char * const r128_family[] = {
49897+static const char * const r128_family[] = {
49898 "AGP",
49899 "PCI",
49900 "PRO AGP",
49901diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49902index 9b0f12c..024673d 100644
49903--- a/drivers/video/aty/atyfb_base.c
49904+++ b/drivers/video/aty/atyfb_base.c
49905@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49906 par->accel_flags = var->accel_flags; /* hack */
49907
49908 if (var->accel_flags) {
49909- info->fbops->fb_sync = atyfb_sync;
49910+ pax_open_kernel();
49911+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49912+ pax_close_kernel();
49913 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49914 } else {
49915- info->fbops->fb_sync = NULL;
49916+ pax_open_kernel();
49917+ *(void **)&info->fbops->fb_sync = NULL;
49918+ pax_close_kernel();
49919 info->flags |= FBINFO_HWACCEL_DISABLED;
49920 }
49921
49922diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49923index 95ec042..e6affdd 100644
49924--- a/drivers/video/aty/mach64_cursor.c
49925+++ b/drivers/video/aty/mach64_cursor.c
49926@@ -7,6 +7,7 @@
49927 #include <linux/string.h>
49928
49929 #include <asm/io.h>
49930+#include <asm/pgtable.h>
49931
49932 #ifdef __sparc__
49933 #include <asm/fbio.h>
49934@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49935 info->sprite.buf_align = 16; /* and 64 lines tall. */
49936 info->sprite.flags = FB_PIXMAP_IO;
49937
49938- info->fbops->fb_cursor = atyfb_cursor;
49939+ pax_open_kernel();
49940+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49941+ pax_close_kernel();
49942
49943 return 0;
49944 }
49945diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49946index bca6ccc..252107e 100644
49947--- a/drivers/video/backlight/kb3886_bl.c
49948+++ b/drivers/video/backlight/kb3886_bl.c
49949@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49950 static unsigned long kb3886bl_flags;
49951 #define KB3886BL_SUSPENDED 0x01
49952
49953-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49954+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49955 {
49956 .ident = "Sahara Touch-iT",
49957 .matches = {
49958diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49959index 900aa4e..6d49418 100644
49960--- a/drivers/video/fb_defio.c
49961+++ b/drivers/video/fb_defio.c
49962@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49963
49964 BUG_ON(!fbdefio);
49965 mutex_init(&fbdefio->lock);
49966- info->fbops->fb_mmap = fb_deferred_io_mmap;
49967+ pax_open_kernel();
49968+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49969+ pax_close_kernel();
49970 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49971 INIT_LIST_HEAD(&fbdefio->pagelist);
49972 if (fbdefio->delay == 0) /* set a default of 1 s */
49973@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49974 page->mapping = NULL;
49975 }
49976
49977- info->fbops->fb_mmap = NULL;
49978+ *(void **)&info->fbops->fb_mmap = NULL;
49979 mutex_destroy(&fbdefio->lock);
49980 }
49981 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49982diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49983index dacaf74..8478a46 100644
49984--- a/drivers/video/fbmem.c
49985+++ b/drivers/video/fbmem.c
49986@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49987 image->dx += image->width + 8;
49988 }
49989 } else if (rotate == FB_ROTATE_UD) {
49990- for (x = 0; x < num && image->dx >= 0; x++) {
49991+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49992 info->fbops->fb_imageblit(info, image);
49993 image->dx -= image->width + 8;
49994 }
49995@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49996 image->dy += image->height + 8;
49997 }
49998 } else if (rotate == FB_ROTATE_CCW) {
49999- for (x = 0; x < num && image->dy >= 0; x++) {
50000+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
50001 info->fbops->fb_imageblit(info, image);
50002 image->dy -= image->height + 8;
50003 }
50004@@ -1175,7 +1175,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
50005 return -EFAULT;
50006 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
50007 return -EINVAL;
50008- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
50009+ if (con2fb.framebuffer >= FB_MAX)
50010 return -EINVAL;
50011 if (!registered_fb[con2fb.framebuffer])
50012 request_module("fb%d", con2fb.framebuffer);
50013diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
50014index 8d456dc..b4fa44b 100644
50015--- a/drivers/video/hyperv_fb.c
50016+++ b/drivers/video/hyperv_fb.c
50017@@ -233,7 +233,7 @@ static uint screen_fb_size;
50018 static inline int synthvid_send(struct hv_device *hdev,
50019 struct synthvid_msg *msg)
50020 {
50021- static atomic64_t request_id = ATOMIC64_INIT(0);
50022+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
50023 int ret;
50024
50025 msg->pipe_hdr.type = PIPE_MSG_DATA;
50026@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
50027
50028 ret = vmbus_sendpacket(hdev->channel, msg,
50029 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
50030- atomic64_inc_return(&request_id),
50031+ atomic64_inc_return_unchecked(&request_id),
50032 VM_PKT_DATA_INBAND, 0);
50033
50034 if (ret)
50035diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
50036index 7672d2e..b56437f 100644
50037--- a/drivers/video/i810/i810_accel.c
50038+++ b/drivers/video/i810/i810_accel.c
50039@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
50040 }
50041 }
50042 printk("ringbuffer lockup!!!\n");
50043+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
50044 i810_report_error(mmio);
50045 par->dev_flags |= LOCKUP;
50046 info->pixmap.scan_align = 1;
50047diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
50048index 3c14e43..2630570 100644
50049--- a/drivers/video/logo/logo_linux_clut224.ppm
50050+++ b/drivers/video/logo/logo_linux_clut224.ppm
50051@@ -2,1603 +2,1123 @@ P3
50052 # Standard 224-color Linux logo
50053 80 80
50054 255
50055- 0 0 0 0 0 0 0 0 0 0 0 0
50056- 0 0 0 0 0 0 0 0 0 0 0 0
50057- 0 0 0 0 0 0 0 0 0 0 0 0
50058- 0 0 0 0 0 0 0 0 0 0 0 0
50059- 0 0 0 0 0 0 0 0 0 0 0 0
50060- 0 0 0 0 0 0 0 0 0 0 0 0
50061- 0 0 0 0 0 0 0 0 0 0 0 0
50062- 0 0 0 0 0 0 0 0 0 0 0 0
50063- 0 0 0 0 0 0 0 0 0 0 0 0
50064- 6 6 6 6 6 6 10 10 10 10 10 10
50065- 10 10 10 6 6 6 6 6 6 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
50075- 0 0 0 0 0 0 0 0 0 0 0 0
50076- 0 0 0 0 0 0 0 0 0 0 0 0
50077- 0 0 0 0 0 0 0 0 0 0 0 0
50078- 0 0 0 0 0 0 0 0 0 0 0 0
50079- 0 0 0 0 0 0 0 0 0 0 0 0
50080- 0 0 0 0 0 0 0 0 0 0 0 0
50081- 0 0 0 0 0 0 0 0 0 0 0 0
50082- 0 0 0 0 0 0 0 0 0 0 0 0
50083- 0 0 0 6 6 6 10 10 10 14 14 14
50084- 22 22 22 26 26 26 30 30 30 34 34 34
50085- 30 30 30 30 30 30 26 26 26 18 18 18
50086- 14 14 14 10 10 10 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50095- 0 0 0 0 0 0 0 0 0 0 0 0
50096- 0 0 0 0 0 1 0 0 1 0 0 0
50097- 0 0 0 0 0 0 0 0 0 0 0 0
50098- 0 0 0 0 0 0 0 0 0 0 0 0
50099- 0 0 0 0 0 0 0 0 0 0 0 0
50100- 0 0 0 0 0 0 0 0 0 0 0 0
50101- 0 0 0 0 0 0 0 0 0 0 0 0
50102- 0 0 0 0 0 0 0 0 0 0 0 0
50103- 6 6 6 14 14 14 26 26 26 42 42 42
50104- 54 54 54 66 66 66 78 78 78 78 78 78
50105- 78 78 78 74 74 74 66 66 66 54 54 54
50106- 42 42 42 26 26 26 18 18 18 10 10 10
50107- 6 6 6 0 0 0 0 0 0 0 0 0
50108- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
50114- 0 0 0 0 0 0 0 0 0 0 0 0
50115- 0 0 0 0 0 0 0 0 0 0 0 0
50116- 0 0 1 0 0 0 0 0 0 0 0 0
50117- 0 0 0 0 0 0 0 0 0 0 0 0
50118- 0 0 0 0 0 0 0 0 0 0 0 0
50119- 0 0 0 0 0 0 0 0 0 0 0 0
50120- 0 0 0 0 0 0 0 0 0 0 0 0
50121- 0 0 0 0 0 0 0 0 0 0 0 0
50122- 0 0 0 0 0 0 0 0 0 10 10 10
50123- 22 22 22 42 42 42 66 66 66 86 86 86
50124- 66 66 66 38 38 38 38 38 38 22 22 22
50125- 26 26 26 34 34 34 54 54 54 66 66 66
50126- 86 86 86 70 70 70 46 46 46 26 26 26
50127- 14 14 14 6 6 6 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 0 0 0
50134- 0 0 0 0 0 0 0 0 0 0 0 0
50135- 0 0 0 0 0 0 0 0 0 0 0 0
50136- 0 0 1 0 0 1 0 0 1 0 0 0
50137- 0 0 0 0 0 0 0 0 0 0 0 0
50138- 0 0 0 0 0 0 0 0 0 0 0 0
50139- 0 0 0 0 0 0 0 0 0 0 0 0
50140- 0 0 0 0 0 0 0 0 0 0 0 0
50141- 0 0 0 0 0 0 0 0 0 0 0 0
50142- 0 0 0 0 0 0 10 10 10 26 26 26
50143- 50 50 50 82 82 82 58 58 58 6 6 6
50144- 2 2 6 2 2 6 2 2 6 2 2 6
50145- 2 2 6 2 2 6 2 2 6 2 2 6
50146- 6 6 6 54 54 54 86 86 86 66 66 66
50147- 38 38 38 18 18 18 6 6 6 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 0 0 0
50154- 0 0 0 0 0 0 0 0 0 0 0 0
50155- 0 0 0 0 0 0 0 0 0 0 0 0
50156- 0 0 0 0 0 0 0 0 0 0 0 0
50157- 0 0 0 0 0 0 0 0 0 0 0 0
50158- 0 0 0 0 0 0 0 0 0 0 0 0
50159- 0 0 0 0 0 0 0 0 0 0 0 0
50160- 0 0 0 0 0 0 0 0 0 0 0 0
50161- 0 0 0 0 0 0 0 0 0 0 0 0
50162- 0 0 0 6 6 6 22 22 22 50 50 50
50163- 78 78 78 34 34 34 2 2 6 2 2 6
50164- 2 2 6 2 2 6 2 2 6 2 2 6
50165- 2 2 6 2 2 6 2 2 6 2 2 6
50166- 2 2 6 2 2 6 6 6 6 70 70 70
50167- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0
50174- 0 0 0 0 0 0 0 0 0 0 0 0
50175- 0 0 0 0 0 0 0 0 0 0 0 0
50176- 0 0 1 0 0 1 0 0 1 0 0 0
50177- 0 0 0 0 0 0 0 0 0 0 0 0
50178- 0 0 0 0 0 0 0 0 0 0 0 0
50179- 0 0 0 0 0 0 0 0 0 0 0 0
50180- 0 0 0 0 0 0 0 0 0 0 0 0
50181- 0 0 0 0 0 0 0 0 0 0 0 0
50182- 6 6 6 18 18 18 42 42 42 82 82 82
50183- 26 26 26 2 2 6 2 2 6 2 2 6
50184- 2 2 6 2 2 6 2 2 6 2 2 6
50185- 2 2 6 2 2 6 2 2 6 14 14 14
50186- 46 46 46 34 34 34 6 6 6 2 2 6
50187- 42 42 42 78 78 78 42 42 42 18 18 18
50188- 6 6 6 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 0 0 0 0 0 0
50194- 0 0 0 0 0 0 0 0 0 0 0 0
50195- 0 0 0 0 0 0 0 0 0 0 0 0
50196- 0 0 1 0 0 0 0 0 1 0 0 0
50197- 0 0 0 0 0 0 0 0 0 0 0 0
50198- 0 0 0 0 0 0 0 0 0 0 0 0
50199- 0 0 0 0 0 0 0 0 0 0 0 0
50200- 0 0 0 0 0 0 0 0 0 0 0 0
50201- 0 0 0 0 0 0 0 0 0 0 0 0
50202- 10 10 10 30 30 30 66 66 66 58 58 58
50203- 2 2 6 2 2 6 2 2 6 2 2 6
50204- 2 2 6 2 2 6 2 2 6 2 2 6
50205- 2 2 6 2 2 6 2 2 6 26 26 26
50206- 86 86 86 101 101 101 46 46 46 10 10 10
50207- 2 2 6 58 58 58 70 70 70 34 34 34
50208- 10 10 10 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 0 0 0 0 0 0 0 0 0
50214- 0 0 0 0 0 0 0 0 0 0 0 0
50215- 0 0 0 0 0 0 0 0 0 0 0 0
50216- 0 0 1 0 0 1 0 0 1 0 0 0
50217- 0 0 0 0 0 0 0 0 0 0 0 0
50218- 0 0 0 0 0 0 0 0 0 0 0 0
50219- 0 0 0 0 0 0 0 0 0 0 0 0
50220- 0 0 0 0 0 0 0 0 0 0 0 0
50221- 0 0 0 0 0 0 0 0 0 0 0 0
50222- 14 14 14 42 42 42 86 86 86 10 10 10
50223- 2 2 6 2 2 6 2 2 6 2 2 6
50224- 2 2 6 2 2 6 2 2 6 2 2 6
50225- 2 2 6 2 2 6 2 2 6 30 30 30
50226- 94 94 94 94 94 94 58 58 58 26 26 26
50227- 2 2 6 6 6 6 78 78 78 54 54 54
50228- 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0
50234- 0 0 0 0 0 0 0 0 0 0 0 0
50235- 0 0 0 0 0 0 0 0 0 0 0 0
50236- 0 0 0 0 0 0 0 0 0 0 0 0
50237- 0 0 0 0 0 0 0 0 0 0 0 0
50238- 0 0 0 0 0 0 0 0 0 0 0 0
50239- 0 0 0 0 0 0 0 0 0 0 0 0
50240- 0 0 0 0 0 0 0 0 0 0 0 0
50241- 0 0 0 0 0 0 0 0 0 6 6 6
50242- 22 22 22 62 62 62 62 62 62 2 2 6
50243- 2 2 6 2 2 6 2 2 6 2 2 6
50244- 2 2 6 2 2 6 2 2 6 2 2 6
50245- 2 2 6 2 2 6 2 2 6 26 26 26
50246- 54 54 54 38 38 38 18 18 18 10 10 10
50247- 2 2 6 2 2 6 34 34 34 82 82 82
50248- 38 38 38 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
50254- 0 0 0 0 0 0 0 0 0 0 0 0
50255- 0 0 0 0 0 0 0 0 0 0 0 0
50256- 0 0 0 0 0 1 0 0 1 0 0 0
50257- 0 0 0 0 0 0 0 0 0 0 0 0
50258- 0 0 0 0 0 0 0 0 0 0 0 0
50259- 0 0 0 0 0 0 0 0 0 0 0 0
50260- 0 0 0 0 0 0 0 0 0 0 0 0
50261- 0 0 0 0 0 0 0 0 0 6 6 6
50262- 30 30 30 78 78 78 30 30 30 2 2 6
50263- 2 2 6 2 2 6 2 2 6 2 2 6
50264- 2 2 6 2 2 6 2 2 6 2 2 6
50265- 2 2 6 2 2 6 2 2 6 10 10 10
50266- 10 10 10 2 2 6 2 2 6 2 2 6
50267- 2 2 6 2 2 6 2 2 6 78 78 78
50268- 50 50 50 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50274- 0 0 0 0 0 0 0 0 0 0 0 0
50275- 0 0 0 0 0 0 0 0 0 0 0 0
50276- 0 0 1 0 0 0 0 0 0 0 0 0
50277- 0 0 0 0 0 0 0 0 0 0 0 0
50278- 0 0 0 0 0 0 0 0 0 0 0 0
50279- 0 0 0 0 0 0 0 0 0 0 0 0
50280- 0 0 0 0 0 0 0 0 0 0 0 0
50281- 0 0 0 0 0 0 0 0 0 10 10 10
50282- 38 38 38 86 86 86 14 14 14 2 2 6
50283- 2 2 6 2 2 6 2 2 6 2 2 6
50284- 2 2 6 2 2 6 2 2 6 2 2 6
50285- 2 2 6 2 2 6 2 2 6 2 2 6
50286- 2 2 6 2 2 6 2 2 6 2 2 6
50287- 2 2 6 2 2 6 2 2 6 54 54 54
50288- 66 66 66 26 26 26 6 6 6 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 0 0 0
50293- 0 0 0 0 0 0 0 0 0 0 0 0
50294- 0 0 0 0 0 0 0 0 0 0 0 0
50295- 0 0 0 0 0 0 0 0 0 0 0 0
50296- 0 0 0 0 0 1 0 0 1 0 0 0
50297- 0 0 0 0 0 0 0 0 0 0 0 0
50298- 0 0 0 0 0 0 0 0 0 0 0 0
50299- 0 0 0 0 0 0 0 0 0 0 0 0
50300- 0 0 0 0 0 0 0 0 0 0 0 0
50301- 0 0 0 0 0 0 0 0 0 14 14 14
50302- 42 42 42 82 82 82 2 2 6 2 2 6
50303- 2 2 6 6 6 6 10 10 10 2 2 6
50304- 2 2 6 2 2 6 2 2 6 2 2 6
50305- 2 2 6 2 2 6 2 2 6 6 6 6
50306- 14 14 14 10 10 10 2 2 6 2 2 6
50307- 2 2 6 2 2 6 2 2 6 18 18 18
50308- 82 82 82 34 34 34 10 10 10 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 0 0 0
50313- 0 0 0 0 0 0 0 0 0 0 0 0
50314- 0 0 0 0 0 0 0 0 0 0 0 0
50315- 0 0 0 0 0 0 0 0 0 0 0 0
50316- 0 0 1 0 0 0 0 0 0 0 0 0
50317- 0 0 0 0 0 0 0 0 0 0 0 0
50318- 0 0 0 0 0 0 0 0 0 0 0 0
50319- 0 0 0 0 0 0 0 0 0 0 0 0
50320- 0 0 0 0 0 0 0 0 0 0 0 0
50321- 0 0 0 0 0 0 0 0 0 14 14 14
50322- 46 46 46 86 86 86 2 2 6 2 2 6
50323- 6 6 6 6 6 6 22 22 22 34 34 34
50324- 6 6 6 2 2 6 2 2 6 2 2 6
50325- 2 2 6 2 2 6 18 18 18 34 34 34
50326- 10 10 10 50 50 50 22 22 22 2 2 6
50327- 2 2 6 2 2 6 2 2 6 10 10 10
50328- 86 86 86 42 42 42 14 14 14 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 0 0 0
50333- 0 0 0 0 0 0 0 0 0 0 0 0
50334- 0 0 0 0 0 0 0 0 0 0 0 0
50335- 0 0 0 0 0 0 0 0 0 0 0 0
50336- 0 0 1 0 0 1 0 0 1 0 0 0
50337- 0 0 0 0 0 0 0 0 0 0 0 0
50338- 0 0 0 0 0 0 0 0 0 0 0 0
50339- 0 0 0 0 0 0 0 0 0 0 0 0
50340- 0 0 0 0 0 0 0 0 0 0 0 0
50341- 0 0 0 0 0 0 0 0 0 14 14 14
50342- 46 46 46 86 86 86 2 2 6 2 2 6
50343- 38 38 38 116 116 116 94 94 94 22 22 22
50344- 22 22 22 2 2 6 2 2 6 2 2 6
50345- 14 14 14 86 86 86 138 138 138 162 162 162
50346-154 154 154 38 38 38 26 26 26 6 6 6
50347- 2 2 6 2 2 6 2 2 6 2 2 6
50348- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
50353- 0 0 0 0 0 0 0 0 0 0 0 0
50354- 0 0 0 0 0 0 0 0 0 0 0 0
50355- 0 0 0 0 0 0 0 0 0 0 0 0
50356- 0 0 0 0 0 0 0 0 0 0 0 0
50357- 0 0 0 0 0 0 0 0 0 0 0 0
50358- 0 0 0 0 0 0 0 0 0 0 0 0
50359- 0 0 0 0 0 0 0 0 0 0 0 0
50360- 0 0 0 0 0 0 0 0 0 0 0 0
50361- 0 0 0 0 0 0 0 0 0 14 14 14
50362- 46 46 46 86 86 86 2 2 6 14 14 14
50363-134 134 134 198 198 198 195 195 195 116 116 116
50364- 10 10 10 2 2 6 2 2 6 6 6 6
50365-101 98 89 187 187 187 210 210 210 218 218 218
50366-214 214 214 134 134 134 14 14 14 6 6 6
50367- 2 2 6 2 2 6 2 2 6 2 2 6
50368- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0
50373- 0 0 0 0 0 0 0 0 0 0 0 0
50374- 0 0 0 0 0 0 0 0 0 0 0 0
50375- 0 0 0 0 0 0 0 0 1 0 0 0
50376- 0 0 1 0 0 1 0 0 1 0 0 0
50377- 0 0 0 0 0 0 0 0 0 0 0 0
50378- 0 0 0 0 0 0 0 0 0 0 0 0
50379- 0 0 0 0 0 0 0 0 0 0 0 0
50380- 0 0 0 0 0 0 0 0 0 0 0 0
50381- 0 0 0 0 0 0 0 0 0 14 14 14
50382- 46 46 46 86 86 86 2 2 6 54 54 54
50383-218 218 218 195 195 195 226 226 226 246 246 246
50384- 58 58 58 2 2 6 2 2 6 30 30 30
50385-210 210 210 253 253 253 174 174 174 123 123 123
50386-221 221 221 234 234 234 74 74 74 2 2 6
50387- 2 2 6 2 2 6 2 2 6 2 2 6
50388- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
50393- 0 0 0 0 0 0 0 0 0 0 0 0
50394- 0 0 0 0 0 0 0 0 0 0 0 0
50395- 0 0 0 0 0 0 0 0 0 0 0 0
50396- 0 0 0 0 0 0 0 0 0 0 0 0
50397- 0 0 0 0 0 0 0 0 0 0 0 0
50398- 0 0 0 0 0 0 0 0 0 0 0 0
50399- 0 0 0 0 0 0 0 0 0 0 0 0
50400- 0 0 0 0 0 0 0 0 0 0 0 0
50401- 0 0 0 0 0 0 0 0 0 14 14 14
50402- 46 46 46 82 82 82 2 2 6 106 106 106
50403-170 170 170 26 26 26 86 86 86 226 226 226
50404-123 123 123 10 10 10 14 14 14 46 46 46
50405-231 231 231 190 190 190 6 6 6 70 70 70
50406- 90 90 90 238 238 238 158 158 158 2 2 6
50407- 2 2 6 2 2 6 2 2 6 2 2 6
50408- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
50413- 0 0 0 0 0 0 0 0 0 0 0 0
50414- 0 0 0 0 0 0 0 0 0 0 0 0
50415- 0 0 0 0 0 0 0 0 1 0 0 0
50416- 0 0 1 0 0 1 0 0 1 0 0 0
50417- 0 0 0 0 0 0 0 0 0 0 0 0
50418- 0 0 0 0 0 0 0 0 0 0 0 0
50419- 0 0 0 0 0 0 0 0 0 0 0 0
50420- 0 0 0 0 0 0 0 0 0 0 0 0
50421- 0 0 0 0 0 0 0 0 0 14 14 14
50422- 42 42 42 86 86 86 6 6 6 116 116 116
50423-106 106 106 6 6 6 70 70 70 149 149 149
50424-128 128 128 18 18 18 38 38 38 54 54 54
50425-221 221 221 106 106 106 2 2 6 14 14 14
50426- 46 46 46 190 190 190 198 198 198 2 2 6
50427- 2 2 6 2 2 6 2 2 6 2 2 6
50428- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
50432- 0 0 0 0 0 0 0 0 0 0 0 0
50433- 0 0 0 0 0 0 0 0 0 0 0 0
50434- 0 0 0 0 0 0 0 0 0 0 0 0
50435- 0 0 0 0 0 0 0 0 1 0 0 0
50436- 0 0 1 0 0 0 0 0 1 0 0 0
50437- 0 0 0 0 0 0 0 0 0 0 0 0
50438- 0 0 0 0 0 0 0 0 0 0 0 0
50439- 0 0 0 0 0 0 0 0 0 0 0 0
50440- 0 0 0 0 0 0 0 0 0 0 0 0
50441- 0 0 0 0 0 0 0 0 0 14 14 14
50442- 42 42 42 94 94 94 14 14 14 101 101 101
50443-128 128 128 2 2 6 18 18 18 116 116 116
50444-118 98 46 121 92 8 121 92 8 98 78 10
50445-162 162 162 106 106 106 2 2 6 2 2 6
50446- 2 2 6 195 195 195 195 195 195 6 6 6
50447- 2 2 6 2 2 6 2 2 6 2 2 6
50448- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
50452- 0 0 0 0 0 0 0 0 0 0 0 0
50453- 0 0 0 0 0 0 0 0 0 0 0 0
50454- 0 0 0 0 0 0 0 0 0 0 0 0
50455- 0 0 0 0 0 0 0 0 1 0 0 1
50456- 0 0 1 0 0 0 0 0 1 0 0 0
50457- 0 0 0 0 0 0 0 0 0 0 0 0
50458- 0 0 0 0 0 0 0 0 0 0 0 0
50459- 0 0 0 0 0 0 0 0 0 0 0 0
50460- 0 0 0 0 0 0 0 0 0 0 0 0
50461- 0 0 0 0 0 0 0 0 0 10 10 10
50462- 38 38 38 90 90 90 14 14 14 58 58 58
50463-210 210 210 26 26 26 54 38 6 154 114 10
50464-226 170 11 236 186 11 225 175 15 184 144 12
50465-215 174 15 175 146 61 37 26 9 2 2 6
50466- 70 70 70 246 246 246 138 138 138 2 2 6
50467- 2 2 6 2 2 6 2 2 6 2 2 6
50468- 70 70 70 66 66 66 26 26 26 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
50472- 0 0 0 0 0 0 0 0 0 0 0 0
50473- 0 0 0 0 0 0 0 0 0 0 0 0
50474- 0 0 0 0 0 0 0 0 0 0 0 0
50475- 0 0 0 0 0 0 0 0 0 0 0 0
50476- 0 0 0 0 0 0 0 0 0 0 0 0
50477- 0 0 0 0 0 0 0 0 0 0 0 0
50478- 0 0 0 0 0 0 0 0 0 0 0 0
50479- 0 0 0 0 0 0 0 0 0 0 0 0
50480- 0 0 0 0 0 0 0 0 0 0 0 0
50481- 0 0 0 0 0 0 0 0 0 10 10 10
50482- 38 38 38 86 86 86 14 14 14 10 10 10
50483-195 195 195 188 164 115 192 133 9 225 175 15
50484-239 182 13 234 190 10 232 195 16 232 200 30
50485-245 207 45 241 208 19 232 195 16 184 144 12
50486-218 194 134 211 206 186 42 42 42 2 2 6
50487- 2 2 6 2 2 6 2 2 6 2 2 6
50488- 50 50 50 74 74 74 30 30 30 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
50492- 0 0 0 0 0 0 0 0 0 0 0 0
50493- 0 0 0 0 0 0 0 0 0 0 0 0
50494- 0 0 0 0 0 0 0 0 0 0 0 0
50495- 0 0 0 0 0 0 0 0 0 0 0 0
50496- 0 0 0 0 0 0 0 0 0 0 0 0
50497- 0 0 0 0 0 0 0 0 0 0 0 0
50498- 0 0 0 0 0 0 0 0 0 0 0 0
50499- 0 0 0 0 0 0 0 0 0 0 0 0
50500- 0 0 0 0 0 0 0 0 0 0 0 0
50501- 0 0 0 0 0 0 0 0 0 10 10 10
50502- 34 34 34 86 86 86 14 14 14 2 2 6
50503-121 87 25 192 133 9 219 162 10 239 182 13
50504-236 186 11 232 195 16 241 208 19 244 214 54
50505-246 218 60 246 218 38 246 215 20 241 208 19
50506-241 208 19 226 184 13 121 87 25 2 2 6
50507- 2 2 6 2 2 6 2 2 6 2 2 6
50508- 50 50 50 82 82 82 34 34 34 10 10 10
50509- 0 0 0 0 0 0 0 0 0 0 0 0
50510- 0 0 0 0 0 0 0 0 0 0 0 0
50511- 0 0 0 0 0 0 0 0 0 0 0 0
50512- 0 0 0 0 0 0 0 0 0 0 0 0
50513- 0 0 0 0 0 0 0 0 0 0 0 0
50514- 0 0 0 0 0 0 0 0 0 0 0 0
50515- 0 0 0 0 0 0 0 0 0 0 0 0
50516- 0 0 0 0 0 0 0 0 0 0 0 0
50517- 0 0 0 0 0 0 0 0 0 0 0 0
50518- 0 0 0 0 0 0 0 0 0 0 0 0
50519- 0 0 0 0 0 0 0 0 0 0 0 0
50520- 0 0 0 0 0 0 0 0 0 0 0 0
50521- 0 0 0 0 0 0 0 0 0 10 10 10
50522- 34 34 34 82 82 82 30 30 30 61 42 6
50523-180 123 7 206 145 10 230 174 11 239 182 13
50524-234 190 10 238 202 15 241 208 19 246 218 74
50525-246 218 38 246 215 20 246 215 20 246 215 20
50526-226 184 13 215 174 15 184 144 12 6 6 6
50527- 2 2 6 2 2 6 2 2 6 2 2 6
50528- 26 26 26 94 94 94 42 42 42 14 14 14
50529- 0 0 0 0 0 0 0 0 0 0 0 0
50530- 0 0 0 0 0 0 0 0 0 0 0 0
50531- 0 0 0 0 0 0 0 0 0 0 0 0
50532- 0 0 0 0 0 0 0 0 0 0 0 0
50533- 0 0 0 0 0 0 0 0 0 0 0 0
50534- 0 0 0 0 0 0 0 0 0 0 0 0
50535- 0 0 0 0 0 0 0 0 0 0 0 0
50536- 0 0 0 0 0 0 0 0 0 0 0 0
50537- 0 0 0 0 0 0 0 0 0 0 0 0
50538- 0 0 0 0 0 0 0 0 0 0 0 0
50539- 0 0 0 0 0 0 0 0 0 0 0 0
50540- 0 0 0 0 0 0 0 0 0 0 0 0
50541- 0 0 0 0 0 0 0 0 0 10 10 10
50542- 30 30 30 78 78 78 50 50 50 104 69 6
50543-192 133 9 216 158 10 236 178 12 236 186 11
50544-232 195 16 241 208 19 244 214 54 245 215 43
50545-246 215 20 246 215 20 241 208 19 198 155 10
50546-200 144 11 216 158 10 156 118 10 2 2 6
50547- 2 2 6 2 2 6 2 2 6 2 2 6
50548- 6 6 6 90 90 90 54 54 54 18 18 18
50549- 6 6 6 0 0 0 0 0 0 0 0 0
50550- 0 0 0 0 0 0 0 0 0 0 0 0
50551- 0 0 0 0 0 0 0 0 0 0 0 0
50552- 0 0 0 0 0 0 0 0 0 0 0 0
50553- 0 0 0 0 0 0 0 0 0 0 0 0
50554- 0 0 0 0 0 0 0 0 0 0 0 0
50555- 0 0 0 0 0 0 0 0 0 0 0 0
50556- 0 0 0 0 0 0 0 0 0 0 0 0
50557- 0 0 0 0 0 0 0 0 0 0 0 0
50558- 0 0 0 0 0 0 0 0 0 0 0 0
50559- 0 0 0 0 0 0 0 0 0 0 0 0
50560- 0 0 0 0 0 0 0 0 0 0 0 0
50561- 0 0 0 0 0 0 0 0 0 10 10 10
50562- 30 30 30 78 78 78 46 46 46 22 22 22
50563-137 92 6 210 162 10 239 182 13 238 190 10
50564-238 202 15 241 208 19 246 215 20 246 215 20
50565-241 208 19 203 166 17 185 133 11 210 150 10
50566-216 158 10 210 150 10 102 78 10 2 2 6
50567- 6 6 6 54 54 54 14 14 14 2 2 6
50568- 2 2 6 62 62 62 74 74 74 30 30 30
50569- 10 10 10 0 0 0 0 0 0 0 0 0
50570- 0 0 0 0 0 0 0 0 0 0 0 0
50571- 0 0 0 0 0 0 0 0 0 0 0 0
50572- 0 0 0 0 0 0 0 0 0 0 0 0
50573- 0 0 0 0 0 0 0 0 0 0 0 0
50574- 0 0 0 0 0 0 0 0 0 0 0 0
50575- 0 0 0 0 0 0 0 0 0 0 0 0
50576- 0 0 0 0 0 0 0 0 0 0 0 0
50577- 0 0 0 0 0 0 0 0 0 0 0 0
50578- 0 0 0 0 0 0 0 0 0 0 0 0
50579- 0 0 0 0 0 0 0 0 0 0 0 0
50580- 0 0 0 0 0 0 0 0 0 0 0 0
50581- 0 0 0 0 0 0 0 0 0 10 10 10
50582- 34 34 34 78 78 78 50 50 50 6 6 6
50583- 94 70 30 139 102 15 190 146 13 226 184 13
50584-232 200 30 232 195 16 215 174 15 190 146 13
50585-168 122 10 192 133 9 210 150 10 213 154 11
50586-202 150 34 182 157 106 101 98 89 2 2 6
50587- 2 2 6 78 78 78 116 116 116 58 58 58
50588- 2 2 6 22 22 22 90 90 90 46 46 46
50589- 18 18 18 6 6 6 0 0 0 0 0 0
50590- 0 0 0 0 0 0 0 0 0 0 0 0
50591- 0 0 0 0 0 0 0 0 0 0 0 0
50592- 0 0 0 0 0 0 0 0 0 0 0 0
50593- 0 0 0 0 0 0 0 0 0 0 0 0
50594- 0 0 0 0 0 0 0 0 0 0 0 0
50595- 0 0 0 0 0 0 0 0 0 0 0 0
50596- 0 0 0 0 0 0 0 0 0 0 0 0
50597- 0 0 0 0 0 0 0 0 0 0 0 0
50598- 0 0 0 0 0 0 0 0 0 0 0 0
50599- 0 0 0 0 0 0 0 0 0 0 0 0
50600- 0 0 0 0 0 0 0 0 0 0 0 0
50601- 0 0 0 0 0 0 0 0 0 10 10 10
50602- 38 38 38 86 86 86 50 50 50 6 6 6
50603-128 128 128 174 154 114 156 107 11 168 122 10
50604-198 155 10 184 144 12 197 138 11 200 144 11
50605-206 145 10 206 145 10 197 138 11 188 164 115
50606-195 195 195 198 198 198 174 174 174 14 14 14
50607- 2 2 6 22 22 22 116 116 116 116 116 116
50608- 22 22 22 2 2 6 74 74 74 70 70 70
50609- 30 30 30 10 10 10 0 0 0 0 0 0
50610- 0 0 0 0 0 0 0 0 0 0 0 0
50611- 0 0 0 0 0 0 0 0 0 0 0 0
50612- 0 0 0 0 0 0 0 0 0 0 0 0
50613- 0 0 0 0 0 0 0 0 0 0 0 0
50614- 0 0 0 0 0 0 0 0 0 0 0 0
50615- 0 0 0 0 0 0 0 0 0 0 0 0
50616- 0 0 0 0 0 0 0 0 0 0 0 0
50617- 0 0 0 0 0 0 0 0 0 0 0 0
50618- 0 0 0 0 0 0 0 0 0 0 0 0
50619- 0 0 0 0 0 0 0 0 0 0 0 0
50620- 0 0 0 0 0 0 0 0 0 0 0 0
50621- 0 0 0 0 0 0 6 6 6 18 18 18
50622- 50 50 50 101 101 101 26 26 26 10 10 10
50623-138 138 138 190 190 190 174 154 114 156 107 11
50624-197 138 11 200 144 11 197 138 11 192 133 9
50625-180 123 7 190 142 34 190 178 144 187 187 187
50626-202 202 202 221 221 221 214 214 214 66 66 66
50627- 2 2 6 2 2 6 50 50 50 62 62 62
50628- 6 6 6 2 2 6 10 10 10 90 90 90
50629- 50 50 50 18 18 18 6 6 6 0 0 0
50630- 0 0 0 0 0 0 0 0 0 0 0 0
50631- 0 0 0 0 0 0 0 0 0 0 0 0
50632- 0 0 0 0 0 0 0 0 0 0 0 0
50633- 0 0 0 0 0 0 0 0 0 0 0 0
50634- 0 0 0 0 0 0 0 0 0 0 0 0
50635- 0 0 0 0 0 0 0 0 0 0 0 0
50636- 0 0 0 0 0 0 0 0 0 0 0 0
50637- 0 0 0 0 0 0 0 0 0 0 0 0
50638- 0 0 0 0 0 0 0 0 0 0 0 0
50639- 0 0 0 0 0 0 0 0 0 0 0 0
50640- 0 0 0 0 0 0 0 0 0 0 0 0
50641- 0 0 0 0 0 0 10 10 10 34 34 34
50642- 74 74 74 74 74 74 2 2 6 6 6 6
50643-144 144 144 198 198 198 190 190 190 178 166 146
50644-154 121 60 156 107 11 156 107 11 168 124 44
50645-174 154 114 187 187 187 190 190 190 210 210 210
50646-246 246 246 253 253 253 253 253 253 182 182 182
50647- 6 6 6 2 2 6 2 2 6 2 2 6
50648- 2 2 6 2 2 6 2 2 6 62 62 62
50649- 74 74 74 34 34 34 14 14 14 0 0 0
50650- 0 0 0 0 0 0 0 0 0 0 0 0
50651- 0 0 0 0 0 0 0 0 0 0 0 0
50652- 0 0 0 0 0 0 0 0 0 0 0 0
50653- 0 0 0 0 0 0 0 0 0 0 0 0
50654- 0 0 0 0 0 0 0 0 0 0 0 0
50655- 0 0 0 0 0 0 0 0 0 0 0 0
50656- 0 0 0 0 0 0 0 0 0 0 0 0
50657- 0 0 0 0 0 0 0 0 0 0 0 0
50658- 0 0 0 0 0 0 0 0 0 0 0 0
50659- 0 0 0 0 0 0 0 0 0 0 0 0
50660- 0 0 0 0 0 0 0 0 0 0 0 0
50661- 0 0 0 10 10 10 22 22 22 54 54 54
50662- 94 94 94 18 18 18 2 2 6 46 46 46
50663-234 234 234 221 221 221 190 190 190 190 190 190
50664-190 190 190 187 187 187 187 187 187 190 190 190
50665-190 190 190 195 195 195 214 214 214 242 242 242
50666-253 253 253 253 253 253 253 253 253 253 253 253
50667- 82 82 82 2 2 6 2 2 6 2 2 6
50668- 2 2 6 2 2 6 2 2 6 14 14 14
50669- 86 86 86 54 54 54 22 22 22 6 6 6
50670- 0 0 0 0 0 0 0 0 0 0 0 0
50671- 0 0 0 0 0 0 0 0 0 0 0 0
50672- 0 0 0 0 0 0 0 0 0 0 0 0
50673- 0 0 0 0 0 0 0 0 0 0 0 0
50674- 0 0 0 0 0 0 0 0 0 0 0 0
50675- 0 0 0 0 0 0 0 0 0 0 0 0
50676- 0 0 0 0 0 0 0 0 0 0 0 0
50677- 0 0 0 0 0 0 0 0 0 0 0 0
50678- 0 0 0 0 0 0 0 0 0 0 0 0
50679- 0 0 0 0 0 0 0 0 0 0 0 0
50680- 0 0 0 0 0 0 0 0 0 0 0 0
50681- 6 6 6 18 18 18 46 46 46 90 90 90
50682- 46 46 46 18 18 18 6 6 6 182 182 182
50683-253 253 253 246 246 246 206 206 206 190 190 190
50684-190 190 190 190 190 190 190 190 190 190 190 190
50685-206 206 206 231 231 231 250 250 250 253 253 253
50686-253 253 253 253 253 253 253 253 253 253 253 253
50687-202 202 202 14 14 14 2 2 6 2 2 6
50688- 2 2 6 2 2 6 2 2 6 2 2 6
50689- 42 42 42 86 86 86 42 42 42 18 18 18
50690- 6 6 6 0 0 0 0 0 0 0 0 0
50691- 0 0 0 0 0 0 0 0 0 0 0 0
50692- 0 0 0 0 0 0 0 0 0 0 0 0
50693- 0 0 0 0 0 0 0 0 0 0 0 0
50694- 0 0 0 0 0 0 0 0 0 0 0 0
50695- 0 0 0 0 0 0 0 0 0 0 0 0
50696- 0 0 0 0 0 0 0 0 0 0 0 0
50697- 0 0 0 0 0 0 0 0 0 0 0 0
50698- 0 0 0 0 0 0 0 0 0 0 0 0
50699- 0 0 0 0 0 0 0 0 0 0 0 0
50700- 0 0 0 0 0 0 0 0 0 6 6 6
50701- 14 14 14 38 38 38 74 74 74 66 66 66
50702- 2 2 6 6 6 6 90 90 90 250 250 250
50703-253 253 253 253 253 253 238 238 238 198 198 198
50704-190 190 190 190 190 190 195 195 195 221 221 221
50705-246 246 246 253 253 253 253 253 253 253 253 253
50706-253 253 253 253 253 253 253 253 253 253 253 253
50707-253 253 253 82 82 82 2 2 6 2 2 6
50708- 2 2 6 2 2 6 2 2 6 2 2 6
50709- 2 2 6 78 78 78 70 70 70 34 34 34
50710- 14 14 14 6 6 6 0 0 0 0 0 0
50711- 0 0 0 0 0 0 0 0 0 0 0 0
50712- 0 0 0 0 0 0 0 0 0 0 0 0
50713- 0 0 0 0 0 0 0 0 0 0 0 0
50714- 0 0 0 0 0 0 0 0 0 0 0 0
50715- 0 0 0 0 0 0 0 0 0 0 0 0
50716- 0 0 0 0 0 0 0 0 0 0 0 0
50717- 0 0 0 0 0 0 0 0 0 0 0 0
50718- 0 0 0 0 0 0 0 0 0 0 0 0
50719- 0 0 0 0 0 0 0 0 0 0 0 0
50720- 0 0 0 0 0 0 0 0 0 14 14 14
50721- 34 34 34 66 66 66 78 78 78 6 6 6
50722- 2 2 6 18 18 18 218 218 218 253 253 253
50723-253 253 253 253 253 253 253 253 253 246 246 246
50724-226 226 226 231 231 231 246 246 246 253 253 253
50725-253 253 253 253 253 253 253 253 253 253 253 253
50726-253 253 253 253 253 253 253 253 253 253 253 253
50727-253 253 253 178 178 178 2 2 6 2 2 6
50728- 2 2 6 2 2 6 2 2 6 2 2 6
50729- 2 2 6 18 18 18 90 90 90 62 62 62
50730- 30 30 30 10 10 10 0 0 0 0 0 0
50731- 0 0 0 0 0 0 0 0 0 0 0 0
50732- 0 0 0 0 0 0 0 0 0 0 0 0
50733- 0 0 0 0 0 0 0 0 0 0 0 0
50734- 0 0 0 0 0 0 0 0 0 0 0 0
50735- 0 0 0 0 0 0 0 0 0 0 0 0
50736- 0 0 0 0 0 0 0 0 0 0 0 0
50737- 0 0 0 0 0 0 0 0 0 0 0 0
50738- 0 0 0 0 0 0 0 0 0 0 0 0
50739- 0 0 0 0 0 0 0 0 0 0 0 0
50740- 0 0 0 0 0 0 10 10 10 26 26 26
50741- 58 58 58 90 90 90 18 18 18 2 2 6
50742- 2 2 6 110 110 110 253 253 253 253 253 253
50743-253 253 253 253 253 253 253 253 253 253 253 253
50744-250 250 250 253 253 253 253 253 253 253 253 253
50745-253 253 253 253 253 253 253 253 253 253 253 253
50746-253 253 253 253 253 253 253 253 253 253 253 253
50747-253 253 253 231 231 231 18 18 18 2 2 6
50748- 2 2 6 2 2 6 2 2 6 2 2 6
50749- 2 2 6 2 2 6 18 18 18 94 94 94
50750- 54 54 54 26 26 26 10 10 10 0 0 0
50751- 0 0 0 0 0 0 0 0 0 0 0 0
50752- 0 0 0 0 0 0 0 0 0 0 0 0
50753- 0 0 0 0 0 0 0 0 0 0 0 0
50754- 0 0 0 0 0 0 0 0 0 0 0 0
50755- 0 0 0 0 0 0 0 0 0 0 0 0
50756- 0 0 0 0 0 0 0 0 0 0 0 0
50757- 0 0 0 0 0 0 0 0 0 0 0 0
50758- 0 0 0 0 0 0 0 0 0 0 0 0
50759- 0 0 0 0 0 0 0 0 0 0 0 0
50760- 0 0 0 6 6 6 22 22 22 50 50 50
50761- 90 90 90 26 26 26 2 2 6 2 2 6
50762- 14 14 14 195 195 195 250 250 250 253 253 253
50763-253 253 253 253 253 253 253 253 253 253 253 253
50764-253 253 253 253 253 253 253 253 253 253 253 253
50765-253 253 253 253 253 253 253 253 253 253 253 253
50766-253 253 253 253 253 253 253 253 253 253 253 253
50767-250 250 250 242 242 242 54 54 54 2 2 6
50768- 2 2 6 2 2 6 2 2 6 2 2 6
50769- 2 2 6 2 2 6 2 2 6 38 38 38
50770- 86 86 86 50 50 50 22 22 22 6 6 6
50771- 0 0 0 0 0 0 0 0 0 0 0 0
50772- 0 0 0 0 0 0 0 0 0 0 0 0
50773- 0 0 0 0 0 0 0 0 0 0 0 0
50774- 0 0 0 0 0 0 0 0 0 0 0 0
50775- 0 0 0 0 0 0 0 0 0 0 0 0
50776- 0 0 0 0 0 0 0 0 0 0 0 0
50777- 0 0 0 0 0 0 0 0 0 0 0 0
50778- 0 0 0 0 0 0 0 0 0 0 0 0
50779- 0 0 0 0 0 0 0 0 0 0 0 0
50780- 6 6 6 14 14 14 38 38 38 82 82 82
50781- 34 34 34 2 2 6 2 2 6 2 2 6
50782- 42 42 42 195 195 195 246 246 246 253 253 253
50783-253 253 253 253 253 253 253 253 253 250 250 250
50784-242 242 242 242 242 242 250 250 250 253 253 253
50785-253 253 253 253 253 253 253 253 253 253 253 253
50786-253 253 253 250 250 250 246 246 246 238 238 238
50787-226 226 226 231 231 231 101 101 101 6 6 6
50788- 2 2 6 2 2 6 2 2 6 2 2 6
50789- 2 2 6 2 2 6 2 2 6 2 2 6
50790- 38 38 38 82 82 82 42 42 42 14 14 14
50791- 6 6 6 0 0 0 0 0 0 0 0 0
50792- 0 0 0 0 0 0 0 0 0 0 0 0
50793- 0 0 0 0 0 0 0 0 0 0 0 0
50794- 0 0 0 0 0 0 0 0 0 0 0 0
50795- 0 0 0 0 0 0 0 0 0 0 0 0
50796- 0 0 0 0 0 0 0 0 0 0 0 0
50797- 0 0 0 0 0 0 0 0 0 0 0 0
50798- 0 0 0 0 0 0 0 0 0 0 0 0
50799- 0 0 0 0 0 0 0 0 0 0 0 0
50800- 10 10 10 26 26 26 62 62 62 66 66 66
50801- 2 2 6 2 2 6 2 2 6 6 6 6
50802- 70 70 70 170 170 170 206 206 206 234 234 234
50803-246 246 246 250 250 250 250 250 250 238 238 238
50804-226 226 226 231 231 231 238 238 238 250 250 250
50805-250 250 250 250 250 250 246 246 246 231 231 231
50806-214 214 214 206 206 206 202 202 202 202 202 202
50807-198 198 198 202 202 202 182 182 182 18 18 18
50808- 2 2 6 2 2 6 2 2 6 2 2 6
50809- 2 2 6 2 2 6 2 2 6 2 2 6
50810- 2 2 6 62 62 62 66 66 66 30 30 30
50811- 10 10 10 0 0 0 0 0 0 0 0 0
50812- 0 0 0 0 0 0 0 0 0 0 0 0
50813- 0 0 0 0 0 0 0 0 0 0 0 0
50814- 0 0 0 0 0 0 0 0 0 0 0 0
50815- 0 0 0 0 0 0 0 0 0 0 0 0
50816- 0 0 0 0 0 0 0 0 0 0 0 0
50817- 0 0 0 0 0 0 0 0 0 0 0 0
50818- 0 0 0 0 0 0 0 0 0 0 0 0
50819- 0 0 0 0 0 0 0 0 0 0 0 0
50820- 14 14 14 42 42 42 82 82 82 18 18 18
50821- 2 2 6 2 2 6 2 2 6 10 10 10
50822- 94 94 94 182 182 182 218 218 218 242 242 242
50823-250 250 250 253 253 253 253 253 253 250 250 250
50824-234 234 234 253 253 253 253 253 253 253 253 253
50825-253 253 253 253 253 253 253 253 253 246 246 246
50826-238 238 238 226 226 226 210 210 210 202 202 202
50827-195 195 195 195 195 195 210 210 210 158 158 158
50828- 6 6 6 14 14 14 50 50 50 14 14 14
50829- 2 2 6 2 2 6 2 2 6 2 2 6
50830- 2 2 6 6 6 6 86 86 86 46 46 46
50831- 18 18 18 6 6 6 0 0 0 0 0 0
50832- 0 0 0 0 0 0 0 0 0 0 0 0
50833- 0 0 0 0 0 0 0 0 0 0 0 0
50834- 0 0 0 0 0 0 0 0 0 0 0 0
50835- 0 0 0 0 0 0 0 0 0 0 0 0
50836- 0 0 0 0 0 0 0 0 0 0 0 0
50837- 0 0 0 0 0 0 0 0 0 0 0 0
50838- 0 0 0 0 0 0 0 0 0 0 0 0
50839- 0 0 0 0 0 0 0 0 0 6 6 6
50840- 22 22 22 54 54 54 70 70 70 2 2 6
50841- 2 2 6 10 10 10 2 2 6 22 22 22
50842-166 166 166 231 231 231 250 250 250 253 253 253
50843-253 253 253 253 253 253 253 253 253 250 250 250
50844-242 242 242 253 253 253 253 253 253 253 253 253
50845-253 253 253 253 253 253 253 253 253 253 253 253
50846-253 253 253 253 253 253 253 253 253 246 246 246
50847-231 231 231 206 206 206 198 198 198 226 226 226
50848- 94 94 94 2 2 6 6 6 6 38 38 38
50849- 30 30 30 2 2 6 2 2 6 2 2 6
50850- 2 2 6 2 2 6 62 62 62 66 66 66
50851- 26 26 26 10 10 10 0 0 0 0 0 0
50852- 0 0 0 0 0 0 0 0 0 0 0 0
50853- 0 0 0 0 0 0 0 0 0 0 0 0
50854- 0 0 0 0 0 0 0 0 0 0 0 0
50855- 0 0 0 0 0 0 0 0 0 0 0 0
50856- 0 0 0 0 0 0 0 0 0 0 0 0
50857- 0 0 0 0 0 0 0 0 0 0 0 0
50858- 0 0 0 0 0 0 0 0 0 0 0 0
50859- 0 0 0 0 0 0 0 0 0 10 10 10
50860- 30 30 30 74 74 74 50 50 50 2 2 6
50861- 26 26 26 26 26 26 2 2 6 106 106 106
50862-238 238 238 253 253 253 253 253 253 253 253 253
50863-253 253 253 253 253 253 253 253 253 253 253 253
50864-253 253 253 253 253 253 253 253 253 253 253 253
50865-253 253 253 253 253 253 253 253 253 253 253 253
50866-253 253 253 253 253 253 253 253 253 253 253 253
50867-253 253 253 246 246 246 218 218 218 202 202 202
50868-210 210 210 14 14 14 2 2 6 2 2 6
50869- 30 30 30 22 22 22 2 2 6 2 2 6
50870- 2 2 6 2 2 6 18 18 18 86 86 86
50871- 42 42 42 14 14 14 0 0 0 0 0 0
50872- 0 0 0 0 0 0 0 0 0 0 0 0
50873- 0 0 0 0 0 0 0 0 0 0 0 0
50874- 0 0 0 0 0 0 0 0 0 0 0 0
50875- 0 0 0 0 0 0 0 0 0 0 0 0
50876- 0 0 0 0 0 0 0 0 0 0 0 0
50877- 0 0 0 0 0 0 0 0 0 0 0 0
50878- 0 0 0 0 0 0 0 0 0 0 0 0
50879- 0 0 0 0 0 0 0 0 0 14 14 14
50880- 42 42 42 90 90 90 22 22 22 2 2 6
50881- 42 42 42 2 2 6 18 18 18 218 218 218
50882-253 253 253 253 253 253 253 253 253 253 253 253
50883-253 253 253 253 253 253 253 253 253 253 253 253
50884-253 253 253 253 253 253 253 253 253 253 253 253
50885-253 253 253 253 253 253 253 253 253 253 253 253
50886-253 253 253 253 253 253 253 253 253 253 253 253
50887-253 253 253 253 253 253 250 250 250 221 221 221
50888-218 218 218 101 101 101 2 2 6 14 14 14
50889- 18 18 18 38 38 38 10 10 10 2 2 6
50890- 2 2 6 2 2 6 2 2 6 78 78 78
50891- 58 58 58 22 22 22 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50895- 0 0 0 0 0 0 0 0 0 0 0 0
50896- 0 0 0 0 0 0 0 0 0 0 0 0
50897- 0 0 0 0 0 0 0 0 0 0 0 0
50898- 0 0 0 0 0 0 0 0 0 0 0 0
50899- 0 0 0 0 0 0 6 6 6 18 18 18
50900- 54 54 54 82 82 82 2 2 6 26 26 26
50901- 22 22 22 2 2 6 123 123 123 253 253 253
50902-253 253 253 253 253 253 253 253 253 253 253 253
50903-253 253 253 253 253 253 253 253 253 253 253 253
50904-253 253 253 253 253 253 253 253 253 253 253 253
50905-253 253 253 253 253 253 253 253 253 253 253 253
50906-253 253 253 253 253 253 253 253 253 253 253 253
50907-253 253 253 253 253 253 253 253 253 250 250 250
50908-238 238 238 198 198 198 6 6 6 38 38 38
50909- 58 58 58 26 26 26 38 38 38 2 2 6
50910- 2 2 6 2 2 6 2 2 6 46 46 46
50911- 78 78 78 30 30 30 10 10 10 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 0 0 0
50915- 0 0 0 0 0 0 0 0 0 0 0 0
50916- 0 0 0 0 0 0 0 0 0 0 0 0
50917- 0 0 0 0 0 0 0 0 0 0 0 0
50918- 0 0 0 0 0 0 0 0 0 0 0 0
50919- 0 0 0 0 0 0 10 10 10 30 30 30
50920- 74 74 74 58 58 58 2 2 6 42 42 42
50921- 2 2 6 22 22 22 231 231 231 253 253 253
50922-253 253 253 253 253 253 253 253 253 253 253 253
50923-253 253 253 253 253 253 253 253 253 250 250 250
50924-253 253 253 253 253 253 253 253 253 253 253 253
50925-253 253 253 253 253 253 253 253 253 253 253 253
50926-253 253 253 253 253 253 253 253 253 253 253 253
50927-253 253 253 253 253 253 253 253 253 253 253 253
50928-253 253 253 246 246 246 46 46 46 38 38 38
50929- 42 42 42 14 14 14 38 38 38 14 14 14
50930- 2 2 6 2 2 6 2 2 6 6 6 6
50931- 86 86 86 46 46 46 14 14 14 0 0 0
50932- 0 0 0 0 0 0 0 0 0 0 0 0
50933- 0 0 0 0 0 0 0 0 0 0 0 0
50934- 0 0 0 0 0 0 0 0 0 0 0 0
50935- 0 0 0 0 0 0 0 0 0 0 0 0
50936- 0 0 0 0 0 0 0 0 0 0 0 0
50937- 0 0 0 0 0 0 0 0 0 0 0 0
50938- 0 0 0 0 0 0 0 0 0 0 0 0
50939- 0 0 0 6 6 6 14 14 14 42 42 42
50940- 90 90 90 18 18 18 18 18 18 26 26 26
50941- 2 2 6 116 116 116 253 253 253 253 253 253
50942-253 253 253 253 253 253 253 253 253 253 253 253
50943-253 253 253 253 253 253 250 250 250 238 238 238
50944-253 253 253 253 253 253 253 253 253 253 253 253
50945-253 253 253 253 253 253 253 253 253 253 253 253
50946-253 253 253 253 253 253 253 253 253 253 253 253
50947-253 253 253 253 253 253 253 253 253 253 253 253
50948-253 253 253 253 253 253 94 94 94 6 6 6
50949- 2 2 6 2 2 6 10 10 10 34 34 34
50950- 2 2 6 2 2 6 2 2 6 2 2 6
50951- 74 74 74 58 58 58 22 22 22 6 6 6
50952- 0 0 0 0 0 0 0 0 0 0 0 0
50953- 0 0 0 0 0 0 0 0 0 0 0 0
50954- 0 0 0 0 0 0 0 0 0 0 0 0
50955- 0 0 0 0 0 0 0 0 0 0 0 0
50956- 0 0 0 0 0 0 0 0 0 0 0 0
50957- 0 0 0 0 0 0 0 0 0 0 0 0
50958- 0 0 0 0 0 0 0 0 0 0 0 0
50959- 0 0 0 10 10 10 26 26 26 66 66 66
50960- 82 82 82 2 2 6 38 38 38 6 6 6
50961- 14 14 14 210 210 210 253 253 253 253 253 253
50962-253 253 253 253 253 253 253 253 253 253 253 253
50963-253 253 253 253 253 253 246 246 246 242 242 242
50964-253 253 253 253 253 253 253 253 253 253 253 253
50965-253 253 253 253 253 253 253 253 253 253 253 253
50966-253 253 253 253 253 253 253 253 253 253 253 253
50967-253 253 253 253 253 253 253 253 253 253 253 253
50968-253 253 253 253 253 253 144 144 144 2 2 6
50969- 2 2 6 2 2 6 2 2 6 46 46 46
50970- 2 2 6 2 2 6 2 2 6 2 2 6
50971- 42 42 42 74 74 74 30 30 30 10 10 10
50972- 0 0 0 0 0 0 0 0 0 0 0 0
50973- 0 0 0 0 0 0 0 0 0 0 0 0
50974- 0 0 0 0 0 0 0 0 0 0 0 0
50975- 0 0 0 0 0 0 0 0 0 0 0 0
50976- 0 0 0 0 0 0 0 0 0 0 0 0
50977- 0 0 0 0 0 0 0 0 0 0 0 0
50978- 0 0 0 0 0 0 0 0 0 0 0 0
50979- 6 6 6 14 14 14 42 42 42 90 90 90
50980- 26 26 26 6 6 6 42 42 42 2 2 6
50981- 74 74 74 250 250 250 253 253 253 253 253 253
50982-253 253 253 253 253 253 253 253 253 253 253 253
50983-253 253 253 253 253 253 242 242 242 242 242 242
50984-253 253 253 253 253 253 253 253 253 253 253 253
50985-253 253 253 253 253 253 253 253 253 253 253 253
50986-253 253 253 253 253 253 253 253 253 253 253 253
50987-253 253 253 253 253 253 253 253 253 253 253 253
50988-253 253 253 253 253 253 182 182 182 2 2 6
50989- 2 2 6 2 2 6 2 2 6 46 46 46
50990- 2 2 6 2 2 6 2 2 6 2 2 6
50991- 10 10 10 86 86 86 38 38 38 10 10 10
50992- 0 0 0 0 0 0 0 0 0 0 0 0
50993- 0 0 0 0 0 0 0 0 0 0 0 0
50994- 0 0 0 0 0 0 0 0 0 0 0 0
50995- 0 0 0 0 0 0 0 0 0 0 0 0
50996- 0 0 0 0 0 0 0 0 0 0 0 0
50997- 0 0 0 0 0 0 0 0 0 0 0 0
50998- 0 0 0 0 0 0 0 0 0 0 0 0
50999- 10 10 10 26 26 26 66 66 66 82 82 82
51000- 2 2 6 22 22 22 18 18 18 2 2 6
51001-149 149 149 253 253 253 253 253 253 253 253 253
51002-253 253 253 253 253 253 253 253 253 253 253 253
51003-253 253 253 253 253 253 234 234 234 242 242 242
51004-253 253 253 253 253 253 253 253 253 253 253 253
51005-253 253 253 253 253 253 253 253 253 253 253 253
51006-253 253 253 253 253 253 253 253 253 253 253 253
51007-253 253 253 253 253 253 253 253 253 253 253 253
51008-253 253 253 253 253 253 206 206 206 2 2 6
51009- 2 2 6 2 2 6 2 2 6 38 38 38
51010- 2 2 6 2 2 6 2 2 6 2 2 6
51011- 6 6 6 86 86 86 46 46 46 14 14 14
51012- 0 0 0 0 0 0 0 0 0 0 0 0
51013- 0 0 0 0 0 0 0 0 0 0 0 0
51014- 0 0 0 0 0 0 0 0 0 0 0 0
51015- 0 0 0 0 0 0 0 0 0 0 0 0
51016- 0 0 0 0 0 0 0 0 0 0 0 0
51017- 0 0 0 0 0 0 0 0 0 0 0 0
51018- 0 0 0 0 0 0 0 0 0 6 6 6
51019- 18 18 18 46 46 46 86 86 86 18 18 18
51020- 2 2 6 34 34 34 10 10 10 6 6 6
51021-210 210 210 253 253 253 253 253 253 253 253 253
51022-253 253 253 253 253 253 253 253 253 253 253 253
51023-253 253 253 253 253 253 234 234 234 242 242 242
51024-253 253 253 253 253 253 253 253 253 253 253 253
51025-253 253 253 253 253 253 253 253 253 253 253 253
51026-253 253 253 253 253 253 253 253 253 253 253 253
51027-253 253 253 253 253 253 253 253 253 253 253 253
51028-253 253 253 253 253 253 221 221 221 6 6 6
51029- 2 2 6 2 2 6 6 6 6 30 30 30
51030- 2 2 6 2 2 6 2 2 6 2 2 6
51031- 2 2 6 82 82 82 54 54 54 18 18 18
51032- 6 6 6 0 0 0 0 0 0 0 0 0
51033- 0 0 0 0 0 0 0 0 0 0 0 0
51034- 0 0 0 0 0 0 0 0 0 0 0 0
51035- 0 0 0 0 0 0 0 0 0 0 0 0
51036- 0 0 0 0 0 0 0 0 0 0 0 0
51037- 0 0 0 0 0 0 0 0 0 0 0 0
51038- 0 0 0 0 0 0 0 0 0 10 10 10
51039- 26 26 26 66 66 66 62 62 62 2 2 6
51040- 2 2 6 38 38 38 10 10 10 26 26 26
51041-238 238 238 253 253 253 253 253 253 253 253 253
51042-253 253 253 253 253 253 253 253 253 253 253 253
51043-253 253 253 253 253 253 231 231 231 238 238 238
51044-253 253 253 253 253 253 253 253 253 253 253 253
51045-253 253 253 253 253 253 253 253 253 253 253 253
51046-253 253 253 253 253 253 253 253 253 253 253 253
51047-253 253 253 253 253 253 253 253 253 253 253 253
51048-253 253 253 253 253 253 231 231 231 6 6 6
51049- 2 2 6 2 2 6 10 10 10 30 30 30
51050- 2 2 6 2 2 6 2 2 6 2 2 6
51051- 2 2 6 66 66 66 58 58 58 22 22 22
51052- 6 6 6 0 0 0 0 0 0 0 0 0
51053- 0 0 0 0 0 0 0 0 0 0 0 0
51054- 0 0 0 0 0 0 0 0 0 0 0 0
51055- 0 0 0 0 0 0 0 0 0 0 0 0
51056- 0 0 0 0 0 0 0 0 0 0 0 0
51057- 0 0 0 0 0 0 0 0 0 0 0 0
51058- 0 0 0 0 0 0 0 0 0 10 10 10
51059- 38 38 38 78 78 78 6 6 6 2 2 6
51060- 2 2 6 46 46 46 14 14 14 42 42 42
51061-246 246 246 253 253 253 253 253 253 253 253 253
51062-253 253 253 253 253 253 253 253 253 253 253 253
51063-253 253 253 253 253 253 231 231 231 242 242 242
51064-253 253 253 253 253 253 253 253 253 253 253 253
51065-253 253 253 253 253 253 253 253 253 253 253 253
51066-253 253 253 253 253 253 253 253 253 253 253 253
51067-253 253 253 253 253 253 253 253 253 253 253 253
51068-253 253 253 253 253 253 234 234 234 10 10 10
51069- 2 2 6 2 2 6 22 22 22 14 14 14
51070- 2 2 6 2 2 6 2 2 6 2 2 6
51071- 2 2 6 66 66 66 62 62 62 22 22 22
51072- 6 6 6 0 0 0 0 0 0 0 0 0
51073- 0 0 0 0 0 0 0 0 0 0 0 0
51074- 0 0 0 0 0 0 0 0 0 0 0 0
51075- 0 0 0 0 0 0 0 0 0 0 0 0
51076- 0 0 0 0 0 0 0 0 0 0 0 0
51077- 0 0 0 0 0 0 0 0 0 0 0 0
51078- 0 0 0 0 0 0 6 6 6 18 18 18
51079- 50 50 50 74 74 74 2 2 6 2 2 6
51080- 14 14 14 70 70 70 34 34 34 62 62 62
51081-250 250 250 253 253 253 253 253 253 253 253 253
51082-253 253 253 253 253 253 253 253 253 253 253 253
51083-253 253 253 253 253 253 231 231 231 246 246 246
51084-253 253 253 253 253 253 253 253 253 253 253 253
51085-253 253 253 253 253 253 253 253 253 253 253 253
51086-253 253 253 253 253 253 253 253 253 253 253 253
51087-253 253 253 253 253 253 253 253 253 253 253 253
51088-253 253 253 253 253 253 234 234 234 14 14 14
51089- 2 2 6 2 2 6 30 30 30 2 2 6
51090- 2 2 6 2 2 6 2 2 6 2 2 6
51091- 2 2 6 66 66 66 62 62 62 22 22 22
51092- 6 6 6 0 0 0 0 0 0 0 0 0
51093- 0 0 0 0 0 0 0 0 0 0 0 0
51094- 0 0 0 0 0 0 0 0 0 0 0 0
51095- 0 0 0 0 0 0 0 0 0 0 0 0
51096- 0 0 0 0 0 0 0 0 0 0 0 0
51097- 0 0 0 0 0 0 0 0 0 0 0 0
51098- 0 0 0 0 0 0 6 6 6 18 18 18
51099- 54 54 54 62 62 62 2 2 6 2 2 6
51100- 2 2 6 30 30 30 46 46 46 70 70 70
51101-250 250 250 253 253 253 253 253 253 253 253 253
51102-253 253 253 253 253 253 253 253 253 253 253 253
51103-253 253 253 253 253 253 231 231 231 246 246 246
51104-253 253 253 253 253 253 253 253 253 253 253 253
51105-253 253 253 253 253 253 253 253 253 253 253 253
51106-253 253 253 253 253 253 253 253 253 253 253 253
51107-253 253 253 253 253 253 253 253 253 253 253 253
51108-253 253 253 253 253 253 226 226 226 10 10 10
51109- 2 2 6 6 6 6 30 30 30 2 2 6
51110- 2 2 6 2 2 6 2 2 6 2 2 6
51111- 2 2 6 66 66 66 58 58 58 22 22 22
51112- 6 6 6 0 0 0 0 0 0 0 0 0
51113- 0 0 0 0 0 0 0 0 0 0 0 0
51114- 0 0 0 0 0 0 0 0 0 0 0 0
51115- 0 0 0 0 0 0 0 0 0 0 0 0
51116- 0 0 0 0 0 0 0 0 0 0 0 0
51117- 0 0 0 0 0 0 0 0 0 0 0 0
51118- 0 0 0 0 0 0 6 6 6 22 22 22
51119- 58 58 58 62 62 62 2 2 6 2 2 6
51120- 2 2 6 2 2 6 30 30 30 78 78 78
51121-250 250 250 253 253 253 253 253 253 253 253 253
51122-253 253 253 253 253 253 253 253 253 253 253 253
51123-253 253 253 253 253 253 231 231 231 246 246 246
51124-253 253 253 253 253 253 253 253 253 253 253 253
51125-253 253 253 253 253 253 253 253 253 253 253 253
51126-253 253 253 253 253 253 253 253 253 253 253 253
51127-253 253 253 253 253 253 253 253 253 253 253 253
51128-253 253 253 253 253 253 206 206 206 2 2 6
51129- 22 22 22 34 34 34 18 14 6 22 22 22
51130- 26 26 26 18 18 18 6 6 6 2 2 6
51131- 2 2 6 82 82 82 54 54 54 18 18 18
51132- 6 6 6 0 0 0 0 0 0 0 0 0
51133- 0 0 0 0 0 0 0 0 0 0 0 0
51134- 0 0 0 0 0 0 0 0 0 0 0 0
51135- 0 0 0 0 0 0 0 0 0 0 0 0
51136- 0 0 0 0 0 0 0 0 0 0 0 0
51137- 0 0 0 0 0 0 0 0 0 0 0 0
51138- 0 0 0 0 0 0 6 6 6 26 26 26
51139- 62 62 62 106 106 106 74 54 14 185 133 11
51140-210 162 10 121 92 8 6 6 6 62 62 62
51141-238 238 238 253 253 253 253 253 253 253 253 253
51142-253 253 253 253 253 253 253 253 253 253 253 253
51143-253 253 253 253 253 253 231 231 231 246 246 246
51144-253 253 253 253 253 253 253 253 253 253 253 253
51145-253 253 253 253 253 253 253 253 253 253 253 253
51146-253 253 253 253 253 253 253 253 253 253 253 253
51147-253 253 253 253 253 253 253 253 253 253 253 253
51148-253 253 253 253 253 253 158 158 158 18 18 18
51149- 14 14 14 2 2 6 2 2 6 2 2 6
51150- 6 6 6 18 18 18 66 66 66 38 38 38
51151- 6 6 6 94 94 94 50 50 50 18 18 18
51152- 6 6 6 0 0 0 0 0 0 0 0 0
51153- 0 0 0 0 0 0 0 0 0 0 0 0
51154- 0 0 0 0 0 0 0 0 0 0 0 0
51155- 0 0 0 0 0 0 0 0 0 0 0 0
51156- 0 0 0 0 0 0 0 0 0 0 0 0
51157- 0 0 0 0 0 0 0 0 0 6 6 6
51158- 10 10 10 10 10 10 18 18 18 38 38 38
51159- 78 78 78 142 134 106 216 158 10 242 186 14
51160-246 190 14 246 190 14 156 118 10 10 10 10
51161- 90 90 90 238 238 238 253 253 253 253 253 253
51162-253 253 253 253 253 253 253 253 253 253 253 253
51163-253 253 253 253 253 253 231 231 231 250 250 250
51164-253 253 253 253 253 253 253 253 253 253 253 253
51165-253 253 253 253 253 253 253 253 253 253 253 253
51166-253 253 253 253 253 253 253 253 253 253 253 253
51167-253 253 253 253 253 253 253 253 253 246 230 190
51168-238 204 91 238 204 91 181 142 44 37 26 9
51169- 2 2 6 2 2 6 2 2 6 2 2 6
51170- 2 2 6 2 2 6 38 38 38 46 46 46
51171- 26 26 26 106 106 106 54 54 54 18 18 18
51172- 6 6 6 0 0 0 0 0 0 0 0 0
51173- 0 0 0 0 0 0 0 0 0 0 0 0
51174- 0 0 0 0 0 0 0 0 0 0 0 0
51175- 0 0 0 0 0 0 0 0 0 0 0 0
51176- 0 0 0 0 0 0 0 0 0 0 0 0
51177- 0 0 0 6 6 6 14 14 14 22 22 22
51178- 30 30 30 38 38 38 50 50 50 70 70 70
51179-106 106 106 190 142 34 226 170 11 242 186 14
51180-246 190 14 246 190 14 246 190 14 154 114 10
51181- 6 6 6 74 74 74 226 226 226 253 253 253
51182-253 253 253 253 253 253 253 253 253 253 253 253
51183-253 253 253 253 253 253 231 231 231 250 250 250
51184-253 253 253 253 253 253 253 253 253 253 253 253
51185-253 253 253 253 253 253 253 253 253 253 253 253
51186-253 253 253 253 253 253 253 253 253 253 253 253
51187-253 253 253 253 253 253 253 253 253 228 184 62
51188-241 196 14 241 208 19 232 195 16 38 30 10
51189- 2 2 6 2 2 6 2 2 6 2 2 6
51190- 2 2 6 6 6 6 30 30 30 26 26 26
51191-203 166 17 154 142 90 66 66 66 26 26 26
51192- 6 6 6 0 0 0 0 0 0 0 0 0
51193- 0 0 0 0 0 0 0 0 0 0 0 0
51194- 0 0 0 0 0 0 0 0 0 0 0 0
51195- 0 0 0 0 0 0 0 0 0 0 0 0
51196- 0 0 0 0 0 0 0 0 0 0 0 0
51197- 6 6 6 18 18 18 38 38 38 58 58 58
51198- 78 78 78 86 86 86 101 101 101 123 123 123
51199-175 146 61 210 150 10 234 174 13 246 186 14
51200-246 190 14 246 190 14 246 190 14 238 190 10
51201-102 78 10 2 2 6 46 46 46 198 198 198
51202-253 253 253 253 253 253 253 253 253 253 253 253
51203-253 253 253 253 253 253 234 234 234 242 242 242
51204-253 253 253 253 253 253 253 253 253 253 253 253
51205-253 253 253 253 253 253 253 253 253 253 253 253
51206-253 253 253 253 253 253 253 253 253 253 253 253
51207-253 253 253 253 253 253 253 253 253 224 178 62
51208-242 186 14 241 196 14 210 166 10 22 18 6
51209- 2 2 6 2 2 6 2 2 6 2 2 6
51210- 2 2 6 2 2 6 6 6 6 121 92 8
51211-238 202 15 232 195 16 82 82 82 34 34 34
51212- 10 10 10 0 0 0 0 0 0 0 0 0
51213- 0 0 0 0 0 0 0 0 0 0 0 0
51214- 0 0 0 0 0 0 0 0 0 0 0 0
51215- 0 0 0 0 0 0 0 0 0 0 0 0
51216- 0 0 0 0 0 0 0 0 0 0 0 0
51217- 14 14 14 38 38 38 70 70 70 154 122 46
51218-190 142 34 200 144 11 197 138 11 197 138 11
51219-213 154 11 226 170 11 242 186 14 246 190 14
51220-246 190 14 246 190 14 246 190 14 246 190 14
51221-225 175 15 46 32 6 2 2 6 22 22 22
51222-158 158 158 250 250 250 253 253 253 253 253 253
51223-253 253 253 253 253 253 253 253 253 253 253 253
51224-253 253 253 253 253 253 253 253 253 253 253 253
51225-253 253 253 253 253 253 253 253 253 253 253 253
51226-253 253 253 253 253 253 253 253 253 253 253 253
51227-253 253 253 250 250 250 242 242 242 224 178 62
51228-239 182 13 236 186 11 213 154 11 46 32 6
51229- 2 2 6 2 2 6 2 2 6 2 2 6
51230- 2 2 6 2 2 6 61 42 6 225 175 15
51231-238 190 10 236 186 11 112 100 78 42 42 42
51232- 14 14 14 0 0 0 0 0 0 0 0 0
51233- 0 0 0 0 0 0 0 0 0 0 0 0
51234- 0 0 0 0 0 0 0 0 0 0 0 0
51235- 0 0 0 0 0 0 0 0 0 0 0 0
51236- 0 0 0 0 0 0 0 0 0 6 6 6
51237- 22 22 22 54 54 54 154 122 46 213 154 11
51238-226 170 11 230 174 11 226 170 11 226 170 11
51239-236 178 12 242 186 14 246 190 14 246 190 14
51240-246 190 14 246 190 14 246 190 14 246 190 14
51241-241 196 14 184 144 12 10 10 10 2 2 6
51242- 6 6 6 116 116 116 242 242 242 253 253 253
51243-253 253 253 253 253 253 253 253 253 253 253 253
51244-253 253 253 253 253 253 253 253 253 253 253 253
51245-253 253 253 253 253 253 253 253 253 253 253 253
51246-253 253 253 253 253 253 253 253 253 253 253 253
51247-253 253 253 231 231 231 198 198 198 214 170 54
51248-236 178 12 236 178 12 210 150 10 137 92 6
51249- 18 14 6 2 2 6 2 2 6 2 2 6
51250- 6 6 6 70 47 6 200 144 11 236 178 12
51251-239 182 13 239 182 13 124 112 88 58 58 58
51252- 22 22 22 6 6 6 0 0 0 0 0 0
51253- 0 0 0 0 0 0 0 0 0 0 0 0
51254- 0 0 0 0 0 0 0 0 0 0 0 0
51255- 0 0 0 0 0 0 0 0 0 0 0 0
51256- 0 0 0 0 0 0 0 0 0 10 10 10
51257- 30 30 30 70 70 70 180 133 36 226 170 11
51258-239 182 13 242 186 14 242 186 14 246 186 14
51259-246 190 14 246 190 14 246 190 14 246 190 14
51260-246 190 14 246 190 14 246 190 14 246 190 14
51261-246 190 14 232 195 16 98 70 6 2 2 6
51262- 2 2 6 2 2 6 66 66 66 221 221 221
51263-253 253 253 253 253 253 253 253 253 253 253 253
51264-253 253 253 253 253 253 253 253 253 253 253 253
51265-253 253 253 253 253 253 253 253 253 253 253 253
51266-253 253 253 253 253 253 253 253 253 253 253 253
51267-253 253 253 206 206 206 198 198 198 214 166 58
51268-230 174 11 230 174 11 216 158 10 192 133 9
51269-163 110 8 116 81 8 102 78 10 116 81 8
51270-167 114 7 197 138 11 226 170 11 239 182 13
51271-242 186 14 242 186 14 162 146 94 78 78 78
51272- 34 34 34 14 14 14 6 6 6 0 0 0
51273- 0 0 0 0 0 0 0 0 0 0 0 0
51274- 0 0 0 0 0 0 0 0 0 0 0 0
51275- 0 0 0 0 0 0 0 0 0 0 0 0
51276- 0 0 0 0 0 0 0 0 0 6 6 6
51277- 30 30 30 78 78 78 190 142 34 226 170 11
51278-239 182 13 246 190 14 246 190 14 246 190 14
51279-246 190 14 246 190 14 246 190 14 246 190 14
51280-246 190 14 246 190 14 246 190 14 246 190 14
51281-246 190 14 241 196 14 203 166 17 22 18 6
51282- 2 2 6 2 2 6 2 2 6 38 38 38
51283-218 218 218 253 253 253 253 253 253 253 253 253
51284-253 253 253 253 253 253 253 253 253 253 253 253
51285-253 253 253 253 253 253 253 253 253 253 253 253
51286-253 253 253 253 253 253 253 253 253 253 253 253
51287-250 250 250 206 206 206 198 198 198 202 162 69
51288-226 170 11 236 178 12 224 166 10 210 150 10
51289-200 144 11 197 138 11 192 133 9 197 138 11
51290-210 150 10 226 170 11 242 186 14 246 190 14
51291-246 190 14 246 186 14 225 175 15 124 112 88
51292- 62 62 62 30 30 30 14 14 14 6 6 6
51293- 0 0 0 0 0 0 0 0 0 0 0 0
51294- 0 0 0 0 0 0 0 0 0 0 0 0
51295- 0 0 0 0 0 0 0 0 0 0 0 0
51296- 0 0 0 0 0 0 0 0 0 10 10 10
51297- 30 30 30 78 78 78 174 135 50 224 166 10
51298-239 182 13 246 190 14 246 190 14 246 190 14
51299-246 190 14 246 190 14 246 190 14 246 190 14
51300-246 190 14 246 190 14 246 190 14 246 190 14
51301-246 190 14 246 190 14 241 196 14 139 102 15
51302- 2 2 6 2 2 6 2 2 6 2 2 6
51303- 78 78 78 250 250 250 253 253 253 253 253 253
51304-253 253 253 253 253 253 253 253 253 253 253 253
51305-253 253 253 253 253 253 253 253 253 253 253 253
51306-253 253 253 253 253 253 253 253 253 253 253 253
51307-250 250 250 214 214 214 198 198 198 190 150 46
51308-219 162 10 236 178 12 234 174 13 224 166 10
51309-216 158 10 213 154 11 213 154 11 216 158 10
51310-226 170 11 239 182 13 246 190 14 246 190 14
51311-246 190 14 246 190 14 242 186 14 206 162 42
51312-101 101 101 58 58 58 30 30 30 14 14 14
51313- 6 6 6 0 0 0 0 0 0 0 0 0
51314- 0 0 0 0 0 0 0 0 0 0 0 0
51315- 0 0 0 0 0 0 0 0 0 0 0 0
51316- 0 0 0 0 0 0 0 0 0 10 10 10
51317- 30 30 30 74 74 74 174 135 50 216 158 10
51318-236 178 12 246 190 14 246 190 14 246 190 14
51319-246 190 14 246 190 14 246 190 14 246 190 14
51320-246 190 14 246 190 14 246 190 14 246 190 14
51321-246 190 14 246 190 14 241 196 14 226 184 13
51322- 61 42 6 2 2 6 2 2 6 2 2 6
51323- 22 22 22 238 238 238 253 253 253 253 253 253
51324-253 253 253 253 253 253 253 253 253 253 253 253
51325-253 253 253 253 253 253 253 253 253 253 253 253
51326-253 253 253 253 253 253 253 253 253 253 253 253
51327-253 253 253 226 226 226 187 187 187 180 133 36
51328-216 158 10 236 178 12 239 182 13 236 178 12
51329-230 174 11 226 170 11 226 170 11 230 174 11
51330-236 178 12 242 186 14 246 190 14 246 190 14
51331-246 190 14 246 190 14 246 186 14 239 182 13
51332-206 162 42 106 106 106 66 66 66 34 34 34
51333- 14 14 14 6 6 6 0 0 0 0 0 0
51334- 0 0 0 0 0 0 0 0 0 0 0 0
51335- 0 0 0 0 0 0 0 0 0 0 0 0
51336- 0 0 0 0 0 0 0 0 0 6 6 6
51337- 26 26 26 70 70 70 163 133 67 213 154 11
51338-236 178 12 246 190 14 246 190 14 246 190 14
51339-246 190 14 246 190 14 246 190 14 246 190 14
51340-246 190 14 246 190 14 246 190 14 246 190 14
51341-246 190 14 246 190 14 246 190 14 241 196 14
51342-190 146 13 18 14 6 2 2 6 2 2 6
51343- 46 46 46 246 246 246 253 253 253 253 253 253
51344-253 253 253 253 253 253 253 253 253 253 253 253
51345-253 253 253 253 253 253 253 253 253 253 253 253
51346-253 253 253 253 253 253 253 253 253 253 253 253
51347-253 253 253 221 221 221 86 86 86 156 107 11
51348-216 158 10 236 178 12 242 186 14 246 186 14
51349-242 186 14 239 182 13 239 182 13 242 186 14
51350-242 186 14 246 186 14 246 190 14 246 190 14
51351-246 190 14 246 190 14 246 190 14 246 190 14
51352-242 186 14 225 175 15 142 122 72 66 66 66
51353- 30 30 30 10 10 10 0 0 0 0 0 0
51354- 0 0 0 0 0 0 0 0 0 0 0 0
51355- 0 0 0 0 0 0 0 0 0 0 0 0
51356- 0 0 0 0 0 0 0 0 0 6 6 6
51357- 26 26 26 70 70 70 163 133 67 210 150 10
51358-236 178 12 246 190 14 246 190 14 246 190 14
51359-246 190 14 246 190 14 246 190 14 246 190 14
51360-246 190 14 246 190 14 246 190 14 246 190 14
51361-246 190 14 246 190 14 246 190 14 246 190 14
51362-232 195 16 121 92 8 34 34 34 106 106 106
51363-221 221 221 253 253 253 253 253 253 253 253 253
51364-253 253 253 253 253 253 253 253 253 253 253 253
51365-253 253 253 253 253 253 253 253 253 253 253 253
51366-253 253 253 253 253 253 253 253 253 253 253 253
51367-242 242 242 82 82 82 18 14 6 163 110 8
51368-216 158 10 236 178 12 242 186 14 246 190 14
51369-246 190 14 246 190 14 246 190 14 246 190 14
51370-246 190 14 246 190 14 246 190 14 246 190 14
51371-246 190 14 246 190 14 246 190 14 246 190 14
51372-246 190 14 246 190 14 242 186 14 163 133 67
51373- 46 46 46 18 18 18 6 6 6 0 0 0
51374- 0 0 0 0 0 0 0 0 0 0 0 0
51375- 0 0 0 0 0 0 0 0 0 0 0 0
51376- 0 0 0 0 0 0 0 0 0 10 10 10
51377- 30 30 30 78 78 78 163 133 67 210 150 10
51378-236 178 12 246 186 14 246 190 14 246 190 14
51379-246 190 14 246 190 14 246 190 14 246 190 14
51380-246 190 14 246 190 14 246 190 14 246 190 14
51381-246 190 14 246 190 14 246 190 14 246 190 14
51382-241 196 14 215 174 15 190 178 144 253 253 253
51383-253 253 253 253 253 253 253 253 253 253 253 253
51384-253 253 253 253 253 253 253 253 253 253 253 253
51385-253 253 253 253 253 253 253 253 253 253 253 253
51386-253 253 253 253 253 253 253 253 253 218 218 218
51387- 58 58 58 2 2 6 22 18 6 167 114 7
51388-216 158 10 236 178 12 246 186 14 246 190 14
51389-246 190 14 246 190 14 246 190 14 246 190 14
51390-246 190 14 246 190 14 246 190 14 246 190 14
51391-246 190 14 246 190 14 246 190 14 246 190 14
51392-246 190 14 246 186 14 242 186 14 190 150 46
51393- 54 54 54 22 22 22 6 6 6 0 0 0
51394- 0 0 0 0 0 0 0 0 0 0 0 0
51395- 0 0 0 0 0 0 0 0 0 0 0 0
51396- 0 0 0 0 0 0 0 0 0 14 14 14
51397- 38 38 38 86 86 86 180 133 36 213 154 11
51398-236 178 12 246 186 14 246 190 14 246 190 14
51399-246 190 14 246 190 14 246 190 14 246 190 14
51400-246 190 14 246 190 14 246 190 14 246 190 14
51401-246 190 14 246 190 14 246 190 14 246 190 14
51402-246 190 14 232 195 16 190 146 13 214 214 214
51403-253 253 253 253 253 253 253 253 253 253 253 253
51404-253 253 253 253 253 253 253 253 253 253 253 253
51405-253 253 253 253 253 253 253 253 253 253 253 253
51406-253 253 253 250 250 250 170 170 170 26 26 26
51407- 2 2 6 2 2 6 37 26 9 163 110 8
51408-219 162 10 239 182 13 246 186 14 246 190 14
51409-246 190 14 246 190 14 246 190 14 246 190 14
51410-246 190 14 246 190 14 246 190 14 246 190 14
51411-246 190 14 246 190 14 246 190 14 246 190 14
51412-246 186 14 236 178 12 224 166 10 142 122 72
51413- 46 46 46 18 18 18 6 6 6 0 0 0
51414- 0 0 0 0 0 0 0 0 0 0 0 0
51415- 0 0 0 0 0 0 0 0 0 0 0 0
51416- 0 0 0 0 0 0 6 6 6 18 18 18
51417- 50 50 50 109 106 95 192 133 9 224 166 10
51418-242 186 14 246 190 14 246 190 14 246 190 14
51419-246 190 14 246 190 14 246 190 14 246 190 14
51420-246 190 14 246 190 14 246 190 14 246 190 14
51421-246 190 14 246 190 14 246 190 14 246 190 14
51422-242 186 14 226 184 13 210 162 10 142 110 46
51423-226 226 226 253 253 253 253 253 253 253 253 253
51424-253 253 253 253 253 253 253 253 253 253 253 253
51425-253 253 253 253 253 253 253 253 253 253 253 253
51426-198 198 198 66 66 66 2 2 6 2 2 6
51427- 2 2 6 2 2 6 50 34 6 156 107 11
51428-219 162 10 239 182 13 246 186 14 246 190 14
51429-246 190 14 246 190 14 246 190 14 246 190 14
51430-246 190 14 246 190 14 246 190 14 246 190 14
51431-246 190 14 246 190 14 246 190 14 242 186 14
51432-234 174 13 213 154 11 154 122 46 66 66 66
51433- 30 30 30 10 10 10 0 0 0 0 0 0
51434- 0 0 0 0 0 0 0 0 0 0 0 0
51435- 0 0 0 0 0 0 0 0 0 0 0 0
51436- 0 0 0 0 0 0 6 6 6 22 22 22
51437- 58 58 58 154 121 60 206 145 10 234 174 13
51438-242 186 14 246 186 14 246 190 14 246 190 14
51439-246 190 14 246 190 14 246 190 14 246 190 14
51440-246 190 14 246 190 14 246 190 14 246 190 14
51441-246 190 14 246 190 14 246 190 14 246 190 14
51442-246 186 14 236 178 12 210 162 10 163 110 8
51443- 61 42 6 138 138 138 218 218 218 250 250 250
51444-253 253 253 253 253 253 253 253 253 250 250 250
51445-242 242 242 210 210 210 144 144 144 66 66 66
51446- 6 6 6 2 2 6 2 2 6 2 2 6
51447- 2 2 6 2 2 6 61 42 6 163 110 8
51448-216 158 10 236 178 12 246 190 14 246 190 14
51449-246 190 14 246 190 14 246 190 14 246 190 14
51450-246 190 14 246 190 14 246 190 14 246 190 14
51451-246 190 14 239 182 13 230 174 11 216 158 10
51452-190 142 34 124 112 88 70 70 70 38 38 38
51453- 18 18 18 6 6 6 0 0 0 0 0 0
51454- 0 0 0 0 0 0 0 0 0 0 0 0
51455- 0 0 0 0 0 0 0 0 0 0 0 0
51456- 0 0 0 0 0 0 6 6 6 22 22 22
51457- 62 62 62 168 124 44 206 145 10 224 166 10
51458-236 178 12 239 182 13 242 186 14 242 186 14
51459-246 186 14 246 190 14 246 190 14 246 190 14
51460-246 190 14 246 190 14 246 190 14 246 190 14
51461-246 190 14 246 190 14 246 190 14 246 190 14
51462-246 190 14 236 178 12 216 158 10 175 118 6
51463- 80 54 7 2 2 6 6 6 6 30 30 30
51464- 54 54 54 62 62 62 50 50 50 38 38 38
51465- 14 14 14 2 2 6 2 2 6 2 2 6
51466- 2 2 6 2 2 6 2 2 6 2 2 6
51467- 2 2 6 6 6 6 80 54 7 167 114 7
51468-213 154 11 236 178 12 246 190 14 246 190 14
51469-246 190 14 246 190 14 246 190 14 246 190 14
51470-246 190 14 242 186 14 239 182 13 239 182 13
51471-230 174 11 210 150 10 174 135 50 124 112 88
51472- 82 82 82 54 54 54 34 34 34 18 18 18
51473- 6 6 6 0 0 0 0 0 0 0 0 0
51474- 0 0 0 0 0 0 0 0 0 0 0 0
51475- 0 0 0 0 0 0 0 0 0 0 0 0
51476- 0 0 0 0 0 0 6 6 6 18 18 18
51477- 50 50 50 158 118 36 192 133 9 200 144 11
51478-216 158 10 219 162 10 224 166 10 226 170 11
51479-230 174 11 236 178 12 239 182 13 239 182 13
51480-242 186 14 246 186 14 246 190 14 246 190 14
51481-246 190 14 246 190 14 246 190 14 246 190 14
51482-246 186 14 230 174 11 210 150 10 163 110 8
51483-104 69 6 10 10 10 2 2 6 2 2 6
51484- 2 2 6 2 2 6 2 2 6 2 2 6
51485- 2 2 6 2 2 6 2 2 6 2 2 6
51486- 2 2 6 2 2 6 2 2 6 2 2 6
51487- 2 2 6 6 6 6 91 60 6 167 114 7
51488-206 145 10 230 174 11 242 186 14 246 190 14
51489-246 190 14 246 190 14 246 186 14 242 186 14
51490-239 182 13 230 174 11 224 166 10 213 154 11
51491-180 133 36 124 112 88 86 86 86 58 58 58
51492- 38 38 38 22 22 22 10 10 10 6 6 6
51493- 0 0 0 0 0 0 0 0 0 0 0 0
51494- 0 0 0 0 0 0 0 0 0 0 0 0
51495- 0 0 0 0 0 0 0 0 0 0 0 0
51496- 0 0 0 0 0 0 0 0 0 14 14 14
51497- 34 34 34 70 70 70 138 110 50 158 118 36
51498-167 114 7 180 123 7 192 133 9 197 138 11
51499-200 144 11 206 145 10 213 154 11 219 162 10
51500-224 166 10 230 174 11 239 182 13 242 186 14
51501-246 186 14 246 186 14 246 186 14 246 186 14
51502-239 182 13 216 158 10 185 133 11 152 99 6
51503-104 69 6 18 14 6 2 2 6 2 2 6
51504- 2 2 6 2 2 6 2 2 6 2 2 6
51505- 2 2 6 2 2 6 2 2 6 2 2 6
51506- 2 2 6 2 2 6 2 2 6 2 2 6
51507- 2 2 6 6 6 6 80 54 7 152 99 6
51508-192 133 9 219 162 10 236 178 12 239 182 13
51509-246 186 14 242 186 14 239 182 13 236 178 12
51510-224 166 10 206 145 10 192 133 9 154 121 60
51511- 94 94 94 62 62 62 42 42 42 22 22 22
51512- 14 14 14 6 6 6 0 0 0 0 0 0
51513- 0 0 0 0 0 0 0 0 0 0 0 0
51514- 0 0 0 0 0 0 0 0 0 0 0 0
51515- 0 0 0 0 0 0 0 0 0 0 0 0
51516- 0 0 0 0 0 0 0 0 0 6 6 6
51517- 18 18 18 34 34 34 58 58 58 78 78 78
51518-101 98 89 124 112 88 142 110 46 156 107 11
51519-163 110 8 167 114 7 175 118 6 180 123 7
51520-185 133 11 197 138 11 210 150 10 219 162 10
51521-226 170 11 236 178 12 236 178 12 234 174 13
51522-219 162 10 197 138 11 163 110 8 130 83 6
51523- 91 60 6 10 10 10 2 2 6 2 2 6
51524- 18 18 18 38 38 38 38 38 38 38 38 38
51525- 38 38 38 38 38 38 38 38 38 38 38 38
51526- 38 38 38 38 38 38 26 26 26 2 2 6
51527- 2 2 6 6 6 6 70 47 6 137 92 6
51528-175 118 6 200 144 11 219 162 10 230 174 11
51529-234 174 13 230 174 11 219 162 10 210 150 10
51530-192 133 9 163 110 8 124 112 88 82 82 82
51531- 50 50 50 30 30 30 14 14 14 6 6 6
51532- 0 0 0 0 0 0 0 0 0 0 0 0
51533- 0 0 0 0 0 0 0 0 0 0 0 0
51534- 0 0 0 0 0 0 0 0 0 0 0 0
51535- 0 0 0 0 0 0 0 0 0 0 0 0
51536- 0 0 0 0 0 0 0 0 0 0 0 0
51537- 6 6 6 14 14 14 22 22 22 34 34 34
51538- 42 42 42 58 58 58 74 74 74 86 86 86
51539-101 98 89 122 102 70 130 98 46 121 87 25
51540-137 92 6 152 99 6 163 110 8 180 123 7
51541-185 133 11 197 138 11 206 145 10 200 144 11
51542-180 123 7 156 107 11 130 83 6 104 69 6
51543- 50 34 6 54 54 54 110 110 110 101 98 89
51544- 86 86 86 82 82 82 78 78 78 78 78 78
51545- 78 78 78 78 78 78 78 78 78 78 78 78
51546- 78 78 78 82 82 82 86 86 86 94 94 94
51547-106 106 106 101 101 101 86 66 34 124 80 6
51548-156 107 11 180 123 7 192 133 9 200 144 11
51549-206 145 10 200 144 11 192 133 9 175 118 6
51550-139 102 15 109 106 95 70 70 70 42 42 42
51551- 22 22 22 10 10 10 0 0 0 0 0 0
51552- 0 0 0 0 0 0 0 0 0 0 0 0
51553- 0 0 0 0 0 0 0 0 0 0 0 0
51554- 0 0 0 0 0 0 0 0 0 0 0 0
51555- 0 0 0 0 0 0 0 0 0 0 0 0
51556- 0 0 0 0 0 0 0 0 0 0 0 0
51557- 0 0 0 0 0 0 6 6 6 10 10 10
51558- 14 14 14 22 22 22 30 30 30 38 38 38
51559- 50 50 50 62 62 62 74 74 74 90 90 90
51560-101 98 89 112 100 78 121 87 25 124 80 6
51561-137 92 6 152 99 6 152 99 6 152 99 6
51562-138 86 6 124 80 6 98 70 6 86 66 30
51563-101 98 89 82 82 82 58 58 58 46 46 46
51564- 38 38 38 34 34 34 34 34 34 34 34 34
51565- 34 34 34 34 34 34 34 34 34 34 34 34
51566- 34 34 34 34 34 34 38 38 38 42 42 42
51567- 54 54 54 82 82 82 94 86 76 91 60 6
51568-134 86 6 156 107 11 167 114 7 175 118 6
51569-175 118 6 167 114 7 152 99 6 121 87 25
51570-101 98 89 62 62 62 34 34 34 18 18 18
51571- 6 6 6 0 0 0 0 0 0 0 0 0
51572- 0 0 0 0 0 0 0 0 0 0 0 0
51573- 0 0 0 0 0 0 0 0 0 0 0 0
51574- 0 0 0 0 0 0 0 0 0 0 0 0
51575- 0 0 0 0 0 0 0 0 0 0 0 0
51576- 0 0 0 0 0 0 0 0 0 0 0 0
51577- 0 0 0 0 0 0 0 0 0 0 0 0
51578- 0 0 0 6 6 6 6 6 6 10 10 10
51579- 18 18 18 22 22 22 30 30 30 42 42 42
51580- 50 50 50 66 66 66 86 86 86 101 98 89
51581-106 86 58 98 70 6 104 69 6 104 69 6
51582-104 69 6 91 60 6 82 62 34 90 90 90
51583- 62 62 62 38 38 38 22 22 22 14 14 14
51584- 10 10 10 10 10 10 10 10 10 10 10 10
51585- 10 10 10 10 10 10 6 6 6 10 10 10
51586- 10 10 10 10 10 10 10 10 10 14 14 14
51587- 22 22 22 42 42 42 70 70 70 89 81 66
51588- 80 54 7 104 69 6 124 80 6 137 92 6
51589-134 86 6 116 81 8 100 82 52 86 86 86
51590- 58 58 58 30 30 30 14 14 14 6 6 6
51591- 0 0 0 0 0 0 0 0 0 0 0 0
51592- 0 0 0 0 0 0 0 0 0 0 0 0
51593- 0 0 0 0 0 0 0 0 0 0 0 0
51594- 0 0 0 0 0 0 0 0 0 0 0 0
51595- 0 0 0 0 0 0 0 0 0 0 0 0
51596- 0 0 0 0 0 0 0 0 0 0 0 0
51597- 0 0 0 0 0 0 0 0 0 0 0 0
51598- 0 0 0 0 0 0 0 0 0 0 0 0
51599- 0 0 0 6 6 6 10 10 10 14 14 14
51600- 18 18 18 26 26 26 38 38 38 54 54 54
51601- 70 70 70 86 86 86 94 86 76 89 81 66
51602- 89 81 66 86 86 86 74 74 74 50 50 50
51603- 30 30 30 14 14 14 6 6 6 0 0 0
51604- 0 0 0 0 0 0 0 0 0 0 0 0
51605- 0 0 0 0 0 0 0 0 0 0 0 0
51606- 0 0 0 0 0 0 0 0 0 0 0 0
51607- 6 6 6 18 18 18 34 34 34 58 58 58
51608- 82 82 82 89 81 66 89 81 66 89 81 66
51609- 94 86 66 94 86 76 74 74 74 50 50 50
51610- 26 26 26 14 14 14 6 6 6 0 0 0
51611- 0 0 0 0 0 0 0 0 0 0 0 0
51612- 0 0 0 0 0 0 0 0 0 0 0 0
51613- 0 0 0 0 0 0 0 0 0 0 0 0
51614- 0 0 0 0 0 0 0 0 0 0 0 0
51615- 0 0 0 0 0 0 0 0 0 0 0 0
51616- 0 0 0 0 0 0 0 0 0 0 0 0
51617- 0 0 0 0 0 0 0 0 0 0 0 0
51618- 0 0 0 0 0 0 0 0 0 0 0 0
51619- 0 0 0 0 0 0 0 0 0 0 0 0
51620- 6 6 6 6 6 6 14 14 14 18 18 18
51621- 30 30 30 38 38 38 46 46 46 54 54 54
51622- 50 50 50 42 42 42 30 30 30 18 18 18
51623- 10 10 10 0 0 0 0 0 0 0 0 0
51624- 0 0 0 0 0 0 0 0 0 0 0 0
51625- 0 0 0 0 0 0 0 0 0 0 0 0
51626- 0 0 0 0 0 0 0 0 0 0 0 0
51627- 0 0 0 6 6 6 14 14 14 26 26 26
51628- 38 38 38 50 50 50 58 58 58 58 58 58
51629- 54 54 54 42 42 42 30 30 30 18 18 18
51630- 10 10 10 0 0 0 0 0 0 0 0 0
51631- 0 0 0 0 0 0 0 0 0 0 0 0
51632- 0 0 0 0 0 0 0 0 0 0 0 0
51633- 0 0 0 0 0 0 0 0 0 0 0 0
51634- 0 0 0 0 0 0 0 0 0 0 0 0
51635- 0 0 0 0 0 0 0 0 0 0 0 0
51636- 0 0 0 0 0 0 0 0 0 0 0 0
51637- 0 0 0 0 0 0 0 0 0 0 0 0
51638- 0 0 0 0 0 0 0 0 0 0 0 0
51639- 0 0 0 0 0 0 0 0 0 0 0 0
51640- 0 0 0 0 0 0 0 0 0 6 6 6
51641- 6 6 6 10 10 10 14 14 14 18 18 18
51642- 18 18 18 14 14 14 10 10 10 6 6 6
51643- 0 0 0 0 0 0 0 0 0 0 0 0
51644- 0 0 0 0 0 0 0 0 0 0 0 0
51645- 0 0 0 0 0 0 0 0 0 0 0 0
51646- 0 0 0 0 0 0 0 0 0 0 0 0
51647- 0 0 0 0 0 0 0 0 0 6 6 6
51648- 14 14 14 18 18 18 22 22 22 22 22 22
51649- 18 18 18 14 14 14 10 10 10 6 6 6
51650- 0 0 0 0 0 0 0 0 0 0 0 0
51651- 0 0 0 0 0 0 0 0 0 0 0 0
51652- 0 0 0 0 0 0 0 0 0 0 0 0
51653- 0 0 0 0 0 0 0 0 0 0 0 0
51654- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
51657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51668+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 4 4 4 4 4 4 4 4 4 4 4 4
51671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51682+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 4 4 4 4 4 4 4 4 4 4 4 4
51685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51696+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 4 4 4 4 4 4 4 4 4 4 4 4
51699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51710+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 4 4 4 4 4 4 4 4 4 4 4 4
51713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51724+4 4 4 4 4 4
51725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51738+4 4 4 4 4 4
51739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51743+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
51744+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
51745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51748+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
51749+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51750+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
51753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51757+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
51758+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
51759+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51762+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
51763+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
51764+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
51765+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51766+4 4 4 4 4 4
51767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51771+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
51772+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
51773+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51776+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
51777+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
51778+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
51779+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
51780+4 4 4 4 4 4
51781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51784+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
51785+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
51786+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
51787+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
51788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51789+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51790+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
51791+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
51792+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
51793+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
51794+4 4 4 4 4 4
51795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51798+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
51799+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
51800+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
51801+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
51802+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51803+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
51804+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
51805+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
51806+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
51807+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
51808+4 4 4 4 4 4
51809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51812+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
51813+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
51814+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
51815+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
51816+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51817+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
51818+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
51819+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
51820+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
51821+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
51822+4 4 4 4 4 4
51823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51825+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
51826+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
51827+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
51828+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
51829+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
51830+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
51831+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
51832+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
51833+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
51834+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
51835+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
51836+4 4 4 4 4 4
51837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51839+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
51840+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
51841+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
51842+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
51843+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
51844+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
51845+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
51846+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
51847+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
51848+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
51849+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
51850+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 4 4 4 4 4 4 4 4 4 4 4 4
51853+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
51854+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
51855+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
51856+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
51857+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
51858+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
51859+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
51860+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
51861+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
51862+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
51863+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51864+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 4 4 4 4 4 4 4 4 4 4 4 4
51867+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
51868+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
51869+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
51870+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
51871+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
51872+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
51873+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
51874+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
51875+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
51876+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
51877+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
51878+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 4 4 4 4 4 4 3 3 3 0 0 0
51881+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
51882+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
51883+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
51884+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
51885+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
51886+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
51887+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
51888+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
51889+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
51890+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
51891+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
51892+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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
51895+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
51896+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
51897+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51898+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
51899+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
51900+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
51901+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
51902+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
51903+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
51904+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
51905+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
51906+0 0 0 4 4 4
51907+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51908+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
51909+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
51910+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
51911+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
51912+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
51913+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
51914+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
51915+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
51916+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
51917+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
51918+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
51919+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
51920+2 0 0 0 0 0
51921+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
51922+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
51923+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
51924+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
51925+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
51926+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
51927+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
51928+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
51929+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
51930+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
51931+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
51932+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
51933+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
51934+37 38 37 0 0 0
51935+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51936+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
51937+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
51938+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
51939+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
51940+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
51941+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
51942+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
51943+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
51944+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
51945+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
51946+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
51947+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
51948+85 115 134 4 0 0
51949+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
51950+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
51951+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
51952+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
51953+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
51954+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
51955+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
51956+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
51957+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
51958+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
51959+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
51960+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
51961+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
51962+60 73 81 4 0 0
51963+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
51964+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
51965+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
51966+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
51967+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
51968+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
51969+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
51970+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
51971+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
51972+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
51973+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
51974+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
51975+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
51976+16 19 21 4 0 0
51977+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51978+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51979+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51980+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51981+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51982+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51983+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51984+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51985+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51986+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51987+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51988+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51989+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51990+4 0 0 4 3 3
51991+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51992+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51993+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51995+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51996+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51997+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51998+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51999+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
52000+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
52001+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
52002+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
52003+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
52004+3 2 2 4 4 4
52005+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
52006+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
52007+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
52008+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
52009+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
52010+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
52011+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
52012+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
52013+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
52014+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
52015+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
52016+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
52017+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
52018+4 4 4 4 4 4
52019+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
52020+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
52021+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
52022+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
52023+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
52024+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
52025+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
52026+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
52027+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
52028+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
52029+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
52030+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
52031+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
52032+4 4 4 4 4 4
52033+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
52034+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
52035+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
52036+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
52037+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
52038+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
52039+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
52040+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
52041+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
52042+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
52043+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
52044+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
52045+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
52046+5 5 5 5 5 5
52047+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
52048+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
52049+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
52050+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
52051+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
52052+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52053+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
52054+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
52055+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
52056+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
52057+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
52058+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
52059+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
52060+5 5 5 4 4 4
52061+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
52062+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
52063+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
52064+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
52065+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
52066+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
52067+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
52068+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
52069+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
52070+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
52071+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
52072+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
52073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52074+4 4 4 4 4 4
52075+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
52076+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
52077+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
52078+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
52079+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
52080+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52081+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52082+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
52083+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
52084+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
52085+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
52086+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
52087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52088+4 4 4 4 4 4
52089+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
52090+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
52091+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
52092+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
52093+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
52094+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
52095+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
52096+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
52097+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
52098+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
52099+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
52100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52102+4 4 4 4 4 4
52103+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
52104+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
52105+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
52106+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
52107+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
52108+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52109+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52110+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
52111+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
52112+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
52113+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
52114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52116+4 4 4 4 4 4
52117+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
52118+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
52119+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
52120+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
52121+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
52122+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
52123+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
52124+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
52125+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
52126+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
52127+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52130+4 4 4 4 4 4
52131+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
52132+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
52133+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
52134+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
52135+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
52136+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
52137+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
52138+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
52139+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
52140+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
52141+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
52142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52144+4 4 4 4 4 4
52145+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
52146+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
52147+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
52148+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
52149+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
52150+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
52151+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
52152+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
52153+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
52154+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
52155+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
52156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52158+4 4 4 4 4 4
52159+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
52160+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
52161+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
52162+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
52163+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
52164+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
52165+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
52166+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
52167+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
52168+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
52169+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52172+4 4 4 4 4 4
52173+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
52174+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
52175+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
52176+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
52177+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52178+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
52179+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
52180+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
52181+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
52182+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
52183+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52186+4 4 4 4 4 4
52187+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
52188+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
52189+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
52190+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
52191+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52192+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
52193+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
52194+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
52195+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
52196+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
52197+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52200+4 4 4 4 4 4
52201+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
52202+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
52203+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
52204+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
52205+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52206+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
52207+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
52208+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
52209+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
52210+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52211+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52214+4 4 4 4 4 4
52215+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
52216+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
52217+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
52218+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
52219+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
52220+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
52221+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
52222+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
52223+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52224+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52225+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52228+4 4 4 4 4 4
52229+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
52230+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
52231+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
52232+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
52233+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52234+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
52235+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
52236+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
52237+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52238+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52239+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52242+4 4 4 4 4 4
52243+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
52244+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
52245+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
52246+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
52247+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
52248+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
52249+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
52250+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
52251+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52252+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52253+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52256+4 4 4 4 4 4
52257+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
52258+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
52259+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52260+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
52261+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
52262+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
52263+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
52264+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
52265+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
52266+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52267+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52270+4 4 4 4 4 4
52271+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52272+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
52273+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
52274+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
52275+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
52276+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
52277+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
52278+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
52279+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52280+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52281+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52284+4 4 4 4 4 4
52285+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
52286+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
52287+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52288+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
52289+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
52290+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
52291+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
52292+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
52293+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
52294+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52295+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52298+4 4 4 4 4 4
52299+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52300+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
52301+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
52302+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
52303+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
52304+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
52305+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
52306+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
52307+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52308+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52309+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52312+4 4 4 4 4 4
52313+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52314+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
52315+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52316+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
52317+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
52318+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
52319+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
52320+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
52321+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52322+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52323+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52326+4 4 4 4 4 4
52327+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52328+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
52329+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
52330+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
52331+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
52332+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
52333+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52334+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
52335+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52336+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52337+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52340+4 4 4 4 4 4
52341+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52342+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
52343+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
52344+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52345+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
52346+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
52347+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52348+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
52349+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52350+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52351+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52354+4 4 4 4 4 4
52355+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52356+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
52357+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
52358+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
52359+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
52360+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
52361+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
52362+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
52363+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
52364+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52365+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52368+4 4 4 4 4 4
52369+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52370+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
52371+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
52372+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
52373+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
52374+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
52375+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
52376+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
52377+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
52378+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52379+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52382+4 4 4 4 4 4
52383+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
52384+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
52385+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
52386+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
52387+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52388+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
52389+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
52390+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
52391+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
52392+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52393+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52396+4 4 4 4 4 4
52397+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52398+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
52399+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
52400+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
52401+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
52402+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
52403+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
52404+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
52405+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
52406+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52407+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52410+4 4 4 4 4 4
52411+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
52412+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
52413+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
52414+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
52415+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
52416+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
52417+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
52418+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
52419+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
52420+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
52421+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52424+4 4 4 4 4 4
52425+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
52426+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52427+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
52428+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
52429+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
52430+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
52431+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
52432+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
52433+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
52434+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
52435+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52438+4 4 4 4 4 4
52439+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
52440+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52441+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
52442+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
52443+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
52444+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
52445+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52446+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
52447+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
52448+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
52449+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52452+4 4 4 4 4 4
52453+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
52454+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
52455+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
52456+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
52457+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
52458+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
52459+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
52460+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
52461+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
52462+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
52463+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52466+4 4 4 4 4 4
52467+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
52468+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
52469+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52470+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
52471+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
52472+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
52473+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
52474+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
52475+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
52476+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
52477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52480+4 4 4 4 4 4
52481+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52482+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
52483+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
52484+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
52485+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
52486+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
52487+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
52488+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
52489+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
52490+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52494+4 4 4 4 4 4
52495+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
52496+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
52497+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
52498+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
52499+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
52500+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
52501+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
52502+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
52503+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
52504+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
52505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52508+4 4 4 4 4 4
52509+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
52510+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
52511+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
52512+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
52513+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
52514+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
52515+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
52516+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
52517+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
52518+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52522+4 4 4 4 4 4
52523+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
52524+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52525+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
52526+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52527+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
52528+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
52529+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
52530+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
52531+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
52532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52536+4 4 4 4 4 4
52537+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
52538+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
52539+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
52540+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
52541+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
52542+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
52543+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
52544+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
52545+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
52546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52550+4 4 4 4 4 4
52551+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52552+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
52553+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
52554+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
52555+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
52556+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
52557+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
52558+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
52559+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52564+4 4 4 4 4 4
52565+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
52566+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
52567+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52568+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
52569+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
52570+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
52571+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
52572+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
52573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52578+4 4 4 4 4 4
52579+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52580+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
52581+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
52582+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
52583+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
52584+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
52585+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
52586+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52592+4 4 4 4 4 4
52593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52594+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
52595+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52596+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
52597+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
52598+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
52599+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
52600+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
52601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52606+4 4 4 4 4 4
52607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52608+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
52609+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
52610+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
52611+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
52612+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
52613+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
52614+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
52615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52620+4 4 4 4 4 4
52621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52622+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
52623+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
52624+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52625+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
52626+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
52627+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
52628+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52634+4 4 4 4 4 4
52635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52637+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52638+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
52639+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
52640+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
52641+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
52642+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52648+4 4 4 4 4 4
52649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52652+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52653+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
52654+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
52655+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
52656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52662+4 4 4 4 4 4
52663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52666+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52667+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52668+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
52669+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
52670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52676+4 4 4 4 4 4
52677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52680+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52681+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52682+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52683+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
52684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52690+4 4 4 4 4 4
52691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52694+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
52695+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
52696+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
52697+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
52698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52704+4 4 4 4 4 4
52705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52709+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
52710+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52711+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52718+4 4 4 4 4 4
52719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52723+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
52724+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
52725+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52732+4 4 4 4 4 4
52733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52737+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
52738+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
52739+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52746+4 4 4 4 4 4
52747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52751+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
52752+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
52753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52760+4 4 4 4 4 4
52761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52765+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52766+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
52767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52774+4 4 4 4 4 4
52775diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
52776index fe92eed..106e085 100644
52777--- a/drivers/video/mb862xx/mb862xxfb_accel.c
52778+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
52779@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52780 struct mb862xxfb_par *par = info->par;
52781
52782 if (info->var.bits_per_pixel == 32) {
52783- info->fbops->fb_fillrect = cfb_fillrect;
52784- info->fbops->fb_copyarea = cfb_copyarea;
52785- info->fbops->fb_imageblit = cfb_imageblit;
52786+ pax_open_kernel();
52787+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52788+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52789+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52790+ pax_close_kernel();
52791 } else {
52792 outreg(disp, GC_L0EM, 3);
52793- info->fbops->fb_fillrect = mb86290fb_fillrect;
52794- info->fbops->fb_copyarea = mb86290fb_copyarea;
52795- info->fbops->fb_imageblit = mb86290fb_imageblit;
52796+ pax_open_kernel();
52797+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52798+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52799+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52800+ pax_close_kernel();
52801 }
52802 outreg(draw, GDC_REG_DRAW_BASE, 0);
52803 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52804diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
52805index ff22871..b129bed 100644
52806--- a/drivers/video/nvidia/nvidia.c
52807+++ b/drivers/video/nvidia/nvidia.c
52808@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52809 info->fix.line_length = (info->var.xres_virtual *
52810 info->var.bits_per_pixel) >> 3;
52811 if (info->var.accel_flags) {
52812- info->fbops->fb_imageblit = nvidiafb_imageblit;
52813- info->fbops->fb_fillrect = nvidiafb_fillrect;
52814- info->fbops->fb_copyarea = nvidiafb_copyarea;
52815- info->fbops->fb_sync = nvidiafb_sync;
52816+ pax_open_kernel();
52817+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52818+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52819+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52820+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52821+ pax_close_kernel();
52822 info->pixmap.scan_align = 4;
52823 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52824 info->flags |= FBINFO_READS_FAST;
52825 NVResetGraphics(info);
52826 } else {
52827- info->fbops->fb_imageblit = cfb_imageblit;
52828- info->fbops->fb_fillrect = cfb_fillrect;
52829- info->fbops->fb_copyarea = cfb_copyarea;
52830- info->fbops->fb_sync = NULL;
52831+ pax_open_kernel();
52832+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52833+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52834+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52835+ *(void **)&info->fbops->fb_sync = NULL;
52836+ pax_close_kernel();
52837 info->pixmap.scan_align = 1;
52838 info->flags |= FBINFO_HWACCEL_DISABLED;
52839 info->flags &= ~FBINFO_READS_FAST;
52840@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52841 info->pixmap.size = 8 * 1024;
52842 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52843
52844- if (!hwcur)
52845- info->fbops->fb_cursor = NULL;
52846+ if (!hwcur) {
52847+ pax_open_kernel();
52848+ *(void **)&info->fbops->fb_cursor = NULL;
52849+ pax_close_kernel();
52850+ }
52851
52852 info->var.accel_flags = (!noaccel);
52853
52854diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
52855index fafe7c9..93197b9 100644
52856--- a/drivers/video/omap2/dss/display.c
52857+++ b/drivers/video/omap2/dss/display.c
52858@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52859 snprintf(dssdev->alias, sizeof(dssdev->alias),
52860 "display%d", disp_num_counter++);
52861
52862+ pax_open_kernel();
52863 if (drv && drv->get_resolution == NULL)
52864- drv->get_resolution = omapdss_default_get_resolution;
52865+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52866 if (drv && drv->get_recommended_bpp == NULL)
52867- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52868+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52869 if (drv && drv->get_timings == NULL)
52870- drv->get_timings = omapdss_default_get_timings;
52871+ *(void **)&drv->get_timings = omapdss_default_get_timings;
52872+ pax_close_kernel();
52873
52874 mutex_lock(&panel_list_mutex);
52875 list_add_tail(&dssdev->panel_list, &panel_list);
52876diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
52877index 05c2dc3..ea1f391 100644
52878--- a/drivers/video/s1d13xxxfb.c
52879+++ b/drivers/video/s1d13xxxfb.c
52880@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52881
52882 switch(prod_id) {
52883 case S1D13506_PROD_ID: /* activate acceleration */
52884- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52885- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52886+ pax_open_kernel();
52887+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52888+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52889+ pax_close_kernel();
52890 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52891 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52892 break;
52893diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
52894index e188ada..aac63c8 100644
52895--- a/drivers/video/smscufx.c
52896+++ b/drivers/video/smscufx.c
52897@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52898 fb_deferred_io_cleanup(info);
52899 kfree(info->fbdefio);
52900 info->fbdefio = NULL;
52901- info->fbops->fb_mmap = ufx_ops_mmap;
52902+ pax_open_kernel();
52903+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52904+ pax_close_kernel();
52905 }
52906
52907 pr_debug("released /dev/fb%d user=%d count=%d",
52908diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
52909index d2e5bc3..4cb05d1 100644
52910--- a/drivers/video/udlfb.c
52911+++ b/drivers/video/udlfb.c
52912@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52913 dlfb_urb_completion(urb);
52914
52915 error:
52916- atomic_add(bytes_sent, &dev->bytes_sent);
52917- atomic_add(bytes_identical, &dev->bytes_identical);
52918- atomic_add(width*height*2, &dev->bytes_rendered);
52919+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52920+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52921+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52922 end_cycles = get_cycles();
52923- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52924+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52925 >> 10)), /* Kcycles */
52926 &dev->cpu_kcycles_used);
52927
52928@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52929 dlfb_urb_completion(urb);
52930
52931 error:
52932- atomic_add(bytes_sent, &dev->bytes_sent);
52933- atomic_add(bytes_identical, &dev->bytes_identical);
52934- atomic_add(bytes_rendered, &dev->bytes_rendered);
52935+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52936+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52937+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52938 end_cycles = get_cycles();
52939- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52940+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52941 >> 10)), /* Kcycles */
52942 &dev->cpu_kcycles_used);
52943 }
52944@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52945 fb_deferred_io_cleanup(info);
52946 kfree(info->fbdefio);
52947 info->fbdefio = NULL;
52948- info->fbops->fb_mmap = dlfb_ops_mmap;
52949+ pax_open_kernel();
52950+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52951+ pax_close_kernel();
52952 }
52953
52954 pr_warn("released /dev/fb%d user=%d count=%d\n",
52955@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52956 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52957 struct dlfb_data *dev = fb_info->par;
52958 return snprintf(buf, PAGE_SIZE, "%u\n",
52959- atomic_read(&dev->bytes_rendered));
52960+ atomic_read_unchecked(&dev->bytes_rendered));
52961 }
52962
52963 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52964@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52965 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52966 struct dlfb_data *dev = fb_info->par;
52967 return snprintf(buf, PAGE_SIZE, "%u\n",
52968- atomic_read(&dev->bytes_identical));
52969+ atomic_read_unchecked(&dev->bytes_identical));
52970 }
52971
52972 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52973@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52974 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52975 struct dlfb_data *dev = fb_info->par;
52976 return snprintf(buf, PAGE_SIZE, "%u\n",
52977- atomic_read(&dev->bytes_sent));
52978+ atomic_read_unchecked(&dev->bytes_sent));
52979 }
52980
52981 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52982@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52983 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52984 struct dlfb_data *dev = fb_info->par;
52985 return snprintf(buf, PAGE_SIZE, "%u\n",
52986- atomic_read(&dev->cpu_kcycles_used));
52987+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52988 }
52989
52990 static ssize_t edid_show(
52991@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52992 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52993 struct dlfb_data *dev = fb_info->par;
52994
52995- atomic_set(&dev->bytes_rendered, 0);
52996- atomic_set(&dev->bytes_identical, 0);
52997- atomic_set(&dev->bytes_sent, 0);
52998- atomic_set(&dev->cpu_kcycles_used, 0);
52999+ atomic_set_unchecked(&dev->bytes_rendered, 0);
53000+ atomic_set_unchecked(&dev->bytes_identical, 0);
53001+ atomic_set_unchecked(&dev->bytes_sent, 0);
53002+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53003
53004 return count;
53005 }
53006diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
53007index 7aec6f3..e3b2d55 100644
53008--- a/drivers/video/uvesafb.c
53009+++ b/drivers/video/uvesafb.c
53010@@ -19,6 +19,7 @@
53011 #include <linux/io.h>
53012 #include <linux/mutex.h>
53013 #include <linux/slab.h>
53014+#include <linux/moduleloader.h>
53015 #include <video/edid.h>
53016 #include <video/uvesafb.h>
53017 #ifdef CONFIG_X86
53018@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53019 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53020 par->pmi_setpal = par->ypan = 0;
53021 } else {
53022+
53023+#ifdef CONFIG_PAX_KERNEXEC
53024+#ifdef CONFIG_MODULES
53025+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53026+#endif
53027+ if (!par->pmi_code) {
53028+ par->pmi_setpal = par->ypan = 0;
53029+ return 0;
53030+ }
53031+#endif
53032+
53033 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53034 + task->t.regs.edi);
53035+
53036+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53037+ pax_open_kernel();
53038+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53039+ pax_close_kernel();
53040+
53041+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53042+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53043+#else
53044 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53045 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53046+#endif
53047+
53048 printk(KERN_INFO "uvesafb: protected mode interface info at "
53049 "%04x:%04x\n",
53050 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53051@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53052 par->ypan = ypan;
53053
53054 if (par->pmi_setpal || par->ypan) {
53055+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53056 if (__supported_pte_mask & _PAGE_NX) {
53057 par->pmi_setpal = par->ypan = 0;
53058 printk(KERN_WARNING "uvesafb: NX protection is active, "
53059 "better not use the PMI.\n");
53060- } else {
53061+ } else
53062+#endif
53063 uvesafb_vbe_getpmi(task, par);
53064- }
53065 }
53066 #else
53067 /* The protected mode interface is not available on non-x86. */
53068@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53069 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53070
53071 /* Disable blanking if the user requested so. */
53072- if (!blank)
53073- info->fbops->fb_blank = NULL;
53074+ if (!blank) {
53075+ pax_open_kernel();
53076+ *(void **)&info->fbops->fb_blank = NULL;
53077+ pax_close_kernel();
53078+ }
53079
53080 /*
53081 * Find out how much IO memory is required for the mode with
53082@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53083 info->flags = FBINFO_FLAG_DEFAULT |
53084 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53085
53086- if (!par->ypan)
53087- info->fbops->fb_pan_display = NULL;
53088+ if (!par->ypan) {
53089+ pax_open_kernel();
53090+ *(void **)&info->fbops->fb_pan_display = NULL;
53091+ pax_close_kernel();
53092+ }
53093 }
53094
53095 static void uvesafb_init_mtrr(struct fb_info *info)
53096@@ -1796,6 +1826,11 @@ out:
53097 if (par->vbe_modes)
53098 kfree(par->vbe_modes);
53099
53100+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53101+ if (par->pmi_code)
53102+ module_free_exec(NULL, par->pmi_code);
53103+#endif
53104+
53105 framebuffer_release(info);
53106 return err;
53107 }
53108@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
53109 kfree(par->vbe_state_orig);
53110 if (par->vbe_state_saved)
53111 kfree(par->vbe_state_saved);
53112+
53113+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53114+ if (par->pmi_code)
53115+ module_free_exec(NULL, par->pmi_code);
53116+#endif
53117+
53118 }
53119
53120 framebuffer_release(info);
53121diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
53122index bd83233..7d8a5aa 100644
53123--- a/drivers/video/vesafb.c
53124+++ b/drivers/video/vesafb.c
53125@@ -9,6 +9,7 @@
53126 */
53127
53128 #include <linux/module.h>
53129+#include <linux/moduleloader.h>
53130 #include <linux/kernel.h>
53131 #include <linux/errno.h>
53132 #include <linux/string.h>
53133@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53134 static int vram_total; /* Set total amount of memory */
53135 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53136 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53137-static void (*pmi_start)(void) __read_mostly;
53138-static void (*pmi_pal) (void) __read_mostly;
53139+static void (*pmi_start)(void) __read_only;
53140+static void (*pmi_pal) (void) __read_only;
53141 static int depth __read_mostly;
53142 static int vga_compat __read_mostly;
53143 /* --------------------------------------------------------------------- */
53144@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
53145 unsigned int size_remap;
53146 unsigned int size_total;
53147 char *option = NULL;
53148+ void *pmi_code = NULL;
53149
53150 /* ignore error return of fb_get_options */
53151 fb_get_options("vesafb", &option);
53152@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
53153 size_remap = size_total;
53154 vesafb_fix.smem_len = size_remap;
53155
53156-#ifndef __i386__
53157- screen_info.vesapm_seg = 0;
53158-#endif
53159-
53160 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53161 printk(KERN_WARNING
53162 "vesafb: cannot reserve video memory at 0x%lx\n",
53163@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53164 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53165 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53166
53167+#ifdef __i386__
53168+
53169+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53170+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
53171+ if (!pmi_code)
53172+#elif !defined(CONFIG_PAX_KERNEXEC)
53173+ if (0)
53174+#endif
53175+
53176+#endif
53177+ screen_info.vesapm_seg = 0;
53178+
53179 if (screen_info.vesapm_seg) {
53180- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53181- screen_info.vesapm_seg,screen_info.vesapm_off);
53182+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53183+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53184 }
53185
53186 if (screen_info.vesapm_seg < 0xc000)
53187@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53188
53189 if (ypan || pmi_setpal) {
53190 unsigned short *pmi_base;
53191+
53192 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53193- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53194- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53195+
53196+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53197+ pax_open_kernel();
53198+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53199+#else
53200+ pmi_code = pmi_base;
53201+#endif
53202+
53203+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53204+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53205+
53206+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53207+ pmi_start = ktva_ktla(pmi_start);
53208+ pmi_pal = ktva_ktla(pmi_pal);
53209+ pax_close_kernel();
53210+#endif
53211+
53212 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53213 if (pmi_base[3]) {
53214 printk(KERN_INFO "vesafb: pmi: ports = ");
53215@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53216 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53217 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53218
53219- if (!ypan)
53220- info->fbops->fb_pan_display = NULL;
53221+ if (!ypan) {
53222+ pax_open_kernel();
53223+ *(void **)&info->fbops->fb_pan_display = NULL;
53224+ pax_close_kernel();
53225+ }
53226
53227 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53228 err = -ENOMEM;
53229@@ -493,6 +522,11 @@ static int vesafb_probe(struct platform_device *dev)
53230 info->node, info->fix.id);
53231 return 0;
53232 err:
53233+
53234+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53235+ module_free_exec(NULL, pmi_code);
53236+#endif
53237+
53238 if (info->screen_base)
53239 iounmap(info->screen_base);
53240 framebuffer_release(info);
53241diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
53242index 88714ae..16c2e11 100644
53243--- a/drivers/video/via/via_clock.h
53244+++ b/drivers/video/via/via_clock.h
53245@@ -56,7 +56,7 @@ struct via_clock {
53246
53247 void (*set_engine_pll_state)(u8 state);
53248 void (*set_engine_pll)(struct via_pll_config config);
53249-};
53250+} __no_const;
53251
53252
53253 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53254diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
53255index fef20db..d28b1ab 100644
53256--- a/drivers/xen/xenfs/xenstored.c
53257+++ b/drivers/xen/xenfs/xenstored.c
53258@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
53259 static int xsd_kva_open(struct inode *inode, struct file *file)
53260 {
53261 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
53262+#ifdef CONFIG_GRKERNSEC_HIDESYM
53263+ NULL);
53264+#else
53265 xen_store_interface);
53266+#endif
53267+
53268 if (!file->private_data)
53269 return -ENOMEM;
53270 return 0;
53271diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
53272index 9ff073f..05cef23 100644
53273--- a/fs/9p/vfs_addr.c
53274+++ b/fs/9p/vfs_addr.c
53275@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
53276
53277 retval = v9fs_file_write_internal(inode,
53278 v9inode->writeback_fid,
53279- (__force const char __user *)buffer,
53280+ (const char __force_user *)buffer,
53281 len, &offset, 0);
53282 if (retval > 0)
53283 retval = 0;
53284diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
53285index 94de6d1..8d81256 100644
53286--- a/fs/9p/vfs_inode.c
53287+++ b/fs/9p/vfs_inode.c
53288@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53289 void
53290 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53291 {
53292- char *s = nd_get_link(nd);
53293+ const char *s = nd_get_link(nd);
53294
53295 p9_debug(P9_DEBUG_VFS, " %s %s\n",
53296 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
53297diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
53298index 370b24c..ff0be7b 100644
53299--- a/fs/Kconfig.binfmt
53300+++ b/fs/Kconfig.binfmt
53301@@ -103,7 +103,7 @@ config HAVE_AOUT
53302
53303 config BINFMT_AOUT
53304 tristate "Kernel support for a.out and ECOFF binaries"
53305- depends on HAVE_AOUT
53306+ depends on HAVE_AOUT && BROKEN
53307 ---help---
53308 A.out (Assembler.OUTput) is a set of formats for libraries and
53309 executables used in the earliest versions of UNIX. Linux used
53310diff --git a/fs/afs/inode.c b/fs/afs/inode.c
53311index 789bc25..fafaeea 100644
53312--- a/fs/afs/inode.c
53313+++ b/fs/afs/inode.c
53314@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53315 struct afs_vnode *vnode;
53316 struct super_block *sb;
53317 struct inode *inode;
53318- static atomic_t afs_autocell_ino;
53319+ static atomic_unchecked_t afs_autocell_ino;
53320
53321 _enter("{%x:%u},%*.*s,",
53322 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
53323@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53324 data.fid.unique = 0;
53325 data.fid.vnode = 0;
53326
53327- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
53328+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
53329 afs_iget5_autocell_test, afs_iget5_set,
53330 &data);
53331 if (!inode) {
53332diff --git a/fs/aio.c b/fs/aio.c
53333index 6efb7f6..ec354de 100644
53334--- a/fs/aio.c
53335+++ b/fs/aio.c
53336@@ -338,7 +338,7 @@ static int aio_setup_ring(struct kioctx *ctx)
53337 size += sizeof(struct io_event) * nr_events;
53338
53339 nr_pages = PFN_UP(size);
53340- if (nr_pages < 0)
53341+ if (nr_pages <= 0)
53342 return -EINVAL;
53343
53344 file = aio_private_file(ctx, nr_pages);
53345@@ -652,7 +652,8 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
53346 aio_nr += ctx->max_reqs;
53347 spin_unlock(&aio_nr_lock);
53348
53349- percpu_ref_get(&ctx->users); /* io_setup() will drop this ref */
53350+ percpu_ref_get(&ctx->users); /* io_setup() will drop this ref */
53351+ percpu_ref_get(&ctx->reqs); /* free_ioctx_users() will drop this */
53352
53353 err = ioctx_add_table(ctx, mm);
53354 if (err)
53355diff --git a/fs/attr.c b/fs/attr.c
53356index 1449adb..a2038c2 100644
53357--- a/fs/attr.c
53358+++ b/fs/attr.c
53359@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
53360 unsigned long limit;
53361
53362 limit = rlimit(RLIMIT_FSIZE);
53363+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
53364 if (limit != RLIM_INFINITY && offset > limit)
53365 goto out_sig;
53366 if (offset > inode->i_sb->s_maxbytes)
53367diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
53368index 689e40d..515cac5 100644
53369--- a/fs/autofs4/waitq.c
53370+++ b/fs/autofs4/waitq.c
53371@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
53372 {
53373 unsigned long sigpipe, flags;
53374 mm_segment_t fs;
53375- const char *data = (const char *)addr;
53376+ const char __user *data = (const char __force_user *)addr;
53377 ssize_t wr = 0;
53378
53379 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
53380@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
53381 return 1;
53382 }
53383
53384+#ifdef CONFIG_GRKERNSEC_HIDESYM
53385+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
53386+#endif
53387+
53388 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53389 enum autofs_notify notify)
53390 {
53391@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53392
53393 /* If this is a direct mount request create a dummy name */
53394 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
53395+#ifdef CONFIG_GRKERNSEC_HIDESYM
53396+ /* this name does get written to userland via autofs4_write() */
53397+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
53398+#else
53399 qstr.len = sprintf(name, "%p", dentry);
53400+#endif
53401 else {
53402 qstr.len = autofs4_getpath(sbi, dentry, &name);
53403 if (!qstr.len) {
53404diff --git a/fs/befs/endian.h b/fs/befs/endian.h
53405index 2722387..56059b5 100644
53406--- a/fs/befs/endian.h
53407+++ b/fs/befs/endian.h
53408@@ -11,7 +11,7 @@
53409
53410 #include <asm/byteorder.h>
53411
53412-static inline u64
53413+static inline u64 __intentional_overflow(-1)
53414 fs64_to_cpu(const struct super_block *sb, fs64 n)
53415 {
53416 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53417@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
53418 return (__force fs64)cpu_to_be64(n);
53419 }
53420
53421-static inline u32
53422+static inline u32 __intentional_overflow(-1)
53423 fs32_to_cpu(const struct super_block *sb, fs32 n)
53424 {
53425 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53426@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
53427 return (__force fs32)cpu_to_be32(n);
53428 }
53429
53430-static inline u16
53431+static inline u16 __intentional_overflow(-1)
53432 fs16_to_cpu(const struct super_block *sb, fs16 n)
53433 {
53434 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53435diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
53436index e9c75e2..1baece1 100644
53437--- a/fs/befs/linuxvfs.c
53438+++ b/fs/befs/linuxvfs.c
53439@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53440 {
53441 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
53442 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
53443- char *link = nd_get_link(nd);
53444+ const char *link = nd_get_link(nd);
53445 if (!IS_ERR(link))
53446 kfree(link);
53447 }
53448diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
53449index 89dec7f..361b0d75 100644
53450--- a/fs/binfmt_aout.c
53451+++ b/fs/binfmt_aout.c
53452@@ -16,6 +16,7 @@
53453 #include <linux/string.h>
53454 #include <linux/fs.h>
53455 #include <linux/file.h>
53456+#include <linux/security.h>
53457 #include <linux/stat.h>
53458 #include <linux/fcntl.h>
53459 #include <linux/ptrace.h>
53460@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
53461 #endif
53462 # define START_STACK(u) ((void __user *)u.start_stack)
53463
53464+ memset(&dump, 0, sizeof(dump));
53465+
53466 fs = get_fs();
53467 set_fs(KERNEL_DS);
53468 has_dumped = 1;
53469@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
53470
53471 /* If the size of the dump file exceeds the rlimit, then see what would happen
53472 if we wrote the stack, but not the data area. */
53473+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
53474 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
53475 dump.u_dsize = 0;
53476
53477 /* Make sure we have enough room to write the stack and data areas. */
53478+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
53479 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
53480 dump.u_ssize = 0;
53481
53482@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
53483 rlim = rlimit(RLIMIT_DATA);
53484 if (rlim >= RLIM_INFINITY)
53485 rlim = ~0;
53486+
53487+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
53488 if (ex.a_data + ex.a_bss > rlim)
53489 return -ENOMEM;
53490
53491@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
53492
53493 install_exec_creds(bprm);
53494
53495+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53496+ current->mm->pax_flags = 0UL;
53497+#endif
53498+
53499+#ifdef CONFIG_PAX_PAGEEXEC
53500+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
53501+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
53502+
53503+#ifdef CONFIG_PAX_EMUTRAMP
53504+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
53505+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
53506+#endif
53507+
53508+#ifdef CONFIG_PAX_MPROTECT
53509+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
53510+ current->mm->pax_flags |= MF_PAX_MPROTECT;
53511+#endif
53512+
53513+ }
53514+#endif
53515+
53516 if (N_MAGIC(ex) == OMAGIC) {
53517 unsigned long text_addr, map_size;
53518 loff_t pos;
53519@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
53520 }
53521
53522 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
53523- PROT_READ | PROT_WRITE | PROT_EXEC,
53524+ PROT_READ | PROT_WRITE,
53525 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
53526 fd_offset + ex.a_text);
53527 if (error != N_DATADDR(ex)) {
53528diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
53529index 4c94a79..2610454 100644
53530--- a/fs/binfmt_elf.c
53531+++ b/fs/binfmt_elf.c
53532@@ -34,6 +34,7 @@
53533 #include <linux/utsname.h>
53534 #include <linux/coredump.h>
53535 #include <linux/sched.h>
53536+#include <linux/xattr.h>
53537 #include <asm/uaccess.h>
53538 #include <asm/param.h>
53539 #include <asm/page.h>
53540@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
53541 #define elf_core_dump NULL
53542 #endif
53543
53544+#ifdef CONFIG_PAX_MPROTECT
53545+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
53546+#endif
53547+
53548+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53549+static void elf_handle_mmap(struct file *file);
53550+#endif
53551+
53552 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
53553 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
53554 #else
53555@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
53556 .load_binary = load_elf_binary,
53557 .load_shlib = load_elf_library,
53558 .core_dump = elf_core_dump,
53559+
53560+#ifdef CONFIG_PAX_MPROTECT
53561+ .handle_mprotect= elf_handle_mprotect,
53562+#endif
53563+
53564+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53565+ .handle_mmap = elf_handle_mmap,
53566+#endif
53567+
53568 .min_coredump = ELF_EXEC_PAGESIZE,
53569 };
53570
53571@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
53572
53573 static int set_brk(unsigned long start, unsigned long end)
53574 {
53575+ unsigned long e = end;
53576+
53577 start = ELF_PAGEALIGN(start);
53578 end = ELF_PAGEALIGN(end);
53579 if (end > start) {
53580@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
53581 if (BAD_ADDR(addr))
53582 return addr;
53583 }
53584- current->mm->start_brk = current->mm->brk = end;
53585+ current->mm->start_brk = current->mm->brk = e;
53586 return 0;
53587 }
53588
53589@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53590 elf_addr_t __user *u_rand_bytes;
53591 const char *k_platform = ELF_PLATFORM;
53592 const char *k_base_platform = ELF_BASE_PLATFORM;
53593- unsigned char k_rand_bytes[16];
53594+ u32 k_rand_bytes[4];
53595 int items;
53596 elf_addr_t *elf_info;
53597 int ei_index = 0;
53598 const struct cred *cred = current_cred();
53599 struct vm_area_struct *vma;
53600+ unsigned long saved_auxv[AT_VECTOR_SIZE];
53601
53602 /*
53603 * In some cases (e.g. Hyper-Threading), we want to avoid L1
53604@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53605 * Generate 16 random bytes for userspace PRNG seeding.
53606 */
53607 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
53608- u_rand_bytes = (elf_addr_t __user *)
53609- STACK_ALLOC(p, sizeof(k_rand_bytes));
53610+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
53611+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
53612+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
53613+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
53614+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
53615+ u_rand_bytes = (elf_addr_t __user *) p;
53616 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
53617 return -EFAULT;
53618
53619@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53620 return -EFAULT;
53621 current->mm->env_end = p;
53622
53623+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
53624+
53625 /* Put the elf_info on the stack in the right place. */
53626 sp = (elf_addr_t __user *)envp + 1;
53627- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
53628+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
53629 return -EFAULT;
53630 return 0;
53631 }
53632@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
53633 an ELF header */
53634
53635 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53636- struct file *interpreter, unsigned long *interp_map_addr,
53637- unsigned long no_base)
53638+ struct file *interpreter, unsigned long no_base)
53639 {
53640 struct elf_phdr *elf_phdata;
53641 struct elf_phdr *eppnt;
53642- unsigned long load_addr = 0;
53643+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
53644 int load_addr_set = 0;
53645 unsigned long last_bss = 0, elf_bss = 0;
53646- unsigned long error = ~0UL;
53647+ unsigned long error = -EINVAL;
53648 unsigned long total_size;
53649 int retval, i, size;
53650
53651@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53652 goto out_close;
53653 }
53654
53655+#ifdef CONFIG_PAX_SEGMEXEC
53656+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
53657+ pax_task_size = SEGMEXEC_TASK_SIZE;
53658+#endif
53659+
53660 eppnt = elf_phdata;
53661 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
53662 if (eppnt->p_type == PT_LOAD) {
53663@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53664 map_addr = elf_map(interpreter, load_addr + vaddr,
53665 eppnt, elf_prot, elf_type, total_size);
53666 total_size = 0;
53667- if (!*interp_map_addr)
53668- *interp_map_addr = map_addr;
53669 error = map_addr;
53670 if (BAD_ADDR(map_addr))
53671 goto out_close;
53672@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53673 k = load_addr + eppnt->p_vaddr;
53674 if (BAD_ADDR(k) ||
53675 eppnt->p_filesz > eppnt->p_memsz ||
53676- eppnt->p_memsz > TASK_SIZE ||
53677- TASK_SIZE - eppnt->p_memsz < k) {
53678+ eppnt->p_memsz > pax_task_size ||
53679+ pax_task_size - eppnt->p_memsz < k) {
53680 error = -ENOMEM;
53681 goto out_close;
53682 }
53683@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53684 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
53685
53686 /* Map the last of the bss segment */
53687- error = vm_brk(elf_bss, last_bss - elf_bss);
53688- if (BAD_ADDR(error))
53689- goto out_close;
53690+ if (last_bss > elf_bss) {
53691+ error = vm_brk(elf_bss, last_bss - elf_bss);
53692+ if (BAD_ADDR(error))
53693+ goto out_close;
53694+ }
53695 }
53696
53697 error = load_addr;
53698@@ -538,6 +569,315 @@ out:
53699 return error;
53700 }
53701
53702+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53703+#ifdef CONFIG_PAX_SOFTMODE
53704+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
53705+{
53706+ unsigned long pax_flags = 0UL;
53707+
53708+#ifdef CONFIG_PAX_PAGEEXEC
53709+ if (elf_phdata->p_flags & PF_PAGEEXEC)
53710+ pax_flags |= MF_PAX_PAGEEXEC;
53711+#endif
53712+
53713+#ifdef CONFIG_PAX_SEGMEXEC
53714+ if (elf_phdata->p_flags & PF_SEGMEXEC)
53715+ pax_flags |= MF_PAX_SEGMEXEC;
53716+#endif
53717+
53718+#ifdef CONFIG_PAX_EMUTRAMP
53719+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53720+ pax_flags |= MF_PAX_EMUTRAMP;
53721+#endif
53722+
53723+#ifdef CONFIG_PAX_MPROTECT
53724+ if (elf_phdata->p_flags & PF_MPROTECT)
53725+ pax_flags |= MF_PAX_MPROTECT;
53726+#endif
53727+
53728+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53729+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
53730+ pax_flags |= MF_PAX_RANDMMAP;
53731+#endif
53732+
53733+ return pax_flags;
53734+}
53735+#endif
53736+
53737+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
53738+{
53739+ unsigned long pax_flags = 0UL;
53740+
53741+#ifdef CONFIG_PAX_PAGEEXEC
53742+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
53743+ pax_flags |= MF_PAX_PAGEEXEC;
53744+#endif
53745+
53746+#ifdef CONFIG_PAX_SEGMEXEC
53747+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
53748+ pax_flags |= MF_PAX_SEGMEXEC;
53749+#endif
53750+
53751+#ifdef CONFIG_PAX_EMUTRAMP
53752+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
53753+ pax_flags |= MF_PAX_EMUTRAMP;
53754+#endif
53755+
53756+#ifdef CONFIG_PAX_MPROTECT
53757+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
53758+ pax_flags |= MF_PAX_MPROTECT;
53759+#endif
53760+
53761+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53762+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
53763+ pax_flags |= MF_PAX_RANDMMAP;
53764+#endif
53765+
53766+ return pax_flags;
53767+}
53768+#endif
53769+
53770+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53771+#ifdef CONFIG_PAX_SOFTMODE
53772+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
53773+{
53774+ unsigned long pax_flags = 0UL;
53775+
53776+#ifdef CONFIG_PAX_PAGEEXEC
53777+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
53778+ pax_flags |= MF_PAX_PAGEEXEC;
53779+#endif
53780+
53781+#ifdef CONFIG_PAX_SEGMEXEC
53782+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
53783+ pax_flags |= MF_PAX_SEGMEXEC;
53784+#endif
53785+
53786+#ifdef CONFIG_PAX_EMUTRAMP
53787+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53788+ pax_flags |= MF_PAX_EMUTRAMP;
53789+#endif
53790+
53791+#ifdef CONFIG_PAX_MPROTECT
53792+ if (pax_flags_softmode & MF_PAX_MPROTECT)
53793+ pax_flags |= MF_PAX_MPROTECT;
53794+#endif
53795+
53796+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53797+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
53798+ pax_flags |= MF_PAX_RANDMMAP;
53799+#endif
53800+
53801+ return pax_flags;
53802+}
53803+#endif
53804+
53805+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
53806+{
53807+ unsigned long pax_flags = 0UL;
53808+
53809+#ifdef CONFIG_PAX_PAGEEXEC
53810+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
53811+ pax_flags |= MF_PAX_PAGEEXEC;
53812+#endif
53813+
53814+#ifdef CONFIG_PAX_SEGMEXEC
53815+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
53816+ pax_flags |= MF_PAX_SEGMEXEC;
53817+#endif
53818+
53819+#ifdef CONFIG_PAX_EMUTRAMP
53820+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
53821+ pax_flags |= MF_PAX_EMUTRAMP;
53822+#endif
53823+
53824+#ifdef CONFIG_PAX_MPROTECT
53825+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
53826+ pax_flags |= MF_PAX_MPROTECT;
53827+#endif
53828+
53829+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53830+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
53831+ pax_flags |= MF_PAX_RANDMMAP;
53832+#endif
53833+
53834+ return pax_flags;
53835+}
53836+#endif
53837+
53838+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53839+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
53840+{
53841+ unsigned long pax_flags = 0UL;
53842+
53843+#ifdef CONFIG_PAX_EI_PAX
53844+
53845+#ifdef CONFIG_PAX_PAGEEXEC
53846+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
53847+ pax_flags |= MF_PAX_PAGEEXEC;
53848+#endif
53849+
53850+#ifdef CONFIG_PAX_SEGMEXEC
53851+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
53852+ pax_flags |= MF_PAX_SEGMEXEC;
53853+#endif
53854+
53855+#ifdef CONFIG_PAX_EMUTRAMP
53856+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
53857+ pax_flags |= MF_PAX_EMUTRAMP;
53858+#endif
53859+
53860+#ifdef CONFIG_PAX_MPROTECT
53861+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
53862+ pax_flags |= MF_PAX_MPROTECT;
53863+#endif
53864+
53865+#ifdef CONFIG_PAX_ASLR
53866+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
53867+ pax_flags |= MF_PAX_RANDMMAP;
53868+#endif
53869+
53870+#else
53871+
53872+#ifdef CONFIG_PAX_PAGEEXEC
53873+ pax_flags |= MF_PAX_PAGEEXEC;
53874+#endif
53875+
53876+#ifdef CONFIG_PAX_SEGMEXEC
53877+ pax_flags |= MF_PAX_SEGMEXEC;
53878+#endif
53879+
53880+#ifdef CONFIG_PAX_MPROTECT
53881+ pax_flags |= MF_PAX_MPROTECT;
53882+#endif
53883+
53884+#ifdef CONFIG_PAX_RANDMMAP
53885+ if (randomize_va_space)
53886+ pax_flags |= MF_PAX_RANDMMAP;
53887+#endif
53888+
53889+#endif
53890+
53891+ return pax_flags;
53892+}
53893+
53894+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
53895+{
53896+
53897+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53898+ unsigned long i;
53899+
53900+ for (i = 0UL; i < elf_ex->e_phnum; i++)
53901+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
53902+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
53903+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
53904+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
53905+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
53906+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
53907+ return ~0UL;
53908+
53909+#ifdef CONFIG_PAX_SOFTMODE
53910+ if (pax_softmode)
53911+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
53912+ else
53913+#endif
53914+
53915+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
53916+ break;
53917+ }
53918+#endif
53919+
53920+ return ~0UL;
53921+}
53922+
53923+static unsigned long pax_parse_xattr_pax(struct file * const file)
53924+{
53925+
53926+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53927+ ssize_t xattr_size, i;
53928+ unsigned char xattr_value[sizeof("pemrs") - 1];
53929+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
53930+
53931+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
53932+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
53933+ return ~0UL;
53934+
53935+ for (i = 0; i < xattr_size; i++)
53936+ switch (xattr_value[i]) {
53937+ default:
53938+ return ~0UL;
53939+
53940+#define parse_flag(option1, option2, flag) \
53941+ case option1: \
53942+ if (pax_flags_hardmode & MF_PAX_##flag) \
53943+ return ~0UL; \
53944+ pax_flags_hardmode |= MF_PAX_##flag; \
53945+ break; \
53946+ case option2: \
53947+ if (pax_flags_softmode & MF_PAX_##flag) \
53948+ return ~0UL; \
53949+ pax_flags_softmode |= MF_PAX_##flag; \
53950+ break;
53951+
53952+ parse_flag('p', 'P', PAGEEXEC);
53953+ parse_flag('e', 'E', EMUTRAMP);
53954+ parse_flag('m', 'M', MPROTECT);
53955+ parse_flag('r', 'R', RANDMMAP);
53956+ parse_flag('s', 'S', SEGMEXEC);
53957+
53958+#undef parse_flag
53959+ }
53960+
53961+ if (pax_flags_hardmode & pax_flags_softmode)
53962+ return ~0UL;
53963+
53964+#ifdef CONFIG_PAX_SOFTMODE
53965+ if (pax_softmode)
53966+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
53967+ else
53968+#endif
53969+
53970+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
53971+#else
53972+ return ~0UL;
53973+#endif
53974+
53975+}
53976+
53977+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
53978+{
53979+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
53980+
53981+ pax_flags = pax_parse_ei_pax(elf_ex);
53982+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
53983+ xattr_pax_flags = pax_parse_xattr_pax(file);
53984+
53985+ if (pt_pax_flags == ~0UL)
53986+ pt_pax_flags = xattr_pax_flags;
53987+ else if (xattr_pax_flags == ~0UL)
53988+ xattr_pax_flags = pt_pax_flags;
53989+ if (pt_pax_flags != xattr_pax_flags)
53990+ return -EINVAL;
53991+ if (pt_pax_flags != ~0UL)
53992+ pax_flags = pt_pax_flags;
53993+
53994+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
53995+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53996+ if ((__supported_pte_mask & _PAGE_NX))
53997+ pax_flags &= ~MF_PAX_SEGMEXEC;
53998+ else
53999+ pax_flags &= ~MF_PAX_PAGEEXEC;
54000+ }
54001+#endif
54002+
54003+ if (0 > pax_check_flags(&pax_flags))
54004+ return -EINVAL;
54005+
54006+ current->mm->pax_flags = pax_flags;
54007+ return 0;
54008+}
54009+#endif
54010+
54011 /*
54012 * These are the functions used to load ELF style executables and shared
54013 * libraries. There is no binary dependent code anywhere else.
54014@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
54015 {
54016 unsigned int random_variable = 0;
54017
54018+#ifdef CONFIG_PAX_RANDUSTACK
54019+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
54020+ return stack_top - current->mm->delta_stack;
54021+#endif
54022+
54023 if ((current->flags & PF_RANDOMIZE) &&
54024 !(current->personality & ADDR_NO_RANDOMIZE)) {
54025 random_variable = get_random_int() & STACK_RND_MASK;
54026@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
54027 unsigned long load_addr = 0, load_bias = 0;
54028 int load_addr_set = 0;
54029 char * elf_interpreter = NULL;
54030- unsigned long error;
54031+ unsigned long error = 0;
54032 struct elf_phdr *elf_ppnt, *elf_phdata;
54033 unsigned long elf_bss, elf_brk;
54034 int retval, i;
54035@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
54036 unsigned long start_code, end_code, start_data, end_data;
54037 unsigned long reloc_func_desc __maybe_unused = 0;
54038 int executable_stack = EXSTACK_DEFAULT;
54039- unsigned long def_flags = 0;
54040 struct pt_regs *regs = current_pt_regs();
54041 struct {
54042 struct elfhdr elf_ex;
54043 struct elfhdr interp_elf_ex;
54044 } *loc;
54045+ unsigned long pax_task_size;
54046
54047 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
54048 if (!loc) {
54049@@ -723,11 +1068,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
54050 goto out_free_dentry;
54051
54052 /* OK, This is the point of no return */
54053- current->mm->def_flags = def_flags;
54054+ current->mm->def_flags = 0;
54055
54056 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
54057 may depend on the personality. */
54058 SET_PERSONALITY(loc->elf_ex);
54059+
54060+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54061+ current->mm->pax_flags = 0UL;
54062+#endif
54063+
54064+#ifdef CONFIG_PAX_DLRESOLVE
54065+ current->mm->call_dl_resolve = 0UL;
54066+#endif
54067+
54068+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
54069+ current->mm->call_syscall = 0UL;
54070+#endif
54071+
54072+#ifdef CONFIG_PAX_ASLR
54073+ current->mm->delta_mmap = 0UL;
54074+ current->mm->delta_stack = 0UL;
54075+#endif
54076+
54077+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54078+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
54079+ send_sig(SIGKILL, current, 0);
54080+ goto out_free_dentry;
54081+ }
54082+#endif
54083+
54084+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54085+ pax_set_initial_flags(bprm);
54086+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
54087+ if (pax_set_initial_flags_func)
54088+ (pax_set_initial_flags_func)(bprm);
54089+#endif
54090+
54091+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54092+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
54093+ current->mm->context.user_cs_limit = PAGE_SIZE;
54094+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
54095+ }
54096+#endif
54097+
54098+#ifdef CONFIG_PAX_SEGMEXEC
54099+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
54100+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
54101+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
54102+ pax_task_size = SEGMEXEC_TASK_SIZE;
54103+ current->mm->def_flags |= VM_NOHUGEPAGE;
54104+ } else
54105+#endif
54106+
54107+ pax_task_size = TASK_SIZE;
54108+
54109+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
54110+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54111+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
54112+ put_cpu();
54113+ }
54114+#endif
54115+
54116+#ifdef CONFIG_PAX_ASLR
54117+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
54118+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
54119+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
54120+ }
54121+#endif
54122+
54123+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54124+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54125+ executable_stack = EXSTACK_DISABLE_X;
54126+ current->personality &= ~READ_IMPLIES_EXEC;
54127+ } else
54128+#endif
54129+
54130 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
54131 current->personality |= READ_IMPLIES_EXEC;
54132
54133@@ -817,6 +1233,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
54134 #else
54135 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
54136 #endif
54137+
54138+#ifdef CONFIG_PAX_RANDMMAP
54139+ /* PaX: randomize base address at the default exe base if requested */
54140+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
54141+#ifdef CONFIG_SPARC64
54142+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
54143+#else
54144+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
54145+#endif
54146+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
54147+ elf_flags |= MAP_FIXED;
54148+ }
54149+#endif
54150+
54151 }
54152
54153 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
54154@@ -849,9 +1279,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
54155 * allowed task size. Note that p_filesz must always be
54156 * <= p_memsz so it is only necessary to check p_memsz.
54157 */
54158- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
54159- elf_ppnt->p_memsz > TASK_SIZE ||
54160- TASK_SIZE - elf_ppnt->p_memsz < k) {
54161+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
54162+ elf_ppnt->p_memsz > pax_task_size ||
54163+ pax_task_size - elf_ppnt->p_memsz < k) {
54164 /* set_brk can never work. Avoid overflows. */
54165 send_sig(SIGKILL, current, 0);
54166 retval = -EINVAL;
54167@@ -890,17 +1320,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
54168 goto out_free_dentry;
54169 }
54170 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
54171- send_sig(SIGSEGV, current, 0);
54172- retval = -EFAULT; /* Nobody gets to see this, but.. */
54173- goto out_free_dentry;
54174+ /*
54175+ * This bss-zeroing can fail if the ELF
54176+ * file specifies odd protections. So
54177+ * we don't check the return value
54178+ */
54179 }
54180
54181+#ifdef CONFIG_PAX_RANDMMAP
54182+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
54183+ unsigned long start, size, flags;
54184+ vm_flags_t vm_flags;
54185+
54186+ start = ELF_PAGEALIGN(elf_brk);
54187+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
54188+ flags = MAP_FIXED | MAP_PRIVATE;
54189+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
54190+
54191+ down_write(&current->mm->mmap_sem);
54192+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
54193+ retval = -ENOMEM;
54194+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
54195+// if (current->personality & ADDR_NO_RANDOMIZE)
54196+// vm_flags |= VM_READ | VM_MAYREAD;
54197+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
54198+ retval = IS_ERR_VALUE(start) ? start : 0;
54199+ }
54200+ up_write(&current->mm->mmap_sem);
54201+ if (retval == 0)
54202+ retval = set_brk(start + size, start + size + PAGE_SIZE);
54203+ if (retval < 0) {
54204+ send_sig(SIGKILL, current, 0);
54205+ goto out_free_dentry;
54206+ }
54207+ }
54208+#endif
54209+
54210 if (elf_interpreter) {
54211- unsigned long interp_map_addr = 0;
54212-
54213 elf_entry = load_elf_interp(&loc->interp_elf_ex,
54214 interpreter,
54215- &interp_map_addr,
54216 load_bias);
54217 if (!IS_ERR((void *)elf_entry)) {
54218 /*
54219@@ -1122,7 +1580,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
54220 * Decide what to dump of a segment, part, all or none.
54221 */
54222 static unsigned long vma_dump_size(struct vm_area_struct *vma,
54223- unsigned long mm_flags)
54224+ unsigned long mm_flags, long signr)
54225 {
54226 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
54227
54228@@ -1160,7 +1618,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
54229 if (vma->vm_file == NULL)
54230 return 0;
54231
54232- if (FILTER(MAPPED_PRIVATE))
54233+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
54234 goto whole;
54235
54236 /*
54237@@ -1385,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
54238 {
54239 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
54240 int i = 0;
54241- do
54242+ do {
54243 i += 2;
54244- while (auxv[i - 2] != AT_NULL);
54245+ } while (auxv[i - 2] != AT_NULL);
54246 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
54247 }
54248
54249@@ -1396,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
54250 {
54251 mm_segment_t old_fs = get_fs();
54252 set_fs(KERNEL_DS);
54253- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
54254+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
54255 set_fs(old_fs);
54256 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
54257 }
54258@@ -2023,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
54259 }
54260
54261 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
54262- unsigned long mm_flags)
54263+ struct coredump_params *cprm)
54264 {
54265 struct vm_area_struct *vma;
54266 size_t size = 0;
54267
54268 for (vma = first_vma(current, gate_vma); vma != NULL;
54269 vma = next_vma(vma, gate_vma))
54270- size += vma_dump_size(vma, mm_flags);
54271+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54272 return size;
54273 }
54274
54275@@ -2123,7 +2581,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54276
54277 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
54278
54279- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
54280+ offset += elf_core_vma_data_size(gate_vma, cprm);
54281 offset += elf_core_extra_data_size();
54282 e_shoff = offset;
54283
54284@@ -2137,10 +2595,12 @@ static int elf_core_dump(struct coredump_params *cprm)
54285 offset = dataoff;
54286
54287 size += sizeof(*elf);
54288+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54289 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
54290 goto end_coredump;
54291
54292 size += sizeof(*phdr4note);
54293+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54294 if (size > cprm->limit
54295 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
54296 goto end_coredump;
54297@@ -2154,7 +2614,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54298 phdr.p_offset = offset;
54299 phdr.p_vaddr = vma->vm_start;
54300 phdr.p_paddr = 0;
54301- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
54302+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54303 phdr.p_memsz = vma->vm_end - vma->vm_start;
54304 offset += phdr.p_filesz;
54305 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
54306@@ -2165,6 +2625,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54307 phdr.p_align = ELF_EXEC_PAGESIZE;
54308
54309 size += sizeof(phdr);
54310+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54311 if (size > cprm->limit
54312 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
54313 goto end_coredump;
54314@@ -2189,7 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54315 unsigned long addr;
54316 unsigned long end;
54317
54318- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
54319+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54320
54321 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
54322 struct page *page;
54323@@ -2198,6 +2659,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54324 page = get_dump_page(addr);
54325 if (page) {
54326 void *kaddr = kmap(page);
54327+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
54328 stop = ((size += PAGE_SIZE) > cprm->limit) ||
54329 !dump_write(cprm->file, kaddr,
54330 PAGE_SIZE);
54331@@ -2215,6 +2677,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54332
54333 if (e_phnum == PN_XNUM) {
54334 size += sizeof(*shdr4extnum);
54335+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54336 if (size > cprm->limit
54337 || !dump_write(cprm->file, shdr4extnum,
54338 sizeof(*shdr4extnum)))
54339@@ -2235,6 +2698,167 @@ out:
54340
54341 #endif /* CONFIG_ELF_CORE */
54342
54343+#ifdef CONFIG_PAX_MPROTECT
54344+/* PaX: non-PIC ELF libraries need relocations on their executable segments
54345+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
54346+ * we'll remove VM_MAYWRITE for good on RELRO segments.
54347+ *
54348+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
54349+ * basis because we want to allow the common case and not the special ones.
54350+ */
54351+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
54352+{
54353+ struct elfhdr elf_h;
54354+ struct elf_phdr elf_p;
54355+ unsigned long i;
54356+ unsigned long oldflags;
54357+ bool is_textrel_rw, is_textrel_rx, is_relro;
54358+
54359+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
54360+ return;
54361+
54362+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
54363+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
54364+
54365+#ifdef CONFIG_PAX_ELFRELOCS
54366+ /* possible TEXTREL */
54367+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
54368+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
54369+#else
54370+ is_textrel_rw = false;
54371+ is_textrel_rx = false;
54372+#endif
54373+
54374+ /* possible RELRO */
54375+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
54376+
54377+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
54378+ return;
54379+
54380+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54381+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54382+
54383+#ifdef CONFIG_PAX_ETEXECRELOCS
54384+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54385+#else
54386+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
54387+#endif
54388+
54389+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54390+ !elf_check_arch(&elf_h) ||
54391+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54392+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54393+ return;
54394+
54395+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54396+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54397+ return;
54398+ switch (elf_p.p_type) {
54399+ case PT_DYNAMIC:
54400+ if (!is_textrel_rw && !is_textrel_rx)
54401+ continue;
54402+ i = 0UL;
54403+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
54404+ elf_dyn dyn;
54405+
54406+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
54407+ break;
54408+ if (dyn.d_tag == DT_NULL)
54409+ break;
54410+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
54411+ gr_log_textrel(vma);
54412+ if (is_textrel_rw)
54413+ vma->vm_flags |= VM_MAYWRITE;
54414+ else
54415+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
54416+ vma->vm_flags &= ~VM_MAYWRITE;
54417+ break;
54418+ }
54419+ i++;
54420+ }
54421+ is_textrel_rw = false;
54422+ is_textrel_rx = false;
54423+ continue;
54424+
54425+ case PT_GNU_RELRO:
54426+ if (!is_relro)
54427+ continue;
54428+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
54429+ vma->vm_flags &= ~VM_MAYWRITE;
54430+ is_relro = false;
54431+ continue;
54432+
54433+#ifdef CONFIG_PAX_PT_PAX_FLAGS
54434+ case PT_PAX_FLAGS: {
54435+ const char *msg_mprotect = "", *msg_emutramp = "";
54436+ char *buffer_lib, *buffer_exe;
54437+
54438+ if (elf_p.p_flags & PF_NOMPROTECT)
54439+ msg_mprotect = "MPROTECT disabled";
54440+
54441+#ifdef CONFIG_PAX_EMUTRAMP
54442+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
54443+ msg_emutramp = "EMUTRAMP enabled";
54444+#endif
54445+
54446+ if (!msg_mprotect[0] && !msg_emutramp[0])
54447+ continue;
54448+
54449+ if (!printk_ratelimit())
54450+ continue;
54451+
54452+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
54453+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
54454+ if (buffer_lib && buffer_exe) {
54455+ char *path_lib, *path_exe;
54456+
54457+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
54458+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
54459+
54460+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
54461+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
54462+
54463+ }
54464+ free_page((unsigned long)buffer_exe);
54465+ free_page((unsigned long)buffer_lib);
54466+ continue;
54467+ }
54468+#endif
54469+
54470+ }
54471+ }
54472+}
54473+#endif
54474+
54475+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54476+
54477+extern int grsec_enable_log_rwxmaps;
54478+
54479+static void elf_handle_mmap(struct file *file)
54480+{
54481+ struct elfhdr elf_h;
54482+ struct elf_phdr elf_p;
54483+ unsigned long i;
54484+
54485+ if (!grsec_enable_log_rwxmaps)
54486+ return;
54487+
54488+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54489+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54490+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
54491+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54492+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54493+ return;
54494+
54495+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54496+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54497+ return;
54498+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
54499+ gr_log_ptgnustack(file);
54500+ }
54501+}
54502+#endif
54503+
54504 static int __init init_elf_binfmt(void)
54505 {
54506 register_binfmt(&elf_format);
54507diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
54508index d50bbe5..af3b649 100644
54509--- a/fs/binfmt_flat.c
54510+++ b/fs/binfmt_flat.c
54511@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
54512 realdatastart = (unsigned long) -ENOMEM;
54513 printk("Unable to allocate RAM for process data, errno %d\n",
54514 (int)-realdatastart);
54515+ down_write(&current->mm->mmap_sem);
54516 vm_munmap(textpos, text_len);
54517+ up_write(&current->mm->mmap_sem);
54518 ret = realdatastart;
54519 goto err;
54520 }
54521@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54522 }
54523 if (IS_ERR_VALUE(result)) {
54524 printk("Unable to read data+bss, errno %d\n", (int)-result);
54525+ down_write(&current->mm->mmap_sem);
54526 vm_munmap(textpos, text_len);
54527 vm_munmap(realdatastart, len);
54528+ up_write(&current->mm->mmap_sem);
54529 ret = result;
54530 goto err;
54531 }
54532@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54533 }
54534 if (IS_ERR_VALUE(result)) {
54535 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
54536+ down_write(&current->mm->mmap_sem);
54537 vm_munmap(textpos, text_len + data_len + extra +
54538 MAX_SHARED_LIBS * sizeof(unsigned long));
54539+ up_write(&current->mm->mmap_sem);
54540 ret = result;
54541 goto err;
54542 }
54543diff --git a/fs/bio.c b/fs/bio.c
54544index ea5035d..a2932eb 100644
54545--- a/fs/bio.c
54546+++ b/fs/bio.c
54547@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
54548 /*
54549 * Overflow, abort
54550 */
54551- if (end < start)
54552+ if (end < start || end - start > INT_MAX - nr_pages)
54553 return ERR_PTR(-EINVAL);
54554
54555 nr_pages += end - start;
54556@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
54557 /*
54558 * Overflow, abort
54559 */
54560- if (end < start)
54561+ if (end < start || end - start > INT_MAX - nr_pages)
54562 return ERR_PTR(-EINVAL);
54563
54564 nr_pages += end - start;
54565@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
54566 const int read = bio_data_dir(bio) == READ;
54567 struct bio_map_data *bmd = bio->bi_private;
54568 int i;
54569- char *p = bmd->sgvecs[0].iov_base;
54570+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
54571
54572 bio_for_each_segment_all(bvec, bio, i) {
54573 char *addr = page_address(bvec->bv_page);
54574diff --git a/fs/block_dev.c b/fs/block_dev.c
54575index 1e86823..8e34695 100644
54576--- a/fs/block_dev.c
54577+++ b/fs/block_dev.c
54578@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
54579 else if (bdev->bd_contains == bdev)
54580 return true; /* is a whole device which isn't held */
54581
54582- else if (whole->bd_holder == bd_may_claim)
54583+ else if (whole->bd_holder == (void *)bd_may_claim)
54584 return true; /* is a partition of a device that is being partitioned */
54585 else if (whole->bd_holder != NULL)
54586 return false; /* is a partition of a held device */
54587diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
54588index b544a44..f3fb987 100644
54589--- a/fs/btrfs/ctree.c
54590+++ b/fs/btrfs/ctree.c
54591@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
54592 free_extent_buffer(buf);
54593 add_root_to_dirty_list(root);
54594 } else {
54595- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
54596- parent_start = parent->start;
54597- else
54598+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
54599+ if (parent)
54600+ parent_start = parent->start;
54601+ else
54602+ parent_start = 0;
54603+ } else
54604 parent_start = 0;
54605
54606 WARN_ON(trans->transid != btrfs_header_generation(parent));
54607diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
54608index cbd9523..5cca781 100644
54609--- a/fs/btrfs/delayed-inode.c
54610+++ b/fs/btrfs/delayed-inode.c
54611@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
54612
54613 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
54614 {
54615- int seq = atomic_inc_return(&delayed_root->items_seq);
54616+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
54617 if ((atomic_dec_return(&delayed_root->items) <
54618 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
54619 waitqueue_active(&delayed_root->wait))
54620@@ -1378,7 +1378,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
54621 static int refs_newer(struct btrfs_delayed_root *delayed_root,
54622 int seq, int count)
54623 {
54624- int val = atomic_read(&delayed_root->items_seq);
54625+ int val = atomic_read_unchecked(&delayed_root->items_seq);
54626
54627 if (val < seq || val >= seq + count)
54628 return 1;
54629@@ -1395,7 +1395,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
54630 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
54631 return;
54632
54633- seq = atomic_read(&delayed_root->items_seq);
54634+ seq = atomic_read_unchecked(&delayed_root->items_seq);
54635
54636 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
54637 int ret;
54638diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
54639index a4b38f9..f86a509 100644
54640--- a/fs/btrfs/delayed-inode.h
54641+++ b/fs/btrfs/delayed-inode.h
54642@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
54643 */
54644 struct list_head prepare_list;
54645 atomic_t items; /* for delayed items */
54646- atomic_t items_seq; /* for delayed items */
54647+ atomic_unchecked_t items_seq; /* for delayed items */
54648 int nodes; /* for delayed nodes */
54649 wait_queue_head_t wait;
54650 };
54651@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
54652 struct btrfs_delayed_root *delayed_root)
54653 {
54654 atomic_set(&delayed_root->items, 0);
54655- atomic_set(&delayed_root->items_seq, 0);
54656+ atomic_set_unchecked(&delayed_root->items_seq, 0);
54657 delayed_root->nodes = 0;
54658 spin_lock_init(&delayed_root->lock);
54659 init_waitqueue_head(&delayed_root->wait);
54660diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
54661index 8747feb..ad1655c 100644
54662--- a/fs/btrfs/ioctl.c
54663+++ b/fs/btrfs/ioctl.c
54664@@ -3465,9 +3465,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54665 for (i = 0; i < num_types; i++) {
54666 struct btrfs_space_info *tmp;
54667
54668+ /* Don't copy in more than we allocated */
54669 if (!slot_count)
54670 break;
54671
54672+ slot_count--;
54673+
54674 info = NULL;
54675 rcu_read_lock();
54676 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
54677@@ -3489,10 +3492,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54678 memcpy(dest, &space, sizeof(space));
54679 dest++;
54680 space_args.total_spaces++;
54681- slot_count--;
54682 }
54683- if (!slot_count)
54684- break;
54685 }
54686 up_read(&info->groups_sem);
54687 }
54688diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
54689index e913328..a34fb36 100644
54690--- a/fs/btrfs/super.c
54691+++ b/fs/btrfs/super.c
54692@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
54693 function, line, errstr);
54694 return;
54695 }
54696- ACCESS_ONCE(trans->transaction->aborted) = errno;
54697+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
54698 /* Wake up anybody who may be waiting on this transaction */
54699 wake_up(&root->fs_info->transaction_wait);
54700 wake_up(&root->fs_info->transaction_blocked_wait);
54701diff --git a/fs/buffer.c b/fs/buffer.c
54702index 6024877..7bd000a 100644
54703--- a/fs/buffer.c
54704+++ b/fs/buffer.c
54705@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
54706 bh_cachep = kmem_cache_create("buffer_head",
54707 sizeof(struct buffer_head), 0,
54708 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
54709- SLAB_MEM_SPREAD),
54710+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
54711 NULL);
54712
54713 /*
54714diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
54715index 622f469..e8d2d55 100644
54716--- a/fs/cachefiles/bind.c
54717+++ b/fs/cachefiles/bind.c
54718@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
54719 args);
54720
54721 /* start by checking things over */
54722- ASSERT(cache->fstop_percent >= 0 &&
54723- cache->fstop_percent < cache->fcull_percent &&
54724+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
54725 cache->fcull_percent < cache->frun_percent &&
54726 cache->frun_percent < 100);
54727
54728- ASSERT(cache->bstop_percent >= 0 &&
54729- cache->bstop_percent < cache->bcull_percent &&
54730+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
54731 cache->bcull_percent < cache->brun_percent &&
54732 cache->brun_percent < 100);
54733
54734diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
54735index 0a1467b..6a53245 100644
54736--- a/fs/cachefiles/daemon.c
54737+++ b/fs/cachefiles/daemon.c
54738@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
54739 if (n > buflen)
54740 return -EMSGSIZE;
54741
54742- if (copy_to_user(_buffer, buffer, n) != 0)
54743+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
54744 return -EFAULT;
54745
54746 return n;
54747@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
54748 if (test_bit(CACHEFILES_DEAD, &cache->flags))
54749 return -EIO;
54750
54751- if (datalen < 0 || datalen > PAGE_SIZE - 1)
54752+ if (datalen > PAGE_SIZE - 1)
54753 return -EOPNOTSUPP;
54754
54755 /* drag the command string into the kernel so we can parse it */
54756@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
54757 if (args[0] != '%' || args[1] != '\0')
54758 return -EINVAL;
54759
54760- if (fstop < 0 || fstop >= cache->fcull_percent)
54761+ if (fstop >= cache->fcull_percent)
54762 return cachefiles_daemon_range_error(cache, args);
54763
54764 cache->fstop_percent = fstop;
54765@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
54766 if (args[0] != '%' || args[1] != '\0')
54767 return -EINVAL;
54768
54769- if (bstop < 0 || bstop >= cache->bcull_percent)
54770+ if (bstop >= cache->bcull_percent)
54771 return cachefiles_daemon_range_error(cache, args);
54772
54773 cache->bstop_percent = bstop;
54774diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
54775index 5349473..d6c0b93 100644
54776--- a/fs/cachefiles/internal.h
54777+++ b/fs/cachefiles/internal.h
54778@@ -59,7 +59,7 @@ struct cachefiles_cache {
54779 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
54780 struct rb_root active_nodes; /* active nodes (can't be culled) */
54781 rwlock_t active_lock; /* lock for active_nodes */
54782- atomic_t gravecounter; /* graveyard uniquifier */
54783+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
54784 unsigned frun_percent; /* when to stop culling (% files) */
54785 unsigned fcull_percent; /* when to start culling (% files) */
54786 unsigned fstop_percent; /* when to stop allocating (% files) */
54787@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
54788 * proc.c
54789 */
54790 #ifdef CONFIG_CACHEFILES_HISTOGRAM
54791-extern atomic_t cachefiles_lookup_histogram[HZ];
54792-extern atomic_t cachefiles_mkdir_histogram[HZ];
54793-extern atomic_t cachefiles_create_histogram[HZ];
54794+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54795+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54796+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
54797
54798 extern int __init cachefiles_proc_init(void);
54799 extern void cachefiles_proc_cleanup(void);
54800 static inline
54801-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
54802+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
54803 {
54804 unsigned long jif = jiffies - start_jif;
54805 if (jif >= HZ)
54806 jif = HZ - 1;
54807- atomic_inc(&histogram[jif]);
54808+ atomic_inc_unchecked(&histogram[jif]);
54809 }
54810
54811 #else
54812diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
54813index f4a08d7..5aa4599 100644
54814--- a/fs/cachefiles/namei.c
54815+++ b/fs/cachefiles/namei.c
54816@@ -317,7 +317,7 @@ try_again:
54817 /* first step is to make up a grave dentry in the graveyard */
54818 sprintf(nbuffer, "%08x%08x",
54819 (uint32_t) get_seconds(),
54820- (uint32_t) atomic_inc_return(&cache->gravecounter));
54821+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
54822
54823 /* do the multiway lock magic */
54824 trap = lock_rename(cache->graveyard, dir);
54825diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
54826index eccd339..4c1d995 100644
54827--- a/fs/cachefiles/proc.c
54828+++ b/fs/cachefiles/proc.c
54829@@ -14,9 +14,9 @@
54830 #include <linux/seq_file.h>
54831 #include "internal.h"
54832
54833-atomic_t cachefiles_lookup_histogram[HZ];
54834-atomic_t cachefiles_mkdir_histogram[HZ];
54835-atomic_t cachefiles_create_histogram[HZ];
54836+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54837+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54838+atomic_unchecked_t cachefiles_create_histogram[HZ];
54839
54840 /*
54841 * display the latency histogram
54842@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
54843 return 0;
54844 default:
54845 index = (unsigned long) v - 3;
54846- x = atomic_read(&cachefiles_lookup_histogram[index]);
54847- y = atomic_read(&cachefiles_mkdir_histogram[index]);
54848- z = atomic_read(&cachefiles_create_histogram[index]);
54849+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
54850+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
54851+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
54852 if (x == 0 && y == 0 && z == 0)
54853 return 0;
54854
54855diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
54856index ebaff36..7e3ea26 100644
54857--- a/fs/cachefiles/rdwr.c
54858+++ b/fs/cachefiles/rdwr.c
54859@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
54860 old_fs = get_fs();
54861 set_fs(KERNEL_DS);
54862 ret = file->f_op->write(
54863- file, (const void __user *) data, len, &pos);
54864+ file, (const void __force_user *) data, len, &pos);
54865 set_fs(old_fs);
54866 kunmap(page);
54867 file_end_write(file);
54868diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
54869index 868b61d..58835a5 100644
54870--- a/fs/ceph/dir.c
54871+++ b/fs/ceph/dir.c
54872@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
54873 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
54874 struct ceph_mds_client *mdsc = fsc->mdsc;
54875 unsigned frag = fpos_frag(ctx->pos);
54876- int off = fpos_off(ctx->pos);
54877+ unsigned int off = fpos_off(ctx->pos);
54878 int err;
54879 u32 ftype;
54880 struct ceph_mds_reply_info_parsed *rinfo;
54881diff --git a/fs/ceph/super.c b/fs/ceph/super.c
54882index 6a0951e..03fac6d 100644
54883--- a/fs/ceph/super.c
54884+++ b/fs/ceph/super.c
54885@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
54886 /*
54887 * construct our own bdi so we can control readahead, etc.
54888 */
54889-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
54890+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
54891
54892 static int ceph_register_bdi(struct super_block *sb,
54893 struct ceph_fs_client *fsc)
54894@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
54895 default_backing_dev_info.ra_pages;
54896
54897 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
54898- atomic_long_inc_return(&bdi_seq));
54899+ atomic_long_inc_return_unchecked(&bdi_seq));
54900 if (!err)
54901 sb->s_bdi = &fsc->backing_dev_info;
54902 return err;
54903diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
54904index f3ac415..3d2420c 100644
54905--- a/fs/cifs/cifs_debug.c
54906+++ b/fs/cifs/cifs_debug.c
54907@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54908
54909 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
54910 #ifdef CONFIG_CIFS_STATS2
54911- atomic_set(&totBufAllocCount, 0);
54912- atomic_set(&totSmBufAllocCount, 0);
54913+ atomic_set_unchecked(&totBufAllocCount, 0);
54914+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54915 #endif /* CONFIG_CIFS_STATS2 */
54916 spin_lock(&cifs_tcp_ses_lock);
54917 list_for_each(tmp1, &cifs_tcp_ses_list) {
54918@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54919 tcon = list_entry(tmp3,
54920 struct cifs_tcon,
54921 tcon_list);
54922- atomic_set(&tcon->num_smbs_sent, 0);
54923+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
54924 if (server->ops->clear_stats)
54925 server->ops->clear_stats(tcon);
54926 }
54927@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54928 smBufAllocCount.counter, cifs_min_small);
54929 #ifdef CONFIG_CIFS_STATS2
54930 seq_printf(m, "Total Large %d Small %d Allocations\n",
54931- atomic_read(&totBufAllocCount),
54932- atomic_read(&totSmBufAllocCount));
54933+ atomic_read_unchecked(&totBufAllocCount),
54934+ atomic_read_unchecked(&totSmBufAllocCount));
54935 #endif /* CONFIG_CIFS_STATS2 */
54936
54937 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
54938@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54939 if (tcon->need_reconnect)
54940 seq_puts(m, "\tDISCONNECTED ");
54941 seq_printf(m, "\nSMBs: %d",
54942- atomic_read(&tcon->num_smbs_sent));
54943+ atomic_read_unchecked(&tcon->num_smbs_sent));
54944 if (server->ops->print_stats)
54945 server->ops->print_stats(m, tcon);
54946 }
54947diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
54948index 77fc5e1..e3d13e6 100644
54949--- a/fs/cifs/cifsfs.c
54950+++ b/fs/cifs/cifsfs.c
54951@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
54952 */
54953 cifs_req_cachep = kmem_cache_create("cifs_request",
54954 CIFSMaxBufSize + max_hdr_size, 0,
54955- SLAB_HWCACHE_ALIGN, NULL);
54956+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
54957 if (cifs_req_cachep == NULL)
54958 return -ENOMEM;
54959
54960@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
54961 efficient to alloc 1 per page off the slab compared to 17K (5page)
54962 alloc of large cifs buffers even when page debugging is on */
54963 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
54964- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
54965+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
54966 NULL);
54967 if (cifs_sm_req_cachep == NULL) {
54968 mempool_destroy(cifs_req_poolp);
54969@@ -1168,8 +1168,8 @@ init_cifs(void)
54970 atomic_set(&bufAllocCount, 0);
54971 atomic_set(&smBufAllocCount, 0);
54972 #ifdef CONFIG_CIFS_STATS2
54973- atomic_set(&totBufAllocCount, 0);
54974- atomic_set(&totSmBufAllocCount, 0);
54975+ atomic_set_unchecked(&totBufAllocCount, 0);
54976+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54977 #endif /* CONFIG_CIFS_STATS2 */
54978
54979 atomic_set(&midCount, 0);
54980diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
54981index c8e03f8..75362f6 100644
54982--- a/fs/cifs/cifsglob.h
54983+++ b/fs/cifs/cifsglob.h
54984@@ -758,35 +758,35 @@ struct cifs_tcon {
54985 __u16 Flags; /* optional support bits */
54986 enum statusEnum tidStatus;
54987 #ifdef CONFIG_CIFS_STATS
54988- atomic_t num_smbs_sent;
54989+ atomic_unchecked_t num_smbs_sent;
54990 union {
54991 struct {
54992- atomic_t num_writes;
54993- atomic_t num_reads;
54994- atomic_t num_flushes;
54995- atomic_t num_oplock_brks;
54996- atomic_t num_opens;
54997- atomic_t num_closes;
54998- atomic_t num_deletes;
54999- atomic_t num_mkdirs;
55000- atomic_t num_posixopens;
55001- atomic_t num_posixmkdirs;
55002- atomic_t num_rmdirs;
55003- atomic_t num_renames;
55004- atomic_t num_t2renames;
55005- atomic_t num_ffirst;
55006- atomic_t num_fnext;
55007- atomic_t num_fclose;
55008- atomic_t num_hardlinks;
55009- atomic_t num_symlinks;
55010- atomic_t num_locks;
55011- atomic_t num_acl_get;
55012- atomic_t num_acl_set;
55013+ atomic_unchecked_t num_writes;
55014+ atomic_unchecked_t num_reads;
55015+ atomic_unchecked_t num_flushes;
55016+ atomic_unchecked_t num_oplock_brks;
55017+ atomic_unchecked_t num_opens;
55018+ atomic_unchecked_t num_closes;
55019+ atomic_unchecked_t num_deletes;
55020+ atomic_unchecked_t num_mkdirs;
55021+ atomic_unchecked_t num_posixopens;
55022+ atomic_unchecked_t num_posixmkdirs;
55023+ atomic_unchecked_t num_rmdirs;
55024+ atomic_unchecked_t num_renames;
55025+ atomic_unchecked_t num_t2renames;
55026+ atomic_unchecked_t num_ffirst;
55027+ atomic_unchecked_t num_fnext;
55028+ atomic_unchecked_t num_fclose;
55029+ atomic_unchecked_t num_hardlinks;
55030+ atomic_unchecked_t num_symlinks;
55031+ atomic_unchecked_t num_locks;
55032+ atomic_unchecked_t num_acl_get;
55033+ atomic_unchecked_t num_acl_set;
55034 } cifs_stats;
55035 #ifdef CONFIG_CIFS_SMB2
55036 struct {
55037- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
55038- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
55039+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
55040+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
55041 } smb2_stats;
55042 #endif /* CONFIG_CIFS_SMB2 */
55043 } stats;
55044@@ -1111,7 +1111,7 @@ convert_delimiter(char *path, char delim)
55045 }
55046
55047 #ifdef CONFIG_CIFS_STATS
55048-#define cifs_stats_inc atomic_inc
55049+#define cifs_stats_inc atomic_inc_unchecked
55050
55051 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
55052 unsigned int bytes)
55053@@ -1477,8 +1477,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
55054 /* Various Debug counters */
55055 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
55056 #ifdef CONFIG_CIFS_STATS2
55057-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
55058-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
55059+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
55060+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
55061 #endif
55062 GLOBAL_EXTERN atomic_t smBufAllocCount;
55063 GLOBAL_EXTERN atomic_t midCount;
55064diff --git a/fs/cifs/file.c b/fs/cifs/file.c
55065index 7ddddf2..2e12dbc 100644
55066--- a/fs/cifs/file.c
55067+++ b/fs/cifs/file.c
55068@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
55069 index = mapping->writeback_index; /* Start from prev offset */
55070 end = -1;
55071 } else {
55072- index = wbc->range_start >> PAGE_CACHE_SHIFT;
55073- end = wbc->range_end >> PAGE_CACHE_SHIFT;
55074- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
55075+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
55076 range_whole = true;
55077+ index = 0;
55078+ end = ULONG_MAX;
55079+ } else {
55080+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
55081+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
55082+ }
55083 scanned = true;
55084 }
55085 retry:
55086diff --git a/fs/cifs/link.c b/fs/cifs/link.c
55087index 7e36ceb..109252f 100644
55088--- a/fs/cifs/link.c
55089+++ b/fs/cifs/link.c
55090@@ -624,7 +624,7 @@ symlink_exit:
55091
55092 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
55093 {
55094- char *p = nd_get_link(nd);
55095+ const char *p = nd_get_link(nd);
55096 if (!IS_ERR(p))
55097 kfree(p);
55098 }
55099diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
55100index 138a011..cf9e13a 100644
55101--- a/fs/cifs/misc.c
55102+++ b/fs/cifs/misc.c
55103@@ -170,7 +170,7 @@ cifs_buf_get(void)
55104 memset(ret_buf, 0, buf_size + 3);
55105 atomic_inc(&bufAllocCount);
55106 #ifdef CONFIG_CIFS_STATS2
55107- atomic_inc(&totBufAllocCount);
55108+ atomic_inc_unchecked(&totBufAllocCount);
55109 #endif /* CONFIG_CIFS_STATS2 */
55110 }
55111
55112@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
55113 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
55114 atomic_inc(&smBufAllocCount);
55115 #ifdef CONFIG_CIFS_STATS2
55116- atomic_inc(&totSmBufAllocCount);
55117+ atomic_inc_unchecked(&totSmBufAllocCount);
55118 #endif /* CONFIG_CIFS_STATS2 */
55119
55120 }
55121diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
55122index e50554b..c011413 100644
55123--- a/fs/cifs/smb1ops.c
55124+++ b/fs/cifs/smb1ops.c
55125@@ -609,27 +609,27 @@ static void
55126 cifs_clear_stats(struct cifs_tcon *tcon)
55127 {
55128 #ifdef CONFIG_CIFS_STATS
55129- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
55130- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
55131- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
55132- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
55133- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
55134- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
55135- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
55136- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
55137- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
55138- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
55139- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
55140- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
55141- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
55142- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
55143- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
55144- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
55145- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
55146- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
55147- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
55148- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
55149- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
55150+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
55151+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
55152+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
55153+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
55154+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
55155+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
55156+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
55157+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
55158+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
55159+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
55160+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
55161+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
55162+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
55163+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
55164+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
55165+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
55166+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
55167+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
55168+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
55169+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
55170+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
55171 #endif
55172 }
55173
55174@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
55175 {
55176 #ifdef CONFIG_CIFS_STATS
55177 seq_printf(m, " Oplocks breaks: %d",
55178- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
55179+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
55180 seq_printf(m, "\nReads: %d Bytes: %llu",
55181- atomic_read(&tcon->stats.cifs_stats.num_reads),
55182+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
55183 (long long)(tcon->bytes_read));
55184 seq_printf(m, "\nWrites: %d Bytes: %llu",
55185- atomic_read(&tcon->stats.cifs_stats.num_writes),
55186+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
55187 (long long)(tcon->bytes_written));
55188 seq_printf(m, "\nFlushes: %d",
55189- atomic_read(&tcon->stats.cifs_stats.num_flushes));
55190+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
55191 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
55192- atomic_read(&tcon->stats.cifs_stats.num_locks),
55193- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
55194- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
55195+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
55196+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
55197+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
55198 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
55199- atomic_read(&tcon->stats.cifs_stats.num_opens),
55200- atomic_read(&tcon->stats.cifs_stats.num_closes),
55201- atomic_read(&tcon->stats.cifs_stats.num_deletes));
55202+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
55203+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
55204+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
55205 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
55206- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
55207- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
55208+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
55209+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
55210 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
55211- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
55212- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
55213+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
55214+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
55215 seq_printf(m, "\nRenames: %d T2 Renames %d",
55216- atomic_read(&tcon->stats.cifs_stats.num_renames),
55217- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
55218+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
55219+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
55220 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
55221- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
55222- atomic_read(&tcon->stats.cifs_stats.num_fnext),
55223- atomic_read(&tcon->stats.cifs_stats.num_fclose));
55224+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
55225+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
55226+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
55227 #endif
55228 }
55229
55230diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
55231index 861b332..5506392 100644
55232--- a/fs/cifs/smb2ops.c
55233+++ b/fs/cifs/smb2ops.c
55234@@ -282,8 +282,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
55235 #ifdef CONFIG_CIFS_STATS
55236 int i;
55237 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
55238- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
55239- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
55240+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
55241+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
55242 }
55243 #endif
55244 }
55245@@ -311,65 +311,65 @@ static void
55246 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
55247 {
55248 #ifdef CONFIG_CIFS_STATS
55249- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
55250- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
55251+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
55252+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
55253 seq_printf(m, "\nNegotiates: %d sent %d failed",
55254- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
55255- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
55256+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
55257+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
55258 seq_printf(m, "\nSessionSetups: %d sent %d failed",
55259- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
55260- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
55261+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
55262+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
55263 seq_printf(m, "\nLogoffs: %d sent %d failed",
55264- atomic_read(&sent[SMB2_LOGOFF_HE]),
55265- atomic_read(&failed[SMB2_LOGOFF_HE]));
55266+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
55267+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
55268 seq_printf(m, "\nTreeConnects: %d sent %d failed",
55269- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
55270- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
55271+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
55272+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
55273 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
55274- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
55275- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
55276+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
55277+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
55278 seq_printf(m, "\nCreates: %d sent %d failed",
55279- atomic_read(&sent[SMB2_CREATE_HE]),
55280- atomic_read(&failed[SMB2_CREATE_HE]));
55281+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
55282+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
55283 seq_printf(m, "\nCloses: %d sent %d failed",
55284- atomic_read(&sent[SMB2_CLOSE_HE]),
55285- atomic_read(&failed[SMB2_CLOSE_HE]));
55286+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
55287+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
55288 seq_printf(m, "\nFlushes: %d sent %d failed",
55289- atomic_read(&sent[SMB2_FLUSH_HE]),
55290- atomic_read(&failed[SMB2_FLUSH_HE]));
55291+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
55292+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
55293 seq_printf(m, "\nReads: %d sent %d failed",
55294- atomic_read(&sent[SMB2_READ_HE]),
55295- atomic_read(&failed[SMB2_READ_HE]));
55296+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
55297+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
55298 seq_printf(m, "\nWrites: %d sent %d failed",
55299- atomic_read(&sent[SMB2_WRITE_HE]),
55300- atomic_read(&failed[SMB2_WRITE_HE]));
55301+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
55302+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
55303 seq_printf(m, "\nLocks: %d sent %d failed",
55304- atomic_read(&sent[SMB2_LOCK_HE]),
55305- atomic_read(&failed[SMB2_LOCK_HE]));
55306+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
55307+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
55308 seq_printf(m, "\nIOCTLs: %d sent %d failed",
55309- atomic_read(&sent[SMB2_IOCTL_HE]),
55310- atomic_read(&failed[SMB2_IOCTL_HE]));
55311+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
55312+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
55313 seq_printf(m, "\nCancels: %d sent %d failed",
55314- atomic_read(&sent[SMB2_CANCEL_HE]),
55315- atomic_read(&failed[SMB2_CANCEL_HE]));
55316+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
55317+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
55318 seq_printf(m, "\nEchos: %d sent %d failed",
55319- atomic_read(&sent[SMB2_ECHO_HE]),
55320- atomic_read(&failed[SMB2_ECHO_HE]));
55321+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
55322+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
55323 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
55324- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
55325- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
55326+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
55327+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
55328 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
55329- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
55330- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
55331+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
55332+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
55333 seq_printf(m, "\nQueryInfos: %d sent %d failed",
55334- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
55335- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
55336+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
55337+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
55338 seq_printf(m, "\nSetInfos: %d sent %d failed",
55339- atomic_read(&sent[SMB2_SET_INFO_HE]),
55340- atomic_read(&failed[SMB2_SET_INFO_HE]));
55341+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
55342+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
55343 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
55344- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
55345- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
55346+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
55347+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
55348 #endif
55349 }
55350
55351diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
55352index edccb52..16bc6db 100644
55353--- a/fs/cifs/smb2pdu.c
55354+++ b/fs/cifs/smb2pdu.c
55355@@ -1957,8 +1957,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
55356 default:
55357 cifs_dbg(VFS, "info level %u isn't supported\n",
55358 srch_inf->info_level);
55359- rc = -EINVAL;
55360- goto qdir_exit;
55361+ return -EINVAL;
55362 }
55363
55364 req->FileIndex = cpu_to_le32(index);
55365diff --git a/fs/coda/cache.c b/fs/coda/cache.c
55366index 1da168c..8bc7ff6 100644
55367--- a/fs/coda/cache.c
55368+++ b/fs/coda/cache.c
55369@@ -24,7 +24,7 @@
55370 #include "coda_linux.h"
55371 #include "coda_cache.h"
55372
55373-static atomic_t permission_epoch = ATOMIC_INIT(0);
55374+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
55375
55376 /* replace or extend an acl cache hit */
55377 void coda_cache_enter(struct inode *inode, int mask)
55378@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
55379 struct coda_inode_info *cii = ITOC(inode);
55380
55381 spin_lock(&cii->c_lock);
55382- cii->c_cached_epoch = atomic_read(&permission_epoch);
55383+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
55384 if (!uid_eq(cii->c_uid, current_fsuid())) {
55385 cii->c_uid = current_fsuid();
55386 cii->c_cached_perm = mask;
55387@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
55388 {
55389 struct coda_inode_info *cii = ITOC(inode);
55390 spin_lock(&cii->c_lock);
55391- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
55392+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
55393 spin_unlock(&cii->c_lock);
55394 }
55395
55396 /* remove all acl caches */
55397 void coda_cache_clear_all(struct super_block *sb)
55398 {
55399- atomic_inc(&permission_epoch);
55400+ atomic_inc_unchecked(&permission_epoch);
55401 }
55402
55403
55404@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
55405 spin_lock(&cii->c_lock);
55406 hit = (mask & cii->c_cached_perm) == mask &&
55407 uid_eq(cii->c_uid, current_fsuid()) &&
55408- cii->c_cached_epoch == atomic_read(&permission_epoch);
55409+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
55410 spin_unlock(&cii->c_lock);
55411
55412 return hit;
55413diff --git a/fs/compat.c b/fs/compat.c
55414index 6af20de..fec3fbb 100644
55415--- a/fs/compat.c
55416+++ b/fs/compat.c
55417@@ -54,7 +54,7 @@
55418 #include <asm/ioctls.h>
55419 #include "internal.h"
55420
55421-int compat_log = 1;
55422+int compat_log = 0;
55423
55424 int compat_printk(const char *fmt, ...)
55425 {
55426@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
55427
55428 set_fs(KERNEL_DS);
55429 /* The __user pointer cast is valid because of the set_fs() */
55430- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
55431+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
55432 set_fs(oldfs);
55433 /* truncating is ok because it's a user address */
55434 if (!ret)
55435@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
55436 goto out;
55437
55438 ret = -EINVAL;
55439- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
55440+ if (nr_segs > UIO_MAXIOV)
55441 goto out;
55442 if (nr_segs > fast_segs) {
55443 ret = -ENOMEM;
55444@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
55445 struct compat_readdir_callback {
55446 struct dir_context ctx;
55447 struct compat_old_linux_dirent __user *dirent;
55448+ struct file * file;
55449 int result;
55450 };
55451
55452@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
55453 buf->result = -EOVERFLOW;
55454 return -EOVERFLOW;
55455 }
55456+
55457+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55458+ return 0;
55459+
55460 buf->result++;
55461 dirent = buf->dirent;
55462 if (!access_ok(VERIFY_WRITE, dirent,
55463@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
55464 if (!f.file)
55465 return -EBADF;
55466
55467+ buf.file = f.file;
55468 error = iterate_dir(f.file, &buf.ctx);
55469 if (buf.result)
55470 error = buf.result;
55471@@ -901,6 +907,7 @@ struct compat_getdents_callback {
55472 struct dir_context ctx;
55473 struct compat_linux_dirent __user *current_dir;
55474 struct compat_linux_dirent __user *previous;
55475+ struct file * file;
55476 int count;
55477 int error;
55478 };
55479@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
55480 buf->error = -EOVERFLOW;
55481 return -EOVERFLOW;
55482 }
55483+
55484+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55485+ return 0;
55486+
55487 dirent = buf->previous;
55488 if (dirent) {
55489 if (__put_user(offset, &dirent->d_off))
55490@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
55491 if (!f.file)
55492 return -EBADF;
55493
55494+ buf.file = f.file;
55495 error = iterate_dir(f.file, &buf.ctx);
55496 if (error >= 0)
55497 error = buf.error;
55498@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
55499 struct dir_context ctx;
55500 struct linux_dirent64 __user *current_dir;
55501 struct linux_dirent64 __user *previous;
55502+ struct file * file;
55503 int count;
55504 int error;
55505 };
55506@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
55507 buf->error = -EINVAL; /* only used if we fail.. */
55508 if (reclen > buf->count)
55509 return -EINVAL;
55510+
55511+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55512+ return 0;
55513+
55514 dirent = buf->previous;
55515
55516 if (dirent) {
55517@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
55518 if (!f.file)
55519 return -EBADF;
55520
55521+ buf.file = f.file;
55522 error = iterate_dir(f.file, &buf.ctx);
55523 if (error >= 0)
55524 error = buf.error;
55525diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
55526index a81147e..20bf2b5 100644
55527--- a/fs/compat_binfmt_elf.c
55528+++ b/fs/compat_binfmt_elf.c
55529@@ -30,11 +30,13 @@
55530 #undef elf_phdr
55531 #undef elf_shdr
55532 #undef elf_note
55533+#undef elf_dyn
55534 #undef elf_addr_t
55535 #define elfhdr elf32_hdr
55536 #define elf_phdr elf32_phdr
55537 #define elf_shdr elf32_shdr
55538 #define elf_note elf32_note
55539+#define elf_dyn Elf32_Dyn
55540 #define elf_addr_t Elf32_Addr
55541
55542 /*
55543diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
55544index 5d19acf..9ab093b 100644
55545--- a/fs/compat_ioctl.c
55546+++ b/fs/compat_ioctl.c
55547@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
55548 return -EFAULT;
55549 if (__get_user(udata, &ss32->iomem_base))
55550 return -EFAULT;
55551- ss.iomem_base = compat_ptr(udata);
55552+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
55553 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
55554 __get_user(ss.port_high, &ss32->port_high))
55555 return -EFAULT;
55556@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
55557 for (i = 0; i < nmsgs; i++) {
55558 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
55559 return -EFAULT;
55560- if (get_user(datap, &umsgs[i].buf) ||
55561- put_user(compat_ptr(datap), &tmsgs[i].buf))
55562+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
55563+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
55564 return -EFAULT;
55565 }
55566 return sys_ioctl(fd, cmd, (unsigned long)tdata);
55567@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
55568 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
55569 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
55570 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
55571- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55572+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55573 return -EFAULT;
55574
55575 return ioctl_preallocate(file, p);
55576@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
55577 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
55578 {
55579 unsigned int a, b;
55580- a = *(unsigned int *)p;
55581- b = *(unsigned int *)q;
55582+ a = *(const unsigned int *)p;
55583+ b = *(const unsigned int *)q;
55584 if (a > b)
55585 return 1;
55586 if (a < b)
55587diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
55588index 511d415..319d0e5 100644
55589--- a/fs/configfs/dir.c
55590+++ b/fs/configfs/dir.c
55591@@ -1558,7 +1558,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
55592 }
55593 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
55594 struct configfs_dirent *next;
55595- const char *name;
55596+ const unsigned char * name;
55597+ char d_name[sizeof(next->s_dentry->d_iname)];
55598 int len;
55599 struct inode *inode = NULL;
55600
55601@@ -1567,7 +1568,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
55602 continue;
55603
55604 name = configfs_get_name(next);
55605- len = strlen(name);
55606+ if (next->s_dentry && name == next->s_dentry->d_iname) {
55607+ len = next->s_dentry->d_name.len;
55608+ memcpy(d_name, name, len);
55609+ name = d_name;
55610+ } else
55611+ len = strlen(name);
55612
55613 /*
55614 * We'll have a dentry and an inode for
55615diff --git a/fs/coredump.c b/fs/coredump.c
55616index 9bdeca1..2a9b08d 100644
55617--- a/fs/coredump.c
55618+++ b/fs/coredump.c
55619@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
55620 struct pipe_inode_info *pipe = file->private_data;
55621
55622 pipe_lock(pipe);
55623- pipe->readers++;
55624- pipe->writers--;
55625+ atomic_inc(&pipe->readers);
55626+ atomic_dec(&pipe->writers);
55627 wake_up_interruptible_sync(&pipe->wait);
55628 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55629 pipe_unlock(pipe);
55630@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
55631 * We actually want wait_event_freezable() but then we need
55632 * to clear TIF_SIGPENDING and improve dump_interrupted().
55633 */
55634- wait_event_interruptible(pipe->wait, pipe->readers == 1);
55635+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
55636
55637 pipe_lock(pipe);
55638- pipe->readers--;
55639- pipe->writers++;
55640+ atomic_dec(&pipe->readers);
55641+ atomic_inc(&pipe->writers);
55642 pipe_unlock(pipe);
55643 }
55644
55645@@ -499,7 +499,9 @@ void do_coredump(siginfo_t *siginfo)
55646 struct files_struct *displaced;
55647 bool need_nonrelative = false;
55648 bool core_dumped = false;
55649- static atomic_t core_dump_count = ATOMIC_INIT(0);
55650+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
55651+ long signr = siginfo->si_signo;
55652+ int dumpable;
55653 struct coredump_params cprm = {
55654 .siginfo = siginfo,
55655 .regs = signal_pt_regs(),
55656@@ -512,12 +514,17 @@ void do_coredump(siginfo_t *siginfo)
55657 .mm_flags = mm->flags,
55658 };
55659
55660- audit_core_dumps(siginfo->si_signo);
55661+ audit_core_dumps(signr);
55662+
55663+ dumpable = __get_dumpable(cprm.mm_flags);
55664+
55665+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
55666+ gr_handle_brute_attach(dumpable);
55667
55668 binfmt = mm->binfmt;
55669 if (!binfmt || !binfmt->core_dump)
55670 goto fail;
55671- if (!__get_dumpable(cprm.mm_flags))
55672+ if (!dumpable)
55673 goto fail;
55674
55675 cred = prepare_creds();
55676@@ -536,7 +543,7 @@ void do_coredump(siginfo_t *siginfo)
55677 need_nonrelative = true;
55678 }
55679
55680- retval = coredump_wait(siginfo->si_signo, &core_state);
55681+ retval = coredump_wait(signr, &core_state);
55682 if (retval < 0)
55683 goto fail_creds;
55684
55685@@ -579,7 +586,7 @@ void do_coredump(siginfo_t *siginfo)
55686 }
55687 cprm.limit = RLIM_INFINITY;
55688
55689- dump_count = atomic_inc_return(&core_dump_count);
55690+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
55691 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
55692 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
55693 task_tgid_vnr(current), current->comm);
55694@@ -611,6 +618,8 @@ void do_coredump(siginfo_t *siginfo)
55695 } else {
55696 struct inode *inode;
55697
55698+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
55699+
55700 if (cprm.limit < binfmt->min_coredump)
55701 goto fail_unlock;
55702
55703@@ -669,7 +678,7 @@ close_fail:
55704 filp_close(cprm.file, NULL);
55705 fail_dropcount:
55706 if (ispipe)
55707- atomic_dec(&core_dump_count);
55708+ atomic_dec_unchecked(&core_dump_count);
55709 fail_unlock:
55710 kfree(cn.corename);
55711 coredump_finish(mm, core_dumped);
55712@@ -689,7 +698,7 @@ int dump_write(struct file *file, const void *addr, int nr)
55713 {
55714 return !dump_interrupted() &&
55715 access_ok(VERIFY_READ, addr, nr) &&
55716- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
55717+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
55718 }
55719 EXPORT_SYMBOL(dump_write);
55720
55721diff --git a/fs/dcache.c b/fs/dcache.c
55722index 89f9671..d2dce57 100644
55723--- a/fs/dcache.c
55724+++ b/fs/dcache.c
55725@@ -1570,7 +1570,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
55726 */
55727 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
55728 if (name->len > DNAME_INLINE_LEN-1) {
55729- dname = kmalloc(name->len + 1, GFP_KERNEL);
55730+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
55731 if (!dname) {
55732 kmem_cache_free(dentry_cache, dentry);
55733 return NULL;
55734@@ -2893,6 +2893,7 @@ static int prepend_path(const struct path *path,
55735 restart:
55736 bptr = *buffer;
55737 blen = *buflen;
55738+ error = 0;
55739 dentry = path->dentry;
55740 vfsmnt = path->mnt;
55741 mnt = real_mount(vfsmnt);
55742@@ -3432,7 +3433,8 @@ void __init vfs_caches_init(unsigned long mempages)
55743 mempages -= reserve;
55744
55745 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
55746- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
55747+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
55748+ SLAB_NO_SANITIZE, NULL);
55749
55750 dcache_init();
55751 inode_init();
55752diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
55753index c7c83ff..bda9461 100644
55754--- a/fs/debugfs/inode.c
55755+++ b/fs/debugfs/inode.c
55756@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
55757 */
55758 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
55759 {
55760+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55761+ return __create_file(name, S_IFDIR | S_IRWXU,
55762+#else
55763 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
55764+#endif
55765 parent, NULL, NULL);
55766 }
55767 EXPORT_SYMBOL_GPL(debugfs_create_dir);
55768diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
55769index 67e9b63..a9adb68 100644
55770--- a/fs/ecryptfs/inode.c
55771+++ b/fs/ecryptfs/inode.c
55772@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
55773 old_fs = get_fs();
55774 set_fs(get_ds());
55775 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
55776- (char __user *)lower_buf,
55777+ (char __force_user *)lower_buf,
55778 PATH_MAX);
55779 set_fs(old_fs);
55780 if (rc < 0)
55781@@ -706,7 +706,7 @@ out:
55782 static void
55783 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
55784 {
55785- char *buf = nd_get_link(nd);
55786+ const char *buf = nd_get_link(nd);
55787 if (!IS_ERR(buf)) {
55788 /* Free the char* */
55789 kfree(buf);
55790diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
55791index e4141f2..d8263e8 100644
55792--- a/fs/ecryptfs/miscdev.c
55793+++ b/fs/ecryptfs/miscdev.c
55794@@ -304,7 +304,7 @@ check_list:
55795 goto out_unlock_msg_ctx;
55796 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
55797 if (msg_ctx->msg) {
55798- if (copy_to_user(&buf[i], packet_length, packet_length_size))
55799+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
55800 goto out_unlock_msg_ctx;
55801 i += packet_length_size;
55802 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
55803diff --git a/fs/exec.c b/fs/exec.c
55804index bb8afc1..2f5087e 100644
55805--- a/fs/exec.c
55806+++ b/fs/exec.c
55807@@ -55,8 +55,20 @@
55808 #include <linux/pipe_fs_i.h>
55809 #include <linux/oom.h>
55810 #include <linux/compat.h>
55811+#include <linux/random.h>
55812+#include <linux/seq_file.h>
55813+#include <linux/coredump.h>
55814+#include <linux/mman.h>
55815+
55816+#ifdef CONFIG_PAX_REFCOUNT
55817+#include <linux/kallsyms.h>
55818+#include <linux/kdebug.h>
55819+#endif
55820+
55821+#include <trace/events/fs.h>
55822
55823 #include <asm/uaccess.h>
55824+#include <asm/sections.h>
55825 #include <asm/mmu_context.h>
55826 #include <asm/tlb.h>
55827
55828@@ -66,19 +78,34 @@
55829
55830 #include <trace/events/sched.h>
55831
55832+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55833+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
55834+{
55835+ 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");
55836+}
55837+#endif
55838+
55839+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
55840+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
55841+EXPORT_SYMBOL(pax_set_initial_flags_func);
55842+#endif
55843+
55844 int suid_dumpable = 0;
55845
55846 static LIST_HEAD(formats);
55847 static DEFINE_RWLOCK(binfmt_lock);
55848
55849+extern int gr_process_kernel_exec_ban(void);
55850+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
55851+
55852 void __register_binfmt(struct linux_binfmt * fmt, int insert)
55853 {
55854 BUG_ON(!fmt);
55855 if (WARN_ON(!fmt->load_binary))
55856 return;
55857 write_lock(&binfmt_lock);
55858- insert ? list_add(&fmt->lh, &formats) :
55859- list_add_tail(&fmt->lh, &formats);
55860+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
55861+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
55862 write_unlock(&binfmt_lock);
55863 }
55864
55865@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
55866 void unregister_binfmt(struct linux_binfmt * fmt)
55867 {
55868 write_lock(&binfmt_lock);
55869- list_del(&fmt->lh);
55870+ pax_list_del((struct list_head *)&fmt->lh);
55871 write_unlock(&binfmt_lock);
55872 }
55873
55874@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55875 int write)
55876 {
55877 struct page *page;
55878- int ret;
55879
55880-#ifdef CONFIG_STACK_GROWSUP
55881- if (write) {
55882- ret = expand_downwards(bprm->vma, pos);
55883- if (ret < 0)
55884- return NULL;
55885- }
55886-#endif
55887- ret = get_user_pages(current, bprm->mm, pos,
55888- 1, write, 1, &page, NULL);
55889- if (ret <= 0)
55890+ if (0 > expand_downwards(bprm->vma, pos))
55891+ return NULL;
55892+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
55893 return NULL;
55894
55895 if (write) {
55896@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55897 if (size <= ARG_MAX)
55898 return page;
55899
55900+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55901+ // only allow 512KB for argv+env on suid/sgid binaries
55902+ // to prevent easy ASLR exhaustion
55903+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
55904+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
55905+ (size > (512 * 1024))) {
55906+ put_page(page);
55907+ return NULL;
55908+ }
55909+#endif
55910+
55911 /*
55912 * Limit to 1/4-th the stack size for the argv+env strings.
55913 * This ensures that:
55914@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55915 vma->vm_end = STACK_TOP_MAX;
55916 vma->vm_start = vma->vm_end - PAGE_SIZE;
55917 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
55918+
55919+#ifdef CONFIG_PAX_SEGMEXEC
55920+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
55921+#endif
55922+
55923 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
55924 INIT_LIST_HEAD(&vma->anon_vma_chain);
55925
55926@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55927 mm->stack_vm = mm->total_vm = 1;
55928 up_write(&mm->mmap_sem);
55929 bprm->p = vma->vm_end - sizeof(void *);
55930+
55931+#ifdef CONFIG_PAX_RANDUSTACK
55932+ if (randomize_va_space)
55933+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
55934+#endif
55935+
55936 return 0;
55937 err:
55938 up_write(&mm->mmap_sem);
55939@@ -399,7 +440,7 @@ struct user_arg_ptr {
55940 } ptr;
55941 };
55942
55943-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55944+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55945 {
55946 const char __user *native;
55947
55948@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55949 compat_uptr_t compat;
55950
55951 if (get_user(compat, argv.ptr.compat + nr))
55952- return ERR_PTR(-EFAULT);
55953+ return (const char __force_user *)ERR_PTR(-EFAULT);
55954
55955 return compat_ptr(compat);
55956 }
55957 #endif
55958
55959 if (get_user(native, argv.ptr.native + nr))
55960- return ERR_PTR(-EFAULT);
55961+ return (const char __force_user *)ERR_PTR(-EFAULT);
55962
55963 return native;
55964 }
55965@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
55966 if (!p)
55967 break;
55968
55969- if (IS_ERR(p))
55970+ if (IS_ERR((const char __force_kernel *)p))
55971 return -EFAULT;
55972
55973 if (i >= max)
55974@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
55975
55976 ret = -EFAULT;
55977 str = get_user_arg_ptr(argv, argc);
55978- if (IS_ERR(str))
55979+ if (IS_ERR((const char __force_kernel *)str))
55980 goto out;
55981
55982 len = strnlen_user(str, MAX_ARG_STRLEN);
55983@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
55984 int r;
55985 mm_segment_t oldfs = get_fs();
55986 struct user_arg_ptr argv = {
55987- .ptr.native = (const char __user *const __user *)__argv,
55988+ .ptr.native = (const char __force_user * const __force_user *)__argv,
55989 };
55990
55991 set_fs(KERNEL_DS);
55992@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55993 unsigned long new_end = old_end - shift;
55994 struct mmu_gather tlb;
55995
55996- BUG_ON(new_start > new_end);
55997+ if (new_start >= new_end || new_start < mmap_min_addr)
55998+ return -ENOMEM;
55999
56000 /*
56001 * ensure there are no vmas between where we want to go
56002@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
56003 if (vma != find_vma(mm, new_start))
56004 return -EFAULT;
56005
56006+#ifdef CONFIG_PAX_SEGMEXEC
56007+ BUG_ON(pax_find_mirror_vma(vma));
56008+#endif
56009+
56010 /*
56011 * cover the whole range: [new_start, old_end)
56012 */
56013@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
56014 stack_top = arch_align_stack(stack_top);
56015 stack_top = PAGE_ALIGN(stack_top);
56016
56017- if (unlikely(stack_top < mmap_min_addr) ||
56018- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
56019- return -ENOMEM;
56020-
56021 stack_shift = vma->vm_end - stack_top;
56022
56023 bprm->p -= stack_shift;
56024@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
56025 bprm->exec -= stack_shift;
56026
56027 down_write(&mm->mmap_sem);
56028+
56029+ /* Move stack pages down in memory. */
56030+ if (stack_shift) {
56031+ ret = shift_arg_pages(vma, stack_shift);
56032+ if (ret)
56033+ goto out_unlock;
56034+ }
56035+
56036 vm_flags = VM_STACK_FLAGS;
56037
56038+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56039+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56040+ vm_flags &= ~VM_EXEC;
56041+
56042+#ifdef CONFIG_PAX_MPROTECT
56043+ if (mm->pax_flags & MF_PAX_MPROTECT)
56044+ vm_flags &= ~VM_MAYEXEC;
56045+#endif
56046+
56047+ }
56048+#endif
56049+
56050 /*
56051 * Adjust stack execute permissions; explicitly enable for
56052 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
56053@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
56054 goto out_unlock;
56055 BUG_ON(prev != vma);
56056
56057- /* Move stack pages down in memory. */
56058- if (stack_shift) {
56059- ret = shift_arg_pages(vma, stack_shift);
56060- if (ret)
56061- goto out_unlock;
56062- }
56063-
56064 /* mprotect_fixup is overkill to remove the temporary stack flags */
56065 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
56066
56067@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
56068 #endif
56069 current->mm->start_stack = bprm->p;
56070 ret = expand_stack(vma, stack_base);
56071+
56072+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
56073+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
56074+ unsigned long size;
56075+ vm_flags_t vm_flags;
56076+
56077+ size = STACK_TOP - vma->vm_end;
56078+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
56079+
56080+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
56081+
56082+#ifdef CONFIG_X86
56083+ if (!ret) {
56084+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
56085+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
56086+ }
56087+#endif
56088+
56089+ }
56090+#endif
56091+
56092 if (ret)
56093 ret = -EFAULT;
56094
56095@@ -776,6 +852,8 @@ struct file *open_exec(const char *name)
56096
56097 fsnotify_open(file);
56098
56099+ trace_open_exec(name);
56100+
56101 err = deny_write_access(file);
56102 if (err)
56103 goto exit;
56104@@ -799,7 +877,7 @@ int kernel_read(struct file *file, loff_t offset,
56105 old_fs = get_fs();
56106 set_fs(get_ds());
56107 /* The cast to a user pointer is valid due to the set_fs() */
56108- result = vfs_read(file, (void __user *)addr, count, &pos);
56109+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
56110 set_fs(old_fs);
56111 return result;
56112 }
56113@@ -1255,7 +1333,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
56114 }
56115 rcu_read_unlock();
56116
56117- if (p->fs->users > n_fs) {
56118+ if (atomic_read(&p->fs->users) > n_fs) {
56119 bprm->unsafe |= LSM_UNSAFE_SHARE;
56120 } else {
56121 res = -EAGAIN;
56122@@ -1451,6 +1529,31 @@ static int exec_binprm(struct linux_binprm *bprm)
56123 return ret;
56124 }
56125
56126+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56127+static DEFINE_PER_CPU(u64, exec_counter);
56128+static int __init init_exec_counters(void)
56129+{
56130+ unsigned int cpu;
56131+
56132+ for_each_possible_cpu(cpu) {
56133+ per_cpu(exec_counter, cpu) = (u64)cpu;
56134+ }
56135+
56136+ return 0;
56137+}
56138+early_initcall(init_exec_counters);
56139+static inline void increment_exec_counter(void)
56140+{
56141+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
56142+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
56143+}
56144+#else
56145+static inline void increment_exec_counter(void) {}
56146+#endif
56147+
56148+extern void gr_handle_exec_args(struct linux_binprm *bprm,
56149+ struct user_arg_ptr argv);
56150+
56151 /*
56152 * sys_execve() executes a new program.
56153 */
56154@@ -1458,12 +1561,19 @@ static int do_execve_common(const char *filename,
56155 struct user_arg_ptr argv,
56156 struct user_arg_ptr envp)
56157 {
56158+#ifdef CONFIG_GRKERNSEC
56159+ struct file *old_exec_file;
56160+ struct acl_subject_label *old_acl;
56161+ struct rlimit old_rlim[RLIM_NLIMITS];
56162+#endif
56163 struct linux_binprm *bprm;
56164 struct file *file;
56165 struct files_struct *displaced;
56166 bool clear_in_exec;
56167 int retval;
56168
56169+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
56170+
56171 /*
56172 * We move the actual failure in case of RLIMIT_NPROC excess from
56173 * set*uid() to execve() because too many poorly written programs
56174@@ -1504,12 +1614,22 @@ static int do_execve_common(const char *filename,
56175 if (IS_ERR(file))
56176 goto out_unmark;
56177
56178+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
56179+ retval = -EPERM;
56180+ goto out_file;
56181+ }
56182+
56183 sched_exec();
56184
56185 bprm->file = file;
56186 bprm->filename = filename;
56187 bprm->interp = filename;
56188
56189+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
56190+ retval = -EACCES;
56191+ goto out_file;
56192+ }
56193+
56194 retval = bprm_mm_init(bprm);
56195 if (retval)
56196 goto out_file;
56197@@ -1526,24 +1646,70 @@ static int do_execve_common(const char *filename,
56198 if (retval < 0)
56199 goto out;
56200
56201+#ifdef CONFIG_GRKERNSEC
56202+ old_acl = current->acl;
56203+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
56204+ old_exec_file = current->exec_file;
56205+ get_file(file);
56206+ current->exec_file = file;
56207+#endif
56208+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56209+ /* limit suid stack to 8MB
56210+ * we saved the old limits above and will restore them if this exec fails
56211+ */
56212+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
56213+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
56214+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
56215+#endif
56216+
56217+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
56218+ retval = -EPERM;
56219+ goto out_fail;
56220+ }
56221+
56222+ if (!gr_tpe_allow(file)) {
56223+ retval = -EACCES;
56224+ goto out_fail;
56225+ }
56226+
56227+ if (gr_check_crash_exec(file)) {
56228+ retval = -EACCES;
56229+ goto out_fail;
56230+ }
56231+
56232+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
56233+ bprm->unsafe);
56234+ if (retval < 0)
56235+ goto out_fail;
56236+
56237 retval = copy_strings_kernel(1, &bprm->filename, bprm);
56238 if (retval < 0)
56239- goto out;
56240+ goto out_fail;
56241
56242 bprm->exec = bprm->p;
56243 retval = copy_strings(bprm->envc, envp, bprm);
56244 if (retval < 0)
56245- goto out;
56246+ goto out_fail;
56247
56248 retval = copy_strings(bprm->argc, argv, bprm);
56249 if (retval < 0)
56250- goto out;
56251+ goto out_fail;
56252+
56253+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
56254+
56255+ gr_handle_exec_args(bprm, argv);
56256
56257 retval = exec_binprm(bprm);
56258 if (retval < 0)
56259- goto out;
56260+ goto out_fail;
56261+#ifdef CONFIG_GRKERNSEC
56262+ if (old_exec_file)
56263+ fput(old_exec_file);
56264+#endif
56265
56266 /* execve succeeded */
56267+
56268+ increment_exec_counter();
56269 current->fs->in_exec = 0;
56270 current->in_execve = 0;
56271 acct_update_integrals(current);
56272@@ -1552,6 +1718,14 @@ static int do_execve_common(const char *filename,
56273 put_files_struct(displaced);
56274 return retval;
56275
56276+out_fail:
56277+#ifdef CONFIG_GRKERNSEC
56278+ current->acl = old_acl;
56279+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
56280+ fput(current->exec_file);
56281+ current->exec_file = old_exec_file;
56282+#endif
56283+
56284 out:
56285 if (bprm->mm) {
56286 acct_arg_size(bprm, 0);
56287@@ -1706,3 +1880,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
56288 return error;
56289 }
56290 #endif
56291+
56292+int pax_check_flags(unsigned long *flags)
56293+{
56294+ int retval = 0;
56295+
56296+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
56297+ if (*flags & MF_PAX_SEGMEXEC)
56298+ {
56299+ *flags &= ~MF_PAX_SEGMEXEC;
56300+ retval = -EINVAL;
56301+ }
56302+#endif
56303+
56304+ if ((*flags & MF_PAX_PAGEEXEC)
56305+
56306+#ifdef CONFIG_PAX_PAGEEXEC
56307+ && (*flags & MF_PAX_SEGMEXEC)
56308+#endif
56309+
56310+ )
56311+ {
56312+ *flags &= ~MF_PAX_PAGEEXEC;
56313+ retval = -EINVAL;
56314+ }
56315+
56316+ if ((*flags & MF_PAX_MPROTECT)
56317+
56318+#ifdef CONFIG_PAX_MPROTECT
56319+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56320+#endif
56321+
56322+ )
56323+ {
56324+ *flags &= ~MF_PAX_MPROTECT;
56325+ retval = -EINVAL;
56326+ }
56327+
56328+ if ((*flags & MF_PAX_EMUTRAMP)
56329+
56330+#ifdef CONFIG_PAX_EMUTRAMP
56331+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56332+#endif
56333+
56334+ )
56335+ {
56336+ *flags &= ~MF_PAX_EMUTRAMP;
56337+ retval = -EINVAL;
56338+ }
56339+
56340+ return retval;
56341+}
56342+
56343+EXPORT_SYMBOL(pax_check_flags);
56344+
56345+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56346+char *pax_get_path(const struct path *path, char *buf, int buflen)
56347+{
56348+ char *pathname = d_path(path, buf, buflen);
56349+
56350+ if (IS_ERR(pathname))
56351+ goto toolong;
56352+
56353+ pathname = mangle_path(buf, pathname, "\t\n\\");
56354+ if (!pathname)
56355+ goto toolong;
56356+
56357+ *pathname = 0;
56358+ return buf;
56359+
56360+toolong:
56361+ return "<path too long>";
56362+}
56363+EXPORT_SYMBOL(pax_get_path);
56364+
56365+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
56366+{
56367+ struct task_struct *tsk = current;
56368+ struct mm_struct *mm = current->mm;
56369+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
56370+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
56371+ char *path_exec = NULL;
56372+ char *path_fault = NULL;
56373+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
56374+ siginfo_t info = { };
56375+
56376+ if (buffer_exec && buffer_fault) {
56377+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
56378+
56379+ down_read(&mm->mmap_sem);
56380+ vma = mm->mmap;
56381+ while (vma && (!vma_exec || !vma_fault)) {
56382+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
56383+ vma_exec = vma;
56384+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
56385+ vma_fault = vma;
56386+ vma = vma->vm_next;
56387+ }
56388+ if (vma_exec)
56389+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
56390+ if (vma_fault) {
56391+ start = vma_fault->vm_start;
56392+ end = vma_fault->vm_end;
56393+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
56394+ if (vma_fault->vm_file)
56395+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
56396+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
56397+ path_fault = "<heap>";
56398+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
56399+ path_fault = "<stack>";
56400+ else
56401+ path_fault = "<anonymous mapping>";
56402+ }
56403+ up_read(&mm->mmap_sem);
56404+ }
56405+ if (tsk->signal->curr_ip)
56406+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
56407+ else
56408+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
56409+ 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),
56410+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
56411+ free_page((unsigned long)buffer_exec);
56412+ free_page((unsigned long)buffer_fault);
56413+ pax_report_insns(regs, pc, sp);
56414+ info.si_signo = SIGKILL;
56415+ info.si_errno = 0;
56416+ info.si_code = SI_KERNEL;
56417+ info.si_pid = 0;
56418+ info.si_uid = 0;
56419+ do_coredump(&info);
56420+}
56421+#endif
56422+
56423+#ifdef CONFIG_PAX_REFCOUNT
56424+void pax_report_refcount_overflow(struct pt_regs *regs)
56425+{
56426+ if (current->signal->curr_ip)
56427+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
56428+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
56429+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56430+ else
56431+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
56432+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56433+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
56434+ preempt_disable();
56435+ show_regs(regs);
56436+ preempt_enable();
56437+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
56438+}
56439+#endif
56440+
56441+#ifdef CONFIG_PAX_USERCOPY
56442+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
56443+static noinline int check_stack_object(const void *obj, unsigned long len)
56444+{
56445+ const void * const stack = task_stack_page(current);
56446+ const void * const stackend = stack + THREAD_SIZE;
56447+
56448+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56449+ const void *frame = NULL;
56450+ const void *oldframe;
56451+#endif
56452+
56453+ if (obj + len < obj)
56454+ return -1;
56455+
56456+ if (obj + len <= stack || stackend <= obj)
56457+ return 0;
56458+
56459+ if (obj < stack || stackend < obj + len)
56460+ return -1;
56461+
56462+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56463+ oldframe = __builtin_frame_address(1);
56464+ if (oldframe)
56465+ frame = __builtin_frame_address(2);
56466+ /*
56467+ low ----------------------------------------------> high
56468+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
56469+ ^----------------^
56470+ allow copies only within here
56471+ */
56472+ while (stack <= frame && frame < stackend) {
56473+ /* if obj + len extends past the last frame, this
56474+ check won't pass and the next frame will be 0,
56475+ causing us to bail out and correctly report
56476+ the copy as invalid
56477+ */
56478+ if (obj + len <= frame)
56479+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
56480+ oldframe = frame;
56481+ frame = *(const void * const *)frame;
56482+ }
56483+ return -1;
56484+#else
56485+ return 1;
56486+#endif
56487+}
56488+
56489+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
56490+{
56491+ if (current->signal->curr_ip)
56492+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56493+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56494+ else
56495+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56496+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56497+ dump_stack();
56498+ gr_handle_kernel_exploit();
56499+ do_group_exit(SIGKILL);
56500+}
56501+#endif
56502+
56503+#ifdef CONFIG_PAX_USERCOPY
56504+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
56505+{
56506+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
56507+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
56508+#ifdef CONFIG_MODULES
56509+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
56510+#else
56511+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
56512+#endif
56513+
56514+#else
56515+ unsigned long textlow = (unsigned long)_stext;
56516+ unsigned long texthigh = (unsigned long)_etext;
56517+
56518+#ifdef CONFIG_X86_64
56519+ /* check against linear mapping as well */
56520+ if (high > (unsigned long)__va(__pa(textlow)) &&
56521+ low <= (unsigned long)__va(__pa(texthigh)))
56522+ return true;
56523+#endif
56524+
56525+#endif
56526+
56527+ if (high <= textlow || low > texthigh)
56528+ return false;
56529+ else
56530+ return true;
56531+}
56532+#endif
56533+
56534+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
56535+{
56536+
56537+#ifdef CONFIG_PAX_USERCOPY
56538+ const char *type;
56539+
56540+ if (!n)
56541+ return;
56542+
56543+ type = check_heap_object(ptr, n);
56544+ if (!type) {
56545+ int ret = check_stack_object(ptr, n);
56546+ if (ret == 1 || ret == 2)
56547+ return;
56548+ if (ret == 0) {
56549+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
56550+ type = "<kernel text>";
56551+ else
56552+ return;
56553+ } else
56554+ type = "<process stack>";
56555+ }
56556+
56557+ pax_report_usercopy(ptr, n, to_user, type);
56558+#endif
56559+
56560+}
56561+EXPORT_SYMBOL(__check_object_size);
56562+
56563+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56564+void pax_track_stack(void)
56565+{
56566+ unsigned long sp = (unsigned long)&sp;
56567+ if (sp < current_thread_info()->lowest_stack &&
56568+ sp > (unsigned long)task_stack_page(current))
56569+ current_thread_info()->lowest_stack = sp;
56570+}
56571+EXPORT_SYMBOL(pax_track_stack);
56572+#endif
56573+
56574+#ifdef CONFIG_PAX_SIZE_OVERFLOW
56575+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
56576+{
56577+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
56578+ dump_stack();
56579+ do_group_exit(SIGKILL);
56580+}
56581+EXPORT_SYMBOL(report_size_overflow);
56582+#endif
56583diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
56584index 9f9992b..8b59411 100644
56585--- a/fs/ext2/balloc.c
56586+++ b/fs/ext2/balloc.c
56587@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
56588
56589 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56590 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56591- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56592+ if (free_blocks < root_blocks + 1 &&
56593 !uid_eq(sbi->s_resuid, current_fsuid()) &&
56594 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56595- !in_group_p (sbi->s_resgid))) {
56596+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56597 return 0;
56598 }
56599 return 1;
56600diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
56601index 2d7557d..14e38f94 100644
56602--- a/fs/ext2/xattr.c
56603+++ b/fs/ext2/xattr.c
56604@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
56605 struct buffer_head *bh = NULL;
56606 struct ext2_xattr_entry *entry;
56607 char *end;
56608- size_t rest = buffer_size;
56609+ size_t rest = buffer_size, total_size = 0;
56610 int error;
56611
56612 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
56613@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
56614 buffer += size;
56615 }
56616 rest -= size;
56617+ total_size += size;
56618 }
56619 }
56620- error = buffer_size - rest; /* total size */
56621+ error = total_size;
56622
56623 cleanup:
56624 brelse(bh);
56625diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
56626index 22548f5..41521d8 100644
56627--- a/fs/ext3/balloc.c
56628+++ b/fs/ext3/balloc.c
56629@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
56630
56631 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56632 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56633- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56634+ if (free_blocks < root_blocks + 1 &&
56635 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
56636 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56637- !in_group_p (sbi->s_resgid))) {
56638+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56639 return 0;
56640 }
56641 return 1;
56642diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
56643index b1fc963..881228c 100644
56644--- a/fs/ext3/xattr.c
56645+++ b/fs/ext3/xattr.c
56646@@ -330,7 +330,7 @@ static int
56647 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
56648 char *buffer, size_t buffer_size)
56649 {
56650- size_t rest = buffer_size;
56651+ size_t rest = buffer_size, total_size = 0;
56652
56653 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
56654 const struct xattr_handler *handler =
56655@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
56656 buffer += size;
56657 }
56658 rest -= size;
56659+ total_size += size;
56660 }
56661 }
56662- return buffer_size - rest;
56663+ return total_size;
56664 }
56665
56666 static int
56667diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
56668index dc5d572..4c21f8e 100644
56669--- a/fs/ext4/balloc.c
56670+++ b/fs/ext4/balloc.c
56671@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
56672 /* Hm, nope. Are (enough) root reserved clusters available? */
56673 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
56674 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
56675- capable(CAP_SYS_RESOURCE) ||
56676- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
56677+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
56678+ capable_nolog(CAP_SYS_RESOURCE)) {
56679
56680 if (free_clusters >= (nclusters + dirty_clusters +
56681 resv_clusters))
56682diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
56683index af815ea..99294a6 100644
56684--- a/fs/ext4/ext4.h
56685+++ b/fs/ext4/ext4.h
56686@@ -1256,19 +1256,19 @@ struct ext4_sb_info {
56687 unsigned long s_mb_last_start;
56688
56689 /* stats for buddy allocator */
56690- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
56691- atomic_t s_bal_success; /* we found long enough chunks */
56692- atomic_t s_bal_allocated; /* in blocks */
56693- atomic_t s_bal_ex_scanned; /* total extents scanned */
56694- atomic_t s_bal_goals; /* goal hits */
56695- atomic_t s_bal_breaks; /* too long searches */
56696- atomic_t s_bal_2orders; /* 2^order hits */
56697+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
56698+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
56699+ atomic_unchecked_t s_bal_allocated; /* in blocks */
56700+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
56701+ atomic_unchecked_t s_bal_goals; /* goal hits */
56702+ atomic_unchecked_t s_bal_breaks; /* too long searches */
56703+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
56704 spinlock_t s_bal_lock;
56705 unsigned long s_mb_buddies_generated;
56706 unsigned long long s_mb_generation_time;
56707- atomic_t s_mb_lost_chunks;
56708- atomic_t s_mb_preallocated;
56709- atomic_t s_mb_discarded;
56710+ atomic_unchecked_t s_mb_lost_chunks;
56711+ atomic_unchecked_t s_mb_preallocated;
56712+ atomic_unchecked_t s_mb_discarded;
56713 atomic_t s_lock_busy;
56714
56715 /* locality groups */
56716diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
56717index a41e3ba..e574a00 100644
56718--- a/fs/ext4/mballoc.c
56719+++ b/fs/ext4/mballoc.c
56720@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
56721 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
56722
56723 if (EXT4_SB(sb)->s_mb_stats)
56724- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
56725+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
56726
56727 break;
56728 }
56729@@ -2189,7 +2189,7 @@ repeat:
56730 ac->ac_status = AC_STATUS_CONTINUE;
56731 ac->ac_flags |= EXT4_MB_HINT_FIRST;
56732 cr = 3;
56733- atomic_inc(&sbi->s_mb_lost_chunks);
56734+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
56735 goto repeat;
56736 }
56737 }
56738@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
56739 if (sbi->s_mb_stats) {
56740 ext4_msg(sb, KERN_INFO,
56741 "mballoc: %u blocks %u reqs (%u success)",
56742- atomic_read(&sbi->s_bal_allocated),
56743- atomic_read(&sbi->s_bal_reqs),
56744- atomic_read(&sbi->s_bal_success));
56745+ atomic_read_unchecked(&sbi->s_bal_allocated),
56746+ atomic_read_unchecked(&sbi->s_bal_reqs),
56747+ atomic_read_unchecked(&sbi->s_bal_success));
56748 ext4_msg(sb, KERN_INFO,
56749 "mballoc: %u extents scanned, %u goal hits, "
56750 "%u 2^N hits, %u breaks, %u lost",
56751- atomic_read(&sbi->s_bal_ex_scanned),
56752- atomic_read(&sbi->s_bal_goals),
56753- atomic_read(&sbi->s_bal_2orders),
56754- atomic_read(&sbi->s_bal_breaks),
56755- atomic_read(&sbi->s_mb_lost_chunks));
56756+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
56757+ atomic_read_unchecked(&sbi->s_bal_goals),
56758+ atomic_read_unchecked(&sbi->s_bal_2orders),
56759+ atomic_read_unchecked(&sbi->s_bal_breaks),
56760+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
56761 ext4_msg(sb, KERN_INFO,
56762 "mballoc: %lu generated and it took %Lu",
56763 sbi->s_mb_buddies_generated,
56764 sbi->s_mb_generation_time);
56765 ext4_msg(sb, KERN_INFO,
56766 "mballoc: %u preallocated, %u discarded",
56767- atomic_read(&sbi->s_mb_preallocated),
56768- atomic_read(&sbi->s_mb_discarded));
56769+ atomic_read_unchecked(&sbi->s_mb_preallocated),
56770+ atomic_read_unchecked(&sbi->s_mb_discarded));
56771 }
56772
56773 free_percpu(sbi->s_locality_groups);
56774@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
56775 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
56776
56777 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
56778- atomic_inc(&sbi->s_bal_reqs);
56779- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56780+ atomic_inc_unchecked(&sbi->s_bal_reqs);
56781+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56782 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
56783- atomic_inc(&sbi->s_bal_success);
56784- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
56785+ atomic_inc_unchecked(&sbi->s_bal_success);
56786+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
56787 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
56788 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
56789- atomic_inc(&sbi->s_bal_goals);
56790+ atomic_inc_unchecked(&sbi->s_bal_goals);
56791 if (ac->ac_found > sbi->s_mb_max_to_scan)
56792- atomic_inc(&sbi->s_bal_breaks);
56793+ atomic_inc_unchecked(&sbi->s_bal_breaks);
56794 }
56795
56796 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
56797@@ -3578,7 +3578,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
56798 trace_ext4_mb_new_inode_pa(ac, pa);
56799
56800 ext4_mb_use_inode_pa(ac, pa);
56801- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
56802+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
56803
56804 ei = EXT4_I(ac->ac_inode);
56805 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56806@@ -3638,7 +3638,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
56807 trace_ext4_mb_new_group_pa(ac, pa);
56808
56809 ext4_mb_use_group_pa(ac, pa);
56810- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56811+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56812
56813 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56814 lg = ac->ac_lg;
56815@@ -3727,7 +3727,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
56816 * from the bitmap and continue.
56817 */
56818 }
56819- atomic_add(free, &sbi->s_mb_discarded);
56820+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
56821
56822 return err;
56823 }
56824@@ -3745,7 +3745,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
56825 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
56826 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
56827 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
56828- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56829+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56830 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
56831
56832 return 0;
56833diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
56834index 214461e..3614c89 100644
56835--- a/fs/ext4/mmp.c
56836+++ b/fs/ext4/mmp.c
56837@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
56838 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
56839 const char *function, unsigned int line, const char *msg)
56840 {
56841- __ext4_warning(sb, function, line, msg);
56842+ __ext4_warning(sb, function, line, "%s", msg);
56843 __ext4_warning(sb, function, line,
56844 "MMP failure info: last update time: %llu, last update "
56845 "node: %s, last update device: %s\n",
56846diff --git a/fs/ext4/super.c b/fs/ext4/super.c
56847index 2c2e6cb..7c3ee62 100644
56848--- a/fs/ext4/super.c
56849+++ b/fs/ext4/super.c
56850@@ -1251,7 +1251,7 @@ static ext4_fsblk_t get_sb_block(void **data)
56851 }
56852
56853 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
56854-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56855+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56856 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
56857
56858 #ifdef CONFIG_QUOTA
56859@@ -2431,7 +2431,7 @@ struct ext4_attr {
56860 int offset;
56861 int deprecated_val;
56862 } u;
56863-};
56864+} __do_const;
56865
56866 static int parse_strtoull(const char *buf,
56867 unsigned long long max, unsigned long long *value)
56868diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
56869index 1423c48..9c0c6dc 100644
56870--- a/fs/ext4/xattr.c
56871+++ b/fs/ext4/xattr.c
56872@@ -381,7 +381,7 @@ static int
56873 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56874 char *buffer, size_t buffer_size)
56875 {
56876- size_t rest = buffer_size;
56877+ size_t rest = buffer_size, total_size = 0;
56878
56879 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
56880 const struct xattr_handler *handler =
56881@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56882 buffer += size;
56883 }
56884 rest -= size;
56885+ total_size += size;
56886 }
56887 }
56888- return buffer_size - rest;
56889+ return total_size;
56890 }
56891
56892 static int
56893diff --git a/fs/fcntl.c b/fs/fcntl.c
56894index 65343c3..9969dcf 100644
56895--- a/fs/fcntl.c
56896+++ b/fs/fcntl.c
56897@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
56898 if (err)
56899 return err;
56900
56901+ if (gr_handle_chroot_fowner(pid, type))
56902+ return -ENOENT;
56903+ if (gr_check_protected_task_fowner(pid, type))
56904+ return -EACCES;
56905+
56906 f_modown(filp, pid, type, force);
56907 return 0;
56908 }
56909diff --git a/fs/fhandle.c b/fs/fhandle.c
56910index 999ff5c..41f4109 100644
56911--- a/fs/fhandle.c
56912+++ b/fs/fhandle.c
56913@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
56914 } else
56915 retval = 0;
56916 /* copy the mount id */
56917- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
56918- sizeof(*mnt_id)) ||
56919+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
56920 copy_to_user(ufh, handle,
56921 sizeof(struct file_handle) + handle_bytes))
56922 retval = -EFAULT;
56923diff --git a/fs/file.c b/fs/file.c
56924index 4a78f98..f9a6d25 100644
56925--- a/fs/file.c
56926+++ b/fs/file.c
56927@@ -16,6 +16,7 @@
56928 #include <linux/slab.h>
56929 #include <linux/vmalloc.h>
56930 #include <linux/file.h>
56931+#include <linux/security.h>
56932 #include <linux/fdtable.h>
56933 #include <linux/bitops.h>
56934 #include <linux/interrupt.h>
56935@@ -141,7 +142,7 @@ out:
56936 * Return <0 error code on error; 1 on successful completion.
56937 * The files->file_lock should be held on entry, and will be held on exit.
56938 */
56939-static int expand_fdtable(struct files_struct *files, int nr)
56940+static int expand_fdtable(struct files_struct *files, unsigned int nr)
56941 __releases(files->file_lock)
56942 __acquires(files->file_lock)
56943 {
56944@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
56945 * expanded and execution may have blocked.
56946 * The files->file_lock should be held on entry, and will be held on exit.
56947 */
56948-static int expand_files(struct files_struct *files, int nr)
56949+static int expand_files(struct files_struct *files, unsigned int nr)
56950 {
56951 struct fdtable *fdt;
56952
56953@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
56954 if (!file)
56955 return __close_fd(files, fd);
56956
56957+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
56958 if (fd >= rlimit(RLIMIT_NOFILE))
56959 return -EBADF;
56960
56961@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
56962 if (unlikely(oldfd == newfd))
56963 return -EINVAL;
56964
56965+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
56966 if (newfd >= rlimit(RLIMIT_NOFILE))
56967 return -EBADF;
56968
56969@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
56970 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
56971 {
56972 int err;
56973+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
56974 if (from >= rlimit(RLIMIT_NOFILE))
56975 return -EINVAL;
56976 err = alloc_fd(from, flags);
56977diff --git a/fs/filesystems.c b/fs/filesystems.c
56978index 92567d9..fcd8cbf 100644
56979--- a/fs/filesystems.c
56980+++ b/fs/filesystems.c
56981@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
56982 int len = dot ? dot - name : strlen(name);
56983
56984 fs = __get_fs_type(name, len);
56985+#ifdef CONFIG_GRKERNSEC_MODHARDEN
56986+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
56987+#else
56988 if (!fs && (request_module("fs-%.*s", len, name) == 0))
56989+#endif
56990 fs = __get_fs_type(name, len);
56991
56992 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
56993diff --git a/fs/fs_struct.c b/fs/fs_struct.c
56994index d8ac61d..79a36f0 100644
56995--- a/fs/fs_struct.c
56996+++ b/fs/fs_struct.c
56997@@ -4,6 +4,7 @@
56998 #include <linux/path.h>
56999 #include <linux/slab.h>
57000 #include <linux/fs_struct.h>
57001+#include <linux/grsecurity.h>
57002 #include "internal.h"
57003
57004 /*
57005@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
57006 write_seqcount_begin(&fs->seq);
57007 old_root = fs->root;
57008 fs->root = *path;
57009+ gr_set_chroot_entries(current, path);
57010 write_seqcount_end(&fs->seq);
57011 spin_unlock(&fs->lock);
57012 if (old_root.dentry)
57013@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
57014 int hits = 0;
57015 spin_lock(&fs->lock);
57016 write_seqcount_begin(&fs->seq);
57017+ /* this root replacement is only done by pivot_root,
57018+ leave grsec's chroot tagging alone for this task
57019+ so that a pivoted root isn't treated as a chroot
57020+ */
57021 hits += replace_path(&fs->root, old_root, new_root);
57022 hits += replace_path(&fs->pwd, old_root, new_root);
57023 write_seqcount_end(&fs->seq);
57024@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
57025 task_lock(tsk);
57026 spin_lock(&fs->lock);
57027 tsk->fs = NULL;
57028- kill = !--fs->users;
57029+ gr_clear_chroot_entries(tsk);
57030+ kill = !atomic_dec_return(&fs->users);
57031 spin_unlock(&fs->lock);
57032 task_unlock(tsk);
57033 if (kill)
57034@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
57035 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
57036 /* We don't need to lock fs - think why ;-) */
57037 if (fs) {
57038- fs->users = 1;
57039+ atomic_set(&fs->users, 1);
57040 fs->in_exec = 0;
57041 spin_lock_init(&fs->lock);
57042 seqcount_init(&fs->seq);
57043@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
57044 spin_lock(&old->lock);
57045 fs->root = old->root;
57046 path_get(&fs->root);
57047+ /* instead of calling gr_set_chroot_entries here,
57048+ we call it from every caller of this function
57049+ */
57050 fs->pwd = old->pwd;
57051 path_get(&fs->pwd);
57052 spin_unlock(&old->lock);
57053@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
57054
57055 task_lock(current);
57056 spin_lock(&fs->lock);
57057- kill = !--fs->users;
57058+ kill = !atomic_dec_return(&fs->users);
57059 current->fs = new_fs;
57060+ gr_set_chroot_entries(current, &new_fs->root);
57061 spin_unlock(&fs->lock);
57062 task_unlock(current);
57063
57064@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
57065
57066 int current_umask(void)
57067 {
57068- return current->fs->umask;
57069+ return current->fs->umask | gr_acl_umask();
57070 }
57071 EXPORT_SYMBOL(current_umask);
57072
57073 /* to be mentioned only in INIT_TASK */
57074 struct fs_struct init_fs = {
57075- .users = 1,
57076+ .users = ATOMIC_INIT(1),
57077 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
57078 .seq = SEQCNT_ZERO,
57079 .umask = 0022,
57080diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
57081index b2a86e3..37f425a 100644
57082--- a/fs/fscache/cookie.c
57083+++ b/fs/fscache/cookie.c
57084@@ -19,7 +19,7 @@
57085
57086 struct kmem_cache *fscache_cookie_jar;
57087
57088-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
57089+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
57090
57091 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
57092 static int fscache_alloc_object(struct fscache_cache *cache,
57093@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
57094 parent ? (char *) parent->def->name : "<no-parent>",
57095 def->name, netfs_data);
57096
57097- fscache_stat(&fscache_n_acquires);
57098+ fscache_stat_unchecked(&fscache_n_acquires);
57099
57100 /* if there's no parent cookie, then we don't create one here either */
57101 if (!parent) {
57102- fscache_stat(&fscache_n_acquires_null);
57103+ fscache_stat_unchecked(&fscache_n_acquires_null);
57104 _leave(" [no parent]");
57105 return NULL;
57106 }
57107@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
57108 /* allocate and initialise a cookie */
57109 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
57110 if (!cookie) {
57111- fscache_stat(&fscache_n_acquires_oom);
57112+ fscache_stat_unchecked(&fscache_n_acquires_oom);
57113 _leave(" [ENOMEM]");
57114 return NULL;
57115 }
57116@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
57117
57118 switch (cookie->def->type) {
57119 case FSCACHE_COOKIE_TYPE_INDEX:
57120- fscache_stat(&fscache_n_cookie_index);
57121+ fscache_stat_unchecked(&fscache_n_cookie_index);
57122 break;
57123 case FSCACHE_COOKIE_TYPE_DATAFILE:
57124- fscache_stat(&fscache_n_cookie_data);
57125+ fscache_stat_unchecked(&fscache_n_cookie_data);
57126 break;
57127 default:
57128- fscache_stat(&fscache_n_cookie_special);
57129+ fscache_stat_unchecked(&fscache_n_cookie_special);
57130 break;
57131 }
57132
57133@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
57134 if (fscache_acquire_non_index_cookie(cookie) < 0) {
57135 atomic_dec(&parent->n_children);
57136 __fscache_cookie_put(cookie);
57137- fscache_stat(&fscache_n_acquires_nobufs);
57138+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
57139 _leave(" = NULL");
57140 return NULL;
57141 }
57142 }
57143
57144- fscache_stat(&fscache_n_acquires_ok);
57145+ fscache_stat_unchecked(&fscache_n_acquires_ok);
57146 _leave(" = %p", cookie);
57147 return cookie;
57148 }
57149@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
57150 cache = fscache_select_cache_for_object(cookie->parent);
57151 if (!cache) {
57152 up_read(&fscache_addremove_sem);
57153- fscache_stat(&fscache_n_acquires_no_cache);
57154+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
57155 _leave(" = -ENOMEDIUM [no cache]");
57156 return -ENOMEDIUM;
57157 }
57158@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
57159 object = cache->ops->alloc_object(cache, cookie);
57160 fscache_stat_d(&fscache_n_cop_alloc_object);
57161 if (IS_ERR(object)) {
57162- fscache_stat(&fscache_n_object_no_alloc);
57163+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
57164 ret = PTR_ERR(object);
57165 goto error;
57166 }
57167
57168- fscache_stat(&fscache_n_object_alloc);
57169+ fscache_stat_unchecked(&fscache_n_object_alloc);
57170
57171- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
57172+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
57173
57174 _debug("ALLOC OBJ%x: %s {%lx}",
57175 object->debug_id, cookie->def->name, object->events);
57176@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
57177
57178 _enter("{%s}", cookie->def->name);
57179
57180- fscache_stat(&fscache_n_invalidates);
57181+ fscache_stat_unchecked(&fscache_n_invalidates);
57182
57183 /* Only permit invalidation of data files. Invalidating an index will
57184 * require the caller to release all its attachments to the tree rooted
57185@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
57186 {
57187 struct fscache_object *object;
57188
57189- fscache_stat(&fscache_n_updates);
57190+ fscache_stat_unchecked(&fscache_n_updates);
57191
57192 if (!cookie) {
57193- fscache_stat(&fscache_n_updates_null);
57194+ fscache_stat_unchecked(&fscache_n_updates_null);
57195 _leave(" [no cookie]");
57196 return;
57197 }
57198@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
57199 {
57200 struct fscache_object *object;
57201
57202- fscache_stat(&fscache_n_relinquishes);
57203+ fscache_stat_unchecked(&fscache_n_relinquishes);
57204 if (retire)
57205- fscache_stat(&fscache_n_relinquishes_retire);
57206+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
57207
57208 if (!cookie) {
57209- fscache_stat(&fscache_n_relinquishes_null);
57210+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
57211 _leave(" [no cookie]");
57212 return;
57213 }
57214@@ -598,7 +598,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
57215 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
57216 goto inconsistent;
57217
57218- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
57219+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57220
57221 atomic_inc(&cookie->n_active);
57222 if (fscache_submit_op(object, op) < 0)
57223diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
57224index 4226f66..0fb3f45 100644
57225--- a/fs/fscache/internal.h
57226+++ b/fs/fscache/internal.h
57227@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
57228 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
57229 extern int fscache_wait_for_operation_activation(struct fscache_object *,
57230 struct fscache_operation *,
57231- atomic_t *,
57232- atomic_t *,
57233+ atomic_unchecked_t *,
57234+ atomic_unchecked_t *,
57235 void (*)(struct fscache_operation *));
57236 extern void fscache_invalidate_writes(struct fscache_cookie *);
57237
57238@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
57239 * stats.c
57240 */
57241 #ifdef CONFIG_FSCACHE_STATS
57242-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
57243-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
57244+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
57245+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
57246
57247-extern atomic_t fscache_n_op_pend;
57248-extern atomic_t fscache_n_op_run;
57249-extern atomic_t fscache_n_op_enqueue;
57250-extern atomic_t fscache_n_op_deferred_release;
57251-extern atomic_t fscache_n_op_release;
57252-extern atomic_t fscache_n_op_gc;
57253-extern atomic_t fscache_n_op_cancelled;
57254-extern atomic_t fscache_n_op_rejected;
57255+extern atomic_unchecked_t fscache_n_op_pend;
57256+extern atomic_unchecked_t fscache_n_op_run;
57257+extern atomic_unchecked_t fscache_n_op_enqueue;
57258+extern atomic_unchecked_t fscache_n_op_deferred_release;
57259+extern atomic_unchecked_t fscache_n_op_release;
57260+extern atomic_unchecked_t fscache_n_op_gc;
57261+extern atomic_unchecked_t fscache_n_op_cancelled;
57262+extern atomic_unchecked_t fscache_n_op_rejected;
57263
57264-extern atomic_t fscache_n_attr_changed;
57265-extern atomic_t fscache_n_attr_changed_ok;
57266-extern atomic_t fscache_n_attr_changed_nobufs;
57267-extern atomic_t fscache_n_attr_changed_nomem;
57268-extern atomic_t fscache_n_attr_changed_calls;
57269+extern atomic_unchecked_t fscache_n_attr_changed;
57270+extern atomic_unchecked_t fscache_n_attr_changed_ok;
57271+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
57272+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
57273+extern atomic_unchecked_t fscache_n_attr_changed_calls;
57274
57275-extern atomic_t fscache_n_allocs;
57276-extern atomic_t fscache_n_allocs_ok;
57277-extern atomic_t fscache_n_allocs_wait;
57278-extern atomic_t fscache_n_allocs_nobufs;
57279-extern atomic_t fscache_n_allocs_intr;
57280-extern atomic_t fscache_n_allocs_object_dead;
57281-extern atomic_t fscache_n_alloc_ops;
57282-extern atomic_t fscache_n_alloc_op_waits;
57283+extern atomic_unchecked_t fscache_n_allocs;
57284+extern atomic_unchecked_t fscache_n_allocs_ok;
57285+extern atomic_unchecked_t fscache_n_allocs_wait;
57286+extern atomic_unchecked_t fscache_n_allocs_nobufs;
57287+extern atomic_unchecked_t fscache_n_allocs_intr;
57288+extern atomic_unchecked_t fscache_n_allocs_object_dead;
57289+extern atomic_unchecked_t fscache_n_alloc_ops;
57290+extern atomic_unchecked_t fscache_n_alloc_op_waits;
57291
57292-extern atomic_t fscache_n_retrievals;
57293-extern atomic_t fscache_n_retrievals_ok;
57294-extern atomic_t fscache_n_retrievals_wait;
57295-extern atomic_t fscache_n_retrievals_nodata;
57296-extern atomic_t fscache_n_retrievals_nobufs;
57297-extern atomic_t fscache_n_retrievals_intr;
57298-extern atomic_t fscache_n_retrievals_nomem;
57299-extern atomic_t fscache_n_retrievals_object_dead;
57300-extern atomic_t fscache_n_retrieval_ops;
57301-extern atomic_t fscache_n_retrieval_op_waits;
57302+extern atomic_unchecked_t fscache_n_retrievals;
57303+extern atomic_unchecked_t fscache_n_retrievals_ok;
57304+extern atomic_unchecked_t fscache_n_retrievals_wait;
57305+extern atomic_unchecked_t fscache_n_retrievals_nodata;
57306+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
57307+extern atomic_unchecked_t fscache_n_retrievals_intr;
57308+extern atomic_unchecked_t fscache_n_retrievals_nomem;
57309+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
57310+extern atomic_unchecked_t fscache_n_retrieval_ops;
57311+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
57312
57313-extern atomic_t fscache_n_stores;
57314-extern atomic_t fscache_n_stores_ok;
57315-extern atomic_t fscache_n_stores_again;
57316-extern atomic_t fscache_n_stores_nobufs;
57317-extern atomic_t fscache_n_stores_oom;
57318-extern atomic_t fscache_n_store_ops;
57319-extern atomic_t fscache_n_store_calls;
57320-extern atomic_t fscache_n_store_pages;
57321-extern atomic_t fscache_n_store_radix_deletes;
57322-extern atomic_t fscache_n_store_pages_over_limit;
57323+extern atomic_unchecked_t fscache_n_stores;
57324+extern atomic_unchecked_t fscache_n_stores_ok;
57325+extern atomic_unchecked_t fscache_n_stores_again;
57326+extern atomic_unchecked_t fscache_n_stores_nobufs;
57327+extern atomic_unchecked_t fscache_n_stores_oom;
57328+extern atomic_unchecked_t fscache_n_store_ops;
57329+extern atomic_unchecked_t fscache_n_store_calls;
57330+extern atomic_unchecked_t fscache_n_store_pages;
57331+extern atomic_unchecked_t fscache_n_store_radix_deletes;
57332+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
57333
57334-extern atomic_t fscache_n_store_vmscan_not_storing;
57335-extern atomic_t fscache_n_store_vmscan_gone;
57336-extern atomic_t fscache_n_store_vmscan_busy;
57337-extern atomic_t fscache_n_store_vmscan_cancelled;
57338-extern atomic_t fscache_n_store_vmscan_wait;
57339+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57340+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
57341+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
57342+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57343+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
57344
57345-extern atomic_t fscache_n_marks;
57346-extern atomic_t fscache_n_uncaches;
57347+extern atomic_unchecked_t fscache_n_marks;
57348+extern atomic_unchecked_t fscache_n_uncaches;
57349
57350-extern atomic_t fscache_n_acquires;
57351-extern atomic_t fscache_n_acquires_null;
57352-extern atomic_t fscache_n_acquires_no_cache;
57353-extern atomic_t fscache_n_acquires_ok;
57354-extern atomic_t fscache_n_acquires_nobufs;
57355-extern atomic_t fscache_n_acquires_oom;
57356+extern atomic_unchecked_t fscache_n_acquires;
57357+extern atomic_unchecked_t fscache_n_acquires_null;
57358+extern atomic_unchecked_t fscache_n_acquires_no_cache;
57359+extern atomic_unchecked_t fscache_n_acquires_ok;
57360+extern atomic_unchecked_t fscache_n_acquires_nobufs;
57361+extern atomic_unchecked_t fscache_n_acquires_oom;
57362
57363-extern atomic_t fscache_n_invalidates;
57364-extern atomic_t fscache_n_invalidates_run;
57365+extern atomic_unchecked_t fscache_n_invalidates;
57366+extern atomic_unchecked_t fscache_n_invalidates_run;
57367
57368-extern atomic_t fscache_n_updates;
57369-extern atomic_t fscache_n_updates_null;
57370-extern atomic_t fscache_n_updates_run;
57371+extern atomic_unchecked_t fscache_n_updates;
57372+extern atomic_unchecked_t fscache_n_updates_null;
57373+extern atomic_unchecked_t fscache_n_updates_run;
57374
57375-extern atomic_t fscache_n_relinquishes;
57376-extern atomic_t fscache_n_relinquishes_null;
57377-extern atomic_t fscache_n_relinquishes_waitcrt;
57378-extern atomic_t fscache_n_relinquishes_retire;
57379+extern atomic_unchecked_t fscache_n_relinquishes;
57380+extern atomic_unchecked_t fscache_n_relinquishes_null;
57381+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57382+extern atomic_unchecked_t fscache_n_relinquishes_retire;
57383
57384-extern atomic_t fscache_n_cookie_index;
57385-extern atomic_t fscache_n_cookie_data;
57386-extern atomic_t fscache_n_cookie_special;
57387+extern atomic_unchecked_t fscache_n_cookie_index;
57388+extern atomic_unchecked_t fscache_n_cookie_data;
57389+extern atomic_unchecked_t fscache_n_cookie_special;
57390
57391-extern atomic_t fscache_n_object_alloc;
57392-extern atomic_t fscache_n_object_no_alloc;
57393-extern atomic_t fscache_n_object_lookups;
57394-extern atomic_t fscache_n_object_lookups_negative;
57395-extern atomic_t fscache_n_object_lookups_positive;
57396-extern atomic_t fscache_n_object_lookups_timed_out;
57397-extern atomic_t fscache_n_object_created;
57398-extern atomic_t fscache_n_object_avail;
57399-extern atomic_t fscache_n_object_dead;
57400+extern atomic_unchecked_t fscache_n_object_alloc;
57401+extern atomic_unchecked_t fscache_n_object_no_alloc;
57402+extern atomic_unchecked_t fscache_n_object_lookups;
57403+extern atomic_unchecked_t fscache_n_object_lookups_negative;
57404+extern atomic_unchecked_t fscache_n_object_lookups_positive;
57405+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
57406+extern atomic_unchecked_t fscache_n_object_created;
57407+extern atomic_unchecked_t fscache_n_object_avail;
57408+extern atomic_unchecked_t fscache_n_object_dead;
57409
57410-extern atomic_t fscache_n_checkaux_none;
57411-extern atomic_t fscache_n_checkaux_okay;
57412-extern atomic_t fscache_n_checkaux_update;
57413-extern atomic_t fscache_n_checkaux_obsolete;
57414+extern atomic_unchecked_t fscache_n_checkaux_none;
57415+extern atomic_unchecked_t fscache_n_checkaux_okay;
57416+extern atomic_unchecked_t fscache_n_checkaux_update;
57417+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
57418
57419 extern atomic_t fscache_n_cop_alloc_object;
57420 extern atomic_t fscache_n_cop_lookup_object;
57421@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
57422 atomic_inc(stat);
57423 }
57424
57425+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
57426+{
57427+ atomic_inc_unchecked(stat);
57428+}
57429+
57430 static inline void fscache_stat_d(atomic_t *stat)
57431 {
57432 atomic_dec(stat);
57433@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
57434
57435 #define __fscache_stat(stat) (NULL)
57436 #define fscache_stat(stat) do {} while (0)
57437+#define fscache_stat_unchecked(stat) do {} while (0)
57438 #define fscache_stat_d(stat) do {} while (0)
57439 #endif
57440
57441diff --git a/fs/fscache/object.c b/fs/fscache/object.c
57442index 86d75a6..5f3d7a0 100644
57443--- a/fs/fscache/object.c
57444+++ b/fs/fscache/object.c
57445@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
57446 _debug("LOOKUP \"%s\" in \"%s\"",
57447 cookie->def->name, object->cache->tag->name);
57448
57449- fscache_stat(&fscache_n_object_lookups);
57450+ fscache_stat_unchecked(&fscache_n_object_lookups);
57451 fscache_stat(&fscache_n_cop_lookup_object);
57452 ret = object->cache->ops->lookup_object(object);
57453 fscache_stat_d(&fscache_n_cop_lookup_object);
57454@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
57455 if (ret == -ETIMEDOUT) {
57456 /* probably stuck behind another object, so move this one to
57457 * the back of the queue */
57458- fscache_stat(&fscache_n_object_lookups_timed_out);
57459+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
57460 _leave(" [timeout]");
57461 return NO_TRANSIT;
57462 }
57463@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
57464 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
57465
57466 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
57467- fscache_stat(&fscache_n_object_lookups_negative);
57468+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
57469
57470 /* Allow write requests to begin stacking up and read requests to begin
57471 * returning ENODATA.
57472@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
57473 /* if we were still looking up, then we must have a positive lookup
57474 * result, in which case there may be data available */
57475 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
57476- fscache_stat(&fscache_n_object_lookups_positive);
57477+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
57478
57479 /* We do (presumably) have data */
57480 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
57481@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
57482 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
57483 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
57484 } else {
57485- fscache_stat(&fscache_n_object_created);
57486+ fscache_stat_unchecked(&fscache_n_object_created);
57487 }
57488
57489 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
57490@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
57491 fscache_stat_d(&fscache_n_cop_lookup_complete);
57492
57493 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
57494- fscache_stat(&fscache_n_object_avail);
57495+ fscache_stat_unchecked(&fscache_n_object_avail);
57496
57497 _leave("");
57498 return transit_to(JUMPSTART_DEPS);
57499@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
57500
57501 /* this just shifts the object release to the work processor */
57502 fscache_put_object(object);
57503- fscache_stat(&fscache_n_object_dead);
57504+ fscache_stat_unchecked(&fscache_n_object_dead);
57505
57506 _leave("");
57507 return transit_to(OBJECT_DEAD);
57508@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57509 enum fscache_checkaux result;
57510
57511 if (!object->cookie->def->check_aux) {
57512- fscache_stat(&fscache_n_checkaux_none);
57513+ fscache_stat_unchecked(&fscache_n_checkaux_none);
57514 return FSCACHE_CHECKAUX_OKAY;
57515 }
57516
57517@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57518 switch (result) {
57519 /* entry okay as is */
57520 case FSCACHE_CHECKAUX_OKAY:
57521- fscache_stat(&fscache_n_checkaux_okay);
57522+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
57523 break;
57524
57525 /* entry requires update */
57526 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
57527- fscache_stat(&fscache_n_checkaux_update);
57528+ fscache_stat_unchecked(&fscache_n_checkaux_update);
57529 break;
57530
57531 /* entry requires deletion */
57532 case FSCACHE_CHECKAUX_OBSOLETE:
57533- fscache_stat(&fscache_n_checkaux_obsolete);
57534+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
57535 break;
57536
57537 default:
57538@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
57539 {
57540 const struct fscache_state *s;
57541
57542- fscache_stat(&fscache_n_invalidates_run);
57543+ fscache_stat_unchecked(&fscache_n_invalidates_run);
57544 fscache_stat(&fscache_n_cop_invalidate_object);
57545 s = _fscache_invalidate_object(object, event);
57546 fscache_stat_d(&fscache_n_cop_invalidate_object);
57547@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
57548 {
57549 _enter("{OBJ%x},%d", object->debug_id, event);
57550
57551- fscache_stat(&fscache_n_updates_run);
57552+ fscache_stat_unchecked(&fscache_n_updates_run);
57553 fscache_stat(&fscache_n_cop_update_object);
57554 object->cache->ops->update_object(object);
57555 fscache_stat_d(&fscache_n_cop_update_object);
57556diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
57557index 318071a..379938b 100644
57558--- a/fs/fscache/operation.c
57559+++ b/fs/fscache/operation.c
57560@@ -17,7 +17,7 @@
57561 #include <linux/slab.h>
57562 #include "internal.h"
57563
57564-atomic_t fscache_op_debug_id;
57565+atomic_unchecked_t fscache_op_debug_id;
57566 EXPORT_SYMBOL(fscache_op_debug_id);
57567
57568 /**
57569@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
57570 ASSERTCMP(atomic_read(&op->usage), >, 0);
57571 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
57572
57573- fscache_stat(&fscache_n_op_enqueue);
57574+ fscache_stat_unchecked(&fscache_n_op_enqueue);
57575 switch (op->flags & FSCACHE_OP_TYPE) {
57576 case FSCACHE_OP_ASYNC:
57577 _debug("queue async");
57578@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
57579 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
57580 if (op->processor)
57581 fscache_enqueue_operation(op);
57582- fscache_stat(&fscache_n_op_run);
57583+ fscache_stat_unchecked(&fscache_n_op_run);
57584 }
57585
57586 /*
57587@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57588 if (object->n_in_progress > 0) {
57589 atomic_inc(&op->usage);
57590 list_add_tail(&op->pend_link, &object->pending_ops);
57591- fscache_stat(&fscache_n_op_pend);
57592+ fscache_stat_unchecked(&fscache_n_op_pend);
57593 } else if (!list_empty(&object->pending_ops)) {
57594 atomic_inc(&op->usage);
57595 list_add_tail(&op->pend_link, &object->pending_ops);
57596- fscache_stat(&fscache_n_op_pend);
57597+ fscache_stat_unchecked(&fscache_n_op_pend);
57598 fscache_start_operations(object);
57599 } else {
57600 ASSERTCMP(object->n_in_progress, ==, 0);
57601@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57602 object->n_exclusive++; /* reads and writes must wait */
57603 atomic_inc(&op->usage);
57604 list_add_tail(&op->pend_link, &object->pending_ops);
57605- fscache_stat(&fscache_n_op_pend);
57606+ fscache_stat_unchecked(&fscache_n_op_pend);
57607 ret = 0;
57608 } else {
57609 /* If we're in any other state, there must have been an I/O
57610@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
57611 if (object->n_exclusive > 0) {
57612 atomic_inc(&op->usage);
57613 list_add_tail(&op->pend_link, &object->pending_ops);
57614- fscache_stat(&fscache_n_op_pend);
57615+ fscache_stat_unchecked(&fscache_n_op_pend);
57616 } else if (!list_empty(&object->pending_ops)) {
57617 atomic_inc(&op->usage);
57618 list_add_tail(&op->pend_link, &object->pending_ops);
57619- fscache_stat(&fscache_n_op_pend);
57620+ fscache_stat_unchecked(&fscache_n_op_pend);
57621 fscache_start_operations(object);
57622 } else {
57623 ASSERTCMP(object->n_exclusive, ==, 0);
57624@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
57625 object->n_ops++;
57626 atomic_inc(&op->usage);
57627 list_add_tail(&op->pend_link, &object->pending_ops);
57628- fscache_stat(&fscache_n_op_pend);
57629+ fscache_stat_unchecked(&fscache_n_op_pend);
57630 ret = 0;
57631 } else if (fscache_object_is_dying(object)) {
57632- fscache_stat(&fscache_n_op_rejected);
57633+ fscache_stat_unchecked(&fscache_n_op_rejected);
57634 op->state = FSCACHE_OP_ST_CANCELLED;
57635 ret = -ENOBUFS;
57636 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
57637@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
57638 ret = -EBUSY;
57639 if (op->state == FSCACHE_OP_ST_PENDING) {
57640 ASSERT(!list_empty(&op->pend_link));
57641- fscache_stat(&fscache_n_op_cancelled);
57642+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57643 list_del_init(&op->pend_link);
57644 if (do_cancel)
57645 do_cancel(op);
57646@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
57647 while (!list_empty(&object->pending_ops)) {
57648 op = list_entry(object->pending_ops.next,
57649 struct fscache_operation, pend_link);
57650- fscache_stat(&fscache_n_op_cancelled);
57651+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57652 list_del_init(&op->pend_link);
57653
57654 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
57655@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
57656 op->state, ==, FSCACHE_OP_ST_CANCELLED);
57657 op->state = FSCACHE_OP_ST_DEAD;
57658
57659- fscache_stat(&fscache_n_op_release);
57660+ fscache_stat_unchecked(&fscache_n_op_release);
57661
57662 if (op->release) {
57663 op->release(op);
57664@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
57665 * lock, and defer it otherwise */
57666 if (!spin_trylock(&object->lock)) {
57667 _debug("defer put");
57668- fscache_stat(&fscache_n_op_deferred_release);
57669+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
57670
57671 cache = object->cache;
57672 spin_lock(&cache->op_gc_list_lock);
57673@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
57674
57675 _debug("GC DEFERRED REL OBJ%x OP%x",
57676 object->debug_id, op->debug_id);
57677- fscache_stat(&fscache_n_op_gc);
57678+ fscache_stat_unchecked(&fscache_n_op_gc);
57679
57680 ASSERTCMP(atomic_read(&op->usage), ==, 0);
57681 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
57682diff --git a/fs/fscache/page.c b/fs/fscache/page.c
57683index 73899c1..ae40c58 100644
57684--- a/fs/fscache/page.c
57685+++ b/fs/fscache/page.c
57686@@ -61,7 +61,7 @@ try_again:
57687 val = radix_tree_lookup(&cookie->stores, page->index);
57688 if (!val) {
57689 rcu_read_unlock();
57690- fscache_stat(&fscache_n_store_vmscan_not_storing);
57691+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
57692 __fscache_uncache_page(cookie, page);
57693 return true;
57694 }
57695@@ -91,11 +91,11 @@ try_again:
57696 spin_unlock(&cookie->stores_lock);
57697
57698 if (xpage) {
57699- fscache_stat(&fscache_n_store_vmscan_cancelled);
57700- fscache_stat(&fscache_n_store_radix_deletes);
57701+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
57702+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57703 ASSERTCMP(xpage, ==, page);
57704 } else {
57705- fscache_stat(&fscache_n_store_vmscan_gone);
57706+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
57707 }
57708
57709 wake_up_bit(&cookie->flags, 0);
57710@@ -110,11 +110,11 @@ page_busy:
57711 * sleeping on memory allocation, so we may need to impose a timeout
57712 * too. */
57713 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
57714- fscache_stat(&fscache_n_store_vmscan_busy);
57715+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
57716 return false;
57717 }
57718
57719- fscache_stat(&fscache_n_store_vmscan_wait);
57720+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
57721 __fscache_wait_on_page_write(cookie, page);
57722 gfp &= ~__GFP_WAIT;
57723 goto try_again;
57724@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
57725 FSCACHE_COOKIE_STORING_TAG);
57726 if (!radix_tree_tag_get(&cookie->stores, page->index,
57727 FSCACHE_COOKIE_PENDING_TAG)) {
57728- fscache_stat(&fscache_n_store_radix_deletes);
57729+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57730 xpage = radix_tree_delete(&cookie->stores, page->index);
57731 }
57732 spin_unlock(&cookie->stores_lock);
57733@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
57734
57735 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
57736
57737- fscache_stat(&fscache_n_attr_changed_calls);
57738+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
57739
57740 if (fscache_object_is_active(object) &&
57741 fscache_use_cookie(object)) {
57742@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57743
57744 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57745
57746- fscache_stat(&fscache_n_attr_changed);
57747+ fscache_stat_unchecked(&fscache_n_attr_changed);
57748
57749 op = kzalloc(sizeof(*op), GFP_KERNEL);
57750 if (!op) {
57751- fscache_stat(&fscache_n_attr_changed_nomem);
57752+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
57753 _leave(" = -ENOMEM");
57754 return -ENOMEM;
57755 }
57756@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57757 if (fscache_submit_exclusive_op(object, op) < 0)
57758 goto nobufs;
57759 spin_unlock(&cookie->lock);
57760- fscache_stat(&fscache_n_attr_changed_ok);
57761+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
57762 fscache_put_operation(op);
57763 _leave(" = 0");
57764 return 0;
57765@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57766 nobufs:
57767 spin_unlock(&cookie->lock);
57768 kfree(op);
57769- fscache_stat(&fscache_n_attr_changed_nobufs);
57770+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
57771 _leave(" = %d", -ENOBUFS);
57772 return -ENOBUFS;
57773 }
57774@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
57775 /* allocate a retrieval operation and attempt to submit it */
57776 op = kzalloc(sizeof(*op), GFP_NOIO);
57777 if (!op) {
57778- fscache_stat(&fscache_n_retrievals_nomem);
57779+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57780 return NULL;
57781 }
57782
57783@@ -289,13 +289,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
57784 return 0;
57785 }
57786
57787- fscache_stat(&fscache_n_retrievals_wait);
57788+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
57789
57790 jif = jiffies;
57791 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
57792 fscache_wait_bit_interruptible,
57793 TASK_INTERRUPTIBLE) != 0) {
57794- fscache_stat(&fscache_n_retrievals_intr);
57795+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57796 _leave(" = -ERESTARTSYS");
57797 return -ERESTARTSYS;
57798 }
57799@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
57800 */
57801 int fscache_wait_for_operation_activation(struct fscache_object *object,
57802 struct fscache_operation *op,
57803- atomic_t *stat_op_waits,
57804- atomic_t *stat_object_dead,
57805+ atomic_unchecked_t *stat_op_waits,
57806+ atomic_unchecked_t *stat_object_dead,
57807 void (*do_cancel)(struct fscache_operation *))
57808 {
57809 int ret;
57810@@ -335,7 +335,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57811
57812 _debug(">>> WT");
57813 if (stat_op_waits)
57814- fscache_stat(stat_op_waits);
57815+ fscache_stat_unchecked(stat_op_waits);
57816 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
57817 fscache_wait_bit_interruptible,
57818 TASK_INTERRUPTIBLE) != 0) {
57819@@ -353,7 +353,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57820 check_if_dead:
57821 if (op->state == FSCACHE_OP_ST_CANCELLED) {
57822 if (stat_object_dead)
57823- fscache_stat(stat_object_dead);
57824+ fscache_stat_unchecked(stat_object_dead);
57825 _leave(" = -ENOBUFS [cancelled]");
57826 return -ENOBUFS;
57827 }
57828@@ -361,7 +361,7 @@ check_if_dead:
57829 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
57830 fscache_cancel_op(op, do_cancel);
57831 if (stat_object_dead)
57832- fscache_stat(stat_object_dead);
57833+ fscache_stat_unchecked(stat_object_dead);
57834 return -ENOBUFS;
57835 }
57836 return 0;
57837@@ -388,7 +388,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57838
57839 _enter("%p,%p,,,", cookie, page);
57840
57841- fscache_stat(&fscache_n_retrievals);
57842+ fscache_stat_unchecked(&fscache_n_retrievals);
57843
57844 if (hlist_empty(&cookie->backing_objects))
57845 goto nobufs;
57846@@ -428,7 +428,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57847 goto nobufs_unlock_dec;
57848 spin_unlock(&cookie->lock);
57849
57850- fscache_stat(&fscache_n_retrieval_ops);
57851+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57852
57853 /* pin the netfs read context in case we need to do the actual netfs
57854 * read because we've encountered a cache read failure */
57855@@ -459,15 +459,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57856
57857 error:
57858 if (ret == -ENOMEM)
57859- fscache_stat(&fscache_n_retrievals_nomem);
57860+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57861 else if (ret == -ERESTARTSYS)
57862- fscache_stat(&fscache_n_retrievals_intr);
57863+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57864 else if (ret == -ENODATA)
57865- fscache_stat(&fscache_n_retrievals_nodata);
57866+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57867 else if (ret < 0)
57868- fscache_stat(&fscache_n_retrievals_nobufs);
57869+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57870 else
57871- fscache_stat(&fscache_n_retrievals_ok);
57872+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57873
57874 fscache_put_retrieval(op);
57875 _leave(" = %d", ret);
57876@@ -480,7 +480,7 @@ nobufs_unlock:
57877 atomic_dec(&cookie->n_active);
57878 kfree(op);
57879 nobufs:
57880- fscache_stat(&fscache_n_retrievals_nobufs);
57881+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57882 _leave(" = -ENOBUFS");
57883 return -ENOBUFS;
57884 }
57885@@ -518,7 +518,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57886
57887 _enter("%p,,%d,,,", cookie, *nr_pages);
57888
57889- fscache_stat(&fscache_n_retrievals);
57890+ fscache_stat_unchecked(&fscache_n_retrievals);
57891
57892 if (hlist_empty(&cookie->backing_objects))
57893 goto nobufs;
57894@@ -554,7 +554,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57895 goto nobufs_unlock_dec;
57896 spin_unlock(&cookie->lock);
57897
57898- fscache_stat(&fscache_n_retrieval_ops);
57899+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57900
57901 /* pin the netfs read context in case we need to do the actual netfs
57902 * read because we've encountered a cache read failure */
57903@@ -585,15 +585,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57904
57905 error:
57906 if (ret == -ENOMEM)
57907- fscache_stat(&fscache_n_retrievals_nomem);
57908+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57909 else if (ret == -ERESTARTSYS)
57910- fscache_stat(&fscache_n_retrievals_intr);
57911+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57912 else if (ret == -ENODATA)
57913- fscache_stat(&fscache_n_retrievals_nodata);
57914+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57915 else if (ret < 0)
57916- fscache_stat(&fscache_n_retrievals_nobufs);
57917+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57918 else
57919- fscache_stat(&fscache_n_retrievals_ok);
57920+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57921
57922 fscache_put_retrieval(op);
57923 _leave(" = %d", ret);
57924@@ -606,7 +606,7 @@ nobufs_unlock:
57925 atomic_dec(&cookie->n_active);
57926 kfree(op);
57927 nobufs:
57928- fscache_stat(&fscache_n_retrievals_nobufs);
57929+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57930 _leave(" = -ENOBUFS");
57931 return -ENOBUFS;
57932 }
57933@@ -630,7 +630,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57934
57935 _enter("%p,%p,,,", cookie, page);
57936
57937- fscache_stat(&fscache_n_allocs);
57938+ fscache_stat_unchecked(&fscache_n_allocs);
57939
57940 if (hlist_empty(&cookie->backing_objects))
57941 goto nobufs;
57942@@ -662,7 +662,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57943 goto nobufs_unlock;
57944 spin_unlock(&cookie->lock);
57945
57946- fscache_stat(&fscache_n_alloc_ops);
57947+ fscache_stat_unchecked(&fscache_n_alloc_ops);
57948
57949 ret = fscache_wait_for_operation_activation(
57950 object, &op->op,
57951@@ -679,11 +679,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57952
57953 error:
57954 if (ret == -ERESTARTSYS)
57955- fscache_stat(&fscache_n_allocs_intr);
57956+ fscache_stat_unchecked(&fscache_n_allocs_intr);
57957 else if (ret < 0)
57958- fscache_stat(&fscache_n_allocs_nobufs);
57959+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57960 else
57961- fscache_stat(&fscache_n_allocs_ok);
57962+ fscache_stat_unchecked(&fscache_n_allocs_ok);
57963
57964 fscache_put_retrieval(op);
57965 _leave(" = %d", ret);
57966@@ -694,7 +694,7 @@ nobufs_unlock:
57967 atomic_dec(&cookie->n_active);
57968 kfree(op);
57969 nobufs:
57970- fscache_stat(&fscache_n_allocs_nobufs);
57971+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57972 _leave(" = -ENOBUFS");
57973 return -ENOBUFS;
57974 }
57975@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57976
57977 spin_lock(&cookie->stores_lock);
57978
57979- fscache_stat(&fscache_n_store_calls);
57980+ fscache_stat_unchecked(&fscache_n_store_calls);
57981
57982 /* find a page to store */
57983 page = NULL;
57984@@ -781,7 +781,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57985 page = results[0];
57986 _debug("gang %d [%lx]", n, page->index);
57987 if (page->index > op->store_limit) {
57988- fscache_stat(&fscache_n_store_pages_over_limit);
57989+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
57990 goto superseded;
57991 }
57992
57993@@ -793,7 +793,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57994 spin_unlock(&cookie->stores_lock);
57995 spin_unlock(&object->lock);
57996
57997- fscache_stat(&fscache_n_store_pages);
57998+ fscache_stat_unchecked(&fscache_n_store_pages);
57999 fscache_stat(&fscache_n_cop_write_page);
58000 ret = object->cache->ops->write_page(op, page);
58001 fscache_stat_d(&fscache_n_cop_write_page);
58002@@ -896,7 +896,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58003 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
58004 ASSERT(PageFsCache(page));
58005
58006- fscache_stat(&fscache_n_stores);
58007+ fscache_stat_unchecked(&fscache_n_stores);
58008
58009 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
58010 _leave(" = -ENOBUFS [invalidating]");
58011@@ -954,7 +954,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58012 spin_unlock(&cookie->stores_lock);
58013 spin_unlock(&object->lock);
58014
58015- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
58016+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58017 op->store_limit = object->store_limit;
58018
58019 atomic_inc(&cookie->n_active);
58020@@ -963,8 +963,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58021
58022 spin_unlock(&cookie->lock);
58023 radix_tree_preload_end();
58024- fscache_stat(&fscache_n_store_ops);
58025- fscache_stat(&fscache_n_stores_ok);
58026+ fscache_stat_unchecked(&fscache_n_store_ops);
58027+ fscache_stat_unchecked(&fscache_n_stores_ok);
58028
58029 /* the work queue now carries its own ref on the object */
58030 fscache_put_operation(&op->op);
58031@@ -972,14 +972,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58032 return 0;
58033
58034 already_queued:
58035- fscache_stat(&fscache_n_stores_again);
58036+ fscache_stat_unchecked(&fscache_n_stores_again);
58037 already_pending:
58038 spin_unlock(&cookie->stores_lock);
58039 spin_unlock(&object->lock);
58040 spin_unlock(&cookie->lock);
58041 radix_tree_preload_end();
58042 kfree(op);
58043- fscache_stat(&fscache_n_stores_ok);
58044+ fscache_stat_unchecked(&fscache_n_stores_ok);
58045 _leave(" = 0");
58046 return 0;
58047
58048@@ -999,14 +999,14 @@ nobufs:
58049 spin_unlock(&cookie->lock);
58050 radix_tree_preload_end();
58051 kfree(op);
58052- fscache_stat(&fscache_n_stores_nobufs);
58053+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
58054 _leave(" = -ENOBUFS");
58055 return -ENOBUFS;
58056
58057 nomem_free:
58058 kfree(op);
58059 nomem:
58060- fscache_stat(&fscache_n_stores_oom);
58061+ fscache_stat_unchecked(&fscache_n_stores_oom);
58062 _leave(" = -ENOMEM");
58063 return -ENOMEM;
58064 }
58065@@ -1024,7 +1024,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
58066 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
58067 ASSERTCMP(page, !=, NULL);
58068
58069- fscache_stat(&fscache_n_uncaches);
58070+ fscache_stat_unchecked(&fscache_n_uncaches);
58071
58072 /* cache withdrawal may beat us to it */
58073 if (!PageFsCache(page))
58074@@ -1075,7 +1075,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
58075 struct fscache_cookie *cookie = op->op.object->cookie;
58076
58077 #ifdef CONFIG_FSCACHE_STATS
58078- atomic_inc(&fscache_n_marks);
58079+ atomic_inc_unchecked(&fscache_n_marks);
58080 #endif
58081
58082 _debug("- mark %p{%lx}", page, page->index);
58083diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
58084index 40d13c7..ddf52b9 100644
58085--- a/fs/fscache/stats.c
58086+++ b/fs/fscache/stats.c
58087@@ -18,99 +18,99 @@
58088 /*
58089 * operation counters
58090 */
58091-atomic_t fscache_n_op_pend;
58092-atomic_t fscache_n_op_run;
58093-atomic_t fscache_n_op_enqueue;
58094-atomic_t fscache_n_op_requeue;
58095-atomic_t fscache_n_op_deferred_release;
58096-atomic_t fscache_n_op_release;
58097-atomic_t fscache_n_op_gc;
58098-atomic_t fscache_n_op_cancelled;
58099-atomic_t fscache_n_op_rejected;
58100+atomic_unchecked_t fscache_n_op_pend;
58101+atomic_unchecked_t fscache_n_op_run;
58102+atomic_unchecked_t fscache_n_op_enqueue;
58103+atomic_unchecked_t fscache_n_op_requeue;
58104+atomic_unchecked_t fscache_n_op_deferred_release;
58105+atomic_unchecked_t fscache_n_op_release;
58106+atomic_unchecked_t fscache_n_op_gc;
58107+atomic_unchecked_t fscache_n_op_cancelled;
58108+atomic_unchecked_t fscache_n_op_rejected;
58109
58110-atomic_t fscache_n_attr_changed;
58111-atomic_t fscache_n_attr_changed_ok;
58112-atomic_t fscache_n_attr_changed_nobufs;
58113-atomic_t fscache_n_attr_changed_nomem;
58114-atomic_t fscache_n_attr_changed_calls;
58115+atomic_unchecked_t fscache_n_attr_changed;
58116+atomic_unchecked_t fscache_n_attr_changed_ok;
58117+atomic_unchecked_t fscache_n_attr_changed_nobufs;
58118+atomic_unchecked_t fscache_n_attr_changed_nomem;
58119+atomic_unchecked_t fscache_n_attr_changed_calls;
58120
58121-atomic_t fscache_n_allocs;
58122-atomic_t fscache_n_allocs_ok;
58123-atomic_t fscache_n_allocs_wait;
58124-atomic_t fscache_n_allocs_nobufs;
58125-atomic_t fscache_n_allocs_intr;
58126-atomic_t fscache_n_allocs_object_dead;
58127-atomic_t fscache_n_alloc_ops;
58128-atomic_t fscache_n_alloc_op_waits;
58129+atomic_unchecked_t fscache_n_allocs;
58130+atomic_unchecked_t fscache_n_allocs_ok;
58131+atomic_unchecked_t fscache_n_allocs_wait;
58132+atomic_unchecked_t fscache_n_allocs_nobufs;
58133+atomic_unchecked_t fscache_n_allocs_intr;
58134+atomic_unchecked_t fscache_n_allocs_object_dead;
58135+atomic_unchecked_t fscache_n_alloc_ops;
58136+atomic_unchecked_t fscache_n_alloc_op_waits;
58137
58138-atomic_t fscache_n_retrievals;
58139-atomic_t fscache_n_retrievals_ok;
58140-atomic_t fscache_n_retrievals_wait;
58141-atomic_t fscache_n_retrievals_nodata;
58142-atomic_t fscache_n_retrievals_nobufs;
58143-atomic_t fscache_n_retrievals_intr;
58144-atomic_t fscache_n_retrievals_nomem;
58145-atomic_t fscache_n_retrievals_object_dead;
58146-atomic_t fscache_n_retrieval_ops;
58147-atomic_t fscache_n_retrieval_op_waits;
58148+atomic_unchecked_t fscache_n_retrievals;
58149+atomic_unchecked_t fscache_n_retrievals_ok;
58150+atomic_unchecked_t fscache_n_retrievals_wait;
58151+atomic_unchecked_t fscache_n_retrievals_nodata;
58152+atomic_unchecked_t fscache_n_retrievals_nobufs;
58153+atomic_unchecked_t fscache_n_retrievals_intr;
58154+atomic_unchecked_t fscache_n_retrievals_nomem;
58155+atomic_unchecked_t fscache_n_retrievals_object_dead;
58156+atomic_unchecked_t fscache_n_retrieval_ops;
58157+atomic_unchecked_t fscache_n_retrieval_op_waits;
58158
58159-atomic_t fscache_n_stores;
58160-atomic_t fscache_n_stores_ok;
58161-atomic_t fscache_n_stores_again;
58162-atomic_t fscache_n_stores_nobufs;
58163-atomic_t fscache_n_stores_oom;
58164-atomic_t fscache_n_store_ops;
58165-atomic_t fscache_n_store_calls;
58166-atomic_t fscache_n_store_pages;
58167-atomic_t fscache_n_store_radix_deletes;
58168-atomic_t fscache_n_store_pages_over_limit;
58169+atomic_unchecked_t fscache_n_stores;
58170+atomic_unchecked_t fscache_n_stores_ok;
58171+atomic_unchecked_t fscache_n_stores_again;
58172+atomic_unchecked_t fscache_n_stores_nobufs;
58173+atomic_unchecked_t fscache_n_stores_oom;
58174+atomic_unchecked_t fscache_n_store_ops;
58175+atomic_unchecked_t fscache_n_store_calls;
58176+atomic_unchecked_t fscache_n_store_pages;
58177+atomic_unchecked_t fscache_n_store_radix_deletes;
58178+atomic_unchecked_t fscache_n_store_pages_over_limit;
58179
58180-atomic_t fscache_n_store_vmscan_not_storing;
58181-atomic_t fscache_n_store_vmscan_gone;
58182-atomic_t fscache_n_store_vmscan_busy;
58183-atomic_t fscache_n_store_vmscan_cancelled;
58184-atomic_t fscache_n_store_vmscan_wait;
58185+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58186+atomic_unchecked_t fscache_n_store_vmscan_gone;
58187+atomic_unchecked_t fscache_n_store_vmscan_busy;
58188+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58189+atomic_unchecked_t fscache_n_store_vmscan_wait;
58190
58191-atomic_t fscache_n_marks;
58192-atomic_t fscache_n_uncaches;
58193+atomic_unchecked_t fscache_n_marks;
58194+atomic_unchecked_t fscache_n_uncaches;
58195
58196-atomic_t fscache_n_acquires;
58197-atomic_t fscache_n_acquires_null;
58198-atomic_t fscache_n_acquires_no_cache;
58199-atomic_t fscache_n_acquires_ok;
58200-atomic_t fscache_n_acquires_nobufs;
58201-atomic_t fscache_n_acquires_oom;
58202+atomic_unchecked_t fscache_n_acquires;
58203+atomic_unchecked_t fscache_n_acquires_null;
58204+atomic_unchecked_t fscache_n_acquires_no_cache;
58205+atomic_unchecked_t fscache_n_acquires_ok;
58206+atomic_unchecked_t fscache_n_acquires_nobufs;
58207+atomic_unchecked_t fscache_n_acquires_oom;
58208
58209-atomic_t fscache_n_invalidates;
58210-atomic_t fscache_n_invalidates_run;
58211+atomic_unchecked_t fscache_n_invalidates;
58212+atomic_unchecked_t fscache_n_invalidates_run;
58213
58214-atomic_t fscache_n_updates;
58215-atomic_t fscache_n_updates_null;
58216-atomic_t fscache_n_updates_run;
58217+atomic_unchecked_t fscache_n_updates;
58218+atomic_unchecked_t fscache_n_updates_null;
58219+atomic_unchecked_t fscache_n_updates_run;
58220
58221-atomic_t fscache_n_relinquishes;
58222-atomic_t fscache_n_relinquishes_null;
58223-atomic_t fscache_n_relinquishes_waitcrt;
58224-atomic_t fscache_n_relinquishes_retire;
58225+atomic_unchecked_t fscache_n_relinquishes;
58226+atomic_unchecked_t fscache_n_relinquishes_null;
58227+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58228+atomic_unchecked_t fscache_n_relinquishes_retire;
58229
58230-atomic_t fscache_n_cookie_index;
58231-atomic_t fscache_n_cookie_data;
58232-atomic_t fscache_n_cookie_special;
58233+atomic_unchecked_t fscache_n_cookie_index;
58234+atomic_unchecked_t fscache_n_cookie_data;
58235+atomic_unchecked_t fscache_n_cookie_special;
58236
58237-atomic_t fscache_n_object_alloc;
58238-atomic_t fscache_n_object_no_alloc;
58239-atomic_t fscache_n_object_lookups;
58240-atomic_t fscache_n_object_lookups_negative;
58241-atomic_t fscache_n_object_lookups_positive;
58242-atomic_t fscache_n_object_lookups_timed_out;
58243-atomic_t fscache_n_object_created;
58244-atomic_t fscache_n_object_avail;
58245-atomic_t fscache_n_object_dead;
58246+atomic_unchecked_t fscache_n_object_alloc;
58247+atomic_unchecked_t fscache_n_object_no_alloc;
58248+atomic_unchecked_t fscache_n_object_lookups;
58249+atomic_unchecked_t fscache_n_object_lookups_negative;
58250+atomic_unchecked_t fscache_n_object_lookups_positive;
58251+atomic_unchecked_t fscache_n_object_lookups_timed_out;
58252+atomic_unchecked_t fscache_n_object_created;
58253+atomic_unchecked_t fscache_n_object_avail;
58254+atomic_unchecked_t fscache_n_object_dead;
58255
58256-atomic_t fscache_n_checkaux_none;
58257-atomic_t fscache_n_checkaux_okay;
58258-atomic_t fscache_n_checkaux_update;
58259-atomic_t fscache_n_checkaux_obsolete;
58260+atomic_unchecked_t fscache_n_checkaux_none;
58261+atomic_unchecked_t fscache_n_checkaux_okay;
58262+atomic_unchecked_t fscache_n_checkaux_update;
58263+atomic_unchecked_t fscache_n_checkaux_obsolete;
58264
58265 atomic_t fscache_n_cop_alloc_object;
58266 atomic_t fscache_n_cop_lookup_object;
58267@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
58268 seq_puts(m, "FS-Cache statistics\n");
58269
58270 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
58271- atomic_read(&fscache_n_cookie_index),
58272- atomic_read(&fscache_n_cookie_data),
58273- atomic_read(&fscache_n_cookie_special));
58274+ atomic_read_unchecked(&fscache_n_cookie_index),
58275+ atomic_read_unchecked(&fscache_n_cookie_data),
58276+ atomic_read_unchecked(&fscache_n_cookie_special));
58277
58278 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
58279- atomic_read(&fscache_n_object_alloc),
58280- atomic_read(&fscache_n_object_no_alloc),
58281- atomic_read(&fscache_n_object_avail),
58282- atomic_read(&fscache_n_object_dead));
58283+ atomic_read_unchecked(&fscache_n_object_alloc),
58284+ atomic_read_unchecked(&fscache_n_object_no_alloc),
58285+ atomic_read_unchecked(&fscache_n_object_avail),
58286+ atomic_read_unchecked(&fscache_n_object_dead));
58287 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
58288- atomic_read(&fscache_n_checkaux_none),
58289- atomic_read(&fscache_n_checkaux_okay),
58290- atomic_read(&fscache_n_checkaux_update),
58291- atomic_read(&fscache_n_checkaux_obsolete));
58292+ atomic_read_unchecked(&fscache_n_checkaux_none),
58293+ atomic_read_unchecked(&fscache_n_checkaux_okay),
58294+ atomic_read_unchecked(&fscache_n_checkaux_update),
58295+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
58296
58297 seq_printf(m, "Pages : mrk=%u unc=%u\n",
58298- atomic_read(&fscache_n_marks),
58299- atomic_read(&fscache_n_uncaches));
58300+ atomic_read_unchecked(&fscache_n_marks),
58301+ atomic_read_unchecked(&fscache_n_uncaches));
58302
58303 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
58304 " oom=%u\n",
58305- atomic_read(&fscache_n_acquires),
58306- atomic_read(&fscache_n_acquires_null),
58307- atomic_read(&fscache_n_acquires_no_cache),
58308- atomic_read(&fscache_n_acquires_ok),
58309- atomic_read(&fscache_n_acquires_nobufs),
58310- atomic_read(&fscache_n_acquires_oom));
58311+ atomic_read_unchecked(&fscache_n_acquires),
58312+ atomic_read_unchecked(&fscache_n_acquires_null),
58313+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
58314+ atomic_read_unchecked(&fscache_n_acquires_ok),
58315+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
58316+ atomic_read_unchecked(&fscache_n_acquires_oom));
58317
58318 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
58319- atomic_read(&fscache_n_object_lookups),
58320- atomic_read(&fscache_n_object_lookups_negative),
58321- atomic_read(&fscache_n_object_lookups_positive),
58322- atomic_read(&fscache_n_object_created),
58323- atomic_read(&fscache_n_object_lookups_timed_out));
58324+ atomic_read_unchecked(&fscache_n_object_lookups),
58325+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
58326+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
58327+ atomic_read_unchecked(&fscache_n_object_created),
58328+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
58329
58330 seq_printf(m, "Invals : n=%u run=%u\n",
58331- atomic_read(&fscache_n_invalidates),
58332- atomic_read(&fscache_n_invalidates_run));
58333+ atomic_read_unchecked(&fscache_n_invalidates),
58334+ atomic_read_unchecked(&fscache_n_invalidates_run));
58335
58336 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
58337- atomic_read(&fscache_n_updates),
58338- atomic_read(&fscache_n_updates_null),
58339- atomic_read(&fscache_n_updates_run));
58340+ atomic_read_unchecked(&fscache_n_updates),
58341+ atomic_read_unchecked(&fscache_n_updates_null),
58342+ atomic_read_unchecked(&fscache_n_updates_run));
58343
58344 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
58345- atomic_read(&fscache_n_relinquishes),
58346- atomic_read(&fscache_n_relinquishes_null),
58347- atomic_read(&fscache_n_relinquishes_waitcrt),
58348- atomic_read(&fscache_n_relinquishes_retire));
58349+ atomic_read_unchecked(&fscache_n_relinquishes),
58350+ atomic_read_unchecked(&fscache_n_relinquishes_null),
58351+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
58352+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
58353
58354 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
58355- atomic_read(&fscache_n_attr_changed),
58356- atomic_read(&fscache_n_attr_changed_ok),
58357- atomic_read(&fscache_n_attr_changed_nobufs),
58358- atomic_read(&fscache_n_attr_changed_nomem),
58359- atomic_read(&fscache_n_attr_changed_calls));
58360+ atomic_read_unchecked(&fscache_n_attr_changed),
58361+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
58362+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
58363+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
58364+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
58365
58366 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
58367- atomic_read(&fscache_n_allocs),
58368- atomic_read(&fscache_n_allocs_ok),
58369- atomic_read(&fscache_n_allocs_wait),
58370- atomic_read(&fscache_n_allocs_nobufs),
58371- atomic_read(&fscache_n_allocs_intr));
58372+ atomic_read_unchecked(&fscache_n_allocs),
58373+ atomic_read_unchecked(&fscache_n_allocs_ok),
58374+ atomic_read_unchecked(&fscache_n_allocs_wait),
58375+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
58376+ atomic_read_unchecked(&fscache_n_allocs_intr));
58377 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
58378- atomic_read(&fscache_n_alloc_ops),
58379- atomic_read(&fscache_n_alloc_op_waits),
58380- atomic_read(&fscache_n_allocs_object_dead));
58381+ atomic_read_unchecked(&fscache_n_alloc_ops),
58382+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
58383+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
58384
58385 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
58386 " int=%u oom=%u\n",
58387- atomic_read(&fscache_n_retrievals),
58388- atomic_read(&fscache_n_retrievals_ok),
58389- atomic_read(&fscache_n_retrievals_wait),
58390- atomic_read(&fscache_n_retrievals_nodata),
58391- atomic_read(&fscache_n_retrievals_nobufs),
58392- atomic_read(&fscache_n_retrievals_intr),
58393- atomic_read(&fscache_n_retrievals_nomem));
58394+ atomic_read_unchecked(&fscache_n_retrievals),
58395+ atomic_read_unchecked(&fscache_n_retrievals_ok),
58396+ atomic_read_unchecked(&fscache_n_retrievals_wait),
58397+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
58398+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
58399+ atomic_read_unchecked(&fscache_n_retrievals_intr),
58400+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
58401 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
58402- atomic_read(&fscache_n_retrieval_ops),
58403- atomic_read(&fscache_n_retrieval_op_waits),
58404- atomic_read(&fscache_n_retrievals_object_dead));
58405+ atomic_read_unchecked(&fscache_n_retrieval_ops),
58406+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
58407+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
58408
58409 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
58410- atomic_read(&fscache_n_stores),
58411- atomic_read(&fscache_n_stores_ok),
58412- atomic_read(&fscache_n_stores_again),
58413- atomic_read(&fscache_n_stores_nobufs),
58414- atomic_read(&fscache_n_stores_oom));
58415+ atomic_read_unchecked(&fscache_n_stores),
58416+ atomic_read_unchecked(&fscache_n_stores_ok),
58417+ atomic_read_unchecked(&fscache_n_stores_again),
58418+ atomic_read_unchecked(&fscache_n_stores_nobufs),
58419+ atomic_read_unchecked(&fscache_n_stores_oom));
58420 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
58421- atomic_read(&fscache_n_store_ops),
58422- atomic_read(&fscache_n_store_calls),
58423- atomic_read(&fscache_n_store_pages),
58424- atomic_read(&fscache_n_store_radix_deletes),
58425- atomic_read(&fscache_n_store_pages_over_limit));
58426+ atomic_read_unchecked(&fscache_n_store_ops),
58427+ atomic_read_unchecked(&fscache_n_store_calls),
58428+ atomic_read_unchecked(&fscache_n_store_pages),
58429+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
58430+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
58431
58432 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
58433- atomic_read(&fscache_n_store_vmscan_not_storing),
58434- atomic_read(&fscache_n_store_vmscan_gone),
58435- atomic_read(&fscache_n_store_vmscan_busy),
58436- atomic_read(&fscache_n_store_vmscan_cancelled),
58437- atomic_read(&fscache_n_store_vmscan_wait));
58438+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
58439+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
58440+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
58441+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
58442+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
58443
58444 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
58445- atomic_read(&fscache_n_op_pend),
58446- atomic_read(&fscache_n_op_run),
58447- atomic_read(&fscache_n_op_enqueue),
58448- atomic_read(&fscache_n_op_cancelled),
58449- atomic_read(&fscache_n_op_rejected));
58450+ atomic_read_unchecked(&fscache_n_op_pend),
58451+ atomic_read_unchecked(&fscache_n_op_run),
58452+ atomic_read_unchecked(&fscache_n_op_enqueue),
58453+ atomic_read_unchecked(&fscache_n_op_cancelled),
58454+ atomic_read_unchecked(&fscache_n_op_rejected));
58455 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
58456- atomic_read(&fscache_n_op_deferred_release),
58457- atomic_read(&fscache_n_op_release),
58458- atomic_read(&fscache_n_op_gc));
58459+ atomic_read_unchecked(&fscache_n_op_deferred_release),
58460+ atomic_read_unchecked(&fscache_n_op_release),
58461+ atomic_read_unchecked(&fscache_n_op_gc));
58462
58463 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
58464 atomic_read(&fscache_n_cop_alloc_object),
58465diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
58466index adbfd66..4b25822 100644
58467--- a/fs/fuse/cuse.c
58468+++ b/fs/fuse/cuse.c
58469@@ -603,10 +603,12 @@ static int __init cuse_init(void)
58470 INIT_LIST_HEAD(&cuse_conntbl[i]);
58471
58472 /* inherit and extend fuse_dev_operations */
58473- cuse_channel_fops = fuse_dev_operations;
58474- cuse_channel_fops.owner = THIS_MODULE;
58475- cuse_channel_fops.open = cuse_channel_open;
58476- cuse_channel_fops.release = cuse_channel_release;
58477+ pax_open_kernel();
58478+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
58479+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
58480+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
58481+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
58482+ pax_close_kernel();
58483
58484 cuse_class = class_create(THIS_MODULE, "cuse");
58485 if (IS_ERR(cuse_class))
58486diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
58487index ef74ad5..c9ac759e 100644
58488--- a/fs/fuse/dev.c
58489+++ b/fs/fuse/dev.c
58490@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58491 ret = 0;
58492 pipe_lock(pipe);
58493
58494- if (!pipe->readers) {
58495+ if (!atomic_read(&pipe->readers)) {
58496 send_sig(SIGPIPE, current, 0);
58497 if (!ret)
58498 ret = -EPIPE;
58499@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58500 page_nr++;
58501 ret += buf->len;
58502
58503- if (pipe->files)
58504+ if (atomic_read(&pipe->files))
58505 do_wakeup = 1;
58506 }
58507
58508diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
58509index b7989f2..1f72ec4 100644
58510--- a/fs/fuse/dir.c
58511+++ b/fs/fuse/dir.c
58512@@ -1438,7 +1438,7 @@ static char *read_link(struct dentry *dentry)
58513 return link;
58514 }
58515
58516-static void free_link(char *link)
58517+static void free_link(const char *link)
58518 {
58519 if (!IS_ERR(link))
58520 free_page((unsigned long) link);
58521diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
58522index 1298766..c964c60 100644
58523--- a/fs/gfs2/inode.c
58524+++ b/fs/gfs2/inode.c
58525@@ -1515,7 +1515,7 @@ out:
58526
58527 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58528 {
58529- char *s = nd_get_link(nd);
58530+ const char *s = nd_get_link(nd);
58531 if (!IS_ERR(s))
58532 kfree(s);
58533 }
58534diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
58535index 2543728..14d7bd4 100644
58536--- a/fs/hostfs/hostfs_kern.c
58537+++ b/fs/hostfs/hostfs_kern.c
58538@@ -904,7 +904,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58539
58540 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
58541 {
58542- char *s = nd_get_link(nd);
58543+ const char *s = nd_get_link(nd);
58544 if (!IS_ERR(s))
58545 __putname(s);
58546 }
58547diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
58548index d19b30a..ef89c36 100644
58549--- a/fs/hugetlbfs/inode.c
58550+++ b/fs/hugetlbfs/inode.c
58551@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58552 struct mm_struct *mm = current->mm;
58553 struct vm_area_struct *vma;
58554 struct hstate *h = hstate_file(file);
58555+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
58556 struct vm_unmapped_area_info info;
58557
58558 if (len & ~huge_page_mask(h))
58559@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58560 return addr;
58561 }
58562
58563+#ifdef CONFIG_PAX_RANDMMAP
58564+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
58565+#endif
58566+
58567 if (addr) {
58568 addr = ALIGN(addr, huge_page_size(h));
58569 vma = find_vma(mm, addr);
58570- if (TASK_SIZE - len >= addr &&
58571- (!vma || addr + len <= vma->vm_start))
58572+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
58573 return addr;
58574 }
58575
58576 info.flags = 0;
58577 info.length = len;
58578 info.low_limit = TASK_UNMAPPED_BASE;
58579+
58580+#ifdef CONFIG_PAX_RANDMMAP
58581+ if (mm->pax_flags & MF_PAX_RANDMMAP)
58582+ info.low_limit += mm->delta_mmap;
58583+#endif
58584+
58585 info.high_limit = TASK_SIZE;
58586 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
58587 info.align_offset = 0;
58588@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
58589 };
58590 MODULE_ALIAS_FS("hugetlbfs");
58591
58592-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58593+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58594
58595 static int can_do_hugetlb_shm(void)
58596 {
58597diff --git a/fs/inode.c b/fs/inode.c
58598index b33ba8e..3c79a47 100644
58599--- a/fs/inode.c
58600+++ b/fs/inode.c
58601@@ -849,8 +849,8 @@ unsigned int get_next_ino(void)
58602
58603 #ifdef CONFIG_SMP
58604 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
58605- static atomic_t shared_last_ino;
58606- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
58607+ static atomic_unchecked_t shared_last_ino;
58608+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
58609
58610 res = next - LAST_INO_BATCH;
58611 }
58612diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
58613index 4a6cf28..d3a29d3 100644
58614--- a/fs/jffs2/erase.c
58615+++ b/fs/jffs2/erase.c
58616@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
58617 struct jffs2_unknown_node marker = {
58618 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
58619 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58620- .totlen = cpu_to_je32(c->cleanmarker_size)
58621+ .totlen = cpu_to_je32(c->cleanmarker_size),
58622+ .hdr_crc = cpu_to_je32(0)
58623 };
58624
58625 jffs2_prealloc_raw_node_refs(c, jeb, 1);
58626diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
58627index a6597d6..41b30ec 100644
58628--- a/fs/jffs2/wbuf.c
58629+++ b/fs/jffs2/wbuf.c
58630@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
58631 {
58632 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
58633 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58634- .totlen = constant_cpu_to_je32(8)
58635+ .totlen = constant_cpu_to_je32(8),
58636+ .hdr_crc = constant_cpu_to_je32(0)
58637 };
58638
58639 /*
58640diff --git a/fs/jfs/super.c b/fs/jfs/super.c
58641index 6669aa2..36b033d 100644
58642--- a/fs/jfs/super.c
58643+++ b/fs/jfs/super.c
58644@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
58645
58646 jfs_inode_cachep =
58647 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
58648- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
58649+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
58650 init_once);
58651 if (jfs_inode_cachep == NULL)
58652 return -ENOMEM;
58653diff --git a/fs/libfs.c b/fs/libfs.c
58654index 193e0c2..7404665 100644
58655--- a/fs/libfs.c
58656+++ b/fs/libfs.c
58657@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
58658
58659 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
58660 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
58661+ char d_name[sizeof(next->d_iname)];
58662+ const unsigned char *name;
58663+
58664 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
58665 if (!simple_positive(next)) {
58666 spin_unlock(&next->d_lock);
58667@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
58668
58669 spin_unlock(&next->d_lock);
58670 spin_unlock(&dentry->d_lock);
58671- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
58672+ name = next->d_name.name;
58673+ if (name == next->d_iname) {
58674+ memcpy(d_name, name, next->d_name.len);
58675+ name = d_name;
58676+ }
58677+ if (!dir_emit(ctx, name, next->d_name.len,
58678 next->d_inode->i_ino, dt_type(next->d_inode)))
58679 return 0;
58680 spin_lock(&dentry->d_lock);
58681diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
58682index acd3947..1f896e2 100644
58683--- a/fs/lockd/clntproc.c
58684+++ b/fs/lockd/clntproc.c
58685@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
58686 /*
58687 * Cookie counter for NLM requests
58688 */
58689-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
58690+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
58691
58692 void nlmclnt_next_cookie(struct nlm_cookie *c)
58693 {
58694- u32 cookie = atomic_inc_return(&nlm_cookie);
58695+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
58696
58697 memcpy(c->data, &cookie, 4);
58698 c->len=4;
58699diff --git a/fs/locks.c b/fs/locks.c
58700index b27a300..4156d0b 100644
58701--- a/fs/locks.c
58702+++ b/fs/locks.c
58703@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
58704 return;
58705
58706 if (filp->f_op && filp->f_op->flock) {
58707- struct file_lock fl = {
58708+ struct file_lock flock = {
58709 .fl_pid = current->tgid,
58710 .fl_file = filp,
58711 .fl_flags = FL_FLOCK,
58712 .fl_type = F_UNLCK,
58713 .fl_end = OFFSET_MAX,
58714 };
58715- filp->f_op->flock(filp, F_SETLKW, &fl);
58716- if (fl.fl_ops && fl.fl_ops->fl_release_private)
58717- fl.fl_ops->fl_release_private(&fl);
58718+ filp->f_op->flock(filp, F_SETLKW, &flock);
58719+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
58720+ flock.fl_ops->fl_release_private(&flock);
58721 }
58722
58723 spin_lock(&inode->i_lock);
58724diff --git a/fs/namei.c b/fs/namei.c
58725index 23ac50f..c6757a5 100644
58726--- a/fs/namei.c
58727+++ b/fs/namei.c
58728@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
58729 if (ret != -EACCES)
58730 return ret;
58731
58732+#ifdef CONFIG_GRKERNSEC
58733+ /* we'll block if we have to log due to a denied capability use */
58734+ if (mask & MAY_NOT_BLOCK)
58735+ return -ECHILD;
58736+#endif
58737+
58738 if (S_ISDIR(inode->i_mode)) {
58739 /* DACs are overridable for directories */
58740- if (inode_capable(inode, CAP_DAC_OVERRIDE))
58741- return 0;
58742 if (!(mask & MAY_WRITE))
58743- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58744+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58745+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58746 return 0;
58747+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
58748+ return 0;
58749 return -EACCES;
58750 }
58751 /*
58752+ * Searching includes executable on directories, else just read.
58753+ */
58754+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58755+ if (mask == MAY_READ)
58756+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58757+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58758+ return 0;
58759+
58760+ /*
58761 * Read/write DACs are always overridable.
58762 * Executable DACs are overridable when there is
58763 * at least one exec bit set.
58764@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
58765 if (inode_capable(inode, CAP_DAC_OVERRIDE))
58766 return 0;
58767
58768- /*
58769- * Searching includes executable on directories, else just read.
58770- */
58771- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58772- if (mask == MAY_READ)
58773- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58774- return 0;
58775-
58776 return -EACCES;
58777 }
58778
58779@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58780 {
58781 struct dentry *dentry = link->dentry;
58782 int error;
58783- char *s;
58784+ const char *s;
58785
58786 BUG_ON(nd->flags & LOOKUP_RCU);
58787
58788@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58789 if (error)
58790 goto out_put_nd_path;
58791
58792+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
58793+ dentry->d_inode, dentry, nd->path.mnt)) {
58794+ error = -EACCES;
58795+ goto out_put_nd_path;
58796+ }
58797+
58798 nd->last_type = LAST_BIND;
58799 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
58800 error = PTR_ERR(*p);
58801@@ -1602,6 +1616,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
58802 if (res)
58803 break;
58804 res = walk_component(nd, path, LOOKUP_FOLLOW);
58805+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
58806+ res = -EACCES;
58807 put_link(nd, &link, cookie);
58808 } while (res > 0);
58809
58810@@ -1700,7 +1716,7 @@ EXPORT_SYMBOL(full_name_hash);
58811 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
58812 {
58813 unsigned long a, b, adata, bdata, mask, hash, len;
58814- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58815+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58816
58817 hash = a = 0;
58818 len = -sizeof(unsigned long);
58819@@ -1981,6 +1997,8 @@ static int path_lookupat(int dfd, const char *name,
58820 if (err)
58821 break;
58822 err = lookup_last(nd, &path);
58823+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
58824+ err = -EACCES;
58825 put_link(nd, &link, cookie);
58826 }
58827 }
58828@@ -1988,6 +2006,13 @@ static int path_lookupat(int dfd, const char *name,
58829 if (!err)
58830 err = complete_walk(nd);
58831
58832+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
58833+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58834+ path_put(&nd->path);
58835+ err = -ENOENT;
58836+ }
58837+ }
58838+
58839 if (!err && nd->flags & LOOKUP_DIRECTORY) {
58840 if (!can_lookup(nd->inode)) {
58841 path_put(&nd->path);
58842@@ -2015,8 +2040,15 @@ static int filename_lookup(int dfd, struct filename *name,
58843 retval = path_lookupat(dfd, name->name,
58844 flags | LOOKUP_REVAL, nd);
58845
58846- if (likely(!retval))
58847+ if (likely(!retval)) {
58848 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
58849+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
58850+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
58851+ path_put(&nd->path);
58852+ return -ENOENT;
58853+ }
58854+ }
58855+ }
58856 return retval;
58857 }
58858
58859@@ -2587,6 +2619,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
58860 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
58861 return -EPERM;
58862
58863+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
58864+ return -EPERM;
58865+ if (gr_handle_rawio(inode))
58866+ return -EPERM;
58867+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
58868+ return -EACCES;
58869+
58870 return 0;
58871 }
58872
58873@@ -2818,7 +2857,7 @@ looked_up:
58874 * cleared otherwise prior to returning.
58875 */
58876 static int lookup_open(struct nameidata *nd, struct path *path,
58877- struct file *file,
58878+ struct path *link, struct file *file,
58879 const struct open_flags *op,
58880 bool got_write, int *opened)
58881 {
58882@@ -2853,6 +2892,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58883 /* Negative dentry, just create the file */
58884 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
58885 umode_t mode = op->mode;
58886+
58887+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
58888+ error = -EACCES;
58889+ goto out_dput;
58890+ }
58891+
58892+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
58893+ error = -EACCES;
58894+ goto out_dput;
58895+ }
58896+
58897 if (!IS_POSIXACL(dir->d_inode))
58898 mode &= ~current_umask();
58899 /*
58900@@ -2874,6 +2924,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58901 nd->flags & LOOKUP_EXCL);
58902 if (error)
58903 goto out_dput;
58904+ else
58905+ gr_handle_create(dentry, nd->path.mnt);
58906 }
58907 out_no_open:
58908 path->dentry = dentry;
58909@@ -2888,7 +2940,7 @@ out_dput:
58910 /*
58911 * Handle the last step of open()
58912 */
58913-static int do_last(struct nameidata *nd, struct path *path,
58914+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
58915 struct file *file, const struct open_flags *op,
58916 int *opened, struct filename *name)
58917 {
58918@@ -2938,6 +2990,15 @@ static int do_last(struct nameidata *nd, struct path *path,
58919 if (error)
58920 return error;
58921
58922+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
58923+ error = -ENOENT;
58924+ goto out;
58925+ }
58926+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58927+ error = -EACCES;
58928+ goto out;
58929+ }
58930+
58931 audit_inode(name, dir, LOOKUP_PARENT);
58932 error = -EISDIR;
58933 /* trailing slashes? */
58934@@ -2957,7 +3018,7 @@ retry_lookup:
58935 */
58936 }
58937 mutex_lock(&dir->d_inode->i_mutex);
58938- error = lookup_open(nd, path, file, op, got_write, opened);
58939+ error = lookup_open(nd, path, link, file, op, got_write, opened);
58940 mutex_unlock(&dir->d_inode->i_mutex);
58941
58942 if (error <= 0) {
58943@@ -2981,11 +3042,28 @@ retry_lookup:
58944 goto finish_open_created;
58945 }
58946
58947+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
58948+ error = -ENOENT;
58949+ goto exit_dput;
58950+ }
58951+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
58952+ error = -EACCES;
58953+ goto exit_dput;
58954+ }
58955+
58956 /*
58957 * create/update audit record if it already exists.
58958 */
58959- if (path->dentry->d_inode)
58960+ if (path->dentry->d_inode) {
58961+ /* only check if O_CREAT is specified, all other checks need to go
58962+ into may_open */
58963+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
58964+ error = -EACCES;
58965+ goto exit_dput;
58966+ }
58967+
58968 audit_inode(name, path->dentry, 0);
58969+ }
58970
58971 /*
58972 * If atomic_open() acquired write access it is dropped now due to
58973@@ -3026,6 +3104,11 @@ finish_lookup:
58974 }
58975 }
58976 BUG_ON(inode != path->dentry->d_inode);
58977+ /* if we're resolving a symlink to another symlink */
58978+ if (link && gr_handle_symlink_owner(link, inode)) {
58979+ error = -EACCES;
58980+ goto out;
58981+ }
58982 return 1;
58983 }
58984
58985@@ -3035,7 +3118,6 @@ finish_lookup:
58986 save_parent.dentry = nd->path.dentry;
58987 save_parent.mnt = mntget(path->mnt);
58988 nd->path.dentry = path->dentry;
58989-
58990 }
58991 nd->inode = inode;
58992 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
58993@@ -3045,7 +3127,18 @@ finish_open:
58994 path_put(&save_parent);
58995 return error;
58996 }
58997+
58998+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58999+ error = -ENOENT;
59000+ goto out;
59001+ }
59002+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
59003+ error = -EACCES;
59004+ goto out;
59005+ }
59006+
59007 audit_inode(name, nd->path.dentry, 0);
59008+
59009 error = -EISDIR;
59010 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
59011 goto out;
59012@@ -3208,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
59013 if (unlikely(error))
59014 goto out;
59015
59016- error = do_last(nd, &path, file, op, &opened, pathname);
59017+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
59018 while (unlikely(error > 0)) { /* trailing symlink */
59019 struct path link = path;
59020 void *cookie;
59021@@ -3226,7 +3319,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
59022 error = follow_link(&link, nd, &cookie);
59023 if (unlikely(error))
59024 break;
59025- error = do_last(nd, &path, file, op, &opened, pathname);
59026+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
59027 put_link(nd, &link, cookie);
59028 }
59029 out:
59030@@ -3326,8 +3419,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
59031 goto unlock;
59032
59033 error = -EEXIST;
59034- if (dentry->d_inode)
59035+ if (dentry->d_inode) {
59036+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
59037+ error = -ENOENT;
59038+ }
59039 goto fail;
59040+ }
59041 /*
59042 * Special case - lookup gave negative, but... we had foo/bar/
59043 * From the vfs_mknod() POV we just have a negative dentry -
59044@@ -3379,6 +3476,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
59045 }
59046 EXPORT_SYMBOL(user_path_create);
59047
59048+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
59049+{
59050+ struct filename *tmp = getname(pathname);
59051+ struct dentry *res;
59052+ if (IS_ERR(tmp))
59053+ return ERR_CAST(tmp);
59054+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
59055+ if (IS_ERR(res))
59056+ putname(tmp);
59057+ else
59058+ *to = tmp;
59059+ return res;
59060+}
59061+
59062 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
59063 {
59064 int error = may_create(dir, dentry);
59065@@ -3441,6 +3552,17 @@ retry:
59066
59067 if (!IS_POSIXACL(path.dentry->d_inode))
59068 mode &= ~current_umask();
59069+
59070+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
59071+ error = -EPERM;
59072+ goto out;
59073+ }
59074+
59075+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
59076+ error = -EACCES;
59077+ goto out;
59078+ }
59079+
59080 error = security_path_mknod(&path, dentry, mode, dev);
59081 if (error)
59082 goto out;
59083@@ -3457,6 +3579,8 @@ retry:
59084 break;
59085 }
59086 out:
59087+ if (!error)
59088+ gr_handle_create(dentry, path.mnt);
59089 done_path_create(&path, dentry);
59090 if (retry_estale(error, lookup_flags)) {
59091 lookup_flags |= LOOKUP_REVAL;
59092@@ -3509,9 +3633,16 @@ retry:
59093
59094 if (!IS_POSIXACL(path.dentry->d_inode))
59095 mode &= ~current_umask();
59096+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
59097+ error = -EACCES;
59098+ goto out;
59099+ }
59100 error = security_path_mkdir(&path, dentry, mode);
59101 if (!error)
59102 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
59103+ if (!error)
59104+ gr_handle_create(dentry, path.mnt);
59105+out:
59106 done_path_create(&path, dentry);
59107 if (retry_estale(error, lookup_flags)) {
59108 lookup_flags |= LOOKUP_REVAL;
59109@@ -3592,6 +3723,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
59110 struct filename *name;
59111 struct dentry *dentry;
59112 struct nameidata nd;
59113+ ino_t saved_ino = 0;
59114+ dev_t saved_dev = 0;
59115 unsigned int lookup_flags = 0;
59116 retry:
59117 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
59118@@ -3624,10 +3757,21 @@ retry:
59119 error = -ENOENT;
59120 goto exit3;
59121 }
59122+
59123+ saved_ino = dentry->d_inode->i_ino;
59124+ saved_dev = gr_get_dev_from_dentry(dentry);
59125+
59126+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
59127+ error = -EACCES;
59128+ goto exit3;
59129+ }
59130+
59131 error = security_path_rmdir(&nd.path, dentry);
59132 if (error)
59133 goto exit3;
59134 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
59135+ if (!error && (saved_dev || saved_ino))
59136+ gr_handle_delete(saved_ino, saved_dev);
59137 exit3:
59138 dput(dentry);
59139 exit2:
59140@@ -3693,6 +3837,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
59141 struct dentry *dentry;
59142 struct nameidata nd;
59143 struct inode *inode = NULL;
59144+ ino_t saved_ino = 0;
59145+ dev_t saved_dev = 0;
59146 unsigned int lookup_flags = 0;
59147 retry:
59148 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
59149@@ -3719,10 +3865,22 @@ retry:
59150 if (!inode)
59151 goto slashes;
59152 ihold(inode);
59153+
59154+ if (inode->i_nlink <= 1) {
59155+ saved_ino = inode->i_ino;
59156+ saved_dev = gr_get_dev_from_dentry(dentry);
59157+ }
59158+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
59159+ error = -EACCES;
59160+ goto exit2;
59161+ }
59162+
59163 error = security_path_unlink(&nd.path, dentry);
59164 if (error)
59165 goto exit2;
59166 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
59167+ if (!error && (saved_ino || saved_dev))
59168+ gr_handle_delete(saved_ino, saved_dev);
59169 exit2:
59170 dput(dentry);
59171 }
59172@@ -3800,9 +3958,17 @@ retry:
59173 if (IS_ERR(dentry))
59174 goto out_putname;
59175
59176+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
59177+ error = -EACCES;
59178+ goto out;
59179+ }
59180+
59181 error = security_path_symlink(&path, dentry, from->name);
59182 if (!error)
59183 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
59184+ if (!error)
59185+ gr_handle_create(dentry, path.mnt);
59186+out:
59187 done_path_create(&path, dentry);
59188 if (retry_estale(error, lookup_flags)) {
59189 lookup_flags |= LOOKUP_REVAL;
59190@@ -3882,6 +4048,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
59191 {
59192 struct dentry *new_dentry;
59193 struct path old_path, new_path;
59194+ struct filename *to = NULL;
59195 int how = 0;
59196 int error;
59197
59198@@ -3905,7 +4072,7 @@ retry:
59199 if (error)
59200 return error;
59201
59202- new_dentry = user_path_create(newdfd, newname, &new_path,
59203+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
59204 (how & LOOKUP_REVAL));
59205 error = PTR_ERR(new_dentry);
59206 if (IS_ERR(new_dentry))
59207@@ -3917,11 +4084,28 @@ retry:
59208 error = may_linkat(&old_path);
59209 if (unlikely(error))
59210 goto out_dput;
59211+
59212+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
59213+ old_path.dentry->d_inode,
59214+ old_path.dentry->d_inode->i_mode, to)) {
59215+ error = -EACCES;
59216+ goto out_dput;
59217+ }
59218+
59219+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
59220+ old_path.dentry, old_path.mnt, to)) {
59221+ error = -EACCES;
59222+ goto out_dput;
59223+ }
59224+
59225 error = security_path_link(old_path.dentry, &new_path, new_dentry);
59226 if (error)
59227 goto out_dput;
59228 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
59229+ if (!error)
59230+ gr_handle_create(new_dentry, new_path.mnt);
59231 out_dput:
59232+ putname(to);
59233 done_path_create(&new_path, new_dentry);
59234 if (retry_estale(error, how)) {
59235 how |= LOOKUP_REVAL;
59236@@ -4167,12 +4351,21 @@ retry:
59237 if (new_dentry == trap)
59238 goto exit5;
59239
59240+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
59241+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
59242+ to);
59243+ if (error)
59244+ goto exit5;
59245+
59246 error = security_path_rename(&oldnd.path, old_dentry,
59247 &newnd.path, new_dentry);
59248 if (error)
59249 goto exit5;
59250 error = vfs_rename(old_dir->d_inode, old_dentry,
59251 new_dir->d_inode, new_dentry);
59252+ if (!error)
59253+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
59254+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
59255 exit5:
59256 dput(new_dentry);
59257 exit4:
59258@@ -4204,6 +4397,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
59259
59260 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
59261 {
59262+ char tmpbuf[64];
59263+ const char *newlink;
59264 int len;
59265
59266 len = PTR_ERR(link);
59267@@ -4213,7 +4408,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
59268 len = strlen(link);
59269 if (len > (unsigned) buflen)
59270 len = buflen;
59271- if (copy_to_user(buffer, link, len))
59272+
59273+ if (len < sizeof(tmpbuf)) {
59274+ memcpy(tmpbuf, link, len);
59275+ newlink = tmpbuf;
59276+ } else
59277+ newlink = link;
59278+
59279+ if (copy_to_user(buffer, newlink, len))
59280 len = -EFAULT;
59281 out:
59282 return len;
59283diff --git a/fs/namespace.c b/fs/namespace.c
59284index da5c494..a755a54 100644
59285--- a/fs/namespace.c
59286+++ b/fs/namespace.c
59287@@ -1268,6 +1268,9 @@ static int do_umount(struct mount *mnt, int flags)
59288 if (!(sb->s_flags & MS_RDONLY))
59289 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
59290 up_write(&sb->s_umount);
59291+
59292+ gr_log_remount(mnt->mnt_devname, retval);
59293+
59294 return retval;
59295 }
59296
59297@@ -1286,6 +1289,9 @@ static int do_umount(struct mount *mnt, int flags)
59298 }
59299 br_write_unlock(&vfsmount_lock);
59300 namespace_unlock();
59301+
59302+ gr_log_unmount(mnt->mnt_devname, retval);
59303+
59304 return retval;
59305 }
59306
59307@@ -1305,7 +1311,7 @@ static inline bool may_mount(void)
59308 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
59309 */
59310
59311-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
59312+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
59313 {
59314 struct path path;
59315 struct mount *mnt;
59316@@ -1347,7 +1353,7 @@ out:
59317 /*
59318 * The 2.0 compatible umount. No flags.
59319 */
59320-SYSCALL_DEFINE1(oldumount, char __user *, name)
59321+SYSCALL_DEFINE1(oldumount, const char __user *, name)
59322 {
59323 return sys_umount(name, 0);
59324 }
59325@@ -2358,6 +2364,16 @@ long do_mount(const char *dev_name, const char *dir_name,
59326 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
59327 MS_STRICTATIME);
59328
59329+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
59330+ retval = -EPERM;
59331+ goto dput_out;
59332+ }
59333+
59334+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
59335+ retval = -EPERM;
59336+ goto dput_out;
59337+ }
59338+
59339 if (flags & MS_REMOUNT)
59340 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
59341 data_page);
59342@@ -2372,6 +2388,9 @@ long do_mount(const char *dev_name, const char *dir_name,
59343 dev_name, data_page);
59344 dput_out:
59345 path_put(&path);
59346+
59347+ gr_log_mount(dev_name, dir_name, retval);
59348+
59349 return retval;
59350 }
59351
59352@@ -2389,7 +2408,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
59353 * number incrementing at 10Ghz will take 12,427 years to wrap which
59354 * is effectively never, so we can ignore the possibility.
59355 */
59356-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
59357+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
59358
59359 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59360 {
59361@@ -2404,7 +2423,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59362 kfree(new_ns);
59363 return ERR_PTR(ret);
59364 }
59365- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
59366+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
59367 atomic_set(&new_ns->count, 1);
59368 new_ns->root = NULL;
59369 INIT_LIST_HEAD(&new_ns->list);
59370@@ -2418,7 +2437,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59371 * Allocate a new namespace structure and populate it with contents
59372 * copied from the namespace of the passed in task structure.
59373 */
59374-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
59375+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
59376 struct user_namespace *user_ns, struct fs_struct *fs)
59377 {
59378 struct mnt_namespace *new_ns;
59379@@ -2549,8 +2568,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
59380 }
59381 EXPORT_SYMBOL(mount_subtree);
59382
59383-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
59384- char __user *, type, unsigned long, flags, void __user *, data)
59385+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
59386+ const char __user *, type, unsigned long, flags, void __user *, data)
59387 {
59388 int ret;
59389 char *kernel_type;
59390@@ -2663,6 +2682,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
59391 if (error)
59392 goto out2;
59393
59394+ if (gr_handle_chroot_pivot()) {
59395+ error = -EPERM;
59396+ goto out2;
59397+ }
59398+
59399 get_fs_root(current->fs, &root);
59400 old_mp = lock_mount(&old);
59401 error = PTR_ERR(old_mp);
59402@@ -2932,7 +2956,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
59403 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
59404 return -EPERM;
59405
59406- if (fs->users != 1)
59407+ if (atomic_read(&fs->users) != 1)
59408 return -EINVAL;
59409
59410 get_mnt_ns(mnt_ns);
59411diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
59412index f4ccfe6..a5cf064 100644
59413--- a/fs/nfs/callback_xdr.c
59414+++ b/fs/nfs/callback_xdr.c
59415@@ -51,7 +51,7 @@ struct callback_op {
59416 callback_decode_arg_t decode_args;
59417 callback_encode_res_t encode_res;
59418 long res_maxsize;
59419-};
59420+} __do_const;
59421
59422 static struct callback_op callback_ops[];
59423
59424diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
59425index eda8879..bfc6837 100644
59426--- a/fs/nfs/inode.c
59427+++ b/fs/nfs/inode.c
59428@@ -1150,16 +1150,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
59429 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
59430 }
59431
59432-static atomic_long_t nfs_attr_generation_counter;
59433+static atomic_long_unchecked_t nfs_attr_generation_counter;
59434
59435 static unsigned long nfs_read_attr_generation_counter(void)
59436 {
59437- return atomic_long_read(&nfs_attr_generation_counter);
59438+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
59439 }
59440
59441 unsigned long nfs_inc_attr_generation_counter(void)
59442 {
59443- return atomic_long_inc_return(&nfs_attr_generation_counter);
59444+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
59445 }
59446
59447 void nfs_fattr_init(struct nfs_fattr *fattr)
59448diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
59449index 419572f..5414a23 100644
59450--- a/fs/nfsd/nfs4proc.c
59451+++ b/fs/nfsd/nfs4proc.c
59452@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
59453 nfsd4op_rsize op_rsize_bop;
59454 stateid_getter op_get_currentstateid;
59455 stateid_setter op_set_currentstateid;
59456-};
59457+} __do_const;
59458
59459 static struct nfsd4_operation nfsd4_ops[];
59460
59461diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
59462index ecc735e..79b2d31 100644
59463--- a/fs/nfsd/nfs4xdr.c
59464+++ b/fs/nfsd/nfs4xdr.c
59465@@ -1500,7 +1500,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
59466
59467 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
59468
59469-static nfsd4_dec nfsd4_dec_ops[] = {
59470+static const nfsd4_dec nfsd4_dec_ops[] = {
59471 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59472 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59473 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59474@@ -1540,7 +1540,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
59475 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
59476 };
59477
59478-static nfsd4_dec nfsd41_dec_ops[] = {
59479+static const nfsd4_dec nfsd41_dec_ops[] = {
59480 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59481 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59482 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59483@@ -1602,7 +1602,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
59484 };
59485
59486 struct nfsd4_minorversion_ops {
59487- nfsd4_dec *decoders;
59488+ const nfsd4_dec *decoders;
59489 int nops;
59490 };
59491
59492diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
59493index b6af150..f6ec5e3 100644
59494--- a/fs/nfsd/nfscache.c
59495+++ b/fs/nfsd/nfscache.c
59496@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
59497 {
59498 struct svc_cacherep *rp = rqstp->rq_cacherep;
59499 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
59500- int len;
59501+ long len;
59502 size_t bufsize = 0;
59503
59504 if (!rp)
59505 return;
59506
59507- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
59508- len >>= 2;
59509+ if (statp) {
59510+ len = (char*)statp - (char*)resv->iov_base;
59511+ len = resv->iov_len - len;
59512+ len >>= 2;
59513+ }
59514
59515 /* Don't cache excessive amounts of data and XDR failures */
59516 if (!statp || len > (256 >> 2)) {
59517diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
59518index 72cb28e..5b5f87d 100644
59519--- a/fs/nfsd/vfs.c
59520+++ b/fs/nfsd/vfs.c
59521@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59522 } else {
59523 oldfs = get_fs();
59524 set_fs(KERNEL_DS);
59525- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
59526+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
59527 set_fs(oldfs);
59528 }
59529
59530@@ -1080,7 +1080,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59531
59532 /* Write the data. */
59533 oldfs = get_fs(); set_fs(KERNEL_DS);
59534- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
59535+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
59536 set_fs(oldfs);
59537 if (host_err < 0)
59538 goto out_nfserr;
59539@@ -1626,7 +1626,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
59540 */
59541
59542 oldfs = get_fs(); set_fs(KERNEL_DS);
59543- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
59544+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
59545 set_fs(oldfs);
59546
59547 if (host_err < 0)
59548diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
59549index fea6bd5..8ee9d81 100644
59550--- a/fs/nls/nls_base.c
59551+++ b/fs/nls/nls_base.c
59552@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
59553
59554 int register_nls(struct nls_table * nls)
59555 {
59556- struct nls_table ** tmp = &tables;
59557+ struct nls_table *tmp = tables;
59558
59559 if (nls->next)
59560 return -EBUSY;
59561
59562 spin_lock(&nls_lock);
59563- while (*tmp) {
59564- if (nls == *tmp) {
59565+ while (tmp) {
59566+ if (nls == tmp) {
59567 spin_unlock(&nls_lock);
59568 return -EBUSY;
59569 }
59570- tmp = &(*tmp)->next;
59571+ tmp = tmp->next;
59572 }
59573- nls->next = tables;
59574+ pax_open_kernel();
59575+ *(struct nls_table **)&nls->next = tables;
59576+ pax_close_kernel();
59577 tables = nls;
59578 spin_unlock(&nls_lock);
59579 return 0;
59580@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
59581
59582 int unregister_nls(struct nls_table * nls)
59583 {
59584- struct nls_table ** tmp = &tables;
59585+ struct nls_table * const * tmp = &tables;
59586
59587 spin_lock(&nls_lock);
59588 while (*tmp) {
59589 if (nls == *tmp) {
59590- *tmp = nls->next;
59591+ pax_open_kernel();
59592+ *(struct nls_table **)tmp = nls->next;
59593+ pax_close_kernel();
59594 spin_unlock(&nls_lock);
59595 return 0;
59596 }
59597diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
59598index 7424929..35f6be5 100644
59599--- a/fs/nls/nls_euc-jp.c
59600+++ b/fs/nls/nls_euc-jp.c
59601@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
59602 p_nls = load_nls("cp932");
59603
59604 if (p_nls) {
59605- table.charset2upper = p_nls->charset2upper;
59606- table.charset2lower = p_nls->charset2lower;
59607+ pax_open_kernel();
59608+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59609+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59610+ pax_close_kernel();
59611 return register_nls(&table);
59612 }
59613
59614diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
59615index e7bc1d7..06bd4bb 100644
59616--- a/fs/nls/nls_koi8-ru.c
59617+++ b/fs/nls/nls_koi8-ru.c
59618@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
59619 p_nls = load_nls("koi8-u");
59620
59621 if (p_nls) {
59622- table.charset2upper = p_nls->charset2upper;
59623- table.charset2lower = p_nls->charset2lower;
59624+ pax_open_kernel();
59625+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59626+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59627+ pax_close_kernel();
59628 return register_nls(&table);
59629 }
59630
59631diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
59632index e44cb64..4807084 100644
59633--- a/fs/notify/fanotify/fanotify_user.c
59634+++ b/fs/notify/fanotify/fanotify_user.c
59635@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
59636
59637 fd = fanotify_event_metadata.fd;
59638 ret = -EFAULT;
59639- if (copy_to_user(buf, &fanotify_event_metadata,
59640- fanotify_event_metadata.event_len))
59641+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
59642+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
59643 goto out_close_fd;
59644
59645 ret = prepare_for_access_response(group, event, fd);
59646diff --git a/fs/notify/notification.c b/fs/notify/notification.c
59647index 7b51b05..5ea5ef6 100644
59648--- a/fs/notify/notification.c
59649+++ b/fs/notify/notification.c
59650@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
59651 * get set to 0 so it will never get 'freed'
59652 */
59653 static struct fsnotify_event *q_overflow_event;
59654-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59655+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59656
59657 /**
59658 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
59659@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59660 */
59661 u32 fsnotify_get_cookie(void)
59662 {
59663- return atomic_inc_return(&fsnotify_sync_cookie);
59664+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
59665 }
59666 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
59667
59668diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
59669index 9e38daf..5727cae 100644
59670--- a/fs/ntfs/dir.c
59671+++ b/fs/ntfs/dir.c
59672@@ -1310,7 +1310,7 @@ find_next_index_buffer:
59673 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
59674 ~(s64)(ndir->itype.index.block_size - 1)));
59675 /* Bounds checks. */
59676- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59677+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59678 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
59679 "inode 0x%lx or driver bug.", vdir->i_ino);
59680 goto err_out;
59681diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
59682index ea4ba9d..1e13d34 100644
59683--- a/fs/ntfs/file.c
59684+++ b/fs/ntfs/file.c
59685@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
59686 char *addr;
59687 size_t total = 0;
59688 unsigned len;
59689- int left;
59690+ unsigned left;
59691
59692 do {
59693 len = PAGE_CACHE_SIZE - ofs;
59694diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
59695index 82650d5..db37dcf 100644
59696--- a/fs/ntfs/super.c
59697+++ b/fs/ntfs/super.c
59698@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59699 if (!silent)
59700 ntfs_error(sb, "Primary boot sector is invalid.");
59701 } else if (!silent)
59702- ntfs_error(sb, read_err_str, "primary");
59703+ ntfs_error(sb, read_err_str, "%s", "primary");
59704 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
59705 if (bh_primary)
59706 brelse(bh_primary);
59707@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59708 goto hotfix_primary_boot_sector;
59709 brelse(bh_backup);
59710 } else if (!silent)
59711- ntfs_error(sb, read_err_str, "backup");
59712+ ntfs_error(sb, read_err_str, "%s", "backup");
59713 /* Try to read NT3.51- backup boot sector. */
59714 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
59715 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
59716@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59717 "sector.");
59718 brelse(bh_backup);
59719 } else if (!silent)
59720- ntfs_error(sb, read_err_str, "backup");
59721+ ntfs_error(sb, read_err_str, "%s", "backup");
59722 /* We failed. Cleanup and return. */
59723 if (bh_primary)
59724 brelse(bh_primary);
59725diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
59726index cd5496b..26a1055 100644
59727--- a/fs/ocfs2/localalloc.c
59728+++ b/fs/ocfs2/localalloc.c
59729@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
59730 goto bail;
59731 }
59732
59733- atomic_inc(&osb->alloc_stats.moves);
59734+ atomic_inc_unchecked(&osb->alloc_stats.moves);
59735
59736 bail:
59737 if (handle)
59738diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
59739index 3a90347..c40bef8 100644
59740--- a/fs/ocfs2/ocfs2.h
59741+++ b/fs/ocfs2/ocfs2.h
59742@@ -235,11 +235,11 @@ enum ocfs2_vol_state
59743
59744 struct ocfs2_alloc_stats
59745 {
59746- atomic_t moves;
59747- atomic_t local_data;
59748- atomic_t bitmap_data;
59749- atomic_t bg_allocs;
59750- atomic_t bg_extends;
59751+ atomic_unchecked_t moves;
59752+ atomic_unchecked_t local_data;
59753+ atomic_unchecked_t bitmap_data;
59754+ atomic_unchecked_t bg_allocs;
59755+ atomic_unchecked_t bg_extends;
59756 };
59757
59758 enum ocfs2_local_alloc_state
59759diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
59760index 5397c07..54afc55 100644
59761--- a/fs/ocfs2/suballoc.c
59762+++ b/fs/ocfs2/suballoc.c
59763@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
59764 mlog_errno(status);
59765 goto bail;
59766 }
59767- atomic_inc(&osb->alloc_stats.bg_extends);
59768+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
59769
59770 /* You should never ask for this much metadata */
59771 BUG_ON(bits_wanted >
59772@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
59773 mlog_errno(status);
59774 goto bail;
59775 }
59776- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59777+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59778
59779 *suballoc_loc = res.sr_bg_blkno;
59780 *suballoc_bit_start = res.sr_bit_offset;
59781@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
59782 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
59783 res->sr_bits);
59784
59785- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59786+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59787
59788 BUG_ON(res->sr_bits != 1);
59789
59790@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
59791 mlog_errno(status);
59792 goto bail;
59793 }
59794- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59795+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59796
59797 BUG_ON(res.sr_bits != 1);
59798
59799@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59800 cluster_start,
59801 num_clusters);
59802 if (!status)
59803- atomic_inc(&osb->alloc_stats.local_data);
59804+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
59805 } else {
59806 if (min_clusters > (osb->bitmap_cpg - 1)) {
59807 /* The only paths asking for contiguousness
59808@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59809 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
59810 res.sr_bg_blkno,
59811 res.sr_bit_offset);
59812- atomic_inc(&osb->alloc_stats.bitmap_data);
59813+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
59814 *num_clusters = res.sr_bits;
59815 }
59816 }
59817diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
59818index d4e81e4..ad89f5f 100644
59819--- a/fs/ocfs2/super.c
59820+++ b/fs/ocfs2/super.c
59821@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
59822 "%10s => GlobalAllocs: %d LocalAllocs: %d "
59823 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
59824 "Stats",
59825- atomic_read(&osb->alloc_stats.bitmap_data),
59826- atomic_read(&osb->alloc_stats.local_data),
59827- atomic_read(&osb->alloc_stats.bg_allocs),
59828- atomic_read(&osb->alloc_stats.moves),
59829- atomic_read(&osb->alloc_stats.bg_extends));
59830+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
59831+ atomic_read_unchecked(&osb->alloc_stats.local_data),
59832+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
59833+ atomic_read_unchecked(&osb->alloc_stats.moves),
59834+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
59835
59836 out += snprintf(buf + out, len - out,
59837 "%10s => State: %u Descriptor: %llu Size: %u bits "
59838@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
59839 spin_lock_init(&osb->osb_xattr_lock);
59840 ocfs2_init_steal_slots(osb);
59841
59842- atomic_set(&osb->alloc_stats.moves, 0);
59843- atomic_set(&osb->alloc_stats.local_data, 0);
59844- atomic_set(&osb->alloc_stats.bitmap_data, 0);
59845- atomic_set(&osb->alloc_stats.bg_allocs, 0);
59846- atomic_set(&osb->alloc_stats.bg_extends, 0);
59847+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
59848+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
59849+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
59850+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
59851+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
59852
59853 /* Copy the blockcheck stats from the superblock probe */
59854 osb->osb_ecc_stats = *stats;
59855diff --git a/fs/open.c b/fs/open.c
59856index d420331..2dbb3fd 100644
59857--- a/fs/open.c
59858+++ b/fs/open.c
59859@@ -32,6 +32,8 @@
59860 #include <linux/dnotify.h>
59861 #include <linux/compat.h>
59862
59863+#define CREATE_TRACE_POINTS
59864+#include <trace/events/fs.h>
59865 #include "internal.h"
59866
59867 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
59868@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
59869 error = locks_verify_truncate(inode, NULL, length);
59870 if (!error)
59871 error = security_path_truncate(path);
59872+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
59873+ error = -EACCES;
59874 if (!error)
59875 error = do_truncate(path->dentry, length, 0, NULL);
59876
59877@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
59878 error = locks_verify_truncate(inode, f.file, length);
59879 if (!error)
59880 error = security_path_truncate(&f.file->f_path);
59881+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
59882+ error = -EACCES;
59883 if (!error)
59884 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
59885 sb_end_write(inode->i_sb);
59886@@ -360,6 +366,9 @@ retry:
59887 if (__mnt_is_readonly(path.mnt))
59888 res = -EROFS;
59889
59890+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
59891+ res = -EACCES;
59892+
59893 out_path_release:
59894 path_put(&path);
59895 if (retry_estale(res, lookup_flags)) {
59896@@ -391,6 +400,8 @@ retry:
59897 if (error)
59898 goto dput_and_out;
59899
59900+ gr_log_chdir(path.dentry, path.mnt);
59901+
59902 set_fs_pwd(current->fs, &path);
59903
59904 dput_and_out:
59905@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
59906 goto out_putf;
59907
59908 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
59909+
59910+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
59911+ error = -EPERM;
59912+
59913+ if (!error)
59914+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
59915+
59916 if (!error)
59917 set_fs_pwd(current->fs, &f.file->f_path);
59918 out_putf:
59919@@ -449,7 +467,13 @@ retry:
59920 if (error)
59921 goto dput_and_out;
59922
59923+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
59924+ goto dput_and_out;
59925+
59926 set_fs_root(current->fs, &path);
59927+
59928+ gr_handle_chroot_chdir(&path);
59929+
59930 error = 0;
59931 dput_and_out:
59932 path_put(&path);
59933@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
59934 if (error)
59935 return error;
59936 mutex_lock(&inode->i_mutex);
59937+
59938+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
59939+ error = -EACCES;
59940+ goto out_unlock;
59941+ }
59942+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
59943+ error = -EACCES;
59944+ goto out_unlock;
59945+ }
59946+
59947 error = security_path_chmod(path, mode);
59948 if (error)
59949 goto out_unlock;
59950@@ -530,6 +564,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
59951 uid = make_kuid(current_user_ns(), user);
59952 gid = make_kgid(current_user_ns(), group);
59953
59954+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
59955+ return -EACCES;
59956+
59957 newattrs.ia_valid = ATTR_CTIME;
59958 if (user != (uid_t) -1) {
59959 if (!uid_valid(uid))
59960@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
59961 } else {
59962 fsnotify_open(f);
59963 fd_install(fd, f);
59964+ trace_do_sys_open(tmp->name, flags, mode);
59965 }
59966 }
59967 putname(tmp);
59968diff --git a/fs/pipe.c b/fs/pipe.c
59969index 0e0752e..7cfdd50 100644
59970--- a/fs/pipe.c
59971+++ b/fs/pipe.c
59972@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
59973
59974 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
59975 {
59976- if (pipe->files)
59977+ if (atomic_read(&pipe->files))
59978 mutex_lock_nested(&pipe->mutex, subclass);
59979 }
59980
59981@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
59982
59983 void pipe_unlock(struct pipe_inode_info *pipe)
59984 {
59985- if (pipe->files)
59986+ if (atomic_read(&pipe->files))
59987 mutex_unlock(&pipe->mutex);
59988 }
59989 EXPORT_SYMBOL(pipe_unlock);
59990@@ -449,9 +449,9 @@ redo:
59991 }
59992 if (bufs) /* More to do? */
59993 continue;
59994- if (!pipe->writers)
59995+ if (!atomic_read(&pipe->writers))
59996 break;
59997- if (!pipe->waiting_writers) {
59998+ if (!atomic_read(&pipe->waiting_writers)) {
59999 /* syscall merging: Usually we must not sleep
60000 * if O_NONBLOCK is set, or if we got some data.
60001 * But if a writer sleeps in kernel space, then
60002@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
60003 ret = 0;
60004 __pipe_lock(pipe);
60005
60006- if (!pipe->readers) {
60007+ if (!atomic_read(&pipe->readers)) {
60008 send_sig(SIGPIPE, current, 0);
60009 ret = -EPIPE;
60010 goto out;
60011@@ -562,7 +562,7 @@ redo1:
60012 for (;;) {
60013 int bufs;
60014
60015- if (!pipe->readers) {
60016+ if (!atomic_read(&pipe->readers)) {
60017 send_sig(SIGPIPE, current, 0);
60018 if (!ret)
60019 ret = -EPIPE;
60020@@ -653,9 +653,9 @@ redo2:
60021 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60022 do_wakeup = 0;
60023 }
60024- pipe->waiting_writers++;
60025+ atomic_inc(&pipe->waiting_writers);
60026 pipe_wait(pipe);
60027- pipe->waiting_writers--;
60028+ atomic_dec(&pipe->waiting_writers);
60029 }
60030 out:
60031 __pipe_unlock(pipe);
60032@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
60033 mask = 0;
60034 if (filp->f_mode & FMODE_READ) {
60035 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
60036- if (!pipe->writers && filp->f_version != pipe->w_counter)
60037+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
60038 mask |= POLLHUP;
60039 }
60040
60041@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
60042 * Most Unices do not set POLLERR for FIFOs but on Linux they
60043 * behave exactly like pipes for poll().
60044 */
60045- if (!pipe->readers)
60046+ if (!atomic_read(&pipe->readers))
60047 mask |= POLLERR;
60048 }
60049
60050@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
60051 int kill = 0;
60052
60053 spin_lock(&inode->i_lock);
60054- if (!--pipe->files) {
60055+ if (atomic_dec_and_test(&pipe->files)) {
60056 inode->i_pipe = NULL;
60057 kill = 1;
60058 }
60059@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
60060
60061 __pipe_lock(pipe);
60062 if (file->f_mode & FMODE_READ)
60063- pipe->readers--;
60064+ atomic_dec(&pipe->readers);
60065 if (file->f_mode & FMODE_WRITE)
60066- pipe->writers--;
60067+ atomic_dec(&pipe->writers);
60068
60069- if (pipe->readers || pipe->writers) {
60070+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
60071 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
60072 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60073 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
60074@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
60075 kfree(pipe);
60076 }
60077
60078-static struct vfsmount *pipe_mnt __read_mostly;
60079+struct vfsmount *pipe_mnt __read_mostly;
60080
60081 /*
60082 * pipefs_dname() is called from d_path().
60083@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
60084 goto fail_iput;
60085
60086 inode->i_pipe = pipe;
60087- pipe->files = 2;
60088- pipe->readers = pipe->writers = 1;
60089+ atomic_set(&pipe->files, 2);
60090+ atomic_set(&pipe->readers, 1);
60091+ atomic_set(&pipe->writers, 1);
60092 inode->i_fop = &pipefifo_fops;
60093
60094 /*
60095@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
60096 spin_lock(&inode->i_lock);
60097 if (inode->i_pipe) {
60098 pipe = inode->i_pipe;
60099- pipe->files++;
60100+ atomic_inc(&pipe->files);
60101 spin_unlock(&inode->i_lock);
60102 } else {
60103 spin_unlock(&inode->i_lock);
60104 pipe = alloc_pipe_info();
60105 if (!pipe)
60106 return -ENOMEM;
60107- pipe->files = 1;
60108+ atomic_set(&pipe->files, 1);
60109 spin_lock(&inode->i_lock);
60110 if (unlikely(inode->i_pipe)) {
60111- inode->i_pipe->files++;
60112+ atomic_inc(&inode->i_pipe->files);
60113 spin_unlock(&inode->i_lock);
60114 free_pipe_info(pipe);
60115 pipe = inode->i_pipe;
60116@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
60117 * opened, even when there is no process writing the FIFO.
60118 */
60119 pipe->r_counter++;
60120- if (pipe->readers++ == 0)
60121+ if (atomic_inc_return(&pipe->readers) == 1)
60122 wake_up_partner(pipe);
60123
60124- if (!is_pipe && !pipe->writers) {
60125+ if (!is_pipe && !atomic_read(&pipe->writers)) {
60126 if ((filp->f_flags & O_NONBLOCK)) {
60127 /* suppress POLLHUP until we have
60128 * seen a writer */
60129@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
60130 * errno=ENXIO when there is no process reading the FIFO.
60131 */
60132 ret = -ENXIO;
60133- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
60134+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
60135 goto err;
60136
60137 pipe->w_counter++;
60138- if (!pipe->writers++)
60139+ if (atomic_inc_return(&pipe->writers) == 1)
60140 wake_up_partner(pipe);
60141
60142- if (!is_pipe && !pipe->readers) {
60143+ if (!is_pipe && !atomic_read(&pipe->readers)) {
60144 if (wait_for_partner(pipe, &pipe->r_counter))
60145 goto err_wr;
60146 }
60147@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
60148 * the process can at least talk to itself.
60149 */
60150
60151- pipe->readers++;
60152- pipe->writers++;
60153+ atomic_inc(&pipe->readers);
60154+ atomic_inc(&pipe->writers);
60155 pipe->r_counter++;
60156 pipe->w_counter++;
60157- if (pipe->readers == 1 || pipe->writers == 1)
60158+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
60159 wake_up_partner(pipe);
60160 break;
60161
60162@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
60163 return 0;
60164
60165 err_rd:
60166- if (!--pipe->readers)
60167+ if (atomic_dec_and_test(&pipe->readers))
60168 wake_up_interruptible(&pipe->wait);
60169 ret = -ERESTARTSYS;
60170 goto err;
60171
60172 err_wr:
60173- if (!--pipe->writers)
60174+ if (atomic_dec_and_test(&pipe->writers))
60175 wake_up_interruptible(&pipe->wait);
60176 ret = -ERESTARTSYS;
60177 goto err;
60178diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
60179index 15af622..0e9f4467 100644
60180--- a/fs/proc/Kconfig
60181+++ b/fs/proc/Kconfig
60182@@ -30,12 +30,12 @@ config PROC_FS
60183
60184 config PROC_KCORE
60185 bool "/proc/kcore support" if !ARM
60186- depends on PROC_FS && MMU
60187+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
60188
60189 config PROC_VMCORE
60190 bool "/proc/vmcore support"
60191- depends on PROC_FS && CRASH_DUMP
60192- default y
60193+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
60194+ default n
60195 help
60196 Exports the dump image of crashed kernel in ELF format.
60197
60198@@ -59,8 +59,8 @@ config PROC_SYSCTL
60199 limited in memory.
60200
60201 config PROC_PAGE_MONITOR
60202- default y
60203- depends on PROC_FS && MMU
60204+ default n
60205+ depends on PROC_FS && MMU && !GRKERNSEC
60206 bool "Enable /proc page monitoring" if EXPERT
60207 help
60208 Various /proc files exist to monitor process memory utilization:
60209diff --git a/fs/proc/array.c b/fs/proc/array.c
60210index cbd0f1b..adec3f0 100644
60211--- a/fs/proc/array.c
60212+++ b/fs/proc/array.c
60213@@ -60,6 +60,7 @@
60214 #include <linux/tty.h>
60215 #include <linux/string.h>
60216 #include <linux/mman.h>
60217+#include <linux/grsecurity.h>
60218 #include <linux/proc_fs.h>
60219 #include <linux/ioport.h>
60220 #include <linux/uaccess.h>
60221@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
60222 seq_putc(m, '\n');
60223 }
60224
60225+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60226+static inline void task_pax(struct seq_file *m, struct task_struct *p)
60227+{
60228+ if (p->mm)
60229+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
60230+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
60231+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
60232+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
60233+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
60234+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
60235+ else
60236+ seq_printf(m, "PaX:\t-----\n");
60237+}
60238+#endif
60239+
60240 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60241 struct pid *pid, struct task_struct *task)
60242 {
60243@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60244 task_cpus_allowed(m, task);
60245 cpuset_task_status_allowed(m, task);
60246 task_context_switch_counts(m, task);
60247+
60248+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60249+ task_pax(m, task);
60250+#endif
60251+
60252+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
60253+ task_grsec_rbac(m, task);
60254+#endif
60255+
60256 return 0;
60257 }
60258
60259+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60260+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60261+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60262+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60263+#endif
60264+
60265 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60266 struct pid *pid, struct task_struct *task, int whole)
60267 {
60268@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60269 char tcomm[sizeof(task->comm)];
60270 unsigned long flags;
60271
60272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60273+ if (current->exec_id != m->exec_id) {
60274+ gr_log_badprocpid("stat");
60275+ return 0;
60276+ }
60277+#endif
60278+
60279 state = *get_task_state(task);
60280 vsize = eip = esp = 0;
60281 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60282@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60283 gtime = task_gtime(task);
60284 }
60285
60286+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60287+ if (PAX_RAND_FLAGS(mm)) {
60288+ eip = 0;
60289+ esp = 0;
60290+ wchan = 0;
60291+ }
60292+#endif
60293+#ifdef CONFIG_GRKERNSEC_HIDESYM
60294+ wchan = 0;
60295+ eip =0;
60296+ esp =0;
60297+#endif
60298+
60299 /* scale priority and nice values from timeslices to -20..20 */
60300 /* to make it look like a "normal" Unix priority/nice value */
60301 priority = task_prio(task);
60302@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60303 seq_put_decimal_ull(m, ' ', vsize);
60304 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
60305 seq_put_decimal_ull(m, ' ', rsslim);
60306+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60307+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
60308+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
60309+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
60310+#else
60311 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
60312 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
60313 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
60314+#endif
60315 seq_put_decimal_ull(m, ' ', esp);
60316 seq_put_decimal_ull(m, ' ', eip);
60317 /* The signal information here is obsolete.
60318@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60319 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
60320 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
60321
60322- if (mm && permitted) {
60323+ if (mm && permitted
60324+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60325+ && !PAX_RAND_FLAGS(mm)
60326+#endif
60327+ ) {
60328 seq_put_decimal_ull(m, ' ', mm->start_data);
60329 seq_put_decimal_ull(m, ' ', mm->end_data);
60330 seq_put_decimal_ull(m, ' ', mm->start_brk);
60331@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60332 struct pid *pid, struct task_struct *task)
60333 {
60334 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
60335- struct mm_struct *mm = get_task_mm(task);
60336+ struct mm_struct *mm;
60337
60338+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60339+ if (current->exec_id != m->exec_id) {
60340+ gr_log_badprocpid("statm");
60341+ return 0;
60342+ }
60343+#endif
60344+ mm = get_task_mm(task);
60345 if (mm) {
60346 size = task_statm(mm, &shared, &text, &data, &resident);
60347 mmput(mm);
60348@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60349 return 0;
60350 }
60351
60352+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60353+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
60354+{
60355+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
60356+}
60357+#endif
60358+
60359 #ifdef CONFIG_CHECKPOINT_RESTORE
60360 static struct pid *
60361 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
60362diff --git a/fs/proc/base.c b/fs/proc/base.c
60363index 1485e38..8ad4236 100644
60364--- a/fs/proc/base.c
60365+++ b/fs/proc/base.c
60366@@ -113,6 +113,14 @@ struct pid_entry {
60367 union proc_op op;
60368 };
60369
60370+struct getdents_callback {
60371+ struct linux_dirent __user * current_dir;
60372+ struct linux_dirent __user * previous;
60373+ struct file * file;
60374+ int count;
60375+ int error;
60376+};
60377+
60378 #define NOD(NAME, MODE, IOP, FOP, OP) { \
60379 .name = (NAME), \
60380 .len = sizeof(NAME) - 1, \
60381@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
60382 if (!mm->arg_end)
60383 goto out_mm; /* Shh! No looking before we're done */
60384
60385+ if (gr_acl_handle_procpidmem(task))
60386+ goto out_mm;
60387+
60388 len = mm->arg_end - mm->arg_start;
60389
60390 if (len > PAGE_SIZE)
60391@@ -237,12 +248,28 @@ out:
60392 return res;
60393 }
60394
60395+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60396+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60397+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60398+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60399+#endif
60400+
60401 static int proc_pid_auxv(struct task_struct *task, char *buffer)
60402 {
60403 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
60404 int res = PTR_ERR(mm);
60405 if (mm && !IS_ERR(mm)) {
60406 unsigned int nwords = 0;
60407+
60408+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60409+ /* allow if we're currently ptracing this task */
60410+ if (PAX_RAND_FLAGS(mm) &&
60411+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
60412+ mmput(mm);
60413+ return 0;
60414+ }
60415+#endif
60416+
60417 do {
60418 nwords += 2;
60419 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
60420@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
60421 }
60422
60423
60424-#ifdef CONFIG_KALLSYMS
60425+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60426 /*
60427 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
60428 * Returns the resolved symbol. If that fails, simply return the address.
60429@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
60430 mutex_unlock(&task->signal->cred_guard_mutex);
60431 }
60432
60433-#ifdef CONFIG_STACKTRACE
60434+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60435
60436 #define MAX_STACK_TRACE_DEPTH 64
60437
60438@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
60439 return count;
60440 }
60441
60442-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60443+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60444 static int proc_pid_syscall(struct task_struct *task, char *buffer)
60445 {
60446 long nr;
60447@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
60448 /************************************************************************/
60449
60450 /* permission checks */
60451-static int proc_fd_access_allowed(struct inode *inode)
60452+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
60453 {
60454 struct task_struct *task;
60455 int allowed = 0;
60456@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
60457 */
60458 task = get_proc_task(inode);
60459 if (task) {
60460- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60461+ if (log)
60462+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60463+ else
60464+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60465 put_task_struct(task);
60466 }
60467 return allowed;
60468@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
60469 struct task_struct *task,
60470 int hide_pid_min)
60471 {
60472+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60473+ return false;
60474+
60475+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60476+ rcu_read_lock();
60477+ {
60478+ const struct cred *tmpcred = current_cred();
60479+ const struct cred *cred = __task_cred(task);
60480+
60481+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
60482+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60483+ || in_group_p(grsec_proc_gid)
60484+#endif
60485+ ) {
60486+ rcu_read_unlock();
60487+ return true;
60488+ }
60489+ }
60490+ rcu_read_unlock();
60491+
60492+ if (!pid->hide_pid)
60493+ return false;
60494+#endif
60495+
60496 if (pid->hide_pid < hide_pid_min)
60497 return true;
60498 if (in_group_p(pid->pid_gid))
60499 return true;
60500+
60501 return ptrace_may_access(task, PTRACE_MODE_READ);
60502 }
60503
60504@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
60505 put_task_struct(task);
60506
60507 if (!has_perms) {
60508+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60509+ {
60510+#else
60511 if (pid->hide_pid == 2) {
60512+#endif
60513 /*
60514 * Let's make getdents(), stat(), and open()
60515 * consistent with each other. If a process
60516@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60517 if (!task)
60518 return -ESRCH;
60519
60520+ if (gr_acl_handle_procpidmem(task)) {
60521+ put_task_struct(task);
60522+ return -EPERM;
60523+ }
60524+
60525 mm = mm_access(task, mode);
60526 put_task_struct(task);
60527
60528@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60529
60530 file->private_data = mm;
60531
60532+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60533+ file->f_version = current->exec_id;
60534+#endif
60535+
60536 return 0;
60537 }
60538
60539@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60540 ssize_t copied;
60541 char *page;
60542
60543+#ifdef CONFIG_GRKERNSEC
60544+ if (write)
60545+ return -EPERM;
60546+#endif
60547+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60548+ if (file->f_version != current->exec_id) {
60549+ gr_log_badprocpid("mem");
60550+ return 0;
60551+ }
60552+#endif
60553+
60554 if (!mm)
60555 return 0;
60556
60557@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60558 goto free;
60559
60560 while (count > 0) {
60561- int this_len = min_t(int, count, PAGE_SIZE);
60562+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
60563
60564 if (write && copy_from_user(page, buf, this_len)) {
60565 copied = -EFAULT;
60566@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60567 if (!mm)
60568 return 0;
60569
60570+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60571+ if (file->f_version != current->exec_id) {
60572+ gr_log_badprocpid("environ");
60573+ return 0;
60574+ }
60575+#endif
60576+
60577 page = (char *)__get_free_page(GFP_TEMPORARY);
60578 if (!page)
60579 return -ENOMEM;
60580@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60581 goto free;
60582 while (count > 0) {
60583 size_t this_len, max_len;
60584- int retval;
60585+ ssize_t retval;
60586
60587 if (src >= (mm->env_end - mm->env_start))
60588 break;
60589@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
60590 int error = -EACCES;
60591
60592 /* Are we allowed to snoop on the tasks file descriptors? */
60593- if (!proc_fd_access_allowed(inode))
60594+ if (!proc_fd_access_allowed(inode, 0))
60595 goto out;
60596
60597 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60598@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
60599 struct path path;
60600
60601 /* Are we allowed to snoop on the tasks file descriptors? */
60602- if (!proc_fd_access_allowed(inode))
60603- goto out;
60604+ /* logging this is needed for learning on chromium to work properly,
60605+ but we don't want to flood the logs from 'ps' which does a readlink
60606+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
60607+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
60608+ */
60609+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
60610+ if (!proc_fd_access_allowed(inode,0))
60611+ goto out;
60612+ } else {
60613+ if (!proc_fd_access_allowed(inode,1))
60614+ goto out;
60615+ }
60616
60617 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60618 if (error)
60619@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
60620 rcu_read_lock();
60621 cred = __task_cred(task);
60622 inode->i_uid = cred->euid;
60623+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60624+ inode->i_gid = grsec_proc_gid;
60625+#else
60626 inode->i_gid = cred->egid;
60627+#endif
60628 rcu_read_unlock();
60629 }
60630 security_task_to_inode(task, inode);
60631@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
60632 return -ENOENT;
60633 }
60634 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60635+#ifdef CONFIG_GRKERNSEC_PROC_USER
60636+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60637+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60638+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60639+#endif
60640 task_dumpable(task)) {
60641 cred = __task_cred(task);
60642 stat->uid = cred->euid;
60643+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60644+ stat->gid = grsec_proc_gid;
60645+#else
60646 stat->gid = cred->egid;
60647+#endif
60648 }
60649 }
60650 rcu_read_unlock();
60651@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
60652
60653 if (task) {
60654 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60655+#ifdef CONFIG_GRKERNSEC_PROC_USER
60656+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60657+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60658+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60659+#endif
60660 task_dumpable(task)) {
60661 rcu_read_lock();
60662 cred = __task_cred(task);
60663 inode->i_uid = cred->euid;
60664+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60665+ inode->i_gid = grsec_proc_gid;
60666+#else
60667 inode->i_gid = cred->egid;
60668+#endif
60669 rcu_read_unlock();
60670 } else {
60671 inode->i_uid = GLOBAL_ROOT_UID;
60672@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
60673 if (!task)
60674 goto out_no_task;
60675
60676+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60677+ goto out;
60678+
60679 /*
60680 * Yes, it does not scale. And it should not. Don't add
60681 * new entries into /proc/<tgid>/ without very good reasons.
60682@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
60683 if (!task)
60684 return -ENOENT;
60685
60686+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60687+ goto out;
60688+
60689 if (!dir_emit_dots(file, ctx))
60690 goto out;
60691
60692@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
60693 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
60694 #endif
60695 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60696-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60697+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60698 INF("syscall", S_IRUGO, proc_pid_syscall),
60699 #endif
60700 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60701@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
60702 #ifdef CONFIG_SECURITY
60703 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60704 #endif
60705-#ifdef CONFIG_KALLSYMS
60706+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60707 INF("wchan", S_IRUGO, proc_pid_wchan),
60708 #endif
60709-#ifdef CONFIG_STACKTRACE
60710+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60711 ONE("stack", S_IRUGO, proc_pid_stack),
60712 #endif
60713 #ifdef CONFIG_SCHEDSTATS
60714@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
60715 #ifdef CONFIG_HARDWALL
60716 INF("hardwall", S_IRUGO, proc_pid_hardwall),
60717 #endif
60718+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60719+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
60720+#endif
60721 #ifdef CONFIG_USER_NS
60722 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
60723 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
60724@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
60725 if (!inode)
60726 goto out;
60727
60728+#ifdef CONFIG_GRKERNSEC_PROC_USER
60729+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
60730+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60731+ inode->i_gid = grsec_proc_gid;
60732+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
60733+#else
60734 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
60735+#endif
60736 inode->i_op = &proc_tgid_base_inode_operations;
60737 inode->i_fop = &proc_tgid_base_operations;
60738 inode->i_flags|=S_IMMUTABLE;
60739@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
60740 if (!task)
60741 goto out;
60742
60743+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60744+ goto out_put_task;
60745+
60746 result = proc_pid_instantiate(dir, dentry, task, NULL);
60747+out_put_task:
60748 put_task_struct(task);
60749 out:
60750 return ERR_PTR(result);
60751@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
60752 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
60753 #endif
60754 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60755-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60756+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60757 INF("syscall", S_IRUGO, proc_pid_syscall),
60758 #endif
60759 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60760@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
60761 #ifdef CONFIG_SECURITY
60762 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60763 #endif
60764-#ifdef CONFIG_KALLSYMS
60765+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60766 INF("wchan", S_IRUGO, proc_pid_wchan),
60767 #endif
60768-#ifdef CONFIG_STACKTRACE
60769+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60770 ONE("stack", S_IRUGO, proc_pid_stack),
60771 #endif
60772 #ifdef CONFIG_SCHEDSTATS
60773diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
60774index 82676e3..5f8518a 100644
60775--- a/fs/proc/cmdline.c
60776+++ b/fs/proc/cmdline.c
60777@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
60778
60779 static int __init proc_cmdline_init(void)
60780 {
60781+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60782+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
60783+#else
60784 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
60785+#endif
60786 return 0;
60787 }
60788 module_init(proc_cmdline_init);
60789diff --git a/fs/proc/devices.c b/fs/proc/devices.c
60790index b143471..bb105e5 100644
60791--- a/fs/proc/devices.c
60792+++ b/fs/proc/devices.c
60793@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
60794
60795 static int __init proc_devices_init(void)
60796 {
60797+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60798+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
60799+#else
60800 proc_create("devices", 0, NULL, &proc_devinfo_operations);
60801+#endif
60802 return 0;
60803 }
60804 module_init(proc_devices_init);
60805diff --git a/fs/proc/fd.c b/fs/proc/fd.c
60806index 985ea88..d118a0a 100644
60807--- a/fs/proc/fd.c
60808+++ b/fs/proc/fd.c
60809@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
60810 if (!task)
60811 return -ENOENT;
60812
60813- files = get_files_struct(task);
60814+ if (!gr_acl_handle_procpidmem(task))
60815+ files = get_files_struct(task);
60816 put_task_struct(task);
60817
60818 if (files) {
60819@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
60820 */
60821 int proc_fd_permission(struct inode *inode, int mask)
60822 {
60823+ struct task_struct *task;
60824 int rv = generic_permission(inode, mask);
60825- if (rv == 0)
60826- return 0;
60827+
60828 if (task_tgid(current) == proc_pid(inode))
60829 rv = 0;
60830+
60831+ task = get_proc_task(inode);
60832+ if (task == NULL)
60833+ return rv;
60834+
60835+ if (gr_acl_handle_procpidmem(task))
60836+ rv = -EACCES;
60837+
60838+ put_task_struct(task);
60839+
60840 return rv;
60841 }
60842
60843diff --git a/fs/proc/inode.c b/fs/proc/inode.c
60844index 8eaa1ba..cc6ff42 100644
60845--- a/fs/proc/inode.c
60846+++ b/fs/proc/inode.c
60847@@ -23,11 +23,17 @@
60848 #include <linux/slab.h>
60849 #include <linux/mount.h>
60850 #include <linux/magic.h>
60851+#include <linux/grsecurity.h>
60852
60853 #include <asm/uaccess.h>
60854
60855 #include "internal.h"
60856
60857+#ifdef CONFIG_PROC_SYSCTL
60858+extern const struct inode_operations proc_sys_inode_operations;
60859+extern const struct inode_operations proc_sys_dir_operations;
60860+#endif
60861+
60862 static void proc_evict_inode(struct inode *inode)
60863 {
60864 struct proc_dir_entry *de;
60865@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
60866 ns = PROC_I(inode)->ns.ns;
60867 if (ns_ops && ns)
60868 ns_ops->put(ns);
60869+
60870+#ifdef CONFIG_PROC_SYSCTL
60871+ if (inode->i_op == &proc_sys_inode_operations ||
60872+ inode->i_op == &proc_sys_dir_operations)
60873+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
60874+#endif
60875+
60876 }
60877
60878 static struct kmem_cache * proc_inode_cachep;
60879@@ -405,7 +418,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
60880 if (de->mode) {
60881 inode->i_mode = de->mode;
60882 inode->i_uid = de->uid;
60883+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60884+ inode->i_gid = grsec_proc_gid;
60885+#else
60886 inode->i_gid = de->gid;
60887+#endif
60888 }
60889 if (de->size)
60890 inode->i_size = de->size;
60891diff --git a/fs/proc/internal.h b/fs/proc/internal.h
60892index 651d09a..60c73ae 100644
60893--- a/fs/proc/internal.h
60894+++ b/fs/proc/internal.h
60895@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
60896 struct pid *, struct task_struct *);
60897 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
60898 struct pid *, struct task_struct *);
60899+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60900+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
60901+#endif
60902
60903 /*
60904 * base.c
60905diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
60906index 05029c0..7ea1987 100644
60907--- a/fs/proc/interrupts.c
60908+++ b/fs/proc/interrupts.c
60909@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
60910
60911 static int __init proc_interrupts_init(void)
60912 {
60913+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60914+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
60915+#else
60916 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
60917+#endif
60918 return 0;
60919 }
60920 module_init(proc_interrupts_init);
60921diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
60922index 06ea155..9a798c7 100644
60923--- a/fs/proc/kcore.c
60924+++ b/fs/proc/kcore.c
60925@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60926 * the addresses in the elf_phdr on our list.
60927 */
60928 start = kc_offset_to_vaddr(*fpos - elf_buflen);
60929- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
60930+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
60931+ if (tsz > buflen)
60932 tsz = buflen;
60933-
60934+
60935 while (buflen) {
60936 struct kcore_list *m;
60937
60938@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60939 kfree(elf_buf);
60940 } else {
60941 if (kern_addr_valid(start)) {
60942- unsigned long n;
60943+ char *elf_buf;
60944+ mm_segment_t oldfs;
60945
60946- n = copy_to_user(buffer, (char *)start, tsz);
60947- /*
60948- * We cannot distinguish between fault on source
60949- * and fault on destination. When this happens
60950- * we clear too and hope it will trigger the
60951- * EFAULT again.
60952- */
60953- if (n) {
60954- if (clear_user(buffer + tsz - n,
60955- n))
60956+ elf_buf = kmalloc(tsz, GFP_KERNEL);
60957+ if (!elf_buf)
60958+ return -ENOMEM;
60959+ oldfs = get_fs();
60960+ set_fs(KERNEL_DS);
60961+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
60962+ set_fs(oldfs);
60963+ if (copy_to_user(buffer, elf_buf, tsz)) {
60964+ kfree(elf_buf);
60965 return -EFAULT;
60966+ }
60967 }
60968+ set_fs(oldfs);
60969+ kfree(elf_buf);
60970 } else {
60971 if (clear_user(buffer, tsz))
60972 return -EFAULT;
60973@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60974
60975 static int open_kcore(struct inode *inode, struct file *filp)
60976 {
60977+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
60978+ return -EPERM;
60979+#endif
60980 if (!capable(CAP_SYS_RAWIO))
60981 return -EPERM;
60982 if (kcore_need_update)
60983diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
60984index 59d85d6..ac6fc05 100644
60985--- a/fs/proc/meminfo.c
60986+++ b/fs/proc/meminfo.c
60987@@ -153,7 +153,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
60988 vmi.used >> 10,
60989 vmi.largest_chunk >> 10
60990 #ifdef CONFIG_MEMORY_FAILURE
60991- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60992+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60993 #endif
60994 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
60995 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
60996diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
60997index ccfd99b..1b7e255 100644
60998--- a/fs/proc/nommu.c
60999+++ b/fs/proc/nommu.c
61000@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
61001 if (len < 1)
61002 len = 1;
61003 seq_printf(m, "%*c", len, ' ');
61004- seq_path(m, &file->f_path, "");
61005+ seq_path(m, &file->f_path, "\n\\");
61006 }
61007
61008 seq_putc(m, '\n');
61009diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
61010index 4677bb7..408e936 100644
61011--- a/fs/proc/proc_net.c
61012+++ b/fs/proc/proc_net.c
61013@@ -23,6 +23,7 @@
61014 #include <linux/nsproxy.h>
61015 #include <net/net_namespace.h>
61016 #include <linux/seq_file.h>
61017+#include <linux/grsecurity.h>
61018
61019 #include "internal.h"
61020
61021@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
61022 struct task_struct *task;
61023 struct nsproxy *ns;
61024 struct net *net = NULL;
61025+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61026+ const struct cred *cred = current_cred();
61027+#endif
61028+
61029+#ifdef CONFIG_GRKERNSEC_PROC_USER
61030+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
61031+ return net;
61032+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61033+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
61034+ return net;
61035+#endif
61036
61037 rcu_read_lock();
61038 task = pid_task(proc_pid(dir), PIDTYPE_PID);
61039diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
61040index 7129046..6914844 100644
61041--- a/fs/proc/proc_sysctl.c
61042+++ b/fs/proc/proc_sysctl.c
61043@@ -11,13 +11,21 @@
61044 #include <linux/namei.h>
61045 #include <linux/mm.h>
61046 #include <linux/module.h>
61047+#include <linux/nsproxy.h>
61048+#ifdef CONFIG_GRKERNSEC
61049+#include <net/net_namespace.h>
61050+#endif
61051 #include "internal.h"
61052
61053+extern int gr_handle_chroot_sysctl(const int op);
61054+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
61055+ const int op);
61056+
61057 static const struct dentry_operations proc_sys_dentry_operations;
61058 static const struct file_operations proc_sys_file_operations;
61059-static const struct inode_operations proc_sys_inode_operations;
61060+const struct inode_operations proc_sys_inode_operations;
61061 static const struct file_operations proc_sys_dir_file_operations;
61062-static const struct inode_operations proc_sys_dir_operations;
61063+const struct inode_operations proc_sys_dir_operations;
61064
61065 void proc_sys_poll_notify(struct ctl_table_poll *poll)
61066 {
61067@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
61068
61069 err = NULL;
61070 d_set_d_op(dentry, &proc_sys_dentry_operations);
61071+
61072+ gr_handle_proc_create(dentry, inode);
61073+
61074 d_add(dentry, inode);
61075
61076 out:
61077@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61078 struct inode *inode = file_inode(filp);
61079 struct ctl_table_header *head = grab_header(inode);
61080 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
61081+ int op = write ? MAY_WRITE : MAY_READ;
61082 ssize_t error;
61083 size_t res;
61084
61085@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61086 * and won't be until we finish.
61087 */
61088 error = -EPERM;
61089- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
61090+ if (sysctl_perm(head, table, op))
61091 goto out;
61092
61093 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
61094@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61095 if (!table->proc_handler)
61096 goto out;
61097
61098+#ifdef CONFIG_GRKERNSEC
61099+ error = -EPERM;
61100+ if (gr_handle_chroot_sysctl(op))
61101+ goto out;
61102+ dget(filp->f_path.dentry);
61103+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
61104+ dput(filp->f_path.dentry);
61105+ goto out;
61106+ }
61107+ dput(filp->f_path.dentry);
61108+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
61109+ goto out;
61110+ if (write) {
61111+ if (current->nsproxy->net_ns != table->extra2) {
61112+ if (!capable(CAP_SYS_ADMIN))
61113+ goto out;
61114+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
61115+ goto out;
61116+ }
61117+#endif
61118+
61119 /* careful: calling conventions are nasty here */
61120 res = count;
61121 error = table->proc_handler(table, write, buf, &res, ppos);
61122@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
61123 return false;
61124 } else {
61125 d_set_d_op(child, &proc_sys_dentry_operations);
61126+
61127+ gr_handle_proc_create(child, inode);
61128+
61129 d_add(child, inode);
61130 }
61131 } else {
61132@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
61133 if ((*pos)++ < ctx->pos)
61134 return true;
61135
61136+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
61137+ return 0;
61138+
61139 if (unlikely(S_ISLNK(table->mode)))
61140 res = proc_sys_link_fill_cache(file, ctx, head, table);
61141 else
61142@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
61143 if (IS_ERR(head))
61144 return PTR_ERR(head);
61145
61146+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
61147+ return -ENOENT;
61148+
61149 generic_fillattr(inode, stat);
61150 if (table)
61151 stat->mode = (stat->mode & S_IFMT) | table->mode;
61152@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
61153 .llseek = generic_file_llseek,
61154 };
61155
61156-static const struct inode_operations proc_sys_inode_operations = {
61157+const struct inode_operations proc_sys_inode_operations = {
61158 .permission = proc_sys_permission,
61159 .setattr = proc_sys_setattr,
61160 .getattr = proc_sys_getattr,
61161 };
61162
61163-static const struct inode_operations proc_sys_dir_operations = {
61164+const struct inode_operations proc_sys_dir_operations = {
61165 .lookup = proc_sys_lookup,
61166 .permission = proc_sys_permission,
61167 .setattr = proc_sys_setattr,
61168@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
61169 static struct ctl_dir *new_dir(struct ctl_table_set *set,
61170 const char *name, int namelen)
61171 {
61172- struct ctl_table *table;
61173+ ctl_table_no_const *table;
61174 struct ctl_dir *new;
61175 struct ctl_node *node;
61176 char *new_name;
61177@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
61178 return NULL;
61179
61180 node = (struct ctl_node *)(new + 1);
61181- table = (struct ctl_table *)(node + 1);
61182+ table = (ctl_table_no_const *)(node + 1);
61183 new_name = (char *)(table + 2);
61184 memcpy(new_name, name, namelen);
61185 new_name[namelen] = '\0';
61186@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
61187 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
61188 struct ctl_table_root *link_root)
61189 {
61190- struct ctl_table *link_table, *entry, *link;
61191+ ctl_table_no_const *link_table, *link;
61192+ struct ctl_table *entry;
61193 struct ctl_table_header *links;
61194 struct ctl_node *node;
61195 char *link_name;
61196@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
61197 return NULL;
61198
61199 node = (struct ctl_node *)(links + 1);
61200- link_table = (struct ctl_table *)(node + nr_entries);
61201+ link_table = (ctl_table_no_const *)(node + nr_entries);
61202 link_name = (char *)&link_table[nr_entries + 1];
61203
61204 for (link = link_table, entry = table; entry->procname; link++, entry++) {
61205@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61206 struct ctl_table_header ***subheader, struct ctl_table_set *set,
61207 struct ctl_table *table)
61208 {
61209- struct ctl_table *ctl_table_arg = NULL;
61210- struct ctl_table *entry, *files;
61211+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
61212+ struct ctl_table *entry;
61213 int nr_files = 0;
61214 int nr_dirs = 0;
61215 int err = -ENOMEM;
61216@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61217 nr_files++;
61218 }
61219
61220- files = table;
61221 /* If there are mixed files and directories we need a new table */
61222 if (nr_dirs && nr_files) {
61223- struct ctl_table *new;
61224+ ctl_table_no_const *new;
61225 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
61226 GFP_KERNEL);
61227 if (!files)
61228@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61229 /* Register everything except a directory full of subdirectories */
61230 if (nr_files || !nr_dirs) {
61231 struct ctl_table_header *header;
61232- header = __register_sysctl_table(set, path, files);
61233+ header = __register_sysctl_table(set, path, files ? files : table);
61234 if (!header) {
61235 kfree(ctl_table_arg);
61236 goto out;
61237diff --git a/fs/proc/root.c b/fs/proc/root.c
61238index 87dbcbe..55e1b4d 100644
61239--- a/fs/proc/root.c
61240+++ b/fs/proc/root.c
61241@@ -186,7 +186,15 @@ void __init proc_root_init(void)
61242 #ifdef CONFIG_PROC_DEVICETREE
61243 proc_device_tree_init();
61244 #endif
61245+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61246+#ifdef CONFIG_GRKERNSEC_PROC_USER
61247+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
61248+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61249+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
61250+#endif
61251+#else
61252 proc_mkdir("bus", NULL);
61253+#endif
61254 proc_sys_init();
61255 }
61256
61257diff --git a/fs/proc/self.c b/fs/proc/self.c
61258index 6b6a993..807cccc 100644
61259--- a/fs/proc/self.c
61260+++ b/fs/proc/self.c
61261@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
61262 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
61263 void *cookie)
61264 {
61265- char *s = nd_get_link(nd);
61266+ const char *s = nd_get_link(nd);
61267 if (!IS_ERR(s))
61268 kfree(s);
61269 }
61270diff --git a/fs/proc/stat.c b/fs/proc/stat.c
61271index 1cf86c0..f61473c 100644
61272--- a/fs/proc/stat.c
61273+++ b/fs/proc/stat.c
61274@@ -11,6 +11,7 @@
61275 #include <linux/irqnr.h>
61276 #include <asm/cputime.h>
61277 #include <linux/tick.h>
61278+#include <linux/grsecurity.h>
61279
61280 #ifndef arch_irq_stat_cpu
61281 #define arch_irq_stat_cpu(cpu) 0
61282@@ -87,13 +88,28 @@ static int show_stat(struct seq_file *p, void *v)
61283 u64 sum_softirq = 0;
61284 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
61285 struct timespec boottime;
61286+ int unrestricted = 1;
61287+
61288+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61289+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61290+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
61291+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
61292+ && !in_group_p(grsec_proc_gid)
61293+#endif
61294+ )
61295+ unrestricted = 0;
61296+#endif
61297+#endif
61298
61299 user = nice = system = idle = iowait =
61300 irq = softirq = steal = 0;
61301 guest = guest_nice = 0;
61302 getboottime(&boottime);
61303 jif = boottime.tv_sec;
61304+ if (!unrestricted)
61305+ jif = 0;
61306
61307+ if (unrestricted) {
61308 for_each_possible_cpu(i) {
61309 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
61310 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
61311@@ -116,6 +132,7 @@ static int show_stat(struct seq_file *p, void *v)
61312 }
61313 }
61314 sum += arch_irq_stat();
61315+ }
61316
61317 seq_puts(p, "cpu ");
61318 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
61319@@ -131,6 +148,7 @@ static int show_stat(struct seq_file *p, void *v)
61320 seq_putc(p, '\n');
61321
61322 for_each_online_cpu(i) {
61323+ if (unrestricted) {
61324 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
61325 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
61326 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
61327@@ -142,6 +160,7 @@ static int show_stat(struct seq_file *p, void *v)
61328 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
61329 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
61330 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
61331+ }
61332 seq_printf(p, "cpu%d", i);
61333 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
61334 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
61335@@ -159,7 +178,7 @@ static int show_stat(struct seq_file *p, void *v)
61336
61337 /* sum again ? it could be updated? */
61338 for_each_irq_nr(j)
61339- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
61340+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
61341
61342 seq_printf(p,
61343 "\nctxt %llu\n"
61344@@ -167,11 +186,11 @@ static int show_stat(struct seq_file *p, void *v)
61345 "processes %lu\n"
61346 "procs_running %lu\n"
61347 "procs_blocked %lu\n",
61348- nr_context_switches(),
61349- (unsigned long)jif,
61350- total_forks,
61351- nr_running(),
61352- nr_iowait());
61353+ unrestricted ? nr_context_switches() : 0ULL,
61354+ unrestricted ? (unsigned long)jif : 0UL,
61355+ unrestricted ? total_forks : 0UL,
61356+ unrestricted ? nr_running() : 0UL,
61357+ unrestricted ? nr_iowait() : 0UL);
61358
61359 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
61360
61361diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
61362index 390bdab..83c1e8a 100644
61363--- a/fs/proc/task_mmu.c
61364+++ b/fs/proc/task_mmu.c
61365@@ -12,12 +12,19 @@
61366 #include <linux/swap.h>
61367 #include <linux/swapops.h>
61368 #include <linux/mmu_notifier.h>
61369+#include <linux/grsecurity.h>
61370
61371 #include <asm/elf.h>
61372 #include <asm/uaccess.h>
61373 #include <asm/tlbflush.h>
61374 #include "internal.h"
61375
61376+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61377+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61378+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61379+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61380+#endif
61381+
61382 void task_mem(struct seq_file *m, struct mm_struct *mm)
61383 {
61384 unsigned long data, text, lib, swap;
61385@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61386 "VmExe:\t%8lu kB\n"
61387 "VmLib:\t%8lu kB\n"
61388 "VmPTE:\t%8lu kB\n"
61389- "VmSwap:\t%8lu kB\n",
61390- hiwater_vm << (PAGE_SHIFT-10),
61391+ "VmSwap:\t%8lu kB\n"
61392+
61393+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61394+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
61395+#endif
61396+
61397+ ,hiwater_vm << (PAGE_SHIFT-10),
61398 total_vm << (PAGE_SHIFT-10),
61399 mm->locked_vm << (PAGE_SHIFT-10),
61400 mm->pinned_vm << (PAGE_SHIFT-10),
61401@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61402 data << (PAGE_SHIFT-10),
61403 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
61404 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
61405- swap << (PAGE_SHIFT-10));
61406+ swap << (PAGE_SHIFT-10)
61407+
61408+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61409+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61410+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
61411+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
61412+#else
61413+ , mm->context.user_cs_base
61414+ , mm->context.user_cs_limit
61415+#endif
61416+#endif
61417+
61418+ );
61419 }
61420
61421 unsigned long task_vsize(struct mm_struct *mm)
61422@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61423 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
61424 }
61425
61426- /* We don't show the stack guard page in /proc/maps */
61427+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61428+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
61429+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
61430+#else
61431 start = vma->vm_start;
61432- if (stack_guard_page_start(vma, start))
61433- start += PAGE_SIZE;
61434 end = vma->vm_end;
61435- if (stack_guard_page_end(vma, end))
61436- end -= PAGE_SIZE;
61437+#endif
61438
61439 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
61440 start,
61441@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61442 flags & VM_WRITE ? 'w' : '-',
61443 flags & VM_EXEC ? 'x' : '-',
61444 flags & VM_MAYSHARE ? 's' : 'p',
61445+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61446+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
61447+#else
61448 pgoff,
61449+#endif
61450 MAJOR(dev), MINOR(dev), ino, &len);
61451
61452 /*
61453@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61454 */
61455 if (file) {
61456 pad_len_spaces(m, len);
61457- seq_path(m, &file->f_path, "\n");
61458+ seq_path(m, &file->f_path, "\n\\");
61459 goto done;
61460 }
61461
61462@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61463 * Thread stack in /proc/PID/task/TID/maps or
61464 * the main process stack.
61465 */
61466- if (!is_pid || (vma->vm_start <= mm->start_stack &&
61467- vma->vm_end >= mm->start_stack)) {
61468+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
61469+ (vma->vm_start <= mm->start_stack &&
61470+ vma->vm_end >= mm->start_stack)) {
61471 name = "[stack]";
61472 } else {
61473 /* Thread stack in /proc/PID/maps */
61474@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
61475 struct proc_maps_private *priv = m->private;
61476 struct task_struct *task = priv->task;
61477
61478+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61479+ if (current->exec_id != m->exec_id) {
61480+ gr_log_badprocpid("maps");
61481+ return 0;
61482+ }
61483+#endif
61484+
61485 show_map_vma(m, vma, is_pid);
61486
61487 if (m->count < m->size) /* vma is copied successfully */
61488@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61489 .private = &mss,
61490 };
61491
61492+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61493+ if (current->exec_id != m->exec_id) {
61494+ gr_log_badprocpid("smaps");
61495+ return 0;
61496+ }
61497+#endif
61498 memset(&mss, 0, sizeof mss);
61499- mss.vma = vma;
61500- /* mmap_sem is held in m_start */
61501- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61502- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61503-
61504+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61505+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
61506+#endif
61507+ mss.vma = vma;
61508+ /* mmap_sem is held in m_start */
61509+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61510+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61511+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61512+ }
61513+#endif
61514 show_map_vma(m, vma, is_pid);
61515
61516 seq_printf(m,
61517@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61518 "KernelPageSize: %8lu kB\n"
61519 "MMUPageSize: %8lu kB\n"
61520 "Locked: %8lu kB\n",
61521+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61522+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
61523+#else
61524 (vma->vm_end - vma->vm_start) >> 10,
61525+#endif
61526 mss.resident >> 10,
61527 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
61528 mss.shared_clean >> 10,
61529@@ -1390,6 +1441,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61530 int n;
61531 char buffer[50];
61532
61533+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61534+ if (current->exec_id != m->exec_id) {
61535+ gr_log_badprocpid("numa_maps");
61536+ return 0;
61537+ }
61538+#endif
61539+
61540 if (!mm)
61541 return 0;
61542
61543@@ -1409,11 +1467,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61544 if (n < 0)
61545 return n;
61546
61547+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61548+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
61549+#else
61550 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
61551+#endif
61552
61553 if (file) {
61554 seq_printf(m, " file=");
61555- seq_path(m, &file->f_path, "\n\t= ");
61556+ seq_path(m, &file->f_path, "\n\t\\= ");
61557 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
61558 seq_printf(m, " heap");
61559 } else {
61560diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
61561index 56123a6..5a2f6ec 100644
61562--- a/fs/proc/task_nommu.c
61563+++ b/fs/proc/task_nommu.c
61564@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61565 else
61566 bytes += kobjsize(mm);
61567
61568- if (current->fs && current->fs->users > 1)
61569+ if (current->fs && atomic_read(&current->fs->users) > 1)
61570 sbytes += kobjsize(current->fs);
61571 else
61572 bytes += kobjsize(current->fs);
61573@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
61574
61575 if (file) {
61576 pad_len_spaces(m, len);
61577- seq_path(m, &file->f_path, "");
61578+ seq_path(m, &file->f_path, "\n\\");
61579 } else if (mm) {
61580 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
61581
61582diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
61583index 9100d69..f1f9fc9 100644
61584--- a/fs/proc/vmcore.c
61585+++ b/fs/proc/vmcore.c
61586@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
61587 nr_bytes = count;
61588
61589 /* If pfn is not ram, return zeros for sparse dump files */
61590- if (pfn_is_ram(pfn) == 0)
61591- memset(buf, 0, nr_bytes);
61592- else {
61593+ if (pfn_is_ram(pfn) == 0) {
61594+ if (userbuf) {
61595+ if (clear_user((char __force_user *)buf, nr_bytes))
61596+ return -EFAULT;
61597+ } else
61598+ memset(buf, 0, nr_bytes);
61599+ } else {
61600 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
61601 offset, userbuf);
61602 if (tmp < 0)
61603@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
61604 if (*fpos < m->offset + m->size) {
61605 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
61606 start = m->paddr + *fpos - m->offset;
61607- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
61608+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
61609 if (tmp < 0)
61610 return tmp;
61611 buflen -= tsz;
61612diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
61613index b00fcc9..e0c6381 100644
61614--- a/fs/qnx6/qnx6.h
61615+++ b/fs/qnx6/qnx6.h
61616@@ -74,7 +74,7 @@ enum {
61617 BYTESEX_BE,
61618 };
61619
61620-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61621+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61622 {
61623 if (sbi->s_bytesex == BYTESEX_LE)
61624 return le64_to_cpu((__force __le64)n);
61625@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
61626 return (__force __fs64)cpu_to_be64(n);
61627 }
61628
61629-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61630+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61631 {
61632 if (sbi->s_bytesex == BYTESEX_LE)
61633 return le32_to_cpu((__force __le32)n);
61634diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
61635index 16e8abb..2dcf914 100644
61636--- a/fs/quota/netlink.c
61637+++ b/fs/quota/netlink.c
61638@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
61639 void quota_send_warning(struct kqid qid, dev_t dev,
61640 const char warntype)
61641 {
61642- static atomic_t seq;
61643+ static atomic_unchecked_t seq;
61644 struct sk_buff *skb;
61645 void *msg_head;
61646 int ret;
61647@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
61648 "VFS: Not enough memory to send quota warning.\n");
61649 return;
61650 }
61651- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
61652+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
61653 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
61654 if (!msg_head) {
61655 printk(KERN_ERR
61656diff --git a/fs/read_write.c b/fs/read_write.c
61657index e3cd280..a378473 100644
61658--- a/fs/read_write.c
61659+++ b/fs/read_write.c
61660@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
61661
61662 old_fs = get_fs();
61663 set_fs(get_ds());
61664- p = (__force const char __user *)buf;
61665+ p = (const char __force_user *)buf;
61666 if (count > MAX_RW_COUNT)
61667 count = MAX_RW_COUNT;
61668 if (file->f_op->write)
61669diff --git a/fs/readdir.c b/fs/readdir.c
61670index 93d71e5..6a14be8 100644
61671--- a/fs/readdir.c
61672+++ b/fs/readdir.c
61673@@ -17,6 +17,7 @@
61674 #include <linux/security.h>
61675 #include <linux/syscalls.h>
61676 #include <linux/unistd.h>
61677+#include <linux/namei.h>
61678
61679 #include <asm/uaccess.h>
61680
61681@@ -69,6 +70,7 @@ struct old_linux_dirent {
61682 struct readdir_callback {
61683 struct dir_context ctx;
61684 struct old_linux_dirent __user * dirent;
61685+ struct file * file;
61686 int result;
61687 };
61688
61689@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
61690 buf->result = -EOVERFLOW;
61691 return -EOVERFLOW;
61692 }
61693+
61694+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61695+ return 0;
61696+
61697 buf->result++;
61698 dirent = buf->dirent;
61699 if (!access_ok(VERIFY_WRITE, dirent,
61700@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61701 if (!f.file)
61702 return -EBADF;
61703
61704+ buf.file = f.file;
61705 error = iterate_dir(f.file, &buf.ctx);
61706 if (buf.result)
61707 error = buf.result;
61708@@ -142,6 +149,7 @@ struct getdents_callback {
61709 struct dir_context ctx;
61710 struct linux_dirent __user * current_dir;
61711 struct linux_dirent __user * previous;
61712+ struct file * file;
61713 int count;
61714 int error;
61715 };
61716@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
61717 buf->error = -EOVERFLOW;
61718 return -EOVERFLOW;
61719 }
61720+
61721+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61722+ return 0;
61723+
61724 dirent = buf->previous;
61725 if (dirent) {
61726 if (__put_user(offset, &dirent->d_off))
61727@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
61728 if (!f.file)
61729 return -EBADF;
61730
61731+ buf.file = f.file;
61732 error = iterate_dir(f.file, &buf.ctx);
61733 if (error >= 0)
61734 error = buf.error;
61735@@ -226,6 +239,7 @@ struct getdents_callback64 {
61736 struct dir_context ctx;
61737 struct linux_dirent64 __user * current_dir;
61738 struct linux_dirent64 __user * previous;
61739+ struct file *file;
61740 int count;
61741 int error;
61742 };
61743@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
61744 buf->error = -EINVAL; /* only used if we fail.. */
61745 if (reclen > buf->count)
61746 return -EINVAL;
61747+
61748+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61749+ return 0;
61750+
61751 dirent = buf->previous;
61752 if (dirent) {
61753 if (__put_user(offset, &dirent->d_off))
61754@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61755 if (!f.file)
61756 return -EBADF;
61757
61758+ buf.file = f.file;
61759 error = iterate_dir(f.file, &buf.ctx);
61760 if (error >= 0)
61761 error = buf.error;
61762diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
61763index 2b7882b..1c5ef48 100644
61764--- a/fs/reiserfs/do_balan.c
61765+++ b/fs/reiserfs/do_balan.c
61766@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
61767 return;
61768 }
61769
61770- atomic_inc(&(fs_generation(tb->tb_sb)));
61771+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
61772 do_balance_starts(tb);
61773
61774 /* balance leaf returns 0 except if combining L R and S into
61775diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
61776index a958444..42b2323 100644
61777--- a/fs/reiserfs/procfs.c
61778+++ b/fs/reiserfs/procfs.c
61779@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
61780 "SMALL_TAILS " : "NO_TAILS ",
61781 replay_only(sb) ? "REPLAY_ONLY " : "",
61782 convert_reiserfs(sb) ? "CONV " : "",
61783- atomic_read(&r->s_generation_counter),
61784+ atomic_read_unchecked(&r->s_generation_counter),
61785 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
61786 SF(s_do_balance), SF(s_unneeded_left_neighbor),
61787 SF(s_good_search_by_key_reada), SF(s_bmaps),
61788diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
61789index f8adaee..0eeeeca 100644
61790--- a/fs/reiserfs/reiserfs.h
61791+++ b/fs/reiserfs/reiserfs.h
61792@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
61793 /* Comment? -Hans */
61794 wait_queue_head_t s_wait;
61795 /* To be obsoleted soon by per buffer seals.. -Hans */
61796- atomic_t s_generation_counter; // increased by one every time the
61797+ atomic_unchecked_t s_generation_counter; // increased by one every time the
61798 // tree gets re-balanced
61799 unsigned long s_properties; /* File system properties. Currently holds
61800 on-disk FS format */
61801@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61802 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61803
61804 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61805-#define get_generation(s) atomic_read (&fs_generation(s))
61806+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61807 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61808 #define __fs_changed(gen,s) (gen != get_generation (s))
61809 #define fs_changed(gen,s) \
61810diff --git a/fs/select.c b/fs/select.c
61811index dfd5cb1..1754d57 100644
61812--- a/fs/select.c
61813+++ b/fs/select.c
61814@@ -20,6 +20,7 @@
61815 #include <linux/export.h>
61816 #include <linux/slab.h>
61817 #include <linux/poll.h>
61818+#include <linux/security.h>
61819 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
61820 #include <linux/file.h>
61821 #include <linux/fdtable.h>
61822@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
61823 struct poll_list *walk = head;
61824 unsigned long todo = nfds;
61825
61826+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
61827 if (nfds > rlimit(RLIMIT_NOFILE))
61828 return -EINVAL;
61829
61830diff --git a/fs/seq_file.c b/fs/seq_file.c
61831index a290157..ec3211a 100644
61832--- a/fs/seq_file.c
61833+++ b/fs/seq_file.c
61834@@ -10,6 +10,7 @@
61835 #include <linux/seq_file.h>
61836 #include <linux/slab.h>
61837 #include <linux/cred.h>
61838+#include <linux/sched.h>
61839
61840 #include <asm/uaccess.h>
61841 #include <asm/page.h>
61842@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
61843 #ifdef CONFIG_USER_NS
61844 p->user_ns = file->f_cred->user_ns;
61845 #endif
61846+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61847+ p->exec_id = current->exec_id;
61848+#endif
61849
61850 /*
61851 * Wrappers around seq_open(e.g. swaps_open) need to be
61852@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61853 return 0;
61854 }
61855 if (!m->buf) {
61856- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61857+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61858 if (!m->buf)
61859 return -ENOMEM;
61860 }
61861@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61862 Eoverflow:
61863 m->op->stop(m, p);
61864 kfree(m->buf);
61865- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61866+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61867 return !m->buf ? -ENOMEM : -EAGAIN;
61868 }
61869
61870@@ -152,7 +156,7 @@ Eoverflow:
61871 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61872 {
61873 struct seq_file *m = file->private_data;
61874- size_t copied = 0;
61875+ ssize_t copied = 0;
61876 loff_t pos;
61877 size_t n;
61878 void *p;
61879@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61880
61881 /* grab buffer if we didn't have one */
61882 if (!m->buf) {
61883- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61884+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61885 if (!m->buf)
61886 goto Enomem;
61887 }
61888@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61889 goto Fill;
61890 m->op->stop(m, p);
61891 kfree(m->buf);
61892- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61893+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61894 if (!m->buf)
61895 goto Enomem;
61896 m->count = 0;
61897@@ -583,7 +587,7 @@ static void single_stop(struct seq_file *p, void *v)
61898 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
61899 void *data)
61900 {
61901- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
61902+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
61903 int res = -ENOMEM;
61904
61905 if (op) {
61906diff --git a/fs/splice.c b/fs/splice.c
61907index 3b7ee65..87fc2e4 100644
61908--- a/fs/splice.c
61909+++ b/fs/splice.c
61910@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61911 pipe_lock(pipe);
61912
61913 for (;;) {
61914- if (!pipe->readers) {
61915+ if (!atomic_read(&pipe->readers)) {
61916 send_sig(SIGPIPE, current, 0);
61917 if (!ret)
61918 ret = -EPIPE;
61919@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61920 page_nr++;
61921 ret += buf->len;
61922
61923- if (pipe->files)
61924+ if (atomic_read(&pipe->files))
61925 do_wakeup = 1;
61926
61927 if (!--spd->nr_pages)
61928@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61929 do_wakeup = 0;
61930 }
61931
61932- pipe->waiting_writers++;
61933+ atomic_inc(&pipe->waiting_writers);
61934 pipe_wait(pipe);
61935- pipe->waiting_writers--;
61936+ atomic_dec(&pipe->waiting_writers);
61937 }
61938
61939 pipe_unlock(pipe);
61940@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
61941 old_fs = get_fs();
61942 set_fs(get_ds());
61943 /* The cast to a user pointer is valid due to the set_fs() */
61944- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
61945+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
61946 set_fs(old_fs);
61947
61948 return res;
61949@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
61950 old_fs = get_fs();
61951 set_fs(get_ds());
61952 /* The cast to a user pointer is valid due to the set_fs() */
61953- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
61954+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
61955 set_fs(old_fs);
61956
61957 return res;
61958@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
61959 goto err;
61960
61961 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
61962- vec[i].iov_base = (void __user *) page_address(page);
61963+ vec[i].iov_base = (void __force_user *) page_address(page);
61964 vec[i].iov_len = this_len;
61965 spd.pages[i] = page;
61966 spd.nr_pages++;
61967@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
61968 ops->release(pipe, buf);
61969 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
61970 pipe->nrbufs--;
61971- if (pipe->files)
61972+ if (atomic_read(&pipe->files))
61973 sd->need_wakeup = true;
61974 }
61975
61976@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
61977 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
61978 {
61979 while (!pipe->nrbufs) {
61980- if (!pipe->writers)
61981+ if (!atomic_read(&pipe->writers))
61982 return 0;
61983
61984- if (!pipe->waiting_writers && sd->num_spliced)
61985+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
61986 return 0;
61987
61988 if (sd->flags & SPLICE_F_NONBLOCK)
61989@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
61990 * out of the pipe right after the splice_to_pipe(). So set
61991 * PIPE_READERS appropriately.
61992 */
61993- pipe->readers = 1;
61994+ atomic_set(&pipe->readers, 1);
61995
61996 current->splice_pipe = pipe;
61997 }
61998@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
61999
62000 partial[buffers].offset = off;
62001 partial[buffers].len = plen;
62002+ partial[buffers].private = 0;
62003
62004 off = 0;
62005 len -= plen;
62006@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
62007 ret = -ERESTARTSYS;
62008 break;
62009 }
62010- if (!pipe->writers)
62011+ if (!atomic_read(&pipe->writers))
62012 break;
62013- if (!pipe->waiting_writers) {
62014+ if (!atomic_read(&pipe->waiting_writers)) {
62015 if (flags & SPLICE_F_NONBLOCK) {
62016 ret = -EAGAIN;
62017 break;
62018@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
62019 pipe_lock(pipe);
62020
62021 while (pipe->nrbufs >= pipe->buffers) {
62022- if (!pipe->readers) {
62023+ if (!atomic_read(&pipe->readers)) {
62024 send_sig(SIGPIPE, current, 0);
62025 ret = -EPIPE;
62026 break;
62027@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
62028 ret = -ERESTARTSYS;
62029 break;
62030 }
62031- pipe->waiting_writers++;
62032+ atomic_inc(&pipe->waiting_writers);
62033 pipe_wait(pipe);
62034- pipe->waiting_writers--;
62035+ atomic_dec(&pipe->waiting_writers);
62036 }
62037
62038 pipe_unlock(pipe);
62039@@ -1862,14 +1863,14 @@ retry:
62040 pipe_double_lock(ipipe, opipe);
62041
62042 do {
62043- if (!opipe->readers) {
62044+ if (!atomic_read(&opipe->readers)) {
62045 send_sig(SIGPIPE, current, 0);
62046 if (!ret)
62047 ret = -EPIPE;
62048 break;
62049 }
62050
62051- if (!ipipe->nrbufs && !ipipe->writers)
62052+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
62053 break;
62054
62055 /*
62056@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
62057 pipe_double_lock(ipipe, opipe);
62058
62059 do {
62060- if (!opipe->readers) {
62061+ if (!atomic_read(&opipe->readers)) {
62062 send_sig(SIGPIPE, current, 0);
62063 if (!ret)
62064 ret = -EPIPE;
62065@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
62066 * return EAGAIN if we have the potential of some data in the
62067 * future, otherwise just return 0
62068 */
62069- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
62070+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
62071 ret = -EAGAIN;
62072
62073 pipe_unlock(ipipe);
62074diff --git a/fs/stat.c b/fs/stat.c
62075index ae0c3ce..9ee641c 100644
62076--- a/fs/stat.c
62077+++ b/fs/stat.c
62078@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
62079 stat->gid = inode->i_gid;
62080 stat->rdev = inode->i_rdev;
62081 stat->size = i_size_read(inode);
62082- stat->atime = inode->i_atime;
62083- stat->mtime = inode->i_mtime;
62084+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
62085+ stat->atime = inode->i_ctime;
62086+ stat->mtime = inode->i_ctime;
62087+ } else {
62088+ stat->atime = inode->i_atime;
62089+ stat->mtime = inode->i_mtime;
62090+ }
62091 stat->ctime = inode->i_ctime;
62092 stat->blksize = (1 << inode->i_blkbits);
62093 stat->blocks = inode->i_blocks;
62094@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
62095 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
62096 {
62097 struct inode *inode = path->dentry->d_inode;
62098+ int retval;
62099
62100- if (inode->i_op->getattr)
62101- return inode->i_op->getattr(path->mnt, path->dentry, stat);
62102+ if (inode->i_op->getattr) {
62103+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
62104+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
62105+ stat->atime = stat->ctime;
62106+ stat->mtime = stat->ctime;
62107+ }
62108+ return retval;
62109+ }
62110
62111 generic_fillattr(inode, stat);
62112 return 0;
62113diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
62114index c590cab..6dfd6fc 100644
62115--- a/fs/sysfs/bin.c
62116+++ b/fs/sysfs/bin.c
62117@@ -234,13 +234,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
62118 return ret;
62119 }
62120
62121-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
62122- void *buf, int len, int write)
62123+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
62124+ void *buf, size_t len, int write)
62125 {
62126 struct file *file = vma->vm_file;
62127 struct bin_buffer *bb = file->private_data;
62128 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
62129- int ret;
62130+ ssize_t ret;
62131
62132 if (!bb->vm_ops)
62133 return -EINVAL;
62134diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
62135index 4d83ced..049dc45 100644
62136--- a/fs/sysfs/dir.c
62137+++ b/fs/sysfs/dir.c
62138@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
62139 *
62140 * Returns 31 bit hash of ns + name (so it fits in an off_t )
62141 */
62142-static unsigned int sysfs_name_hash(const void *ns, const char *name)
62143+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
62144 {
62145 unsigned long hash = init_name_hash();
62146 unsigned int len = strlen(name);
62147@@ -675,6 +675,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
62148 struct sysfs_dirent *sd;
62149 int rc;
62150
62151+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
62152+ const char *parent_name = parent_sd->s_name;
62153+
62154+ mode = S_IFDIR | S_IRWXU;
62155+
62156+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
62157+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
62158+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
62159+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
62160+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
62161+#endif
62162+
62163 /* allocate */
62164 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
62165 if (!sd)
62166diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
62167index 15ef5eb..e474372 100644
62168--- a/fs/sysfs/file.c
62169+++ b/fs/sysfs/file.c
62170@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
62171
62172 struct sysfs_open_dirent {
62173 atomic_t refcnt;
62174- atomic_t event;
62175+ atomic_unchecked_t event;
62176 wait_queue_head_t poll;
62177 struct list_head buffers; /* goes through sysfs_buffer.list */
62178 };
62179@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
62180 if (!sysfs_get_active(attr_sd))
62181 return -ENODEV;
62182
62183- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
62184+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
62185 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
62186
62187 sysfs_put_active(attr_sd);
62188@@ -284,7 +284,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
62189 return -ENOMEM;
62190
62191 atomic_set(&new_od->refcnt, 0);
62192- atomic_set(&new_od->event, 1);
62193+ atomic_set_unchecked(&new_od->event, 1);
62194 init_waitqueue_head(&new_od->poll);
62195 INIT_LIST_HEAD(&new_od->buffers);
62196 goto retry;
62197@@ -430,7 +430,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
62198
62199 sysfs_put_active(attr_sd);
62200
62201- if (buffer->event != atomic_read(&od->event))
62202+ if (buffer->event != atomic_read_unchecked(&od->event))
62203 goto trigger;
62204
62205 return DEFAULT_POLLMASK;
62206@@ -450,7 +450,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
62207 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
62208 od = sd->s_attr.open;
62209 if (od) {
62210- atomic_inc(&od->event);
62211+ atomic_inc_unchecked(&od->event);
62212 wake_up_interruptible(&od->poll);
62213 }
62214 }
62215diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
62216index 2dd4507..62a215a 100644
62217--- a/fs/sysfs/symlink.c
62218+++ b/fs/sysfs/symlink.c
62219@@ -308,7 +308,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
62220 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
62221 void *cookie)
62222 {
62223- char *page = nd_get_link(nd);
62224+ const char *page = nd_get_link(nd);
62225 if (!IS_ERR(page))
62226 free_page((unsigned long)page);
62227 }
62228diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
62229index 69d4889..a810bd4 100644
62230--- a/fs/sysv/sysv.h
62231+++ b/fs/sysv/sysv.h
62232@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
62233 #endif
62234 }
62235
62236-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62237+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62238 {
62239 if (sbi->s_bytesex == BYTESEX_PDP)
62240 return PDP_swab((__force __u32)n);
62241diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
62242index e18b988..f1d4ad0f 100644
62243--- a/fs/ubifs/io.c
62244+++ b/fs/ubifs/io.c
62245@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
62246 return err;
62247 }
62248
62249-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62250+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62251 {
62252 int err;
62253
62254diff --git a/fs/udf/misc.c b/fs/udf/misc.c
62255index c175b4d..8f36a16 100644
62256--- a/fs/udf/misc.c
62257+++ b/fs/udf/misc.c
62258@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
62259
62260 u8 udf_tag_checksum(const struct tag *t)
62261 {
62262- u8 *data = (u8 *)t;
62263+ const u8 *data = (const u8 *)t;
62264 u8 checksum = 0;
62265 int i;
62266 for (i = 0; i < sizeof(struct tag); ++i)
62267diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
62268index 8d974c4..b82f6ec 100644
62269--- a/fs/ufs/swab.h
62270+++ b/fs/ufs/swab.h
62271@@ -22,7 +22,7 @@ enum {
62272 BYTESEX_BE
62273 };
62274
62275-static inline u64
62276+static inline u64 __intentional_overflow(-1)
62277 fs64_to_cpu(struct super_block *sbp, __fs64 n)
62278 {
62279 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62280@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
62281 return (__force __fs64)cpu_to_be64(n);
62282 }
62283
62284-static inline u32
62285+static inline u32 __intentional_overflow(-1)
62286 fs32_to_cpu(struct super_block *sbp, __fs32 n)
62287 {
62288 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62289diff --git a/fs/utimes.c b/fs/utimes.c
62290index f4fb7ec..3fe03c0 100644
62291--- a/fs/utimes.c
62292+++ b/fs/utimes.c
62293@@ -1,6 +1,7 @@
62294 #include <linux/compiler.h>
62295 #include <linux/file.h>
62296 #include <linux/fs.h>
62297+#include <linux/security.h>
62298 #include <linux/linkage.h>
62299 #include <linux/mount.h>
62300 #include <linux/namei.h>
62301@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
62302 goto mnt_drop_write_and_out;
62303 }
62304 }
62305+
62306+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
62307+ error = -EACCES;
62308+ goto mnt_drop_write_and_out;
62309+ }
62310+
62311 mutex_lock(&inode->i_mutex);
62312 error = notify_change(path->dentry, &newattrs);
62313 mutex_unlock(&inode->i_mutex);
62314diff --git a/fs/xattr.c b/fs/xattr.c
62315index 3377dff..f394815 100644
62316--- a/fs/xattr.c
62317+++ b/fs/xattr.c
62318@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
62319 return rc;
62320 }
62321
62322+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
62323+ssize_t
62324+pax_getxattr(struct dentry *dentry, void *value, size_t size)
62325+{
62326+ struct inode *inode = dentry->d_inode;
62327+ ssize_t error;
62328+
62329+ error = inode_permission(inode, MAY_EXEC);
62330+ if (error)
62331+ return error;
62332+
62333+ if (inode->i_op->getxattr)
62334+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
62335+ else
62336+ error = -EOPNOTSUPP;
62337+
62338+ return error;
62339+}
62340+EXPORT_SYMBOL(pax_getxattr);
62341+#endif
62342+
62343 ssize_t
62344 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
62345 {
62346@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
62347 * Extended attribute SET operations
62348 */
62349 static long
62350-setxattr(struct dentry *d, const char __user *name, const void __user *value,
62351+setxattr(struct path *path, const char __user *name, const void __user *value,
62352 size_t size, int flags)
62353 {
62354 int error;
62355@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
62356 posix_acl_fix_xattr_from_user(kvalue, size);
62357 }
62358
62359- error = vfs_setxattr(d, kname, kvalue, size, flags);
62360+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
62361+ error = -EACCES;
62362+ goto out;
62363+ }
62364+
62365+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
62366 out:
62367 if (vvalue)
62368 vfree(vvalue);
62369@@ -377,7 +403,7 @@ retry:
62370 return error;
62371 error = mnt_want_write(path.mnt);
62372 if (!error) {
62373- error = setxattr(path.dentry, name, value, size, flags);
62374+ error = setxattr(&path, name, value, size, flags);
62375 mnt_drop_write(path.mnt);
62376 }
62377 path_put(&path);
62378@@ -401,7 +427,7 @@ retry:
62379 return error;
62380 error = mnt_want_write(path.mnt);
62381 if (!error) {
62382- error = setxattr(path.dentry, name, value, size, flags);
62383+ error = setxattr(&path, name, value, size, flags);
62384 mnt_drop_write(path.mnt);
62385 }
62386 path_put(&path);
62387@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
62388 const void __user *,value, size_t, size, int, flags)
62389 {
62390 struct fd f = fdget(fd);
62391- struct dentry *dentry;
62392 int error = -EBADF;
62393
62394 if (!f.file)
62395 return error;
62396- dentry = f.file->f_path.dentry;
62397- audit_inode(NULL, dentry, 0);
62398+ audit_inode(NULL, f.file->f_path.dentry, 0);
62399 error = mnt_want_write_file(f.file);
62400 if (!error) {
62401- error = setxattr(dentry, name, value, size, flags);
62402+ error = setxattr(&f.file->f_path, name, value, size, flags);
62403 mnt_drop_write_file(f.file);
62404 }
62405 fdput(f);
62406@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
62407 * Extended attribute REMOVE operations
62408 */
62409 static long
62410-removexattr(struct dentry *d, const char __user *name)
62411+removexattr(struct path *path, const char __user *name)
62412 {
62413 int error;
62414 char kname[XATTR_NAME_MAX + 1];
62415@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
62416 if (error < 0)
62417 return error;
62418
62419- return vfs_removexattr(d, kname);
62420+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
62421+ return -EACCES;
62422+
62423+ return vfs_removexattr(path->dentry, kname);
62424 }
62425
62426 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
62427@@ -652,7 +679,7 @@ retry:
62428 return error;
62429 error = mnt_want_write(path.mnt);
62430 if (!error) {
62431- error = removexattr(path.dentry, name);
62432+ error = removexattr(&path, name);
62433 mnt_drop_write(path.mnt);
62434 }
62435 path_put(&path);
62436@@ -675,7 +702,7 @@ retry:
62437 return error;
62438 error = mnt_want_write(path.mnt);
62439 if (!error) {
62440- error = removexattr(path.dentry, name);
62441+ error = removexattr(&path, name);
62442 mnt_drop_write(path.mnt);
62443 }
62444 path_put(&path);
62445@@ -689,16 +716,16 @@ retry:
62446 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
62447 {
62448 struct fd f = fdget(fd);
62449- struct dentry *dentry;
62450+ struct path *path;
62451 int error = -EBADF;
62452
62453 if (!f.file)
62454 return error;
62455- dentry = f.file->f_path.dentry;
62456- audit_inode(NULL, dentry, 0);
62457+ path = &f.file->f_path;
62458+ audit_inode(NULL, path->dentry, 0);
62459 error = mnt_want_write_file(f.file);
62460 if (!error) {
62461- error = removexattr(dentry, name);
62462+ error = removexattr(path, name);
62463 mnt_drop_write_file(f.file);
62464 }
62465 fdput(f);
62466diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
62467index 9fbea87..6b19972 100644
62468--- a/fs/xattr_acl.c
62469+++ b/fs/xattr_acl.c
62470@@ -76,8 +76,8 @@ struct posix_acl *
62471 posix_acl_from_xattr(struct user_namespace *user_ns,
62472 const void *value, size_t size)
62473 {
62474- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62475- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62476+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62477+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62478 int count;
62479 struct posix_acl *acl;
62480 struct posix_acl_entry *acl_e;
62481diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
62482index f47e65c..e7125d9 100644
62483--- a/fs/xfs/xfs_bmap.c
62484+++ b/fs/xfs/xfs_bmap.c
62485@@ -586,7 +586,7 @@ xfs_bmap_validate_ret(
62486
62487 #else
62488 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
62489-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
62490+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
62491 #endif /* DEBUG */
62492
62493 /*
62494diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
62495index 8f84153..7ce60d0 100644
62496--- a/fs/xfs/xfs_dir2_readdir.c
62497+++ b/fs/xfs/xfs_dir2_readdir.c
62498@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
62499 ino = xfs_dir3_sfe_get_ino(mp, sfp, sfep);
62500 filetype = xfs_dir3_sfe_get_ftype(mp, sfp, sfep);
62501 ctx->pos = off & 0x7fffffff;
62502- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
62503+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
62504+ char name[sfep->namelen];
62505+ memcpy(name, sfep->name, sfep->namelen);
62506+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
62507+ return 0;
62508+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
62509 xfs_dir3_get_dtype(mp, filetype)))
62510 return 0;
62511 sfep = xfs_dir3_sf_nextentry(mp, sfp, sfep);
62512diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
62513index 8c8ef24..689f742 100644
62514--- a/fs/xfs/xfs_ioctl.c
62515+++ b/fs/xfs/xfs_ioctl.c
62516@@ -127,7 +127,7 @@ xfs_find_handle(
62517 }
62518
62519 error = -EFAULT;
62520- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
62521+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
62522 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
62523 goto out_put;
62524
62525diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
62526index 2b8952d..a60c6be 100644
62527--- a/fs/xfs/xfs_iops.c
62528+++ b/fs/xfs/xfs_iops.c
62529@@ -401,7 +401,7 @@ xfs_vn_put_link(
62530 struct nameidata *nd,
62531 void *p)
62532 {
62533- char *s = nd_get_link(nd);
62534+ const char *s = nd_get_link(nd);
62535
62536 if (!IS_ERR(s))
62537 kfree(s);
62538diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
62539new file mode 100644
62540index 0000000..5b2538b
62541--- /dev/null
62542+++ b/grsecurity/Kconfig
62543@@ -0,0 +1,1116 @@
62544+#
62545+# grecurity configuration
62546+#
62547+menu "Memory Protections"
62548+depends on GRKERNSEC
62549+
62550+config GRKERNSEC_KMEM
62551+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
62552+ default y if GRKERNSEC_CONFIG_AUTO
62553+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
62554+ help
62555+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
62556+ be written to or read from to modify or leak the contents of the running
62557+ kernel. /dev/port will also not be allowed to be opened, and support
62558+ for /dev/cpu/*/msr and kexec will be removed. If you have module
62559+ support disabled, enabling this will close up six ways that are
62560+ currently used to insert malicious code into the running kernel.
62561+
62562+ Even with this feature enabled, we still highly recommend that
62563+ you use the RBAC system, as it is still possible for an attacker to
62564+ modify the running kernel through other more obscure methods.
62565+
62566+ Enabling this feature will prevent the "cpupower" and "powertop" tools
62567+ from working.
62568+
62569+ It is highly recommended that you say Y here if you meet all the
62570+ conditions above.
62571+
62572+config GRKERNSEC_VM86
62573+ bool "Restrict VM86 mode"
62574+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62575+ depends on X86_32
62576+
62577+ help
62578+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
62579+ make use of a special execution mode on 32bit x86 processors called
62580+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
62581+ video cards and will still work with this option enabled. The purpose
62582+ of the option is to prevent exploitation of emulation errors in
62583+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
62584+ Nearly all users should be able to enable this option.
62585+
62586+config GRKERNSEC_IO
62587+ bool "Disable privileged I/O"
62588+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62589+ depends on X86
62590+ select RTC_CLASS
62591+ select RTC_INTF_DEV
62592+ select RTC_DRV_CMOS
62593+
62594+ help
62595+ If you say Y here, all ioperm and iopl calls will return an error.
62596+ Ioperm and iopl can be used to modify the running kernel.
62597+ Unfortunately, some programs need this access to operate properly,
62598+ the most notable of which are XFree86 and hwclock. hwclock can be
62599+ remedied by having RTC support in the kernel, so real-time
62600+ clock support is enabled if this option is enabled, to ensure
62601+ that hwclock operates correctly.
62602+
62603+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
62604+ you may not be able to boot into a graphical environment with this
62605+ option enabled. In this case, you should use the RBAC system instead.
62606+
62607+config GRKERNSEC_JIT_HARDEN
62608+ bool "Harden BPF JIT against spray attacks"
62609+ default y if GRKERNSEC_CONFIG_AUTO
62610+ depends on BPF_JIT
62611+ help
62612+ If you say Y here, the native code generated by the kernel's Berkeley
62613+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
62614+ attacks that attempt to fit attacker-beneficial instructions in
62615+ 32bit immediate fields of JIT-generated native instructions. The
62616+ attacker will generally aim to cause an unintended instruction sequence
62617+ of JIT-generated native code to execute by jumping into the middle of
62618+ a generated instruction. This feature effectively randomizes the 32bit
62619+ immediate constants present in the generated code to thwart such attacks.
62620+
62621+ If you're using KERNEXEC, it's recommended that you enable this option
62622+ to supplement the hardening of the kernel.
62623+
62624+config GRKERNSEC_PERF_HARDEN
62625+ bool "Disable unprivileged PERF_EVENTS usage by default"
62626+ default y if GRKERNSEC_CONFIG_AUTO
62627+ depends on PERF_EVENTS
62628+ help
62629+ If you say Y here, the range of acceptable values for the
62630+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
62631+ default to a new value: 3. When the sysctl is set to this value, no
62632+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
62633+
62634+ Though PERF_EVENTS can be used legitimately for performance monitoring
62635+ and low-level application profiling, it is forced on regardless of
62636+ configuration, has been at fault for several vulnerabilities, and
62637+ creates new opportunities for side channels and other information leaks.
62638+
62639+ This feature puts PERF_EVENTS into a secure default state and permits
62640+ the administrator to change out of it temporarily if unprivileged
62641+ application profiling is needed.
62642+
62643+config GRKERNSEC_RAND_THREADSTACK
62644+ bool "Insert random gaps between thread stacks"
62645+ default y if GRKERNSEC_CONFIG_AUTO
62646+ depends on PAX_RANDMMAP && !PPC
62647+ help
62648+ If you say Y here, a random-sized gap will be enforced between allocated
62649+ thread stacks. Glibc's NPTL and other threading libraries that
62650+ pass MAP_STACK to the kernel for thread stack allocation are supported.
62651+ The implementation currently provides 8 bits of entropy for the gap.
62652+
62653+ Many distributions do not compile threaded remote services with the
62654+ -fstack-check argument to GCC, causing the variable-sized stack-based
62655+ allocator, alloca(), to not probe the stack on allocation. This
62656+ permits an unbounded alloca() to skip over any guard page and potentially
62657+ modify another thread's stack reliably. An enforced random gap
62658+ reduces the reliability of such an attack and increases the chance
62659+ that such a read/write to another thread's stack instead lands in
62660+ an unmapped area, causing a crash and triggering grsecurity's
62661+ anti-bruteforcing logic.
62662+
62663+config GRKERNSEC_PROC_MEMMAP
62664+ bool "Harden ASLR against information leaks and entropy reduction"
62665+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
62666+ depends on PAX_NOEXEC || PAX_ASLR
62667+ help
62668+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
62669+ give no information about the addresses of its mappings if
62670+ PaX features that rely on random addresses are enabled on the task.
62671+ In addition to sanitizing this information and disabling other
62672+ dangerous sources of information, this option causes reads of sensitive
62673+ /proc/<pid> entries where the file descriptor was opened in a different
62674+ task than the one performing the read. Such attempts are logged.
62675+ This option also limits argv/env strings for suid/sgid binaries
62676+ to 512KB to prevent a complete exhaustion of the stack entropy provided
62677+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
62678+ binaries to prevent alternative mmap layouts from being abused.
62679+
62680+ If you use PaX it is essential that you say Y here as it closes up
62681+ several holes that make full ASLR useless locally.
62682+
62683+config GRKERNSEC_BRUTE
62684+ bool "Deter exploit bruteforcing"
62685+ default y if GRKERNSEC_CONFIG_AUTO
62686+ help
62687+ If you say Y here, attempts to bruteforce exploits against forking
62688+ daemons such as apache or sshd, as well as against suid/sgid binaries
62689+ will be deterred. When a child of a forking daemon is killed by PaX
62690+ or crashes due to an illegal instruction or other suspicious signal,
62691+ the parent process will be delayed 30 seconds upon every subsequent
62692+ fork until the administrator is able to assess the situation and
62693+ restart the daemon.
62694+ In the suid/sgid case, the attempt is logged, the user has all their
62695+ existing instances of the suid/sgid binary terminated and will
62696+ be unable to execute any suid/sgid binaries for 15 minutes.
62697+
62698+ It is recommended that you also enable signal logging in the auditing
62699+ section so that logs are generated when a process triggers a suspicious
62700+ signal.
62701+ If the sysctl option is enabled, a sysctl option with name
62702+ "deter_bruteforce" is created.
62703+
62704+
62705+config GRKERNSEC_MODHARDEN
62706+ bool "Harden module auto-loading"
62707+ default y if GRKERNSEC_CONFIG_AUTO
62708+ depends on MODULES
62709+ help
62710+ If you say Y here, module auto-loading in response to use of some
62711+ feature implemented by an unloaded module will be restricted to
62712+ root users. Enabling this option helps defend against attacks
62713+ by unprivileged users who abuse the auto-loading behavior to
62714+ cause a vulnerable module to load that is then exploited.
62715+
62716+ If this option prevents a legitimate use of auto-loading for a
62717+ non-root user, the administrator can execute modprobe manually
62718+ with the exact name of the module mentioned in the alert log.
62719+ Alternatively, the administrator can add the module to the list
62720+ of modules loaded at boot by modifying init scripts.
62721+
62722+ Modification of init scripts will most likely be needed on
62723+ Ubuntu servers with encrypted home directory support enabled,
62724+ as the first non-root user logging in will cause the ecb(aes),
62725+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
62726+
62727+config GRKERNSEC_HIDESYM
62728+ bool "Hide kernel symbols"
62729+ default y if GRKERNSEC_CONFIG_AUTO
62730+ select PAX_USERCOPY_SLABS
62731+ help
62732+ If you say Y here, getting information on loaded modules, and
62733+ displaying all kernel symbols through a syscall will be restricted
62734+ to users with CAP_SYS_MODULE. For software compatibility reasons,
62735+ /proc/kallsyms will be restricted to the root user. The RBAC
62736+ system can hide that entry even from root.
62737+
62738+ This option also prevents leaking of kernel addresses through
62739+ several /proc entries.
62740+
62741+ Note that this option is only effective provided the following
62742+ conditions are met:
62743+ 1) The kernel using grsecurity is not precompiled by some distribution
62744+ 2) You have also enabled GRKERNSEC_DMESG
62745+ 3) You are using the RBAC system and hiding other files such as your
62746+ kernel image and System.map. Alternatively, enabling this option
62747+ causes the permissions on /boot, /lib/modules, and the kernel
62748+ source directory to change at compile time to prevent
62749+ reading by non-root users.
62750+ If the above conditions are met, this option will aid in providing a
62751+ useful protection against local kernel exploitation of overflows
62752+ and arbitrary read/write vulnerabilities.
62753+
62754+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
62755+ in addition to this feature.
62756+
62757+config GRKERNSEC_KERN_LOCKOUT
62758+ bool "Active kernel exploit response"
62759+ default y if GRKERNSEC_CONFIG_AUTO
62760+ depends on X86 || ARM || PPC || SPARC
62761+ help
62762+ If you say Y here, when a PaX alert is triggered due to suspicious
62763+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
62764+ or an OOPS occurs due to bad memory accesses, instead of just
62765+ terminating the offending process (and potentially allowing
62766+ a subsequent exploit from the same user), we will take one of two
62767+ actions:
62768+ If the user was root, we will panic the system
62769+ If the user was non-root, we will log the attempt, terminate
62770+ all processes owned by the user, then prevent them from creating
62771+ any new processes until the system is restarted
62772+ This deters repeated kernel exploitation/bruteforcing attempts
62773+ and is useful for later forensics.
62774+
62775+config GRKERNSEC_OLD_ARM_USERLAND
62776+ bool "Old ARM userland compatibility"
62777+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
62778+ help
62779+ If you say Y here, stubs of executable code to perform such operations
62780+ as "compare-exchange" will be placed at fixed locations in the ARM vector
62781+ table. This is unfortunately needed for old ARM userland meant to run
62782+ across a wide range of processors. Without this option enabled,
62783+ the get_tls and data memory barrier stubs will be emulated by the kernel,
62784+ which is enough for Linaro userlands or other userlands designed for v6
62785+ and newer ARM CPUs. It's recommended that you try without this option enabled
62786+ first, and only enable it if your userland does not boot (it will likely fail
62787+ at init time).
62788+
62789+endmenu
62790+menu "Role Based Access Control Options"
62791+depends on GRKERNSEC
62792+
62793+config GRKERNSEC_RBAC_DEBUG
62794+ bool
62795+
62796+config GRKERNSEC_NO_RBAC
62797+ bool "Disable RBAC system"
62798+ help
62799+ If you say Y here, the /dev/grsec device will be removed from the kernel,
62800+ preventing the RBAC system from being enabled. You should only say Y
62801+ here if you have no intention of using the RBAC system, so as to prevent
62802+ an attacker with root access from misusing the RBAC system to hide files
62803+ and processes when loadable module support and /dev/[k]mem have been
62804+ locked down.
62805+
62806+config GRKERNSEC_ACL_HIDEKERN
62807+ bool "Hide kernel processes"
62808+ help
62809+ If you say Y here, all kernel threads will be hidden to all
62810+ processes but those whose subject has the "view hidden processes"
62811+ flag.
62812+
62813+config GRKERNSEC_ACL_MAXTRIES
62814+ int "Maximum tries before password lockout"
62815+ default 3
62816+ help
62817+ This option enforces the maximum number of times a user can attempt
62818+ to authorize themselves with the grsecurity RBAC system before being
62819+ denied the ability to attempt authorization again for a specified time.
62820+ The lower the number, the harder it will be to brute-force a password.
62821+
62822+config GRKERNSEC_ACL_TIMEOUT
62823+ int "Time to wait after max password tries, in seconds"
62824+ default 30
62825+ help
62826+ This option specifies the time the user must wait after attempting to
62827+ authorize to the RBAC system with the maximum number of invalid
62828+ passwords. The higher the number, the harder it will be to brute-force
62829+ a password.
62830+
62831+endmenu
62832+menu "Filesystem Protections"
62833+depends on GRKERNSEC
62834+
62835+config GRKERNSEC_PROC
62836+ bool "Proc restrictions"
62837+ default y if GRKERNSEC_CONFIG_AUTO
62838+ help
62839+ If you say Y here, the permissions of the /proc filesystem
62840+ will be altered to enhance system security and privacy. You MUST
62841+ choose either a user only restriction or a user and group restriction.
62842+ Depending upon the option you choose, you can either restrict users to
62843+ see only the processes they themselves run, or choose a group that can
62844+ view all processes and files normally restricted to root if you choose
62845+ the "restrict to user only" option. NOTE: If you're running identd or
62846+ ntpd as a non-root user, you will have to run it as the group you
62847+ specify here.
62848+
62849+config GRKERNSEC_PROC_USER
62850+ bool "Restrict /proc to user only"
62851+ depends on GRKERNSEC_PROC
62852+ help
62853+ If you say Y here, non-root users will only be able to view their own
62854+ processes, and restricts them from viewing network-related information,
62855+ and viewing kernel symbol and module information.
62856+
62857+config GRKERNSEC_PROC_USERGROUP
62858+ bool "Allow special group"
62859+ default y if GRKERNSEC_CONFIG_AUTO
62860+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
62861+ help
62862+ If you say Y here, you will be able to select a group that will be
62863+ able to view all processes and network-related information. If you've
62864+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
62865+ remain hidden. This option is useful if you want to run identd as
62866+ a non-root user. The group you select may also be chosen at boot time
62867+ via "grsec_proc_gid=" on the kernel commandline.
62868+
62869+config GRKERNSEC_PROC_GID
62870+ int "GID for special group"
62871+ depends on GRKERNSEC_PROC_USERGROUP
62872+ default 1001
62873+
62874+config GRKERNSEC_PROC_ADD
62875+ bool "Additional restrictions"
62876+ default y if GRKERNSEC_CONFIG_AUTO
62877+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
62878+ help
62879+ If you say Y here, additional restrictions will be placed on
62880+ /proc that keep normal users from viewing device information and
62881+ slabinfo information that could be useful for exploits.
62882+
62883+config GRKERNSEC_LINK
62884+ bool "Linking restrictions"
62885+ default y if GRKERNSEC_CONFIG_AUTO
62886+ help
62887+ If you say Y here, /tmp race exploits will be prevented, since users
62888+ will no longer be able to follow symlinks owned by other users in
62889+ world-writable +t directories (e.g. /tmp), unless the owner of the
62890+ symlink is the owner of the directory. users will also not be
62891+ able to hardlink to files they do not own. If the sysctl option is
62892+ enabled, a sysctl option with name "linking_restrictions" is created.
62893+
62894+config GRKERNSEC_SYMLINKOWN
62895+ bool "Kernel-enforced SymlinksIfOwnerMatch"
62896+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
62897+ help
62898+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
62899+ that prevents it from being used as a security feature. As Apache
62900+ verifies the symlink by performing a stat() against the target of
62901+ the symlink before it is followed, an attacker can setup a symlink
62902+ to point to a same-owned file, then replace the symlink with one
62903+ that targets another user's file just after Apache "validates" the
62904+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
62905+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
62906+ will be in place for the group you specify. If the sysctl option
62907+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
62908+ created.
62909+
62910+config GRKERNSEC_SYMLINKOWN_GID
62911+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
62912+ depends on GRKERNSEC_SYMLINKOWN
62913+ default 1006
62914+ help
62915+ Setting this GID determines what group kernel-enforced
62916+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
62917+ is enabled, a sysctl option with name "symlinkown_gid" is created.
62918+
62919+config GRKERNSEC_FIFO
62920+ bool "FIFO restrictions"
62921+ default y if GRKERNSEC_CONFIG_AUTO
62922+ help
62923+ If you say Y here, users will not be able to write to FIFOs they don't
62924+ own in world-writable +t directories (e.g. /tmp), unless the owner of
62925+ the FIFO is the same owner of the directory it's held in. If the sysctl
62926+ option is enabled, a sysctl option with name "fifo_restrictions" is
62927+ created.
62928+
62929+config GRKERNSEC_SYSFS_RESTRICT
62930+ bool "Sysfs/debugfs restriction"
62931+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62932+ depends on SYSFS
62933+ help
62934+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
62935+ any filesystem normally mounted under it (e.g. debugfs) will be
62936+ mostly accessible only by root. These filesystems generally provide access
62937+ to hardware and debug information that isn't appropriate for unprivileged
62938+ users of the system. Sysfs and debugfs have also become a large source
62939+ of new vulnerabilities, ranging from infoleaks to local compromise.
62940+ There has been very little oversight with an eye toward security involved
62941+ in adding new exporters of information to these filesystems, so their
62942+ use is discouraged.
62943+ For reasons of compatibility, a few directories have been whitelisted
62944+ for access by non-root users:
62945+ /sys/fs/selinux
62946+ /sys/fs/fuse
62947+ /sys/devices/system/cpu
62948+
62949+config GRKERNSEC_ROFS
62950+ bool "Runtime read-only mount protection"
62951+ depends on SYSCTL
62952+ help
62953+ If you say Y here, a sysctl option with name "romount_protect" will
62954+ be created. By setting this option to 1 at runtime, filesystems
62955+ will be protected in the following ways:
62956+ * No new writable mounts will be allowed
62957+ * Existing read-only mounts won't be able to be remounted read/write
62958+ * Write operations will be denied on all block devices
62959+ This option acts independently of grsec_lock: once it is set to 1,
62960+ it cannot be turned off. Therefore, please be mindful of the resulting
62961+ behavior if this option is enabled in an init script on a read-only
62962+ filesystem.
62963+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
62964+ and GRKERNSEC_IO should be enabled and module loading disabled via
62965+ config or at runtime.
62966+ This feature is mainly intended for secure embedded systems.
62967+
62968+
62969+config GRKERNSEC_DEVICE_SIDECHANNEL
62970+ bool "Eliminate stat/notify-based device sidechannels"
62971+ default y if GRKERNSEC_CONFIG_AUTO
62972+ help
62973+ If you say Y here, timing analyses on block or character
62974+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
62975+ will be thwarted for unprivileged users. If a process without
62976+ CAP_MKNOD stats such a device, the last access and last modify times
62977+ will match the device's create time. No access or modify events
62978+ will be triggered through inotify/dnotify/fanotify for such devices.
62979+ This feature will prevent attacks that may at a minimum
62980+ allow an attacker to determine the administrator's password length.
62981+
62982+config GRKERNSEC_CHROOT
62983+ bool "Chroot jail restrictions"
62984+ default y if GRKERNSEC_CONFIG_AUTO
62985+ help
62986+ If you say Y here, you will be able to choose several options that will
62987+ make breaking out of a chrooted jail much more difficult. If you
62988+ encounter no software incompatibilities with the following options, it
62989+ is recommended that you enable each one.
62990+
62991+config GRKERNSEC_CHROOT_MOUNT
62992+ bool "Deny mounts"
62993+ default y if GRKERNSEC_CONFIG_AUTO
62994+ depends on GRKERNSEC_CHROOT
62995+ help
62996+ If you say Y here, processes inside a chroot will not be able to
62997+ mount or remount filesystems. If the sysctl option is enabled, a
62998+ sysctl option with name "chroot_deny_mount" is created.
62999+
63000+config GRKERNSEC_CHROOT_DOUBLE
63001+ bool "Deny double-chroots"
63002+ default y if GRKERNSEC_CONFIG_AUTO
63003+ depends on GRKERNSEC_CHROOT
63004+ help
63005+ If you say Y here, processes inside a chroot will not be able to chroot
63006+ again outside the chroot. This is a widely used method of breaking
63007+ out of a chroot jail and should not be allowed. If the sysctl
63008+ option is enabled, a sysctl option with name
63009+ "chroot_deny_chroot" is created.
63010+
63011+config GRKERNSEC_CHROOT_PIVOT
63012+ bool "Deny pivot_root in chroot"
63013+ default y if GRKERNSEC_CONFIG_AUTO
63014+ depends on GRKERNSEC_CHROOT
63015+ help
63016+ If you say Y here, processes inside a chroot will not be able to use
63017+ a function called pivot_root() that was introduced in Linux 2.3.41. It
63018+ works similar to chroot in that it changes the root filesystem. This
63019+ function could be misused in a chrooted process to attempt to break out
63020+ of the chroot, and therefore should not be allowed. If the sysctl
63021+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
63022+ created.
63023+
63024+config GRKERNSEC_CHROOT_CHDIR
63025+ bool "Enforce chdir(\"/\") on all chroots"
63026+ default y if GRKERNSEC_CONFIG_AUTO
63027+ depends on GRKERNSEC_CHROOT
63028+ help
63029+ If you say Y here, the current working directory of all newly-chrooted
63030+ applications will be set to the the root directory of the chroot.
63031+ The man page on chroot(2) states:
63032+ Note that this call does not change the current working
63033+ directory, so that `.' can be outside the tree rooted at
63034+ `/'. In particular, the super-user can escape from a
63035+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
63036+
63037+ It is recommended that you say Y here, since it's not known to break
63038+ any software. If the sysctl option is enabled, a sysctl option with
63039+ name "chroot_enforce_chdir" is created.
63040+
63041+config GRKERNSEC_CHROOT_CHMOD
63042+ bool "Deny (f)chmod +s"
63043+ default y if GRKERNSEC_CONFIG_AUTO
63044+ depends on GRKERNSEC_CHROOT
63045+ help
63046+ If you say Y here, processes inside a chroot will not be able to chmod
63047+ or fchmod files to make them have suid or sgid bits. This protects
63048+ against another published method of breaking a chroot. If the sysctl
63049+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
63050+ created.
63051+
63052+config GRKERNSEC_CHROOT_FCHDIR
63053+ bool "Deny fchdir out of chroot"
63054+ default y if GRKERNSEC_CONFIG_AUTO
63055+ depends on GRKERNSEC_CHROOT
63056+ help
63057+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
63058+ to a file descriptor of the chrooting process that points to a directory
63059+ outside the filesystem will be stopped. If the sysctl option
63060+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
63061+
63062+config GRKERNSEC_CHROOT_MKNOD
63063+ bool "Deny mknod"
63064+ default y if GRKERNSEC_CONFIG_AUTO
63065+ depends on GRKERNSEC_CHROOT
63066+ help
63067+ If you say Y here, processes inside a chroot will not be allowed to
63068+ mknod. The problem with using mknod inside a chroot is that it
63069+ would allow an attacker to create a device entry that is the same
63070+ as one on the physical root of your system, which could range from
63071+ anything from the console device to a device for your harddrive (which
63072+ they could then use to wipe the drive or steal data). It is recommended
63073+ that you say Y here, unless you run into software incompatibilities.
63074+ If the sysctl option is enabled, a sysctl option with name
63075+ "chroot_deny_mknod" is created.
63076+
63077+config GRKERNSEC_CHROOT_SHMAT
63078+ bool "Deny shmat() out of chroot"
63079+ default y if GRKERNSEC_CONFIG_AUTO
63080+ depends on GRKERNSEC_CHROOT
63081+ help
63082+ If you say Y here, processes inside a chroot will not be able to attach
63083+ to shared memory segments that were created outside of the chroot jail.
63084+ It is recommended that you say Y here. If the sysctl option is enabled,
63085+ a sysctl option with name "chroot_deny_shmat" is created.
63086+
63087+config GRKERNSEC_CHROOT_UNIX
63088+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
63089+ default y if GRKERNSEC_CONFIG_AUTO
63090+ depends on GRKERNSEC_CHROOT
63091+ help
63092+ If you say Y here, processes inside a chroot will not be able to
63093+ connect to abstract (meaning not belonging to a filesystem) Unix
63094+ domain sockets that were bound outside of a chroot. It is recommended
63095+ that you say Y here. If the sysctl option is enabled, a sysctl option
63096+ with name "chroot_deny_unix" is created.
63097+
63098+config GRKERNSEC_CHROOT_FINDTASK
63099+ bool "Protect outside processes"
63100+ default y if GRKERNSEC_CONFIG_AUTO
63101+ depends on GRKERNSEC_CHROOT
63102+ help
63103+ If you say Y here, processes inside a chroot will not be able to
63104+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
63105+ getsid, or view any process outside of the chroot. If the sysctl
63106+ option is enabled, a sysctl option with name "chroot_findtask" is
63107+ created.
63108+
63109+config GRKERNSEC_CHROOT_NICE
63110+ bool "Restrict priority changes"
63111+ default y if GRKERNSEC_CONFIG_AUTO
63112+ depends on GRKERNSEC_CHROOT
63113+ help
63114+ If you say Y here, processes inside a chroot will not be able to raise
63115+ the priority of processes in the chroot, or alter the priority of
63116+ processes outside the chroot. This provides more security than simply
63117+ removing CAP_SYS_NICE from the process' capability set. If the
63118+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
63119+ is created.
63120+
63121+config GRKERNSEC_CHROOT_SYSCTL
63122+ bool "Deny sysctl writes"
63123+ default y if GRKERNSEC_CONFIG_AUTO
63124+ depends on GRKERNSEC_CHROOT
63125+ help
63126+ If you say Y here, an attacker in a chroot will not be able to
63127+ write to sysctl entries, either by sysctl(2) or through a /proc
63128+ interface. It is strongly recommended that you say Y here. If the
63129+ sysctl option is enabled, a sysctl option with name
63130+ "chroot_deny_sysctl" is created.
63131+
63132+config GRKERNSEC_CHROOT_CAPS
63133+ bool "Capability restrictions"
63134+ default y if GRKERNSEC_CONFIG_AUTO
63135+ depends on GRKERNSEC_CHROOT
63136+ help
63137+ If you say Y here, the capabilities on all processes within a
63138+ chroot jail will be lowered to stop module insertion, raw i/o,
63139+ system and net admin tasks, rebooting the system, modifying immutable
63140+ files, modifying IPC owned by another, and changing the system time.
63141+ This is left an option because it can break some apps. Disable this
63142+ if your chrooted apps are having problems performing those kinds of
63143+ tasks. If the sysctl option is enabled, a sysctl option with
63144+ name "chroot_caps" is created.
63145+
63146+config GRKERNSEC_CHROOT_INITRD
63147+ bool "Exempt initrd tasks from restrictions"
63148+ default y if GRKERNSEC_CONFIG_AUTO
63149+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
63150+ help
63151+ If you say Y here, tasks started prior to init will be exempted from
63152+ grsecurity's chroot restrictions. This option is mainly meant to
63153+ resolve Plymouth's performing privileged operations unnecessarily
63154+ in a chroot.
63155+
63156+endmenu
63157+menu "Kernel Auditing"
63158+depends on GRKERNSEC
63159+
63160+config GRKERNSEC_AUDIT_GROUP
63161+ bool "Single group for auditing"
63162+ help
63163+ If you say Y here, the exec and chdir logging features will only operate
63164+ on a group you specify. This option is recommended if you only want to
63165+ watch certain users instead of having a large amount of logs from the
63166+ entire system. If the sysctl option is enabled, a sysctl option with
63167+ name "audit_group" is created.
63168+
63169+config GRKERNSEC_AUDIT_GID
63170+ int "GID for auditing"
63171+ depends on GRKERNSEC_AUDIT_GROUP
63172+ default 1007
63173+
63174+config GRKERNSEC_EXECLOG
63175+ bool "Exec logging"
63176+ help
63177+ If you say Y here, all execve() calls will be logged (since the
63178+ other exec*() calls are frontends to execve(), all execution
63179+ will be logged). Useful for shell-servers that like to keep track
63180+ of their users. If the sysctl option is enabled, a sysctl option with
63181+ name "exec_logging" is created.
63182+ WARNING: This option when enabled will produce a LOT of logs, especially
63183+ on an active system.
63184+
63185+config GRKERNSEC_RESLOG
63186+ bool "Resource logging"
63187+ default y if GRKERNSEC_CONFIG_AUTO
63188+ help
63189+ If you say Y here, all attempts to overstep resource limits will
63190+ be logged with the resource name, the requested size, and the current
63191+ limit. It is highly recommended that you say Y here. If the sysctl
63192+ option is enabled, a sysctl option with name "resource_logging" is
63193+ created. If the RBAC system is enabled, the sysctl value is ignored.
63194+
63195+config GRKERNSEC_CHROOT_EXECLOG
63196+ bool "Log execs within chroot"
63197+ help
63198+ If you say Y here, all executions inside a chroot jail will be logged
63199+ to syslog. This can cause a large amount of logs if certain
63200+ applications (eg. djb's daemontools) are installed on the system, and
63201+ is therefore left as an option. If the sysctl option is enabled, a
63202+ sysctl option with name "chroot_execlog" is created.
63203+
63204+config GRKERNSEC_AUDIT_PTRACE
63205+ bool "Ptrace logging"
63206+ help
63207+ If you say Y here, all attempts to attach to a process via ptrace
63208+ will be logged. If the sysctl option is enabled, a sysctl option
63209+ with name "audit_ptrace" is created.
63210+
63211+config GRKERNSEC_AUDIT_CHDIR
63212+ bool "Chdir logging"
63213+ help
63214+ If you say Y here, all chdir() calls will be logged. If the sysctl
63215+ option is enabled, a sysctl option with name "audit_chdir" is created.
63216+
63217+config GRKERNSEC_AUDIT_MOUNT
63218+ bool "(Un)Mount logging"
63219+ help
63220+ If you say Y here, all mounts and unmounts will be logged. If the
63221+ sysctl option is enabled, a sysctl option with name "audit_mount" is
63222+ created.
63223+
63224+config GRKERNSEC_SIGNAL
63225+ bool "Signal logging"
63226+ default y if GRKERNSEC_CONFIG_AUTO
63227+ help
63228+ If you say Y here, certain important signals will be logged, such as
63229+ SIGSEGV, which will as a result inform you of when a error in a program
63230+ occurred, which in some cases could mean a possible exploit attempt.
63231+ If the sysctl option is enabled, a sysctl option with name
63232+ "signal_logging" is created.
63233+
63234+config GRKERNSEC_FORKFAIL
63235+ bool "Fork failure logging"
63236+ help
63237+ If you say Y here, all failed fork() attempts will be logged.
63238+ This could suggest a fork bomb, or someone attempting to overstep
63239+ their process limit. If the sysctl option is enabled, a sysctl option
63240+ with name "forkfail_logging" is created.
63241+
63242+config GRKERNSEC_TIME
63243+ bool "Time change logging"
63244+ default y if GRKERNSEC_CONFIG_AUTO
63245+ help
63246+ If you say Y here, any changes of the system clock will be logged.
63247+ If the sysctl option is enabled, a sysctl option with name
63248+ "timechange_logging" is created.
63249+
63250+config GRKERNSEC_PROC_IPADDR
63251+ bool "/proc/<pid>/ipaddr support"
63252+ default y if GRKERNSEC_CONFIG_AUTO
63253+ help
63254+ If you say Y here, a new entry will be added to each /proc/<pid>
63255+ directory that contains the IP address of the person using the task.
63256+ The IP is carried across local TCP and AF_UNIX stream sockets.
63257+ This information can be useful for IDS/IPSes to perform remote response
63258+ to a local attack. The entry is readable by only the owner of the
63259+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
63260+ the RBAC system), and thus does not create privacy concerns.
63261+
63262+config GRKERNSEC_RWXMAP_LOG
63263+ bool 'Denied RWX mmap/mprotect logging'
63264+ default y if GRKERNSEC_CONFIG_AUTO
63265+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
63266+ help
63267+ If you say Y here, calls to mmap() and mprotect() with explicit
63268+ usage of PROT_WRITE and PROT_EXEC together will be logged when
63269+ denied by the PAX_MPROTECT feature. This feature will also
63270+ log other problematic scenarios that can occur when PAX_MPROTECT
63271+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
63272+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
63273+ is created.
63274+
63275+endmenu
63276+
63277+menu "Executable Protections"
63278+depends on GRKERNSEC
63279+
63280+config GRKERNSEC_DMESG
63281+ bool "Dmesg(8) restriction"
63282+ default y if GRKERNSEC_CONFIG_AUTO
63283+ help
63284+ If you say Y here, non-root users will not be able to use dmesg(8)
63285+ to view the contents of the kernel's circular log buffer.
63286+ The kernel's log buffer often contains kernel addresses and other
63287+ identifying information useful to an attacker in fingerprinting a
63288+ system for a targeted exploit.
63289+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
63290+ created.
63291+
63292+config GRKERNSEC_HARDEN_PTRACE
63293+ bool "Deter ptrace-based process snooping"
63294+ default y if GRKERNSEC_CONFIG_AUTO
63295+ help
63296+ If you say Y here, TTY sniffers and other malicious monitoring
63297+ programs implemented through ptrace will be defeated. If you
63298+ have been using the RBAC system, this option has already been
63299+ enabled for several years for all users, with the ability to make
63300+ fine-grained exceptions.
63301+
63302+ This option only affects the ability of non-root users to ptrace
63303+ processes that are not a descendent of the ptracing process.
63304+ This means that strace ./binary and gdb ./binary will still work,
63305+ but attaching to arbitrary processes will not. If the sysctl
63306+ option is enabled, a sysctl option with name "harden_ptrace" is
63307+ created.
63308+
63309+config GRKERNSEC_PTRACE_READEXEC
63310+ bool "Require read access to ptrace sensitive binaries"
63311+ default y if GRKERNSEC_CONFIG_AUTO
63312+ help
63313+ If you say Y here, unprivileged users will not be able to ptrace unreadable
63314+ binaries. This option is useful in environments that
63315+ remove the read bits (e.g. file mode 4711) from suid binaries to
63316+ prevent infoleaking of their contents. This option adds
63317+ consistency to the use of that file mode, as the binary could normally
63318+ be read out when run without privileges while ptracing.
63319+
63320+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
63321+ is created.
63322+
63323+config GRKERNSEC_SETXID
63324+ bool "Enforce consistent multithreaded privileges"
63325+ default y if GRKERNSEC_CONFIG_AUTO
63326+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
63327+ help
63328+ If you say Y here, a change from a root uid to a non-root uid
63329+ in a multithreaded application will cause the resulting uids,
63330+ gids, supplementary groups, and capabilities in that thread
63331+ to be propagated to the other threads of the process. In most
63332+ cases this is unnecessary, as glibc will emulate this behavior
63333+ on behalf of the application. Other libcs do not act in the
63334+ same way, allowing the other threads of the process to continue
63335+ running with root privileges. If the sysctl option is enabled,
63336+ a sysctl option with name "consistent_setxid" is created.
63337+
63338+config GRKERNSEC_HARDEN_IPC
63339+ bool "Disallow access to overly-permissive IPC objects"
63340+ default y if GRKERNSEC_CONFIG_AUTO
63341+ depends on SYSVIPC
63342+ help
63343+ If you say Y here, access to overly-permissive IPC objects (shared
63344+ memory, message queues, and semaphores) will be denied for processes
63345+ given the following criteria beyond normal permission checks:
63346+ 1) If the IPC object is world-accessible and the euid doesn't match
63347+ that of the creator or current uid for the IPC object
63348+ 2) If the IPC object is group-accessible and the egid doesn't
63349+ match that of the creator or current gid for the IPC object
63350+ It's a common error to grant too much permission to these objects,
63351+ with impact ranging from denial of service and information leaking to
63352+ privilege escalation. This feature was developed in response to
63353+ research by Tim Brown:
63354+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
63355+ who found hundreds of such insecure usages. Processes with
63356+ CAP_IPC_OWNER are still permitted to access these IPC objects.
63357+ If the sysctl option is enabled, a sysctl option with name
63358+ "harden_ipc" is created.
63359+
63360+config GRKERNSEC_TPE
63361+ bool "Trusted Path Execution (TPE)"
63362+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
63363+ help
63364+ If you say Y here, you will be able to choose a gid to add to the
63365+ supplementary groups of users you want to mark as "untrusted."
63366+ These users will not be able to execute any files that are not in
63367+ root-owned directories writable only by root. If the sysctl option
63368+ is enabled, a sysctl option with name "tpe" is created.
63369+
63370+config GRKERNSEC_TPE_ALL
63371+ bool "Partially restrict all non-root users"
63372+ depends on GRKERNSEC_TPE
63373+ help
63374+ If you say Y here, all non-root users will be covered under
63375+ a weaker TPE restriction. This is separate from, and in addition to,
63376+ the main TPE options that you have selected elsewhere. Thus, if a
63377+ "trusted" GID is chosen, this restriction applies to even that GID.
63378+ Under this restriction, all non-root users will only be allowed to
63379+ execute files in directories they own that are not group or
63380+ world-writable, or in directories owned by root and writable only by
63381+ root. If the sysctl option is enabled, a sysctl option with name
63382+ "tpe_restrict_all" is created.
63383+
63384+config GRKERNSEC_TPE_INVERT
63385+ bool "Invert GID option"
63386+ depends on GRKERNSEC_TPE
63387+ help
63388+ If you say Y here, the group you specify in the TPE configuration will
63389+ decide what group TPE restrictions will be *disabled* for. This
63390+ option is useful if you want TPE restrictions to be applied to most
63391+ users on the system. If the sysctl option is enabled, a sysctl option
63392+ with name "tpe_invert" is created. Unlike other sysctl options, this
63393+ entry will default to on for backward-compatibility.
63394+
63395+config GRKERNSEC_TPE_GID
63396+ int
63397+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
63398+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
63399+
63400+config GRKERNSEC_TPE_UNTRUSTED_GID
63401+ int "GID for TPE-untrusted users"
63402+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
63403+ default 1005
63404+ help
63405+ Setting this GID determines what group TPE restrictions will be
63406+ *enabled* for. If the sysctl option is enabled, a sysctl option
63407+ with name "tpe_gid" is created.
63408+
63409+config GRKERNSEC_TPE_TRUSTED_GID
63410+ int "GID for TPE-trusted users"
63411+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
63412+ default 1005
63413+ help
63414+ Setting this GID determines what group TPE restrictions will be
63415+ *disabled* for. If the sysctl option is enabled, a sysctl option
63416+ with name "tpe_gid" is created.
63417+
63418+endmenu
63419+menu "Network Protections"
63420+depends on GRKERNSEC
63421+
63422+config GRKERNSEC_RANDNET
63423+ bool "Larger entropy pools"
63424+ default y if GRKERNSEC_CONFIG_AUTO
63425+ help
63426+ If you say Y here, the entropy pools used for many features of Linux
63427+ and grsecurity will be doubled in size. Since several grsecurity
63428+ features use additional randomness, it is recommended that you say Y
63429+ here. Saying Y here has a similar effect as modifying
63430+ /proc/sys/kernel/random/poolsize.
63431+
63432+config GRKERNSEC_BLACKHOLE
63433+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
63434+ default y if GRKERNSEC_CONFIG_AUTO
63435+ depends on NET
63436+ help
63437+ If you say Y here, neither TCP resets nor ICMP
63438+ destination-unreachable packets will be sent in response to packets
63439+ sent to ports for which no associated listening process exists.
63440+ This feature supports both IPV4 and IPV6 and exempts the
63441+ loopback interface from blackholing. Enabling this feature
63442+ makes a host more resilient to DoS attacks and reduces network
63443+ visibility against scanners.
63444+
63445+ The blackhole feature as-implemented is equivalent to the FreeBSD
63446+ blackhole feature, as it prevents RST responses to all packets, not
63447+ just SYNs. Under most application behavior this causes no
63448+ problems, but applications (like haproxy) may not close certain
63449+ connections in a way that cleanly terminates them on the remote
63450+ end, leaving the remote host in LAST_ACK state. Because of this
63451+ side-effect and to prevent intentional LAST_ACK DoSes, this
63452+ feature also adds automatic mitigation against such attacks.
63453+ The mitigation drastically reduces the amount of time a socket
63454+ can spend in LAST_ACK state. If you're using haproxy and not
63455+ all servers it connects to have this option enabled, consider
63456+ disabling this feature on the haproxy host.
63457+
63458+ If the sysctl option is enabled, two sysctl options with names
63459+ "ip_blackhole" and "lastack_retries" will be created.
63460+ While "ip_blackhole" takes the standard zero/non-zero on/off
63461+ toggle, "lastack_retries" uses the same kinds of values as
63462+ "tcp_retries1" and "tcp_retries2". The default value of 4
63463+ prevents a socket from lasting more than 45 seconds in LAST_ACK
63464+ state.
63465+
63466+config GRKERNSEC_NO_SIMULT_CONNECT
63467+ bool "Disable TCP Simultaneous Connect"
63468+ default y if GRKERNSEC_CONFIG_AUTO
63469+ depends on NET
63470+ help
63471+ If you say Y here, a feature by Willy Tarreau will be enabled that
63472+ removes a weakness in Linux's strict implementation of TCP that
63473+ allows two clients to connect to each other without either entering
63474+ a listening state. The weakness allows an attacker to easily prevent
63475+ a client from connecting to a known server provided the source port
63476+ for the connection is guessed correctly.
63477+
63478+ As the weakness could be used to prevent an antivirus or IPS from
63479+ fetching updates, or prevent an SSL gateway from fetching a CRL,
63480+ it should be eliminated by enabling this option. Though Linux is
63481+ one of few operating systems supporting simultaneous connect, it
63482+ has no legitimate use in practice and is rarely supported by firewalls.
63483+
63484+config GRKERNSEC_SOCKET
63485+ bool "Socket restrictions"
63486+ depends on NET
63487+ help
63488+ If you say Y here, you will be able to choose from several options.
63489+ If you assign a GID on your system and add it to the supplementary
63490+ groups of users you want to restrict socket access to, this patch
63491+ will perform up to three things, based on the option(s) you choose.
63492+
63493+config GRKERNSEC_SOCKET_ALL
63494+ bool "Deny any sockets to group"
63495+ depends on GRKERNSEC_SOCKET
63496+ help
63497+ If you say Y here, you will be able to choose a GID of whose users will
63498+ be unable to connect to other hosts from your machine or run server
63499+ applications from your machine. If the sysctl option is enabled, a
63500+ sysctl option with name "socket_all" is created.
63501+
63502+config GRKERNSEC_SOCKET_ALL_GID
63503+ int "GID to deny all sockets for"
63504+ depends on GRKERNSEC_SOCKET_ALL
63505+ default 1004
63506+ help
63507+ Here you can choose the GID to disable socket access for. Remember to
63508+ add the users you want socket access disabled for to the GID
63509+ specified here. If the sysctl option is enabled, a sysctl option
63510+ with name "socket_all_gid" is created.
63511+
63512+config GRKERNSEC_SOCKET_CLIENT
63513+ bool "Deny client sockets to group"
63514+ depends on GRKERNSEC_SOCKET
63515+ help
63516+ If you say Y here, you will be able to choose a GID of whose users will
63517+ be unable to connect to other hosts from your machine, but will be
63518+ able to run servers. If this option is enabled, all users in the group
63519+ you specify will have to use passive mode when initiating ftp transfers
63520+ from the shell on your machine. If the sysctl option is enabled, a
63521+ sysctl option with name "socket_client" is created.
63522+
63523+config GRKERNSEC_SOCKET_CLIENT_GID
63524+ int "GID to deny client sockets for"
63525+ depends on GRKERNSEC_SOCKET_CLIENT
63526+ default 1003
63527+ help
63528+ Here you can choose the GID to disable client socket access for.
63529+ Remember to add the users you want client socket access disabled for to
63530+ the GID specified here. If the sysctl option is enabled, a sysctl
63531+ option with name "socket_client_gid" is created.
63532+
63533+config GRKERNSEC_SOCKET_SERVER
63534+ bool "Deny server sockets to group"
63535+ depends on GRKERNSEC_SOCKET
63536+ help
63537+ If you say Y here, you will be able to choose a GID of whose users will
63538+ be unable to run server applications from your machine. If the sysctl
63539+ option is enabled, a sysctl option with name "socket_server" is created.
63540+
63541+config GRKERNSEC_SOCKET_SERVER_GID
63542+ int "GID to deny server sockets for"
63543+ depends on GRKERNSEC_SOCKET_SERVER
63544+ default 1002
63545+ help
63546+ Here you can choose the GID to disable server socket access for.
63547+ Remember to add the users you want server socket access disabled for to
63548+ the GID specified here. If the sysctl option is enabled, a sysctl
63549+ option with name "socket_server_gid" is created.
63550+
63551+endmenu
63552+
63553+menu "Physical Protections"
63554+depends on GRKERNSEC
63555+
63556+config GRKERNSEC_DENYUSB
63557+ bool "Deny new USB connections after toggle"
63558+ default y if GRKERNSEC_CONFIG_AUTO
63559+ depends on SYSCTL && USB_SUPPORT
63560+ help
63561+ If you say Y here, a new sysctl option with name "deny_new_usb"
63562+ will be created. Setting its value to 1 will prevent any new
63563+ USB devices from being recognized by the OS. Any attempted USB
63564+ device insertion will be logged. This option is intended to be
63565+ used against custom USB devices designed to exploit vulnerabilities
63566+ in various USB device drivers.
63567+
63568+ For greatest effectiveness, this sysctl should be set after any
63569+ relevant init scripts. This option is safe to enable in distros
63570+ as each user can choose whether or not to toggle the sysctl.
63571+
63572+config GRKERNSEC_DENYUSB_FORCE
63573+ bool "Reject all USB devices not connected at boot"
63574+ select USB
63575+ depends on GRKERNSEC_DENYUSB
63576+ help
63577+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
63578+ that doesn't involve a sysctl entry. This option should only be
63579+ enabled if you're sure you want to deny all new USB connections
63580+ at runtime and don't want to modify init scripts. This should not
63581+ be enabled by distros. It forces the core USB code to be built
63582+ into the kernel image so that all devices connected at boot time
63583+ can be recognized and new USB device connections can be prevented
63584+ prior to init running.
63585+
63586+endmenu
63587+
63588+menu "Sysctl Support"
63589+depends on GRKERNSEC && SYSCTL
63590+
63591+config GRKERNSEC_SYSCTL
63592+ bool "Sysctl support"
63593+ default y if GRKERNSEC_CONFIG_AUTO
63594+ help
63595+ If you say Y here, you will be able to change the options that
63596+ grsecurity runs with at bootup, without having to recompile your
63597+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
63598+ to enable (1) or disable (0) various features. All the sysctl entries
63599+ are mutable until the "grsec_lock" entry is set to a non-zero value.
63600+ All features enabled in the kernel configuration are disabled at boot
63601+ if you do not say Y to the "Turn on features by default" option.
63602+ All options should be set at startup, and the grsec_lock entry should
63603+ be set to a non-zero value after all the options are set.
63604+ *THIS IS EXTREMELY IMPORTANT*
63605+
63606+config GRKERNSEC_SYSCTL_DISTRO
63607+ bool "Extra sysctl support for distro makers (READ HELP)"
63608+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
63609+ help
63610+ If you say Y here, additional sysctl options will be created
63611+ for features that affect processes running as root. Therefore,
63612+ it is critical when using this option that the grsec_lock entry be
63613+ enabled after boot. Only distros with prebuilt kernel packages
63614+ with this option enabled that can ensure grsec_lock is enabled
63615+ after boot should use this option.
63616+ *Failure to set grsec_lock after boot makes all grsec features
63617+ this option covers useless*
63618+
63619+ Currently this option creates the following sysctl entries:
63620+ "Disable Privileged I/O": "disable_priv_io"
63621+
63622+config GRKERNSEC_SYSCTL_ON
63623+ bool "Turn on features by default"
63624+ default y if GRKERNSEC_CONFIG_AUTO
63625+ depends on GRKERNSEC_SYSCTL
63626+ help
63627+ If you say Y here, instead of having all features enabled in the
63628+ kernel configuration disabled at boot time, the features will be
63629+ enabled at boot time. It is recommended you say Y here unless
63630+ there is some reason you would want all sysctl-tunable features to
63631+ be disabled by default. As mentioned elsewhere, it is important
63632+ to enable the grsec_lock entry once you have finished modifying
63633+ the sysctl entries.
63634+
63635+endmenu
63636+menu "Logging Options"
63637+depends on GRKERNSEC
63638+
63639+config GRKERNSEC_FLOODTIME
63640+ int "Seconds in between log messages (minimum)"
63641+ default 10
63642+ help
63643+ This option allows you to enforce the number of seconds between
63644+ grsecurity log messages. The default should be suitable for most
63645+ people, however, if you choose to change it, choose a value small enough
63646+ to allow informative logs to be produced, but large enough to
63647+ prevent flooding.
63648+
63649+config GRKERNSEC_FLOODBURST
63650+ int "Number of messages in a burst (maximum)"
63651+ default 6
63652+ help
63653+ This option allows you to choose the maximum number of messages allowed
63654+ within the flood time interval you chose in a separate option. The
63655+ default should be suitable for most people, however if you find that
63656+ many of your logs are being interpreted as flooding, you may want to
63657+ raise this value.
63658+
63659+endmenu
63660diff --git a/grsecurity/Makefile b/grsecurity/Makefile
63661new file mode 100644
63662index 0000000..85beb79
63663--- /dev/null
63664+++ b/grsecurity/Makefile
63665@@ -0,0 +1,43 @@
63666+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
63667+# during 2001-2009 it has been completely redesigned by Brad Spengler
63668+# into an RBAC system
63669+#
63670+# All code in this directory and various hooks inserted throughout the kernel
63671+# are copyright Brad Spengler - Open Source Security, Inc., and released
63672+# under the GPL v2 or higher
63673+
63674+KBUILD_CFLAGS += -Werror
63675+
63676+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
63677+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
63678+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
63679+ grsec_usb.o grsec_ipc.o
63680+
63681+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
63682+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
63683+ gracl_learn.o grsec_log.o gracl_policy.o
63684+ifdef CONFIG_COMPAT
63685+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
63686+endif
63687+
63688+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
63689+
63690+ifdef CONFIG_NET
63691+obj-y += grsec_sock.o
63692+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
63693+endif
63694+
63695+ifndef CONFIG_GRKERNSEC
63696+obj-y += grsec_disabled.o
63697+endif
63698+
63699+ifdef CONFIG_GRKERNSEC_HIDESYM
63700+extra-y := grsec_hidesym.o
63701+$(obj)/grsec_hidesym.o:
63702+ @-chmod -f 500 /boot
63703+ @-chmod -f 500 /lib/modules
63704+ @-chmod -f 500 /lib64/modules
63705+ @-chmod -f 500 /lib32/modules
63706+ @-chmod -f 700 .
63707+ @echo ' grsec: protected kernel image paths'
63708+endif
63709diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
63710new file mode 100644
63711index 0000000..90f71ce
63712--- /dev/null
63713+++ b/grsecurity/gracl.c
63714@@ -0,0 +1,2679 @@
63715+#include <linux/kernel.h>
63716+#include <linux/module.h>
63717+#include <linux/sched.h>
63718+#include <linux/mm.h>
63719+#include <linux/file.h>
63720+#include <linux/fs.h>
63721+#include <linux/namei.h>
63722+#include <linux/mount.h>
63723+#include <linux/tty.h>
63724+#include <linux/proc_fs.h>
63725+#include <linux/lglock.h>
63726+#include <linux/slab.h>
63727+#include <linux/vmalloc.h>
63728+#include <linux/types.h>
63729+#include <linux/sysctl.h>
63730+#include <linux/netdevice.h>
63731+#include <linux/ptrace.h>
63732+#include <linux/gracl.h>
63733+#include <linux/gralloc.h>
63734+#include <linux/security.h>
63735+#include <linux/grinternal.h>
63736+#include <linux/pid_namespace.h>
63737+#include <linux/stop_machine.h>
63738+#include <linux/fdtable.h>
63739+#include <linux/percpu.h>
63740+#include <linux/lglock.h>
63741+#include <linux/hugetlb.h>
63742+#include <linux/posix-timers.h>
63743+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63744+#include <linux/magic.h>
63745+#include <linux/pagemap.h>
63746+#include "../fs/btrfs/async-thread.h"
63747+#include "../fs/btrfs/ctree.h"
63748+#include "../fs/btrfs/btrfs_inode.h"
63749+#endif
63750+#include "../fs/mount.h"
63751+
63752+#include <asm/uaccess.h>
63753+#include <asm/errno.h>
63754+#include <asm/mman.h>
63755+
63756+#define FOR_EACH_ROLE_START(role) \
63757+ role = running_polstate.role_list; \
63758+ while (role) {
63759+
63760+#define FOR_EACH_ROLE_END(role) \
63761+ role = role->prev; \
63762+ }
63763+
63764+extern struct lglock vfsmount_lock;
63765+
63766+extern struct path gr_real_root;
63767+
63768+static struct gr_policy_state running_polstate;
63769+struct gr_policy_state *polstate = &running_polstate;
63770+extern struct gr_alloc_state *current_alloc_state;
63771+
63772+extern char *gr_shared_page[4];
63773+DEFINE_RWLOCK(gr_inode_lock);
63774+
63775+static unsigned int gr_status __read_only = GR_STATUS_INIT;
63776+
63777+#ifdef CONFIG_NET
63778+extern struct vfsmount *sock_mnt;
63779+#endif
63780+
63781+extern struct vfsmount *pipe_mnt;
63782+extern struct vfsmount *shm_mnt;
63783+
63784+#ifdef CONFIG_HUGETLBFS
63785+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63786+#endif
63787+
63788+extern u16 acl_sp_role_value;
63789+extern struct acl_object_label *fakefs_obj_rw;
63790+extern struct acl_object_label *fakefs_obj_rwx;
63791+
63792+int gr_acl_is_enabled(void)
63793+{
63794+ return (gr_status & GR_READY);
63795+}
63796+
63797+void gr_enable_rbac_system(void)
63798+{
63799+ pax_open_kernel();
63800+ gr_status |= GR_READY;
63801+ pax_close_kernel();
63802+}
63803+
63804+int gr_rbac_disable(void *unused)
63805+{
63806+ pax_open_kernel();
63807+ gr_status &= ~GR_READY;
63808+ pax_close_kernel();
63809+
63810+ return 0;
63811+}
63812+
63813+static inline dev_t __get_dev(const struct dentry *dentry)
63814+{
63815+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63816+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63817+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63818+ else
63819+#endif
63820+ return dentry->d_sb->s_dev;
63821+}
63822+
63823+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63824+{
63825+ return __get_dev(dentry);
63826+}
63827+
63828+static char gr_task_roletype_to_char(struct task_struct *task)
63829+{
63830+ switch (task->role->roletype &
63831+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
63832+ GR_ROLE_SPECIAL)) {
63833+ case GR_ROLE_DEFAULT:
63834+ return 'D';
63835+ case GR_ROLE_USER:
63836+ return 'U';
63837+ case GR_ROLE_GROUP:
63838+ return 'G';
63839+ case GR_ROLE_SPECIAL:
63840+ return 'S';
63841+ }
63842+
63843+ return 'X';
63844+}
63845+
63846+char gr_roletype_to_char(void)
63847+{
63848+ return gr_task_roletype_to_char(current);
63849+}
63850+
63851+__inline__ int
63852+gr_acl_tpe_check(void)
63853+{
63854+ if (unlikely(!(gr_status & GR_READY)))
63855+ return 0;
63856+ if (current->role->roletype & GR_ROLE_TPE)
63857+ return 1;
63858+ else
63859+ return 0;
63860+}
63861+
63862+int
63863+gr_handle_rawio(const struct inode *inode)
63864+{
63865+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63866+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
63867+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
63868+ !capable(CAP_SYS_RAWIO))
63869+ return 1;
63870+#endif
63871+ return 0;
63872+}
63873+
63874+int
63875+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
63876+{
63877+ if (likely(lena != lenb))
63878+ return 0;
63879+
63880+ return !memcmp(a, b, lena);
63881+}
63882+
63883+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
63884+{
63885+ *buflen -= namelen;
63886+ if (*buflen < 0)
63887+ return -ENAMETOOLONG;
63888+ *buffer -= namelen;
63889+ memcpy(*buffer, str, namelen);
63890+ return 0;
63891+}
63892+
63893+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
63894+{
63895+ return prepend(buffer, buflen, name->name, name->len);
63896+}
63897+
63898+static int prepend_path(const struct path *path, struct path *root,
63899+ char **buffer, int *buflen)
63900+{
63901+ struct dentry *dentry = path->dentry;
63902+ struct vfsmount *vfsmnt = path->mnt;
63903+ struct mount *mnt = real_mount(vfsmnt);
63904+ bool slash = false;
63905+ int error = 0;
63906+
63907+ while (dentry != root->dentry || vfsmnt != root->mnt) {
63908+ struct dentry * parent;
63909+
63910+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
63911+ /* Global root? */
63912+ if (!mnt_has_parent(mnt)) {
63913+ goto out;
63914+ }
63915+ dentry = mnt->mnt_mountpoint;
63916+ mnt = mnt->mnt_parent;
63917+ vfsmnt = &mnt->mnt;
63918+ continue;
63919+ }
63920+ parent = dentry->d_parent;
63921+ prefetch(parent);
63922+ spin_lock(&dentry->d_lock);
63923+ error = prepend_name(buffer, buflen, &dentry->d_name);
63924+ spin_unlock(&dentry->d_lock);
63925+ if (!error)
63926+ error = prepend(buffer, buflen, "/", 1);
63927+ if (error)
63928+ break;
63929+
63930+ slash = true;
63931+ dentry = parent;
63932+ }
63933+
63934+out:
63935+ if (!error && !slash)
63936+ error = prepend(buffer, buflen, "/", 1);
63937+
63938+ return error;
63939+}
63940+
63941+/* this must be called with vfsmount_lock and rename_lock held */
63942+
63943+static char *__our_d_path(const struct path *path, struct path *root,
63944+ char *buf, int buflen)
63945+{
63946+ char *res = buf + buflen;
63947+ int error;
63948+
63949+ prepend(&res, &buflen, "\0", 1);
63950+ error = prepend_path(path, root, &res, &buflen);
63951+ if (error)
63952+ return ERR_PTR(error);
63953+
63954+ return res;
63955+}
63956+
63957+static char *
63958+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
63959+{
63960+ char *retval;
63961+
63962+ retval = __our_d_path(path, root, buf, buflen);
63963+ if (unlikely(IS_ERR(retval)))
63964+ retval = strcpy(buf, "<path too long>");
63965+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
63966+ retval[1] = '\0';
63967+
63968+ return retval;
63969+}
63970+
63971+static char *
63972+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63973+ char *buf, int buflen)
63974+{
63975+ struct path path;
63976+ char *res;
63977+
63978+ path.dentry = (struct dentry *)dentry;
63979+ path.mnt = (struct vfsmount *)vfsmnt;
63980+
63981+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
63982+ by the RBAC system */
63983+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
63984+
63985+ return res;
63986+}
63987+
63988+static char *
63989+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63990+ char *buf, int buflen)
63991+{
63992+ char *res;
63993+ struct path path;
63994+ struct path root;
63995+ struct task_struct *reaper = init_pid_ns.child_reaper;
63996+
63997+ path.dentry = (struct dentry *)dentry;
63998+ path.mnt = (struct vfsmount *)vfsmnt;
63999+
64000+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
64001+ get_fs_root(reaper->fs, &root);
64002+
64003+ br_read_lock(&vfsmount_lock);
64004+ write_seqlock(&rename_lock);
64005+ res = gen_full_path(&path, &root, buf, buflen);
64006+ write_sequnlock(&rename_lock);
64007+ br_read_unlock(&vfsmount_lock);
64008+
64009+ path_put(&root);
64010+ return res;
64011+}
64012+
64013+char *
64014+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
64015+{
64016+ char *ret;
64017+ br_read_lock(&vfsmount_lock);
64018+ write_seqlock(&rename_lock);
64019+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
64020+ PAGE_SIZE);
64021+ write_sequnlock(&rename_lock);
64022+ br_read_unlock(&vfsmount_lock);
64023+ return ret;
64024+}
64025+
64026+static char *
64027+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
64028+{
64029+ char *ret;
64030+ char *buf;
64031+ int buflen;
64032+
64033+ br_read_lock(&vfsmount_lock);
64034+ write_seqlock(&rename_lock);
64035+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
64036+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
64037+ buflen = (int)(ret - buf);
64038+ if (buflen >= 5)
64039+ prepend(&ret, &buflen, "/proc", 5);
64040+ else
64041+ ret = strcpy(buf, "<path too long>");
64042+ write_sequnlock(&rename_lock);
64043+ br_read_unlock(&vfsmount_lock);
64044+ return ret;
64045+}
64046+
64047+char *
64048+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
64049+{
64050+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
64051+ PAGE_SIZE);
64052+}
64053+
64054+char *
64055+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
64056+{
64057+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
64058+ PAGE_SIZE);
64059+}
64060+
64061+char *
64062+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
64063+{
64064+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
64065+ PAGE_SIZE);
64066+}
64067+
64068+char *
64069+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
64070+{
64071+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
64072+ PAGE_SIZE);
64073+}
64074+
64075+char *
64076+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
64077+{
64078+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
64079+ PAGE_SIZE);
64080+}
64081+
64082+__inline__ __u32
64083+to_gr_audit(const __u32 reqmode)
64084+{
64085+ /* masks off auditable permission flags, then shifts them to create
64086+ auditing flags, and adds the special case of append auditing if
64087+ we're requesting write */
64088+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
64089+}
64090+
64091+struct acl_role_label *
64092+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
64093+ const gid_t gid)
64094+{
64095+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
64096+ struct acl_role_label *match;
64097+ struct role_allowed_ip *ipp;
64098+ unsigned int x;
64099+ u32 curr_ip = task->signal->saved_ip;
64100+
64101+ match = state->acl_role_set.r_hash[index];
64102+
64103+ while (match) {
64104+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
64105+ for (x = 0; x < match->domain_child_num; x++) {
64106+ if (match->domain_children[x] == uid)
64107+ goto found;
64108+ }
64109+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
64110+ break;
64111+ match = match->next;
64112+ }
64113+found:
64114+ if (match == NULL) {
64115+ try_group:
64116+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
64117+ match = state->acl_role_set.r_hash[index];
64118+
64119+ while (match) {
64120+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
64121+ for (x = 0; x < match->domain_child_num; x++) {
64122+ if (match->domain_children[x] == gid)
64123+ goto found2;
64124+ }
64125+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
64126+ break;
64127+ match = match->next;
64128+ }
64129+found2:
64130+ if (match == NULL)
64131+ match = state->default_role;
64132+ if (match->allowed_ips == NULL)
64133+ return match;
64134+ else {
64135+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64136+ if (likely
64137+ ((ntohl(curr_ip) & ipp->netmask) ==
64138+ (ntohl(ipp->addr) & ipp->netmask)))
64139+ return match;
64140+ }
64141+ match = state->default_role;
64142+ }
64143+ } else if (match->allowed_ips == NULL) {
64144+ return match;
64145+ } else {
64146+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64147+ if (likely
64148+ ((ntohl(curr_ip) & ipp->netmask) ==
64149+ (ntohl(ipp->addr) & ipp->netmask)))
64150+ return match;
64151+ }
64152+ goto try_group;
64153+ }
64154+
64155+ return match;
64156+}
64157+
64158+static struct acl_role_label *
64159+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
64160+ const gid_t gid)
64161+{
64162+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
64163+}
64164+
64165+struct acl_subject_label *
64166+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
64167+ const struct acl_role_label *role)
64168+{
64169+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64170+ struct acl_subject_label *match;
64171+
64172+ match = role->subj_hash[index];
64173+
64174+ while (match && (match->inode != ino || match->device != dev ||
64175+ (match->mode & GR_DELETED))) {
64176+ match = match->next;
64177+ }
64178+
64179+ if (match && !(match->mode & GR_DELETED))
64180+ return match;
64181+ else
64182+ return NULL;
64183+}
64184+
64185+struct acl_subject_label *
64186+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
64187+ const struct acl_role_label *role)
64188+{
64189+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64190+ struct acl_subject_label *match;
64191+
64192+ match = role->subj_hash[index];
64193+
64194+ while (match && (match->inode != ino || match->device != dev ||
64195+ !(match->mode & GR_DELETED))) {
64196+ match = match->next;
64197+ }
64198+
64199+ if (match && (match->mode & GR_DELETED))
64200+ return match;
64201+ else
64202+ return NULL;
64203+}
64204+
64205+static struct acl_object_label *
64206+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
64207+ const struct acl_subject_label *subj)
64208+{
64209+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64210+ struct acl_object_label *match;
64211+
64212+ match = subj->obj_hash[index];
64213+
64214+ while (match && (match->inode != ino || match->device != dev ||
64215+ (match->mode & GR_DELETED))) {
64216+ match = match->next;
64217+ }
64218+
64219+ if (match && !(match->mode & GR_DELETED))
64220+ return match;
64221+ else
64222+ return NULL;
64223+}
64224+
64225+static struct acl_object_label *
64226+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
64227+ const struct acl_subject_label *subj)
64228+{
64229+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64230+ struct acl_object_label *match;
64231+
64232+ match = subj->obj_hash[index];
64233+
64234+ while (match && (match->inode != ino || match->device != dev ||
64235+ !(match->mode & GR_DELETED))) {
64236+ match = match->next;
64237+ }
64238+
64239+ if (match && (match->mode & GR_DELETED))
64240+ return match;
64241+
64242+ match = subj->obj_hash[index];
64243+
64244+ while (match && (match->inode != ino || match->device != dev ||
64245+ (match->mode & GR_DELETED))) {
64246+ match = match->next;
64247+ }
64248+
64249+ if (match && !(match->mode & GR_DELETED))
64250+ return match;
64251+ else
64252+ return NULL;
64253+}
64254+
64255+struct name_entry *
64256+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
64257+{
64258+ unsigned int len = strlen(name);
64259+ unsigned int key = full_name_hash(name, len);
64260+ unsigned int index = key % state->name_set.n_size;
64261+ struct name_entry *match;
64262+
64263+ match = state->name_set.n_hash[index];
64264+
64265+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
64266+ match = match->next;
64267+
64268+ return match;
64269+}
64270+
64271+static struct name_entry *
64272+lookup_name_entry(const char *name)
64273+{
64274+ return __lookup_name_entry(&running_polstate, name);
64275+}
64276+
64277+static struct name_entry *
64278+lookup_name_entry_create(const char *name)
64279+{
64280+ unsigned int len = strlen(name);
64281+ unsigned int key = full_name_hash(name, len);
64282+ unsigned int index = key % running_polstate.name_set.n_size;
64283+ struct name_entry *match;
64284+
64285+ match = running_polstate.name_set.n_hash[index];
64286+
64287+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64288+ !match->deleted))
64289+ match = match->next;
64290+
64291+ if (match && match->deleted)
64292+ return match;
64293+
64294+ match = running_polstate.name_set.n_hash[index];
64295+
64296+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64297+ match->deleted))
64298+ match = match->next;
64299+
64300+ if (match && !match->deleted)
64301+ return match;
64302+ else
64303+ return NULL;
64304+}
64305+
64306+static struct inodev_entry *
64307+lookup_inodev_entry(const ino_t ino, const dev_t dev)
64308+{
64309+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
64310+ struct inodev_entry *match;
64311+
64312+ match = running_polstate.inodev_set.i_hash[index];
64313+
64314+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
64315+ match = match->next;
64316+
64317+ return match;
64318+}
64319+
64320+void
64321+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
64322+{
64323+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
64324+ state->inodev_set.i_size);
64325+ struct inodev_entry **curr;
64326+
64327+ entry->prev = NULL;
64328+
64329+ curr = &state->inodev_set.i_hash[index];
64330+ if (*curr != NULL)
64331+ (*curr)->prev = entry;
64332+
64333+ entry->next = *curr;
64334+ *curr = entry;
64335+
64336+ return;
64337+}
64338+
64339+static void
64340+insert_inodev_entry(struct inodev_entry *entry)
64341+{
64342+ __insert_inodev_entry(&running_polstate, entry);
64343+}
64344+
64345+void
64346+insert_acl_obj_label(struct acl_object_label *obj,
64347+ struct acl_subject_label *subj)
64348+{
64349+ unsigned int index =
64350+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
64351+ struct acl_object_label **curr;
64352+
64353+ obj->prev = NULL;
64354+
64355+ curr = &subj->obj_hash[index];
64356+ if (*curr != NULL)
64357+ (*curr)->prev = obj;
64358+
64359+ obj->next = *curr;
64360+ *curr = obj;
64361+
64362+ return;
64363+}
64364+
64365+void
64366+insert_acl_subj_label(struct acl_subject_label *obj,
64367+ struct acl_role_label *role)
64368+{
64369+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
64370+ struct acl_subject_label **curr;
64371+
64372+ obj->prev = NULL;
64373+
64374+ curr = &role->subj_hash[index];
64375+ if (*curr != NULL)
64376+ (*curr)->prev = obj;
64377+
64378+ obj->next = *curr;
64379+ *curr = obj;
64380+
64381+ return;
64382+}
64383+
64384+/* derived from glibc fnmatch() 0: match, 1: no match*/
64385+
64386+static int
64387+glob_match(const char *p, const char *n)
64388+{
64389+ char c;
64390+
64391+ while ((c = *p++) != '\0') {
64392+ switch (c) {
64393+ case '?':
64394+ if (*n == '\0')
64395+ return 1;
64396+ else if (*n == '/')
64397+ return 1;
64398+ break;
64399+ case '\\':
64400+ if (*n != c)
64401+ return 1;
64402+ break;
64403+ case '*':
64404+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
64405+ if (*n == '/')
64406+ return 1;
64407+ else if (c == '?') {
64408+ if (*n == '\0')
64409+ return 1;
64410+ else
64411+ ++n;
64412+ }
64413+ }
64414+ if (c == '\0') {
64415+ return 0;
64416+ } else {
64417+ const char *endp;
64418+
64419+ if ((endp = strchr(n, '/')) == NULL)
64420+ endp = n + strlen(n);
64421+
64422+ if (c == '[') {
64423+ for (--p; n < endp; ++n)
64424+ if (!glob_match(p, n))
64425+ return 0;
64426+ } else if (c == '/') {
64427+ while (*n != '\0' && *n != '/')
64428+ ++n;
64429+ if (*n == '/' && !glob_match(p, n + 1))
64430+ return 0;
64431+ } else {
64432+ for (--p; n < endp; ++n)
64433+ if (*n == c && !glob_match(p, n))
64434+ return 0;
64435+ }
64436+
64437+ return 1;
64438+ }
64439+ case '[':
64440+ {
64441+ int not;
64442+ char cold;
64443+
64444+ if (*n == '\0' || *n == '/')
64445+ return 1;
64446+
64447+ not = (*p == '!' || *p == '^');
64448+ if (not)
64449+ ++p;
64450+
64451+ c = *p++;
64452+ for (;;) {
64453+ unsigned char fn = (unsigned char)*n;
64454+
64455+ if (c == '\0')
64456+ return 1;
64457+ else {
64458+ if (c == fn)
64459+ goto matched;
64460+ cold = c;
64461+ c = *p++;
64462+
64463+ if (c == '-' && *p != ']') {
64464+ unsigned char cend = *p++;
64465+
64466+ if (cend == '\0')
64467+ return 1;
64468+
64469+ if (cold <= fn && fn <= cend)
64470+ goto matched;
64471+
64472+ c = *p++;
64473+ }
64474+ }
64475+
64476+ if (c == ']')
64477+ break;
64478+ }
64479+ if (!not)
64480+ return 1;
64481+ break;
64482+ matched:
64483+ while (c != ']') {
64484+ if (c == '\0')
64485+ return 1;
64486+
64487+ c = *p++;
64488+ }
64489+ if (not)
64490+ return 1;
64491+ }
64492+ break;
64493+ default:
64494+ if (c != *n)
64495+ return 1;
64496+ }
64497+
64498+ ++n;
64499+ }
64500+
64501+ if (*n == '\0')
64502+ return 0;
64503+
64504+ if (*n == '/')
64505+ return 0;
64506+
64507+ return 1;
64508+}
64509+
64510+static struct acl_object_label *
64511+chk_glob_label(struct acl_object_label *globbed,
64512+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64513+{
64514+ struct acl_object_label *tmp;
64515+
64516+ if (*path == NULL)
64517+ *path = gr_to_filename_nolock(dentry, mnt);
64518+
64519+ tmp = globbed;
64520+
64521+ while (tmp) {
64522+ if (!glob_match(tmp->filename, *path))
64523+ return tmp;
64524+ tmp = tmp->next;
64525+ }
64526+
64527+ return NULL;
64528+}
64529+
64530+static struct acl_object_label *
64531+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64532+ const ino_t curr_ino, const dev_t curr_dev,
64533+ const struct acl_subject_label *subj, char **path, const int checkglob)
64534+{
64535+ struct acl_subject_label *tmpsubj;
64536+ struct acl_object_label *retval;
64537+ struct acl_object_label *retval2;
64538+
64539+ tmpsubj = (struct acl_subject_label *) subj;
64540+ read_lock(&gr_inode_lock);
64541+ do {
64542+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64543+ if (retval) {
64544+ if (checkglob && retval->globbed) {
64545+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64546+ if (retval2)
64547+ retval = retval2;
64548+ }
64549+ break;
64550+ }
64551+ } while ((tmpsubj = tmpsubj->parent_subject));
64552+ read_unlock(&gr_inode_lock);
64553+
64554+ return retval;
64555+}
64556+
64557+static __inline__ struct acl_object_label *
64558+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64559+ struct dentry *curr_dentry,
64560+ const struct acl_subject_label *subj, char **path, const int checkglob)
64561+{
64562+ int newglob = checkglob;
64563+ ino_t inode;
64564+ dev_t device;
64565+
64566+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64567+ as we don't want a / * rule to match instead of the / object
64568+ don't do this for create lookups that call this function though, since they're looking up
64569+ on the parent and thus need globbing checks on all paths
64570+ */
64571+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64572+ newglob = GR_NO_GLOB;
64573+
64574+ spin_lock(&curr_dentry->d_lock);
64575+ inode = curr_dentry->d_inode->i_ino;
64576+ device = __get_dev(curr_dentry);
64577+ spin_unlock(&curr_dentry->d_lock);
64578+
64579+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64580+}
64581+
64582+#ifdef CONFIG_HUGETLBFS
64583+static inline bool
64584+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64585+{
64586+ int i;
64587+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64588+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64589+ return true;
64590+ }
64591+
64592+ return false;
64593+}
64594+#endif
64595+
64596+static struct acl_object_label *
64597+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64598+ const struct acl_subject_label *subj, char *path, const int checkglob)
64599+{
64600+ struct dentry *dentry = (struct dentry *) l_dentry;
64601+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64602+ struct mount *real_mnt = real_mount(mnt);
64603+ struct acl_object_label *retval;
64604+ struct dentry *parent;
64605+
64606+ br_read_lock(&vfsmount_lock);
64607+ write_seqlock(&rename_lock);
64608+
64609+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64610+#ifdef CONFIG_NET
64611+ mnt == sock_mnt ||
64612+#endif
64613+#ifdef CONFIG_HUGETLBFS
64614+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64615+#endif
64616+ /* ignore Eric Biederman */
64617+ IS_PRIVATE(l_dentry->d_inode))) {
64618+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64619+ goto out;
64620+ }
64621+
64622+ for (;;) {
64623+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
64624+ break;
64625+
64626+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64627+ if (!mnt_has_parent(real_mnt))
64628+ break;
64629+
64630+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64631+ if (retval != NULL)
64632+ goto out;
64633+
64634+ dentry = real_mnt->mnt_mountpoint;
64635+ real_mnt = real_mnt->mnt_parent;
64636+ mnt = &real_mnt->mnt;
64637+ continue;
64638+ }
64639+
64640+ parent = dentry->d_parent;
64641+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64642+ if (retval != NULL)
64643+ goto out;
64644+
64645+ dentry = parent;
64646+ }
64647+
64648+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64649+
64650+ /* gr_real_root is pinned so we don't have to hold a reference */
64651+ if (retval == NULL)
64652+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
64653+out:
64654+ write_sequnlock(&rename_lock);
64655+ br_read_unlock(&vfsmount_lock);
64656+
64657+ BUG_ON(retval == NULL);
64658+
64659+ return retval;
64660+}
64661+
64662+static __inline__ struct acl_object_label *
64663+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64664+ const struct acl_subject_label *subj)
64665+{
64666+ char *path = NULL;
64667+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64668+}
64669+
64670+static __inline__ struct acl_object_label *
64671+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64672+ const struct acl_subject_label *subj)
64673+{
64674+ char *path = NULL;
64675+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64676+}
64677+
64678+static __inline__ struct acl_object_label *
64679+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64680+ const struct acl_subject_label *subj, char *path)
64681+{
64682+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64683+}
64684+
64685+struct acl_subject_label *
64686+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64687+ const struct acl_role_label *role)
64688+{
64689+ struct dentry *dentry = (struct dentry *) l_dentry;
64690+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64691+ struct mount *real_mnt = real_mount(mnt);
64692+ struct acl_subject_label *retval;
64693+ struct dentry *parent;
64694+
64695+ br_read_lock(&vfsmount_lock);
64696+ write_seqlock(&rename_lock);
64697+
64698+ for (;;) {
64699+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
64700+ break;
64701+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64702+ if (!mnt_has_parent(real_mnt))
64703+ break;
64704+
64705+ spin_lock(&dentry->d_lock);
64706+ read_lock(&gr_inode_lock);
64707+ retval =
64708+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64709+ __get_dev(dentry), role);
64710+ read_unlock(&gr_inode_lock);
64711+ spin_unlock(&dentry->d_lock);
64712+ if (retval != NULL)
64713+ goto out;
64714+
64715+ dentry = real_mnt->mnt_mountpoint;
64716+ real_mnt = real_mnt->mnt_parent;
64717+ mnt = &real_mnt->mnt;
64718+ continue;
64719+ }
64720+
64721+ spin_lock(&dentry->d_lock);
64722+ read_lock(&gr_inode_lock);
64723+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64724+ __get_dev(dentry), role);
64725+ read_unlock(&gr_inode_lock);
64726+ parent = dentry->d_parent;
64727+ spin_unlock(&dentry->d_lock);
64728+
64729+ if (retval != NULL)
64730+ goto out;
64731+
64732+ dentry = parent;
64733+ }
64734+
64735+ spin_lock(&dentry->d_lock);
64736+ read_lock(&gr_inode_lock);
64737+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64738+ __get_dev(dentry), role);
64739+ read_unlock(&gr_inode_lock);
64740+ spin_unlock(&dentry->d_lock);
64741+
64742+ if (unlikely(retval == NULL)) {
64743+ /* gr_real_root is pinned, we don't need to hold a reference */
64744+ read_lock(&gr_inode_lock);
64745+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
64746+ __get_dev(gr_real_root.dentry), role);
64747+ read_unlock(&gr_inode_lock);
64748+ }
64749+out:
64750+ write_sequnlock(&rename_lock);
64751+ br_read_unlock(&vfsmount_lock);
64752+
64753+ BUG_ON(retval == NULL);
64754+
64755+ return retval;
64756+}
64757+
64758+void
64759+assign_special_role(const char *rolename)
64760+{
64761+ struct acl_object_label *obj;
64762+ struct acl_role_label *r;
64763+ struct acl_role_label *assigned = NULL;
64764+ struct task_struct *tsk;
64765+ struct file *filp;
64766+
64767+ FOR_EACH_ROLE_START(r)
64768+ if (!strcmp(rolename, r->rolename) &&
64769+ (r->roletype & GR_ROLE_SPECIAL)) {
64770+ assigned = r;
64771+ break;
64772+ }
64773+ FOR_EACH_ROLE_END(r)
64774+
64775+ if (!assigned)
64776+ return;
64777+
64778+ read_lock(&tasklist_lock);
64779+ read_lock(&grsec_exec_file_lock);
64780+
64781+ tsk = current->real_parent;
64782+ if (tsk == NULL)
64783+ goto out_unlock;
64784+
64785+ filp = tsk->exec_file;
64786+ if (filp == NULL)
64787+ goto out_unlock;
64788+
64789+ tsk->is_writable = 0;
64790+ tsk->inherited = 0;
64791+
64792+ tsk->acl_sp_role = 1;
64793+ tsk->acl_role_id = ++acl_sp_role_value;
64794+ tsk->role = assigned;
64795+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
64796+
64797+ /* ignore additional mmap checks for processes that are writable
64798+ by the default ACL */
64799+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
64800+ if (unlikely(obj->mode & GR_WRITE))
64801+ tsk->is_writable = 1;
64802+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
64803+ if (unlikely(obj->mode & GR_WRITE))
64804+ tsk->is_writable = 1;
64805+
64806+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64807+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
64808+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
64809+#endif
64810+
64811+out_unlock:
64812+ read_unlock(&grsec_exec_file_lock);
64813+ read_unlock(&tasklist_lock);
64814+ return;
64815+}
64816+
64817+
64818+static void
64819+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64820+{
64821+ struct task_struct *task = current;
64822+ const struct cred *cred = current_cred();
64823+
64824+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64825+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64826+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64827+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64828+
64829+ return;
64830+}
64831+
64832+static void
64833+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64834+{
64835+ struct task_struct *task = current;
64836+ const struct cred *cred = current_cred();
64837+
64838+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64839+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64840+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64841+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64842+
64843+ return;
64844+}
64845+
64846+static void
64847+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64848+{
64849+ struct task_struct *task = current;
64850+ const struct cred *cred = current_cred();
64851+
64852+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64853+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64854+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64855+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64856+
64857+ return;
64858+}
64859+
64860+static void
64861+gr_set_proc_res(struct task_struct *task)
64862+{
64863+ struct acl_subject_label *proc;
64864+ unsigned short i;
64865+
64866+ proc = task->acl;
64867+
64868+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64869+ return;
64870+
64871+ for (i = 0; i < RLIM_NLIMITS; i++) {
64872+ if (!(proc->resmask & (1U << i)))
64873+ continue;
64874+
64875+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64876+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64877+
64878+ if (i == RLIMIT_CPU)
64879+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64880+ }
64881+
64882+ return;
64883+}
64884+
64885+/* both of the below must be called with
64886+ rcu_read_lock();
64887+ read_lock(&tasklist_lock);
64888+ read_lock(&grsec_exec_file_lock);
64889+*/
64890+
64891+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
64892+{
64893+ char *tmpname;
64894+ struct acl_subject_label *tmpsubj;
64895+ struct file *filp;
64896+ struct name_entry *nmatch;
64897+
64898+ filp = task->exec_file;
64899+ if (filp == NULL)
64900+ return NULL;
64901+
64902+ /* the following is to apply the correct subject
64903+ on binaries running when the RBAC system
64904+ is enabled, when the binaries have been
64905+ replaced or deleted since their execution
64906+ -----
64907+ when the RBAC system starts, the inode/dev
64908+ from exec_file will be one the RBAC system
64909+ is unaware of. It only knows the inode/dev
64910+ of the present file on disk, or the absence
64911+ of it.
64912+ */
64913+
64914+ if (filename)
64915+ nmatch = __lookup_name_entry(state, filename);
64916+ else {
64917+ preempt_disable();
64918+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
64919+
64920+ nmatch = __lookup_name_entry(state, tmpname);
64921+ preempt_enable();
64922+ }
64923+ tmpsubj = NULL;
64924+ if (nmatch) {
64925+ if (nmatch->deleted)
64926+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
64927+ else
64928+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
64929+ }
64930+ /* this also works for the reload case -- if we don't match a potentially inherited subject
64931+ then we fall back to a normal lookup based on the binary's ino/dev
64932+ */
64933+ if (tmpsubj == NULL)
64934+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
64935+
64936+ return tmpsubj;
64937+}
64938+
64939+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
64940+{
64941+ return __gr_get_subject_for_task(&running_polstate, task, filename);
64942+}
64943+
64944+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
64945+{
64946+ struct acl_object_label *obj;
64947+ struct file *filp;
64948+
64949+ filp = task->exec_file;
64950+
64951+ task->acl = subj;
64952+ task->is_writable = 0;
64953+ /* ignore additional mmap checks for processes that are writable
64954+ by the default ACL */
64955+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
64956+ if (unlikely(obj->mode & GR_WRITE))
64957+ task->is_writable = 1;
64958+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64959+ if (unlikely(obj->mode & GR_WRITE))
64960+ task->is_writable = 1;
64961+
64962+ gr_set_proc_res(task);
64963+
64964+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64965+ 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);
64966+#endif
64967+}
64968+
64969+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
64970+{
64971+ __gr_apply_subject_to_task(&running_polstate, task, subj);
64972+}
64973+
64974+__u32
64975+gr_search_file(const struct dentry * dentry, const __u32 mode,
64976+ const struct vfsmount * mnt)
64977+{
64978+ __u32 retval = mode;
64979+ struct acl_subject_label *curracl;
64980+ struct acl_object_label *currobj;
64981+
64982+ if (unlikely(!(gr_status & GR_READY)))
64983+ return (mode & ~GR_AUDITS);
64984+
64985+ curracl = current->acl;
64986+
64987+ currobj = chk_obj_label(dentry, mnt, curracl);
64988+ retval = currobj->mode & mode;
64989+
64990+ /* if we're opening a specified transfer file for writing
64991+ (e.g. /dev/initctl), then transfer our role to init
64992+ */
64993+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64994+ current->role->roletype & GR_ROLE_PERSIST)) {
64995+ struct task_struct *task = init_pid_ns.child_reaper;
64996+
64997+ if (task->role != current->role) {
64998+ struct acl_subject_label *subj;
64999+
65000+ task->acl_sp_role = 0;
65001+ task->acl_role_id = current->acl_role_id;
65002+ task->role = current->role;
65003+ rcu_read_lock();
65004+ read_lock(&grsec_exec_file_lock);
65005+ subj = gr_get_subject_for_task(task, NULL);
65006+ gr_apply_subject_to_task(task, subj);
65007+ read_unlock(&grsec_exec_file_lock);
65008+ rcu_read_unlock();
65009+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
65010+ }
65011+ }
65012+
65013+ if (unlikely
65014+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
65015+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
65016+ __u32 new_mode = mode;
65017+
65018+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
65019+
65020+ retval = new_mode;
65021+
65022+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
65023+ new_mode |= GR_INHERIT;
65024+
65025+ if (!(mode & GR_NOLEARN))
65026+ gr_log_learn(dentry, mnt, new_mode);
65027+ }
65028+
65029+ return retval;
65030+}
65031+
65032+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
65033+ const struct dentry *parent,
65034+ const struct vfsmount *mnt)
65035+{
65036+ struct name_entry *match;
65037+ struct acl_object_label *matchpo;
65038+ struct acl_subject_label *curracl;
65039+ char *path;
65040+
65041+ if (unlikely(!(gr_status & GR_READY)))
65042+ return NULL;
65043+
65044+ preempt_disable();
65045+ path = gr_to_filename_rbac(new_dentry, mnt);
65046+ match = lookup_name_entry_create(path);
65047+
65048+ curracl = current->acl;
65049+
65050+ if (match) {
65051+ read_lock(&gr_inode_lock);
65052+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
65053+ read_unlock(&gr_inode_lock);
65054+
65055+ if (matchpo) {
65056+ preempt_enable();
65057+ return matchpo;
65058+ }
65059+ }
65060+
65061+ // lookup parent
65062+
65063+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
65064+
65065+ preempt_enable();
65066+ return matchpo;
65067+}
65068+
65069+__u32
65070+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
65071+ const struct vfsmount * mnt, const __u32 mode)
65072+{
65073+ struct acl_object_label *matchpo;
65074+ __u32 retval;
65075+
65076+ if (unlikely(!(gr_status & GR_READY)))
65077+ return (mode & ~GR_AUDITS);
65078+
65079+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
65080+
65081+ retval = matchpo->mode & mode;
65082+
65083+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
65084+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65085+ __u32 new_mode = mode;
65086+
65087+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
65088+
65089+ gr_log_learn(new_dentry, mnt, new_mode);
65090+ return new_mode;
65091+ }
65092+
65093+ return retval;
65094+}
65095+
65096+__u32
65097+gr_check_link(const struct dentry * new_dentry,
65098+ const struct dentry * parent_dentry,
65099+ const struct vfsmount * parent_mnt,
65100+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
65101+{
65102+ struct acl_object_label *obj;
65103+ __u32 oldmode, newmode;
65104+ __u32 needmode;
65105+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
65106+ GR_DELETE | GR_INHERIT;
65107+
65108+ if (unlikely(!(gr_status & GR_READY)))
65109+ return (GR_CREATE | GR_LINK);
65110+
65111+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
65112+ oldmode = obj->mode;
65113+
65114+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
65115+ newmode = obj->mode;
65116+
65117+ needmode = newmode & checkmodes;
65118+
65119+ // old name for hardlink must have at least the permissions of the new name
65120+ if ((oldmode & needmode) != needmode)
65121+ goto bad;
65122+
65123+ // if old name had restrictions/auditing, make sure the new name does as well
65124+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
65125+
65126+ // don't allow hardlinking of suid/sgid/fcapped files without permission
65127+ if (is_privileged_binary(old_dentry))
65128+ needmode |= GR_SETID;
65129+
65130+ if ((newmode & needmode) != needmode)
65131+ goto bad;
65132+
65133+ // enforce minimum permissions
65134+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
65135+ return newmode;
65136+bad:
65137+ needmode = oldmode;
65138+ if (is_privileged_binary(old_dentry))
65139+ needmode |= GR_SETID;
65140+
65141+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
65142+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
65143+ return (GR_CREATE | GR_LINK);
65144+ } else if (newmode & GR_SUPPRESS)
65145+ return GR_SUPPRESS;
65146+ else
65147+ return 0;
65148+}
65149+
65150+int
65151+gr_check_hidden_task(const struct task_struct *task)
65152+{
65153+ if (unlikely(!(gr_status & GR_READY)))
65154+ return 0;
65155+
65156+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
65157+ return 1;
65158+
65159+ return 0;
65160+}
65161+
65162+int
65163+gr_check_protected_task(const struct task_struct *task)
65164+{
65165+ if (unlikely(!(gr_status & GR_READY) || !task))
65166+ return 0;
65167+
65168+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65169+ task->acl != current->acl)
65170+ return 1;
65171+
65172+ return 0;
65173+}
65174+
65175+int
65176+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
65177+{
65178+ struct task_struct *p;
65179+ int ret = 0;
65180+
65181+ if (unlikely(!(gr_status & GR_READY) || !pid))
65182+ return ret;
65183+
65184+ read_lock(&tasklist_lock);
65185+ do_each_pid_task(pid, type, p) {
65186+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65187+ p->acl != current->acl) {
65188+ ret = 1;
65189+ goto out;
65190+ }
65191+ } while_each_pid_task(pid, type, p);
65192+out:
65193+ read_unlock(&tasklist_lock);
65194+
65195+ return ret;
65196+}
65197+
65198+void
65199+gr_copy_label(struct task_struct *tsk)
65200+{
65201+ struct task_struct *p = current;
65202+
65203+ tsk->inherited = p->inherited;
65204+ tsk->acl_sp_role = 0;
65205+ tsk->acl_role_id = p->acl_role_id;
65206+ tsk->acl = p->acl;
65207+ tsk->role = p->role;
65208+ tsk->signal->used_accept = 0;
65209+ tsk->signal->curr_ip = p->signal->curr_ip;
65210+ tsk->signal->saved_ip = p->signal->saved_ip;
65211+ if (p->exec_file)
65212+ get_file(p->exec_file);
65213+ tsk->exec_file = p->exec_file;
65214+ tsk->is_writable = p->is_writable;
65215+ if (unlikely(p->signal->used_accept)) {
65216+ p->signal->curr_ip = 0;
65217+ p->signal->saved_ip = 0;
65218+ }
65219+
65220+ return;
65221+}
65222+
65223+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
65224+
65225+int
65226+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
65227+{
65228+ unsigned int i;
65229+ __u16 num;
65230+ uid_t *uidlist;
65231+ uid_t curuid;
65232+ int realok = 0;
65233+ int effectiveok = 0;
65234+ int fsok = 0;
65235+ uid_t globalreal, globaleffective, globalfs;
65236+
65237+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
65238+ struct user_struct *user;
65239+
65240+ if (!uid_valid(real))
65241+ goto skipit;
65242+
65243+ /* find user based on global namespace */
65244+
65245+ globalreal = GR_GLOBAL_UID(real);
65246+
65247+ user = find_user(make_kuid(&init_user_ns, globalreal));
65248+ if (user == NULL)
65249+ goto skipit;
65250+
65251+ if (gr_process_kernel_setuid_ban(user)) {
65252+ /* for find_user */
65253+ free_uid(user);
65254+ return 1;
65255+ }
65256+
65257+ /* for find_user */
65258+ free_uid(user);
65259+
65260+skipit:
65261+#endif
65262+
65263+ if (unlikely(!(gr_status & GR_READY)))
65264+ return 0;
65265+
65266+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65267+ gr_log_learn_uid_change(real, effective, fs);
65268+
65269+ num = current->acl->user_trans_num;
65270+ uidlist = current->acl->user_transitions;
65271+
65272+ if (uidlist == NULL)
65273+ return 0;
65274+
65275+ if (!uid_valid(real)) {
65276+ realok = 1;
65277+ globalreal = (uid_t)-1;
65278+ } else {
65279+ globalreal = GR_GLOBAL_UID(real);
65280+ }
65281+ if (!uid_valid(effective)) {
65282+ effectiveok = 1;
65283+ globaleffective = (uid_t)-1;
65284+ } else {
65285+ globaleffective = GR_GLOBAL_UID(effective);
65286+ }
65287+ if (!uid_valid(fs)) {
65288+ fsok = 1;
65289+ globalfs = (uid_t)-1;
65290+ } else {
65291+ globalfs = GR_GLOBAL_UID(fs);
65292+ }
65293+
65294+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
65295+ for (i = 0; i < num; i++) {
65296+ curuid = uidlist[i];
65297+ if (globalreal == curuid)
65298+ realok = 1;
65299+ if (globaleffective == curuid)
65300+ effectiveok = 1;
65301+ if (globalfs == curuid)
65302+ fsok = 1;
65303+ }
65304+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
65305+ for (i = 0; i < num; i++) {
65306+ curuid = uidlist[i];
65307+ if (globalreal == curuid)
65308+ break;
65309+ if (globaleffective == curuid)
65310+ break;
65311+ if (globalfs == curuid)
65312+ break;
65313+ }
65314+ /* not in deny list */
65315+ if (i == num) {
65316+ realok = 1;
65317+ effectiveok = 1;
65318+ fsok = 1;
65319+ }
65320+ }
65321+
65322+ if (realok && effectiveok && fsok)
65323+ return 0;
65324+ else {
65325+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
65326+ return 1;
65327+ }
65328+}
65329+
65330+int
65331+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
65332+{
65333+ unsigned int i;
65334+ __u16 num;
65335+ gid_t *gidlist;
65336+ gid_t curgid;
65337+ int realok = 0;
65338+ int effectiveok = 0;
65339+ int fsok = 0;
65340+ gid_t globalreal, globaleffective, globalfs;
65341+
65342+ if (unlikely(!(gr_status & GR_READY)))
65343+ return 0;
65344+
65345+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65346+ gr_log_learn_gid_change(real, effective, fs);
65347+
65348+ num = current->acl->group_trans_num;
65349+ gidlist = current->acl->group_transitions;
65350+
65351+ if (gidlist == NULL)
65352+ return 0;
65353+
65354+ if (!gid_valid(real)) {
65355+ realok = 1;
65356+ globalreal = (gid_t)-1;
65357+ } else {
65358+ globalreal = GR_GLOBAL_GID(real);
65359+ }
65360+ if (!gid_valid(effective)) {
65361+ effectiveok = 1;
65362+ globaleffective = (gid_t)-1;
65363+ } else {
65364+ globaleffective = GR_GLOBAL_GID(effective);
65365+ }
65366+ if (!gid_valid(fs)) {
65367+ fsok = 1;
65368+ globalfs = (gid_t)-1;
65369+ } else {
65370+ globalfs = GR_GLOBAL_GID(fs);
65371+ }
65372+
65373+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
65374+ for (i = 0; i < num; i++) {
65375+ curgid = gidlist[i];
65376+ if (globalreal == curgid)
65377+ realok = 1;
65378+ if (globaleffective == curgid)
65379+ effectiveok = 1;
65380+ if (globalfs == curgid)
65381+ fsok = 1;
65382+ }
65383+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
65384+ for (i = 0; i < num; i++) {
65385+ curgid = gidlist[i];
65386+ if (globalreal == curgid)
65387+ break;
65388+ if (globaleffective == curgid)
65389+ break;
65390+ if (globalfs == curgid)
65391+ break;
65392+ }
65393+ /* not in deny list */
65394+ if (i == num) {
65395+ realok = 1;
65396+ effectiveok = 1;
65397+ fsok = 1;
65398+ }
65399+ }
65400+
65401+ if (realok && effectiveok && fsok)
65402+ return 0;
65403+ else {
65404+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
65405+ return 1;
65406+ }
65407+}
65408+
65409+extern int gr_acl_is_capable(const int cap);
65410+
65411+void
65412+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
65413+{
65414+ struct acl_role_label *role = task->role;
65415+ struct acl_subject_label *subj = NULL;
65416+ struct acl_object_label *obj;
65417+ struct file *filp;
65418+ uid_t uid;
65419+ gid_t gid;
65420+
65421+ if (unlikely(!(gr_status & GR_READY)))
65422+ return;
65423+
65424+ uid = GR_GLOBAL_UID(kuid);
65425+ gid = GR_GLOBAL_GID(kgid);
65426+
65427+ filp = task->exec_file;
65428+
65429+ /* kernel process, we'll give them the kernel role */
65430+ if (unlikely(!filp)) {
65431+ task->role = running_polstate.kernel_role;
65432+ task->acl = running_polstate.kernel_role->root_label;
65433+ return;
65434+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
65435+ /* save the current ip at time of role lookup so that the proper
65436+ IP will be learned for role_allowed_ip */
65437+ task->signal->saved_ip = task->signal->curr_ip;
65438+ role = lookup_acl_role_label(task, uid, gid);
65439+ }
65440+
65441+ /* don't change the role if we're not a privileged process */
65442+ if (role && task->role != role &&
65443+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
65444+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
65445+ return;
65446+
65447+ /* perform subject lookup in possibly new role
65448+ we can use this result below in the case where role == task->role
65449+ */
65450+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
65451+
65452+ /* if we changed uid/gid, but result in the same role
65453+ and are using inheritance, don't lose the inherited subject
65454+ if current subject is other than what normal lookup
65455+ would result in, we arrived via inheritance, don't
65456+ lose subject
65457+ */
65458+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
65459+ (subj == task->acl)))
65460+ task->acl = subj;
65461+
65462+ /* leave task->inherited unaffected */
65463+
65464+ task->role = role;
65465+
65466+ task->is_writable = 0;
65467+
65468+ /* ignore additional mmap checks for processes that are writable
65469+ by the default ACL */
65470+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
65471+ if (unlikely(obj->mode & GR_WRITE))
65472+ task->is_writable = 1;
65473+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65474+ if (unlikely(obj->mode & GR_WRITE))
65475+ task->is_writable = 1;
65476+
65477+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65478+ 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);
65479+#endif
65480+
65481+ gr_set_proc_res(task);
65482+
65483+ return;
65484+}
65485+
65486+int
65487+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
65488+ const int unsafe_flags)
65489+{
65490+ struct task_struct *task = current;
65491+ struct acl_subject_label *newacl;
65492+ struct acl_object_label *obj;
65493+ __u32 retmode;
65494+
65495+ if (unlikely(!(gr_status & GR_READY)))
65496+ return 0;
65497+
65498+ newacl = chk_subj_label(dentry, mnt, task->role);
65499+
65500+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
65501+ did an exec
65502+ */
65503+ rcu_read_lock();
65504+ read_lock(&tasklist_lock);
65505+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
65506+ (task->parent->acl->mode & GR_POVERRIDE))) {
65507+ read_unlock(&tasklist_lock);
65508+ rcu_read_unlock();
65509+ goto skip_check;
65510+ }
65511+ read_unlock(&tasklist_lock);
65512+ rcu_read_unlock();
65513+
65514+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
65515+ !(task->role->roletype & GR_ROLE_GOD) &&
65516+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
65517+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65518+ if (unsafe_flags & LSM_UNSAFE_SHARE)
65519+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
65520+ else
65521+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
65522+ return -EACCES;
65523+ }
65524+
65525+skip_check:
65526+
65527+ obj = chk_obj_label(dentry, mnt, task->acl);
65528+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
65529+
65530+ if (!(task->acl->mode & GR_INHERITLEARN) &&
65531+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
65532+ if (obj->nested)
65533+ task->acl = obj->nested;
65534+ else
65535+ task->acl = newacl;
65536+ task->inherited = 0;
65537+ } else {
65538+ task->inherited = 1;
65539+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
65540+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
65541+ }
65542+
65543+ task->is_writable = 0;
65544+
65545+ /* ignore additional mmap checks for processes that are writable
65546+ by the default ACL */
65547+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
65548+ if (unlikely(obj->mode & GR_WRITE))
65549+ task->is_writable = 1;
65550+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
65551+ if (unlikely(obj->mode & GR_WRITE))
65552+ task->is_writable = 1;
65553+
65554+ gr_set_proc_res(task);
65555+
65556+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65557+ 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);
65558+#endif
65559+ return 0;
65560+}
65561+
65562+/* always called with valid inodev ptr */
65563+static void
65564+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
65565+{
65566+ struct acl_object_label *matchpo;
65567+ struct acl_subject_label *matchps;
65568+ struct acl_subject_label *subj;
65569+ struct acl_role_label *role;
65570+ unsigned int x;
65571+
65572+ FOR_EACH_ROLE_START(role)
65573+ FOR_EACH_SUBJECT_START(role, subj, x)
65574+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65575+ matchpo->mode |= GR_DELETED;
65576+ FOR_EACH_SUBJECT_END(subj,x)
65577+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65578+ /* nested subjects aren't in the role's subj_hash table */
65579+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65580+ matchpo->mode |= GR_DELETED;
65581+ FOR_EACH_NESTED_SUBJECT_END(subj)
65582+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
65583+ matchps->mode |= GR_DELETED;
65584+ FOR_EACH_ROLE_END(role)
65585+
65586+ inodev->nentry->deleted = 1;
65587+
65588+ return;
65589+}
65590+
65591+void
65592+gr_handle_delete(const ino_t ino, const dev_t dev)
65593+{
65594+ struct inodev_entry *inodev;
65595+
65596+ if (unlikely(!(gr_status & GR_READY)))
65597+ return;
65598+
65599+ write_lock(&gr_inode_lock);
65600+ inodev = lookup_inodev_entry(ino, dev);
65601+ if (inodev != NULL)
65602+ do_handle_delete(inodev, ino, dev);
65603+ write_unlock(&gr_inode_lock);
65604+
65605+ return;
65606+}
65607+
65608+static void
65609+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
65610+ const ino_t newinode, const dev_t newdevice,
65611+ struct acl_subject_label *subj)
65612+{
65613+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
65614+ struct acl_object_label *match;
65615+
65616+ match = subj->obj_hash[index];
65617+
65618+ while (match && (match->inode != oldinode ||
65619+ match->device != olddevice ||
65620+ !(match->mode & GR_DELETED)))
65621+ match = match->next;
65622+
65623+ if (match && (match->inode == oldinode)
65624+ && (match->device == olddevice)
65625+ && (match->mode & GR_DELETED)) {
65626+ if (match->prev == NULL) {
65627+ subj->obj_hash[index] = match->next;
65628+ if (match->next != NULL)
65629+ match->next->prev = NULL;
65630+ } else {
65631+ match->prev->next = match->next;
65632+ if (match->next != NULL)
65633+ match->next->prev = match->prev;
65634+ }
65635+ match->prev = NULL;
65636+ match->next = NULL;
65637+ match->inode = newinode;
65638+ match->device = newdevice;
65639+ match->mode &= ~GR_DELETED;
65640+
65641+ insert_acl_obj_label(match, subj);
65642+ }
65643+
65644+ return;
65645+}
65646+
65647+static void
65648+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65649+ const ino_t newinode, const dev_t newdevice,
65650+ struct acl_role_label *role)
65651+{
65652+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65653+ struct acl_subject_label *match;
65654+
65655+ match = role->subj_hash[index];
65656+
65657+ while (match && (match->inode != oldinode ||
65658+ match->device != olddevice ||
65659+ !(match->mode & GR_DELETED)))
65660+ match = match->next;
65661+
65662+ if (match && (match->inode == oldinode)
65663+ && (match->device == olddevice)
65664+ && (match->mode & GR_DELETED)) {
65665+ if (match->prev == NULL) {
65666+ role->subj_hash[index] = match->next;
65667+ if (match->next != NULL)
65668+ match->next->prev = NULL;
65669+ } else {
65670+ match->prev->next = match->next;
65671+ if (match->next != NULL)
65672+ match->next->prev = match->prev;
65673+ }
65674+ match->prev = NULL;
65675+ match->next = NULL;
65676+ match->inode = newinode;
65677+ match->device = newdevice;
65678+ match->mode &= ~GR_DELETED;
65679+
65680+ insert_acl_subj_label(match, role);
65681+ }
65682+
65683+ return;
65684+}
65685+
65686+static void
65687+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65688+ const ino_t newinode, const dev_t newdevice)
65689+{
65690+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
65691+ struct inodev_entry *match;
65692+
65693+ match = running_polstate.inodev_set.i_hash[index];
65694+
65695+ while (match && (match->nentry->inode != oldinode ||
65696+ match->nentry->device != olddevice || !match->nentry->deleted))
65697+ match = match->next;
65698+
65699+ if (match && (match->nentry->inode == oldinode)
65700+ && (match->nentry->device == olddevice) &&
65701+ match->nentry->deleted) {
65702+ if (match->prev == NULL) {
65703+ running_polstate.inodev_set.i_hash[index] = match->next;
65704+ if (match->next != NULL)
65705+ match->next->prev = NULL;
65706+ } else {
65707+ match->prev->next = match->next;
65708+ if (match->next != NULL)
65709+ match->next->prev = match->prev;
65710+ }
65711+ match->prev = NULL;
65712+ match->next = NULL;
65713+ match->nentry->inode = newinode;
65714+ match->nentry->device = newdevice;
65715+ match->nentry->deleted = 0;
65716+
65717+ insert_inodev_entry(match);
65718+ }
65719+
65720+ return;
65721+}
65722+
65723+static void
65724+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65725+{
65726+ struct acl_subject_label *subj;
65727+ struct acl_role_label *role;
65728+ unsigned int x;
65729+
65730+ FOR_EACH_ROLE_START(role)
65731+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65732+
65733+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65734+ if ((subj->inode == ino) && (subj->device == dev)) {
65735+ subj->inode = ino;
65736+ subj->device = dev;
65737+ }
65738+ /* nested subjects aren't in the role's subj_hash table */
65739+ update_acl_obj_label(matchn->inode, matchn->device,
65740+ ino, dev, subj);
65741+ FOR_EACH_NESTED_SUBJECT_END(subj)
65742+ FOR_EACH_SUBJECT_START(role, subj, x)
65743+ update_acl_obj_label(matchn->inode, matchn->device,
65744+ ino, dev, subj);
65745+ FOR_EACH_SUBJECT_END(subj,x)
65746+ FOR_EACH_ROLE_END(role)
65747+
65748+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65749+
65750+ return;
65751+}
65752+
65753+static void
65754+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65755+ const struct vfsmount *mnt)
65756+{
65757+ ino_t ino = dentry->d_inode->i_ino;
65758+ dev_t dev = __get_dev(dentry);
65759+
65760+ __do_handle_create(matchn, ino, dev);
65761+
65762+ return;
65763+}
65764+
65765+void
65766+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65767+{
65768+ struct name_entry *matchn;
65769+
65770+ if (unlikely(!(gr_status & GR_READY)))
65771+ return;
65772+
65773+ preempt_disable();
65774+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65775+
65776+ if (unlikely((unsigned long)matchn)) {
65777+ write_lock(&gr_inode_lock);
65778+ do_handle_create(matchn, dentry, mnt);
65779+ write_unlock(&gr_inode_lock);
65780+ }
65781+ preempt_enable();
65782+
65783+ return;
65784+}
65785+
65786+void
65787+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65788+{
65789+ struct name_entry *matchn;
65790+
65791+ if (unlikely(!(gr_status & GR_READY)))
65792+ return;
65793+
65794+ preempt_disable();
65795+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65796+
65797+ if (unlikely((unsigned long)matchn)) {
65798+ write_lock(&gr_inode_lock);
65799+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65800+ write_unlock(&gr_inode_lock);
65801+ }
65802+ preempt_enable();
65803+
65804+ return;
65805+}
65806+
65807+void
65808+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65809+ struct dentry *old_dentry,
65810+ struct dentry *new_dentry,
65811+ struct vfsmount *mnt, const __u8 replace)
65812+{
65813+ struct name_entry *matchn;
65814+ struct inodev_entry *inodev;
65815+ struct inode *inode = new_dentry->d_inode;
65816+ ino_t old_ino = old_dentry->d_inode->i_ino;
65817+ dev_t old_dev = __get_dev(old_dentry);
65818+
65819+ /* vfs_rename swaps the name and parent link for old_dentry and
65820+ new_dentry
65821+ at this point, old_dentry has the new name, parent link, and inode
65822+ for the renamed file
65823+ if a file is being replaced by a rename, new_dentry has the inode
65824+ and name for the replaced file
65825+ */
65826+
65827+ if (unlikely(!(gr_status & GR_READY)))
65828+ return;
65829+
65830+ preempt_disable();
65831+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65832+
65833+ /* we wouldn't have to check d_inode if it weren't for
65834+ NFS silly-renaming
65835+ */
65836+
65837+ write_lock(&gr_inode_lock);
65838+ if (unlikely(replace && inode)) {
65839+ ino_t new_ino = inode->i_ino;
65840+ dev_t new_dev = __get_dev(new_dentry);
65841+
65842+ inodev = lookup_inodev_entry(new_ino, new_dev);
65843+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65844+ do_handle_delete(inodev, new_ino, new_dev);
65845+ }
65846+
65847+ inodev = lookup_inodev_entry(old_ino, old_dev);
65848+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65849+ do_handle_delete(inodev, old_ino, old_dev);
65850+
65851+ if (unlikely((unsigned long)matchn))
65852+ do_handle_create(matchn, old_dentry, mnt);
65853+
65854+ write_unlock(&gr_inode_lock);
65855+ preempt_enable();
65856+
65857+ return;
65858+}
65859+
65860+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65861+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65862+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65863+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65864+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65865+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65866+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65867+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65868+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65869+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65870+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65871+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65872+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65873+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65874+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65875+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65876+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65877+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65878+};
65879+
65880+void
65881+gr_learn_resource(const struct task_struct *task,
65882+ const int res, const unsigned long wanted, const int gt)
65883+{
65884+ struct acl_subject_label *acl;
65885+ const struct cred *cred;
65886+
65887+ if (unlikely((gr_status & GR_READY) &&
65888+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65889+ goto skip_reslog;
65890+
65891+ gr_log_resource(task, res, wanted, gt);
65892+skip_reslog:
65893+
65894+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65895+ return;
65896+
65897+ acl = task->acl;
65898+
65899+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65900+ !(acl->resmask & (1U << (unsigned short) res))))
65901+ return;
65902+
65903+ if (wanted >= acl->res[res].rlim_cur) {
65904+ unsigned long res_add;
65905+
65906+ res_add = wanted + res_learn_bumps[res];
65907+
65908+ acl->res[res].rlim_cur = res_add;
65909+
65910+ if (wanted > acl->res[res].rlim_max)
65911+ acl->res[res].rlim_max = res_add;
65912+
65913+ /* only log the subject filename, since resource logging is supported for
65914+ single-subject learning only */
65915+ rcu_read_lock();
65916+ cred = __task_cred(task);
65917+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65918+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65919+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65920+ "", (unsigned long) res, &task->signal->saved_ip);
65921+ rcu_read_unlock();
65922+ }
65923+
65924+ return;
65925+}
65926+EXPORT_SYMBOL(gr_learn_resource);
65927+#endif
65928+
65929+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65930+void
65931+pax_set_initial_flags(struct linux_binprm *bprm)
65932+{
65933+ struct task_struct *task = current;
65934+ struct acl_subject_label *proc;
65935+ unsigned long flags;
65936+
65937+ if (unlikely(!(gr_status & GR_READY)))
65938+ return;
65939+
65940+ flags = pax_get_flags(task);
65941+
65942+ proc = task->acl;
65943+
65944+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65945+ flags &= ~MF_PAX_PAGEEXEC;
65946+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65947+ flags &= ~MF_PAX_SEGMEXEC;
65948+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65949+ flags &= ~MF_PAX_RANDMMAP;
65950+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65951+ flags &= ~MF_PAX_EMUTRAMP;
65952+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65953+ flags &= ~MF_PAX_MPROTECT;
65954+
65955+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65956+ flags |= MF_PAX_PAGEEXEC;
65957+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65958+ flags |= MF_PAX_SEGMEXEC;
65959+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65960+ flags |= MF_PAX_RANDMMAP;
65961+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65962+ flags |= MF_PAX_EMUTRAMP;
65963+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65964+ flags |= MF_PAX_MPROTECT;
65965+
65966+ pax_set_flags(task, flags);
65967+
65968+ return;
65969+}
65970+#endif
65971+
65972+int
65973+gr_handle_proc_ptrace(struct task_struct *task)
65974+{
65975+ struct file *filp;
65976+ struct task_struct *tmp = task;
65977+ struct task_struct *curtemp = current;
65978+ __u32 retmode;
65979+
65980+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65981+ if (unlikely(!(gr_status & GR_READY)))
65982+ return 0;
65983+#endif
65984+
65985+ read_lock(&tasklist_lock);
65986+ read_lock(&grsec_exec_file_lock);
65987+ filp = task->exec_file;
65988+
65989+ while (task_pid_nr(tmp) > 0) {
65990+ if (tmp == curtemp)
65991+ break;
65992+ tmp = tmp->real_parent;
65993+ }
65994+
65995+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65996+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65997+ read_unlock(&grsec_exec_file_lock);
65998+ read_unlock(&tasklist_lock);
65999+ return 1;
66000+ }
66001+
66002+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66003+ if (!(gr_status & GR_READY)) {
66004+ read_unlock(&grsec_exec_file_lock);
66005+ read_unlock(&tasklist_lock);
66006+ return 0;
66007+ }
66008+#endif
66009+
66010+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
66011+ read_unlock(&grsec_exec_file_lock);
66012+ read_unlock(&tasklist_lock);
66013+
66014+ if (retmode & GR_NOPTRACE)
66015+ return 1;
66016+
66017+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
66018+ && (current->acl != task->acl || (current->acl != current->role->root_label
66019+ && task_pid_nr(current) != task_pid_nr(task))))
66020+ return 1;
66021+
66022+ return 0;
66023+}
66024+
66025+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
66026+{
66027+ if (unlikely(!(gr_status & GR_READY)))
66028+ return;
66029+
66030+ if (!(current->role->roletype & GR_ROLE_GOD))
66031+ return;
66032+
66033+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
66034+ p->role->rolename, gr_task_roletype_to_char(p),
66035+ p->acl->filename);
66036+}
66037+
66038+int
66039+gr_handle_ptrace(struct task_struct *task, const long request)
66040+{
66041+ struct task_struct *tmp = task;
66042+ struct task_struct *curtemp = current;
66043+ __u32 retmode;
66044+
66045+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66046+ if (unlikely(!(gr_status & GR_READY)))
66047+ return 0;
66048+#endif
66049+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66050+ read_lock(&tasklist_lock);
66051+ while (task_pid_nr(tmp) > 0) {
66052+ if (tmp == curtemp)
66053+ break;
66054+ tmp = tmp->real_parent;
66055+ }
66056+
66057+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66058+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
66059+ read_unlock(&tasklist_lock);
66060+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66061+ return 1;
66062+ }
66063+ read_unlock(&tasklist_lock);
66064+ }
66065+
66066+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66067+ if (!(gr_status & GR_READY))
66068+ return 0;
66069+#endif
66070+
66071+ read_lock(&grsec_exec_file_lock);
66072+ if (unlikely(!task->exec_file)) {
66073+ read_unlock(&grsec_exec_file_lock);
66074+ return 0;
66075+ }
66076+
66077+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66078+ read_unlock(&grsec_exec_file_lock);
66079+
66080+ if (retmode & GR_NOPTRACE) {
66081+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66082+ return 1;
66083+ }
66084+
66085+ if (retmode & GR_PTRACERD) {
66086+ switch (request) {
66087+ case PTRACE_SEIZE:
66088+ case PTRACE_POKETEXT:
66089+ case PTRACE_POKEDATA:
66090+ case PTRACE_POKEUSR:
66091+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66092+ case PTRACE_SETREGS:
66093+ case PTRACE_SETFPREGS:
66094+#endif
66095+#ifdef CONFIG_X86
66096+ case PTRACE_SETFPXREGS:
66097+#endif
66098+#ifdef CONFIG_ALTIVEC
66099+ case PTRACE_SETVRREGS:
66100+#endif
66101+ return 1;
66102+ default:
66103+ return 0;
66104+ }
66105+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66106+ !(current->role->roletype & GR_ROLE_GOD) &&
66107+ (current->acl != task->acl)) {
66108+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66109+ return 1;
66110+ }
66111+
66112+ return 0;
66113+}
66114+
66115+static int is_writable_mmap(const struct file *filp)
66116+{
66117+ struct task_struct *task = current;
66118+ struct acl_object_label *obj, *obj2;
66119+
66120+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66121+ !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))) {
66122+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66123+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66124+ task->role->root_label);
66125+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66126+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66127+ return 1;
66128+ }
66129+ }
66130+ return 0;
66131+}
66132+
66133+int
66134+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66135+{
66136+ __u32 mode;
66137+
66138+ if (unlikely(!file || !(prot & PROT_EXEC)))
66139+ return 1;
66140+
66141+ if (is_writable_mmap(file))
66142+ return 0;
66143+
66144+ mode =
66145+ gr_search_file(file->f_path.dentry,
66146+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66147+ file->f_path.mnt);
66148+
66149+ if (!gr_tpe_allow(file))
66150+ return 0;
66151+
66152+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66153+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66154+ return 0;
66155+ } else if (unlikely(!(mode & GR_EXEC))) {
66156+ return 0;
66157+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66158+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66159+ return 1;
66160+ }
66161+
66162+ return 1;
66163+}
66164+
66165+int
66166+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66167+{
66168+ __u32 mode;
66169+
66170+ if (unlikely(!file || !(prot & PROT_EXEC)))
66171+ return 1;
66172+
66173+ if (is_writable_mmap(file))
66174+ return 0;
66175+
66176+ mode =
66177+ gr_search_file(file->f_path.dentry,
66178+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66179+ file->f_path.mnt);
66180+
66181+ if (!gr_tpe_allow(file))
66182+ return 0;
66183+
66184+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66185+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66186+ return 0;
66187+ } else if (unlikely(!(mode & GR_EXEC))) {
66188+ return 0;
66189+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66190+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66191+ return 1;
66192+ }
66193+
66194+ return 1;
66195+}
66196+
66197+void
66198+gr_acl_handle_psacct(struct task_struct *task, const long code)
66199+{
66200+ unsigned long runtime;
66201+ unsigned long cputime;
66202+ unsigned int wday, cday;
66203+ __u8 whr, chr;
66204+ __u8 wmin, cmin;
66205+ __u8 wsec, csec;
66206+ struct timespec timeval;
66207+
66208+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66209+ !(task->acl->mode & GR_PROCACCT)))
66210+ return;
66211+
66212+ do_posix_clock_monotonic_gettime(&timeval);
66213+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66214+ wday = runtime / (3600 * 24);
66215+ runtime -= wday * (3600 * 24);
66216+ whr = runtime / 3600;
66217+ runtime -= whr * 3600;
66218+ wmin = runtime / 60;
66219+ runtime -= wmin * 60;
66220+ wsec = runtime;
66221+
66222+ cputime = (task->utime + task->stime) / HZ;
66223+ cday = cputime / (3600 * 24);
66224+ cputime -= cday * (3600 * 24);
66225+ chr = cputime / 3600;
66226+ cputime -= chr * 3600;
66227+ cmin = cputime / 60;
66228+ cputime -= cmin * 60;
66229+ csec = cputime;
66230+
66231+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66232+
66233+ return;
66234+}
66235+
66236+#ifdef CONFIG_TASKSTATS
66237+int gr_is_taskstats_denied(int pid)
66238+{
66239+ struct task_struct *task;
66240+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66241+ const struct cred *cred;
66242+#endif
66243+ int ret = 0;
66244+
66245+ /* restrict taskstats viewing to un-chrooted root users
66246+ who have the 'view' subject flag if the RBAC system is enabled
66247+ */
66248+
66249+ rcu_read_lock();
66250+ read_lock(&tasklist_lock);
66251+ task = find_task_by_vpid(pid);
66252+ if (task) {
66253+#ifdef CONFIG_GRKERNSEC_CHROOT
66254+ if (proc_is_chrooted(task))
66255+ ret = -EACCES;
66256+#endif
66257+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66258+ cred = __task_cred(task);
66259+#ifdef CONFIG_GRKERNSEC_PROC_USER
66260+ if (gr_is_global_nonroot(cred->uid))
66261+ ret = -EACCES;
66262+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66263+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66264+ ret = -EACCES;
66265+#endif
66266+#endif
66267+ if (gr_status & GR_READY) {
66268+ if (!(task->acl->mode & GR_VIEW))
66269+ ret = -EACCES;
66270+ }
66271+ } else
66272+ ret = -ENOENT;
66273+
66274+ read_unlock(&tasklist_lock);
66275+ rcu_read_unlock();
66276+
66277+ return ret;
66278+}
66279+#endif
66280+
66281+/* AUXV entries are filled via a descendant of search_binary_handler
66282+ after we've already applied the subject for the target
66283+*/
66284+int gr_acl_enable_at_secure(void)
66285+{
66286+ if (unlikely(!(gr_status & GR_READY)))
66287+ return 0;
66288+
66289+ if (current->acl->mode & GR_ATSECURE)
66290+ return 1;
66291+
66292+ return 0;
66293+}
66294+
66295+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66296+{
66297+ struct task_struct *task = current;
66298+ struct dentry *dentry = file->f_path.dentry;
66299+ struct vfsmount *mnt = file->f_path.mnt;
66300+ struct acl_object_label *obj, *tmp;
66301+ struct acl_subject_label *subj;
66302+ unsigned int bufsize;
66303+ int is_not_root;
66304+ char *path;
66305+ dev_t dev = __get_dev(dentry);
66306+
66307+ if (unlikely(!(gr_status & GR_READY)))
66308+ return 1;
66309+
66310+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66311+ return 1;
66312+
66313+ /* ignore Eric Biederman */
66314+ if (IS_PRIVATE(dentry->d_inode))
66315+ return 1;
66316+
66317+ subj = task->acl;
66318+ read_lock(&gr_inode_lock);
66319+ do {
66320+ obj = lookup_acl_obj_label(ino, dev, subj);
66321+ if (obj != NULL) {
66322+ read_unlock(&gr_inode_lock);
66323+ return (obj->mode & GR_FIND) ? 1 : 0;
66324+ }
66325+ } while ((subj = subj->parent_subject));
66326+ read_unlock(&gr_inode_lock);
66327+
66328+ /* this is purely an optimization since we're looking for an object
66329+ for the directory we're doing a readdir on
66330+ if it's possible for any globbed object to match the entry we're
66331+ filling into the directory, then the object we find here will be
66332+ an anchor point with attached globbed objects
66333+ */
66334+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66335+ if (obj->globbed == NULL)
66336+ return (obj->mode & GR_FIND) ? 1 : 0;
66337+
66338+ is_not_root = ((obj->filename[0] == '/') &&
66339+ (obj->filename[1] == '\0')) ? 0 : 1;
66340+ bufsize = PAGE_SIZE - namelen - is_not_root;
66341+
66342+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66343+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66344+ return 1;
66345+
66346+ preempt_disable();
66347+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66348+ bufsize);
66349+
66350+ bufsize = strlen(path);
66351+
66352+ /* if base is "/", don't append an additional slash */
66353+ if (is_not_root)
66354+ *(path + bufsize) = '/';
66355+ memcpy(path + bufsize + is_not_root, name, namelen);
66356+ *(path + bufsize + namelen + is_not_root) = '\0';
66357+
66358+ tmp = obj->globbed;
66359+ while (tmp) {
66360+ if (!glob_match(tmp->filename, path)) {
66361+ preempt_enable();
66362+ return (tmp->mode & GR_FIND) ? 1 : 0;
66363+ }
66364+ tmp = tmp->next;
66365+ }
66366+ preempt_enable();
66367+ return (obj->mode & GR_FIND) ? 1 : 0;
66368+}
66369+
66370+void gr_put_exec_file(struct task_struct *task)
66371+{
66372+ struct file *filp;
66373+
66374+ write_lock(&grsec_exec_file_lock);
66375+ filp = task->exec_file;
66376+ task->exec_file = NULL;
66377+ write_unlock(&grsec_exec_file_lock);
66378+
66379+ if (filp)
66380+ fput(filp);
66381+
66382+ return;
66383+}
66384+
66385+
66386+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66387+EXPORT_SYMBOL(gr_acl_is_enabled);
66388+#endif
66389+#ifdef CONFIG_SECURITY
66390+EXPORT_SYMBOL(gr_check_user_change);
66391+EXPORT_SYMBOL(gr_check_group_change);
66392+#endif
66393+
66394diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66395new file mode 100644
66396index 0000000..18ffbbd
66397--- /dev/null
66398+++ b/grsecurity/gracl_alloc.c
66399@@ -0,0 +1,105 @@
66400+#include <linux/kernel.h>
66401+#include <linux/mm.h>
66402+#include <linux/slab.h>
66403+#include <linux/vmalloc.h>
66404+#include <linux/gracl.h>
66405+#include <linux/grsecurity.h>
66406+
66407+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
66408+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
66409+
66410+static __inline__ int
66411+alloc_pop(void)
66412+{
66413+ if (current_alloc_state->alloc_stack_next == 1)
66414+ return 0;
66415+
66416+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
66417+
66418+ current_alloc_state->alloc_stack_next--;
66419+
66420+ return 1;
66421+}
66422+
66423+static __inline__ int
66424+alloc_push(void *buf)
66425+{
66426+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
66427+ return 1;
66428+
66429+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
66430+
66431+ current_alloc_state->alloc_stack_next++;
66432+
66433+ return 0;
66434+}
66435+
66436+void *
66437+acl_alloc(unsigned long len)
66438+{
66439+ void *ret = NULL;
66440+
66441+ if (!len || len > PAGE_SIZE)
66442+ goto out;
66443+
66444+ ret = kmalloc(len, GFP_KERNEL);
66445+
66446+ if (ret) {
66447+ if (alloc_push(ret)) {
66448+ kfree(ret);
66449+ ret = NULL;
66450+ }
66451+ }
66452+
66453+out:
66454+ return ret;
66455+}
66456+
66457+void *
66458+acl_alloc_num(unsigned long num, unsigned long len)
66459+{
66460+ if (!len || (num > (PAGE_SIZE / len)))
66461+ return NULL;
66462+
66463+ return acl_alloc(num * len);
66464+}
66465+
66466+void
66467+acl_free_all(void)
66468+{
66469+ if (!current_alloc_state->alloc_stack)
66470+ return;
66471+
66472+ while (alloc_pop()) ;
66473+
66474+ if (current_alloc_state->alloc_stack) {
66475+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66476+ kfree(current_alloc_state->alloc_stack);
66477+ else
66478+ vfree(current_alloc_state->alloc_stack);
66479+ }
66480+
66481+ current_alloc_state->alloc_stack = NULL;
66482+ current_alloc_state->alloc_stack_size = 1;
66483+ current_alloc_state->alloc_stack_next = 1;
66484+
66485+ return;
66486+}
66487+
66488+int
66489+acl_alloc_stack_init(unsigned long size)
66490+{
66491+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66492+ current_alloc_state->alloc_stack =
66493+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66494+ else
66495+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
66496+
66497+ current_alloc_state->alloc_stack_size = size;
66498+ current_alloc_state->alloc_stack_next = 1;
66499+
66500+ if (!current_alloc_state->alloc_stack)
66501+ return 0;
66502+ else
66503+ return 1;
66504+}
66505diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66506new file mode 100644
66507index 0000000..bdd51ea
66508--- /dev/null
66509+++ b/grsecurity/gracl_cap.c
66510@@ -0,0 +1,110 @@
66511+#include <linux/kernel.h>
66512+#include <linux/module.h>
66513+#include <linux/sched.h>
66514+#include <linux/gracl.h>
66515+#include <linux/grsecurity.h>
66516+#include <linux/grinternal.h>
66517+
66518+extern const char *captab_log[];
66519+extern int captab_log_entries;
66520+
66521+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66522+{
66523+ struct acl_subject_label *curracl;
66524+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66525+ kernel_cap_t cap_audit = __cap_empty_set;
66526+
66527+ if (!gr_acl_is_enabled())
66528+ return 1;
66529+
66530+ curracl = task->acl;
66531+
66532+ cap_drop = curracl->cap_lower;
66533+ cap_mask = curracl->cap_mask;
66534+ cap_audit = curracl->cap_invert_audit;
66535+
66536+ while ((curracl = curracl->parent_subject)) {
66537+ /* if the cap isn't specified in the current computed mask but is specified in the
66538+ current level subject, and is lowered in the current level subject, then add
66539+ it to the set of dropped capabilities
66540+ otherwise, add the current level subject's mask to the current computed mask
66541+ */
66542+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66543+ cap_raise(cap_mask, cap);
66544+ if (cap_raised(curracl->cap_lower, cap))
66545+ cap_raise(cap_drop, cap);
66546+ if (cap_raised(curracl->cap_invert_audit, cap))
66547+ cap_raise(cap_audit, cap);
66548+ }
66549+ }
66550+
66551+ if (!cap_raised(cap_drop, cap)) {
66552+ if (cap_raised(cap_audit, cap))
66553+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66554+ return 1;
66555+ }
66556+
66557+ curracl = task->acl;
66558+
66559+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66560+ && cap_raised(cred->cap_effective, cap)) {
66561+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66562+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66563+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66564+ gr_to_filename(task->exec_file->f_path.dentry,
66565+ task->exec_file->f_path.mnt) : curracl->filename,
66566+ curracl->filename, 0UL,
66567+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66568+ return 1;
66569+ }
66570+
66571+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66572+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66573+
66574+ return 0;
66575+}
66576+
66577+int
66578+gr_acl_is_capable(const int cap)
66579+{
66580+ return gr_task_acl_is_capable(current, current_cred(), cap);
66581+}
66582+
66583+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66584+{
66585+ struct acl_subject_label *curracl;
66586+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66587+
66588+ if (!gr_acl_is_enabled())
66589+ return 1;
66590+
66591+ curracl = task->acl;
66592+
66593+ cap_drop = curracl->cap_lower;
66594+ cap_mask = curracl->cap_mask;
66595+
66596+ while ((curracl = curracl->parent_subject)) {
66597+ /* if the cap isn't specified in the current computed mask but is specified in the
66598+ current level subject, and is lowered in the current level subject, then add
66599+ it to the set of dropped capabilities
66600+ otherwise, add the current level subject's mask to the current computed mask
66601+ */
66602+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66603+ cap_raise(cap_mask, cap);
66604+ if (cap_raised(curracl->cap_lower, cap))
66605+ cap_raise(cap_drop, cap);
66606+ }
66607+ }
66608+
66609+ if (!cap_raised(cap_drop, cap))
66610+ return 1;
66611+
66612+ return 0;
66613+}
66614+
66615+int
66616+gr_acl_is_capable_nolog(const int cap)
66617+{
66618+ return gr_task_acl_is_capable_nolog(current, cap);
66619+}
66620+
66621diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66622new file mode 100644
66623index 0000000..ca25605
66624--- /dev/null
66625+++ b/grsecurity/gracl_compat.c
66626@@ -0,0 +1,270 @@
66627+#include <linux/kernel.h>
66628+#include <linux/gracl.h>
66629+#include <linux/compat.h>
66630+#include <linux/gracl_compat.h>
66631+
66632+#include <asm/uaccess.h>
66633+
66634+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66635+{
66636+ struct gr_arg_wrapper_compat uwrapcompat;
66637+
66638+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66639+ return -EFAULT;
66640+
66641+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
66642+ (uwrapcompat.version != 0x2901)) ||
66643+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66644+ return -EINVAL;
66645+
66646+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66647+ uwrap->version = uwrapcompat.version;
66648+ uwrap->size = sizeof(struct gr_arg);
66649+
66650+ return 0;
66651+}
66652+
66653+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66654+{
66655+ struct gr_arg_compat argcompat;
66656+
66657+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66658+ return -EFAULT;
66659+
66660+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66661+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66662+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66663+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66664+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66665+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66666+
66667+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66668+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66669+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66670+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66671+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66672+ arg->segv_device = argcompat.segv_device;
66673+ arg->segv_inode = argcompat.segv_inode;
66674+ arg->segv_uid = argcompat.segv_uid;
66675+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66676+ arg->mode = argcompat.mode;
66677+
66678+ return 0;
66679+}
66680+
66681+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66682+{
66683+ struct acl_object_label_compat objcompat;
66684+
66685+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66686+ return -EFAULT;
66687+
66688+ obj->filename = compat_ptr(objcompat.filename);
66689+ obj->inode = objcompat.inode;
66690+ obj->device = objcompat.device;
66691+ obj->mode = objcompat.mode;
66692+
66693+ obj->nested = compat_ptr(objcompat.nested);
66694+ obj->globbed = compat_ptr(objcompat.globbed);
66695+
66696+ obj->prev = compat_ptr(objcompat.prev);
66697+ obj->next = compat_ptr(objcompat.next);
66698+
66699+ return 0;
66700+}
66701+
66702+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66703+{
66704+ unsigned int i;
66705+ struct acl_subject_label_compat subjcompat;
66706+
66707+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66708+ return -EFAULT;
66709+
66710+ subj->filename = compat_ptr(subjcompat.filename);
66711+ subj->inode = subjcompat.inode;
66712+ subj->device = subjcompat.device;
66713+ subj->mode = subjcompat.mode;
66714+ subj->cap_mask = subjcompat.cap_mask;
66715+ subj->cap_lower = subjcompat.cap_lower;
66716+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66717+
66718+ for (i = 0; i < GR_NLIMITS; i++) {
66719+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66720+ subj->res[i].rlim_cur = RLIM_INFINITY;
66721+ else
66722+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66723+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66724+ subj->res[i].rlim_max = RLIM_INFINITY;
66725+ else
66726+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66727+ }
66728+ subj->resmask = subjcompat.resmask;
66729+
66730+ subj->user_trans_type = subjcompat.user_trans_type;
66731+ subj->group_trans_type = subjcompat.group_trans_type;
66732+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66733+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66734+ subj->user_trans_num = subjcompat.user_trans_num;
66735+ subj->group_trans_num = subjcompat.group_trans_num;
66736+
66737+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66738+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66739+ subj->ip_type = subjcompat.ip_type;
66740+ subj->ips = compat_ptr(subjcompat.ips);
66741+ subj->ip_num = subjcompat.ip_num;
66742+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66743+
66744+ subj->crashes = subjcompat.crashes;
66745+ subj->expires = subjcompat.expires;
66746+
66747+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66748+ subj->hash = compat_ptr(subjcompat.hash);
66749+ subj->prev = compat_ptr(subjcompat.prev);
66750+ subj->next = compat_ptr(subjcompat.next);
66751+
66752+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66753+ subj->obj_hash_size = subjcompat.obj_hash_size;
66754+ subj->pax_flags = subjcompat.pax_flags;
66755+
66756+ return 0;
66757+}
66758+
66759+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66760+{
66761+ struct acl_role_label_compat rolecompat;
66762+
66763+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66764+ return -EFAULT;
66765+
66766+ role->rolename = compat_ptr(rolecompat.rolename);
66767+ role->uidgid = rolecompat.uidgid;
66768+ role->roletype = rolecompat.roletype;
66769+
66770+ role->auth_attempts = rolecompat.auth_attempts;
66771+ role->expires = rolecompat.expires;
66772+
66773+ role->root_label = compat_ptr(rolecompat.root_label);
66774+ role->hash = compat_ptr(rolecompat.hash);
66775+
66776+ role->prev = compat_ptr(rolecompat.prev);
66777+ role->next = compat_ptr(rolecompat.next);
66778+
66779+ role->transitions = compat_ptr(rolecompat.transitions);
66780+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66781+ role->domain_children = compat_ptr(rolecompat.domain_children);
66782+ role->domain_child_num = rolecompat.domain_child_num;
66783+
66784+ role->umask = rolecompat.umask;
66785+
66786+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66787+ role->subj_hash_size = rolecompat.subj_hash_size;
66788+
66789+ return 0;
66790+}
66791+
66792+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66793+{
66794+ struct role_allowed_ip_compat roleip_compat;
66795+
66796+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66797+ return -EFAULT;
66798+
66799+ roleip->addr = roleip_compat.addr;
66800+ roleip->netmask = roleip_compat.netmask;
66801+
66802+ roleip->prev = compat_ptr(roleip_compat.prev);
66803+ roleip->next = compat_ptr(roleip_compat.next);
66804+
66805+ return 0;
66806+}
66807+
66808+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66809+{
66810+ struct role_transition_compat trans_compat;
66811+
66812+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66813+ return -EFAULT;
66814+
66815+ trans->rolename = compat_ptr(trans_compat.rolename);
66816+
66817+ trans->prev = compat_ptr(trans_compat.prev);
66818+ trans->next = compat_ptr(trans_compat.next);
66819+
66820+ return 0;
66821+
66822+}
66823+
66824+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66825+{
66826+ struct gr_hash_struct_compat hash_compat;
66827+
66828+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66829+ return -EFAULT;
66830+
66831+ hash->table = compat_ptr(hash_compat.table);
66832+ hash->nametable = compat_ptr(hash_compat.nametable);
66833+ hash->first = compat_ptr(hash_compat.first);
66834+
66835+ hash->table_size = hash_compat.table_size;
66836+ hash->used_size = hash_compat.used_size;
66837+
66838+ hash->type = hash_compat.type;
66839+
66840+ return 0;
66841+}
66842+
66843+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66844+{
66845+ compat_uptr_t ptrcompat;
66846+
66847+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66848+ return -EFAULT;
66849+
66850+ *(void **)ptr = compat_ptr(ptrcompat);
66851+
66852+ return 0;
66853+}
66854+
66855+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66856+{
66857+ struct acl_ip_label_compat ip_compat;
66858+
66859+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66860+ return -EFAULT;
66861+
66862+ ip->iface = compat_ptr(ip_compat.iface);
66863+ ip->addr = ip_compat.addr;
66864+ ip->netmask = ip_compat.netmask;
66865+ ip->low = ip_compat.low;
66866+ ip->high = ip_compat.high;
66867+ ip->mode = ip_compat.mode;
66868+ ip->type = ip_compat.type;
66869+
66870+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66871+
66872+ ip->prev = compat_ptr(ip_compat.prev);
66873+ ip->next = compat_ptr(ip_compat.next);
66874+
66875+ return 0;
66876+}
66877+
66878+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66879+{
66880+ struct sprole_pw_compat pw_compat;
66881+
66882+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66883+ return -EFAULT;
66884+
66885+ pw->rolename = compat_ptr(pw_compat.rolename);
66886+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66887+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66888+
66889+ return 0;
66890+}
66891+
66892+size_t get_gr_arg_wrapper_size_compat(void)
66893+{
66894+ return sizeof(struct gr_arg_wrapper_compat);
66895+}
66896+
66897diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66898new file mode 100644
66899index 0000000..deb6f3b
66900--- /dev/null
66901+++ b/grsecurity/gracl_fs.c
66902@@ -0,0 +1,437 @@
66903+#include <linux/kernel.h>
66904+#include <linux/sched.h>
66905+#include <linux/types.h>
66906+#include <linux/fs.h>
66907+#include <linux/file.h>
66908+#include <linux/stat.h>
66909+#include <linux/grsecurity.h>
66910+#include <linux/grinternal.h>
66911+#include <linux/gracl.h>
66912+
66913+umode_t
66914+gr_acl_umask(void)
66915+{
66916+ if (unlikely(!gr_acl_is_enabled()))
66917+ return 0;
66918+
66919+ return current->role->umask;
66920+}
66921+
66922+__u32
66923+gr_acl_handle_hidden_file(const struct dentry * dentry,
66924+ const struct vfsmount * mnt)
66925+{
66926+ __u32 mode;
66927+
66928+ if (unlikely(!dentry->d_inode))
66929+ return GR_FIND;
66930+
66931+ mode =
66932+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66933+
66934+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66935+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66936+ return mode;
66937+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66938+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66939+ return 0;
66940+ } else if (unlikely(!(mode & GR_FIND)))
66941+ return 0;
66942+
66943+ return GR_FIND;
66944+}
66945+
66946+__u32
66947+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66948+ int acc_mode)
66949+{
66950+ __u32 reqmode = GR_FIND;
66951+ __u32 mode;
66952+
66953+ if (unlikely(!dentry->d_inode))
66954+ return reqmode;
66955+
66956+ if (acc_mode & MAY_APPEND)
66957+ reqmode |= GR_APPEND;
66958+ else if (acc_mode & MAY_WRITE)
66959+ reqmode |= GR_WRITE;
66960+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66961+ reqmode |= GR_READ;
66962+
66963+ mode =
66964+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66965+ mnt);
66966+
66967+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66968+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66969+ reqmode & GR_READ ? " reading" : "",
66970+ reqmode & GR_WRITE ? " writing" : reqmode &
66971+ GR_APPEND ? " appending" : "");
66972+ return reqmode;
66973+ } else
66974+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66975+ {
66976+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66977+ reqmode & GR_READ ? " reading" : "",
66978+ reqmode & GR_WRITE ? " writing" : reqmode &
66979+ GR_APPEND ? " appending" : "");
66980+ return 0;
66981+ } else if (unlikely((mode & reqmode) != reqmode))
66982+ return 0;
66983+
66984+ return reqmode;
66985+}
66986+
66987+__u32
66988+gr_acl_handle_creat(const struct dentry * dentry,
66989+ const struct dentry * p_dentry,
66990+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66991+ const int imode)
66992+{
66993+ __u32 reqmode = GR_WRITE | GR_CREATE;
66994+ __u32 mode;
66995+
66996+ if (acc_mode & MAY_APPEND)
66997+ reqmode |= GR_APPEND;
66998+ // if a directory was required or the directory already exists, then
66999+ // don't count this open as a read
67000+ if ((acc_mode & MAY_READ) &&
67001+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
67002+ reqmode |= GR_READ;
67003+ if ((open_flags & O_CREAT) &&
67004+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67005+ reqmode |= GR_SETID;
67006+
67007+ mode =
67008+ gr_check_create(dentry, p_dentry, p_mnt,
67009+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67010+
67011+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67012+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67013+ reqmode & GR_READ ? " reading" : "",
67014+ reqmode & GR_WRITE ? " writing" : reqmode &
67015+ GR_APPEND ? " appending" : "");
67016+ return reqmode;
67017+ } else
67018+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67019+ {
67020+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67021+ reqmode & GR_READ ? " reading" : "",
67022+ reqmode & GR_WRITE ? " writing" : reqmode &
67023+ GR_APPEND ? " appending" : "");
67024+ return 0;
67025+ } else if (unlikely((mode & reqmode) != reqmode))
67026+ return 0;
67027+
67028+ return reqmode;
67029+}
67030+
67031+__u32
67032+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
67033+ const int fmode)
67034+{
67035+ __u32 mode, reqmode = GR_FIND;
67036+
67037+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
67038+ reqmode |= GR_EXEC;
67039+ if (fmode & S_IWOTH)
67040+ reqmode |= GR_WRITE;
67041+ if (fmode & S_IROTH)
67042+ reqmode |= GR_READ;
67043+
67044+ mode =
67045+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67046+ mnt);
67047+
67048+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67049+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67050+ reqmode & GR_READ ? " reading" : "",
67051+ reqmode & GR_WRITE ? " writing" : "",
67052+ reqmode & GR_EXEC ? " executing" : "");
67053+ return reqmode;
67054+ } else
67055+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67056+ {
67057+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67058+ reqmode & GR_READ ? " reading" : "",
67059+ reqmode & GR_WRITE ? " writing" : "",
67060+ reqmode & GR_EXEC ? " executing" : "");
67061+ return 0;
67062+ } else if (unlikely((mode & reqmode) != reqmode))
67063+ return 0;
67064+
67065+ return reqmode;
67066+}
67067+
67068+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67069+{
67070+ __u32 mode;
67071+
67072+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67073+
67074+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67075+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67076+ return mode;
67077+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67078+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67079+ return 0;
67080+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67081+ return 0;
67082+
67083+ return (reqmode);
67084+}
67085+
67086+__u32
67087+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67088+{
67089+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67090+}
67091+
67092+__u32
67093+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67094+{
67095+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67096+}
67097+
67098+__u32
67099+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67100+{
67101+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67102+}
67103+
67104+__u32
67105+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67106+{
67107+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67108+}
67109+
67110+__u32
67111+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67112+ umode_t *modeptr)
67113+{
67114+ umode_t mode;
67115+
67116+ *modeptr &= ~gr_acl_umask();
67117+ mode = *modeptr;
67118+
67119+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67120+ return 1;
67121+
67122+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67123+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67124+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67125+ GR_CHMOD_ACL_MSG);
67126+ } else {
67127+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67128+ }
67129+}
67130+
67131+__u32
67132+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67133+{
67134+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67135+}
67136+
67137+__u32
67138+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67139+{
67140+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67141+}
67142+
67143+__u32
67144+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
67145+{
67146+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
67147+}
67148+
67149+__u32
67150+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67151+{
67152+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67153+}
67154+
67155+__u32
67156+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67157+{
67158+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67159+ GR_UNIXCONNECT_ACL_MSG);
67160+}
67161+
67162+/* hardlinks require at minimum create and link permission,
67163+ any additional privilege required is based on the
67164+ privilege of the file being linked to
67165+*/
67166+__u32
67167+gr_acl_handle_link(const struct dentry * new_dentry,
67168+ const struct dentry * parent_dentry,
67169+ const struct vfsmount * parent_mnt,
67170+ const struct dentry * old_dentry,
67171+ const struct vfsmount * old_mnt, const struct filename *to)
67172+{
67173+ __u32 mode;
67174+ __u32 needmode = GR_CREATE | GR_LINK;
67175+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67176+
67177+ mode =
67178+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67179+ old_mnt);
67180+
67181+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67182+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67183+ return mode;
67184+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67185+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67186+ return 0;
67187+ } else if (unlikely((mode & needmode) != needmode))
67188+ return 0;
67189+
67190+ return 1;
67191+}
67192+
67193+__u32
67194+gr_acl_handle_symlink(const struct dentry * new_dentry,
67195+ const struct dentry * parent_dentry,
67196+ const struct vfsmount * parent_mnt, const struct filename *from)
67197+{
67198+ __u32 needmode = GR_WRITE | GR_CREATE;
67199+ __u32 mode;
67200+
67201+ mode =
67202+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67203+ GR_CREATE | GR_AUDIT_CREATE |
67204+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67205+
67206+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67207+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67208+ return mode;
67209+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67210+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67211+ return 0;
67212+ } else if (unlikely((mode & needmode) != needmode))
67213+ return 0;
67214+
67215+ return (GR_WRITE | GR_CREATE);
67216+}
67217+
67218+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)
67219+{
67220+ __u32 mode;
67221+
67222+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67223+
67224+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67225+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67226+ return mode;
67227+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67228+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67229+ return 0;
67230+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67231+ return 0;
67232+
67233+ return (reqmode);
67234+}
67235+
67236+__u32
67237+gr_acl_handle_mknod(const struct dentry * new_dentry,
67238+ const struct dentry * parent_dentry,
67239+ const struct vfsmount * parent_mnt,
67240+ const int mode)
67241+{
67242+ __u32 reqmode = GR_WRITE | GR_CREATE;
67243+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67244+ reqmode |= GR_SETID;
67245+
67246+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67247+ reqmode, GR_MKNOD_ACL_MSG);
67248+}
67249+
67250+__u32
67251+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67252+ const struct dentry *parent_dentry,
67253+ const struct vfsmount *parent_mnt)
67254+{
67255+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67256+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67257+}
67258+
67259+#define RENAME_CHECK_SUCCESS(old, new) \
67260+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67261+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67262+
67263+int
67264+gr_acl_handle_rename(struct dentry *new_dentry,
67265+ struct dentry *parent_dentry,
67266+ const struct vfsmount *parent_mnt,
67267+ struct dentry *old_dentry,
67268+ struct inode *old_parent_inode,
67269+ struct vfsmount *old_mnt, const struct filename *newname)
67270+{
67271+ __u32 comp1, comp2;
67272+ int error = 0;
67273+
67274+ if (unlikely(!gr_acl_is_enabled()))
67275+ return 0;
67276+
67277+ if (!new_dentry->d_inode) {
67278+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67279+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67280+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67281+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67282+ GR_DELETE | GR_AUDIT_DELETE |
67283+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67284+ GR_SUPPRESS, old_mnt);
67285+ } else {
67286+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67287+ GR_CREATE | GR_DELETE |
67288+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67289+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67290+ GR_SUPPRESS, parent_mnt);
67291+ comp2 =
67292+ gr_search_file(old_dentry,
67293+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67294+ GR_DELETE | GR_AUDIT_DELETE |
67295+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67296+ }
67297+
67298+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67299+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67300+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67301+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67302+ && !(comp2 & GR_SUPPRESS)) {
67303+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67304+ error = -EACCES;
67305+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67306+ error = -EACCES;
67307+
67308+ return error;
67309+}
67310+
67311+void
67312+gr_acl_handle_exit(void)
67313+{
67314+ u16 id;
67315+ char *rolename;
67316+
67317+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67318+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67319+ id = current->acl_role_id;
67320+ rolename = current->role->rolename;
67321+ gr_set_acls(1);
67322+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67323+ }
67324+
67325+ gr_put_exec_file(current);
67326+ return;
67327+}
67328+
67329+int
67330+gr_acl_handle_procpidmem(const struct task_struct *task)
67331+{
67332+ if (unlikely(!gr_acl_is_enabled()))
67333+ return 0;
67334+
67335+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67336+ return -EACCES;
67337+
67338+ return 0;
67339+}
67340diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67341new file mode 100644
67342index 0000000..f056b81
67343--- /dev/null
67344+++ b/grsecurity/gracl_ip.c
67345@@ -0,0 +1,386 @@
67346+#include <linux/kernel.h>
67347+#include <asm/uaccess.h>
67348+#include <asm/errno.h>
67349+#include <net/sock.h>
67350+#include <linux/file.h>
67351+#include <linux/fs.h>
67352+#include <linux/net.h>
67353+#include <linux/in.h>
67354+#include <linux/skbuff.h>
67355+#include <linux/ip.h>
67356+#include <linux/udp.h>
67357+#include <linux/types.h>
67358+#include <linux/sched.h>
67359+#include <linux/netdevice.h>
67360+#include <linux/inetdevice.h>
67361+#include <linux/gracl.h>
67362+#include <linux/grsecurity.h>
67363+#include <linux/grinternal.h>
67364+
67365+#define GR_BIND 0x01
67366+#define GR_CONNECT 0x02
67367+#define GR_INVERT 0x04
67368+#define GR_BINDOVERRIDE 0x08
67369+#define GR_CONNECTOVERRIDE 0x10
67370+#define GR_SOCK_FAMILY 0x20
67371+
67372+static const char * gr_protocols[IPPROTO_MAX] = {
67373+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67374+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67375+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67376+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67377+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67378+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67379+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67380+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67381+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67382+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67383+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67384+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67385+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67386+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67387+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67388+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67389+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67390+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67391+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67392+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67393+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67394+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67395+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67396+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67397+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67398+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67399+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67400+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67401+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67402+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67403+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67404+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67405+ };
67406+
67407+static const char * gr_socktypes[SOCK_MAX] = {
67408+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67409+ "unknown:7", "unknown:8", "unknown:9", "packet"
67410+ };
67411+
67412+static const char * gr_sockfamilies[AF_MAX+1] = {
67413+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67414+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67415+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67416+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67417+ };
67418+
67419+const char *
67420+gr_proto_to_name(unsigned char proto)
67421+{
67422+ return gr_protocols[proto];
67423+}
67424+
67425+const char *
67426+gr_socktype_to_name(unsigned char type)
67427+{
67428+ return gr_socktypes[type];
67429+}
67430+
67431+const char *
67432+gr_sockfamily_to_name(unsigned char family)
67433+{
67434+ return gr_sockfamilies[family];
67435+}
67436+
67437+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67438+
67439+int
67440+gr_search_socket(const int domain, const int type, const int protocol)
67441+{
67442+ struct acl_subject_label *curr;
67443+ const struct cred *cred = current_cred();
67444+
67445+ if (unlikely(!gr_acl_is_enabled()))
67446+ goto exit;
67447+
67448+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67449+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67450+ goto exit; // let the kernel handle it
67451+
67452+ curr = current->acl;
67453+
67454+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67455+ /* the family is allowed, if this is PF_INET allow it only if
67456+ the extra sock type/protocol checks pass */
67457+ if (domain == PF_INET)
67458+ goto inet_check;
67459+ goto exit;
67460+ } else {
67461+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67462+ __u32 fakeip = 0;
67463+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67464+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67465+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67466+ gr_to_filename(current->exec_file->f_path.dentry,
67467+ current->exec_file->f_path.mnt) :
67468+ curr->filename, curr->filename,
67469+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67470+ &current->signal->saved_ip);
67471+ goto exit;
67472+ }
67473+ goto exit_fail;
67474+ }
67475+
67476+inet_check:
67477+ /* the rest of this checking is for IPv4 only */
67478+ if (!curr->ips)
67479+ goto exit;
67480+
67481+ if ((curr->ip_type & (1U << type)) &&
67482+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67483+ goto exit;
67484+
67485+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67486+ /* we don't place acls on raw sockets , and sometimes
67487+ dgram/ip sockets are opened for ioctl and not
67488+ bind/connect, so we'll fake a bind learn log */
67489+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67490+ __u32 fakeip = 0;
67491+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67492+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67493+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67494+ gr_to_filename(current->exec_file->f_path.dentry,
67495+ current->exec_file->f_path.mnt) :
67496+ curr->filename, curr->filename,
67497+ &fakeip, 0, type,
67498+ protocol, GR_CONNECT, &current->signal->saved_ip);
67499+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67500+ __u32 fakeip = 0;
67501+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67502+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67503+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67504+ gr_to_filename(current->exec_file->f_path.dentry,
67505+ current->exec_file->f_path.mnt) :
67506+ curr->filename, curr->filename,
67507+ &fakeip, 0, type,
67508+ protocol, GR_BIND, &current->signal->saved_ip);
67509+ }
67510+ /* we'll log when they use connect or bind */
67511+ goto exit;
67512+ }
67513+
67514+exit_fail:
67515+ if (domain == PF_INET)
67516+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67517+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67518+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67519+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67520+ gr_socktype_to_name(type), protocol);
67521+
67522+ return 0;
67523+exit:
67524+ return 1;
67525+}
67526+
67527+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)
67528+{
67529+ if ((ip->mode & mode) &&
67530+ (ip_port >= ip->low) &&
67531+ (ip_port <= ip->high) &&
67532+ ((ntohl(ip_addr) & our_netmask) ==
67533+ (ntohl(our_addr) & our_netmask))
67534+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67535+ && (ip->type & (1U << type))) {
67536+ if (ip->mode & GR_INVERT)
67537+ return 2; // specifically denied
67538+ else
67539+ return 1; // allowed
67540+ }
67541+
67542+ return 0; // not specifically allowed, may continue parsing
67543+}
67544+
67545+static int
67546+gr_search_connectbind(const int full_mode, struct sock *sk,
67547+ struct sockaddr_in *addr, const int type)
67548+{
67549+ char iface[IFNAMSIZ] = {0};
67550+ struct acl_subject_label *curr;
67551+ struct acl_ip_label *ip;
67552+ struct inet_sock *isk;
67553+ struct net_device *dev;
67554+ struct in_device *idev;
67555+ unsigned long i;
67556+ int ret;
67557+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67558+ __u32 ip_addr = 0;
67559+ __u32 our_addr;
67560+ __u32 our_netmask;
67561+ char *p;
67562+ __u16 ip_port = 0;
67563+ const struct cred *cred = current_cred();
67564+
67565+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67566+ return 0;
67567+
67568+ curr = current->acl;
67569+ isk = inet_sk(sk);
67570+
67571+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67572+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67573+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67574+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67575+ struct sockaddr_in saddr;
67576+ int err;
67577+
67578+ saddr.sin_family = AF_INET;
67579+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67580+ saddr.sin_port = isk->inet_sport;
67581+
67582+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67583+ if (err)
67584+ return err;
67585+
67586+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67587+ if (err)
67588+ return err;
67589+ }
67590+
67591+ if (!curr->ips)
67592+ return 0;
67593+
67594+ ip_addr = addr->sin_addr.s_addr;
67595+ ip_port = ntohs(addr->sin_port);
67596+
67597+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67598+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67599+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67600+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67601+ gr_to_filename(current->exec_file->f_path.dentry,
67602+ current->exec_file->f_path.mnt) :
67603+ curr->filename, curr->filename,
67604+ &ip_addr, ip_port, type,
67605+ sk->sk_protocol, mode, &current->signal->saved_ip);
67606+ return 0;
67607+ }
67608+
67609+ for (i = 0; i < curr->ip_num; i++) {
67610+ ip = *(curr->ips + i);
67611+ if (ip->iface != NULL) {
67612+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67613+ p = strchr(iface, ':');
67614+ if (p != NULL)
67615+ *p = '\0';
67616+ dev = dev_get_by_name(sock_net(sk), iface);
67617+ if (dev == NULL)
67618+ continue;
67619+ idev = in_dev_get(dev);
67620+ if (idev == NULL) {
67621+ dev_put(dev);
67622+ continue;
67623+ }
67624+ rcu_read_lock();
67625+ for_ifa(idev) {
67626+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67627+ our_addr = ifa->ifa_address;
67628+ our_netmask = 0xffffffff;
67629+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67630+ if (ret == 1) {
67631+ rcu_read_unlock();
67632+ in_dev_put(idev);
67633+ dev_put(dev);
67634+ return 0;
67635+ } else if (ret == 2) {
67636+ rcu_read_unlock();
67637+ in_dev_put(idev);
67638+ dev_put(dev);
67639+ goto denied;
67640+ }
67641+ }
67642+ } endfor_ifa(idev);
67643+ rcu_read_unlock();
67644+ in_dev_put(idev);
67645+ dev_put(dev);
67646+ } else {
67647+ our_addr = ip->addr;
67648+ our_netmask = ip->netmask;
67649+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67650+ if (ret == 1)
67651+ return 0;
67652+ else if (ret == 2)
67653+ goto denied;
67654+ }
67655+ }
67656+
67657+denied:
67658+ if (mode == GR_BIND)
67659+ 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));
67660+ else if (mode == GR_CONNECT)
67661+ 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));
67662+
67663+ return -EACCES;
67664+}
67665+
67666+int
67667+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67668+{
67669+ /* always allow disconnection of dgram sockets with connect */
67670+ if (addr->sin_family == AF_UNSPEC)
67671+ return 0;
67672+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67673+}
67674+
67675+int
67676+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67677+{
67678+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67679+}
67680+
67681+int gr_search_listen(struct socket *sock)
67682+{
67683+ struct sock *sk = sock->sk;
67684+ struct sockaddr_in addr;
67685+
67686+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67687+ addr.sin_port = inet_sk(sk)->inet_sport;
67688+
67689+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67690+}
67691+
67692+int gr_search_accept(struct socket *sock)
67693+{
67694+ struct sock *sk = sock->sk;
67695+ struct sockaddr_in addr;
67696+
67697+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67698+ addr.sin_port = inet_sk(sk)->inet_sport;
67699+
67700+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67701+}
67702+
67703+int
67704+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67705+{
67706+ if (addr)
67707+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67708+ else {
67709+ struct sockaddr_in sin;
67710+ const struct inet_sock *inet = inet_sk(sk);
67711+
67712+ sin.sin_addr.s_addr = inet->inet_daddr;
67713+ sin.sin_port = inet->inet_dport;
67714+
67715+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67716+ }
67717+}
67718+
67719+int
67720+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67721+{
67722+ struct sockaddr_in sin;
67723+
67724+ if (unlikely(skb->len < sizeof (struct udphdr)))
67725+ return 0; // skip this packet
67726+
67727+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67728+ sin.sin_port = udp_hdr(skb)->source;
67729+
67730+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67731+}
67732diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67733new file mode 100644
67734index 0000000..25f54ef
67735--- /dev/null
67736+++ b/grsecurity/gracl_learn.c
67737@@ -0,0 +1,207 @@
67738+#include <linux/kernel.h>
67739+#include <linux/mm.h>
67740+#include <linux/sched.h>
67741+#include <linux/poll.h>
67742+#include <linux/string.h>
67743+#include <linux/file.h>
67744+#include <linux/types.h>
67745+#include <linux/vmalloc.h>
67746+#include <linux/grinternal.h>
67747+
67748+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67749+ size_t count, loff_t *ppos);
67750+extern int gr_acl_is_enabled(void);
67751+
67752+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67753+static int gr_learn_attached;
67754+
67755+/* use a 512k buffer */
67756+#define LEARN_BUFFER_SIZE (512 * 1024)
67757+
67758+static DEFINE_SPINLOCK(gr_learn_lock);
67759+static DEFINE_MUTEX(gr_learn_user_mutex);
67760+
67761+/* we need to maintain two buffers, so that the kernel context of grlearn
67762+ uses a semaphore around the userspace copying, and the other kernel contexts
67763+ use a spinlock when copying into the buffer, since they cannot sleep
67764+*/
67765+static char *learn_buffer;
67766+static char *learn_buffer_user;
67767+static int learn_buffer_len;
67768+static int learn_buffer_user_len;
67769+
67770+static ssize_t
67771+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67772+{
67773+ DECLARE_WAITQUEUE(wait, current);
67774+ ssize_t retval = 0;
67775+
67776+ add_wait_queue(&learn_wait, &wait);
67777+ set_current_state(TASK_INTERRUPTIBLE);
67778+ do {
67779+ mutex_lock(&gr_learn_user_mutex);
67780+ spin_lock(&gr_learn_lock);
67781+ if (learn_buffer_len)
67782+ break;
67783+ spin_unlock(&gr_learn_lock);
67784+ mutex_unlock(&gr_learn_user_mutex);
67785+ if (file->f_flags & O_NONBLOCK) {
67786+ retval = -EAGAIN;
67787+ goto out;
67788+ }
67789+ if (signal_pending(current)) {
67790+ retval = -ERESTARTSYS;
67791+ goto out;
67792+ }
67793+
67794+ schedule();
67795+ } while (1);
67796+
67797+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67798+ learn_buffer_user_len = learn_buffer_len;
67799+ retval = learn_buffer_len;
67800+ learn_buffer_len = 0;
67801+
67802+ spin_unlock(&gr_learn_lock);
67803+
67804+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67805+ retval = -EFAULT;
67806+
67807+ mutex_unlock(&gr_learn_user_mutex);
67808+out:
67809+ set_current_state(TASK_RUNNING);
67810+ remove_wait_queue(&learn_wait, &wait);
67811+ return retval;
67812+}
67813+
67814+static unsigned int
67815+poll_learn(struct file * file, poll_table * wait)
67816+{
67817+ poll_wait(file, &learn_wait, wait);
67818+
67819+ if (learn_buffer_len)
67820+ return (POLLIN | POLLRDNORM);
67821+
67822+ return 0;
67823+}
67824+
67825+void
67826+gr_clear_learn_entries(void)
67827+{
67828+ char *tmp;
67829+
67830+ mutex_lock(&gr_learn_user_mutex);
67831+ spin_lock(&gr_learn_lock);
67832+ tmp = learn_buffer;
67833+ learn_buffer = NULL;
67834+ spin_unlock(&gr_learn_lock);
67835+ if (tmp)
67836+ vfree(tmp);
67837+ if (learn_buffer_user != NULL) {
67838+ vfree(learn_buffer_user);
67839+ learn_buffer_user = NULL;
67840+ }
67841+ learn_buffer_len = 0;
67842+ mutex_unlock(&gr_learn_user_mutex);
67843+
67844+ return;
67845+}
67846+
67847+void
67848+gr_add_learn_entry(const char *fmt, ...)
67849+{
67850+ va_list args;
67851+ unsigned int len;
67852+
67853+ if (!gr_learn_attached)
67854+ return;
67855+
67856+ spin_lock(&gr_learn_lock);
67857+
67858+ /* leave a gap at the end so we know when it's "full" but don't have to
67859+ compute the exact length of the string we're trying to append
67860+ */
67861+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67862+ spin_unlock(&gr_learn_lock);
67863+ wake_up_interruptible(&learn_wait);
67864+ return;
67865+ }
67866+ if (learn_buffer == NULL) {
67867+ spin_unlock(&gr_learn_lock);
67868+ return;
67869+ }
67870+
67871+ va_start(args, fmt);
67872+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67873+ va_end(args);
67874+
67875+ learn_buffer_len += len + 1;
67876+
67877+ spin_unlock(&gr_learn_lock);
67878+ wake_up_interruptible(&learn_wait);
67879+
67880+ return;
67881+}
67882+
67883+static int
67884+open_learn(struct inode *inode, struct file *file)
67885+{
67886+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67887+ return -EBUSY;
67888+ if (file->f_mode & FMODE_READ) {
67889+ int retval = 0;
67890+ mutex_lock(&gr_learn_user_mutex);
67891+ if (learn_buffer == NULL)
67892+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67893+ if (learn_buffer_user == NULL)
67894+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67895+ if (learn_buffer == NULL) {
67896+ retval = -ENOMEM;
67897+ goto out_error;
67898+ }
67899+ if (learn_buffer_user == NULL) {
67900+ retval = -ENOMEM;
67901+ goto out_error;
67902+ }
67903+ learn_buffer_len = 0;
67904+ learn_buffer_user_len = 0;
67905+ gr_learn_attached = 1;
67906+out_error:
67907+ mutex_unlock(&gr_learn_user_mutex);
67908+ return retval;
67909+ }
67910+ return 0;
67911+}
67912+
67913+static int
67914+close_learn(struct inode *inode, struct file *file)
67915+{
67916+ if (file->f_mode & FMODE_READ) {
67917+ char *tmp = NULL;
67918+ mutex_lock(&gr_learn_user_mutex);
67919+ spin_lock(&gr_learn_lock);
67920+ tmp = learn_buffer;
67921+ learn_buffer = NULL;
67922+ spin_unlock(&gr_learn_lock);
67923+ if (tmp)
67924+ vfree(tmp);
67925+ if (learn_buffer_user != NULL) {
67926+ vfree(learn_buffer_user);
67927+ learn_buffer_user = NULL;
67928+ }
67929+ learn_buffer_len = 0;
67930+ learn_buffer_user_len = 0;
67931+ gr_learn_attached = 0;
67932+ mutex_unlock(&gr_learn_user_mutex);
67933+ }
67934+
67935+ return 0;
67936+}
67937+
67938+const struct file_operations grsec_fops = {
67939+ .read = read_learn,
67940+ .write = write_grsec_handler,
67941+ .open = open_learn,
67942+ .release = close_learn,
67943+ .poll = poll_learn,
67944+};
67945diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
67946new file mode 100644
67947index 0000000..361a099
67948--- /dev/null
67949+++ b/grsecurity/gracl_policy.c
67950@@ -0,0 +1,1782 @@
67951+#include <linux/kernel.h>
67952+#include <linux/module.h>
67953+#include <linux/sched.h>
67954+#include <linux/mm.h>
67955+#include <linux/file.h>
67956+#include <linux/fs.h>
67957+#include <linux/namei.h>
67958+#include <linux/mount.h>
67959+#include <linux/tty.h>
67960+#include <linux/proc_fs.h>
67961+#include <linux/lglock.h>
67962+#include <linux/slab.h>
67963+#include <linux/vmalloc.h>
67964+#include <linux/types.h>
67965+#include <linux/sysctl.h>
67966+#include <linux/netdevice.h>
67967+#include <linux/ptrace.h>
67968+#include <linux/gracl.h>
67969+#include <linux/gralloc.h>
67970+#include <linux/security.h>
67971+#include <linux/grinternal.h>
67972+#include <linux/pid_namespace.h>
67973+#include <linux/stop_machine.h>
67974+#include <linux/fdtable.h>
67975+#include <linux/percpu.h>
67976+#include <linux/lglock.h>
67977+#include <linux/hugetlb.h>
67978+#include <linux/posix-timers.h>
67979+#include "../fs/mount.h"
67980+
67981+#include <asm/uaccess.h>
67982+#include <asm/errno.h>
67983+#include <asm/mman.h>
67984+
67985+extern struct gr_policy_state *polstate;
67986+
67987+#define FOR_EACH_ROLE_START(role) \
67988+ role = polstate->role_list; \
67989+ while (role) {
67990+
67991+#define FOR_EACH_ROLE_END(role) \
67992+ role = role->prev; \
67993+ }
67994+
67995+struct path gr_real_root;
67996+
67997+extern struct gr_alloc_state *current_alloc_state;
67998+
67999+u16 acl_sp_role_value;
68000+
68001+static DEFINE_MUTEX(gr_dev_mutex);
68002+
68003+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
68004+extern void gr_clear_learn_entries(void);
68005+
68006+static struct gr_arg gr_usermode;
68007+static unsigned char gr_system_salt[GR_SALT_LEN];
68008+static unsigned char gr_system_sum[GR_SHA_LEN];
68009+
68010+static unsigned int gr_auth_attempts = 0;
68011+static unsigned long gr_auth_expires = 0UL;
68012+
68013+struct acl_object_label *fakefs_obj_rw;
68014+struct acl_object_label *fakefs_obj_rwx;
68015+
68016+extern int gr_init_uidset(void);
68017+extern void gr_free_uidset(void);
68018+extern void gr_remove_uid(uid_t uid);
68019+extern int gr_find_uid(uid_t uid);
68020+
68021+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
68022+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
68023+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
68024+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
68025+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);
68026+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
68027+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
68028+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
68029+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
68030+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
68031+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
68032+extern void assign_special_role(const char *rolename);
68033+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
68034+extern int gr_rbac_disable(void *unused);
68035+extern void gr_enable_rbac_system(void);
68036+
68037+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
68038+{
68039+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
68040+ return -EFAULT;
68041+
68042+ return 0;
68043+}
68044+
68045+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68046+{
68047+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
68048+ return -EFAULT;
68049+
68050+ return 0;
68051+}
68052+
68053+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68054+{
68055+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
68056+ return -EFAULT;
68057+
68058+ return 0;
68059+}
68060+
68061+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
68062+{
68063+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
68064+ return -EFAULT;
68065+
68066+ return 0;
68067+}
68068+
68069+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68070+{
68071+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
68072+ return -EFAULT;
68073+
68074+ return 0;
68075+}
68076+
68077+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68078+{
68079+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
68080+ return -EFAULT;
68081+
68082+ return 0;
68083+}
68084+
68085+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68086+{
68087+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
68088+ return -EFAULT;
68089+
68090+ return 0;
68091+}
68092+
68093+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
68094+{
68095+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
68096+ return -EFAULT;
68097+
68098+ return 0;
68099+}
68100+
68101+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
68102+{
68103+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
68104+ return -EFAULT;
68105+
68106+ return 0;
68107+}
68108+
68109+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
68110+{
68111+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
68112+ return -EFAULT;
68113+
68114+ if (((uwrap->version != GRSECURITY_VERSION) &&
68115+ (uwrap->version != 0x2901)) ||
68116+ (uwrap->size != sizeof(struct gr_arg)))
68117+ return -EINVAL;
68118+
68119+ return 0;
68120+}
68121+
68122+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
68123+{
68124+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
68125+ return -EFAULT;
68126+
68127+ return 0;
68128+}
68129+
68130+static size_t get_gr_arg_wrapper_size_normal(void)
68131+{
68132+ return sizeof(struct gr_arg_wrapper);
68133+}
68134+
68135+#ifdef CONFIG_COMPAT
68136+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
68137+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
68138+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
68139+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
68140+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
68141+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
68142+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
68143+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
68144+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
68145+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
68146+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
68147+extern size_t get_gr_arg_wrapper_size_compat(void);
68148+
68149+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
68150+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
68151+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
68152+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
68153+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
68154+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
68155+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
68156+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
68157+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
68158+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
68159+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
68160+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
68161+
68162+#else
68163+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
68164+#define copy_gr_arg copy_gr_arg_normal
68165+#define copy_gr_hash_struct copy_gr_hash_struct_normal
68166+#define copy_acl_object_label copy_acl_object_label_normal
68167+#define copy_acl_subject_label copy_acl_subject_label_normal
68168+#define copy_acl_role_label copy_acl_role_label_normal
68169+#define copy_acl_ip_label copy_acl_ip_label_normal
68170+#define copy_pointer_from_array copy_pointer_from_array_normal
68171+#define copy_sprole_pw copy_sprole_pw_normal
68172+#define copy_role_transition copy_role_transition_normal
68173+#define copy_role_allowed_ip copy_role_allowed_ip_normal
68174+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
68175+#endif
68176+
68177+static struct acl_subject_label *
68178+lookup_subject_map(const struct acl_subject_label *userp)
68179+{
68180+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
68181+ struct subject_map *match;
68182+
68183+ match = polstate->subj_map_set.s_hash[index];
68184+
68185+ while (match && match->user != userp)
68186+ match = match->next;
68187+
68188+ if (match != NULL)
68189+ return match->kernel;
68190+ else
68191+ return NULL;
68192+}
68193+
68194+static void
68195+insert_subj_map_entry(struct subject_map *subjmap)
68196+{
68197+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
68198+ struct subject_map **curr;
68199+
68200+ subjmap->prev = NULL;
68201+
68202+ curr = &polstate->subj_map_set.s_hash[index];
68203+ if (*curr != NULL)
68204+ (*curr)->prev = subjmap;
68205+
68206+ subjmap->next = *curr;
68207+ *curr = subjmap;
68208+
68209+ return;
68210+}
68211+
68212+static void
68213+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
68214+{
68215+ unsigned int index =
68216+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
68217+ struct acl_role_label **curr;
68218+ struct acl_role_label *tmp, *tmp2;
68219+
68220+ curr = &polstate->acl_role_set.r_hash[index];
68221+
68222+ /* simple case, slot is empty, just set it to our role */
68223+ if (*curr == NULL) {
68224+ *curr = role;
68225+ } else {
68226+ /* example:
68227+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
68228+ 2 -> 3
68229+ */
68230+ /* first check to see if we can already be reached via this slot */
68231+ tmp = *curr;
68232+ while (tmp && tmp != role)
68233+ tmp = tmp->next;
68234+ if (tmp == role) {
68235+ /* we don't need to add ourselves to this slot's chain */
68236+ return;
68237+ }
68238+ /* we need to add ourselves to this chain, two cases */
68239+ if (role->next == NULL) {
68240+ /* simple case, append the current chain to our role */
68241+ role->next = *curr;
68242+ *curr = role;
68243+ } else {
68244+ /* 1 -> 2 -> 3 -> 4
68245+ 2 -> 3 -> 4
68246+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
68247+ */
68248+ /* trickier case: walk our role's chain until we find
68249+ the role for the start of the current slot's chain */
68250+ tmp = role;
68251+ tmp2 = *curr;
68252+ while (tmp->next && tmp->next != tmp2)
68253+ tmp = tmp->next;
68254+ if (tmp->next == tmp2) {
68255+ /* from example above, we found 3, so just
68256+ replace this slot's chain with ours */
68257+ *curr = role;
68258+ } else {
68259+ /* we didn't find a subset of our role's chain
68260+ in the current slot's chain, so append their
68261+ chain to ours, and set us as the first role in
68262+ the slot's chain
68263+
68264+ we could fold this case with the case above,
68265+ but making it explicit for clarity
68266+ */
68267+ tmp->next = tmp2;
68268+ *curr = role;
68269+ }
68270+ }
68271+ }
68272+
68273+ return;
68274+}
68275+
68276+static void
68277+insert_acl_role_label(struct acl_role_label *role)
68278+{
68279+ int i;
68280+
68281+ if (polstate->role_list == NULL) {
68282+ polstate->role_list = role;
68283+ role->prev = NULL;
68284+ } else {
68285+ role->prev = polstate->role_list;
68286+ polstate->role_list = role;
68287+ }
68288+
68289+ /* used for hash chains */
68290+ role->next = NULL;
68291+
68292+ if (role->roletype & GR_ROLE_DOMAIN) {
68293+ for (i = 0; i < role->domain_child_num; i++)
68294+ __insert_acl_role_label(role, role->domain_children[i]);
68295+ } else
68296+ __insert_acl_role_label(role, role->uidgid);
68297+}
68298+
68299+static int
68300+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
68301+{
68302+ struct name_entry **curr, *nentry;
68303+ struct inodev_entry *ientry;
68304+ unsigned int len = strlen(name);
68305+ unsigned int key = full_name_hash(name, len);
68306+ unsigned int index = key % polstate->name_set.n_size;
68307+
68308+ curr = &polstate->name_set.n_hash[index];
68309+
68310+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
68311+ curr = &((*curr)->next);
68312+
68313+ if (*curr != NULL)
68314+ return 1;
68315+
68316+ nentry = acl_alloc(sizeof (struct name_entry));
68317+ if (nentry == NULL)
68318+ return 0;
68319+ ientry = acl_alloc(sizeof (struct inodev_entry));
68320+ if (ientry == NULL)
68321+ return 0;
68322+ ientry->nentry = nentry;
68323+
68324+ nentry->key = key;
68325+ nentry->name = name;
68326+ nentry->inode = inode;
68327+ nentry->device = device;
68328+ nentry->len = len;
68329+ nentry->deleted = deleted;
68330+
68331+ nentry->prev = NULL;
68332+ curr = &polstate->name_set.n_hash[index];
68333+ if (*curr != NULL)
68334+ (*curr)->prev = nentry;
68335+ nentry->next = *curr;
68336+ *curr = nentry;
68337+
68338+ /* insert us into the table searchable by inode/dev */
68339+ __insert_inodev_entry(polstate, ientry);
68340+
68341+ return 1;
68342+}
68343+
68344+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
68345+
68346+static void *
68347+create_table(__u32 * len, int elementsize)
68348+{
68349+ unsigned int table_sizes[] = {
68350+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
68351+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
68352+ 4194301, 8388593, 16777213, 33554393, 67108859
68353+ };
68354+ void *newtable = NULL;
68355+ unsigned int pwr = 0;
68356+
68357+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
68358+ table_sizes[pwr] <= *len)
68359+ pwr++;
68360+
68361+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
68362+ return newtable;
68363+
68364+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
68365+ newtable =
68366+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
68367+ else
68368+ newtable = vmalloc(table_sizes[pwr] * elementsize);
68369+
68370+ *len = table_sizes[pwr];
68371+
68372+ return newtable;
68373+}
68374+
68375+static int
68376+init_variables(const struct gr_arg *arg, bool reload)
68377+{
68378+ struct task_struct *reaper = init_pid_ns.child_reaper;
68379+ unsigned int stacksize;
68380+
68381+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
68382+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
68383+ polstate->name_set.n_size = arg->role_db.num_objects;
68384+ polstate->inodev_set.i_size = arg->role_db.num_objects;
68385+
68386+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
68387+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
68388+ return 1;
68389+
68390+ if (!reload) {
68391+ if (!gr_init_uidset())
68392+ return 1;
68393+ }
68394+
68395+ /* set up the stack that holds allocation info */
68396+
68397+ stacksize = arg->role_db.num_pointers + 5;
68398+
68399+ if (!acl_alloc_stack_init(stacksize))
68400+ return 1;
68401+
68402+ if (!reload) {
68403+ /* grab reference for the real root dentry and vfsmount */
68404+ get_fs_root(reaper->fs, &gr_real_root);
68405+
68406+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68407+ 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);
68408+#endif
68409+
68410+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
68411+ if (fakefs_obj_rw == NULL)
68412+ return 1;
68413+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
68414+
68415+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
68416+ if (fakefs_obj_rwx == NULL)
68417+ return 1;
68418+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
68419+ }
68420+
68421+ polstate->subj_map_set.s_hash =
68422+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
68423+ polstate->acl_role_set.r_hash =
68424+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
68425+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
68426+ polstate->inodev_set.i_hash =
68427+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
68428+
68429+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
68430+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
68431+ return 1;
68432+
68433+ memset(polstate->subj_map_set.s_hash, 0,
68434+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
68435+ memset(polstate->acl_role_set.r_hash, 0,
68436+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
68437+ memset(polstate->name_set.n_hash, 0,
68438+ sizeof (struct name_entry *) * polstate->name_set.n_size);
68439+ memset(polstate->inodev_set.i_hash, 0,
68440+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
68441+
68442+ return 0;
68443+}
68444+
68445+/* free information not needed after startup
68446+ currently contains user->kernel pointer mappings for subjects
68447+*/
68448+
68449+static void
68450+free_init_variables(void)
68451+{
68452+ __u32 i;
68453+
68454+ if (polstate->subj_map_set.s_hash) {
68455+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
68456+ if (polstate->subj_map_set.s_hash[i]) {
68457+ kfree(polstate->subj_map_set.s_hash[i]);
68458+ polstate->subj_map_set.s_hash[i] = NULL;
68459+ }
68460+ }
68461+
68462+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
68463+ PAGE_SIZE)
68464+ kfree(polstate->subj_map_set.s_hash);
68465+ else
68466+ vfree(polstate->subj_map_set.s_hash);
68467+ }
68468+
68469+ return;
68470+}
68471+
68472+static void
68473+free_variables(bool reload)
68474+{
68475+ struct acl_subject_label *s;
68476+ struct acl_role_label *r;
68477+ struct task_struct *task, *task2;
68478+ unsigned int x;
68479+
68480+ if (!reload) {
68481+ gr_clear_learn_entries();
68482+
68483+ read_lock(&tasklist_lock);
68484+ do_each_thread(task2, task) {
68485+ task->acl_sp_role = 0;
68486+ task->acl_role_id = 0;
68487+ task->inherited = 0;
68488+ task->acl = NULL;
68489+ task->role = NULL;
68490+ } while_each_thread(task2, task);
68491+ read_unlock(&tasklist_lock);
68492+
68493+ kfree(fakefs_obj_rw);
68494+ fakefs_obj_rw = NULL;
68495+ kfree(fakefs_obj_rwx);
68496+ fakefs_obj_rwx = NULL;
68497+
68498+ /* release the reference to the real root dentry and vfsmount */
68499+ path_put(&gr_real_root);
68500+ memset(&gr_real_root, 0, sizeof(gr_real_root));
68501+ }
68502+
68503+ /* free all object hash tables */
68504+
68505+ FOR_EACH_ROLE_START(r)
68506+ if (r->subj_hash == NULL)
68507+ goto next_role;
68508+ FOR_EACH_SUBJECT_START(r, s, x)
68509+ if (s->obj_hash == NULL)
68510+ break;
68511+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
68512+ kfree(s->obj_hash);
68513+ else
68514+ vfree(s->obj_hash);
68515+ FOR_EACH_SUBJECT_END(s, x)
68516+ FOR_EACH_NESTED_SUBJECT_START(r, s)
68517+ if (s->obj_hash == NULL)
68518+ break;
68519+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
68520+ kfree(s->obj_hash);
68521+ else
68522+ vfree(s->obj_hash);
68523+ FOR_EACH_NESTED_SUBJECT_END(s)
68524+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
68525+ kfree(r->subj_hash);
68526+ else
68527+ vfree(r->subj_hash);
68528+ r->subj_hash = NULL;
68529+next_role:
68530+ FOR_EACH_ROLE_END(r)
68531+
68532+ acl_free_all();
68533+
68534+ if (polstate->acl_role_set.r_hash) {
68535+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
68536+ PAGE_SIZE)
68537+ kfree(polstate->acl_role_set.r_hash);
68538+ else
68539+ vfree(polstate->acl_role_set.r_hash);
68540+ }
68541+ if (polstate->name_set.n_hash) {
68542+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
68543+ PAGE_SIZE)
68544+ kfree(polstate->name_set.n_hash);
68545+ else
68546+ vfree(polstate->name_set.n_hash);
68547+ }
68548+
68549+ if (polstate->inodev_set.i_hash) {
68550+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
68551+ PAGE_SIZE)
68552+ kfree(polstate->inodev_set.i_hash);
68553+ else
68554+ vfree(polstate->inodev_set.i_hash);
68555+ }
68556+
68557+ if (!reload)
68558+ gr_free_uidset();
68559+
68560+ memset(&polstate->name_set, 0, sizeof (struct name_db));
68561+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
68562+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
68563+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
68564+
68565+ polstate->default_role = NULL;
68566+ polstate->kernel_role = NULL;
68567+ polstate->role_list = NULL;
68568+
68569+ return;
68570+}
68571+
68572+static struct acl_subject_label *
68573+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
68574+
68575+static int alloc_and_copy_string(char **name, unsigned int maxlen)
68576+{
68577+ unsigned int len = strnlen_user(*name, maxlen);
68578+ char *tmp;
68579+
68580+ if (!len || len >= maxlen)
68581+ return -EINVAL;
68582+
68583+ if ((tmp = (char *) acl_alloc(len)) == NULL)
68584+ return -ENOMEM;
68585+
68586+ if (copy_from_user(tmp, *name, len))
68587+ return -EFAULT;
68588+
68589+ tmp[len-1] = '\0';
68590+ *name = tmp;
68591+
68592+ return 0;
68593+}
68594+
68595+static int
68596+copy_user_glob(struct acl_object_label *obj)
68597+{
68598+ struct acl_object_label *g_tmp, **guser;
68599+ int error;
68600+
68601+ if (obj->globbed == NULL)
68602+ return 0;
68603+
68604+ guser = &obj->globbed;
68605+ while (*guser) {
68606+ g_tmp = (struct acl_object_label *)
68607+ acl_alloc(sizeof (struct acl_object_label));
68608+ if (g_tmp == NULL)
68609+ return -ENOMEM;
68610+
68611+ if (copy_acl_object_label(g_tmp, *guser))
68612+ return -EFAULT;
68613+
68614+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
68615+ if (error)
68616+ return error;
68617+
68618+ *guser = g_tmp;
68619+ guser = &(g_tmp->next);
68620+ }
68621+
68622+ return 0;
68623+}
68624+
68625+static int
68626+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
68627+ struct acl_role_label *role)
68628+{
68629+ struct acl_object_label *o_tmp;
68630+ int ret;
68631+
68632+ while (userp) {
68633+ if ((o_tmp = (struct acl_object_label *)
68634+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
68635+ return -ENOMEM;
68636+
68637+ if (copy_acl_object_label(o_tmp, userp))
68638+ return -EFAULT;
68639+
68640+ userp = o_tmp->prev;
68641+
68642+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
68643+ if (ret)
68644+ return ret;
68645+
68646+ insert_acl_obj_label(o_tmp, subj);
68647+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
68648+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
68649+ return -ENOMEM;
68650+
68651+ ret = copy_user_glob(o_tmp);
68652+ if (ret)
68653+ return ret;
68654+
68655+ if (o_tmp->nested) {
68656+ int already_copied;
68657+
68658+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
68659+ if (IS_ERR(o_tmp->nested))
68660+ return PTR_ERR(o_tmp->nested);
68661+
68662+ /* insert into nested subject list if we haven't copied this one yet
68663+ to prevent duplicate entries */
68664+ if (!already_copied) {
68665+ o_tmp->nested->next = role->hash->first;
68666+ role->hash->first = o_tmp->nested;
68667+ }
68668+ }
68669+ }
68670+
68671+ return 0;
68672+}
68673+
68674+static __u32
68675+count_user_subjs(struct acl_subject_label *userp)
68676+{
68677+ struct acl_subject_label s_tmp;
68678+ __u32 num = 0;
68679+
68680+ while (userp) {
68681+ if (copy_acl_subject_label(&s_tmp, userp))
68682+ break;
68683+
68684+ userp = s_tmp.prev;
68685+ }
68686+
68687+ return num;
68688+}
68689+
68690+static int
68691+copy_user_allowedips(struct acl_role_label *rolep)
68692+{
68693+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
68694+
68695+ ruserip = rolep->allowed_ips;
68696+
68697+ while (ruserip) {
68698+ rlast = rtmp;
68699+
68700+ if ((rtmp = (struct role_allowed_ip *)
68701+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
68702+ return -ENOMEM;
68703+
68704+ if (copy_role_allowed_ip(rtmp, ruserip))
68705+ return -EFAULT;
68706+
68707+ ruserip = rtmp->prev;
68708+
68709+ if (!rlast) {
68710+ rtmp->prev = NULL;
68711+ rolep->allowed_ips = rtmp;
68712+ } else {
68713+ rlast->next = rtmp;
68714+ rtmp->prev = rlast;
68715+ }
68716+
68717+ if (!ruserip)
68718+ rtmp->next = NULL;
68719+ }
68720+
68721+ return 0;
68722+}
68723+
68724+static int
68725+copy_user_transitions(struct acl_role_label *rolep)
68726+{
68727+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
68728+ int error;
68729+
68730+ rusertp = rolep->transitions;
68731+
68732+ while (rusertp) {
68733+ rlast = rtmp;
68734+
68735+ if ((rtmp = (struct role_transition *)
68736+ acl_alloc(sizeof (struct role_transition))) == NULL)
68737+ return -ENOMEM;
68738+
68739+ if (copy_role_transition(rtmp, rusertp))
68740+ return -EFAULT;
68741+
68742+ rusertp = rtmp->prev;
68743+
68744+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
68745+ if (error)
68746+ return error;
68747+
68748+ if (!rlast) {
68749+ rtmp->prev = NULL;
68750+ rolep->transitions = rtmp;
68751+ } else {
68752+ rlast->next = rtmp;
68753+ rtmp->prev = rlast;
68754+ }
68755+
68756+ if (!rusertp)
68757+ rtmp->next = NULL;
68758+ }
68759+
68760+ return 0;
68761+}
68762+
68763+static __u32 count_user_objs(const struct acl_object_label __user *userp)
68764+{
68765+ struct acl_object_label o_tmp;
68766+ __u32 num = 0;
68767+
68768+ while (userp) {
68769+ if (copy_acl_object_label(&o_tmp, userp))
68770+ break;
68771+
68772+ userp = o_tmp.prev;
68773+ num++;
68774+ }
68775+
68776+ return num;
68777+}
68778+
68779+static struct acl_subject_label *
68780+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
68781+{
68782+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
68783+ __u32 num_objs;
68784+ struct acl_ip_label **i_tmp, *i_utmp2;
68785+ struct gr_hash_struct ghash;
68786+ struct subject_map *subjmap;
68787+ unsigned int i_num;
68788+ int err;
68789+
68790+ if (already_copied != NULL)
68791+ *already_copied = 0;
68792+
68793+ s_tmp = lookup_subject_map(userp);
68794+
68795+ /* we've already copied this subject into the kernel, just return
68796+ the reference to it, and don't copy it over again
68797+ */
68798+ if (s_tmp) {
68799+ if (already_copied != NULL)
68800+ *already_copied = 1;
68801+ return(s_tmp);
68802+ }
68803+
68804+ if ((s_tmp = (struct acl_subject_label *)
68805+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
68806+ return ERR_PTR(-ENOMEM);
68807+
68808+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
68809+ if (subjmap == NULL)
68810+ return ERR_PTR(-ENOMEM);
68811+
68812+ subjmap->user = userp;
68813+ subjmap->kernel = s_tmp;
68814+ insert_subj_map_entry(subjmap);
68815+
68816+ if (copy_acl_subject_label(s_tmp, userp))
68817+ return ERR_PTR(-EFAULT);
68818+
68819+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
68820+ if (err)
68821+ return ERR_PTR(err);
68822+
68823+ if (!strcmp(s_tmp->filename, "/"))
68824+ role->root_label = s_tmp;
68825+
68826+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
68827+ return ERR_PTR(-EFAULT);
68828+
68829+ /* copy user and group transition tables */
68830+
68831+ if (s_tmp->user_trans_num) {
68832+ uid_t *uidlist;
68833+
68834+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
68835+ if (uidlist == NULL)
68836+ return ERR_PTR(-ENOMEM);
68837+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
68838+ return ERR_PTR(-EFAULT);
68839+
68840+ s_tmp->user_transitions = uidlist;
68841+ }
68842+
68843+ if (s_tmp->group_trans_num) {
68844+ gid_t *gidlist;
68845+
68846+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
68847+ if (gidlist == NULL)
68848+ return ERR_PTR(-ENOMEM);
68849+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
68850+ return ERR_PTR(-EFAULT);
68851+
68852+ s_tmp->group_transitions = gidlist;
68853+ }
68854+
68855+ /* set up object hash table */
68856+ num_objs = count_user_objs(ghash.first);
68857+
68858+ s_tmp->obj_hash_size = num_objs;
68859+ s_tmp->obj_hash =
68860+ (struct acl_object_label **)
68861+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
68862+
68863+ if (!s_tmp->obj_hash)
68864+ return ERR_PTR(-ENOMEM);
68865+
68866+ memset(s_tmp->obj_hash, 0,
68867+ s_tmp->obj_hash_size *
68868+ sizeof (struct acl_object_label *));
68869+
68870+ /* add in objects */
68871+ err = copy_user_objs(ghash.first, s_tmp, role);
68872+
68873+ if (err)
68874+ return ERR_PTR(err);
68875+
68876+ /* set pointer for parent subject */
68877+ if (s_tmp->parent_subject) {
68878+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
68879+
68880+ if (IS_ERR(s_tmp2))
68881+ return s_tmp2;
68882+
68883+ s_tmp->parent_subject = s_tmp2;
68884+ }
68885+
68886+ /* add in ip acls */
68887+
68888+ if (!s_tmp->ip_num) {
68889+ s_tmp->ips = NULL;
68890+ goto insert;
68891+ }
68892+
68893+ i_tmp =
68894+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
68895+ sizeof (struct acl_ip_label *));
68896+
68897+ if (!i_tmp)
68898+ return ERR_PTR(-ENOMEM);
68899+
68900+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
68901+ *(i_tmp + i_num) =
68902+ (struct acl_ip_label *)
68903+ acl_alloc(sizeof (struct acl_ip_label));
68904+ if (!*(i_tmp + i_num))
68905+ return ERR_PTR(-ENOMEM);
68906+
68907+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
68908+ return ERR_PTR(-EFAULT);
68909+
68910+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
68911+ return ERR_PTR(-EFAULT);
68912+
68913+ if ((*(i_tmp + i_num))->iface == NULL)
68914+ continue;
68915+
68916+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
68917+ if (err)
68918+ return ERR_PTR(err);
68919+ }
68920+
68921+ s_tmp->ips = i_tmp;
68922+
68923+insert:
68924+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
68925+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
68926+ return ERR_PTR(-ENOMEM);
68927+
68928+ return s_tmp;
68929+}
68930+
68931+static int
68932+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
68933+{
68934+ struct acl_subject_label s_pre;
68935+ struct acl_subject_label * ret;
68936+ int err;
68937+
68938+ while (userp) {
68939+ if (copy_acl_subject_label(&s_pre, userp))
68940+ return -EFAULT;
68941+
68942+ ret = do_copy_user_subj(userp, role, NULL);
68943+
68944+ err = PTR_ERR(ret);
68945+ if (IS_ERR(ret))
68946+ return err;
68947+
68948+ insert_acl_subj_label(ret, role);
68949+
68950+ userp = s_pre.prev;
68951+ }
68952+
68953+ return 0;
68954+}
68955+
68956+static int
68957+copy_user_acl(struct gr_arg *arg)
68958+{
68959+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
68960+ struct acl_subject_label *subj_list;
68961+ struct sprole_pw *sptmp;
68962+ struct gr_hash_struct *ghash;
68963+ uid_t *domainlist;
68964+ unsigned int r_num;
68965+ int err = 0;
68966+ __u16 i;
68967+ __u32 num_subjs;
68968+
68969+ /* we need a default and kernel role */
68970+ if (arg->role_db.num_roles < 2)
68971+ return -EINVAL;
68972+
68973+ /* copy special role authentication info from userspace */
68974+
68975+ polstate->num_sprole_pws = arg->num_sprole_pws;
68976+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
68977+
68978+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
68979+ return -ENOMEM;
68980+
68981+ for (i = 0; i < polstate->num_sprole_pws; i++) {
68982+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
68983+ if (!sptmp)
68984+ return -ENOMEM;
68985+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
68986+ return -EFAULT;
68987+
68988+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
68989+ if (err)
68990+ return err;
68991+
68992+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68993+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
68994+#endif
68995+
68996+ polstate->acl_special_roles[i] = sptmp;
68997+ }
68998+
68999+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
69000+
69001+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
69002+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
69003+
69004+ if (!r_tmp)
69005+ return -ENOMEM;
69006+
69007+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
69008+ return -EFAULT;
69009+
69010+ if (copy_acl_role_label(r_tmp, r_utmp2))
69011+ return -EFAULT;
69012+
69013+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
69014+ if (err)
69015+ return err;
69016+
69017+ if (!strcmp(r_tmp->rolename, "default")
69018+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
69019+ polstate->default_role = r_tmp;
69020+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
69021+ polstate->kernel_role = r_tmp;
69022+ }
69023+
69024+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
69025+ return -ENOMEM;
69026+
69027+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
69028+ return -EFAULT;
69029+
69030+ r_tmp->hash = ghash;
69031+
69032+ num_subjs = count_user_subjs(r_tmp->hash->first);
69033+
69034+ r_tmp->subj_hash_size = num_subjs;
69035+ r_tmp->subj_hash =
69036+ (struct acl_subject_label **)
69037+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
69038+
69039+ if (!r_tmp->subj_hash)
69040+ return -ENOMEM;
69041+
69042+ err = copy_user_allowedips(r_tmp);
69043+ if (err)
69044+ return err;
69045+
69046+ /* copy domain info */
69047+ if (r_tmp->domain_children != NULL) {
69048+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
69049+ if (domainlist == NULL)
69050+ return -ENOMEM;
69051+
69052+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
69053+ return -EFAULT;
69054+
69055+ r_tmp->domain_children = domainlist;
69056+ }
69057+
69058+ err = copy_user_transitions(r_tmp);
69059+ if (err)
69060+ return err;
69061+
69062+ memset(r_tmp->subj_hash, 0,
69063+ r_tmp->subj_hash_size *
69064+ sizeof (struct acl_subject_label *));
69065+
69066+ /* acquire the list of subjects, then NULL out
69067+ the list prior to parsing the subjects for this role,
69068+ as during this parsing the list is replaced with a list
69069+ of *nested* subjects for the role
69070+ */
69071+ subj_list = r_tmp->hash->first;
69072+
69073+ /* set nested subject list to null */
69074+ r_tmp->hash->first = NULL;
69075+
69076+ err = copy_user_subjs(subj_list, r_tmp);
69077+
69078+ if (err)
69079+ return err;
69080+
69081+ insert_acl_role_label(r_tmp);
69082+ }
69083+
69084+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
69085+ return -EINVAL;
69086+
69087+ return err;
69088+}
69089+
69090+static int gracl_reload_apply_policies(void *reload)
69091+{
69092+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
69093+ struct task_struct *task, *task2;
69094+ struct acl_role_label *role, *rtmp;
69095+ struct acl_subject_label *subj;
69096+ const struct cred *cred;
69097+ int role_applied;
69098+ int ret = 0;
69099+
69100+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
69101+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
69102+
69103+ /* first make sure we'll be able to apply the new policy cleanly */
69104+ do_each_thread(task2, task) {
69105+ if (task->exec_file == NULL)
69106+ continue;
69107+ role_applied = 0;
69108+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
69109+ /* preserve special roles */
69110+ FOR_EACH_ROLE_START(role)
69111+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
69112+ rtmp = task->role;
69113+ task->role = role;
69114+ role_applied = 1;
69115+ break;
69116+ }
69117+ FOR_EACH_ROLE_END(role)
69118+ }
69119+ if (!role_applied) {
69120+ cred = __task_cred(task);
69121+ rtmp = task->role;
69122+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
69123+ }
69124+ /* this handles non-nested inherited subjects, nested subjects will still
69125+ be dropped currently */
69126+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
69127+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
69128+ /* change the role back so that we've made no modifications to the policy */
69129+ task->role = rtmp;
69130+
69131+ if (subj == NULL || task->tmpacl == NULL) {
69132+ ret = -EINVAL;
69133+ goto out;
69134+ }
69135+ } while_each_thread(task2, task);
69136+
69137+ /* now actually apply the policy */
69138+
69139+ do_each_thread(task2, task) {
69140+ if (task->exec_file) {
69141+ role_applied = 0;
69142+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
69143+ /* preserve special roles */
69144+ FOR_EACH_ROLE_START(role)
69145+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
69146+ task->role = role;
69147+ role_applied = 1;
69148+ break;
69149+ }
69150+ FOR_EACH_ROLE_END(role)
69151+ }
69152+ if (!role_applied) {
69153+ cred = __task_cred(task);
69154+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
69155+ }
69156+ /* this handles non-nested inherited subjects, nested subjects will still
69157+ be dropped currently */
69158+ if (!reload_state->oldmode && task->inherited)
69159+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
69160+ else {
69161+ /* looked up and tagged to the task previously */
69162+ subj = task->tmpacl;
69163+ }
69164+ /* subj will be non-null */
69165+ __gr_apply_subject_to_task(polstate, task, subj);
69166+ if (reload_state->oldmode) {
69167+ task->acl_role_id = 0;
69168+ task->acl_sp_role = 0;
69169+ task->inherited = 0;
69170+ }
69171+ } else {
69172+ // it's a kernel process
69173+ task->role = polstate->kernel_role;
69174+ task->acl = polstate->kernel_role->root_label;
69175+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
69176+ task->acl->mode &= ~GR_PROCFIND;
69177+#endif
69178+ }
69179+ } while_each_thread(task2, task);
69180+
69181+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
69182+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
69183+
69184+out:
69185+
69186+ return ret;
69187+}
69188+
69189+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
69190+{
69191+ struct gr_reload_state new_reload_state = { };
69192+ int err;
69193+
69194+ new_reload_state.oldpolicy_ptr = polstate;
69195+ new_reload_state.oldalloc_ptr = current_alloc_state;
69196+ new_reload_state.oldmode = oldmode;
69197+
69198+ current_alloc_state = &new_reload_state.newalloc;
69199+ polstate = &new_reload_state.newpolicy;
69200+
69201+ /* everything relevant is now saved off, copy in the new policy */
69202+ if (init_variables(args, true)) {
69203+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
69204+ err = -ENOMEM;
69205+ goto error;
69206+ }
69207+
69208+ err = copy_user_acl(args);
69209+ free_init_variables();
69210+ if (err)
69211+ goto error;
69212+ /* the new policy is copied in, with the old policy available via saved_state
69213+ first go through applying roles, making sure to preserve special roles
69214+ then apply new subjects, making sure to preserve inherited and nested subjects,
69215+ though currently only inherited subjects will be preserved
69216+ */
69217+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
69218+ if (err)
69219+ goto error;
69220+
69221+ /* we've now applied the new policy, so restore the old policy state to free it */
69222+ polstate = &new_reload_state.oldpolicy;
69223+ current_alloc_state = &new_reload_state.oldalloc;
69224+ free_variables(true);
69225+
69226+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
69227+ to running_polstate/current_alloc_state inside stop_machine
69228+ */
69229+ err = 0;
69230+ goto out;
69231+error:
69232+ /* on error of loading the new policy, we'll just keep the previous
69233+ policy set around
69234+ */
69235+ free_variables(true);
69236+
69237+ /* doesn't affect runtime, but maintains consistent state */
69238+out:
69239+ polstate = new_reload_state.oldpolicy_ptr;
69240+ current_alloc_state = new_reload_state.oldalloc_ptr;
69241+
69242+ return err;
69243+}
69244+
69245+static int
69246+gracl_init(struct gr_arg *args)
69247+{
69248+ int error = 0;
69249+
69250+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
69251+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
69252+
69253+ if (init_variables(args, false)) {
69254+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
69255+ error = -ENOMEM;
69256+ goto out;
69257+ }
69258+
69259+ error = copy_user_acl(args);
69260+ free_init_variables();
69261+ if (error)
69262+ goto out;
69263+
69264+ error = gr_set_acls(0);
69265+ if (error)
69266+ goto out;
69267+
69268+ gr_enable_rbac_system();
69269+
69270+ return 0;
69271+
69272+out:
69273+ free_variables(false);
69274+ return error;
69275+}
69276+
69277+static int
69278+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
69279+ unsigned char **sum)
69280+{
69281+ struct acl_role_label *r;
69282+ struct role_allowed_ip *ipp;
69283+ struct role_transition *trans;
69284+ unsigned int i;
69285+ int found = 0;
69286+ u32 curr_ip = current->signal->curr_ip;
69287+
69288+ current->signal->saved_ip = curr_ip;
69289+
69290+ /* check transition table */
69291+
69292+ for (trans = current->role->transitions; trans; trans = trans->next) {
69293+ if (!strcmp(rolename, trans->rolename)) {
69294+ found = 1;
69295+ break;
69296+ }
69297+ }
69298+
69299+ if (!found)
69300+ return 0;
69301+
69302+ /* handle special roles that do not require authentication
69303+ and check ip */
69304+
69305+ FOR_EACH_ROLE_START(r)
69306+ if (!strcmp(rolename, r->rolename) &&
69307+ (r->roletype & GR_ROLE_SPECIAL)) {
69308+ found = 0;
69309+ if (r->allowed_ips != NULL) {
69310+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
69311+ if ((ntohl(curr_ip) & ipp->netmask) ==
69312+ (ntohl(ipp->addr) & ipp->netmask))
69313+ found = 1;
69314+ }
69315+ } else
69316+ found = 2;
69317+ if (!found)
69318+ return 0;
69319+
69320+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
69321+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
69322+ *salt = NULL;
69323+ *sum = NULL;
69324+ return 1;
69325+ }
69326+ }
69327+ FOR_EACH_ROLE_END(r)
69328+
69329+ for (i = 0; i < polstate->num_sprole_pws; i++) {
69330+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
69331+ *salt = polstate->acl_special_roles[i]->salt;
69332+ *sum = polstate->acl_special_roles[i]->sum;
69333+ return 1;
69334+ }
69335+ }
69336+
69337+ return 0;
69338+}
69339+
69340+int gr_check_secure_terminal(struct task_struct *task)
69341+{
69342+ struct task_struct *p, *p2, *p3;
69343+ struct files_struct *files;
69344+ struct fdtable *fdt;
69345+ struct file *our_file = NULL, *file;
69346+ int i;
69347+
69348+ if (task->signal->tty == NULL)
69349+ return 1;
69350+
69351+ files = get_files_struct(task);
69352+ if (files != NULL) {
69353+ rcu_read_lock();
69354+ fdt = files_fdtable(files);
69355+ for (i=0; i < fdt->max_fds; i++) {
69356+ file = fcheck_files(files, i);
69357+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
69358+ get_file(file);
69359+ our_file = file;
69360+ }
69361+ }
69362+ rcu_read_unlock();
69363+ put_files_struct(files);
69364+ }
69365+
69366+ if (our_file == NULL)
69367+ return 1;
69368+
69369+ read_lock(&tasklist_lock);
69370+ do_each_thread(p2, p) {
69371+ files = get_files_struct(p);
69372+ if (files == NULL ||
69373+ (p->signal && p->signal->tty == task->signal->tty)) {
69374+ if (files != NULL)
69375+ put_files_struct(files);
69376+ continue;
69377+ }
69378+ rcu_read_lock();
69379+ fdt = files_fdtable(files);
69380+ for (i=0; i < fdt->max_fds; i++) {
69381+ file = fcheck_files(files, i);
69382+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
69383+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
69384+ p3 = task;
69385+ while (task_pid_nr(p3) > 0) {
69386+ if (p3 == p)
69387+ break;
69388+ p3 = p3->real_parent;
69389+ }
69390+ if (p3 == p)
69391+ break;
69392+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
69393+ gr_handle_alertkill(p);
69394+ rcu_read_unlock();
69395+ put_files_struct(files);
69396+ read_unlock(&tasklist_lock);
69397+ fput(our_file);
69398+ return 0;
69399+ }
69400+ }
69401+ rcu_read_unlock();
69402+ put_files_struct(files);
69403+ } while_each_thread(p2, p);
69404+ read_unlock(&tasklist_lock);
69405+
69406+ fput(our_file);
69407+ return 1;
69408+}
69409+
69410+ssize_t
69411+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
69412+{
69413+ struct gr_arg_wrapper uwrap;
69414+ unsigned char *sprole_salt = NULL;
69415+ unsigned char *sprole_sum = NULL;
69416+ int error = 0;
69417+ int error2 = 0;
69418+ size_t req_count = 0;
69419+ unsigned char oldmode = 0;
69420+
69421+ mutex_lock(&gr_dev_mutex);
69422+
69423+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
69424+ error = -EPERM;
69425+ goto out;
69426+ }
69427+
69428+#ifdef CONFIG_COMPAT
69429+ pax_open_kernel();
69430+ if (is_compat_task()) {
69431+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
69432+ copy_gr_arg = &copy_gr_arg_compat;
69433+ copy_acl_object_label = &copy_acl_object_label_compat;
69434+ copy_acl_subject_label = &copy_acl_subject_label_compat;
69435+ copy_acl_role_label = &copy_acl_role_label_compat;
69436+ copy_acl_ip_label = &copy_acl_ip_label_compat;
69437+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
69438+ copy_role_transition = &copy_role_transition_compat;
69439+ copy_sprole_pw = &copy_sprole_pw_compat;
69440+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
69441+ copy_pointer_from_array = &copy_pointer_from_array_compat;
69442+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
69443+ } else {
69444+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
69445+ copy_gr_arg = &copy_gr_arg_normal;
69446+ copy_acl_object_label = &copy_acl_object_label_normal;
69447+ copy_acl_subject_label = &copy_acl_subject_label_normal;
69448+ copy_acl_role_label = &copy_acl_role_label_normal;
69449+ copy_acl_ip_label = &copy_acl_ip_label_normal;
69450+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
69451+ copy_role_transition = &copy_role_transition_normal;
69452+ copy_sprole_pw = &copy_sprole_pw_normal;
69453+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
69454+ copy_pointer_from_array = &copy_pointer_from_array_normal;
69455+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
69456+ }
69457+ pax_close_kernel();
69458+#endif
69459+
69460+ req_count = get_gr_arg_wrapper_size();
69461+
69462+ if (count != req_count) {
69463+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
69464+ error = -EINVAL;
69465+ goto out;
69466+ }
69467+
69468+
69469+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
69470+ gr_auth_expires = 0;
69471+ gr_auth_attempts = 0;
69472+ }
69473+
69474+ error = copy_gr_arg_wrapper(buf, &uwrap);
69475+ if (error)
69476+ goto out;
69477+
69478+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
69479+ if (error)
69480+ goto out;
69481+
69482+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
69483+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
69484+ time_after(gr_auth_expires, get_seconds())) {
69485+ error = -EBUSY;
69486+ goto out;
69487+ }
69488+
69489+ /* if non-root trying to do anything other than use a special role,
69490+ do not attempt authentication, do not count towards authentication
69491+ locking
69492+ */
69493+
69494+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
69495+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
69496+ gr_is_global_nonroot(current_uid())) {
69497+ error = -EPERM;
69498+ goto out;
69499+ }
69500+
69501+ /* ensure pw and special role name are null terminated */
69502+
69503+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
69504+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
69505+
69506+ /* Okay.
69507+ * We have our enough of the argument structure..(we have yet
69508+ * to copy_from_user the tables themselves) . Copy the tables
69509+ * only if we need them, i.e. for loading operations. */
69510+
69511+ switch (gr_usermode.mode) {
69512+ case GR_STATUS:
69513+ if (gr_acl_is_enabled()) {
69514+ error = 1;
69515+ if (!gr_check_secure_terminal(current))
69516+ error = 3;
69517+ } else
69518+ error = 2;
69519+ goto out;
69520+ case GR_SHUTDOWN:
69521+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
69522+ stop_machine(gr_rbac_disable, NULL, NULL);
69523+ free_variables(false);
69524+ memset(&gr_usermode, 0, sizeof(gr_usermode));
69525+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
69526+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
69527+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
69528+ } else if (gr_acl_is_enabled()) {
69529+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
69530+ error = -EPERM;
69531+ } else {
69532+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
69533+ error = -EAGAIN;
69534+ }
69535+ break;
69536+ case GR_ENABLE:
69537+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
69538+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
69539+ else {
69540+ if (gr_acl_is_enabled())
69541+ error = -EAGAIN;
69542+ else
69543+ error = error2;
69544+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
69545+ }
69546+ break;
69547+ case GR_OLDRELOAD:
69548+ oldmode = 1;
69549+ case GR_RELOAD:
69550+ if (!gr_acl_is_enabled()) {
69551+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
69552+ error = -EAGAIN;
69553+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
69554+ error2 = gracl_reload(&gr_usermode, oldmode);
69555+ if (!error2)
69556+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
69557+ else {
69558+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
69559+ error = error2;
69560+ }
69561+ } else {
69562+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
69563+ error = -EPERM;
69564+ }
69565+ break;
69566+ case GR_SEGVMOD:
69567+ if (unlikely(!gr_acl_is_enabled())) {
69568+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
69569+ error = -EAGAIN;
69570+ break;
69571+ }
69572+
69573+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
69574+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
69575+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
69576+ struct acl_subject_label *segvacl;
69577+ segvacl =
69578+ lookup_acl_subj_label(gr_usermode.segv_inode,
69579+ gr_usermode.segv_device,
69580+ current->role);
69581+ if (segvacl) {
69582+ segvacl->crashes = 0;
69583+ segvacl->expires = 0;
69584+ }
69585+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
69586+ gr_remove_uid(gr_usermode.segv_uid);
69587+ }
69588+ } else {
69589+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
69590+ error = -EPERM;
69591+ }
69592+ break;
69593+ case GR_SPROLE:
69594+ case GR_SPROLEPAM:
69595+ if (unlikely(!gr_acl_is_enabled())) {
69596+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
69597+ error = -EAGAIN;
69598+ break;
69599+ }
69600+
69601+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
69602+ current->role->expires = 0;
69603+ current->role->auth_attempts = 0;
69604+ }
69605+
69606+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
69607+ time_after(current->role->expires, get_seconds())) {
69608+ error = -EBUSY;
69609+ goto out;
69610+ }
69611+
69612+ if (lookup_special_role_auth
69613+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
69614+ && ((!sprole_salt && !sprole_sum)
69615+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
69616+ char *p = "";
69617+ assign_special_role(gr_usermode.sp_role);
69618+ read_lock(&tasklist_lock);
69619+ if (current->real_parent)
69620+ p = current->real_parent->role->rolename;
69621+ read_unlock(&tasklist_lock);
69622+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
69623+ p, acl_sp_role_value);
69624+ } else {
69625+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
69626+ error = -EPERM;
69627+ if(!(current->role->auth_attempts++))
69628+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
69629+
69630+ goto out;
69631+ }
69632+ break;
69633+ case GR_UNSPROLE:
69634+ if (unlikely(!gr_acl_is_enabled())) {
69635+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
69636+ error = -EAGAIN;
69637+ break;
69638+ }
69639+
69640+ if (current->role->roletype & GR_ROLE_SPECIAL) {
69641+ char *p = "";
69642+ int i = 0;
69643+
69644+ read_lock(&tasklist_lock);
69645+ if (current->real_parent) {
69646+ p = current->real_parent->role->rolename;
69647+ i = current->real_parent->acl_role_id;
69648+ }
69649+ read_unlock(&tasklist_lock);
69650+
69651+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
69652+ gr_set_acls(1);
69653+ } else {
69654+ error = -EPERM;
69655+ goto out;
69656+ }
69657+ break;
69658+ default:
69659+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
69660+ error = -EINVAL;
69661+ break;
69662+ }
69663+
69664+ if (error != -EPERM)
69665+ goto out;
69666+
69667+ if(!(gr_auth_attempts++))
69668+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
69669+
69670+ out:
69671+ mutex_unlock(&gr_dev_mutex);
69672+
69673+ if (!error)
69674+ error = req_count;
69675+
69676+ return error;
69677+}
69678+
69679+int
69680+gr_set_acls(const int type)
69681+{
69682+ struct task_struct *task, *task2;
69683+ struct acl_role_label *role = current->role;
69684+ struct acl_subject_label *subj;
69685+ __u16 acl_role_id = current->acl_role_id;
69686+ const struct cred *cred;
69687+ int ret;
69688+
69689+ rcu_read_lock();
69690+ read_lock(&tasklist_lock);
69691+ read_lock(&grsec_exec_file_lock);
69692+ do_each_thread(task2, task) {
69693+ /* check to see if we're called from the exit handler,
69694+ if so, only replace ACLs that have inherited the admin
69695+ ACL */
69696+
69697+ if (type && (task->role != role ||
69698+ task->acl_role_id != acl_role_id))
69699+ continue;
69700+
69701+ task->acl_role_id = 0;
69702+ task->acl_sp_role = 0;
69703+ task->inherited = 0;
69704+
69705+ if (task->exec_file) {
69706+ cred = __task_cred(task);
69707+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
69708+ subj = __gr_get_subject_for_task(polstate, task, NULL);
69709+ if (subj == NULL) {
69710+ ret = -EINVAL;
69711+ read_unlock(&grsec_exec_file_lock);
69712+ read_unlock(&tasklist_lock);
69713+ rcu_read_unlock();
69714+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
69715+ return ret;
69716+ }
69717+ __gr_apply_subject_to_task(polstate, task, subj);
69718+ } else {
69719+ // it's a kernel process
69720+ task->role = polstate->kernel_role;
69721+ task->acl = polstate->kernel_role->root_label;
69722+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
69723+ task->acl->mode &= ~GR_PROCFIND;
69724+#endif
69725+ }
69726+ } while_each_thread(task2, task);
69727+ read_unlock(&grsec_exec_file_lock);
69728+ read_unlock(&tasklist_lock);
69729+ rcu_read_unlock();
69730+
69731+ return 0;
69732+}
69733diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
69734new file mode 100644
69735index 0000000..39645c9
69736--- /dev/null
69737+++ b/grsecurity/gracl_res.c
69738@@ -0,0 +1,68 @@
69739+#include <linux/kernel.h>
69740+#include <linux/sched.h>
69741+#include <linux/gracl.h>
69742+#include <linux/grinternal.h>
69743+
69744+static const char *restab_log[] = {
69745+ [RLIMIT_CPU] = "RLIMIT_CPU",
69746+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
69747+ [RLIMIT_DATA] = "RLIMIT_DATA",
69748+ [RLIMIT_STACK] = "RLIMIT_STACK",
69749+ [RLIMIT_CORE] = "RLIMIT_CORE",
69750+ [RLIMIT_RSS] = "RLIMIT_RSS",
69751+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
69752+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
69753+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
69754+ [RLIMIT_AS] = "RLIMIT_AS",
69755+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
69756+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
69757+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
69758+ [RLIMIT_NICE] = "RLIMIT_NICE",
69759+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
69760+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
69761+ [GR_CRASH_RES] = "RLIMIT_CRASH"
69762+};
69763+
69764+void
69765+gr_log_resource(const struct task_struct *task,
69766+ const int res, const unsigned long wanted, const int gt)
69767+{
69768+ const struct cred *cred;
69769+ unsigned long rlim;
69770+
69771+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
69772+ return;
69773+
69774+ // not yet supported resource
69775+ if (unlikely(!restab_log[res]))
69776+ return;
69777+
69778+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
69779+ rlim = task_rlimit_max(task, res);
69780+ else
69781+ rlim = task_rlimit(task, res);
69782+
69783+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
69784+ return;
69785+
69786+ rcu_read_lock();
69787+ cred = __task_cred(task);
69788+
69789+ if (res == RLIMIT_NPROC &&
69790+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
69791+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
69792+ goto out_rcu_unlock;
69793+ else if (res == RLIMIT_MEMLOCK &&
69794+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
69795+ goto out_rcu_unlock;
69796+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
69797+ goto out_rcu_unlock;
69798+ rcu_read_unlock();
69799+
69800+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
69801+
69802+ return;
69803+out_rcu_unlock:
69804+ rcu_read_unlock();
69805+ return;
69806+}
69807diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
69808new file mode 100644
69809index 0000000..2040e61
69810--- /dev/null
69811+++ b/grsecurity/gracl_segv.c
69812@@ -0,0 +1,313 @@
69813+#include <linux/kernel.h>
69814+#include <linux/mm.h>
69815+#include <asm/uaccess.h>
69816+#include <asm/errno.h>
69817+#include <asm/mman.h>
69818+#include <net/sock.h>
69819+#include <linux/file.h>
69820+#include <linux/fs.h>
69821+#include <linux/net.h>
69822+#include <linux/in.h>
69823+#include <linux/slab.h>
69824+#include <linux/types.h>
69825+#include <linux/sched.h>
69826+#include <linux/timer.h>
69827+#include <linux/gracl.h>
69828+#include <linux/grsecurity.h>
69829+#include <linux/grinternal.h>
69830+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69831+#include <linux/magic.h>
69832+#include <linux/pagemap.h>
69833+#include "../fs/btrfs/async-thread.h"
69834+#include "../fs/btrfs/ctree.h"
69835+#include "../fs/btrfs/btrfs_inode.h"
69836+#endif
69837+
69838+static struct crash_uid *uid_set;
69839+static unsigned short uid_used;
69840+static DEFINE_SPINLOCK(gr_uid_lock);
69841+extern rwlock_t gr_inode_lock;
69842+extern struct acl_subject_label *
69843+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
69844+ struct acl_role_label *role);
69845+
69846+static inline dev_t __get_dev(const struct dentry *dentry)
69847+{
69848+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69849+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69850+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69851+ else
69852+#endif
69853+ return dentry->d_sb->s_dev;
69854+}
69855+
69856+int
69857+gr_init_uidset(void)
69858+{
69859+ uid_set =
69860+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
69861+ uid_used = 0;
69862+
69863+ return uid_set ? 1 : 0;
69864+}
69865+
69866+void
69867+gr_free_uidset(void)
69868+{
69869+ if (uid_set) {
69870+ struct crash_uid *tmpset;
69871+ spin_lock(&gr_uid_lock);
69872+ tmpset = uid_set;
69873+ uid_set = NULL;
69874+ uid_used = 0;
69875+ spin_unlock(&gr_uid_lock);
69876+ if (tmpset)
69877+ kfree(tmpset);
69878+ }
69879+
69880+ return;
69881+}
69882+
69883+int
69884+gr_find_uid(const uid_t uid)
69885+{
69886+ struct crash_uid *tmp = uid_set;
69887+ uid_t buid;
69888+ int low = 0, high = uid_used - 1, mid;
69889+
69890+ while (high >= low) {
69891+ mid = (low + high) >> 1;
69892+ buid = tmp[mid].uid;
69893+ if (buid == uid)
69894+ return mid;
69895+ if (buid > uid)
69896+ high = mid - 1;
69897+ if (buid < uid)
69898+ low = mid + 1;
69899+ }
69900+
69901+ return -1;
69902+}
69903+
69904+static __inline__ void
69905+gr_insertsort(void)
69906+{
69907+ unsigned short i, j;
69908+ struct crash_uid index;
69909+
69910+ for (i = 1; i < uid_used; i++) {
69911+ index = uid_set[i];
69912+ j = i;
69913+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
69914+ uid_set[j] = uid_set[j - 1];
69915+ j--;
69916+ }
69917+ uid_set[j] = index;
69918+ }
69919+
69920+ return;
69921+}
69922+
69923+static __inline__ void
69924+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
69925+{
69926+ int loc;
69927+ uid_t uid = GR_GLOBAL_UID(kuid);
69928+
69929+ if (uid_used == GR_UIDTABLE_MAX)
69930+ return;
69931+
69932+ loc = gr_find_uid(uid);
69933+
69934+ if (loc >= 0) {
69935+ uid_set[loc].expires = expires;
69936+ return;
69937+ }
69938+
69939+ uid_set[uid_used].uid = uid;
69940+ uid_set[uid_used].expires = expires;
69941+ uid_used++;
69942+
69943+ gr_insertsort();
69944+
69945+ return;
69946+}
69947+
69948+void
69949+gr_remove_uid(const unsigned short loc)
69950+{
69951+ unsigned short i;
69952+
69953+ for (i = loc + 1; i < uid_used; i++)
69954+ uid_set[i - 1] = uid_set[i];
69955+
69956+ uid_used--;
69957+
69958+ return;
69959+}
69960+
69961+int
69962+gr_check_crash_uid(const kuid_t kuid)
69963+{
69964+ int loc;
69965+ int ret = 0;
69966+ uid_t uid;
69967+
69968+ if (unlikely(!gr_acl_is_enabled()))
69969+ return 0;
69970+
69971+ uid = GR_GLOBAL_UID(kuid);
69972+
69973+ spin_lock(&gr_uid_lock);
69974+ loc = gr_find_uid(uid);
69975+
69976+ if (loc < 0)
69977+ goto out_unlock;
69978+
69979+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
69980+ gr_remove_uid(loc);
69981+ else
69982+ ret = 1;
69983+
69984+out_unlock:
69985+ spin_unlock(&gr_uid_lock);
69986+ return ret;
69987+}
69988+
69989+static __inline__ int
69990+proc_is_setxid(const struct cred *cred)
69991+{
69992+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
69993+ !uid_eq(cred->uid, cred->fsuid))
69994+ return 1;
69995+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
69996+ !gid_eq(cred->gid, cred->fsgid))
69997+ return 1;
69998+
69999+ return 0;
70000+}
70001+
70002+extern int gr_fake_force_sig(int sig, struct task_struct *t);
70003+
70004+void
70005+gr_handle_crash(struct task_struct *task, const int sig)
70006+{
70007+ struct acl_subject_label *curr;
70008+ struct task_struct *tsk, *tsk2;
70009+ const struct cred *cred;
70010+ const struct cred *cred2;
70011+
70012+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
70013+ return;
70014+
70015+ if (unlikely(!gr_acl_is_enabled()))
70016+ return;
70017+
70018+ curr = task->acl;
70019+
70020+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
70021+ return;
70022+
70023+ if (time_before_eq(curr->expires, get_seconds())) {
70024+ curr->expires = 0;
70025+ curr->crashes = 0;
70026+ }
70027+
70028+ curr->crashes++;
70029+
70030+ if (!curr->expires)
70031+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
70032+
70033+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
70034+ time_after(curr->expires, get_seconds())) {
70035+ rcu_read_lock();
70036+ cred = __task_cred(task);
70037+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
70038+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
70039+ spin_lock(&gr_uid_lock);
70040+ gr_insert_uid(cred->uid, curr->expires);
70041+ spin_unlock(&gr_uid_lock);
70042+ curr->expires = 0;
70043+ curr->crashes = 0;
70044+ read_lock(&tasklist_lock);
70045+ do_each_thread(tsk2, tsk) {
70046+ cred2 = __task_cred(tsk);
70047+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
70048+ gr_fake_force_sig(SIGKILL, tsk);
70049+ } while_each_thread(tsk2, tsk);
70050+ read_unlock(&tasklist_lock);
70051+ } else {
70052+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
70053+ read_lock(&tasklist_lock);
70054+ read_lock(&grsec_exec_file_lock);
70055+ do_each_thread(tsk2, tsk) {
70056+ if (likely(tsk != task)) {
70057+ // if this thread has the same subject as the one that triggered
70058+ // RES_CRASH and it's the same binary, kill it
70059+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
70060+ gr_fake_force_sig(SIGKILL, tsk);
70061+ }
70062+ } while_each_thread(tsk2, tsk);
70063+ read_unlock(&grsec_exec_file_lock);
70064+ read_unlock(&tasklist_lock);
70065+ }
70066+ rcu_read_unlock();
70067+ }
70068+
70069+ return;
70070+}
70071+
70072+int
70073+gr_check_crash_exec(const struct file *filp)
70074+{
70075+ struct acl_subject_label *curr;
70076+
70077+ if (unlikely(!gr_acl_is_enabled()))
70078+ return 0;
70079+
70080+ read_lock(&gr_inode_lock);
70081+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
70082+ __get_dev(filp->f_path.dentry),
70083+ current->role);
70084+ read_unlock(&gr_inode_lock);
70085+
70086+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
70087+ (!curr->crashes && !curr->expires))
70088+ return 0;
70089+
70090+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
70091+ time_after(curr->expires, get_seconds()))
70092+ return 1;
70093+ else if (time_before_eq(curr->expires, get_seconds())) {
70094+ curr->crashes = 0;
70095+ curr->expires = 0;
70096+ }
70097+
70098+ return 0;
70099+}
70100+
70101+void
70102+gr_handle_alertkill(struct task_struct *task)
70103+{
70104+ struct acl_subject_label *curracl;
70105+ __u32 curr_ip;
70106+ struct task_struct *p, *p2;
70107+
70108+ if (unlikely(!gr_acl_is_enabled()))
70109+ return;
70110+
70111+ curracl = task->acl;
70112+ curr_ip = task->signal->curr_ip;
70113+
70114+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
70115+ read_lock(&tasklist_lock);
70116+ do_each_thread(p2, p) {
70117+ if (p->signal->curr_ip == curr_ip)
70118+ gr_fake_force_sig(SIGKILL, p);
70119+ } while_each_thread(p2, p);
70120+ read_unlock(&tasklist_lock);
70121+ } else if (curracl->mode & GR_KILLPROC)
70122+ gr_fake_force_sig(SIGKILL, task);
70123+
70124+ return;
70125+}
70126diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
70127new file mode 100644
70128index 0000000..98011b0
70129--- /dev/null
70130+++ b/grsecurity/gracl_shm.c
70131@@ -0,0 +1,40 @@
70132+#include <linux/kernel.h>
70133+#include <linux/mm.h>
70134+#include <linux/sched.h>
70135+#include <linux/file.h>
70136+#include <linux/ipc.h>
70137+#include <linux/gracl.h>
70138+#include <linux/grsecurity.h>
70139+#include <linux/grinternal.h>
70140+
70141+int
70142+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70143+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
70144+{
70145+ struct task_struct *task;
70146+
70147+ if (!gr_acl_is_enabled())
70148+ return 1;
70149+
70150+ rcu_read_lock();
70151+ read_lock(&tasklist_lock);
70152+
70153+ task = find_task_by_vpid(shm_cprid);
70154+
70155+ if (unlikely(!task))
70156+ task = find_task_by_vpid(shm_lapid);
70157+
70158+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
70159+ (task_pid_nr(task) == shm_lapid)) &&
70160+ (task->acl->mode & GR_PROTSHM) &&
70161+ (task->acl != current->acl))) {
70162+ read_unlock(&tasklist_lock);
70163+ rcu_read_unlock();
70164+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
70165+ return 0;
70166+ }
70167+ read_unlock(&tasklist_lock);
70168+ rcu_read_unlock();
70169+
70170+ return 1;
70171+}
70172diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
70173new file mode 100644
70174index 0000000..bc0be01
70175--- /dev/null
70176+++ b/grsecurity/grsec_chdir.c
70177@@ -0,0 +1,19 @@
70178+#include <linux/kernel.h>
70179+#include <linux/sched.h>
70180+#include <linux/fs.h>
70181+#include <linux/file.h>
70182+#include <linux/grsecurity.h>
70183+#include <linux/grinternal.h>
70184+
70185+void
70186+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
70187+{
70188+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70189+ if ((grsec_enable_chdir && grsec_enable_group &&
70190+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
70191+ !grsec_enable_group)) {
70192+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
70193+ }
70194+#endif
70195+ return;
70196+}
70197diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
70198new file mode 100644
70199index 0000000..e10b319
70200--- /dev/null
70201+++ b/grsecurity/grsec_chroot.c
70202@@ -0,0 +1,370 @@
70203+#include <linux/kernel.h>
70204+#include <linux/module.h>
70205+#include <linux/sched.h>
70206+#include <linux/file.h>
70207+#include <linux/fs.h>
70208+#include <linux/mount.h>
70209+#include <linux/types.h>
70210+#include "../fs/mount.h"
70211+#include <linux/grsecurity.h>
70212+#include <linux/grinternal.h>
70213+
70214+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
70215+int gr_init_ran;
70216+#endif
70217+
70218+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
70219+{
70220+#ifdef CONFIG_GRKERNSEC
70221+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
70222+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
70223+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
70224+ && gr_init_ran
70225+#endif
70226+ )
70227+ task->gr_is_chrooted = 1;
70228+ else {
70229+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
70230+ if (task_pid_nr(task) == 1 && !gr_init_ran)
70231+ gr_init_ran = 1;
70232+#endif
70233+ task->gr_is_chrooted = 0;
70234+ }
70235+
70236+ task->gr_chroot_dentry = path->dentry;
70237+#endif
70238+ return;
70239+}
70240+
70241+void gr_clear_chroot_entries(struct task_struct *task)
70242+{
70243+#ifdef CONFIG_GRKERNSEC
70244+ task->gr_is_chrooted = 0;
70245+ task->gr_chroot_dentry = NULL;
70246+#endif
70247+ return;
70248+}
70249+
70250+int
70251+gr_handle_chroot_unix(const pid_t pid)
70252+{
70253+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70254+ struct task_struct *p;
70255+
70256+ if (unlikely(!grsec_enable_chroot_unix))
70257+ return 1;
70258+
70259+ if (likely(!proc_is_chrooted(current)))
70260+ return 1;
70261+
70262+ rcu_read_lock();
70263+ read_lock(&tasklist_lock);
70264+ p = find_task_by_vpid_unrestricted(pid);
70265+ if (unlikely(p && !have_same_root(current, p))) {
70266+ read_unlock(&tasklist_lock);
70267+ rcu_read_unlock();
70268+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
70269+ return 0;
70270+ }
70271+ read_unlock(&tasklist_lock);
70272+ rcu_read_unlock();
70273+#endif
70274+ return 1;
70275+}
70276+
70277+int
70278+gr_handle_chroot_nice(void)
70279+{
70280+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70281+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
70282+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
70283+ return -EPERM;
70284+ }
70285+#endif
70286+ return 0;
70287+}
70288+
70289+int
70290+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
70291+{
70292+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70293+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
70294+ && proc_is_chrooted(current)) {
70295+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
70296+ return -EACCES;
70297+ }
70298+#endif
70299+ return 0;
70300+}
70301+
70302+int
70303+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
70304+{
70305+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70306+ struct task_struct *p;
70307+ int ret = 0;
70308+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
70309+ return ret;
70310+
70311+ read_lock(&tasklist_lock);
70312+ do_each_pid_task(pid, type, p) {
70313+ if (!have_same_root(current, p)) {
70314+ ret = 1;
70315+ goto out;
70316+ }
70317+ } while_each_pid_task(pid, type, p);
70318+out:
70319+ read_unlock(&tasklist_lock);
70320+ return ret;
70321+#endif
70322+ return 0;
70323+}
70324+
70325+int
70326+gr_pid_is_chrooted(struct task_struct *p)
70327+{
70328+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70329+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
70330+ return 0;
70331+
70332+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
70333+ !have_same_root(current, p)) {
70334+ return 1;
70335+ }
70336+#endif
70337+ return 0;
70338+}
70339+
70340+EXPORT_SYMBOL(gr_pid_is_chrooted);
70341+
70342+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
70343+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
70344+{
70345+ struct path path, currentroot;
70346+ int ret = 0;
70347+
70348+ path.dentry = (struct dentry *)u_dentry;
70349+ path.mnt = (struct vfsmount *)u_mnt;
70350+ get_fs_root(current->fs, &currentroot);
70351+ if (path_is_under(&path, &currentroot))
70352+ ret = 1;
70353+ path_put(&currentroot);
70354+
70355+ return ret;
70356+}
70357+#endif
70358+
70359+int
70360+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
70361+{
70362+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70363+ if (!grsec_enable_chroot_fchdir)
70364+ return 1;
70365+
70366+ if (!proc_is_chrooted(current))
70367+ return 1;
70368+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
70369+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
70370+ return 0;
70371+ }
70372+#endif
70373+ return 1;
70374+}
70375+
70376+int
70377+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70378+ const time_t shm_createtime)
70379+{
70380+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70381+ struct task_struct *p;
70382+ time_t starttime;
70383+
70384+ if (unlikely(!grsec_enable_chroot_shmat))
70385+ return 1;
70386+
70387+ if (likely(!proc_is_chrooted(current)))
70388+ return 1;
70389+
70390+ rcu_read_lock();
70391+ read_lock(&tasklist_lock);
70392+
70393+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
70394+ starttime = p->start_time.tv_sec;
70395+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
70396+ if (have_same_root(current, p)) {
70397+ goto allow;
70398+ } else {
70399+ read_unlock(&tasklist_lock);
70400+ rcu_read_unlock();
70401+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
70402+ return 0;
70403+ }
70404+ }
70405+ /* creator exited, pid reuse, fall through to next check */
70406+ }
70407+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
70408+ if (unlikely(!have_same_root(current, p))) {
70409+ read_unlock(&tasklist_lock);
70410+ rcu_read_unlock();
70411+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
70412+ return 0;
70413+ }
70414+ }
70415+
70416+allow:
70417+ read_unlock(&tasklist_lock);
70418+ rcu_read_unlock();
70419+#endif
70420+ return 1;
70421+}
70422+
70423+void
70424+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
70425+{
70426+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70427+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
70428+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
70429+#endif
70430+ return;
70431+}
70432+
70433+int
70434+gr_handle_chroot_mknod(const struct dentry *dentry,
70435+ const struct vfsmount *mnt, const int mode)
70436+{
70437+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70438+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
70439+ proc_is_chrooted(current)) {
70440+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
70441+ return -EPERM;
70442+ }
70443+#endif
70444+ return 0;
70445+}
70446+
70447+int
70448+gr_handle_chroot_mount(const struct dentry *dentry,
70449+ const struct vfsmount *mnt, const char *dev_name)
70450+{
70451+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70452+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
70453+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
70454+ return -EPERM;
70455+ }
70456+#endif
70457+ return 0;
70458+}
70459+
70460+int
70461+gr_handle_chroot_pivot(void)
70462+{
70463+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70464+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
70465+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
70466+ return -EPERM;
70467+ }
70468+#endif
70469+ return 0;
70470+}
70471+
70472+int
70473+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
70474+{
70475+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70476+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
70477+ !gr_is_outside_chroot(dentry, mnt)) {
70478+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
70479+ return -EPERM;
70480+ }
70481+#endif
70482+ return 0;
70483+}
70484+
70485+extern const char *captab_log[];
70486+extern int captab_log_entries;
70487+
70488+int
70489+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70490+{
70491+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70492+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
70493+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
70494+ if (cap_raised(chroot_caps, cap)) {
70495+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
70496+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
70497+ }
70498+ return 0;
70499+ }
70500+ }
70501+#endif
70502+ return 1;
70503+}
70504+
70505+int
70506+gr_chroot_is_capable(const int cap)
70507+{
70508+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70509+ return gr_task_chroot_is_capable(current, current_cred(), cap);
70510+#endif
70511+ return 1;
70512+}
70513+
70514+int
70515+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
70516+{
70517+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70518+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
70519+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
70520+ if (cap_raised(chroot_caps, cap)) {
70521+ return 0;
70522+ }
70523+ }
70524+#endif
70525+ return 1;
70526+}
70527+
70528+int
70529+gr_chroot_is_capable_nolog(const int cap)
70530+{
70531+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70532+ return gr_task_chroot_is_capable_nolog(current, cap);
70533+#endif
70534+ return 1;
70535+}
70536+
70537+int
70538+gr_handle_chroot_sysctl(const int op)
70539+{
70540+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70541+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
70542+ proc_is_chrooted(current))
70543+ return -EACCES;
70544+#endif
70545+ return 0;
70546+}
70547+
70548+void
70549+gr_handle_chroot_chdir(const struct path *path)
70550+{
70551+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70552+ if (grsec_enable_chroot_chdir)
70553+ set_fs_pwd(current->fs, path);
70554+#endif
70555+ return;
70556+}
70557+
70558+int
70559+gr_handle_chroot_chmod(const struct dentry *dentry,
70560+ const struct vfsmount *mnt, const int mode)
70561+{
70562+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70563+ /* allow chmod +s on directories, but not files */
70564+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
70565+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
70566+ proc_is_chrooted(current)) {
70567+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
70568+ return -EPERM;
70569+ }
70570+#endif
70571+ return 0;
70572+}
70573diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
70574new file mode 100644
70575index 0000000..52b3e30
70576--- /dev/null
70577+++ b/grsecurity/grsec_disabled.c
70578@@ -0,0 +1,433 @@
70579+#include <linux/kernel.h>
70580+#include <linux/module.h>
70581+#include <linux/sched.h>
70582+#include <linux/file.h>
70583+#include <linux/fs.h>
70584+#include <linux/kdev_t.h>
70585+#include <linux/net.h>
70586+#include <linux/in.h>
70587+#include <linux/ip.h>
70588+#include <linux/skbuff.h>
70589+#include <linux/sysctl.h>
70590+
70591+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70592+void
70593+pax_set_initial_flags(struct linux_binprm *bprm)
70594+{
70595+ return;
70596+}
70597+#endif
70598+
70599+#ifdef CONFIG_SYSCTL
70600+__u32
70601+gr_handle_sysctl(const struct ctl_table * table, const int op)
70602+{
70603+ return 0;
70604+}
70605+#endif
70606+
70607+#ifdef CONFIG_TASKSTATS
70608+int gr_is_taskstats_denied(int pid)
70609+{
70610+ return 0;
70611+}
70612+#endif
70613+
70614+int
70615+gr_acl_is_enabled(void)
70616+{
70617+ return 0;
70618+}
70619+
70620+void
70621+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
70622+{
70623+ return;
70624+}
70625+
70626+int
70627+gr_handle_rawio(const struct inode *inode)
70628+{
70629+ return 0;
70630+}
70631+
70632+void
70633+gr_acl_handle_psacct(struct task_struct *task, const long code)
70634+{
70635+ return;
70636+}
70637+
70638+int
70639+gr_handle_ptrace(struct task_struct *task, const long request)
70640+{
70641+ return 0;
70642+}
70643+
70644+int
70645+gr_handle_proc_ptrace(struct task_struct *task)
70646+{
70647+ return 0;
70648+}
70649+
70650+int
70651+gr_set_acls(const int type)
70652+{
70653+ return 0;
70654+}
70655+
70656+int
70657+gr_check_hidden_task(const struct task_struct *tsk)
70658+{
70659+ return 0;
70660+}
70661+
70662+int
70663+gr_check_protected_task(const struct task_struct *task)
70664+{
70665+ return 0;
70666+}
70667+
70668+int
70669+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70670+{
70671+ return 0;
70672+}
70673+
70674+void
70675+gr_copy_label(struct task_struct *tsk)
70676+{
70677+ return;
70678+}
70679+
70680+void
70681+gr_set_pax_flags(struct task_struct *task)
70682+{
70683+ return;
70684+}
70685+
70686+int
70687+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
70688+ const int unsafe_share)
70689+{
70690+ return 0;
70691+}
70692+
70693+void
70694+gr_handle_delete(const ino_t ino, const dev_t dev)
70695+{
70696+ return;
70697+}
70698+
70699+void
70700+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
70701+{
70702+ return;
70703+}
70704+
70705+void
70706+gr_handle_crash(struct task_struct *task, const int sig)
70707+{
70708+ return;
70709+}
70710+
70711+int
70712+gr_check_crash_exec(const struct file *filp)
70713+{
70714+ return 0;
70715+}
70716+
70717+int
70718+gr_check_crash_uid(const kuid_t uid)
70719+{
70720+ return 0;
70721+}
70722+
70723+void
70724+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
70725+ struct dentry *old_dentry,
70726+ struct dentry *new_dentry,
70727+ struct vfsmount *mnt, const __u8 replace)
70728+{
70729+ return;
70730+}
70731+
70732+int
70733+gr_search_socket(const int family, const int type, const int protocol)
70734+{
70735+ return 1;
70736+}
70737+
70738+int
70739+gr_search_connectbind(const int mode, const struct socket *sock,
70740+ const struct sockaddr_in *addr)
70741+{
70742+ return 0;
70743+}
70744+
70745+void
70746+gr_handle_alertkill(struct task_struct *task)
70747+{
70748+ return;
70749+}
70750+
70751+__u32
70752+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
70753+{
70754+ return 1;
70755+}
70756+
70757+__u32
70758+gr_acl_handle_hidden_file(const struct dentry * dentry,
70759+ const struct vfsmount * mnt)
70760+{
70761+ return 1;
70762+}
70763+
70764+__u32
70765+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70766+ int acc_mode)
70767+{
70768+ return 1;
70769+}
70770+
70771+__u32
70772+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70773+{
70774+ return 1;
70775+}
70776+
70777+__u32
70778+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
70779+{
70780+ return 1;
70781+}
70782+
70783+int
70784+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
70785+ unsigned int *vm_flags)
70786+{
70787+ return 1;
70788+}
70789+
70790+__u32
70791+gr_acl_handle_truncate(const struct dentry * dentry,
70792+ const struct vfsmount * mnt)
70793+{
70794+ return 1;
70795+}
70796+
70797+__u32
70798+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
70799+{
70800+ return 1;
70801+}
70802+
70803+__u32
70804+gr_acl_handle_access(const struct dentry * dentry,
70805+ const struct vfsmount * mnt, const int fmode)
70806+{
70807+ return 1;
70808+}
70809+
70810+__u32
70811+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
70812+ umode_t *mode)
70813+{
70814+ return 1;
70815+}
70816+
70817+__u32
70818+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
70819+{
70820+ return 1;
70821+}
70822+
70823+__u32
70824+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
70825+{
70826+ return 1;
70827+}
70828+
70829+__u32
70830+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
70831+{
70832+ return 1;
70833+}
70834+
70835+void
70836+grsecurity_init(void)
70837+{
70838+ return;
70839+}
70840+
70841+umode_t gr_acl_umask(void)
70842+{
70843+ return 0;
70844+}
70845+
70846+__u32
70847+gr_acl_handle_mknod(const struct dentry * new_dentry,
70848+ const struct dentry * parent_dentry,
70849+ const struct vfsmount * parent_mnt,
70850+ const int mode)
70851+{
70852+ return 1;
70853+}
70854+
70855+__u32
70856+gr_acl_handle_mkdir(const struct dentry * new_dentry,
70857+ const struct dentry * parent_dentry,
70858+ const struct vfsmount * parent_mnt)
70859+{
70860+ return 1;
70861+}
70862+
70863+__u32
70864+gr_acl_handle_symlink(const struct dentry * new_dentry,
70865+ const struct dentry * parent_dentry,
70866+ const struct vfsmount * parent_mnt, const struct filename *from)
70867+{
70868+ return 1;
70869+}
70870+
70871+__u32
70872+gr_acl_handle_link(const struct dentry * new_dentry,
70873+ const struct dentry * parent_dentry,
70874+ const struct vfsmount * parent_mnt,
70875+ const struct dentry * old_dentry,
70876+ const struct vfsmount * old_mnt, const struct filename *to)
70877+{
70878+ return 1;
70879+}
70880+
70881+int
70882+gr_acl_handle_rename(const struct dentry *new_dentry,
70883+ const struct dentry *parent_dentry,
70884+ const struct vfsmount *parent_mnt,
70885+ const struct dentry *old_dentry,
70886+ const struct inode *old_parent_inode,
70887+ const struct vfsmount *old_mnt, const struct filename *newname)
70888+{
70889+ return 0;
70890+}
70891+
70892+int
70893+gr_acl_handle_filldir(const struct file *file, const char *name,
70894+ const int namelen, const ino_t ino)
70895+{
70896+ return 1;
70897+}
70898+
70899+int
70900+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70901+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
70902+{
70903+ return 1;
70904+}
70905+
70906+int
70907+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
70908+{
70909+ return 0;
70910+}
70911+
70912+int
70913+gr_search_accept(const struct socket *sock)
70914+{
70915+ return 0;
70916+}
70917+
70918+int
70919+gr_search_listen(const struct socket *sock)
70920+{
70921+ return 0;
70922+}
70923+
70924+int
70925+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
70926+{
70927+ return 0;
70928+}
70929+
70930+__u32
70931+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
70932+{
70933+ return 1;
70934+}
70935+
70936+__u32
70937+gr_acl_handle_creat(const struct dentry * dentry,
70938+ const struct dentry * p_dentry,
70939+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70940+ const int imode)
70941+{
70942+ return 1;
70943+}
70944+
70945+void
70946+gr_acl_handle_exit(void)
70947+{
70948+ return;
70949+}
70950+
70951+int
70952+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
70953+{
70954+ return 1;
70955+}
70956+
70957+void
70958+gr_set_role_label(const kuid_t uid, const kgid_t gid)
70959+{
70960+ return;
70961+}
70962+
70963+int
70964+gr_acl_handle_procpidmem(const struct task_struct *task)
70965+{
70966+ return 0;
70967+}
70968+
70969+int
70970+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
70971+{
70972+ return 0;
70973+}
70974+
70975+int
70976+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
70977+{
70978+ return 0;
70979+}
70980+
70981+int
70982+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70983+{
70984+ return 0;
70985+}
70986+
70987+int
70988+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70989+{
70990+ return 0;
70991+}
70992+
70993+int gr_acl_enable_at_secure(void)
70994+{
70995+ return 0;
70996+}
70997+
70998+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70999+{
71000+ return dentry->d_sb->s_dev;
71001+}
71002+
71003+void gr_put_exec_file(struct task_struct *task)
71004+{
71005+ return;
71006+}
71007+
71008+#ifdef CONFIG_SECURITY
71009+EXPORT_SYMBOL(gr_check_user_change);
71010+EXPORT_SYMBOL(gr_check_group_change);
71011+#endif
71012diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
71013new file mode 100644
71014index 0000000..387032b
71015--- /dev/null
71016+++ b/grsecurity/grsec_exec.c
71017@@ -0,0 +1,187 @@
71018+#include <linux/kernel.h>
71019+#include <linux/sched.h>
71020+#include <linux/file.h>
71021+#include <linux/binfmts.h>
71022+#include <linux/fs.h>
71023+#include <linux/types.h>
71024+#include <linux/grdefs.h>
71025+#include <linux/grsecurity.h>
71026+#include <linux/grinternal.h>
71027+#include <linux/capability.h>
71028+#include <linux/module.h>
71029+#include <linux/compat.h>
71030+
71031+#include <asm/uaccess.h>
71032+
71033+#ifdef CONFIG_GRKERNSEC_EXECLOG
71034+static char gr_exec_arg_buf[132];
71035+static DEFINE_MUTEX(gr_exec_arg_mutex);
71036+#endif
71037+
71038+struct user_arg_ptr {
71039+#ifdef CONFIG_COMPAT
71040+ bool is_compat;
71041+#endif
71042+ union {
71043+ const char __user *const __user *native;
71044+#ifdef CONFIG_COMPAT
71045+ const compat_uptr_t __user *compat;
71046+#endif
71047+ } ptr;
71048+};
71049+
71050+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
71051+
71052+void
71053+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
71054+{
71055+#ifdef CONFIG_GRKERNSEC_EXECLOG
71056+ char *grarg = gr_exec_arg_buf;
71057+ unsigned int i, x, execlen = 0;
71058+ char c;
71059+
71060+ if (!((grsec_enable_execlog && grsec_enable_group &&
71061+ in_group_p(grsec_audit_gid))
71062+ || (grsec_enable_execlog && !grsec_enable_group)))
71063+ return;
71064+
71065+ mutex_lock(&gr_exec_arg_mutex);
71066+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
71067+
71068+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
71069+ const char __user *p;
71070+ unsigned int len;
71071+
71072+ p = get_user_arg_ptr(argv, i);
71073+ if (IS_ERR(p))
71074+ goto log;
71075+
71076+ len = strnlen_user(p, 128 - execlen);
71077+ if (len > 128 - execlen)
71078+ len = 128 - execlen;
71079+ else if (len > 0)
71080+ len--;
71081+ if (copy_from_user(grarg + execlen, p, len))
71082+ goto log;
71083+
71084+ /* rewrite unprintable characters */
71085+ for (x = 0; x < len; x++) {
71086+ c = *(grarg + execlen + x);
71087+ if (c < 32 || c > 126)
71088+ *(grarg + execlen + x) = ' ';
71089+ }
71090+
71091+ execlen += len;
71092+ *(grarg + execlen) = ' ';
71093+ *(grarg + execlen + 1) = '\0';
71094+ execlen++;
71095+ }
71096+
71097+ log:
71098+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
71099+ bprm->file->f_path.mnt, grarg);
71100+ mutex_unlock(&gr_exec_arg_mutex);
71101+#endif
71102+ return;
71103+}
71104+
71105+#ifdef CONFIG_GRKERNSEC
71106+extern int gr_acl_is_capable(const int cap);
71107+extern int gr_acl_is_capable_nolog(const int cap);
71108+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
71109+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
71110+extern int gr_chroot_is_capable(const int cap);
71111+extern int gr_chroot_is_capable_nolog(const int cap);
71112+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
71113+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
71114+#endif
71115+
71116+const char *captab_log[] = {
71117+ "CAP_CHOWN",
71118+ "CAP_DAC_OVERRIDE",
71119+ "CAP_DAC_READ_SEARCH",
71120+ "CAP_FOWNER",
71121+ "CAP_FSETID",
71122+ "CAP_KILL",
71123+ "CAP_SETGID",
71124+ "CAP_SETUID",
71125+ "CAP_SETPCAP",
71126+ "CAP_LINUX_IMMUTABLE",
71127+ "CAP_NET_BIND_SERVICE",
71128+ "CAP_NET_BROADCAST",
71129+ "CAP_NET_ADMIN",
71130+ "CAP_NET_RAW",
71131+ "CAP_IPC_LOCK",
71132+ "CAP_IPC_OWNER",
71133+ "CAP_SYS_MODULE",
71134+ "CAP_SYS_RAWIO",
71135+ "CAP_SYS_CHROOT",
71136+ "CAP_SYS_PTRACE",
71137+ "CAP_SYS_PACCT",
71138+ "CAP_SYS_ADMIN",
71139+ "CAP_SYS_BOOT",
71140+ "CAP_SYS_NICE",
71141+ "CAP_SYS_RESOURCE",
71142+ "CAP_SYS_TIME",
71143+ "CAP_SYS_TTY_CONFIG",
71144+ "CAP_MKNOD",
71145+ "CAP_LEASE",
71146+ "CAP_AUDIT_WRITE",
71147+ "CAP_AUDIT_CONTROL",
71148+ "CAP_SETFCAP",
71149+ "CAP_MAC_OVERRIDE",
71150+ "CAP_MAC_ADMIN",
71151+ "CAP_SYSLOG",
71152+ "CAP_WAKE_ALARM"
71153+};
71154+
71155+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
71156+
71157+int gr_is_capable(const int cap)
71158+{
71159+#ifdef CONFIG_GRKERNSEC
71160+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
71161+ return 1;
71162+ return 0;
71163+#else
71164+ return 1;
71165+#endif
71166+}
71167+
71168+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
71169+{
71170+#ifdef CONFIG_GRKERNSEC
71171+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
71172+ return 1;
71173+ return 0;
71174+#else
71175+ return 1;
71176+#endif
71177+}
71178+
71179+int gr_is_capable_nolog(const int cap)
71180+{
71181+#ifdef CONFIG_GRKERNSEC
71182+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
71183+ return 1;
71184+ return 0;
71185+#else
71186+ return 1;
71187+#endif
71188+}
71189+
71190+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
71191+{
71192+#ifdef CONFIG_GRKERNSEC
71193+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
71194+ return 1;
71195+ return 0;
71196+#else
71197+ return 1;
71198+#endif
71199+}
71200+
71201+EXPORT_SYMBOL(gr_is_capable);
71202+EXPORT_SYMBOL(gr_is_capable_nolog);
71203+EXPORT_SYMBOL(gr_task_is_capable);
71204+EXPORT_SYMBOL(gr_task_is_capable_nolog);
71205diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
71206new file mode 100644
71207index 0000000..06cc6ea
71208--- /dev/null
71209+++ b/grsecurity/grsec_fifo.c
71210@@ -0,0 +1,24 @@
71211+#include <linux/kernel.h>
71212+#include <linux/sched.h>
71213+#include <linux/fs.h>
71214+#include <linux/file.h>
71215+#include <linux/grinternal.h>
71216+
71217+int
71218+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
71219+ const struct dentry *dir, const int flag, const int acc_mode)
71220+{
71221+#ifdef CONFIG_GRKERNSEC_FIFO
71222+ const struct cred *cred = current_cred();
71223+
71224+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
71225+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
71226+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
71227+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
71228+ if (!inode_permission(dentry->d_inode, acc_mode))
71229+ 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));
71230+ return -EACCES;
71231+ }
71232+#endif
71233+ return 0;
71234+}
71235diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
71236new file mode 100644
71237index 0000000..8ca18bf
71238--- /dev/null
71239+++ b/grsecurity/grsec_fork.c
71240@@ -0,0 +1,23 @@
71241+#include <linux/kernel.h>
71242+#include <linux/sched.h>
71243+#include <linux/grsecurity.h>
71244+#include <linux/grinternal.h>
71245+#include <linux/errno.h>
71246+
71247+void
71248+gr_log_forkfail(const int retval)
71249+{
71250+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71251+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
71252+ switch (retval) {
71253+ case -EAGAIN:
71254+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
71255+ break;
71256+ case -ENOMEM:
71257+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
71258+ break;
71259+ }
71260+ }
71261+#endif
71262+ return;
71263+}
71264diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
71265new file mode 100644
71266index 0000000..a88e901
71267--- /dev/null
71268+++ b/grsecurity/grsec_init.c
71269@@ -0,0 +1,272 @@
71270+#include <linux/kernel.h>
71271+#include <linux/sched.h>
71272+#include <linux/mm.h>
71273+#include <linux/gracl.h>
71274+#include <linux/slab.h>
71275+#include <linux/vmalloc.h>
71276+#include <linux/percpu.h>
71277+#include <linux/module.h>
71278+
71279+int grsec_enable_ptrace_readexec;
71280+int grsec_enable_setxid;
71281+int grsec_enable_symlinkown;
71282+kgid_t grsec_symlinkown_gid;
71283+int grsec_enable_brute;
71284+int grsec_enable_link;
71285+int grsec_enable_dmesg;
71286+int grsec_enable_harden_ptrace;
71287+int grsec_enable_harden_ipc;
71288+int grsec_enable_fifo;
71289+int grsec_enable_execlog;
71290+int grsec_enable_signal;
71291+int grsec_enable_forkfail;
71292+int grsec_enable_audit_ptrace;
71293+int grsec_enable_time;
71294+int grsec_enable_group;
71295+kgid_t grsec_audit_gid;
71296+int grsec_enable_chdir;
71297+int grsec_enable_mount;
71298+int grsec_enable_rofs;
71299+int grsec_deny_new_usb;
71300+int grsec_enable_chroot_findtask;
71301+int grsec_enable_chroot_mount;
71302+int grsec_enable_chroot_shmat;
71303+int grsec_enable_chroot_fchdir;
71304+int grsec_enable_chroot_double;
71305+int grsec_enable_chroot_pivot;
71306+int grsec_enable_chroot_chdir;
71307+int grsec_enable_chroot_chmod;
71308+int grsec_enable_chroot_mknod;
71309+int grsec_enable_chroot_nice;
71310+int grsec_enable_chroot_execlog;
71311+int grsec_enable_chroot_caps;
71312+int grsec_enable_chroot_sysctl;
71313+int grsec_enable_chroot_unix;
71314+int grsec_enable_tpe;
71315+kgid_t grsec_tpe_gid;
71316+int grsec_enable_blackhole;
71317+#ifdef CONFIG_IPV6_MODULE
71318+EXPORT_SYMBOL(grsec_enable_blackhole);
71319+#endif
71320+int grsec_lastack_retries;
71321+int grsec_enable_tpe_all;
71322+int grsec_enable_tpe_invert;
71323+int grsec_enable_socket_all;
71324+kgid_t grsec_socket_all_gid;
71325+int grsec_enable_socket_client;
71326+kgid_t grsec_socket_client_gid;
71327+int grsec_enable_socket_server;
71328+kgid_t grsec_socket_server_gid;
71329+int grsec_resource_logging;
71330+int grsec_disable_privio;
71331+int grsec_enable_log_rwxmaps;
71332+int grsec_lock;
71333+
71334+DEFINE_SPINLOCK(grsec_alert_lock);
71335+unsigned long grsec_alert_wtime = 0;
71336+unsigned long grsec_alert_fyet = 0;
71337+
71338+DEFINE_SPINLOCK(grsec_audit_lock);
71339+
71340+DEFINE_RWLOCK(grsec_exec_file_lock);
71341+
71342+char *gr_shared_page[4];
71343+
71344+char *gr_alert_log_fmt;
71345+char *gr_audit_log_fmt;
71346+char *gr_alert_log_buf;
71347+char *gr_audit_log_buf;
71348+
71349+void __init
71350+grsecurity_init(void)
71351+{
71352+ int j;
71353+ /* create the per-cpu shared pages */
71354+
71355+#ifdef CONFIG_X86
71356+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
71357+#endif
71358+
71359+ for (j = 0; j < 4; j++) {
71360+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
71361+ if (gr_shared_page[j] == NULL) {
71362+ panic("Unable to allocate grsecurity shared page");
71363+ return;
71364+ }
71365+ }
71366+
71367+ /* allocate log buffers */
71368+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
71369+ if (!gr_alert_log_fmt) {
71370+ panic("Unable to allocate grsecurity alert log format buffer");
71371+ return;
71372+ }
71373+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
71374+ if (!gr_audit_log_fmt) {
71375+ panic("Unable to allocate grsecurity audit log format buffer");
71376+ return;
71377+ }
71378+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
71379+ if (!gr_alert_log_buf) {
71380+ panic("Unable to allocate grsecurity alert log buffer");
71381+ return;
71382+ }
71383+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
71384+ if (!gr_audit_log_buf) {
71385+ panic("Unable to allocate grsecurity audit log buffer");
71386+ return;
71387+ }
71388+
71389+#ifdef CONFIG_GRKERNSEC_IO
71390+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
71391+ grsec_disable_privio = 1;
71392+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
71393+ grsec_disable_privio = 1;
71394+#else
71395+ grsec_disable_privio = 0;
71396+#endif
71397+#endif
71398+
71399+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71400+ /* for backward compatibility, tpe_invert always defaults to on if
71401+ enabled in the kernel
71402+ */
71403+ grsec_enable_tpe_invert = 1;
71404+#endif
71405+
71406+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
71407+#ifndef CONFIG_GRKERNSEC_SYSCTL
71408+ grsec_lock = 1;
71409+#endif
71410+
71411+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71412+ grsec_enable_log_rwxmaps = 1;
71413+#endif
71414+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71415+ grsec_enable_group = 1;
71416+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
71417+#endif
71418+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71419+ grsec_enable_ptrace_readexec = 1;
71420+#endif
71421+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71422+ grsec_enable_chdir = 1;
71423+#endif
71424+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71425+ grsec_enable_harden_ptrace = 1;
71426+#endif
71427+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
71428+ grsec_enable_harden_ipc = 1;
71429+#endif
71430+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71431+ grsec_enable_mount = 1;
71432+#endif
71433+#ifdef CONFIG_GRKERNSEC_LINK
71434+ grsec_enable_link = 1;
71435+#endif
71436+#ifdef CONFIG_GRKERNSEC_BRUTE
71437+ grsec_enable_brute = 1;
71438+#endif
71439+#ifdef CONFIG_GRKERNSEC_DMESG
71440+ grsec_enable_dmesg = 1;
71441+#endif
71442+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71443+ grsec_enable_blackhole = 1;
71444+ grsec_lastack_retries = 4;
71445+#endif
71446+#ifdef CONFIG_GRKERNSEC_FIFO
71447+ grsec_enable_fifo = 1;
71448+#endif
71449+#ifdef CONFIG_GRKERNSEC_EXECLOG
71450+ grsec_enable_execlog = 1;
71451+#endif
71452+#ifdef CONFIG_GRKERNSEC_SETXID
71453+ grsec_enable_setxid = 1;
71454+#endif
71455+#ifdef CONFIG_GRKERNSEC_SIGNAL
71456+ grsec_enable_signal = 1;
71457+#endif
71458+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71459+ grsec_enable_forkfail = 1;
71460+#endif
71461+#ifdef CONFIG_GRKERNSEC_TIME
71462+ grsec_enable_time = 1;
71463+#endif
71464+#ifdef CONFIG_GRKERNSEC_RESLOG
71465+ grsec_resource_logging = 1;
71466+#endif
71467+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71468+ grsec_enable_chroot_findtask = 1;
71469+#endif
71470+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71471+ grsec_enable_chroot_unix = 1;
71472+#endif
71473+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71474+ grsec_enable_chroot_mount = 1;
71475+#endif
71476+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71477+ grsec_enable_chroot_fchdir = 1;
71478+#endif
71479+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71480+ grsec_enable_chroot_shmat = 1;
71481+#endif
71482+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71483+ grsec_enable_audit_ptrace = 1;
71484+#endif
71485+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71486+ grsec_enable_chroot_double = 1;
71487+#endif
71488+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71489+ grsec_enable_chroot_pivot = 1;
71490+#endif
71491+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71492+ grsec_enable_chroot_chdir = 1;
71493+#endif
71494+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71495+ grsec_enable_chroot_chmod = 1;
71496+#endif
71497+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71498+ grsec_enable_chroot_mknod = 1;
71499+#endif
71500+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71501+ grsec_enable_chroot_nice = 1;
71502+#endif
71503+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71504+ grsec_enable_chroot_execlog = 1;
71505+#endif
71506+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71507+ grsec_enable_chroot_caps = 1;
71508+#endif
71509+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71510+ grsec_enable_chroot_sysctl = 1;
71511+#endif
71512+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71513+ grsec_enable_symlinkown = 1;
71514+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
71515+#endif
71516+#ifdef CONFIG_GRKERNSEC_TPE
71517+ grsec_enable_tpe = 1;
71518+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
71519+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71520+ grsec_enable_tpe_all = 1;
71521+#endif
71522+#endif
71523+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71524+ grsec_enable_socket_all = 1;
71525+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
71526+#endif
71527+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71528+ grsec_enable_socket_client = 1;
71529+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
71530+#endif
71531+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71532+ grsec_enable_socket_server = 1;
71533+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
71534+#endif
71535+#endif
71536+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
71537+ grsec_deny_new_usb = 1;
71538+#endif
71539+
71540+ return;
71541+}
71542diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
71543new file mode 100644
71544index 0000000..78d1680
71545--- /dev/null
71546+++ b/grsecurity/grsec_ipc.c
71547@@ -0,0 +1,48 @@
71548+#include <linux/kernel.h>
71549+#include <linux/mm.h>
71550+#include <linux/sched.h>
71551+#include <linux/file.h>
71552+#include <linux/ipc.h>
71553+#include <linux/ipc_namespace.h>
71554+#include <linux/grsecurity.h>
71555+#include <linux/grinternal.h>
71556+
71557+int
71558+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
71559+{
71560+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
71561+ int write;
71562+ int orig_granted_mode;
71563+ kuid_t euid;
71564+ kgid_t egid;
71565+
71566+ if (!grsec_enable_harden_ipc)
71567+ return 0;
71568+
71569+ euid = current_euid();
71570+ egid = current_egid();
71571+
71572+ write = requested_mode & 00002;
71573+ orig_granted_mode = ipcp->mode;
71574+
71575+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
71576+ orig_granted_mode >>= 6;
71577+ else {
71578+ /* if likely wrong permissions, lock to user */
71579+ if (orig_granted_mode & 0007)
71580+ orig_granted_mode = 0;
71581+ /* otherwise do a egid-only check */
71582+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
71583+ orig_granted_mode >>= 3;
71584+ /* otherwise, no access */
71585+ else
71586+ orig_granted_mode = 0;
71587+ }
71588+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
71589+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
71590+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
71591+ return 0;
71592+ }
71593+#endif
71594+ return 1;
71595+}
71596diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
71597new file mode 100644
71598index 0000000..5e05e20
71599--- /dev/null
71600+++ b/grsecurity/grsec_link.c
71601@@ -0,0 +1,58 @@
71602+#include <linux/kernel.h>
71603+#include <linux/sched.h>
71604+#include <linux/fs.h>
71605+#include <linux/file.h>
71606+#include <linux/grinternal.h>
71607+
71608+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
71609+{
71610+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71611+ const struct inode *link_inode = link->dentry->d_inode;
71612+
71613+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
71614+ /* ignore root-owned links, e.g. /proc/self */
71615+ gr_is_global_nonroot(link_inode->i_uid) && target &&
71616+ !uid_eq(link_inode->i_uid, target->i_uid)) {
71617+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
71618+ return 1;
71619+ }
71620+#endif
71621+ return 0;
71622+}
71623+
71624+int
71625+gr_handle_follow_link(const struct inode *parent,
71626+ const struct inode *inode,
71627+ const struct dentry *dentry, const struct vfsmount *mnt)
71628+{
71629+#ifdef CONFIG_GRKERNSEC_LINK
71630+ const struct cred *cred = current_cred();
71631+
71632+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
71633+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
71634+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
71635+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
71636+ return -EACCES;
71637+ }
71638+#endif
71639+ return 0;
71640+}
71641+
71642+int
71643+gr_handle_hardlink(const struct dentry *dentry,
71644+ const struct vfsmount *mnt,
71645+ struct inode *inode, const int mode, const struct filename *to)
71646+{
71647+#ifdef CONFIG_GRKERNSEC_LINK
71648+ const struct cred *cred = current_cred();
71649+
71650+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
71651+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
71652+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
71653+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
71654+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
71655+ return -EPERM;
71656+ }
71657+#endif
71658+ return 0;
71659+}
71660diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
71661new file mode 100644
71662index 0000000..dbe0a6b
71663--- /dev/null
71664+++ b/grsecurity/grsec_log.c
71665@@ -0,0 +1,341 @@
71666+#include <linux/kernel.h>
71667+#include <linux/sched.h>
71668+#include <linux/file.h>
71669+#include <linux/tty.h>
71670+#include <linux/fs.h>
71671+#include <linux/mm.h>
71672+#include <linux/grinternal.h>
71673+
71674+#ifdef CONFIG_TREE_PREEMPT_RCU
71675+#define DISABLE_PREEMPT() preempt_disable()
71676+#define ENABLE_PREEMPT() preempt_enable()
71677+#else
71678+#define DISABLE_PREEMPT()
71679+#define ENABLE_PREEMPT()
71680+#endif
71681+
71682+#define BEGIN_LOCKS(x) \
71683+ DISABLE_PREEMPT(); \
71684+ rcu_read_lock(); \
71685+ read_lock(&tasklist_lock); \
71686+ read_lock(&grsec_exec_file_lock); \
71687+ if (x != GR_DO_AUDIT) \
71688+ spin_lock(&grsec_alert_lock); \
71689+ else \
71690+ spin_lock(&grsec_audit_lock)
71691+
71692+#define END_LOCKS(x) \
71693+ if (x != GR_DO_AUDIT) \
71694+ spin_unlock(&grsec_alert_lock); \
71695+ else \
71696+ spin_unlock(&grsec_audit_lock); \
71697+ read_unlock(&grsec_exec_file_lock); \
71698+ read_unlock(&tasklist_lock); \
71699+ rcu_read_unlock(); \
71700+ ENABLE_PREEMPT(); \
71701+ if (x == GR_DONT_AUDIT) \
71702+ gr_handle_alertkill(current)
71703+
71704+enum {
71705+ FLOODING,
71706+ NO_FLOODING
71707+};
71708+
71709+extern char *gr_alert_log_fmt;
71710+extern char *gr_audit_log_fmt;
71711+extern char *gr_alert_log_buf;
71712+extern char *gr_audit_log_buf;
71713+
71714+static int gr_log_start(int audit)
71715+{
71716+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
71717+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
71718+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71719+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
71720+ unsigned long curr_secs = get_seconds();
71721+
71722+ if (audit == GR_DO_AUDIT)
71723+ goto set_fmt;
71724+
71725+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
71726+ grsec_alert_wtime = curr_secs;
71727+ grsec_alert_fyet = 0;
71728+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
71729+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
71730+ grsec_alert_fyet++;
71731+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
71732+ grsec_alert_wtime = curr_secs;
71733+ grsec_alert_fyet++;
71734+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
71735+ return FLOODING;
71736+ }
71737+ else return FLOODING;
71738+
71739+set_fmt:
71740+#endif
71741+ memset(buf, 0, PAGE_SIZE);
71742+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
71743+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
71744+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71745+ } else if (current->signal->curr_ip) {
71746+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
71747+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
71748+ } else if (gr_acl_is_enabled()) {
71749+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
71750+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71751+ } else {
71752+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
71753+ strcpy(buf, fmt);
71754+ }
71755+
71756+ return NO_FLOODING;
71757+}
71758+
71759+static void gr_log_middle(int audit, const char *msg, va_list ap)
71760+ __attribute__ ((format (printf, 2, 0)));
71761+
71762+static void gr_log_middle(int audit, const char *msg, va_list ap)
71763+{
71764+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71765+ unsigned int len = strlen(buf);
71766+
71767+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71768+
71769+ return;
71770+}
71771+
71772+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71773+ __attribute__ ((format (printf, 2, 3)));
71774+
71775+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71776+{
71777+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71778+ unsigned int len = strlen(buf);
71779+ va_list ap;
71780+
71781+ va_start(ap, msg);
71782+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71783+ va_end(ap);
71784+
71785+ return;
71786+}
71787+
71788+static void gr_log_end(int audit, int append_default)
71789+{
71790+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71791+ if (append_default) {
71792+ struct task_struct *task = current;
71793+ struct task_struct *parent = task->real_parent;
71794+ const struct cred *cred = __task_cred(task);
71795+ const struct cred *pcred = __task_cred(parent);
71796+ unsigned int len = strlen(buf);
71797+
71798+ 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));
71799+ }
71800+
71801+ printk("%s\n", buf);
71802+
71803+ return;
71804+}
71805+
71806+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
71807+{
71808+ int logtype;
71809+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
71810+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
71811+ void *voidptr = NULL;
71812+ int num1 = 0, num2 = 0;
71813+ unsigned long ulong1 = 0, ulong2 = 0;
71814+ struct dentry *dentry = NULL;
71815+ struct vfsmount *mnt = NULL;
71816+ struct file *file = NULL;
71817+ struct task_struct *task = NULL;
71818+ struct vm_area_struct *vma = NULL;
71819+ const struct cred *cred, *pcred;
71820+ va_list ap;
71821+
71822+ BEGIN_LOCKS(audit);
71823+ logtype = gr_log_start(audit);
71824+ if (logtype == FLOODING) {
71825+ END_LOCKS(audit);
71826+ return;
71827+ }
71828+ va_start(ap, argtypes);
71829+ switch (argtypes) {
71830+ case GR_TTYSNIFF:
71831+ task = va_arg(ap, struct task_struct *);
71832+ 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));
71833+ break;
71834+ case GR_SYSCTL_HIDDEN:
71835+ str1 = va_arg(ap, char *);
71836+ gr_log_middle_varargs(audit, msg, result, str1);
71837+ break;
71838+ case GR_RBAC:
71839+ dentry = va_arg(ap, struct dentry *);
71840+ mnt = va_arg(ap, struct vfsmount *);
71841+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
71842+ break;
71843+ case GR_RBAC_STR:
71844+ dentry = va_arg(ap, struct dentry *);
71845+ mnt = va_arg(ap, struct vfsmount *);
71846+ str1 = va_arg(ap, char *);
71847+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
71848+ break;
71849+ case GR_STR_RBAC:
71850+ str1 = va_arg(ap, char *);
71851+ dentry = va_arg(ap, struct dentry *);
71852+ mnt = va_arg(ap, struct vfsmount *);
71853+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
71854+ break;
71855+ case GR_RBAC_MODE2:
71856+ dentry = va_arg(ap, struct dentry *);
71857+ mnt = va_arg(ap, struct vfsmount *);
71858+ str1 = va_arg(ap, char *);
71859+ str2 = va_arg(ap, char *);
71860+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
71861+ break;
71862+ case GR_RBAC_MODE3:
71863+ dentry = va_arg(ap, struct dentry *);
71864+ mnt = va_arg(ap, struct vfsmount *);
71865+ str1 = va_arg(ap, char *);
71866+ str2 = va_arg(ap, char *);
71867+ str3 = va_arg(ap, char *);
71868+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
71869+ break;
71870+ case GR_FILENAME:
71871+ dentry = va_arg(ap, struct dentry *);
71872+ mnt = va_arg(ap, struct vfsmount *);
71873+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
71874+ break;
71875+ case GR_STR_FILENAME:
71876+ str1 = va_arg(ap, char *);
71877+ dentry = va_arg(ap, struct dentry *);
71878+ mnt = va_arg(ap, struct vfsmount *);
71879+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
71880+ break;
71881+ case GR_FILENAME_STR:
71882+ dentry = va_arg(ap, struct dentry *);
71883+ mnt = va_arg(ap, struct vfsmount *);
71884+ str1 = va_arg(ap, char *);
71885+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
71886+ break;
71887+ case GR_FILENAME_TWO_INT:
71888+ dentry = va_arg(ap, struct dentry *);
71889+ mnt = va_arg(ap, struct vfsmount *);
71890+ num1 = va_arg(ap, int);
71891+ num2 = va_arg(ap, int);
71892+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
71893+ break;
71894+ case GR_FILENAME_TWO_INT_STR:
71895+ dentry = va_arg(ap, struct dentry *);
71896+ mnt = va_arg(ap, struct vfsmount *);
71897+ num1 = va_arg(ap, int);
71898+ num2 = va_arg(ap, int);
71899+ str1 = va_arg(ap, char *);
71900+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
71901+ break;
71902+ case GR_TEXTREL:
71903+ file = va_arg(ap, struct file *);
71904+ ulong1 = va_arg(ap, unsigned long);
71905+ ulong2 = va_arg(ap, unsigned long);
71906+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
71907+ break;
71908+ case GR_PTRACE:
71909+ task = va_arg(ap, struct task_struct *);
71910+ 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));
71911+ break;
71912+ case GR_RESOURCE:
71913+ task = va_arg(ap, struct task_struct *);
71914+ cred = __task_cred(task);
71915+ pcred = __task_cred(task->real_parent);
71916+ ulong1 = va_arg(ap, unsigned long);
71917+ str1 = va_arg(ap, char *);
71918+ ulong2 = va_arg(ap, unsigned long);
71919+ 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));
71920+ break;
71921+ case GR_CAP:
71922+ task = va_arg(ap, struct task_struct *);
71923+ cred = __task_cred(task);
71924+ pcred = __task_cred(task->real_parent);
71925+ str1 = va_arg(ap, char *);
71926+ 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));
71927+ break;
71928+ case GR_SIG:
71929+ str1 = va_arg(ap, char *);
71930+ voidptr = va_arg(ap, void *);
71931+ gr_log_middle_varargs(audit, msg, str1, voidptr);
71932+ break;
71933+ case GR_SIG2:
71934+ task = va_arg(ap, struct task_struct *);
71935+ cred = __task_cred(task);
71936+ pcred = __task_cred(task->real_parent);
71937+ num1 = va_arg(ap, int);
71938+ 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));
71939+ break;
71940+ case GR_CRASH1:
71941+ task = va_arg(ap, struct task_struct *);
71942+ cred = __task_cred(task);
71943+ pcred = __task_cred(task->real_parent);
71944+ ulong1 = va_arg(ap, unsigned long);
71945+ 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);
71946+ break;
71947+ case GR_CRASH2:
71948+ task = va_arg(ap, struct task_struct *);
71949+ cred = __task_cred(task);
71950+ pcred = __task_cred(task->real_parent);
71951+ ulong1 = va_arg(ap, unsigned long);
71952+ 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);
71953+ break;
71954+ case GR_RWXMAP:
71955+ file = va_arg(ap, struct file *);
71956+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
71957+ break;
71958+ case GR_RWXMAPVMA:
71959+ vma = va_arg(ap, struct vm_area_struct *);
71960+ if (vma->vm_file)
71961+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
71962+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
71963+ str1 = "<stack>";
71964+ else if (vma->vm_start <= current->mm->brk &&
71965+ vma->vm_end >= current->mm->start_brk)
71966+ str1 = "<heap>";
71967+ else
71968+ str1 = "<anonymous mapping>";
71969+ gr_log_middle_varargs(audit, msg, str1);
71970+ break;
71971+ case GR_PSACCT:
71972+ {
71973+ unsigned int wday, cday;
71974+ __u8 whr, chr;
71975+ __u8 wmin, cmin;
71976+ __u8 wsec, csec;
71977+ char cur_tty[64] = { 0 };
71978+ char parent_tty[64] = { 0 };
71979+
71980+ task = va_arg(ap, struct task_struct *);
71981+ wday = va_arg(ap, unsigned int);
71982+ cday = va_arg(ap, unsigned int);
71983+ whr = va_arg(ap, int);
71984+ chr = va_arg(ap, int);
71985+ wmin = va_arg(ap, int);
71986+ cmin = va_arg(ap, int);
71987+ wsec = va_arg(ap, int);
71988+ csec = va_arg(ap, int);
71989+ ulong1 = va_arg(ap, unsigned long);
71990+ cred = __task_cred(task);
71991+ pcred = __task_cred(task->real_parent);
71992+
71993+ 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));
71994+ }
71995+ break;
71996+ default:
71997+ gr_log_middle(audit, msg, ap);
71998+ }
71999+ va_end(ap);
72000+ // these don't need DEFAULTSECARGS printed on the end
72001+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
72002+ gr_log_end(audit, 0);
72003+ else
72004+ gr_log_end(audit, 1);
72005+ END_LOCKS(audit);
72006+}
72007diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
72008new file mode 100644
72009index 0000000..f536303
72010--- /dev/null
72011+++ b/grsecurity/grsec_mem.c
72012@@ -0,0 +1,40 @@
72013+#include <linux/kernel.h>
72014+#include <linux/sched.h>
72015+#include <linux/mm.h>
72016+#include <linux/mman.h>
72017+#include <linux/grinternal.h>
72018+
72019+void
72020+gr_handle_ioperm(void)
72021+{
72022+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
72023+ return;
72024+}
72025+
72026+void
72027+gr_handle_iopl(void)
72028+{
72029+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
72030+ return;
72031+}
72032+
72033+void
72034+gr_handle_mem_readwrite(u64 from, u64 to)
72035+{
72036+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
72037+ return;
72038+}
72039+
72040+void
72041+gr_handle_vm86(void)
72042+{
72043+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
72044+ return;
72045+}
72046+
72047+void
72048+gr_log_badprocpid(const char *entry)
72049+{
72050+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
72051+ return;
72052+}
72053diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
72054new file mode 100644
72055index 0000000..cd9e124
72056--- /dev/null
72057+++ b/grsecurity/grsec_mount.c
72058@@ -0,0 +1,65 @@
72059+#include <linux/kernel.h>
72060+#include <linux/sched.h>
72061+#include <linux/mount.h>
72062+#include <linux/major.h>
72063+#include <linux/grsecurity.h>
72064+#include <linux/grinternal.h>
72065+
72066+void
72067+gr_log_remount(const char *devname, const int retval)
72068+{
72069+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72070+ if (grsec_enable_mount && (retval >= 0))
72071+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
72072+#endif
72073+ return;
72074+}
72075+
72076+void
72077+gr_log_unmount(const char *devname, const int retval)
72078+{
72079+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72080+ if (grsec_enable_mount && (retval >= 0))
72081+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
72082+#endif
72083+ return;
72084+}
72085+
72086+void
72087+gr_log_mount(const char *from, const char *to, const int retval)
72088+{
72089+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72090+ if (grsec_enable_mount && (retval >= 0))
72091+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
72092+#endif
72093+ return;
72094+}
72095+
72096+int
72097+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
72098+{
72099+#ifdef CONFIG_GRKERNSEC_ROFS
72100+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
72101+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
72102+ return -EPERM;
72103+ } else
72104+ return 0;
72105+#endif
72106+ return 0;
72107+}
72108+
72109+int
72110+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
72111+{
72112+#ifdef CONFIG_GRKERNSEC_ROFS
72113+ struct inode *inode = dentry->d_inode;
72114+
72115+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
72116+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
72117+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
72118+ return -EPERM;
72119+ } else
72120+ return 0;
72121+#endif
72122+ return 0;
72123+}
72124diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
72125new file mode 100644
72126index 0000000..6ee9d50
72127--- /dev/null
72128+++ b/grsecurity/grsec_pax.c
72129@@ -0,0 +1,45 @@
72130+#include <linux/kernel.h>
72131+#include <linux/sched.h>
72132+#include <linux/mm.h>
72133+#include <linux/file.h>
72134+#include <linux/grinternal.h>
72135+#include <linux/grsecurity.h>
72136+
72137+void
72138+gr_log_textrel(struct vm_area_struct * vma)
72139+{
72140+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72141+ if (grsec_enable_log_rwxmaps)
72142+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
72143+#endif
72144+ return;
72145+}
72146+
72147+void gr_log_ptgnustack(struct file *file)
72148+{
72149+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72150+ if (grsec_enable_log_rwxmaps)
72151+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
72152+#endif
72153+ return;
72154+}
72155+
72156+void
72157+gr_log_rwxmmap(struct file *file)
72158+{
72159+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72160+ if (grsec_enable_log_rwxmaps)
72161+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
72162+#endif
72163+ return;
72164+}
72165+
72166+void
72167+gr_log_rwxmprotect(struct vm_area_struct *vma)
72168+{
72169+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72170+ if (grsec_enable_log_rwxmaps)
72171+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
72172+#endif
72173+ return;
72174+}
72175diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
72176new file mode 100644
72177index 0000000..f7f29aa
72178--- /dev/null
72179+++ b/grsecurity/grsec_ptrace.c
72180@@ -0,0 +1,30 @@
72181+#include <linux/kernel.h>
72182+#include <linux/sched.h>
72183+#include <linux/grinternal.h>
72184+#include <linux/security.h>
72185+
72186+void
72187+gr_audit_ptrace(struct task_struct *task)
72188+{
72189+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72190+ if (grsec_enable_audit_ptrace)
72191+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
72192+#endif
72193+ return;
72194+}
72195+
72196+int
72197+gr_ptrace_readexec(struct file *file, int unsafe_flags)
72198+{
72199+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72200+ const struct dentry *dentry = file->f_path.dentry;
72201+ const struct vfsmount *mnt = file->f_path.mnt;
72202+
72203+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
72204+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
72205+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
72206+ return -EACCES;
72207+ }
72208+#endif
72209+ return 0;
72210+}
72211diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
72212new file mode 100644
72213index 0000000..3860c7e
72214--- /dev/null
72215+++ b/grsecurity/grsec_sig.c
72216@@ -0,0 +1,236 @@
72217+#include <linux/kernel.h>
72218+#include <linux/sched.h>
72219+#include <linux/fs.h>
72220+#include <linux/delay.h>
72221+#include <linux/grsecurity.h>
72222+#include <linux/grinternal.h>
72223+#include <linux/hardirq.h>
72224+
72225+char *signames[] = {
72226+ [SIGSEGV] = "Segmentation fault",
72227+ [SIGILL] = "Illegal instruction",
72228+ [SIGABRT] = "Abort",
72229+ [SIGBUS] = "Invalid alignment/Bus error"
72230+};
72231+
72232+void
72233+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
72234+{
72235+#ifdef CONFIG_GRKERNSEC_SIGNAL
72236+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
72237+ (sig == SIGABRT) || (sig == SIGBUS))) {
72238+ if (task_pid_nr(t) == task_pid_nr(current)) {
72239+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
72240+ } else {
72241+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
72242+ }
72243+ }
72244+#endif
72245+ return;
72246+}
72247+
72248+int
72249+gr_handle_signal(const struct task_struct *p, const int sig)
72250+{
72251+#ifdef CONFIG_GRKERNSEC
72252+ /* ignore the 0 signal for protected task checks */
72253+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
72254+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
72255+ return -EPERM;
72256+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
72257+ return -EPERM;
72258+ }
72259+#endif
72260+ return 0;
72261+}
72262+
72263+#ifdef CONFIG_GRKERNSEC
72264+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
72265+
72266+int gr_fake_force_sig(int sig, struct task_struct *t)
72267+{
72268+ unsigned long int flags;
72269+ int ret, blocked, ignored;
72270+ struct k_sigaction *action;
72271+
72272+ spin_lock_irqsave(&t->sighand->siglock, flags);
72273+ action = &t->sighand->action[sig-1];
72274+ ignored = action->sa.sa_handler == SIG_IGN;
72275+ blocked = sigismember(&t->blocked, sig);
72276+ if (blocked || ignored) {
72277+ action->sa.sa_handler = SIG_DFL;
72278+ if (blocked) {
72279+ sigdelset(&t->blocked, sig);
72280+ recalc_sigpending_and_wake(t);
72281+ }
72282+ }
72283+ if (action->sa.sa_handler == SIG_DFL)
72284+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
72285+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
72286+
72287+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
72288+
72289+ return ret;
72290+}
72291+#endif
72292+
72293+#define GR_USER_BAN_TIME (15 * 60)
72294+#define GR_DAEMON_BRUTE_TIME (30 * 60)
72295+
72296+void gr_handle_brute_attach(int dumpable)
72297+{
72298+#ifdef CONFIG_GRKERNSEC_BRUTE
72299+ struct task_struct *p = current;
72300+ kuid_t uid = GLOBAL_ROOT_UID;
72301+ int daemon = 0;
72302+
72303+ if (!grsec_enable_brute)
72304+ return;
72305+
72306+ rcu_read_lock();
72307+ read_lock(&tasklist_lock);
72308+ read_lock(&grsec_exec_file_lock);
72309+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
72310+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
72311+ p->real_parent->brute = 1;
72312+ daemon = 1;
72313+ } else {
72314+ const struct cred *cred = __task_cred(p), *cred2;
72315+ struct task_struct *tsk, *tsk2;
72316+
72317+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
72318+ struct user_struct *user;
72319+
72320+ uid = cred->uid;
72321+
72322+ /* this is put upon execution past expiration */
72323+ user = find_user(uid);
72324+ if (user == NULL)
72325+ goto unlock;
72326+ user->suid_banned = 1;
72327+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
72328+ if (user->suid_ban_expires == ~0UL)
72329+ user->suid_ban_expires--;
72330+
72331+ /* only kill other threads of the same binary, from the same user */
72332+ do_each_thread(tsk2, tsk) {
72333+ cred2 = __task_cred(tsk);
72334+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
72335+ gr_fake_force_sig(SIGKILL, tsk);
72336+ } while_each_thread(tsk2, tsk);
72337+ }
72338+ }
72339+unlock:
72340+ read_unlock(&grsec_exec_file_lock);
72341+ read_unlock(&tasklist_lock);
72342+ rcu_read_unlock();
72343+
72344+ if (gr_is_global_nonroot(uid))
72345+ 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);
72346+ else if (daemon)
72347+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
72348+
72349+#endif
72350+ return;
72351+}
72352+
72353+void gr_handle_brute_check(void)
72354+{
72355+#ifdef CONFIG_GRKERNSEC_BRUTE
72356+ struct task_struct *p = current;
72357+
72358+ if (unlikely(p->brute)) {
72359+ if (!grsec_enable_brute)
72360+ p->brute = 0;
72361+ else if (time_before(get_seconds(), p->brute_expires))
72362+ msleep(30 * 1000);
72363+ }
72364+#endif
72365+ return;
72366+}
72367+
72368+void gr_handle_kernel_exploit(void)
72369+{
72370+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72371+ const struct cred *cred;
72372+ struct task_struct *tsk, *tsk2;
72373+ struct user_struct *user;
72374+ kuid_t uid;
72375+
72376+ if (in_irq() || in_serving_softirq() || in_nmi())
72377+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
72378+
72379+ uid = current_uid();
72380+
72381+ if (gr_is_global_root(uid))
72382+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
72383+ else {
72384+ /* kill all the processes of this user, hold a reference
72385+ to their creds struct, and prevent them from creating
72386+ another process until system reset
72387+ */
72388+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
72389+ GR_GLOBAL_UID(uid));
72390+ /* we intentionally leak this ref */
72391+ user = get_uid(current->cred->user);
72392+ if (user)
72393+ user->kernel_banned = 1;
72394+
72395+ /* kill all processes of this user */
72396+ read_lock(&tasklist_lock);
72397+ do_each_thread(tsk2, tsk) {
72398+ cred = __task_cred(tsk);
72399+ if (uid_eq(cred->uid, uid))
72400+ gr_fake_force_sig(SIGKILL, tsk);
72401+ } while_each_thread(tsk2, tsk);
72402+ read_unlock(&tasklist_lock);
72403+ }
72404+#endif
72405+}
72406+
72407+#ifdef CONFIG_GRKERNSEC_BRUTE
72408+static bool suid_ban_expired(struct user_struct *user)
72409+{
72410+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
72411+ user->suid_banned = 0;
72412+ user->suid_ban_expires = 0;
72413+ free_uid(user);
72414+ return true;
72415+ }
72416+
72417+ return false;
72418+}
72419+#endif
72420+
72421+int gr_process_kernel_exec_ban(void)
72422+{
72423+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72424+ if (unlikely(current->cred->user->kernel_banned))
72425+ return -EPERM;
72426+#endif
72427+ return 0;
72428+}
72429+
72430+int gr_process_kernel_setuid_ban(struct user_struct *user)
72431+{
72432+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72433+ if (unlikely(user->kernel_banned))
72434+ gr_fake_force_sig(SIGKILL, current);
72435+#endif
72436+ return 0;
72437+}
72438+
72439+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
72440+{
72441+#ifdef CONFIG_GRKERNSEC_BRUTE
72442+ struct user_struct *user = current->cred->user;
72443+ if (unlikely(user->suid_banned)) {
72444+ if (suid_ban_expired(user))
72445+ return 0;
72446+ /* disallow execution of suid binaries only */
72447+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
72448+ return -EPERM;
72449+ }
72450+#endif
72451+ return 0;
72452+}
72453diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
72454new file mode 100644
72455index 0000000..4030d57
72456--- /dev/null
72457+++ b/grsecurity/grsec_sock.c
72458@@ -0,0 +1,244 @@
72459+#include <linux/kernel.h>
72460+#include <linux/module.h>
72461+#include <linux/sched.h>
72462+#include <linux/file.h>
72463+#include <linux/net.h>
72464+#include <linux/in.h>
72465+#include <linux/ip.h>
72466+#include <net/sock.h>
72467+#include <net/inet_sock.h>
72468+#include <linux/grsecurity.h>
72469+#include <linux/grinternal.h>
72470+#include <linux/gracl.h>
72471+
72472+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
72473+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
72474+
72475+EXPORT_SYMBOL(gr_search_udp_recvmsg);
72476+EXPORT_SYMBOL(gr_search_udp_sendmsg);
72477+
72478+#ifdef CONFIG_UNIX_MODULE
72479+EXPORT_SYMBOL(gr_acl_handle_unix);
72480+EXPORT_SYMBOL(gr_acl_handle_mknod);
72481+EXPORT_SYMBOL(gr_handle_chroot_unix);
72482+EXPORT_SYMBOL(gr_handle_create);
72483+#endif
72484+
72485+#ifdef CONFIG_GRKERNSEC
72486+#define gr_conn_table_size 32749
72487+struct conn_table_entry {
72488+ struct conn_table_entry *next;
72489+ struct signal_struct *sig;
72490+};
72491+
72492+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
72493+DEFINE_SPINLOCK(gr_conn_table_lock);
72494+
72495+extern const char * gr_socktype_to_name(unsigned char type);
72496+extern const char * gr_proto_to_name(unsigned char proto);
72497+extern const char * gr_sockfamily_to_name(unsigned char family);
72498+
72499+static __inline__ int
72500+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
72501+{
72502+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
72503+}
72504+
72505+static __inline__ int
72506+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
72507+ __u16 sport, __u16 dport)
72508+{
72509+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
72510+ sig->gr_sport == sport && sig->gr_dport == dport))
72511+ return 1;
72512+ else
72513+ return 0;
72514+}
72515+
72516+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
72517+{
72518+ struct conn_table_entry **match;
72519+ unsigned int index;
72520+
72521+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
72522+ sig->gr_sport, sig->gr_dport,
72523+ gr_conn_table_size);
72524+
72525+ newent->sig = sig;
72526+
72527+ match = &gr_conn_table[index];
72528+ newent->next = *match;
72529+ *match = newent;
72530+
72531+ return;
72532+}
72533+
72534+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
72535+{
72536+ struct conn_table_entry *match, *last = NULL;
72537+ unsigned int index;
72538+
72539+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
72540+ sig->gr_sport, sig->gr_dport,
72541+ gr_conn_table_size);
72542+
72543+ match = gr_conn_table[index];
72544+ while (match && !conn_match(match->sig,
72545+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
72546+ sig->gr_dport)) {
72547+ last = match;
72548+ match = match->next;
72549+ }
72550+
72551+ if (match) {
72552+ if (last)
72553+ last->next = match->next;
72554+ else
72555+ gr_conn_table[index] = NULL;
72556+ kfree(match);
72557+ }
72558+
72559+ return;
72560+}
72561+
72562+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
72563+ __u16 sport, __u16 dport)
72564+{
72565+ struct conn_table_entry *match;
72566+ unsigned int index;
72567+
72568+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
72569+
72570+ match = gr_conn_table[index];
72571+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
72572+ match = match->next;
72573+
72574+ if (match)
72575+ return match->sig;
72576+ else
72577+ return NULL;
72578+}
72579+
72580+#endif
72581+
72582+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
72583+{
72584+#ifdef CONFIG_GRKERNSEC
72585+ struct signal_struct *sig = task->signal;
72586+ struct conn_table_entry *newent;
72587+
72588+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
72589+ if (newent == NULL)
72590+ return;
72591+ /* no bh lock needed since we are called with bh disabled */
72592+ spin_lock(&gr_conn_table_lock);
72593+ gr_del_task_from_ip_table_nolock(sig);
72594+ sig->gr_saddr = inet->inet_rcv_saddr;
72595+ sig->gr_daddr = inet->inet_daddr;
72596+ sig->gr_sport = inet->inet_sport;
72597+ sig->gr_dport = inet->inet_dport;
72598+ gr_add_to_task_ip_table_nolock(sig, newent);
72599+ spin_unlock(&gr_conn_table_lock);
72600+#endif
72601+ return;
72602+}
72603+
72604+void gr_del_task_from_ip_table(struct task_struct *task)
72605+{
72606+#ifdef CONFIG_GRKERNSEC
72607+ spin_lock_bh(&gr_conn_table_lock);
72608+ gr_del_task_from_ip_table_nolock(task->signal);
72609+ spin_unlock_bh(&gr_conn_table_lock);
72610+#endif
72611+ return;
72612+}
72613+
72614+void
72615+gr_attach_curr_ip(const struct sock *sk)
72616+{
72617+#ifdef CONFIG_GRKERNSEC
72618+ struct signal_struct *p, *set;
72619+ const struct inet_sock *inet = inet_sk(sk);
72620+
72621+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
72622+ return;
72623+
72624+ set = current->signal;
72625+
72626+ spin_lock_bh(&gr_conn_table_lock);
72627+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
72628+ inet->inet_dport, inet->inet_sport);
72629+ if (unlikely(p != NULL)) {
72630+ set->curr_ip = p->curr_ip;
72631+ set->used_accept = 1;
72632+ gr_del_task_from_ip_table_nolock(p);
72633+ spin_unlock_bh(&gr_conn_table_lock);
72634+ return;
72635+ }
72636+ spin_unlock_bh(&gr_conn_table_lock);
72637+
72638+ set->curr_ip = inet->inet_daddr;
72639+ set->used_accept = 1;
72640+#endif
72641+ return;
72642+}
72643+
72644+int
72645+gr_handle_sock_all(const int family, const int type, const int protocol)
72646+{
72647+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72648+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
72649+ (family != AF_UNIX)) {
72650+ if (family == AF_INET)
72651+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
72652+ else
72653+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
72654+ return -EACCES;
72655+ }
72656+#endif
72657+ return 0;
72658+}
72659+
72660+int
72661+gr_handle_sock_server(const struct sockaddr *sck)
72662+{
72663+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72664+ if (grsec_enable_socket_server &&
72665+ in_group_p(grsec_socket_server_gid) &&
72666+ sck && (sck->sa_family != AF_UNIX) &&
72667+ (sck->sa_family != AF_LOCAL)) {
72668+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72669+ return -EACCES;
72670+ }
72671+#endif
72672+ return 0;
72673+}
72674+
72675+int
72676+gr_handle_sock_server_other(const struct sock *sck)
72677+{
72678+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72679+ if (grsec_enable_socket_server &&
72680+ in_group_p(grsec_socket_server_gid) &&
72681+ sck && (sck->sk_family != AF_UNIX) &&
72682+ (sck->sk_family != AF_LOCAL)) {
72683+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72684+ return -EACCES;
72685+ }
72686+#endif
72687+ return 0;
72688+}
72689+
72690+int
72691+gr_handle_sock_client(const struct sockaddr *sck)
72692+{
72693+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72694+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
72695+ sck && (sck->sa_family != AF_UNIX) &&
72696+ (sck->sa_family != AF_LOCAL)) {
72697+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
72698+ return -EACCES;
72699+ }
72700+#endif
72701+ return 0;
72702+}
72703diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
72704new file mode 100644
72705index 0000000..8159888
72706--- /dev/null
72707+++ b/grsecurity/grsec_sysctl.c
72708@@ -0,0 +1,479 @@
72709+#include <linux/kernel.h>
72710+#include <linux/sched.h>
72711+#include <linux/sysctl.h>
72712+#include <linux/grsecurity.h>
72713+#include <linux/grinternal.h>
72714+
72715+int
72716+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
72717+{
72718+#ifdef CONFIG_GRKERNSEC_SYSCTL
72719+ if (dirname == NULL || name == NULL)
72720+ return 0;
72721+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
72722+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
72723+ return -EACCES;
72724+ }
72725+#endif
72726+ return 0;
72727+}
72728+
72729+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
72730+static int __maybe_unused __read_only one = 1;
72731+#endif
72732+
72733+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
72734+ defined(CONFIG_GRKERNSEC_DENYUSB)
72735+struct ctl_table grsecurity_table[] = {
72736+#ifdef CONFIG_GRKERNSEC_SYSCTL
72737+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
72738+#ifdef CONFIG_GRKERNSEC_IO
72739+ {
72740+ .procname = "disable_priv_io",
72741+ .data = &grsec_disable_privio,
72742+ .maxlen = sizeof(int),
72743+ .mode = 0600,
72744+ .proc_handler = &proc_dointvec,
72745+ },
72746+#endif
72747+#endif
72748+#ifdef CONFIG_GRKERNSEC_LINK
72749+ {
72750+ .procname = "linking_restrictions",
72751+ .data = &grsec_enable_link,
72752+ .maxlen = sizeof(int),
72753+ .mode = 0600,
72754+ .proc_handler = &proc_dointvec,
72755+ },
72756+#endif
72757+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
72758+ {
72759+ .procname = "enforce_symlinksifowner",
72760+ .data = &grsec_enable_symlinkown,
72761+ .maxlen = sizeof(int),
72762+ .mode = 0600,
72763+ .proc_handler = &proc_dointvec,
72764+ },
72765+ {
72766+ .procname = "symlinkown_gid",
72767+ .data = &grsec_symlinkown_gid,
72768+ .maxlen = sizeof(int),
72769+ .mode = 0600,
72770+ .proc_handler = &proc_dointvec,
72771+ },
72772+#endif
72773+#ifdef CONFIG_GRKERNSEC_BRUTE
72774+ {
72775+ .procname = "deter_bruteforce",
72776+ .data = &grsec_enable_brute,
72777+ .maxlen = sizeof(int),
72778+ .mode = 0600,
72779+ .proc_handler = &proc_dointvec,
72780+ },
72781+#endif
72782+#ifdef CONFIG_GRKERNSEC_FIFO
72783+ {
72784+ .procname = "fifo_restrictions",
72785+ .data = &grsec_enable_fifo,
72786+ .maxlen = sizeof(int),
72787+ .mode = 0600,
72788+ .proc_handler = &proc_dointvec,
72789+ },
72790+#endif
72791+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72792+ {
72793+ .procname = "ptrace_readexec",
72794+ .data = &grsec_enable_ptrace_readexec,
72795+ .maxlen = sizeof(int),
72796+ .mode = 0600,
72797+ .proc_handler = &proc_dointvec,
72798+ },
72799+#endif
72800+#ifdef CONFIG_GRKERNSEC_SETXID
72801+ {
72802+ .procname = "consistent_setxid",
72803+ .data = &grsec_enable_setxid,
72804+ .maxlen = sizeof(int),
72805+ .mode = 0600,
72806+ .proc_handler = &proc_dointvec,
72807+ },
72808+#endif
72809+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72810+ {
72811+ .procname = "ip_blackhole",
72812+ .data = &grsec_enable_blackhole,
72813+ .maxlen = sizeof(int),
72814+ .mode = 0600,
72815+ .proc_handler = &proc_dointvec,
72816+ },
72817+ {
72818+ .procname = "lastack_retries",
72819+ .data = &grsec_lastack_retries,
72820+ .maxlen = sizeof(int),
72821+ .mode = 0600,
72822+ .proc_handler = &proc_dointvec,
72823+ },
72824+#endif
72825+#ifdef CONFIG_GRKERNSEC_EXECLOG
72826+ {
72827+ .procname = "exec_logging",
72828+ .data = &grsec_enable_execlog,
72829+ .maxlen = sizeof(int),
72830+ .mode = 0600,
72831+ .proc_handler = &proc_dointvec,
72832+ },
72833+#endif
72834+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72835+ {
72836+ .procname = "rwxmap_logging",
72837+ .data = &grsec_enable_log_rwxmaps,
72838+ .maxlen = sizeof(int),
72839+ .mode = 0600,
72840+ .proc_handler = &proc_dointvec,
72841+ },
72842+#endif
72843+#ifdef CONFIG_GRKERNSEC_SIGNAL
72844+ {
72845+ .procname = "signal_logging",
72846+ .data = &grsec_enable_signal,
72847+ .maxlen = sizeof(int),
72848+ .mode = 0600,
72849+ .proc_handler = &proc_dointvec,
72850+ },
72851+#endif
72852+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72853+ {
72854+ .procname = "forkfail_logging",
72855+ .data = &grsec_enable_forkfail,
72856+ .maxlen = sizeof(int),
72857+ .mode = 0600,
72858+ .proc_handler = &proc_dointvec,
72859+ },
72860+#endif
72861+#ifdef CONFIG_GRKERNSEC_TIME
72862+ {
72863+ .procname = "timechange_logging",
72864+ .data = &grsec_enable_time,
72865+ .maxlen = sizeof(int),
72866+ .mode = 0600,
72867+ .proc_handler = &proc_dointvec,
72868+ },
72869+#endif
72870+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72871+ {
72872+ .procname = "chroot_deny_shmat",
72873+ .data = &grsec_enable_chroot_shmat,
72874+ .maxlen = sizeof(int),
72875+ .mode = 0600,
72876+ .proc_handler = &proc_dointvec,
72877+ },
72878+#endif
72879+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72880+ {
72881+ .procname = "chroot_deny_unix",
72882+ .data = &grsec_enable_chroot_unix,
72883+ .maxlen = sizeof(int),
72884+ .mode = 0600,
72885+ .proc_handler = &proc_dointvec,
72886+ },
72887+#endif
72888+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72889+ {
72890+ .procname = "chroot_deny_mount",
72891+ .data = &grsec_enable_chroot_mount,
72892+ .maxlen = sizeof(int),
72893+ .mode = 0600,
72894+ .proc_handler = &proc_dointvec,
72895+ },
72896+#endif
72897+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72898+ {
72899+ .procname = "chroot_deny_fchdir",
72900+ .data = &grsec_enable_chroot_fchdir,
72901+ .maxlen = sizeof(int),
72902+ .mode = 0600,
72903+ .proc_handler = &proc_dointvec,
72904+ },
72905+#endif
72906+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72907+ {
72908+ .procname = "chroot_deny_chroot",
72909+ .data = &grsec_enable_chroot_double,
72910+ .maxlen = sizeof(int),
72911+ .mode = 0600,
72912+ .proc_handler = &proc_dointvec,
72913+ },
72914+#endif
72915+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72916+ {
72917+ .procname = "chroot_deny_pivot",
72918+ .data = &grsec_enable_chroot_pivot,
72919+ .maxlen = sizeof(int),
72920+ .mode = 0600,
72921+ .proc_handler = &proc_dointvec,
72922+ },
72923+#endif
72924+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72925+ {
72926+ .procname = "chroot_enforce_chdir",
72927+ .data = &grsec_enable_chroot_chdir,
72928+ .maxlen = sizeof(int),
72929+ .mode = 0600,
72930+ .proc_handler = &proc_dointvec,
72931+ },
72932+#endif
72933+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72934+ {
72935+ .procname = "chroot_deny_chmod",
72936+ .data = &grsec_enable_chroot_chmod,
72937+ .maxlen = sizeof(int),
72938+ .mode = 0600,
72939+ .proc_handler = &proc_dointvec,
72940+ },
72941+#endif
72942+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72943+ {
72944+ .procname = "chroot_deny_mknod",
72945+ .data = &grsec_enable_chroot_mknod,
72946+ .maxlen = sizeof(int),
72947+ .mode = 0600,
72948+ .proc_handler = &proc_dointvec,
72949+ },
72950+#endif
72951+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72952+ {
72953+ .procname = "chroot_restrict_nice",
72954+ .data = &grsec_enable_chroot_nice,
72955+ .maxlen = sizeof(int),
72956+ .mode = 0600,
72957+ .proc_handler = &proc_dointvec,
72958+ },
72959+#endif
72960+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72961+ {
72962+ .procname = "chroot_execlog",
72963+ .data = &grsec_enable_chroot_execlog,
72964+ .maxlen = sizeof(int),
72965+ .mode = 0600,
72966+ .proc_handler = &proc_dointvec,
72967+ },
72968+#endif
72969+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72970+ {
72971+ .procname = "chroot_caps",
72972+ .data = &grsec_enable_chroot_caps,
72973+ .maxlen = sizeof(int),
72974+ .mode = 0600,
72975+ .proc_handler = &proc_dointvec,
72976+ },
72977+#endif
72978+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72979+ {
72980+ .procname = "chroot_deny_sysctl",
72981+ .data = &grsec_enable_chroot_sysctl,
72982+ .maxlen = sizeof(int),
72983+ .mode = 0600,
72984+ .proc_handler = &proc_dointvec,
72985+ },
72986+#endif
72987+#ifdef CONFIG_GRKERNSEC_TPE
72988+ {
72989+ .procname = "tpe",
72990+ .data = &grsec_enable_tpe,
72991+ .maxlen = sizeof(int),
72992+ .mode = 0600,
72993+ .proc_handler = &proc_dointvec,
72994+ },
72995+ {
72996+ .procname = "tpe_gid",
72997+ .data = &grsec_tpe_gid,
72998+ .maxlen = sizeof(int),
72999+ .mode = 0600,
73000+ .proc_handler = &proc_dointvec,
73001+ },
73002+#endif
73003+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73004+ {
73005+ .procname = "tpe_invert",
73006+ .data = &grsec_enable_tpe_invert,
73007+ .maxlen = sizeof(int),
73008+ .mode = 0600,
73009+ .proc_handler = &proc_dointvec,
73010+ },
73011+#endif
73012+#ifdef CONFIG_GRKERNSEC_TPE_ALL
73013+ {
73014+ .procname = "tpe_restrict_all",
73015+ .data = &grsec_enable_tpe_all,
73016+ .maxlen = sizeof(int),
73017+ .mode = 0600,
73018+ .proc_handler = &proc_dointvec,
73019+ },
73020+#endif
73021+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73022+ {
73023+ .procname = "socket_all",
73024+ .data = &grsec_enable_socket_all,
73025+ .maxlen = sizeof(int),
73026+ .mode = 0600,
73027+ .proc_handler = &proc_dointvec,
73028+ },
73029+ {
73030+ .procname = "socket_all_gid",
73031+ .data = &grsec_socket_all_gid,
73032+ .maxlen = sizeof(int),
73033+ .mode = 0600,
73034+ .proc_handler = &proc_dointvec,
73035+ },
73036+#endif
73037+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73038+ {
73039+ .procname = "socket_client",
73040+ .data = &grsec_enable_socket_client,
73041+ .maxlen = sizeof(int),
73042+ .mode = 0600,
73043+ .proc_handler = &proc_dointvec,
73044+ },
73045+ {
73046+ .procname = "socket_client_gid",
73047+ .data = &grsec_socket_client_gid,
73048+ .maxlen = sizeof(int),
73049+ .mode = 0600,
73050+ .proc_handler = &proc_dointvec,
73051+ },
73052+#endif
73053+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73054+ {
73055+ .procname = "socket_server",
73056+ .data = &grsec_enable_socket_server,
73057+ .maxlen = sizeof(int),
73058+ .mode = 0600,
73059+ .proc_handler = &proc_dointvec,
73060+ },
73061+ {
73062+ .procname = "socket_server_gid",
73063+ .data = &grsec_socket_server_gid,
73064+ .maxlen = sizeof(int),
73065+ .mode = 0600,
73066+ .proc_handler = &proc_dointvec,
73067+ },
73068+#endif
73069+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73070+ {
73071+ .procname = "audit_group",
73072+ .data = &grsec_enable_group,
73073+ .maxlen = sizeof(int),
73074+ .mode = 0600,
73075+ .proc_handler = &proc_dointvec,
73076+ },
73077+ {
73078+ .procname = "audit_gid",
73079+ .data = &grsec_audit_gid,
73080+ .maxlen = sizeof(int),
73081+ .mode = 0600,
73082+ .proc_handler = &proc_dointvec,
73083+ },
73084+#endif
73085+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73086+ {
73087+ .procname = "audit_chdir",
73088+ .data = &grsec_enable_chdir,
73089+ .maxlen = sizeof(int),
73090+ .mode = 0600,
73091+ .proc_handler = &proc_dointvec,
73092+ },
73093+#endif
73094+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73095+ {
73096+ .procname = "audit_mount",
73097+ .data = &grsec_enable_mount,
73098+ .maxlen = sizeof(int),
73099+ .mode = 0600,
73100+ .proc_handler = &proc_dointvec,
73101+ },
73102+#endif
73103+#ifdef CONFIG_GRKERNSEC_DMESG
73104+ {
73105+ .procname = "dmesg",
73106+ .data = &grsec_enable_dmesg,
73107+ .maxlen = sizeof(int),
73108+ .mode = 0600,
73109+ .proc_handler = &proc_dointvec,
73110+ },
73111+#endif
73112+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73113+ {
73114+ .procname = "chroot_findtask",
73115+ .data = &grsec_enable_chroot_findtask,
73116+ .maxlen = sizeof(int),
73117+ .mode = 0600,
73118+ .proc_handler = &proc_dointvec,
73119+ },
73120+#endif
73121+#ifdef CONFIG_GRKERNSEC_RESLOG
73122+ {
73123+ .procname = "resource_logging",
73124+ .data = &grsec_resource_logging,
73125+ .maxlen = sizeof(int),
73126+ .mode = 0600,
73127+ .proc_handler = &proc_dointvec,
73128+ },
73129+#endif
73130+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73131+ {
73132+ .procname = "audit_ptrace",
73133+ .data = &grsec_enable_audit_ptrace,
73134+ .maxlen = sizeof(int),
73135+ .mode = 0600,
73136+ .proc_handler = &proc_dointvec,
73137+ },
73138+#endif
73139+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73140+ {
73141+ .procname = "harden_ptrace",
73142+ .data = &grsec_enable_harden_ptrace,
73143+ .maxlen = sizeof(int),
73144+ .mode = 0600,
73145+ .proc_handler = &proc_dointvec,
73146+ },
73147+#endif
73148+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73149+ {
73150+ .procname = "harden_ipc",
73151+ .data = &grsec_enable_harden_ipc,
73152+ .maxlen = sizeof(int),
73153+ .mode = 0600,
73154+ .proc_handler = &proc_dointvec,
73155+ },
73156+#endif
73157+ {
73158+ .procname = "grsec_lock",
73159+ .data = &grsec_lock,
73160+ .maxlen = sizeof(int),
73161+ .mode = 0600,
73162+ .proc_handler = &proc_dointvec,
73163+ },
73164+#endif
73165+#ifdef CONFIG_GRKERNSEC_ROFS
73166+ {
73167+ .procname = "romount_protect",
73168+ .data = &grsec_enable_rofs,
73169+ .maxlen = sizeof(int),
73170+ .mode = 0600,
73171+ .proc_handler = &proc_dointvec_minmax,
73172+ .extra1 = &one,
73173+ .extra2 = &one,
73174+ },
73175+#endif
73176+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
73177+ {
73178+ .procname = "deny_new_usb",
73179+ .data = &grsec_deny_new_usb,
73180+ .maxlen = sizeof(int),
73181+ .mode = 0600,
73182+ .proc_handler = &proc_dointvec,
73183+ },
73184+#endif
73185+ { }
73186+};
73187+#endif
73188diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
73189new file mode 100644
73190index 0000000..0dc13c3
73191--- /dev/null
73192+++ b/grsecurity/grsec_time.c
73193@@ -0,0 +1,16 @@
73194+#include <linux/kernel.h>
73195+#include <linux/sched.h>
73196+#include <linux/grinternal.h>
73197+#include <linux/module.h>
73198+
73199+void
73200+gr_log_timechange(void)
73201+{
73202+#ifdef CONFIG_GRKERNSEC_TIME
73203+ if (grsec_enable_time)
73204+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
73205+#endif
73206+ return;
73207+}
73208+
73209+EXPORT_SYMBOL(gr_log_timechange);
73210diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
73211new file mode 100644
73212index 0000000..ee57dcf
73213--- /dev/null
73214+++ b/grsecurity/grsec_tpe.c
73215@@ -0,0 +1,73 @@
73216+#include <linux/kernel.h>
73217+#include <linux/sched.h>
73218+#include <linux/file.h>
73219+#include <linux/fs.h>
73220+#include <linux/grinternal.h>
73221+
73222+extern int gr_acl_tpe_check(void);
73223+
73224+int
73225+gr_tpe_allow(const struct file *file)
73226+{
73227+#ifdef CONFIG_GRKERNSEC
73228+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
73229+ const struct cred *cred = current_cred();
73230+ char *msg = NULL;
73231+ char *msg2 = NULL;
73232+
73233+ // never restrict root
73234+ if (gr_is_global_root(cred->uid))
73235+ return 1;
73236+
73237+ if (grsec_enable_tpe) {
73238+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73239+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
73240+ msg = "not being in trusted group";
73241+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
73242+ msg = "being in untrusted group";
73243+#else
73244+ if (in_group_p(grsec_tpe_gid))
73245+ msg = "being in untrusted group";
73246+#endif
73247+ }
73248+ if (!msg && gr_acl_tpe_check())
73249+ msg = "being in untrusted role";
73250+
73251+ // not in any affected group/role
73252+ if (!msg)
73253+ goto next_check;
73254+
73255+ if (gr_is_global_nonroot(inode->i_uid))
73256+ msg2 = "file in non-root-owned directory";
73257+ else if (inode->i_mode & S_IWOTH)
73258+ msg2 = "file in world-writable directory";
73259+ else if (inode->i_mode & S_IWGRP)
73260+ msg2 = "file in group-writable directory";
73261+
73262+ if (msg && msg2) {
73263+ char fullmsg[70] = {0};
73264+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
73265+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
73266+ return 0;
73267+ }
73268+ msg = NULL;
73269+next_check:
73270+#ifdef CONFIG_GRKERNSEC_TPE_ALL
73271+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
73272+ return 1;
73273+
73274+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
73275+ msg = "directory not owned by user";
73276+ else if (inode->i_mode & S_IWOTH)
73277+ msg = "file in world-writable directory";
73278+ else if (inode->i_mode & S_IWGRP)
73279+ msg = "file in group-writable directory";
73280+
73281+ if (msg) {
73282+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
73283+ return 0;
73284+ }
73285+#endif
73286+#endif
73287+ return 1;
73288+}
73289diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
73290new file mode 100644
73291index 0000000..ae02d8e
73292--- /dev/null
73293+++ b/grsecurity/grsec_usb.c
73294@@ -0,0 +1,15 @@
73295+#include <linux/kernel.h>
73296+#include <linux/grinternal.h>
73297+#include <linux/module.h>
73298+
73299+int gr_handle_new_usb(void)
73300+{
73301+#ifdef CONFIG_GRKERNSEC_DENYUSB
73302+ if (grsec_deny_new_usb) {
73303+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
73304+ return 1;
73305+ }
73306+#endif
73307+ return 0;
73308+}
73309+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
73310diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
73311new file mode 100644
73312index 0000000..9f7b1ac
73313--- /dev/null
73314+++ b/grsecurity/grsum.c
73315@@ -0,0 +1,61 @@
73316+#include <linux/err.h>
73317+#include <linux/kernel.h>
73318+#include <linux/sched.h>
73319+#include <linux/mm.h>
73320+#include <linux/scatterlist.h>
73321+#include <linux/crypto.h>
73322+#include <linux/gracl.h>
73323+
73324+
73325+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
73326+#error "crypto and sha256 must be built into the kernel"
73327+#endif
73328+
73329+int
73330+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
73331+{
73332+ char *p;
73333+ struct crypto_hash *tfm;
73334+ struct hash_desc desc;
73335+ struct scatterlist sg;
73336+ unsigned char temp_sum[GR_SHA_LEN];
73337+ volatile int retval = 0;
73338+ volatile int dummy = 0;
73339+ unsigned int i;
73340+
73341+ sg_init_table(&sg, 1);
73342+
73343+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
73344+ if (IS_ERR(tfm)) {
73345+ /* should never happen, since sha256 should be built in */
73346+ return 1;
73347+ }
73348+
73349+ desc.tfm = tfm;
73350+ desc.flags = 0;
73351+
73352+ crypto_hash_init(&desc);
73353+
73354+ p = salt;
73355+ sg_set_buf(&sg, p, GR_SALT_LEN);
73356+ crypto_hash_update(&desc, &sg, sg.length);
73357+
73358+ p = entry->pw;
73359+ sg_set_buf(&sg, p, strlen(p));
73360+
73361+ crypto_hash_update(&desc, &sg, sg.length);
73362+
73363+ crypto_hash_final(&desc, temp_sum);
73364+
73365+ memset(entry->pw, 0, GR_PW_LEN);
73366+
73367+ for (i = 0; i < GR_SHA_LEN; i++)
73368+ if (sum[i] != temp_sum[i])
73369+ retval = 1;
73370+ else
73371+ dummy = 1; // waste a cycle
73372+
73373+ crypto_free_hash(tfm);
73374+
73375+ return retval;
73376+}
73377diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
73378index 77ff547..181834f 100644
73379--- a/include/asm-generic/4level-fixup.h
73380+++ b/include/asm-generic/4level-fixup.h
73381@@ -13,8 +13,10 @@
73382 #define pmd_alloc(mm, pud, address) \
73383 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
73384 NULL: pmd_offset(pud, address))
73385+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
73386
73387 #define pud_alloc(mm, pgd, address) (pgd)
73388+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
73389 #define pud_offset(pgd, start) (pgd)
73390 #define pud_none(pud) 0
73391 #define pud_bad(pud) 0
73392diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
73393index b7babf0..97f4c4f 100644
73394--- a/include/asm-generic/atomic-long.h
73395+++ b/include/asm-generic/atomic-long.h
73396@@ -22,6 +22,12 @@
73397
73398 typedef atomic64_t atomic_long_t;
73399
73400+#ifdef CONFIG_PAX_REFCOUNT
73401+typedef atomic64_unchecked_t atomic_long_unchecked_t;
73402+#else
73403+typedef atomic64_t atomic_long_unchecked_t;
73404+#endif
73405+
73406 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
73407
73408 static inline long atomic_long_read(atomic_long_t *l)
73409@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
73410 return (long)atomic64_read(v);
73411 }
73412
73413+#ifdef CONFIG_PAX_REFCOUNT
73414+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
73415+{
73416+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73417+
73418+ return (long)atomic64_read_unchecked(v);
73419+}
73420+#endif
73421+
73422 static inline void atomic_long_set(atomic_long_t *l, long i)
73423 {
73424 atomic64_t *v = (atomic64_t *)l;
73425@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
73426 atomic64_set(v, i);
73427 }
73428
73429+#ifdef CONFIG_PAX_REFCOUNT
73430+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
73431+{
73432+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73433+
73434+ atomic64_set_unchecked(v, i);
73435+}
73436+#endif
73437+
73438 static inline void atomic_long_inc(atomic_long_t *l)
73439 {
73440 atomic64_t *v = (atomic64_t *)l;
73441@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
73442 atomic64_inc(v);
73443 }
73444
73445+#ifdef CONFIG_PAX_REFCOUNT
73446+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
73447+{
73448+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73449+
73450+ atomic64_inc_unchecked(v);
73451+}
73452+#endif
73453+
73454 static inline void atomic_long_dec(atomic_long_t *l)
73455 {
73456 atomic64_t *v = (atomic64_t *)l;
73457@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
73458 atomic64_dec(v);
73459 }
73460
73461+#ifdef CONFIG_PAX_REFCOUNT
73462+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
73463+{
73464+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73465+
73466+ atomic64_dec_unchecked(v);
73467+}
73468+#endif
73469+
73470 static inline void atomic_long_add(long i, atomic_long_t *l)
73471 {
73472 atomic64_t *v = (atomic64_t *)l;
73473@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
73474 atomic64_add(i, v);
73475 }
73476
73477+#ifdef CONFIG_PAX_REFCOUNT
73478+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
73479+{
73480+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73481+
73482+ atomic64_add_unchecked(i, v);
73483+}
73484+#endif
73485+
73486 static inline void atomic_long_sub(long i, atomic_long_t *l)
73487 {
73488 atomic64_t *v = (atomic64_t *)l;
73489@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
73490 atomic64_sub(i, v);
73491 }
73492
73493+#ifdef CONFIG_PAX_REFCOUNT
73494+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
73495+{
73496+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73497+
73498+ atomic64_sub_unchecked(i, v);
73499+}
73500+#endif
73501+
73502 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
73503 {
73504 atomic64_t *v = (atomic64_t *)l;
73505@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
73506 return atomic64_add_negative(i, v);
73507 }
73508
73509-static inline long atomic_long_add_return(long i, atomic_long_t *l)
73510+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
73511 {
73512 atomic64_t *v = (atomic64_t *)l;
73513
73514 return (long)atomic64_add_return(i, v);
73515 }
73516
73517+#ifdef CONFIG_PAX_REFCOUNT
73518+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
73519+{
73520+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73521+
73522+ return (long)atomic64_add_return_unchecked(i, v);
73523+}
73524+#endif
73525+
73526 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
73527 {
73528 atomic64_t *v = (atomic64_t *)l;
73529@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
73530 return (long)atomic64_inc_return(v);
73531 }
73532
73533+#ifdef CONFIG_PAX_REFCOUNT
73534+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
73535+{
73536+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73537+
73538+ return (long)atomic64_inc_return_unchecked(v);
73539+}
73540+#endif
73541+
73542 static inline long atomic_long_dec_return(atomic_long_t *l)
73543 {
73544 atomic64_t *v = (atomic64_t *)l;
73545@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
73546
73547 typedef atomic_t atomic_long_t;
73548
73549+#ifdef CONFIG_PAX_REFCOUNT
73550+typedef atomic_unchecked_t atomic_long_unchecked_t;
73551+#else
73552+typedef atomic_t atomic_long_unchecked_t;
73553+#endif
73554+
73555 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
73556 static inline long atomic_long_read(atomic_long_t *l)
73557 {
73558@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
73559 return (long)atomic_read(v);
73560 }
73561
73562+#ifdef CONFIG_PAX_REFCOUNT
73563+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
73564+{
73565+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73566+
73567+ return (long)atomic_read_unchecked(v);
73568+}
73569+#endif
73570+
73571 static inline void atomic_long_set(atomic_long_t *l, long i)
73572 {
73573 atomic_t *v = (atomic_t *)l;
73574@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
73575 atomic_set(v, i);
73576 }
73577
73578+#ifdef CONFIG_PAX_REFCOUNT
73579+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
73580+{
73581+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73582+
73583+ atomic_set_unchecked(v, i);
73584+}
73585+#endif
73586+
73587 static inline void atomic_long_inc(atomic_long_t *l)
73588 {
73589 atomic_t *v = (atomic_t *)l;
73590@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
73591 atomic_inc(v);
73592 }
73593
73594+#ifdef CONFIG_PAX_REFCOUNT
73595+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
73596+{
73597+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73598+
73599+ atomic_inc_unchecked(v);
73600+}
73601+#endif
73602+
73603 static inline void atomic_long_dec(atomic_long_t *l)
73604 {
73605 atomic_t *v = (atomic_t *)l;
73606@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
73607 atomic_dec(v);
73608 }
73609
73610+#ifdef CONFIG_PAX_REFCOUNT
73611+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
73612+{
73613+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73614+
73615+ atomic_dec_unchecked(v);
73616+}
73617+#endif
73618+
73619 static inline void atomic_long_add(long i, atomic_long_t *l)
73620 {
73621 atomic_t *v = (atomic_t *)l;
73622@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
73623 atomic_add(i, v);
73624 }
73625
73626+#ifdef CONFIG_PAX_REFCOUNT
73627+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
73628+{
73629+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73630+
73631+ atomic_add_unchecked(i, v);
73632+}
73633+#endif
73634+
73635 static inline void atomic_long_sub(long i, atomic_long_t *l)
73636 {
73637 atomic_t *v = (atomic_t *)l;
73638@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
73639 atomic_sub(i, v);
73640 }
73641
73642+#ifdef CONFIG_PAX_REFCOUNT
73643+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
73644+{
73645+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73646+
73647+ atomic_sub_unchecked(i, v);
73648+}
73649+#endif
73650+
73651 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
73652 {
73653 atomic_t *v = (atomic_t *)l;
73654@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
73655 return (long)atomic_add_return(i, v);
73656 }
73657
73658+#ifdef CONFIG_PAX_REFCOUNT
73659+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
73660+{
73661+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73662+
73663+ return (long)atomic_add_return_unchecked(i, v);
73664+}
73665+
73666+#endif
73667+
73668 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
73669 {
73670 atomic_t *v = (atomic_t *)l;
73671@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
73672 return (long)atomic_inc_return(v);
73673 }
73674
73675+#ifdef CONFIG_PAX_REFCOUNT
73676+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
73677+{
73678+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73679+
73680+ return (long)atomic_inc_return_unchecked(v);
73681+}
73682+#endif
73683+
73684 static inline long atomic_long_dec_return(atomic_long_t *l)
73685 {
73686 atomic_t *v = (atomic_t *)l;
73687@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
73688
73689 #endif /* BITS_PER_LONG == 64 */
73690
73691+#ifdef CONFIG_PAX_REFCOUNT
73692+static inline void pax_refcount_needs_these_functions(void)
73693+{
73694+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
73695+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
73696+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
73697+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
73698+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
73699+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
73700+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
73701+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
73702+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
73703+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
73704+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
73705+#ifdef CONFIG_X86
73706+ atomic_clear_mask_unchecked(0, NULL);
73707+ atomic_set_mask_unchecked(0, NULL);
73708+#endif
73709+
73710+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
73711+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
73712+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
73713+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
73714+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
73715+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
73716+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
73717+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
73718+}
73719+#else
73720+#define atomic_read_unchecked(v) atomic_read(v)
73721+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
73722+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
73723+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
73724+#define atomic_inc_unchecked(v) atomic_inc(v)
73725+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
73726+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
73727+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
73728+#define atomic_dec_unchecked(v) atomic_dec(v)
73729+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
73730+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
73731+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
73732+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
73733+
73734+#define atomic_long_read_unchecked(v) atomic_long_read(v)
73735+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
73736+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
73737+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
73738+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
73739+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
73740+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
73741+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
73742+#endif
73743+
73744 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
73745diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
73746index 33bd2de..f31bff97 100644
73747--- a/include/asm-generic/atomic.h
73748+++ b/include/asm-generic/atomic.h
73749@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
73750 * Atomically clears the bits set in @mask from @v
73751 */
73752 #ifndef atomic_clear_mask
73753-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
73754+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
73755 {
73756 unsigned long flags;
73757
73758diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
73759index b18ce4f..2ee2843 100644
73760--- a/include/asm-generic/atomic64.h
73761+++ b/include/asm-generic/atomic64.h
73762@@ -16,6 +16,8 @@ typedef struct {
73763 long long counter;
73764 } atomic64_t;
73765
73766+typedef atomic64_t atomic64_unchecked_t;
73767+
73768 #define ATOMIC64_INIT(i) { (i) }
73769
73770 extern long long atomic64_read(const atomic64_t *v);
73771@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
73772 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
73773 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
73774
73775+#define atomic64_read_unchecked(v) atomic64_read(v)
73776+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
73777+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
73778+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
73779+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
73780+#define atomic64_inc_unchecked(v) atomic64_inc(v)
73781+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
73782+#define atomic64_dec_unchecked(v) atomic64_dec(v)
73783+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
73784+
73785 #endif /* _ASM_GENERIC_ATOMIC64_H */
73786diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
73787index a60a7cc..0fe12f2 100644
73788--- a/include/asm-generic/bitops/__fls.h
73789+++ b/include/asm-generic/bitops/__fls.h
73790@@ -9,7 +9,7 @@
73791 *
73792 * Undefined if no set bit exists, so code should check against 0 first.
73793 */
73794-static __always_inline unsigned long __fls(unsigned long word)
73795+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
73796 {
73797 int num = BITS_PER_LONG - 1;
73798
73799diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
73800index 0576d1f..dad6c71 100644
73801--- a/include/asm-generic/bitops/fls.h
73802+++ b/include/asm-generic/bitops/fls.h
73803@@ -9,7 +9,7 @@
73804 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
73805 */
73806
73807-static __always_inline int fls(int x)
73808+static __always_inline int __intentional_overflow(-1) fls(int x)
73809 {
73810 int r = 32;
73811
73812diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
73813index b097cf8..3d40e14 100644
73814--- a/include/asm-generic/bitops/fls64.h
73815+++ b/include/asm-generic/bitops/fls64.h
73816@@ -15,7 +15,7 @@
73817 * at position 64.
73818 */
73819 #if BITS_PER_LONG == 32
73820-static __always_inline int fls64(__u64 x)
73821+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
73822 {
73823 __u32 h = x >> 32;
73824 if (h)
73825@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
73826 return fls(x);
73827 }
73828 #elif BITS_PER_LONG == 64
73829-static __always_inline int fls64(__u64 x)
73830+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
73831 {
73832 if (x == 0)
73833 return 0;
73834diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
73835index 1bfcfe5..e04c5c9 100644
73836--- a/include/asm-generic/cache.h
73837+++ b/include/asm-generic/cache.h
73838@@ -6,7 +6,7 @@
73839 * cache lines need to provide their own cache.h.
73840 */
73841
73842-#define L1_CACHE_SHIFT 5
73843-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
73844+#define L1_CACHE_SHIFT 5UL
73845+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
73846
73847 #endif /* __ASM_GENERIC_CACHE_H */
73848diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
73849index 0d68a1e..b74a761 100644
73850--- a/include/asm-generic/emergency-restart.h
73851+++ b/include/asm-generic/emergency-restart.h
73852@@ -1,7 +1,7 @@
73853 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
73854 #define _ASM_GENERIC_EMERGENCY_RESTART_H
73855
73856-static inline void machine_emergency_restart(void)
73857+static inline __noreturn void machine_emergency_restart(void)
73858 {
73859 machine_restart(NULL);
73860 }
73861diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
73862index 90f99c7..00ce236 100644
73863--- a/include/asm-generic/kmap_types.h
73864+++ b/include/asm-generic/kmap_types.h
73865@@ -2,9 +2,9 @@
73866 #define _ASM_GENERIC_KMAP_TYPES_H
73867
73868 #ifdef __WITH_KM_FENCE
73869-# define KM_TYPE_NR 41
73870+# define KM_TYPE_NR 42
73871 #else
73872-# define KM_TYPE_NR 20
73873+# define KM_TYPE_NR 21
73874 #endif
73875
73876 #endif
73877diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
73878index 9ceb03b..62b0b8f 100644
73879--- a/include/asm-generic/local.h
73880+++ b/include/asm-generic/local.h
73881@@ -23,24 +23,37 @@ typedef struct
73882 atomic_long_t a;
73883 } local_t;
73884
73885+typedef struct {
73886+ atomic_long_unchecked_t a;
73887+} local_unchecked_t;
73888+
73889 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
73890
73891 #define local_read(l) atomic_long_read(&(l)->a)
73892+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
73893 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
73894+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
73895 #define local_inc(l) atomic_long_inc(&(l)->a)
73896+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
73897 #define local_dec(l) atomic_long_dec(&(l)->a)
73898+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
73899 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
73900+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
73901 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
73902+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
73903
73904 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
73905 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
73906 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
73907 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
73908 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
73909+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
73910 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
73911 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
73912+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
73913
73914 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73915+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73916 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
73917 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
73918 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
73919diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
73920index 725612b..9cc513a 100644
73921--- a/include/asm-generic/pgtable-nopmd.h
73922+++ b/include/asm-generic/pgtable-nopmd.h
73923@@ -1,14 +1,19 @@
73924 #ifndef _PGTABLE_NOPMD_H
73925 #define _PGTABLE_NOPMD_H
73926
73927-#ifndef __ASSEMBLY__
73928-
73929 #include <asm-generic/pgtable-nopud.h>
73930
73931-struct mm_struct;
73932-
73933 #define __PAGETABLE_PMD_FOLDED
73934
73935+#define PMD_SHIFT PUD_SHIFT
73936+#define PTRS_PER_PMD 1
73937+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
73938+#define PMD_MASK (~(PMD_SIZE-1))
73939+
73940+#ifndef __ASSEMBLY__
73941+
73942+struct mm_struct;
73943+
73944 /*
73945 * Having the pmd type consist of a pud gets the size right, and allows
73946 * us to conceptually access the pud entry that this pmd is folded into
73947@@ -16,11 +21,6 @@ struct mm_struct;
73948 */
73949 typedef struct { pud_t pud; } pmd_t;
73950
73951-#define PMD_SHIFT PUD_SHIFT
73952-#define PTRS_PER_PMD 1
73953-#define PMD_SIZE (1UL << PMD_SHIFT)
73954-#define PMD_MASK (~(PMD_SIZE-1))
73955-
73956 /*
73957 * The "pud_xxx()" functions here are trivial for a folded two-level
73958 * setup: the pmd is never bad, and a pmd always exists (as it's folded
73959diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
73960index 810431d..0ec4804f 100644
73961--- a/include/asm-generic/pgtable-nopud.h
73962+++ b/include/asm-generic/pgtable-nopud.h
73963@@ -1,10 +1,15 @@
73964 #ifndef _PGTABLE_NOPUD_H
73965 #define _PGTABLE_NOPUD_H
73966
73967-#ifndef __ASSEMBLY__
73968-
73969 #define __PAGETABLE_PUD_FOLDED
73970
73971+#define PUD_SHIFT PGDIR_SHIFT
73972+#define PTRS_PER_PUD 1
73973+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
73974+#define PUD_MASK (~(PUD_SIZE-1))
73975+
73976+#ifndef __ASSEMBLY__
73977+
73978 /*
73979 * Having the pud type consist of a pgd gets the size right, and allows
73980 * us to conceptually access the pgd entry that this pud is folded into
73981@@ -12,11 +17,6 @@
73982 */
73983 typedef struct { pgd_t pgd; } pud_t;
73984
73985-#define PUD_SHIFT PGDIR_SHIFT
73986-#define PTRS_PER_PUD 1
73987-#define PUD_SIZE (1UL << PUD_SHIFT)
73988-#define PUD_MASK (~(PUD_SIZE-1))
73989-
73990 /*
73991 * The "pgd_xxx()" functions here are trivial for a folded two-level
73992 * setup: the pud is never bad, and a pud always exists (as it's folded
73993@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
73994 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
73995
73996 #define pgd_populate(mm, pgd, pud) do { } while (0)
73997+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
73998 /*
73999 * (puds are folded into pgds so this doesn't get actually called,
74000 * but the define is needed for a generic inline function.)
74001diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
74002index f330d28..d93bba9 100644
74003--- a/include/asm-generic/pgtable.h
74004+++ b/include/asm-generic/pgtable.h
74005@@ -599,11 +599,10 @@ static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
74006 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
74007 barrier();
74008 #endif
74009- if (pmd_none(pmdval))
74010+ if (pmd_none(pmdval) || pmd_trans_huge(pmdval))
74011 return 1;
74012 if (unlikely(pmd_bad(pmdval))) {
74013- if (!pmd_trans_huge(pmdval))
74014- pmd_clear_bad(pmd);
74015+ pmd_clear_bad(pmd);
74016 return 1;
74017 }
74018 return 0;
74019@@ -737,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
74020 }
74021 #endif /* CONFIG_NUMA_BALANCING */
74022
74023+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
74024+#ifdef CONFIG_PAX_KERNEXEC
74025+#error KERNEXEC requires pax_open_kernel
74026+#else
74027+static inline unsigned long pax_open_kernel(void) { return 0; }
74028+#endif
74029+#endif
74030+
74031+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
74032+#ifdef CONFIG_PAX_KERNEXEC
74033+#error KERNEXEC requires pax_close_kernel
74034+#else
74035+static inline unsigned long pax_close_kernel(void) { return 0; }
74036+#endif
74037+#endif
74038+
74039 #endif /* CONFIG_MMU */
74040
74041 #endif /* !__ASSEMBLY__ */
74042diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
74043index dc1269c..48a4f51 100644
74044--- a/include/asm-generic/uaccess.h
74045+++ b/include/asm-generic/uaccess.h
74046@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
74047 return __clear_user(to, n);
74048 }
74049
74050+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
74051+#ifdef CONFIG_PAX_MEMORY_UDEREF
74052+#error UDEREF requires pax_open_userland
74053+#else
74054+static inline unsigned long pax_open_userland(void) { return 0; }
74055+#endif
74056+#endif
74057+
74058+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
74059+#ifdef CONFIG_PAX_MEMORY_UDEREF
74060+#error UDEREF requires pax_close_userland
74061+#else
74062+static inline unsigned long pax_close_userland(void) { return 0; }
74063+#endif
74064+#endif
74065+
74066 #endif /* __ASM_GENERIC_UACCESS_H */
74067diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
74068index 83e2c31..eeb4a04 100644
74069--- a/include/asm-generic/vmlinux.lds.h
74070+++ b/include/asm-generic/vmlinux.lds.h
74071@@ -232,6 +232,7 @@
74072 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
74073 VMLINUX_SYMBOL(__start_rodata) = .; \
74074 *(.rodata) *(.rodata.*) \
74075+ *(.data..read_only) \
74076 *(__vermagic) /* Kernel version magic */ \
74077 . = ALIGN(8); \
74078 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
74079@@ -715,17 +716,18 @@
74080 * section in the linker script will go there too. @phdr should have
74081 * a leading colon.
74082 *
74083- * Note that this macros defines __per_cpu_load as an absolute symbol.
74084+ * Note that this macros defines per_cpu_load as an absolute symbol.
74085 * If there is no need to put the percpu section at a predetermined
74086 * address, use PERCPU_SECTION.
74087 */
74088 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
74089- VMLINUX_SYMBOL(__per_cpu_load) = .; \
74090- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
74091+ per_cpu_load = .; \
74092+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
74093 - LOAD_OFFSET) { \
74094+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
74095 PERCPU_INPUT(cacheline) \
74096 } phdr \
74097- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
74098+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
74099
74100 /**
74101 * PERCPU_SECTION - define output section for percpu area, simple version
74102diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
74103index 418d270..bfd2794 100644
74104--- a/include/crypto/algapi.h
74105+++ b/include/crypto/algapi.h
74106@@ -34,7 +34,7 @@ struct crypto_type {
74107 unsigned int maskclear;
74108 unsigned int maskset;
74109 unsigned int tfmsize;
74110-};
74111+} __do_const;
74112
74113 struct crypto_instance {
74114 struct crypto_alg alg;
74115diff --git a/include/drm/drmP.h b/include/drm/drmP.h
74116index b46fb45..b30d6d5 100644
74117--- a/include/drm/drmP.h
74118+++ b/include/drm/drmP.h
74119@@ -66,6 +66,7 @@
74120 #include <linux/workqueue.h>
74121 #include <linux/poll.h>
74122 #include <asm/pgalloc.h>
74123+#include <asm/local.h>
74124 #include <drm/drm.h>
74125 #include <drm/drm_sarea.h>
74126 #include <drm/drm_vma_manager.h>
74127@@ -277,10 +278,12 @@ do { \
74128 * \param cmd command.
74129 * \param arg argument.
74130 */
74131-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
74132+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
74133+ struct drm_file *file_priv);
74134+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
74135 struct drm_file *file_priv);
74136
74137-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
74138+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
74139 unsigned long arg);
74140
74141 #define DRM_IOCTL_NR(n) _IOC_NR(n)
74142@@ -296,10 +299,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
74143 struct drm_ioctl_desc {
74144 unsigned int cmd;
74145 int flags;
74146- drm_ioctl_t *func;
74147+ drm_ioctl_t func;
74148 unsigned int cmd_drv;
74149 const char *name;
74150-};
74151+} __do_const;
74152
74153 /**
74154 * Creates a driver or general drm_ioctl_desc array entry for the given
74155@@ -1027,7 +1030,7 @@ struct drm_info_list {
74156 int (*show)(struct seq_file*, void*); /** show callback */
74157 u32 driver_features; /**< Required driver features for this entry */
74158 void *data;
74159-};
74160+} __do_const;
74161
74162 /**
74163 * debugfs node structure. This structure represents a debugfs file.
74164@@ -1098,7 +1101,7 @@ struct drm_device {
74165
74166 /** \name Usage Counters */
74167 /*@{ */
74168- int open_count; /**< Outstanding files open */
74169+ local_t open_count; /**< Outstanding files open */
74170 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
74171 atomic_t vma_count; /**< Outstanding vma areas open */
74172 int buf_use; /**< Buffers in use -- cannot alloc */
74173@@ -1109,7 +1112,7 @@ struct drm_device {
74174 /*@{ */
74175 unsigned long counters;
74176 enum drm_stat_type types[15];
74177- atomic_t counts[15];
74178+ atomic_unchecked_t counts[15];
74179 /*@} */
74180
74181 struct list_head filelist;
74182diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
74183index f43d556..94d9343 100644
74184--- a/include/drm/drm_crtc_helper.h
74185+++ b/include/drm/drm_crtc_helper.h
74186@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
74187 struct drm_connector *connector);
74188 /* disable encoder when not in use - more explicit than dpms off */
74189 void (*disable)(struct drm_encoder *encoder);
74190-};
74191+} __no_const;
74192
74193 /**
74194 * drm_connector_helper_funcs - helper operations for connectors
74195diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
74196index 8a10f5c..5de7f5c 100644
74197--- a/include/drm/i915_pciids.h
74198+++ b/include/drm/i915_pciids.h
74199@@ -37,7 +37,7 @@
74200 */
74201 #define INTEL_VGA_DEVICE(id, info) { \
74202 0x8086, id, \
74203- ~0, ~0, \
74204+ PCI_ANY_ID, PCI_ANY_ID, \
74205 0x030000, 0xff0000, \
74206 (unsigned long) info }
74207
74208diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
74209index 72dcbe8..8db58d7 100644
74210--- a/include/drm/ttm/ttm_memory.h
74211+++ b/include/drm/ttm/ttm_memory.h
74212@@ -48,7 +48,7 @@
74213
74214 struct ttm_mem_shrink {
74215 int (*do_shrink) (struct ttm_mem_shrink *);
74216-};
74217+} __no_const;
74218
74219 /**
74220 * struct ttm_mem_global - Global memory accounting structure.
74221diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
74222index 4b840e8..155d235 100644
74223--- a/include/keys/asymmetric-subtype.h
74224+++ b/include/keys/asymmetric-subtype.h
74225@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
74226 /* Verify the signature on a key of this subtype (optional) */
74227 int (*verify_signature)(const struct key *key,
74228 const struct public_key_signature *sig);
74229-};
74230+} __do_const;
74231
74232 /**
74233 * asymmetric_key_subtype - Get the subtype from an asymmetric key
74234diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
74235index c1da539..1dcec55 100644
74236--- a/include/linux/atmdev.h
74237+++ b/include/linux/atmdev.h
74238@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
74239 #endif
74240
74241 struct k_atm_aal_stats {
74242-#define __HANDLE_ITEM(i) atomic_t i
74243+#define __HANDLE_ITEM(i) atomic_unchecked_t i
74244 __AAL_STAT_ITEMS
74245 #undef __HANDLE_ITEM
74246 };
74247@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
74248 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
74249 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
74250 struct module *owner;
74251-};
74252+} __do_const ;
74253
74254 struct atmphy_ops {
74255 int (*start)(struct atm_dev *dev);
74256diff --git a/include/linux/audit.h b/include/linux/audit.h
74257index 729a4d1..9b304ae 100644
74258--- a/include/linux/audit.h
74259+++ b/include/linux/audit.h
74260@@ -193,7 +193,7 @@ static inline void audit_ptrace(struct task_struct *t)
74261 extern unsigned int audit_serial(void);
74262 extern int auditsc_get_stamp(struct audit_context *ctx,
74263 struct timespec *t, unsigned int *serial);
74264-extern int audit_set_loginuid(kuid_t loginuid);
74265+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
74266
74267 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
74268 {
74269diff --git a/include/linux/auxvec.h b/include/linux/auxvec.h
74270index 669fef5..3e0fbe4 100644
74271--- a/include/linux/auxvec.h
74272+++ b/include/linux/auxvec.h
74273@@ -3,6 +3,6 @@
74274
74275 #include <uapi/linux/auxvec.h>
74276
74277-#define AT_VECTOR_SIZE_BASE 19 /* NEW_AUX_ENT entries in auxiliary table */
74278+#define AT_VECTOR_SIZE_BASE 20 /* NEW_AUX_ENT entries in auxiliary table */
74279 /* number of "#define AT_.*" above, minus {AT_NULL, AT_IGNORE, AT_NOTELF} */
74280 #endif /* _LINUX_AUXVEC_H */
74281diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
74282index 7554fd4..0f86379 100644
74283--- a/include/linux/binfmts.h
74284+++ b/include/linux/binfmts.h
74285@@ -73,8 +73,10 @@ struct linux_binfmt {
74286 int (*load_binary)(struct linux_binprm *);
74287 int (*load_shlib)(struct file *);
74288 int (*core_dump)(struct coredump_params *cprm);
74289+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
74290+ void (*handle_mmap)(struct file *);
74291 unsigned long min_coredump; /* minimal dump size */
74292-};
74293+} __do_const;
74294
74295 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
74296
74297diff --git a/include/linux/bitops.h b/include/linux/bitops.h
74298index a3b6b82..2a7d758 100644
74299--- a/include/linux/bitops.h
74300+++ b/include/linux/bitops.h
74301@@ -91,7 +91,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
74302 * @word: value to rotate
74303 * @shift: bits to roll
74304 */
74305-static inline __u32 rol32(__u32 word, unsigned int shift)
74306+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
74307 {
74308 return (word << shift) | (word >> (32 - shift));
74309 }
74310@@ -101,7 +101,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
74311 * @word: value to rotate
74312 * @shift: bits to roll
74313 */
74314-static inline __u32 ror32(__u32 word, unsigned int shift)
74315+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
74316 {
74317 return (word >> shift) | (word << (32 - shift));
74318 }
74319@@ -157,7 +157,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
74320 return (__s32)(value << shift) >> shift;
74321 }
74322
74323-static inline unsigned fls_long(unsigned long l)
74324+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
74325 {
74326 if (sizeof(l) == 4)
74327 return fls(l);
74328diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
74329index 0e6f765..885bb2b 100644
74330--- a/include/linux/blkdev.h
74331+++ b/include/linux/blkdev.h
74332@@ -1537,7 +1537,7 @@ struct block_device_operations {
74333 /* this callback is with swap_lock and sometimes page table lock held */
74334 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
74335 struct module *owner;
74336-};
74337+} __do_const;
74338
74339 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
74340 unsigned long);
74341diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
74342index 7c2e030..b72475d 100644
74343--- a/include/linux/blktrace_api.h
74344+++ b/include/linux/blktrace_api.h
74345@@ -23,7 +23,7 @@ struct blk_trace {
74346 struct dentry *dir;
74347 struct dentry *dropped_file;
74348 struct dentry *msg_file;
74349- atomic_t dropped;
74350+ atomic_unchecked_t dropped;
74351 };
74352
74353 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
74354diff --git a/include/linux/cache.h b/include/linux/cache.h
74355index 4c57065..40346da 100644
74356--- a/include/linux/cache.h
74357+++ b/include/linux/cache.h
74358@@ -16,6 +16,14 @@
74359 #define __read_mostly
74360 #endif
74361
74362+#ifndef __read_only
74363+#ifdef CONFIG_PAX_KERNEXEC
74364+#error KERNEXEC requires __read_only
74365+#else
74366+#define __read_only __read_mostly
74367+#endif
74368+#endif
74369+
74370 #ifndef ____cacheline_aligned
74371 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
74372 #endif
74373diff --git a/include/linux/capability.h b/include/linux/capability.h
74374index a6ee1f9..e1ca49d 100644
74375--- a/include/linux/capability.h
74376+++ b/include/linux/capability.h
74377@@ -212,8 +212,13 @@ extern bool capable(int cap);
74378 extern bool ns_capable(struct user_namespace *ns, int cap);
74379 extern bool inode_capable(const struct inode *inode, int cap);
74380 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
74381+extern bool capable_nolog(int cap);
74382+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
74383+extern bool inode_capable_nolog(const struct inode *inode, int cap);
74384
74385 /* audit system wants to get cap info from files as well */
74386 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
74387
74388+extern int is_privileged_binary(const struct dentry *dentry);
74389+
74390 #endif /* !_LINUX_CAPABILITY_H */
74391diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
74392index 8609d57..86e4d79 100644
74393--- a/include/linux/cdrom.h
74394+++ b/include/linux/cdrom.h
74395@@ -87,7 +87,6 @@ struct cdrom_device_ops {
74396
74397 /* driver specifications */
74398 const int capability; /* capability flags */
74399- int n_minors; /* number of active minor devices */
74400 /* handle uniform packets for scsi type devices (scsi,atapi) */
74401 int (*generic_packet) (struct cdrom_device_info *,
74402 struct packet_command *);
74403diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
74404index 4ce9056..86caac6 100644
74405--- a/include/linux/cleancache.h
74406+++ b/include/linux/cleancache.h
74407@@ -31,7 +31,7 @@ struct cleancache_ops {
74408 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
74409 void (*invalidate_inode)(int, struct cleancache_filekey);
74410 void (*invalidate_fs)(int);
74411-};
74412+} __no_const;
74413
74414 extern struct cleancache_ops *
74415 cleancache_register_ops(struct cleancache_ops *ops);
74416diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
74417index 73bdb69..d66d47a 100644
74418--- a/include/linux/clk-provider.h
74419+++ b/include/linux/clk-provider.h
74420@@ -141,6 +141,7 @@ struct clk_ops {
74421 unsigned long);
74422 void (*init)(struct clk_hw *hw);
74423 };
74424+typedef struct clk_ops __no_const clk_ops_no_const;
74425
74426 /**
74427 * struct clk_init_data - holds init data that's common to all clocks and is
74428diff --git a/include/linux/compat.h b/include/linux/compat.h
74429index 345da00..b6eff26 100644
74430--- a/include/linux/compat.h
74431+++ b/include/linux/compat.h
74432@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
74433 compat_size_t __user *len_ptr);
74434
74435 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
74436-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
74437+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
74438 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
74439 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
74440 compat_ssize_t msgsz, int msgflg);
74441@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
74442 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
74443 compat_ulong_t addr, compat_ulong_t data);
74444 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
74445- compat_long_t addr, compat_long_t data);
74446+ compat_ulong_t addr, compat_ulong_t data);
74447
74448 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
74449 /*
74450diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
74451index ded4299..da50e3b 100644
74452--- a/include/linux/compiler-gcc4.h
74453+++ b/include/linux/compiler-gcc4.h
74454@@ -39,9 +39,29 @@
74455 # define __compiletime_warning(message) __attribute__((warning(message)))
74456 # define __compiletime_error(message) __attribute__((error(message)))
74457 #endif /* __CHECKER__ */
74458+
74459+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
74460+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
74461+#define __bos0(ptr) __bos((ptr), 0)
74462+#define __bos1(ptr) __bos((ptr), 1)
74463 #endif /* GCC_VERSION >= 40300 */
74464
74465 #if GCC_VERSION >= 40500
74466+
74467+#ifdef CONSTIFY_PLUGIN
74468+#define __no_const __attribute__((no_const))
74469+#define __do_const __attribute__((do_const))
74470+#endif
74471+
74472+#ifdef SIZE_OVERFLOW_PLUGIN
74473+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
74474+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
74475+#endif
74476+
74477+#ifdef LATENT_ENTROPY_PLUGIN
74478+#define __latent_entropy __attribute__((latent_entropy))
74479+#endif
74480+
74481 /*
74482 * Mark a position in code as unreachable. This can be used to
74483 * suppress control flow warnings after asm blocks that transfer
74484diff --git a/include/linux/compiler.h b/include/linux/compiler.h
74485index 92669cd..1771a15 100644
74486--- a/include/linux/compiler.h
74487+++ b/include/linux/compiler.h
74488@@ -5,11 +5,14 @@
74489
74490 #ifdef __CHECKER__
74491 # define __user __attribute__((noderef, address_space(1)))
74492+# define __force_user __force __user
74493 # define __kernel __attribute__((address_space(0)))
74494+# define __force_kernel __force __kernel
74495 # define __safe __attribute__((safe))
74496 # define __force __attribute__((force))
74497 # define __nocast __attribute__((nocast))
74498 # define __iomem __attribute__((noderef, address_space(2)))
74499+# define __force_iomem __force __iomem
74500 # define __must_hold(x) __attribute__((context(x,1,1)))
74501 # define __acquires(x) __attribute__((context(x,0,1)))
74502 # define __releases(x) __attribute__((context(x,1,0)))
74503@@ -17,20 +20,37 @@
74504 # define __release(x) __context__(x,-1)
74505 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
74506 # define __percpu __attribute__((noderef, address_space(3)))
74507+# define __force_percpu __force __percpu
74508 #ifdef CONFIG_SPARSE_RCU_POINTER
74509 # define __rcu __attribute__((noderef, address_space(4)))
74510+# define __force_rcu __force __rcu
74511 #else
74512 # define __rcu
74513+# define __force_rcu
74514 #endif
74515 extern void __chk_user_ptr(const volatile void __user *);
74516 extern void __chk_io_ptr(const volatile void __iomem *);
74517 #else
74518-# define __user
74519-# define __kernel
74520+# ifdef CHECKER_PLUGIN
74521+//# define __user
74522+//# define __force_user
74523+//# define __kernel
74524+//# define __force_kernel
74525+# else
74526+# ifdef STRUCTLEAK_PLUGIN
74527+# define __user __attribute__((user))
74528+# else
74529+# define __user
74530+# endif
74531+# define __force_user
74532+# define __kernel
74533+# define __force_kernel
74534+# endif
74535 # define __safe
74536 # define __force
74537 # define __nocast
74538 # define __iomem
74539+# define __force_iomem
74540 # define __chk_user_ptr(x) (void)0
74541 # define __chk_io_ptr(x) (void)0
74542 # define __builtin_warning(x, y...) (1)
74543@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
74544 # define __release(x) (void)0
74545 # define __cond_lock(x,c) (c)
74546 # define __percpu
74547+# define __force_percpu
74548 # define __rcu
74549+# define __force_rcu
74550 #endif
74551
74552 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
74553@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
74554 # define __attribute_const__ /* unimplemented */
74555 #endif
74556
74557+#ifndef __no_const
74558+# define __no_const
74559+#endif
74560+
74561+#ifndef __do_const
74562+# define __do_const
74563+#endif
74564+
74565+#ifndef __size_overflow
74566+# define __size_overflow(...)
74567+#endif
74568+
74569+#ifndef __intentional_overflow
74570+# define __intentional_overflow(...)
74571+#endif
74572+
74573+#ifndef __latent_entropy
74574+# define __latent_entropy
74575+#endif
74576+
74577 /*
74578 * Tell gcc if a function is cold. The compiler will assume any path
74579 * directly leading to the call is unlikely.
74580@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
74581 #define __cold
74582 #endif
74583
74584+#ifndef __alloc_size
74585+#define __alloc_size(...)
74586+#endif
74587+
74588+#ifndef __bos
74589+#define __bos(ptr, arg)
74590+#endif
74591+
74592+#ifndef __bos0
74593+#define __bos0(ptr)
74594+#endif
74595+
74596+#ifndef __bos1
74597+#define __bos1(ptr)
74598+#endif
74599+
74600 /* Simple shorthand for a section definition */
74601 #ifndef __section
74602 # define __section(S) __attribute__ ((__section__(#S)))
74603@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
74604 * use is to mediate communication between process-level code and irq/NMI
74605 * handlers, all running on the same CPU.
74606 */
74607-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
74608+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
74609+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
74610
74611 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
74612 #ifdef CONFIG_KPROBES
74613diff --git a/include/linux/completion.h b/include/linux/completion.h
74614index 3cd574d..240dcb0 100644
74615--- a/include/linux/completion.h
74616+++ b/include/linux/completion.h
74617@@ -78,16 +78,16 @@ static inline void init_completion(struct completion *x)
74618
74619 extern void wait_for_completion(struct completion *);
74620 extern void wait_for_completion_io(struct completion *);
74621-extern int wait_for_completion_interruptible(struct completion *x);
74622-extern int wait_for_completion_killable(struct completion *x);
74623+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
74624+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
74625 extern unsigned long wait_for_completion_timeout(struct completion *x,
74626- unsigned long timeout);
74627+ unsigned long timeout) __intentional_overflow(-1);
74628 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
74629- unsigned long timeout);
74630+ unsigned long timeout) __intentional_overflow(-1);
74631 extern long wait_for_completion_interruptible_timeout(
74632- struct completion *x, unsigned long timeout);
74633+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
74634 extern long wait_for_completion_killable_timeout(
74635- struct completion *x, unsigned long timeout);
74636+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
74637 extern bool try_wait_for_completion(struct completion *x);
74638 extern bool completion_done(struct completion *x);
74639
74640diff --git a/include/linux/configfs.h b/include/linux/configfs.h
74641index 34025df..d94bbbc 100644
74642--- a/include/linux/configfs.h
74643+++ b/include/linux/configfs.h
74644@@ -125,7 +125,7 @@ struct configfs_attribute {
74645 const char *ca_name;
74646 struct module *ca_owner;
74647 umode_t ca_mode;
74648-};
74649+} __do_const;
74650
74651 /*
74652 * Users often need to create attribute structures for their configurable
74653diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
74654index fcabc42..cba5d93 100644
74655--- a/include/linux/cpufreq.h
74656+++ b/include/linux/cpufreq.h
74657@@ -167,6 +167,7 @@ struct global_attr {
74658 ssize_t (*store)(struct kobject *a, struct attribute *b,
74659 const char *c, size_t count);
74660 };
74661+typedef struct global_attr __no_const global_attr_no_const;
74662
74663 #define define_one_global_ro(_name) \
74664 static struct global_attr _name = \
74665@@ -208,7 +209,7 @@ struct cpufreq_driver {
74666 int (*suspend) (struct cpufreq_policy *policy);
74667 int (*resume) (struct cpufreq_policy *policy);
74668 struct freq_attr **attr;
74669-};
74670+} __do_const;
74671
74672 /* flags */
74673 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
74674diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
74675index 781addc..d1e1fe6 100644
74676--- a/include/linux/cpuidle.h
74677+++ b/include/linux/cpuidle.h
74678@@ -50,7 +50,8 @@ struct cpuidle_state {
74679 int index);
74680
74681 int (*enter_dead) (struct cpuidle_device *dev, int index);
74682-};
74683+} __do_const;
74684+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
74685
74686 /* Idle State Flags */
74687 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
74688@@ -192,7 +193,7 @@ struct cpuidle_governor {
74689 void (*reflect) (struct cpuidle_device *dev, int index);
74690
74691 struct module *owner;
74692-};
74693+} __do_const;
74694
74695 #ifdef CONFIG_CPU_IDLE
74696
74697diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
74698index d08e4d2..95fad61 100644
74699--- a/include/linux/cpumask.h
74700+++ b/include/linux/cpumask.h
74701@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
74702 }
74703
74704 /* Valid inputs for n are -1 and 0. */
74705-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
74706+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
74707 {
74708 return n+1;
74709 }
74710
74711-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74712+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
74713 {
74714 return n+1;
74715 }
74716
74717-static inline unsigned int cpumask_next_and(int n,
74718+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
74719 const struct cpumask *srcp,
74720 const struct cpumask *andp)
74721 {
74722@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
74723 *
74724 * Returns >= nr_cpu_ids if no further cpus set.
74725 */
74726-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
74727+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
74728 {
74729 /* -1 is a legal arg here. */
74730 if (n != -1)
74731@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
74732 *
74733 * Returns >= nr_cpu_ids if no further cpus unset.
74734 */
74735-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74736+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
74737 {
74738 /* -1 is a legal arg here. */
74739 if (n != -1)
74740@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74741 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
74742 }
74743
74744-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
74745+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
74746 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
74747
74748 /**
74749diff --git a/include/linux/cred.h b/include/linux/cred.h
74750index 04421e8..6bce4ef 100644
74751--- a/include/linux/cred.h
74752+++ b/include/linux/cred.h
74753@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
74754 static inline void validate_process_creds(void)
74755 {
74756 }
74757+static inline void validate_task_creds(struct task_struct *task)
74758+{
74759+}
74760 #endif
74761
74762 /**
74763diff --git a/include/linux/crypto.h b/include/linux/crypto.h
74764index b92eadf..b4ecdc1 100644
74765--- a/include/linux/crypto.h
74766+++ b/include/linux/crypto.h
74767@@ -373,7 +373,7 @@ struct cipher_tfm {
74768 const u8 *key, unsigned int keylen);
74769 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74770 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74771-};
74772+} __no_const;
74773
74774 struct hash_tfm {
74775 int (*init)(struct hash_desc *desc);
74776@@ -394,13 +394,13 @@ struct compress_tfm {
74777 int (*cot_decompress)(struct crypto_tfm *tfm,
74778 const u8 *src, unsigned int slen,
74779 u8 *dst, unsigned int *dlen);
74780-};
74781+} __no_const;
74782
74783 struct rng_tfm {
74784 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
74785 unsigned int dlen);
74786 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
74787-};
74788+} __no_const;
74789
74790 #define crt_ablkcipher crt_u.ablkcipher
74791 #define crt_aead crt_u.aead
74792diff --git a/include/linux/ctype.h b/include/linux/ctype.h
74793index 653589e..4ef254a 100644
74794--- a/include/linux/ctype.h
74795+++ b/include/linux/ctype.h
74796@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
74797 * Fast implementation of tolower() for internal usage. Do not use in your
74798 * code.
74799 */
74800-static inline char _tolower(const char c)
74801+static inline unsigned char _tolower(const unsigned char c)
74802 {
74803 return c | 0x20;
74804 }
74805diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
74806index 7925bf0..d5143d2 100644
74807--- a/include/linux/decompress/mm.h
74808+++ b/include/linux/decompress/mm.h
74809@@ -77,7 +77,7 @@ static void free(void *where)
74810 * warnings when not needed (indeed large_malloc / large_free are not
74811 * needed by inflate */
74812
74813-#define malloc(a) kmalloc(a, GFP_KERNEL)
74814+#define malloc(a) kmalloc((a), GFP_KERNEL)
74815 #define free(a) kfree(a)
74816
74817 #define large_malloc(a) vmalloc(a)
74818diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
74819index 5f1ab92..39c35ae 100644
74820--- a/include/linux/devfreq.h
74821+++ b/include/linux/devfreq.h
74822@@ -114,7 +114,7 @@ struct devfreq_governor {
74823 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
74824 int (*event_handler)(struct devfreq *devfreq,
74825 unsigned int event, void *data);
74826-};
74827+} __do_const;
74828
74829 /**
74830 * struct devfreq - Device devfreq structure
74831diff --git a/include/linux/device.h b/include/linux/device.h
74832index 2a9d6ed..d14551e3 100644
74833--- a/include/linux/device.h
74834+++ b/include/linux/device.h
74835@@ -313,7 +313,7 @@ struct subsys_interface {
74836 struct list_head node;
74837 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
74838 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
74839-};
74840+} __do_const;
74841
74842 int subsys_interface_register(struct subsys_interface *sif);
74843 void subsys_interface_unregister(struct subsys_interface *sif);
74844@@ -501,7 +501,7 @@ struct device_type {
74845 void (*release)(struct device *dev);
74846
74847 const struct dev_pm_ops *pm;
74848-};
74849+} __do_const;
74850
74851 /* interface for exporting device attributes */
74852 struct device_attribute {
74853@@ -511,11 +511,12 @@ struct device_attribute {
74854 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
74855 const char *buf, size_t count);
74856 };
74857+typedef struct device_attribute __no_const device_attribute_no_const;
74858
74859 struct dev_ext_attribute {
74860 struct device_attribute attr;
74861 void *var;
74862-};
74863+} __do_const;
74864
74865 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
74866 char *buf);
74867diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
74868index 3a8d0a2..c762be2 100644
74869--- a/include/linux/dma-mapping.h
74870+++ b/include/linux/dma-mapping.h
74871@@ -54,7 +54,7 @@ struct dma_map_ops {
74872 u64 (*get_required_mask)(struct device *dev);
74873 #endif
74874 int is_phys;
74875-};
74876+} __do_const;
74877
74878 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
74879
74880diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
74881index 0bc7275..4ccbf11 100644
74882--- a/include/linux/dmaengine.h
74883+++ b/include/linux/dmaengine.h
74884@@ -1078,9 +1078,9 @@ struct dma_pinned_list {
74885 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
74886 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
74887
74888-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74889+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74890 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
74891-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74892+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74893 struct dma_pinned_list *pinned_list, struct page *page,
74894 unsigned int offset, size_t len);
74895
74896diff --git a/include/linux/efi.h b/include/linux/efi.h
74897index 094ddd0..f1dfcd3 100644
74898--- a/include/linux/efi.h
74899+++ b/include/linux/efi.h
74900@@ -745,6 +745,7 @@ struct efivar_operations {
74901 efi_set_variable_t *set_variable;
74902 efi_query_variable_store_t *query_variable_store;
74903 };
74904+typedef struct efivar_operations __no_const efivar_operations_no_const;
74905
74906 struct efivars {
74907 /*
74908diff --git a/include/linux/elf.h b/include/linux/elf.h
74909index 40a3c0e0..4c45a38 100644
74910--- a/include/linux/elf.h
74911+++ b/include/linux/elf.h
74912@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
74913 #define elf_note elf32_note
74914 #define elf_addr_t Elf32_Off
74915 #define Elf_Half Elf32_Half
74916+#define elf_dyn Elf32_Dyn
74917
74918 #else
74919
74920@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
74921 #define elf_note elf64_note
74922 #define elf_addr_t Elf64_Off
74923 #define Elf_Half Elf64_Half
74924+#define elf_dyn Elf64_Dyn
74925
74926 #endif
74927
74928diff --git a/include/linux/err.h b/include/linux/err.h
74929index 15f92e0..e825a8e 100644
74930--- a/include/linux/err.h
74931+++ b/include/linux/err.h
74932@@ -19,12 +19,12 @@
74933
74934 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
74935
74936-static inline void * __must_check ERR_PTR(long error)
74937+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
74938 {
74939 return (void *) error;
74940 }
74941
74942-static inline long __must_check PTR_ERR(__force const void *ptr)
74943+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
74944 {
74945 return (long) ptr;
74946 }
74947diff --git a/include/linux/extcon.h b/include/linux/extcon.h
74948index fcb51c8..bdafcf6 100644
74949--- a/include/linux/extcon.h
74950+++ b/include/linux/extcon.h
74951@@ -134,7 +134,7 @@ struct extcon_dev {
74952 /* /sys/class/extcon/.../mutually_exclusive/... */
74953 struct attribute_group attr_g_muex;
74954 struct attribute **attrs_muex;
74955- struct device_attribute *d_attrs_muex;
74956+ device_attribute_no_const *d_attrs_muex;
74957 };
74958
74959 /**
74960diff --git a/include/linux/fb.h b/include/linux/fb.h
74961index ffac70a..ca3e711 100644
74962--- a/include/linux/fb.h
74963+++ b/include/linux/fb.h
74964@@ -304,7 +304,7 @@ struct fb_ops {
74965 /* called at KDB enter and leave time to prepare the console */
74966 int (*fb_debug_enter)(struct fb_info *info);
74967 int (*fb_debug_leave)(struct fb_info *info);
74968-};
74969+} __do_const;
74970
74971 #ifdef CONFIG_FB_TILEBLITTING
74972 #define FB_TILE_CURSOR_NONE 0
74973diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
74974index 085197b..0fa6f0b 100644
74975--- a/include/linux/fdtable.h
74976+++ b/include/linux/fdtable.h
74977@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
74978 void put_files_struct(struct files_struct *fs);
74979 void reset_files_struct(struct files_struct *);
74980 int unshare_files(struct files_struct **);
74981-struct files_struct *dup_fd(struct files_struct *, int *);
74982+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
74983 void do_close_on_exec(struct files_struct *);
74984 int iterate_fd(struct files_struct *, unsigned,
74985 int (*)(const void *, struct file *, unsigned),
74986diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
74987index 8293262..2b3b8bd 100644
74988--- a/include/linux/frontswap.h
74989+++ b/include/linux/frontswap.h
74990@@ -11,7 +11,7 @@ struct frontswap_ops {
74991 int (*load)(unsigned, pgoff_t, struct page *);
74992 void (*invalidate_page)(unsigned, pgoff_t);
74993 void (*invalidate_area)(unsigned);
74994-};
74995+} __no_const;
74996
74997 extern bool frontswap_enabled;
74998 extern struct frontswap_ops *
74999diff --git a/include/linux/fs.h b/include/linux/fs.h
75000index 164d2a9..0ffa41d0 100644
75001--- a/include/linux/fs.h
75002+++ b/include/linux/fs.h
75003@@ -1552,7 +1552,8 @@ struct file_operations {
75004 long (*fallocate)(struct file *file, int mode, loff_t offset,
75005 loff_t len);
75006 int (*show_fdinfo)(struct seq_file *m, struct file *f);
75007-};
75008+} __do_const;
75009+typedef struct file_operations __no_const file_operations_no_const;
75010
75011 struct inode_operations {
75012 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
75013@@ -2747,4 +2748,14 @@ static inline bool dir_relax(struct inode *inode)
75014 return !IS_DEADDIR(inode);
75015 }
75016
75017+static inline bool is_sidechannel_device(const struct inode *inode)
75018+{
75019+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
75020+ umode_t mode = inode->i_mode;
75021+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
75022+#else
75023+ return false;
75024+#endif
75025+}
75026+
75027 #endif /* _LINUX_FS_H */
75028diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
75029index 0efc3e6..e0e1e5f 100644
75030--- a/include/linux/fs_struct.h
75031+++ b/include/linux/fs_struct.h
75032@@ -6,7 +6,7 @@
75033 #include <linux/seqlock.h>
75034
75035 struct fs_struct {
75036- int users;
75037+ atomic_t users;
75038 spinlock_t lock;
75039 seqcount_t seq;
75040 int umask;
75041diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
75042index 7823e9e..56b6f2f 100644
75043--- a/include/linux/fscache-cache.h
75044+++ b/include/linux/fscache-cache.h
75045@@ -113,7 +113,7 @@ struct fscache_operation {
75046 fscache_operation_release_t release;
75047 };
75048
75049-extern atomic_t fscache_op_debug_id;
75050+extern atomic_unchecked_t fscache_op_debug_id;
75051 extern void fscache_op_work_func(struct work_struct *work);
75052
75053 extern void fscache_enqueue_operation(struct fscache_operation *);
75054@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
75055 INIT_WORK(&op->work, fscache_op_work_func);
75056 atomic_set(&op->usage, 1);
75057 op->state = FSCACHE_OP_ST_INITIALISED;
75058- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
75059+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
75060 op->processor = processor;
75061 op->release = release;
75062 INIT_LIST_HEAD(&op->pend_link);
75063diff --git a/include/linux/fscache.h b/include/linux/fscache.h
75064index 19b4645..3b73dfc 100644
75065--- a/include/linux/fscache.h
75066+++ b/include/linux/fscache.h
75067@@ -152,7 +152,7 @@ struct fscache_cookie_def {
75068 * - this is mandatory for any object that may have data
75069 */
75070 void (*now_uncached)(void *cookie_netfs_data);
75071-};
75072+} __do_const;
75073
75074 /*
75075 * fscache cached network filesystem type
75076diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
75077index 1c804b0..1432c2b 100644
75078--- a/include/linux/fsnotify.h
75079+++ b/include/linux/fsnotify.h
75080@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
75081 struct inode *inode = file_inode(file);
75082 __u32 mask = FS_ACCESS;
75083
75084+ if (is_sidechannel_device(inode))
75085+ return;
75086+
75087 if (S_ISDIR(inode->i_mode))
75088 mask |= FS_ISDIR;
75089
75090@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
75091 struct inode *inode = file_inode(file);
75092 __u32 mask = FS_MODIFY;
75093
75094+ if (is_sidechannel_device(inode))
75095+ return;
75096+
75097 if (S_ISDIR(inode->i_mode))
75098 mask |= FS_ISDIR;
75099
75100@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
75101 */
75102 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
75103 {
75104- return kstrdup(name, GFP_KERNEL);
75105+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
75106 }
75107
75108 /*
75109diff --git a/include/linux/genhd.h b/include/linux/genhd.h
75110index 9f3c275..8bdff5d 100644
75111--- a/include/linux/genhd.h
75112+++ b/include/linux/genhd.h
75113@@ -194,7 +194,7 @@ struct gendisk {
75114 struct kobject *slave_dir;
75115
75116 struct timer_rand_state *random;
75117- atomic_t sync_io; /* RAID */
75118+ atomic_unchecked_t sync_io; /* RAID */
75119 struct disk_events *ev;
75120 #ifdef CONFIG_BLK_DEV_INTEGRITY
75121 struct blk_integrity *integrity;
75122@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
75123 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
75124
75125 /* drivers/char/random.c */
75126-extern void add_disk_randomness(struct gendisk *disk);
75127+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
75128 extern void rand_initialize_disk(struct gendisk *disk);
75129
75130 static inline sector_t get_start_sect(struct block_device *bdev)
75131diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
75132index 023bc34..b02b46a 100644
75133--- a/include/linux/genl_magic_func.h
75134+++ b/include/linux/genl_magic_func.h
75135@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
75136 },
75137
75138 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
75139-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
75140+static struct genl_ops ZZZ_genl_ops[] = {
75141 #include GENL_MAGIC_INCLUDE_FILE
75142 };
75143
75144diff --git a/include/linux/gfp.h b/include/linux/gfp.h
75145index 9b4dd49..61fd41d 100644
75146--- a/include/linux/gfp.h
75147+++ b/include/linux/gfp.h
75148@@ -35,6 +35,13 @@ struct vm_area_struct;
75149 #define ___GFP_NO_KSWAPD 0x400000u
75150 #define ___GFP_OTHER_NODE 0x800000u
75151 #define ___GFP_WRITE 0x1000000u
75152+
75153+#ifdef CONFIG_PAX_USERCOPY_SLABS
75154+#define ___GFP_USERCOPY 0x2000000u
75155+#else
75156+#define ___GFP_USERCOPY 0
75157+#endif
75158+
75159 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
75160
75161 /*
75162@@ -92,6 +99,7 @@ struct vm_area_struct;
75163 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
75164 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
75165 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
75166+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
75167
75168 /*
75169 * This may seem redundant, but it's a way of annotating false positives vs.
75170@@ -99,7 +107,7 @@ struct vm_area_struct;
75171 */
75172 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
75173
75174-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
75175+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
75176 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
75177
75178 /* This equals 0, but use constants in case they ever change */
75179@@ -153,6 +161,8 @@ struct vm_area_struct;
75180 /* 4GB DMA on some platforms */
75181 #define GFP_DMA32 __GFP_DMA32
75182
75183+#define GFP_USERCOPY __GFP_USERCOPY
75184+
75185 /* Convert GFP flags to their corresponding migrate type */
75186 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
75187 {
75188diff --git a/include/linux/gracl.h b/include/linux/gracl.h
75189new file mode 100644
75190index 0000000..edb2cb6
75191--- /dev/null
75192+++ b/include/linux/gracl.h
75193@@ -0,0 +1,340 @@
75194+#ifndef GR_ACL_H
75195+#define GR_ACL_H
75196+
75197+#include <linux/grdefs.h>
75198+#include <linux/resource.h>
75199+#include <linux/capability.h>
75200+#include <linux/dcache.h>
75201+#include <asm/resource.h>
75202+
75203+/* Major status information */
75204+
75205+#define GR_VERSION "grsecurity 3.0"
75206+#define GRSECURITY_VERSION 0x3000
75207+
75208+enum {
75209+ GR_SHUTDOWN = 0,
75210+ GR_ENABLE = 1,
75211+ GR_SPROLE = 2,
75212+ GR_OLDRELOAD = 3,
75213+ GR_SEGVMOD = 4,
75214+ GR_STATUS = 5,
75215+ GR_UNSPROLE = 6,
75216+ GR_PASSSET = 7,
75217+ GR_SPROLEPAM = 8,
75218+ GR_RELOAD = 9,
75219+};
75220+
75221+/* Password setup definitions
75222+ * kernel/grhash.c */
75223+enum {
75224+ GR_PW_LEN = 128,
75225+ GR_SALT_LEN = 16,
75226+ GR_SHA_LEN = 32,
75227+};
75228+
75229+enum {
75230+ GR_SPROLE_LEN = 64,
75231+};
75232+
75233+enum {
75234+ GR_NO_GLOB = 0,
75235+ GR_REG_GLOB,
75236+ GR_CREATE_GLOB
75237+};
75238+
75239+#define GR_NLIMITS 32
75240+
75241+/* Begin Data Structures */
75242+
75243+struct sprole_pw {
75244+ unsigned char *rolename;
75245+ unsigned char salt[GR_SALT_LEN];
75246+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
75247+};
75248+
75249+struct name_entry {
75250+ __u32 key;
75251+ ino_t inode;
75252+ dev_t device;
75253+ char *name;
75254+ __u16 len;
75255+ __u8 deleted;
75256+ struct name_entry *prev;
75257+ struct name_entry *next;
75258+};
75259+
75260+struct inodev_entry {
75261+ struct name_entry *nentry;
75262+ struct inodev_entry *prev;
75263+ struct inodev_entry *next;
75264+};
75265+
75266+struct acl_role_db {
75267+ struct acl_role_label **r_hash;
75268+ __u32 r_size;
75269+};
75270+
75271+struct inodev_db {
75272+ struct inodev_entry **i_hash;
75273+ __u32 i_size;
75274+};
75275+
75276+struct name_db {
75277+ struct name_entry **n_hash;
75278+ __u32 n_size;
75279+};
75280+
75281+struct crash_uid {
75282+ uid_t uid;
75283+ unsigned long expires;
75284+};
75285+
75286+struct gr_hash_struct {
75287+ void **table;
75288+ void **nametable;
75289+ void *first;
75290+ __u32 table_size;
75291+ __u32 used_size;
75292+ int type;
75293+};
75294+
75295+/* Userspace Grsecurity ACL data structures */
75296+
75297+struct acl_subject_label {
75298+ char *filename;
75299+ ino_t inode;
75300+ dev_t device;
75301+ __u32 mode;
75302+ kernel_cap_t cap_mask;
75303+ kernel_cap_t cap_lower;
75304+ kernel_cap_t cap_invert_audit;
75305+
75306+ struct rlimit res[GR_NLIMITS];
75307+ __u32 resmask;
75308+
75309+ __u8 user_trans_type;
75310+ __u8 group_trans_type;
75311+ uid_t *user_transitions;
75312+ gid_t *group_transitions;
75313+ __u16 user_trans_num;
75314+ __u16 group_trans_num;
75315+
75316+ __u32 sock_families[2];
75317+ __u32 ip_proto[8];
75318+ __u32 ip_type;
75319+ struct acl_ip_label **ips;
75320+ __u32 ip_num;
75321+ __u32 inaddr_any_override;
75322+
75323+ __u32 crashes;
75324+ unsigned long expires;
75325+
75326+ struct acl_subject_label *parent_subject;
75327+ struct gr_hash_struct *hash;
75328+ struct acl_subject_label *prev;
75329+ struct acl_subject_label *next;
75330+
75331+ struct acl_object_label **obj_hash;
75332+ __u32 obj_hash_size;
75333+ __u16 pax_flags;
75334+};
75335+
75336+struct role_allowed_ip {
75337+ __u32 addr;
75338+ __u32 netmask;
75339+
75340+ struct role_allowed_ip *prev;
75341+ struct role_allowed_ip *next;
75342+};
75343+
75344+struct role_transition {
75345+ char *rolename;
75346+
75347+ struct role_transition *prev;
75348+ struct role_transition *next;
75349+};
75350+
75351+struct acl_role_label {
75352+ char *rolename;
75353+ uid_t uidgid;
75354+ __u16 roletype;
75355+
75356+ __u16 auth_attempts;
75357+ unsigned long expires;
75358+
75359+ struct acl_subject_label *root_label;
75360+ struct gr_hash_struct *hash;
75361+
75362+ struct acl_role_label *prev;
75363+ struct acl_role_label *next;
75364+
75365+ struct role_transition *transitions;
75366+ struct role_allowed_ip *allowed_ips;
75367+ uid_t *domain_children;
75368+ __u16 domain_child_num;
75369+
75370+ umode_t umask;
75371+
75372+ struct acl_subject_label **subj_hash;
75373+ __u32 subj_hash_size;
75374+};
75375+
75376+struct user_acl_role_db {
75377+ struct acl_role_label **r_table;
75378+ __u32 num_pointers; /* Number of allocations to track */
75379+ __u32 num_roles; /* Number of roles */
75380+ __u32 num_domain_children; /* Number of domain children */
75381+ __u32 num_subjects; /* Number of subjects */
75382+ __u32 num_objects; /* Number of objects */
75383+};
75384+
75385+struct acl_object_label {
75386+ char *filename;
75387+ ino_t inode;
75388+ dev_t device;
75389+ __u32 mode;
75390+
75391+ struct acl_subject_label *nested;
75392+ struct acl_object_label *globbed;
75393+
75394+ /* next two structures not used */
75395+
75396+ struct acl_object_label *prev;
75397+ struct acl_object_label *next;
75398+};
75399+
75400+struct acl_ip_label {
75401+ char *iface;
75402+ __u32 addr;
75403+ __u32 netmask;
75404+ __u16 low, high;
75405+ __u8 mode;
75406+ __u32 type;
75407+ __u32 proto[8];
75408+
75409+ /* next two structures not used */
75410+
75411+ struct acl_ip_label *prev;
75412+ struct acl_ip_label *next;
75413+};
75414+
75415+struct gr_arg {
75416+ struct user_acl_role_db role_db;
75417+ unsigned char pw[GR_PW_LEN];
75418+ unsigned char salt[GR_SALT_LEN];
75419+ unsigned char sum[GR_SHA_LEN];
75420+ unsigned char sp_role[GR_SPROLE_LEN];
75421+ struct sprole_pw *sprole_pws;
75422+ dev_t segv_device;
75423+ ino_t segv_inode;
75424+ uid_t segv_uid;
75425+ __u16 num_sprole_pws;
75426+ __u16 mode;
75427+};
75428+
75429+struct gr_arg_wrapper {
75430+ struct gr_arg *arg;
75431+ __u32 version;
75432+ __u32 size;
75433+};
75434+
75435+struct subject_map {
75436+ struct acl_subject_label *user;
75437+ struct acl_subject_label *kernel;
75438+ struct subject_map *prev;
75439+ struct subject_map *next;
75440+};
75441+
75442+struct acl_subj_map_db {
75443+ struct subject_map **s_hash;
75444+ __u32 s_size;
75445+};
75446+
75447+struct gr_policy_state {
75448+ struct sprole_pw **acl_special_roles;
75449+ __u16 num_sprole_pws;
75450+ struct acl_role_label *kernel_role;
75451+ struct acl_role_label *role_list;
75452+ struct acl_role_label *default_role;
75453+ struct acl_role_db acl_role_set;
75454+ struct acl_subj_map_db subj_map_set;
75455+ struct name_db name_set;
75456+ struct inodev_db inodev_set;
75457+};
75458+
75459+struct gr_alloc_state {
75460+ unsigned long alloc_stack_next;
75461+ unsigned long alloc_stack_size;
75462+ void **alloc_stack;
75463+};
75464+
75465+struct gr_reload_state {
75466+ struct gr_policy_state oldpolicy;
75467+ struct gr_alloc_state oldalloc;
75468+ struct gr_policy_state newpolicy;
75469+ struct gr_alloc_state newalloc;
75470+ struct gr_policy_state *oldpolicy_ptr;
75471+ struct gr_alloc_state *oldalloc_ptr;
75472+ unsigned char oldmode;
75473+};
75474+
75475+/* End Data Structures Section */
75476+
75477+/* Hash functions generated by empirical testing by Brad Spengler
75478+ Makes good use of the low bits of the inode. Generally 0-1 times
75479+ in loop for successful match. 0-3 for unsuccessful match.
75480+ Shift/add algorithm with modulus of table size and an XOR*/
75481+
75482+static __inline__ unsigned int
75483+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
75484+{
75485+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
75486+}
75487+
75488+ static __inline__ unsigned int
75489+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
75490+{
75491+ return ((const unsigned long)userp % sz);
75492+}
75493+
75494+static __inline__ unsigned int
75495+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
75496+{
75497+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
75498+}
75499+
75500+static __inline__ unsigned int
75501+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
75502+{
75503+ return full_name_hash((const unsigned char *)name, len) % sz;
75504+}
75505+
75506+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
75507+ subj = NULL; \
75508+ iter = 0; \
75509+ while (iter < role->subj_hash_size) { \
75510+ if (subj == NULL) \
75511+ subj = role->subj_hash[iter]; \
75512+ if (subj == NULL) { \
75513+ iter++; \
75514+ continue; \
75515+ }
75516+
75517+#define FOR_EACH_SUBJECT_END(subj,iter) \
75518+ subj = subj->next; \
75519+ if (subj == NULL) \
75520+ iter++; \
75521+ }
75522+
75523+
75524+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
75525+ subj = role->hash->first; \
75526+ while (subj != NULL) {
75527+
75528+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
75529+ subj = subj->next; \
75530+ }
75531+
75532+#endif
75533+
75534diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
75535new file mode 100644
75536index 0000000..33ebd1f
75537--- /dev/null
75538+++ b/include/linux/gracl_compat.h
75539@@ -0,0 +1,156 @@
75540+#ifndef GR_ACL_COMPAT_H
75541+#define GR_ACL_COMPAT_H
75542+
75543+#include <linux/resource.h>
75544+#include <asm/resource.h>
75545+
75546+struct sprole_pw_compat {
75547+ compat_uptr_t rolename;
75548+ unsigned char salt[GR_SALT_LEN];
75549+ unsigned char sum[GR_SHA_LEN];
75550+};
75551+
75552+struct gr_hash_struct_compat {
75553+ compat_uptr_t table;
75554+ compat_uptr_t nametable;
75555+ compat_uptr_t first;
75556+ __u32 table_size;
75557+ __u32 used_size;
75558+ int type;
75559+};
75560+
75561+struct acl_subject_label_compat {
75562+ compat_uptr_t filename;
75563+ compat_ino_t inode;
75564+ __u32 device;
75565+ __u32 mode;
75566+ kernel_cap_t cap_mask;
75567+ kernel_cap_t cap_lower;
75568+ kernel_cap_t cap_invert_audit;
75569+
75570+ struct compat_rlimit res[GR_NLIMITS];
75571+ __u32 resmask;
75572+
75573+ __u8 user_trans_type;
75574+ __u8 group_trans_type;
75575+ compat_uptr_t user_transitions;
75576+ compat_uptr_t group_transitions;
75577+ __u16 user_trans_num;
75578+ __u16 group_trans_num;
75579+
75580+ __u32 sock_families[2];
75581+ __u32 ip_proto[8];
75582+ __u32 ip_type;
75583+ compat_uptr_t ips;
75584+ __u32 ip_num;
75585+ __u32 inaddr_any_override;
75586+
75587+ __u32 crashes;
75588+ compat_ulong_t expires;
75589+
75590+ compat_uptr_t parent_subject;
75591+ compat_uptr_t hash;
75592+ compat_uptr_t prev;
75593+ compat_uptr_t next;
75594+
75595+ compat_uptr_t obj_hash;
75596+ __u32 obj_hash_size;
75597+ __u16 pax_flags;
75598+};
75599+
75600+struct role_allowed_ip_compat {
75601+ __u32 addr;
75602+ __u32 netmask;
75603+
75604+ compat_uptr_t prev;
75605+ compat_uptr_t next;
75606+};
75607+
75608+struct role_transition_compat {
75609+ compat_uptr_t rolename;
75610+
75611+ compat_uptr_t prev;
75612+ compat_uptr_t next;
75613+};
75614+
75615+struct acl_role_label_compat {
75616+ compat_uptr_t rolename;
75617+ uid_t uidgid;
75618+ __u16 roletype;
75619+
75620+ __u16 auth_attempts;
75621+ compat_ulong_t expires;
75622+
75623+ compat_uptr_t root_label;
75624+ compat_uptr_t hash;
75625+
75626+ compat_uptr_t prev;
75627+ compat_uptr_t next;
75628+
75629+ compat_uptr_t transitions;
75630+ compat_uptr_t allowed_ips;
75631+ compat_uptr_t domain_children;
75632+ __u16 domain_child_num;
75633+
75634+ umode_t umask;
75635+
75636+ compat_uptr_t subj_hash;
75637+ __u32 subj_hash_size;
75638+};
75639+
75640+struct user_acl_role_db_compat {
75641+ compat_uptr_t r_table;
75642+ __u32 num_pointers;
75643+ __u32 num_roles;
75644+ __u32 num_domain_children;
75645+ __u32 num_subjects;
75646+ __u32 num_objects;
75647+};
75648+
75649+struct acl_object_label_compat {
75650+ compat_uptr_t filename;
75651+ compat_ino_t inode;
75652+ __u32 device;
75653+ __u32 mode;
75654+
75655+ compat_uptr_t nested;
75656+ compat_uptr_t globbed;
75657+
75658+ compat_uptr_t prev;
75659+ compat_uptr_t next;
75660+};
75661+
75662+struct acl_ip_label_compat {
75663+ compat_uptr_t iface;
75664+ __u32 addr;
75665+ __u32 netmask;
75666+ __u16 low, high;
75667+ __u8 mode;
75668+ __u32 type;
75669+ __u32 proto[8];
75670+
75671+ compat_uptr_t prev;
75672+ compat_uptr_t next;
75673+};
75674+
75675+struct gr_arg_compat {
75676+ struct user_acl_role_db_compat role_db;
75677+ unsigned char pw[GR_PW_LEN];
75678+ unsigned char salt[GR_SALT_LEN];
75679+ unsigned char sum[GR_SHA_LEN];
75680+ unsigned char sp_role[GR_SPROLE_LEN];
75681+ compat_uptr_t sprole_pws;
75682+ __u32 segv_device;
75683+ compat_ino_t segv_inode;
75684+ uid_t segv_uid;
75685+ __u16 num_sprole_pws;
75686+ __u16 mode;
75687+};
75688+
75689+struct gr_arg_wrapper_compat {
75690+ compat_uptr_t arg;
75691+ __u32 version;
75692+ __u32 size;
75693+};
75694+
75695+#endif
75696diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
75697new file mode 100644
75698index 0000000..323ecf2
75699--- /dev/null
75700+++ b/include/linux/gralloc.h
75701@@ -0,0 +1,9 @@
75702+#ifndef __GRALLOC_H
75703+#define __GRALLOC_H
75704+
75705+void acl_free_all(void);
75706+int acl_alloc_stack_init(unsigned long size);
75707+void *acl_alloc(unsigned long len);
75708+void *acl_alloc_num(unsigned long num, unsigned long len);
75709+
75710+#endif
75711diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
75712new file mode 100644
75713index 0000000..be66033
75714--- /dev/null
75715+++ b/include/linux/grdefs.h
75716@@ -0,0 +1,140 @@
75717+#ifndef GRDEFS_H
75718+#define GRDEFS_H
75719+
75720+/* Begin grsecurity status declarations */
75721+
75722+enum {
75723+ GR_READY = 0x01,
75724+ GR_STATUS_INIT = 0x00 // disabled state
75725+};
75726+
75727+/* Begin ACL declarations */
75728+
75729+/* Role flags */
75730+
75731+enum {
75732+ GR_ROLE_USER = 0x0001,
75733+ GR_ROLE_GROUP = 0x0002,
75734+ GR_ROLE_DEFAULT = 0x0004,
75735+ GR_ROLE_SPECIAL = 0x0008,
75736+ GR_ROLE_AUTH = 0x0010,
75737+ GR_ROLE_NOPW = 0x0020,
75738+ GR_ROLE_GOD = 0x0040,
75739+ GR_ROLE_LEARN = 0x0080,
75740+ GR_ROLE_TPE = 0x0100,
75741+ GR_ROLE_DOMAIN = 0x0200,
75742+ GR_ROLE_PAM = 0x0400,
75743+ GR_ROLE_PERSIST = 0x0800
75744+};
75745+
75746+/* ACL Subject and Object mode flags */
75747+enum {
75748+ GR_DELETED = 0x80000000
75749+};
75750+
75751+/* ACL Object-only mode flags */
75752+enum {
75753+ GR_READ = 0x00000001,
75754+ GR_APPEND = 0x00000002,
75755+ GR_WRITE = 0x00000004,
75756+ GR_EXEC = 0x00000008,
75757+ GR_FIND = 0x00000010,
75758+ GR_INHERIT = 0x00000020,
75759+ GR_SETID = 0x00000040,
75760+ GR_CREATE = 0x00000080,
75761+ GR_DELETE = 0x00000100,
75762+ GR_LINK = 0x00000200,
75763+ GR_AUDIT_READ = 0x00000400,
75764+ GR_AUDIT_APPEND = 0x00000800,
75765+ GR_AUDIT_WRITE = 0x00001000,
75766+ GR_AUDIT_EXEC = 0x00002000,
75767+ GR_AUDIT_FIND = 0x00004000,
75768+ GR_AUDIT_INHERIT= 0x00008000,
75769+ GR_AUDIT_SETID = 0x00010000,
75770+ GR_AUDIT_CREATE = 0x00020000,
75771+ GR_AUDIT_DELETE = 0x00040000,
75772+ GR_AUDIT_LINK = 0x00080000,
75773+ GR_PTRACERD = 0x00100000,
75774+ GR_NOPTRACE = 0x00200000,
75775+ GR_SUPPRESS = 0x00400000,
75776+ GR_NOLEARN = 0x00800000,
75777+ GR_INIT_TRANSFER= 0x01000000
75778+};
75779+
75780+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
75781+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
75782+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
75783+
75784+/* ACL subject-only mode flags */
75785+enum {
75786+ GR_KILL = 0x00000001,
75787+ GR_VIEW = 0x00000002,
75788+ GR_PROTECTED = 0x00000004,
75789+ GR_LEARN = 0x00000008,
75790+ GR_OVERRIDE = 0x00000010,
75791+ /* just a placeholder, this mode is only used in userspace */
75792+ GR_DUMMY = 0x00000020,
75793+ GR_PROTSHM = 0x00000040,
75794+ GR_KILLPROC = 0x00000080,
75795+ GR_KILLIPPROC = 0x00000100,
75796+ /* just a placeholder, this mode is only used in userspace */
75797+ GR_NOTROJAN = 0x00000200,
75798+ GR_PROTPROCFD = 0x00000400,
75799+ GR_PROCACCT = 0x00000800,
75800+ GR_RELAXPTRACE = 0x00001000,
75801+ //GR_NESTED = 0x00002000,
75802+ GR_INHERITLEARN = 0x00004000,
75803+ GR_PROCFIND = 0x00008000,
75804+ GR_POVERRIDE = 0x00010000,
75805+ GR_KERNELAUTH = 0x00020000,
75806+ GR_ATSECURE = 0x00040000,
75807+ GR_SHMEXEC = 0x00080000
75808+};
75809+
75810+enum {
75811+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
75812+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
75813+ GR_PAX_ENABLE_MPROTECT = 0x0004,
75814+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
75815+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
75816+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
75817+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
75818+ GR_PAX_DISABLE_MPROTECT = 0x0400,
75819+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
75820+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
75821+};
75822+
75823+enum {
75824+ GR_ID_USER = 0x01,
75825+ GR_ID_GROUP = 0x02,
75826+};
75827+
75828+enum {
75829+ GR_ID_ALLOW = 0x01,
75830+ GR_ID_DENY = 0x02,
75831+};
75832+
75833+#define GR_CRASH_RES 31
75834+#define GR_UIDTABLE_MAX 500
75835+
75836+/* begin resource learning section */
75837+enum {
75838+ GR_RLIM_CPU_BUMP = 60,
75839+ GR_RLIM_FSIZE_BUMP = 50000,
75840+ GR_RLIM_DATA_BUMP = 10000,
75841+ GR_RLIM_STACK_BUMP = 1000,
75842+ GR_RLIM_CORE_BUMP = 10000,
75843+ GR_RLIM_RSS_BUMP = 500000,
75844+ GR_RLIM_NPROC_BUMP = 1,
75845+ GR_RLIM_NOFILE_BUMP = 5,
75846+ GR_RLIM_MEMLOCK_BUMP = 50000,
75847+ GR_RLIM_AS_BUMP = 500000,
75848+ GR_RLIM_LOCKS_BUMP = 2,
75849+ GR_RLIM_SIGPENDING_BUMP = 5,
75850+ GR_RLIM_MSGQUEUE_BUMP = 10000,
75851+ GR_RLIM_NICE_BUMP = 1,
75852+ GR_RLIM_RTPRIO_BUMP = 1,
75853+ GR_RLIM_RTTIME_BUMP = 1000000
75854+};
75855+
75856+#endif
75857diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
75858new file mode 100644
75859index 0000000..d25522e
75860--- /dev/null
75861+++ b/include/linux/grinternal.h
75862@@ -0,0 +1,229 @@
75863+#ifndef __GRINTERNAL_H
75864+#define __GRINTERNAL_H
75865+
75866+#ifdef CONFIG_GRKERNSEC
75867+
75868+#include <linux/fs.h>
75869+#include <linux/mnt_namespace.h>
75870+#include <linux/nsproxy.h>
75871+#include <linux/gracl.h>
75872+#include <linux/grdefs.h>
75873+#include <linux/grmsg.h>
75874+
75875+void gr_add_learn_entry(const char *fmt, ...)
75876+ __attribute__ ((format (printf, 1, 2)));
75877+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
75878+ const struct vfsmount *mnt);
75879+__u32 gr_check_create(const struct dentry *new_dentry,
75880+ const struct dentry *parent,
75881+ const struct vfsmount *mnt, const __u32 mode);
75882+int gr_check_protected_task(const struct task_struct *task);
75883+__u32 to_gr_audit(const __u32 reqmode);
75884+int gr_set_acls(const int type);
75885+int gr_acl_is_enabled(void);
75886+char gr_roletype_to_char(void);
75887+
75888+void gr_handle_alertkill(struct task_struct *task);
75889+char *gr_to_filename(const struct dentry *dentry,
75890+ const struct vfsmount *mnt);
75891+char *gr_to_filename1(const struct dentry *dentry,
75892+ const struct vfsmount *mnt);
75893+char *gr_to_filename2(const struct dentry *dentry,
75894+ const struct vfsmount *mnt);
75895+char *gr_to_filename3(const struct dentry *dentry,
75896+ const struct vfsmount *mnt);
75897+
75898+extern int grsec_enable_ptrace_readexec;
75899+extern int grsec_enable_harden_ptrace;
75900+extern int grsec_enable_link;
75901+extern int grsec_enable_fifo;
75902+extern int grsec_enable_execve;
75903+extern int grsec_enable_shm;
75904+extern int grsec_enable_execlog;
75905+extern int grsec_enable_signal;
75906+extern int grsec_enable_audit_ptrace;
75907+extern int grsec_enable_forkfail;
75908+extern int grsec_enable_time;
75909+extern int grsec_enable_rofs;
75910+extern int grsec_deny_new_usb;
75911+extern int grsec_enable_chroot_shmat;
75912+extern int grsec_enable_chroot_mount;
75913+extern int grsec_enable_chroot_double;
75914+extern int grsec_enable_chroot_pivot;
75915+extern int grsec_enable_chroot_chdir;
75916+extern int grsec_enable_chroot_chmod;
75917+extern int grsec_enable_chroot_mknod;
75918+extern int grsec_enable_chroot_fchdir;
75919+extern int grsec_enable_chroot_nice;
75920+extern int grsec_enable_chroot_execlog;
75921+extern int grsec_enable_chroot_caps;
75922+extern int grsec_enable_chroot_sysctl;
75923+extern int grsec_enable_chroot_unix;
75924+extern int grsec_enable_symlinkown;
75925+extern kgid_t grsec_symlinkown_gid;
75926+extern int grsec_enable_tpe;
75927+extern kgid_t grsec_tpe_gid;
75928+extern int grsec_enable_tpe_all;
75929+extern int grsec_enable_tpe_invert;
75930+extern int grsec_enable_socket_all;
75931+extern kgid_t grsec_socket_all_gid;
75932+extern int grsec_enable_socket_client;
75933+extern kgid_t grsec_socket_client_gid;
75934+extern int grsec_enable_socket_server;
75935+extern kgid_t grsec_socket_server_gid;
75936+extern kgid_t grsec_audit_gid;
75937+extern int grsec_enable_group;
75938+extern int grsec_enable_log_rwxmaps;
75939+extern int grsec_enable_mount;
75940+extern int grsec_enable_chdir;
75941+extern int grsec_resource_logging;
75942+extern int grsec_enable_blackhole;
75943+extern int grsec_lastack_retries;
75944+extern int grsec_enable_brute;
75945+extern int grsec_enable_harden_ipc;
75946+extern int grsec_lock;
75947+
75948+extern spinlock_t grsec_alert_lock;
75949+extern unsigned long grsec_alert_wtime;
75950+extern unsigned long grsec_alert_fyet;
75951+
75952+extern spinlock_t grsec_audit_lock;
75953+
75954+extern rwlock_t grsec_exec_file_lock;
75955+
75956+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
75957+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
75958+ (tsk)->exec_file->f_path.mnt) : "/")
75959+
75960+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
75961+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
75962+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75963+
75964+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
75965+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
75966+ (tsk)->exec_file->f_path.mnt) : "/")
75967+
75968+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
75969+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
75970+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75971+
75972+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
75973+
75974+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
75975+
75976+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
75977+{
75978+ if (file1 && file2) {
75979+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
75980+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
75981+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
75982+ return true;
75983+ }
75984+
75985+ return false;
75986+}
75987+
75988+#define GR_CHROOT_CAPS {{ \
75989+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
75990+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
75991+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
75992+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
75993+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
75994+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
75995+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
75996+
75997+#define security_learn(normal_msg,args...) \
75998+({ \
75999+ read_lock(&grsec_exec_file_lock); \
76000+ gr_add_learn_entry(normal_msg "\n", ## args); \
76001+ read_unlock(&grsec_exec_file_lock); \
76002+})
76003+
76004+enum {
76005+ GR_DO_AUDIT,
76006+ GR_DONT_AUDIT,
76007+ /* used for non-audit messages that we shouldn't kill the task on */
76008+ GR_DONT_AUDIT_GOOD
76009+};
76010+
76011+enum {
76012+ GR_TTYSNIFF,
76013+ GR_RBAC,
76014+ GR_RBAC_STR,
76015+ GR_STR_RBAC,
76016+ GR_RBAC_MODE2,
76017+ GR_RBAC_MODE3,
76018+ GR_FILENAME,
76019+ GR_SYSCTL_HIDDEN,
76020+ GR_NOARGS,
76021+ GR_ONE_INT,
76022+ GR_ONE_INT_TWO_STR,
76023+ GR_ONE_STR,
76024+ GR_STR_INT,
76025+ GR_TWO_STR_INT,
76026+ GR_TWO_INT,
76027+ GR_TWO_U64,
76028+ GR_THREE_INT,
76029+ GR_FIVE_INT_TWO_STR,
76030+ GR_TWO_STR,
76031+ GR_THREE_STR,
76032+ GR_FOUR_STR,
76033+ GR_STR_FILENAME,
76034+ GR_FILENAME_STR,
76035+ GR_FILENAME_TWO_INT,
76036+ GR_FILENAME_TWO_INT_STR,
76037+ GR_TEXTREL,
76038+ GR_PTRACE,
76039+ GR_RESOURCE,
76040+ GR_CAP,
76041+ GR_SIG,
76042+ GR_SIG2,
76043+ GR_CRASH1,
76044+ GR_CRASH2,
76045+ GR_PSACCT,
76046+ GR_RWXMAP,
76047+ GR_RWXMAPVMA
76048+};
76049+
76050+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
76051+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
76052+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
76053+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
76054+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
76055+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
76056+#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)
76057+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
76058+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
76059+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
76060+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
76061+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
76062+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
76063+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
76064+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
76065+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
76066+#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)
76067+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
76068+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
76069+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
76070+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
76071+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
76072+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
76073+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
76074+#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)
76075+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
76076+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
76077+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
76078+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
76079+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
76080+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
76081+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
76082+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
76083+#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)
76084+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
76085+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
76086+
76087+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
76088+
76089+#endif
76090+
76091+#endif
76092diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
76093new file mode 100644
76094index 0000000..195cbe4
76095--- /dev/null
76096+++ b/include/linux/grmsg.h
76097@@ -0,0 +1,115 @@
76098+#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"
76099+#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"
76100+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
76101+#define GR_STOPMOD_MSG "denied modification of module state by "
76102+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
76103+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
76104+#define GR_IOPERM_MSG "denied use of ioperm() by "
76105+#define GR_IOPL_MSG "denied use of iopl() by "
76106+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
76107+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
76108+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
76109+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
76110+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
76111+#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"
76112+#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"
76113+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
76114+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
76115+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
76116+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
76117+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
76118+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
76119+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
76120+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
76121+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
76122+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
76123+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
76124+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
76125+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
76126+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
76127+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
76128+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
76129+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
76130+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
76131+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
76132+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
76133+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
76134+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
76135+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
76136+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
76137+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
76138+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
76139+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
76140+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
76141+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
76142+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
76143+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
76144+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
76145+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
76146+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
76147+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
76148+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
76149+#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"
76150+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
76151+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
76152+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
76153+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
76154+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
76155+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
76156+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
76157+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
76158+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
76159+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
76160+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
76161+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
76162+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
76163+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
76164+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
76165+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
76166+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
76167+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
76168+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
76169+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
76170+#define GR_FAILFORK_MSG "failed fork with errno %s by "
76171+#define GR_NICE_CHROOT_MSG "denied priority change by "
76172+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
76173+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
76174+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
76175+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
76176+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
76177+#define GR_TIME_MSG "time set by "
76178+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
76179+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
76180+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
76181+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
76182+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
76183+#define GR_BIND_MSG "denied bind() by "
76184+#define GR_CONNECT_MSG "denied connect() by "
76185+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
76186+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
76187+#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"
76188+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
76189+#define GR_CAP_ACL_MSG "use of %s denied for "
76190+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
76191+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
76192+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
76193+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
76194+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
76195+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
76196+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
76197+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
76198+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
76199+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
76200+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
76201+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
76202+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
76203+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
76204+#define GR_VM86_MSG "denied use of vm86 by "
76205+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
76206+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
76207+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
76208+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
76209+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
76210+#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 "
76211+#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 "
76212+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
76213diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
76214new file mode 100644
76215index 0000000..d8b5b48
76216--- /dev/null
76217+++ b/include/linux/grsecurity.h
76218@@ -0,0 +1,245 @@
76219+#ifndef GR_SECURITY_H
76220+#define GR_SECURITY_H
76221+#include <linux/fs.h>
76222+#include <linux/fs_struct.h>
76223+#include <linux/binfmts.h>
76224+#include <linux/gracl.h>
76225+
76226+/* notify of brain-dead configs */
76227+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76228+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
76229+#endif
76230+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
76231+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
76232+#endif
76233+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
76234+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
76235+#endif
76236+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
76237+#error "CONFIG_PAX enabled, but no PaX options are enabled."
76238+#endif
76239+
76240+int gr_handle_new_usb(void);
76241+
76242+void gr_handle_brute_attach(int dumpable);
76243+void gr_handle_brute_check(void);
76244+void gr_handle_kernel_exploit(void);
76245+
76246+char gr_roletype_to_char(void);
76247+
76248+int gr_acl_enable_at_secure(void);
76249+
76250+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
76251+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
76252+
76253+void gr_del_task_from_ip_table(struct task_struct *p);
76254+
76255+int gr_pid_is_chrooted(struct task_struct *p);
76256+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
76257+int gr_handle_chroot_nice(void);
76258+int gr_handle_chroot_sysctl(const int op);
76259+int gr_handle_chroot_setpriority(struct task_struct *p,
76260+ const int niceval);
76261+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
76262+int gr_handle_chroot_chroot(const struct dentry *dentry,
76263+ const struct vfsmount *mnt);
76264+void gr_handle_chroot_chdir(const struct path *path);
76265+int gr_handle_chroot_chmod(const struct dentry *dentry,
76266+ const struct vfsmount *mnt, const int mode);
76267+int gr_handle_chroot_mknod(const struct dentry *dentry,
76268+ const struct vfsmount *mnt, const int mode);
76269+int gr_handle_chroot_mount(const struct dentry *dentry,
76270+ const struct vfsmount *mnt,
76271+ const char *dev_name);
76272+int gr_handle_chroot_pivot(void);
76273+int gr_handle_chroot_unix(const pid_t pid);
76274+
76275+int gr_handle_rawio(const struct inode *inode);
76276+
76277+void gr_handle_ioperm(void);
76278+void gr_handle_iopl(void);
76279+
76280+umode_t gr_acl_umask(void);
76281+
76282+int gr_tpe_allow(const struct file *file);
76283+
76284+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
76285+void gr_clear_chroot_entries(struct task_struct *task);
76286+
76287+void gr_log_forkfail(const int retval);
76288+void gr_log_timechange(void);
76289+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
76290+void gr_log_chdir(const struct dentry *dentry,
76291+ const struct vfsmount *mnt);
76292+void gr_log_chroot_exec(const struct dentry *dentry,
76293+ const struct vfsmount *mnt);
76294+void gr_log_remount(const char *devname, const int retval);
76295+void gr_log_unmount(const char *devname, const int retval);
76296+void gr_log_mount(const char *from, const char *to, const int retval);
76297+void gr_log_textrel(struct vm_area_struct *vma);
76298+void gr_log_ptgnustack(struct file *file);
76299+void gr_log_rwxmmap(struct file *file);
76300+void gr_log_rwxmprotect(struct vm_area_struct *vma);
76301+
76302+int gr_handle_follow_link(const struct inode *parent,
76303+ const struct inode *inode,
76304+ const struct dentry *dentry,
76305+ const struct vfsmount *mnt);
76306+int gr_handle_fifo(const struct dentry *dentry,
76307+ const struct vfsmount *mnt,
76308+ const struct dentry *dir, const int flag,
76309+ const int acc_mode);
76310+int gr_handle_hardlink(const struct dentry *dentry,
76311+ const struct vfsmount *mnt,
76312+ struct inode *inode,
76313+ const int mode, const struct filename *to);
76314+
76315+int gr_is_capable(const int cap);
76316+int gr_is_capable_nolog(const int cap);
76317+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76318+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
76319+
76320+void gr_copy_label(struct task_struct *tsk);
76321+void gr_handle_crash(struct task_struct *task, const int sig);
76322+int gr_handle_signal(const struct task_struct *p, const int sig);
76323+int gr_check_crash_uid(const kuid_t uid);
76324+int gr_check_protected_task(const struct task_struct *task);
76325+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
76326+int gr_acl_handle_mmap(const struct file *file,
76327+ const unsigned long prot);
76328+int gr_acl_handle_mprotect(const struct file *file,
76329+ const unsigned long prot);
76330+int gr_check_hidden_task(const struct task_struct *tsk);
76331+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
76332+ const struct vfsmount *mnt);
76333+__u32 gr_acl_handle_utime(const struct dentry *dentry,
76334+ const struct vfsmount *mnt);
76335+__u32 gr_acl_handle_access(const struct dentry *dentry,
76336+ const struct vfsmount *mnt, const int fmode);
76337+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
76338+ const struct vfsmount *mnt, umode_t *mode);
76339+__u32 gr_acl_handle_chown(const struct dentry *dentry,
76340+ const struct vfsmount *mnt);
76341+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
76342+ const struct vfsmount *mnt);
76343+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
76344+ const struct vfsmount *mnt);
76345+int gr_handle_ptrace(struct task_struct *task, const long request);
76346+int gr_handle_proc_ptrace(struct task_struct *task);
76347+__u32 gr_acl_handle_execve(const struct dentry *dentry,
76348+ const struct vfsmount *mnt);
76349+int gr_check_crash_exec(const struct file *filp);
76350+int gr_acl_is_enabled(void);
76351+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
76352+ const kgid_t gid);
76353+int gr_set_proc_label(const struct dentry *dentry,
76354+ const struct vfsmount *mnt,
76355+ const int unsafe_flags);
76356+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
76357+ const struct vfsmount *mnt);
76358+__u32 gr_acl_handle_open(const struct dentry *dentry,
76359+ const struct vfsmount *mnt, int acc_mode);
76360+__u32 gr_acl_handle_creat(const struct dentry *dentry,
76361+ const struct dentry *p_dentry,
76362+ const struct vfsmount *p_mnt,
76363+ int open_flags, int acc_mode, const int imode);
76364+void gr_handle_create(const struct dentry *dentry,
76365+ const struct vfsmount *mnt);
76366+void gr_handle_proc_create(const struct dentry *dentry,
76367+ const struct inode *inode);
76368+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
76369+ const struct dentry *parent_dentry,
76370+ const struct vfsmount *parent_mnt,
76371+ const int mode);
76372+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
76373+ const struct dentry *parent_dentry,
76374+ const struct vfsmount *parent_mnt);
76375+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
76376+ const struct vfsmount *mnt);
76377+void gr_handle_delete(const ino_t ino, const dev_t dev);
76378+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
76379+ const struct vfsmount *mnt);
76380+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
76381+ const struct dentry *parent_dentry,
76382+ const struct vfsmount *parent_mnt,
76383+ const struct filename *from);
76384+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
76385+ const struct dentry *parent_dentry,
76386+ const struct vfsmount *parent_mnt,
76387+ const struct dentry *old_dentry,
76388+ const struct vfsmount *old_mnt, const struct filename *to);
76389+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
76390+int gr_acl_handle_rename(struct dentry *new_dentry,
76391+ struct dentry *parent_dentry,
76392+ const struct vfsmount *parent_mnt,
76393+ struct dentry *old_dentry,
76394+ struct inode *old_parent_inode,
76395+ struct vfsmount *old_mnt, const struct filename *newname);
76396+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76397+ struct dentry *old_dentry,
76398+ struct dentry *new_dentry,
76399+ struct vfsmount *mnt, const __u8 replace);
76400+__u32 gr_check_link(const struct dentry *new_dentry,
76401+ const struct dentry *parent_dentry,
76402+ const struct vfsmount *parent_mnt,
76403+ const struct dentry *old_dentry,
76404+ const struct vfsmount *old_mnt);
76405+int gr_acl_handle_filldir(const struct file *file, const char *name,
76406+ const unsigned int namelen, const ino_t ino);
76407+
76408+__u32 gr_acl_handle_unix(const struct dentry *dentry,
76409+ const struct vfsmount *mnt);
76410+void gr_acl_handle_exit(void);
76411+void gr_acl_handle_psacct(struct task_struct *task, const long code);
76412+int gr_acl_handle_procpidmem(const struct task_struct *task);
76413+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
76414+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
76415+void gr_audit_ptrace(struct task_struct *task);
76416+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
76417+void gr_put_exec_file(struct task_struct *task);
76418+
76419+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
76420+
76421+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
76422+extern void gr_learn_resource(const struct task_struct *task, const int res,
76423+ const unsigned long wanted, const int gt);
76424+#else
76425+static inline void gr_learn_resource(const struct task_struct *task, const int res,
76426+ const unsigned long wanted, const int gt)
76427+{
76428+}
76429+#endif
76430+
76431+#ifdef CONFIG_GRKERNSEC_RESLOG
76432+extern void gr_log_resource(const struct task_struct *task, const int res,
76433+ const unsigned long wanted, const int gt);
76434+#else
76435+static inline void gr_log_resource(const struct task_struct *task, const int res,
76436+ const unsigned long wanted, const int gt)
76437+{
76438+}
76439+#endif
76440+
76441+#ifdef CONFIG_GRKERNSEC
76442+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
76443+void gr_handle_vm86(void);
76444+void gr_handle_mem_readwrite(u64 from, u64 to);
76445+
76446+void gr_log_badprocpid(const char *entry);
76447+
76448+extern int grsec_enable_dmesg;
76449+extern int grsec_disable_privio;
76450+
76451+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76452+extern kgid_t grsec_proc_gid;
76453+#endif
76454+
76455+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76456+extern int grsec_enable_chroot_findtask;
76457+#endif
76458+#ifdef CONFIG_GRKERNSEC_SETXID
76459+extern int grsec_enable_setxid;
76460+#endif
76461+#endif
76462+
76463+#endif
76464diff --git a/include/linux/grsock.h b/include/linux/grsock.h
76465new file mode 100644
76466index 0000000..e7ffaaf
76467--- /dev/null
76468+++ b/include/linux/grsock.h
76469@@ -0,0 +1,19 @@
76470+#ifndef __GRSOCK_H
76471+#define __GRSOCK_H
76472+
76473+extern void gr_attach_curr_ip(const struct sock *sk);
76474+extern int gr_handle_sock_all(const int family, const int type,
76475+ const int protocol);
76476+extern int gr_handle_sock_server(const struct sockaddr *sck);
76477+extern int gr_handle_sock_server_other(const struct sock *sck);
76478+extern int gr_handle_sock_client(const struct sockaddr *sck);
76479+extern int gr_search_connect(struct socket * sock,
76480+ struct sockaddr_in * addr);
76481+extern int gr_search_bind(struct socket * sock,
76482+ struct sockaddr_in * addr);
76483+extern int gr_search_listen(struct socket * sock);
76484+extern int gr_search_accept(struct socket * sock);
76485+extern int gr_search_socket(const int domain, const int type,
76486+ const int protocol);
76487+
76488+#endif
76489diff --git a/include/linux/highmem.h b/include/linux/highmem.h
76490index 7fb31da..08b5114 100644
76491--- a/include/linux/highmem.h
76492+++ b/include/linux/highmem.h
76493@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
76494 kunmap_atomic(kaddr);
76495 }
76496
76497+static inline void sanitize_highpage(struct page *page)
76498+{
76499+ void *kaddr;
76500+ unsigned long flags;
76501+
76502+ local_irq_save(flags);
76503+ kaddr = kmap_atomic(page);
76504+ clear_page(kaddr);
76505+ kunmap_atomic(kaddr);
76506+ local_irq_restore(flags);
76507+}
76508+
76509 static inline void zero_user_segments(struct page *page,
76510 unsigned start1, unsigned end1,
76511 unsigned start2, unsigned end2)
76512diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
76513index 1c7b89a..7dda400 100644
76514--- a/include/linux/hwmon-sysfs.h
76515+++ b/include/linux/hwmon-sysfs.h
76516@@ -25,7 +25,8 @@
76517 struct sensor_device_attribute{
76518 struct device_attribute dev_attr;
76519 int index;
76520-};
76521+} __do_const;
76522+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
76523 #define to_sensor_dev_attr(_dev_attr) \
76524 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
76525
76526@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
76527 struct device_attribute dev_attr;
76528 u8 index;
76529 u8 nr;
76530-};
76531+} __do_const;
76532+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
76533 #define to_sensor_dev_attr_2(_dev_attr) \
76534 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
76535
76536diff --git a/include/linux/i2c.h b/include/linux/i2c.h
76537index 2ab11dc..663a3f2 100644
76538--- a/include/linux/i2c.h
76539+++ b/include/linux/i2c.h
76540@@ -366,6 +366,7 @@ struct i2c_algorithm {
76541 /* To determine what the adapter supports */
76542 u32 (*functionality) (struct i2c_adapter *);
76543 };
76544+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
76545
76546 /**
76547 * struct i2c_bus_recovery_info - I2C bus recovery information
76548diff --git a/include/linux/i2o.h b/include/linux/i2o.h
76549index d23c3c2..eb63c81 100644
76550--- a/include/linux/i2o.h
76551+++ b/include/linux/i2o.h
76552@@ -565,7 +565,7 @@ struct i2o_controller {
76553 struct i2o_device *exec; /* Executive */
76554 #if BITS_PER_LONG == 64
76555 spinlock_t context_list_lock; /* lock for context_list */
76556- atomic_t context_list_counter; /* needed for unique contexts */
76557+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
76558 struct list_head context_list; /* list of context id's
76559 and pointers */
76560 #endif
76561diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
76562index aff7ad8..3942bbd 100644
76563--- a/include/linux/if_pppox.h
76564+++ b/include/linux/if_pppox.h
76565@@ -76,7 +76,7 @@ struct pppox_proto {
76566 int (*ioctl)(struct socket *sock, unsigned int cmd,
76567 unsigned long arg);
76568 struct module *owner;
76569-};
76570+} __do_const;
76571
76572 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
76573 extern void unregister_pppox_proto(int proto_num);
76574diff --git a/include/linux/init.h b/include/linux/init.h
76575index f1c27a71..7d6010e 100644
76576--- a/include/linux/init.h
76577+++ b/include/linux/init.h
76578@@ -39,9 +39,17 @@
76579 * Also note, that this data cannot be "const".
76580 */
76581
76582+#define add_init_latent_entropy __latent_entropy
76583+
76584+#ifdef CONFIG_MEMORY_HOTPLUG
76585+#define add_meminit_latent_entropy
76586+#else
76587+#define add_meminit_latent_entropy __latent_entropy
76588+#endif
76589+
76590 /* These are for everybody (although not all archs will actually
76591 discard it in modules) */
76592-#define __init __section(.init.text) __cold notrace
76593+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
76594 #define __initdata __section(.init.data)
76595 #define __initconst __constsection(.init.rodata)
76596 #define __exitdata __section(.exit.data)
76597@@ -102,7 +110,7 @@
76598 #define __cpuexitconst
76599
76600 /* Used for MEMORY_HOTPLUG */
76601-#define __meminit __section(.meminit.text) __cold notrace
76602+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
76603 #define __meminitdata __section(.meminit.data)
76604 #define __meminitconst __constsection(.meminit.rodata)
76605 #define __memexit __section(.memexit.text) __exitused __cold notrace
76606diff --git a/include/linux/init_task.h b/include/linux/init_task.h
76607index 5cd0f09..c9f67cc 100644
76608--- a/include/linux/init_task.h
76609+++ b/include/linux/init_task.h
76610@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
76611
76612 #define INIT_TASK_COMM "swapper"
76613
76614+#ifdef CONFIG_X86
76615+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
76616+#else
76617+#define INIT_TASK_THREAD_INFO
76618+#endif
76619+
76620 /*
76621 * INIT_TASK is used to set up the first task table, touch at
76622 * your own risk!. Base=0, limit=0x1fffff (=2MB)
76623@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
76624 RCU_POINTER_INITIALIZER(cred, &init_cred), \
76625 .comm = INIT_TASK_COMM, \
76626 .thread = INIT_THREAD, \
76627+ INIT_TASK_THREAD_INFO \
76628 .fs = &init_fs, \
76629 .files = &init_files, \
76630 .signal = &init_signals, \
76631diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
76632index 5e865b5..71bd258 100644
76633--- a/include/linux/interrupt.h
76634+++ b/include/linux/interrupt.h
76635@@ -361,7 +361,7 @@ enum
76636 /* map softirq index to softirq name. update 'softirq_to_name' in
76637 * kernel/softirq.c when adding a new softirq.
76638 */
76639-extern char *softirq_to_name[NR_SOFTIRQS];
76640+extern const char * const softirq_to_name[NR_SOFTIRQS];
76641
76642 /* softirq mask and active fields moved to irq_cpustat_t in
76643 * asm/hardirq.h to get better cache usage. KAO
76644@@ -369,12 +369,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
76645
76646 struct softirq_action
76647 {
76648- void (*action)(struct softirq_action *);
76649-};
76650+ void (*action)(void);
76651+} __no_const;
76652
76653 asmlinkage void do_softirq(void);
76654 asmlinkage void __do_softirq(void);
76655-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
76656+extern void open_softirq(int nr, void (*action)(void));
76657 extern void softirq_init(void);
76658 extern void __raise_softirq_irqoff(unsigned int nr);
76659
76660diff --git a/include/linux/iommu.h b/include/linux/iommu.h
76661index 7ea319e..f9e971d 100644
76662--- a/include/linux/iommu.h
76663+++ b/include/linux/iommu.h
76664@@ -129,7 +129,7 @@ struct iommu_ops {
76665 u32 (*domain_get_windows)(struct iommu_domain *domain);
76666
76667 unsigned long pgsize_bitmap;
76668-};
76669+} __do_const;
76670
76671 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
76672 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
76673diff --git a/include/linux/ioport.h b/include/linux/ioport.h
76674index 89b7c24..382af74 100644
76675--- a/include/linux/ioport.h
76676+++ b/include/linux/ioport.h
76677@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
76678 int adjust_resource(struct resource *res, resource_size_t start,
76679 resource_size_t size);
76680 resource_size_t resource_alignment(struct resource *res);
76681-static inline resource_size_t resource_size(const struct resource *res)
76682+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
76683 {
76684 return res->end - res->start + 1;
76685 }
76686diff --git a/include/linux/irq.h b/include/linux/irq.h
76687index 56bb0dc..8ae94d62 100644
76688--- a/include/linux/irq.h
76689+++ b/include/linux/irq.h
76690@@ -333,7 +333,8 @@ struct irq_chip {
76691 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
76692
76693 unsigned long flags;
76694-};
76695+} __do_const;
76696+typedef struct irq_chip __no_const irq_chip_no_const;
76697
76698 /*
76699 * irq_chip specific flags
76700diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
76701index 0e5d9ec..46acb3a 100644
76702--- a/include/linux/irqchip/arm-gic.h
76703+++ b/include/linux/irqchip/arm-gic.h
76704@@ -59,9 +59,11 @@
76705
76706 #ifndef __ASSEMBLY__
76707
76708+#include <linux/irq.h>
76709+
76710 struct device_node;
76711
76712-extern struct irq_chip gic_arch_extn;
76713+extern irq_chip_no_const gic_arch_extn;
76714
76715 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
76716 u32 offset, struct device_node *);
76717diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
76718index d235e88..8ccbe74 100644
76719--- a/include/linux/jiffies.h
76720+++ b/include/linux/jiffies.h
76721@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
76722 /*
76723 * Convert various time units to each other:
76724 */
76725-extern unsigned int jiffies_to_msecs(const unsigned long j);
76726-extern unsigned int jiffies_to_usecs(const unsigned long j);
76727-extern unsigned long msecs_to_jiffies(const unsigned int m);
76728-extern unsigned long usecs_to_jiffies(const unsigned int u);
76729-extern unsigned long timespec_to_jiffies(const struct timespec *value);
76730+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
76731+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
76732+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
76733+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
76734+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
76735 extern void jiffies_to_timespec(const unsigned long jiffies,
76736 struct timespec *value);
76737-extern unsigned long timeval_to_jiffies(const struct timeval *value);
76738+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
76739 extern void jiffies_to_timeval(const unsigned long jiffies,
76740 struct timeval *value);
76741
76742diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
76743index 6883e19..e854fcb 100644
76744--- a/include/linux/kallsyms.h
76745+++ b/include/linux/kallsyms.h
76746@@ -15,7 +15,8 @@
76747
76748 struct module;
76749
76750-#ifdef CONFIG_KALLSYMS
76751+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
76752+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76753 /* Lookup the address for a symbol. Returns 0 if not found. */
76754 unsigned long kallsyms_lookup_name(const char *name);
76755
76756@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
76757 /* Stupid that this does nothing, but I didn't create this mess. */
76758 #define __print_symbol(fmt, addr)
76759 #endif /*CONFIG_KALLSYMS*/
76760+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
76761+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
76762+extern unsigned long kallsyms_lookup_name(const char *name);
76763+extern void __print_symbol(const char *fmt, unsigned long address);
76764+extern int sprint_backtrace(char *buffer, unsigned long address);
76765+extern int sprint_symbol(char *buffer, unsigned long address);
76766+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
76767+const char *kallsyms_lookup(unsigned long addr,
76768+ unsigned long *symbolsize,
76769+ unsigned long *offset,
76770+ char **modname, char *namebuf);
76771+extern int kallsyms_lookup_size_offset(unsigned long addr,
76772+ unsigned long *symbolsize,
76773+ unsigned long *offset);
76774+#endif
76775
76776 /* This macro allows us to keep printk typechecking */
76777 static __printf(1, 2)
76778diff --git a/include/linux/key-type.h b/include/linux/key-type.h
76779index 518a53a..5e28358 100644
76780--- a/include/linux/key-type.h
76781+++ b/include/linux/key-type.h
76782@@ -125,7 +125,7 @@ struct key_type {
76783 /* internal fields */
76784 struct list_head link; /* link in types list */
76785 struct lock_class_key lock_class; /* key->sem lock class */
76786-};
76787+} __do_const;
76788
76789 extern struct key_type key_type_keyring;
76790
76791diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
76792index c6e091b..a940adf 100644
76793--- a/include/linux/kgdb.h
76794+++ b/include/linux/kgdb.h
76795@@ -52,7 +52,7 @@ extern int kgdb_connected;
76796 extern int kgdb_io_module_registered;
76797
76798 extern atomic_t kgdb_setting_breakpoint;
76799-extern atomic_t kgdb_cpu_doing_single_step;
76800+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
76801
76802 extern struct task_struct *kgdb_usethread;
76803 extern struct task_struct *kgdb_contthread;
76804@@ -254,7 +254,7 @@ struct kgdb_arch {
76805 void (*correct_hw_break)(void);
76806
76807 void (*enable_nmi)(bool on);
76808-};
76809+} __do_const;
76810
76811 /**
76812 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
76813@@ -279,7 +279,7 @@ struct kgdb_io {
76814 void (*pre_exception) (void);
76815 void (*post_exception) (void);
76816 int is_console;
76817-};
76818+} __do_const;
76819
76820 extern struct kgdb_arch arch_kgdb_ops;
76821
76822diff --git a/include/linux/kmod.h b/include/linux/kmod.h
76823index 0555cc6..40116ce 100644
76824--- a/include/linux/kmod.h
76825+++ b/include/linux/kmod.h
76826@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
76827 * usually useless though. */
76828 extern __printf(2, 3)
76829 int __request_module(bool wait, const char *name, ...);
76830+extern __printf(3, 4)
76831+int ___request_module(bool wait, char *param_name, const char *name, ...);
76832 #define request_module(mod...) __request_module(true, mod)
76833 #define request_module_nowait(mod...) __request_module(false, mod)
76834 #define try_then_request_module(x, mod...) \
76835@@ -57,6 +59,9 @@ struct subprocess_info {
76836 struct work_struct work;
76837 struct completion *complete;
76838 char *path;
76839+#ifdef CONFIG_GRKERNSEC
76840+ char *origpath;
76841+#endif
76842 char **argv;
76843 char **envp;
76844 int wait;
76845diff --git a/include/linux/kobject.h b/include/linux/kobject.h
76846index de6dcbcc..4735f88 100644
76847--- a/include/linux/kobject.h
76848+++ b/include/linux/kobject.h
76849@@ -115,7 +115,7 @@ struct kobj_type {
76850 struct attribute **default_attrs;
76851 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
76852 const void *(*namespace)(struct kobject *kobj);
76853-};
76854+} __do_const;
76855
76856 struct kobj_uevent_env {
76857 char *envp[UEVENT_NUM_ENVP];
76858@@ -138,6 +138,7 @@ struct kobj_attribute {
76859 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
76860 const char *buf, size_t count);
76861 };
76862+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
76863
76864 extern const struct sysfs_ops kobj_sysfs_ops;
76865
76866diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
76867index df32d25..fb52e27 100644
76868--- a/include/linux/kobject_ns.h
76869+++ b/include/linux/kobject_ns.h
76870@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
76871 const void *(*netlink_ns)(struct sock *sk);
76872 const void *(*initial_ns)(void);
76873 void (*drop_ns)(void *);
76874-};
76875+} __do_const;
76876
76877 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
76878 int kobj_ns_type_registered(enum kobj_ns_type type);
76879diff --git a/include/linux/kref.h b/include/linux/kref.h
76880index 484604d..0f6c5b6 100644
76881--- a/include/linux/kref.h
76882+++ b/include/linux/kref.h
76883@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
76884 static inline int kref_sub(struct kref *kref, unsigned int count,
76885 void (*release)(struct kref *kref))
76886 {
76887- WARN_ON(release == NULL);
76888+ BUG_ON(release == NULL);
76889
76890 if (atomic_sub_and_test((int) count, &kref->refcount)) {
76891 release(kref);
76892diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
76893index 0fbbc7a..db081e3 100644
76894--- a/include/linux/kvm_host.h
76895+++ b/include/linux/kvm_host.h
76896@@ -458,7 +458,7 @@ static inline void kvm_irqfd_exit(void)
76897 {
76898 }
76899 #endif
76900-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76901+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76902 struct module *module);
76903 void kvm_exit(void);
76904
76905@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
76906 struct kvm_guest_debug *dbg);
76907 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
76908
76909-int kvm_arch_init(void *opaque);
76910+int kvm_arch_init(const void *opaque);
76911 void kvm_arch_exit(void);
76912
76913 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
76914diff --git a/include/linux/libata.h b/include/linux/libata.h
76915index 0e23c26..6ad8c33 100644
76916--- a/include/linux/libata.h
76917+++ b/include/linux/libata.h
76918@@ -972,7 +972,7 @@ struct ata_port_operations {
76919 * fields must be pointers.
76920 */
76921 const struct ata_port_operations *inherits;
76922-};
76923+} __do_const;
76924
76925 struct ata_port_info {
76926 unsigned long flags;
76927diff --git a/include/linux/linkage.h b/include/linux/linkage.h
76928index d3e8ad2..a949f68 100644
76929--- a/include/linux/linkage.h
76930+++ b/include/linux/linkage.h
76931@@ -31,6 +31,7 @@
76932 #endif
76933
76934 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
76935+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
76936 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
76937
76938 /*
76939diff --git a/include/linux/list.h b/include/linux/list.h
76940index f4d8a2f..38e6e46 100644
76941--- a/include/linux/list.h
76942+++ b/include/linux/list.h
76943@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
76944 extern void list_del(struct list_head *entry);
76945 #endif
76946
76947+extern void __pax_list_add(struct list_head *new,
76948+ struct list_head *prev,
76949+ struct list_head *next);
76950+static inline void pax_list_add(struct list_head *new, struct list_head *head)
76951+{
76952+ __pax_list_add(new, head, head->next);
76953+}
76954+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
76955+{
76956+ __pax_list_add(new, head->prev, head);
76957+}
76958+extern void pax_list_del(struct list_head *entry);
76959+
76960 /**
76961 * list_replace - replace old entry by new one
76962 * @old : the element to be replaced
76963@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
76964 INIT_LIST_HEAD(entry);
76965 }
76966
76967+extern void pax_list_del_init(struct list_head *entry);
76968+
76969 /**
76970 * list_move - delete from one list and add as another's head
76971 * @list: the entry to move
76972diff --git a/include/linux/math64.h b/include/linux/math64.h
76973index 69ed5f5..243ed51 100644
76974--- a/include/linux/math64.h
76975+++ b/include/linux/math64.h
76976@@ -15,7 +15,7 @@
76977 * This is commonly provided by 32bit archs to provide an optimized 64bit
76978 * divide.
76979 */
76980-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76981+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76982 {
76983 *remainder = dividend % divisor;
76984 return dividend / divisor;
76985@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
76986 /**
76987 * div64_u64 - unsigned 64bit divide with 64bit divisor
76988 */
76989-static inline u64 div64_u64(u64 dividend, u64 divisor)
76990+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
76991 {
76992 return dividend / divisor;
76993 }
76994@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
76995 #define div64_ul(x, y) div_u64((x), (y))
76996
76997 #ifndef div_u64_rem
76998-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76999+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
77000 {
77001 *remainder = do_div(dividend, divisor);
77002 return dividend;
77003@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
77004 #endif
77005
77006 #ifndef div64_u64
77007-extern u64 div64_u64(u64 dividend, u64 divisor);
77008+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
77009 #endif
77010
77011 #ifndef div64_s64
77012@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
77013 * divide.
77014 */
77015 #ifndef div_u64
77016-static inline u64 div_u64(u64 dividend, u32 divisor)
77017+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
77018 {
77019 u32 remainder;
77020 return div_u64_rem(dividend, divisor, &remainder);
77021diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
77022index da6716b..2e31db3 100644
77023--- a/include/linux/mempolicy.h
77024+++ b/include/linux/mempolicy.h
77025@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
77026 }
77027
77028 #define vma_policy(vma) ((vma)->vm_policy)
77029+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
77030+{
77031+ vma->vm_policy = pol;
77032+}
77033
77034 static inline void mpol_get(struct mempolicy *pol)
77035 {
77036@@ -240,6 +244,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
77037 }
77038
77039 #define vma_policy(vma) NULL
77040+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
77041+{
77042+}
77043
77044 static inline int
77045 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
77046diff --git a/include/linux/mm.h b/include/linux/mm.h
77047index 8b6e55e..c4edf39 100644
77048--- a/include/linux/mm.h
77049+++ b/include/linux/mm.h
77050@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
77051 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
77052 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
77053 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
77054+
77055+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
77056+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
77057+#endif
77058+
77059 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
77060
77061 #ifdef CONFIG_MEM_SOFT_DIRTY
77062@@ -215,8 +220,8 @@ struct vm_operations_struct {
77063 /* called by access_process_vm when get_user_pages() fails, typically
77064 * for use by special VMAs that can switch between memory and hardware
77065 */
77066- int (*access)(struct vm_area_struct *vma, unsigned long addr,
77067- void *buf, int len, int write);
77068+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
77069+ void *buf, size_t len, int write);
77070 #ifdef CONFIG_NUMA
77071 /*
77072 * set_policy() op must add a reference to any non-NULL @new mempolicy
77073@@ -246,6 +251,7 @@ struct vm_operations_struct {
77074 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
77075 unsigned long size, pgoff_t pgoff);
77076 };
77077+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
77078
77079 struct mmu_gather;
77080 struct inode;
77081@@ -977,8 +983,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
77082 unsigned long *pfn);
77083 int follow_phys(struct vm_area_struct *vma, unsigned long address,
77084 unsigned int flags, unsigned long *prot, resource_size_t *phys);
77085-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
77086- void *buf, int len, int write);
77087+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
77088+ void *buf, size_t len, int write);
77089
77090 static inline void unmap_shared_mapping_range(struct address_space *mapping,
77091 loff_t const holebegin, loff_t const holelen)
77092@@ -1017,9 +1023,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
77093 }
77094 #endif
77095
77096-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
77097-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
77098- void *buf, int len, int write);
77099+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
77100+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
77101+ void *buf, size_t len, int write);
77102
77103 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
77104 unsigned long start, unsigned long nr_pages,
77105@@ -1051,34 +1057,6 @@ int set_page_dirty(struct page *page);
77106 int set_page_dirty_lock(struct page *page);
77107 int clear_page_dirty_for_io(struct page *page);
77108
77109-/* Is the vma a continuation of the stack vma above it? */
77110-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
77111-{
77112- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
77113-}
77114-
77115-static inline int stack_guard_page_start(struct vm_area_struct *vma,
77116- unsigned long addr)
77117-{
77118- return (vma->vm_flags & VM_GROWSDOWN) &&
77119- (vma->vm_start == addr) &&
77120- !vma_growsdown(vma->vm_prev, addr);
77121-}
77122-
77123-/* Is the vma a continuation of the stack vma below it? */
77124-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
77125-{
77126- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
77127-}
77128-
77129-static inline int stack_guard_page_end(struct vm_area_struct *vma,
77130- unsigned long addr)
77131-{
77132- return (vma->vm_flags & VM_GROWSUP) &&
77133- (vma->vm_end == addr) &&
77134- !vma_growsup(vma->vm_next, addr);
77135-}
77136-
77137 extern pid_t
77138 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
77139
77140@@ -1178,6 +1156,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
77141 }
77142 #endif
77143
77144+#ifdef CONFIG_MMU
77145+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
77146+#else
77147+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
77148+{
77149+ return __pgprot(0);
77150+}
77151+#endif
77152+
77153 int vma_wants_writenotify(struct vm_area_struct *vma);
77154
77155 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
77156@@ -1196,8 +1183,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
77157 {
77158 return 0;
77159 }
77160+
77161+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
77162+ unsigned long address)
77163+{
77164+ return 0;
77165+}
77166 #else
77167 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
77168+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
77169 #endif
77170
77171 #ifdef __PAGETABLE_PMD_FOLDED
77172@@ -1206,8 +1200,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
77173 {
77174 return 0;
77175 }
77176+
77177+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
77178+ unsigned long address)
77179+{
77180+ return 0;
77181+}
77182 #else
77183 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
77184+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
77185 #endif
77186
77187 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
77188@@ -1225,11 +1226,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
77189 NULL: pud_offset(pgd, address);
77190 }
77191
77192+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
77193+{
77194+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
77195+ NULL: pud_offset(pgd, address);
77196+}
77197+
77198 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
77199 {
77200 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
77201 NULL: pmd_offset(pud, address);
77202 }
77203+
77204+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
77205+{
77206+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
77207+ NULL: pmd_offset(pud, address);
77208+}
77209 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
77210
77211 #if USE_SPLIT_PTLOCKS
77212@@ -1517,7 +1530,7 @@ extern int install_special_mapping(struct mm_struct *mm,
77213 unsigned long addr, unsigned long len,
77214 unsigned long flags, struct page **pages);
77215
77216-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
77217+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
77218
77219 extern unsigned long mmap_region(struct file *file, unsigned long addr,
77220 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
77221@@ -1525,6 +1538,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77222 unsigned long len, unsigned long prot, unsigned long flags,
77223 unsigned long pgoff, unsigned long *populate);
77224 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
77225+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
77226
77227 #ifdef CONFIG_MMU
77228 extern int __mm_populate(unsigned long addr, unsigned long len,
77229@@ -1553,10 +1567,11 @@ struct vm_unmapped_area_info {
77230 unsigned long high_limit;
77231 unsigned long align_mask;
77232 unsigned long align_offset;
77233+ unsigned long threadstack_offset;
77234 };
77235
77236-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
77237-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
77238+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
77239+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
77240
77241 /*
77242 * Search for an unmapped address range.
77243@@ -1568,7 +1583,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
77244 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
77245 */
77246 static inline unsigned long
77247-vm_unmapped_area(struct vm_unmapped_area_info *info)
77248+vm_unmapped_area(const struct vm_unmapped_area_info *info)
77249 {
77250 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
77251 return unmapped_area(info);
77252@@ -1631,6 +1646,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
77253 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
77254 struct vm_area_struct **pprev);
77255
77256+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
77257+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
77258+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
77259+
77260 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
77261 NULL if none. Assume start_addr < end_addr. */
77262 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
77263@@ -1659,15 +1678,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
77264 return vma;
77265 }
77266
77267-#ifdef CONFIG_MMU
77268-pgprot_t vm_get_page_prot(unsigned long vm_flags);
77269-#else
77270-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
77271-{
77272- return __pgprot(0);
77273-}
77274-#endif
77275-
77276 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
77277 unsigned long change_prot_numa(struct vm_area_struct *vma,
77278 unsigned long start, unsigned long end);
77279@@ -1719,6 +1729,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
77280 static inline void vm_stat_account(struct mm_struct *mm,
77281 unsigned long flags, struct file *file, long pages)
77282 {
77283+
77284+#ifdef CONFIG_PAX_RANDMMAP
77285+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
77286+#endif
77287+
77288 mm->total_vm += pages;
77289 }
77290 #endif /* CONFIG_PROC_FS */
77291@@ -1800,7 +1815,7 @@ extern int unpoison_memory(unsigned long pfn);
77292 extern int sysctl_memory_failure_early_kill;
77293 extern int sysctl_memory_failure_recovery;
77294 extern void shake_page(struct page *p, int access);
77295-extern atomic_long_t num_poisoned_pages;
77296+extern atomic_long_unchecked_t num_poisoned_pages;
77297 extern int soft_offline_page(struct page *page, int flags);
77298
77299 extern void dump_page(struct page *page);
77300@@ -1837,5 +1852,11 @@ void __init setup_nr_node_ids(void);
77301 static inline void setup_nr_node_ids(void) {}
77302 #endif
77303
77304+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77305+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
77306+#else
77307+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
77308+#endif
77309+
77310 #endif /* __KERNEL__ */
77311 #endif /* _LINUX_MM_H */
77312diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
77313index d9851ee..619492d 100644
77314--- a/include/linux/mm_types.h
77315+++ b/include/linux/mm_types.h
77316@@ -289,6 +289,8 @@ struct vm_area_struct {
77317 #ifdef CONFIG_NUMA
77318 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
77319 #endif
77320+
77321+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
77322 };
77323
77324 struct core_thread {
77325@@ -436,6 +438,24 @@ struct mm_struct {
77326 int first_nid;
77327 #endif
77328 struct uprobes_state uprobes_state;
77329+
77330+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
77331+ unsigned long pax_flags;
77332+#endif
77333+
77334+#ifdef CONFIG_PAX_DLRESOLVE
77335+ unsigned long call_dl_resolve;
77336+#endif
77337+
77338+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
77339+ unsigned long call_syscall;
77340+#endif
77341+
77342+#ifdef CONFIG_PAX_ASLR
77343+ unsigned long delta_mmap; /* randomized offset */
77344+ unsigned long delta_stack; /* randomized offset */
77345+#endif
77346+
77347 };
77348
77349 /* first nid will either be a valid NID or one of these values */
77350diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
77351index c5d5278..f0b68c8 100644
77352--- a/include/linux/mmiotrace.h
77353+++ b/include/linux/mmiotrace.h
77354@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
77355 /* Called from ioremap.c */
77356 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
77357 void __iomem *addr);
77358-extern void mmiotrace_iounmap(volatile void __iomem *addr);
77359+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
77360
77361 /* For anyone to insert markers. Remember trailing newline. */
77362 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
77363@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
77364 {
77365 }
77366
77367-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
77368+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
77369 {
77370 }
77371
77372diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
77373index bd791e4..8617c34f 100644
77374--- a/include/linux/mmzone.h
77375+++ b/include/linux/mmzone.h
77376@@ -396,7 +396,7 @@ struct zone {
77377 unsigned long flags; /* zone flags, see below */
77378
77379 /* Zone statistics */
77380- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77381+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77382
77383 /*
77384 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
77385diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
77386index 45e9214..a7227d6 100644
77387--- a/include/linux/mod_devicetable.h
77388+++ b/include/linux/mod_devicetable.h
77389@@ -13,7 +13,7 @@
77390 typedef unsigned long kernel_ulong_t;
77391 #endif
77392
77393-#define PCI_ANY_ID (~0)
77394+#define PCI_ANY_ID ((__u16)~0)
77395
77396 struct pci_device_id {
77397 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
77398@@ -139,7 +139,7 @@ struct usb_device_id {
77399 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
77400 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
77401
77402-#define HID_ANY_ID (~0)
77403+#define HID_ANY_ID (~0U)
77404 #define HID_BUS_ANY 0xffff
77405 #define HID_GROUP_ANY 0x0000
77406
77407@@ -467,7 +467,7 @@ struct dmi_system_id {
77408 const char *ident;
77409 struct dmi_strmatch matches[4];
77410 void *driver_data;
77411-};
77412+} __do_const;
77413 /*
77414 * struct dmi_device_id appears during expansion of
77415 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
77416diff --git a/include/linux/module.h b/include/linux/module.h
77417index 05f2447..2aee07c 100644
77418--- a/include/linux/module.h
77419+++ b/include/linux/module.h
77420@@ -17,9 +17,11 @@
77421 #include <linux/moduleparam.h>
77422 #include <linux/tracepoint.h>
77423 #include <linux/export.h>
77424+#include <linux/fs.h>
77425
77426 #include <linux/percpu.h>
77427 #include <asm/module.h>
77428+#include <asm/pgtable.h>
77429
77430 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
77431 #define MODULE_SIG_STRING "~Module signature appended~\n"
77432@@ -55,12 +57,13 @@ struct module_attribute {
77433 int (*test)(struct module *);
77434 void (*free)(struct module *);
77435 };
77436+typedef struct module_attribute __no_const module_attribute_no_const;
77437
77438 struct module_version_attribute {
77439 struct module_attribute mattr;
77440 const char *module_name;
77441 const char *version;
77442-} __attribute__ ((__aligned__(sizeof(void *))));
77443+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
77444
77445 extern ssize_t __modver_version_show(struct module_attribute *,
77446 struct module_kobject *, char *);
77447@@ -238,7 +241,7 @@ struct module
77448
77449 /* Sysfs stuff. */
77450 struct module_kobject mkobj;
77451- struct module_attribute *modinfo_attrs;
77452+ module_attribute_no_const *modinfo_attrs;
77453 const char *version;
77454 const char *srcversion;
77455 struct kobject *holders_dir;
77456@@ -287,19 +290,16 @@ struct module
77457 int (*init)(void);
77458
77459 /* If this is non-NULL, vfree after init() returns */
77460- void *module_init;
77461+ void *module_init_rx, *module_init_rw;
77462
77463 /* Here is the actual code + data, vfree'd on unload. */
77464- void *module_core;
77465+ void *module_core_rx, *module_core_rw;
77466
77467 /* Here are the sizes of the init and core sections */
77468- unsigned int init_size, core_size;
77469+ unsigned int init_size_rw, core_size_rw;
77470
77471 /* The size of the executable code in each section. */
77472- unsigned int init_text_size, core_text_size;
77473-
77474- /* Size of RO sections of the module (text+rodata) */
77475- unsigned int init_ro_size, core_ro_size;
77476+ unsigned int init_size_rx, core_size_rx;
77477
77478 /* Arch-specific module values */
77479 struct mod_arch_specific arch;
77480@@ -355,6 +355,10 @@ struct module
77481 #ifdef CONFIG_EVENT_TRACING
77482 struct ftrace_event_call **trace_events;
77483 unsigned int num_trace_events;
77484+ struct file_operations trace_id;
77485+ struct file_operations trace_enable;
77486+ struct file_operations trace_format;
77487+ struct file_operations trace_filter;
77488 #endif
77489 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
77490 unsigned int num_ftrace_callsites;
77491@@ -402,16 +406,46 @@ bool is_module_address(unsigned long addr);
77492 bool is_module_percpu_address(unsigned long addr);
77493 bool is_module_text_address(unsigned long addr);
77494
77495+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
77496+{
77497+
77498+#ifdef CONFIG_PAX_KERNEXEC
77499+ if (ktla_ktva(addr) >= (unsigned long)start &&
77500+ ktla_ktva(addr) < (unsigned long)start + size)
77501+ return 1;
77502+#endif
77503+
77504+ return ((void *)addr >= start && (void *)addr < start + size);
77505+}
77506+
77507+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
77508+{
77509+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
77510+}
77511+
77512+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
77513+{
77514+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
77515+}
77516+
77517+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
77518+{
77519+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
77520+}
77521+
77522+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
77523+{
77524+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
77525+}
77526+
77527 static inline int within_module_core(unsigned long addr, const struct module *mod)
77528 {
77529- return (unsigned long)mod->module_core <= addr &&
77530- addr < (unsigned long)mod->module_core + mod->core_size;
77531+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
77532 }
77533
77534 static inline int within_module_init(unsigned long addr, const struct module *mod)
77535 {
77536- return (unsigned long)mod->module_init <= addr &&
77537- addr < (unsigned long)mod->module_init + mod->init_size;
77538+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
77539 }
77540
77541 /* Search for module by name: must hold module_mutex. */
77542diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
77543index 560ca53..ef621ef 100644
77544--- a/include/linux/moduleloader.h
77545+++ b/include/linux/moduleloader.h
77546@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
77547 sections. Returns NULL on failure. */
77548 void *module_alloc(unsigned long size);
77549
77550+#ifdef CONFIG_PAX_KERNEXEC
77551+void *module_alloc_exec(unsigned long size);
77552+#else
77553+#define module_alloc_exec(x) module_alloc(x)
77554+#endif
77555+
77556 /* Free memory returned from module_alloc. */
77557 void module_free(struct module *mod, void *module_region);
77558
77559+#ifdef CONFIG_PAX_KERNEXEC
77560+void module_free_exec(struct module *mod, void *module_region);
77561+#else
77562+#define module_free_exec(x, y) module_free((x), (y))
77563+#endif
77564+
77565 /*
77566 * Apply the given relocation to the (simplified) ELF. Return -error
77567 * or 0.
77568@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
77569 unsigned int relsec,
77570 struct module *me)
77571 {
77572+#ifdef CONFIG_MODULES
77573 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
77574+#endif
77575 return -ENOEXEC;
77576 }
77577 #endif
77578@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
77579 unsigned int relsec,
77580 struct module *me)
77581 {
77582+#ifdef CONFIG_MODULES
77583 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
77584+#endif
77585 return -ENOEXEC;
77586 }
77587 #endif
77588diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
77589index c3eb102..073c4a6 100644
77590--- a/include/linux/moduleparam.h
77591+++ b/include/linux/moduleparam.h
77592@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
77593 * @len is usually just sizeof(string).
77594 */
77595 #define module_param_string(name, string, len, perm) \
77596- static const struct kparam_string __param_string_##name \
77597+ static const struct kparam_string __param_string_##name __used \
77598 = { len, string }; \
77599 __module_param_call(MODULE_PARAM_PREFIX, name, \
77600 &param_ops_string, \
77601@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
77602 */
77603 #define module_param_array_named(name, array, type, nump, perm) \
77604 param_check_##type(name, &(array)[0]); \
77605- static const struct kparam_array __param_arr_##name \
77606+ static const struct kparam_array __param_arr_##name __used \
77607 = { .max = ARRAY_SIZE(array), .num = nump, \
77608 .ops = &param_ops_##type, \
77609 .elemsize = sizeof(array[0]), .elem = array }; \
77610diff --git a/include/linux/namei.h b/include/linux/namei.h
77611index 8e47bc7..c70fd73 100644
77612--- a/include/linux/namei.h
77613+++ b/include/linux/namei.h
77614@@ -19,7 +19,7 @@ struct nameidata {
77615 unsigned seq;
77616 int last_type;
77617 unsigned depth;
77618- char *saved_names[MAX_NESTED_LINKS + 1];
77619+ const char *saved_names[MAX_NESTED_LINKS + 1];
77620 };
77621
77622 /*
77623@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
77624
77625 extern void nd_jump_link(struct nameidata *nd, struct path *path);
77626
77627-static inline void nd_set_link(struct nameidata *nd, char *path)
77628+static inline void nd_set_link(struct nameidata *nd, const char *path)
77629 {
77630 nd->saved_names[nd->depth] = path;
77631 }
77632
77633-static inline char *nd_get_link(struct nameidata *nd)
77634+static inline const char *nd_get_link(const struct nameidata *nd)
77635 {
77636 return nd->saved_names[nd->depth];
77637 }
77638diff --git a/include/linux/net.h b/include/linux/net.h
77639index 8bd9d92..08b1c20 100644
77640--- a/include/linux/net.h
77641+++ b/include/linux/net.h
77642@@ -191,7 +191,7 @@ struct net_proto_family {
77643 int (*create)(struct net *net, struct socket *sock,
77644 int protocol, int kern);
77645 struct module *owner;
77646-};
77647+} __do_const;
77648
77649 struct iovec;
77650 struct kvec;
77651diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
77652index 25f5d2d1..5cf2120 100644
77653--- a/include/linux/netdevice.h
77654+++ b/include/linux/netdevice.h
77655@@ -1098,6 +1098,7 @@ struct net_device_ops {
77656 sa_family_t sa_family,
77657 __be16 port);
77658 };
77659+typedef struct net_device_ops __no_const net_device_ops_no_const;
77660
77661 /*
77662 * The DEVICE structure.
77663@@ -1169,7 +1170,7 @@ struct net_device {
77664 int iflink;
77665
77666 struct net_device_stats stats;
77667- atomic_long_t rx_dropped; /* dropped packets by core network
77668+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
77669 * Do not use this in drivers.
77670 */
77671
77672diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
77673index 708fe72ab9..77084a3 100644
77674--- a/include/linux/netfilter.h
77675+++ b/include/linux/netfilter.h
77676@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
77677 #endif
77678 /* Use the module struct to lock set/get code in place */
77679 struct module *owner;
77680-};
77681+} __do_const;
77682
77683 /* Function to register/unregister hook points. */
77684 int nf_register_hook(struct nf_hook_ops *reg);
77685diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
77686index cadb740..d7c37c0 100644
77687--- a/include/linux/netfilter/nfnetlink.h
77688+++ b/include/linux/netfilter/nfnetlink.h
77689@@ -16,7 +16,7 @@ struct nfnl_callback {
77690 const struct nlattr * const cda[]);
77691 const struct nla_policy *policy; /* netlink attribute policy */
77692 const u_int16_t attr_count; /* number of nlattr's */
77693-};
77694+} __do_const;
77695
77696 struct nfnetlink_subsystem {
77697 const char *name;
77698diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
77699new file mode 100644
77700index 0000000..33f4af8
77701--- /dev/null
77702+++ b/include/linux/netfilter/xt_gradm.h
77703@@ -0,0 +1,9 @@
77704+#ifndef _LINUX_NETFILTER_XT_GRADM_H
77705+#define _LINUX_NETFILTER_XT_GRADM_H 1
77706+
77707+struct xt_gradm_mtinfo {
77708+ __u16 flags;
77709+ __u16 invflags;
77710+};
77711+
77712+#endif
77713diff --git a/include/linux/nls.h b/include/linux/nls.h
77714index 5dc635f..35f5e11 100644
77715--- a/include/linux/nls.h
77716+++ b/include/linux/nls.h
77717@@ -31,7 +31,7 @@ struct nls_table {
77718 const unsigned char *charset2upper;
77719 struct module *owner;
77720 struct nls_table *next;
77721-};
77722+} __do_const;
77723
77724 /* this value hold the maximum octet of charset */
77725 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
77726diff --git a/include/linux/notifier.h b/include/linux/notifier.h
77727index d14a4c3..a078786 100644
77728--- a/include/linux/notifier.h
77729+++ b/include/linux/notifier.h
77730@@ -54,7 +54,8 @@ struct notifier_block {
77731 notifier_fn_t notifier_call;
77732 struct notifier_block __rcu *next;
77733 int priority;
77734-};
77735+} __do_const;
77736+typedef struct notifier_block __no_const notifier_block_no_const;
77737
77738 struct atomic_notifier_head {
77739 spinlock_t lock;
77740diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
77741index b2a0f15..4d7da32 100644
77742--- a/include/linux/oprofile.h
77743+++ b/include/linux/oprofile.h
77744@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
77745 int oprofilefs_create_ro_ulong(struct dentry * root,
77746 char const * name, ulong * val);
77747
77748-/** Create a file for read-only access to an atomic_t. */
77749+/** Create a file for read-only access to an atomic_unchecked_t. */
77750 int oprofilefs_create_ro_atomic(struct dentry * root,
77751- char const * name, atomic_t * val);
77752+ char const * name, atomic_unchecked_t * val);
77753
77754 /** create a directory */
77755 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
77756diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
77757index 430dd96..544e26e 100644
77758--- a/include/linux/pci_hotplug.h
77759+++ b/include/linux/pci_hotplug.h
77760@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
77761 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
77762 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
77763 int (*reset_slot) (struct hotplug_slot *slot, int probe);
77764-};
77765+} __do_const;
77766+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
77767
77768 /**
77769 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
77770diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
77771index c8ba627..24bdfa8 100644
77772--- a/include/linux/perf_event.h
77773+++ b/include/linux/perf_event.h
77774@@ -327,8 +327,8 @@ struct perf_event {
77775
77776 enum perf_event_active_state state;
77777 unsigned int attach_state;
77778- local64_t count;
77779- atomic64_t child_count;
77780+ local64_t count; /* PaX: fix it one day */
77781+ atomic64_unchecked_t child_count;
77782
77783 /*
77784 * These are the total time in nanoseconds that the event
77785@@ -379,8 +379,8 @@ struct perf_event {
77786 * These accumulate total time (in nanoseconds) that children
77787 * events have been enabled and running, respectively.
77788 */
77789- atomic64_t child_total_time_enabled;
77790- atomic64_t child_total_time_running;
77791+ atomic64_unchecked_t child_total_time_enabled;
77792+ atomic64_unchecked_t child_total_time_running;
77793
77794 /*
77795 * Protect attach/detach and child_list:
77796@@ -702,7 +702,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
77797 entry->ip[entry->nr++] = ip;
77798 }
77799
77800-extern int sysctl_perf_event_paranoid;
77801+extern int sysctl_perf_event_legitimately_concerned;
77802 extern int sysctl_perf_event_mlock;
77803 extern int sysctl_perf_event_sample_rate;
77804 extern int sysctl_perf_cpu_time_max_percent;
77805@@ -717,19 +717,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
77806 loff_t *ppos);
77807
77808
77809+static inline bool perf_paranoid_any(void)
77810+{
77811+ return sysctl_perf_event_legitimately_concerned > 2;
77812+}
77813+
77814 static inline bool perf_paranoid_tracepoint_raw(void)
77815 {
77816- return sysctl_perf_event_paranoid > -1;
77817+ return sysctl_perf_event_legitimately_concerned > -1;
77818 }
77819
77820 static inline bool perf_paranoid_cpu(void)
77821 {
77822- return sysctl_perf_event_paranoid > 0;
77823+ return sysctl_perf_event_legitimately_concerned > 0;
77824 }
77825
77826 static inline bool perf_paranoid_kernel(void)
77827 {
77828- return sysctl_perf_event_paranoid > 1;
77829+ return sysctl_perf_event_legitimately_concerned > 1;
77830 }
77831
77832 extern void perf_event_init(void);
77833@@ -845,7 +850,7 @@ struct perf_pmu_events_attr {
77834 struct device_attribute attr;
77835 u64 id;
77836 const char *event_str;
77837-};
77838+} __do_const;
77839
77840 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
77841 static struct perf_pmu_events_attr _var = { \
77842diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
77843index b8809fe..ae4ccd0 100644
77844--- a/include/linux/pipe_fs_i.h
77845+++ b/include/linux/pipe_fs_i.h
77846@@ -47,10 +47,10 @@ struct pipe_inode_info {
77847 struct mutex mutex;
77848 wait_queue_head_t wait;
77849 unsigned int nrbufs, curbuf, buffers;
77850- unsigned int readers;
77851- unsigned int writers;
77852- unsigned int files;
77853- unsigned int waiting_writers;
77854+ atomic_t readers;
77855+ atomic_t writers;
77856+ atomic_t files;
77857+ atomic_t waiting_writers;
77858 unsigned int r_counter;
77859 unsigned int w_counter;
77860 struct page *tmp_page;
77861diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
77862index 5f28cae..3d23723 100644
77863--- a/include/linux/platform_data/usb-ehci-s5p.h
77864+++ b/include/linux/platform_data/usb-ehci-s5p.h
77865@@ -14,7 +14,7 @@
77866 struct s5p_ehci_platdata {
77867 int (*phy_init)(struct platform_device *pdev, int type);
77868 int (*phy_exit)(struct platform_device *pdev, int type);
77869-};
77870+} __no_const;
77871
77872 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
77873
77874diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
77875index c256c59..8ea94c7 100644
77876--- a/include/linux/platform_data/usb-ohci-exynos.h
77877+++ b/include/linux/platform_data/usb-ohci-exynos.h
77878@@ -14,7 +14,7 @@
77879 struct exynos4_ohci_platdata {
77880 int (*phy_init)(struct platform_device *pdev, int type);
77881 int (*phy_exit)(struct platform_device *pdev, int type);
77882-};
77883+} __no_const;
77884
77885 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
77886
77887diff --git a/include/linux/pm.h b/include/linux/pm.h
77888index a224c7f..92d8a97 100644
77889--- a/include/linux/pm.h
77890+++ b/include/linux/pm.h
77891@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
77892 struct dev_pm_domain {
77893 struct dev_pm_ops ops;
77894 };
77895+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
77896
77897 /*
77898 * The PM_EVENT_ messages are also used by drivers implementing the legacy
77899diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
77900index 7c1d252..c5c773e 100644
77901--- a/include/linux/pm_domain.h
77902+++ b/include/linux/pm_domain.h
77903@@ -48,7 +48,7 @@ struct gpd_dev_ops {
77904
77905 struct gpd_cpu_data {
77906 unsigned int saved_exit_latency;
77907- struct cpuidle_state *idle_state;
77908+ cpuidle_state_no_const *idle_state;
77909 };
77910
77911 struct generic_pm_domain {
77912diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
77913index 6fa7cea..7bf6415 100644
77914--- a/include/linux/pm_runtime.h
77915+++ b/include/linux/pm_runtime.h
77916@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
77917
77918 static inline void pm_runtime_mark_last_busy(struct device *dev)
77919 {
77920- ACCESS_ONCE(dev->power.last_busy) = jiffies;
77921+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
77922 }
77923
77924 #else /* !CONFIG_PM_RUNTIME */
77925diff --git a/include/linux/pnp.h b/include/linux/pnp.h
77926index 195aafc..49a7bc2 100644
77927--- a/include/linux/pnp.h
77928+++ b/include/linux/pnp.h
77929@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
77930 struct pnp_fixup {
77931 char id[7];
77932 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
77933-};
77934+} __do_const;
77935
77936 /* config parameters */
77937 #define PNP_CONFIG_NORMAL 0x0001
77938diff --git a/include/linux/poison.h b/include/linux/poison.h
77939index 2110a81..13a11bb 100644
77940--- a/include/linux/poison.h
77941+++ b/include/linux/poison.h
77942@@ -19,8 +19,8 @@
77943 * under normal circumstances, used to verify that nobody uses
77944 * non-initialized list entries.
77945 */
77946-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
77947-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
77948+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
77949+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
77950
77951 /********** include/linux/timer.h **********/
77952 /*
77953diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
77954index d8b187c3..9a9257a 100644
77955--- a/include/linux/power/smartreflex.h
77956+++ b/include/linux/power/smartreflex.h
77957@@ -238,7 +238,7 @@ struct omap_sr_class_data {
77958 int (*notify)(struct omap_sr *sr, u32 status);
77959 u8 notify_flags;
77960 u8 class_type;
77961-};
77962+} __do_const;
77963
77964 /**
77965 * struct omap_sr_nvalue_table - Smartreflex n-target value info
77966diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
77967index 4ea1d37..80f4b33 100644
77968--- a/include/linux/ppp-comp.h
77969+++ b/include/linux/ppp-comp.h
77970@@ -84,7 +84,7 @@ struct compressor {
77971 struct module *owner;
77972 /* Extra skb space needed by the compressor algorithm */
77973 unsigned int comp_extra;
77974-};
77975+} __do_const;
77976
77977 /*
77978 * The return value from decompress routine is the length of the
77979diff --git a/include/linux/preempt.h b/include/linux/preempt.h
77980index f5d4723..a6ea2fa 100644
77981--- a/include/linux/preempt.h
77982+++ b/include/linux/preempt.h
77983@@ -18,8 +18,13 @@
77984 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77985 #endif
77986
77987+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
77988+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77989+
77990 #define inc_preempt_count() add_preempt_count(1)
77991+#define raw_inc_preempt_count() raw_add_preempt_count(1)
77992 #define dec_preempt_count() sub_preempt_count(1)
77993+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
77994
77995 #define preempt_count() (current_thread_info()->preempt_count)
77996
77997@@ -64,6 +69,12 @@ do { \
77998 barrier(); \
77999 } while (0)
78000
78001+#define raw_preempt_disable() \
78002+do { \
78003+ raw_inc_preempt_count(); \
78004+ barrier(); \
78005+} while (0)
78006+
78007 #define sched_preempt_enable_no_resched() \
78008 do { \
78009 barrier(); \
78010@@ -72,6 +83,12 @@ do { \
78011
78012 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
78013
78014+#define raw_preempt_enable_no_resched() \
78015+do { \
78016+ barrier(); \
78017+ raw_dec_preempt_count(); \
78018+} while (0)
78019+
78020 #define preempt_enable() \
78021 do { \
78022 preempt_enable_no_resched(); \
78023@@ -116,8 +133,10 @@ do { \
78024 * region.
78025 */
78026 #define preempt_disable() barrier()
78027+#define raw_preempt_disable() barrier()
78028 #define sched_preempt_enable_no_resched() barrier()
78029 #define preempt_enable_no_resched() barrier()
78030+#define raw_preempt_enable_no_resched() barrier()
78031 #define preempt_enable() barrier()
78032
78033 #define preempt_disable_notrace() barrier()
78034diff --git a/include/linux/printk.h b/include/linux/printk.h
78035index e6131a78..8e9fb61 100644
78036--- a/include/linux/printk.h
78037+++ b/include/linux/printk.h
78038@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
78039 void early_printk(const char *s, ...) { }
78040 #endif
78041
78042+extern int kptr_restrict;
78043+
78044 #ifdef CONFIG_PRINTK
78045 asmlinkage __printf(5, 0)
78046 int vprintk_emit(int facility, int level,
78047@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
78048
78049 extern int printk_delay_msec;
78050 extern int dmesg_restrict;
78051-extern int kptr_restrict;
78052
78053 extern void wake_up_klogd(void);
78054
78055diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
78056index 608e60a..c26f864 100644
78057--- a/include/linux/proc_fs.h
78058+++ b/include/linux/proc_fs.h
78059@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
78060 return proc_create_data(name, mode, parent, proc_fops, NULL);
78061 }
78062
78063+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
78064+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
78065+{
78066+#ifdef CONFIG_GRKERNSEC_PROC_USER
78067+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
78068+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78069+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
78070+#else
78071+ return proc_create_data(name, mode, parent, proc_fops, NULL);
78072+#endif
78073+}
78074+
78075+
78076 extern void proc_set_size(struct proc_dir_entry *, loff_t);
78077 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
78078 extern void *PDE_DATA(const struct inode *);
78079diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
78080index 34a1e10..03a6d03 100644
78081--- a/include/linux/proc_ns.h
78082+++ b/include/linux/proc_ns.h
78083@@ -14,7 +14,7 @@ struct proc_ns_operations {
78084 void (*put)(void *ns);
78085 int (*install)(struct nsproxy *nsproxy, void *ns);
78086 unsigned int (*inum)(void *ns);
78087-};
78088+} __do_const;
78089
78090 struct proc_ns {
78091 void *ns;
78092diff --git a/include/linux/quota.h b/include/linux/quota.h
78093index cc7494a..1e27036 100644
78094--- a/include/linux/quota.h
78095+++ b/include/linux/quota.h
78096@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
78097
78098 extern bool qid_eq(struct kqid left, struct kqid right);
78099 extern bool qid_lt(struct kqid left, struct kqid right);
78100-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
78101+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
78102 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
78103 extern bool qid_valid(struct kqid qid);
78104
78105diff --git a/include/linux/random.h b/include/linux/random.h
78106index bf9085e..1e8bbcf 100644
78107--- a/include/linux/random.h
78108+++ b/include/linux/random.h
78109@@ -10,9 +10,19 @@
78110
78111
78112 extern void add_device_randomness(const void *, unsigned int);
78113+
78114+static inline void add_latent_entropy(void)
78115+{
78116+
78117+#ifdef LATENT_ENTROPY_PLUGIN
78118+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
78119+#endif
78120+
78121+}
78122+
78123 extern void add_input_randomness(unsigned int type, unsigned int code,
78124- unsigned int value);
78125-extern void add_interrupt_randomness(int irq, int irq_flags);
78126+ unsigned int value) __latent_entropy;
78127+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
78128
78129 extern void get_random_bytes(void *buf, int nbytes);
78130 extern void get_random_bytes_arch(void *buf, int nbytes);
78131@@ -23,16 +33,21 @@ extern int random_int_secret_init(void);
78132 extern const struct file_operations random_fops, urandom_fops;
78133 #endif
78134
78135-unsigned int get_random_int(void);
78136+unsigned int __intentional_overflow(-1) get_random_int(void);
78137 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
78138
78139-u32 prandom_u32(void);
78140+u32 prandom_u32(void) __intentional_overflow(-1);
78141 void prandom_bytes(void *buf, int nbytes);
78142 void prandom_seed(u32 seed);
78143
78144 u32 prandom_u32_state(struct rnd_state *);
78145 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
78146
78147+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
78148+{
78149+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
78150+}
78151+
78152 /*
78153 * Handle minimum values for seeds
78154 */
78155diff --git a/include/linux/rculist.h b/include/linux/rculist.h
78156index 4106721..132d42c 100644
78157--- a/include/linux/rculist.h
78158+++ b/include/linux/rculist.h
78159@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
78160 struct list_head *prev, struct list_head *next);
78161 #endif
78162
78163+extern void __pax_list_add_rcu(struct list_head *new,
78164+ struct list_head *prev, struct list_head *next);
78165+
78166 /**
78167 * list_add_rcu - add a new entry to rcu-protected list
78168 * @new: new entry to be added
78169@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
78170 __list_add_rcu(new, head, head->next);
78171 }
78172
78173+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
78174+{
78175+ __pax_list_add_rcu(new, head, head->next);
78176+}
78177+
78178 /**
78179 * list_add_tail_rcu - add a new entry to rcu-protected list
78180 * @new: new entry to be added
78181@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
78182 __list_add_rcu(new, head->prev, head);
78183 }
78184
78185+static inline void pax_list_add_tail_rcu(struct list_head *new,
78186+ struct list_head *head)
78187+{
78188+ __pax_list_add_rcu(new, head->prev, head);
78189+}
78190+
78191 /**
78192 * list_del_rcu - deletes entry from list without re-initialization
78193 * @entry: the element to delete from the list.
78194@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
78195 entry->prev = LIST_POISON2;
78196 }
78197
78198+extern void pax_list_del_rcu(struct list_head *entry);
78199+
78200 /**
78201 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
78202 * @n: the element to delete from the hash list.
78203diff --git a/include/linux/reboot.h b/include/linux/reboot.h
78204index 8e00f9f..9449b55 100644
78205--- a/include/linux/reboot.h
78206+++ b/include/linux/reboot.h
78207@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
78208 * Architecture-specific implementations of sys_reboot commands.
78209 */
78210
78211-extern void machine_restart(char *cmd);
78212-extern void machine_halt(void);
78213-extern void machine_power_off(void);
78214+extern void machine_restart(char *cmd) __noreturn;
78215+extern void machine_halt(void) __noreturn;
78216+extern void machine_power_off(void) __noreturn;
78217
78218 extern void machine_shutdown(void);
78219 struct pt_regs;
78220@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
78221 */
78222
78223 extern void kernel_restart_prepare(char *cmd);
78224-extern void kernel_restart(char *cmd);
78225-extern void kernel_halt(void);
78226-extern void kernel_power_off(void);
78227+extern void kernel_restart(char *cmd) __noreturn;
78228+extern void kernel_halt(void) __noreturn;
78229+extern void kernel_power_off(void) __noreturn;
78230
78231 extern int C_A_D; /* for sysctl */
78232 void ctrl_alt_del(void);
78233@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
78234 * Emergency restart, callable from an interrupt handler.
78235 */
78236
78237-extern void emergency_restart(void);
78238+extern void emergency_restart(void) __noreturn;
78239 #include <asm/emergency-restart.h>
78240
78241 #endif /* _LINUX_REBOOT_H */
78242diff --git a/include/linux/regset.h b/include/linux/regset.h
78243index 8e0c9fe..ac4d221 100644
78244--- a/include/linux/regset.h
78245+++ b/include/linux/regset.h
78246@@ -161,7 +161,8 @@ struct user_regset {
78247 unsigned int align;
78248 unsigned int bias;
78249 unsigned int core_note_type;
78250-};
78251+} __do_const;
78252+typedef struct user_regset __no_const user_regset_no_const;
78253
78254 /**
78255 * struct user_regset_view - available regsets
78256diff --git a/include/linux/relay.h b/include/linux/relay.h
78257index d7c8359..818daf5 100644
78258--- a/include/linux/relay.h
78259+++ b/include/linux/relay.h
78260@@ -157,7 +157,7 @@ struct rchan_callbacks
78261 * The callback should return 0 if successful, negative if not.
78262 */
78263 int (*remove_buf_file)(struct dentry *dentry);
78264-};
78265+} __no_const;
78266
78267 /*
78268 * CONFIG_RELAY kernel API, kernel/relay.c
78269diff --git a/include/linux/rio.h b/include/linux/rio.h
78270index b71d573..2f940bd 100644
78271--- a/include/linux/rio.h
78272+++ b/include/linux/rio.h
78273@@ -355,7 +355,7 @@ struct rio_ops {
78274 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
78275 u64 rstart, u32 size, u32 flags);
78276 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
78277-};
78278+} __no_const;
78279
78280 #define RIO_RESOURCE_MEM 0x00000100
78281 #define RIO_RESOURCE_DOORBELL 0x00000200
78282diff --git a/include/linux/rmap.h b/include/linux/rmap.h
78283index 6dacb93..6174423 100644
78284--- a/include/linux/rmap.h
78285+++ b/include/linux/rmap.h
78286@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
78287 void anon_vma_init(void); /* create anon_vma_cachep */
78288 int anon_vma_prepare(struct vm_area_struct *);
78289 void unlink_anon_vmas(struct vm_area_struct *);
78290-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
78291-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
78292+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
78293+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
78294
78295 static inline void anon_vma_merge(struct vm_area_struct *vma,
78296 struct vm_area_struct *next)
78297diff --git a/include/linux/sched.h b/include/linux/sched.h
78298index b1e963e..114b8fd 100644
78299--- a/include/linux/sched.h
78300+++ b/include/linux/sched.h
78301@@ -62,6 +62,7 @@ struct bio_list;
78302 struct fs_struct;
78303 struct perf_event_context;
78304 struct blk_plug;
78305+struct linux_binprm;
78306
78307 /*
78308 * List of flags we want to share for kernel threads,
78309@@ -295,7 +296,7 @@ extern char __sched_text_start[], __sched_text_end[];
78310 extern int in_sched_functions(unsigned long addr);
78311
78312 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
78313-extern signed long schedule_timeout(signed long timeout);
78314+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
78315 extern signed long schedule_timeout_interruptible(signed long timeout);
78316 extern signed long schedule_timeout_killable(signed long timeout);
78317 extern signed long schedule_timeout_uninterruptible(signed long timeout);
78318@@ -306,6 +307,19 @@ struct nsproxy;
78319 struct user_namespace;
78320
78321 #ifdef CONFIG_MMU
78322+
78323+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
78324+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
78325+#else
78326+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
78327+{
78328+ return 0;
78329+}
78330+#endif
78331+
78332+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
78333+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
78334+
78335 extern void arch_pick_mmap_layout(struct mm_struct *mm);
78336 extern unsigned long
78337 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
78338@@ -585,6 +599,17 @@ struct signal_struct {
78339 #ifdef CONFIG_TASKSTATS
78340 struct taskstats *stats;
78341 #endif
78342+
78343+#ifdef CONFIG_GRKERNSEC
78344+ u32 curr_ip;
78345+ u32 saved_ip;
78346+ u32 gr_saddr;
78347+ u32 gr_daddr;
78348+ u16 gr_sport;
78349+ u16 gr_dport;
78350+ u8 used_accept:1;
78351+#endif
78352+
78353 #ifdef CONFIG_AUDIT
78354 unsigned audit_tty;
78355 unsigned audit_tty_log_passwd;
78356@@ -665,6 +690,14 @@ struct user_struct {
78357 struct key *session_keyring; /* UID's default session keyring */
78358 #endif
78359
78360+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78361+ unsigned char kernel_banned;
78362+#endif
78363+#ifdef CONFIG_GRKERNSEC_BRUTE
78364+ unsigned char suid_banned;
78365+ unsigned long suid_ban_expires;
78366+#endif
78367+
78368 /* Hash table maintenance information */
78369 struct hlist_node uidhash_node;
78370 kuid_t uid;
78371@@ -1150,8 +1183,8 @@ struct task_struct {
78372 struct list_head thread_group;
78373
78374 struct completion *vfork_done; /* for vfork() */
78375- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
78376- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
78377+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
78378+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
78379
78380 cputime_t utime, stime, utimescaled, stimescaled;
78381 cputime_t gtime;
78382@@ -1176,11 +1209,6 @@ struct task_struct {
78383 struct task_cputime cputime_expires;
78384 struct list_head cpu_timers[3];
78385
78386-/* process credentials */
78387- const struct cred __rcu *real_cred; /* objective and real subjective task
78388- * credentials (COW) */
78389- const struct cred __rcu *cred; /* effective (overridable) subjective task
78390- * credentials (COW) */
78391 char comm[TASK_COMM_LEN]; /* executable name excluding path
78392 - access with [gs]et_task_comm (which lock
78393 it with task_lock())
78394@@ -1197,6 +1225,10 @@ struct task_struct {
78395 #endif
78396 /* CPU-specific state of this task */
78397 struct thread_struct thread;
78398+/* thread_info moved to task_struct */
78399+#ifdef CONFIG_X86
78400+ struct thread_info tinfo;
78401+#endif
78402 /* filesystem information */
78403 struct fs_struct *fs;
78404 /* open file information */
78405@@ -1270,6 +1302,10 @@ struct task_struct {
78406 gfp_t lockdep_reclaim_gfp;
78407 #endif
78408
78409+/* process credentials */
78410+ const struct cred __rcu *real_cred; /* objective and real subjective task
78411+ * credentials (COW) */
78412+
78413 /* journalling filesystem info */
78414 void *journal_info;
78415
78416@@ -1308,6 +1344,10 @@ struct task_struct {
78417 /* cg_list protected by css_set_lock and tsk->alloc_lock */
78418 struct list_head cg_list;
78419 #endif
78420+
78421+ const struct cred __rcu *cred; /* effective (overridable) subjective task
78422+ * credentials (COW) */
78423+
78424 #ifdef CONFIG_FUTEX
78425 struct robust_list_head __user *robust_list;
78426 #ifdef CONFIG_COMPAT
78427@@ -1411,8 +1451,78 @@ struct task_struct {
78428 unsigned int sequential_io;
78429 unsigned int sequential_io_avg;
78430 #endif
78431+
78432+#ifdef CONFIG_GRKERNSEC
78433+ /* grsecurity */
78434+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
78435+ u64 exec_id;
78436+#endif
78437+#ifdef CONFIG_GRKERNSEC_SETXID
78438+ const struct cred *delayed_cred;
78439+#endif
78440+ struct dentry *gr_chroot_dentry;
78441+ struct acl_subject_label *acl;
78442+ struct acl_subject_label *tmpacl;
78443+ struct acl_role_label *role;
78444+ struct file *exec_file;
78445+ unsigned long brute_expires;
78446+ u16 acl_role_id;
78447+ u8 inherited;
78448+ /* is this the task that authenticated to the special role */
78449+ u8 acl_sp_role;
78450+ u8 is_writable;
78451+ u8 brute;
78452+ u8 gr_is_chrooted;
78453+#endif
78454+
78455 };
78456
78457+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
78458+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
78459+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
78460+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
78461+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
78462+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
78463+
78464+#ifdef CONFIG_PAX_SOFTMODE
78465+extern int pax_softmode;
78466+#endif
78467+
78468+extern int pax_check_flags(unsigned long *);
78469+
78470+/* if tsk != current then task_lock must be held on it */
78471+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
78472+static inline unsigned long pax_get_flags(struct task_struct *tsk)
78473+{
78474+ if (likely(tsk->mm))
78475+ return tsk->mm->pax_flags;
78476+ else
78477+ return 0UL;
78478+}
78479+
78480+/* if tsk != current then task_lock must be held on it */
78481+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
78482+{
78483+ if (likely(tsk->mm)) {
78484+ tsk->mm->pax_flags = flags;
78485+ return 0;
78486+ }
78487+ return -EINVAL;
78488+}
78489+#endif
78490+
78491+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
78492+extern void pax_set_initial_flags(struct linux_binprm *bprm);
78493+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
78494+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
78495+#endif
78496+
78497+struct path;
78498+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
78499+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
78500+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
78501+extern void pax_report_refcount_overflow(struct pt_regs *regs);
78502+
78503 /* Future-safe accessor for struct task_struct's cpus_allowed. */
78504 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
78505
78506@@ -1471,7 +1581,7 @@ struct pid_namespace;
78507 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
78508 struct pid_namespace *ns);
78509
78510-static inline pid_t task_pid_nr(struct task_struct *tsk)
78511+static inline pid_t task_pid_nr(const struct task_struct *tsk)
78512 {
78513 return tsk->pid;
78514 }
78515@@ -1921,7 +2031,9 @@ void yield(void);
78516 extern struct exec_domain default_exec_domain;
78517
78518 union thread_union {
78519+#ifndef CONFIG_X86
78520 struct thread_info thread_info;
78521+#endif
78522 unsigned long stack[THREAD_SIZE/sizeof(long)];
78523 };
78524
78525@@ -1954,6 +2066,7 @@ extern struct pid_namespace init_pid_ns;
78526 */
78527
78528 extern struct task_struct *find_task_by_vpid(pid_t nr);
78529+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
78530 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
78531 struct pid_namespace *ns);
78532
78533@@ -2118,7 +2231,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
78534 extern void exit_itimers(struct signal_struct *);
78535 extern void flush_itimer_signals(void);
78536
78537-extern void do_group_exit(int);
78538+extern __noreturn void do_group_exit(int);
78539
78540 extern int allow_signal(int);
78541 extern int disallow_signal(int);
78542@@ -2309,9 +2422,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
78543
78544 #endif
78545
78546-static inline int object_is_on_stack(void *obj)
78547+static inline int object_starts_on_stack(void *obj)
78548 {
78549- void *stack = task_stack_page(current);
78550+ const void *stack = task_stack_page(current);
78551
78552 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
78553 }
78554diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
78555index bf8086b..962b035 100644
78556--- a/include/linux/sched/sysctl.h
78557+++ b/include/linux/sched/sysctl.h
78558@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
78559 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
78560
78561 extern int sysctl_max_map_count;
78562+extern unsigned long sysctl_heap_stack_gap;
78563
78564 extern unsigned int sysctl_sched_latency;
78565 extern unsigned int sysctl_sched_min_granularity;
78566diff --git a/include/linux/security.h b/include/linux/security.h
78567index 9d37e2b..43368e4 100644
78568--- a/include/linux/security.h
78569+++ b/include/linux/security.h
78570@@ -27,6 +27,7 @@
78571 #include <linux/slab.h>
78572 #include <linux/err.h>
78573 #include <linux/string.h>
78574+#include <linux/grsecurity.h>
78575
78576 struct linux_binprm;
78577 struct cred;
78578@@ -116,8 +117,6 @@ struct seq_file;
78579
78580 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
78581
78582-void reset_security_ops(void);
78583-
78584 #ifdef CONFIG_MMU
78585 extern unsigned long mmap_min_addr;
78586 extern unsigned long dac_mmap_min_addr;
78587diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
78588index dc368b8..e895209 100644
78589--- a/include/linux/semaphore.h
78590+++ b/include/linux/semaphore.h
78591@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
78592 }
78593
78594 extern void down(struct semaphore *sem);
78595-extern int __must_check down_interruptible(struct semaphore *sem);
78596+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
78597 extern int __must_check down_killable(struct semaphore *sem);
78598 extern int __must_check down_trylock(struct semaphore *sem);
78599 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
78600diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
78601index 4e32edc..f8f2d18 100644
78602--- a/include/linux/seq_file.h
78603+++ b/include/linux/seq_file.h
78604@@ -26,6 +26,9 @@ struct seq_file {
78605 struct mutex lock;
78606 const struct seq_operations *op;
78607 int poll_event;
78608+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
78609+ u64 exec_id;
78610+#endif
78611 #ifdef CONFIG_USER_NS
78612 struct user_namespace *user_ns;
78613 #endif
78614@@ -38,6 +41,7 @@ struct seq_operations {
78615 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
78616 int (*show) (struct seq_file *m, void *v);
78617 };
78618+typedef struct seq_operations __no_const seq_operations_no_const;
78619
78620 #define SEQ_SKIP 1
78621
78622diff --git a/include/linux/shm.h b/include/linux/shm.h
78623index 429c199..4d42e38 100644
78624--- a/include/linux/shm.h
78625+++ b/include/linux/shm.h
78626@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
78627
78628 /* The task created the shm object. NULL if the task is dead. */
78629 struct task_struct *shm_creator;
78630+#ifdef CONFIG_GRKERNSEC
78631+ time_t shm_createtime;
78632+ pid_t shm_lapid;
78633+#endif
78634 };
78635
78636 /* shm_mode upper byte flags */
78637diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
78638index f66f346..2e304d5 100644
78639--- a/include/linux/skbuff.h
78640+++ b/include/linux/skbuff.h
78641@@ -639,7 +639,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
78642 extern struct sk_buff *__alloc_skb(unsigned int size,
78643 gfp_t priority, int flags, int node);
78644 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
78645-static inline struct sk_buff *alloc_skb(unsigned int size,
78646+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
78647 gfp_t priority)
78648 {
78649 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
78650@@ -755,7 +755,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
78651 */
78652 static inline int skb_queue_empty(const struct sk_buff_head *list)
78653 {
78654- return list->next == (struct sk_buff *)list;
78655+ return list->next == (const struct sk_buff *)list;
78656 }
78657
78658 /**
78659@@ -768,7 +768,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
78660 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
78661 const struct sk_buff *skb)
78662 {
78663- return skb->next == (struct sk_buff *)list;
78664+ return skb->next == (const struct sk_buff *)list;
78665 }
78666
78667 /**
78668@@ -781,7 +781,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
78669 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
78670 const struct sk_buff *skb)
78671 {
78672- return skb->prev == (struct sk_buff *)list;
78673+ return skb->prev == (const struct sk_buff *)list;
78674 }
78675
78676 /**
78677@@ -1741,7 +1741,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
78678 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
78679 */
78680 #ifndef NET_SKB_PAD
78681-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
78682+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
78683 #endif
78684
78685 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
78686@@ -2339,7 +2339,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
78687 int noblock, int *err);
78688 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
78689 struct poll_table_struct *wait);
78690-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
78691+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
78692 int offset, struct iovec *to,
78693 int size);
78694 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
78695@@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
78696 nf_bridge_put(skb->nf_bridge);
78697 skb->nf_bridge = NULL;
78698 #endif
78699+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
78700+ skb->nf_trace = 0;
78701+#endif
78702 }
78703
78704 static inline void nf_reset_trace(struct sk_buff *skb)
78705diff --git a/include/linux/slab.h b/include/linux/slab.h
78706index 74f1058..914b7da 100644
78707--- a/include/linux/slab.h
78708+++ b/include/linux/slab.h
78709@@ -14,15 +14,29 @@
78710 #include <linux/gfp.h>
78711 #include <linux/types.h>
78712 #include <linux/workqueue.h>
78713-
78714+#include <linux/err.h>
78715
78716 /*
78717 * Flags to pass to kmem_cache_create().
78718 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
78719 */
78720 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
78721+
78722+#ifdef CONFIG_PAX_USERCOPY_SLABS
78723+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
78724+#else
78725+#define SLAB_USERCOPY 0x00000000UL
78726+#endif
78727+
78728 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
78729 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
78730+
78731+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78732+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
78733+#else
78734+#define SLAB_NO_SANITIZE 0x00000000UL
78735+#endif
78736+
78737 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
78738 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
78739 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
78740@@ -91,10 +105,13 @@
78741 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
78742 * Both make kfree a no-op.
78743 */
78744-#define ZERO_SIZE_PTR ((void *)16)
78745+#define ZERO_SIZE_PTR \
78746+({ \
78747+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
78748+ (void *)(-MAX_ERRNO-1L); \
78749+})
78750
78751-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
78752- (unsigned long)ZERO_SIZE_PTR)
78753+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
78754
78755 #include <linux/kmemleak.h>
78756
78757@@ -135,6 +152,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
78758 void kfree(const void *);
78759 void kzfree(const void *);
78760 size_t ksize(const void *);
78761+const char *check_heap_object(const void *ptr, unsigned long n);
78762+bool is_usercopy_object(const void *ptr);
78763
78764 /*
78765 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
78766@@ -167,7 +186,7 @@ struct kmem_cache {
78767 unsigned int align; /* Alignment as calculated */
78768 unsigned long flags; /* Active flags on the slab */
78769 const char *name; /* Slab name for sysfs */
78770- int refcount; /* Use counter */
78771+ atomic_t refcount; /* Use counter */
78772 void (*ctor)(void *); /* Called on object slot creation */
78773 struct list_head list; /* List of all slab caches on the system */
78774 };
78775@@ -241,6 +260,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
78776 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
78777 #endif
78778
78779+#ifdef CONFIG_PAX_USERCOPY_SLABS
78780+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
78781+#endif
78782+
78783 /*
78784 * Figure out which kmalloc slab an allocation of a certain size
78785 * belongs to.
78786@@ -249,7 +272,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
78787 * 2 = 120 .. 192 bytes
78788 * n = 2^(n-1) .. 2^n -1
78789 */
78790-static __always_inline int kmalloc_index(size_t size)
78791+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
78792 {
78793 if (!size)
78794 return 0;
78795@@ -292,11 +315,11 @@ static __always_inline int kmalloc_index(size_t size)
78796 }
78797 #endif /* !CONFIG_SLOB */
78798
78799-void *__kmalloc(size_t size, gfp_t flags);
78800+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
78801 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
78802
78803 #ifdef CONFIG_NUMA
78804-void *__kmalloc_node(size_t size, gfp_t flags, int node);
78805+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
78806 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
78807 #else
78808 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
78809diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
78810index e9346b4..1494959 100644
78811--- a/include/linux/slab_def.h
78812+++ b/include/linux/slab_def.h
78813@@ -36,7 +36,7 @@ struct kmem_cache {
78814 /* 4) cache creation/removal */
78815 const char *name;
78816 struct list_head list;
78817- int refcount;
78818+ atomic_t refcount;
78819 int object_size;
78820 int align;
78821
78822@@ -52,10 +52,14 @@ struct kmem_cache {
78823 unsigned long node_allocs;
78824 unsigned long node_frees;
78825 unsigned long node_overflow;
78826- atomic_t allochit;
78827- atomic_t allocmiss;
78828- atomic_t freehit;
78829- atomic_t freemiss;
78830+ atomic_unchecked_t allochit;
78831+ atomic_unchecked_t allocmiss;
78832+ atomic_unchecked_t freehit;
78833+ atomic_unchecked_t freemiss;
78834+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78835+ atomic_unchecked_t sanitized;
78836+ atomic_unchecked_t not_sanitized;
78837+#endif
78838
78839 /*
78840 * If debugging is enabled, then the allocator can add additional
78841diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
78842index cc0b67e..a0329b1 100644
78843--- a/include/linux/slub_def.h
78844+++ b/include/linux/slub_def.h
78845@@ -74,7 +74,7 @@ struct kmem_cache {
78846 struct kmem_cache_order_objects max;
78847 struct kmem_cache_order_objects min;
78848 gfp_t allocflags; /* gfp flags to use on each alloc */
78849- int refcount; /* Refcount for slab cache destroy */
78850+ atomic_t refcount; /* Refcount for slab cache destroy */
78851 void (*ctor)(void *);
78852 int inuse; /* Offset to metadata */
78853 int align; /* Alignment */
78854diff --git a/include/linux/smp.h b/include/linux/smp.h
78855index 731f523..3340268 100644
78856--- a/include/linux/smp.h
78857+++ b/include/linux/smp.h
78858@@ -186,7 +186,9 @@ static inline void __smp_call_function_single(int cpuid,
78859 #endif
78860
78861 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
78862+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
78863 #define put_cpu() preempt_enable()
78864+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
78865
78866 /*
78867 * Callback to arch code if there's nosmp or maxcpus=0 on the
78868diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
78869index 54f91d3..be2c379 100644
78870--- a/include/linux/sock_diag.h
78871+++ b/include/linux/sock_diag.h
78872@@ -11,7 +11,7 @@ struct sock;
78873 struct sock_diag_handler {
78874 __u8 family;
78875 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
78876-};
78877+} __do_const;
78878
78879 int sock_diag_register(const struct sock_diag_handler *h);
78880 void sock_diag_unregister(const struct sock_diag_handler *h);
78881diff --git a/include/linux/sonet.h b/include/linux/sonet.h
78882index 680f9a3..f13aeb0 100644
78883--- a/include/linux/sonet.h
78884+++ b/include/linux/sonet.h
78885@@ -7,7 +7,7 @@
78886 #include <uapi/linux/sonet.h>
78887
78888 struct k_sonet_stats {
78889-#define __HANDLE_ITEM(i) atomic_t i
78890+#define __HANDLE_ITEM(i) atomic_unchecked_t i
78891 __SONET_ITEMS
78892 #undef __HANDLE_ITEM
78893 };
78894diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
78895index 07d8e53..dc934c9 100644
78896--- a/include/linux/sunrpc/addr.h
78897+++ b/include/linux/sunrpc/addr.h
78898@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
78899 {
78900 switch (sap->sa_family) {
78901 case AF_INET:
78902- return ntohs(((struct sockaddr_in *)sap)->sin_port);
78903+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
78904 case AF_INET6:
78905- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
78906+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
78907 }
78908 return 0;
78909 }
78910@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
78911 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
78912 const struct sockaddr *src)
78913 {
78914- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
78915+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
78916 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
78917
78918 dsin->sin_family = ssin->sin_family;
78919@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
78920 if (sa->sa_family != AF_INET6)
78921 return 0;
78922
78923- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
78924+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
78925 }
78926
78927 #endif /* _LINUX_SUNRPC_ADDR_H */
78928diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
78929index 6740801..c535f27 100644
78930--- a/include/linux/sunrpc/clnt.h
78931+++ b/include/linux/sunrpc/clnt.h
78932@@ -96,7 +96,7 @@ struct rpc_procinfo {
78933 unsigned int p_timer; /* Which RTT timer to use */
78934 u32 p_statidx; /* Which procedure to account */
78935 const char * p_name; /* name of procedure */
78936-};
78937+} __do_const;
78938
78939 #ifdef __KERNEL__
78940
78941diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
78942index 6eecfc2..7ada79d 100644
78943--- a/include/linux/sunrpc/svc.h
78944+++ b/include/linux/sunrpc/svc.h
78945@@ -410,7 +410,7 @@ struct svc_procedure {
78946 unsigned int pc_count; /* call count */
78947 unsigned int pc_cachetype; /* cache info (NFS) */
78948 unsigned int pc_xdrressize; /* maximum size of XDR reply */
78949-};
78950+} __do_const;
78951
78952 /*
78953 * Function prototypes.
78954diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
78955index 0b8e3e6..33e0a01 100644
78956--- a/include/linux/sunrpc/svc_rdma.h
78957+++ b/include/linux/sunrpc/svc_rdma.h
78958@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
78959 extern unsigned int svcrdma_max_requests;
78960 extern unsigned int svcrdma_max_req_size;
78961
78962-extern atomic_t rdma_stat_recv;
78963-extern atomic_t rdma_stat_read;
78964-extern atomic_t rdma_stat_write;
78965-extern atomic_t rdma_stat_sq_starve;
78966-extern atomic_t rdma_stat_rq_starve;
78967-extern atomic_t rdma_stat_rq_poll;
78968-extern atomic_t rdma_stat_rq_prod;
78969-extern atomic_t rdma_stat_sq_poll;
78970-extern atomic_t rdma_stat_sq_prod;
78971+extern atomic_unchecked_t rdma_stat_recv;
78972+extern atomic_unchecked_t rdma_stat_read;
78973+extern atomic_unchecked_t rdma_stat_write;
78974+extern atomic_unchecked_t rdma_stat_sq_starve;
78975+extern atomic_unchecked_t rdma_stat_rq_starve;
78976+extern atomic_unchecked_t rdma_stat_rq_poll;
78977+extern atomic_unchecked_t rdma_stat_rq_prod;
78978+extern atomic_unchecked_t rdma_stat_sq_poll;
78979+extern atomic_unchecked_t rdma_stat_sq_prod;
78980
78981 #define RPCRDMA_VERSION 1
78982
78983diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
78984index 8d71d65..f79586e 100644
78985--- a/include/linux/sunrpc/svcauth.h
78986+++ b/include/linux/sunrpc/svcauth.h
78987@@ -120,7 +120,7 @@ struct auth_ops {
78988 int (*release)(struct svc_rqst *rq);
78989 void (*domain_release)(struct auth_domain *);
78990 int (*set_client)(struct svc_rqst *rq);
78991-};
78992+} __do_const;
78993
78994 #define SVC_GARBAGE 1
78995 #define SVC_SYSERR 2
78996diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
78997index a5ffd32..0935dea 100644
78998--- a/include/linux/swiotlb.h
78999+++ b/include/linux/swiotlb.h
79000@@ -60,7 +60,8 @@ extern void
79001
79002 extern void
79003 swiotlb_free_coherent(struct device *hwdev, size_t size,
79004- void *vaddr, dma_addr_t dma_handle);
79005+ void *vaddr, dma_addr_t dma_handle,
79006+ struct dma_attrs *attrs);
79007
79008 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
79009 unsigned long offset, size_t size,
79010diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
79011index 7fac04e..de57300 100644
79012--- a/include/linux/syscalls.h
79013+++ b/include/linux/syscalls.h
79014@@ -97,8 +97,14 @@ struct sigaltstack;
79015 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
79016
79017 #define __SC_DECL(t, a) t a
79018+#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))
79019 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
79020-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
79021+#define __SC_LONG(t, a) __typeof( \
79022+ __builtin_choose_expr( \
79023+ sizeof(t) > sizeof(int), \
79024+ (t) 0, \
79025+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
79026+ )) a
79027 #define __SC_CAST(t, a) (t) a
79028 #define __SC_ARGS(t, a) a
79029 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
79030@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
79031 asmlinkage long sys_fsync(unsigned int fd);
79032 asmlinkage long sys_fdatasync(unsigned int fd);
79033 asmlinkage long sys_bdflush(int func, long data);
79034-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
79035- char __user *type, unsigned long flags,
79036+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
79037+ const char __user *type, unsigned long flags,
79038 void __user *data);
79039-asmlinkage long sys_umount(char __user *name, int flags);
79040-asmlinkage long sys_oldumount(char __user *name);
79041+asmlinkage long sys_umount(const char __user *name, int flags);
79042+asmlinkage long sys_oldumount(const char __user *name);
79043 asmlinkage long sys_truncate(const char __user *path, long length);
79044 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
79045 asmlinkage long sys_stat(const char __user *filename,
79046@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
79047 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
79048 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
79049 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
79050- struct sockaddr __user *, int);
79051+ struct sockaddr __user *, int) __intentional_overflow(0);
79052 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
79053 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
79054 unsigned int vlen, unsigned flags);
79055diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
79056index 27b3b0b..e093dd9 100644
79057--- a/include/linux/syscore_ops.h
79058+++ b/include/linux/syscore_ops.h
79059@@ -16,7 +16,7 @@ struct syscore_ops {
79060 int (*suspend)(void);
79061 void (*resume)(void);
79062 void (*shutdown)(void);
79063-};
79064+} __do_const;
79065
79066 extern void register_syscore_ops(struct syscore_ops *ops);
79067 extern void unregister_syscore_ops(struct syscore_ops *ops);
79068diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
79069index 14a8ff2..af52bad 100644
79070--- a/include/linux/sysctl.h
79071+++ b/include/linux/sysctl.h
79072@@ -34,13 +34,13 @@ struct ctl_table_root;
79073 struct ctl_table_header;
79074 struct ctl_dir;
79075
79076-typedef struct ctl_table ctl_table;
79077-
79078 typedef int proc_handler (struct ctl_table *ctl, int write,
79079 void __user *buffer, size_t *lenp, loff_t *ppos);
79080
79081 extern int proc_dostring(struct ctl_table *, int,
79082 void __user *, size_t *, loff_t *);
79083+extern int proc_dostring_modpriv(struct ctl_table *, int,
79084+ void __user *, size_t *, loff_t *);
79085 extern int proc_dointvec(struct ctl_table *, int,
79086 void __user *, size_t *, loff_t *);
79087 extern int proc_dointvec_minmax(struct ctl_table *, int,
79088@@ -115,7 +115,9 @@ struct ctl_table
79089 struct ctl_table_poll *poll;
79090 void *extra1;
79091 void *extra2;
79092-};
79093+} __do_const;
79094+typedef struct ctl_table __no_const ctl_table_no_const;
79095+typedef struct ctl_table ctl_table;
79096
79097 struct ctl_node {
79098 struct rb_node node;
79099diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
79100index 11baec7..706f99f 100644
79101--- a/include/linux/sysfs.h
79102+++ b/include/linux/sysfs.h
79103@@ -33,7 +33,8 @@ struct attribute {
79104 struct lock_class_key *key;
79105 struct lock_class_key skey;
79106 #endif
79107-};
79108+} __do_const;
79109+typedef struct attribute __no_const attribute_no_const;
79110
79111 /**
79112 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
79113@@ -62,7 +63,8 @@ struct attribute_group {
79114 struct attribute *, int);
79115 struct attribute **attrs;
79116 struct bin_attribute **bin_attrs;
79117-};
79118+} __do_const;
79119+typedef struct attribute_group __no_const attribute_group_no_const;
79120
79121 /**
79122 * Use these macros to make defining attributes easier. See include/linux/device.h
79123@@ -126,7 +128,8 @@ struct bin_attribute {
79124 char *, loff_t, size_t);
79125 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
79126 struct vm_area_struct *vma);
79127-};
79128+} __do_const;
79129+typedef struct bin_attribute __no_const bin_attribute_no_const;
79130
79131 /**
79132 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
79133diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
79134index 7faf933..9b85a0c 100644
79135--- a/include/linux/sysrq.h
79136+++ b/include/linux/sysrq.h
79137@@ -16,6 +16,7 @@
79138
79139 #include <linux/errno.h>
79140 #include <linux/types.h>
79141+#include <linux/compiler.h>
79142
79143 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
79144 #define SYSRQ_DEFAULT_ENABLE 1
79145@@ -36,7 +37,7 @@ struct sysrq_key_op {
79146 char *help_msg;
79147 char *action_msg;
79148 int enable_mask;
79149-};
79150+} __do_const;
79151
79152 #ifdef CONFIG_MAGIC_SYSRQ
79153
79154diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
79155index 4ae6f32..425d3e1 100644
79156--- a/include/linux/thread_info.h
79157+++ b/include/linux/thread_info.h
79158@@ -150,6 +150,15 @@ static inline bool test_and_clear_restore_sigmask(void)
79159 #error "no set_restore_sigmask() provided and default one won't work"
79160 #endif
79161
79162+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
79163+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
79164+{
79165+#ifndef CONFIG_PAX_USERCOPY_DEBUG
79166+ if (!__builtin_constant_p(n))
79167+#endif
79168+ __check_object_size(ptr, n, to_user);
79169+}
79170+
79171 #endif /* __KERNEL__ */
79172
79173 #endif /* _LINUX_THREAD_INFO_H */
79174diff --git a/include/linux/tty.h b/include/linux/tty.h
79175index 64f8646..1515fc7 100644
79176--- a/include/linux/tty.h
79177+++ b/include/linux/tty.h
79178@@ -197,7 +197,7 @@ struct tty_port {
79179 const struct tty_port_operations *ops; /* Port operations */
79180 spinlock_t lock; /* Lock protecting tty field */
79181 int blocked_open; /* Waiting to open */
79182- int count; /* Usage count */
79183+ atomic_t count; /* Usage count */
79184 wait_queue_head_t open_wait; /* Open waiters */
79185 wait_queue_head_t close_wait; /* Close waiters */
79186 wait_queue_head_t delta_msr_wait; /* Modem status change */
79187@@ -546,7 +546,7 @@ extern int tty_port_open(struct tty_port *port,
79188 struct tty_struct *tty, struct file *filp);
79189 static inline int tty_port_users(struct tty_port *port)
79190 {
79191- return port->count + port->blocked_open;
79192+ return atomic_read(&port->count) + port->blocked_open;
79193 }
79194
79195 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
79196diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
79197index 756a609..b302dd6 100644
79198--- a/include/linux/tty_driver.h
79199+++ b/include/linux/tty_driver.h
79200@@ -285,7 +285,7 @@ struct tty_operations {
79201 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
79202 #endif
79203 const struct file_operations *proc_fops;
79204-};
79205+} __do_const;
79206
79207 struct tty_driver {
79208 int magic; /* magic number for this structure */
79209diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
79210index f15c898..207b7d1 100644
79211--- a/include/linux/tty_ldisc.h
79212+++ b/include/linux/tty_ldisc.h
79213@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
79214
79215 struct module *owner;
79216
79217- int refcount;
79218+ atomic_t refcount;
79219 };
79220
79221 struct tty_ldisc {
79222diff --git a/include/linux/types.h b/include/linux/types.h
79223index 4d118ba..c3ee9bf 100644
79224--- a/include/linux/types.h
79225+++ b/include/linux/types.h
79226@@ -176,10 +176,26 @@ typedef struct {
79227 int counter;
79228 } atomic_t;
79229
79230+#ifdef CONFIG_PAX_REFCOUNT
79231+typedef struct {
79232+ int counter;
79233+} atomic_unchecked_t;
79234+#else
79235+typedef atomic_t atomic_unchecked_t;
79236+#endif
79237+
79238 #ifdef CONFIG_64BIT
79239 typedef struct {
79240 long counter;
79241 } atomic64_t;
79242+
79243+#ifdef CONFIG_PAX_REFCOUNT
79244+typedef struct {
79245+ long counter;
79246+} atomic64_unchecked_t;
79247+#else
79248+typedef atomic64_t atomic64_unchecked_t;
79249+#endif
79250 #endif
79251
79252 struct list_head {
79253diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
79254index 5ca0951..ab496a5 100644
79255--- a/include/linux/uaccess.h
79256+++ b/include/linux/uaccess.h
79257@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
79258 long ret; \
79259 mm_segment_t old_fs = get_fs(); \
79260 \
79261- set_fs(KERNEL_DS); \
79262 pagefault_disable(); \
79263- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
79264- pagefault_enable(); \
79265+ set_fs(KERNEL_DS); \
79266+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
79267 set_fs(old_fs); \
79268+ pagefault_enable(); \
79269 ret; \
79270 })
79271
79272diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
79273index 8e522cbc..aa8572d 100644
79274--- a/include/linux/uidgid.h
79275+++ b/include/linux/uidgid.h
79276@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
79277
79278 #endif /* CONFIG_USER_NS */
79279
79280+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
79281+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
79282+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
79283+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
79284+
79285 #endif /* _LINUX_UIDGID_H */
79286diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
79287index 99c1b4d..562e6f3 100644
79288--- a/include/linux/unaligned/access_ok.h
79289+++ b/include/linux/unaligned/access_ok.h
79290@@ -4,34 +4,34 @@
79291 #include <linux/kernel.h>
79292 #include <asm/byteorder.h>
79293
79294-static inline u16 get_unaligned_le16(const void *p)
79295+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
79296 {
79297- return le16_to_cpup((__le16 *)p);
79298+ return le16_to_cpup((const __le16 *)p);
79299 }
79300
79301-static inline u32 get_unaligned_le32(const void *p)
79302+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
79303 {
79304- return le32_to_cpup((__le32 *)p);
79305+ return le32_to_cpup((const __le32 *)p);
79306 }
79307
79308-static inline u64 get_unaligned_le64(const void *p)
79309+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
79310 {
79311- return le64_to_cpup((__le64 *)p);
79312+ return le64_to_cpup((const __le64 *)p);
79313 }
79314
79315-static inline u16 get_unaligned_be16(const void *p)
79316+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
79317 {
79318- return be16_to_cpup((__be16 *)p);
79319+ return be16_to_cpup((const __be16 *)p);
79320 }
79321
79322-static inline u32 get_unaligned_be32(const void *p)
79323+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
79324 {
79325- return be32_to_cpup((__be32 *)p);
79326+ return be32_to_cpup((const __be32 *)p);
79327 }
79328
79329-static inline u64 get_unaligned_be64(const void *p)
79330+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
79331 {
79332- return be64_to_cpup((__be64 *)p);
79333+ return be64_to_cpup((const __be64 *)p);
79334 }
79335
79336 static inline void put_unaligned_le16(u16 val, void *p)
79337diff --git a/include/linux/usb.h b/include/linux/usb.h
79338index 6b02370..2355ffa 100644
79339--- a/include/linux/usb.h
79340+++ b/include/linux/usb.h
79341@@ -563,7 +563,7 @@ struct usb_device {
79342 int maxchild;
79343
79344 u32 quirks;
79345- atomic_t urbnum;
79346+ atomic_unchecked_t urbnum;
79347
79348 unsigned long active_duration;
79349
79350@@ -1639,7 +1639,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
79351
79352 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
79353 __u8 request, __u8 requesttype, __u16 value, __u16 index,
79354- void *data, __u16 size, int timeout);
79355+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
79356 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
79357 void *data, int len, int *actual_length, int timeout);
79358 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
79359diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
79360index e452ba6..78f8e80 100644
79361--- a/include/linux/usb/renesas_usbhs.h
79362+++ b/include/linux/usb/renesas_usbhs.h
79363@@ -39,7 +39,7 @@ enum {
79364 */
79365 struct renesas_usbhs_driver_callback {
79366 int (*notify_hotplug)(struct platform_device *pdev);
79367-};
79368+} __no_const;
79369
79370 /*
79371 * callback functions for platform
79372diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
79373index 6f8fbcf..8259001 100644
79374--- a/include/linux/vermagic.h
79375+++ b/include/linux/vermagic.h
79376@@ -25,9 +25,35 @@
79377 #define MODULE_ARCH_VERMAGIC ""
79378 #endif
79379
79380+#ifdef CONFIG_PAX_REFCOUNT
79381+#define MODULE_PAX_REFCOUNT "REFCOUNT "
79382+#else
79383+#define MODULE_PAX_REFCOUNT ""
79384+#endif
79385+
79386+#ifdef CONSTIFY_PLUGIN
79387+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
79388+#else
79389+#define MODULE_CONSTIFY_PLUGIN ""
79390+#endif
79391+
79392+#ifdef STACKLEAK_PLUGIN
79393+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
79394+#else
79395+#define MODULE_STACKLEAK_PLUGIN ""
79396+#endif
79397+
79398+#ifdef CONFIG_GRKERNSEC
79399+#define MODULE_GRSEC "GRSEC "
79400+#else
79401+#define MODULE_GRSEC ""
79402+#endif
79403+
79404 #define VERMAGIC_STRING \
79405 UTS_RELEASE " " \
79406 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
79407 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
79408- MODULE_ARCH_VERMAGIC
79409+ MODULE_ARCH_VERMAGIC \
79410+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
79411+ MODULE_GRSEC
79412
79413diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
79414index 502073a..a7de024 100644
79415--- a/include/linux/vga_switcheroo.h
79416+++ b/include/linux/vga_switcheroo.h
79417@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
79418
79419 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
79420
79421-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
79422-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
79423+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
79424+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
79425 #else
79426
79427 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
79428@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
79429
79430 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
79431
79432-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
79433-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
79434+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
79435+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
79436
79437 #endif
79438 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
79439diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
79440index 4b8a891..cb8df6e 100644
79441--- a/include/linux/vmalloc.h
79442+++ b/include/linux/vmalloc.h
79443@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
79444 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
79445 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
79446 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
79447+
79448+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79449+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
79450+#endif
79451+
79452 /* bits [20..32] reserved for arch specific ioremap internals */
79453
79454 /*
79455@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
79456
79457 /* for /dev/kmem */
79458 extern long vread(char *buf, char *addr, unsigned long count);
79459-extern long vwrite(char *buf, char *addr, unsigned long count);
79460+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
79461
79462 /*
79463 * Internals. Dont't use..
79464diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
79465index e4b9480..5a5f65a 100644
79466--- a/include/linux/vmstat.h
79467+++ b/include/linux/vmstat.h
79468@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
79469 /*
79470 * Zone based page accounting with per cpu differentials.
79471 */
79472-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79473+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79474
79475 static inline void zone_page_state_add(long x, struct zone *zone,
79476 enum zone_stat_item item)
79477 {
79478- atomic_long_add(x, &zone->vm_stat[item]);
79479- atomic_long_add(x, &vm_stat[item]);
79480+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
79481+ atomic_long_add_unchecked(x, &vm_stat[item]);
79482 }
79483
79484-static inline unsigned long global_page_state(enum zone_stat_item item)
79485+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
79486 {
79487- long x = atomic_long_read(&vm_stat[item]);
79488+ long x = atomic_long_read_unchecked(&vm_stat[item]);
79489 #ifdef CONFIG_SMP
79490 if (x < 0)
79491 x = 0;
79492@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
79493 return x;
79494 }
79495
79496-static inline unsigned long zone_page_state(struct zone *zone,
79497+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
79498 enum zone_stat_item item)
79499 {
79500- long x = atomic_long_read(&zone->vm_stat[item]);
79501+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
79502 #ifdef CONFIG_SMP
79503 if (x < 0)
79504 x = 0;
79505@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
79506 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
79507 enum zone_stat_item item)
79508 {
79509- long x = atomic_long_read(&zone->vm_stat[item]);
79510+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
79511
79512 #ifdef CONFIG_SMP
79513 int cpu;
79514@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
79515
79516 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
79517 {
79518- atomic_long_inc(&zone->vm_stat[item]);
79519- atomic_long_inc(&vm_stat[item]);
79520+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
79521+ atomic_long_inc_unchecked(&vm_stat[item]);
79522 }
79523
79524 static inline void __inc_zone_page_state(struct page *page,
79525@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
79526
79527 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
79528 {
79529- atomic_long_dec(&zone->vm_stat[item]);
79530- atomic_long_dec(&vm_stat[item]);
79531+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
79532+ atomic_long_dec_unchecked(&vm_stat[item]);
79533 }
79534
79535 static inline void __dec_zone_page_state(struct page *page,
79536diff --git a/include/linux/xattr.h b/include/linux/xattr.h
79537index 91b0a68..0e9adf6 100644
79538--- a/include/linux/xattr.h
79539+++ b/include/linux/xattr.h
79540@@ -28,7 +28,7 @@ struct xattr_handler {
79541 size_t size, int handler_flags);
79542 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
79543 size_t size, int flags, int handler_flags);
79544-};
79545+} __do_const;
79546
79547 struct xattr {
79548 const char *name;
79549@@ -37,6 +37,9 @@ struct xattr {
79550 };
79551
79552 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
79553+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
79554+ssize_t pax_getxattr(struct dentry *, void *, size_t);
79555+#endif
79556 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
79557 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
79558 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
79559diff --git a/include/linux/zlib.h b/include/linux/zlib.h
79560index 9c5a6b4..09c9438 100644
79561--- a/include/linux/zlib.h
79562+++ b/include/linux/zlib.h
79563@@ -31,6 +31,7 @@
79564 #define _ZLIB_H
79565
79566 #include <linux/zconf.h>
79567+#include <linux/compiler.h>
79568
79569 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
79570 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
79571@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
79572
79573 /* basic functions */
79574
79575-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
79576+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
79577 /*
79578 Returns the number of bytes that needs to be allocated for a per-
79579 stream workspace with the specified parameters. A pointer to this
79580diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
79581index c768c9f..bdcaa5a 100644
79582--- a/include/media/v4l2-dev.h
79583+++ b/include/media/v4l2-dev.h
79584@@ -76,7 +76,7 @@ struct v4l2_file_operations {
79585 int (*mmap) (struct file *, struct vm_area_struct *);
79586 int (*open) (struct file *);
79587 int (*release) (struct file *);
79588-};
79589+} __do_const;
79590
79591 /*
79592 * Newer version of video_device, handled by videodev2.c
79593diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
79594index c9b1593..a572459 100644
79595--- a/include/media/v4l2-device.h
79596+++ b/include/media/v4l2-device.h
79597@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
79598 this function returns 0. If the name ends with a digit (e.g. cx18),
79599 then the name will be set to cx18-0 since cx180 looks really odd. */
79600 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
79601- atomic_t *instance);
79602+ atomic_unchecked_t *instance);
79603
79604 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
79605 Since the parent disappears this ensures that v4l2_dev doesn't have an
79606diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
79607index 9a36d92..0aafe2a 100644
79608--- a/include/net/9p/transport.h
79609+++ b/include/net/9p/transport.h
79610@@ -60,7 +60,7 @@ struct p9_trans_module {
79611 int (*cancel) (struct p9_client *, struct p9_req_t *req);
79612 int (*zc_request)(struct p9_client *, struct p9_req_t *,
79613 char *, char *, int , int, int, int);
79614-};
79615+} __do_const;
79616
79617 void v9fs_register_trans(struct p9_trans_module *m);
79618 void v9fs_unregister_trans(struct p9_trans_module *m);
79619diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
79620index 1a966af..2767cf6 100644
79621--- a/include/net/bluetooth/l2cap.h
79622+++ b/include/net/bluetooth/l2cap.h
79623@@ -551,7 +551,7 @@ struct l2cap_ops {
79624 void (*defer) (struct l2cap_chan *chan);
79625 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
79626 unsigned long len, int nb);
79627-};
79628+} __do_const;
79629
79630 struct l2cap_conn {
79631 struct hci_conn *hcon;
79632diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
79633index f2ae33d..c457cf0 100644
79634--- a/include/net/caif/cfctrl.h
79635+++ b/include/net/caif/cfctrl.h
79636@@ -52,7 +52,7 @@ struct cfctrl_rsp {
79637 void (*radioset_rsp)(void);
79638 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
79639 struct cflayer *client_layer);
79640-};
79641+} __no_const;
79642
79643 /* Link Setup Parameters for CAIF-Links. */
79644 struct cfctrl_link_param {
79645@@ -101,8 +101,8 @@ struct cfctrl_request_info {
79646 struct cfctrl {
79647 struct cfsrvl serv;
79648 struct cfctrl_rsp res;
79649- atomic_t req_seq_no;
79650- atomic_t rsp_seq_no;
79651+ atomic_unchecked_t req_seq_no;
79652+ atomic_unchecked_t rsp_seq_no;
79653 struct list_head list;
79654 /* Protects from simultaneous access to first_req list */
79655 spinlock_t info_list_lock;
79656diff --git a/include/net/flow.h b/include/net/flow.h
79657index 628e11b..4c475df 100644
79658--- a/include/net/flow.h
79659+++ b/include/net/flow.h
79660@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
79661
79662 extern void flow_cache_flush(void);
79663 extern void flow_cache_flush_deferred(void);
79664-extern atomic_t flow_cache_genid;
79665+extern atomic_unchecked_t flow_cache_genid;
79666
79667 #endif
79668diff --git a/include/net/genetlink.h b/include/net/genetlink.h
79669index 8e0b6c8..73cf605 100644
79670--- a/include/net/genetlink.h
79671+++ b/include/net/genetlink.h
79672@@ -120,7 +120,7 @@ struct genl_ops {
79673 struct netlink_callback *cb);
79674 int (*done)(struct netlink_callback *cb);
79675 struct list_head ops_list;
79676-};
79677+} __do_const;
79678
79679 extern int __genl_register_family(struct genl_family *family);
79680
79681diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
79682index 734d9b5..48a9a4b 100644
79683--- a/include/net/gro_cells.h
79684+++ b/include/net/gro_cells.h
79685@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
79686 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
79687
79688 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
79689- atomic_long_inc(&dev->rx_dropped);
79690+ atomic_long_inc_unchecked(&dev->rx_dropped);
79691 kfree_skb(skb);
79692 return;
79693 }
79694diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
79695index de2c785..0588a6b 100644
79696--- a/include/net/inet_connection_sock.h
79697+++ b/include/net/inet_connection_sock.h
79698@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
79699 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
79700 int (*bind_conflict)(const struct sock *sk,
79701 const struct inet_bind_bucket *tb, bool relax);
79702-};
79703+} __do_const;
79704
79705 /** inet_connection_sock - INET connection oriented sock
79706 *
79707diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
79708index 53f464d..0bd0b49 100644
79709--- a/include/net/inetpeer.h
79710+++ b/include/net/inetpeer.h
79711@@ -47,8 +47,8 @@ struct inet_peer {
79712 */
79713 union {
79714 struct {
79715- atomic_t rid; /* Frag reception counter */
79716- atomic_t ip_id_count; /* IP ID for the next packet */
79717+ atomic_unchecked_t rid; /* Frag reception counter */
79718+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
79719 };
79720 struct rcu_head rcu;
79721 struct inet_peer *gc_next;
79722@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
79723 /* can be called with or without local BH being disabled */
79724 static inline int inet_getid(struct inet_peer *p, int more)
79725 {
79726- int old, new;
79727+ int id;
79728 more++;
79729 inet_peer_refcheck(p);
79730- do {
79731- old = atomic_read(&p->ip_id_count);
79732- new = old + more;
79733- if (!new)
79734- new = 1;
79735- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
79736- return new;
79737+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
79738+ if (!id)
79739+ id = atomic_inc_return_unchecked(&p->ip_id_count);
79740+ return id;
79741 }
79742
79743 #endif /* _NET_INETPEER_H */
79744diff --git a/include/net/ip.h b/include/net/ip.h
79745index 301f10c..b52cdaf 100644
79746--- a/include/net/ip.h
79747+++ b/include/net/ip.h
79748@@ -212,7 +212,7 @@ extern struct local_ports {
79749 } sysctl_local_ports;
79750 extern void inet_get_local_port_range(int *low, int *high);
79751
79752-extern unsigned long *sysctl_local_reserved_ports;
79753+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
79754 static inline int inet_is_reserved_local_port(int port)
79755 {
79756 return test_bit(port, sysctl_local_reserved_ports);
79757diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
79758index cbf2be3..3683f6d 100644
79759--- a/include/net/ip_fib.h
79760+++ b/include/net/ip_fib.h
79761@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
79762
79763 #define FIB_RES_SADDR(net, res) \
79764 ((FIB_RES_NH(res).nh_saddr_genid == \
79765- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
79766+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
79767 FIB_RES_NH(res).nh_saddr : \
79768 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
79769 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
79770diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
79771index 772252d..1e69799 100644
79772--- a/include/net/ip_vs.h
79773+++ b/include/net/ip_vs.h
79774@@ -558,7 +558,7 @@ struct ip_vs_conn {
79775 struct ip_vs_conn *control; /* Master control connection */
79776 atomic_t n_control; /* Number of controlled ones */
79777 struct ip_vs_dest *dest; /* real server */
79778- atomic_t in_pkts; /* incoming packet counter */
79779+ atomic_unchecked_t in_pkts; /* incoming packet counter */
79780
79781 /* packet transmitter for different forwarding methods. If it
79782 mangles the packet, it must return NF_DROP or better NF_STOLEN,
79783@@ -705,7 +705,7 @@ struct ip_vs_dest {
79784 __be16 port; /* port number of the server */
79785 union nf_inet_addr addr; /* IP address of the server */
79786 volatile unsigned int flags; /* dest status flags */
79787- atomic_t conn_flags; /* flags to copy to conn */
79788+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
79789 atomic_t weight; /* server weight */
79790
79791 atomic_t refcnt; /* reference counter */
79792@@ -960,11 +960,11 @@ struct netns_ipvs {
79793 /* ip_vs_lblc */
79794 int sysctl_lblc_expiration;
79795 struct ctl_table_header *lblc_ctl_header;
79796- struct ctl_table *lblc_ctl_table;
79797+ ctl_table_no_const *lblc_ctl_table;
79798 /* ip_vs_lblcr */
79799 int sysctl_lblcr_expiration;
79800 struct ctl_table_header *lblcr_ctl_header;
79801- struct ctl_table *lblcr_ctl_table;
79802+ ctl_table_no_const *lblcr_ctl_table;
79803 /* ip_vs_est */
79804 struct list_head est_list; /* estimator list */
79805 spinlock_t est_lock;
79806diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
79807index 80ffde3..968b0f4 100644
79808--- a/include/net/irda/ircomm_tty.h
79809+++ b/include/net/irda/ircomm_tty.h
79810@@ -35,6 +35,7 @@
79811 #include <linux/termios.h>
79812 #include <linux/timer.h>
79813 #include <linux/tty.h> /* struct tty_struct */
79814+#include <asm/local.h>
79815
79816 #include <net/irda/irias_object.h>
79817 #include <net/irda/ircomm_core.h>
79818diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
79819index 714cc9a..ea05f3e 100644
79820--- a/include/net/iucv/af_iucv.h
79821+++ b/include/net/iucv/af_iucv.h
79822@@ -149,7 +149,7 @@ struct iucv_skb_cb {
79823 struct iucv_sock_list {
79824 struct hlist_head head;
79825 rwlock_t lock;
79826- atomic_t autobind_name;
79827+ atomic_unchecked_t autobind_name;
79828 };
79829
79830 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
79831diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
79832index df83f69..9b640b8 100644
79833--- a/include/net/llc_c_ac.h
79834+++ b/include/net/llc_c_ac.h
79835@@ -87,7 +87,7 @@
79836 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
79837 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
79838
79839-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79840+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79841
79842 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
79843 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
79844diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
79845index 6ca3113..f8026dd 100644
79846--- a/include/net/llc_c_ev.h
79847+++ b/include/net/llc_c_ev.h
79848@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
79849 return (struct llc_conn_state_ev *)skb->cb;
79850 }
79851
79852-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79853-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79854+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79855+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79856
79857 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
79858 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
79859diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
79860index 0e79cfb..f46db31 100644
79861--- a/include/net/llc_c_st.h
79862+++ b/include/net/llc_c_st.h
79863@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
79864 u8 next_state;
79865 llc_conn_ev_qfyr_t *ev_qualifiers;
79866 llc_conn_action_t *ev_actions;
79867-};
79868+} __do_const;
79869
79870 struct llc_conn_state {
79871 u8 current_state;
79872diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
79873index 37a3bbd..55a4241 100644
79874--- a/include/net/llc_s_ac.h
79875+++ b/include/net/llc_s_ac.h
79876@@ -23,7 +23,7 @@
79877 #define SAP_ACT_TEST_IND 9
79878
79879 /* All action functions must look like this */
79880-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79881+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79882
79883 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
79884 struct sk_buff *skb);
79885diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
79886index 567c681..cd73ac0 100644
79887--- a/include/net/llc_s_st.h
79888+++ b/include/net/llc_s_st.h
79889@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
79890 llc_sap_ev_t ev;
79891 u8 next_state;
79892 llc_sap_action_t *ev_actions;
79893-};
79894+} __do_const;
79895
79896 struct llc_sap_state {
79897 u8 curr_state;
79898diff --git a/include/net/mac80211.h b/include/net/mac80211.h
79899index cc6035f..a8406fc 100644
79900--- a/include/net/mac80211.h
79901+++ b/include/net/mac80211.h
79902@@ -4361,7 +4361,7 @@ struct rate_control_ops {
79903 void (*add_sta_debugfs)(void *priv, void *priv_sta,
79904 struct dentry *dir);
79905 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
79906-};
79907+} __do_const;
79908
79909 static inline int rate_supported(struct ieee80211_sta *sta,
79910 enum ieee80211_band band,
79911diff --git a/include/net/neighbour.h b/include/net/neighbour.h
79912index 536501a..7c6193c 100644
79913--- a/include/net/neighbour.h
79914+++ b/include/net/neighbour.h
79915@@ -123,7 +123,7 @@ struct neigh_ops {
79916 void (*error_report)(struct neighbour *, struct sk_buff *);
79917 int (*output)(struct neighbour *, struct sk_buff *);
79918 int (*connected_output)(struct neighbour *, struct sk_buff *);
79919-};
79920+} __do_const;
79921
79922 struct pneigh_entry {
79923 struct pneigh_entry *next;
79924diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
79925index 9d22f08..980fbf8 100644
79926--- a/include/net/net_namespace.h
79927+++ b/include/net/net_namespace.h
79928@@ -120,7 +120,7 @@ struct net {
79929 struct netns_ipvs *ipvs;
79930 #endif
79931 struct sock *diag_nlsk;
79932- atomic_t fnhe_genid;
79933+ atomic_unchecked_t fnhe_genid;
79934 };
79935
79936 /*
79937@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
79938 #define __net_init __init
79939 #define __net_exit __exit_refok
79940 #define __net_initdata __initdata
79941+#ifdef CONSTIFY_PLUGIN
79942 #define __net_initconst __initconst
79943+#else
79944+#define __net_initconst __initdata
79945+#endif
79946 #endif
79947
79948 struct pernet_operations {
79949@@ -287,7 +291,7 @@ struct pernet_operations {
79950 void (*exit_batch)(struct list_head *net_exit_list);
79951 int *id;
79952 size_t size;
79953-};
79954+} __do_const;
79955
79956 /*
79957 * Use these carefully. If you implement a network device and it
79958@@ -335,23 +339,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
79959
79960 static inline int rt_genid_ipv4(struct net *net)
79961 {
79962- return atomic_read(&net->ipv4.rt_genid);
79963+ return atomic_read_unchecked(&net->ipv4.rt_genid);
79964 }
79965
79966 static inline void rt_genid_bump_ipv4(struct net *net)
79967 {
79968- atomic_inc(&net->ipv4.rt_genid);
79969+ atomic_inc_unchecked(&net->ipv4.rt_genid);
79970 }
79971
79972 #if IS_ENABLED(CONFIG_IPV6)
79973 static inline int rt_genid_ipv6(struct net *net)
79974 {
79975- return atomic_read(&net->ipv6.rt_genid);
79976+ return atomic_read_unchecked(&net->ipv6.rt_genid);
79977 }
79978
79979 static inline void rt_genid_bump_ipv6(struct net *net)
79980 {
79981- atomic_inc(&net->ipv6.rt_genid);
79982+ atomic_inc_unchecked(&net->ipv6.rt_genid);
79983 }
79984 #else
79985 static inline int rt_genid_ipv6(struct net *net)
79986@@ -373,12 +377,12 @@ static inline void rt_genid_bump_all(struct net *net)
79987
79988 static inline int fnhe_genid(struct net *net)
79989 {
79990- return atomic_read(&net->fnhe_genid);
79991+ return atomic_read_unchecked(&net->fnhe_genid);
79992 }
79993
79994 static inline void fnhe_genid_bump(struct net *net)
79995 {
79996- atomic_inc(&net->fnhe_genid);
79997+ atomic_inc_unchecked(&net->fnhe_genid);
79998 }
79999
80000 #endif /* __NET_NET_NAMESPACE_H */
80001diff --git a/include/net/netdma.h b/include/net/netdma.h
80002index 8ba8ce2..99b7fff 100644
80003--- a/include/net/netdma.h
80004+++ b/include/net/netdma.h
80005@@ -24,7 +24,7 @@
80006 #include <linux/dmaengine.h>
80007 #include <linux/skbuff.h>
80008
80009-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
80010+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
80011 struct sk_buff *skb, int offset, struct iovec *to,
80012 size_t len, struct dma_pinned_list *pinned_list);
80013
80014diff --git a/include/net/netlink.h b/include/net/netlink.h
80015index 9690b0f..87aded7 100644
80016--- a/include/net/netlink.h
80017+++ b/include/net/netlink.h
80018@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
80019 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
80020 {
80021 if (mark)
80022- skb_trim(skb, (unsigned char *) mark - skb->data);
80023+ skb_trim(skb, (const unsigned char *) mark - skb->data);
80024 }
80025
80026 /**
80027diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
80028index c9c0c53..53f24c3 100644
80029--- a/include/net/netns/conntrack.h
80030+++ b/include/net/netns/conntrack.h
80031@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
80032 struct nf_proto_net {
80033 #ifdef CONFIG_SYSCTL
80034 struct ctl_table_header *ctl_table_header;
80035- struct ctl_table *ctl_table;
80036+ ctl_table_no_const *ctl_table;
80037 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
80038 struct ctl_table_header *ctl_compat_header;
80039- struct ctl_table *ctl_compat_table;
80040+ ctl_table_no_const *ctl_compat_table;
80041 #endif
80042 #endif
80043 unsigned int users;
80044@@ -58,7 +58,7 @@ struct nf_ip_net {
80045 struct nf_icmp_net icmpv6;
80046 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
80047 struct ctl_table_header *ctl_table_header;
80048- struct ctl_table *ctl_table;
80049+ ctl_table_no_const *ctl_table;
80050 #endif
80051 };
80052
80053diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
80054index bf2ec22..5e7f9d9 100644
80055--- a/include/net/netns/ipv4.h
80056+++ b/include/net/netns/ipv4.h
80057@@ -67,7 +67,7 @@ struct netns_ipv4 {
80058 kgid_t sysctl_ping_group_range[2];
80059 long sysctl_tcp_mem[3];
80060
80061- atomic_t dev_addr_genid;
80062+ atomic_unchecked_t dev_addr_genid;
80063
80064 #ifdef CONFIG_IP_MROUTE
80065 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
80066@@ -77,6 +77,6 @@ struct netns_ipv4 {
80067 struct fib_rules_ops *mr_rules_ops;
80068 #endif
80069 #endif
80070- atomic_t rt_genid;
80071+ atomic_unchecked_t rt_genid;
80072 };
80073 #endif
80074diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
80075index 0fb2401..477d81c 100644
80076--- a/include/net/netns/ipv6.h
80077+++ b/include/net/netns/ipv6.h
80078@@ -71,8 +71,8 @@ struct netns_ipv6 {
80079 struct fib_rules_ops *mr6_rules_ops;
80080 #endif
80081 #endif
80082- atomic_t dev_addr_genid;
80083- atomic_t rt_genid;
80084+ atomic_unchecked_t dev_addr_genid;
80085+ atomic_unchecked_t rt_genid;
80086 };
80087
80088 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
80089diff --git a/include/net/ping.h b/include/net/ping.h
80090index 2b496e9..935fd8d 100644
80091--- a/include/net/ping.h
80092+++ b/include/net/ping.h
80093@@ -56,7 +56,7 @@ struct ping_iter_state {
80094 extern struct proto ping_prot;
80095 extern struct ping_table ping_table;
80096 #if IS_ENABLED(CONFIG_IPV6)
80097-extern struct pingv6_ops pingv6_ops;
80098+extern struct pingv6_ops *pingv6_ops;
80099 #endif
80100
80101 struct pingfakehdr {
80102diff --git a/include/net/protocol.h b/include/net/protocol.h
80103index 047c047..b9dad15 100644
80104--- a/include/net/protocol.h
80105+++ b/include/net/protocol.h
80106@@ -44,7 +44,7 @@ struct net_protocol {
80107 void (*err_handler)(struct sk_buff *skb, u32 info);
80108 unsigned int no_policy:1,
80109 netns_ok:1;
80110-};
80111+} __do_const;
80112
80113 #if IS_ENABLED(CONFIG_IPV6)
80114 struct inet6_protocol {
80115@@ -57,7 +57,7 @@ struct inet6_protocol {
80116 u8 type, u8 code, int offset,
80117 __be32 info);
80118 unsigned int flags; /* INET6_PROTO_xxx */
80119-};
80120+} __do_const;
80121
80122 #define INET6_PROTO_NOPOLICY 0x1
80123 #define INET6_PROTO_FINAL 0x2
80124diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
80125index 7026648..584cc8c 100644
80126--- a/include/net/rtnetlink.h
80127+++ b/include/net/rtnetlink.h
80128@@ -81,7 +81,7 @@ struct rtnl_link_ops {
80129 const struct net_device *dev);
80130 unsigned int (*get_num_tx_queues)(void);
80131 unsigned int (*get_num_rx_queues)(void);
80132-};
80133+} __do_const;
80134
80135 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
80136 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
80137diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
80138index 4ef75af..5aa073a 100644
80139--- a/include/net/sctp/sm.h
80140+++ b/include/net/sctp/sm.h
80141@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
80142 typedef struct {
80143 sctp_state_fn_t *fn;
80144 const char *name;
80145-} sctp_sm_table_entry_t;
80146+} __do_const sctp_sm_table_entry_t;
80147
80148 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
80149 * currently in use.
80150@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
80151 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
80152
80153 /* Extern declarations for major data structures. */
80154-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
80155+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
80156
80157
80158 /* Get the size of a DATA chunk payload. */
80159diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
80160index 2174d8d..71d5257 100644
80161--- a/include/net/sctp/structs.h
80162+++ b/include/net/sctp/structs.h
80163@@ -508,7 +508,7 @@ struct sctp_pf {
80164 struct sctp_association *asoc);
80165 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
80166 struct sctp_af *af;
80167-};
80168+} __do_const;
80169
80170
80171 /* Structure to track chunk fragments that have been acked, but peer
80172diff --git a/include/net/sock.h b/include/net/sock.h
80173index 808cbc2..8617e9c 100644
80174--- a/include/net/sock.h
80175+++ b/include/net/sock.h
80176@@ -332,7 +332,7 @@ struct sock {
80177 unsigned int sk_napi_id;
80178 unsigned int sk_ll_usec;
80179 #endif
80180- atomic_t sk_drops;
80181+ atomic_unchecked_t sk_drops;
80182 int sk_rcvbuf;
80183
80184 struct sk_filter __rcu *sk_filter;
80185@@ -1194,7 +1194,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
80186 return ret >> PAGE_SHIFT;
80187 }
80188
80189-static inline long
80190+static inline long __intentional_overflow(-1)
80191 sk_memory_allocated(const struct sock *sk)
80192 {
80193 struct proto *prot = sk->sk_prot;
80194@@ -1821,7 +1821,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
80195 }
80196
80197 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
80198- char __user *from, char *to,
80199+ char __user *from, unsigned char *to,
80200 int copy, int offset)
80201 {
80202 if (skb->ip_summed == CHECKSUM_NONE) {
80203@@ -2083,7 +2083,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
80204 }
80205 }
80206
80207-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
80208+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
80209
80210 /**
80211 * sk_page_frag - return an appropriate page_frag
80212diff --git a/include/net/tcp.h b/include/net/tcp.h
80213index b1aa324..b8530ea 100644
80214--- a/include/net/tcp.h
80215+++ b/include/net/tcp.h
80216@@ -527,7 +527,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
80217 extern void tcp_xmit_retransmit_queue(struct sock *);
80218 extern void tcp_simple_retransmit(struct sock *);
80219 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
80220-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
80221+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
80222
80223 extern void tcp_send_probe0(struct sock *);
80224 extern void tcp_send_partial(struct sock *);
80225@@ -699,8 +699,8 @@ struct tcp_skb_cb {
80226 struct inet6_skb_parm h6;
80227 #endif
80228 } header; /* For incoming frames */
80229- __u32 seq; /* Starting sequence number */
80230- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
80231+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
80232+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
80233 __u32 when; /* used to compute rtt's */
80234 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
80235
80236@@ -714,7 +714,7 @@ struct tcp_skb_cb {
80237
80238 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
80239 /* 1 byte hole */
80240- __u32 ack_seq; /* Sequence number ACK'd */
80241+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
80242 };
80243
80244 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
80245diff --git a/include/net/xfrm.h b/include/net/xfrm.h
80246index e253bf0..2278b4b 100644
80247--- a/include/net/xfrm.h
80248+++ b/include/net/xfrm.h
80249@@ -287,7 +287,6 @@ struct xfrm_dst;
80250 struct xfrm_policy_afinfo {
80251 unsigned short family;
80252 struct dst_ops *dst_ops;
80253- void (*garbage_collect)(struct net *net);
80254 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
80255 const xfrm_address_t *saddr,
80256 const xfrm_address_t *daddr);
80257@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
80258 struct net_device *dev,
80259 const struct flowi *fl);
80260 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
80261-};
80262+} __do_const;
80263
80264 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
80265 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
80266@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
80267 int (*transport_finish)(struct sk_buff *skb,
80268 int async);
80269 void (*local_error)(struct sk_buff *skb, u32 mtu);
80270-};
80271+} __do_const;
80272
80273 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
80274 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
80275@@ -427,7 +426,7 @@ struct xfrm_mode {
80276 struct module *owner;
80277 unsigned int encap;
80278 int flags;
80279-};
80280+} __do_const;
80281
80282 /* Flags for xfrm_mode. */
80283 enum {
80284@@ -524,7 +523,7 @@ struct xfrm_policy {
80285 struct timer_list timer;
80286
80287 struct flow_cache_object flo;
80288- atomic_t genid;
80289+ atomic_unchecked_t genid;
80290 u32 priority;
80291 u32 index;
80292 struct xfrm_mark mark;
80293@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
80294 }
80295
80296 extern void xfrm_garbage_collect(struct net *net);
80297+extern void xfrm_garbage_collect_deferred(struct net *net);
80298
80299 #else
80300
80301@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
80302 static inline void xfrm_garbage_collect(struct net *net)
80303 {
80304 }
80305+static inline void xfrm_garbage_collect_deferred(struct net *net)
80306+{
80307+}
80308 #endif
80309
80310 static __inline__
80311diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
80312index 1017e0b..227aa4d 100644
80313--- a/include/rdma/iw_cm.h
80314+++ b/include/rdma/iw_cm.h
80315@@ -122,7 +122,7 @@ struct iw_cm_verbs {
80316 int backlog);
80317
80318 int (*destroy_listen)(struct iw_cm_id *cm_id);
80319-};
80320+} __no_const;
80321
80322 /**
80323 * iw_create_cm_id - Create an IW CM identifier.
80324diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
80325index e1379b4..67eafbe 100644
80326--- a/include/scsi/libfc.h
80327+++ b/include/scsi/libfc.h
80328@@ -762,6 +762,7 @@ struct libfc_function_template {
80329 */
80330 void (*disc_stop_final) (struct fc_lport *);
80331 };
80332+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
80333
80334 /**
80335 * struct fc_disc - Discovery context
80336@@ -866,7 +867,7 @@ struct fc_lport {
80337 struct fc_vport *vport;
80338
80339 /* Operational Information */
80340- struct libfc_function_template tt;
80341+ libfc_function_template_no_const tt;
80342 u8 link_up;
80343 u8 qfull;
80344 enum fc_lport_state state;
80345diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
80346index d65fbec..f80fef2 100644
80347--- a/include/scsi/scsi_device.h
80348+++ b/include/scsi/scsi_device.h
80349@@ -180,9 +180,9 @@ struct scsi_device {
80350 unsigned int max_device_blocked; /* what device_blocked counts down from */
80351 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
80352
80353- atomic_t iorequest_cnt;
80354- atomic_t iodone_cnt;
80355- atomic_t ioerr_cnt;
80356+ atomic_unchecked_t iorequest_cnt;
80357+ atomic_unchecked_t iodone_cnt;
80358+ atomic_unchecked_t ioerr_cnt;
80359
80360 struct device sdev_gendev,
80361 sdev_dev;
80362diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
80363index b797e8f..8e2c3aa 100644
80364--- a/include/scsi/scsi_transport_fc.h
80365+++ b/include/scsi/scsi_transport_fc.h
80366@@ -751,7 +751,8 @@ struct fc_function_template {
80367 unsigned long show_host_system_hostname:1;
80368
80369 unsigned long disable_target_scan:1;
80370-};
80371+} __do_const;
80372+typedef struct fc_function_template __no_const fc_function_template_no_const;
80373
80374
80375 /**
80376diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
80377index ae6c3b8..fd748ac 100644
80378--- a/include/sound/compress_driver.h
80379+++ b/include/sound/compress_driver.h
80380@@ -128,7 +128,7 @@ struct snd_compr_ops {
80381 struct snd_compr_caps *caps);
80382 int (*get_codec_caps) (struct snd_compr_stream *stream,
80383 struct snd_compr_codec_caps *codec);
80384-};
80385+} __no_const;
80386
80387 /**
80388 * struct snd_compr: Compressed device
80389diff --git a/include/sound/soc.h b/include/sound/soc.h
80390index d22cb0a..c6ba150 100644
80391--- a/include/sound/soc.h
80392+++ b/include/sound/soc.h
80393@@ -780,7 +780,7 @@ struct snd_soc_codec_driver {
80394 /* probe ordering - for components with runtime dependencies */
80395 int probe_order;
80396 int remove_order;
80397-};
80398+} __do_const;
80399
80400 /* SoC platform interface */
80401 struct snd_soc_platform_driver {
80402@@ -826,7 +826,7 @@ struct snd_soc_platform_driver {
80403 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
80404 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
80405 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
80406-};
80407+} __do_const;
80408
80409 struct snd_soc_platform {
80410 const char *name;
80411diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
80412index 5bdb8b7..bb1096c 100644
80413--- a/include/target/target_core_base.h
80414+++ b/include/target/target_core_base.h
80415@@ -663,7 +663,7 @@ struct se_device {
80416 spinlock_t stats_lock;
80417 /* Active commands on this virtual SE device */
80418 atomic_t simple_cmds;
80419- atomic_t dev_ordered_id;
80420+ atomic_unchecked_t dev_ordered_id;
80421 atomic_t dev_ordered_sync;
80422 atomic_t dev_qf_count;
80423 int export_count;
80424diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
80425new file mode 100644
80426index 0000000..fb634b7
80427--- /dev/null
80428+++ b/include/trace/events/fs.h
80429@@ -0,0 +1,53 @@
80430+#undef TRACE_SYSTEM
80431+#define TRACE_SYSTEM fs
80432+
80433+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
80434+#define _TRACE_FS_H
80435+
80436+#include <linux/fs.h>
80437+#include <linux/tracepoint.h>
80438+
80439+TRACE_EVENT(do_sys_open,
80440+
80441+ TP_PROTO(const char *filename, int flags, int mode),
80442+
80443+ TP_ARGS(filename, flags, mode),
80444+
80445+ TP_STRUCT__entry(
80446+ __string( filename, filename )
80447+ __field( int, flags )
80448+ __field( int, mode )
80449+ ),
80450+
80451+ TP_fast_assign(
80452+ __assign_str(filename, filename);
80453+ __entry->flags = flags;
80454+ __entry->mode = mode;
80455+ ),
80456+
80457+ TP_printk("\"%s\" %x %o",
80458+ __get_str(filename), __entry->flags, __entry->mode)
80459+);
80460+
80461+TRACE_EVENT(open_exec,
80462+
80463+ TP_PROTO(const char *filename),
80464+
80465+ TP_ARGS(filename),
80466+
80467+ TP_STRUCT__entry(
80468+ __string( filename, filename )
80469+ ),
80470+
80471+ TP_fast_assign(
80472+ __assign_str(filename, filename);
80473+ ),
80474+
80475+ TP_printk("\"%s\"",
80476+ __get_str(filename))
80477+);
80478+
80479+#endif /* _TRACE_FS_H */
80480+
80481+/* This part must be outside protection */
80482+#include <trace/define_trace.h>
80483diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
80484index 1c09820..7f5ec79 100644
80485--- a/include/trace/events/irq.h
80486+++ b/include/trace/events/irq.h
80487@@ -36,7 +36,7 @@ struct softirq_action;
80488 */
80489 TRACE_EVENT(irq_handler_entry,
80490
80491- TP_PROTO(int irq, struct irqaction *action),
80492+ TP_PROTO(int irq, const struct irqaction *action),
80493
80494 TP_ARGS(irq, action),
80495
80496@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
80497 */
80498 TRACE_EVENT(irq_handler_exit,
80499
80500- TP_PROTO(int irq, struct irqaction *action, int ret),
80501+ TP_PROTO(int irq, const struct irqaction *action, int ret),
80502
80503 TP_ARGS(irq, action, ret),
80504
80505diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
80506index 7caf44c..23c6f27 100644
80507--- a/include/uapi/linux/a.out.h
80508+++ b/include/uapi/linux/a.out.h
80509@@ -39,6 +39,14 @@ enum machine_type {
80510 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
80511 };
80512
80513+/* Constants for the N_FLAGS field */
80514+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
80515+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
80516+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
80517+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
80518+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
80519+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
80520+
80521 #if !defined (N_MAGIC)
80522 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
80523 #endif
80524diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
80525index d876736..ccce5c0 100644
80526--- a/include/uapi/linux/byteorder/little_endian.h
80527+++ b/include/uapi/linux/byteorder/little_endian.h
80528@@ -42,51 +42,51 @@
80529
80530 static inline __le64 __cpu_to_le64p(const __u64 *p)
80531 {
80532- return (__force __le64)*p;
80533+ return (__force const __le64)*p;
80534 }
80535-static inline __u64 __le64_to_cpup(const __le64 *p)
80536+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
80537 {
80538- return (__force __u64)*p;
80539+ return (__force const __u64)*p;
80540 }
80541 static inline __le32 __cpu_to_le32p(const __u32 *p)
80542 {
80543- return (__force __le32)*p;
80544+ return (__force const __le32)*p;
80545 }
80546 static inline __u32 __le32_to_cpup(const __le32 *p)
80547 {
80548- return (__force __u32)*p;
80549+ return (__force const __u32)*p;
80550 }
80551 static inline __le16 __cpu_to_le16p(const __u16 *p)
80552 {
80553- return (__force __le16)*p;
80554+ return (__force const __le16)*p;
80555 }
80556 static inline __u16 __le16_to_cpup(const __le16 *p)
80557 {
80558- return (__force __u16)*p;
80559+ return (__force const __u16)*p;
80560 }
80561 static inline __be64 __cpu_to_be64p(const __u64 *p)
80562 {
80563- return (__force __be64)__swab64p(p);
80564+ return (__force const __be64)__swab64p(p);
80565 }
80566 static inline __u64 __be64_to_cpup(const __be64 *p)
80567 {
80568- return __swab64p((__u64 *)p);
80569+ return __swab64p((const __u64 *)p);
80570 }
80571 static inline __be32 __cpu_to_be32p(const __u32 *p)
80572 {
80573- return (__force __be32)__swab32p(p);
80574+ return (__force const __be32)__swab32p(p);
80575 }
80576-static inline __u32 __be32_to_cpup(const __be32 *p)
80577+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
80578 {
80579- return __swab32p((__u32 *)p);
80580+ return __swab32p((const __u32 *)p);
80581 }
80582 static inline __be16 __cpu_to_be16p(const __u16 *p)
80583 {
80584- return (__force __be16)__swab16p(p);
80585+ return (__force const __be16)__swab16p(p);
80586 }
80587 static inline __u16 __be16_to_cpup(const __be16 *p)
80588 {
80589- return __swab16p((__u16 *)p);
80590+ return __swab16p((const __u16 *)p);
80591 }
80592 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
80593 #define __le64_to_cpus(x) do { (void)(x); } while (0)
80594diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
80595index ef6103b..d4e65dd 100644
80596--- a/include/uapi/linux/elf.h
80597+++ b/include/uapi/linux/elf.h
80598@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
80599 #define PT_GNU_EH_FRAME 0x6474e550
80600
80601 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
80602+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
80603+
80604+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
80605+
80606+/* Constants for the e_flags field */
80607+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
80608+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
80609+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
80610+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
80611+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
80612+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
80613
80614 /*
80615 * Extended Numbering
80616@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
80617 #define DT_DEBUG 21
80618 #define DT_TEXTREL 22
80619 #define DT_JMPREL 23
80620+#define DT_FLAGS 30
80621+ #define DF_TEXTREL 0x00000004
80622 #define DT_ENCODING 32
80623 #define OLD_DT_LOOS 0x60000000
80624 #define DT_LOOS 0x6000000d
80625@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
80626 #define PF_W 0x2
80627 #define PF_X 0x1
80628
80629+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
80630+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
80631+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
80632+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
80633+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
80634+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
80635+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
80636+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
80637+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
80638+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
80639+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
80640+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
80641+
80642 typedef struct elf32_phdr{
80643 Elf32_Word p_type;
80644 Elf32_Off p_offset;
80645@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
80646 #define EI_OSABI 7
80647 #define EI_PAD 8
80648
80649+#define EI_PAX 14
80650+
80651 #define ELFMAG0 0x7f /* EI_MAG */
80652 #define ELFMAG1 'E'
80653 #define ELFMAG2 'L'
80654diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
80655index aa169c4..6a2771d 100644
80656--- a/include/uapi/linux/personality.h
80657+++ b/include/uapi/linux/personality.h
80658@@ -30,6 +30,7 @@ enum {
80659 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
80660 ADDR_NO_RANDOMIZE | \
80661 ADDR_COMPAT_LAYOUT | \
80662+ ADDR_LIMIT_3GB | \
80663 MMAP_PAGE_ZERO)
80664
80665 /*
80666diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
80667index 7530e74..e714828 100644
80668--- a/include/uapi/linux/screen_info.h
80669+++ b/include/uapi/linux/screen_info.h
80670@@ -43,7 +43,8 @@ struct screen_info {
80671 __u16 pages; /* 0x32 */
80672 __u16 vesa_attributes; /* 0x34 */
80673 __u32 capabilities; /* 0x36 */
80674- __u8 _reserved[6]; /* 0x3a */
80675+ __u16 vesapm_size; /* 0x3a */
80676+ __u8 _reserved[4]; /* 0x3c */
80677 } __attribute__((packed));
80678
80679 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
80680diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
80681index 0e011eb..82681b1 100644
80682--- a/include/uapi/linux/swab.h
80683+++ b/include/uapi/linux/swab.h
80684@@ -43,7 +43,7 @@
80685 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
80686 */
80687
80688-static inline __attribute_const__ __u16 __fswab16(__u16 val)
80689+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
80690 {
80691 #ifdef __HAVE_BUILTIN_BSWAP16__
80692 return __builtin_bswap16(val);
80693@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
80694 #endif
80695 }
80696
80697-static inline __attribute_const__ __u32 __fswab32(__u32 val)
80698+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
80699 {
80700 #ifdef __HAVE_BUILTIN_BSWAP32__
80701 return __builtin_bswap32(val);
80702@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
80703 #endif
80704 }
80705
80706-static inline __attribute_const__ __u64 __fswab64(__u64 val)
80707+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
80708 {
80709 #ifdef __HAVE_BUILTIN_BSWAP64__
80710 return __builtin_bswap64(val);
80711diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
80712index 6d67213..8dab561 100644
80713--- a/include/uapi/linux/sysctl.h
80714+++ b/include/uapi/linux/sysctl.h
80715@@ -155,7 +155,11 @@ enum
80716 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
80717 };
80718
80719-
80720+#ifdef CONFIG_PAX_SOFTMODE
80721+enum {
80722+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
80723+};
80724+#endif
80725
80726 /* CTL_VM names: */
80727 enum
80728diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
80729index e4629b9..6958086 100644
80730--- a/include/uapi/linux/xattr.h
80731+++ b/include/uapi/linux/xattr.h
80732@@ -63,5 +63,9 @@
80733 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
80734 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
80735
80736+/* User namespace */
80737+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
80738+#define XATTR_PAX_FLAGS_SUFFIX "flags"
80739+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
80740
80741 #endif /* _UAPI_LINUX_XATTR_H */
80742diff --git a/include/video/udlfb.h b/include/video/udlfb.h
80743index f9466fa..f4e2b81 100644
80744--- a/include/video/udlfb.h
80745+++ b/include/video/udlfb.h
80746@@ -53,10 +53,10 @@ struct dlfb_data {
80747 u32 pseudo_palette[256];
80748 int blank_mode; /*one of FB_BLANK_ */
80749 /* blit-only rendering path metrics, exposed through sysfs */
80750- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
80751- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
80752- atomic_t bytes_sent; /* to usb, after compression including overhead */
80753- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
80754+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
80755+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
80756+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
80757+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
80758 };
80759
80760 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
80761diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
80762index 30f5362..8ed8ac9 100644
80763--- a/include/video/uvesafb.h
80764+++ b/include/video/uvesafb.h
80765@@ -122,6 +122,7 @@ struct uvesafb_par {
80766 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
80767 u8 pmi_setpal; /* PMI for palette changes */
80768 u16 *pmi_base; /* protected mode interface location */
80769+ u8 *pmi_code; /* protected mode code location */
80770 void *pmi_start;
80771 void *pmi_pal;
80772 u8 *vbe_state_orig; /*
80773diff --git a/init/Kconfig b/init/Kconfig
80774index 3ecd8a1..627843f 100644
80775--- a/init/Kconfig
80776+++ b/init/Kconfig
80777@@ -1086,6 +1086,7 @@ endif # CGROUPS
80778
80779 config CHECKPOINT_RESTORE
80780 bool "Checkpoint/restore support" if EXPERT
80781+ depends on !GRKERNSEC
80782 default n
80783 help
80784 Enables additional kernel features in a sake of checkpoint/restore.
80785@@ -1557,7 +1558,7 @@ config SLUB_DEBUG
80786
80787 config COMPAT_BRK
80788 bool "Disable heap randomization"
80789- default y
80790+ default n
80791 help
80792 Randomizing heap placement makes heap exploits harder, but it
80793 also breaks ancient binaries (including anything libc5 based).
80794@@ -1832,7 +1833,7 @@ config INIT_ALL_POSSIBLE
80795 config STOP_MACHINE
80796 bool
80797 default y
80798- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
80799+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
80800 help
80801 Need stop_machine() primitive.
80802
80803diff --git a/init/Makefile b/init/Makefile
80804index 7bc47ee..6da2dc7 100644
80805--- a/init/Makefile
80806+++ b/init/Makefile
80807@@ -2,6 +2,9 @@
80808 # Makefile for the linux kernel.
80809 #
80810
80811+ccflags-y := $(GCC_PLUGINS_CFLAGS)
80812+asflags-y := $(GCC_PLUGINS_AFLAGS)
80813+
80814 obj-y := main.o version.o mounts.o
80815 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
80816 obj-y += noinitramfs.o
80817diff --git a/init/do_mounts.c b/init/do_mounts.c
80818index a51cddc..25c2768 100644
80819--- a/init/do_mounts.c
80820+++ b/init/do_mounts.c
80821@@ -357,11 +357,11 @@ static void __init get_fs_names(char *page)
80822 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
80823 {
80824 struct super_block *s;
80825- int err = sys_mount(name, "/root", fs, flags, data);
80826+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
80827 if (err)
80828 return err;
80829
80830- sys_chdir("/root");
80831+ sys_chdir((const char __force_user *)"/root");
80832 s = current->fs->pwd.dentry->d_sb;
80833 ROOT_DEV = s->s_dev;
80834 printk(KERN_INFO
80835@@ -482,18 +482,18 @@ void __init change_floppy(char *fmt, ...)
80836 va_start(args, fmt);
80837 vsprintf(buf, fmt, args);
80838 va_end(args);
80839- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
80840+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
80841 if (fd >= 0) {
80842 sys_ioctl(fd, FDEJECT, 0);
80843 sys_close(fd);
80844 }
80845 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
80846- fd = sys_open("/dev/console", O_RDWR, 0);
80847+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
80848 if (fd >= 0) {
80849 sys_ioctl(fd, TCGETS, (long)&termios);
80850 termios.c_lflag &= ~ICANON;
80851 sys_ioctl(fd, TCSETSF, (long)&termios);
80852- sys_read(fd, &c, 1);
80853+ sys_read(fd, (char __user *)&c, 1);
80854 termios.c_lflag |= ICANON;
80855 sys_ioctl(fd, TCSETSF, (long)&termios);
80856 sys_close(fd);
80857@@ -587,8 +587,8 @@ void __init prepare_namespace(void)
80858 mount_root();
80859 out:
80860 devtmpfs_mount("dev");
80861- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80862- sys_chroot(".");
80863+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80864+ sys_chroot((const char __force_user *)".");
80865 }
80866
80867 static bool is_tmpfs;
80868diff --git a/init/do_mounts.h b/init/do_mounts.h
80869index f5b978a..69dbfe8 100644
80870--- a/init/do_mounts.h
80871+++ b/init/do_mounts.h
80872@@ -15,15 +15,15 @@ extern int root_mountflags;
80873
80874 static inline int create_dev(char *name, dev_t dev)
80875 {
80876- sys_unlink(name);
80877- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
80878+ sys_unlink((char __force_user *)name);
80879+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
80880 }
80881
80882 #if BITS_PER_LONG == 32
80883 static inline u32 bstat(char *name)
80884 {
80885 struct stat64 stat;
80886- if (sys_stat64(name, &stat) != 0)
80887+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
80888 return 0;
80889 if (!S_ISBLK(stat.st_mode))
80890 return 0;
80891@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
80892 static inline u32 bstat(char *name)
80893 {
80894 struct stat stat;
80895- if (sys_newstat(name, &stat) != 0)
80896+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
80897 return 0;
80898 if (!S_ISBLK(stat.st_mode))
80899 return 0;
80900diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
80901index 3e0878e..8a9d7a0 100644
80902--- a/init/do_mounts_initrd.c
80903+++ b/init/do_mounts_initrd.c
80904@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
80905 {
80906 sys_unshare(CLONE_FS | CLONE_FILES);
80907 /* stdin/stdout/stderr for /linuxrc */
80908- sys_open("/dev/console", O_RDWR, 0);
80909+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
80910 sys_dup(0);
80911 sys_dup(0);
80912 /* move initrd over / and chdir/chroot in initrd root */
80913- sys_chdir("/root");
80914- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80915- sys_chroot(".");
80916+ sys_chdir((const char __force_user *)"/root");
80917+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80918+ sys_chroot((const char __force_user *)".");
80919 sys_setsid();
80920 return 0;
80921 }
80922@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
80923 create_dev("/dev/root.old", Root_RAM0);
80924 /* mount initrd on rootfs' /root */
80925 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
80926- sys_mkdir("/old", 0700);
80927- sys_chdir("/old");
80928+ sys_mkdir((const char __force_user *)"/old", 0700);
80929+ sys_chdir((const char __force_user *)"/old");
80930
80931 /* try loading default modules from initrd */
80932 load_default_modules();
80933@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
80934 current->flags &= ~PF_FREEZER_SKIP;
80935
80936 /* move initrd to rootfs' /old */
80937- sys_mount("..", ".", NULL, MS_MOVE, NULL);
80938+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
80939 /* switch root and cwd back to / of rootfs */
80940- sys_chroot("..");
80941+ sys_chroot((const char __force_user *)"..");
80942
80943 if (new_decode_dev(real_root_dev) == Root_RAM0) {
80944- sys_chdir("/old");
80945+ sys_chdir((const char __force_user *)"/old");
80946 return;
80947 }
80948
80949- sys_chdir("/");
80950+ sys_chdir((const char __force_user *)"/");
80951 ROOT_DEV = new_decode_dev(real_root_dev);
80952 mount_root();
80953
80954 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
80955- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
80956+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
80957 if (!error)
80958 printk("okay\n");
80959 else {
80960- int fd = sys_open("/dev/root.old", O_RDWR, 0);
80961+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
80962 if (error == -ENOENT)
80963 printk("/initrd does not exist. Ignored.\n");
80964 else
80965 printk("failed\n");
80966 printk(KERN_NOTICE "Unmounting old root\n");
80967- sys_umount("/old", MNT_DETACH);
80968+ sys_umount((char __force_user *)"/old", MNT_DETACH);
80969 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
80970 if (fd < 0) {
80971 error = fd;
80972@@ -127,11 +127,11 @@ int __init initrd_load(void)
80973 * mounted in the normal path.
80974 */
80975 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
80976- sys_unlink("/initrd.image");
80977+ sys_unlink((const char __force_user *)"/initrd.image");
80978 handle_initrd();
80979 return 1;
80980 }
80981 }
80982- sys_unlink("/initrd.image");
80983+ sys_unlink((const char __force_user *)"/initrd.image");
80984 return 0;
80985 }
80986diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
80987index 8cb6db5..d729f50 100644
80988--- a/init/do_mounts_md.c
80989+++ b/init/do_mounts_md.c
80990@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
80991 partitioned ? "_d" : "", minor,
80992 md_setup_args[ent].device_names);
80993
80994- fd = sys_open(name, 0, 0);
80995+ fd = sys_open((char __force_user *)name, 0, 0);
80996 if (fd < 0) {
80997 printk(KERN_ERR "md: open failed - cannot start "
80998 "array %s\n", name);
80999@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
81000 * array without it
81001 */
81002 sys_close(fd);
81003- fd = sys_open(name, 0, 0);
81004+ fd = sys_open((char __force_user *)name, 0, 0);
81005 sys_ioctl(fd, BLKRRPART, 0);
81006 }
81007 sys_close(fd);
81008@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
81009
81010 wait_for_device_probe();
81011
81012- fd = sys_open("/dev/md0", 0, 0);
81013+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
81014 if (fd >= 0) {
81015 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
81016 sys_close(fd);
81017diff --git a/init/init_task.c b/init/init_task.c
81018index ba0a7f36..2bcf1d5 100644
81019--- a/init/init_task.c
81020+++ b/init/init_task.c
81021@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
81022 * Initial thread structure. Alignment of this is handled by a special
81023 * linker map entry.
81024 */
81025+#ifdef CONFIG_X86
81026+union thread_union init_thread_union __init_task_data;
81027+#else
81028 union thread_union init_thread_union __init_task_data =
81029 { INIT_THREAD_INFO(init_task) };
81030+#endif
81031diff --git a/init/initramfs.c b/init/initramfs.c
81032index a67ef9d..2d17ed9 100644
81033--- a/init/initramfs.c
81034+++ b/init/initramfs.c
81035@@ -84,7 +84,7 @@ static void __init free_hash(void)
81036 }
81037 }
81038
81039-static long __init do_utime(char *filename, time_t mtime)
81040+static long __init do_utime(char __force_user *filename, time_t mtime)
81041 {
81042 struct timespec t[2];
81043
81044@@ -119,7 +119,7 @@ static void __init dir_utime(void)
81045 struct dir_entry *de, *tmp;
81046 list_for_each_entry_safe(de, tmp, &dir_list, list) {
81047 list_del(&de->list);
81048- do_utime(de->name, de->mtime);
81049+ do_utime((char __force_user *)de->name, de->mtime);
81050 kfree(de->name);
81051 kfree(de);
81052 }
81053@@ -281,7 +281,7 @@ static int __init maybe_link(void)
81054 if (nlink >= 2) {
81055 char *old = find_link(major, minor, ino, mode, collected);
81056 if (old)
81057- return (sys_link(old, collected) < 0) ? -1 : 1;
81058+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
81059 }
81060 return 0;
81061 }
81062@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
81063 {
81064 struct stat st;
81065
81066- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
81067+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
81068 if (S_ISDIR(st.st_mode))
81069- sys_rmdir(path);
81070+ sys_rmdir((char __force_user *)path);
81071 else
81072- sys_unlink(path);
81073+ sys_unlink((char __force_user *)path);
81074 }
81075 }
81076
81077@@ -315,7 +315,7 @@ static int __init do_name(void)
81078 int openflags = O_WRONLY|O_CREAT;
81079 if (ml != 1)
81080 openflags |= O_TRUNC;
81081- wfd = sys_open(collected, openflags, mode);
81082+ wfd = sys_open((char __force_user *)collected, openflags, mode);
81083
81084 if (wfd >= 0) {
81085 sys_fchown(wfd, uid, gid);
81086@@ -327,17 +327,17 @@ static int __init do_name(void)
81087 }
81088 }
81089 } else if (S_ISDIR(mode)) {
81090- sys_mkdir(collected, mode);
81091- sys_chown(collected, uid, gid);
81092- sys_chmod(collected, mode);
81093+ sys_mkdir((char __force_user *)collected, mode);
81094+ sys_chown((char __force_user *)collected, uid, gid);
81095+ sys_chmod((char __force_user *)collected, mode);
81096 dir_add(collected, mtime);
81097 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
81098 S_ISFIFO(mode) || S_ISSOCK(mode)) {
81099 if (maybe_link() == 0) {
81100- sys_mknod(collected, mode, rdev);
81101- sys_chown(collected, uid, gid);
81102- sys_chmod(collected, mode);
81103- do_utime(collected, mtime);
81104+ sys_mknod((char __force_user *)collected, mode, rdev);
81105+ sys_chown((char __force_user *)collected, uid, gid);
81106+ sys_chmod((char __force_user *)collected, mode);
81107+ do_utime((char __force_user *)collected, mtime);
81108 }
81109 }
81110 return 0;
81111@@ -346,15 +346,15 @@ static int __init do_name(void)
81112 static int __init do_copy(void)
81113 {
81114 if (count >= body_len) {
81115- sys_write(wfd, victim, body_len);
81116+ sys_write(wfd, (char __force_user *)victim, body_len);
81117 sys_close(wfd);
81118- do_utime(vcollected, mtime);
81119+ do_utime((char __force_user *)vcollected, mtime);
81120 kfree(vcollected);
81121 eat(body_len);
81122 state = SkipIt;
81123 return 0;
81124 } else {
81125- sys_write(wfd, victim, count);
81126+ sys_write(wfd, (char __force_user *)victim, count);
81127 body_len -= count;
81128 eat(count);
81129 return 1;
81130@@ -365,9 +365,9 @@ static int __init do_symlink(void)
81131 {
81132 collected[N_ALIGN(name_len) + body_len] = '\0';
81133 clean_path(collected, 0);
81134- sys_symlink(collected + N_ALIGN(name_len), collected);
81135- sys_lchown(collected, uid, gid);
81136- do_utime(collected, mtime);
81137+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
81138+ sys_lchown((char __force_user *)collected, uid, gid);
81139+ do_utime((char __force_user *)collected, mtime);
81140 state = SkipIt;
81141 next_state = Reset;
81142 return 0;
81143@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
81144 {
81145 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
81146 if (err)
81147- panic(err); /* Failed to decompress INTERNAL initramfs */
81148+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
81149 if (initrd_start) {
81150 #ifdef CONFIG_BLK_DEV_RAM
81151 int fd;
81152diff --git a/init/main.c b/init/main.c
81153index 63d3e8f..50bd5f8 100644
81154--- a/init/main.c
81155+++ b/init/main.c
81156@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
81157 extern void tc_init(void);
81158 #endif
81159
81160+extern void grsecurity_init(void);
81161+
81162 /*
81163 * Debug helper: via this flag we know that we are in 'early bootup code'
81164 * where only the boot processor is running with IRQ disabled. This means
81165@@ -156,6 +158,75 @@ static int __init set_reset_devices(char *str)
81166
81167 __setup("reset_devices", set_reset_devices);
81168
81169+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
81170+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
81171+static int __init setup_grsec_proc_gid(char *str)
81172+{
81173+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
81174+ return 1;
81175+}
81176+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
81177+#endif
81178+
81179+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
81180+unsigned long pax_user_shadow_base __read_only;
81181+EXPORT_SYMBOL(pax_user_shadow_base);
81182+extern char pax_enter_kernel_user[];
81183+extern char pax_exit_kernel_user[];
81184+#endif
81185+
81186+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
81187+static int __init setup_pax_nouderef(char *str)
81188+{
81189+#ifdef CONFIG_X86_32
81190+ unsigned int cpu;
81191+ struct desc_struct *gdt;
81192+
81193+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
81194+ gdt = get_cpu_gdt_table(cpu);
81195+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
81196+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
81197+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
81198+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
81199+ }
81200+ loadsegment(ds, __KERNEL_DS);
81201+ loadsegment(es, __KERNEL_DS);
81202+ loadsegment(ss, __KERNEL_DS);
81203+#else
81204+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
81205+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
81206+ clone_pgd_mask = ~(pgdval_t)0UL;
81207+ pax_user_shadow_base = 0UL;
81208+ setup_clear_cpu_cap(X86_FEATURE_PCID);
81209+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
81210+#endif
81211+
81212+ return 0;
81213+}
81214+early_param("pax_nouderef", setup_pax_nouderef);
81215+
81216+#ifdef CONFIG_X86_64
81217+static int __init setup_pax_weakuderef(char *str)
81218+{
81219+ if (clone_pgd_mask != ~(pgdval_t)0UL)
81220+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
81221+ return 1;
81222+}
81223+__setup("pax_weakuderef", setup_pax_weakuderef);
81224+#endif
81225+#endif
81226+
81227+#ifdef CONFIG_PAX_SOFTMODE
81228+int pax_softmode;
81229+
81230+static int __init setup_pax_softmode(char *str)
81231+{
81232+ get_option(&str, &pax_softmode);
81233+ return 1;
81234+}
81235+__setup("pax_softmode=", setup_pax_softmode);
81236+#endif
81237+
81238 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
81239 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
81240 static const char *panic_later, *panic_param;
81241@@ -682,25 +753,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
81242 {
81243 int count = preempt_count();
81244 int ret;
81245- char msgbuf[64];
81246+ const char *msg1 = "", *msg2 = "";
81247
81248 if (initcall_debug)
81249 ret = do_one_initcall_debug(fn);
81250 else
81251 ret = fn();
81252
81253- msgbuf[0] = 0;
81254-
81255 if (preempt_count() != count) {
81256- sprintf(msgbuf, "preemption imbalance ");
81257+ msg1 = " preemption imbalance";
81258 preempt_count() = count;
81259 }
81260 if (irqs_disabled()) {
81261- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
81262+ msg2 = " disabled interrupts";
81263 local_irq_enable();
81264 }
81265- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
81266+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
81267
81268+ add_latent_entropy();
81269 return ret;
81270 }
81271
81272@@ -807,10 +877,14 @@ static int run_init_process(const char *init_filename)
81273 {
81274 argv_init[0] = init_filename;
81275 return do_execve(init_filename,
81276- (const char __user *const __user *)argv_init,
81277- (const char __user *const __user *)envp_init);
81278+ (const char __user *const __force_user *)argv_init,
81279+ (const char __user *const __force_user *)envp_init);
81280 }
81281
81282+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
81283+extern int gr_init_ran;
81284+#endif
81285+
81286 static noinline void __init kernel_init_freeable(void);
81287
81288 static int __ref kernel_init(void *unused)
81289@@ -831,6 +905,11 @@ static int __ref kernel_init(void *unused)
81290 pr_err("Failed to execute %s\n", ramdisk_execute_command);
81291 }
81292
81293+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
81294+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
81295+ gr_init_ran = 1;
81296+#endif
81297+
81298 /*
81299 * We try each of these until one succeeds.
81300 *
81301@@ -885,7 +964,7 @@ static noinline void __init kernel_init_freeable(void)
81302 do_basic_setup();
81303
81304 /* Open the /dev/console on the rootfs, this should never fail */
81305- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
81306+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
81307 pr_err("Warning: unable to open an initial console.\n");
81308
81309 (void) sys_dup(0);
81310@@ -898,11 +977,13 @@ static noinline void __init kernel_init_freeable(void)
81311 if (!ramdisk_execute_command)
81312 ramdisk_execute_command = "/init";
81313
81314- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
81315+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
81316 ramdisk_execute_command = NULL;
81317 prepare_namespace();
81318 }
81319
81320+ grsecurity_init();
81321+
81322 /*
81323 * Ok, we have completed the initial bootup, and
81324 * we're essentially up and running. Get rid of the
81325diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
81326index b0e99de..09f385c 100644
81327--- a/ipc/ipc_sysctl.c
81328+++ b/ipc/ipc_sysctl.c
81329@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
81330 static int proc_ipc_dointvec(ctl_table *table, int write,
81331 void __user *buffer, size_t *lenp, loff_t *ppos)
81332 {
81333- struct ctl_table ipc_table;
81334+ ctl_table_no_const ipc_table;
81335
81336 memcpy(&ipc_table, table, sizeof(ipc_table));
81337 ipc_table.data = get_ipc(table);
81338@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
81339 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
81340 void __user *buffer, size_t *lenp, loff_t *ppos)
81341 {
81342- struct ctl_table ipc_table;
81343+ ctl_table_no_const ipc_table;
81344
81345 memcpy(&ipc_table, table, sizeof(ipc_table));
81346 ipc_table.data = get_ipc(table);
81347@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
81348 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
81349 void __user *buffer, size_t *lenp, loff_t *ppos)
81350 {
81351- struct ctl_table ipc_table;
81352+ ctl_table_no_const ipc_table;
81353 size_t lenp_bef = *lenp;
81354 int rc;
81355
81356@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
81357 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
81358 void __user *buffer, size_t *lenp, loff_t *ppos)
81359 {
81360- struct ctl_table ipc_table;
81361+ ctl_table_no_const ipc_table;
81362 memcpy(&ipc_table, table, sizeof(ipc_table));
81363 ipc_table.data = get_ipc(table);
81364
81365@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
81366 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
81367 void __user *buffer, size_t *lenp, loff_t *ppos)
81368 {
81369- struct ctl_table ipc_table;
81370+ ctl_table_no_const ipc_table;
81371 size_t lenp_bef = *lenp;
81372 int oldval;
81373 int rc;
81374diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
81375index 383d638..943fdbb 100644
81376--- a/ipc/mq_sysctl.c
81377+++ b/ipc/mq_sysctl.c
81378@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
81379 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
81380 void __user *buffer, size_t *lenp, loff_t *ppos)
81381 {
81382- struct ctl_table mq_table;
81383+ ctl_table_no_const mq_table;
81384 memcpy(&mq_table, table, sizeof(mq_table));
81385 mq_table.data = get_mq(table);
81386
81387diff --git a/ipc/mqueue.c b/ipc/mqueue.c
81388index ae1996d..a35f2cc 100644
81389--- a/ipc/mqueue.c
81390+++ b/ipc/mqueue.c
81391@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
81392 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
81393 info->attr.mq_msgsize);
81394
81395+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
81396 spin_lock(&mq_lock);
81397 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
81398 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
81399diff --git a/ipc/msg.c b/ipc/msg.c
81400index 558aa91..359e718 100644
81401--- a/ipc/msg.c
81402+++ b/ipc/msg.c
81403@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
81404 return security_msg_queue_associate(msq, msgflg);
81405 }
81406
81407+static struct ipc_ops msg_ops = {
81408+ .getnew = newque,
81409+ .associate = msg_security,
81410+ .more_checks = NULL
81411+};
81412+
81413 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
81414 {
81415 struct ipc_namespace *ns;
81416- struct ipc_ops msg_ops;
81417 struct ipc_params msg_params;
81418
81419 ns = current->nsproxy->ipc_ns;
81420
81421- msg_ops.getnew = newque;
81422- msg_ops.associate = msg_security;
81423- msg_ops.more_checks = NULL;
81424-
81425 msg_params.key = key;
81426 msg_params.flg = msgflg;
81427
81428diff --git a/ipc/sem.c b/ipc/sem.c
81429index db9d241..bc8427c 100644
81430--- a/ipc/sem.c
81431+++ b/ipc/sem.c
81432@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
81433 return 0;
81434 }
81435
81436+static struct ipc_ops sem_ops = {
81437+ .getnew = newary,
81438+ .associate = sem_security,
81439+ .more_checks = sem_more_checks
81440+};
81441+
81442 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
81443 {
81444 struct ipc_namespace *ns;
81445- struct ipc_ops sem_ops;
81446 struct ipc_params sem_params;
81447
81448 ns = current->nsproxy->ipc_ns;
81449@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
81450 if (nsems < 0 || nsems > ns->sc_semmsl)
81451 return -EINVAL;
81452
81453- sem_ops.getnew = newary;
81454- sem_ops.associate = sem_security;
81455- sem_ops.more_checks = sem_more_checks;
81456-
81457 sem_params.key = key;
81458 sem_params.flg = semflg;
81459 sem_params.u.nsems = nsems;
81460diff --git a/ipc/shm.c b/ipc/shm.c
81461index 7a51443..3a257d8 100644
81462--- a/ipc/shm.c
81463+++ b/ipc/shm.c
81464@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
81465 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
81466 #endif
81467
81468+#ifdef CONFIG_GRKERNSEC
81469+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
81470+ const time_t shm_createtime, const kuid_t cuid,
81471+ const int shmid);
81472+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
81473+ const time_t shm_createtime);
81474+#endif
81475+
81476 void shm_init_ns(struct ipc_namespace *ns)
81477 {
81478 ns->shm_ctlmax = SHMMAX;
81479@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
81480 shp->shm_lprid = 0;
81481 shp->shm_atim = shp->shm_dtim = 0;
81482 shp->shm_ctim = get_seconds();
81483+#ifdef CONFIG_GRKERNSEC
81484+ {
81485+ struct timespec timeval;
81486+ do_posix_clock_monotonic_gettime(&timeval);
81487+
81488+ shp->shm_createtime = timeval.tv_sec;
81489+ }
81490+#endif
81491 shp->shm_segsz = size;
81492 shp->shm_nattch = 0;
81493 shp->shm_file = file;
81494@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
81495 return 0;
81496 }
81497
81498+static struct ipc_ops shm_ops = {
81499+ .getnew = newseg,
81500+ .associate = shm_security,
81501+ .more_checks = shm_more_checks
81502+};
81503+
81504 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
81505 {
81506 struct ipc_namespace *ns;
81507- struct ipc_ops shm_ops;
81508 struct ipc_params shm_params;
81509
81510 ns = current->nsproxy->ipc_ns;
81511
81512- shm_ops.getnew = newseg;
81513- shm_ops.associate = shm_security;
81514- shm_ops.more_checks = shm_more_checks;
81515-
81516 shm_params.key = key;
81517 shm_params.flg = shmflg;
81518 shm_params.u.size = size;
81519@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
81520 f_mode = FMODE_READ | FMODE_WRITE;
81521 }
81522 if (shmflg & SHM_EXEC) {
81523+
81524+#ifdef CONFIG_PAX_MPROTECT
81525+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
81526+ goto out;
81527+#endif
81528+
81529 prot |= PROT_EXEC;
81530 acc_mode |= S_IXUGO;
81531 }
81532@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
81533 if (err)
81534 goto out_unlock;
81535
81536+#ifdef CONFIG_GRKERNSEC
81537+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
81538+ shp->shm_perm.cuid, shmid) ||
81539+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
81540+ err = -EACCES;
81541+ goto out_unlock;
81542+ }
81543+#endif
81544+
81545 ipc_lock_object(&shp->shm_perm);
81546
81547 /* check if shm_destroy() is tearing down shp */
81548@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
81549 path = shp->shm_file->f_path;
81550 path_get(&path);
81551 shp->shm_nattch++;
81552+#ifdef CONFIG_GRKERNSEC
81553+ shp->shm_lapid = current->pid;
81554+#endif
81555 size = i_size_read(path.dentry->d_inode);
81556 ipc_unlock_object(&shp->shm_perm);
81557 rcu_read_unlock();
81558diff --git a/ipc/util.c b/ipc/util.c
81559index 7684f41..5bf1880 100644
81560--- a/ipc/util.c
81561+++ b/ipc/util.c
81562@@ -71,6 +71,8 @@ struct ipc_proc_iface {
81563 int (*show)(struct seq_file *, void *);
81564 };
81565
81566+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
81567+
81568 static void ipc_memory_notifier(struct work_struct *work)
81569 {
81570 ipcns_notify(IPCNS_MEMCHANGED);
81571@@ -560,6 +562,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
81572 granted_mode >>= 6;
81573 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
81574 granted_mode >>= 3;
81575+
81576+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
81577+ return -1;
81578+
81579 /* is there some bit set in requested_mode but not in granted_mode? */
81580 if ((requested_mode & ~granted_mode & 0007) &&
81581 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
81582diff --git a/kernel/acct.c b/kernel/acct.c
81583index 8d6e145..33e0b1e 100644
81584--- a/kernel/acct.c
81585+++ b/kernel/acct.c
81586@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
81587 */
81588 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
81589 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
81590- file->f_op->write(file, (char *)&ac,
81591+ file->f_op->write(file, (char __force_user *)&ac,
81592 sizeof(acct_t), &file->f_pos);
81593 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
81594 set_fs(fs);
81595diff --git a/kernel/audit.c b/kernel/audit.c
81596index 7ddfd8a..49766eb 100644
81597--- a/kernel/audit.c
81598+++ b/kernel/audit.c
81599@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
81600 3) suppressed due to audit_rate_limit
81601 4) suppressed due to audit_backlog_limit
81602 */
81603-static atomic_t audit_lost = ATOMIC_INIT(0);
81604+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
81605
81606 /* The netlink socket. */
81607 static struct sock *audit_sock;
81608@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
81609 unsigned long now;
81610 int print;
81611
81612- atomic_inc(&audit_lost);
81613+ atomic_inc_unchecked(&audit_lost);
81614
81615 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
81616
81617@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
81618 printk(KERN_WARNING
81619 "audit: audit_lost=%d audit_rate_limit=%d "
81620 "audit_backlog_limit=%d\n",
81621- atomic_read(&audit_lost),
81622+ atomic_read_unchecked(&audit_lost),
81623 audit_rate_limit,
81624 audit_backlog_limit);
81625 audit_panic(message);
81626@@ -665,7 +665,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
81627 status_set.pid = audit_pid;
81628 status_set.rate_limit = audit_rate_limit;
81629 status_set.backlog_limit = audit_backlog_limit;
81630- status_set.lost = atomic_read(&audit_lost);
81631+ status_set.lost = atomic_read_unchecked(&audit_lost);
81632 status_set.backlog = skb_queue_len(&audit_skb_queue);
81633 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
81634 &status_set, sizeof(status_set));
81635@@ -1252,7 +1252,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
81636 int i, avail, new_len;
81637 unsigned char *ptr;
81638 struct sk_buff *skb;
81639- static const unsigned char *hex = "0123456789ABCDEF";
81640+ static const unsigned char hex[] = "0123456789ABCDEF";
81641
81642 if (!ab)
81643 return;
81644diff --git a/kernel/auditsc.c b/kernel/auditsc.c
81645index 9845cb3..3ec9369 100644
81646--- a/kernel/auditsc.c
81647+++ b/kernel/auditsc.c
81648@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
81649 }
81650
81651 /* global counter which is incremented every time something logs in */
81652-static atomic_t session_id = ATOMIC_INIT(0);
81653+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
81654
81655 /**
81656 * audit_set_loginuid - set current task's audit_context loginuid
81657@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
81658 return -EPERM;
81659 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
81660
81661- sessionid = atomic_inc_return(&session_id);
81662+ sessionid = atomic_inc_return_unchecked(&session_id);
81663 if (context && context->in_syscall) {
81664 struct audit_buffer *ab;
81665
81666diff --git a/kernel/capability.c b/kernel/capability.c
81667index 4e66bf9..cdccecf 100644
81668--- a/kernel/capability.c
81669+++ b/kernel/capability.c
81670@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
81671 * before modification is attempted and the application
81672 * fails.
81673 */
81674+ if (tocopy > ARRAY_SIZE(kdata))
81675+ return -EFAULT;
81676+
81677 if (copy_to_user(dataptr, kdata, tocopy
81678 * sizeof(struct __user_cap_data_struct))) {
81679 return -EFAULT;
81680@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
81681 int ret;
81682
81683 rcu_read_lock();
81684- ret = security_capable(__task_cred(t), ns, cap);
81685+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
81686+ gr_task_is_capable(t, __task_cred(t), cap);
81687 rcu_read_unlock();
81688
81689- return (ret == 0);
81690+ return ret;
81691 }
81692
81693 /**
81694@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
81695 int ret;
81696
81697 rcu_read_lock();
81698- ret = security_capable_noaudit(__task_cred(t), ns, cap);
81699+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
81700 rcu_read_unlock();
81701
81702- return (ret == 0);
81703+ return ret;
81704 }
81705
81706 /**
81707@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
81708 BUG();
81709 }
81710
81711- if (security_capable(current_cred(), ns, cap) == 0) {
81712+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
81713 current->flags |= PF_SUPERPRIV;
81714 return true;
81715 }
81716@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
81717 }
81718 EXPORT_SYMBOL(ns_capable);
81719
81720+bool ns_capable_nolog(struct user_namespace *ns, int cap)
81721+{
81722+ if (unlikely(!cap_valid(cap))) {
81723+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
81724+ BUG();
81725+ }
81726+
81727+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
81728+ current->flags |= PF_SUPERPRIV;
81729+ return true;
81730+ }
81731+ return false;
81732+}
81733+EXPORT_SYMBOL(ns_capable_nolog);
81734+
81735 /**
81736 * file_ns_capable - Determine if the file's opener had a capability in effect
81737 * @file: The file we want to check
81738@@ -432,6 +451,12 @@ bool capable(int cap)
81739 }
81740 EXPORT_SYMBOL(capable);
81741
81742+bool capable_nolog(int cap)
81743+{
81744+ return ns_capable_nolog(&init_user_ns, cap);
81745+}
81746+EXPORT_SYMBOL(capable_nolog);
81747+
81748 /**
81749 * inode_capable - Check superior capability over inode
81750 * @inode: The inode in question
81751@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
81752 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
81753 }
81754 EXPORT_SYMBOL(inode_capable);
81755+
81756+bool inode_capable_nolog(const struct inode *inode, int cap)
81757+{
81758+ struct user_namespace *ns = current_user_ns();
81759+
81760+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
81761+}
81762+EXPORT_SYMBOL(inode_capable_nolog);
81763diff --git a/kernel/cgroup.c b/kernel/cgroup.c
81764index 5c9127d..f871169 100644
81765--- a/kernel/cgroup.c
81766+++ b/kernel/cgroup.c
81767@@ -5844,7 +5844,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
81768 struct css_set *cset = link->cset;
81769 struct task_struct *task;
81770 int count = 0;
81771- seq_printf(seq, "css_set %p\n", cset);
81772+ seq_printf(seq, "css_set %pK\n", cset);
81773 list_for_each_entry(task, &cset->tasks, cg_list) {
81774 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
81775 seq_puts(seq, " ...\n");
81776diff --git a/kernel/compat.c b/kernel/compat.c
81777index 0a09e48..f44f3f0 100644
81778--- a/kernel/compat.c
81779+++ b/kernel/compat.c
81780@@ -13,6 +13,7 @@
81781
81782 #include <linux/linkage.h>
81783 #include <linux/compat.h>
81784+#include <linux/module.h>
81785 #include <linux/errno.h>
81786 #include <linux/time.h>
81787 #include <linux/signal.h>
81788@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
81789 mm_segment_t oldfs;
81790 long ret;
81791
81792- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
81793+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
81794 oldfs = get_fs();
81795 set_fs(KERNEL_DS);
81796 ret = hrtimer_nanosleep_restart(restart);
81797@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
81798 oldfs = get_fs();
81799 set_fs(KERNEL_DS);
81800 ret = hrtimer_nanosleep(&tu,
81801- rmtp ? (struct timespec __user *)&rmt : NULL,
81802+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
81803 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
81804 set_fs(oldfs);
81805
81806@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
81807 mm_segment_t old_fs = get_fs();
81808
81809 set_fs(KERNEL_DS);
81810- ret = sys_sigpending((old_sigset_t __user *) &s);
81811+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
81812 set_fs(old_fs);
81813 if (ret == 0)
81814 ret = put_user(s, set);
81815@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
81816 mm_segment_t old_fs = get_fs();
81817
81818 set_fs(KERNEL_DS);
81819- ret = sys_old_getrlimit(resource, &r);
81820+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
81821 set_fs(old_fs);
81822
81823 if (!ret) {
81824@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
81825 set_fs (KERNEL_DS);
81826 ret = sys_wait4(pid,
81827 (stat_addr ?
81828- (unsigned int __user *) &status : NULL),
81829- options, (struct rusage __user *) &r);
81830+ (unsigned int __force_user *) &status : NULL),
81831+ options, (struct rusage __force_user *) &r);
81832 set_fs (old_fs);
81833
81834 if (ret > 0) {
81835@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
81836 memset(&info, 0, sizeof(info));
81837
81838 set_fs(KERNEL_DS);
81839- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
81840- uru ? (struct rusage __user *)&ru : NULL);
81841+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
81842+ uru ? (struct rusage __force_user *)&ru : NULL);
81843 set_fs(old_fs);
81844
81845 if ((ret < 0) || (info.si_signo == 0))
81846@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
81847 oldfs = get_fs();
81848 set_fs(KERNEL_DS);
81849 err = sys_timer_settime(timer_id, flags,
81850- (struct itimerspec __user *) &newts,
81851- (struct itimerspec __user *) &oldts);
81852+ (struct itimerspec __force_user *) &newts,
81853+ (struct itimerspec __force_user *) &oldts);
81854 set_fs(oldfs);
81855 if (!err && old && put_compat_itimerspec(old, &oldts))
81856 return -EFAULT;
81857@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
81858 oldfs = get_fs();
81859 set_fs(KERNEL_DS);
81860 err = sys_timer_gettime(timer_id,
81861- (struct itimerspec __user *) &ts);
81862+ (struct itimerspec __force_user *) &ts);
81863 set_fs(oldfs);
81864 if (!err && put_compat_itimerspec(setting, &ts))
81865 return -EFAULT;
81866@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
81867 oldfs = get_fs();
81868 set_fs(KERNEL_DS);
81869 err = sys_clock_settime(which_clock,
81870- (struct timespec __user *) &ts);
81871+ (struct timespec __force_user *) &ts);
81872 set_fs(oldfs);
81873 return err;
81874 }
81875@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
81876 oldfs = get_fs();
81877 set_fs(KERNEL_DS);
81878 err = sys_clock_gettime(which_clock,
81879- (struct timespec __user *) &ts);
81880+ (struct timespec __force_user *) &ts);
81881 set_fs(oldfs);
81882 if (!err && put_compat_timespec(&ts, tp))
81883 return -EFAULT;
81884@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
81885
81886 oldfs = get_fs();
81887 set_fs(KERNEL_DS);
81888- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
81889+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
81890 set_fs(oldfs);
81891
81892 err = compat_put_timex(utp, &txc);
81893@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
81894 oldfs = get_fs();
81895 set_fs(KERNEL_DS);
81896 err = sys_clock_getres(which_clock,
81897- (struct timespec __user *) &ts);
81898+ (struct timespec __force_user *) &ts);
81899 set_fs(oldfs);
81900 if (!err && tp && put_compat_timespec(&ts, tp))
81901 return -EFAULT;
81902@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
81903 long err;
81904 mm_segment_t oldfs;
81905 struct timespec tu;
81906- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
81907+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
81908
81909- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
81910+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
81911 oldfs = get_fs();
81912 set_fs(KERNEL_DS);
81913 err = clock_nanosleep_restart(restart);
81914@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
81915 oldfs = get_fs();
81916 set_fs(KERNEL_DS);
81917 err = sys_clock_nanosleep(which_clock, flags,
81918- (struct timespec __user *) &in,
81919- (struct timespec __user *) &out);
81920+ (struct timespec __force_user *) &in,
81921+ (struct timespec __force_user *) &out);
81922 set_fs(oldfs);
81923
81924 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
81925diff --git a/kernel/configs.c b/kernel/configs.c
81926index c18b1f1..b9a0132 100644
81927--- a/kernel/configs.c
81928+++ b/kernel/configs.c
81929@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
81930 struct proc_dir_entry *entry;
81931
81932 /* create the current config file */
81933+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
81934+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
81935+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
81936+ &ikconfig_file_ops);
81937+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81938+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
81939+ &ikconfig_file_ops);
81940+#endif
81941+#else
81942 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
81943 &ikconfig_file_ops);
81944+#endif
81945+
81946 if (!entry)
81947 return -ENOMEM;
81948
81949diff --git a/kernel/cred.c b/kernel/cred.c
81950index e0573a4..3874e41 100644
81951--- a/kernel/cred.c
81952+++ b/kernel/cred.c
81953@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
81954 validate_creds(cred);
81955 alter_cred_subscribers(cred, -1);
81956 put_cred(cred);
81957+
81958+#ifdef CONFIG_GRKERNSEC_SETXID
81959+ cred = (struct cred *) tsk->delayed_cred;
81960+ if (cred != NULL) {
81961+ tsk->delayed_cred = NULL;
81962+ validate_creds(cred);
81963+ alter_cred_subscribers(cred, -1);
81964+ put_cred(cred);
81965+ }
81966+#endif
81967 }
81968
81969 /**
81970@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
81971 * Always returns 0 thus allowing this function to be tail-called at the end
81972 * of, say, sys_setgid().
81973 */
81974-int commit_creds(struct cred *new)
81975+static int __commit_creds(struct cred *new)
81976 {
81977 struct task_struct *task = current;
81978 const struct cred *old = task->real_cred;
81979@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
81980
81981 get_cred(new); /* we will require a ref for the subj creds too */
81982
81983+ gr_set_role_label(task, new->uid, new->gid);
81984+
81985 /* dumpability changes */
81986 if (!uid_eq(old->euid, new->euid) ||
81987 !gid_eq(old->egid, new->egid) ||
81988@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
81989 put_cred(old);
81990 return 0;
81991 }
81992+#ifdef CONFIG_GRKERNSEC_SETXID
81993+extern int set_user(struct cred *new);
81994+
81995+void gr_delayed_cred_worker(void)
81996+{
81997+ const struct cred *new = current->delayed_cred;
81998+ struct cred *ncred;
81999+
82000+ current->delayed_cred = NULL;
82001+
82002+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
82003+ // from doing get_cred on it when queueing this
82004+ put_cred(new);
82005+ return;
82006+ } else if (new == NULL)
82007+ return;
82008+
82009+ ncred = prepare_creds();
82010+ if (!ncred)
82011+ goto die;
82012+ // uids
82013+ ncred->uid = new->uid;
82014+ ncred->euid = new->euid;
82015+ ncred->suid = new->suid;
82016+ ncred->fsuid = new->fsuid;
82017+ // gids
82018+ ncred->gid = new->gid;
82019+ ncred->egid = new->egid;
82020+ ncred->sgid = new->sgid;
82021+ ncred->fsgid = new->fsgid;
82022+ // groups
82023+ if (set_groups(ncred, new->group_info) < 0) {
82024+ abort_creds(ncred);
82025+ goto die;
82026+ }
82027+ // caps
82028+ ncred->securebits = new->securebits;
82029+ ncred->cap_inheritable = new->cap_inheritable;
82030+ ncred->cap_permitted = new->cap_permitted;
82031+ ncred->cap_effective = new->cap_effective;
82032+ ncred->cap_bset = new->cap_bset;
82033+
82034+ if (set_user(ncred)) {
82035+ abort_creds(ncred);
82036+ goto die;
82037+ }
82038+
82039+ // from doing get_cred on it when queueing this
82040+ put_cred(new);
82041+
82042+ __commit_creds(ncred);
82043+ return;
82044+die:
82045+ // from doing get_cred on it when queueing this
82046+ put_cred(new);
82047+ do_group_exit(SIGKILL);
82048+}
82049+#endif
82050+
82051+int commit_creds(struct cred *new)
82052+{
82053+#ifdef CONFIG_GRKERNSEC_SETXID
82054+ int ret;
82055+ int schedule_it = 0;
82056+ struct task_struct *t;
82057+
82058+ /* we won't get called with tasklist_lock held for writing
82059+ and interrupts disabled as the cred struct in that case is
82060+ init_cred
82061+ */
82062+ if (grsec_enable_setxid && !current_is_single_threaded() &&
82063+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
82064+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
82065+ schedule_it = 1;
82066+ }
82067+ ret = __commit_creds(new);
82068+ if (schedule_it) {
82069+ rcu_read_lock();
82070+ read_lock(&tasklist_lock);
82071+ for (t = next_thread(current); t != current;
82072+ t = next_thread(t)) {
82073+ if (t->delayed_cred == NULL) {
82074+ t->delayed_cred = get_cred(new);
82075+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
82076+ set_tsk_need_resched(t);
82077+ }
82078+ }
82079+ read_unlock(&tasklist_lock);
82080+ rcu_read_unlock();
82081+ }
82082+ return ret;
82083+#else
82084+ return __commit_creds(new);
82085+#endif
82086+}
82087+
82088 EXPORT_SYMBOL(commit_creds);
82089
82090 /**
82091diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
82092index 0506d44..2c20034 100644
82093--- a/kernel/debug/debug_core.c
82094+++ b/kernel/debug/debug_core.c
82095@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
82096 */
82097 static atomic_t masters_in_kgdb;
82098 static atomic_t slaves_in_kgdb;
82099-static atomic_t kgdb_break_tasklet_var;
82100+static atomic_unchecked_t kgdb_break_tasklet_var;
82101 atomic_t kgdb_setting_breakpoint;
82102
82103 struct task_struct *kgdb_usethread;
82104@@ -133,7 +133,7 @@ int kgdb_single_step;
82105 static pid_t kgdb_sstep_pid;
82106
82107 /* to keep track of the CPU which is doing the single stepping*/
82108-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
82109+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
82110
82111 /*
82112 * If you are debugging a problem where roundup (the collection of
82113@@ -541,7 +541,7 @@ return_normal:
82114 * kernel will only try for the value of sstep_tries before
82115 * giving up and continuing on.
82116 */
82117- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
82118+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
82119 (kgdb_info[cpu].task &&
82120 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
82121 atomic_set(&kgdb_active, -1);
82122@@ -635,8 +635,8 @@ cpu_master_loop:
82123 }
82124
82125 kgdb_restore:
82126- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
82127- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
82128+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
82129+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
82130 if (kgdb_info[sstep_cpu].task)
82131 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
82132 else
82133@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
82134 static void kgdb_tasklet_bpt(unsigned long ing)
82135 {
82136 kgdb_breakpoint();
82137- atomic_set(&kgdb_break_tasklet_var, 0);
82138+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
82139 }
82140
82141 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
82142
82143 void kgdb_schedule_breakpoint(void)
82144 {
82145- if (atomic_read(&kgdb_break_tasklet_var) ||
82146+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
82147 atomic_read(&kgdb_active) != -1 ||
82148 atomic_read(&kgdb_setting_breakpoint))
82149 return;
82150- atomic_inc(&kgdb_break_tasklet_var);
82151+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
82152 tasklet_schedule(&kgdb_tasklet_breakpoint);
82153 }
82154 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
82155diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
82156index 00eb8f7..d7e3244 100644
82157--- a/kernel/debug/kdb/kdb_main.c
82158+++ b/kernel/debug/kdb/kdb_main.c
82159@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
82160 continue;
82161
82162 kdb_printf("%-20s%8u 0x%p ", mod->name,
82163- mod->core_size, (void *)mod);
82164+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
82165 #ifdef CONFIG_MODULE_UNLOAD
82166 kdb_printf("%4ld ", module_refcount(mod));
82167 #endif
82168@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
82169 kdb_printf(" (Loading)");
82170 else
82171 kdb_printf(" (Live)");
82172- kdb_printf(" 0x%p", mod->module_core);
82173+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
82174
82175 #ifdef CONFIG_MODULE_UNLOAD
82176 {
82177diff --git a/kernel/events/core.c b/kernel/events/core.c
82178index 953c143..5646bb1 100644
82179--- a/kernel/events/core.c
82180+++ b/kernel/events/core.c
82181@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
82182 * 0 - disallow raw tracepoint access for unpriv
82183 * 1 - disallow cpu events for unpriv
82184 * 2 - disallow kernel profiling for unpriv
82185+ * 3 - disallow all unpriv perf event use
82186 */
82187-int sysctl_perf_event_paranoid __read_mostly = 1;
82188+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
82189+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
82190+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
82191+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
82192+#else
82193+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
82194+#endif
82195
82196 /* Minimum for 512 kiB + 1 user control page */
82197 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
82198@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
82199 update_perf_cpu_limits();
82200 }
82201
82202-static atomic64_t perf_event_id;
82203+static atomic64_unchecked_t perf_event_id;
82204
82205 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
82206 enum event_type_t event_type);
82207@@ -2940,7 +2947,7 @@ static void __perf_event_read(void *info)
82208
82209 static inline u64 perf_event_count(struct perf_event *event)
82210 {
82211- return local64_read(&event->count) + atomic64_read(&event->child_count);
82212+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
82213 }
82214
82215 static u64 perf_event_read(struct perf_event *event)
82216@@ -3308,9 +3315,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
82217 mutex_lock(&event->child_mutex);
82218 total += perf_event_read(event);
82219 *enabled += event->total_time_enabled +
82220- atomic64_read(&event->child_total_time_enabled);
82221+ atomic64_read_unchecked(&event->child_total_time_enabled);
82222 *running += event->total_time_running +
82223- atomic64_read(&event->child_total_time_running);
82224+ atomic64_read_unchecked(&event->child_total_time_running);
82225
82226 list_for_each_entry(child, &event->child_list, child_list) {
82227 total += perf_event_read(child);
82228@@ -3725,10 +3732,10 @@ void perf_event_update_userpage(struct perf_event *event)
82229 userpg->offset -= local64_read(&event->hw.prev_count);
82230
82231 userpg->time_enabled = enabled +
82232- atomic64_read(&event->child_total_time_enabled);
82233+ atomic64_read_unchecked(&event->child_total_time_enabled);
82234
82235 userpg->time_running = running +
82236- atomic64_read(&event->child_total_time_running);
82237+ atomic64_read_unchecked(&event->child_total_time_running);
82238
82239 arch_perf_update_userpage(userpg, now);
82240
82241@@ -4279,7 +4286,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
82242
82243 /* Data. */
82244 sp = perf_user_stack_pointer(regs);
82245- rem = __output_copy_user(handle, (void *) sp, dump_size);
82246+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
82247 dyn_size = dump_size - rem;
82248
82249 perf_output_skip(handle, rem);
82250@@ -4370,11 +4377,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
82251 values[n++] = perf_event_count(event);
82252 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
82253 values[n++] = enabled +
82254- atomic64_read(&event->child_total_time_enabled);
82255+ atomic64_read_unchecked(&event->child_total_time_enabled);
82256 }
82257 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
82258 values[n++] = running +
82259- atomic64_read(&event->child_total_time_running);
82260+ atomic64_read_unchecked(&event->child_total_time_running);
82261 }
82262 if (read_format & PERF_FORMAT_ID)
82263 values[n++] = primary_event_id(event);
82264@@ -5112,12 +5119,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
82265 * need to add enough zero bytes after the string to handle
82266 * the 64bit alignment we do later.
82267 */
82268- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
82269+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
82270 if (!buf) {
82271 name = strncpy(tmp, "//enomem", sizeof(tmp));
82272 goto got_name;
82273 }
82274- name = d_path(&file->f_path, buf, PATH_MAX);
82275+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
82276 if (IS_ERR(name)) {
82277 name = strncpy(tmp, "//toolong", sizeof(tmp));
82278 goto got_name;
82279@@ -6639,7 +6646,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
82280 event->parent = parent_event;
82281
82282 event->ns = get_pid_ns(task_active_pid_ns(current));
82283- event->id = atomic64_inc_return(&perf_event_id);
82284+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
82285
82286 event->state = PERF_EVENT_STATE_INACTIVE;
82287
82288@@ -6938,6 +6945,11 @@ SYSCALL_DEFINE5(perf_event_open,
82289 if (flags & ~PERF_FLAG_ALL)
82290 return -EINVAL;
82291
82292+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
82293+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
82294+ return -EACCES;
82295+#endif
82296+
82297 err = perf_copy_attr(attr_uptr, &attr);
82298 if (err)
82299 return err;
82300@@ -7271,10 +7283,10 @@ static void sync_child_event(struct perf_event *child_event,
82301 /*
82302 * Add back the child's count to the parent's count:
82303 */
82304- atomic64_add(child_val, &parent_event->child_count);
82305- atomic64_add(child_event->total_time_enabled,
82306+ atomic64_add_unchecked(child_val, &parent_event->child_count);
82307+ atomic64_add_unchecked(child_event->total_time_enabled,
82308 &parent_event->child_total_time_enabled);
82309- atomic64_add(child_event->total_time_running,
82310+ atomic64_add_unchecked(child_event->total_time_running,
82311 &parent_event->child_total_time_running);
82312
82313 /*
82314diff --git a/kernel/events/internal.h b/kernel/events/internal.h
82315index ca65997..60df03d 100644
82316--- a/kernel/events/internal.h
82317+++ b/kernel/events/internal.h
82318@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
82319 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
82320 }
82321
82322-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
82323-static inline unsigned int \
82324+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
82325+static inline unsigned long \
82326 func_name(struct perf_output_handle *handle, \
82327- const void *buf, unsigned int len) \
82328+ const void user *buf, unsigned long len) \
82329 { \
82330 unsigned long size, written; \
82331 \
82332@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
82333 return n;
82334 }
82335
82336-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
82337+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
82338
82339 #define MEMCPY_SKIP(dst, src, n) (n)
82340
82341-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
82342+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
82343
82344 #ifndef arch_perf_out_copy_user
82345 #define arch_perf_out_copy_user __copy_from_user_inatomic
82346 #endif
82347
82348-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
82349+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
82350
82351 /* Callchain handling */
82352 extern struct perf_callchain_entry *
82353diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
82354index ad8e1bd..fed7ba9 100644
82355--- a/kernel/events/uprobes.c
82356+++ b/kernel/events/uprobes.c
82357@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
82358 {
82359 struct page *page;
82360 uprobe_opcode_t opcode;
82361- int result;
82362+ long result;
82363
82364 pagefault_disable();
82365 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
82366diff --git a/kernel/exit.c b/kernel/exit.c
82367index a949819..a5f127d 100644
82368--- a/kernel/exit.c
82369+++ b/kernel/exit.c
82370@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
82371 struct task_struct *leader;
82372 int zap_leader;
82373 repeat:
82374+#ifdef CONFIG_NET
82375+ gr_del_task_from_ip_table(p);
82376+#endif
82377+
82378 /* don't need to get the RCU readlock here - the process is dead and
82379 * can't be modifying its own credentials. But shut RCU-lockdep up */
82380 rcu_read_lock();
82381@@ -329,7 +333,7 @@ int allow_signal(int sig)
82382 * know it'll be handled, so that they don't get converted to
82383 * SIGKILL or just silently dropped.
82384 */
82385- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
82386+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
82387 recalc_sigpending();
82388 spin_unlock_irq(&current->sighand->siglock);
82389 return 0;
82390@@ -698,6 +702,8 @@ void do_exit(long code)
82391 struct task_struct *tsk = current;
82392 int group_dead;
82393
82394+ set_fs(USER_DS);
82395+
82396 profile_task_exit(tsk);
82397
82398 WARN_ON(blk_needs_flush_plug(tsk));
82399@@ -714,7 +720,6 @@ void do_exit(long code)
82400 * mm_release()->clear_child_tid() from writing to a user-controlled
82401 * kernel address.
82402 */
82403- set_fs(USER_DS);
82404
82405 ptrace_event(PTRACE_EVENT_EXIT, code);
82406
82407@@ -773,6 +778,9 @@ void do_exit(long code)
82408 tsk->exit_code = code;
82409 taskstats_exit(tsk, group_dead);
82410
82411+ gr_acl_handle_psacct(tsk, code);
82412+ gr_acl_handle_exit();
82413+
82414 exit_mm(tsk);
82415
82416 if (group_dead)
82417@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
82418 * Take down every thread in the group. This is called by fatal signals
82419 * as well as by sys_exit_group (below).
82420 */
82421-void
82422+__noreturn void
82423 do_group_exit(int exit_code)
82424 {
82425 struct signal_struct *sig = current->signal;
82426diff --git a/kernel/fork.c b/kernel/fork.c
82427index 086fe73..72c1122 100644
82428--- a/kernel/fork.c
82429+++ b/kernel/fork.c
82430@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
82431 *stackend = STACK_END_MAGIC; /* for overflow detection */
82432
82433 #ifdef CONFIG_CC_STACKPROTECTOR
82434- tsk->stack_canary = get_random_int();
82435+ tsk->stack_canary = pax_get_random_long();
82436 #endif
82437
82438 /*
82439@@ -345,12 +345,80 @@ free_tsk:
82440 }
82441
82442 #ifdef CONFIG_MMU
82443-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82444+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
82445+{
82446+ struct vm_area_struct *tmp;
82447+ unsigned long charge;
82448+ struct file *file;
82449+ int retval;
82450+
82451+ charge = 0;
82452+ if (mpnt->vm_flags & VM_ACCOUNT) {
82453+ unsigned long len = vma_pages(mpnt);
82454+
82455+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
82456+ goto fail_nomem;
82457+ charge = len;
82458+ }
82459+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82460+ if (!tmp)
82461+ goto fail_nomem;
82462+ *tmp = *mpnt;
82463+ tmp->vm_mm = mm;
82464+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
82465+ retval = vma_dup_policy(mpnt, tmp);
82466+ if (retval)
82467+ goto fail_nomem_policy;
82468+ if (anon_vma_fork(tmp, mpnt))
82469+ goto fail_nomem_anon_vma_fork;
82470+ tmp->vm_flags &= ~VM_LOCKED;
82471+ tmp->vm_next = tmp->vm_prev = NULL;
82472+ tmp->vm_mirror = NULL;
82473+ file = tmp->vm_file;
82474+ if (file) {
82475+ struct inode *inode = file_inode(file);
82476+ struct address_space *mapping = file->f_mapping;
82477+
82478+ get_file(file);
82479+ if (tmp->vm_flags & VM_DENYWRITE)
82480+ atomic_dec(&inode->i_writecount);
82481+ mutex_lock(&mapping->i_mmap_mutex);
82482+ if (tmp->vm_flags & VM_SHARED)
82483+ mapping->i_mmap_writable++;
82484+ flush_dcache_mmap_lock(mapping);
82485+ /* insert tmp into the share list, just after mpnt */
82486+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
82487+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
82488+ else
82489+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
82490+ flush_dcache_mmap_unlock(mapping);
82491+ mutex_unlock(&mapping->i_mmap_mutex);
82492+ }
82493+
82494+ /*
82495+ * Clear hugetlb-related page reserves for children. This only
82496+ * affects MAP_PRIVATE mappings. Faults generated by the child
82497+ * are not guaranteed to succeed, even if read-only
82498+ */
82499+ if (is_vm_hugetlb_page(tmp))
82500+ reset_vma_resv_huge_pages(tmp);
82501+
82502+ return tmp;
82503+
82504+fail_nomem_anon_vma_fork:
82505+ mpol_put(vma_policy(tmp));
82506+fail_nomem_policy:
82507+ kmem_cache_free(vm_area_cachep, tmp);
82508+fail_nomem:
82509+ vm_unacct_memory(charge);
82510+ return NULL;
82511+}
82512+
82513+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82514 {
82515 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
82516 struct rb_node **rb_link, *rb_parent;
82517 int retval;
82518- unsigned long charge;
82519
82520 uprobe_start_dup_mmap();
82521 down_write(&oldmm->mmap_sem);
82522@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82523
82524 prev = NULL;
82525 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
82526- struct file *file;
82527-
82528 if (mpnt->vm_flags & VM_DONTCOPY) {
82529 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
82530 -vma_pages(mpnt));
82531 continue;
82532 }
82533- charge = 0;
82534- if (mpnt->vm_flags & VM_ACCOUNT) {
82535- unsigned long len = vma_pages(mpnt);
82536-
82537- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
82538- goto fail_nomem;
82539- charge = len;
82540- }
82541- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82542- if (!tmp)
82543- goto fail_nomem;
82544- *tmp = *mpnt;
82545- INIT_LIST_HEAD(&tmp->anon_vma_chain);
82546- retval = vma_dup_policy(mpnt, tmp);
82547- if (retval)
82548- goto fail_nomem_policy;
82549- tmp->vm_mm = mm;
82550- if (anon_vma_fork(tmp, mpnt))
82551- goto fail_nomem_anon_vma_fork;
82552- tmp->vm_flags &= ~VM_LOCKED;
82553- tmp->vm_next = tmp->vm_prev = NULL;
82554- file = tmp->vm_file;
82555- if (file) {
82556- struct inode *inode = file_inode(file);
82557- struct address_space *mapping = file->f_mapping;
82558-
82559- get_file(file);
82560- if (tmp->vm_flags & VM_DENYWRITE)
82561- atomic_dec(&inode->i_writecount);
82562- mutex_lock(&mapping->i_mmap_mutex);
82563- if (tmp->vm_flags & VM_SHARED)
82564- mapping->i_mmap_writable++;
82565- flush_dcache_mmap_lock(mapping);
82566- /* insert tmp into the share list, just after mpnt */
82567- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
82568- vma_nonlinear_insert(tmp,
82569- &mapping->i_mmap_nonlinear);
82570- else
82571- vma_interval_tree_insert_after(tmp, mpnt,
82572- &mapping->i_mmap);
82573- flush_dcache_mmap_unlock(mapping);
82574- mutex_unlock(&mapping->i_mmap_mutex);
82575+ tmp = dup_vma(mm, oldmm, mpnt);
82576+ if (!tmp) {
82577+ retval = -ENOMEM;
82578+ goto out;
82579 }
82580
82581 /*
82582@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82583 if (retval)
82584 goto out;
82585 }
82586+
82587+#ifdef CONFIG_PAX_SEGMEXEC
82588+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
82589+ struct vm_area_struct *mpnt_m;
82590+
82591+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
82592+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
82593+
82594+ if (!mpnt->vm_mirror)
82595+ continue;
82596+
82597+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
82598+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
82599+ mpnt->vm_mirror = mpnt_m;
82600+ } else {
82601+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
82602+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
82603+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
82604+ mpnt->vm_mirror->vm_mirror = mpnt;
82605+ }
82606+ }
82607+ BUG_ON(mpnt_m);
82608+ }
82609+#endif
82610+
82611 /* a new mm has just been created */
82612 arch_dup_mmap(oldmm, mm);
82613 retval = 0;
82614@@ -468,14 +521,6 @@ out:
82615 up_write(&oldmm->mmap_sem);
82616 uprobe_end_dup_mmap();
82617 return retval;
82618-fail_nomem_anon_vma_fork:
82619- mpol_put(vma_policy(tmp));
82620-fail_nomem_policy:
82621- kmem_cache_free(vm_area_cachep, tmp);
82622-fail_nomem:
82623- retval = -ENOMEM;
82624- vm_unacct_memory(charge);
82625- goto out;
82626 }
82627
82628 static inline int mm_alloc_pgd(struct mm_struct *mm)
82629@@ -688,8 +733,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
82630 return ERR_PTR(err);
82631
82632 mm = get_task_mm(task);
82633- if (mm && mm != current->mm &&
82634- !ptrace_may_access(task, mode)) {
82635+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
82636+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
82637 mmput(mm);
82638 mm = ERR_PTR(-EACCES);
82639 }
82640@@ -911,13 +956,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
82641 spin_unlock(&fs->lock);
82642 return -EAGAIN;
82643 }
82644- fs->users++;
82645+ atomic_inc(&fs->users);
82646 spin_unlock(&fs->lock);
82647 return 0;
82648 }
82649 tsk->fs = copy_fs_struct(fs);
82650 if (!tsk->fs)
82651 return -ENOMEM;
82652+ /* Carry through gr_chroot_dentry and is_chrooted instead
82653+ of recomputing it here. Already copied when the task struct
82654+ is duplicated. This allows pivot_root to not be treated as
82655+ a chroot
82656+ */
82657+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
82658+
82659 return 0;
82660 }
82661
82662@@ -1128,7 +1180,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
82663 * parts of the process environment (as per the clone
82664 * flags). The actual kick-off is left to the caller.
82665 */
82666-static struct task_struct *copy_process(unsigned long clone_flags,
82667+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
82668 unsigned long stack_start,
82669 unsigned long stack_size,
82670 int __user *child_tidptr,
82671@@ -1200,6 +1252,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
82672 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
82673 #endif
82674 retval = -EAGAIN;
82675+
82676+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
82677+
82678 if (atomic_read(&p->real_cred->user->processes) >=
82679 task_rlimit(p, RLIMIT_NPROC)) {
82680 if (p->real_cred->user != INIT_USER &&
82681@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
82682 goto bad_fork_free_pid;
82683 }
82684
82685+ /* synchronizes with gr_set_acls()
82686+ we need to call this past the point of no return for fork()
82687+ */
82688+ gr_copy_label(p);
82689+
82690 if (likely(p->pid)) {
82691 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
82692
82693@@ -1534,6 +1594,8 @@ bad_fork_cleanup_count:
82694 bad_fork_free:
82695 free_task(p);
82696 fork_out:
82697+ gr_log_forkfail(retval);
82698+
82699 return ERR_PTR(retval);
82700 }
82701
82702@@ -1595,6 +1657,7 @@ long do_fork(unsigned long clone_flags,
82703
82704 p = copy_process(clone_flags, stack_start, stack_size,
82705 child_tidptr, NULL, trace);
82706+ add_latent_entropy();
82707 /*
82708 * Do this prior waking up the new thread - the thread pointer
82709 * might get invalid after that point, if the thread exits quickly.
82710@@ -1609,6 +1672,8 @@ long do_fork(unsigned long clone_flags,
82711 if (clone_flags & CLONE_PARENT_SETTID)
82712 put_user(nr, parent_tidptr);
82713
82714+ gr_handle_brute_check();
82715+
82716 if (clone_flags & CLONE_VFORK) {
82717 p->vfork_done = &vfork;
82718 init_completion(&vfork);
82719@@ -1725,7 +1790,7 @@ void __init proc_caches_init(void)
82720 mm_cachep = kmem_cache_create("mm_struct",
82721 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
82722 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
82723- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
82724+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
82725 mmap_init();
82726 nsproxy_cache_init();
82727 }
82728@@ -1765,7 +1830,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
82729 return 0;
82730
82731 /* don't need lock here; in the worst case we'll do useless copy */
82732- if (fs->users == 1)
82733+ if (atomic_read(&fs->users) == 1)
82734 return 0;
82735
82736 *new_fsp = copy_fs_struct(fs);
82737@@ -1872,7 +1937,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
82738 fs = current->fs;
82739 spin_lock(&fs->lock);
82740 current->fs = new_fs;
82741- if (--fs->users)
82742+ gr_set_chroot_entries(current, &current->fs->root);
82743+ if (atomic_dec_return(&fs->users))
82744 new_fs = NULL;
82745 else
82746 new_fs = fs;
82747diff --git a/kernel/futex.c b/kernel/futex.c
82748index 221a58f..1b8cfce 100644
82749--- a/kernel/futex.c
82750+++ b/kernel/futex.c
82751@@ -54,6 +54,7 @@
82752 #include <linux/mount.h>
82753 #include <linux/pagemap.h>
82754 #include <linux/syscalls.h>
82755+#include <linux/ptrace.h>
82756 #include <linux/signal.h>
82757 #include <linux/export.h>
82758 #include <linux/magic.h>
82759@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
82760 struct page *page, *page_head;
82761 int err, ro = 0;
82762
82763+#ifdef CONFIG_PAX_SEGMEXEC
82764+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
82765+ return -EFAULT;
82766+#endif
82767+
82768 /*
82769 * The futex address must be "naturally" aligned.
82770 */
82771@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
82772
82773 static int get_futex_value_locked(u32 *dest, u32 __user *from)
82774 {
82775- int ret;
82776+ unsigned long ret;
82777
82778 pagefault_disable();
82779 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
82780@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
82781 {
82782 u32 curval;
82783 int i;
82784+ mm_segment_t oldfs;
82785
82786 /*
82787 * This will fail and we want it. Some arch implementations do
82788@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
82789 * implementation, the non-functional ones will return
82790 * -ENOSYS.
82791 */
82792+ oldfs = get_fs();
82793+ set_fs(USER_DS);
82794 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
82795 futex_cmpxchg_enabled = 1;
82796+ set_fs(oldfs);
82797
82798 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
82799 plist_head_init(&futex_queues[i].chain);
82800diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
82801index f9f44fd..29885e4 100644
82802--- a/kernel/futex_compat.c
82803+++ b/kernel/futex_compat.c
82804@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
82805 return 0;
82806 }
82807
82808-static void __user *futex_uaddr(struct robust_list __user *entry,
82809+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
82810 compat_long_t futex_offset)
82811 {
82812 compat_uptr_t base = ptr_to_compat(entry);
82813diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
82814index 9b22d03..6295b62 100644
82815--- a/kernel/gcov/base.c
82816+++ b/kernel/gcov/base.c
82817@@ -102,11 +102,6 @@ void gcov_enable_events(void)
82818 }
82819
82820 #ifdef CONFIG_MODULES
82821-static inline int within(void *addr, void *start, unsigned long size)
82822-{
82823- return ((addr >= start) && (addr < start + size));
82824-}
82825-
82826 /* Update list and generate events when modules are unloaded. */
82827 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
82828 void *data)
82829@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
82830 prev = NULL;
82831 /* Remove entries located in module from linked list. */
82832 for (info = gcov_info_head; info; info = info->next) {
82833- if (within(info, mod->module_core, mod->core_size)) {
82834+ if (within_module_core_rw((unsigned long)info, mod)) {
82835 if (prev)
82836 prev->next = info->next;
82837 else
82838diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
82839index 383319b..56ebb13 100644
82840--- a/kernel/hrtimer.c
82841+++ b/kernel/hrtimer.c
82842@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
82843 local_irq_restore(flags);
82844 }
82845
82846-static void run_hrtimer_softirq(struct softirq_action *h)
82847+static __latent_entropy void run_hrtimer_softirq(void)
82848 {
82849 hrtimer_peek_ahead_timers();
82850 }
82851diff --git a/kernel/irq_work.c b/kernel/irq_work.c
82852index 55fcce6..0e4cf34 100644
82853--- a/kernel/irq_work.c
82854+++ b/kernel/irq_work.c
82855@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
82856 return NOTIFY_OK;
82857 }
82858
82859-static struct notifier_block cpu_notify;
82860+static struct notifier_block cpu_notify = {
82861+ .notifier_call = irq_work_cpu_notify,
82862+ .priority = 0,
82863+};
82864
82865 static __init int irq_work_init_cpu_notifier(void)
82866 {
82867- cpu_notify.notifier_call = irq_work_cpu_notify;
82868- cpu_notify.priority = 0;
82869 register_cpu_notifier(&cpu_notify);
82870 return 0;
82871 }
82872diff --git a/kernel/jump_label.c b/kernel/jump_label.c
82873index 297a924..7290070 100644
82874--- a/kernel/jump_label.c
82875+++ b/kernel/jump_label.c
82876@@ -14,6 +14,7 @@
82877 #include <linux/err.h>
82878 #include <linux/static_key.h>
82879 #include <linux/jump_label_ratelimit.h>
82880+#include <linux/mm.h>
82881
82882 #ifdef HAVE_JUMP_LABEL
82883
82884@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
82885
82886 size = (((unsigned long)stop - (unsigned long)start)
82887 / sizeof(struct jump_entry));
82888+ pax_open_kernel();
82889 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
82890+ pax_close_kernel();
82891 }
82892
82893 static void jump_label_update(struct static_key *key, int enable);
82894@@ -358,10 +361,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
82895 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
82896 struct jump_entry *iter;
82897
82898+ pax_open_kernel();
82899 for (iter = iter_start; iter < iter_stop; iter++) {
82900 if (within_module_init(iter->code, mod))
82901 iter->code = 0;
82902 }
82903+ pax_close_kernel();
82904 }
82905
82906 static int
82907diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
82908index 3127ad5..159d880 100644
82909--- a/kernel/kallsyms.c
82910+++ b/kernel/kallsyms.c
82911@@ -11,6 +11,9 @@
82912 * Changed the compression method from stem compression to "table lookup"
82913 * compression (see scripts/kallsyms.c for a more complete description)
82914 */
82915+#ifdef CONFIG_GRKERNSEC_HIDESYM
82916+#define __INCLUDED_BY_HIDESYM 1
82917+#endif
82918 #include <linux/kallsyms.h>
82919 #include <linux/module.h>
82920 #include <linux/init.h>
82921@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
82922
82923 static inline int is_kernel_inittext(unsigned long addr)
82924 {
82925+ if (system_state != SYSTEM_BOOTING)
82926+ return 0;
82927+
82928 if (addr >= (unsigned long)_sinittext
82929 && addr <= (unsigned long)_einittext)
82930 return 1;
82931 return 0;
82932 }
82933
82934+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82935+#ifdef CONFIG_MODULES
82936+static inline int is_module_text(unsigned long addr)
82937+{
82938+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
82939+ return 1;
82940+
82941+ addr = ktla_ktva(addr);
82942+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
82943+}
82944+#else
82945+static inline int is_module_text(unsigned long addr)
82946+{
82947+ return 0;
82948+}
82949+#endif
82950+#endif
82951+
82952 static inline int is_kernel_text(unsigned long addr)
82953 {
82954 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
82955@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
82956
82957 static inline int is_kernel(unsigned long addr)
82958 {
82959+
82960+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82961+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
82962+ return 1;
82963+
82964+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
82965+#else
82966 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
82967+#endif
82968+
82969 return 1;
82970 return in_gate_area_no_mm(addr);
82971 }
82972
82973 static int is_ksym_addr(unsigned long addr)
82974 {
82975+
82976+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82977+ if (is_module_text(addr))
82978+ return 0;
82979+#endif
82980+
82981 if (all_var)
82982 return is_kernel(addr);
82983
82984@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
82985
82986 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
82987 {
82988- iter->name[0] = '\0';
82989 iter->nameoff = get_symbol_offset(new_pos);
82990 iter->pos = new_pos;
82991 }
82992@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
82993 {
82994 struct kallsym_iter *iter = m->private;
82995
82996+#ifdef CONFIG_GRKERNSEC_HIDESYM
82997+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
82998+ return 0;
82999+#endif
83000+
83001 /* Some debugging symbols have no name. Ignore them. */
83002 if (!iter->name[0])
83003 return 0;
83004@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
83005 */
83006 type = iter->exported ? toupper(iter->type) :
83007 tolower(iter->type);
83008+
83009 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
83010 type, iter->name, iter->module_name);
83011 } else
83012@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
83013 struct kallsym_iter *iter;
83014 int ret;
83015
83016- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
83017+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
83018 if (!iter)
83019 return -ENOMEM;
83020 reset_iter(iter, 0);
83021diff --git a/kernel/kcmp.c b/kernel/kcmp.c
83022index e30ac0f..3528cac 100644
83023--- a/kernel/kcmp.c
83024+++ b/kernel/kcmp.c
83025@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
83026 struct task_struct *task1, *task2;
83027 int ret;
83028
83029+#ifdef CONFIG_GRKERNSEC
83030+ return -ENOSYS;
83031+#endif
83032+
83033 rcu_read_lock();
83034
83035 /*
83036diff --git a/kernel/kexec.c b/kernel/kexec.c
83037index ecd783d..9aa270c 100644
83038--- a/kernel/kexec.c
83039+++ b/kernel/kexec.c
83040@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
83041 unsigned long flags)
83042 {
83043 struct compat_kexec_segment in;
83044- struct kexec_segment out, __user *ksegments;
83045+ struct kexec_segment out;
83046+ struct kexec_segment __user *ksegments;
83047 unsigned long i, result;
83048
83049 /* Don't allow clients that don't understand the native
83050diff --git a/kernel/kmod.c b/kernel/kmod.c
83051index b086006..6d2e579 100644
83052--- a/kernel/kmod.c
83053+++ b/kernel/kmod.c
83054@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
83055 kfree(info->argv);
83056 }
83057
83058-static int call_modprobe(char *module_name, int wait)
83059+static int call_modprobe(char *module_name, char *module_param, int wait)
83060 {
83061 struct subprocess_info *info;
83062 static char *envp[] = {
83063@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
83064 NULL
83065 };
83066
83067- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
83068+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
83069 if (!argv)
83070 goto out;
83071
83072@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
83073 argv[1] = "-q";
83074 argv[2] = "--";
83075 argv[3] = module_name; /* check free_modprobe_argv() */
83076- argv[4] = NULL;
83077+ argv[4] = module_param;
83078+ argv[5] = NULL;
83079
83080 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
83081 NULL, free_modprobe_argv, NULL);
83082@@ -129,9 +130,8 @@ out:
83083 * If module auto-loading support is disabled then this function
83084 * becomes a no-operation.
83085 */
83086-int __request_module(bool wait, const char *fmt, ...)
83087+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
83088 {
83089- va_list args;
83090 char module_name[MODULE_NAME_LEN];
83091 unsigned int max_modprobes;
83092 int ret;
83093@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
83094 if (!modprobe_path[0])
83095 return 0;
83096
83097- va_start(args, fmt);
83098- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
83099- va_end(args);
83100+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
83101 if (ret >= MODULE_NAME_LEN)
83102 return -ENAMETOOLONG;
83103
83104@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
83105 if (ret)
83106 return ret;
83107
83108+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83109+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
83110+ /* hack to workaround consolekit/udisks stupidity */
83111+ read_lock(&tasklist_lock);
83112+ if (!strcmp(current->comm, "mount") &&
83113+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
83114+ read_unlock(&tasklist_lock);
83115+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
83116+ return -EPERM;
83117+ }
83118+ read_unlock(&tasklist_lock);
83119+ }
83120+#endif
83121+
83122 /* If modprobe needs a service that is in a module, we get a recursive
83123 * loop. Limit the number of running kmod threads to max_threads/2 or
83124 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
83125@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
83126
83127 trace_module_request(module_name, wait, _RET_IP_);
83128
83129- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
83130+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
83131
83132 atomic_dec(&kmod_concurrent);
83133 return ret;
83134 }
83135+
83136+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
83137+{
83138+ va_list args;
83139+ int ret;
83140+
83141+ va_start(args, fmt);
83142+ ret = ____request_module(wait, module_param, fmt, args);
83143+ va_end(args);
83144+
83145+ return ret;
83146+}
83147+
83148+int __request_module(bool wait, const char *fmt, ...)
83149+{
83150+ va_list args;
83151+ int ret;
83152+
83153+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83154+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
83155+ char module_param[MODULE_NAME_LEN];
83156+
83157+ memset(module_param, 0, sizeof(module_param));
83158+
83159+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
83160+
83161+ va_start(args, fmt);
83162+ ret = ____request_module(wait, module_param, fmt, args);
83163+ va_end(args);
83164+
83165+ return ret;
83166+ }
83167+#endif
83168+
83169+ va_start(args, fmt);
83170+ ret = ____request_module(wait, NULL, fmt, args);
83171+ va_end(args);
83172+
83173+ return ret;
83174+}
83175+
83176 EXPORT_SYMBOL(__request_module);
83177 #endif /* CONFIG_MODULES */
83178
83179@@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
83180 */
83181 set_user_nice(current, 0);
83182
83183+#ifdef CONFIG_GRKERNSEC
83184+ /* this is race-free as far as userland is concerned as we copied
83185+ out the path to be used prior to this point and are now operating
83186+ on that copy
83187+ */
83188+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
83189+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
83190+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
83191+ retval = -EPERM;
83192+ goto fail;
83193+ }
83194+#endif
83195+
83196 retval = -ENOMEM;
83197 new = prepare_kernel_cred(current);
83198 if (!new)
83199@@ -260,6 +326,10 @@ static int call_helper(void *data)
83200
83201 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
83202 {
83203+#ifdef CONFIG_GRKERNSEC
83204+ kfree(info->path);
83205+ info->path = info->origpath;
83206+#endif
83207 if (info->cleanup)
83208 (*info->cleanup)(info);
83209 kfree(info);
83210@@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
83211 *
83212 * Thus the __user pointer cast is valid here.
83213 */
83214- sys_wait4(pid, (int __user *)&ret, 0, NULL);
83215+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
83216
83217 /*
83218 * If ret is 0, either ____call_usermodehelper failed and the
83219@@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
83220 goto out;
83221
83222 INIT_WORK(&sub_info->work, __call_usermodehelper);
83223+#ifdef CONFIG_GRKERNSEC
83224+ sub_info->origpath = path;
83225+ sub_info->path = kstrdup(path, gfp_mask);
83226+#else
83227 sub_info->path = path;
83228+#endif
83229 sub_info->argv = argv;
83230 sub_info->envp = envp;
83231
83232@@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
83233 static int proc_cap_handler(struct ctl_table *table, int write,
83234 void __user *buffer, size_t *lenp, loff_t *ppos)
83235 {
83236- struct ctl_table t;
83237+ ctl_table_no_const t;
83238 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
83239 kernel_cap_t new_cap;
83240 int err, i;
83241diff --git a/kernel/kprobes.c b/kernel/kprobes.c
83242index a0d367a..11c18b6 100644
83243--- a/kernel/kprobes.c
83244+++ b/kernel/kprobes.c
83245@@ -31,6 +31,9 @@
83246 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
83247 * <prasanna@in.ibm.com> added function-return probes.
83248 */
83249+#ifdef CONFIG_GRKERNSEC_HIDESYM
83250+#define __INCLUDED_BY_HIDESYM 1
83251+#endif
83252 #include <linux/kprobes.h>
83253 #include <linux/hash.h>
83254 #include <linux/init.h>
83255@@ -135,12 +138,12 @@ enum kprobe_slot_state {
83256
83257 static void *alloc_insn_page(void)
83258 {
83259- return module_alloc(PAGE_SIZE);
83260+ return module_alloc_exec(PAGE_SIZE);
83261 }
83262
83263 static void free_insn_page(void *page)
83264 {
83265- module_free(NULL, page);
83266+ module_free_exec(NULL, page);
83267 }
83268
83269 struct kprobe_insn_cache kprobe_insn_slots = {
83270@@ -2066,7 +2069,7 @@ static int __init init_kprobes(void)
83271 {
83272 int i, err = 0;
83273 unsigned long offset = 0, size = 0;
83274- char *modname, namebuf[128];
83275+ char *modname, namebuf[KSYM_NAME_LEN];
83276 const char *symbol_name;
83277 void *addr;
83278 struct kprobe_blackpoint *kb;
83279@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
83280 kprobe_type = "k";
83281
83282 if (sym)
83283- seq_printf(pi, "%p %s %s+0x%x %s ",
83284+ seq_printf(pi, "%pK %s %s+0x%x %s ",
83285 p->addr, kprobe_type, sym, offset,
83286 (modname ? modname : " "));
83287 else
83288- seq_printf(pi, "%p %s %p ",
83289+ seq_printf(pi, "%pK %s %pK ",
83290 p->addr, kprobe_type, p->addr);
83291
83292 if (!pp)
83293@@ -2192,7 +2195,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
83294 const char *sym = NULL;
83295 unsigned int i = *(loff_t *) v;
83296 unsigned long offset = 0;
83297- char *modname, namebuf[128];
83298+ char *modname, namebuf[KSYM_NAME_LEN];
83299
83300 head = &kprobe_table[i];
83301 preempt_disable();
83302diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
83303index 9659d38..bffd520 100644
83304--- a/kernel/ksysfs.c
83305+++ b/kernel/ksysfs.c
83306@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
83307 {
83308 if (count+1 > UEVENT_HELPER_PATH_LEN)
83309 return -ENOENT;
83310+ if (!capable(CAP_SYS_ADMIN))
83311+ return -EPERM;
83312 memcpy(uevent_helper, buf, count);
83313 uevent_helper[count] = '\0';
83314 if (count && uevent_helper[count-1] == '\n')
83315@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
83316 return count;
83317 }
83318
83319-static struct bin_attribute notes_attr = {
83320+static bin_attribute_no_const notes_attr __read_only = {
83321 .attr = {
83322 .name = "notes",
83323 .mode = S_IRUGO,
83324diff --git a/kernel/lockdep.c b/kernel/lockdep.c
83325index e16c45b..6f49c48 100644
83326--- a/kernel/lockdep.c
83327+++ b/kernel/lockdep.c
83328@@ -596,6 +596,10 @@ static int static_obj(void *obj)
83329 end = (unsigned long) &_end,
83330 addr = (unsigned long) obj;
83331
83332+#ifdef CONFIG_PAX_KERNEXEC
83333+ start = ktla_ktva(start);
83334+#endif
83335+
83336 /*
83337 * static variable?
83338 */
83339@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
83340 if (!static_obj(lock->key)) {
83341 debug_locks_off();
83342 printk("INFO: trying to register non-static key.\n");
83343+ printk("lock:%pS key:%pS.\n", lock, lock->key);
83344 printk("the code is fine but needs lockdep annotation.\n");
83345 printk("turning off the locking correctness validator.\n");
83346 dump_stack();
83347@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
83348 if (!class)
83349 return 0;
83350 }
83351- atomic_inc((atomic_t *)&class->ops);
83352+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
83353 if (very_verbose(class)) {
83354 printk("\nacquire class [%p] %s", class->key, class->name);
83355 if (class->name_version > 1)
83356diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
83357index b2c71c5..7b88d63 100644
83358--- a/kernel/lockdep_proc.c
83359+++ b/kernel/lockdep_proc.c
83360@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
83361 return 0;
83362 }
83363
83364- seq_printf(m, "%p", class->key);
83365+ seq_printf(m, "%pK", class->key);
83366 #ifdef CONFIG_DEBUG_LOCKDEP
83367 seq_printf(m, " OPS:%8ld", class->ops);
83368 #endif
83369@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
83370
83371 list_for_each_entry(entry, &class->locks_after, entry) {
83372 if (entry->distance == 1) {
83373- seq_printf(m, " -> [%p] ", entry->class->key);
83374+ seq_printf(m, " -> [%pK] ", entry->class->key);
83375 print_name(m, entry->class);
83376 seq_puts(m, "\n");
83377 }
83378@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
83379 if (!class->key)
83380 continue;
83381
83382- seq_printf(m, "[%p] ", class->key);
83383+ seq_printf(m, "[%pK] ", class->key);
83384 print_name(m, class);
83385 seq_puts(m, "\n");
83386 }
83387@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
83388 if (!i)
83389 seq_line(m, '-', 40-namelen, namelen);
83390
83391- snprintf(ip, sizeof(ip), "[<%p>]",
83392+ snprintf(ip, sizeof(ip), "[<%pK>]",
83393 (void *)class->contention_point[i]);
83394 seq_printf(m, "%40s %14lu %29s %pS\n",
83395 name, stats->contention_point[i],
83396@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
83397 if (!i)
83398 seq_line(m, '-', 40-namelen, namelen);
83399
83400- snprintf(ip, sizeof(ip), "[<%p>]",
83401+ snprintf(ip, sizeof(ip), "[<%pK>]",
83402 (void *)class->contending_point[i]);
83403 seq_printf(m, "%40s %14lu %29s %pS\n",
83404 name, stats->contending_point[i],
83405diff --git a/kernel/module.c b/kernel/module.c
83406index dc58274..3ddfa55 100644
83407--- a/kernel/module.c
83408+++ b/kernel/module.c
83409@@ -61,6 +61,7 @@
83410 #include <linux/pfn.h>
83411 #include <linux/bsearch.h>
83412 #include <linux/fips.h>
83413+#include <linux/grsecurity.h>
83414 #include <uapi/linux/module.h>
83415 #include "module-internal.h"
83416
83417@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
83418
83419 /* Bounds of module allocation, for speeding __module_address.
83420 * Protected by module_mutex. */
83421-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
83422+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
83423+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
83424
83425 int register_module_notifier(struct notifier_block * nb)
83426 {
83427@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
83428 return true;
83429
83430 list_for_each_entry_rcu(mod, &modules, list) {
83431- struct symsearch arr[] = {
83432+ struct symsearch modarr[] = {
83433 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
83434 NOT_GPL_ONLY, false },
83435 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
83436@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
83437 if (mod->state == MODULE_STATE_UNFORMED)
83438 continue;
83439
83440- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
83441+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
83442 return true;
83443 }
83444 return false;
83445@@ -491,7 +493,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
83446 if (!pcpusec->sh_size)
83447 return 0;
83448
83449- if (align > PAGE_SIZE) {
83450+ if (align-1 >= PAGE_SIZE) {
83451 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
83452 mod->name, align, PAGE_SIZE);
83453 align = PAGE_SIZE;
83454@@ -1097,7 +1099,7 @@ struct module_attribute module_uevent =
83455 static ssize_t show_coresize(struct module_attribute *mattr,
83456 struct module_kobject *mk, char *buffer)
83457 {
83458- return sprintf(buffer, "%u\n", mk->mod->core_size);
83459+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
83460 }
83461
83462 static struct module_attribute modinfo_coresize =
83463@@ -1106,7 +1108,7 @@ static struct module_attribute modinfo_coresize =
83464 static ssize_t show_initsize(struct module_attribute *mattr,
83465 struct module_kobject *mk, char *buffer)
83466 {
83467- return sprintf(buffer, "%u\n", mk->mod->init_size);
83468+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
83469 }
83470
83471 static struct module_attribute modinfo_initsize =
83472@@ -1321,7 +1323,7 @@ resolve_symbol_wait(struct module *mod,
83473 */
83474 #ifdef CONFIG_SYSFS
83475
83476-#ifdef CONFIG_KALLSYMS
83477+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83478 static inline bool sect_empty(const Elf_Shdr *sect)
83479 {
83480 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
83481@@ -1461,7 +1463,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
83482 {
83483 unsigned int notes, loaded, i;
83484 struct module_notes_attrs *notes_attrs;
83485- struct bin_attribute *nattr;
83486+ bin_attribute_no_const *nattr;
83487
83488 /* failed to create section attributes, so can't create notes */
83489 if (!mod->sect_attrs)
83490@@ -1573,7 +1575,7 @@ static void del_usage_links(struct module *mod)
83491 static int module_add_modinfo_attrs(struct module *mod)
83492 {
83493 struct module_attribute *attr;
83494- struct module_attribute *temp_attr;
83495+ module_attribute_no_const *temp_attr;
83496 int error = 0;
83497 int i;
83498
83499@@ -1795,21 +1797,21 @@ static void set_section_ro_nx(void *base,
83500
83501 static void unset_module_core_ro_nx(struct module *mod)
83502 {
83503- set_page_attributes(mod->module_core + mod->core_text_size,
83504- mod->module_core + mod->core_size,
83505+ set_page_attributes(mod->module_core_rw,
83506+ mod->module_core_rw + mod->core_size_rw,
83507 set_memory_x);
83508- set_page_attributes(mod->module_core,
83509- mod->module_core + mod->core_ro_size,
83510+ set_page_attributes(mod->module_core_rx,
83511+ mod->module_core_rx + mod->core_size_rx,
83512 set_memory_rw);
83513 }
83514
83515 static void unset_module_init_ro_nx(struct module *mod)
83516 {
83517- set_page_attributes(mod->module_init + mod->init_text_size,
83518- mod->module_init + mod->init_size,
83519+ set_page_attributes(mod->module_init_rw,
83520+ mod->module_init_rw + mod->init_size_rw,
83521 set_memory_x);
83522- set_page_attributes(mod->module_init,
83523- mod->module_init + mod->init_ro_size,
83524+ set_page_attributes(mod->module_init_rx,
83525+ mod->module_init_rx + mod->init_size_rx,
83526 set_memory_rw);
83527 }
83528
83529@@ -1822,14 +1824,14 @@ void set_all_modules_text_rw(void)
83530 list_for_each_entry_rcu(mod, &modules, list) {
83531 if (mod->state == MODULE_STATE_UNFORMED)
83532 continue;
83533- if ((mod->module_core) && (mod->core_text_size)) {
83534- set_page_attributes(mod->module_core,
83535- mod->module_core + mod->core_text_size,
83536+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
83537+ set_page_attributes(mod->module_core_rx,
83538+ mod->module_core_rx + mod->core_size_rx,
83539 set_memory_rw);
83540 }
83541- if ((mod->module_init) && (mod->init_text_size)) {
83542- set_page_attributes(mod->module_init,
83543- mod->module_init + mod->init_text_size,
83544+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
83545+ set_page_attributes(mod->module_init_rx,
83546+ mod->module_init_rx + mod->init_size_rx,
83547 set_memory_rw);
83548 }
83549 }
83550@@ -1845,14 +1847,14 @@ void set_all_modules_text_ro(void)
83551 list_for_each_entry_rcu(mod, &modules, list) {
83552 if (mod->state == MODULE_STATE_UNFORMED)
83553 continue;
83554- if ((mod->module_core) && (mod->core_text_size)) {
83555- set_page_attributes(mod->module_core,
83556- mod->module_core + mod->core_text_size,
83557+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
83558+ set_page_attributes(mod->module_core_rx,
83559+ mod->module_core_rx + mod->core_size_rx,
83560 set_memory_ro);
83561 }
83562- if ((mod->module_init) && (mod->init_text_size)) {
83563- set_page_attributes(mod->module_init,
83564- mod->module_init + mod->init_text_size,
83565+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
83566+ set_page_attributes(mod->module_init_rx,
83567+ mod->module_init_rx + mod->init_size_rx,
83568 set_memory_ro);
83569 }
83570 }
83571@@ -1903,16 +1905,19 @@ static void free_module(struct module *mod)
83572
83573 /* This may be NULL, but that's OK */
83574 unset_module_init_ro_nx(mod);
83575- module_free(mod, mod->module_init);
83576+ module_free(mod, mod->module_init_rw);
83577+ module_free_exec(mod, mod->module_init_rx);
83578 kfree(mod->args);
83579 percpu_modfree(mod);
83580
83581 /* Free lock-classes: */
83582- lockdep_free_key_range(mod->module_core, mod->core_size);
83583+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
83584+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
83585
83586 /* Finally, free the core (containing the module structure) */
83587 unset_module_core_ro_nx(mod);
83588- module_free(mod, mod->module_core);
83589+ module_free_exec(mod, mod->module_core_rx);
83590+ module_free(mod, mod->module_core_rw);
83591
83592 #ifdef CONFIG_MPU
83593 update_protections(current->mm);
83594@@ -1982,9 +1987,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
83595 int ret = 0;
83596 const struct kernel_symbol *ksym;
83597
83598+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83599+ int is_fs_load = 0;
83600+ int register_filesystem_found = 0;
83601+ char *p;
83602+
83603+ p = strstr(mod->args, "grsec_modharden_fs");
83604+ if (p) {
83605+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
83606+ /* copy \0 as well */
83607+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
83608+ is_fs_load = 1;
83609+ }
83610+#endif
83611+
83612 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
83613 const char *name = info->strtab + sym[i].st_name;
83614
83615+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83616+ /* it's a real shame this will never get ripped and copied
83617+ upstream! ;(
83618+ */
83619+ if (is_fs_load && !strcmp(name, "register_filesystem"))
83620+ register_filesystem_found = 1;
83621+#endif
83622+
83623 switch (sym[i].st_shndx) {
83624 case SHN_COMMON:
83625 /* We compiled with -fno-common. These are not
83626@@ -2005,7 +2032,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
83627 ksym = resolve_symbol_wait(mod, info, name);
83628 /* Ok if resolved. */
83629 if (ksym && !IS_ERR(ksym)) {
83630+ pax_open_kernel();
83631 sym[i].st_value = ksym->value;
83632+ pax_close_kernel();
83633 break;
83634 }
83635
83636@@ -2024,11 +2053,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
83637 secbase = (unsigned long)mod_percpu(mod);
83638 else
83639 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
83640+ pax_open_kernel();
83641 sym[i].st_value += secbase;
83642+ pax_close_kernel();
83643 break;
83644 }
83645 }
83646
83647+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83648+ if (is_fs_load && !register_filesystem_found) {
83649+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
83650+ ret = -EPERM;
83651+ }
83652+#endif
83653+
83654 return ret;
83655 }
83656
83657@@ -2112,22 +2150,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
83658 || s->sh_entsize != ~0UL
83659 || strstarts(sname, ".init"))
83660 continue;
83661- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
83662+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
83663+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
83664+ else
83665+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
83666 pr_debug("\t%s\n", sname);
83667 }
83668- switch (m) {
83669- case 0: /* executable */
83670- mod->core_size = debug_align(mod->core_size);
83671- mod->core_text_size = mod->core_size;
83672- break;
83673- case 1: /* RO: text and ro-data */
83674- mod->core_size = debug_align(mod->core_size);
83675- mod->core_ro_size = mod->core_size;
83676- break;
83677- case 3: /* whole core */
83678- mod->core_size = debug_align(mod->core_size);
83679- break;
83680- }
83681 }
83682
83683 pr_debug("Init section allocation order:\n");
83684@@ -2141,23 +2169,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
83685 || s->sh_entsize != ~0UL
83686 || !strstarts(sname, ".init"))
83687 continue;
83688- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
83689- | INIT_OFFSET_MASK);
83690+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
83691+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
83692+ else
83693+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
83694+ s->sh_entsize |= INIT_OFFSET_MASK;
83695 pr_debug("\t%s\n", sname);
83696 }
83697- switch (m) {
83698- case 0: /* executable */
83699- mod->init_size = debug_align(mod->init_size);
83700- mod->init_text_size = mod->init_size;
83701- break;
83702- case 1: /* RO: text and ro-data */
83703- mod->init_size = debug_align(mod->init_size);
83704- mod->init_ro_size = mod->init_size;
83705- break;
83706- case 3: /* whole init */
83707- mod->init_size = debug_align(mod->init_size);
83708- break;
83709- }
83710 }
83711 }
83712
83713@@ -2330,7 +2348,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
83714
83715 /* Put symbol section at end of init part of module. */
83716 symsect->sh_flags |= SHF_ALLOC;
83717- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
83718+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
83719 info->index.sym) | INIT_OFFSET_MASK;
83720 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
83721
83722@@ -2347,13 +2365,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
83723 }
83724
83725 /* Append room for core symbols at end of core part. */
83726- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
83727- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
83728- mod->core_size += strtab_size;
83729+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
83730+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
83731+ mod->core_size_rx += strtab_size;
83732
83733 /* Put string table section at end of init part of module. */
83734 strsect->sh_flags |= SHF_ALLOC;
83735- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
83736+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
83737 info->index.str) | INIT_OFFSET_MASK;
83738 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
83739 }
83740@@ -2371,12 +2389,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
83741 /* Make sure we get permanent strtab: don't use info->strtab. */
83742 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
83743
83744+ pax_open_kernel();
83745+
83746 /* Set types up while we still have access to sections. */
83747 for (i = 0; i < mod->num_symtab; i++)
83748 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
83749
83750- mod->core_symtab = dst = mod->module_core + info->symoffs;
83751- mod->core_strtab = s = mod->module_core + info->stroffs;
83752+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
83753+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
83754 src = mod->symtab;
83755 for (ndst = i = 0; i < mod->num_symtab; i++) {
83756 if (i == 0 ||
83757@@ -2388,6 +2408,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
83758 }
83759 }
83760 mod->core_num_syms = ndst;
83761+
83762+ pax_close_kernel();
83763 }
83764 #else
83765 static inline void layout_symtab(struct module *mod, struct load_info *info)
83766@@ -2421,17 +2443,33 @@ void * __weak module_alloc(unsigned long size)
83767 return vmalloc_exec(size);
83768 }
83769
83770-static void *module_alloc_update_bounds(unsigned long size)
83771+static void *module_alloc_update_bounds_rw(unsigned long size)
83772 {
83773 void *ret = module_alloc(size);
83774
83775 if (ret) {
83776 mutex_lock(&module_mutex);
83777 /* Update module bounds. */
83778- if ((unsigned long)ret < module_addr_min)
83779- module_addr_min = (unsigned long)ret;
83780- if ((unsigned long)ret + size > module_addr_max)
83781- module_addr_max = (unsigned long)ret + size;
83782+ if ((unsigned long)ret < module_addr_min_rw)
83783+ module_addr_min_rw = (unsigned long)ret;
83784+ if ((unsigned long)ret + size > module_addr_max_rw)
83785+ module_addr_max_rw = (unsigned long)ret + size;
83786+ mutex_unlock(&module_mutex);
83787+ }
83788+ return ret;
83789+}
83790+
83791+static void *module_alloc_update_bounds_rx(unsigned long size)
83792+{
83793+ void *ret = module_alloc_exec(size);
83794+
83795+ if (ret) {
83796+ mutex_lock(&module_mutex);
83797+ /* Update module bounds. */
83798+ if ((unsigned long)ret < module_addr_min_rx)
83799+ module_addr_min_rx = (unsigned long)ret;
83800+ if ((unsigned long)ret + size > module_addr_max_rx)
83801+ module_addr_max_rx = (unsigned long)ret + size;
83802 mutex_unlock(&module_mutex);
83803 }
83804 return ret;
83805@@ -2706,8 +2744,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
83806 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
83807 {
83808 const char *modmagic = get_modinfo(info, "vermagic");
83809+ const char *license = get_modinfo(info, "license");
83810 int err;
83811
83812+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
83813+ if (!license || !license_is_gpl_compatible(license))
83814+ return -ENOEXEC;
83815+#endif
83816+
83817 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
83818 modmagic = NULL;
83819
83820@@ -2733,7 +2777,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
83821 }
83822
83823 /* Set up license info based on the info section */
83824- set_license(mod, get_modinfo(info, "license"));
83825+ set_license(mod, license);
83826
83827 return 0;
83828 }
83829@@ -2814,7 +2858,7 @@ static int move_module(struct module *mod, struct load_info *info)
83830 void *ptr;
83831
83832 /* Do the allocs. */
83833- ptr = module_alloc_update_bounds(mod->core_size);
83834+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
83835 /*
83836 * The pointer to this block is stored in the module structure
83837 * which is inside the block. Just mark it as not being a
83838@@ -2824,11 +2868,11 @@ static int move_module(struct module *mod, struct load_info *info)
83839 if (!ptr)
83840 return -ENOMEM;
83841
83842- memset(ptr, 0, mod->core_size);
83843- mod->module_core = ptr;
83844+ memset(ptr, 0, mod->core_size_rw);
83845+ mod->module_core_rw = ptr;
83846
83847- if (mod->init_size) {
83848- ptr = module_alloc_update_bounds(mod->init_size);
83849+ if (mod->init_size_rw) {
83850+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
83851 /*
83852 * The pointer to this block is stored in the module structure
83853 * which is inside the block. This block doesn't need to be
83854@@ -2837,13 +2881,45 @@ static int move_module(struct module *mod, struct load_info *info)
83855 */
83856 kmemleak_ignore(ptr);
83857 if (!ptr) {
83858- module_free(mod, mod->module_core);
83859+ module_free(mod, mod->module_core_rw);
83860 return -ENOMEM;
83861 }
83862- memset(ptr, 0, mod->init_size);
83863- mod->module_init = ptr;
83864+ memset(ptr, 0, mod->init_size_rw);
83865+ mod->module_init_rw = ptr;
83866 } else
83867- mod->module_init = NULL;
83868+ mod->module_init_rw = NULL;
83869+
83870+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
83871+ kmemleak_not_leak(ptr);
83872+ if (!ptr) {
83873+ if (mod->module_init_rw)
83874+ module_free(mod, mod->module_init_rw);
83875+ module_free(mod, mod->module_core_rw);
83876+ return -ENOMEM;
83877+ }
83878+
83879+ pax_open_kernel();
83880+ memset(ptr, 0, mod->core_size_rx);
83881+ pax_close_kernel();
83882+ mod->module_core_rx = ptr;
83883+
83884+ if (mod->init_size_rx) {
83885+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
83886+ kmemleak_ignore(ptr);
83887+ if (!ptr && mod->init_size_rx) {
83888+ module_free_exec(mod, mod->module_core_rx);
83889+ if (mod->module_init_rw)
83890+ module_free(mod, mod->module_init_rw);
83891+ module_free(mod, mod->module_core_rw);
83892+ return -ENOMEM;
83893+ }
83894+
83895+ pax_open_kernel();
83896+ memset(ptr, 0, mod->init_size_rx);
83897+ pax_close_kernel();
83898+ mod->module_init_rx = ptr;
83899+ } else
83900+ mod->module_init_rx = NULL;
83901
83902 /* Transfer each section which specifies SHF_ALLOC */
83903 pr_debug("final section addresses:\n");
83904@@ -2854,16 +2930,45 @@ static int move_module(struct module *mod, struct load_info *info)
83905 if (!(shdr->sh_flags & SHF_ALLOC))
83906 continue;
83907
83908- if (shdr->sh_entsize & INIT_OFFSET_MASK)
83909- dest = mod->module_init
83910- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83911- else
83912- dest = mod->module_core + shdr->sh_entsize;
83913+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
83914+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83915+ dest = mod->module_init_rw
83916+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83917+ else
83918+ dest = mod->module_init_rx
83919+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83920+ } else {
83921+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83922+ dest = mod->module_core_rw + shdr->sh_entsize;
83923+ else
83924+ dest = mod->module_core_rx + shdr->sh_entsize;
83925+ }
83926+
83927+ if (shdr->sh_type != SHT_NOBITS) {
83928+
83929+#ifdef CONFIG_PAX_KERNEXEC
83930+#ifdef CONFIG_X86_64
83931+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
83932+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
83933+#endif
83934+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
83935+ pax_open_kernel();
83936+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83937+ pax_close_kernel();
83938+ } else
83939+#endif
83940
83941- if (shdr->sh_type != SHT_NOBITS)
83942 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83943+ }
83944 /* Update sh_addr to point to copy in image. */
83945- shdr->sh_addr = (unsigned long)dest;
83946+
83947+#ifdef CONFIG_PAX_KERNEXEC
83948+ if (shdr->sh_flags & SHF_EXECINSTR)
83949+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
83950+ else
83951+#endif
83952+
83953+ shdr->sh_addr = (unsigned long)dest;
83954 pr_debug("\t0x%lx %s\n",
83955 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
83956 }
83957@@ -2920,12 +3025,12 @@ static void flush_module_icache(const struct module *mod)
83958 * Do it before processing of module parameters, so the module
83959 * can provide parameter accessor functions of its own.
83960 */
83961- if (mod->module_init)
83962- flush_icache_range((unsigned long)mod->module_init,
83963- (unsigned long)mod->module_init
83964- + mod->init_size);
83965- flush_icache_range((unsigned long)mod->module_core,
83966- (unsigned long)mod->module_core + mod->core_size);
83967+ if (mod->module_init_rx)
83968+ flush_icache_range((unsigned long)mod->module_init_rx,
83969+ (unsigned long)mod->module_init_rx
83970+ + mod->init_size_rx);
83971+ flush_icache_range((unsigned long)mod->module_core_rx,
83972+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
83973
83974 set_fs(old_fs);
83975 }
83976@@ -2982,8 +3087,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
83977 static void module_deallocate(struct module *mod, struct load_info *info)
83978 {
83979 percpu_modfree(mod);
83980- module_free(mod, mod->module_init);
83981- module_free(mod, mod->module_core);
83982+ module_free_exec(mod, mod->module_init_rx);
83983+ module_free_exec(mod, mod->module_core_rx);
83984+ module_free(mod, mod->module_init_rw);
83985+ module_free(mod, mod->module_core_rw);
83986 }
83987
83988 int __weak module_finalize(const Elf_Ehdr *hdr,
83989@@ -2996,7 +3103,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
83990 static int post_relocation(struct module *mod, const struct load_info *info)
83991 {
83992 /* Sort exception table now relocations are done. */
83993+ pax_open_kernel();
83994 sort_extable(mod->extable, mod->extable + mod->num_exentries);
83995+ pax_close_kernel();
83996
83997 /* Copy relocated percpu area over. */
83998 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
83999@@ -3050,16 +3159,16 @@ static int do_init_module(struct module *mod)
84000 MODULE_STATE_COMING, mod);
84001
84002 /* Set RO and NX regions for core */
84003- set_section_ro_nx(mod->module_core,
84004- mod->core_text_size,
84005- mod->core_ro_size,
84006- mod->core_size);
84007+ set_section_ro_nx(mod->module_core_rx,
84008+ mod->core_size_rx,
84009+ mod->core_size_rx,
84010+ mod->core_size_rx);
84011
84012 /* Set RO and NX regions for init */
84013- set_section_ro_nx(mod->module_init,
84014- mod->init_text_size,
84015- mod->init_ro_size,
84016- mod->init_size);
84017+ set_section_ro_nx(mod->module_init_rx,
84018+ mod->init_size_rx,
84019+ mod->init_size_rx,
84020+ mod->init_size_rx);
84021
84022 do_mod_ctors(mod);
84023 /* Start the module */
84024@@ -3121,11 +3230,12 @@ static int do_init_module(struct module *mod)
84025 mod->strtab = mod->core_strtab;
84026 #endif
84027 unset_module_init_ro_nx(mod);
84028- module_free(mod, mod->module_init);
84029- mod->module_init = NULL;
84030- mod->init_size = 0;
84031- mod->init_ro_size = 0;
84032- mod->init_text_size = 0;
84033+ module_free(mod, mod->module_init_rw);
84034+ module_free_exec(mod, mod->module_init_rx);
84035+ mod->module_init_rw = NULL;
84036+ mod->module_init_rx = NULL;
84037+ mod->init_size_rw = 0;
84038+ mod->init_size_rx = 0;
84039 mutex_unlock(&module_mutex);
84040 wake_up_all(&module_wq);
84041
84042@@ -3269,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
84043 if (err)
84044 goto free_unload;
84045
84046+ /* Now copy in args */
84047+ mod->args = strndup_user(uargs, ~0UL >> 1);
84048+ if (IS_ERR(mod->args)) {
84049+ err = PTR_ERR(mod->args);
84050+ goto free_unload;
84051+ }
84052+
84053 /* Set up MODINFO_ATTR fields */
84054 setup_modinfo(mod, info);
84055
84056+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84057+ {
84058+ char *p, *p2;
84059+
84060+ if (strstr(mod->args, "grsec_modharden_netdev")) {
84061+ 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);
84062+ err = -EPERM;
84063+ goto free_modinfo;
84064+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
84065+ p += sizeof("grsec_modharden_normal") - 1;
84066+ p2 = strstr(p, "_");
84067+ if (p2) {
84068+ *p2 = '\0';
84069+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
84070+ *p2 = '_';
84071+ }
84072+ err = -EPERM;
84073+ goto free_modinfo;
84074+ }
84075+ }
84076+#endif
84077+
84078 /* Fix up syms, so that st_value is a pointer to location. */
84079 err = simplify_symbols(mod, info);
84080 if (err < 0)
84081@@ -3287,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
84082
84083 flush_module_icache(mod);
84084
84085- /* Now copy in args */
84086- mod->args = strndup_user(uargs, ~0UL >> 1);
84087- if (IS_ERR(mod->args)) {
84088- err = PTR_ERR(mod->args);
84089- goto free_arch_cleanup;
84090- }
84091-
84092 dynamic_debug_setup(info->debug, info->num_debug);
84093
84094 /* Finally it's fully formed, ready to start executing. */
84095@@ -3328,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
84096 ddebug_cleanup:
84097 dynamic_debug_remove(info->debug);
84098 synchronize_sched();
84099- kfree(mod->args);
84100- free_arch_cleanup:
84101 module_arch_cleanup(mod);
84102 free_modinfo:
84103 free_modinfo(mod);
84104+ kfree(mod->args);
84105 free_unload:
84106 module_unload_free(mod);
84107 unlink_mod:
84108@@ -3415,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
84109 unsigned long nextval;
84110
84111 /* At worse, next value is at end of module */
84112- if (within_module_init(addr, mod))
84113- nextval = (unsigned long)mod->module_init+mod->init_text_size;
84114+ if (within_module_init_rx(addr, mod))
84115+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
84116+ else if (within_module_init_rw(addr, mod))
84117+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
84118+ else if (within_module_core_rx(addr, mod))
84119+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
84120+ else if (within_module_core_rw(addr, mod))
84121+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
84122 else
84123- nextval = (unsigned long)mod->module_core+mod->core_text_size;
84124+ return NULL;
84125
84126 /* Scan for closest preceding symbol, and next symbol. (ELF
84127 starts real symbols at 1). */
84128@@ -3669,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
84129 return 0;
84130
84131 seq_printf(m, "%s %u",
84132- mod->name, mod->init_size + mod->core_size);
84133+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
84134 print_unload_info(m, mod);
84135
84136 /* Informative for users. */
84137@@ -3678,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
84138 mod->state == MODULE_STATE_COMING ? "Loading":
84139 "Live");
84140 /* Used by oprofile and other similar tools. */
84141- seq_printf(m, " 0x%pK", mod->module_core);
84142+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
84143
84144 /* Taints info */
84145 if (mod->taints)
84146@@ -3714,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
84147
84148 static int __init proc_modules_init(void)
84149 {
84150+#ifndef CONFIG_GRKERNSEC_HIDESYM
84151+#ifdef CONFIG_GRKERNSEC_PROC_USER
84152+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
84153+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84154+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
84155+#else
84156 proc_create("modules", 0, NULL, &proc_modules_operations);
84157+#endif
84158+#else
84159+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
84160+#endif
84161 return 0;
84162 }
84163 module_init(proc_modules_init);
84164@@ -3775,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
84165 {
84166 struct module *mod;
84167
84168- if (addr < module_addr_min || addr > module_addr_max)
84169+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
84170+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
84171 return NULL;
84172
84173 list_for_each_entry_rcu(mod, &modules, list) {
84174 if (mod->state == MODULE_STATE_UNFORMED)
84175 continue;
84176- if (within_module_core(addr, mod)
84177- || within_module_init(addr, mod))
84178+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
84179 return mod;
84180 }
84181 return NULL;
84182@@ -3817,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
84183 */
84184 struct module *__module_text_address(unsigned long addr)
84185 {
84186- struct module *mod = __module_address(addr);
84187+ struct module *mod;
84188+
84189+#ifdef CONFIG_X86_32
84190+ addr = ktla_ktva(addr);
84191+#endif
84192+
84193+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
84194+ return NULL;
84195+
84196+ mod = __module_address(addr);
84197+
84198 if (mod) {
84199 /* Make sure it's within the text section. */
84200- if (!within(addr, mod->module_init, mod->init_text_size)
84201- && !within(addr, mod->module_core, mod->core_text_size))
84202+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
84203 mod = NULL;
84204 }
84205 return mod;
84206diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
84207index 7e3443f..b2a1e6b 100644
84208--- a/kernel/mutex-debug.c
84209+++ b/kernel/mutex-debug.c
84210@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
84211 }
84212
84213 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
84214- struct thread_info *ti)
84215+ struct task_struct *task)
84216 {
84217 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
84218
84219 /* Mark the current thread as blocked on the lock: */
84220- ti->task->blocked_on = waiter;
84221+ task->blocked_on = waiter;
84222 }
84223
84224 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
84225- struct thread_info *ti)
84226+ struct task_struct *task)
84227 {
84228 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
84229- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
84230- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
84231- ti->task->blocked_on = NULL;
84232+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
84233+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
84234+ task->blocked_on = NULL;
84235
84236 list_del_init(&waiter->list);
84237 waiter->task = NULL;
84238diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
84239index 0799fd3..d06ae3b 100644
84240--- a/kernel/mutex-debug.h
84241+++ b/kernel/mutex-debug.h
84242@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
84243 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
84244 extern void debug_mutex_add_waiter(struct mutex *lock,
84245 struct mutex_waiter *waiter,
84246- struct thread_info *ti);
84247+ struct task_struct *task);
84248 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
84249- struct thread_info *ti);
84250+ struct task_struct *task);
84251 extern void debug_mutex_unlock(struct mutex *lock);
84252 extern void debug_mutex_init(struct mutex *lock, const char *name,
84253 struct lock_class_key *key);
84254diff --git a/kernel/mutex.c b/kernel/mutex.c
84255index d24105b..15648eb 100644
84256--- a/kernel/mutex.c
84257+++ b/kernel/mutex.c
84258@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
84259 node->locked = 1;
84260 return;
84261 }
84262- ACCESS_ONCE(prev->next) = node;
84263+ ACCESS_ONCE_RW(prev->next) = node;
84264 smp_wmb();
84265 /* Wait until the lock holder passes the lock down */
84266 while (!ACCESS_ONCE(node->locked))
84267@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
84268 while (!(next = ACCESS_ONCE(node->next)))
84269 arch_mutex_cpu_relax();
84270 }
84271- ACCESS_ONCE(next->locked) = 1;
84272+ ACCESS_ONCE_RW(next->locked) = 1;
84273 smp_wmb();
84274 }
84275
84276@@ -520,7 +520,7 @@ slowpath:
84277 goto skip_wait;
84278
84279 debug_mutex_lock_common(lock, &waiter);
84280- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
84281+ debug_mutex_add_waiter(lock, &waiter, task);
84282
84283 /* add waiting tasks to the end of the waitqueue (FIFO): */
84284 list_add_tail(&waiter.list, &lock->wait_list);
84285@@ -564,7 +564,7 @@ slowpath:
84286 schedule_preempt_disabled();
84287 spin_lock_mutex(&lock->wait_lock, flags);
84288 }
84289- mutex_remove_waiter(lock, &waiter, current_thread_info());
84290+ mutex_remove_waiter(lock, &waiter, task);
84291 /* set it to 0 if there are no waiters left: */
84292 if (likely(list_empty(&lock->wait_list)))
84293 atomic_set(&lock->count, 0);
84294@@ -601,7 +601,7 @@ skip_wait:
84295 return 0;
84296
84297 err:
84298- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
84299+ mutex_remove_waiter(lock, &waiter, task);
84300 spin_unlock_mutex(&lock->wait_lock, flags);
84301 debug_mutex_free_waiter(&waiter);
84302 mutex_release(&lock->dep_map, 1, ip);
84303diff --git a/kernel/notifier.c b/kernel/notifier.c
84304index 2d5cc4c..d9ea600 100644
84305--- a/kernel/notifier.c
84306+++ b/kernel/notifier.c
84307@@ -5,6 +5,7 @@
84308 #include <linux/rcupdate.h>
84309 #include <linux/vmalloc.h>
84310 #include <linux/reboot.h>
84311+#include <linux/mm.h>
84312
84313 /*
84314 * Notifier list for kernel code which wants to be called
84315@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
84316 while ((*nl) != NULL) {
84317 if (n->priority > (*nl)->priority)
84318 break;
84319- nl = &((*nl)->next);
84320+ nl = (struct notifier_block **)&((*nl)->next);
84321 }
84322- n->next = *nl;
84323+ pax_open_kernel();
84324+ *(const void **)&n->next = *nl;
84325 rcu_assign_pointer(*nl, n);
84326+ pax_close_kernel();
84327 return 0;
84328 }
84329
84330@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
84331 return 0;
84332 if (n->priority > (*nl)->priority)
84333 break;
84334- nl = &((*nl)->next);
84335+ nl = (struct notifier_block **)&((*nl)->next);
84336 }
84337- n->next = *nl;
84338+ pax_open_kernel();
84339+ *(const void **)&n->next = *nl;
84340 rcu_assign_pointer(*nl, n);
84341+ pax_close_kernel();
84342 return 0;
84343 }
84344
84345@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
84346 {
84347 while ((*nl) != NULL) {
84348 if ((*nl) == n) {
84349+ pax_open_kernel();
84350 rcu_assign_pointer(*nl, n->next);
84351+ pax_close_kernel();
84352 return 0;
84353 }
84354- nl = &((*nl)->next);
84355+ nl = (struct notifier_block **)&((*nl)->next);
84356 }
84357 return -ENOENT;
84358 }
84359diff --git a/kernel/panic.c b/kernel/panic.c
84360index b6c482c..5578061 100644
84361--- a/kernel/panic.c
84362+++ b/kernel/panic.c
84363@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
84364 disable_trace_on_warning();
84365
84366 pr_warn("------------[ cut here ]------------\n");
84367- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
84368+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
84369 raw_smp_processor_id(), current->pid, file, line, caller);
84370
84371 if (args)
84372@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
84373 */
84374 void __stack_chk_fail(void)
84375 {
84376- panic("stack-protector: Kernel stack is corrupted in: %p\n",
84377+ dump_stack();
84378+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
84379 __builtin_return_address(0));
84380 }
84381 EXPORT_SYMBOL(__stack_chk_fail);
84382diff --git a/kernel/pid.c b/kernel/pid.c
84383index 9b9a266..c20ef80 100644
84384--- a/kernel/pid.c
84385+++ b/kernel/pid.c
84386@@ -33,6 +33,7 @@
84387 #include <linux/rculist.h>
84388 #include <linux/bootmem.h>
84389 #include <linux/hash.h>
84390+#include <linux/security.h>
84391 #include <linux/pid_namespace.h>
84392 #include <linux/init_task.h>
84393 #include <linux/syscalls.h>
84394@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
84395
84396 int pid_max = PID_MAX_DEFAULT;
84397
84398-#define RESERVED_PIDS 300
84399+#define RESERVED_PIDS 500
84400
84401 int pid_max_min = RESERVED_PIDS + 1;
84402 int pid_max_max = PID_MAX_LIMIT;
84403@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
84404 */
84405 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
84406 {
84407+ struct task_struct *task;
84408+
84409 rcu_lockdep_assert(rcu_read_lock_held(),
84410 "find_task_by_pid_ns() needs rcu_read_lock()"
84411 " protection");
84412- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
84413+
84414+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
84415+
84416+ if (gr_pid_is_chrooted(task))
84417+ return NULL;
84418+
84419+ return task;
84420 }
84421
84422 struct task_struct *find_task_by_vpid(pid_t vnr)
84423@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
84424 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
84425 }
84426
84427+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
84428+{
84429+ rcu_lockdep_assert(rcu_read_lock_held(),
84430+ "find_task_by_pid_ns() needs rcu_read_lock()"
84431+ " protection");
84432+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
84433+}
84434+
84435 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
84436 {
84437 struct pid *pid;
84438diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
84439index 4208655..19f36a5 100644
84440--- a/kernel/pid_namespace.c
84441+++ b/kernel/pid_namespace.c
84442@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
84443 void __user *buffer, size_t *lenp, loff_t *ppos)
84444 {
84445 struct pid_namespace *pid_ns = task_active_pid_ns(current);
84446- struct ctl_table tmp = *table;
84447+ ctl_table_no_const tmp = *table;
84448
84449 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
84450 return -EPERM;
84451diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
84452index c7f31aa..2b44977 100644
84453--- a/kernel/posix-cpu-timers.c
84454+++ b/kernel/posix-cpu-timers.c
84455@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
84456
84457 static __init int init_posix_cpu_timers(void)
84458 {
84459- struct k_clock process = {
84460+ static struct k_clock process = {
84461 .clock_getres = process_cpu_clock_getres,
84462 .clock_get = process_cpu_clock_get,
84463 .timer_create = process_cpu_timer_create,
84464 .nsleep = process_cpu_nsleep,
84465 .nsleep_restart = process_cpu_nsleep_restart,
84466 };
84467- struct k_clock thread = {
84468+ static struct k_clock thread = {
84469 .clock_getres = thread_cpu_clock_getres,
84470 .clock_get = thread_cpu_clock_get,
84471 .timer_create = thread_cpu_timer_create,
84472diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
84473index 424c2d4..679242f 100644
84474--- a/kernel/posix-timers.c
84475+++ b/kernel/posix-timers.c
84476@@ -43,6 +43,7 @@
84477 #include <linux/hash.h>
84478 #include <linux/posix-clock.h>
84479 #include <linux/posix-timers.h>
84480+#include <linux/grsecurity.h>
84481 #include <linux/syscalls.h>
84482 #include <linux/wait.h>
84483 #include <linux/workqueue.h>
84484@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
84485 * which we beg off on and pass to do_sys_settimeofday().
84486 */
84487
84488-static struct k_clock posix_clocks[MAX_CLOCKS];
84489+static struct k_clock *posix_clocks[MAX_CLOCKS];
84490
84491 /*
84492 * These ones are defined below.
84493@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
84494 */
84495 static __init int init_posix_timers(void)
84496 {
84497- struct k_clock clock_realtime = {
84498+ static struct k_clock clock_realtime = {
84499 .clock_getres = hrtimer_get_res,
84500 .clock_get = posix_clock_realtime_get,
84501 .clock_set = posix_clock_realtime_set,
84502@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
84503 .timer_get = common_timer_get,
84504 .timer_del = common_timer_del,
84505 };
84506- struct k_clock clock_monotonic = {
84507+ static struct k_clock clock_monotonic = {
84508 .clock_getres = hrtimer_get_res,
84509 .clock_get = posix_ktime_get_ts,
84510 .nsleep = common_nsleep,
84511@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
84512 .timer_get = common_timer_get,
84513 .timer_del = common_timer_del,
84514 };
84515- struct k_clock clock_monotonic_raw = {
84516+ static struct k_clock clock_monotonic_raw = {
84517 .clock_getres = hrtimer_get_res,
84518 .clock_get = posix_get_monotonic_raw,
84519 };
84520- struct k_clock clock_realtime_coarse = {
84521+ static struct k_clock clock_realtime_coarse = {
84522 .clock_getres = posix_get_coarse_res,
84523 .clock_get = posix_get_realtime_coarse,
84524 };
84525- struct k_clock clock_monotonic_coarse = {
84526+ static struct k_clock clock_monotonic_coarse = {
84527 .clock_getres = posix_get_coarse_res,
84528 .clock_get = posix_get_monotonic_coarse,
84529 };
84530- struct k_clock clock_tai = {
84531+ static struct k_clock clock_tai = {
84532 .clock_getres = hrtimer_get_res,
84533 .clock_get = posix_get_tai,
84534 .nsleep = common_nsleep,
84535@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
84536 .timer_get = common_timer_get,
84537 .timer_del = common_timer_del,
84538 };
84539- struct k_clock clock_boottime = {
84540+ static struct k_clock clock_boottime = {
84541 .clock_getres = hrtimer_get_res,
84542 .clock_get = posix_get_boottime,
84543 .nsleep = common_nsleep,
84544@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
84545 return;
84546 }
84547
84548- posix_clocks[clock_id] = *new_clock;
84549+ posix_clocks[clock_id] = new_clock;
84550 }
84551 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
84552
84553@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
84554 return (id & CLOCKFD_MASK) == CLOCKFD ?
84555 &clock_posix_dynamic : &clock_posix_cpu;
84556
84557- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
84558+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
84559 return NULL;
84560- return &posix_clocks[id];
84561+ return posix_clocks[id];
84562 }
84563
84564 static int common_timer_create(struct k_itimer *new_timer)
84565@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
84566 struct k_clock *kc = clockid_to_kclock(which_clock);
84567 struct k_itimer *new_timer;
84568 int error, new_timer_id;
84569- sigevent_t event;
84570+ sigevent_t event = { };
84571 int it_id_set = IT_ID_NOT_SET;
84572
84573 if (!kc)
84574@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
84575 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
84576 return -EFAULT;
84577
84578+ /* only the CLOCK_REALTIME clock can be set, all other clocks
84579+ have their clock_set fptr set to a nosettime dummy function
84580+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
84581+ call common_clock_set, which calls do_sys_settimeofday, which
84582+ we hook
84583+ */
84584+
84585 return kc->clock_set(which_clock, &new_tp);
84586 }
84587
84588diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
84589index d444c4e..bc3de51 100644
84590--- a/kernel/power/Kconfig
84591+++ b/kernel/power/Kconfig
84592@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
84593 config HIBERNATION
84594 bool "Hibernation (aka 'suspend to disk')"
84595 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
84596+ depends on !GRKERNSEC_KMEM
84597+ depends on !PAX_MEMORY_SANITIZE
84598 select HIBERNATE_CALLBACKS
84599 select LZO_COMPRESS
84600 select LZO_DECOMPRESS
84601diff --git a/kernel/power/process.c b/kernel/power/process.c
84602index 06ec886..9dba35e 100644
84603--- a/kernel/power/process.c
84604+++ b/kernel/power/process.c
84605@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
84606 unsigned int elapsed_msecs;
84607 bool wakeup = false;
84608 int sleep_usecs = USEC_PER_MSEC;
84609+ bool timedout = false;
84610
84611 do_gettimeofday(&start);
84612
84613@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
84614
84615 while (true) {
84616 todo = 0;
84617+ if (time_after(jiffies, end_time))
84618+ timedout = true;
84619 read_lock(&tasklist_lock);
84620 do_each_thread(g, p) {
84621 if (p == current || !freeze_task(p))
84622 continue;
84623
84624- if (!freezer_should_skip(p))
84625+ if (!freezer_should_skip(p)) {
84626 todo++;
84627+ if (timedout) {
84628+ printk(KERN_ERR "Task refusing to freeze:\n");
84629+ sched_show_task(p);
84630+ }
84631+ }
84632 } while_each_thread(g, p);
84633 read_unlock(&tasklist_lock);
84634
84635@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
84636 todo += wq_busy;
84637 }
84638
84639- if (!todo || time_after(jiffies, end_time))
84640+ if (!todo || timedout)
84641 break;
84642
84643 if (pm_wakeup_pending()) {
84644diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
84645index b4e8500..b457a6c 100644
84646--- a/kernel/printk/printk.c
84647+++ b/kernel/printk/printk.c
84648@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
84649 if (from_file && type != SYSLOG_ACTION_OPEN)
84650 return 0;
84651
84652+#ifdef CONFIG_GRKERNSEC_DMESG
84653+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
84654+ return -EPERM;
84655+#endif
84656+
84657 if (syslog_action_restricted(type)) {
84658 if (capable(CAP_SYSLOG))
84659 return 0;
84660diff --git a/kernel/profile.c b/kernel/profile.c
84661index 6631e1e..310c266 100644
84662--- a/kernel/profile.c
84663+++ b/kernel/profile.c
84664@@ -37,7 +37,7 @@ struct profile_hit {
84665 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
84666 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
84667
84668-static atomic_t *prof_buffer;
84669+static atomic_unchecked_t *prof_buffer;
84670 static unsigned long prof_len, prof_shift;
84671
84672 int prof_on __read_mostly;
84673@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
84674 hits[i].pc = 0;
84675 continue;
84676 }
84677- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
84678+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
84679 hits[i].hits = hits[i].pc = 0;
84680 }
84681 }
84682@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
84683 * Add the current hit(s) and flush the write-queue out
84684 * to the global buffer:
84685 */
84686- atomic_add(nr_hits, &prof_buffer[pc]);
84687+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
84688 for (i = 0; i < NR_PROFILE_HIT; ++i) {
84689- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
84690+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
84691 hits[i].pc = hits[i].hits = 0;
84692 }
84693 out:
84694@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
84695 {
84696 unsigned long pc;
84697 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
84698- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
84699+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
84700 }
84701 #endif /* !CONFIG_SMP */
84702
84703@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
84704 return -EFAULT;
84705 buf++; p++; count--; read++;
84706 }
84707- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
84708+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
84709 if (copy_to_user(buf, (void *)pnt, count))
84710 return -EFAULT;
84711 read += count;
84712@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
84713 }
84714 #endif
84715 profile_discard_flip_buffers();
84716- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
84717+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
84718 return count;
84719 }
84720
84721diff --git a/kernel/ptrace.c b/kernel/ptrace.c
84722index 1f4bcb3..99cf7ab 100644
84723--- a/kernel/ptrace.c
84724+++ b/kernel/ptrace.c
84725@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
84726 if (seize)
84727 flags |= PT_SEIZED;
84728 rcu_read_lock();
84729- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
84730+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
84731 flags |= PT_PTRACE_CAP;
84732 rcu_read_unlock();
84733 task->ptrace = flags;
84734@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
84735 break;
84736 return -EIO;
84737 }
84738- if (copy_to_user(dst, buf, retval))
84739+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
84740 return -EFAULT;
84741 copied += retval;
84742 src += retval;
84743@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
84744 bool seized = child->ptrace & PT_SEIZED;
84745 int ret = -EIO;
84746 siginfo_t siginfo, *si;
84747- void __user *datavp = (void __user *) data;
84748+ void __user *datavp = (__force void __user *) data;
84749 unsigned long __user *datalp = datavp;
84750 unsigned long flags;
84751
84752@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
84753 goto out;
84754 }
84755
84756+ if (gr_handle_ptrace(child, request)) {
84757+ ret = -EPERM;
84758+ goto out_put_task_struct;
84759+ }
84760+
84761 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
84762 ret = ptrace_attach(child, request, addr, data);
84763 /*
84764 * Some architectures need to do book-keeping after
84765 * a ptrace attach.
84766 */
84767- if (!ret)
84768+ if (!ret) {
84769 arch_ptrace_attach(child);
84770+ gr_audit_ptrace(child);
84771+ }
84772 goto out_put_task_struct;
84773 }
84774
84775@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
84776 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
84777 if (copied != sizeof(tmp))
84778 return -EIO;
84779- return put_user(tmp, (unsigned long __user *)data);
84780+ return put_user(tmp, (__force unsigned long __user *)data);
84781 }
84782
84783 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
84784@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
84785 }
84786
84787 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
84788- compat_long_t addr, compat_long_t data)
84789+ compat_ulong_t addr, compat_ulong_t data)
84790 {
84791 struct task_struct *child;
84792 long ret;
84793@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
84794 goto out;
84795 }
84796
84797+ if (gr_handle_ptrace(child, request)) {
84798+ ret = -EPERM;
84799+ goto out_put_task_struct;
84800+ }
84801+
84802 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
84803 ret = ptrace_attach(child, request, addr, data);
84804 /*
84805 * Some architectures need to do book-keeping after
84806 * a ptrace attach.
84807 */
84808- if (!ret)
84809+ if (!ret) {
84810 arch_ptrace_attach(child);
84811+ gr_audit_ptrace(child);
84812+ }
84813 goto out_put_task_struct;
84814 }
84815
84816diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
84817index b02a339..ce2d20c 100644
84818--- a/kernel/rcupdate.c
84819+++ b/kernel/rcupdate.c
84820@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
84821 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
84822 */
84823 if (till_stall_check < 3) {
84824- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
84825+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
84826 till_stall_check = 3;
84827 } else if (till_stall_check > 300) {
84828- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
84829+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
84830 till_stall_check = 300;
84831 }
84832 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
84833diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
84834index 9ed6075..c9e8a63 100644
84835--- a/kernel/rcutiny.c
84836+++ b/kernel/rcutiny.c
84837@@ -45,7 +45,7 @@
84838 /* Forward declarations for rcutiny_plugin.h. */
84839 struct rcu_ctrlblk;
84840 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
84841-static void rcu_process_callbacks(struct softirq_action *unused);
84842+static void rcu_process_callbacks(void);
84843 static void __call_rcu(struct rcu_head *head,
84844 void (*func)(struct rcu_head *rcu),
84845 struct rcu_ctrlblk *rcp);
84846@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
84847 false));
84848 }
84849
84850-static void rcu_process_callbacks(struct softirq_action *unused)
84851+static __latent_entropy void rcu_process_callbacks(void)
84852 {
84853 __rcu_process_callbacks(&rcu_sched_ctrlblk);
84854 __rcu_process_callbacks(&rcu_bh_ctrlblk);
84855diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
84856index be63101..05cf721 100644
84857--- a/kernel/rcutorture.c
84858+++ b/kernel/rcutorture.c
84859@@ -170,12 +170,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
84860 { 0 };
84861 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
84862 { 0 };
84863-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
84864-static atomic_t n_rcu_torture_alloc;
84865-static atomic_t n_rcu_torture_alloc_fail;
84866-static atomic_t n_rcu_torture_free;
84867-static atomic_t n_rcu_torture_mberror;
84868-static atomic_t n_rcu_torture_error;
84869+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
84870+static atomic_unchecked_t n_rcu_torture_alloc;
84871+static atomic_unchecked_t n_rcu_torture_alloc_fail;
84872+static atomic_unchecked_t n_rcu_torture_free;
84873+static atomic_unchecked_t n_rcu_torture_mberror;
84874+static atomic_unchecked_t n_rcu_torture_error;
84875 static long n_rcu_torture_barrier_error;
84876 static long n_rcu_torture_boost_ktrerror;
84877 static long n_rcu_torture_boost_rterror;
84878@@ -293,11 +293,11 @@ rcu_torture_alloc(void)
84879
84880 spin_lock_bh(&rcu_torture_lock);
84881 if (list_empty(&rcu_torture_freelist)) {
84882- atomic_inc(&n_rcu_torture_alloc_fail);
84883+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
84884 spin_unlock_bh(&rcu_torture_lock);
84885 return NULL;
84886 }
84887- atomic_inc(&n_rcu_torture_alloc);
84888+ atomic_inc_unchecked(&n_rcu_torture_alloc);
84889 p = rcu_torture_freelist.next;
84890 list_del_init(p);
84891 spin_unlock_bh(&rcu_torture_lock);
84892@@ -310,7 +310,7 @@ rcu_torture_alloc(void)
84893 static void
84894 rcu_torture_free(struct rcu_torture *p)
84895 {
84896- atomic_inc(&n_rcu_torture_free);
84897+ atomic_inc_unchecked(&n_rcu_torture_free);
84898 spin_lock_bh(&rcu_torture_lock);
84899 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
84900 spin_unlock_bh(&rcu_torture_lock);
84901@@ -431,7 +431,7 @@ rcu_torture_cb(struct rcu_head *p)
84902 i = rp->rtort_pipe_count;
84903 if (i > RCU_TORTURE_PIPE_LEN)
84904 i = RCU_TORTURE_PIPE_LEN;
84905- atomic_inc(&rcu_torture_wcount[i]);
84906+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84907 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
84908 rp->rtort_mbtest = 0;
84909 rcu_torture_free(rp);
84910@@ -821,7 +821,7 @@ rcu_torture_writer(void *arg)
84911 i = old_rp->rtort_pipe_count;
84912 if (i > RCU_TORTURE_PIPE_LEN)
84913 i = RCU_TORTURE_PIPE_LEN;
84914- atomic_inc(&rcu_torture_wcount[i]);
84915+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84916 old_rp->rtort_pipe_count++;
84917 if (gp_normal == gp_exp)
84918 exp = !!(rcu_random(&rand) & 0x80);
84919@@ -839,7 +839,7 @@ rcu_torture_writer(void *arg)
84920 i = rp->rtort_pipe_count;
84921 if (i > RCU_TORTURE_PIPE_LEN)
84922 i = RCU_TORTURE_PIPE_LEN;
84923- atomic_inc(&rcu_torture_wcount[i]);
84924+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84925 if (++rp->rtort_pipe_count >=
84926 RCU_TORTURE_PIPE_LEN) {
84927 rp->rtort_mbtest = 0;
84928@@ -938,7 +938,7 @@ static void rcu_torture_timer(unsigned long unused)
84929 return;
84930 }
84931 if (p->rtort_mbtest == 0)
84932- atomic_inc(&n_rcu_torture_mberror);
84933+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84934 spin_lock(&rand_lock);
84935 cur_ops->read_delay(&rand);
84936 n_rcu_torture_timers++;
84937@@ -1008,7 +1008,7 @@ rcu_torture_reader(void *arg)
84938 continue;
84939 }
84940 if (p->rtort_mbtest == 0)
84941- atomic_inc(&n_rcu_torture_mberror);
84942+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84943 cur_ops->read_delay(&rand);
84944 preempt_disable();
84945 pipe_count = p->rtort_pipe_count;
84946@@ -1071,11 +1071,11 @@ rcu_torture_printk(char *page)
84947 rcu_torture_current,
84948 rcu_torture_current_version,
84949 list_empty(&rcu_torture_freelist),
84950- atomic_read(&n_rcu_torture_alloc),
84951- atomic_read(&n_rcu_torture_alloc_fail),
84952- atomic_read(&n_rcu_torture_free));
84953+ atomic_read_unchecked(&n_rcu_torture_alloc),
84954+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
84955+ atomic_read_unchecked(&n_rcu_torture_free));
84956 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
84957- atomic_read(&n_rcu_torture_mberror),
84958+ atomic_read_unchecked(&n_rcu_torture_mberror),
84959 n_rcu_torture_boost_ktrerror,
84960 n_rcu_torture_boost_rterror);
84961 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
84962@@ -1094,14 +1094,14 @@ rcu_torture_printk(char *page)
84963 n_barrier_attempts,
84964 n_rcu_torture_barrier_error);
84965 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
84966- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
84967+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
84968 n_rcu_torture_barrier_error != 0 ||
84969 n_rcu_torture_boost_ktrerror != 0 ||
84970 n_rcu_torture_boost_rterror != 0 ||
84971 n_rcu_torture_boost_failure != 0 ||
84972 i > 1) {
84973 cnt += sprintf(&page[cnt], "!!! ");
84974- atomic_inc(&n_rcu_torture_error);
84975+ atomic_inc_unchecked(&n_rcu_torture_error);
84976 WARN_ON_ONCE(1);
84977 }
84978 cnt += sprintf(&page[cnt], "Reader Pipe: ");
84979@@ -1115,7 +1115,7 @@ rcu_torture_printk(char *page)
84980 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
84981 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84982 cnt += sprintf(&page[cnt], " %d",
84983- atomic_read(&rcu_torture_wcount[i]));
84984+ atomic_read_unchecked(&rcu_torture_wcount[i]));
84985 }
84986 cnt += sprintf(&page[cnt], "\n");
84987 if (cur_ops->stats)
84988@@ -1830,7 +1830,7 @@ rcu_torture_cleanup(void)
84989
84990 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
84991
84992- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84993+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84994 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
84995 else if (n_online_successes != n_online_attempts ||
84996 n_offline_successes != n_offline_attempts)
84997@@ -1952,18 +1952,18 @@ rcu_torture_init(void)
84998
84999 rcu_torture_current = NULL;
85000 rcu_torture_current_version = 0;
85001- atomic_set(&n_rcu_torture_alloc, 0);
85002- atomic_set(&n_rcu_torture_alloc_fail, 0);
85003- atomic_set(&n_rcu_torture_free, 0);
85004- atomic_set(&n_rcu_torture_mberror, 0);
85005- atomic_set(&n_rcu_torture_error, 0);
85006+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
85007+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
85008+ atomic_set_unchecked(&n_rcu_torture_free, 0);
85009+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
85010+ atomic_set_unchecked(&n_rcu_torture_error, 0);
85011 n_rcu_torture_barrier_error = 0;
85012 n_rcu_torture_boost_ktrerror = 0;
85013 n_rcu_torture_boost_rterror = 0;
85014 n_rcu_torture_boost_failure = 0;
85015 n_rcu_torture_boosts = 0;
85016 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
85017- atomic_set(&rcu_torture_wcount[i], 0);
85018+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
85019 for_each_possible_cpu(cpu) {
85020 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
85021 per_cpu(rcu_torture_count, cpu)[i] = 0;
85022diff --git a/kernel/rcutree.c b/kernel/rcutree.c
85023index 32618b3..c1fb822 100644
85024--- a/kernel/rcutree.c
85025+++ b/kernel/rcutree.c
85026@@ -382,9 +382,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
85027 rcu_prepare_for_idle(smp_processor_id());
85028 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
85029 smp_mb__before_atomic_inc(); /* See above. */
85030- atomic_inc(&rdtp->dynticks);
85031+ atomic_inc_unchecked(&rdtp->dynticks);
85032 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
85033- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
85034+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
85035
85036 /*
85037 * It is illegal to enter an extended quiescent state while
85038@@ -501,10 +501,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
85039 int user)
85040 {
85041 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
85042- atomic_inc(&rdtp->dynticks);
85043+ atomic_inc_unchecked(&rdtp->dynticks);
85044 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
85045 smp_mb__after_atomic_inc(); /* See above. */
85046- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
85047+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
85048 rcu_cleanup_after_idle(smp_processor_id());
85049 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
85050 if (!user && !is_idle_task(current)) {
85051@@ -623,14 +623,14 @@ void rcu_nmi_enter(void)
85052 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
85053
85054 if (rdtp->dynticks_nmi_nesting == 0 &&
85055- (atomic_read(&rdtp->dynticks) & 0x1))
85056+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
85057 return;
85058 rdtp->dynticks_nmi_nesting++;
85059 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
85060- atomic_inc(&rdtp->dynticks);
85061+ atomic_inc_unchecked(&rdtp->dynticks);
85062 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
85063 smp_mb__after_atomic_inc(); /* See above. */
85064- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
85065+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
85066 }
85067
85068 /**
85069@@ -649,9 +649,9 @@ void rcu_nmi_exit(void)
85070 return;
85071 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
85072 smp_mb__before_atomic_inc(); /* See above. */
85073- atomic_inc(&rdtp->dynticks);
85074+ atomic_inc_unchecked(&rdtp->dynticks);
85075 smp_mb__after_atomic_inc(); /* Force delay to next write. */
85076- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
85077+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
85078 }
85079
85080 /**
85081@@ -665,7 +665,7 @@ int rcu_is_cpu_idle(void)
85082 int ret;
85083
85084 preempt_disable();
85085- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
85086+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
85087 preempt_enable();
85088 return ret;
85089 }
85090@@ -734,7 +734,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
85091 static int dyntick_save_progress_counter(struct rcu_data *rdp,
85092 bool *isidle, unsigned long *maxj)
85093 {
85094- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
85095+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
85096 rcu_sysidle_check_cpu(rdp, isidle, maxj);
85097 return (rdp->dynticks_snap & 0x1) == 0;
85098 }
85099@@ -751,7 +751,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
85100 unsigned int curr;
85101 unsigned int snap;
85102
85103- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
85104+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
85105 snap = (unsigned int)rdp->dynticks_snap;
85106
85107 /*
85108@@ -1341,9 +1341,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
85109 rdp = this_cpu_ptr(rsp->rda);
85110 rcu_preempt_check_blocked_tasks(rnp);
85111 rnp->qsmask = rnp->qsmaskinit;
85112- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
85113+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
85114 WARN_ON_ONCE(rnp->completed != rsp->completed);
85115- ACCESS_ONCE(rnp->completed) = rsp->completed;
85116+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
85117 if (rnp == rdp->mynode)
85118 __note_gp_changes(rsp, rnp, rdp);
85119 rcu_preempt_boost_start_gp(rnp);
85120@@ -1434,7 +1434,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
85121 */
85122 rcu_for_each_node_breadth_first(rsp, rnp) {
85123 raw_spin_lock_irq(&rnp->lock);
85124- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
85125+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
85126 rdp = this_cpu_ptr(rsp->rda);
85127 if (rnp == rdp->mynode)
85128 __note_gp_changes(rsp, rnp, rdp);
85129@@ -1766,7 +1766,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
85130 rsp->qlen += rdp->qlen;
85131 rdp->n_cbs_orphaned += rdp->qlen;
85132 rdp->qlen_lazy = 0;
85133- ACCESS_ONCE(rdp->qlen) = 0;
85134+ ACCESS_ONCE_RW(rdp->qlen) = 0;
85135 }
85136
85137 /*
85138@@ -2012,7 +2012,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
85139 }
85140 smp_mb(); /* List handling before counting for rcu_barrier(). */
85141 rdp->qlen_lazy -= count_lazy;
85142- ACCESS_ONCE(rdp->qlen) -= count;
85143+ ACCESS_ONCE_RW(rdp->qlen) -= count;
85144 rdp->n_cbs_invoked += count;
85145
85146 /* Reinstate batch limit if we have worked down the excess. */
85147@@ -2209,7 +2209,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
85148 /*
85149 * Do RCU core processing for the current CPU.
85150 */
85151-static void rcu_process_callbacks(struct softirq_action *unused)
85152+static __latent_entropy void rcu_process_callbacks(void)
85153 {
85154 struct rcu_state *rsp;
85155
85156@@ -2316,7 +2316,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
85157 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
85158 if (debug_rcu_head_queue(head)) {
85159 /* Probable double call_rcu(), so leak the callback. */
85160- ACCESS_ONCE(head->func) = rcu_leak_callback;
85161+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
85162 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
85163 return;
85164 }
85165@@ -2344,7 +2344,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
85166 local_irq_restore(flags);
85167 return;
85168 }
85169- ACCESS_ONCE(rdp->qlen)++;
85170+ ACCESS_ONCE_RW(rdp->qlen)++;
85171 if (lazy)
85172 rdp->qlen_lazy++;
85173 else
85174@@ -2553,11 +2553,11 @@ void synchronize_sched_expedited(void)
85175 * counter wrap on a 32-bit system. Quite a few more CPUs would of
85176 * course be required on a 64-bit system.
85177 */
85178- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
85179+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
85180 (ulong)atomic_long_read(&rsp->expedited_done) +
85181 ULONG_MAX / 8)) {
85182 synchronize_sched();
85183- atomic_long_inc(&rsp->expedited_wrap);
85184+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
85185 return;
85186 }
85187
85188@@ -2565,7 +2565,7 @@ void synchronize_sched_expedited(void)
85189 * Take a ticket. Note that atomic_inc_return() implies a
85190 * full memory barrier.
85191 */
85192- snap = atomic_long_inc_return(&rsp->expedited_start);
85193+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
85194 firstsnap = snap;
85195 get_online_cpus();
85196 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
85197@@ -2578,14 +2578,14 @@ void synchronize_sched_expedited(void)
85198 synchronize_sched_expedited_cpu_stop,
85199 NULL) == -EAGAIN) {
85200 put_online_cpus();
85201- atomic_long_inc(&rsp->expedited_tryfail);
85202+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
85203
85204 /* Check to see if someone else did our work for us. */
85205 s = atomic_long_read(&rsp->expedited_done);
85206 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
85207 /* ensure test happens before caller kfree */
85208 smp_mb__before_atomic_inc(); /* ^^^ */
85209- atomic_long_inc(&rsp->expedited_workdone1);
85210+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
85211 return;
85212 }
85213
85214@@ -2594,7 +2594,7 @@ void synchronize_sched_expedited(void)
85215 udelay(trycount * num_online_cpus());
85216 } else {
85217 wait_rcu_gp(call_rcu_sched);
85218- atomic_long_inc(&rsp->expedited_normal);
85219+ atomic_long_inc_unchecked(&rsp->expedited_normal);
85220 return;
85221 }
85222
85223@@ -2603,7 +2603,7 @@ void synchronize_sched_expedited(void)
85224 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
85225 /* ensure test happens before caller kfree */
85226 smp_mb__before_atomic_inc(); /* ^^^ */
85227- atomic_long_inc(&rsp->expedited_workdone2);
85228+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
85229 return;
85230 }
85231
85232@@ -2615,10 +2615,10 @@ void synchronize_sched_expedited(void)
85233 * period works for us.
85234 */
85235 get_online_cpus();
85236- snap = atomic_long_read(&rsp->expedited_start);
85237+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
85238 smp_mb(); /* ensure read is before try_stop_cpus(). */
85239 }
85240- atomic_long_inc(&rsp->expedited_stoppedcpus);
85241+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
85242
85243 /*
85244 * Everyone up to our most recent fetch is covered by our grace
85245@@ -2627,16 +2627,16 @@ void synchronize_sched_expedited(void)
85246 * than we did already did their update.
85247 */
85248 do {
85249- atomic_long_inc(&rsp->expedited_done_tries);
85250+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
85251 s = atomic_long_read(&rsp->expedited_done);
85252 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
85253 /* ensure test happens before caller kfree */
85254 smp_mb__before_atomic_inc(); /* ^^^ */
85255- atomic_long_inc(&rsp->expedited_done_lost);
85256+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
85257 break;
85258 }
85259 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
85260- atomic_long_inc(&rsp->expedited_done_exit);
85261+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
85262
85263 put_online_cpus();
85264 }
85265@@ -2829,7 +2829,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
85266 * ACCESS_ONCE() to prevent the compiler from speculating
85267 * the increment to precede the early-exit check.
85268 */
85269- ACCESS_ONCE(rsp->n_barrier_done)++;
85270+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
85271 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
85272 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
85273 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
85274@@ -2879,7 +2879,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
85275
85276 /* Increment ->n_barrier_done to prevent duplicate work. */
85277 smp_mb(); /* Keep increment after above mechanism. */
85278- ACCESS_ONCE(rsp->n_barrier_done)++;
85279+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
85280 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
85281 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
85282 smp_mb(); /* Keep increment before caller's subsequent code. */
85283@@ -2924,10 +2924,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
85284 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
85285 init_callback_list(rdp);
85286 rdp->qlen_lazy = 0;
85287- ACCESS_ONCE(rdp->qlen) = 0;
85288+ ACCESS_ONCE_RW(rdp->qlen) = 0;
85289 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
85290 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
85291- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
85292+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
85293 rdp->cpu = cpu;
85294 rdp->rsp = rsp;
85295 rcu_boot_init_nocb_percpu_data(rdp);
85296@@ -2961,8 +2961,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
85297 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
85298 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
85299 rcu_sysidle_init_percpu_data(rdp->dynticks);
85300- atomic_set(&rdp->dynticks->dynticks,
85301- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
85302+ atomic_set_unchecked(&rdp->dynticks->dynticks,
85303+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
85304 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
85305
85306 /* Add CPU to rcu_node bitmasks. */
85307diff --git a/kernel/rcutree.h b/kernel/rcutree.h
85308index 5f97eab..db8f687 100644
85309--- a/kernel/rcutree.h
85310+++ b/kernel/rcutree.h
85311@@ -87,11 +87,11 @@ struct rcu_dynticks {
85312 long long dynticks_nesting; /* Track irq/process nesting level. */
85313 /* Process level is worth LLONG_MAX/2. */
85314 int dynticks_nmi_nesting; /* Track NMI nesting level. */
85315- atomic_t dynticks; /* Even value for idle, else odd. */
85316+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
85317 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
85318 long long dynticks_idle_nesting;
85319 /* irq/process nesting level from idle. */
85320- atomic_t dynticks_idle; /* Even value for idle, else odd. */
85321+ atomic_unchecked_t dynticks_idle; /* Even value for idle, else odd. */
85322 /* "Idle" excludes userspace execution. */
85323 unsigned long dynticks_idle_jiffies;
85324 /* End of last non-NMI non-idle period. */
85325@@ -427,17 +427,17 @@ struct rcu_state {
85326 /* _rcu_barrier(). */
85327 /* End of fields guarded by barrier_mutex. */
85328
85329- atomic_long_t expedited_start; /* Starting ticket. */
85330- atomic_long_t expedited_done; /* Done ticket. */
85331- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
85332- atomic_long_t expedited_tryfail; /* # acquisition failures. */
85333- atomic_long_t expedited_workdone1; /* # done by others #1. */
85334- atomic_long_t expedited_workdone2; /* # done by others #2. */
85335- atomic_long_t expedited_normal; /* # fallbacks to normal. */
85336- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
85337- atomic_long_t expedited_done_tries; /* # tries to update _done. */
85338- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
85339- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
85340+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
85341+ atomic_long_t expedited_done; /* Done ticket. */
85342+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
85343+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
85344+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
85345+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
85346+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
85347+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
85348+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
85349+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
85350+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
85351
85352 unsigned long jiffies_force_qs; /* Time at which to invoke */
85353 /* force_quiescent_state(). */
85354diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
85355index 130c97b..bcbe7f7 100644
85356--- a/kernel/rcutree_plugin.h
85357+++ b/kernel/rcutree_plugin.h
85358@@ -744,7 +744,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
85359 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
85360 {
85361 return !rcu_preempted_readers_exp(rnp) &&
85362- ACCESS_ONCE(rnp->expmask) == 0;
85363+ ACCESS_ONCE_RW(rnp->expmask) == 0;
85364 }
85365
85366 /*
85367@@ -900,7 +900,7 @@ void synchronize_rcu_expedited(void)
85368
85369 /* Clean up and exit. */
85370 smp_mb(); /* ensure expedited GP seen before counter increment. */
85371- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
85372+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
85373 unlock_mb_ret:
85374 mutex_unlock(&sync_rcu_preempt_exp_mutex);
85375 mb_ret:
85376@@ -1474,7 +1474,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
85377 free_cpumask_var(cm);
85378 }
85379
85380-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
85381+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
85382 .store = &rcu_cpu_kthread_task,
85383 .thread_should_run = rcu_cpu_kthread_should_run,
85384 .thread_fn = rcu_cpu_kthread,
85385@@ -1939,7 +1939,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
85386 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
85387 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
85388 cpu, ticks_value, ticks_title,
85389- atomic_read(&rdtp->dynticks) & 0xfff,
85390+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
85391 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
85392 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
85393 fast_no_hz);
85394@@ -2102,7 +2102,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
85395
85396 /* Enqueue the callback on the nocb list and update counts. */
85397 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
85398- ACCESS_ONCE(*old_rhpp) = rhp;
85399+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
85400 atomic_long_add(rhcount, &rdp->nocb_q_count);
85401 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
85402
85403@@ -2242,12 +2242,12 @@ static int rcu_nocb_kthread(void *arg)
85404 * Extract queued callbacks, update counts, and wait
85405 * for a grace period to elapse.
85406 */
85407- ACCESS_ONCE(rdp->nocb_head) = NULL;
85408+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
85409 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
85410 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
85411 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
85412- ACCESS_ONCE(rdp->nocb_p_count) += c;
85413- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
85414+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
85415+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
85416 rcu_nocb_wait_gp(rdp);
85417
85418 /* Each pass through the following loop invokes a callback. */
85419@@ -2269,8 +2269,8 @@ static int rcu_nocb_kthread(void *arg)
85420 list = next;
85421 }
85422 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
85423- ACCESS_ONCE(rdp->nocb_p_count) -= c;
85424- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
85425+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
85426+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
85427 rdp->n_nocbs_invoked += c;
85428 }
85429 return 0;
85430@@ -2297,7 +2297,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
85431 t = kthread_run(rcu_nocb_kthread, rdp,
85432 "rcuo%c/%d", rsp->abbr, cpu);
85433 BUG_ON(IS_ERR(t));
85434- ACCESS_ONCE(rdp->nocb_kthread) = t;
85435+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
85436 }
85437 }
85438
85439@@ -2423,11 +2423,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
85440
85441 /* Record start of fully idle period. */
85442 j = jiffies;
85443- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
85444+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
85445 smp_mb__before_atomic_inc();
85446- atomic_inc(&rdtp->dynticks_idle);
85447+ atomic_inc_unchecked(&rdtp->dynticks_idle);
85448 smp_mb__after_atomic_inc();
85449- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
85450+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
85451 }
85452
85453 /*
85454@@ -2492,9 +2492,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
85455
85456 /* Record end of idle period. */
85457 smp_mb__before_atomic_inc();
85458- atomic_inc(&rdtp->dynticks_idle);
85459+ atomic_inc_unchecked(&rdtp->dynticks_idle);
85460 smp_mb__after_atomic_inc();
85461- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
85462+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
85463
85464 /*
85465 * If we are the timekeeping CPU, we are permitted to be non-idle
85466@@ -2535,7 +2535,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
85467 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
85468
85469 /* Pick up current idle and NMI-nesting counter and check. */
85470- cur = atomic_read(&rdtp->dynticks_idle);
85471+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
85472 if (cur & 0x1) {
85473 *isidle = false; /* We are not idle! */
85474 return;
85475@@ -2598,7 +2598,7 @@ static void rcu_sysidle(unsigned long j)
85476 case RCU_SYSIDLE_NOT:
85477
85478 /* First time all are idle, so note a short idle period. */
85479- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
85480+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
85481 break;
85482
85483 case RCU_SYSIDLE_SHORT:
85484@@ -2635,7 +2635,7 @@ static void rcu_sysidle(unsigned long j)
85485 static void rcu_sysidle_cancel(void)
85486 {
85487 smp_mb();
85488- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
85489+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
85490 }
85491
85492 /*
85493@@ -2683,7 +2683,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
85494 smp_mb(); /* grace period precedes setting inuse. */
85495
85496 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
85497- ACCESS_ONCE(rshp->inuse) = 0;
85498+ ACCESS_ONCE_RW(rshp->inuse) = 0;
85499 }
85500
85501 /*
85502diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
85503index cf6c174..a8f4b50 100644
85504--- a/kernel/rcutree_trace.c
85505+++ b/kernel/rcutree_trace.c
85506@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
85507 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
85508 rdp->passed_quiesce, rdp->qs_pending);
85509 seq_printf(m, " dt=%d/%llx/%d df=%lu",
85510- atomic_read(&rdp->dynticks->dynticks),
85511+ atomic_read_unchecked(&rdp->dynticks->dynticks),
85512 rdp->dynticks->dynticks_nesting,
85513 rdp->dynticks->dynticks_nmi_nesting,
85514 rdp->dynticks_fqs);
85515@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
85516 struct rcu_state *rsp = (struct rcu_state *)m->private;
85517
85518 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",
85519- atomic_long_read(&rsp->expedited_start),
85520+ atomic_long_read_unchecked(&rsp->expedited_start),
85521 atomic_long_read(&rsp->expedited_done),
85522- atomic_long_read(&rsp->expedited_wrap),
85523- atomic_long_read(&rsp->expedited_tryfail),
85524- atomic_long_read(&rsp->expedited_workdone1),
85525- atomic_long_read(&rsp->expedited_workdone2),
85526- atomic_long_read(&rsp->expedited_normal),
85527- atomic_long_read(&rsp->expedited_stoppedcpus),
85528- atomic_long_read(&rsp->expedited_done_tries),
85529- atomic_long_read(&rsp->expedited_done_lost),
85530- atomic_long_read(&rsp->expedited_done_exit));
85531+ atomic_long_read_unchecked(&rsp->expedited_wrap),
85532+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
85533+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
85534+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
85535+ atomic_long_read_unchecked(&rsp->expedited_normal),
85536+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
85537+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
85538+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
85539+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
85540 return 0;
85541 }
85542
85543diff --git a/kernel/resource.c b/kernel/resource.c
85544index 3f285dc..5755f62 100644
85545--- a/kernel/resource.c
85546+++ b/kernel/resource.c
85547@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
85548
85549 static int __init ioresources_init(void)
85550 {
85551+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85552+#ifdef CONFIG_GRKERNSEC_PROC_USER
85553+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
85554+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
85555+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85556+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
85557+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
85558+#endif
85559+#else
85560 proc_create("ioports", 0, NULL, &proc_ioports_operations);
85561 proc_create("iomem", 0, NULL, &proc_iomem_operations);
85562+#endif
85563 return 0;
85564 }
85565 __initcall(ioresources_init);
85566diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
85567index 1d96dd0..994ff19 100644
85568--- a/kernel/rtmutex-tester.c
85569+++ b/kernel/rtmutex-tester.c
85570@@ -22,7 +22,7 @@
85571 #define MAX_RT_TEST_MUTEXES 8
85572
85573 static spinlock_t rttest_lock;
85574-static atomic_t rttest_event;
85575+static atomic_unchecked_t rttest_event;
85576
85577 struct test_thread_data {
85578 int opcode;
85579@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85580
85581 case RTTEST_LOCKCONT:
85582 td->mutexes[td->opdata] = 1;
85583- td->event = atomic_add_return(1, &rttest_event);
85584+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85585 return 0;
85586
85587 case RTTEST_RESET:
85588@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85589 return 0;
85590
85591 case RTTEST_RESETEVENT:
85592- atomic_set(&rttest_event, 0);
85593+ atomic_set_unchecked(&rttest_event, 0);
85594 return 0;
85595
85596 default:
85597@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85598 return ret;
85599
85600 td->mutexes[id] = 1;
85601- td->event = atomic_add_return(1, &rttest_event);
85602+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85603 rt_mutex_lock(&mutexes[id]);
85604- td->event = atomic_add_return(1, &rttest_event);
85605+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85606 td->mutexes[id] = 4;
85607 return 0;
85608
85609@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85610 return ret;
85611
85612 td->mutexes[id] = 1;
85613- td->event = atomic_add_return(1, &rttest_event);
85614+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85615 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85616- td->event = atomic_add_return(1, &rttest_event);
85617+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85618 td->mutexes[id] = ret ? 0 : 4;
85619 return ret ? -EINTR : 0;
85620
85621@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85622 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85623 return ret;
85624
85625- td->event = atomic_add_return(1, &rttest_event);
85626+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85627 rt_mutex_unlock(&mutexes[id]);
85628- td->event = atomic_add_return(1, &rttest_event);
85629+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85630 td->mutexes[id] = 0;
85631 return 0;
85632
85633@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85634 break;
85635
85636 td->mutexes[dat] = 2;
85637- td->event = atomic_add_return(1, &rttest_event);
85638+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85639 break;
85640
85641 default:
85642@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85643 return;
85644
85645 td->mutexes[dat] = 3;
85646- td->event = atomic_add_return(1, &rttest_event);
85647+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85648 break;
85649
85650 case RTTEST_LOCKNOWAIT:
85651@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85652 return;
85653
85654 td->mutexes[dat] = 1;
85655- td->event = atomic_add_return(1, &rttest_event);
85656+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85657 return;
85658
85659 default:
85660diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
85661index 4a07353..66b5291 100644
85662--- a/kernel/sched/auto_group.c
85663+++ b/kernel/sched/auto_group.c
85664@@ -11,7 +11,7 @@
85665
85666 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
85667 static struct autogroup autogroup_default;
85668-static atomic_t autogroup_seq_nr;
85669+static atomic_unchecked_t autogroup_seq_nr;
85670
85671 void __init autogroup_init(struct task_struct *init_task)
85672 {
85673@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
85674
85675 kref_init(&ag->kref);
85676 init_rwsem(&ag->lock);
85677- ag->id = atomic_inc_return(&autogroup_seq_nr);
85678+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
85679 ag->tg = tg;
85680 #ifdef CONFIG_RT_GROUP_SCHED
85681 /*
85682diff --git a/kernel/sched/core.c b/kernel/sched/core.c
85683index 5ac63c9..d912786 100644
85684--- a/kernel/sched/core.c
85685+++ b/kernel/sched/core.c
85686@@ -2868,7 +2868,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
85687 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
85688 * or number of jiffies left till timeout) if completed.
85689 */
85690-long __sched
85691+long __sched __intentional_overflow(-1)
85692 wait_for_completion_interruptible_timeout(struct completion *x,
85693 unsigned long timeout)
85694 {
85695@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
85696 *
85697 * Return: -ERESTARTSYS if interrupted, 0 if completed.
85698 */
85699-int __sched wait_for_completion_killable(struct completion *x)
85700+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
85701 {
85702 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
85703 if (t == -ERESTARTSYS)
85704@@ -2906,7 +2906,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
85705 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
85706 * or number of jiffies left till timeout) if completed.
85707 */
85708-long __sched
85709+long __sched __intentional_overflow(-1)
85710 wait_for_completion_killable_timeout(struct completion *x,
85711 unsigned long timeout)
85712 {
85713@@ -3132,6 +3132,8 @@ int can_nice(const struct task_struct *p, const int nice)
85714 /* convert nice value [19,-20] to rlimit style value [1,40] */
85715 int nice_rlim = 20 - nice;
85716
85717+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
85718+
85719 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
85720 capable(CAP_SYS_NICE));
85721 }
85722@@ -3165,7 +3167,8 @@ SYSCALL_DEFINE1(nice, int, increment)
85723 if (nice > 19)
85724 nice = 19;
85725
85726- if (increment < 0 && !can_nice(current, nice))
85727+ if (increment < 0 && (!can_nice(current, nice) ||
85728+ gr_handle_chroot_nice()))
85729 return -EPERM;
85730
85731 retval = security_task_setnice(current, nice);
85732@@ -3327,6 +3330,7 @@ recheck:
85733 unsigned long rlim_rtprio =
85734 task_rlimit(p, RLIMIT_RTPRIO);
85735
85736+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
85737 /* can't set/change the rt policy */
85738 if (policy != p->policy && !rlim_rtprio)
85739 return -EPERM;
85740@@ -4456,7 +4460,7 @@ static void migrate_tasks(unsigned int dead_cpu)
85741
85742 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
85743
85744-static struct ctl_table sd_ctl_dir[] = {
85745+static ctl_table_no_const sd_ctl_dir[] __read_only = {
85746 {
85747 .procname = "sched_domain",
85748 .mode = 0555,
85749@@ -4473,17 +4477,17 @@ static struct ctl_table sd_ctl_root[] = {
85750 {}
85751 };
85752
85753-static struct ctl_table *sd_alloc_ctl_entry(int n)
85754+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
85755 {
85756- struct ctl_table *entry =
85757+ ctl_table_no_const *entry =
85758 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
85759
85760 return entry;
85761 }
85762
85763-static void sd_free_ctl_entry(struct ctl_table **tablep)
85764+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
85765 {
85766- struct ctl_table *entry;
85767+ ctl_table_no_const *entry;
85768
85769 /*
85770 * In the intermediate directories, both the child directory and
85771@@ -4491,22 +4495,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
85772 * will always be set. In the lowest directory the names are
85773 * static strings and all have proc handlers.
85774 */
85775- for (entry = *tablep; entry->mode; entry++) {
85776- if (entry->child)
85777- sd_free_ctl_entry(&entry->child);
85778+ for (entry = tablep; entry->mode; entry++) {
85779+ if (entry->child) {
85780+ sd_free_ctl_entry(entry->child);
85781+ pax_open_kernel();
85782+ entry->child = NULL;
85783+ pax_close_kernel();
85784+ }
85785 if (entry->proc_handler == NULL)
85786 kfree(entry->procname);
85787 }
85788
85789- kfree(*tablep);
85790- *tablep = NULL;
85791+ kfree(tablep);
85792 }
85793
85794 static int min_load_idx = 0;
85795 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
85796
85797 static void
85798-set_table_entry(struct ctl_table *entry,
85799+set_table_entry(ctl_table_no_const *entry,
85800 const char *procname, void *data, int maxlen,
85801 umode_t mode, proc_handler *proc_handler,
85802 bool load_idx)
85803@@ -4526,7 +4533,7 @@ set_table_entry(struct ctl_table *entry,
85804 static struct ctl_table *
85805 sd_alloc_ctl_domain_table(struct sched_domain *sd)
85806 {
85807- struct ctl_table *table = sd_alloc_ctl_entry(13);
85808+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
85809
85810 if (table == NULL)
85811 return NULL;
85812@@ -4561,9 +4568,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
85813 return table;
85814 }
85815
85816-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
85817+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
85818 {
85819- struct ctl_table *entry, *table;
85820+ ctl_table_no_const *entry, *table;
85821 struct sched_domain *sd;
85822 int domain_num = 0, i;
85823 char buf[32];
85824@@ -4590,11 +4597,13 @@ static struct ctl_table_header *sd_sysctl_header;
85825 static void register_sched_domain_sysctl(void)
85826 {
85827 int i, cpu_num = num_possible_cpus();
85828- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
85829+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
85830 char buf[32];
85831
85832 WARN_ON(sd_ctl_dir[0].child);
85833+ pax_open_kernel();
85834 sd_ctl_dir[0].child = entry;
85835+ pax_close_kernel();
85836
85837 if (entry == NULL)
85838 return;
85839@@ -4617,8 +4626,12 @@ static void unregister_sched_domain_sysctl(void)
85840 if (sd_sysctl_header)
85841 unregister_sysctl_table(sd_sysctl_header);
85842 sd_sysctl_header = NULL;
85843- if (sd_ctl_dir[0].child)
85844- sd_free_ctl_entry(&sd_ctl_dir[0].child);
85845+ if (sd_ctl_dir[0].child) {
85846+ sd_free_ctl_entry(sd_ctl_dir[0].child);
85847+ pax_open_kernel();
85848+ sd_ctl_dir[0].child = NULL;
85849+ pax_close_kernel();
85850+ }
85851 }
85852 #else
85853 static void register_sched_domain_sysctl(void)
85854diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
85855index 513fc2f..906a851 100644
85856--- a/kernel/sched/fair.c
85857+++ b/kernel/sched/fair.c
85858@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
85859
85860 static void reset_ptenuma_scan(struct task_struct *p)
85861 {
85862- ACCESS_ONCE(p->mm->numa_scan_seq)++;
85863+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
85864 p->mm->numa_scan_offset = 0;
85865 }
85866
85867@@ -5840,7 +5840,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
85868 * run_rebalance_domains is triggered when needed from the scheduler tick.
85869 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
85870 */
85871-static void run_rebalance_domains(struct softirq_action *h)
85872+static __latent_entropy void run_rebalance_domains(void)
85873 {
85874 int this_cpu = smp_processor_id();
85875 struct rq *this_rq = cpu_rq(this_cpu);
85876diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
85877index b3c5653..a4d192a 100644
85878--- a/kernel/sched/sched.h
85879+++ b/kernel/sched/sched.h
85880@@ -1004,7 +1004,7 @@ struct sched_class {
85881 #ifdef CONFIG_FAIR_GROUP_SCHED
85882 void (*task_move_group) (struct task_struct *p, int on_rq);
85883 #endif
85884-};
85885+} __do_const;
85886
85887 #define sched_class_highest (&stop_sched_class)
85888 #define for_each_class(class) \
85889diff --git a/kernel/signal.c b/kernel/signal.c
85890index ded28b9..6886c08 100644
85891--- a/kernel/signal.c
85892+++ b/kernel/signal.c
85893@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
85894
85895 int print_fatal_signals __read_mostly;
85896
85897-static void __user *sig_handler(struct task_struct *t, int sig)
85898+static __sighandler_t sig_handler(struct task_struct *t, int sig)
85899 {
85900 return t->sighand->action[sig - 1].sa.sa_handler;
85901 }
85902
85903-static int sig_handler_ignored(void __user *handler, int sig)
85904+static int sig_handler_ignored(__sighandler_t handler, int sig)
85905 {
85906 /* Is it explicitly or implicitly ignored? */
85907 return handler == SIG_IGN ||
85908@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
85909
85910 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
85911 {
85912- void __user *handler;
85913+ __sighandler_t handler;
85914
85915 handler = sig_handler(t, sig);
85916
85917@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
85918 atomic_inc(&user->sigpending);
85919 rcu_read_unlock();
85920
85921+ if (!override_rlimit)
85922+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
85923+
85924 if (override_rlimit ||
85925 atomic_read(&user->sigpending) <=
85926 task_rlimit(t, RLIMIT_SIGPENDING)) {
85927@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
85928
85929 int unhandled_signal(struct task_struct *tsk, int sig)
85930 {
85931- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
85932+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
85933 if (is_global_init(tsk))
85934 return 1;
85935 if (handler != SIG_IGN && handler != SIG_DFL)
85936@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
85937 }
85938 }
85939
85940+ /* allow glibc communication via tgkill to other threads in our
85941+ thread group */
85942+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
85943+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
85944+ && gr_handle_signal(t, sig))
85945+ return -EPERM;
85946+
85947 return security_task_kill(t, info, sig, 0);
85948 }
85949
85950@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85951 return send_signal(sig, info, p, 1);
85952 }
85953
85954-static int
85955+int
85956 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85957 {
85958 return send_signal(sig, info, t, 0);
85959@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85960 unsigned long int flags;
85961 int ret, blocked, ignored;
85962 struct k_sigaction *action;
85963+ int is_unhandled = 0;
85964
85965 spin_lock_irqsave(&t->sighand->siglock, flags);
85966 action = &t->sighand->action[sig-1];
85967@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85968 }
85969 if (action->sa.sa_handler == SIG_DFL)
85970 t->signal->flags &= ~SIGNAL_UNKILLABLE;
85971+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
85972+ is_unhandled = 1;
85973 ret = specific_send_sig_info(sig, info, t);
85974 spin_unlock_irqrestore(&t->sighand->siglock, flags);
85975
85976+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
85977+ normal operation */
85978+ if (is_unhandled) {
85979+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
85980+ gr_handle_crash(t, sig);
85981+ }
85982+
85983 return ret;
85984 }
85985
85986@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85987 ret = check_kill_permission(sig, info, p);
85988 rcu_read_unlock();
85989
85990- if (!ret && sig)
85991+ if (!ret && sig) {
85992 ret = do_send_sig_info(sig, info, p, true);
85993+ if (!ret)
85994+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
85995+ }
85996
85997 return ret;
85998 }
85999@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
86000 int error = -ESRCH;
86001
86002 rcu_read_lock();
86003- p = find_task_by_vpid(pid);
86004+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
86005+ /* allow glibc communication via tgkill to other threads in our
86006+ thread group */
86007+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
86008+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
86009+ p = find_task_by_vpid_unrestricted(pid);
86010+ else
86011+#endif
86012+ p = find_task_by_vpid(pid);
86013 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
86014 error = check_kill_permission(sig, info, p);
86015 /*
86016@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
86017 }
86018 seg = get_fs();
86019 set_fs(KERNEL_DS);
86020- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
86021- (stack_t __force __user *) &uoss,
86022+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
86023+ (stack_t __force_user *) &uoss,
86024 compat_user_stack_pointer());
86025 set_fs(seg);
86026 if (ret >= 0 && uoss_ptr) {
86027diff --git a/kernel/smpboot.c b/kernel/smpboot.c
86028index eb89e18..a4e6792 100644
86029--- a/kernel/smpboot.c
86030+++ b/kernel/smpboot.c
86031@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
86032 }
86033 smpboot_unpark_thread(plug_thread, cpu);
86034 }
86035- list_add(&plug_thread->list, &hotplug_threads);
86036+ pax_list_add(&plug_thread->list, &hotplug_threads);
86037 out:
86038 mutex_unlock(&smpboot_threads_lock);
86039 return ret;
86040@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
86041 {
86042 get_online_cpus();
86043 mutex_lock(&smpboot_threads_lock);
86044- list_del(&plug_thread->list);
86045+ pax_list_del(&plug_thread->list);
86046 smpboot_destroy_threads(plug_thread);
86047 mutex_unlock(&smpboot_threads_lock);
86048 put_online_cpus();
86049diff --git a/kernel/softirq.c b/kernel/softirq.c
86050index d7d498d..94fe0f7 100644
86051--- a/kernel/softirq.c
86052+++ b/kernel/softirq.c
86053@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
86054 EXPORT_SYMBOL(irq_stat);
86055 #endif
86056
86057-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
86058+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
86059
86060 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
86061
86062-char *softirq_to_name[NR_SOFTIRQS] = {
86063+const char * const softirq_to_name[NR_SOFTIRQS] = {
86064 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
86065 "TASKLET", "SCHED", "HRTIMER", "RCU"
86066 };
86067@@ -248,7 +248,7 @@ restart:
86068 kstat_incr_softirqs_this_cpu(vec_nr);
86069
86070 trace_softirq_entry(vec_nr);
86071- h->action(h);
86072+ h->action();
86073 trace_softirq_exit(vec_nr);
86074 if (unlikely(prev_count != preempt_count())) {
86075 printk(KERN_ERR "huh, entered softirq %u %s %p"
86076@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
86077 or_softirq_pending(1UL << nr);
86078 }
86079
86080-void open_softirq(int nr, void (*action)(struct softirq_action *))
86081+void __init open_softirq(int nr, void (*action)(void))
86082 {
86083 softirq_vec[nr].action = action;
86084 }
86085@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
86086
86087 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
86088
86089-static void tasklet_action(struct softirq_action *a)
86090+static __latent_entropy void tasklet_action(void)
86091 {
86092 struct tasklet_struct *list;
86093
86094@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
86095 }
86096 }
86097
86098-static void tasklet_hi_action(struct softirq_action *a)
86099+static __latent_entropy void tasklet_hi_action(void)
86100 {
86101 struct tasklet_struct *list;
86102
86103@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
86104 .notifier_call = cpu_callback
86105 };
86106
86107-static struct smp_hotplug_thread softirq_threads = {
86108+static struct smp_hotplug_thread softirq_threads __read_only = {
86109 .store = &ksoftirqd,
86110 .thread_should_run = ksoftirqd_should_run,
86111 .thread_fn = run_ksoftirqd,
86112diff --git a/kernel/srcu.c b/kernel/srcu.c
86113index 01d5ccb..cdcbee6 100644
86114--- a/kernel/srcu.c
86115+++ b/kernel/srcu.c
86116@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
86117
86118 idx = ACCESS_ONCE(sp->completed) & 0x1;
86119 preempt_disable();
86120- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86121+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86122 smp_mb(); /* B */ /* Avoid leaking the critical section. */
86123- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86124+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86125 preempt_enable();
86126 return idx;
86127 }
86128diff --git a/kernel/sys.c b/kernel/sys.c
86129index c18ecca..b3c2dd2 100644
86130--- a/kernel/sys.c
86131+++ b/kernel/sys.c
86132@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
86133 error = -EACCES;
86134 goto out;
86135 }
86136+
86137+ if (gr_handle_chroot_setpriority(p, niceval)) {
86138+ error = -EACCES;
86139+ goto out;
86140+ }
86141+
86142 no_nice = security_task_setnice(p, niceval);
86143 if (no_nice) {
86144 error = no_nice;
86145@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
86146 goto error;
86147 }
86148
86149+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
86150+ goto error;
86151+
86152 if (rgid != (gid_t) -1 ||
86153 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
86154 new->sgid = new->egid;
86155@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
86156 old = current_cred();
86157
86158 retval = -EPERM;
86159+
86160+ if (gr_check_group_change(kgid, kgid, kgid))
86161+ goto error;
86162+
86163 if (ns_capable(old->user_ns, CAP_SETGID))
86164 new->gid = new->egid = new->sgid = new->fsgid = kgid;
86165 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
86166@@ -404,7 +417,7 @@ error:
86167 /*
86168 * change the user struct in a credentials set to match the new UID
86169 */
86170-static int set_user(struct cred *new)
86171+int set_user(struct cred *new)
86172 {
86173 struct user_struct *new_user;
86174
86175@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
86176 goto error;
86177 }
86178
86179+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
86180+ goto error;
86181+
86182 if (!uid_eq(new->uid, old->uid)) {
86183 retval = set_user(new);
86184 if (retval < 0)
86185@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
86186 old = current_cred();
86187
86188 retval = -EPERM;
86189+
86190+ if (gr_check_crash_uid(kuid))
86191+ goto error;
86192+ if (gr_check_user_change(kuid, kuid, kuid))
86193+ goto error;
86194+
86195 if (ns_capable(old->user_ns, CAP_SETUID)) {
86196 new->suid = new->uid = kuid;
86197 if (!uid_eq(kuid, old->uid)) {
86198@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
86199 goto error;
86200 }
86201
86202+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
86203+ goto error;
86204+
86205 if (ruid != (uid_t) -1) {
86206 new->uid = kruid;
86207 if (!uid_eq(kruid, old->uid)) {
86208@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
86209 goto error;
86210 }
86211
86212+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
86213+ goto error;
86214+
86215 if (rgid != (gid_t) -1)
86216 new->gid = krgid;
86217 if (egid != (gid_t) -1)
86218@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
86219 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
86220 ns_capable(old->user_ns, CAP_SETUID)) {
86221 if (!uid_eq(kuid, old->fsuid)) {
86222+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
86223+ goto error;
86224+
86225 new->fsuid = kuid;
86226 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
86227 goto change_okay;
86228 }
86229 }
86230
86231+error:
86232 abort_creds(new);
86233 return old_fsuid;
86234
86235@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
86236 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
86237 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
86238 ns_capable(old->user_ns, CAP_SETGID)) {
86239+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
86240+ goto error;
86241+
86242 if (!gid_eq(kgid, old->fsgid)) {
86243 new->fsgid = kgid;
86244 goto change_okay;
86245 }
86246 }
86247
86248+error:
86249 abort_creds(new);
86250 return old_fsgid;
86251
86252@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
86253 return -EFAULT;
86254
86255 down_read(&uts_sem);
86256- error = __copy_to_user(&name->sysname, &utsname()->sysname,
86257+ error = __copy_to_user(name->sysname, &utsname()->sysname,
86258 __OLD_UTS_LEN);
86259 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
86260- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
86261+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
86262 __OLD_UTS_LEN);
86263 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
86264- error |= __copy_to_user(&name->release, &utsname()->release,
86265+ error |= __copy_to_user(name->release, &utsname()->release,
86266 __OLD_UTS_LEN);
86267 error |= __put_user(0, name->release + __OLD_UTS_LEN);
86268- error |= __copy_to_user(&name->version, &utsname()->version,
86269+ error |= __copy_to_user(name->version, &utsname()->version,
86270 __OLD_UTS_LEN);
86271 error |= __put_user(0, name->version + __OLD_UTS_LEN);
86272- error |= __copy_to_user(&name->machine, &utsname()->machine,
86273+ error |= __copy_to_user(name->machine, &utsname()->machine,
86274 __OLD_UTS_LEN);
86275 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
86276 up_read(&uts_sem);
86277@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
86278 */
86279 new_rlim->rlim_cur = 1;
86280 }
86281+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
86282+ is changed to a lower value. Since tasks can be created by the same
86283+ user in between this limit change and an execve by this task, force
86284+ a recheck only for this task by setting PF_NPROC_EXCEEDED
86285+ */
86286+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
86287+ tsk->flags |= PF_NPROC_EXCEEDED;
86288 }
86289 if (!retval) {
86290 if (old_rlim)
86291diff --git a/kernel/sysctl.c b/kernel/sysctl.c
86292index b2f06f3..e6354ab 100644
86293--- a/kernel/sysctl.c
86294+++ b/kernel/sysctl.c
86295@@ -93,7 +93,6 @@
86296
86297
86298 #if defined(CONFIG_SYSCTL)
86299-
86300 /* External variables not in a header file. */
86301 extern int sysctl_overcommit_memory;
86302 extern int sysctl_overcommit_ratio;
86303@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
86304
86305 /* Constants used for minimum and maximum */
86306 #ifdef CONFIG_LOCKUP_DETECTOR
86307-static int sixty = 60;
86308+static int sixty __read_only = 60;
86309 #endif
86310
86311-static int zero;
86312-static int __maybe_unused one = 1;
86313-static int __maybe_unused two = 2;
86314-static int __maybe_unused three = 3;
86315-static unsigned long one_ul = 1;
86316-static int one_hundred = 100;
86317+static int neg_one __read_only = -1;
86318+static int zero __read_only = 0;
86319+static int __maybe_unused one __read_only = 1;
86320+static int __maybe_unused two __read_only = 2;
86321+static int __maybe_unused three __read_only = 3;
86322+static unsigned long one_ul __read_only = 1;
86323+static int one_hundred __read_only = 100;
86324 #ifdef CONFIG_PRINTK
86325-static int ten_thousand = 10000;
86326+static int ten_thousand __read_only = 10000;
86327 #endif
86328
86329 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
86330@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
86331 void __user *buffer, size_t *lenp, loff_t *ppos);
86332 #endif
86333
86334-#ifdef CONFIG_PRINTK
86335 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
86336 void __user *buffer, size_t *lenp, loff_t *ppos);
86337-#endif
86338
86339 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
86340 void __user *buffer, size_t *lenp, loff_t *ppos);
86341@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
86342
86343 #endif
86344
86345+extern struct ctl_table grsecurity_table[];
86346+
86347 static struct ctl_table kern_table[];
86348 static struct ctl_table vm_table[];
86349 static struct ctl_table fs_table[];
86350@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
86351 int sysctl_legacy_va_layout;
86352 #endif
86353
86354+#ifdef CONFIG_PAX_SOFTMODE
86355+static ctl_table pax_table[] = {
86356+ {
86357+ .procname = "softmode",
86358+ .data = &pax_softmode,
86359+ .maxlen = sizeof(unsigned int),
86360+ .mode = 0600,
86361+ .proc_handler = &proc_dointvec,
86362+ },
86363+
86364+ { }
86365+};
86366+#endif
86367+
86368 /* The default sysctl tables: */
86369
86370 static struct ctl_table sysctl_base_table[] = {
86371@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
86372 #endif
86373
86374 static struct ctl_table kern_table[] = {
86375+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
86376+ {
86377+ .procname = "grsecurity",
86378+ .mode = 0500,
86379+ .child = grsecurity_table,
86380+ },
86381+#endif
86382+
86383+#ifdef CONFIG_PAX_SOFTMODE
86384+ {
86385+ .procname = "pax",
86386+ .mode = 0500,
86387+ .child = pax_table,
86388+ },
86389+#endif
86390+
86391 {
86392 .procname = "sched_child_runs_first",
86393 .data = &sysctl_sched_child_runs_first,
86394@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
86395 .data = &modprobe_path,
86396 .maxlen = KMOD_PATH_LEN,
86397 .mode = 0644,
86398- .proc_handler = proc_dostring,
86399+ .proc_handler = proc_dostring_modpriv,
86400 },
86401 {
86402 .procname = "modules_disabled",
86403@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
86404 .extra1 = &zero,
86405 .extra2 = &one,
86406 },
86407+#endif
86408 {
86409 .procname = "kptr_restrict",
86410 .data = &kptr_restrict,
86411 .maxlen = sizeof(int),
86412 .mode = 0644,
86413 .proc_handler = proc_dointvec_minmax_sysadmin,
86414+#ifdef CONFIG_GRKERNSEC_HIDESYM
86415+ .extra1 = &two,
86416+#else
86417 .extra1 = &zero,
86418+#endif
86419 .extra2 = &two,
86420 },
86421-#endif
86422 {
86423 .procname = "ngroups_max",
86424 .data = &ngroups_max,
86425@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
86426 */
86427 {
86428 .procname = "perf_event_paranoid",
86429- .data = &sysctl_perf_event_paranoid,
86430- .maxlen = sizeof(sysctl_perf_event_paranoid),
86431+ .data = &sysctl_perf_event_legitimately_concerned,
86432+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
86433 .mode = 0644,
86434- .proc_handler = proc_dointvec,
86435+ /* go ahead, be a hero */
86436+ .proc_handler = proc_dointvec_minmax_sysadmin,
86437+ .extra1 = &neg_one,
86438+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86439+ .extra2 = &three,
86440+#else
86441+ .extra2 = &two,
86442+#endif
86443 },
86444 {
86445 .procname = "perf_event_mlock_kb",
86446@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
86447 .proc_handler = proc_dointvec_minmax,
86448 .extra1 = &zero,
86449 },
86450+ {
86451+ .procname = "heap_stack_gap",
86452+ .data = &sysctl_heap_stack_gap,
86453+ .maxlen = sizeof(sysctl_heap_stack_gap),
86454+ .mode = 0644,
86455+ .proc_handler = proc_doulongvec_minmax,
86456+ },
86457 #else
86458 {
86459 .procname = "nr_trim_pages",
86460@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
86461 buffer, lenp, ppos);
86462 }
86463
86464+int proc_dostring_modpriv(struct ctl_table *table, int write,
86465+ void __user *buffer, size_t *lenp, loff_t *ppos)
86466+{
86467+ if (write && !capable(CAP_SYS_MODULE))
86468+ return -EPERM;
86469+
86470+ return _proc_do_string(table->data, table->maxlen, write,
86471+ buffer, lenp, ppos);
86472+}
86473+
86474 static size_t proc_skip_spaces(char **buf)
86475 {
86476 size_t ret;
86477@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
86478 len = strlen(tmp);
86479 if (len > *size)
86480 len = *size;
86481+ if (len > sizeof(tmp))
86482+ len = sizeof(tmp);
86483 if (copy_to_user(*buf, tmp, len))
86484 return -EFAULT;
86485 *size -= len;
86486@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
86487 static int proc_taint(struct ctl_table *table, int write,
86488 void __user *buffer, size_t *lenp, loff_t *ppos)
86489 {
86490- struct ctl_table t;
86491+ ctl_table_no_const t;
86492 unsigned long tmptaint = get_taint();
86493 int err;
86494
86495@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
86496 return err;
86497 }
86498
86499-#ifdef CONFIG_PRINTK
86500 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
86501 void __user *buffer, size_t *lenp, loff_t *ppos)
86502 {
86503@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
86504
86505 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
86506 }
86507-#endif
86508
86509 struct do_proc_dointvec_minmax_conv_param {
86510 int *min;
86511@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
86512 *i = val;
86513 } else {
86514 val = convdiv * (*i) / convmul;
86515- if (!first)
86516+ if (!first) {
86517 err = proc_put_char(&buffer, &left, '\t');
86518+ if (err)
86519+ break;
86520+ }
86521 err = proc_put_long(&buffer, &left, val, false);
86522 if (err)
86523 break;
86524@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
86525 return -ENOSYS;
86526 }
86527
86528+int proc_dostring_modpriv(struct ctl_table *table, int write,
86529+ void __user *buffer, size_t *lenp, loff_t *ppos)
86530+{
86531+ return -ENOSYS;
86532+}
86533+
86534 int proc_dointvec(struct ctl_table *table, int write,
86535 void __user *buffer, size_t *lenp, loff_t *ppos)
86536 {
86537@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
86538 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
86539 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
86540 EXPORT_SYMBOL(proc_dostring);
86541+EXPORT_SYMBOL(proc_dostring_modpriv);
86542 EXPORT_SYMBOL(proc_doulongvec_minmax);
86543 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
86544diff --git a/kernel/taskstats.c b/kernel/taskstats.c
86545index 145bb4d..b2aa969 100644
86546--- a/kernel/taskstats.c
86547+++ b/kernel/taskstats.c
86548@@ -28,9 +28,12 @@
86549 #include <linux/fs.h>
86550 #include <linux/file.h>
86551 #include <linux/pid_namespace.h>
86552+#include <linux/grsecurity.h>
86553 #include <net/genetlink.h>
86554 #include <linux/atomic.h>
86555
86556+extern int gr_is_taskstats_denied(int pid);
86557+
86558 /*
86559 * Maximum length of a cpumask that can be specified in
86560 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
86561@@ -570,6 +573,9 @@ err:
86562
86563 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
86564 {
86565+ if (gr_is_taskstats_denied(current->pid))
86566+ return -EACCES;
86567+
86568 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
86569 return cmd_attr_register_cpumask(info);
86570 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
86571diff --git a/kernel/time.c b/kernel/time.c
86572index 7c7964c..2a0d412 100644
86573--- a/kernel/time.c
86574+++ b/kernel/time.c
86575@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
86576 return error;
86577
86578 if (tz) {
86579+ /* we log in do_settimeofday called below, so don't log twice
86580+ */
86581+ if (!tv)
86582+ gr_log_timechange();
86583+
86584 sys_tz = *tz;
86585 update_vsyscall_tz();
86586 if (firsttime) {
86587diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
86588index 88c9c65..7497ebc 100644
86589--- a/kernel/time/alarmtimer.c
86590+++ b/kernel/time/alarmtimer.c
86591@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
86592 struct platform_device *pdev;
86593 int error = 0;
86594 int i;
86595- struct k_clock alarm_clock = {
86596+ static struct k_clock alarm_clock = {
86597 .clock_getres = alarm_clock_getres,
86598 .clock_get = alarm_clock_get,
86599 .timer_create = alarm_timer_create,
86600diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
86601index 5cf6c70..ac341b0 100644
86602--- a/kernel/time/timekeeping.c
86603+++ b/kernel/time/timekeeping.c
86604@@ -15,6 +15,7 @@
86605 #include <linux/init.h>
86606 #include <linux/mm.h>
86607 #include <linux/sched.h>
86608+#include <linux/grsecurity.h>
86609 #include <linux/syscore_ops.h>
86610 #include <linux/clocksource.h>
86611 #include <linux/jiffies.h>
86612@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
86613 if (!timespec_valid_strict(tv))
86614 return -EINVAL;
86615
86616+ gr_log_timechange();
86617+
86618 raw_spin_lock_irqsave(&timekeeper_lock, flags);
86619 write_seqcount_begin(&timekeeper_seq);
86620
86621diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
86622index 61ed862..3b52c65 100644
86623--- a/kernel/time/timer_list.c
86624+++ b/kernel/time/timer_list.c
86625@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
86626
86627 static void print_name_offset(struct seq_file *m, void *sym)
86628 {
86629+#ifdef CONFIG_GRKERNSEC_HIDESYM
86630+ SEQ_printf(m, "<%p>", NULL);
86631+#else
86632 char symname[KSYM_NAME_LEN];
86633
86634 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
86635 SEQ_printf(m, "<%pK>", sym);
86636 else
86637 SEQ_printf(m, "%s", symname);
86638+#endif
86639 }
86640
86641 static void
86642@@ -119,7 +123,11 @@ next_one:
86643 static void
86644 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
86645 {
86646+#ifdef CONFIG_GRKERNSEC_HIDESYM
86647+ SEQ_printf(m, " .base: %p\n", NULL);
86648+#else
86649 SEQ_printf(m, " .base: %pK\n", base);
86650+#endif
86651 SEQ_printf(m, " .index: %d\n",
86652 base->index);
86653 SEQ_printf(m, " .resolution: %Lu nsecs\n",
86654@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
86655 {
86656 struct proc_dir_entry *pe;
86657
86658+#ifdef CONFIG_GRKERNSEC_PROC_ADD
86659+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
86660+#else
86661 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
86662+#endif
86663 if (!pe)
86664 return -ENOMEM;
86665 return 0;
86666diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
86667index 0b537f2..40d6c20 100644
86668--- a/kernel/time/timer_stats.c
86669+++ b/kernel/time/timer_stats.c
86670@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
86671 static unsigned long nr_entries;
86672 static struct entry entries[MAX_ENTRIES];
86673
86674-static atomic_t overflow_count;
86675+static atomic_unchecked_t overflow_count;
86676
86677 /*
86678 * The entries are in a hash-table, for fast lookup:
86679@@ -140,7 +140,7 @@ static void reset_entries(void)
86680 nr_entries = 0;
86681 memset(entries, 0, sizeof(entries));
86682 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
86683- atomic_set(&overflow_count, 0);
86684+ atomic_set_unchecked(&overflow_count, 0);
86685 }
86686
86687 static struct entry *alloc_entry(void)
86688@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
86689 if (likely(entry))
86690 entry->count++;
86691 else
86692- atomic_inc(&overflow_count);
86693+ atomic_inc_unchecked(&overflow_count);
86694
86695 out_unlock:
86696 raw_spin_unlock_irqrestore(lock, flags);
86697@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
86698
86699 static void print_name_offset(struct seq_file *m, unsigned long addr)
86700 {
86701+#ifdef CONFIG_GRKERNSEC_HIDESYM
86702+ seq_printf(m, "<%p>", NULL);
86703+#else
86704 char symname[KSYM_NAME_LEN];
86705
86706 if (lookup_symbol_name(addr, symname) < 0)
86707- seq_printf(m, "<%p>", (void *)addr);
86708+ seq_printf(m, "<%pK>", (void *)addr);
86709 else
86710 seq_printf(m, "%s", symname);
86711+#endif
86712 }
86713
86714 static int tstats_show(struct seq_file *m, void *v)
86715@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
86716
86717 seq_puts(m, "Timer Stats Version: v0.2\n");
86718 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
86719- if (atomic_read(&overflow_count))
86720+ if (atomic_read_unchecked(&overflow_count))
86721 seq_printf(m, "Overflow: %d entries\n",
86722- atomic_read(&overflow_count));
86723+ atomic_read_unchecked(&overflow_count));
86724
86725 for (i = 0; i < nr_entries; i++) {
86726 entry = entries + i;
86727@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
86728 {
86729 struct proc_dir_entry *pe;
86730
86731+#ifdef CONFIG_GRKERNSEC_PROC_ADD
86732+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
86733+#else
86734 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
86735+#endif
86736 if (!pe)
86737 return -ENOMEM;
86738 return 0;
86739diff --git a/kernel/timer.c b/kernel/timer.c
86740index 4296d13..0164b04 100644
86741--- a/kernel/timer.c
86742+++ b/kernel/timer.c
86743@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
86744 /*
86745 * This function runs timers and the timer-tq in bottom half context.
86746 */
86747-static void run_timer_softirq(struct softirq_action *h)
86748+static __latent_entropy void run_timer_softirq(void)
86749 {
86750 struct tvec_base *base = __this_cpu_read(tvec_bases);
86751
86752@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
86753 *
86754 * In all cases the return value is guaranteed to be non-negative.
86755 */
86756-signed long __sched schedule_timeout(signed long timeout)
86757+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
86758 {
86759 struct timer_list timer;
86760 unsigned long expire;
86761diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
86762index b8b8560..75b1a09 100644
86763--- a/kernel/trace/blktrace.c
86764+++ b/kernel/trace/blktrace.c
86765@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
86766 struct blk_trace *bt = filp->private_data;
86767 char buf[16];
86768
86769- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
86770+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
86771
86772 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
86773 }
86774@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
86775 return 1;
86776
86777 bt = buf->chan->private_data;
86778- atomic_inc(&bt->dropped);
86779+ atomic_inc_unchecked(&bt->dropped);
86780 return 0;
86781 }
86782
86783@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
86784
86785 bt->dir = dir;
86786 bt->dev = dev;
86787- atomic_set(&bt->dropped, 0);
86788+ atomic_set_unchecked(&bt->dropped, 0);
86789
86790 ret = -EIO;
86791 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
86792diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
86793index f3bd09ee..9bb9586 100644
86794--- a/kernel/trace/ftrace.c
86795+++ b/kernel/trace/ftrace.c
86796@@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
86797 if (unlikely(ftrace_disabled))
86798 return 0;
86799
86800+ ret = ftrace_arch_code_modify_prepare();
86801+ FTRACE_WARN_ON(ret);
86802+ if (ret)
86803+ return 0;
86804+
86805 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
86806+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
86807 if (ret) {
86808 ftrace_bug(ret, ip);
86809- return 0;
86810 }
86811- return 1;
86812+ return ret ? 0 : 1;
86813 }
86814
86815 /*
86816@@ -4043,8 +4048,10 @@ static int ftrace_process_locs(struct module *mod,
86817 if (!count)
86818 return 0;
86819
86820+ pax_open_kernel();
86821 sort(start, count, sizeof(*start),
86822 ftrace_cmp_ips, ftrace_swap_ips);
86823+ pax_close_kernel();
86824
86825 start_pg = ftrace_allocate_pages(count);
86826 if (!start_pg)
86827@@ -4766,8 +4773,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
86828 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
86829
86830 static int ftrace_graph_active;
86831-static struct notifier_block ftrace_suspend_notifier;
86832-
86833 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
86834 {
86835 return 0;
86836@@ -4918,6 +4923,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
86837 FTRACE_OPS_FL_RECURSION_SAFE,
86838 };
86839
86840+static struct notifier_block ftrace_suspend_notifier = {
86841+ .notifier_call = ftrace_suspend_notifier_call
86842+};
86843+
86844 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
86845 trace_func_graph_ent_t entryfunc)
86846 {
86847@@ -4931,7 +4940,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
86848 goto out;
86849 }
86850
86851- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
86852 register_pm_notifier(&ftrace_suspend_notifier);
86853
86854 ftrace_graph_active++;
86855diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
86856index cc2f66f..05edd54 100644
86857--- a/kernel/trace/ring_buffer.c
86858+++ b/kernel/trace/ring_buffer.c
86859@@ -352,9 +352,9 @@ struct buffer_data_page {
86860 */
86861 struct buffer_page {
86862 struct list_head list; /* list of buffer pages */
86863- local_t write; /* index for next write */
86864+ local_unchecked_t write; /* index for next write */
86865 unsigned read; /* index for next read */
86866- local_t entries; /* entries on this page */
86867+ local_unchecked_t entries; /* entries on this page */
86868 unsigned long real_end; /* real end of data */
86869 struct buffer_data_page *page; /* Actual data page */
86870 };
86871@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
86872 unsigned long last_overrun;
86873 local_t entries_bytes;
86874 local_t entries;
86875- local_t overrun;
86876- local_t commit_overrun;
86877+ local_unchecked_t overrun;
86878+ local_unchecked_t commit_overrun;
86879 local_t dropped_events;
86880 local_t committing;
86881 local_t commits;
86882@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86883 *
86884 * We add a counter to the write field to denote this.
86885 */
86886- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
86887- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
86888+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
86889+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
86890
86891 /*
86892 * Just make sure we have seen our old_write and synchronize
86893@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86894 * cmpxchg to only update if an interrupt did not already
86895 * do it for us. If the cmpxchg fails, we don't care.
86896 */
86897- (void)local_cmpxchg(&next_page->write, old_write, val);
86898- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
86899+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
86900+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
86901
86902 /*
86903 * No need to worry about races with clearing out the commit.
86904@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
86905
86906 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
86907 {
86908- return local_read(&bpage->entries) & RB_WRITE_MASK;
86909+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
86910 }
86911
86912 static inline unsigned long rb_page_write(struct buffer_page *bpage)
86913 {
86914- return local_read(&bpage->write) & RB_WRITE_MASK;
86915+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
86916 }
86917
86918 static int
86919@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
86920 * bytes consumed in ring buffer from here.
86921 * Increment overrun to account for the lost events.
86922 */
86923- local_add(page_entries, &cpu_buffer->overrun);
86924+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
86925 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86926 }
86927
86928@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
86929 * it is our responsibility to update
86930 * the counters.
86931 */
86932- local_add(entries, &cpu_buffer->overrun);
86933+ local_add_unchecked(entries, &cpu_buffer->overrun);
86934 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86935
86936 /*
86937@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86938 if (tail == BUF_PAGE_SIZE)
86939 tail_page->real_end = 0;
86940
86941- local_sub(length, &tail_page->write);
86942+ local_sub_unchecked(length, &tail_page->write);
86943 return;
86944 }
86945
86946@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86947 rb_event_set_padding(event);
86948
86949 /* Set the write back to the previous setting */
86950- local_sub(length, &tail_page->write);
86951+ local_sub_unchecked(length, &tail_page->write);
86952 return;
86953 }
86954
86955@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86956
86957 /* Set write to end of buffer */
86958 length = (tail + length) - BUF_PAGE_SIZE;
86959- local_sub(length, &tail_page->write);
86960+ local_sub_unchecked(length, &tail_page->write);
86961 }
86962
86963 /*
86964@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86965 * about it.
86966 */
86967 if (unlikely(next_page == commit_page)) {
86968- local_inc(&cpu_buffer->commit_overrun);
86969+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86970 goto out_reset;
86971 }
86972
86973@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86974 cpu_buffer->tail_page) &&
86975 (cpu_buffer->commit_page ==
86976 cpu_buffer->reader_page))) {
86977- local_inc(&cpu_buffer->commit_overrun);
86978+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86979 goto out_reset;
86980 }
86981 }
86982@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86983 length += RB_LEN_TIME_EXTEND;
86984
86985 tail_page = cpu_buffer->tail_page;
86986- write = local_add_return(length, &tail_page->write);
86987+ write = local_add_return_unchecked(length, &tail_page->write);
86988
86989 /* set write to only the index of the write */
86990 write &= RB_WRITE_MASK;
86991@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86992 kmemcheck_annotate_bitfield(event, bitfield);
86993 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
86994
86995- local_inc(&tail_page->entries);
86996+ local_inc_unchecked(&tail_page->entries);
86997
86998 /*
86999 * If this is the first commit on the page, then update
87000@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
87001
87002 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
87003 unsigned long write_mask =
87004- local_read(&bpage->write) & ~RB_WRITE_MASK;
87005+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
87006 unsigned long event_length = rb_event_length(event);
87007 /*
87008 * This is on the tail page. It is possible that
87009@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
87010 */
87011 old_index += write_mask;
87012 new_index += write_mask;
87013- index = local_cmpxchg(&bpage->write, old_index, new_index);
87014+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
87015 if (index == old_index) {
87016 /* update counters */
87017 local_sub(event_length, &cpu_buffer->entries_bytes);
87018@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
87019
87020 /* Do the likely case first */
87021 if (likely(bpage->page == (void *)addr)) {
87022- local_dec(&bpage->entries);
87023+ local_dec_unchecked(&bpage->entries);
87024 return;
87025 }
87026
87027@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
87028 start = bpage;
87029 do {
87030 if (bpage->page == (void *)addr) {
87031- local_dec(&bpage->entries);
87032+ local_dec_unchecked(&bpage->entries);
87033 return;
87034 }
87035 rb_inc_page(cpu_buffer, &bpage);
87036@@ -3139,7 +3139,7 @@ static inline unsigned long
87037 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
87038 {
87039 return local_read(&cpu_buffer->entries) -
87040- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
87041+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
87042 }
87043
87044 /**
87045@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
87046 return 0;
87047
87048 cpu_buffer = buffer->buffers[cpu];
87049- ret = local_read(&cpu_buffer->overrun);
87050+ ret = local_read_unchecked(&cpu_buffer->overrun);
87051
87052 return ret;
87053 }
87054@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
87055 return 0;
87056
87057 cpu_buffer = buffer->buffers[cpu];
87058- ret = local_read(&cpu_buffer->commit_overrun);
87059+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
87060
87061 return ret;
87062 }
87063@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
87064 /* if you care about this being correct, lock the buffer */
87065 for_each_buffer_cpu(buffer, cpu) {
87066 cpu_buffer = buffer->buffers[cpu];
87067- overruns += local_read(&cpu_buffer->overrun);
87068+ overruns += local_read_unchecked(&cpu_buffer->overrun);
87069 }
87070
87071 return overruns;
87072@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
87073 /*
87074 * Reset the reader page to size zero.
87075 */
87076- local_set(&cpu_buffer->reader_page->write, 0);
87077- local_set(&cpu_buffer->reader_page->entries, 0);
87078+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
87079+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
87080 local_set(&cpu_buffer->reader_page->page->commit, 0);
87081 cpu_buffer->reader_page->real_end = 0;
87082
87083@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
87084 * want to compare with the last_overrun.
87085 */
87086 smp_mb();
87087- overwrite = local_read(&(cpu_buffer->overrun));
87088+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
87089
87090 /*
87091 * Here's the tricky part.
87092@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
87093
87094 cpu_buffer->head_page
87095 = list_entry(cpu_buffer->pages, struct buffer_page, list);
87096- local_set(&cpu_buffer->head_page->write, 0);
87097- local_set(&cpu_buffer->head_page->entries, 0);
87098+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
87099+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
87100 local_set(&cpu_buffer->head_page->page->commit, 0);
87101
87102 cpu_buffer->head_page->read = 0;
87103@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
87104
87105 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
87106 INIT_LIST_HEAD(&cpu_buffer->new_pages);
87107- local_set(&cpu_buffer->reader_page->write, 0);
87108- local_set(&cpu_buffer->reader_page->entries, 0);
87109+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
87110+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
87111 local_set(&cpu_buffer->reader_page->page->commit, 0);
87112 cpu_buffer->reader_page->read = 0;
87113
87114 local_set(&cpu_buffer->entries_bytes, 0);
87115- local_set(&cpu_buffer->overrun, 0);
87116- local_set(&cpu_buffer->commit_overrun, 0);
87117+ local_set_unchecked(&cpu_buffer->overrun, 0);
87118+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
87119 local_set(&cpu_buffer->dropped_events, 0);
87120 local_set(&cpu_buffer->entries, 0);
87121 local_set(&cpu_buffer->committing, 0);
87122@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
87123 rb_init_page(bpage);
87124 bpage = reader->page;
87125 reader->page = *data_page;
87126- local_set(&reader->write, 0);
87127- local_set(&reader->entries, 0);
87128+ local_set_unchecked(&reader->write, 0);
87129+ local_set_unchecked(&reader->entries, 0);
87130 reader->read = 0;
87131 *data_page = bpage;
87132
87133diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
87134index b778e96..4e84621 100644
87135--- a/kernel/trace/trace.c
87136+++ b/kernel/trace/trace.c
87137@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
87138 return 0;
87139 }
87140
87141-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
87142+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
87143 {
87144 /* do nothing if flag is already set */
87145 if (!!(trace_flags & mask) == !!enabled)
87146diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
87147index 10c86fb..645ab0a 100644
87148--- a/kernel/trace/trace.h
87149+++ b/kernel/trace/trace.h
87150@@ -1029,7 +1029,7 @@ extern const char *__stop___tracepoint_str[];
87151 void trace_printk_init_buffers(void);
87152 void trace_printk_start_comm(void);
87153 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
87154-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
87155+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
87156
87157 /*
87158 * Normal trace_printk() and friends allocates special buffers
87159diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
87160index 26dc348..8708ca7 100644
87161--- a/kernel/trace/trace_clock.c
87162+++ b/kernel/trace/trace_clock.c
87163@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
87164 return now;
87165 }
87166
87167-static atomic64_t trace_counter;
87168+static atomic64_unchecked_t trace_counter;
87169
87170 /*
87171 * trace_clock_counter(): simply an atomic counter.
87172@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
87173 */
87174 u64 notrace trace_clock_counter(void)
87175 {
87176- return atomic64_add_return(1, &trace_counter);
87177+ return atomic64_inc_return_unchecked(&trace_counter);
87178 }
87179diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
87180index 368a4d5..7b6d1d5 100644
87181--- a/kernel/trace/trace_events.c
87182+++ b/kernel/trace/trace_events.c
87183@@ -1673,7 +1673,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
87184 return 0;
87185 }
87186
87187-struct ftrace_module_file_ops;
87188 static void __add_event_to_tracers(struct ftrace_event_call *call);
87189
87190 /* Add an additional event_call dynamically */
87191diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
87192index b3dcfb2..ebee344 100644
87193--- a/kernel/trace/trace_mmiotrace.c
87194+++ b/kernel/trace/trace_mmiotrace.c
87195@@ -24,7 +24,7 @@ struct header_iter {
87196 static struct trace_array *mmio_trace_array;
87197 static bool overrun_detected;
87198 static unsigned long prev_overruns;
87199-static atomic_t dropped_count;
87200+static atomic_unchecked_t dropped_count;
87201
87202 static void mmio_reset_data(struct trace_array *tr)
87203 {
87204@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
87205
87206 static unsigned long count_overruns(struct trace_iterator *iter)
87207 {
87208- unsigned long cnt = atomic_xchg(&dropped_count, 0);
87209+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
87210 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
87211
87212 if (over > prev_overruns)
87213@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
87214 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
87215 sizeof(*entry), 0, pc);
87216 if (!event) {
87217- atomic_inc(&dropped_count);
87218+ atomic_inc_unchecked(&dropped_count);
87219 return;
87220 }
87221 entry = ring_buffer_event_data(event);
87222@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
87223 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
87224 sizeof(*entry), 0, pc);
87225 if (!event) {
87226- atomic_inc(&dropped_count);
87227+ atomic_inc_unchecked(&dropped_count);
87228 return;
87229 }
87230 entry = ring_buffer_event_data(event);
87231diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
87232index 34e7cba..6f9a729 100644
87233--- a/kernel/trace/trace_output.c
87234+++ b/kernel/trace/trace_output.c
87235@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
87236
87237 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
87238 if (!IS_ERR(p)) {
87239- p = mangle_path(s->buffer + s->len, p, "\n");
87240+ p = mangle_path(s->buffer + s->len, p, "\n\\");
87241 if (p) {
87242 s->len = p - s->buffer;
87243 return 1;
87244@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
87245 goto out;
87246 }
87247
87248+ pax_open_kernel();
87249 if (event->funcs->trace == NULL)
87250- event->funcs->trace = trace_nop_print;
87251+ *(void **)&event->funcs->trace = trace_nop_print;
87252 if (event->funcs->raw == NULL)
87253- event->funcs->raw = trace_nop_print;
87254+ *(void **)&event->funcs->raw = trace_nop_print;
87255 if (event->funcs->hex == NULL)
87256- event->funcs->hex = trace_nop_print;
87257+ *(void **)&event->funcs->hex = trace_nop_print;
87258 if (event->funcs->binary == NULL)
87259- event->funcs->binary = trace_nop_print;
87260+ *(void **)&event->funcs->binary = trace_nop_print;
87261+ pax_close_kernel();
87262
87263 key = event->type & (EVENT_HASHSIZE - 1);
87264
87265diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
87266index b20428c..4845a10 100644
87267--- a/kernel/trace/trace_stack.c
87268+++ b/kernel/trace/trace_stack.c
87269@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
87270 return;
87271
87272 /* we do not handle interrupt stacks yet */
87273- if (!object_is_on_stack(stack))
87274+ if (!object_starts_on_stack(stack))
87275 return;
87276
87277 local_irq_save(flags);
87278diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
87279index 13fb113..a6ced3f 100644
87280--- a/kernel/user_namespace.c
87281+++ b/kernel/user_namespace.c
87282@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
87283 !kgid_has_mapping(parent_ns, group))
87284 return -EPERM;
87285
87286+#ifdef CONFIG_GRKERNSEC
87287+ /*
87288+ * This doesn't really inspire confidence:
87289+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
87290+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
87291+ * Increases kernel attack surface in areas developers
87292+ * previously cared little about ("low importance due
87293+ * to requiring "root" capability")
87294+ * To be removed when this code receives *proper* review
87295+ */
87296+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
87297+ !capable(CAP_SETGID))
87298+ return -EPERM;
87299+#endif
87300+
87301 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
87302 if (!ns)
87303 return -ENOMEM;
87304@@ -860,7 +875,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
87305 if (atomic_read(&current->mm->mm_users) > 1)
87306 return -EINVAL;
87307
87308- if (current->fs->users != 1)
87309+ if (atomic_read(&current->fs->users) != 1)
87310 return -EINVAL;
87311
87312 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
87313diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
87314index 4f69f9a..7c6f8f8 100644
87315--- a/kernel/utsname_sysctl.c
87316+++ b/kernel/utsname_sysctl.c
87317@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
87318 static int proc_do_uts_string(ctl_table *table, int write,
87319 void __user *buffer, size_t *lenp, loff_t *ppos)
87320 {
87321- struct ctl_table uts_table;
87322+ ctl_table_no_const uts_table;
87323 int r;
87324 memcpy(&uts_table, table, sizeof(uts_table));
87325 uts_table.data = get_uts(table, write);
87326diff --git a/kernel/watchdog.c b/kernel/watchdog.c
87327index 4431610..4265616 100644
87328--- a/kernel/watchdog.c
87329+++ b/kernel/watchdog.c
87330@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
87331 static void watchdog_nmi_disable(unsigned int cpu) { return; }
87332 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
87333
87334-static struct smp_hotplug_thread watchdog_threads = {
87335+static struct smp_hotplug_thread watchdog_threads __read_only = {
87336 .store = &softlockup_watchdog,
87337 .thread_should_run = watchdog_should_run,
87338 .thread_fn = watchdog,
87339diff --git a/kernel/workqueue.c b/kernel/workqueue.c
87340index 93c2652..66a1cfd 100644
87341--- a/kernel/workqueue.c
87342+++ b/kernel/workqueue.c
87343@@ -4668,7 +4668,7 @@ static void rebind_workers(struct worker_pool *pool)
87344 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
87345 worker_flags |= WORKER_REBOUND;
87346 worker_flags &= ~WORKER_UNBOUND;
87347- ACCESS_ONCE(worker->flags) = worker_flags;
87348+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
87349 }
87350
87351 spin_unlock_irq(&pool->lock);
87352diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
87353index 094f315..244a824 100644
87354--- a/lib/Kconfig.debug
87355+++ b/lib/Kconfig.debug
87356@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
87357
87358 config DEBUG_WW_MUTEX_SLOWPATH
87359 bool "Wait/wound mutex debugging: Slowpath testing"
87360- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87361+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87362 select DEBUG_LOCK_ALLOC
87363 select DEBUG_SPINLOCK
87364 select DEBUG_MUTEXES
87365@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
87366
87367 config DEBUG_LOCK_ALLOC
87368 bool "Lock debugging: detect incorrect freeing of live locks"
87369- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87370+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87371 select DEBUG_SPINLOCK
87372 select DEBUG_MUTEXES
87373 select LOCKDEP
87374@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
87375
87376 config PROVE_LOCKING
87377 bool "Lock debugging: prove locking correctness"
87378- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87379+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87380 select LOCKDEP
87381 select DEBUG_SPINLOCK
87382 select DEBUG_MUTEXES
87383@@ -914,7 +914,7 @@ config LOCKDEP
87384
87385 config LOCK_STAT
87386 bool "Lock usage statistics"
87387- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87388+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87389 select LOCKDEP
87390 select DEBUG_SPINLOCK
87391 select DEBUG_MUTEXES
87392@@ -1376,6 +1376,7 @@ config LATENCYTOP
87393 depends on DEBUG_KERNEL
87394 depends on STACKTRACE_SUPPORT
87395 depends on PROC_FS
87396+ depends on !GRKERNSEC_HIDESYM
87397 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
87398 select KALLSYMS
87399 select KALLSYMS_ALL
87400@@ -1392,7 +1393,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
87401 config DEBUG_STRICT_USER_COPY_CHECKS
87402 bool "Strict user copy size checks"
87403 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
87404- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
87405+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
87406 help
87407 Enabling this option turns a certain set of sanity checks for user
87408 copy operations into compile time failures.
87409@@ -1502,7 +1503,7 @@ endmenu # runtime tests
87410
87411 config PROVIDE_OHCI1394_DMA_INIT
87412 bool "Remote debugging over FireWire early on boot"
87413- depends on PCI && X86
87414+ depends on PCI && X86 && !GRKERNSEC
87415 help
87416 If you want to debug problems which hang or crash the kernel early
87417 on boot and the crashing machine has a FireWire port, you can use
87418@@ -1531,7 +1532,7 @@ config PROVIDE_OHCI1394_DMA_INIT
87419
87420 config FIREWIRE_OHCI_REMOTE_DMA
87421 bool "Remote debugging over FireWire with firewire-ohci"
87422- depends on FIREWIRE_OHCI
87423+ depends on FIREWIRE_OHCI && !GRKERNSEC
87424 help
87425 This option lets you use the FireWire bus for remote debugging
87426 with help of the firewire-ohci driver. It enables unfiltered
87427diff --git a/lib/Makefile b/lib/Makefile
87428index f3bb2cb..b358ace 100644
87429--- a/lib/Makefile
87430+++ b/lib/Makefile
87431@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
87432
87433 obj-$(CONFIG_BTREE) += btree.o
87434 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
87435-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
87436+obj-y += list_debug.o
87437 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
87438
87439 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
87440diff --git a/lib/bitmap.c b/lib/bitmap.c
87441index 06f7e4f..f3cf2b0 100644
87442--- a/lib/bitmap.c
87443+++ b/lib/bitmap.c
87444@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
87445 {
87446 int c, old_c, totaldigits, ndigits, nchunks, nbits;
87447 u32 chunk;
87448- const char __user __force *ubuf = (const char __user __force *)buf;
87449+ const char __user *ubuf = (const char __force_user *)buf;
87450
87451 bitmap_zero(maskp, nmaskbits);
87452
87453@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
87454 {
87455 if (!access_ok(VERIFY_READ, ubuf, ulen))
87456 return -EFAULT;
87457- return __bitmap_parse((const char __force *)ubuf,
87458+ return __bitmap_parse((const char __force_kernel *)ubuf,
87459 ulen, 1, maskp, nmaskbits);
87460
87461 }
87462@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
87463 {
87464 unsigned a, b;
87465 int c, old_c, totaldigits;
87466- const char __user __force *ubuf = (const char __user __force *)buf;
87467+ const char __user *ubuf = (const char __force_user *)buf;
87468 int exp_digit, in_range;
87469
87470 totaldigits = c = 0;
87471@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
87472 {
87473 if (!access_ok(VERIFY_READ, ubuf, ulen))
87474 return -EFAULT;
87475- return __bitmap_parselist((const char __force *)ubuf,
87476+ return __bitmap_parselist((const char __force_kernel *)ubuf,
87477 ulen, 1, maskp, nmaskbits);
87478 }
87479 EXPORT_SYMBOL(bitmap_parselist_user);
87480diff --git a/lib/bug.c b/lib/bug.c
87481index 1686034..a9c00c8 100644
87482--- a/lib/bug.c
87483+++ b/lib/bug.c
87484@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
87485 return BUG_TRAP_TYPE_NONE;
87486
87487 bug = find_bug(bugaddr);
87488+ if (!bug)
87489+ return BUG_TRAP_TYPE_NONE;
87490
87491 file = NULL;
87492 line = 0;
87493diff --git a/lib/debugobjects.c b/lib/debugobjects.c
87494index bf2c8b1..1d00ccf 100644
87495--- a/lib/debugobjects.c
87496+++ b/lib/debugobjects.c
87497@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
87498 if (limit > 4)
87499 return;
87500
87501- is_on_stack = object_is_on_stack(addr);
87502+ is_on_stack = object_starts_on_stack(addr);
87503 if (is_on_stack == onstack)
87504 return;
87505
87506diff --git a/lib/devres.c b/lib/devres.c
87507index 8235331..5881053 100644
87508--- a/lib/devres.c
87509+++ b/lib/devres.c
87510@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
87511 void devm_iounmap(struct device *dev, void __iomem *addr)
87512 {
87513 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
87514- (void *)addr));
87515+ (void __force *)addr));
87516 iounmap(addr);
87517 }
87518 EXPORT_SYMBOL(devm_iounmap);
87519@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
87520 {
87521 ioport_unmap(addr);
87522 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
87523- devm_ioport_map_match, (void *)addr));
87524+ devm_ioport_map_match, (void __force *)addr));
87525 }
87526 EXPORT_SYMBOL(devm_ioport_unmap);
87527 #endif /* CONFIG_HAS_IOPORT */
87528diff --git a/lib/div64.c b/lib/div64.c
87529index 4382ad7..08aa558 100644
87530--- a/lib/div64.c
87531+++ b/lib/div64.c
87532@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
87533 EXPORT_SYMBOL(__div64_32);
87534
87535 #ifndef div_s64_rem
87536-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
87537+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
87538 {
87539 u64 quotient;
87540
87541@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
87542 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
87543 */
87544 #ifndef div64_u64
87545-u64 div64_u64(u64 dividend, u64 divisor)
87546+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
87547 {
87548 u32 high = divisor >> 32;
87549 u64 quot;
87550diff --git a/lib/dma-debug.c b/lib/dma-debug.c
87551index d87a17a..ac0d79a 100644
87552--- a/lib/dma-debug.c
87553+++ b/lib/dma-debug.c
87554@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
87555
87556 void dma_debug_add_bus(struct bus_type *bus)
87557 {
87558- struct notifier_block *nb;
87559+ notifier_block_no_const *nb;
87560
87561 if (global_disable)
87562 return;
87563@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
87564
87565 static void check_for_stack(struct device *dev, void *addr)
87566 {
87567- if (object_is_on_stack(addr))
87568+ if (object_starts_on_stack(addr))
87569 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
87570 "stack [addr=%p]\n", addr);
87571 }
87572diff --git a/lib/inflate.c b/lib/inflate.c
87573index 013a761..c28f3fc 100644
87574--- a/lib/inflate.c
87575+++ b/lib/inflate.c
87576@@ -269,7 +269,7 @@ static void free(void *where)
87577 malloc_ptr = free_mem_ptr;
87578 }
87579 #else
87580-#define malloc(a) kmalloc(a, GFP_KERNEL)
87581+#define malloc(a) kmalloc((a), GFP_KERNEL)
87582 #define free(a) kfree(a)
87583 #endif
87584
87585diff --git a/lib/ioremap.c b/lib/ioremap.c
87586index 0c9216c..863bd89 100644
87587--- a/lib/ioremap.c
87588+++ b/lib/ioremap.c
87589@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
87590 unsigned long next;
87591
87592 phys_addr -= addr;
87593- pmd = pmd_alloc(&init_mm, pud, addr);
87594+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
87595 if (!pmd)
87596 return -ENOMEM;
87597 do {
87598@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
87599 unsigned long next;
87600
87601 phys_addr -= addr;
87602- pud = pud_alloc(&init_mm, pgd, addr);
87603+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
87604 if (!pud)
87605 return -ENOMEM;
87606 do {
87607diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
87608index bd2bea9..6b3c95e 100644
87609--- a/lib/is_single_threaded.c
87610+++ b/lib/is_single_threaded.c
87611@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
87612 struct task_struct *p, *t;
87613 bool ret;
87614
87615+ if (!mm)
87616+ return true;
87617+
87618 if (atomic_read(&task->signal->live) != 1)
87619 return false;
87620
87621diff --git a/lib/kobject.c b/lib/kobject.c
87622index 084f7b1..d265b8a 100644
87623--- a/lib/kobject.c
87624+++ b/lib/kobject.c
87625@@ -875,9 +875,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
87626
87627
87628 static DEFINE_SPINLOCK(kobj_ns_type_lock);
87629-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
87630+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
87631
87632-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
87633+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
87634 {
87635 enum kobj_ns_type type = ops->type;
87636 int error;
87637diff --git a/lib/list_debug.c b/lib/list_debug.c
87638index c24c2f7..f0296f4 100644
87639--- a/lib/list_debug.c
87640+++ b/lib/list_debug.c
87641@@ -11,7 +11,9 @@
87642 #include <linux/bug.h>
87643 #include <linux/kernel.h>
87644 #include <linux/rculist.h>
87645+#include <linux/mm.h>
87646
87647+#ifdef CONFIG_DEBUG_LIST
87648 /*
87649 * Insert a new entry between two known consecutive entries.
87650 *
87651@@ -19,21 +21,40 @@
87652 * the prev/next entries already!
87653 */
87654
87655+static bool __list_add_debug(struct list_head *new,
87656+ struct list_head *prev,
87657+ struct list_head *next)
87658+{
87659+ if (unlikely(next->prev != prev)) {
87660+ printk(KERN_ERR "list_add corruption. next->prev should be "
87661+ "prev (%p), but was %p. (next=%p).\n",
87662+ prev, next->prev, next);
87663+ BUG();
87664+ return false;
87665+ }
87666+ if (unlikely(prev->next != next)) {
87667+ printk(KERN_ERR "list_add corruption. prev->next should be "
87668+ "next (%p), but was %p. (prev=%p).\n",
87669+ next, prev->next, prev);
87670+ BUG();
87671+ return false;
87672+ }
87673+ if (unlikely(new == prev || new == next)) {
87674+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
87675+ new, prev, next);
87676+ BUG();
87677+ return false;
87678+ }
87679+ return true;
87680+}
87681+
87682 void __list_add(struct list_head *new,
87683- struct list_head *prev,
87684- struct list_head *next)
87685+ struct list_head *prev,
87686+ struct list_head *next)
87687 {
87688- WARN(next->prev != prev,
87689- "list_add corruption. next->prev should be "
87690- "prev (%p), but was %p. (next=%p).\n",
87691- prev, next->prev, next);
87692- WARN(prev->next != next,
87693- "list_add corruption. prev->next should be "
87694- "next (%p), but was %p. (prev=%p).\n",
87695- next, prev->next, prev);
87696- WARN(new == prev || new == next,
87697- "list_add double add: new=%p, prev=%p, next=%p.\n",
87698- new, prev, next);
87699+ if (!__list_add_debug(new, prev, next))
87700+ return;
87701+
87702 next->prev = new;
87703 new->next = next;
87704 new->prev = prev;
87705@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
87706 }
87707 EXPORT_SYMBOL(__list_add);
87708
87709-void __list_del_entry(struct list_head *entry)
87710+static bool __list_del_entry_debug(struct list_head *entry)
87711 {
87712 struct list_head *prev, *next;
87713
87714 prev = entry->prev;
87715 next = entry->next;
87716
87717- if (WARN(next == LIST_POISON1,
87718- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
87719- entry, LIST_POISON1) ||
87720- WARN(prev == LIST_POISON2,
87721- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
87722- entry, LIST_POISON2) ||
87723- WARN(prev->next != entry,
87724- "list_del corruption. prev->next should be %p, "
87725- "but was %p\n", entry, prev->next) ||
87726- WARN(next->prev != entry,
87727- "list_del corruption. next->prev should be %p, "
87728- "but was %p\n", entry, next->prev))
87729+ if (unlikely(next == LIST_POISON1)) {
87730+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
87731+ entry, LIST_POISON1);
87732+ BUG();
87733+ return false;
87734+ }
87735+ if (unlikely(prev == LIST_POISON2)) {
87736+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
87737+ entry, LIST_POISON2);
87738+ BUG();
87739+ return false;
87740+ }
87741+ if (unlikely(entry->prev->next != entry)) {
87742+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
87743+ "but was %p\n", entry, prev->next);
87744+ BUG();
87745+ return false;
87746+ }
87747+ if (unlikely(entry->next->prev != entry)) {
87748+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
87749+ "but was %p\n", entry, next->prev);
87750+ BUG();
87751+ return false;
87752+ }
87753+ return true;
87754+}
87755+
87756+void __list_del_entry(struct list_head *entry)
87757+{
87758+ if (!__list_del_entry_debug(entry))
87759 return;
87760
87761- __list_del(prev, next);
87762+ __list_del(entry->prev, entry->next);
87763 }
87764 EXPORT_SYMBOL(__list_del_entry);
87765
87766@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
87767 void __list_add_rcu(struct list_head *new,
87768 struct list_head *prev, struct list_head *next)
87769 {
87770- WARN(next->prev != prev,
87771- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
87772- prev, next->prev, next);
87773- WARN(prev->next != next,
87774- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
87775- next, prev->next, prev);
87776+ if (!__list_add_debug(new, prev, next))
87777+ return;
87778+
87779 new->next = next;
87780 new->prev = prev;
87781 rcu_assign_pointer(list_next_rcu(prev), new);
87782 next->prev = new;
87783 }
87784 EXPORT_SYMBOL(__list_add_rcu);
87785+#endif
87786+
87787+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
87788+{
87789+#ifdef CONFIG_DEBUG_LIST
87790+ if (!__list_add_debug(new, prev, next))
87791+ return;
87792+#endif
87793+
87794+ pax_open_kernel();
87795+ next->prev = new;
87796+ new->next = next;
87797+ new->prev = prev;
87798+ prev->next = new;
87799+ pax_close_kernel();
87800+}
87801+EXPORT_SYMBOL(__pax_list_add);
87802+
87803+void pax_list_del(struct list_head *entry)
87804+{
87805+#ifdef CONFIG_DEBUG_LIST
87806+ if (!__list_del_entry_debug(entry))
87807+ return;
87808+#endif
87809+
87810+ pax_open_kernel();
87811+ __list_del(entry->prev, entry->next);
87812+ entry->next = LIST_POISON1;
87813+ entry->prev = LIST_POISON2;
87814+ pax_close_kernel();
87815+}
87816+EXPORT_SYMBOL(pax_list_del);
87817+
87818+void pax_list_del_init(struct list_head *entry)
87819+{
87820+ pax_open_kernel();
87821+ __list_del(entry->prev, entry->next);
87822+ INIT_LIST_HEAD(entry);
87823+ pax_close_kernel();
87824+}
87825+EXPORT_SYMBOL(pax_list_del_init);
87826+
87827+void __pax_list_add_rcu(struct list_head *new,
87828+ struct list_head *prev, struct list_head *next)
87829+{
87830+#ifdef CONFIG_DEBUG_LIST
87831+ if (!__list_add_debug(new, prev, next))
87832+ return;
87833+#endif
87834+
87835+ pax_open_kernel();
87836+ new->next = next;
87837+ new->prev = prev;
87838+ rcu_assign_pointer(list_next_rcu(prev), new);
87839+ next->prev = new;
87840+ pax_close_kernel();
87841+}
87842+EXPORT_SYMBOL(__pax_list_add_rcu);
87843+
87844+void pax_list_del_rcu(struct list_head *entry)
87845+{
87846+#ifdef CONFIG_DEBUG_LIST
87847+ if (!__list_del_entry_debug(entry))
87848+ return;
87849+#endif
87850+
87851+ pax_open_kernel();
87852+ __list_del(entry->prev, entry->next);
87853+ entry->next = LIST_POISON1;
87854+ entry->prev = LIST_POISON2;
87855+ pax_close_kernel();
87856+}
87857+EXPORT_SYMBOL(pax_list_del_rcu);
87858diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
87859index 1a53d49..ace934c 100644
87860--- a/lib/percpu-refcount.c
87861+++ b/lib/percpu-refcount.c
87862@@ -29,7 +29,7 @@
87863 * can't hit 0 before we've added up all the percpu refs.
87864 */
87865
87866-#define PCPU_COUNT_BIAS (1U << 31)
87867+#define PCPU_COUNT_BIAS (1U << 30)
87868
87869 /**
87870 * percpu_ref_init - initialize a percpu refcount
87871diff --git a/lib/radix-tree.c b/lib/radix-tree.c
87872index 7811ed3..f80ca19 100644
87873--- a/lib/radix-tree.c
87874+++ b/lib/radix-tree.c
87875@@ -93,7 +93,7 @@ struct radix_tree_preload {
87876 int nr;
87877 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
87878 };
87879-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
87880+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
87881
87882 static inline void *ptr_to_indirect(void *ptr)
87883 {
87884diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
87885index bb2b201..46abaf9 100644
87886--- a/lib/strncpy_from_user.c
87887+++ b/lib/strncpy_from_user.c
87888@@ -21,7 +21,7 @@
87889 */
87890 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
87891 {
87892- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87893+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87894 long res = 0;
87895
87896 /*
87897diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
87898index a28df52..3d55877 100644
87899--- a/lib/strnlen_user.c
87900+++ b/lib/strnlen_user.c
87901@@ -26,7 +26,7 @@
87902 */
87903 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
87904 {
87905- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87906+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87907 long align, res = 0;
87908 unsigned long c;
87909
87910diff --git a/lib/swiotlb.c b/lib/swiotlb.c
87911index 4e8686c..3e8c92f 100644
87912--- a/lib/swiotlb.c
87913+++ b/lib/swiotlb.c
87914@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
87915
87916 void
87917 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
87918- dma_addr_t dev_addr)
87919+ dma_addr_t dev_addr, struct dma_attrs *attrs)
87920 {
87921 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
87922
87923diff --git a/lib/usercopy.c b/lib/usercopy.c
87924index 4f5b1dd..7cab418 100644
87925--- a/lib/usercopy.c
87926+++ b/lib/usercopy.c
87927@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
87928 WARN(1, "Buffer overflow detected!\n");
87929 }
87930 EXPORT_SYMBOL(copy_from_user_overflow);
87931+
87932+void copy_to_user_overflow(void)
87933+{
87934+ WARN(1, "Buffer overflow detected!\n");
87935+}
87936+EXPORT_SYMBOL(copy_to_user_overflow);
87937diff --git a/lib/vsprintf.c b/lib/vsprintf.c
87938index d76555c..62d4bfe 100644
87939--- a/lib/vsprintf.c
87940+++ b/lib/vsprintf.c
87941@@ -16,6 +16,9 @@
87942 * - scnprintf and vscnprintf
87943 */
87944
87945+#ifdef CONFIG_GRKERNSEC_HIDESYM
87946+#define __INCLUDED_BY_HIDESYM 1
87947+#endif
87948 #include <stdarg.h>
87949 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
87950 #include <linux/types.h>
87951@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
87952 return number(buf, end, *(const netdev_features_t *)addr, spec);
87953 }
87954
87955+#ifdef CONFIG_GRKERNSEC_HIDESYM
87956+int kptr_restrict __read_mostly = 2;
87957+#else
87958 int kptr_restrict __read_mostly;
87959+#endif
87960
87961 /*
87962 * Show a '%p' thing. A kernel extension is that the '%p' is followed
87963@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
87964 * - 'f' For simple symbolic function names without offset
87965 * - 'S' For symbolic direct pointers with offset
87966 * - 's' For symbolic direct pointers without offset
87967+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
87968 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
87969 * - 'B' For backtraced symbolic direct pointers with offset
87970 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
87971@@ -1232,12 +1240,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87972
87973 if (!ptr && *fmt != 'K') {
87974 /*
87975- * Print (null) with the same width as a pointer so it makes
87976+ * Print (nil) with the same width as a pointer so it makes
87977 * tabular output look nice.
87978 */
87979 if (spec.field_width == -1)
87980 spec.field_width = default_width;
87981- return string(buf, end, "(null)", spec);
87982+ return string(buf, end, "(nil)", spec);
87983 }
87984
87985 switch (*fmt) {
87986@@ -1247,6 +1255,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87987 /* Fallthrough */
87988 case 'S':
87989 case 's':
87990+#ifdef CONFIG_GRKERNSEC_HIDESYM
87991+ break;
87992+#else
87993+ return symbol_string(buf, end, ptr, spec, fmt);
87994+#endif
87995+ case 'A':
87996 case 'B':
87997 return symbol_string(buf, end, ptr, spec, fmt);
87998 case 'R':
87999@@ -1302,6 +1316,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
88000 va_end(va);
88001 return buf;
88002 }
88003+ case 'P':
88004+ break;
88005 case 'K':
88006 /*
88007 * %pK cannot be used in IRQ context because its test
88008@@ -1363,6 +1379,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
88009 ((const struct file *)ptr)->f_path.dentry,
88010 spec, fmt);
88011 }
88012+
88013+#ifdef CONFIG_GRKERNSEC_HIDESYM
88014+ /* 'P' = approved pointers to copy to userland,
88015+ as in the /proc/kallsyms case, as we make it display nothing
88016+ for non-root users, and the real contents for root users
88017+ Also ignore 'K' pointers, since we force their NULLing for non-root users
88018+ above
88019+ */
88020+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
88021+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
88022+ dump_stack();
88023+ ptr = NULL;
88024+ }
88025+#endif
88026+
88027 spec.flags |= SMALL;
88028 if (spec.field_width == -1) {
88029 spec.field_width = default_width;
88030@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
88031 typeof(type) value; \
88032 if (sizeof(type) == 8) { \
88033 args = PTR_ALIGN(args, sizeof(u32)); \
88034- *(u32 *)&value = *(u32 *)args; \
88035- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
88036+ *(u32 *)&value = *(const u32 *)args; \
88037+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
88038 } else { \
88039 args = PTR_ALIGN(args, sizeof(type)); \
88040- value = *(typeof(type) *)args; \
88041+ value = *(const typeof(type) *)args; \
88042 } \
88043 args += sizeof(type); \
88044 value; \
88045@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
88046 case FORMAT_TYPE_STR: {
88047 const char *str_arg = args;
88048 args += strlen(str_arg) + 1;
88049- str = string(str, end, (char *)str_arg, spec);
88050+ str = string(str, end, str_arg, spec);
88051 break;
88052 }
88053
88054diff --git a/localversion-grsec b/localversion-grsec
88055new file mode 100644
88056index 0000000..7cd6065
88057--- /dev/null
88058+++ b/localversion-grsec
88059@@ -0,0 +1 @@
88060+-grsec
88061diff --git a/mm/Kconfig b/mm/Kconfig
88062index 394838f..0e5f816 100644
88063--- a/mm/Kconfig
88064+++ b/mm/Kconfig
88065@@ -317,10 +317,11 @@ config KSM
88066 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
88067
88068 config DEFAULT_MMAP_MIN_ADDR
88069- int "Low address space to protect from user allocation"
88070+ int "Low address space to protect from user allocation"
88071 depends on MMU
88072- default 4096
88073- help
88074+ default 32768 if ALPHA || ARM || PARISC || SPARC32
88075+ default 65536
88076+ help
88077 This is the portion of low virtual memory which should be protected
88078 from userspace allocation. Keeping a user from writing to low pages
88079 can help reduce the impact of kernel NULL pointer bugs.
88080@@ -351,7 +352,7 @@ config MEMORY_FAILURE
88081
88082 config HWPOISON_INJECT
88083 tristate "HWPoison pages injector"
88084- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
88085+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
88086 select PROC_PAGE_MONITOR
88087
88088 config NOMMU_INITIAL_TRIM_EXCESS
88089diff --git a/mm/backing-dev.c b/mm/backing-dev.c
88090index ce682f7..1fb54f9 100644
88091--- a/mm/backing-dev.c
88092+++ b/mm/backing-dev.c
88093@@ -12,7 +12,7 @@
88094 #include <linux/device.h>
88095 #include <trace/events/writeback.h>
88096
88097-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
88098+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
88099
88100 struct backing_dev_info default_backing_dev_info = {
88101 .name = "default",
88102@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
88103 return err;
88104
88105 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
88106- atomic_long_inc_return(&bdi_seq));
88107+ atomic_long_inc_return_unchecked(&bdi_seq));
88108 if (err) {
88109 bdi_destroy(bdi);
88110 return err;
88111diff --git a/mm/filemap.c b/mm/filemap.c
88112index ae4846f..b0acebe 100644
88113--- a/mm/filemap.c
88114+++ b/mm/filemap.c
88115@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
88116 struct address_space *mapping = file->f_mapping;
88117
88118 if (!mapping->a_ops->readpage)
88119- return -ENOEXEC;
88120+ return -ENODEV;
88121 file_accessed(file);
88122 vma->vm_ops = &generic_file_vm_ops;
88123 return 0;
88124@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
88125
88126 while (bytes) {
88127 char __user *buf = iov->iov_base + base;
88128- int copy = min(bytes, iov->iov_len - base);
88129+ size_t copy = min(bytes, iov->iov_len - base);
88130
88131 base = 0;
88132 left = __copy_from_user_inatomic(vaddr, buf, copy);
88133@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
88134 BUG_ON(!in_atomic());
88135 kaddr = kmap_atomic(page);
88136 if (likely(i->nr_segs == 1)) {
88137- int left;
88138+ size_t left;
88139 char __user *buf = i->iov->iov_base + i->iov_offset;
88140 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
88141 copied = bytes - left;
88142@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
88143
88144 kaddr = kmap(page);
88145 if (likely(i->nr_segs == 1)) {
88146- int left;
88147+ size_t left;
88148 char __user *buf = i->iov->iov_base + i->iov_offset;
88149 left = __copy_from_user(kaddr + offset, buf, bytes);
88150 copied = bytes - left;
88151@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
88152 * zero-length segments (without overruning the iovec).
88153 */
88154 while (bytes || unlikely(i->count && !iov->iov_len)) {
88155- int copy;
88156+ size_t copy;
88157
88158 copy = min(bytes, iov->iov_len - base);
88159 BUG_ON(!i->count || i->count < copy);
88160@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
88161 *pos = i_size_read(inode);
88162
88163 if (limit != RLIM_INFINITY) {
88164+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
88165 if (*pos >= limit) {
88166 send_sig(SIGXFSZ, current, 0);
88167 return -EFBIG;
88168diff --git a/mm/fremap.c b/mm/fremap.c
88169index 5bff081..bfa6e93 100644
88170--- a/mm/fremap.c
88171+++ b/mm/fremap.c
88172@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
88173 retry:
88174 vma = find_vma(mm, start);
88175
88176+#ifdef CONFIG_PAX_SEGMEXEC
88177+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
88178+ goto out;
88179+#endif
88180+
88181 /*
88182 * Make sure the vma is shared, that it supports prefaulting,
88183 * and that the remapped range is valid and fully within
88184@@ -208,9 +213,10 @@ get_write_lock:
88185 if (mapping_cap_account_dirty(mapping)) {
88186 unsigned long addr;
88187 struct file *file = get_file(vma->vm_file);
88188+ /* mmap_region may free vma; grab the info now */
88189+ vm_flags = ACCESS_ONCE(vma->vm_flags);
88190
88191- addr = mmap_region(file, start, size,
88192- vma->vm_flags, pgoff);
88193+ addr = mmap_region(file, start, size, vm_flags, pgoff);
88194 fput(file);
88195 if (IS_ERR_VALUE(addr)) {
88196 err = addr;
88197@@ -218,7 +224,7 @@ get_write_lock:
88198 BUG_ON(addr != start);
88199 err = 0;
88200 }
88201- goto out;
88202+ goto out_freed;
88203 }
88204 mutex_lock(&mapping->i_mmap_mutex);
88205 flush_dcache_mmap_lock(mapping);
88206@@ -253,6 +259,7 @@ get_write_lock:
88207 out:
88208 if (vma)
88209 vm_flags = vma->vm_flags;
88210+out_freed:
88211 if (likely(!has_write_lock))
88212 up_read(&mm->mmap_sem);
88213 else
88214diff --git a/mm/highmem.c b/mm/highmem.c
88215index b32b70c..e512eb0 100644
88216--- a/mm/highmem.c
88217+++ b/mm/highmem.c
88218@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
88219 * So no dangers, even with speculative execution.
88220 */
88221 page = pte_page(pkmap_page_table[i]);
88222+ pax_open_kernel();
88223 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
88224-
88225+ pax_close_kernel();
88226 set_page_address(page, NULL);
88227 need_flush = 1;
88228 }
88229@@ -198,9 +199,11 @@ start:
88230 }
88231 }
88232 vaddr = PKMAP_ADDR(last_pkmap_nr);
88233+
88234+ pax_open_kernel();
88235 set_pte_at(&init_mm, vaddr,
88236 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
88237-
88238+ pax_close_kernel();
88239 pkmap_count[last_pkmap_nr] = 1;
88240 set_page_address(page, (void *)vaddr);
88241
88242diff --git a/mm/hugetlb.c b/mm/hugetlb.c
88243index 0b7656e..d21cefc 100644
88244--- a/mm/hugetlb.c
88245+++ b/mm/hugetlb.c
88246@@ -2094,15 +2094,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
88247 struct hstate *h = &default_hstate;
88248 unsigned long tmp;
88249 int ret;
88250+ ctl_table_no_const hugetlb_table;
88251
88252 tmp = h->max_huge_pages;
88253
88254 if (write && h->order >= MAX_ORDER)
88255 return -EINVAL;
88256
88257- table->data = &tmp;
88258- table->maxlen = sizeof(unsigned long);
88259- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
88260+ hugetlb_table = *table;
88261+ hugetlb_table.data = &tmp;
88262+ hugetlb_table.maxlen = sizeof(unsigned long);
88263+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
88264 if (ret)
88265 goto out;
88266
88267@@ -2147,15 +2149,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
88268 struct hstate *h = &default_hstate;
88269 unsigned long tmp;
88270 int ret;
88271+ ctl_table_no_const hugetlb_table;
88272
88273 tmp = h->nr_overcommit_huge_pages;
88274
88275 if (write && h->order >= MAX_ORDER)
88276 return -EINVAL;
88277
88278- table->data = &tmp;
88279- table->maxlen = sizeof(unsigned long);
88280- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
88281+ hugetlb_table = *table;
88282+ hugetlb_table.data = &tmp;
88283+ hugetlb_table.maxlen = sizeof(unsigned long);
88284+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
88285 if (ret)
88286 goto out;
88287
88288@@ -2605,6 +2609,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
88289 return 1;
88290 }
88291
88292+#ifdef CONFIG_PAX_SEGMEXEC
88293+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
88294+{
88295+ struct mm_struct *mm = vma->vm_mm;
88296+ struct vm_area_struct *vma_m;
88297+ unsigned long address_m;
88298+ pte_t *ptep_m;
88299+
88300+ vma_m = pax_find_mirror_vma(vma);
88301+ if (!vma_m)
88302+ return;
88303+
88304+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88305+ address_m = address + SEGMEXEC_TASK_SIZE;
88306+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
88307+ get_page(page_m);
88308+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
88309+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
88310+}
88311+#endif
88312+
88313 /*
88314 * Hugetlb_cow() should be called with page lock of the original hugepage held.
88315 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
88316@@ -2721,6 +2746,11 @@ retry_avoidcopy:
88317 make_huge_pte(vma, new_page, 1));
88318 page_remove_rmap(old_page);
88319 hugepage_add_new_anon_rmap(new_page, vma, address);
88320+
88321+#ifdef CONFIG_PAX_SEGMEXEC
88322+ pax_mirror_huge_pte(vma, address, new_page);
88323+#endif
88324+
88325 /* Make the old page be freed below */
88326 new_page = old_page;
88327 }
88328@@ -2883,6 +2913,10 @@ retry:
88329 && (vma->vm_flags & VM_SHARED)));
88330 set_huge_pte_at(mm, address, ptep, new_pte);
88331
88332+#ifdef CONFIG_PAX_SEGMEXEC
88333+ pax_mirror_huge_pte(vma, address, page);
88334+#endif
88335+
88336 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
88337 /* Optimization, do the COW without a second fault */
88338 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
88339@@ -2912,6 +2946,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88340 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
88341 struct hstate *h = hstate_vma(vma);
88342
88343+#ifdef CONFIG_PAX_SEGMEXEC
88344+ struct vm_area_struct *vma_m;
88345+#endif
88346+
88347 address &= huge_page_mask(h);
88348
88349 ptep = huge_pte_offset(mm, address);
88350@@ -2925,6 +2963,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88351 VM_FAULT_SET_HINDEX(hstate_index(h));
88352 }
88353
88354+#ifdef CONFIG_PAX_SEGMEXEC
88355+ vma_m = pax_find_mirror_vma(vma);
88356+ if (vma_m) {
88357+ unsigned long address_m;
88358+
88359+ if (vma->vm_start > vma_m->vm_start) {
88360+ address_m = address;
88361+ address -= SEGMEXEC_TASK_SIZE;
88362+ vma = vma_m;
88363+ h = hstate_vma(vma);
88364+ } else
88365+ address_m = address + SEGMEXEC_TASK_SIZE;
88366+
88367+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
88368+ return VM_FAULT_OOM;
88369+ address_m &= HPAGE_MASK;
88370+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
88371+ }
88372+#endif
88373+
88374 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
88375 if (!ptep)
88376 return VM_FAULT_OOM;
88377diff --git a/mm/internal.h b/mm/internal.h
88378index 684f7aa..9eb9edc 100644
88379--- a/mm/internal.h
88380+++ b/mm/internal.h
88381@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
88382 * in mm/page_alloc.c
88383 */
88384 extern void __free_pages_bootmem(struct page *page, unsigned int order);
88385+extern void free_compound_page(struct page *page);
88386 extern void prep_compound_page(struct page *page, unsigned long order);
88387 #ifdef CONFIG_MEMORY_FAILURE
88388 extern bool is_free_buddy_page(struct page *page);
88389@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
88390
88391 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
88392 unsigned long, unsigned long,
88393- unsigned long, unsigned long);
88394+ unsigned long, unsigned long) __intentional_overflow(-1);
88395
88396 extern void set_pageblock_order(void);
88397 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
88398diff --git a/mm/kmemleak.c b/mm/kmemleak.c
88399index e126b0e..e986018 100644
88400--- a/mm/kmemleak.c
88401+++ b/mm/kmemleak.c
88402@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
88403
88404 for (i = 0; i < object->trace_len; i++) {
88405 void *ptr = (void *)object->trace[i];
88406- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
88407+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
88408 }
88409 }
88410
88411@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
88412 return -ENOMEM;
88413 }
88414
88415- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
88416+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
88417 &kmemleak_fops);
88418 if (!dentry)
88419 pr_warning("Failed to create the debugfs kmemleak file\n");
88420diff --git a/mm/maccess.c b/mm/maccess.c
88421index d53adf9..03a24bf 100644
88422--- a/mm/maccess.c
88423+++ b/mm/maccess.c
88424@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
88425 set_fs(KERNEL_DS);
88426 pagefault_disable();
88427 ret = __copy_from_user_inatomic(dst,
88428- (__force const void __user *)src, size);
88429+ (const void __force_user *)src, size);
88430 pagefault_enable();
88431 set_fs(old_fs);
88432
88433@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
88434
88435 set_fs(KERNEL_DS);
88436 pagefault_disable();
88437- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
88438+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
88439 pagefault_enable();
88440 set_fs(old_fs);
88441
88442diff --git a/mm/madvise.c b/mm/madvise.c
88443index 539eeb9..e24a987 100644
88444--- a/mm/madvise.c
88445+++ b/mm/madvise.c
88446@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
88447 pgoff_t pgoff;
88448 unsigned long new_flags = vma->vm_flags;
88449
88450+#ifdef CONFIG_PAX_SEGMEXEC
88451+ struct vm_area_struct *vma_m;
88452+#endif
88453+
88454 switch (behavior) {
88455 case MADV_NORMAL:
88456 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
88457@@ -126,6 +130,13 @@ success:
88458 /*
88459 * vm_flags is protected by the mmap_sem held in write mode.
88460 */
88461+
88462+#ifdef CONFIG_PAX_SEGMEXEC
88463+ vma_m = pax_find_mirror_vma(vma);
88464+ if (vma_m)
88465+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
88466+#endif
88467+
88468 vma->vm_flags = new_flags;
88469
88470 out:
88471@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
88472 struct vm_area_struct **prev,
88473 unsigned long start, unsigned long end)
88474 {
88475+
88476+#ifdef CONFIG_PAX_SEGMEXEC
88477+ struct vm_area_struct *vma_m;
88478+#endif
88479+
88480 *prev = vma;
88481 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
88482 return -EINVAL;
88483@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
88484 zap_page_range(vma, start, end - start, &details);
88485 } else
88486 zap_page_range(vma, start, end - start, NULL);
88487+
88488+#ifdef CONFIG_PAX_SEGMEXEC
88489+ vma_m = pax_find_mirror_vma(vma);
88490+ if (vma_m) {
88491+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
88492+ struct zap_details details = {
88493+ .nonlinear_vma = vma_m,
88494+ .last_index = ULONG_MAX,
88495+ };
88496+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
88497+ } else
88498+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
88499+ }
88500+#endif
88501+
88502 return 0;
88503 }
88504
88505@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
88506 if (end < start)
88507 return error;
88508
88509+#ifdef CONFIG_PAX_SEGMEXEC
88510+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88511+ if (end > SEGMEXEC_TASK_SIZE)
88512+ return error;
88513+ } else
88514+#endif
88515+
88516+ if (end > TASK_SIZE)
88517+ return error;
88518+
88519 error = 0;
88520 if (end == start)
88521 return error;
88522diff --git a/mm/memory-failure.c b/mm/memory-failure.c
88523index bf3351b..aea800d 100644
88524--- a/mm/memory-failure.c
88525+++ b/mm/memory-failure.c
88526@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
88527
88528 int sysctl_memory_failure_recovery __read_mostly = 1;
88529
88530-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
88531+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
88532
88533 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
88534
88535@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
88536 pfn, t->comm, t->pid);
88537 si.si_signo = SIGBUS;
88538 si.si_errno = 0;
88539- si.si_addr = (void *)addr;
88540+ si.si_addr = (void __user *)addr;
88541 #ifdef __ARCH_SI_TRAPNO
88542 si.si_trapno = trapno;
88543 #endif
88544@@ -762,7 +762,7 @@ static struct page_state {
88545 unsigned long res;
88546 char *msg;
88547 int (*action)(struct page *p, unsigned long pfn);
88548-} error_states[] = {
88549+} __do_const error_states[] = {
88550 { reserved, reserved, "reserved kernel", me_kernel },
88551 /*
88552 * free pages are specially detected outside this table:
88553@@ -1053,7 +1053,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
88554 nr_pages = 1 << compound_order(hpage);
88555 else /* normal page or thp */
88556 nr_pages = 1;
88557- atomic_long_add(nr_pages, &num_poisoned_pages);
88558+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
88559
88560 /*
88561 * We need/can do nothing about count=0 pages.
88562@@ -1083,7 +1083,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
88563 if (!PageHWPoison(hpage)
88564 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
88565 || (p != hpage && TestSetPageHWPoison(hpage))) {
88566- atomic_long_sub(nr_pages, &num_poisoned_pages);
88567+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
88568 return 0;
88569 }
88570 set_page_hwpoison_huge_page(hpage);
88571@@ -1152,7 +1152,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
88572 }
88573 if (hwpoison_filter(p)) {
88574 if (TestClearPageHWPoison(p))
88575- atomic_long_sub(nr_pages, &num_poisoned_pages);
88576+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
88577 unlock_page(hpage);
88578 put_page(hpage);
88579 return 0;
88580@@ -1370,7 +1370,7 @@ int unpoison_memory(unsigned long pfn)
88581 return 0;
88582 }
88583 if (TestClearPageHWPoison(p))
88584- atomic_long_dec(&num_poisoned_pages);
88585+ atomic_long_dec_unchecked(&num_poisoned_pages);
88586 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
88587 return 0;
88588 }
88589@@ -1384,7 +1384,7 @@ int unpoison_memory(unsigned long pfn)
88590 */
88591 if (TestClearPageHWPoison(page)) {
88592 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
88593- atomic_long_sub(nr_pages, &num_poisoned_pages);
88594+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
88595 freeit = 1;
88596 if (PageHuge(page))
88597 clear_page_hwpoison_huge_page(page);
88598@@ -1521,7 +1521,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
88599 } else {
88600 set_page_hwpoison_huge_page(hpage);
88601 dequeue_hwpoisoned_huge_page(hpage);
88602- atomic_long_add(1 << compound_order(hpage),
88603+ atomic_long_add_unchecked(1 << compound_order(hpage),
88604 &num_poisoned_pages);
88605 }
88606 return ret;
88607@@ -1560,7 +1560,7 @@ static int __soft_offline_page(struct page *page, int flags)
88608 put_page(page);
88609 pr_info("soft_offline: %#lx: invalidated\n", pfn);
88610 SetPageHWPoison(page);
88611- atomic_long_inc(&num_poisoned_pages);
88612+ atomic_long_inc_unchecked(&num_poisoned_pages);
88613 return 0;
88614 }
88615
88616@@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
88617 if (!is_free_buddy_page(page))
88618 pr_info("soft offline: %#lx: page leaked\n",
88619 pfn);
88620- atomic_long_inc(&num_poisoned_pages);
88621+ atomic_long_inc_unchecked(&num_poisoned_pages);
88622 }
88623 } else {
88624 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
88625@@ -1666,11 +1666,11 @@ int soft_offline_page(struct page *page, int flags)
88626 if (PageHuge(page)) {
88627 set_page_hwpoison_huge_page(hpage);
88628 dequeue_hwpoisoned_huge_page(hpage);
88629- atomic_long_add(1 << compound_order(hpage),
88630+ atomic_long_add_unchecked(1 << compound_order(hpage),
88631 &num_poisoned_pages);
88632 } else {
88633 SetPageHWPoison(page);
88634- atomic_long_inc(&num_poisoned_pages);
88635+ atomic_long_inc_unchecked(&num_poisoned_pages);
88636 }
88637 }
88638 unset:
88639diff --git a/mm/memory.c b/mm/memory.c
88640index d176154..cd1b387 100644
88641--- a/mm/memory.c
88642+++ b/mm/memory.c
88643@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
88644 free_pte_range(tlb, pmd, addr);
88645 } while (pmd++, addr = next, addr != end);
88646
88647+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
88648 start &= PUD_MASK;
88649 if (start < floor)
88650 return;
88651@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
88652 pmd = pmd_offset(pud, start);
88653 pud_clear(pud);
88654 pmd_free_tlb(tlb, pmd, start);
88655+#endif
88656+
88657 }
88658
88659 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
88660@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
88661 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
88662 } while (pud++, addr = next, addr != end);
88663
88664+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
88665 start &= PGDIR_MASK;
88666 if (start < floor)
88667 return;
88668@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
88669 pud = pud_offset(pgd, start);
88670 pgd_clear(pgd);
88671 pud_free_tlb(tlb, pud, start);
88672+#endif
88673+
88674 }
88675
88676 /*
88677@@ -1636,12 +1642,6 @@ no_page_table:
88678 return page;
88679 }
88680
88681-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
88682-{
88683- return stack_guard_page_start(vma, addr) ||
88684- stack_guard_page_end(vma, addr+PAGE_SIZE);
88685-}
88686-
88687 /**
88688 * __get_user_pages() - pin user pages in memory
88689 * @tsk: task_struct of target task
88690@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
88691
88692 i = 0;
88693
88694- do {
88695+ while (nr_pages) {
88696 struct vm_area_struct *vma;
88697
88698- vma = find_extend_vma(mm, start);
88699+ vma = find_vma(mm, start);
88700 if (!vma && in_gate_area(mm, start)) {
88701 unsigned long pg = start & PAGE_MASK;
88702 pgd_t *pgd;
88703@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
88704 goto next_page;
88705 }
88706
88707- if (!vma ||
88708+ if (!vma || start < vma->vm_start ||
88709 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
88710 !(vm_flags & vma->vm_flags))
88711 return i ? : -EFAULT;
88712@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
88713 int ret;
88714 unsigned int fault_flags = 0;
88715
88716- /* For mlock, just skip the stack guard page. */
88717- if (foll_flags & FOLL_MLOCK) {
88718- if (stack_guard_page(vma, start))
88719- goto next_page;
88720- }
88721 if (foll_flags & FOLL_WRITE)
88722 fault_flags |= FAULT_FLAG_WRITE;
88723 if (nonblocking)
88724@@ -1893,7 +1888,7 @@ next_page:
88725 start += page_increm * PAGE_SIZE;
88726 nr_pages -= page_increm;
88727 } while (nr_pages && start < vma->vm_end);
88728- } while (nr_pages);
88729+ }
88730 return i;
88731 }
88732 EXPORT_SYMBOL(__get_user_pages);
88733@@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
88734 page_add_file_rmap(page);
88735 set_pte_at(mm, addr, pte, mk_pte(page, prot));
88736
88737+#ifdef CONFIG_PAX_SEGMEXEC
88738+ pax_mirror_file_pte(vma, addr, page, ptl);
88739+#endif
88740+
88741 retval = 0;
88742 pte_unmap_unlock(pte, ptl);
88743 return retval;
88744@@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
88745 if (!page_count(page))
88746 return -EINVAL;
88747 if (!(vma->vm_flags & VM_MIXEDMAP)) {
88748+
88749+#ifdef CONFIG_PAX_SEGMEXEC
88750+ struct vm_area_struct *vma_m;
88751+#endif
88752+
88753 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
88754 BUG_ON(vma->vm_flags & VM_PFNMAP);
88755 vma->vm_flags |= VM_MIXEDMAP;
88756+
88757+#ifdef CONFIG_PAX_SEGMEXEC
88758+ vma_m = pax_find_mirror_vma(vma);
88759+ if (vma_m)
88760+ vma_m->vm_flags |= VM_MIXEDMAP;
88761+#endif
88762+
88763 }
88764 return insert_page(vma, addr, page, vma->vm_page_prot);
88765 }
88766@@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
88767 unsigned long pfn)
88768 {
88769 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
88770+ BUG_ON(vma->vm_mirror);
88771
88772 if (addr < vma->vm_start || addr >= vma->vm_end)
88773 return -EFAULT;
88774@@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
88775
88776 BUG_ON(pud_huge(*pud));
88777
88778- pmd = pmd_alloc(mm, pud, addr);
88779+ pmd = (mm == &init_mm) ?
88780+ pmd_alloc_kernel(mm, pud, addr) :
88781+ pmd_alloc(mm, pud, addr);
88782 if (!pmd)
88783 return -ENOMEM;
88784 do {
88785@@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
88786 unsigned long next;
88787 int err;
88788
88789- pud = pud_alloc(mm, pgd, addr);
88790+ pud = (mm == &init_mm) ?
88791+ pud_alloc_kernel(mm, pgd, addr) :
88792+ pud_alloc(mm, pgd, addr);
88793 if (!pud)
88794 return -ENOMEM;
88795 do {
88796@@ -2584,6 +2600,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
88797 copy_user_highpage(dst, src, va, vma);
88798 }
88799
88800+#ifdef CONFIG_PAX_SEGMEXEC
88801+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
88802+{
88803+ struct mm_struct *mm = vma->vm_mm;
88804+ spinlock_t *ptl;
88805+ pte_t *pte, entry;
88806+
88807+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
88808+ entry = *pte;
88809+ if (!pte_present(entry)) {
88810+ if (!pte_none(entry)) {
88811+ BUG_ON(pte_file(entry));
88812+ free_swap_and_cache(pte_to_swp_entry(entry));
88813+ pte_clear_not_present_full(mm, address, pte, 0);
88814+ }
88815+ } else {
88816+ struct page *page;
88817+
88818+ flush_cache_page(vma, address, pte_pfn(entry));
88819+ entry = ptep_clear_flush(vma, address, pte);
88820+ BUG_ON(pte_dirty(entry));
88821+ page = vm_normal_page(vma, address, entry);
88822+ if (page) {
88823+ update_hiwater_rss(mm);
88824+ if (PageAnon(page))
88825+ dec_mm_counter_fast(mm, MM_ANONPAGES);
88826+ else
88827+ dec_mm_counter_fast(mm, MM_FILEPAGES);
88828+ page_remove_rmap(page);
88829+ page_cache_release(page);
88830+ }
88831+ }
88832+ pte_unmap_unlock(pte, ptl);
88833+}
88834+
88835+/* PaX: if vma is mirrored, synchronize the mirror's PTE
88836+ *
88837+ * the ptl of the lower mapped page is held on entry and is not released on exit
88838+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
88839+ */
88840+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
88841+{
88842+ struct mm_struct *mm = vma->vm_mm;
88843+ unsigned long address_m;
88844+ spinlock_t *ptl_m;
88845+ struct vm_area_struct *vma_m;
88846+ pmd_t *pmd_m;
88847+ pte_t *pte_m, entry_m;
88848+
88849+ BUG_ON(!page_m || !PageAnon(page_m));
88850+
88851+ vma_m = pax_find_mirror_vma(vma);
88852+ if (!vma_m)
88853+ return;
88854+
88855+ BUG_ON(!PageLocked(page_m));
88856+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88857+ address_m = address + SEGMEXEC_TASK_SIZE;
88858+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88859+ pte_m = pte_offset_map(pmd_m, address_m);
88860+ ptl_m = pte_lockptr(mm, pmd_m);
88861+ if (ptl != ptl_m) {
88862+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88863+ if (!pte_none(*pte_m))
88864+ goto out;
88865+ }
88866+
88867+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
88868+ page_cache_get(page_m);
88869+ page_add_anon_rmap(page_m, vma_m, address_m);
88870+ inc_mm_counter_fast(mm, MM_ANONPAGES);
88871+ set_pte_at(mm, address_m, pte_m, entry_m);
88872+ update_mmu_cache(vma_m, address_m, pte_m);
88873+out:
88874+ if (ptl != ptl_m)
88875+ spin_unlock(ptl_m);
88876+ pte_unmap(pte_m);
88877+ unlock_page(page_m);
88878+}
88879+
88880+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
88881+{
88882+ struct mm_struct *mm = vma->vm_mm;
88883+ unsigned long address_m;
88884+ spinlock_t *ptl_m;
88885+ struct vm_area_struct *vma_m;
88886+ pmd_t *pmd_m;
88887+ pte_t *pte_m, entry_m;
88888+
88889+ BUG_ON(!page_m || PageAnon(page_m));
88890+
88891+ vma_m = pax_find_mirror_vma(vma);
88892+ if (!vma_m)
88893+ return;
88894+
88895+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88896+ address_m = address + SEGMEXEC_TASK_SIZE;
88897+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88898+ pte_m = pte_offset_map(pmd_m, address_m);
88899+ ptl_m = pte_lockptr(mm, pmd_m);
88900+ if (ptl != ptl_m) {
88901+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88902+ if (!pte_none(*pte_m))
88903+ goto out;
88904+ }
88905+
88906+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
88907+ page_cache_get(page_m);
88908+ page_add_file_rmap(page_m);
88909+ inc_mm_counter_fast(mm, MM_FILEPAGES);
88910+ set_pte_at(mm, address_m, pte_m, entry_m);
88911+ update_mmu_cache(vma_m, address_m, pte_m);
88912+out:
88913+ if (ptl != ptl_m)
88914+ spin_unlock(ptl_m);
88915+ pte_unmap(pte_m);
88916+}
88917+
88918+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
88919+{
88920+ struct mm_struct *mm = vma->vm_mm;
88921+ unsigned long address_m;
88922+ spinlock_t *ptl_m;
88923+ struct vm_area_struct *vma_m;
88924+ pmd_t *pmd_m;
88925+ pte_t *pte_m, entry_m;
88926+
88927+ vma_m = pax_find_mirror_vma(vma);
88928+ if (!vma_m)
88929+ return;
88930+
88931+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88932+ address_m = address + SEGMEXEC_TASK_SIZE;
88933+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88934+ pte_m = pte_offset_map(pmd_m, address_m);
88935+ ptl_m = pte_lockptr(mm, pmd_m);
88936+ if (ptl != ptl_m) {
88937+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88938+ if (!pte_none(*pte_m))
88939+ goto out;
88940+ }
88941+
88942+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
88943+ set_pte_at(mm, address_m, pte_m, entry_m);
88944+out:
88945+ if (ptl != ptl_m)
88946+ spin_unlock(ptl_m);
88947+ pte_unmap(pte_m);
88948+}
88949+
88950+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
88951+{
88952+ struct page *page_m;
88953+ pte_t entry;
88954+
88955+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
88956+ goto out;
88957+
88958+ entry = *pte;
88959+ page_m = vm_normal_page(vma, address, entry);
88960+ if (!page_m)
88961+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
88962+ else if (PageAnon(page_m)) {
88963+ if (pax_find_mirror_vma(vma)) {
88964+ pte_unmap_unlock(pte, ptl);
88965+ lock_page(page_m);
88966+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
88967+ if (pte_same(entry, *pte))
88968+ pax_mirror_anon_pte(vma, address, page_m, ptl);
88969+ else
88970+ unlock_page(page_m);
88971+ }
88972+ } else
88973+ pax_mirror_file_pte(vma, address, page_m, ptl);
88974+
88975+out:
88976+ pte_unmap_unlock(pte, ptl);
88977+}
88978+#endif
88979+
88980 /*
88981 * This routine handles present pages, when users try to write
88982 * to a shared page. It is done by copying the page to a new address
88983@@ -2800,6 +2996,12 @@ gotten:
88984 */
88985 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88986 if (likely(pte_same(*page_table, orig_pte))) {
88987+
88988+#ifdef CONFIG_PAX_SEGMEXEC
88989+ if (pax_find_mirror_vma(vma))
88990+ BUG_ON(!trylock_page(new_page));
88991+#endif
88992+
88993 if (old_page) {
88994 if (!PageAnon(old_page)) {
88995 dec_mm_counter_fast(mm, MM_FILEPAGES);
88996@@ -2851,6 +3053,10 @@ gotten:
88997 page_remove_rmap(old_page);
88998 }
88999
89000+#ifdef CONFIG_PAX_SEGMEXEC
89001+ pax_mirror_anon_pte(vma, address, new_page, ptl);
89002+#endif
89003+
89004 /* Free the old page.. */
89005 new_page = old_page;
89006 ret |= VM_FAULT_WRITE;
89007@@ -3128,6 +3334,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
89008 swap_free(entry);
89009 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
89010 try_to_free_swap(page);
89011+
89012+#ifdef CONFIG_PAX_SEGMEXEC
89013+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
89014+#endif
89015+
89016 unlock_page(page);
89017 if (page != swapcache) {
89018 /*
89019@@ -3151,6 +3362,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
89020
89021 /* No need to invalidate - it was non-present before */
89022 update_mmu_cache(vma, address, page_table);
89023+
89024+#ifdef CONFIG_PAX_SEGMEXEC
89025+ pax_mirror_anon_pte(vma, address, page, ptl);
89026+#endif
89027+
89028 unlock:
89029 pte_unmap_unlock(page_table, ptl);
89030 out:
89031@@ -3170,40 +3386,6 @@ out_release:
89032 }
89033
89034 /*
89035- * This is like a special single-page "expand_{down|up}wards()",
89036- * except we must first make sure that 'address{-|+}PAGE_SIZE'
89037- * doesn't hit another vma.
89038- */
89039-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
89040-{
89041- address &= PAGE_MASK;
89042- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
89043- struct vm_area_struct *prev = vma->vm_prev;
89044-
89045- /*
89046- * Is there a mapping abutting this one below?
89047- *
89048- * That's only ok if it's the same stack mapping
89049- * that has gotten split..
89050- */
89051- if (prev && prev->vm_end == address)
89052- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
89053-
89054- expand_downwards(vma, address - PAGE_SIZE);
89055- }
89056- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
89057- struct vm_area_struct *next = vma->vm_next;
89058-
89059- /* As VM_GROWSDOWN but s/below/above/ */
89060- if (next && next->vm_start == address + PAGE_SIZE)
89061- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
89062-
89063- expand_upwards(vma, address + PAGE_SIZE);
89064- }
89065- return 0;
89066-}
89067-
89068-/*
89069 * We enter with non-exclusive mmap_sem (to exclude vma changes,
89070 * but allow concurrent faults), and pte mapped but not yet locked.
89071 * We return with mmap_sem still held, but pte unmapped and unlocked.
89072@@ -3212,27 +3394,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
89073 unsigned long address, pte_t *page_table, pmd_t *pmd,
89074 unsigned int flags)
89075 {
89076- struct page *page;
89077+ struct page *page = NULL;
89078 spinlock_t *ptl;
89079 pte_t entry;
89080
89081- pte_unmap(page_table);
89082-
89083- /* Check if we need to add a guard page to the stack */
89084- if (check_stack_guard_page(vma, address) < 0)
89085- return VM_FAULT_SIGBUS;
89086-
89087- /* Use the zero-page for reads */
89088 if (!(flags & FAULT_FLAG_WRITE)) {
89089 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
89090 vma->vm_page_prot));
89091- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
89092+ ptl = pte_lockptr(mm, pmd);
89093+ spin_lock(ptl);
89094 if (!pte_none(*page_table))
89095 goto unlock;
89096 goto setpte;
89097 }
89098
89099 /* Allocate our own private page. */
89100+ pte_unmap(page_table);
89101+
89102 if (unlikely(anon_vma_prepare(vma)))
89103 goto oom;
89104 page = alloc_zeroed_user_highpage_movable(vma, address);
89105@@ -3256,6 +3434,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
89106 if (!pte_none(*page_table))
89107 goto release;
89108
89109+#ifdef CONFIG_PAX_SEGMEXEC
89110+ if (pax_find_mirror_vma(vma))
89111+ BUG_ON(!trylock_page(page));
89112+#endif
89113+
89114 inc_mm_counter_fast(mm, MM_ANONPAGES);
89115 page_add_new_anon_rmap(page, vma, address);
89116 setpte:
89117@@ -3263,6 +3446,12 @@ setpte:
89118
89119 /* No need to invalidate - it was non-present before */
89120 update_mmu_cache(vma, address, page_table);
89121+
89122+#ifdef CONFIG_PAX_SEGMEXEC
89123+ if (page)
89124+ pax_mirror_anon_pte(vma, address, page, ptl);
89125+#endif
89126+
89127 unlock:
89128 pte_unmap_unlock(page_table, ptl);
89129 return 0;
89130@@ -3406,6 +3595,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
89131 */
89132 /* Only go through if we didn't race with anybody else... */
89133 if (likely(pte_same(*page_table, orig_pte))) {
89134+
89135+#ifdef CONFIG_PAX_SEGMEXEC
89136+ if (anon && pax_find_mirror_vma(vma))
89137+ BUG_ON(!trylock_page(page));
89138+#endif
89139+
89140 flush_icache_page(vma, page);
89141 entry = mk_pte(page, vma->vm_page_prot);
89142 if (flags & FAULT_FLAG_WRITE)
89143@@ -3427,6 +3622,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
89144
89145 /* no need to invalidate: a not-present page won't be cached */
89146 update_mmu_cache(vma, address, page_table);
89147+
89148+#ifdef CONFIG_PAX_SEGMEXEC
89149+ if (anon)
89150+ pax_mirror_anon_pte(vma, address, page, ptl);
89151+ else
89152+ pax_mirror_file_pte(vma, address, page, ptl);
89153+#endif
89154+
89155 } else {
89156 if (cow_page)
89157 mem_cgroup_uncharge_page(cow_page);
89158@@ -3737,6 +3940,12 @@ static int handle_pte_fault(struct mm_struct *mm,
89159 if (flags & FAULT_FLAG_WRITE)
89160 flush_tlb_fix_spurious_fault(vma, address);
89161 }
89162+
89163+#ifdef CONFIG_PAX_SEGMEXEC
89164+ pax_mirror_pte(vma, address, pte, pmd, ptl);
89165+ return 0;
89166+#endif
89167+
89168 unlock:
89169 pte_unmap_unlock(pte, ptl);
89170 return 0;
89171@@ -3753,9 +3962,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
89172 pmd_t *pmd;
89173 pte_t *pte;
89174
89175+#ifdef CONFIG_PAX_SEGMEXEC
89176+ struct vm_area_struct *vma_m;
89177+#endif
89178+
89179 if (unlikely(is_vm_hugetlb_page(vma)))
89180 return hugetlb_fault(mm, vma, address, flags);
89181
89182+#ifdef CONFIG_PAX_SEGMEXEC
89183+ vma_m = pax_find_mirror_vma(vma);
89184+ if (vma_m) {
89185+ unsigned long address_m;
89186+ pgd_t *pgd_m;
89187+ pud_t *pud_m;
89188+ pmd_t *pmd_m;
89189+
89190+ if (vma->vm_start > vma_m->vm_start) {
89191+ address_m = address;
89192+ address -= SEGMEXEC_TASK_SIZE;
89193+ vma = vma_m;
89194+ } else
89195+ address_m = address + SEGMEXEC_TASK_SIZE;
89196+
89197+ pgd_m = pgd_offset(mm, address_m);
89198+ pud_m = pud_alloc(mm, pgd_m, address_m);
89199+ if (!pud_m)
89200+ return VM_FAULT_OOM;
89201+ pmd_m = pmd_alloc(mm, pud_m, address_m);
89202+ if (!pmd_m)
89203+ return VM_FAULT_OOM;
89204+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
89205+ return VM_FAULT_OOM;
89206+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
89207+ }
89208+#endif
89209+
89210 retry:
89211 pgd = pgd_offset(mm, address);
89212 pud = pud_alloc(mm, pgd, address);
89213@@ -3894,6 +4135,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
89214 spin_unlock(&mm->page_table_lock);
89215 return 0;
89216 }
89217+
89218+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
89219+{
89220+ pud_t *new = pud_alloc_one(mm, address);
89221+ if (!new)
89222+ return -ENOMEM;
89223+
89224+ smp_wmb(); /* See comment in __pte_alloc */
89225+
89226+ spin_lock(&mm->page_table_lock);
89227+ if (pgd_present(*pgd)) /* Another has populated it */
89228+ pud_free(mm, new);
89229+ else
89230+ pgd_populate_kernel(mm, pgd, new);
89231+ spin_unlock(&mm->page_table_lock);
89232+ return 0;
89233+}
89234 #endif /* __PAGETABLE_PUD_FOLDED */
89235
89236 #ifndef __PAGETABLE_PMD_FOLDED
89237@@ -3924,6 +4182,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
89238 spin_unlock(&mm->page_table_lock);
89239 return 0;
89240 }
89241+
89242+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
89243+{
89244+ pmd_t *new = pmd_alloc_one(mm, address);
89245+ if (!new)
89246+ return -ENOMEM;
89247+
89248+ smp_wmb(); /* See comment in __pte_alloc */
89249+
89250+ spin_lock(&mm->page_table_lock);
89251+#ifndef __ARCH_HAS_4LEVEL_HACK
89252+ if (pud_present(*pud)) /* Another has populated it */
89253+ pmd_free(mm, new);
89254+ else
89255+ pud_populate_kernel(mm, pud, new);
89256+#else
89257+ if (pgd_present(*pud)) /* Another has populated it */
89258+ pmd_free(mm, new);
89259+ else
89260+ pgd_populate_kernel(mm, pud, new);
89261+#endif /* __ARCH_HAS_4LEVEL_HACK */
89262+ spin_unlock(&mm->page_table_lock);
89263+ return 0;
89264+}
89265 #endif /* __PAGETABLE_PMD_FOLDED */
89266
89267 #if !defined(__HAVE_ARCH_GATE_AREA)
89268@@ -3937,7 +4219,7 @@ static int __init gate_vma_init(void)
89269 gate_vma.vm_start = FIXADDR_USER_START;
89270 gate_vma.vm_end = FIXADDR_USER_END;
89271 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
89272- gate_vma.vm_page_prot = __P101;
89273+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
89274
89275 return 0;
89276 }
89277@@ -4071,8 +4353,8 @@ out:
89278 return ret;
89279 }
89280
89281-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
89282- void *buf, int len, int write)
89283+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
89284+ void *buf, size_t len, int write)
89285 {
89286 resource_size_t phys_addr;
89287 unsigned long prot = 0;
89288@@ -4098,8 +4380,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
89289 * Access another process' address space as given in mm. If non-NULL, use the
89290 * given task for page fault accounting.
89291 */
89292-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89293- unsigned long addr, void *buf, int len, int write)
89294+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89295+ unsigned long addr, void *buf, size_t len, int write)
89296 {
89297 struct vm_area_struct *vma;
89298 void *old_buf = buf;
89299@@ -4107,7 +4389,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89300 down_read(&mm->mmap_sem);
89301 /* ignore errors, just check how much was successfully transferred */
89302 while (len) {
89303- int bytes, ret, offset;
89304+ ssize_t bytes, ret, offset;
89305 void *maddr;
89306 struct page *page = NULL;
89307
89308@@ -4166,8 +4448,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89309 *
89310 * The caller must hold a reference on @mm.
89311 */
89312-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89313- void *buf, int len, int write)
89314+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
89315+ void *buf, size_t len, int write)
89316 {
89317 return __access_remote_vm(NULL, mm, addr, buf, len, write);
89318 }
89319@@ -4177,11 +4459,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89320 * Source/target buffer must be kernel space,
89321 * Do not walk the page table directly, use get_user_pages
89322 */
89323-int access_process_vm(struct task_struct *tsk, unsigned long addr,
89324- void *buf, int len, int write)
89325+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
89326+ void *buf, size_t len, int write)
89327 {
89328 struct mm_struct *mm;
89329- int ret;
89330+ ssize_t ret;
89331
89332 mm = get_task_mm(tsk);
89333 if (!mm)
89334diff --git a/mm/mempolicy.c b/mm/mempolicy.c
89335index 0472964..7d5a0ea 100644
89336--- a/mm/mempolicy.c
89337+++ b/mm/mempolicy.c
89338@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
89339 unsigned long vmstart;
89340 unsigned long vmend;
89341
89342+#ifdef CONFIG_PAX_SEGMEXEC
89343+ struct vm_area_struct *vma_m;
89344+#endif
89345+
89346 vma = find_vma(mm, start);
89347 if (!vma || vma->vm_start > start)
89348 return -EFAULT;
89349@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
89350 err = vma_replace_policy(vma, new_pol);
89351 if (err)
89352 goto out;
89353+
89354+#ifdef CONFIG_PAX_SEGMEXEC
89355+ vma_m = pax_find_mirror_vma(vma);
89356+ if (vma_m) {
89357+ err = vma_replace_policy(vma_m, new_pol);
89358+ if (err)
89359+ goto out;
89360+ }
89361+#endif
89362+
89363 }
89364
89365 out:
89366@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
89367
89368 if (end < start)
89369 return -EINVAL;
89370+
89371+#ifdef CONFIG_PAX_SEGMEXEC
89372+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
89373+ if (end > SEGMEXEC_TASK_SIZE)
89374+ return -EINVAL;
89375+ } else
89376+#endif
89377+
89378+ if (end > TASK_SIZE)
89379+ return -EINVAL;
89380+
89381 if (end == start)
89382 return 0;
89383
89384@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
89385 */
89386 tcred = __task_cred(task);
89387 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
89388- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
89389- !capable(CAP_SYS_NICE)) {
89390+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
89391 rcu_read_unlock();
89392 err = -EPERM;
89393 goto out_put;
89394@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
89395 goto out;
89396 }
89397
89398+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
89399+ if (mm != current->mm &&
89400+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
89401+ mmput(mm);
89402+ err = -EPERM;
89403+ goto out;
89404+ }
89405+#endif
89406+
89407 err = do_migrate_pages(mm, old, new,
89408 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
89409
89410diff --git a/mm/migrate.c b/mm/migrate.c
89411index c046927..6996b40 100644
89412--- a/mm/migrate.c
89413+++ b/mm/migrate.c
89414@@ -1404,8 +1404,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
89415 */
89416 tcred = __task_cred(task);
89417 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
89418- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
89419- !capable(CAP_SYS_NICE)) {
89420+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
89421 rcu_read_unlock();
89422 err = -EPERM;
89423 goto out;
89424diff --git a/mm/mlock.c b/mm/mlock.c
89425index d480cd6..0f98458 100644
89426--- a/mm/mlock.c
89427+++ b/mm/mlock.c
89428@@ -14,6 +14,7 @@
89429 #include <linux/pagevec.h>
89430 #include <linux/mempolicy.h>
89431 #include <linux/syscalls.h>
89432+#include <linux/security.h>
89433 #include <linux/sched.h>
89434 #include <linux/export.h>
89435 #include <linux/rmap.h>
89436@@ -568,7 +569,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
89437 {
89438 unsigned long nstart, end, tmp;
89439 struct vm_area_struct * vma, * prev;
89440- int error;
89441+ int error = 0;
89442
89443 VM_BUG_ON(start & ~PAGE_MASK);
89444 VM_BUG_ON(len != PAGE_ALIGN(len));
89445@@ -577,6 +578,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
89446 return -EINVAL;
89447 if (end == start)
89448 return 0;
89449+ if (end > TASK_SIZE)
89450+ return -EINVAL;
89451+
89452 vma = find_vma(current->mm, start);
89453 if (!vma || vma->vm_start > start)
89454 return -ENOMEM;
89455@@ -588,6 +592,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
89456 for (nstart = start ; ; ) {
89457 vm_flags_t newflags;
89458
89459+#ifdef CONFIG_PAX_SEGMEXEC
89460+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
89461+ break;
89462+#endif
89463+
89464 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
89465
89466 newflags = vma->vm_flags & ~VM_LOCKED;
89467@@ -700,6 +709,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
89468 lock_limit >>= PAGE_SHIFT;
89469
89470 /* check against resource limits */
89471+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
89472 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
89473 error = do_mlock(start, len, 1);
89474 up_write(&current->mm->mmap_sem);
89475@@ -734,6 +744,11 @@ static int do_mlockall(int flags)
89476 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
89477 vm_flags_t newflags;
89478
89479+#ifdef CONFIG_PAX_SEGMEXEC
89480+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
89481+ break;
89482+#endif
89483+
89484 newflags = vma->vm_flags & ~VM_LOCKED;
89485 if (flags & MCL_CURRENT)
89486 newflags |= VM_LOCKED;
89487@@ -767,6 +782,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
89488 lock_limit >>= PAGE_SHIFT;
89489
89490 ret = -ENOMEM;
89491+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
89492 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
89493 capable(CAP_IPC_LOCK))
89494 ret = do_mlockall(flags);
89495diff --git a/mm/mmap.c b/mm/mmap.c
89496index 362e5f1..8968e02 100644
89497--- a/mm/mmap.c
89498+++ b/mm/mmap.c
89499@@ -36,6 +36,7 @@
89500 #include <linux/sched/sysctl.h>
89501 #include <linux/notifier.h>
89502 #include <linux/memory.h>
89503+#include <linux/random.h>
89504
89505 #include <asm/uaccess.h>
89506 #include <asm/cacheflush.h>
89507@@ -52,6 +53,16 @@
89508 #define arch_rebalance_pgtables(addr, len) (addr)
89509 #endif
89510
89511+static inline void verify_mm_writelocked(struct mm_struct *mm)
89512+{
89513+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
89514+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
89515+ up_read(&mm->mmap_sem);
89516+ BUG();
89517+ }
89518+#endif
89519+}
89520+
89521 static void unmap_region(struct mm_struct *mm,
89522 struct vm_area_struct *vma, struct vm_area_struct *prev,
89523 unsigned long start, unsigned long end);
89524@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
89525 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
89526 *
89527 */
89528-pgprot_t protection_map[16] = {
89529+pgprot_t protection_map[16] __read_only = {
89530 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
89531 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
89532 };
89533
89534-pgprot_t vm_get_page_prot(unsigned long vm_flags)
89535+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
89536 {
89537- return __pgprot(pgprot_val(protection_map[vm_flags &
89538+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
89539 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
89540 pgprot_val(arch_vm_get_page_prot(vm_flags)));
89541+
89542+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
89543+ if (!(__supported_pte_mask & _PAGE_NX) &&
89544+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
89545+ (vm_flags & (VM_READ | VM_WRITE)))
89546+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
89547+#endif
89548+
89549+ return prot;
89550 }
89551 EXPORT_SYMBOL(vm_get_page_prot);
89552
89553@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
89554 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
89555 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
89556 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
89557+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
89558 /*
89559 * Make sure vm_committed_as in one cacheline and not cacheline shared with
89560 * other variables. It can be updated by several CPUs frequently.
89561@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
89562 struct vm_area_struct *next = vma->vm_next;
89563
89564 might_sleep();
89565+ BUG_ON(vma->vm_mirror);
89566 if (vma->vm_ops && vma->vm_ops->close)
89567 vma->vm_ops->close(vma);
89568 if (vma->vm_file)
89569@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
89570 * not page aligned -Ram Gupta
89571 */
89572 rlim = rlimit(RLIMIT_DATA);
89573+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
89574 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
89575 (mm->end_data - mm->start_data) > rlim)
89576 goto out;
89577@@ -933,6 +956,12 @@ static int
89578 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
89579 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
89580 {
89581+
89582+#ifdef CONFIG_PAX_SEGMEXEC
89583+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
89584+ return 0;
89585+#endif
89586+
89587 if (is_mergeable_vma(vma, file, vm_flags) &&
89588 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
89589 if (vma->vm_pgoff == vm_pgoff)
89590@@ -952,6 +981,12 @@ static int
89591 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
89592 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
89593 {
89594+
89595+#ifdef CONFIG_PAX_SEGMEXEC
89596+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
89597+ return 0;
89598+#endif
89599+
89600 if (is_mergeable_vma(vma, file, vm_flags) &&
89601 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
89602 pgoff_t vm_pglen;
89603@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
89604 struct vm_area_struct *vma_merge(struct mm_struct *mm,
89605 struct vm_area_struct *prev, unsigned long addr,
89606 unsigned long end, unsigned long vm_flags,
89607- struct anon_vma *anon_vma, struct file *file,
89608+ struct anon_vma *anon_vma, struct file *file,
89609 pgoff_t pgoff, struct mempolicy *policy)
89610 {
89611 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
89612 struct vm_area_struct *area, *next;
89613 int err;
89614
89615+#ifdef CONFIG_PAX_SEGMEXEC
89616+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
89617+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
89618+
89619+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
89620+#endif
89621+
89622 /*
89623 * We later require that vma->vm_flags == vm_flags,
89624 * so this tests vma->vm_flags & VM_SPECIAL, too.
89625@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
89626 if (next && next->vm_end == end) /* cases 6, 7, 8 */
89627 next = next->vm_next;
89628
89629+#ifdef CONFIG_PAX_SEGMEXEC
89630+ if (prev)
89631+ prev_m = pax_find_mirror_vma(prev);
89632+ if (area)
89633+ area_m = pax_find_mirror_vma(area);
89634+ if (next)
89635+ next_m = pax_find_mirror_vma(next);
89636+#endif
89637+
89638 /*
89639 * Can it merge with the predecessor?
89640 */
89641@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
89642 /* cases 1, 6 */
89643 err = vma_adjust(prev, prev->vm_start,
89644 next->vm_end, prev->vm_pgoff, NULL);
89645- } else /* cases 2, 5, 7 */
89646+
89647+#ifdef CONFIG_PAX_SEGMEXEC
89648+ if (!err && prev_m)
89649+ err = vma_adjust(prev_m, prev_m->vm_start,
89650+ next_m->vm_end, prev_m->vm_pgoff, NULL);
89651+#endif
89652+
89653+ } else { /* cases 2, 5, 7 */
89654 err = vma_adjust(prev, prev->vm_start,
89655 end, prev->vm_pgoff, NULL);
89656+
89657+#ifdef CONFIG_PAX_SEGMEXEC
89658+ if (!err && prev_m)
89659+ err = vma_adjust(prev_m, prev_m->vm_start,
89660+ end_m, prev_m->vm_pgoff, NULL);
89661+#endif
89662+
89663+ }
89664 if (err)
89665 return NULL;
89666 khugepaged_enter_vma_merge(prev);
89667@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
89668 mpol_equal(policy, vma_policy(next)) &&
89669 can_vma_merge_before(next, vm_flags,
89670 anon_vma, file, pgoff+pglen)) {
89671- if (prev && addr < prev->vm_end) /* case 4 */
89672+ if (prev && addr < prev->vm_end) { /* case 4 */
89673 err = vma_adjust(prev, prev->vm_start,
89674 addr, prev->vm_pgoff, NULL);
89675- else /* cases 3, 8 */
89676+
89677+#ifdef CONFIG_PAX_SEGMEXEC
89678+ if (!err && prev_m)
89679+ err = vma_adjust(prev_m, prev_m->vm_start,
89680+ addr_m, prev_m->vm_pgoff, NULL);
89681+#endif
89682+
89683+ } else { /* cases 3, 8 */
89684 err = vma_adjust(area, addr, next->vm_end,
89685 next->vm_pgoff - pglen, NULL);
89686+
89687+#ifdef CONFIG_PAX_SEGMEXEC
89688+ if (!err && area_m)
89689+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
89690+ next_m->vm_pgoff - pglen, NULL);
89691+#endif
89692+
89693+ }
89694 if (err)
89695 return NULL;
89696 khugepaged_enter_vma_merge(area);
89697@@ -1165,8 +1246,10 @@ none:
89698 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
89699 struct file *file, long pages)
89700 {
89701- const unsigned long stack_flags
89702- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
89703+
89704+#ifdef CONFIG_PAX_RANDMMAP
89705+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
89706+#endif
89707
89708 mm->total_vm += pages;
89709
89710@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
89711 mm->shared_vm += pages;
89712 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
89713 mm->exec_vm += pages;
89714- } else if (flags & stack_flags)
89715+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
89716 mm->stack_vm += pages;
89717 }
89718 #endif /* CONFIG_PROC_FS */
89719@@ -1212,7 +1295,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89720 * (the exception is when the underlying filesystem is noexec
89721 * mounted, in which case we dont add PROT_EXEC.)
89722 */
89723- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
89724+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
89725 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
89726 prot |= PROT_EXEC;
89727
89728@@ -1238,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89729 /* Obtain the address to map to. we verify (or select) it and ensure
89730 * that it represents a valid section of the address space.
89731 */
89732- addr = get_unmapped_area(file, addr, len, pgoff, flags);
89733+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
89734 if (addr & ~PAGE_MASK)
89735 return addr;
89736
89737@@ -1249,6 +1332,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89738 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
89739 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
89740
89741+#ifdef CONFIG_PAX_MPROTECT
89742+ if (mm->pax_flags & MF_PAX_MPROTECT) {
89743+
89744+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
89745+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
89746+ mm->binfmt->handle_mmap)
89747+ mm->binfmt->handle_mmap(file);
89748+#endif
89749+
89750+#ifndef CONFIG_PAX_MPROTECT_COMPAT
89751+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
89752+ gr_log_rwxmmap(file);
89753+
89754+#ifdef CONFIG_PAX_EMUPLT
89755+ vm_flags &= ~VM_EXEC;
89756+#else
89757+ return -EPERM;
89758+#endif
89759+
89760+ }
89761+
89762+ if (!(vm_flags & VM_EXEC))
89763+ vm_flags &= ~VM_MAYEXEC;
89764+#else
89765+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
89766+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
89767+#endif
89768+ else
89769+ vm_flags &= ~VM_MAYWRITE;
89770+ }
89771+#endif
89772+
89773+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
89774+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
89775+ vm_flags &= ~VM_PAGEEXEC;
89776+#endif
89777+
89778 if (flags & MAP_LOCKED)
89779 if (!can_do_mlock())
89780 return -EPERM;
89781@@ -1260,6 +1380,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89782 locked += mm->locked_vm;
89783 lock_limit = rlimit(RLIMIT_MEMLOCK);
89784 lock_limit >>= PAGE_SHIFT;
89785+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89786 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
89787 return -EAGAIN;
89788 }
89789@@ -1344,6 +1465,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89790 vm_flags |= VM_NORESERVE;
89791 }
89792
89793+ if (!gr_acl_handle_mmap(file, prot))
89794+ return -EACCES;
89795+
89796 addr = mmap_region(file, addr, len, vm_flags, pgoff);
89797 if (!IS_ERR_VALUE(addr) &&
89798 ((vm_flags & VM_LOCKED) ||
89799@@ -1437,7 +1561,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
89800 vm_flags_t vm_flags = vma->vm_flags;
89801
89802 /* If it was private or non-writable, the write bit is already clear */
89803- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
89804+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
89805 return 0;
89806
89807 /* The backer wishes to know when pages are first written to? */
89808@@ -1483,7 +1607,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
89809 struct rb_node **rb_link, *rb_parent;
89810 unsigned long charged = 0;
89811
89812+#ifdef CONFIG_PAX_SEGMEXEC
89813+ struct vm_area_struct *vma_m = NULL;
89814+#endif
89815+
89816+ /*
89817+ * mm->mmap_sem is required to protect against another thread
89818+ * changing the mappings in case we sleep.
89819+ */
89820+ verify_mm_writelocked(mm);
89821+
89822 /* Check against address space limit. */
89823+
89824+#ifdef CONFIG_PAX_RANDMMAP
89825+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
89826+#endif
89827+
89828 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
89829 unsigned long nr_pages;
89830
89831@@ -1502,11 +1641,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
89832
89833 /* Clear old maps */
89834 error = -ENOMEM;
89835-munmap_back:
89836 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
89837 if (do_munmap(mm, addr, len))
89838 return -ENOMEM;
89839- goto munmap_back;
89840+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
89841 }
89842
89843 /*
89844@@ -1537,6 +1675,16 @@ munmap_back:
89845 goto unacct_error;
89846 }
89847
89848+#ifdef CONFIG_PAX_SEGMEXEC
89849+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
89850+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89851+ if (!vma_m) {
89852+ error = -ENOMEM;
89853+ goto free_vma;
89854+ }
89855+ }
89856+#endif
89857+
89858 vma->vm_mm = mm;
89859 vma->vm_start = addr;
89860 vma->vm_end = addr + len;
89861@@ -1556,6 +1704,13 @@ munmap_back:
89862 if (error)
89863 goto unmap_and_free_vma;
89864
89865+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
89866+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
89867+ vma->vm_flags |= VM_PAGEEXEC;
89868+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
89869+ }
89870+#endif
89871+
89872 /* Can addr have changed??
89873 *
89874 * Answer: Yes, several device drivers can do it in their
89875@@ -1589,6 +1744,12 @@ munmap_back:
89876 }
89877
89878 vma_link(mm, vma, prev, rb_link, rb_parent);
89879+
89880+#ifdef CONFIG_PAX_SEGMEXEC
89881+ if (vma_m)
89882+ BUG_ON(pax_mirror_vma(vma_m, vma));
89883+#endif
89884+
89885 /* Once vma denies write, undo our temporary denial count */
89886 if (vm_flags & VM_DENYWRITE)
89887 allow_write_access(file);
89888@@ -1597,6 +1758,7 @@ out:
89889 perf_event_mmap(vma);
89890
89891 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
89892+ track_exec_limit(mm, addr, addr + len, vm_flags);
89893 if (vm_flags & VM_LOCKED) {
89894 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
89895 vma == get_gate_vma(current->mm)))
89896@@ -1629,6 +1791,12 @@ unmap_and_free_vma:
89897 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
89898 charged = 0;
89899 free_vma:
89900+
89901+#ifdef CONFIG_PAX_SEGMEXEC
89902+ if (vma_m)
89903+ kmem_cache_free(vm_area_cachep, vma_m);
89904+#endif
89905+
89906 kmem_cache_free(vm_area_cachep, vma);
89907 unacct_error:
89908 if (charged)
89909@@ -1636,7 +1804,63 @@ unacct_error:
89910 return error;
89911 }
89912
89913-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89914+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
89915+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
89916+{
89917+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
89918+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
89919+
89920+ return 0;
89921+}
89922+#endif
89923+
89924+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
89925+{
89926+ if (!vma) {
89927+#ifdef CONFIG_STACK_GROWSUP
89928+ if (addr > sysctl_heap_stack_gap)
89929+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
89930+ else
89931+ vma = find_vma(current->mm, 0);
89932+ if (vma && (vma->vm_flags & VM_GROWSUP))
89933+ return false;
89934+#endif
89935+ return true;
89936+ }
89937+
89938+ if (addr + len > vma->vm_start)
89939+ return false;
89940+
89941+ if (vma->vm_flags & VM_GROWSDOWN)
89942+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
89943+#ifdef CONFIG_STACK_GROWSUP
89944+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
89945+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
89946+#endif
89947+ else if (offset)
89948+ return offset <= vma->vm_start - addr - len;
89949+
89950+ return true;
89951+}
89952+
89953+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
89954+{
89955+ if (vma->vm_start < len)
89956+ return -ENOMEM;
89957+
89958+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
89959+ if (offset <= vma->vm_start - len)
89960+ return vma->vm_start - len - offset;
89961+ else
89962+ return -ENOMEM;
89963+ }
89964+
89965+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
89966+ return vma->vm_start - len - sysctl_heap_stack_gap;
89967+ return -ENOMEM;
89968+}
89969+
89970+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
89971 {
89972 /*
89973 * We implement the search by looking for an rbtree node that
89974@@ -1684,11 +1908,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89975 }
89976 }
89977
89978- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
89979+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
89980 check_current:
89981 /* Check if current node has a suitable gap */
89982 if (gap_start > high_limit)
89983 return -ENOMEM;
89984+
89985+ if (gap_end - gap_start > info->threadstack_offset)
89986+ gap_start += info->threadstack_offset;
89987+ else
89988+ gap_start = gap_end;
89989+
89990+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89991+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89992+ gap_start += sysctl_heap_stack_gap;
89993+ else
89994+ gap_start = gap_end;
89995+ }
89996+ if (vma->vm_flags & VM_GROWSDOWN) {
89997+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89998+ gap_end -= sysctl_heap_stack_gap;
89999+ else
90000+ gap_end = gap_start;
90001+ }
90002 if (gap_end >= low_limit && gap_end - gap_start >= length)
90003 goto found;
90004
90005@@ -1738,7 +1980,7 @@ found:
90006 return gap_start;
90007 }
90008
90009-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
90010+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
90011 {
90012 struct mm_struct *mm = current->mm;
90013 struct vm_area_struct *vma;
90014@@ -1792,6 +2034,24 @@ check_current:
90015 gap_end = vma->vm_start;
90016 if (gap_end < low_limit)
90017 return -ENOMEM;
90018+
90019+ if (gap_end - gap_start > info->threadstack_offset)
90020+ gap_end -= info->threadstack_offset;
90021+ else
90022+ gap_end = gap_start;
90023+
90024+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
90025+ if (gap_end - gap_start > sysctl_heap_stack_gap)
90026+ gap_start += sysctl_heap_stack_gap;
90027+ else
90028+ gap_start = gap_end;
90029+ }
90030+ if (vma->vm_flags & VM_GROWSDOWN) {
90031+ if (gap_end - gap_start > sysctl_heap_stack_gap)
90032+ gap_end -= sysctl_heap_stack_gap;
90033+ else
90034+ gap_end = gap_start;
90035+ }
90036 if (gap_start <= high_limit && gap_end - gap_start >= length)
90037 goto found;
90038
90039@@ -1855,6 +2115,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
90040 struct mm_struct *mm = current->mm;
90041 struct vm_area_struct *vma;
90042 struct vm_unmapped_area_info info;
90043+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
90044
90045 if (len > TASK_SIZE - mmap_min_addr)
90046 return -ENOMEM;
90047@@ -1862,19 +2123,30 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
90048 if (flags & MAP_FIXED)
90049 return addr;
90050
90051+#ifdef CONFIG_PAX_RANDMMAP
90052+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
90053+#endif
90054+
90055 if (addr) {
90056 addr = PAGE_ALIGN(addr);
90057 vma = find_vma(mm, addr);
90058 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
90059- (!vma || addr + len <= vma->vm_start))
90060+ check_heap_stack_gap(vma, addr, len, offset))
90061 return addr;
90062 }
90063
90064 info.flags = 0;
90065 info.length = len;
90066 info.low_limit = TASK_UNMAPPED_BASE;
90067+
90068+#ifdef CONFIG_PAX_RANDMMAP
90069+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90070+ info.low_limit += mm->delta_mmap;
90071+#endif
90072+
90073 info.high_limit = TASK_SIZE;
90074 info.align_mask = 0;
90075+ info.threadstack_offset = offset;
90076 return vm_unmapped_area(&info);
90077 }
90078 #endif
90079@@ -1893,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
90080 struct mm_struct *mm = current->mm;
90081 unsigned long addr = addr0;
90082 struct vm_unmapped_area_info info;
90083+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
90084
90085 /* requested length too big for entire address space */
90086 if (len > TASK_SIZE - mmap_min_addr)
90087@@ -1901,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
90088 if (flags & MAP_FIXED)
90089 return addr;
90090
90091+#ifdef CONFIG_PAX_RANDMMAP
90092+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
90093+#endif
90094+
90095 /* requesting a specific address */
90096 if (addr) {
90097 addr = PAGE_ALIGN(addr);
90098 vma = find_vma(mm, addr);
90099 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
90100- (!vma || addr + len <= vma->vm_start))
90101+ check_heap_stack_gap(vma, addr, len, offset))
90102 return addr;
90103 }
90104
90105@@ -1915,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
90106 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
90107 info.high_limit = mm->mmap_base;
90108 info.align_mask = 0;
90109+ info.threadstack_offset = offset;
90110 addr = vm_unmapped_area(&info);
90111
90112 /*
90113@@ -1927,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
90114 VM_BUG_ON(addr != -ENOMEM);
90115 info.flags = 0;
90116 info.low_limit = TASK_UNMAPPED_BASE;
90117+
90118+#ifdef CONFIG_PAX_RANDMMAP
90119+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90120+ info.low_limit += mm->delta_mmap;
90121+#endif
90122+
90123 info.high_limit = TASK_SIZE;
90124 addr = vm_unmapped_area(&info);
90125 }
90126@@ -2028,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
90127 return vma;
90128 }
90129
90130+#ifdef CONFIG_PAX_SEGMEXEC
90131+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
90132+{
90133+ struct vm_area_struct *vma_m;
90134+
90135+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
90136+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
90137+ BUG_ON(vma->vm_mirror);
90138+ return NULL;
90139+ }
90140+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
90141+ vma_m = vma->vm_mirror;
90142+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
90143+ BUG_ON(vma->vm_file != vma_m->vm_file);
90144+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
90145+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
90146+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
90147+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
90148+ return vma_m;
90149+}
90150+#endif
90151+
90152 /*
90153 * Verify that the stack growth is acceptable and
90154 * update accounting. This is shared with both the
90155@@ -2044,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
90156 return -ENOMEM;
90157
90158 /* Stack limit test */
90159+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
90160 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
90161 return -ENOMEM;
90162
90163@@ -2054,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
90164 locked = mm->locked_vm + grow;
90165 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
90166 limit >>= PAGE_SHIFT;
90167+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
90168 if (locked > limit && !capable(CAP_IPC_LOCK))
90169 return -ENOMEM;
90170 }
90171@@ -2083,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
90172 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
90173 * vma is the last one with address > vma->vm_end. Have to extend vma.
90174 */
90175+#ifndef CONFIG_IA64
90176+static
90177+#endif
90178 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
90179 {
90180 int error;
90181+ bool locknext;
90182
90183 if (!(vma->vm_flags & VM_GROWSUP))
90184 return -EFAULT;
90185
90186+ /* Also guard against wrapping around to address 0. */
90187+ if (address < PAGE_ALIGN(address+1))
90188+ address = PAGE_ALIGN(address+1);
90189+ else
90190+ return -ENOMEM;
90191+
90192 /*
90193 * We must make sure the anon_vma is allocated
90194 * so that the anon_vma locking is not a noop.
90195 */
90196 if (unlikely(anon_vma_prepare(vma)))
90197 return -ENOMEM;
90198+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
90199+ if (locknext && anon_vma_prepare(vma->vm_next))
90200+ return -ENOMEM;
90201 vma_lock_anon_vma(vma);
90202+ if (locknext)
90203+ vma_lock_anon_vma(vma->vm_next);
90204
90205 /*
90206 * vma->vm_start/vm_end cannot change under us because the caller
90207 * is required to hold the mmap_sem in read mode. We need the
90208- * anon_vma lock to serialize against concurrent expand_stacks.
90209- * Also guard against wrapping around to address 0.
90210+ * anon_vma locks to serialize against concurrent expand_stacks
90211+ * and expand_upwards.
90212 */
90213- if (address < PAGE_ALIGN(address+4))
90214- address = PAGE_ALIGN(address+4);
90215- else {
90216- vma_unlock_anon_vma(vma);
90217- return -ENOMEM;
90218- }
90219 error = 0;
90220
90221 /* Somebody else might have raced and expanded it already */
90222- if (address > vma->vm_end) {
90223+ 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)
90224+ error = -ENOMEM;
90225+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
90226 unsigned long size, grow;
90227
90228 size = address - vma->vm_start;
90229@@ -2148,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
90230 }
90231 }
90232 }
90233+ if (locknext)
90234+ vma_unlock_anon_vma(vma->vm_next);
90235 vma_unlock_anon_vma(vma);
90236 khugepaged_enter_vma_merge(vma);
90237 validate_mm(vma->vm_mm);
90238@@ -2162,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
90239 unsigned long address)
90240 {
90241 int error;
90242+ bool lockprev = false;
90243+ struct vm_area_struct *prev;
90244
90245 /*
90246 * We must make sure the anon_vma is allocated
90247@@ -2175,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
90248 if (error)
90249 return error;
90250
90251+ prev = vma->vm_prev;
90252+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
90253+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
90254+#endif
90255+ if (lockprev && anon_vma_prepare(prev))
90256+ return -ENOMEM;
90257+ if (lockprev)
90258+ vma_lock_anon_vma(prev);
90259+
90260 vma_lock_anon_vma(vma);
90261
90262 /*
90263@@ -2184,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
90264 */
90265
90266 /* Somebody else might have raced and expanded it already */
90267- if (address < vma->vm_start) {
90268+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
90269+ error = -ENOMEM;
90270+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
90271 unsigned long size, grow;
90272
90273+#ifdef CONFIG_PAX_SEGMEXEC
90274+ struct vm_area_struct *vma_m;
90275+
90276+ vma_m = pax_find_mirror_vma(vma);
90277+#endif
90278+
90279 size = vma->vm_end - address;
90280 grow = (vma->vm_start - address) >> PAGE_SHIFT;
90281
90282@@ -2211,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
90283 vma->vm_pgoff -= grow;
90284 anon_vma_interval_tree_post_update_vma(vma);
90285 vma_gap_update(vma);
90286+
90287+#ifdef CONFIG_PAX_SEGMEXEC
90288+ if (vma_m) {
90289+ anon_vma_interval_tree_pre_update_vma(vma_m);
90290+ vma_m->vm_start -= grow << PAGE_SHIFT;
90291+ vma_m->vm_pgoff -= grow;
90292+ anon_vma_interval_tree_post_update_vma(vma_m);
90293+ vma_gap_update(vma_m);
90294+ }
90295+#endif
90296+
90297 spin_unlock(&vma->vm_mm->page_table_lock);
90298
90299+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
90300 perf_event_mmap(vma);
90301 }
90302 }
90303 }
90304 vma_unlock_anon_vma(vma);
90305+ if (lockprev)
90306+ vma_unlock_anon_vma(prev);
90307 khugepaged_enter_vma_merge(vma);
90308 validate_mm(vma->vm_mm);
90309 return error;
90310@@ -2315,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
90311 do {
90312 long nrpages = vma_pages(vma);
90313
90314+#ifdef CONFIG_PAX_SEGMEXEC
90315+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
90316+ vma = remove_vma(vma);
90317+ continue;
90318+ }
90319+#endif
90320+
90321 if (vma->vm_flags & VM_ACCOUNT)
90322 nr_accounted += nrpages;
90323 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
90324@@ -2359,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
90325 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
90326 vma->vm_prev = NULL;
90327 do {
90328+
90329+#ifdef CONFIG_PAX_SEGMEXEC
90330+ if (vma->vm_mirror) {
90331+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
90332+ vma->vm_mirror->vm_mirror = NULL;
90333+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
90334+ vma->vm_mirror = NULL;
90335+ }
90336+#endif
90337+
90338 vma_rb_erase(vma, &mm->mm_rb);
90339 mm->map_count--;
90340 tail_vma = vma;
90341@@ -2384,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90342 struct vm_area_struct *new;
90343 int err = -ENOMEM;
90344
90345+#ifdef CONFIG_PAX_SEGMEXEC
90346+ struct vm_area_struct *vma_m, *new_m = NULL;
90347+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
90348+#endif
90349+
90350 if (is_vm_hugetlb_page(vma) && (addr &
90351 ~(huge_page_mask(hstate_vma(vma)))))
90352 return -EINVAL;
90353
90354+#ifdef CONFIG_PAX_SEGMEXEC
90355+ vma_m = pax_find_mirror_vma(vma);
90356+#endif
90357+
90358 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90359 if (!new)
90360 goto out_err;
90361
90362+#ifdef CONFIG_PAX_SEGMEXEC
90363+ if (vma_m) {
90364+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90365+ if (!new_m) {
90366+ kmem_cache_free(vm_area_cachep, new);
90367+ goto out_err;
90368+ }
90369+ }
90370+#endif
90371+
90372 /* most fields are the same, copy all, and then fixup */
90373 *new = *vma;
90374
90375@@ -2404,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90376 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
90377 }
90378
90379+#ifdef CONFIG_PAX_SEGMEXEC
90380+ if (vma_m) {
90381+ *new_m = *vma_m;
90382+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
90383+ new_m->vm_mirror = new;
90384+ new->vm_mirror = new_m;
90385+
90386+ if (new_below)
90387+ new_m->vm_end = addr_m;
90388+ else {
90389+ new_m->vm_start = addr_m;
90390+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
90391+ }
90392+ }
90393+#endif
90394+
90395 err = vma_dup_policy(vma, new);
90396 if (err)
90397 goto out_free_vma;
90398@@ -2423,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90399 else
90400 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
90401
90402+#ifdef CONFIG_PAX_SEGMEXEC
90403+ if (!err && vma_m) {
90404+ struct mempolicy *pol = vma_policy(new);
90405+
90406+ if (anon_vma_clone(new_m, vma_m))
90407+ goto out_free_mpol;
90408+
90409+ mpol_get(pol);
90410+ set_vma_policy(new_m, pol);
90411+
90412+ if (new_m->vm_file)
90413+ get_file(new_m->vm_file);
90414+
90415+ if (new_m->vm_ops && new_m->vm_ops->open)
90416+ new_m->vm_ops->open(new_m);
90417+
90418+ if (new_below)
90419+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
90420+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
90421+ else
90422+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
90423+
90424+ if (err) {
90425+ if (new_m->vm_ops && new_m->vm_ops->close)
90426+ new_m->vm_ops->close(new_m);
90427+ if (new_m->vm_file)
90428+ fput(new_m->vm_file);
90429+ mpol_put(pol);
90430+ }
90431+ }
90432+#endif
90433+
90434 /* Success. */
90435 if (!err)
90436 return 0;
90437@@ -2432,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90438 new->vm_ops->close(new);
90439 if (new->vm_file)
90440 fput(new->vm_file);
90441- unlink_anon_vmas(new);
90442 out_free_mpol:
90443 mpol_put(vma_policy(new));
90444 out_free_vma:
90445+
90446+#ifdef CONFIG_PAX_SEGMEXEC
90447+ if (new_m) {
90448+ unlink_anon_vmas(new_m);
90449+ kmem_cache_free(vm_area_cachep, new_m);
90450+ }
90451+#endif
90452+
90453+ unlink_anon_vmas(new);
90454 kmem_cache_free(vm_area_cachep, new);
90455 out_err:
90456 return err;
90457@@ -2448,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90458 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90459 unsigned long addr, int new_below)
90460 {
90461+
90462+#ifdef CONFIG_PAX_SEGMEXEC
90463+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
90464+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
90465+ if (mm->map_count >= sysctl_max_map_count-1)
90466+ return -ENOMEM;
90467+ } else
90468+#endif
90469+
90470 if (mm->map_count >= sysctl_max_map_count)
90471 return -ENOMEM;
90472
90473@@ -2459,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90474 * work. This now handles partial unmappings.
90475 * Jeremy Fitzhardinge <jeremy@goop.org>
90476 */
90477+#ifdef CONFIG_PAX_SEGMEXEC
90478 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90479 {
90480+ int ret = __do_munmap(mm, start, len);
90481+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
90482+ return ret;
90483+
90484+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
90485+}
90486+
90487+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90488+#else
90489+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90490+#endif
90491+{
90492 unsigned long end;
90493 struct vm_area_struct *vma, *prev, *last;
90494
90495+ /*
90496+ * mm->mmap_sem is required to protect against another thread
90497+ * changing the mappings in case we sleep.
90498+ */
90499+ verify_mm_writelocked(mm);
90500+
90501 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
90502 return -EINVAL;
90503
90504@@ -2538,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90505 /* Fix up all other VM information */
90506 remove_vma_list(mm, vma);
90507
90508+ track_exec_limit(mm, start, end, 0UL);
90509+
90510 return 0;
90511 }
90512
90513@@ -2546,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
90514 int ret;
90515 struct mm_struct *mm = current->mm;
90516
90517+
90518+#ifdef CONFIG_PAX_SEGMEXEC
90519+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
90520+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
90521+ return -EINVAL;
90522+#endif
90523+
90524 down_write(&mm->mmap_sem);
90525 ret = do_munmap(mm, start, len);
90526 up_write(&mm->mmap_sem);
90527@@ -2559,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
90528 return vm_munmap(addr, len);
90529 }
90530
90531-static inline void verify_mm_writelocked(struct mm_struct *mm)
90532-{
90533-#ifdef CONFIG_DEBUG_VM
90534- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
90535- WARN_ON(1);
90536- up_read(&mm->mmap_sem);
90537- }
90538-#endif
90539-}
90540-
90541 /*
90542 * this is really a simplified "do_mmap". it only handles
90543 * anonymous maps. eventually we may be able to do some
90544@@ -2582,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90545 struct rb_node ** rb_link, * rb_parent;
90546 pgoff_t pgoff = addr >> PAGE_SHIFT;
90547 int error;
90548+ unsigned long charged;
90549
90550 len = PAGE_ALIGN(len);
90551 if (!len)
90552@@ -2589,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90553
90554 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
90555
90556+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
90557+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
90558+ flags &= ~VM_EXEC;
90559+
90560+#ifdef CONFIG_PAX_MPROTECT
90561+ if (mm->pax_flags & MF_PAX_MPROTECT)
90562+ flags &= ~VM_MAYEXEC;
90563+#endif
90564+
90565+ }
90566+#endif
90567+
90568 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
90569 if (error & ~PAGE_MASK)
90570 return error;
90571
90572+ charged = len >> PAGE_SHIFT;
90573+
90574 /*
90575 * mlock MCL_FUTURE?
90576 */
90577 if (mm->def_flags & VM_LOCKED) {
90578 unsigned long locked, lock_limit;
90579- locked = len >> PAGE_SHIFT;
90580+ locked = charged;
90581 locked += mm->locked_vm;
90582 lock_limit = rlimit(RLIMIT_MEMLOCK);
90583 lock_limit >>= PAGE_SHIFT;
90584@@ -2615,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90585 /*
90586 * Clear old maps. this also does some error checking for us
90587 */
90588- munmap_back:
90589 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
90590 if (do_munmap(mm, addr, len))
90591 return -ENOMEM;
90592- goto munmap_back;
90593+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
90594 }
90595
90596 /* Check against address space limits *after* clearing old maps... */
90597- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
90598+ if (!may_expand_vm(mm, charged))
90599 return -ENOMEM;
90600
90601 if (mm->map_count > sysctl_max_map_count)
90602 return -ENOMEM;
90603
90604- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
90605+ if (security_vm_enough_memory_mm(mm, charged))
90606 return -ENOMEM;
90607
90608 /* Can we just expand an old private anonymous mapping? */
90609@@ -2643,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90610 */
90611 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90612 if (!vma) {
90613- vm_unacct_memory(len >> PAGE_SHIFT);
90614+ vm_unacct_memory(charged);
90615 return -ENOMEM;
90616 }
90617
90618@@ -2657,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90619 vma_link(mm, vma, prev, rb_link, rb_parent);
90620 out:
90621 perf_event_mmap(vma);
90622- mm->total_vm += len >> PAGE_SHIFT;
90623+ mm->total_vm += charged;
90624 if (flags & VM_LOCKED)
90625- mm->locked_vm += (len >> PAGE_SHIFT);
90626+ mm->locked_vm += charged;
90627 vma->vm_flags |= VM_SOFTDIRTY;
90628+ track_exec_limit(mm, addr, addr + len, flags);
90629 return addr;
90630 }
90631
90632@@ -2722,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
90633 while (vma) {
90634 if (vma->vm_flags & VM_ACCOUNT)
90635 nr_accounted += vma_pages(vma);
90636+ vma->vm_mirror = NULL;
90637 vma = remove_vma(vma);
90638 }
90639 vm_unacct_memory(nr_accounted);
90640@@ -2738,6 +3227,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
90641 struct vm_area_struct *prev;
90642 struct rb_node **rb_link, *rb_parent;
90643
90644+#ifdef CONFIG_PAX_SEGMEXEC
90645+ struct vm_area_struct *vma_m = NULL;
90646+#endif
90647+
90648+ if (security_mmap_addr(vma->vm_start))
90649+ return -EPERM;
90650+
90651 /*
90652 * The vm_pgoff of a purely anonymous vma should be irrelevant
90653 * until its first write fault, when page's anon_vma and index
90654@@ -2761,7 +3257,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
90655 security_vm_enough_memory_mm(mm, vma_pages(vma)))
90656 return -ENOMEM;
90657
90658+#ifdef CONFIG_PAX_SEGMEXEC
90659+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
90660+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90661+ if (!vma_m)
90662+ return -ENOMEM;
90663+ }
90664+#endif
90665+
90666 vma_link(mm, vma, prev, rb_link, rb_parent);
90667+
90668+#ifdef CONFIG_PAX_SEGMEXEC
90669+ if (vma_m)
90670+ BUG_ON(pax_mirror_vma(vma_m, vma));
90671+#endif
90672+
90673 return 0;
90674 }
90675
90676@@ -2780,6 +3290,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
90677 struct rb_node **rb_link, *rb_parent;
90678 bool faulted_in_anon_vma = true;
90679
90680+ BUG_ON(vma->vm_mirror);
90681+
90682 /*
90683 * If anonymous vma has not yet been faulted, update new pgoff
90684 * to match new location, to increase its chance of merging.
90685@@ -2844,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
90686 return NULL;
90687 }
90688
90689+#ifdef CONFIG_PAX_SEGMEXEC
90690+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
90691+{
90692+ struct vm_area_struct *prev_m;
90693+ struct rb_node **rb_link_m, *rb_parent_m;
90694+ struct mempolicy *pol_m;
90695+
90696+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
90697+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
90698+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
90699+ *vma_m = *vma;
90700+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
90701+ if (anon_vma_clone(vma_m, vma))
90702+ return -ENOMEM;
90703+ pol_m = vma_policy(vma_m);
90704+ mpol_get(pol_m);
90705+ set_vma_policy(vma_m, pol_m);
90706+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
90707+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
90708+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
90709+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
90710+ if (vma_m->vm_file)
90711+ get_file(vma_m->vm_file);
90712+ if (vma_m->vm_ops && vma_m->vm_ops->open)
90713+ vma_m->vm_ops->open(vma_m);
90714+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
90715+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
90716+ vma_m->vm_mirror = vma;
90717+ vma->vm_mirror = vma_m;
90718+ return 0;
90719+}
90720+#endif
90721+
90722 /*
90723 * Return true if the calling process may expand its vm space by the passed
90724 * number of pages
90725@@ -2855,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
90726
90727 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
90728
90729+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
90730 if (cur + npages > lim)
90731 return 0;
90732 return 1;
90733@@ -2925,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
90734 vma->vm_start = addr;
90735 vma->vm_end = addr + len;
90736
90737+#ifdef CONFIG_PAX_MPROTECT
90738+ if (mm->pax_flags & MF_PAX_MPROTECT) {
90739+#ifndef CONFIG_PAX_MPROTECT_COMPAT
90740+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
90741+ return -EPERM;
90742+ if (!(vm_flags & VM_EXEC))
90743+ vm_flags &= ~VM_MAYEXEC;
90744+#else
90745+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
90746+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
90747+#endif
90748+ else
90749+ vm_flags &= ~VM_MAYWRITE;
90750+ }
90751+#endif
90752+
90753 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
90754 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
90755
90756diff --git a/mm/mprotect.c b/mm/mprotect.c
90757index 6c3f56f..b2340b0 100644
90758--- a/mm/mprotect.c
90759+++ b/mm/mprotect.c
90760@@ -23,10 +23,18 @@
90761 #include <linux/mmu_notifier.h>
90762 #include <linux/migrate.h>
90763 #include <linux/perf_event.h>
90764+#include <linux/sched/sysctl.h>
90765+
90766+#ifdef CONFIG_PAX_MPROTECT
90767+#include <linux/elf.h>
90768+#include <linux/binfmts.h>
90769+#endif
90770+
90771 #include <asm/uaccess.h>
90772 #include <asm/pgtable.h>
90773 #include <asm/cacheflush.h>
90774 #include <asm/tlbflush.h>
90775+#include <asm/mmu_context.h>
90776
90777 #ifndef pgprot_modify
90778 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
90779@@ -241,6 +249,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
90780 return pages;
90781 }
90782
90783+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
90784+/* called while holding the mmap semaphor for writing except stack expansion */
90785+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
90786+{
90787+ unsigned long oldlimit, newlimit = 0UL;
90788+
90789+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
90790+ return;
90791+
90792+ spin_lock(&mm->page_table_lock);
90793+ oldlimit = mm->context.user_cs_limit;
90794+ if ((prot & VM_EXEC) && oldlimit < end)
90795+ /* USER_CS limit moved up */
90796+ newlimit = end;
90797+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
90798+ /* USER_CS limit moved down */
90799+ newlimit = start;
90800+
90801+ if (newlimit) {
90802+ mm->context.user_cs_limit = newlimit;
90803+
90804+#ifdef CONFIG_SMP
90805+ wmb();
90806+ cpus_clear(mm->context.cpu_user_cs_mask);
90807+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
90808+#endif
90809+
90810+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
90811+ }
90812+ spin_unlock(&mm->page_table_lock);
90813+ if (newlimit == end) {
90814+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
90815+
90816+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
90817+ if (is_vm_hugetlb_page(vma))
90818+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
90819+ else
90820+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
90821+ }
90822+}
90823+#endif
90824+
90825 int
90826 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90827 unsigned long start, unsigned long end, unsigned long newflags)
90828@@ -253,11 +303,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90829 int error;
90830 int dirty_accountable = 0;
90831
90832+#ifdef CONFIG_PAX_SEGMEXEC
90833+ struct vm_area_struct *vma_m = NULL;
90834+ unsigned long start_m, end_m;
90835+
90836+ start_m = start + SEGMEXEC_TASK_SIZE;
90837+ end_m = end + SEGMEXEC_TASK_SIZE;
90838+#endif
90839+
90840 if (newflags == oldflags) {
90841 *pprev = vma;
90842 return 0;
90843 }
90844
90845+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
90846+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
90847+
90848+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
90849+ return -ENOMEM;
90850+
90851+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
90852+ return -ENOMEM;
90853+ }
90854+
90855 /*
90856 * If we make a private mapping writable we increase our commit;
90857 * but (without finer accounting) cannot reduce our commit if we
90858@@ -274,6 +342,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90859 }
90860 }
90861
90862+#ifdef CONFIG_PAX_SEGMEXEC
90863+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
90864+ if (start != vma->vm_start) {
90865+ error = split_vma(mm, vma, start, 1);
90866+ if (error)
90867+ goto fail;
90868+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
90869+ *pprev = (*pprev)->vm_next;
90870+ }
90871+
90872+ if (end != vma->vm_end) {
90873+ error = split_vma(mm, vma, end, 0);
90874+ if (error)
90875+ goto fail;
90876+ }
90877+
90878+ if (pax_find_mirror_vma(vma)) {
90879+ error = __do_munmap(mm, start_m, end_m - start_m);
90880+ if (error)
90881+ goto fail;
90882+ } else {
90883+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90884+ if (!vma_m) {
90885+ error = -ENOMEM;
90886+ goto fail;
90887+ }
90888+ vma->vm_flags = newflags;
90889+ error = pax_mirror_vma(vma_m, vma);
90890+ if (error) {
90891+ vma->vm_flags = oldflags;
90892+ goto fail;
90893+ }
90894+ }
90895+ }
90896+#endif
90897+
90898 /*
90899 * First try to merge with previous and/or next vma.
90900 */
90901@@ -304,9 +408,21 @@ success:
90902 * vm_flags and vm_page_prot are protected by the mmap_sem
90903 * held in write mode.
90904 */
90905+
90906+#ifdef CONFIG_PAX_SEGMEXEC
90907+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
90908+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
90909+#endif
90910+
90911 vma->vm_flags = newflags;
90912+
90913+#ifdef CONFIG_PAX_MPROTECT
90914+ if (mm->binfmt && mm->binfmt->handle_mprotect)
90915+ mm->binfmt->handle_mprotect(vma, newflags);
90916+#endif
90917+
90918 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
90919- vm_get_page_prot(newflags));
90920+ vm_get_page_prot(vma->vm_flags));
90921
90922 if (vma_wants_writenotify(vma)) {
90923 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
90924@@ -345,6 +461,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90925 end = start + len;
90926 if (end <= start)
90927 return -ENOMEM;
90928+
90929+#ifdef CONFIG_PAX_SEGMEXEC
90930+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90931+ if (end > SEGMEXEC_TASK_SIZE)
90932+ return -EINVAL;
90933+ } else
90934+#endif
90935+
90936+ if (end > TASK_SIZE)
90937+ return -EINVAL;
90938+
90939 if (!arch_validate_prot(prot))
90940 return -EINVAL;
90941
90942@@ -352,7 +479,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90943 /*
90944 * Does the application expect PROT_READ to imply PROT_EXEC:
90945 */
90946- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
90947+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
90948 prot |= PROT_EXEC;
90949
90950 vm_flags = calc_vm_prot_bits(prot);
90951@@ -384,6 +511,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90952 if (start > vma->vm_start)
90953 prev = vma;
90954
90955+#ifdef CONFIG_PAX_MPROTECT
90956+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
90957+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
90958+#endif
90959+
90960 for (nstart = start ; ; ) {
90961 unsigned long newflags;
90962
90963@@ -394,6 +526,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90964
90965 /* newflags >> 4 shift VM_MAY% in place of VM_% */
90966 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
90967+ if (prot & (PROT_WRITE | PROT_EXEC))
90968+ gr_log_rwxmprotect(vma);
90969+
90970+ error = -EACCES;
90971+ goto out;
90972+ }
90973+
90974+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
90975 error = -EACCES;
90976 goto out;
90977 }
90978@@ -408,6 +548,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90979 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
90980 if (error)
90981 goto out;
90982+
90983+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
90984+
90985 nstart = tmp;
90986
90987 if (nstart < prev->vm_end)
90988diff --git a/mm/mremap.c b/mm/mremap.c
90989index 0843feb..4f5b2e6 100644
90990--- a/mm/mremap.c
90991+++ b/mm/mremap.c
90992@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
90993 continue;
90994 pte = ptep_get_and_clear(mm, old_addr, old_pte);
90995 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
90996+
90997+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
90998+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
90999+ pte = pte_exprotect(pte);
91000+#endif
91001+
91002 pte = move_soft_dirty_pte(pte);
91003 set_pte_at(mm, new_addr, new_pte, pte);
91004 }
91005@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
91006 if (is_vm_hugetlb_page(vma))
91007 goto Einval;
91008
91009+#ifdef CONFIG_PAX_SEGMEXEC
91010+ if (pax_find_mirror_vma(vma))
91011+ goto Einval;
91012+#endif
91013+
91014 /* We can't remap across vm area boundaries */
91015 if (old_len > vma->vm_end - addr)
91016 goto Efault;
91017@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
91018 unsigned long ret = -EINVAL;
91019 unsigned long charged = 0;
91020 unsigned long map_flags;
91021+ unsigned long pax_task_size = TASK_SIZE;
91022
91023 if (new_addr & ~PAGE_MASK)
91024 goto out;
91025
91026- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
91027+#ifdef CONFIG_PAX_SEGMEXEC
91028+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
91029+ pax_task_size = SEGMEXEC_TASK_SIZE;
91030+#endif
91031+
91032+ pax_task_size -= PAGE_SIZE;
91033+
91034+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
91035 goto out;
91036
91037 /* Check if the location we're moving into overlaps the
91038 * old location at all, and fail if it does.
91039 */
91040- if ((new_addr <= addr) && (new_addr+new_len) > addr)
91041- goto out;
91042-
91043- if ((addr <= new_addr) && (addr+old_len) > new_addr)
91044+ if (addr + old_len > new_addr && new_addr + new_len > addr)
91045 goto out;
91046
91047 ret = do_munmap(mm, new_addr, new_len);
91048@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
91049 unsigned long ret = -EINVAL;
91050 unsigned long charged = 0;
91051 bool locked = false;
91052+ unsigned long pax_task_size = TASK_SIZE;
91053
91054 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
91055 return ret;
91056@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
91057 if (!new_len)
91058 return ret;
91059
91060+#ifdef CONFIG_PAX_SEGMEXEC
91061+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
91062+ pax_task_size = SEGMEXEC_TASK_SIZE;
91063+#endif
91064+
91065+ pax_task_size -= PAGE_SIZE;
91066+
91067+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
91068+ old_len > pax_task_size || addr > pax_task_size-old_len)
91069+ return ret;
91070+
91071 down_write(&current->mm->mmap_sem);
91072
91073 if (flags & MREMAP_FIXED) {
91074@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
91075 new_addr = addr;
91076 }
91077 ret = addr;
91078+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
91079 goto out;
91080 }
91081 }
91082@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
91083 goto out;
91084 }
91085
91086+ map_flags = vma->vm_flags;
91087 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
91088+ if (!(ret & ~PAGE_MASK)) {
91089+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
91090+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
91091+ }
91092 }
91093 out:
91094 if (ret & ~PAGE_MASK)
91095diff --git a/mm/nommu.c b/mm/nommu.c
91096index ecd1f15..77039bd 100644
91097--- a/mm/nommu.c
91098+++ b/mm/nommu.c
91099@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
91100 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
91101 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91102 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91103-int heap_stack_gap = 0;
91104
91105 atomic_long_t mmap_pages_allocated;
91106
91107@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
91108 EXPORT_SYMBOL(find_vma);
91109
91110 /*
91111- * find a VMA
91112- * - we don't extend stack VMAs under NOMMU conditions
91113- */
91114-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
91115-{
91116- return find_vma(mm, addr);
91117-}
91118-
91119-/*
91120 * expand a stack to a given address
91121 * - not supported under NOMMU conditions
91122 */
91123@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
91124
91125 /* most fields are the same, copy all, and then fixup */
91126 *new = *vma;
91127+ INIT_LIST_HEAD(&new->anon_vma_chain);
91128 *region = *vma->vm_region;
91129 new->vm_region = region;
91130
91131@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
91132 }
91133 EXPORT_SYMBOL(generic_file_remap_pages);
91134
91135-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91136- unsigned long addr, void *buf, int len, int write)
91137+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91138+ unsigned long addr, void *buf, size_t len, int write)
91139 {
91140 struct vm_area_struct *vma;
91141
91142@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91143 *
91144 * The caller must hold a reference on @mm.
91145 */
91146-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91147- void *buf, int len, int write)
91148+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91149+ void *buf, size_t len, int write)
91150 {
91151 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91152 }
91153@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91154 * Access another process' address space.
91155 * - source/target buffer must be kernel space
91156 */
91157-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
91158+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
91159 {
91160 struct mm_struct *mm;
91161
91162diff --git a/mm/page-writeback.c b/mm/page-writeback.c
91163index 6380758..4064aec 100644
91164--- a/mm/page-writeback.c
91165+++ b/mm/page-writeback.c
91166@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
91167 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
91168 * - the bdi dirty thresh drops quickly due to change of JBOD workload
91169 */
91170-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
91171+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
91172 unsigned long thresh,
91173 unsigned long bg_thresh,
91174 unsigned long dirty,
91175diff --git a/mm/page_alloc.c b/mm/page_alloc.c
91176index dd886fa..7686339 100644
91177--- a/mm/page_alloc.c
91178+++ b/mm/page_alloc.c
91179@@ -61,6 +61,7 @@
91180 #include <linux/page-debug-flags.h>
91181 #include <linux/hugetlb.h>
91182 #include <linux/sched/rt.h>
91183+#include <linux/random.h>
91184
91185 #include <asm/sections.h>
91186 #include <asm/tlbflush.h>
91187@@ -354,7 +355,7 @@ out:
91188 * This usage means that zero-order pages may not be compound.
91189 */
91190
91191-static void free_compound_page(struct page *page)
91192+void free_compound_page(struct page *page)
91193 {
91194 __free_pages_ok(page, compound_order(page));
91195 }
91196@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
91197 int i;
91198 int bad = 0;
91199
91200+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91201+ unsigned long index = 1UL << order;
91202+#endif
91203+
91204 trace_mm_page_free(page, order);
91205 kmemcheck_free_shadow(page, order);
91206
91207@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
91208 debug_check_no_obj_freed(page_address(page),
91209 PAGE_SIZE << order);
91210 }
91211+
91212+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91213+ for (; index; --index)
91214+ sanitize_highpage(page + index - 1);
91215+#endif
91216+
91217 arch_free_page(page, order);
91218 kernel_map_pages(page, 1 << order, 0);
91219
91220@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
91221 local_irq_restore(flags);
91222 }
91223
91224+#ifdef CONFIG_PAX_LATENT_ENTROPY
91225+bool __meminitdata extra_latent_entropy;
91226+
91227+static int __init setup_pax_extra_latent_entropy(char *str)
91228+{
91229+ extra_latent_entropy = true;
91230+ return 0;
91231+}
91232+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
91233+
91234+volatile u64 latent_entropy __latent_entropy;
91235+EXPORT_SYMBOL(latent_entropy);
91236+#endif
91237+
91238 void __init __free_pages_bootmem(struct page *page, unsigned int order)
91239 {
91240 unsigned int nr_pages = 1 << order;
91241@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
91242 __ClearPageReserved(p);
91243 set_page_count(p, 0);
91244
91245+#ifdef CONFIG_PAX_LATENT_ENTROPY
91246+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
91247+ u64 hash = 0;
91248+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
91249+ const u64 *data = lowmem_page_address(page);
91250+
91251+ for (index = 0; index < end; index++)
91252+ hash ^= hash + data[index];
91253+ latent_entropy ^= hash;
91254+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
91255+ }
91256+#endif
91257+
91258 page_zone(page)->managed_pages += nr_pages;
91259 set_page_refcounted(page);
91260 __free_pages(page, order);
91261@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
91262 arch_alloc_page(page, order);
91263 kernel_map_pages(page, 1 << order, 1);
91264
91265+#ifndef CONFIG_PAX_MEMORY_SANITIZE
91266 if (gfp_flags & __GFP_ZERO)
91267 prep_zero_page(page, order, gfp_flags);
91268+#endif
91269
91270 if (order && (gfp_flags & __GFP_COMP))
91271 prep_compound_page(page, order);
91272diff --git a/mm/page_io.c b/mm/page_io.c
91273index 8c79a47..a689e0d 100644
91274--- a/mm/page_io.c
91275+++ b/mm/page_io.c
91276@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
91277 struct file *swap_file = sis->swap_file;
91278 struct address_space *mapping = swap_file->f_mapping;
91279 struct iovec iov = {
91280- .iov_base = kmap(page),
91281+ .iov_base = (void __force_user *)kmap(page),
91282 .iov_len = PAGE_SIZE,
91283 };
91284
91285diff --git a/mm/percpu.c b/mm/percpu.c
91286index 8c8e08f..73a5cda 100644
91287--- a/mm/percpu.c
91288+++ b/mm/percpu.c
91289@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
91290 static unsigned int pcpu_high_unit_cpu __read_mostly;
91291
91292 /* the address of the first chunk which starts with the kernel static area */
91293-void *pcpu_base_addr __read_mostly;
91294+void *pcpu_base_addr __read_only;
91295 EXPORT_SYMBOL_GPL(pcpu_base_addr);
91296
91297 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
91298diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
91299index fd26d04..0cea1b0 100644
91300--- a/mm/process_vm_access.c
91301+++ b/mm/process_vm_access.c
91302@@ -13,6 +13,7 @@
91303 #include <linux/uio.h>
91304 #include <linux/sched.h>
91305 #include <linux/highmem.h>
91306+#include <linux/security.h>
91307 #include <linux/ptrace.h>
91308 #include <linux/slab.h>
91309 #include <linux/syscalls.h>
91310@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
91311 size_t iov_l_curr_offset = 0;
91312 ssize_t iov_len;
91313
91314+ return -ENOSYS; // PaX: until properly audited
91315+
91316 /*
91317 * Work out how many pages of struct pages we're going to need
91318 * when eventually calling get_user_pages
91319 */
91320 for (i = 0; i < riovcnt; i++) {
91321 iov_len = rvec[i].iov_len;
91322- if (iov_len > 0) {
91323- nr_pages_iov = ((unsigned long)rvec[i].iov_base
91324- + iov_len)
91325- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
91326- / PAGE_SIZE + 1;
91327- nr_pages = max(nr_pages, nr_pages_iov);
91328- }
91329+ if (iov_len <= 0)
91330+ continue;
91331+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
91332+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
91333+ nr_pages = max(nr_pages, nr_pages_iov);
91334 }
91335
91336 if (nr_pages == 0)
91337@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
91338 goto free_proc_pages;
91339 }
91340
91341+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
91342+ rc = -EPERM;
91343+ goto put_task_struct;
91344+ }
91345+
91346 mm = mm_access(task, PTRACE_MODE_ATTACH);
91347 if (!mm || IS_ERR(mm)) {
91348 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
91349diff --git a/mm/rmap.c b/mm/rmap.c
91350index fd3ee7a..e4baa1f 100644
91351--- a/mm/rmap.c
91352+++ b/mm/rmap.c
91353@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91354 struct anon_vma *anon_vma = vma->anon_vma;
91355 struct anon_vma_chain *avc;
91356
91357+#ifdef CONFIG_PAX_SEGMEXEC
91358+ struct anon_vma_chain *avc_m = NULL;
91359+#endif
91360+
91361 might_sleep();
91362 if (unlikely(!anon_vma)) {
91363 struct mm_struct *mm = vma->vm_mm;
91364@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91365 if (!avc)
91366 goto out_enomem;
91367
91368+#ifdef CONFIG_PAX_SEGMEXEC
91369+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
91370+ if (!avc_m)
91371+ goto out_enomem_free_avc;
91372+#endif
91373+
91374 anon_vma = find_mergeable_anon_vma(vma);
91375 allocated = NULL;
91376 if (!anon_vma) {
91377@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91378 /* page_table_lock to protect against threads */
91379 spin_lock(&mm->page_table_lock);
91380 if (likely(!vma->anon_vma)) {
91381+
91382+#ifdef CONFIG_PAX_SEGMEXEC
91383+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
91384+
91385+ if (vma_m) {
91386+ BUG_ON(vma_m->anon_vma);
91387+ vma_m->anon_vma = anon_vma;
91388+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
91389+ avc_m = NULL;
91390+ }
91391+#endif
91392+
91393 vma->anon_vma = anon_vma;
91394 anon_vma_chain_link(vma, avc, anon_vma);
91395 allocated = NULL;
91396@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91397
91398 if (unlikely(allocated))
91399 put_anon_vma(allocated);
91400+
91401+#ifdef CONFIG_PAX_SEGMEXEC
91402+ if (unlikely(avc_m))
91403+ anon_vma_chain_free(avc_m);
91404+#endif
91405+
91406 if (unlikely(avc))
91407 anon_vma_chain_free(avc);
91408 }
91409 return 0;
91410
91411 out_enomem_free_avc:
91412+
91413+#ifdef CONFIG_PAX_SEGMEXEC
91414+ if (avc_m)
91415+ anon_vma_chain_free(avc_m);
91416+#endif
91417+
91418 anon_vma_chain_free(avc);
91419 out_enomem:
91420 return -ENOMEM;
91421@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
91422 * Attach the anon_vmas from src to dst.
91423 * Returns 0 on success, -ENOMEM on failure.
91424 */
91425-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
91426+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
91427 {
91428 struct anon_vma_chain *avc, *pavc;
91429 struct anon_vma *root = NULL;
91430@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
91431 * the corresponding VMA in the parent process is attached to.
91432 * Returns 0 on success, non-zero on failure.
91433 */
91434-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
91435+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
91436 {
91437 struct anon_vma_chain *avc;
91438 struct anon_vma *anon_vma;
91439@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
91440 void __init anon_vma_init(void)
91441 {
91442 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
91443- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
91444- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
91445+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
91446+ anon_vma_ctor);
91447+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
91448+ SLAB_PANIC|SLAB_NO_SANITIZE);
91449 }
91450
91451 /*
91452@@ -600,7 +636,11 @@ pte_t *__page_check_address(struct page *page, struct mm_struct *mm,
91453 spinlock_t *ptl;
91454
91455 if (unlikely(PageHuge(page))) {
91456+ /* when pud is not present, pte will be NULL */
91457 pte = huge_pte_offset(mm, address);
91458+ if (!pte)
91459+ return NULL;
91460+
91461 ptl = &mm->page_table_lock;
91462 goto check;
91463 }
91464diff --git a/mm/shmem.c b/mm/shmem.c
91465index 8297623..6b9dfe9 100644
91466--- a/mm/shmem.c
91467+++ b/mm/shmem.c
91468@@ -33,7 +33,7 @@
91469 #include <linux/swap.h>
91470 #include <linux/aio.h>
91471
91472-static struct vfsmount *shm_mnt;
91473+struct vfsmount *shm_mnt;
91474
91475 #ifdef CONFIG_SHMEM
91476 /*
91477@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
91478 #define BOGO_DIRENT_SIZE 20
91479
91480 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
91481-#define SHORT_SYMLINK_LEN 128
91482+#define SHORT_SYMLINK_LEN 64
91483
91484 /*
91485 * shmem_fallocate and shmem_writepage communicate via inode->i_private
91486@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
91487 static int shmem_xattr_validate(const char *name)
91488 {
91489 struct { const char *prefix; size_t len; } arr[] = {
91490+
91491+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
91492+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
91493+#endif
91494+
91495 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
91496 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
91497 };
91498@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
91499 if (err)
91500 return err;
91501
91502+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
91503+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
91504+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
91505+ return -EOPNOTSUPP;
91506+ if (size > 8)
91507+ return -EINVAL;
91508+ }
91509+#endif
91510+
91511 return simple_xattr_set(&info->xattrs, name, value, size, flags);
91512 }
91513
91514@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
91515 int err = -ENOMEM;
91516
91517 /* Round up to L1_CACHE_BYTES to resist false sharing */
91518- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
91519- L1_CACHE_BYTES), GFP_KERNEL);
91520+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
91521 if (!sbinfo)
91522 return -ENOMEM;
91523
91524diff --git a/mm/slab.c b/mm/slab.c
91525index 2580db0..0523956 100644
91526--- a/mm/slab.c
91527+++ b/mm/slab.c
91528@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
91529 if ((x)->max_freeable < i) \
91530 (x)->max_freeable = i; \
91531 } while (0)
91532-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
91533-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
91534-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
91535-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
91536+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
91537+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
91538+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
91539+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
91540+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
91541+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
91542 #else
91543 #define STATS_INC_ACTIVE(x) do { } while (0)
91544 #define STATS_DEC_ACTIVE(x) do { } while (0)
91545@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
91546 #define STATS_INC_ALLOCMISS(x) do { } while (0)
91547 #define STATS_INC_FREEHIT(x) do { } while (0)
91548 #define STATS_INC_FREEMISS(x) do { } while (0)
91549+#define STATS_INC_SANITIZED(x) do { } while (0)
91550+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
91551 #endif
91552
91553 #if DEBUG
91554@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
91555 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
91556 */
91557 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
91558- const struct slab *slab, void *obj)
91559+ const struct slab *slab, const void *obj)
91560 {
91561 u32 offset = (obj - slab->s_mem);
91562 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
91563@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
91564 */
91565
91566 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
91567- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
91568+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
91569
91570 if (INDEX_AC != INDEX_NODE)
91571 kmalloc_caches[INDEX_NODE] =
91572 create_kmalloc_cache("kmalloc-node",
91573- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
91574+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
91575
91576 slab_early_init = 0;
91577
91578@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
91579 struct array_cache *ac = cpu_cache_get(cachep);
91580
91581 check_irq_off();
91582+
91583+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91584+ if (pax_sanitize_slab) {
91585+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
91586+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
91587+
91588+ if (cachep->ctor)
91589+ cachep->ctor(objp);
91590+
91591+ STATS_INC_SANITIZED(cachep);
91592+ } else
91593+ STATS_INC_NOT_SANITIZED(cachep);
91594+ }
91595+#endif
91596+
91597 kmemleak_free_recursive(objp, cachep->flags);
91598 objp = cache_free_debugcheck(cachep, objp, caller);
91599
91600@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
91601
91602 if (unlikely(ZERO_OR_NULL_PTR(objp)))
91603 return;
91604+ VM_BUG_ON(!virt_addr_valid(objp));
91605 local_irq_save(flags);
91606 kfree_debugcheck(objp);
91607 c = virt_to_cache(objp);
91608@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
91609 }
91610 /* cpu stats */
91611 {
91612- unsigned long allochit = atomic_read(&cachep->allochit);
91613- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
91614- unsigned long freehit = atomic_read(&cachep->freehit);
91615- unsigned long freemiss = atomic_read(&cachep->freemiss);
91616+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
91617+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
91618+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
91619+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
91620
91621 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
91622 allochit, allocmiss, freehit, freemiss);
91623 }
91624+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91625+ {
91626+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
91627+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
91628+
91629+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
91630+ }
91631+#endif
91632 #endif
91633 }
91634
91635@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
91636 static int __init slab_proc_init(void)
91637 {
91638 #ifdef CONFIG_DEBUG_SLAB_LEAK
91639- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
91640+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
91641 #endif
91642 return 0;
91643 }
91644 module_init(slab_proc_init);
91645 #endif
91646
91647+bool is_usercopy_object(const void *ptr)
91648+{
91649+ struct page *page;
91650+ struct kmem_cache *cachep;
91651+
91652+ if (ZERO_OR_NULL_PTR(ptr))
91653+ return false;
91654+
91655+ if (!slab_is_available())
91656+ return false;
91657+
91658+ if (!virt_addr_valid(ptr))
91659+ return false;
91660+
91661+ page = virt_to_head_page(ptr);
91662+
91663+ if (!PageSlab(page))
91664+ return false;
91665+
91666+ cachep = page->slab_cache;
91667+ return cachep->flags & SLAB_USERCOPY;
91668+}
91669+
91670+#ifdef CONFIG_PAX_USERCOPY
91671+const char *check_heap_object(const void *ptr, unsigned long n)
91672+{
91673+ struct page *page;
91674+ struct kmem_cache *cachep;
91675+ struct slab *slabp;
91676+ unsigned int objnr;
91677+ unsigned long offset;
91678+
91679+ if (ZERO_OR_NULL_PTR(ptr))
91680+ return "<null>";
91681+
91682+ if (!virt_addr_valid(ptr))
91683+ return NULL;
91684+
91685+ page = virt_to_head_page(ptr);
91686+
91687+ if (!PageSlab(page))
91688+ return NULL;
91689+
91690+ cachep = page->slab_cache;
91691+ if (!(cachep->flags & SLAB_USERCOPY))
91692+ return cachep->name;
91693+
91694+ slabp = page->slab_page;
91695+ objnr = obj_to_index(cachep, slabp, ptr);
91696+ BUG_ON(objnr >= cachep->num);
91697+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
91698+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
91699+ return NULL;
91700+
91701+ return cachep->name;
91702+}
91703+#endif
91704+
91705 /**
91706 * ksize - get the actual amount of memory allocated for a given object
91707 * @objp: Pointer to the object
91708diff --git a/mm/slab.h b/mm/slab.h
91709index a535033..2f98fe5 100644
91710--- a/mm/slab.h
91711+++ b/mm/slab.h
91712@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
91713 /* The slab cache that manages slab cache information */
91714 extern struct kmem_cache *kmem_cache;
91715
91716+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91717+#ifdef CONFIG_X86_64
91718+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
91719+#else
91720+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
91721+#endif
91722+extern bool pax_sanitize_slab;
91723+#endif
91724+
91725 unsigned long calculate_alignment(unsigned long flags,
91726 unsigned long align, unsigned long size);
91727
91728@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91729
91730 /* Legal flag mask for kmem_cache_create(), for various configurations */
91731 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
91732- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
91733+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
91734+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
91735
91736 #if defined(CONFIG_DEBUG_SLAB)
91737 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
91738@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
91739 return s;
91740
91741 page = virt_to_head_page(x);
91742+
91743+ BUG_ON(!PageSlab(page));
91744+
91745 cachep = page->slab_cache;
91746 if (slab_equal_or_root(cachep, s))
91747 return cachep;
91748diff --git a/mm/slab_common.c b/mm/slab_common.c
91749index e2e98af..3b1a163 100644
91750--- a/mm/slab_common.c
91751+++ b/mm/slab_common.c
91752@@ -23,11 +23,22 @@
91753
91754 #include "slab.h"
91755
91756-enum slab_state slab_state;
91757+enum slab_state slab_state __read_only;
91758 LIST_HEAD(slab_caches);
91759 DEFINE_MUTEX(slab_mutex);
91760 struct kmem_cache *kmem_cache;
91761
91762+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91763+bool pax_sanitize_slab __read_only = true;
91764+static int __init pax_sanitize_slab_setup(char *str)
91765+{
91766+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
91767+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
91768+ return 1;
91769+}
91770+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
91771+#endif
91772+
91773 #ifdef CONFIG_DEBUG_VM
91774 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
91775 size_t size)
91776@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
91777
91778 err = __kmem_cache_create(s, flags);
91779 if (!err) {
91780- s->refcount = 1;
91781+ atomic_set(&s->refcount, 1);
91782 list_add(&s->list, &slab_caches);
91783 memcg_cache_list_add(memcg, s);
91784 } else {
91785@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
91786
91787 get_online_cpus();
91788 mutex_lock(&slab_mutex);
91789- s->refcount--;
91790- if (!s->refcount) {
91791+ if (atomic_dec_and_test(&s->refcount)) {
91792 list_del(&s->list);
91793
91794 if (!__kmem_cache_shutdown(s)) {
91795@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
91796 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
91797 name, size, err);
91798
91799- s->refcount = -1; /* Exempt from merging for now */
91800+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
91801 }
91802
91803 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
91804@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
91805
91806 create_boot_cache(s, name, size, flags);
91807 list_add(&s->list, &slab_caches);
91808- s->refcount = 1;
91809+ atomic_set(&s->refcount, 1);
91810 return s;
91811 }
91812
91813@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
91814 EXPORT_SYMBOL(kmalloc_dma_caches);
91815 #endif
91816
91817+#ifdef CONFIG_PAX_USERCOPY_SLABS
91818+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
91819+EXPORT_SYMBOL(kmalloc_usercopy_caches);
91820+#endif
91821+
91822 /*
91823 * Conversion table for small slabs sizes / 8 to the index in the
91824 * kmalloc array. This is necessary for slabs < 192 since we have non power
91825@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
91826 return kmalloc_dma_caches[index];
91827
91828 #endif
91829+
91830+#ifdef CONFIG_PAX_USERCOPY_SLABS
91831+ if (unlikely((flags & GFP_USERCOPY)))
91832+ return kmalloc_usercopy_caches[index];
91833+
91834+#endif
91835+
91836 return kmalloc_caches[index];
91837 }
91838
91839@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
91840 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
91841 if (!kmalloc_caches[i]) {
91842 kmalloc_caches[i] = create_kmalloc_cache(NULL,
91843- 1 << i, flags);
91844+ 1 << i, SLAB_USERCOPY | flags);
91845 }
91846
91847 /*
91848@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
91849 * earlier power of two caches
91850 */
91851 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
91852- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
91853+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
91854
91855 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
91856- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
91857+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
91858 }
91859
91860 /* Kmalloc array is now usable */
91861@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
91862 }
91863 }
91864 #endif
91865+
91866+#ifdef CONFIG_PAX_USERCOPY_SLABS
91867+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
91868+ struct kmem_cache *s = kmalloc_caches[i];
91869+
91870+ if (s) {
91871+ int size = kmalloc_size(i);
91872+ char *n = kasprintf(GFP_NOWAIT,
91873+ "usercopy-kmalloc-%d", size);
91874+
91875+ BUG_ON(!n);
91876+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
91877+ size, SLAB_USERCOPY | flags);
91878+ }
91879+ }
91880+#endif
91881+
91882 }
91883 #endif /* !CONFIG_SLOB */
91884
91885@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
91886 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
91887 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
91888 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
91889+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91890+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
91891+#endif
91892 #endif
91893 seq_putc(m, '\n');
91894 }
91895diff --git a/mm/slob.c b/mm/slob.c
91896index 4bf8809..98a6914 100644
91897--- a/mm/slob.c
91898+++ b/mm/slob.c
91899@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
91900 /*
91901 * Return the size of a slob block.
91902 */
91903-static slobidx_t slob_units(slob_t *s)
91904+static slobidx_t slob_units(const slob_t *s)
91905 {
91906 if (s->units > 0)
91907 return s->units;
91908@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
91909 /*
91910 * Return the next free slob block pointer after this one.
91911 */
91912-static slob_t *slob_next(slob_t *s)
91913+static slob_t *slob_next(const slob_t *s)
91914 {
91915 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
91916 slobidx_t next;
91917@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
91918 /*
91919 * Returns true if s is the last free block in its page.
91920 */
91921-static int slob_last(slob_t *s)
91922+static int slob_last(const slob_t *s)
91923 {
91924 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
91925 }
91926
91927-static void *slob_new_pages(gfp_t gfp, int order, int node)
91928+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
91929 {
91930- void *page;
91931+ struct page *page;
91932
91933 #ifdef CONFIG_NUMA
91934 if (node != NUMA_NO_NODE)
91935@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
91936 if (!page)
91937 return NULL;
91938
91939- return page_address(page);
91940+ __SetPageSlab(page);
91941+ return page;
91942 }
91943
91944-static void slob_free_pages(void *b, int order)
91945+static void slob_free_pages(struct page *sp, int order)
91946 {
91947 if (current->reclaim_state)
91948 current->reclaim_state->reclaimed_slab += 1 << order;
91949- free_pages((unsigned long)b, order);
91950+ __ClearPageSlab(sp);
91951+ page_mapcount_reset(sp);
91952+ sp->private = 0;
91953+ __free_pages(sp, order);
91954 }
91955
91956 /*
91957@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
91958
91959 /* Not enough space: must allocate a new page */
91960 if (!b) {
91961- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91962- if (!b)
91963+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91964+ if (!sp)
91965 return NULL;
91966- sp = virt_to_page(b);
91967- __SetPageSlab(sp);
91968+ b = page_address(sp);
91969
91970 spin_lock_irqsave(&slob_lock, flags);
91971 sp->units = SLOB_UNITS(PAGE_SIZE);
91972 sp->freelist = b;
91973+ sp->private = 0;
91974 INIT_LIST_HEAD(&sp->list);
91975 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
91976 set_slob_page_free(sp, slob_list);
91977@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
91978 if (slob_page_free(sp))
91979 clear_slob_page_free(sp);
91980 spin_unlock_irqrestore(&slob_lock, flags);
91981- __ClearPageSlab(sp);
91982- page_mapcount_reset(sp);
91983- slob_free_pages(b, 0);
91984+ slob_free_pages(sp, 0);
91985 return;
91986 }
91987
91988+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91989+ if (pax_sanitize_slab)
91990+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
91991+#endif
91992+
91993 if (!slob_page_free(sp)) {
91994 /* This slob page is about to become partially free. Easy! */
91995 sp->units = units;
91996@@ -424,11 +431,10 @@ out:
91997 */
91998
91999 static __always_inline void *
92000-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
92001+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
92002 {
92003- unsigned int *m;
92004- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
92005- void *ret;
92006+ slob_t *m;
92007+ void *ret = NULL;
92008
92009 gfp &= gfp_allowed_mask;
92010
92011@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
92012
92013 if (!m)
92014 return NULL;
92015- *m = size;
92016+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
92017+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
92018+ m[0].units = size;
92019+ m[1].units = align;
92020 ret = (void *)m + align;
92021
92022 trace_kmalloc_node(caller, ret,
92023 size, size + align, gfp, node);
92024 } else {
92025 unsigned int order = get_order(size);
92026+ struct page *page;
92027
92028 if (likely(order))
92029 gfp |= __GFP_COMP;
92030- ret = slob_new_pages(gfp, order, node);
92031+ page = slob_new_pages(gfp, order, node);
92032+ if (page) {
92033+ ret = page_address(page);
92034+ page->private = size;
92035+ }
92036
92037 trace_kmalloc_node(caller, ret,
92038 size, PAGE_SIZE << order, gfp, node);
92039 }
92040
92041- kmemleak_alloc(ret, size, 1, gfp);
92042+ return ret;
92043+}
92044+
92045+static __always_inline void *
92046+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
92047+{
92048+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
92049+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
92050+
92051+ if (!ZERO_OR_NULL_PTR(ret))
92052+ kmemleak_alloc(ret, size, 1, gfp);
92053 return ret;
92054 }
92055
92056@@ -493,34 +517,112 @@ void kfree(const void *block)
92057 return;
92058 kmemleak_free(block);
92059
92060+ VM_BUG_ON(!virt_addr_valid(block));
92061 sp = virt_to_page(block);
92062- if (PageSlab(sp)) {
92063+ VM_BUG_ON(!PageSlab(sp));
92064+ if (!sp->private) {
92065 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
92066- unsigned int *m = (unsigned int *)(block - align);
92067- slob_free(m, *m + align);
92068- } else
92069+ slob_t *m = (slob_t *)(block - align);
92070+ slob_free(m, m[0].units + align);
92071+ } else {
92072+ __ClearPageSlab(sp);
92073+ page_mapcount_reset(sp);
92074+ sp->private = 0;
92075 __free_pages(sp, compound_order(sp));
92076+ }
92077 }
92078 EXPORT_SYMBOL(kfree);
92079
92080+bool is_usercopy_object(const void *ptr)
92081+{
92082+ if (!slab_is_available())
92083+ return false;
92084+
92085+ // PAX: TODO
92086+
92087+ return false;
92088+}
92089+
92090+#ifdef CONFIG_PAX_USERCOPY
92091+const char *check_heap_object(const void *ptr, unsigned long n)
92092+{
92093+ struct page *page;
92094+ const slob_t *free;
92095+ const void *base;
92096+ unsigned long flags;
92097+
92098+ if (ZERO_OR_NULL_PTR(ptr))
92099+ return "<null>";
92100+
92101+ if (!virt_addr_valid(ptr))
92102+ return NULL;
92103+
92104+ page = virt_to_head_page(ptr);
92105+ if (!PageSlab(page))
92106+ return NULL;
92107+
92108+ if (page->private) {
92109+ base = page;
92110+ if (base <= ptr && n <= page->private - (ptr - base))
92111+ return NULL;
92112+ return "<slob>";
92113+ }
92114+
92115+ /* some tricky double walking to find the chunk */
92116+ spin_lock_irqsave(&slob_lock, flags);
92117+ base = (void *)((unsigned long)ptr & PAGE_MASK);
92118+ free = page->freelist;
92119+
92120+ while (!slob_last(free) && (void *)free <= ptr) {
92121+ base = free + slob_units(free);
92122+ free = slob_next(free);
92123+ }
92124+
92125+ while (base < (void *)free) {
92126+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
92127+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
92128+ int offset;
92129+
92130+ if (ptr < base + align)
92131+ break;
92132+
92133+ offset = ptr - base - align;
92134+ if (offset >= m) {
92135+ base += size;
92136+ continue;
92137+ }
92138+
92139+ if (n > m - offset)
92140+ break;
92141+
92142+ spin_unlock_irqrestore(&slob_lock, flags);
92143+ return NULL;
92144+ }
92145+
92146+ spin_unlock_irqrestore(&slob_lock, flags);
92147+ return "<slob>";
92148+}
92149+#endif
92150+
92151 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
92152 size_t ksize(const void *block)
92153 {
92154 struct page *sp;
92155 int align;
92156- unsigned int *m;
92157+ slob_t *m;
92158
92159 BUG_ON(!block);
92160 if (unlikely(block == ZERO_SIZE_PTR))
92161 return 0;
92162
92163 sp = virt_to_page(block);
92164- if (unlikely(!PageSlab(sp)))
92165- return PAGE_SIZE << compound_order(sp);
92166+ VM_BUG_ON(!PageSlab(sp));
92167+ if (sp->private)
92168+ return sp->private;
92169
92170 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
92171- m = (unsigned int *)(block - align);
92172- return SLOB_UNITS(*m) * SLOB_UNIT;
92173+ m = (slob_t *)(block - align);
92174+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
92175 }
92176 EXPORT_SYMBOL(ksize);
92177
92178@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
92179
92180 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
92181 {
92182- void *b;
92183+ void *b = NULL;
92184
92185 flags &= gfp_allowed_mask;
92186
92187 lockdep_trace_alloc(flags);
92188
92189+#ifdef CONFIG_PAX_USERCOPY_SLABS
92190+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
92191+#else
92192 if (c->size < PAGE_SIZE) {
92193 b = slob_alloc(c->size, flags, c->align, node);
92194 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
92195 SLOB_UNITS(c->size) * SLOB_UNIT,
92196 flags, node);
92197 } else {
92198- b = slob_new_pages(flags, get_order(c->size), node);
92199+ struct page *sp;
92200+
92201+ sp = slob_new_pages(flags, get_order(c->size), node);
92202+ if (sp) {
92203+ b = page_address(sp);
92204+ sp->private = c->size;
92205+ }
92206 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
92207 PAGE_SIZE << get_order(c->size),
92208 flags, node);
92209 }
92210+#endif
92211
92212 if (b && c->ctor)
92213 c->ctor(b);
92214@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
92215
92216 static void __kmem_cache_free(void *b, int size)
92217 {
92218- if (size < PAGE_SIZE)
92219+ struct page *sp;
92220+
92221+ sp = virt_to_page(b);
92222+ BUG_ON(!PageSlab(sp));
92223+ if (!sp->private)
92224 slob_free(b, size);
92225 else
92226- slob_free_pages(b, get_order(size));
92227+ slob_free_pages(sp, get_order(size));
92228 }
92229
92230 static void kmem_rcu_free(struct rcu_head *head)
92231@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
92232
92233 void kmem_cache_free(struct kmem_cache *c, void *b)
92234 {
92235+ int size = c->size;
92236+
92237+#ifdef CONFIG_PAX_USERCOPY_SLABS
92238+ if (size + c->align < PAGE_SIZE) {
92239+ size += c->align;
92240+ b -= c->align;
92241+ }
92242+#endif
92243+
92244 kmemleak_free_recursive(b, c->flags);
92245 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
92246 struct slob_rcu *slob_rcu;
92247- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
92248- slob_rcu->size = c->size;
92249+ slob_rcu = b + (size - sizeof(struct slob_rcu));
92250+ slob_rcu->size = size;
92251 call_rcu(&slob_rcu->head, kmem_rcu_free);
92252 } else {
92253- __kmem_cache_free(b, c->size);
92254+ __kmem_cache_free(b, size);
92255 }
92256
92257+#ifdef CONFIG_PAX_USERCOPY_SLABS
92258+ trace_kfree(_RET_IP_, b);
92259+#else
92260 trace_kmem_cache_free(_RET_IP_, b);
92261+#endif
92262+
92263 }
92264 EXPORT_SYMBOL(kmem_cache_free);
92265
92266diff --git a/mm/slub.c b/mm/slub.c
92267index 96f2169..9111a59 100644
92268--- a/mm/slub.c
92269+++ b/mm/slub.c
92270@@ -207,7 +207,7 @@ struct track {
92271
92272 enum track_item { TRACK_ALLOC, TRACK_FREE };
92273
92274-#ifdef CONFIG_SYSFS
92275+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92276 static int sysfs_slab_add(struct kmem_cache *);
92277 static int sysfs_slab_alias(struct kmem_cache *, const char *);
92278 static void sysfs_slab_remove(struct kmem_cache *);
92279@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
92280 if (!t->addr)
92281 return;
92282
92283- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
92284+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
92285 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
92286 #ifdef CONFIG_STACKTRACE
92287 {
92288@@ -2616,6 +2616,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
92289
92290 slab_free_hook(s, x);
92291
92292+#ifdef CONFIG_PAX_MEMORY_SANITIZE
92293+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
92294+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
92295+ if (s->ctor)
92296+ s->ctor(x);
92297+ }
92298+#endif
92299+
92300 redo:
92301 /*
92302 * Determine the currently cpus per cpu slab.
92303@@ -2683,7 +2691,7 @@ static int slub_min_objects;
92304 * Merge control. If this is set then no merging of slab caches will occur.
92305 * (Could be removed. This was introduced to pacify the merge skeptics.)
92306 */
92307-static int slub_nomerge;
92308+static int slub_nomerge = 1;
92309
92310 /*
92311 * Calculate the order of allocation given an slab object size.
92312@@ -2960,6 +2968,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
92313 s->inuse = size;
92314
92315 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
92316+#ifdef CONFIG_PAX_MEMORY_SANITIZE
92317+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
92318+#endif
92319 s->ctor)) {
92320 /*
92321 * Relocate free pointer after the object if it is not
92322@@ -3305,6 +3316,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
92323 EXPORT_SYMBOL(__kmalloc_node);
92324 #endif
92325
92326+bool is_usercopy_object(const void *ptr)
92327+{
92328+ struct page *page;
92329+ struct kmem_cache *s;
92330+
92331+ if (ZERO_OR_NULL_PTR(ptr))
92332+ return false;
92333+
92334+ if (!slab_is_available())
92335+ return false;
92336+
92337+ if (!virt_addr_valid(ptr))
92338+ return false;
92339+
92340+ page = virt_to_head_page(ptr);
92341+
92342+ if (!PageSlab(page))
92343+ return false;
92344+
92345+ s = page->slab_cache;
92346+ return s->flags & SLAB_USERCOPY;
92347+}
92348+
92349+#ifdef CONFIG_PAX_USERCOPY
92350+const char *check_heap_object(const void *ptr, unsigned long n)
92351+{
92352+ struct page *page;
92353+ struct kmem_cache *s;
92354+ unsigned long offset;
92355+
92356+ if (ZERO_OR_NULL_PTR(ptr))
92357+ return "<null>";
92358+
92359+ if (!virt_addr_valid(ptr))
92360+ return NULL;
92361+
92362+ page = virt_to_head_page(ptr);
92363+
92364+ if (!PageSlab(page))
92365+ return NULL;
92366+
92367+ s = page->slab_cache;
92368+ if (!(s->flags & SLAB_USERCOPY))
92369+ return s->name;
92370+
92371+ offset = (ptr - page_address(page)) % s->size;
92372+ if (offset <= s->object_size && n <= s->object_size - offset)
92373+ return NULL;
92374+
92375+ return s->name;
92376+}
92377+#endif
92378+
92379 size_t ksize(const void *object)
92380 {
92381 struct page *page;
92382@@ -3333,6 +3397,7 @@ void kfree(const void *x)
92383 if (unlikely(ZERO_OR_NULL_PTR(x)))
92384 return;
92385
92386+ VM_BUG_ON(!virt_addr_valid(x));
92387 page = virt_to_head_page(x);
92388 if (unlikely(!PageSlab(page))) {
92389 BUG_ON(!PageCompound(page));
92390@@ -3638,7 +3703,7 @@ static int slab_unmergeable(struct kmem_cache *s)
92391 /*
92392 * We may have set a slab to be unmergeable during bootstrap.
92393 */
92394- if (s->refcount < 0)
92395+ if (atomic_read(&s->refcount) < 0)
92396 return 1;
92397
92398 return 0;
92399@@ -3696,7 +3761,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
92400
92401 s = find_mergeable(memcg, size, align, flags, name, ctor);
92402 if (s) {
92403- s->refcount++;
92404+ atomic_inc(&s->refcount);
92405 /*
92406 * Adjust the object sizes so that we clear
92407 * the complete object on kzalloc.
92408@@ -3705,7 +3770,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
92409 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
92410
92411 if (sysfs_slab_alias(s, name)) {
92412- s->refcount--;
92413+ atomic_dec(&s->refcount);
92414 s = NULL;
92415 }
92416 }
92417@@ -3825,7 +3890,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
92418 }
92419 #endif
92420
92421-#ifdef CONFIG_SYSFS
92422+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92423 static int count_inuse(struct page *page)
92424 {
92425 return page->inuse;
92426@@ -4214,12 +4279,12 @@ static void resiliency_test(void)
92427 validate_slab_cache(kmalloc_caches[9]);
92428 }
92429 #else
92430-#ifdef CONFIG_SYSFS
92431+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92432 static void resiliency_test(void) {};
92433 #endif
92434 #endif
92435
92436-#ifdef CONFIG_SYSFS
92437+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92438 enum slab_stat_type {
92439 SL_ALL, /* All slabs */
92440 SL_PARTIAL, /* Only partially allocated slabs */
92441@@ -4459,7 +4524,7 @@ SLAB_ATTR_RO(ctor);
92442
92443 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
92444 {
92445- return sprintf(buf, "%d\n", s->refcount - 1);
92446+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
92447 }
92448 SLAB_ATTR_RO(aliases);
92449
92450@@ -4547,6 +4612,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
92451 SLAB_ATTR_RO(cache_dma);
92452 #endif
92453
92454+#ifdef CONFIG_PAX_USERCOPY_SLABS
92455+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
92456+{
92457+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
92458+}
92459+SLAB_ATTR_RO(usercopy);
92460+#endif
92461+
92462 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
92463 {
92464 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
92465@@ -4881,6 +4954,9 @@ static struct attribute *slab_attrs[] = {
92466 #ifdef CONFIG_ZONE_DMA
92467 &cache_dma_attr.attr,
92468 #endif
92469+#ifdef CONFIG_PAX_USERCOPY_SLABS
92470+ &usercopy_attr.attr,
92471+#endif
92472 #ifdef CONFIG_NUMA
92473 &remote_node_defrag_ratio_attr.attr,
92474 #endif
92475@@ -5113,6 +5189,7 @@ static char *create_unique_id(struct kmem_cache *s)
92476 return name;
92477 }
92478
92479+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92480 static int sysfs_slab_add(struct kmem_cache *s)
92481 {
92482 int err;
92483@@ -5136,7 +5213,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
92484 }
92485
92486 s->kobj.kset = slab_kset;
92487- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
92488+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
92489 if (err) {
92490 kobject_put(&s->kobj);
92491 return err;
92492@@ -5170,6 +5247,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
92493 kobject_del(&s->kobj);
92494 kobject_put(&s->kobj);
92495 }
92496+#endif
92497
92498 /*
92499 * Need to buffer aliases during bootup until sysfs becomes
92500@@ -5183,6 +5261,7 @@ struct saved_alias {
92501
92502 static struct saved_alias *alias_list;
92503
92504+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92505 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
92506 {
92507 struct saved_alias *al;
92508@@ -5205,6 +5284,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
92509 alias_list = al;
92510 return 0;
92511 }
92512+#endif
92513
92514 static int __init slab_sysfs_init(void)
92515 {
92516diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
92517index 27eeab3..7c3f7f2 100644
92518--- a/mm/sparse-vmemmap.c
92519+++ b/mm/sparse-vmemmap.c
92520@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
92521 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
92522 if (!p)
92523 return NULL;
92524- pud_populate(&init_mm, pud, p);
92525+ pud_populate_kernel(&init_mm, pud, p);
92526 }
92527 return pud;
92528 }
92529@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
92530 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
92531 if (!p)
92532 return NULL;
92533- pgd_populate(&init_mm, pgd, p);
92534+ pgd_populate_kernel(&init_mm, pgd, p);
92535 }
92536 return pgd;
92537 }
92538diff --git a/mm/sparse.c b/mm/sparse.c
92539index 4ac1d7e..bbfcb1f 100644
92540--- a/mm/sparse.c
92541+++ b/mm/sparse.c
92542@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
92543
92544 for (i = 0; i < PAGES_PER_SECTION; i++) {
92545 if (PageHWPoison(&memmap[i])) {
92546- atomic_long_sub(1, &num_poisoned_pages);
92547+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
92548 ClearPageHWPoison(&memmap[i]);
92549 }
92550 }
92551diff --git a/mm/swap.c b/mm/swap.c
92552index 759c3ca..7c1a5b4 100644
92553--- a/mm/swap.c
92554+++ b/mm/swap.c
92555@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
92556
92557 __page_cache_release(page);
92558 dtor = get_compound_page_dtor(page);
92559+ if (!PageHuge(page))
92560+ BUG_ON(dtor != free_compound_page);
92561 (*dtor)(page);
92562 }
92563
92564diff --git a/mm/swapfile.c b/mm/swapfile.c
92565index de7c904..c84bf11 100644
92566--- a/mm/swapfile.c
92567+++ b/mm/swapfile.c
92568@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
92569
92570 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
92571 /* Activity counter to indicate that a swapon or swapoff has occurred */
92572-static atomic_t proc_poll_event = ATOMIC_INIT(0);
92573+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
92574
92575 static inline unsigned char swap_count(unsigned char ent)
92576 {
92577@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
92578 }
92579 filp_close(swap_file, NULL);
92580 err = 0;
92581- atomic_inc(&proc_poll_event);
92582+ atomic_inc_unchecked(&proc_poll_event);
92583 wake_up_interruptible(&proc_poll_wait);
92584
92585 out_dput:
92586@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
92587
92588 poll_wait(file, &proc_poll_wait, wait);
92589
92590- if (seq->poll_event != atomic_read(&proc_poll_event)) {
92591- seq->poll_event = atomic_read(&proc_poll_event);
92592+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
92593+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
92594 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
92595 }
92596
92597@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
92598 return ret;
92599
92600 seq = file->private_data;
92601- seq->poll_event = atomic_read(&proc_poll_event);
92602+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
92603 return 0;
92604 }
92605
92606@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
92607 (frontswap_map) ? "FS" : "");
92608
92609 mutex_unlock(&swapon_mutex);
92610- atomic_inc(&proc_poll_event);
92611+ atomic_inc_unchecked(&proc_poll_event);
92612 wake_up_interruptible(&proc_poll_wait);
92613
92614 if (S_ISREG(inode->i_mode))
92615diff --git a/mm/util.c b/mm/util.c
92616index eaf63fc2..32b2629 100644
92617--- a/mm/util.c
92618+++ b/mm/util.c
92619@@ -294,6 +294,12 @@ done:
92620 void arch_pick_mmap_layout(struct mm_struct *mm)
92621 {
92622 mm->mmap_base = TASK_UNMAPPED_BASE;
92623+
92624+#ifdef CONFIG_PAX_RANDMMAP
92625+ if (mm->pax_flags & MF_PAX_RANDMMAP)
92626+ mm->mmap_base += mm->delta_mmap;
92627+#endif
92628+
92629 mm->get_unmapped_area = arch_get_unmapped_area;
92630 }
92631 #endif
92632diff --git a/mm/vmalloc.c b/mm/vmalloc.c
92633index 1074543..136dbe0 100644
92634--- a/mm/vmalloc.c
92635+++ b/mm/vmalloc.c
92636@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
92637
92638 pte = pte_offset_kernel(pmd, addr);
92639 do {
92640- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
92641- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
92642+
92643+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
92644+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
92645+ BUG_ON(!pte_exec(*pte));
92646+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
92647+ continue;
92648+ }
92649+#endif
92650+
92651+ {
92652+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
92653+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
92654+ }
92655 } while (pte++, addr += PAGE_SIZE, addr != end);
92656 }
92657
92658@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
92659 pte = pte_alloc_kernel(pmd, addr);
92660 if (!pte)
92661 return -ENOMEM;
92662+
92663+ pax_open_kernel();
92664 do {
92665 struct page *page = pages[*nr];
92666
92667- if (WARN_ON(!pte_none(*pte)))
92668+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
92669+ if (pgprot_val(prot) & _PAGE_NX)
92670+#endif
92671+
92672+ if (!pte_none(*pte)) {
92673+ pax_close_kernel();
92674+ WARN_ON(1);
92675 return -EBUSY;
92676- if (WARN_ON(!page))
92677+ }
92678+ if (!page) {
92679+ pax_close_kernel();
92680+ WARN_ON(1);
92681 return -ENOMEM;
92682+ }
92683 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
92684 (*nr)++;
92685 } while (pte++, addr += PAGE_SIZE, addr != end);
92686+ pax_close_kernel();
92687 return 0;
92688 }
92689
92690@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
92691 pmd_t *pmd;
92692 unsigned long next;
92693
92694- pmd = pmd_alloc(&init_mm, pud, addr);
92695+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92696 if (!pmd)
92697 return -ENOMEM;
92698 do {
92699@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
92700 pud_t *pud;
92701 unsigned long next;
92702
92703- pud = pud_alloc(&init_mm, pgd, addr);
92704+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
92705 if (!pud)
92706 return -ENOMEM;
92707 do {
92708@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
92709 if (addr >= MODULES_VADDR && addr < MODULES_END)
92710 return 1;
92711 #endif
92712+
92713+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
92714+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
92715+ return 1;
92716+#endif
92717+
92718 return is_vmalloc_addr(x);
92719 }
92720
92721@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
92722
92723 if (!pgd_none(*pgd)) {
92724 pud_t *pud = pud_offset(pgd, addr);
92725+#ifdef CONFIG_X86
92726+ if (!pud_large(*pud))
92727+#endif
92728 if (!pud_none(*pud)) {
92729 pmd_t *pmd = pmd_offset(pud, addr);
92730+#ifdef CONFIG_X86
92731+ if (!pmd_large(*pmd))
92732+#endif
92733 if (!pmd_none(*pmd)) {
92734 pte_t *ptep, pte;
92735
92736@@ -1303,6 +1339,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
92737 struct vm_struct *area;
92738
92739 BUG_ON(in_interrupt());
92740+
92741+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
92742+ if (flags & VM_KERNEXEC) {
92743+ if (start != VMALLOC_START || end != VMALLOC_END)
92744+ return NULL;
92745+ start = (unsigned long)MODULES_EXEC_VADDR;
92746+ end = (unsigned long)MODULES_EXEC_END;
92747+ }
92748+#endif
92749+
92750 if (flags & VM_IOREMAP)
92751 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
92752
92753@@ -1528,6 +1574,11 @@ void *vmap(struct page **pages, unsigned int count,
92754 if (count > totalram_pages)
92755 return NULL;
92756
92757+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
92758+ if (!(pgprot_val(prot) & _PAGE_NX))
92759+ flags |= VM_KERNEXEC;
92760+#endif
92761+
92762 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
92763 __builtin_return_address(0));
92764 if (!area)
92765@@ -1629,6 +1680,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
92766 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
92767 goto fail;
92768
92769+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
92770+ if (!(pgprot_val(prot) & _PAGE_NX))
92771+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
92772+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
92773+ else
92774+#endif
92775+
92776 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
92777 start, end, node, gfp_mask, caller);
92778 if (!area)
92779@@ -1805,10 +1863,9 @@ EXPORT_SYMBOL(vzalloc_node);
92780 * For tight control over page level allocator and protection flags
92781 * use __vmalloc() instead.
92782 */
92783-
92784 void *vmalloc_exec(unsigned long size)
92785 {
92786- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
92787+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
92788 NUMA_NO_NODE, __builtin_return_address(0));
92789 }
92790
92791@@ -2115,6 +2172,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
92792 {
92793 struct vm_struct *area;
92794
92795+ BUG_ON(vma->vm_mirror);
92796+
92797 size = PAGE_ALIGN(size);
92798
92799 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
92800@@ -2600,7 +2659,11 @@ static int s_show(struct seq_file *m, void *p)
92801 v->addr, v->addr + v->size, v->size);
92802
92803 if (v->caller)
92804+#ifdef CONFIG_GRKERNSEC_HIDESYM
92805+ seq_printf(m, " %pK", v->caller);
92806+#else
92807 seq_printf(m, " %pS", v->caller);
92808+#endif
92809
92810 if (v->nr_pages)
92811 seq_printf(m, " pages=%d", v->nr_pages);
92812diff --git a/mm/vmstat.c b/mm/vmstat.c
92813index 5a442a7..5eb281e 100644
92814--- a/mm/vmstat.c
92815+++ b/mm/vmstat.c
92816@@ -79,7 +79,7 @@ void vm_events_fold_cpu(int cpu)
92817 *
92818 * vm_stat contains the global counters
92819 */
92820-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
92821+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
92822 EXPORT_SYMBOL(vm_stat);
92823
92824 #ifdef CONFIG_SMP
92825@@ -423,7 +423,7 @@ static inline void fold_diff(int *diff)
92826
92827 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
92828 if (diff[i])
92829- atomic_long_add(diff[i], &vm_stat[i]);
92830+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
92831 }
92832
92833 /*
92834@@ -455,7 +455,7 @@ static void refresh_cpu_vm_stats(void)
92835 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
92836 if (v) {
92837
92838- atomic_long_add(v, &zone->vm_stat[i]);
92839+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92840 global_diff[i] += v;
92841 #ifdef CONFIG_NUMA
92842 /* 3 seconds idle till flush */
92843@@ -517,7 +517,7 @@ void cpu_vm_stats_fold(int cpu)
92844
92845 v = p->vm_stat_diff[i];
92846 p->vm_stat_diff[i] = 0;
92847- atomic_long_add(v, &zone->vm_stat[i]);
92848+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92849 global_diff[i] += v;
92850 }
92851 }
92852@@ -537,8 +537,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
92853 if (pset->vm_stat_diff[i]) {
92854 int v = pset->vm_stat_diff[i];
92855 pset->vm_stat_diff[i] = 0;
92856- atomic_long_add(v, &zone->vm_stat[i]);
92857- atomic_long_add(v, &vm_stat[i]);
92858+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92859+ atomic_long_add_unchecked(v, &vm_stat[i]);
92860 }
92861 }
92862 #endif
92863@@ -1281,10 +1281,20 @@ static int __init setup_vmstat(void)
92864 start_cpu_timer(cpu);
92865 #endif
92866 #ifdef CONFIG_PROC_FS
92867- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
92868- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
92869- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
92870- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
92871+ {
92872+ mode_t gr_mode = S_IRUGO;
92873+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92874+ gr_mode = S_IRUSR;
92875+#endif
92876+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
92877+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
92878+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
92879+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
92880+#else
92881+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
92882+#endif
92883+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
92884+ }
92885 #endif
92886 return 0;
92887 }
92888diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
92889index 61fc573..b5e47d0 100644
92890--- a/net/8021q/vlan.c
92891+++ b/net/8021q/vlan.c
92892@@ -472,7 +472,7 @@ out:
92893 return NOTIFY_DONE;
92894 }
92895
92896-static struct notifier_block vlan_notifier_block __read_mostly = {
92897+static struct notifier_block vlan_notifier_block = {
92898 .notifier_call = vlan_device_event,
92899 };
92900
92901@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
92902 err = -EPERM;
92903 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
92904 break;
92905- if ((args.u.name_type >= 0) &&
92906- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
92907+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
92908 struct vlan_net *vn;
92909
92910 vn = net_generic(net, vlan_net_id);
92911diff --git a/net/9p/mod.c b/net/9p/mod.c
92912index 6ab36ae..6f1841b 100644
92913--- a/net/9p/mod.c
92914+++ b/net/9p/mod.c
92915@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
92916 void v9fs_register_trans(struct p9_trans_module *m)
92917 {
92918 spin_lock(&v9fs_trans_lock);
92919- list_add_tail(&m->list, &v9fs_trans_list);
92920+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
92921 spin_unlock(&v9fs_trans_lock);
92922 }
92923 EXPORT_SYMBOL(v9fs_register_trans);
92924@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
92925 void v9fs_unregister_trans(struct p9_trans_module *m)
92926 {
92927 spin_lock(&v9fs_trans_lock);
92928- list_del_init(&m->list);
92929+ pax_list_del_init((struct list_head *)&m->list);
92930 spin_unlock(&v9fs_trans_lock);
92931 }
92932 EXPORT_SYMBOL(v9fs_unregister_trans);
92933diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
92934index 3ffda1b..fceac96 100644
92935--- a/net/9p/trans_fd.c
92936+++ b/net/9p/trans_fd.c
92937@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
92938 oldfs = get_fs();
92939 set_fs(get_ds());
92940 /* The cast to a user pointer is valid due to the set_fs() */
92941- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
92942+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
92943 set_fs(oldfs);
92944
92945 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
92946diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
92947index 876fbe8..8bbea9f 100644
92948--- a/net/atm/atm_misc.c
92949+++ b/net/atm/atm_misc.c
92950@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
92951 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
92952 return 1;
92953 atm_return(vcc, truesize);
92954- atomic_inc(&vcc->stats->rx_drop);
92955+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92956 return 0;
92957 }
92958 EXPORT_SYMBOL(atm_charge);
92959@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
92960 }
92961 }
92962 atm_return(vcc, guess);
92963- atomic_inc(&vcc->stats->rx_drop);
92964+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92965 return NULL;
92966 }
92967 EXPORT_SYMBOL(atm_alloc_charge);
92968@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
92969
92970 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92971 {
92972-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92973+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92974 __SONET_ITEMS
92975 #undef __HANDLE_ITEM
92976 }
92977@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
92978
92979 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92980 {
92981-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92982+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
92983 __SONET_ITEMS
92984 #undef __HANDLE_ITEM
92985 }
92986diff --git a/net/atm/lec.h b/net/atm/lec.h
92987index 4149db1..f2ab682 100644
92988--- a/net/atm/lec.h
92989+++ b/net/atm/lec.h
92990@@ -48,7 +48,7 @@ struct lane2_ops {
92991 const u8 *tlvs, u32 sizeoftlvs);
92992 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
92993 const u8 *tlvs, u32 sizeoftlvs);
92994-};
92995+} __no_const;
92996
92997 /*
92998 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
92999diff --git a/net/atm/proc.c b/net/atm/proc.c
93000index bbb6461..cf04016 100644
93001--- a/net/atm/proc.c
93002+++ b/net/atm/proc.c
93003@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
93004 const struct k_atm_aal_stats *stats)
93005 {
93006 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
93007- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
93008- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
93009- atomic_read(&stats->rx_drop));
93010+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
93011+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
93012+ atomic_read_unchecked(&stats->rx_drop));
93013 }
93014
93015 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
93016diff --git a/net/atm/resources.c b/net/atm/resources.c
93017index 0447d5d..3cf4728 100644
93018--- a/net/atm/resources.c
93019+++ b/net/atm/resources.c
93020@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
93021 static void copy_aal_stats(struct k_atm_aal_stats *from,
93022 struct atm_aal_stats *to)
93023 {
93024-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
93025+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
93026 __AAL_STAT_ITEMS
93027 #undef __HANDLE_ITEM
93028 }
93029@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
93030 static void subtract_aal_stats(struct k_atm_aal_stats *from,
93031 struct atm_aal_stats *to)
93032 {
93033-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
93034+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
93035 __AAL_STAT_ITEMS
93036 #undef __HANDLE_ITEM
93037 }
93038diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
93039index 919a5ce..cc6b444 100644
93040--- a/net/ax25/sysctl_net_ax25.c
93041+++ b/net/ax25/sysctl_net_ax25.c
93042@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
93043 {
93044 char path[sizeof("net/ax25/") + IFNAMSIZ];
93045 int k;
93046- struct ctl_table *table;
93047+ ctl_table_no_const *table;
93048
93049 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
93050 if (!table)
93051diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
93052index 0a8a80c..f7e89aa 100644
93053--- a/net/batman-adv/bat_iv_ogm.c
93054+++ b/net/batman-adv/bat_iv_ogm.c
93055@@ -121,7 +121,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
93056
93057 /* randomize initial seqno to avoid collision */
93058 get_random_bytes(&random_seqno, sizeof(random_seqno));
93059- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
93060+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
93061
93062 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
93063 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
93064@@ -703,9 +703,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
93065 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
93066
93067 /* change sequence number to network order */
93068- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
93069+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
93070 batadv_ogm_packet->seqno = htonl(seqno);
93071- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
93072+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
93073
93074 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
93075 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
93076@@ -1111,7 +1111,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
93077 return;
93078
93079 /* could be changed by schedule_own_packet() */
93080- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
93081+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
93082
93083 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
93084 has_directlink_flag = 1;
93085diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
93086index c478e6b..469fd2f 100644
93087--- a/net/batman-adv/hard-interface.c
93088+++ b/net/batman-adv/hard-interface.c
93089@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
93090 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
93091 dev_add_pack(&hard_iface->batman_adv_ptype);
93092
93093- atomic_set(&hard_iface->frag_seqno, 1);
93094+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
93095 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
93096 hard_iface->net_dev->name);
93097
93098diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
93099index 813db4e..847edac 100644
93100--- a/net/batman-adv/soft-interface.c
93101+++ b/net/batman-adv/soft-interface.c
93102@@ -263,7 +263,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
93103 primary_if->net_dev->dev_addr, ETH_ALEN);
93104
93105 /* set broadcast sequence number */
93106- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
93107+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
93108 bcast_packet->seqno = htonl(seqno);
93109
93110 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
93111@@ -483,7 +483,7 @@ static int batadv_softif_init_late(struct net_device *dev)
93112 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
93113
93114 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
93115- atomic_set(&bat_priv->bcast_seqno, 1);
93116+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
93117 atomic_set(&bat_priv->tt.vn, 0);
93118 atomic_set(&bat_priv->tt.local_changes, 0);
93119 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
93120diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
93121index b2c94e1..3d47e07 100644
93122--- a/net/batman-adv/types.h
93123+++ b/net/batman-adv/types.h
93124@@ -51,7 +51,7 @@
93125 struct batadv_hard_iface_bat_iv {
93126 unsigned char *ogm_buff;
93127 int ogm_buff_len;
93128- atomic_t ogm_seqno;
93129+ atomic_unchecked_t ogm_seqno;
93130 };
93131
93132 /**
93133@@ -76,7 +76,7 @@ struct batadv_hard_iface {
93134 int16_t if_num;
93135 char if_status;
93136 struct net_device *net_dev;
93137- atomic_t frag_seqno;
93138+ atomic_unchecked_t frag_seqno;
93139 uint8_t num_bcasts;
93140 struct kobject *hardif_obj;
93141 atomic_t refcount;
93142@@ -560,7 +560,7 @@ struct batadv_priv {
93143 #ifdef CONFIG_BATMAN_ADV_DEBUG
93144 atomic_t log_level;
93145 #endif
93146- atomic_t bcast_seqno;
93147+ atomic_unchecked_t bcast_seqno;
93148 atomic_t bcast_queue_left;
93149 atomic_t batman_queue_left;
93150 char num_ifaces;
93151diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
93152index 48b31d3..62a0bcb 100644
93153--- a/net/batman-adv/unicast.c
93154+++ b/net/batman-adv/unicast.c
93155@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
93156 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
93157 frag2->flags = large_tail;
93158
93159- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
93160+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
93161 frag1->seqno = htons(seqno - 1);
93162 frag2->seqno = htons(seqno);
93163
93164diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
93165index fa4bf66..e92948f 100644
93166--- a/net/bluetooth/hci_sock.c
93167+++ b/net/bluetooth/hci_sock.c
93168@@ -932,7 +932,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
93169 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
93170 }
93171
93172- len = min_t(unsigned int, len, sizeof(uf));
93173+ len = min((size_t)len, sizeof(uf));
93174 if (copy_from_user(&uf, optval, len)) {
93175 err = -EFAULT;
93176 break;
93177diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
93178index 63fa111..b166ec6 100644
93179--- a/net/bluetooth/l2cap_core.c
93180+++ b/net/bluetooth/l2cap_core.c
93181@@ -3511,8 +3511,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
93182 break;
93183
93184 case L2CAP_CONF_RFC:
93185- if (olen == sizeof(rfc))
93186- memcpy(&rfc, (void *)val, olen);
93187+ if (olen != sizeof(rfc))
93188+ break;
93189+
93190+ memcpy(&rfc, (void *)val, olen);
93191
93192 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
93193 rfc.mode != chan->mode)
93194diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
93195index 0098af8..fb5a31f 100644
93196--- a/net/bluetooth/l2cap_sock.c
93197+++ b/net/bluetooth/l2cap_sock.c
93198@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
93199 struct sock *sk = sock->sk;
93200 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
93201 struct l2cap_options opts;
93202- int len, err = 0;
93203+ int err = 0;
93204+ size_t len = optlen;
93205 u32 opt;
93206
93207 BT_DBG("sk %p", sk);
93208@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
93209 opts.max_tx = chan->max_tx;
93210 opts.txwin_size = chan->tx_win;
93211
93212- len = min_t(unsigned int, sizeof(opts), optlen);
93213+ len = min(sizeof(opts), len);
93214 if (copy_from_user((char *) &opts, optval, len)) {
93215 err = -EFAULT;
93216 break;
93217@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
93218 struct bt_security sec;
93219 struct bt_power pwr;
93220 struct l2cap_conn *conn;
93221- int len, err = 0;
93222+ int err = 0;
93223+ size_t len = optlen;
93224 u32 opt;
93225
93226 BT_DBG("sk %p", sk);
93227@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
93228
93229 sec.level = BT_SECURITY_LOW;
93230
93231- len = min_t(unsigned int, sizeof(sec), optlen);
93232+ len = min(sizeof(sec), len);
93233 if (copy_from_user((char *) &sec, optval, len)) {
93234 err = -EFAULT;
93235 break;
93236@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
93237
93238 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
93239
93240- len = min_t(unsigned int, sizeof(pwr), optlen);
93241+ len = min(sizeof(pwr), len);
93242 if (copy_from_user((char *) &pwr, optval, len)) {
93243 err = -EFAULT;
93244 break;
93245diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
93246index c1c6028..17e8dcc 100644
93247--- a/net/bluetooth/rfcomm/sock.c
93248+++ b/net/bluetooth/rfcomm/sock.c
93249@@ -665,7 +665,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
93250 struct sock *sk = sock->sk;
93251 struct bt_security sec;
93252 int err = 0;
93253- size_t len;
93254+ size_t len = optlen;
93255 u32 opt;
93256
93257 BT_DBG("sk %p", sk);
93258@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
93259
93260 sec.level = BT_SECURITY_LOW;
93261
93262- len = min_t(unsigned int, sizeof(sec), optlen);
93263+ len = min(sizeof(sec), len);
93264 if (copy_from_user((char *) &sec, optval, len)) {
93265 err = -EFAULT;
93266 break;
93267diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
93268index 84fcf9f..e389b27 100644
93269--- a/net/bluetooth/rfcomm/tty.c
93270+++ b/net/bluetooth/rfcomm/tty.c
93271@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
93272 BT_DBG("tty %p id %d", tty, tty->index);
93273
93274 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
93275- dev->channel, dev->port.count);
93276+ dev->channel, atomic_read(&dev->port.count));
93277
93278 err = tty_port_open(&dev->port, tty, filp);
93279 if (err)
93280@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
93281 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
93282
93283 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
93284- dev->port.count);
93285+ atomic_read(&dev->port.count));
93286
93287 tty_port_close(&dev->port, tty, filp);
93288 }
93289diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
93290index 5180938..7c470c3 100644
93291--- a/net/bridge/netfilter/ebt_ulog.c
93292+++ b/net/bridge/netfilter/ebt_ulog.c
93293@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
93294 ub->qlen++;
93295
93296 pm = nlmsg_data(nlh);
93297+ memset(pm, 0, sizeof(*pm));
93298
93299 /* Fill in the ulog data */
93300 pm->version = EBT_ULOG_VERSION;
93301@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
93302 pm->hook = hooknr;
93303 if (uloginfo->prefix != NULL)
93304 strcpy(pm->prefix, uloginfo->prefix);
93305- else
93306- *(pm->prefix) = '\0';
93307
93308 if (in) {
93309 strcpy(pm->physindev, in->name);
93310@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
93311 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
93312 else
93313 strcpy(pm->indev, in->name);
93314- } else
93315- pm->indev[0] = pm->physindev[0] = '\0';
93316+ }
93317
93318 if (out) {
93319 /* If out exists, then out is a bridge port */
93320 strcpy(pm->physoutdev, out->name);
93321 /* rcu_read_lock()ed by nf_hook_slow */
93322 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
93323- } else
93324- pm->outdev[0] = pm->physoutdev[0] = '\0';
93325+ }
93326
93327 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
93328 BUG();
93329diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
93330index ac78024..161a80c 100644
93331--- a/net/bridge/netfilter/ebtables.c
93332+++ b/net/bridge/netfilter/ebtables.c
93333@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93334 tmp.valid_hooks = t->table->valid_hooks;
93335 }
93336 mutex_unlock(&ebt_mutex);
93337- if (copy_to_user(user, &tmp, *len) != 0){
93338+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
93339 BUGPRINT("c2u Didn't work\n");
93340 ret = -EFAULT;
93341 break;
93342@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
93343 goto out;
93344 tmp.valid_hooks = t->valid_hooks;
93345
93346- if (copy_to_user(user, &tmp, *len) != 0) {
93347+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
93348 ret = -EFAULT;
93349 break;
93350 }
93351@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
93352 tmp.entries_size = t->table->entries_size;
93353 tmp.valid_hooks = t->table->valid_hooks;
93354
93355- if (copy_to_user(user, &tmp, *len) != 0) {
93356+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
93357 ret = -EFAULT;
93358 break;
93359 }
93360diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
93361index 0f45522..dab651f 100644
93362--- a/net/caif/cfctrl.c
93363+++ b/net/caif/cfctrl.c
93364@@ -10,6 +10,7 @@
93365 #include <linux/spinlock.h>
93366 #include <linux/slab.h>
93367 #include <linux/pkt_sched.h>
93368+#include <linux/sched.h>
93369 #include <net/caif/caif_layer.h>
93370 #include <net/caif/cfpkt.h>
93371 #include <net/caif/cfctrl.h>
93372@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
93373 memset(&dev_info, 0, sizeof(dev_info));
93374 dev_info.id = 0xff;
93375 cfsrvl_init(&this->serv, 0, &dev_info, false);
93376- atomic_set(&this->req_seq_no, 1);
93377- atomic_set(&this->rsp_seq_no, 1);
93378+ atomic_set_unchecked(&this->req_seq_no, 1);
93379+ atomic_set_unchecked(&this->rsp_seq_no, 1);
93380 this->serv.layer.receive = cfctrl_recv;
93381 sprintf(this->serv.layer.name, "ctrl");
93382 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
93383@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
93384 struct cfctrl_request_info *req)
93385 {
93386 spin_lock_bh(&ctrl->info_list_lock);
93387- atomic_inc(&ctrl->req_seq_no);
93388- req->sequence_no = atomic_read(&ctrl->req_seq_no);
93389+ atomic_inc_unchecked(&ctrl->req_seq_no);
93390+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
93391 list_add_tail(&req->list, &ctrl->list);
93392 spin_unlock_bh(&ctrl->info_list_lock);
93393 }
93394@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
93395 if (p != first)
93396 pr_warn("Requests are not received in order\n");
93397
93398- atomic_set(&ctrl->rsp_seq_no,
93399+ atomic_set_unchecked(&ctrl->rsp_seq_no,
93400 p->sequence_no);
93401 list_del(&p->list);
93402 goto out;
93403diff --git a/net/can/af_can.c b/net/can/af_can.c
93404index 3ab8dd2..b9aef13 100644
93405--- a/net/can/af_can.c
93406+++ b/net/can/af_can.c
93407@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
93408 };
93409
93410 /* notifier block for netdevice event */
93411-static struct notifier_block can_netdev_notifier __read_mostly = {
93412+static struct notifier_block can_netdev_notifier = {
93413 .notifier_call = can_notifier,
93414 };
93415
93416diff --git a/net/can/gw.c b/net/can/gw.c
93417index 3f9b0f3..fc6d4fa 100644
93418--- a/net/can/gw.c
93419+++ b/net/can/gw.c
93420@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
93421 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
93422
93423 static HLIST_HEAD(cgw_list);
93424-static struct notifier_block notifier;
93425
93426 static struct kmem_cache *cgw_cache __read_mostly;
93427
93428@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
93429 return err;
93430 }
93431
93432+static struct notifier_block notifier = {
93433+ .notifier_call = cgw_notifier
93434+};
93435+
93436 static __init int cgw_module_init(void)
93437 {
93438 /* sanitize given module parameter */
93439@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
93440 return -ENOMEM;
93441
93442 /* set notifier */
93443- notifier.notifier_call = cgw_notifier;
93444 register_netdevice_notifier(&notifier);
93445
93446 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
93447diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
93448index 4a5df7b..9ad1f1d 100644
93449--- a/net/ceph/messenger.c
93450+++ b/net/ceph/messenger.c
93451@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
93452 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
93453
93454 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
93455-static atomic_t addr_str_seq = ATOMIC_INIT(0);
93456+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
93457
93458 static struct page *zero_page; /* used in certain error cases */
93459
93460@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
93461 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
93462 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
93463
93464- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
93465+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
93466 s = addr_str[i];
93467
93468 switch (ss->ss_family) {
93469diff --git a/net/compat.c b/net/compat.c
93470index dd32e34..6066f87 100644
93471--- a/net/compat.c
93472+++ b/net/compat.c
93473@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
93474 return -EFAULT;
93475 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
93476 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
93477- kmsg->msg_name = compat_ptr(tmp1);
93478- kmsg->msg_iov = compat_ptr(tmp2);
93479- kmsg->msg_control = compat_ptr(tmp3);
93480+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
93481+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
93482+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
93483 return 0;
93484 }
93485
93486@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
93487
93488 if (kern_msg->msg_namelen) {
93489 if (mode == VERIFY_READ) {
93490- int err = move_addr_to_kernel(kern_msg->msg_name,
93491+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
93492 kern_msg->msg_namelen,
93493 kern_address);
93494 if (err < 0)
93495@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
93496 kern_msg->msg_name = NULL;
93497
93498 tot_len = iov_from_user_compat_to_kern(kern_iov,
93499- (struct compat_iovec __user *)kern_msg->msg_iov,
93500+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
93501 kern_msg->msg_iovlen);
93502 if (tot_len >= 0)
93503 kern_msg->msg_iov = kern_iov;
93504@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
93505
93506 #define CMSG_COMPAT_FIRSTHDR(msg) \
93507 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
93508- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
93509+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
93510 (struct compat_cmsghdr __user *)NULL)
93511
93512 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
93513 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
93514 (ucmlen) <= (unsigned long) \
93515 ((mhdr)->msg_controllen - \
93516- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
93517+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
93518
93519 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
93520 struct compat_cmsghdr __user *cmsg, int cmsg_len)
93521 {
93522 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
93523- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
93524+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
93525 msg->msg_controllen)
93526 return NULL;
93527 return (struct compat_cmsghdr __user *)ptr;
93528@@ -222,7 +222,7 @@ Efault:
93529
93530 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
93531 {
93532- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
93533+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
93534 struct compat_cmsghdr cmhdr;
93535 struct compat_timeval ctv;
93536 struct compat_timespec cts[3];
93537@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
93538
93539 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
93540 {
93541- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
93542+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
93543 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
93544 int fdnum = scm->fp->count;
93545 struct file **fp = scm->fp->fp;
93546@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
93547 return -EFAULT;
93548 old_fs = get_fs();
93549 set_fs(KERNEL_DS);
93550- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
93551+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
93552 set_fs(old_fs);
93553
93554 return err;
93555@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
93556 len = sizeof(ktime);
93557 old_fs = get_fs();
93558 set_fs(KERNEL_DS);
93559- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
93560+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
93561 set_fs(old_fs);
93562
93563 if (!err) {
93564@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
93565 case MCAST_JOIN_GROUP:
93566 case MCAST_LEAVE_GROUP:
93567 {
93568- struct compat_group_req __user *gr32 = (void *)optval;
93569+ struct compat_group_req __user *gr32 = (void __user *)optval;
93570 struct group_req __user *kgr =
93571 compat_alloc_user_space(sizeof(struct group_req));
93572 u32 interface;
93573@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
93574 case MCAST_BLOCK_SOURCE:
93575 case MCAST_UNBLOCK_SOURCE:
93576 {
93577- struct compat_group_source_req __user *gsr32 = (void *)optval;
93578+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
93579 struct group_source_req __user *kgsr = compat_alloc_user_space(
93580 sizeof(struct group_source_req));
93581 u32 interface;
93582@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
93583 }
93584 case MCAST_MSFILTER:
93585 {
93586- struct compat_group_filter __user *gf32 = (void *)optval;
93587+ struct compat_group_filter __user *gf32 = (void __user *)optval;
93588 struct group_filter __user *kgf;
93589 u32 interface, fmode, numsrc;
93590
93591@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
93592 char __user *optval, int __user *optlen,
93593 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
93594 {
93595- struct compat_group_filter __user *gf32 = (void *)optval;
93596+ struct compat_group_filter __user *gf32 = (void __user *)optval;
93597 struct group_filter __user *kgf;
93598 int __user *koptlen;
93599 u32 interface, fmode, numsrc;
93600@@ -808,7 +808,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
93601
93602 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
93603 return -EINVAL;
93604- if (copy_from_user(a, args, nas[call]))
93605+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
93606 return -EFAULT;
93607 a0 = a[0];
93608 a1 = a[1];
93609diff --git a/net/core/datagram.c b/net/core/datagram.c
93610index af814e7..3d761de 100644
93611--- a/net/core/datagram.c
93612+++ b/net/core/datagram.c
93613@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
93614 }
93615
93616 kfree_skb(skb);
93617- atomic_inc(&sk->sk_drops);
93618+ atomic_inc_unchecked(&sk->sk_drops);
93619 sk_mem_reclaim_partial(sk);
93620
93621 return err;
93622diff --git a/net/core/dev.c b/net/core/dev.c
93623index 3d13874..6e78dc7 100644
93624--- a/net/core/dev.c
93625+++ b/net/core/dev.c
93626@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
93627 {
93628 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
93629 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
93630- atomic_long_inc(&dev->rx_dropped);
93631+ atomic_long_inc_unchecked(&dev->rx_dropped);
93632 kfree_skb(skb);
93633 return NET_RX_DROP;
93634 }
93635 }
93636
93637 if (unlikely(!is_skb_forwardable(dev, skb))) {
93638- atomic_long_inc(&dev->rx_dropped);
93639+ atomic_long_inc_unchecked(&dev->rx_dropped);
93640 kfree_skb(skb);
93641 return NET_RX_DROP;
93642 }
93643@@ -2428,7 +2428,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
93644
93645 struct dev_gso_cb {
93646 void (*destructor)(struct sk_buff *skb);
93647-};
93648+} __no_const;
93649
93650 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
93651
93652@@ -3203,7 +3203,7 @@ enqueue:
93653
93654 local_irq_restore(flags);
93655
93656- atomic_long_inc(&skb->dev->rx_dropped);
93657+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93658 kfree_skb(skb);
93659 return NET_RX_DROP;
93660 }
93661@@ -3275,7 +3275,7 @@ int netif_rx_ni(struct sk_buff *skb)
93662 }
93663 EXPORT_SYMBOL(netif_rx_ni);
93664
93665-static void net_tx_action(struct softirq_action *h)
93666+static __latent_entropy void net_tx_action(void)
93667 {
93668 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93669
93670@@ -3609,7 +3609,7 @@ ncls:
93671 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
93672 } else {
93673 drop:
93674- atomic_long_inc(&skb->dev->rx_dropped);
93675+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93676 kfree_skb(skb);
93677 /* Jamal, now you will not able to escape explaining
93678 * me how you were going to use this. :-)
93679@@ -4269,7 +4269,7 @@ void netif_napi_del(struct napi_struct *napi)
93680 }
93681 EXPORT_SYMBOL(netif_napi_del);
93682
93683-static void net_rx_action(struct softirq_action *h)
93684+static __latent_entropy void net_rx_action(void)
93685 {
93686 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93687 unsigned long time_limit = jiffies + 2;
93688@@ -5973,7 +5973,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
93689 } else {
93690 netdev_stats_to_stats64(storage, &dev->stats);
93691 }
93692- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
93693+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
93694 return storage;
93695 }
93696 EXPORT_SYMBOL(dev_get_stats);
93697diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
93698index 5b7d0e1..cb960fc 100644
93699--- a/net/core/dev_ioctl.c
93700+++ b/net/core/dev_ioctl.c
93701@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
93702 if (no_module && capable(CAP_NET_ADMIN))
93703 no_module = request_module("netdev-%s", name);
93704 if (no_module && capable(CAP_SYS_MODULE)) {
93705+#ifdef CONFIG_GRKERNSEC_MODHARDEN
93706+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
93707+#else
93708 if (!request_module("%s", name))
93709 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
93710 name);
93711+#endif
93712 }
93713 }
93714 EXPORT_SYMBOL(dev_load);
93715diff --git a/net/core/flow.c b/net/core/flow.c
93716index dfa602c..3103d88 100644
93717--- a/net/core/flow.c
93718+++ b/net/core/flow.c
93719@@ -61,7 +61,7 @@ struct flow_cache {
93720 struct timer_list rnd_timer;
93721 };
93722
93723-atomic_t flow_cache_genid = ATOMIC_INIT(0);
93724+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
93725 EXPORT_SYMBOL(flow_cache_genid);
93726 static struct flow_cache flow_cache_global;
93727 static struct kmem_cache *flow_cachep __read_mostly;
93728@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
93729
93730 static int flow_entry_valid(struct flow_cache_entry *fle)
93731 {
93732- if (atomic_read(&flow_cache_genid) != fle->genid)
93733+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
93734 return 0;
93735 if (fle->object && !fle->object->ops->check(fle->object))
93736 return 0;
93737@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
93738 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
93739 fcp->hash_count++;
93740 }
93741- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
93742+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
93743 flo = fle->object;
93744 if (!flo)
93745 goto ret_object;
93746@@ -279,7 +279,7 @@ nocache:
93747 }
93748 flo = resolver(net, key, family, dir, flo, ctx);
93749 if (fle) {
93750- fle->genid = atomic_read(&flow_cache_genid);
93751+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
93752 if (!IS_ERR(flo))
93753 fle->object = flo;
93754 else
93755diff --git a/net/core/iovec.c b/net/core/iovec.c
93756index 7d84ea1..55385ae 100644
93757--- a/net/core/iovec.c
93758+++ b/net/core/iovec.c
93759@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93760 if (m->msg_namelen) {
93761 if (mode == VERIFY_READ) {
93762 void __user *namep;
93763- namep = (void __user __force *) m->msg_name;
93764+ namep = (void __force_user *) m->msg_name;
93765 err = move_addr_to_kernel(namep, m->msg_namelen,
93766 address);
93767 if (err < 0)
93768@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93769 }
93770
93771 size = m->msg_iovlen * sizeof(struct iovec);
93772- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
93773+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
93774 return -EFAULT;
93775
93776 m->msg_iov = iov;
93777diff --git a/net/core/neighbour.c b/net/core/neighbour.c
93778index 6072610..7374c18 100644
93779--- a/net/core/neighbour.c
93780+++ b/net/core/neighbour.c
93781@@ -2774,7 +2774,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
93782 void __user *buffer, size_t *lenp, loff_t *ppos)
93783 {
93784 int size, ret;
93785- struct ctl_table tmp = *ctl;
93786+ ctl_table_no_const tmp = *ctl;
93787
93788 tmp.extra1 = &zero;
93789 tmp.extra2 = &unres_qlen_max;
93790diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
93791index 2bf8329..7960607 100644
93792--- a/net/core/net-procfs.c
93793+++ b/net/core/net-procfs.c
93794@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
93795 else
93796 seq_printf(seq, "%04x", ntohs(pt->type));
93797
93798+#ifdef CONFIG_GRKERNSEC_HIDESYM
93799+ seq_printf(seq, " %-8s %pf\n",
93800+ pt->dev ? pt->dev->name : "", NULL);
93801+#else
93802 seq_printf(seq, " %-8s %pf\n",
93803 pt->dev ? pt->dev->name : "", pt->func);
93804+#endif
93805 }
93806
93807 return 0;
93808diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
93809index d954b56..b0a0f7a 100644
93810--- a/net/core/net-sysfs.c
93811+++ b/net/core/net-sysfs.c
93812@@ -1356,7 +1356,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
93813 }
93814 EXPORT_SYMBOL(netdev_class_remove_file);
93815
93816-int netdev_kobject_init(void)
93817+int __init netdev_kobject_init(void)
93818 {
93819 kobj_ns_type_register(&net_ns_type_operations);
93820 return class_register(&net_class);
93821diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
93822index 81d3a9a..a0bd7a8 100644
93823--- a/net/core/net_namespace.c
93824+++ b/net/core/net_namespace.c
93825@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
93826 int error;
93827 LIST_HEAD(net_exit_list);
93828
93829- list_add_tail(&ops->list, list);
93830+ pax_list_add_tail((struct list_head *)&ops->list, list);
93831 if (ops->init || (ops->id && ops->size)) {
93832 for_each_net(net) {
93833 error = ops_init(ops, net);
93834@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
93835
93836 out_undo:
93837 /* If I have an error cleanup all namespaces I initialized */
93838- list_del(&ops->list);
93839+ pax_list_del((struct list_head *)&ops->list);
93840 ops_exit_list(ops, &net_exit_list);
93841 ops_free_list(ops, &net_exit_list);
93842 return error;
93843@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
93844 struct net *net;
93845 LIST_HEAD(net_exit_list);
93846
93847- list_del(&ops->list);
93848+ pax_list_del((struct list_head *)&ops->list);
93849 for_each_net(net)
93850 list_add_tail(&net->exit_list, &net_exit_list);
93851 ops_exit_list(ops, &net_exit_list);
93852@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
93853 mutex_lock(&net_mutex);
93854 error = register_pernet_operations(&pernet_list, ops);
93855 if (!error && (first_device == &pernet_list))
93856- first_device = &ops->list;
93857+ first_device = (struct list_head *)&ops->list;
93858 mutex_unlock(&net_mutex);
93859 return error;
93860 }
93861diff --git a/net/core/netpoll.c b/net/core/netpoll.c
93862index fc75c9e..8c8e9be 100644
93863--- a/net/core/netpoll.c
93864+++ b/net/core/netpoll.c
93865@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93866 struct udphdr *udph;
93867 struct iphdr *iph;
93868 struct ethhdr *eth;
93869- static atomic_t ip_ident;
93870+ static atomic_unchecked_t ip_ident;
93871 struct ipv6hdr *ip6h;
93872
93873 udp_len = len + sizeof(*udph);
93874@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93875 put_unaligned(0x45, (unsigned char *)iph);
93876 iph->tos = 0;
93877 put_unaligned(htons(ip_len), &(iph->tot_len));
93878- iph->id = htons(atomic_inc_return(&ip_ident));
93879+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
93880 iph->frag_off = 0;
93881 iph->ttl = 64;
93882 iph->protocol = IPPROTO_UDP;
93883diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
93884index 2a0e21d..6ad7642 100644
93885--- a/net/core/rtnetlink.c
93886+++ b/net/core/rtnetlink.c
93887@@ -58,7 +58,7 @@ struct rtnl_link {
93888 rtnl_doit_func doit;
93889 rtnl_dumpit_func dumpit;
93890 rtnl_calcit_func calcit;
93891-};
93892+} __no_const;
93893
93894 static DEFINE_MUTEX(rtnl_mutex);
93895
93896@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
93897 if (rtnl_link_ops_get(ops->kind))
93898 return -EEXIST;
93899
93900- if (!ops->dellink)
93901- ops->dellink = unregister_netdevice_queue;
93902+ if (!ops->dellink) {
93903+ pax_open_kernel();
93904+ *(void **)&ops->dellink = unregister_netdevice_queue;
93905+ pax_close_kernel();
93906+ }
93907
93908- list_add_tail(&ops->list, &link_ops);
93909+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
93910 return 0;
93911 }
93912 EXPORT_SYMBOL_GPL(__rtnl_link_register);
93913@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
93914 for_each_net(net) {
93915 __rtnl_kill_links(net, ops);
93916 }
93917- list_del(&ops->list);
93918+ pax_list_del((struct list_head *)&ops->list);
93919 }
93920 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
93921
93922diff --git a/net/core/scm.c b/net/core/scm.c
93923index b442e7e..6f5b5a2 100644
93924--- a/net/core/scm.c
93925+++ b/net/core/scm.c
93926@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
93927 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93928 {
93929 struct cmsghdr __user *cm
93930- = (__force struct cmsghdr __user *)msg->msg_control;
93931+ = (struct cmsghdr __force_user *)msg->msg_control;
93932 struct cmsghdr cmhdr;
93933 int cmlen = CMSG_LEN(len);
93934 int err;
93935@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93936 err = -EFAULT;
93937 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
93938 goto out;
93939- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
93940+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
93941 goto out;
93942 cmlen = CMSG_SPACE(len);
93943 if (msg->msg_controllen < cmlen)
93944@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
93945 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93946 {
93947 struct cmsghdr __user *cm
93948- = (__force struct cmsghdr __user*)msg->msg_control;
93949+ = (struct cmsghdr __force_user *)msg->msg_control;
93950
93951 int fdmax = 0;
93952 int fdnum = scm->fp->count;
93953@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93954 if (fdnum < fdmax)
93955 fdmax = fdnum;
93956
93957- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
93958+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
93959 i++, cmfptr++)
93960 {
93961 struct socket *sock;
93962diff --git a/net/core/skbuff.c b/net/core/skbuff.c
93963index c28c7fe..a399a6d 100644
93964--- a/net/core/skbuff.c
93965+++ b/net/core/skbuff.c
93966@@ -3104,13 +3104,15 @@ void __init skb_init(void)
93967 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
93968 sizeof(struct sk_buff),
93969 0,
93970- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93971+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93972+ SLAB_NO_SANITIZE,
93973 NULL);
93974 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
93975 (2*sizeof(struct sk_buff)) +
93976 sizeof(atomic_t),
93977 0,
93978- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93979+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93980+ SLAB_NO_SANITIZE,
93981 NULL);
93982 }
93983
93984@@ -3541,6 +3543,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
93985 skb->tstamp.tv64 = 0;
93986 skb->pkt_type = PACKET_HOST;
93987 skb->skb_iif = 0;
93988+ skb->local_df = 0;
93989 skb_dst_drop(skb);
93990 skb->mark = 0;
93991 secpath_reset(skb);
93992diff --git a/net/core/sock.c b/net/core/sock.c
93993index 0b39e7a..5e9f91e 100644
93994--- a/net/core/sock.c
93995+++ b/net/core/sock.c
93996@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93997 struct sk_buff_head *list = &sk->sk_receive_queue;
93998
93999 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
94000- atomic_inc(&sk->sk_drops);
94001+ atomic_inc_unchecked(&sk->sk_drops);
94002 trace_sock_rcvqueue_full(sk, skb);
94003 return -ENOMEM;
94004 }
94005@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
94006 return err;
94007
94008 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
94009- atomic_inc(&sk->sk_drops);
94010+ atomic_inc_unchecked(&sk->sk_drops);
94011 return -ENOBUFS;
94012 }
94013
94014@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
94015 skb_dst_force(skb);
94016
94017 spin_lock_irqsave(&list->lock, flags);
94018- skb->dropcount = atomic_read(&sk->sk_drops);
94019+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
94020 __skb_queue_tail(list, skb);
94021 spin_unlock_irqrestore(&list->lock, flags);
94022
94023@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
94024 skb->dev = NULL;
94025
94026 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
94027- atomic_inc(&sk->sk_drops);
94028+ atomic_inc_unchecked(&sk->sk_drops);
94029 goto discard_and_relse;
94030 }
94031 if (nested)
94032@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
94033 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
94034 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
94035 bh_unlock_sock(sk);
94036- atomic_inc(&sk->sk_drops);
94037+ atomic_inc_unchecked(&sk->sk_drops);
94038 goto discard_and_relse;
94039 }
94040
94041@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
94042 struct timeval tm;
94043 } v;
94044
94045- int lv = sizeof(int);
94046- int len;
94047+ unsigned int lv = sizeof(int);
94048+ unsigned int len;
94049
94050 if (get_user(len, optlen))
94051 return -EFAULT;
94052- if (len < 0)
94053+ if (len > INT_MAX)
94054 return -EINVAL;
94055
94056 memset(&v, 0, sizeof(v));
94057@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
94058
94059 case SO_PEERNAME:
94060 {
94061- char address[128];
94062+ char address[_K_SS_MAXSIZE];
94063
94064 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
94065 return -ENOTCONN;
94066- if (lv < len)
94067+ if (lv < len || sizeof address < len)
94068 return -EINVAL;
94069 if (copy_to_user(optval, address, len))
94070 return -EFAULT;
94071@@ -1183,7 +1183,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
94072
94073 if (len > lv)
94074 len = lv;
94075- if (copy_to_user(optval, &v, len))
94076+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
94077 return -EFAULT;
94078 lenout:
94079 if (put_user(len, optlen))
94080@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
94081 */
94082 smp_wmb();
94083 atomic_set(&sk->sk_refcnt, 1);
94084- atomic_set(&sk->sk_drops, 0);
94085+ atomic_set_unchecked(&sk->sk_drops, 0);
94086 }
94087 EXPORT_SYMBOL(sock_init_data);
94088
94089@@ -2451,6 +2451,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
94090 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
94091 int level, int type)
94092 {
94093+ struct sock_extended_err ee;
94094 struct sock_exterr_skb *serr;
94095 struct sk_buff *skb, *skb2;
94096 int copied, err;
94097@@ -2472,7 +2473,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
94098 sock_recv_timestamp(msg, sk, skb);
94099
94100 serr = SKB_EXT_ERR(skb);
94101- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
94102+ ee = serr->ee;
94103+ put_cmsg(msg, level, type, sizeof ee, &ee);
94104
94105 msg->msg_flags |= MSG_ERRQUEUE;
94106 err = copied;
94107diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
94108index a0e9cf6..ef7f9ed 100644
94109--- a/net/core/sock_diag.c
94110+++ b/net/core/sock_diag.c
94111@@ -9,26 +9,33 @@
94112 #include <linux/inet_diag.h>
94113 #include <linux/sock_diag.h>
94114
94115-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
94116+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
94117 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
94118 static DEFINE_MUTEX(sock_diag_table_mutex);
94119
94120 int sock_diag_check_cookie(void *sk, __u32 *cookie)
94121 {
94122+#ifndef CONFIG_GRKERNSEC_HIDESYM
94123 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
94124 cookie[1] != INET_DIAG_NOCOOKIE) &&
94125 ((u32)(unsigned long)sk != cookie[0] ||
94126 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
94127 return -ESTALE;
94128 else
94129+#endif
94130 return 0;
94131 }
94132 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
94133
94134 void sock_diag_save_cookie(void *sk, __u32 *cookie)
94135 {
94136+#ifdef CONFIG_GRKERNSEC_HIDESYM
94137+ cookie[0] = 0;
94138+ cookie[1] = 0;
94139+#else
94140 cookie[0] = (u32)(unsigned long)sk;
94141 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
94142+#endif
94143 }
94144 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
94145
94146@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
94147 mutex_lock(&sock_diag_table_mutex);
94148 if (sock_diag_handlers[hndl->family])
94149 err = -EBUSY;
94150- else
94151+ else {
94152+ pax_open_kernel();
94153 sock_diag_handlers[hndl->family] = hndl;
94154+ pax_close_kernel();
94155+ }
94156 mutex_unlock(&sock_diag_table_mutex);
94157
94158 return err;
94159@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
94160
94161 mutex_lock(&sock_diag_table_mutex);
94162 BUG_ON(sock_diag_handlers[family] != hnld);
94163+ pax_open_kernel();
94164 sock_diag_handlers[family] = NULL;
94165+ pax_close_kernel();
94166 mutex_unlock(&sock_diag_table_mutex);
94167 }
94168 EXPORT_SYMBOL_GPL(sock_diag_unregister);
94169diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
94170index cca4441..5e616de 100644
94171--- a/net/core/sysctl_net_core.c
94172+++ b/net/core/sysctl_net_core.c
94173@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
94174 {
94175 unsigned int orig_size, size;
94176 int ret, i;
94177- struct ctl_table tmp = {
94178+ ctl_table_no_const tmp = {
94179 .data = &size,
94180 .maxlen = sizeof(size),
94181 .mode = table->mode
94182@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
94183 void __user *buffer, size_t *lenp, loff_t *ppos)
94184 {
94185 char id[IFNAMSIZ];
94186- struct ctl_table tbl = {
94187+ ctl_table_no_const tbl = {
94188 .data = id,
94189 .maxlen = IFNAMSIZ,
94190 };
94191@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
94192
94193 static __net_init int sysctl_core_net_init(struct net *net)
94194 {
94195- struct ctl_table *tbl;
94196+ ctl_table_no_const *tbl = NULL;
94197
94198 net->core.sysctl_somaxconn = SOMAXCONN;
94199
94200- tbl = netns_core_table;
94201 if (!net_eq(net, &init_net)) {
94202- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
94203+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
94204 if (tbl == NULL)
94205 goto err_dup;
94206
94207@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
94208 if (net->user_ns != &init_user_ns) {
94209 tbl[0].procname = NULL;
94210 }
94211- }
94212-
94213- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
94214+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
94215+ } else
94216+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
94217 if (net->core.sysctl_hdr == NULL)
94218 goto err_reg;
94219
94220 return 0;
94221
94222 err_reg:
94223- if (tbl != netns_core_table)
94224- kfree(tbl);
94225+ kfree(tbl);
94226 err_dup:
94227 return -ENOMEM;
94228 }
94229@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
94230 kfree(tbl);
94231 }
94232
94233-static __net_initdata struct pernet_operations sysctl_core_ops = {
94234+static __net_initconst struct pernet_operations sysctl_core_ops = {
94235 .init = sysctl_core_net_init,
94236 .exit = sysctl_core_net_exit,
94237 };
94238diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
94239index dd4d506..fb2fb87 100644
94240--- a/net/decnet/af_decnet.c
94241+++ b/net/decnet/af_decnet.c
94242@@ -465,6 +465,7 @@ static struct proto dn_proto = {
94243 .sysctl_rmem = sysctl_decnet_rmem,
94244 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
94245 .obj_size = sizeof(struct dn_sock),
94246+ .slab_flags = SLAB_USERCOPY,
94247 };
94248
94249 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
94250diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
94251index 5325b54..a0d4d69 100644
94252--- a/net/decnet/sysctl_net_decnet.c
94253+++ b/net/decnet/sysctl_net_decnet.c
94254@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
94255
94256 if (len > *lenp) len = *lenp;
94257
94258- if (copy_to_user(buffer, addr, len))
94259+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
94260 return -EFAULT;
94261
94262 *lenp = len;
94263@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
94264
94265 if (len > *lenp) len = *lenp;
94266
94267- if (copy_to_user(buffer, devname, len))
94268+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
94269 return -EFAULT;
94270
94271 *lenp = len;
94272diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
94273index 008f337..b03b8c9 100644
94274--- a/net/ieee802154/6lowpan.c
94275+++ b/net/ieee802154/6lowpan.c
94276@@ -548,7 +548,7 @@ static int lowpan_header_create(struct sk_buff *skb,
94277 hc06_ptr += 3;
94278 } else {
94279 /* compress nothing */
94280- memcpy(hc06_ptr, &hdr, 4);
94281+ memcpy(hc06_ptr, hdr, 4);
94282 /* replace the top byte with new ECN | DSCP format */
94283 *hc06_ptr = tmp;
94284 hc06_ptr += 4;
94285diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
94286index cfeb85c..385989a 100644
94287--- a/net/ipv4/af_inet.c
94288+++ b/net/ipv4/af_inet.c
94289@@ -1675,13 +1675,9 @@ static int __init inet_init(void)
94290
94291 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
94292
94293- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
94294- if (!sysctl_local_reserved_ports)
94295- goto out;
94296-
94297 rc = proto_register(&tcp_prot, 1);
94298 if (rc)
94299- goto out_free_reserved_ports;
94300+ goto out;
94301
94302 rc = proto_register(&udp_prot, 1);
94303 if (rc)
94304@@ -1790,8 +1786,6 @@ out_unregister_udp_proto:
94305 proto_unregister(&udp_prot);
94306 out_unregister_tcp_proto:
94307 proto_unregister(&tcp_prot);
94308-out_free_reserved_ports:
94309- kfree(sysctl_local_reserved_ports);
94310 goto out;
94311 }
94312
94313diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
94314index a1b5bcb..62ec5c6 100644
94315--- a/net/ipv4/devinet.c
94316+++ b/net/ipv4/devinet.c
94317@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
94318 idx = 0;
94319 head = &net->dev_index_head[h];
94320 rcu_read_lock();
94321- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
94322+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
94323 net->dev_base_seq;
94324 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94325 if (idx < s_idx)
94326@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
94327 idx = 0;
94328 head = &net->dev_index_head[h];
94329 rcu_read_lock();
94330- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
94331+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
94332 net->dev_base_seq;
94333 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94334 if (idx < s_idx)
94335@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
94336 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
94337 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
94338
94339-static struct devinet_sysctl_table {
94340+static const struct devinet_sysctl_table {
94341 struct ctl_table_header *sysctl_header;
94342 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
94343 } devinet_sysctl = {
94344@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
94345 int err;
94346 struct ipv4_devconf *all, *dflt;
94347 #ifdef CONFIG_SYSCTL
94348- struct ctl_table *tbl = ctl_forward_entry;
94349+ ctl_table_no_const *tbl = NULL;
94350 struct ctl_table_header *forw_hdr;
94351 #endif
94352
94353@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
94354 goto err_alloc_dflt;
94355
94356 #ifdef CONFIG_SYSCTL
94357- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
94358+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
94359 if (tbl == NULL)
94360 goto err_alloc_ctl;
94361
94362@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
94363 goto err_reg_dflt;
94364
94365 err = -ENOMEM;
94366- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
94367+ if (!net_eq(net, &init_net))
94368+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
94369+ else
94370+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
94371 if (forw_hdr == NULL)
94372 goto err_reg_ctl;
94373 net->ipv4.forw_hdr = forw_hdr;
94374@@ -2245,8 +2248,7 @@ err_reg_ctl:
94375 err_reg_dflt:
94376 __devinet_sysctl_unregister(all);
94377 err_reg_all:
94378- if (tbl != ctl_forward_entry)
94379- kfree(tbl);
94380+ kfree(tbl);
94381 err_alloc_ctl:
94382 #endif
94383 if (dflt != &ipv4_devconf_dflt)
94384diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
94385index b3f627a..b0f3e99 100644
94386--- a/net/ipv4/fib_frontend.c
94387+++ b/net/ipv4/fib_frontend.c
94388@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
94389 #ifdef CONFIG_IP_ROUTE_MULTIPATH
94390 fib_sync_up(dev);
94391 #endif
94392- atomic_inc(&net->ipv4.dev_addr_genid);
94393+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
94394 rt_cache_flush(dev_net(dev));
94395 break;
94396 case NETDEV_DOWN:
94397 fib_del_ifaddr(ifa, NULL);
94398- atomic_inc(&net->ipv4.dev_addr_genid);
94399+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
94400 if (ifa->ifa_dev->ifa_list == NULL) {
94401 /* Last address was deleted from this interface.
94402 * Disable IP.
94403@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
94404 #ifdef CONFIG_IP_ROUTE_MULTIPATH
94405 fib_sync_up(dev);
94406 #endif
94407- atomic_inc(&net->ipv4.dev_addr_genid);
94408+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
94409 rt_cache_flush(net);
94410 break;
94411 case NETDEV_DOWN:
94412diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
94413index d5dbca5..6251d5f 100644
94414--- a/net/ipv4/fib_semantics.c
94415+++ b/net/ipv4/fib_semantics.c
94416@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
94417 nh->nh_saddr = inet_select_addr(nh->nh_dev,
94418 nh->nh_gw,
94419 nh->nh_parent->fib_scope);
94420- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
94421+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
94422
94423 return nh->nh_saddr;
94424 }
94425diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
94426index 6acb541..9ea617d 100644
94427--- a/net/ipv4/inet_connection_sock.c
94428+++ b/net/ipv4/inet_connection_sock.c
94429@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
94430 .range = { 32768, 61000 },
94431 };
94432
94433-unsigned long *sysctl_local_reserved_ports;
94434+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
94435 EXPORT_SYMBOL(sysctl_local_reserved_ports);
94436
94437 void inet_get_local_port_range(int *low, int *high)
94438diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
94439index 5f64875..31cf54d 100644
94440--- a/net/ipv4/inet_diag.c
94441+++ b/net/ipv4/inet_diag.c
94442@@ -106,6 +106,10 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
94443
94444 r->id.idiag_sport = inet->inet_sport;
94445 r->id.idiag_dport = inet->inet_dport;
94446+
94447+ memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
94448+ memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
94449+
94450 r->id.idiag_src[0] = inet->inet_rcv_saddr;
94451 r->id.idiag_dst[0] = inet->inet_daddr;
94452
94453@@ -240,12 +244,19 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
94454
94455 r->idiag_family = tw->tw_family;
94456 r->idiag_retrans = 0;
94457+
94458 r->id.idiag_if = tw->tw_bound_dev_if;
94459 sock_diag_save_cookie(tw, r->id.idiag_cookie);
94460+
94461 r->id.idiag_sport = tw->tw_sport;
94462 r->id.idiag_dport = tw->tw_dport;
94463+
94464+ memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
94465+ memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
94466+
94467 r->id.idiag_src[0] = tw->tw_rcv_saddr;
94468 r->id.idiag_dst[0] = tw->tw_daddr;
94469+
94470 r->idiag_state = tw->tw_substate;
94471 r->idiag_timer = 3;
94472 r->idiag_expires = DIV_ROUND_UP(tmo * 1000, HZ);
94473@@ -732,8 +743,13 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
94474
94475 r->id.idiag_sport = inet->inet_sport;
94476 r->id.idiag_dport = ireq->rmt_port;
94477+
94478+ memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
94479+ memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
94480+
94481 r->id.idiag_src[0] = ireq->loc_addr;
94482 r->id.idiag_dst[0] = ireq->rmt_addr;
94483+
94484 r->idiag_expires = jiffies_to_msecs(tmo);
94485 r->idiag_rqueue = 0;
94486 r->idiag_wqueue = 0;
94487diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
94488index 96da9c7..b956690 100644
94489--- a/net/ipv4/inet_hashtables.c
94490+++ b/net/ipv4/inet_hashtables.c
94491@@ -18,12 +18,15 @@
94492 #include <linux/sched.h>
94493 #include <linux/slab.h>
94494 #include <linux/wait.h>
94495+#include <linux/security.h>
94496
94497 #include <net/inet_connection_sock.h>
94498 #include <net/inet_hashtables.h>
94499 #include <net/secure_seq.h>
94500 #include <net/ip.h>
94501
94502+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
94503+
94504 /*
94505 * Allocate and initialize a new local port bind bucket.
94506 * The bindhash mutex for snum's hash chain must be held here.
94507@@ -554,6 +557,8 @@ ok:
94508 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
94509 spin_unlock(&head->lock);
94510
94511+ gr_update_task_in_ip_table(current, inet_sk(sk));
94512+
94513 if (tw) {
94514 inet_twsk_deschedule(tw, death_row);
94515 while (twrefcnt) {
94516diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
94517index 33d5537..da337a4 100644
94518--- a/net/ipv4/inetpeer.c
94519+++ b/net/ipv4/inetpeer.c
94520@@ -503,8 +503,8 @@ relookup:
94521 if (p) {
94522 p->daddr = *daddr;
94523 atomic_set(&p->refcnt, 1);
94524- atomic_set(&p->rid, 0);
94525- atomic_set(&p->ip_id_count,
94526+ atomic_set_unchecked(&p->rid, 0);
94527+ atomic_set_unchecked(&p->ip_id_count,
94528 (daddr->family == AF_INET) ?
94529 secure_ip_id(daddr->addr.a4) :
94530 secure_ipv6_id(daddr->addr.a6));
94531diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
94532index b66910a..cfe416e 100644
94533--- a/net/ipv4/ip_fragment.c
94534+++ b/net/ipv4/ip_fragment.c
94535@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
94536 return 0;
94537
94538 start = qp->rid;
94539- end = atomic_inc_return(&peer->rid);
94540+ end = atomic_inc_return_unchecked(&peer->rid);
94541 qp->rid = end;
94542
94543 rc = qp->q.fragments && (end - start) > max;
94544@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
94545
94546 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
94547 {
94548- struct ctl_table *table;
94549+ ctl_table_no_const *table = NULL;
94550 struct ctl_table_header *hdr;
94551
94552- table = ip4_frags_ns_ctl_table;
94553 if (!net_eq(net, &init_net)) {
94554- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
94555+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
94556 if (table == NULL)
94557 goto err_alloc;
94558
94559@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
94560 /* Don't export sysctls to unprivileged users */
94561 if (net->user_ns != &init_user_ns)
94562 table[0].procname = NULL;
94563- }
94564+ hdr = register_net_sysctl(net, "net/ipv4", table);
94565+ } else
94566+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
94567
94568- hdr = register_net_sysctl(net, "net/ipv4", table);
94569 if (hdr == NULL)
94570 goto err_reg;
94571
94572@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
94573 return 0;
94574
94575 err_reg:
94576- if (!net_eq(net, &init_net))
94577- kfree(table);
94578+ kfree(table);
94579 err_alloc:
94580 return -ENOMEM;
94581 }
94582diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
94583index d7aea4c..a8ee872 100644
94584--- a/net/ipv4/ip_gre.c
94585+++ b/net/ipv4/ip_gre.c
94586@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
94587 module_param(log_ecn_error, bool, 0644);
94588 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94589
94590-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
94591+static struct rtnl_link_ops ipgre_link_ops;
94592 static int ipgre_tunnel_init(struct net_device *dev);
94593
94594 static int ipgre_net_id __read_mostly;
94595@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
94596 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
94597 };
94598
94599-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94600+static struct rtnl_link_ops ipgre_link_ops = {
94601 .kind = "gre",
94602 .maxtype = IFLA_GRE_MAX,
94603 .policy = ipgre_policy,
94604@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94605 .fill_info = ipgre_fill_info,
94606 };
94607
94608-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
94609+static struct rtnl_link_ops ipgre_tap_ops = {
94610 .kind = "gretap",
94611 .maxtype = IFLA_GRE_MAX,
94612 .policy = ipgre_policy,
94613diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
94614index 23e6ab0..be67a57 100644
94615--- a/net/ipv4/ip_sockglue.c
94616+++ b/net/ipv4/ip_sockglue.c
94617@@ -1153,7 +1153,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94618 len = min_t(unsigned int, len, opt->optlen);
94619 if (put_user(len, optlen))
94620 return -EFAULT;
94621- if (copy_to_user(optval, opt->__data, len))
94622+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
94623+ copy_to_user(optval, opt->__data, len))
94624 return -EFAULT;
94625 return 0;
94626 }
94627@@ -1284,7 +1285,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94628 if (sk->sk_type != SOCK_STREAM)
94629 return -ENOPROTOOPT;
94630
94631- msg.msg_control = optval;
94632+ msg.msg_control = (void __force_kernel *)optval;
94633 msg.msg_controllen = len;
94634 msg.msg_flags = flags;
94635
94636diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
94637index 26847e1..75d2d2f 100644
94638--- a/net/ipv4/ip_vti.c
94639+++ b/net/ipv4/ip_vti.c
94640@@ -44,7 +44,7 @@
94641 #include <net/net_namespace.h>
94642 #include <net/netns/generic.h>
94643
94644-static struct rtnl_link_ops vti_link_ops __read_mostly;
94645+static struct rtnl_link_ops vti_link_ops;
94646
94647 static int vti_net_id __read_mostly;
94648 static int vti_tunnel_init(struct net_device *dev);
94649@@ -425,7 +425,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
94650 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
94651 };
94652
94653-static struct rtnl_link_ops vti_link_ops __read_mostly = {
94654+static struct rtnl_link_ops vti_link_ops = {
94655 .kind = "vti",
94656 .maxtype = IFLA_VTI_MAX,
94657 .policy = vti_policy,
94658diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
94659index efa1138..20dbba0 100644
94660--- a/net/ipv4/ipconfig.c
94661+++ b/net/ipv4/ipconfig.c
94662@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
94663
94664 mm_segment_t oldfs = get_fs();
94665 set_fs(get_ds());
94666- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94667+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94668 set_fs(oldfs);
94669 return res;
94670 }
94671@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
94672
94673 mm_segment_t oldfs = get_fs();
94674 set_fs(get_ds());
94675- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94676+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94677 set_fs(oldfs);
94678 return res;
94679 }
94680@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
94681
94682 mm_segment_t oldfs = get_fs();
94683 set_fs(get_ds());
94684- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
94685+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
94686 set_fs(oldfs);
94687 return res;
94688 }
94689diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
94690index 7f80fb4..b0328f6 100644
94691--- a/net/ipv4/ipip.c
94692+++ b/net/ipv4/ipip.c
94693@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94694 static int ipip_net_id __read_mostly;
94695
94696 static int ipip_tunnel_init(struct net_device *dev);
94697-static struct rtnl_link_ops ipip_link_ops __read_mostly;
94698+static struct rtnl_link_ops ipip_link_ops;
94699
94700 static int ipip_err(struct sk_buff *skb, u32 info)
94701 {
94702@@ -408,7 +408,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
94703 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
94704 };
94705
94706-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
94707+static struct rtnl_link_ops ipip_link_ops = {
94708 .kind = "ipip",
94709 .maxtype = IFLA_IPTUN_MAX,
94710 .policy = ipip_policy,
94711diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
94712index 85a4f21..1beb1f5 100644
94713--- a/net/ipv4/netfilter/arp_tables.c
94714+++ b/net/ipv4/netfilter/arp_tables.c
94715@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
94716 #endif
94717
94718 static int get_info(struct net *net, void __user *user,
94719- const int *len, int compat)
94720+ int len, int compat)
94721 {
94722 char name[XT_TABLE_MAXNAMELEN];
94723 struct xt_table *t;
94724 int ret;
94725
94726- if (*len != sizeof(struct arpt_getinfo)) {
94727- duprintf("length %u != %Zu\n", *len,
94728+ if (len != sizeof(struct arpt_getinfo)) {
94729+ duprintf("length %u != %Zu\n", len,
94730 sizeof(struct arpt_getinfo));
94731 return -EINVAL;
94732 }
94733@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
94734 info.size = private->size;
94735 strcpy(info.name, name);
94736
94737- if (copy_to_user(user, &info, *len) != 0)
94738+ if (copy_to_user(user, &info, len) != 0)
94739 ret = -EFAULT;
94740 else
94741 ret = 0;
94742@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
94743
94744 switch (cmd) {
94745 case ARPT_SO_GET_INFO:
94746- ret = get_info(sock_net(sk), user, len, 1);
94747+ ret = get_info(sock_net(sk), user, *len, 1);
94748 break;
94749 case ARPT_SO_GET_ENTRIES:
94750 ret = compat_get_entries(sock_net(sk), user, len);
94751@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
94752
94753 switch (cmd) {
94754 case ARPT_SO_GET_INFO:
94755- ret = get_info(sock_net(sk), user, len, 0);
94756+ ret = get_info(sock_net(sk), user, *len, 0);
94757 break;
94758
94759 case ARPT_SO_GET_ENTRIES:
94760diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
94761index d23118d..6ad7277 100644
94762--- a/net/ipv4/netfilter/ip_tables.c
94763+++ b/net/ipv4/netfilter/ip_tables.c
94764@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
94765 #endif
94766
94767 static int get_info(struct net *net, void __user *user,
94768- const int *len, int compat)
94769+ int len, int compat)
94770 {
94771 char name[XT_TABLE_MAXNAMELEN];
94772 struct xt_table *t;
94773 int ret;
94774
94775- if (*len != sizeof(struct ipt_getinfo)) {
94776- duprintf("length %u != %zu\n", *len,
94777+ if (len != sizeof(struct ipt_getinfo)) {
94778+ duprintf("length %u != %zu\n", len,
94779 sizeof(struct ipt_getinfo));
94780 return -EINVAL;
94781 }
94782@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
94783 info.size = private->size;
94784 strcpy(info.name, name);
94785
94786- if (copy_to_user(user, &info, *len) != 0)
94787+ if (copy_to_user(user, &info, len) != 0)
94788 ret = -EFAULT;
94789 else
94790 ret = 0;
94791@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94792
94793 switch (cmd) {
94794 case IPT_SO_GET_INFO:
94795- ret = get_info(sock_net(sk), user, len, 1);
94796+ ret = get_info(sock_net(sk), user, *len, 1);
94797 break;
94798 case IPT_SO_GET_ENTRIES:
94799 ret = compat_get_entries(sock_net(sk), user, len);
94800@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94801
94802 switch (cmd) {
94803 case IPT_SO_GET_INFO:
94804- ret = get_info(sock_net(sk), user, len, 0);
94805+ ret = get_info(sock_net(sk), user, *len, 0);
94806 break;
94807
94808 case IPT_SO_GET_ENTRIES:
94809diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
94810index cbc2215..9cb993c 100644
94811--- a/net/ipv4/netfilter/ipt_ULOG.c
94812+++ b/net/ipv4/netfilter/ipt_ULOG.c
94813@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
94814 ub->qlen++;
94815
94816 pm = nlmsg_data(nlh);
94817+ memset(pm, 0, sizeof(*pm));
94818
94819 /* We might not have a timestamp, get one */
94820 if (skb->tstamp.tv64 == 0)
94821@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
94822 }
94823 else if (loginfo->prefix[0] != '\0')
94824 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
94825- else
94826- *(pm->prefix) = '\0';
94827
94828 if (in && in->hard_header_len > 0 &&
94829 skb->mac_header != skb->network_header &&
94830@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
94831
94832 if (in)
94833 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
94834- else
94835- pm->indev_name[0] = '\0';
94836
94837 if (out)
94838 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
94839- else
94840- pm->outdev_name[0] = '\0';
94841
94842 /* copy_len <= skb->len, so can't fail. */
94843 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
94844diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
94845index c482f7c..2784262 100644
94846--- a/net/ipv4/ping.c
94847+++ b/net/ipv4/ping.c
94848@@ -55,7 +55,7 @@
94849
94850
94851 struct ping_table ping_table;
94852-struct pingv6_ops pingv6_ops;
94853+struct pingv6_ops *pingv6_ops;
94854 EXPORT_SYMBOL_GPL(pingv6_ops);
94855
94856 static u16 ping_port_rover;
94857@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
94858 return -ENODEV;
94859 }
94860 }
94861- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
94862+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
94863 scoped);
94864 rcu_read_unlock();
94865
94866@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
94867 }
94868 #if IS_ENABLED(CONFIG_IPV6)
94869 } else if (skb->protocol == htons(ETH_P_IPV6)) {
94870- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
94871+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
94872 #endif
94873 }
94874
94875@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
94876 info, (u8 *)icmph);
94877 #if IS_ENABLED(CONFIG_IPV6)
94878 } else if (family == AF_INET6) {
94879- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
94880+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
94881 info, (u8 *)icmph);
94882 #endif
94883 }
94884@@ -841,7 +841,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94885 return ip_recv_error(sk, msg, len, addr_len);
94886 #if IS_ENABLED(CONFIG_IPV6)
94887 } else if (family == AF_INET6) {
94888- return pingv6_ops.ipv6_recv_error(sk, msg, len,
94889+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
94890 addr_len);
94891 #endif
94892 }
94893@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94894 }
94895
94896 if (inet6_sk(sk)->rxopt.all)
94897- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
94898+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
94899 #endif
94900 } else {
94901 BUG();
94902@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
94903 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94904 0, sock_i_ino(sp),
94905 atomic_read(&sp->sk_refcnt), sp,
94906- atomic_read(&sp->sk_drops), len);
94907+ atomic_read_unchecked(&sp->sk_drops), len);
94908 }
94909
94910 static int ping_v4_seq_show(struct seq_file *seq, void *v)
94911diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
94912index 7d3db78..9fd511d 100644
94913--- a/net/ipv4/raw.c
94914+++ b/net/ipv4/raw.c
94915@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
94916 int raw_rcv(struct sock *sk, struct sk_buff *skb)
94917 {
94918 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
94919- atomic_inc(&sk->sk_drops);
94920+ atomic_inc_unchecked(&sk->sk_drops);
94921 kfree_skb(skb);
94922 return NET_RX_DROP;
94923 }
94924@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
94925
94926 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
94927 {
94928+ struct icmp_filter filter;
94929+
94930 if (optlen > sizeof(struct icmp_filter))
94931 optlen = sizeof(struct icmp_filter);
94932- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
94933+ if (copy_from_user(&filter, optval, optlen))
94934 return -EFAULT;
94935+ raw_sk(sk)->filter = filter;
94936 return 0;
94937 }
94938
94939 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
94940 {
94941 int len, ret = -EFAULT;
94942+ struct icmp_filter filter;
94943
94944 if (get_user(len, optlen))
94945 goto out;
94946@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
94947 if (len > sizeof(struct icmp_filter))
94948 len = sizeof(struct icmp_filter);
94949 ret = -EFAULT;
94950- if (put_user(len, optlen) ||
94951- copy_to_user(optval, &raw_sk(sk)->filter, len))
94952+ filter = raw_sk(sk)->filter;
94953+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
94954 goto out;
94955 ret = 0;
94956 out: return ret;
94957@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
94958 0, 0L, 0,
94959 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
94960 0, sock_i_ino(sp),
94961- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
94962+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
94963 }
94964
94965 static int raw_seq_show(struct seq_file *seq, void *v)
94966diff --git a/net/ipv4/route.c b/net/ipv4/route.c
94967index 62290b5..f0d944f 100644
94968--- a/net/ipv4/route.c
94969+++ b/net/ipv4/route.c
94970@@ -2617,34 +2617,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
94971 .maxlen = sizeof(int),
94972 .mode = 0200,
94973 .proc_handler = ipv4_sysctl_rtcache_flush,
94974+ .extra1 = &init_net,
94975 },
94976 { },
94977 };
94978
94979 static __net_init int sysctl_route_net_init(struct net *net)
94980 {
94981- struct ctl_table *tbl;
94982+ ctl_table_no_const *tbl = NULL;
94983
94984- tbl = ipv4_route_flush_table;
94985 if (!net_eq(net, &init_net)) {
94986- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94987+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94988 if (tbl == NULL)
94989 goto err_dup;
94990
94991 /* Don't export sysctls to unprivileged users */
94992 if (net->user_ns != &init_user_ns)
94993 tbl[0].procname = NULL;
94994- }
94995- tbl[0].extra1 = net;
94996+ tbl[0].extra1 = net;
94997+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94998+ } else
94999+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
95000
95001- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
95002 if (net->ipv4.route_hdr == NULL)
95003 goto err_reg;
95004 return 0;
95005
95006 err_reg:
95007- if (tbl != ipv4_route_flush_table)
95008- kfree(tbl);
95009+ kfree(tbl);
95010 err_dup:
95011 return -ENOMEM;
95012 }
95013@@ -2667,8 +2667,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
95014
95015 static __net_init int rt_genid_init(struct net *net)
95016 {
95017- atomic_set(&net->ipv4.rt_genid, 0);
95018- atomic_set(&net->fnhe_genid, 0);
95019+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
95020+ atomic_set_unchecked(&net->fnhe_genid, 0);
95021 get_random_bytes(&net->ipv4.dev_addr_genid,
95022 sizeof(net->ipv4.dev_addr_genid));
95023 return 0;
95024diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
95025index 540279f..9855b16 100644
95026--- a/net/ipv4/sysctl_net_ipv4.c
95027+++ b/net/ipv4/sysctl_net_ipv4.c
95028@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
95029 {
95030 int ret;
95031 int range[2];
95032- struct ctl_table tmp = {
95033+ ctl_table_no_const tmp = {
95034 .data = &range,
95035 .maxlen = sizeof(range),
95036 .mode = table->mode,
95037@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
95038 int ret;
95039 gid_t urange[2];
95040 kgid_t low, high;
95041- struct ctl_table tmp = {
95042+ ctl_table_no_const tmp = {
95043 .data = &urange,
95044 .maxlen = sizeof(urange),
95045 .mode = table->mode,
95046@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
95047 void __user *buffer, size_t *lenp, loff_t *ppos)
95048 {
95049 char val[TCP_CA_NAME_MAX];
95050- struct ctl_table tbl = {
95051+ ctl_table_no_const tbl = {
95052 .data = val,
95053 .maxlen = TCP_CA_NAME_MAX,
95054 };
95055@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
95056 void __user *buffer, size_t *lenp,
95057 loff_t *ppos)
95058 {
95059- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
95060+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
95061 int ret;
95062
95063 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
95064@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
95065 void __user *buffer, size_t *lenp,
95066 loff_t *ppos)
95067 {
95068- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
95069+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
95070 int ret;
95071
95072 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
95073@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
95074 struct mem_cgroup *memcg;
95075 #endif
95076
95077- struct ctl_table tmp = {
95078+ ctl_table_no_const tmp = {
95079 .data = &vec,
95080 .maxlen = sizeof(vec),
95081 .mode = ctl->mode,
95082 };
95083
95084 if (!write) {
95085- ctl->data = &net->ipv4.sysctl_tcp_mem;
95086- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
95087+ ctl_table_no_const tcp_mem = *ctl;
95088+
95089+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
95090+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
95091 }
95092
95093 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
95094@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
95095 void __user *buffer, size_t *lenp,
95096 loff_t *ppos)
95097 {
95098- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
95099+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
95100 struct tcp_fastopen_context *ctxt;
95101 int ret;
95102 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
95103@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
95104 },
95105 {
95106 .procname = "ip_local_reserved_ports",
95107- .data = NULL, /* initialized in sysctl_ipv4_init */
95108+ .data = sysctl_local_reserved_ports,
95109 .maxlen = 65536,
95110 .mode = 0644,
95111 .proc_handler = proc_do_large_bitmap,
95112@@ -864,11 +866,10 @@ static struct ctl_table ipv4_net_table[] = {
95113
95114 static __net_init int ipv4_sysctl_init_net(struct net *net)
95115 {
95116- struct ctl_table *table;
95117+ ctl_table_no_const *table = NULL;
95118
95119- table = ipv4_net_table;
95120 if (!net_eq(net, &init_net)) {
95121- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
95122+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
95123 if (table == NULL)
95124 goto err_alloc;
95125
95126@@ -903,15 +904,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
95127
95128 tcp_init_mem(net);
95129
95130- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
95131+ if (!net_eq(net, &init_net))
95132+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
95133+ else
95134+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
95135 if (net->ipv4.ipv4_hdr == NULL)
95136 goto err_reg;
95137
95138 return 0;
95139
95140 err_reg:
95141- if (!net_eq(net, &init_net))
95142- kfree(table);
95143+ kfree(table);
95144 err_alloc:
95145 return -ENOMEM;
95146 }
95147@@ -933,16 +936,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
95148 static __init int sysctl_ipv4_init(void)
95149 {
95150 struct ctl_table_header *hdr;
95151- struct ctl_table *i;
95152-
95153- for (i = ipv4_table; i->procname; i++) {
95154- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
95155- i->data = sysctl_local_reserved_ports;
95156- break;
95157- }
95158- }
95159- if (!i->procname)
95160- return -EINVAL;
95161
95162 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
95163 if (hdr == NULL)
95164diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
95165index 068c8fb..a755c52 100644
95166--- a/net/ipv4/tcp_input.c
95167+++ b/net/ipv4/tcp_input.c
95168@@ -4435,7 +4435,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
95169 * simplifies code)
95170 */
95171 static void
95172-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
95173+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
95174 struct sk_buff *head, struct sk_buff *tail,
95175 u32 start, u32 end)
95176 {
95177@@ -5520,6 +5520,7 @@ discard:
95178 tcp_paws_reject(&tp->rx_opt, 0))
95179 goto discard_and_undo;
95180
95181+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
95182 if (th->syn) {
95183 /* We see SYN without ACK. It is attempt of
95184 * simultaneous connect with crossed SYNs.
95185@@ -5570,6 +5571,7 @@ discard:
95186 goto discard;
95187 #endif
95188 }
95189+#endif
95190 /* "fifth, if neither of the SYN or RST bits is set then
95191 * drop the segment and return."
95192 */
95193@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
95194 goto discard;
95195
95196 if (th->syn) {
95197- if (th->fin)
95198+ if (th->fin || th->urg || th->psh)
95199 goto discard;
95200 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
95201 return 1;
95202diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
95203index 5031f68..91569e2 100644
95204--- a/net/ipv4/tcp_ipv4.c
95205+++ b/net/ipv4/tcp_ipv4.c
95206@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
95207 EXPORT_SYMBOL(sysctl_tcp_low_latency);
95208
95209
95210+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95211+extern int grsec_enable_blackhole;
95212+#endif
95213+
95214 #ifdef CONFIG_TCP_MD5SIG
95215 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
95216 __be32 daddr, __be32 saddr, const struct tcphdr *th);
95217@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
95218 return 0;
95219
95220 reset:
95221+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95222+ if (!grsec_enable_blackhole)
95223+#endif
95224 tcp_v4_send_reset(rsk, skb);
95225 discard:
95226 kfree_skb(skb);
95227@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
95228 TCP_SKB_CB(skb)->sacked = 0;
95229
95230 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
95231- if (!sk)
95232+ if (!sk) {
95233+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95234+ ret = 1;
95235+#endif
95236 goto no_tcp_socket;
95237-
95238+ }
95239 process:
95240- if (sk->sk_state == TCP_TIME_WAIT)
95241+ if (sk->sk_state == TCP_TIME_WAIT) {
95242+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95243+ ret = 2;
95244+#endif
95245 goto do_time_wait;
95246+ }
95247
95248 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
95249 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
95250@@ -2033,6 +2047,10 @@ csum_error:
95251 bad_packet:
95252 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
95253 } else {
95254+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95255+ if (!grsec_enable_blackhole || (ret == 1 &&
95256+ (skb->dev->flags & IFF_LOOPBACK)))
95257+#endif
95258 tcp_v4_send_reset(NULL, skb);
95259 }
95260
95261diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
95262index 58a3e69..7f0626e 100644
95263--- a/net/ipv4/tcp_minisocks.c
95264+++ b/net/ipv4/tcp_minisocks.c
95265@@ -27,6 +27,10 @@
95266 #include <net/inet_common.h>
95267 #include <net/xfrm.h>
95268
95269+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95270+extern int grsec_enable_blackhole;
95271+#endif
95272+
95273 int sysctl_tcp_syncookies __read_mostly = 1;
95274 EXPORT_SYMBOL(sysctl_tcp_syncookies);
95275
95276@@ -711,7 +715,10 @@ embryonic_reset:
95277 * avoid becoming vulnerable to outside attack aiming at
95278 * resetting legit local connections.
95279 */
95280- req->rsk_ops->send_reset(sk, skb);
95281+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95282+ if (!grsec_enable_blackhole)
95283+#endif
95284+ req->rsk_ops->send_reset(sk, skb);
95285 } else if (fastopen) { /* received a valid RST pkt */
95286 reqsk_fastopen_remove(sk, req, true);
95287 tcp_reset(sk);
95288diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
95289index 611beab..c4b6e1d 100644
95290--- a/net/ipv4/tcp_probe.c
95291+++ b/net/ipv4/tcp_probe.c
95292@@ -245,7 +245,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
95293 if (cnt + width >= len)
95294 break;
95295
95296- if (copy_to_user(buf + cnt, tbuf, width))
95297+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
95298 return -EFAULT;
95299 cnt += width;
95300 }
95301diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
95302index 4b85e6f..22f9ac9 100644
95303--- a/net/ipv4/tcp_timer.c
95304+++ b/net/ipv4/tcp_timer.c
95305@@ -22,6 +22,10 @@
95306 #include <linux/gfp.h>
95307 #include <net/tcp.h>
95308
95309+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95310+extern int grsec_lastack_retries;
95311+#endif
95312+
95313 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
95314 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
95315 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
95316@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
95317 }
95318 }
95319
95320+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95321+ if ((sk->sk_state == TCP_LAST_ACK) &&
95322+ (grsec_lastack_retries > 0) &&
95323+ (grsec_lastack_retries < retry_until))
95324+ retry_until = grsec_lastack_retries;
95325+#endif
95326+
95327 if (retransmits_timed_out(sk, retry_until,
95328 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
95329 /* Has it gone just too far? */
95330diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
95331index 5e2c2f1..6473c22 100644
95332--- a/net/ipv4/udp.c
95333+++ b/net/ipv4/udp.c
95334@@ -87,6 +87,7 @@
95335 #include <linux/types.h>
95336 #include <linux/fcntl.h>
95337 #include <linux/module.h>
95338+#include <linux/security.h>
95339 #include <linux/socket.h>
95340 #include <linux/sockios.h>
95341 #include <linux/igmp.h>
95342@@ -112,6 +113,10 @@
95343 #include <net/busy_poll.h>
95344 #include "udp_impl.h"
95345
95346+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95347+extern int grsec_enable_blackhole;
95348+#endif
95349+
95350 struct udp_table udp_table __read_mostly;
95351 EXPORT_SYMBOL(udp_table);
95352
95353@@ -595,6 +600,9 @@ found:
95354 return s;
95355 }
95356
95357+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
95358+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
95359+
95360 /*
95361 * This routine is called by the ICMP module when it gets some
95362 * sort of error condition. If err < 0 then the socket should
95363@@ -892,9 +900,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
95364 dport = usin->sin_port;
95365 if (dport == 0)
95366 return -EINVAL;
95367+
95368+ err = gr_search_udp_sendmsg(sk, usin);
95369+ if (err)
95370+ return err;
95371 } else {
95372 if (sk->sk_state != TCP_ESTABLISHED)
95373 return -EDESTADDRREQ;
95374+
95375+ err = gr_search_udp_sendmsg(sk, NULL);
95376+ if (err)
95377+ return err;
95378+
95379 daddr = inet->inet_daddr;
95380 dport = inet->inet_dport;
95381 /* Open fast path for connected socket.
95382@@ -1141,7 +1158,7 @@ static unsigned int first_packet_length(struct sock *sk)
95383 IS_UDPLITE(sk));
95384 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95385 IS_UDPLITE(sk));
95386- atomic_inc(&sk->sk_drops);
95387+ atomic_inc_unchecked(&sk->sk_drops);
95388 __skb_unlink(skb, rcvq);
95389 __skb_queue_tail(&list_kill, skb);
95390 }
95391@@ -1221,6 +1238,10 @@ try_again:
95392 if (!skb)
95393 goto out;
95394
95395+ err = gr_search_udp_recvmsg(sk, skb);
95396+ if (err)
95397+ goto out_free;
95398+
95399 ulen = skb->len - sizeof(struct udphdr);
95400 copied = len;
95401 if (copied > ulen)
95402@@ -1254,7 +1275,7 @@ try_again:
95403 if (unlikely(err)) {
95404 trace_kfree_skb(skb, udp_recvmsg);
95405 if (!peeked) {
95406- atomic_inc(&sk->sk_drops);
95407+ atomic_inc_unchecked(&sk->sk_drops);
95408 UDP_INC_STATS_USER(sock_net(sk),
95409 UDP_MIB_INERRORS, is_udplite);
95410 }
95411@@ -1542,7 +1563,7 @@ csum_error:
95412 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
95413 drop:
95414 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
95415- atomic_inc(&sk->sk_drops);
95416+ atomic_inc_unchecked(&sk->sk_drops);
95417 kfree_skb(skb);
95418 return -1;
95419 }
95420@@ -1561,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
95421 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
95422
95423 if (!skb1) {
95424- atomic_inc(&sk->sk_drops);
95425+ atomic_inc_unchecked(&sk->sk_drops);
95426 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
95427 IS_UDPLITE(sk));
95428 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95429@@ -1733,6 +1754,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
95430 goto csum_error;
95431
95432 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
95433+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95434+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
95435+#endif
95436 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
95437
95438 /*
95439@@ -2165,7 +2189,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
95440 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
95441 0, sock_i_ino(sp),
95442 atomic_read(&sp->sk_refcnt), sp,
95443- atomic_read(&sp->sk_drops), len);
95444+ atomic_read_unchecked(&sp->sk_drops), len);
95445 }
95446
95447 int udp4_seq_show(struct seq_file *seq, void *v)
95448diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
95449index adf9983..8e45d0a 100644
95450--- a/net/ipv4/xfrm4_policy.c
95451+++ b/net/ipv4/xfrm4_policy.c
95452@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
95453 fl4->flowi4_tos = iph->tos;
95454 }
95455
95456-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
95457+static int xfrm4_garbage_collect(struct dst_ops *ops)
95458 {
95459 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
95460
95461- xfrm4_policy_afinfo.garbage_collect(net);
95462+ xfrm_garbage_collect_deferred(net);
95463 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
95464 }
95465
95466@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
95467
95468 static int __net_init xfrm4_net_init(struct net *net)
95469 {
95470- struct ctl_table *table;
95471+ ctl_table_no_const *table = NULL;
95472 struct ctl_table_header *hdr;
95473
95474- table = xfrm4_policy_table;
95475 if (!net_eq(net, &init_net)) {
95476- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
95477+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
95478 if (!table)
95479 goto err_alloc;
95480
95481 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
95482- }
95483-
95484- hdr = register_net_sysctl(net, "net/ipv4", table);
95485+ hdr = register_net_sysctl(net, "net/ipv4", table);
95486+ } else
95487+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
95488 if (!hdr)
95489 goto err_reg;
95490
95491@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
95492 return 0;
95493
95494 err_reg:
95495- if (!net_eq(net, &init_net))
95496- kfree(table);
95497+ kfree(table);
95498 err_alloc:
95499 return -ENOMEM;
95500 }
95501diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
95502index cd3fb30..b7dfef7 100644
95503--- a/net/ipv6/addrconf.c
95504+++ b/net/ipv6/addrconf.c
95505@@ -586,7 +586,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
95506 idx = 0;
95507 head = &net->dev_index_head[h];
95508 rcu_read_lock();
95509- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
95510+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
95511 net->dev_base_seq;
95512 hlist_for_each_entry_rcu(dev, head, index_hlist) {
95513 if (idx < s_idx)
95514@@ -2364,7 +2364,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
95515 p.iph.ihl = 5;
95516 p.iph.protocol = IPPROTO_IPV6;
95517 p.iph.ttl = 64;
95518- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
95519+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
95520
95521 if (ops->ndo_do_ioctl) {
95522 mm_segment_t oldfs = get_fs();
95523@@ -3977,7 +3977,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
95524 s_ip_idx = ip_idx = cb->args[2];
95525
95526 rcu_read_lock();
95527- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
95528+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
95529 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
95530 idx = 0;
95531 head = &net->dev_index_head[h];
95532@@ -4603,7 +4603,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
95533 dst_free(&ifp->rt->dst);
95534 break;
95535 }
95536- atomic_inc(&net->ipv6.dev_addr_genid);
95537+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
95538 rt_genid_bump_ipv6(net);
95539 }
95540
95541@@ -4624,7 +4624,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
95542 int *valp = ctl->data;
95543 int val = *valp;
95544 loff_t pos = *ppos;
95545- struct ctl_table lctl;
95546+ ctl_table_no_const lctl;
95547 int ret;
95548
95549 /*
95550@@ -4709,7 +4709,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
95551 int *valp = ctl->data;
95552 int val = *valp;
95553 loff_t pos = *ppos;
95554- struct ctl_table lctl;
95555+ ctl_table_no_const lctl;
95556 int ret;
95557
95558 /*
95559diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
95560index 8132b44..b8eca70 100644
95561--- a/net/ipv6/af_inet6.c
95562+++ b/net/ipv6/af_inet6.c
95563@@ -767,7 +767,7 @@ static int __net_init inet6_net_init(struct net *net)
95564
95565 net->ipv6.sysctl.bindv6only = 0;
95566 net->ipv6.sysctl.icmpv6_time = 1*HZ;
95567- atomic_set(&net->ipv6.rt_genid, 0);
95568+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
95569
95570 err = ipv6_init_mibs(net);
95571 if (err)
95572diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
95573index c66c6df..f375d3c 100644
95574--- a/net/ipv6/datagram.c
95575+++ b/net/ipv6/datagram.c
95576@@ -908,5 +908,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
95577 0,
95578 sock_i_ino(sp),
95579 atomic_read(&sp->sk_refcnt), sp,
95580- atomic_read(&sp->sk_drops));
95581+ atomic_read_unchecked(&sp->sk_drops));
95582 }
95583diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
95584index eef8d94..cfa1852 100644
95585--- a/net/ipv6/icmp.c
95586+++ b/net/ipv6/icmp.c
95587@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
95588
95589 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
95590 {
95591- struct ctl_table *table;
95592+ ctl_table_no_const *table;
95593
95594 table = kmemdup(ipv6_icmp_table_template,
95595 sizeof(ipv6_icmp_table_template),
95596diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
95597index bf4a9a0..e5f6ac5 100644
95598--- a/net/ipv6/ip6_gre.c
95599+++ b/net/ipv6/ip6_gre.c
95600@@ -74,7 +74,7 @@ struct ip6gre_net {
95601 struct net_device *fb_tunnel_dev;
95602 };
95603
95604-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
95605+static struct rtnl_link_ops ip6gre_link_ops;
95606 static int ip6gre_tunnel_init(struct net_device *dev);
95607 static void ip6gre_tunnel_setup(struct net_device *dev);
95608 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
95609@@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
95610 }
95611
95612
95613-static struct inet6_protocol ip6gre_protocol __read_mostly = {
95614+static struct inet6_protocol ip6gre_protocol = {
95615 .handler = ip6gre_rcv,
95616 .err_handler = ip6gre_err,
95617 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
95618@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
95619 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
95620 };
95621
95622-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
95623+static struct rtnl_link_ops ip6gre_link_ops = {
95624 .kind = "ip6gre",
95625 .maxtype = IFLA_GRE_MAX,
95626 .policy = ip6gre_policy,
95627@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
95628 .fill_info = ip6gre_fill_info,
95629 };
95630
95631-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
95632+static struct rtnl_link_ops ip6gre_tap_ops = {
95633 .kind = "ip6gretap",
95634 .maxtype = IFLA_GRE_MAX,
95635 .policy = ip6gre_policy,
95636diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
95637index c1e11b5..568e633 100644
95638--- a/net/ipv6/ip6_tunnel.c
95639+++ b/net/ipv6/ip6_tunnel.c
95640@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
95641
95642 static int ip6_tnl_dev_init(struct net_device *dev);
95643 static void ip6_tnl_dev_setup(struct net_device *dev);
95644-static struct rtnl_link_ops ip6_link_ops __read_mostly;
95645+static struct rtnl_link_ops ip6_link_ops;
95646
95647 static int ip6_tnl_net_id __read_mostly;
95648 struct ip6_tnl_net {
95649@@ -1699,7 +1699,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
95650 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
95651 };
95652
95653-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
95654+static struct rtnl_link_ops ip6_link_ops = {
95655 .kind = "ip6tnl",
95656 .maxtype = IFLA_IPTUN_MAX,
95657 .policy = ip6_tnl_policy,
95658diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
95659index d1e2e8e..51c19ae 100644
95660--- a/net/ipv6/ipv6_sockglue.c
95661+++ b/net/ipv6/ipv6_sockglue.c
95662@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
95663 if (sk->sk_type != SOCK_STREAM)
95664 return -ENOPROTOOPT;
95665
95666- msg.msg_control = optval;
95667+ msg.msg_control = (void __force_kernel *)optval;
95668 msg.msg_controllen = len;
95669 msg.msg_flags = flags;
95670
95671diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
95672index 44400c2..8e11f52 100644
95673--- a/net/ipv6/netfilter/ip6_tables.c
95674+++ b/net/ipv6/netfilter/ip6_tables.c
95675@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
95676 #endif
95677
95678 static int get_info(struct net *net, void __user *user,
95679- const int *len, int compat)
95680+ int len, int compat)
95681 {
95682 char name[XT_TABLE_MAXNAMELEN];
95683 struct xt_table *t;
95684 int ret;
95685
95686- if (*len != sizeof(struct ip6t_getinfo)) {
95687- duprintf("length %u != %zu\n", *len,
95688+ if (len != sizeof(struct ip6t_getinfo)) {
95689+ duprintf("length %u != %zu\n", len,
95690 sizeof(struct ip6t_getinfo));
95691 return -EINVAL;
95692 }
95693@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
95694 info.size = private->size;
95695 strcpy(info.name, name);
95696
95697- if (copy_to_user(user, &info, *len) != 0)
95698+ if (copy_to_user(user, &info, len) != 0)
95699 ret = -EFAULT;
95700 else
95701 ret = 0;
95702@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95703
95704 switch (cmd) {
95705 case IP6T_SO_GET_INFO:
95706- ret = get_info(sock_net(sk), user, len, 1);
95707+ ret = get_info(sock_net(sk), user, *len, 1);
95708 break;
95709 case IP6T_SO_GET_ENTRIES:
95710 ret = compat_get_entries(sock_net(sk), user, len);
95711@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95712
95713 switch (cmd) {
95714 case IP6T_SO_GET_INFO:
95715- ret = get_info(sock_net(sk), user, len, 0);
95716+ ret = get_info(sock_net(sk), user, *len, 0);
95717 break;
95718
95719 case IP6T_SO_GET_ENTRIES:
95720diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
95721index 253566a..9fa50c7 100644
95722--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
95723+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
95724@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
95725
95726 static int nf_ct_frag6_sysctl_register(struct net *net)
95727 {
95728- struct ctl_table *table;
95729+ ctl_table_no_const *table = NULL;
95730 struct ctl_table_header *hdr;
95731
95732- table = nf_ct_frag6_sysctl_table;
95733 if (!net_eq(net, &init_net)) {
95734- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
95735+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
95736 GFP_KERNEL);
95737 if (table == NULL)
95738 goto err_alloc;
95739@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95740 table[0].data = &net->nf_frag.frags.timeout;
95741 table[1].data = &net->nf_frag.frags.low_thresh;
95742 table[2].data = &net->nf_frag.frags.high_thresh;
95743- }
95744-
95745- hdr = register_net_sysctl(net, "net/netfilter", table);
95746+ hdr = register_net_sysctl(net, "net/netfilter", table);
95747+ } else
95748+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
95749 if (hdr == NULL)
95750 goto err_reg;
95751
95752@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95753 return 0;
95754
95755 err_reg:
95756- if (!net_eq(net, &init_net))
95757- kfree(table);
95758+ kfree(table);
95759 err_alloc:
95760 return -ENOMEM;
95761 }
95762diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
95763index 827f795..7e28e82 100644
95764--- a/net/ipv6/output_core.c
95765+++ b/net/ipv6/output_core.c
95766@@ -9,8 +9,8 @@
95767
95768 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95769 {
95770- static atomic_t ipv6_fragmentation_id;
95771- int old, new;
95772+ static atomic_unchecked_t ipv6_fragmentation_id;
95773+ int id;
95774
95775 #if IS_ENABLED(CONFIG_IPV6)
95776 if (rt && !(rt->dst.flags & DST_NOPEER)) {
95777@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95778 }
95779 }
95780 #endif
95781- do {
95782- old = atomic_read(&ipv6_fragmentation_id);
95783- new = old + 1;
95784- if (!new)
95785- new = 1;
95786- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
95787- fhdr->identification = htonl(new);
95788+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95789+ if (!id)
95790+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95791+ fhdr->identification = htonl(id);
95792 }
95793 EXPORT_SYMBOL(ipv6_select_ident);
95794
95795diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
95796index 7856e96..75ebc7f 100644
95797--- a/net/ipv6/ping.c
95798+++ b/net/ipv6/ping.c
95799@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
95800 };
95801 #endif
95802
95803+static struct pingv6_ops real_pingv6_ops = {
95804+ .ipv6_recv_error = ipv6_recv_error,
95805+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
95806+ .icmpv6_err_convert = icmpv6_err_convert,
95807+ .ipv6_icmp_error = ipv6_icmp_error,
95808+ .ipv6_chk_addr = ipv6_chk_addr,
95809+};
95810+
95811+static struct pingv6_ops dummy_pingv6_ops = {
95812+ .ipv6_recv_error = dummy_ipv6_recv_error,
95813+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
95814+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
95815+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
95816+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
95817+};
95818+
95819 int __init pingv6_init(void)
95820 {
95821 #ifdef CONFIG_PROC_FS
95822@@ -253,11 +269,7 @@ int __init pingv6_init(void)
95823 if (ret)
95824 return ret;
95825 #endif
95826- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
95827- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
95828- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
95829- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
95830- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
95831+ pingv6_ops = &real_pingv6_ops;
95832 return inet6_register_protosw(&pingv6_protosw);
95833 }
95834
95835@@ -266,11 +278,7 @@ int __init pingv6_init(void)
95836 */
95837 void pingv6_exit(void)
95838 {
95839- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
95840- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
95841- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
95842- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
95843- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
95844+ pingv6_ops = &dummy_pingv6_ops;
95845 #ifdef CONFIG_PROC_FS
95846 unregister_pernet_subsys(&ping_v6_net_ops);
95847 #endif
95848diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
95849index 430067c..4adf088 100644
95850--- a/net/ipv6/raw.c
95851+++ b/net/ipv6/raw.c
95852@@ -385,7 +385,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
95853 {
95854 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
95855 skb_checksum_complete(skb)) {
95856- atomic_inc(&sk->sk_drops);
95857+ atomic_inc_unchecked(&sk->sk_drops);
95858 kfree_skb(skb);
95859 return NET_RX_DROP;
95860 }
95861@@ -413,7 +413,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95862 struct raw6_sock *rp = raw6_sk(sk);
95863
95864 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
95865- atomic_inc(&sk->sk_drops);
95866+ atomic_inc_unchecked(&sk->sk_drops);
95867 kfree_skb(skb);
95868 return NET_RX_DROP;
95869 }
95870@@ -437,7 +437,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95871
95872 if (inet->hdrincl) {
95873 if (skb_checksum_complete(skb)) {
95874- atomic_inc(&sk->sk_drops);
95875+ atomic_inc_unchecked(&sk->sk_drops);
95876 kfree_skb(skb);
95877 return NET_RX_DROP;
95878 }
95879@@ -607,7 +607,7 @@ out:
95880 return err;
95881 }
95882
95883-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
95884+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
95885 struct flowi6 *fl6, struct dst_entry **dstp,
95886 unsigned int flags)
95887 {
95888@@ -920,12 +920,15 @@ do_confirm:
95889 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
95890 char __user *optval, int optlen)
95891 {
95892+ struct icmp6_filter filter;
95893+
95894 switch (optname) {
95895 case ICMPV6_FILTER:
95896 if (optlen > sizeof(struct icmp6_filter))
95897 optlen = sizeof(struct icmp6_filter);
95898- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
95899+ if (copy_from_user(&filter, optval, optlen))
95900 return -EFAULT;
95901+ raw6_sk(sk)->filter = filter;
95902 return 0;
95903 default:
95904 return -ENOPROTOOPT;
95905@@ -938,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95906 char __user *optval, int __user *optlen)
95907 {
95908 int len;
95909+ struct icmp6_filter filter;
95910
95911 switch (optname) {
95912 case ICMPV6_FILTER:
95913@@ -949,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95914 len = sizeof(struct icmp6_filter);
95915 if (put_user(len, optlen))
95916 return -EFAULT;
95917- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
95918+ filter = raw6_sk(sk)->filter;
95919+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
95920 return -EFAULT;
95921 return 0;
95922 default:
95923diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
95924index 1aeb473..bea761c 100644
95925--- a/net/ipv6/reassembly.c
95926+++ b/net/ipv6/reassembly.c
95927@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
95928
95929 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95930 {
95931- struct ctl_table *table;
95932+ ctl_table_no_const *table = NULL;
95933 struct ctl_table_header *hdr;
95934
95935- table = ip6_frags_ns_ctl_table;
95936 if (!net_eq(net, &init_net)) {
95937- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95938+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95939 if (table == NULL)
95940 goto err_alloc;
95941
95942@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95943 /* Don't export sysctls to unprivileged users */
95944 if (net->user_ns != &init_user_ns)
95945 table[0].procname = NULL;
95946- }
95947+ hdr = register_net_sysctl(net, "net/ipv6", table);
95948+ } else
95949+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
95950
95951- hdr = register_net_sysctl(net, "net/ipv6", table);
95952 if (hdr == NULL)
95953 goto err_reg;
95954
95955@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95956 return 0;
95957
95958 err_reg:
95959- if (!net_eq(net, &init_net))
95960- kfree(table);
95961+ kfree(table);
95962 err_alloc:
95963 return -ENOMEM;
95964 }
95965diff --git a/net/ipv6/route.c b/net/ipv6/route.c
95966index 77308af..36ed509 100644
95967--- a/net/ipv6/route.c
95968+++ b/net/ipv6/route.c
95969@@ -3009,7 +3009,7 @@ struct ctl_table ipv6_route_table_template[] = {
95970
95971 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
95972 {
95973- struct ctl_table *table;
95974+ ctl_table_no_const *table;
95975
95976 table = kmemdup(ipv6_route_table_template,
95977 sizeof(ipv6_route_table_template),
95978diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
95979index b433884..3875266 100644
95980--- a/net/ipv6/sit.c
95981+++ b/net/ipv6/sit.c
95982@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
95983 static void ipip6_dev_free(struct net_device *dev);
95984 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
95985 __be32 *v4dst);
95986-static struct rtnl_link_ops sit_link_ops __read_mostly;
95987+static struct rtnl_link_ops sit_link_ops;
95988
95989 static int sit_net_id __read_mostly;
95990 struct sit_net {
95991@@ -1603,7 +1603,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
95992 unregister_netdevice_queue(dev, head);
95993 }
95994
95995-static struct rtnl_link_ops sit_link_ops __read_mostly = {
95996+static struct rtnl_link_ops sit_link_ops = {
95997 .kind = "sit",
95998 .maxtype = IFLA_IPTUN_MAX,
95999 .policy = ipip6_policy,
96000diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
96001index 107b2f1..72741a9 100644
96002--- a/net/ipv6/sysctl_net_ipv6.c
96003+++ b/net/ipv6/sysctl_net_ipv6.c
96004@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
96005
96006 static int __net_init ipv6_sysctl_net_init(struct net *net)
96007 {
96008- struct ctl_table *ipv6_table;
96009+ ctl_table_no_const *ipv6_table;
96010 struct ctl_table *ipv6_route_table;
96011 struct ctl_table *ipv6_icmp_table;
96012 int err;
96013diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
96014index 5c71501..7e8d5d3 100644
96015--- a/net/ipv6/tcp_ipv6.c
96016+++ b/net/ipv6/tcp_ipv6.c
96017@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
96018 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
96019 }
96020
96021+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96022+extern int grsec_enable_blackhole;
96023+#endif
96024+
96025 static void tcp_v6_hash(struct sock *sk)
96026 {
96027 if (sk->sk_state != TCP_CLOSE) {
96028@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
96029 return 0;
96030
96031 reset:
96032+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96033+ if (!grsec_enable_blackhole)
96034+#endif
96035 tcp_v6_send_reset(sk, skb);
96036 discard:
96037 if (opt_skb)
96038@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
96039 TCP_SKB_CB(skb)->sacked = 0;
96040
96041 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
96042- if (!sk)
96043+ if (!sk) {
96044+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96045+ ret = 1;
96046+#endif
96047 goto no_tcp_socket;
96048+ }
96049
96050 process:
96051- if (sk->sk_state == TCP_TIME_WAIT)
96052+ if (sk->sk_state == TCP_TIME_WAIT) {
96053+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96054+ ret = 2;
96055+#endif
96056 goto do_time_wait;
96057+ }
96058
96059 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
96060 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
96061@@ -1536,6 +1551,10 @@ csum_error:
96062 bad_packet:
96063 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
96064 } else {
96065+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96066+ if (!grsec_enable_blackhole || (ret == 1 &&
96067+ (skb->dev->flags & IFF_LOOPBACK)))
96068+#endif
96069 tcp_v6_send_reset(NULL, skb);
96070 }
96071
96072diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
96073index 3d2758d..626c422 100644
96074--- a/net/ipv6/udp.c
96075+++ b/net/ipv6/udp.c
96076@@ -53,6 +53,10 @@
96077 #include <trace/events/skb.h>
96078 #include "udp_impl.h"
96079
96080+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96081+extern int grsec_enable_blackhole;
96082+#endif
96083+
96084 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
96085 {
96086 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
96087@@ -417,7 +421,7 @@ try_again:
96088 if (unlikely(err)) {
96089 trace_kfree_skb(skb, udpv6_recvmsg);
96090 if (!peeked) {
96091- atomic_inc(&sk->sk_drops);
96092+ atomic_inc_unchecked(&sk->sk_drops);
96093 if (is_udp4)
96094 UDP_INC_STATS_USER(sock_net(sk),
96095 UDP_MIB_INERRORS,
96096@@ -665,7 +669,7 @@ csum_error:
96097 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
96098 drop:
96099 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
96100- atomic_inc(&sk->sk_drops);
96101+ atomic_inc_unchecked(&sk->sk_drops);
96102 kfree_skb(skb);
96103 return -1;
96104 }
96105@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
96106 if (likely(skb1 == NULL))
96107 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
96108 if (!skb1) {
96109- atomic_inc(&sk->sk_drops);
96110+ atomic_inc_unchecked(&sk->sk_drops);
96111 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
96112 IS_UDPLITE(sk));
96113 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
96114@@ -863,6 +867,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
96115 goto csum_error;
96116
96117 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
96118+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
96119+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
96120+#endif
96121 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
96122
96123 kfree_skb(skb);
96124diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
96125index 550b195..6acea83 100644
96126--- a/net/ipv6/xfrm6_policy.c
96127+++ b/net/ipv6/xfrm6_policy.c
96128@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
96129 }
96130 }
96131
96132-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
96133+static int xfrm6_garbage_collect(struct dst_ops *ops)
96134 {
96135 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
96136
96137- xfrm6_policy_afinfo.garbage_collect(net);
96138+ xfrm_garbage_collect_deferred(net);
96139 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
96140 }
96141
96142@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
96143
96144 static int __net_init xfrm6_net_init(struct net *net)
96145 {
96146- struct ctl_table *table;
96147+ ctl_table_no_const *table = NULL;
96148 struct ctl_table_header *hdr;
96149
96150- table = xfrm6_policy_table;
96151 if (!net_eq(net, &init_net)) {
96152- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
96153+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
96154 if (!table)
96155 goto err_alloc;
96156
96157 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
96158- }
96159+ hdr = register_net_sysctl(net, "net/ipv6", table);
96160+ } else
96161+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
96162
96163- hdr = register_net_sysctl(net, "net/ipv6", table);
96164 if (!hdr)
96165 goto err_reg;
96166
96167@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
96168 return 0;
96169
96170 err_reg:
96171- if (!net_eq(net, &init_net))
96172- kfree(table);
96173+ kfree(table);
96174 err_alloc:
96175 return -ENOMEM;
96176 }
96177diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
96178index 41ac7938..75e3bb1 100644
96179--- a/net/irda/ircomm/ircomm_tty.c
96180+++ b/net/irda/ircomm/ircomm_tty.c
96181@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
96182 add_wait_queue(&port->open_wait, &wait);
96183
96184 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
96185- __FILE__, __LINE__, tty->driver->name, port->count);
96186+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
96187
96188 spin_lock_irqsave(&port->lock, flags);
96189 if (!tty_hung_up_p(filp))
96190- port->count--;
96191+ atomic_dec(&port->count);
96192 port->blocked_open++;
96193 spin_unlock_irqrestore(&port->lock, flags);
96194
96195@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
96196 }
96197
96198 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
96199- __FILE__, __LINE__, tty->driver->name, port->count);
96200+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
96201
96202 schedule();
96203 }
96204@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
96205
96206 spin_lock_irqsave(&port->lock, flags);
96207 if (!tty_hung_up_p(filp))
96208- port->count++;
96209+ atomic_inc(&port->count);
96210 port->blocked_open--;
96211 spin_unlock_irqrestore(&port->lock, flags);
96212
96213 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
96214- __FILE__, __LINE__, tty->driver->name, port->count);
96215+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
96216
96217 if (!retval)
96218 port->flags |= ASYNC_NORMAL_ACTIVE;
96219@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
96220
96221 /* ++ is not atomic, so this should be protected - Jean II */
96222 spin_lock_irqsave(&self->port.lock, flags);
96223- self->port.count++;
96224+ atomic_inc(&self->port.count);
96225 spin_unlock_irqrestore(&self->port.lock, flags);
96226 tty_port_tty_set(&self->port, tty);
96227
96228 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
96229- self->line, self->port.count);
96230+ self->line, atomic_read(&self->port.count));
96231
96232 /* Not really used by us, but lets do it anyway */
96233 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
96234@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
96235 tty_kref_put(port->tty);
96236 }
96237 port->tty = NULL;
96238- port->count = 0;
96239+ atomic_set(&port->count, 0);
96240 spin_unlock_irqrestore(&port->lock, flags);
96241
96242 wake_up_interruptible(&port->open_wait);
96243@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
96244 seq_putc(m, '\n');
96245
96246 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
96247- seq_printf(m, "Open count: %d\n", self->port.count);
96248+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
96249 seq_printf(m, "Max data size: %d\n", self->max_data_size);
96250 seq_printf(m, "Max header size: %d\n", self->max_header_size);
96251
96252diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
96253index c4b7218..3e83259 100644
96254--- a/net/iucv/af_iucv.c
96255+++ b/net/iucv/af_iucv.c
96256@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
96257
96258 write_lock_bh(&iucv_sk_list.lock);
96259
96260- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
96261+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
96262 while (__iucv_get_sock_by_name(name)) {
96263 sprintf(name, "%08x",
96264- atomic_inc_return(&iucv_sk_list.autobind_name));
96265+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
96266 }
96267
96268 write_unlock_bh(&iucv_sk_list.lock);
96269diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
96270index cd5b8ec..f205e6b 100644
96271--- a/net/iucv/iucv.c
96272+++ b/net/iucv/iucv.c
96273@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
96274 return NOTIFY_OK;
96275 }
96276
96277-static struct notifier_block __refdata iucv_cpu_notifier = {
96278+static struct notifier_block iucv_cpu_notifier = {
96279 .notifier_call = iucv_cpu_notify,
96280 };
96281
96282diff --git a/net/key/af_key.c b/net/key/af_key.c
96283index 545f047..9757a9d 100644
96284--- a/net/key/af_key.c
96285+++ b/net/key/af_key.c
96286@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
96287 static u32 get_acqseq(void)
96288 {
96289 u32 res;
96290- static atomic_t acqseq;
96291+ static atomic_unchecked_t acqseq;
96292
96293 do {
96294- res = atomic_inc_return(&acqseq);
96295+ res = atomic_inc_return_unchecked(&acqseq);
96296 } while (!res);
96297 return res;
96298 }
96299diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
96300index 9903ee5..18978be 100644
96301--- a/net/mac80211/cfg.c
96302+++ b/net/mac80211/cfg.c
96303@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
96304 ret = ieee80211_vif_use_channel(sdata, chandef,
96305 IEEE80211_CHANCTX_EXCLUSIVE);
96306 }
96307- } else if (local->open_count == local->monitors) {
96308+ } else if (local_read(&local->open_count) == local->monitors) {
96309 local->_oper_chandef = *chandef;
96310 ieee80211_hw_config(local, 0);
96311 }
96312@@ -3124,7 +3124,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
96313 else
96314 local->probe_req_reg--;
96315
96316- if (!local->open_count)
96317+ if (!local_read(&local->open_count))
96318 break;
96319
96320 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
96321@@ -3587,8 +3587,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
96322 if (chanctx_conf) {
96323 *chandef = chanctx_conf->def;
96324 ret = 0;
96325- } else if (local->open_count > 0 &&
96326- local->open_count == local->monitors &&
96327+ } else if (local_read(&local->open_count) > 0 &&
96328+ local_read(&local->open_count) == local->monitors &&
96329 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
96330 if (local->use_chanctx)
96331 *chandef = local->monitor_chandef;
96332diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
96333index 611abfc..8c2c7e4 100644
96334--- a/net/mac80211/ieee80211_i.h
96335+++ b/net/mac80211/ieee80211_i.h
96336@@ -28,6 +28,7 @@
96337 #include <net/ieee80211_radiotap.h>
96338 #include <net/cfg80211.h>
96339 #include <net/mac80211.h>
96340+#include <asm/local.h>
96341 #include "key.h"
96342 #include "sta_info.h"
96343 #include "debug.h"
96344@@ -945,7 +946,7 @@ struct ieee80211_local {
96345 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
96346 spinlock_t queue_stop_reason_lock;
96347
96348- int open_count;
96349+ local_t open_count;
96350 int monitors, cooked_mntrs;
96351 /* number of interfaces with corresponding FIF_ flags */
96352 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
96353diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
96354index fcecd63..a404454 100644
96355--- a/net/mac80211/iface.c
96356+++ b/net/mac80211/iface.c
96357@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96358 break;
96359 }
96360
96361- if (local->open_count == 0) {
96362+ if (local_read(&local->open_count) == 0) {
96363 res = drv_start(local);
96364 if (res)
96365 goto err_del_bss;
96366@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96367 res = drv_add_interface(local, sdata);
96368 if (res)
96369 goto err_stop;
96370- } else if (local->monitors == 0 && local->open_count == 0) {
96371+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
96372 res = ieee80211_add_virtual_monitor(local);
96373 if (res)
96374 goto err_stop;
96375@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96376 atomic_inc(&local->iff_promiscs);
96377
96378 if (coming_up)
96379- local->open_count++;
96380+ local_inc(&local->open_count);
96381
96382 if (hw_reconf_flags)
96383 ieee80211_hw_config(local, hw_reconf_flags);
96384@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96385 err_del_interface:
96386 drv_remove_interface(local, sdata);
96387 err_stop:
96388- if (!local->open_count)
96389+ if (!local_read(&local->open_count))
96390 drv_stop(local);
96391 err_del_bss:
96392 sdata->bss = NULL;
96393@@ -852,7 +852,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96394 }
96395
96396 if (going_down)
96397- local->open_count--;
96398+ local_dec(&local->open_count);
96399
96400 switch (sdata->vif.type) {
96401 case NL80211_IFTYPE_AP_VLAN:
96402@@ -919,7 +919,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96403 }
96404 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
96405
96406- if (local->open_count == 0)
96407+ if (local_read(&local->open_count) == 0)
96408 ieee80211_clear_tx_pending(local);
96409
96410 /*
96411@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96412
96413 ieee80211_recalc_ps(local, -1);
96414
96415- if (local->open_count == 0) {
96416+ if (local_read(&local->open_count) == 0) {
96417 ieee80211_stop_device(local);
96418
96419 /* no reconfiguring after stop! */
96420@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96421 ieee80211_configure_filter(local);
96422 ieee80211_hw_config(local, hw_reconf_flags);
96423
96424- if (local->monitors == local->open_count)
96425+ if (local->monitors == local_read(&local->open_count))
96426 ieee80211_add_virtual_monitor(local);
96427 }
96428
96429diff --git a/net/mac80211/main.c b/net/mac80211/main.c
96430index e765f77..dfd72e7 100644
96431--- a/net/mac80211/main.c
96432+++ b/net/mac80211/main.c
96433@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
96434 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
96435 IEEE80211_CONF_CHANGE_POWER);
96436
96437- if (changed && local->open_count) {
96438+ if (changed && local_read(&local->open_count)) {
96439 ret = drv_config(local, changed);
96440 /*
96441 * Goal:
96442diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
96443index 3401262..d5cd68d 100644
96444--- a/net/mac80211/pm.c
96445+++ b/net/mac80211/pm.c
96446@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
96447 struct ieee80211_sub_if_data *sdata;
96448 struct sta_info *sta;
96449
96450- if (!local->open_count)
96451+ if (!local_read(&local->open_count))
96452 goto suspend;
96453
96454 ieee80211_scan_cancel(local);
96455@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
96456 cancel_work_sync(&local->dynamic_ps_enable_work);
96457 del_timer_sync(&local->dynamic_ps_timer);
96458
96459- local->wowlan = wowlan && local->open_count;
96460+ local->wowlan = wowlan && local_read(&local->open_count);
96461 if (local->wowlan) {
96462 int err = drv_suspend(local, wowlan);
96463 if (err < 0) {
96464@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
96465 WARN_ON(!list_empty(&local->chanctx_list));
96466
96467 /* stop hardware - this must stop RX */
96468- if (local->open_count)
96469+ if (local_read(&local->open_count))
96470 ieee80211_stop_device(local);
96471
96472 suspend:
96473diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
96474index e126605..73d2c39 100644
96475--- a/net/mac80211/rate.c
96476+++ b/net/mac80211/rate.c
96477@@ -725,7 +725,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
96478
96479 ASSERT_RTNL();
96480
96481- if (local->open_count)
96482+ if (local_read(&local->open_count))
96483 return -EBUSY;
96484
96485 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
96486diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
96487index c97a065..ff61928 100644
96488--- a/net/mac80211/rc80211_pid_debugfs.c
96489+++ b/net/mac80211/rc80211_pid_debugfs.c
96490@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
96491
96492 spin_unlock_irqrestore(&events->lock, status);
96493
96494- if (copy_to_user(buf, pb, p))
96495+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
96496 return -EFAULT;
96497
96498 return p;
96499diff --git a/net/mac80211/util.c b/net/mac80211/util.c
96500index 69e4ef5..e8e4b92 100644
96501--- a/net/mac80211/util.c
96502+++ b/net/mac80211/util.c
96503@@ -1470,7 +1470,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
96504 }
96505 #endif
96506 /* everything else happens only if HW was up & running */
96507- if (!local->open_count)
96508+ if (!local_read(&local->open_count))
96509 goto wake_up;
96510
96511 /*
96512@@ -1695,7 +1695,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
96513 local->in_reconfig = false;
96514 barrier();
96515
96516- if (local->monitors == local->open_count && local->monitors > 0)
96517+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
96518 ieee80211_add_virtual_monitor(local);
96519
96520 /*
96521diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
96522index 6e839b6..002a233 100644
96523--- a/net/netfilter/Kconfig
96524+++ b/net/netfilter/Kconfig
96525@@ -950,6 +950,16 @@ config NETFILTER_XT_MATCH_ESP
96526
96527 To compile it as a module, choose M here. If unsure, say N.
96528
96529+config NETFILTER_XT_MATCH_GRADM
96530+ tristate '"gradm" match support'
96531+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
96532+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
96533+ ---help---
96534+ The gradm match allows to match on grsecurity RBAC being enabled.
96535+ It is useful when iptables rules are applied early on bootup to
96536+ prevent connections to the machine (except from a trusted host)
96537+ while the RBAC system is disabled.
96538+
96539 config NETFILTER_XT_MATCH_HASHLIMIT
96540 tristate '"hashlimit" match support'
96541 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
96542diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
96543index c3a0a12..90b587f 100644
96544--- a/net/netfilter/Makefile
96545+++ b/net/netfilter/Makefile
96546@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
96547 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
96548 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
96549 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
96550+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
96551 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
96552 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
96553 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
96554diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
96555index f2e30fb..f131862 100644
96556--- a/net/netfilter/ipset/ip_set_core.c
96557+++ b/net/netfilter/ipset/ip_set_core.c
96558@@ -1819,7 +1819,7 @@ done:
96559 return ret;
96560 }
96561
96562-static struct nf_sockopt_ops so_set __read_mostly = {
96563+static struct nf_sockopt_ops so_set = {
96564 .pf = PF_INET,
96565 .get_optmin = SO_IP_SET,
96566 .get_optmax = SO_IP_SET + 1,
96567diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
96568index 4c8e5c0..5a79b4d 100644
96569--- a/net/netfilter/ipvs/ip_vs_conn.c
96570+++ b/net/netfilter/ipvs/ip_vs_conn.c
96571@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
96572 /* Increase the refcnt counter of the dest */
96573 ip_vs_dest_hold(dest);
96574
96575- conn_flags = atomic_read(&dest->conn_flags);
96576+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
96577 if (cp->protocol != IPPROTO_UDP)
96578 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
96579 flags = cp->flags;
96580@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
96581
96582 cp->control = NULL;
96583 atomic_set(&cp->n_control, 0);
96584- atomic_set(&cp->in_pkts, 0);
96585+ atomic_set_unchecked(&cp->in_pkts, 0);
96586
96587 cp->packet_xmit = NULL;
96588 cp->app = NULL;
96589@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
96590
96591 /* Don't drop the entry if its number of incoming packets is not
96592 located in [0, 8] */
96593- i = atomic_read(&cp->in_pkts);
96594+ i = atomic_read_unchecked(&cp->in_pkts);
96595 if (i > 8 || i < 0) return 0;
96596
96597 if (!todrop_rate[i]) return 0;
96598diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
96599index 3581736..c0453e9 100644
96600--- a/net/netfilter/ipvs/ip_vs_core.c
96601+++ b/net/netfilter/ipvs/ip_vs_core.c
96602@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
96603 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
96604 /* do not touch skb anymore */
96605
96606- atomic_inc(&cp->in_pkts);
96607+ atomic_inc_unchecked(&cp->in_pkts);
96608 ip_vs_conn_put(cp);
96609 return ret;
96610 }
96611@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
96612 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
96613 pkts = sysctl_sync_threshold(ipvs);
96614 else
96615- pkts = atomic_add_return(1, &cp->in_pkts);
96616+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96617
96618 if (ipvs->sync_state & IP_VS_STATE_MASTER)
96619 ip_vs_sync_conn(net, cp, pkts);
96620diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
96621index a3df9bd..895ae09 100644
96622--- a/net/netfilter/ipvs/ip_vs_ctl.c
96623+++ b/net/netfilter/ipvs/ip_vs_ctl.c
96624@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
96625 */
96626 ip_vs_rs_hash(ipvs, dest);
96627 }
96628- atomic_set(&dest->conn_flags, conn_flags);
96629+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
96630
96631 /* bind the service */
96632 old_svc = rcu_dereference_protected(dest->svc, 1);
96633@@ -1641,7 +1641,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
96634 * align with netns init in ip_vs_control_net_init()
96635 */
96636
96637-static struct ctl_table vs_vars[] = {
96638+static ctl_table_no_const vs_vars[] __read_only = {
96639 {
96640 .procname = "amemthresh",
96641 .maxlen = sizeof(int),
96642@@ -2062,7 +2062,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
96643 " %-7s %-6d %-10d %-10d\n",
96644 &dest->addr.in6,
96645 ntohs(dest->port),
96646- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
96647+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
96648 atomic_read(&dest->weight),
96649 atomic_read(&dest->activeconns),
96650 atomic_read(&dest->inactconns));
96651@@ -2073,7 +2073,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
96652 "%-7s %-6d %-10d %-10d\n",
96653 ntohl(dest->addr.ip),
96654 ntohs(dest->port),
96655- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
96656+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
96657 atomic_read(&dest->weight),
96658 atomic_read(&dest->activeconns),
96659 atomic_read(&dest->inactconns));
96660@@ -2551,7 +2551,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
96661
96662 entry.addr = dest->addr.ip;
96663 entry.port = dest->port;
96664- entry.conn_flags = atomic_read(&dest->conn_flags);
96665+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
96666 entry.weight = atomic_read(&dest->weight);
96667 entry.u_threshold = dest->u_threshold;
96668 entry.l_threshold = dest->l_threshold;
96669@@ -3094,7 +3094,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
96670 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
96671 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
96672 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
96673- (atomic_read(&dest->conn_flags) &
96674+ (atomic_read_unchecked(&dest->conn_flags) &
96675 IP_VS_CONN_F_FWD_MASK)) ||
96676 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
96677 atomic_read(&dest->weight)) ||
96678@@ -3684,7 +3684,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
96679 {
96680 int idx;
96681 struct netns_ipvs *ipvs = net_ipvs(net);
96682- struct ctl_table *tbl;
96683+ ctl_table_no_const *tbl;
96684
96685 atomic_set(&ipvs->dropentry, 0);
96686 spin_lock_init(&ipvs->dropentry_lock);
96687diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
96688index eff13c9..c1aab3e 100644
96689--- a/net/netfilter/ipvs/ip_vs_lblc.c
96690+++ b/net/netfilter/ipvs/ip_vs_lblc.c
96691@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
96692 * IPVS LBLC sysctl table
96693 */
96694 #ifdef CONFIG_SYSCTL
96695-static struct ctl_table vs_vars_table[] = {
96696+static ctl_table_no_const vs_vars_table[] __read_only = {
96697 {
96698 .procname = "lblc_expiration",
96699 .data = NULL,
96700diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
96701index 0b85500..8513fa5 100644
96702--- a/net/netfilter/ipvs/ip_vs_lblcr.c
96703+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
96704@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
96705 * IPVS LBLCR sysctl table
96706 */
96707
96708-static struct ctl_table vs_vars_table[] = {
96709+static ctl_table_no_const vs_vars_table[] __read_only = {
96710 {
96711 .procname = "lblcr_expiration",
96712 .data = NULL,
96713diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
96714index f448471..995f131 100644
96715--- a/net/netfilter/ipvs/ip_vs_sync.c
96716+++ b/net/netfilter/ipvs/ip_vs_sync.c
96717@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
96718 cp = cp->control;
96719 if (cp) {
96720 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96721- pkts = atomic_add_return(1, &cp->in_pkts);
96722+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96723 else
96724 pkts = sysctl_sync_threshold(ipvs);
96725 ip_vs_sync_conn(net, cp->control, pkts);
96726@@ -771,7 +771,7 @@ control:
96727 if (!cp)
96728 return;
96729 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96730- pkts = atomic_add_return(1, &cp->in_pkts);
96731+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96732 else
96733 pkts = sysctl_sync_threshold(ipvs);
96734 goto sloop;
96735@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
96736
96737 if (opt)
96738 memcpy(&cp->in_seq, opt, sizeof(*opt));
96739- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96740+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96741 cp->state = state;
96742 cp->old_state = cp->state;
96743 /*
96744diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
96745index c47444e..b0961c6 100644
96746--- a/net/netfilter/ipvs/ip_vs_xmit.c
96747+++ b/net/netfilter/ipvs/ip_vs_xmit.c
96748@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
96749 else
96750 rc = NF_ACCEPT;
96751 /* do not touch skb anymore */
96752- atomic_inc(&cp->in_pkts);
96753+ atomic_inc_unchecked(&cp->in_pkts);
96754 goto out;
96755 }
96756
96757@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
96758 else
96759 rc = NF_ACCEPT;
96760 /* do not touch skb anymore */
96761- atomic_inc(&cp->in_pkts);
96762+ atomic_inc_unchecked(&cp->in_pkts);
96763 goto out;
96764 }
96765
96766diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
96767index 2d3030a..7ba1c0a 100644
96768--- a/net/netfilter/nf_conntrack_acct.c
96769+++ b/net/netfilter/nf_conntrack_acct.c
96770@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
96771 #ifdef CONFIG_SYSCTL
96772 static int nf_conntrack_acct_init_sysctl(struct net *net)
96773 {
96774- struct ctl_table *table;
96775+ ctl_table_no_const *table;
96776
96777 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
96778 GFP_KERNEL);
96779diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
96780index 5d892fe..d2fc9d8 100644
96781--- a/net/netfilter/nf_conntrack_core.c
96782+++ b/net/netfilter/nf_conntrack_core.c
96783@@ -1600,6 +1600,10 @@ void nf_conntrack_init_end(void)
96784 #define DYING_NULLS_VAL ((1<<30)+1)
96785 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
96786
96787+#ifdef CONFIG_GRKERNSEC_HIDESYM
96788+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
96789+#endif
96790+
96791 int nf_conntrack_init_net(struct net *net)
96792 {
96793 int ret;
96794@@ -1614,7 +1618,11 @@ int nf_conntrack_init_net(struct net *net)
96795 goto err_stat;
96796 }
96797
96798+#ifdef CONFIG_GRKERNSEC_HIDESYM
96799+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
96800+#else
96801 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
96802+#endif
96803 if (!net->ct.slabname) {
96804 ret = -ENOMEM;
96805 goto err_slabname;
96806diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
96807index 1df1761..ce8b88a 100644
96808--- a/net/netfilter/nf_conntrack_ecache.c
96809+++ b/net/netfilter/nf_conntrack_ecache.c
96810@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
96811 #ifdef CONFIG_SYSCTL
96812 static int nf_conntrack_event_init_sysctl(struct net *net)
96813 {
96814- struct ctl_table *table;
96815+ ctl_table_no_const *table;
96816
96817 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
96818 GFP_KERNEL);
96819diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
96820index 974a2a4..52cc6ff 100644
96821--- a/net/netfilter/nf_conntrack_helper.c
96822+++ b/net/netfilter/nf_conntrack_helper.c
96823@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
96824
96825 static int nf_conntrack_helper_init_sysctl(struct net *net)
96826 {
96827- struct ctl_table *table;
96828+ ctl_table_no_const *table;
96829
96830 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
96831 GFP_KERNEL);
96832diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
96833index ce30041..3861b5d 100644
96834--- a/net/netfilter/nf_conntrack_proto.c
96835+++ b/net/netfilter/nf_conntrack_proto.c
96836@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
96837
96838 static void
96839 nf_ct_unregister_sysctl(struct ctl_table_header **header,
96840- struct ctl_table **table,
96841+ ctl_table_no_const **table,
96842 unsigned int users)
96843 {
96844 if (users > 0)
96845diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
96846index a99b6c3..cb372f9 100644
96847--- a/net/netfilter/nf_conntrack_proto_dccp.c
96848+++ b/net/netfilter/nf_conntrack_proto_dccp.c
96849@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96850 const char *msg;
96851 u_int8_t state;
96852
96853- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96854+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96855 BUG_ON(dh == NULL);
96856
96857 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
96858@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96859 out_invalid:
96860 if (LOG_INVALID(net, IPPROTO_DCCP))
96861 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
96862- NULL, msg);
96863+ NULL, "%s", msg);
96864 return false;
96865 }
96866
96867@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
96868 u_int8_t type, old_state, new_state;
96869 enum ct_dccp_roles role;
96870
96871- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96872+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96873 BUG_ON(dh == NULL);
96874 type = dh->dccph_type;
96875
96876@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96877 unsigned int cscov;
96878 const char *msg;
96879
96880- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96881+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96882 if (dh == NULL) {
96883 msg = "nf_ct_dccp: short packet ";
96884 goto out_invalid;
96885@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96886
96887 out_invalid:
96888 if (LOG_INVALID(net, IPPROTO_DCCP))
96889- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
96890+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
96891 return -NF_ACCEPT;
96892 }
96893
96894diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
96895index f641751..d3c5b51 100644
96896--- a/net/netfilter/nf_conntrack_standalone.c
96897+++ b/net/netfilter/nf_conntrack_standalone.c
96898@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
96899
96900 static int nf_conntrack_standalone_init_sysctl(struct net *net)
96901 {
96902- struct ctl_table *table;
96903+ ctl_table_no_const *table;
96904
96905 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
96906 GFP_KERNEL);
96907diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
96908index 902fb0a..87f7fdb 100644
96909--- a/net/netfilter/nf_conntrack_timestamp.c
96910+++ b/net/netfilter/nf_conntrack_timestamp.c
96911@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
96912 #ifdef CONFIG_SYSCTL
96913 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
96914 {
96915- struct ctl_table *table;
96916+ ctl_table_no_const *table;
96917
96918 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
96919 GFP_KERNEL);
96920diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
96921index 85296d4..8becdec 100644
96922--- a/net/netfilter/nf_log.c
96923+++ b/net/netfilter/nf_log.c
96924@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
96925
96926 #ifdef CONFIG_SYSCTL
96927 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
96928-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
96929+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
96930
96931 static int nf_log_proc_dostring(struct ctl_table *table, int write,
96932 void __user *buffer, size_t *lenp, loff_t *ppos)
96933@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
96934 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
96935 mutex_unlock(&nf_log_mutex);
96936 } else {
96937+ ctl_table_no_const nf_log_table = *table;
96938+
96939 mutex_lock(&nf_log_mutex);
96940 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
96941 lockdep_is_held(&nf_log_mutex));
96942 if (!logger)
96943- table->data = "NONE";
96944+ nf_log_table.data = "NONE";
96945 else
96946- table->data = logger->name;
96947- r = proc_dostring(table, write, buffer, lenp, ppos);
96948+ nf_log_table.data = logger->name;
96949+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
96950 mutex_unlock(&nf_log_mutex);
96951 }
96952
96953diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
96954index f042ae5..30ea486 100644
96955--- a/net/netfilter/nf_sockopt.c
96956+++ b/net/netfilter/nf_sockopt.c
96957@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
96958 }
96959 }
96960
96961- list_add(&reg->list, &nf_sockopts);
96962+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
96963 out:
96964 mutex_unlock(&nf_sockopt_mutex);
96965 return ret;
96966@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
96967 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
96968 {
96969 mutex_lock(&nf_sockopt_mutex);
96970- list_del(&reg->list);
96971+ pax_list_del((struct list_head *)&reg->list);
96972 mutex_unlock(&nf_sockopt_mutex);
96973 }
96974 EXPORT_SYMBOL(nf_unregister_sockopt);
96975diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
96976index d92cc31..e46f350 100644
96977--- a/net/netfilter/nfnetlink_log.c
96978+++ b/net/netfilter/nfnetlink_log.c
96979@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
96980 struct nfnl_log_net {
96981 spinlock_t instances_lock;
96982 struct hlist_head instance_table[INSTANCE_BUCKETS];
96983- atomic_t global_seq;
96984+ atomic_unchecked_t global_seq;
96985 };
96986
96987 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
96988@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
96989 /* global sequence number */
96990 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
96991 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
96992- htonl(atomic_inc_return(&log->global_seq))))
96993+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
96994 goto nla_put_failure;
96995
96996 if (data_len) {
96997diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
96998new file mode 100644
96999index 0000000..c566332
97000--- /dev/null
97001+++ b/net/netfilter/xt_gradm.c
97002@@ -0,0 +1,51 @@
97003+/*
97004+ * gradm match for netfilter
97005