]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.12.2-201312032145.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.12.2-201312032145.patch
CommitLineData
2b5227c2
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 e6e72b6..570e70a 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..41c7f61 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+} __do_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 be956db..c8f25e2 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 9cbe70c..a7b5e34 100644
2370--- a/arch/arm/kernel/entry-armv.S
2371+++ b/arch/arm/kernel/entry-armv.S
2372@@ -47,6 +47,87 @@
2373 9997:
2374 .endm
2375
2376+ .macro pax_enter_kernel
2377+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2378+ @ make aligned space for saved DACR
2379+ sub sp, sp, #8
2380+ @ save regs
2381+ stmdb sp!, {r1, r2}
2382+ @ read DACR from cpu_domain into r1
2383+ mov r2, sp
2384+ @ assume 8K pages, since we have to split the immediate in two
2385+ bic r2, r2, #(0x1fc0)
2386+ bic r2, r2, #(0x3f)
2387+ ldr r1, [r2, #TI_CPU_DOMAIN]
2388+ @ store old DACR on stack
2389+ str r1, [sp, #8]
2390+#ifdef CONFIG_PAX_KERNEXEC
2391+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2392+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2393+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2394+#endif
2395+#ifdef CONFIG_PAX_MEMORY_UDEREF
2396+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2397+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2398+#endif
2399+ @ write r1 to current_thread_info()->cpu_domain
2400+ str r1, [r2, #TI_CPU_DOMAIN]
2401+ @ write r1 to DACR
2402+ mcr p15, 0, r1, c3, c0, 0
2403+ @ instruction sync
2404+ instr_sync
2405+ @ restore regs
2406+ ldmia sp!, {r1, r2}
2407+#endif
2408+ .endm
2409+
2410+ .macro pax_open_userland
2411+#ifdef CONFIG_PAX_MEMORY_UDEREF
2412+ @ save regs
2413+ stmdb sp!, {r0, r1}
2414+ @ read DACR from cpu_domain into r1
2415+ mov r0, sp
2416+ @ assume 8K pages, since we have to split the immediate in two
2417+ bic r0, r0, #(0x1fc0)
2418+ bic r0, r0, #(0x3f)
2419+ ldr r1, [r0, #TI_CPU_DOMAIN]
2420+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2421+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2422+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2423+ @ write r1 to current_thread_info()->cpu_domain
2424+ str r1, [r0, #TI_CPU_DOMAIN]
2425+ @ write r1 to DACR
2426+ mcr p15, 0, r1, c3, c0, 0
2427+ @ instruction sync
2428+ instr_sync
2429+ @ restore regs
2430+ ldmia sp!, {r0, r1}
2431+#endif
2432+ .endm
2433+
2434+ .macro pax_close_userland
2435+#ifdef CONFIG_PAX_MEMORY_UDEREF
2436+ @ save regs
2437+ stmdb sp!, {r0, r1}
2438+ @ read DACR from cpu_domain into r1
2439+ mov r0, sp
2440+ @ assume 8K pages, since we have to split the immediate in two
2441+ bic r0, r0, #(0x1fc0)
2442+ bic r0, r0, #(0x3f)
2443+ ldr r1, [r0, #TI_CPU_DOMAIN]
2444+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2445+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2446+ @ write r1 to current_thread_info()->cpu_domain
2447+ str r1, [r0, #TI_CPU_DOMAIN]
2448+ @ write r1 to DACR
2449+ mcr p15, 0, r1, c3, c0, 0
2450+ @ instruction sync
2451+ instr_sync
2452+ @ restore regs
2453+ ldmia sp!, {r0, r1}
2454+#endif
2455+ .endm
2456+
2457 .macro pabt_helper
2458 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2459 #ifdef MULTI_PABORT
2460@@ -89,11 +170,15 @@
2461 * Invalid mode handlers
2462 */
2463 .macro inv_entry, reason
2464+
2465+ pax_enter_kernel
2466+
2467 sub sp, sp, #S_FRAME_SIZE
2468 ARM( stmib sp, {r1 - lr} )
2469 THUMB( stmia sp, {r0 - r12} )
2470 THUMB( str sp, [sp, #S_SP] )
2471 THUMB( str lr, [sp, #S_LR] )
2472+
2473 mov r1, #\reason
2474 .endm
2475
2476@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2477 .macro svc_entry, stack_hole=0
2478 UNWIND(.fnstart )
2479 UNWIND(.save {r0 - pc} )
2480+
2481+ pax_enter_kernel
2482+
2483 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2484+
2485 #ifdef CONFIG_THUMB2_KERNEL
2486 SPFIX( str r0, [sp] ) @ temporarily saved
2487 SPFIX( mov r0, sp )
2488@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2489 ldmia r0, {r3 - r5}
2490 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2491 mov r6, #-1 @ "" "" "" ""
2492+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2493+ @ offset sp by 8 as done in pax_enter_kernel
2494+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2495+#else
2496 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2497+#endif
2498 SPFIX( addeq r2, r2, #4 )
2499 str r3, [sp, #-4]! @ save the "real" r0 copied
2500 @ from the exception stack
2501@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2502 .macro usr_entry
2503 UNWIND(.fnstart )
2504 UNWIND(.cantunwind ) @ don't unwind the user space
2505+
2506+ pax_enter_kernel_user
2507+
2508 sub sp, sp, #S_FRAME_SIZE
2509 ARM( stmib sp, {r1 - r12} )
2510 THUMB( stmia sp, {r0 - r12} )
2511@@ -415,7 +512,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@@ -450,10 +549,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@@ -482,7 +585,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@@ -692,7 +796,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@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2556 ldr r8, =__stack_chk_guard
2557 ldr r7, [r7, #TSK_STACK_CANARY]
2558 #endif
2559-#ifdef CONFIG_CPU_USE_DOMAINS
2560+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2561 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2562 #endif
2563 mov r5, r0
2564diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2565index bc6bd96..bd026cb 100644
2566--- a/arch/arm/kernel/entry-common.S
2567+++ b/arch/arm/kernel/entry-common.S
2568@@ -10,18 +10,46 @@
2569
2570 #include <asm/unistd.h>
2571 #include <asm/ftrace.h>
2572+#include <asm/domain.h>
2573 #include <asm/unwind.h>
2574
2575+#include "entry-header.S"
2576+
2577 #ifdef CONFIG_NEED_RET_TO_USER
2578 #include <mach/entry-macro.S>
2579 #else
2580 .macro arch_ret_to_user, tmp1, tmp2
2581+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2582+ @ save regs
2583+ stmdb sp!, {r1, r2}
2584+ @ read DACR from cpu_domain into r1
2585+ mov r2, sp
2586+ @ assume 8K pages, since we have to split the immediate in two
2587+ bic r2, r2, #(0x1fc0)
2588+ bic r2, r2, #(0x3f)
2589+ ldr r1, [r2, #TI_CPU_DOMAIN]
2590+#ifdef CONFIG_PAX_KERNEXEC
2591+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2592+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2593+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2594+#endif
2595+#ifdef CONFIG_PAX_MEMORY_UDEREF
2596+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2597+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2598+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2599+#endif
2600+ @ write r1 to current_thread_info()->cpu_domain
2601+ str r1, [r2, #TI_CPU_DOMAIN]
2602+ @ write r1 to DACR
2603+ mcr p15, 0, r1, c3, c0, 0
2604+ @ instruction sync
2605+ instr_sync
2606+ @ restore regs
2607+ ldmia sp!, {r1, r2}
2608+#endif
2609 .endm
2610 #endif
2611
2612-#include "entry-header.S"
2613-
2614-
2615 .align 5
2616 /*
2617 * This is the fast syscall return path. We do as little as
2618@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2619 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2620 #endif
2621
2622+ /*
2623+ * do this here to avoid a performance hit of wrapping the code above
2624+ * that directly dereferences userland to parse the SWI instruction
2625+ */
2626+ pax_enter_kernel_user
2627+
2628 adr tbl, sys_call_table @ load syscall table pointer
2629
2630 #if defined(CONFIG_OABI_COMPAT)
2631diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2632index 39f89fb..d612bd9 100644
2633--- a/arch/arm/kernel/entry-header.S
2634+++ b/arch/arm/kernel/entry-header.S
2635@@ -184,6 +184,60 @@
2636 msr cpsr_c, \rtemp @ switch back to the SVC mode
2637 .endm
2638
2639+ .macro pax_enter_kernel_user
2640+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2641+ @ save regs
2642+ stmdb sp!, {r0, r1}
2643+ @ read DACR from cpu_domain into r1
2644+ mov r0, sp
2645+ @ assume 8K pages, since we have to split the immediate in two
2646+ bic r0, r0, #(0x1fc0)
2647+ bic r0, r0, #(0x3f)
2648+ ldr r1, [r0, #TI_CPU_DOMAIN]
2649+#ifdef CONFIG_PAX_MEMORY_UDEREF
2650+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2651+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2652+#endif
2653+#ifdef CONFIG_PAX_KERNEXEC
2654+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2655+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2656+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2657+#endif
2658+ @ write r1 to current_thread_info()->cpu_domain
2659+ str r1, [r0, #TI_CPU_DOMAIN]
2660+ @ write r1 to DACR
2661+ mcr p15, 0, r1, c3, c0, 0
2662+ @ instruction sync
2663+ instr_sync
2664+ @ restore regs
2665+ ldmia sp!, {r0, r1}
2666+#endif
2667+ .endm
2668+
2669+ .macro pax_exit_kernel
2670+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2671+ @ save regs
2672+ stmdb sp!, {r0, r1}
2673+ @ read old DACR from stack into r1
2674+ ldr r1, [sp, #(8 + S_SP)]
2675+ sub r1, r1, #8
2676+ ldr r1, [r1]
2677+
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ mov r0, sp
2680+ @ assume 8K pages, since we have to split the immediate in two
2681+ bic r0, r0, #(0x1fc0)
2682+ bic r0, r0, #(0x3f)
2683+ str r1, [r0, #TI_CPU_DOMAIN]
2684+ @ write r1 to DACR
2685+ mcr p15, 0, r1, c3, c0, 0
2686+ @ instruction sync
2687+ instr_sync
2688+ @ restore regs
2689+ ldmia sp!, {r0, r1}
2690+#endif
2691+ .endm
2692+
2693 #ifndef CONFIG_THUMB2_KERNEL
2694 .macro svc_exit, rpsr, irq = 0
2695 .if \irq != 0
2696@@ -203,6 +257,9 @@
2697 blne trace_hardirqs_off
2698 #endif
2699 .endif
2700+
2701+ pax_exit_kernel
2702+
2703 msr spsr_cxsf, \rpsr
2704 #if defined(CONFIG_CPU_V6)
2705 ldr r0, [sp]
2706@@ -266,6 +323,9 @@
2707 blne trace_hardirqs_off
2708 #endif
2709 .endif
2710+
2711+ pax_exit_kernel
2712+
2713 ldr lr, [sp, #S_SP] @ top of the stack
2714 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2715 clrex @ clear the exclusive monitor
2716diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2717index 918875d..cd5fa27 100644
2718--- a/arch/arm/kernel/fiq.c
2719+++ b/arch/arm/kernel/fiq.c
2720@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2721 void *base = vectors_page;
2722 unsigned offset = FIQ_OFFSET;
2723
2724+ pax_open_kernel();
2725 memcpy(base + offset, start, length);
2726+ pax_close_kernel();
2727+
2728 if (!cache_is_vipt_nonaliasing())
2729 flush_icache_range((unsigned long)base + offset, offset +
2730 length);
2731diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2732index 476de57..4857a76 100644
2733--- a/arch/arm/kernel/head.S
2734+++ b/arch/arm/kernel/head.S
2735@@ -52,7 +52,9 @@
2736 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2737
2738 .macro pgtbl, rd, phys
2739- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2740+ mov \rd, #TEXT_OFFSET
2741+ sub \rd, #PG_DIR_SIZE
2742+ add \rd, \rd, \phys
2743 .endm
2744
2745 /*
2746@@ -432,7 +434,7 @@ __enable_mmu:
2747 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2748 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2749 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2750- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2751+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2752 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2753 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2754 #endif
2755diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2756index 084dc88..fce4e68 100644
2757--- a/arch/arm/kernel/module.c
2758+++ b/arch/arm/kernel/module.c
2759@@ -37,12 +37,39 @@
2760 #endif
2761
2762 #ifdef CONFIG_MMU
2763-void *module_alloc(unsigned long size)
2764+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2765 {
2766+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2767+ return NULL;
2768 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2769- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2770+ GFP_KERNEL, prot, -1,
2771 __builtin_return_address(0));
2772 }
2773+
2774+void *module_alloc(unsigned long size)
2775+{
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+ return __module_alloc(size, PAGE_KERNEL);
2779+#else
2780+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2781+#endif
2782+
2783+}
2784+
2785+#ifdef CONFIG_PAX_KERNEXEC
2786+void module_free_exec(struct module *mod, void *module_region)
2787+{
2788+ module_free(mod, module_region);
2789+}
2790+EXPORT_SYMBOL(module_free_exec);
2791+
2792+void *module_alloc_exec(unsigned long size)
2793+{
2794+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2795+}
2796+EXPORT_SYMBOL(module_alloc_exec);
2797+#endif
2798 #endif
2799
2800 int
2801diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2802index 07314af..c46655c 100644
2803--- a/arch/arm/kernel/patch.c
2804+++ b/arch/arm/kernel/patch.c
2805@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2807 int size;
2808
2809+ pax_open_kernel();
2810 if (thumb2 && __opcode_is_thumb16(insn)) {
2811 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2812 size = sizeof(u16);
2813@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2814 *(u32 *)addr = insn;
2815 size = sizeof(u32);
2816 }
2817+ pax_close_kernel();
2818
2819 flush_icache_range((uintptr_t)(addr),
2820 (uintptr_t)(addr) + size);
2821diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2822index 94f6b05..efd7312 100644
2823--- a/arch/arm/kernel/process.c
2824+++ b/arch/arm/kernel/process.c
2825@@ -217,6 +217,7 @@ void machine_power_off(void)
2826
2827 if (pm_power_off)
2828 pm_power_off();
2829+ BUG();
2830 }
2831
2832 /*
2833@@ -230,7 +231,7 @@ void machine_power_off(void)
2834 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2835 * to use. Implementing such co-ordination would be essentially impossible.
2836 */
2837-void machine_restart(char *cmd)
2838+__noreturn void machine_restart(char *cmd)
2839 {
2840 local_irq_disable();
2841 smp_send_stop();
2842@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2843
2844 show_regs_print_info(KERN_DEFAULT);
2845
2846- print_symbol("PC is at %s\n", instruction_pointer(regs));
2847- print_symbol("LR is at %s\n", regs->ARM_lr);
2848+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2849+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2850 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2851 "sp : %08lx ip : %08lx fp : %08lx\n",
2852 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2853@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2854 return 0;
2855 }
2856
2857-unsigned long arch_randomize_brk(struct mm_struct *mm)
2858-{
2859- unsigned long range_end = mm->brk + 0x02000000;
2860- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2861-}
2862-
2863 #ifdef CONFIG_MMU
2864 #ifdef CONFIG_KUSER_HELPERS
2865 /*
2866@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2867
2868 static int __init gate_vma_init(void)
2869 {
2870- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2871+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2872 return 0;
2873 }
2874 arch_initcall(gate_vma_init);
2875@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2876
2877 const char *arch_vma_name(struct vm_area_struct *vma)
2878 {
2879- return is_gate_vma(vma) ? "[vectors]" :
2880- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2881- "[sigpage]" : NULL;
2882+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2883 }
2884
2885-static struct page *signal_page;
2886-extern struct page *get_signal_page(void);
2887-
2888 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2889 {
2890 struct mm_struct *mm = current->mm;
2891- unsigned long addr;
2892- int ret;
2893-
2894- if (!signal_page)
2895- signal_page = get_signal_page();
2896- if (!signal_page)
2897- return -ENOMEM;
2898
2899 down_write(&mm->mmap_sem);
2900- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2901- if (IS_ERR_VALUE(addr)) {
2902- ret = addr;
2903- goto up_fail;
2904- }
2905-
2906- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2907- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2908- &signal_page);
2909-
2910- if (ret == 0)
2911- mm->context.sigpage = addr;
2912-
2913- up_fail:
2914+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2915 up_write(&mm->mmap_sem);
2916- return ret;
2917+ return 0;
2918 }
2919 #endif
2920diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2921index 4693188..4596c5e 100644
2922--- a/arch/arm/kernel/psci.c
2923+++ b/arch/arm/kernel/psci.c
2924@@ -24,7 +24,7 @@
2925 #include <asm/opcodes-virt.h>
2926 #include <asm/psci.h>
2927
2928-struct psci_operations psci_ops;
2929+struct psci_operations psci_ops __read_only;
2930
2931 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2932
2933diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2934index 0dd3b79..e018f64 100644
2935--- a/arch/arm/kernel/ptrace.c
2936+++ b/arch/arm/kernel/ptrace.c
2937@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2938 return current_thread_info()->syscall;
2939 }
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+extern void gr_delayed_cred_worker(void);
2943+#endif
2944+
2945 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2946 {
2947 current_thread_info()->syscall = scno;
2948
2949+#ifdef CONFIG_GRKERNSEC_SETXID
2950+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2951+ gr_delayed_cred_worker();
2952+#endif
2953+
2954 /* Do the secure computing check first; failures should be fast. */
2955 if (secure_computing(scno) == -1)
2956 return -1;
2957diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2958index 0e1e2b3..c0e821d 100644
2959--- a/arch/arm/kernel/setup.c
2960+++ b/arch/arm/kernel/setup.c
2961@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2962 unsigned int elf_hwcap __read_mostly;
2963 EXPORT_SYMBOL(elf_hwcap);
2964
2965+pteval_t __supported_pte_mask __read_only;
2966+pmdval_t __supported_pmd_mask __read_only;
2967
2968 #ifdef MULTI_CPU
2969-struct processor processor __read_mostly;
2970+struct processor processor;
2971 #endif
2972 #ifdef MULTI_TLB
2973-struct cpu_tlb_fns cpu_tlb __read_mostly;
2974+struct cpu_tlb_fns cpu_tlb __read_only;
2975 #endif
2976 #ifdef MULTI_USER
2977-struct cpu_user_fns cpu_user __read_mostly;
2978+struct cpu_user_fns cpu_user __read_only;
2979 #endif
2980 #ifdef MULTI_CACHE
2981-struct cpu_cache_fns cpu_cache __read_mostly;
2982+struct cpu_cache_fns cpu_cache __read_only;
2983 #endif
2984 #ifdef CONFIG_OUTER_CACHE
2985-struct outer_cache_fns outer_cache __read_mostly;
2986+struct outer_cache_fns outer_cache __read_only;
2987 EXPORT_SYMBOL(outer_cache);
2988 #endif
2989
2990@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2991 asm("mrc p15, 0, %0, c0, c1, 4"
2992 : "=r" (mmfr0));
2993 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2994- (mmfr0 & 0x000000f0) >= 0x00000030)
2995+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2996 cpu_arch = CPU_ARCH_ARMv7;
2997- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2998+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2999+ __supported_pte_mask |= L_PTE_PXN;
3000+ __supported_pmd_mask |= PMD_PXNTABLE;
3001+ }
3002+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3003 (mmfr0 & 0x000000f0) == 0x00000020)
3004 cpu_arch = CPU_ARCH_ARMv6;
3005 else
3006@@ -571,7 +577,7 @@ static void __init setup_processor(void)
3007 __cpu_architecture = __get_cpu_architecture();
3008
3009 #ifdef MULTI_CPU
3010- processor = *list->proc;
3011+ memcpy((void *)&processor, list->proc, sizeof processor);
3012 #endif
3013 #ifdef MULTI_TLB
3014 cpu_tlb = *list->tlb;
3015diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016index ab33042..11248a8 100644
3017--- a/arch/arm/kernel/signal.c
3018+++ b/arch/arm/kernel/signal.c
3019@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3020 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3021 };
3022
3023-static unsigned long signal_return_offset;
3024-
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032- retcode = mm->context.sigpage + signal_return_offset +
3033- (idx << 2) + thumb;
3034+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042-
3043-struct page *get_signal_page(void)
3044-{
3045- unsigned long ptr;
3046- unsigned offset;
3047- struct page *page;
3048- void *addr;
3049-
3050- page = alloc_pages(GFP_KERNEL, 0);
3051-
3052- if (!page)
3053- return NULL;
3054-
3055- addr = page_address(page);
3056-
3057- /* Give the signal return code some randomness */
3058- offset = 0x200 + (get_random_int() & 0x7fc);
3059- signal_return_offset = offset;
3060-
3061- /*
3062- * Copy signal return handlers into the vector page, and
3063- * set sigreturn to be a pointer to these.
3064- */
3065- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066-
3067- ptr = (unsigned long)addr + offset;
3068- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069-
3070- return page;
3071-}
3072diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073index 72024ea..ae302dd 100644
3074--- a/arch/arm/kernel/smp.c
3075+++ b/arch/arm/kernel/smp.c
3076@@ -70,7 +70,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080-static struct smp_operations smp_ops;
3081+static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3086index 8fcda14..4512b9d 100644
3087--- a/arch/arm/kernel/traps.c
3088+++ b/arch/arm/kernel/traps.c
3089@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3090 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3091 {
3092 #ifdef CONFIG_KALLSYMS
3093- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3094+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3095 #else
3096 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3097 #endif
3098@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3099 static int die_owner = -1;
3100 static unsigned int die_nest_count;
3101
3102+extern void gr_handle_kernel_exploit(void);
3103+
3104 static unsigned long oops_begin(void)
3105 {
3106 int cpu;
3107@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3108 panic("Fatal exception in interrupt");
3109 if (panic_on_oops)
3110 panic("Fatal exception");
3111+
3112+ gr_handle_kernel_exploit();
3113+
3114 if (signr)
3115 do_exit(signr);
3116 }
3117@@ -628,7 +633,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3118 * The user helper at 0xffff0fe0 must be used instead.
3119 * (see entry-armv.S for details)
3120 */
3121+ pax_open_kernel();
3122 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3123+ pax_close_kernel();
3124 }
3125 return 0;
3126
3127@@ -885,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3128 kuser_init(vectors_base);
3129
3130 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3131- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3132+
3133+#ifndef CONFIG_PAX_MEMORY_UDEREF
3134+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3135+#endif
3136+
3137 #else /* ifndef CONFIG_CPU_V7M */
3138 /*
3139 * on V7-M there is no need to copy the vector table to a dedicated
3140diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3141index 7bcee5c..e2f3249 100644
3142--- a/arch/arm/kernel/vmlinux.lds.S
3143+++ b/arch/arm/kernel/vmlinux.lds.S
3144@@ -8,7 +8,11 @@
3145 #include <asm/thread_info.h>
3146 #include <asm/memory.h>
3147 #include <asm/page.h>
3148-
3149+
3150+#ifdef CONFIG_PAX_KERNEXEC
3151+#include <asm/pgtable.h>
3152+#endif
3153+
3154 #define PROC_INFO \
3155 . = ALIGN(4); \
3156 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3157@@ -34,7 +38,7 @@
3158 #endif
3159
3160 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3161- defined(CONFIG_GENERIC_BUG)
3162+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3163 #define ARM_EXIT_KEEP(x) x
3164 #define ARM_EXIT_DISCARD(x)
3165 #else
3166@@ -90,6 +94,11 @@ SECTIONS
3167 _text = .;
3168 HEAD_TEXT
3169 }
3170+
3171+#ifdef CONFIG_PAX_KERNEXEC
3172+ . = ALIGN(1<<SECTION_SHIFT);
3173+#endif
3174+
3175 .text : { /* Real text segment */
3176 _stext = .; /* Text and read-only data */
3177 __exception_text_start = .;
3178@@ -112,6 +121,8 @@ SECTIONS
3179 ARM_CPU_KEEP(PROC_INFO)
3180 }
3181
3182+ _etext = .; /* End of text section */
3183+
3184 RO_DATA(PAGE_SIZE)
3185
3186 . = ALIGN(4);
3187@@ -142,7 +153,9 @@ SECTIONS
3188
3189 NOTES
3190
3191- _etext = .; /* End of text and rodata section */
3192+#ifdef CONFIG_PAX_KERNEXEC
3193+ . = ALIGN(1<<SECTION_SHIFT);
3194+#endif
3195
3196 #ifndef CONFIG_XIP_KERNEL
3197 . = ALIGN(PAGE_SIZE);
3198@@ -220,6 +233,11 @@ SECTIONS
3199 . = PAGE_OFFSET + TEXT_OFFSET;
3200 #else
3201 __init_end = .;
3202+
3203+#ifdef CONFIG_PAX_KERNEXEC
3204+ . = ALIGN(1<<SECTION_SHIFT);
3205+#endif
3206+
3207 . = ALIGN(THREAD_SIZE);
3208 __data_loc = .;
3209 #endif
3210diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3211index 9c697db..115237f 100644
3212--- a/arch/arm/kvm/arm.c
3213+++ b/arch/arm/kvm/arm.c
3214@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3215 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3216
3217 /* The VMID used in the VTTBR */
3218-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3219+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3220 static u8 kvm_next_vmid;
3221 static DEFINE_SPINLOCK(kvm_vmid_lock);
3222
3223@@ -396,7 +396,7 @@ void force_vm_exit(const cpumask_t *mask)
3224 */
3225 static bool need_new_vmid_gen(struct kvm *kvm)
3226 {
3227- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3228+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3229 }
3230
3231 /**
3232@@ -429,7 +429,7 @@ static void update_vttbr(struct kvm *kvm)
3233
3234 /* First user of a new VMID generation? */
3235 if (unlikely(kvm_next_vmid == 0)) {
3236- atomic64_inc(&kvm_vmid_gen);
3237+ atomic64_inc_unchecked(&kvm_vmid_gen);
3238 kvm_next_vmid = 1;
3239
3240 /*
3241@@ -446,7 +446,7 @@ static void update_vttbr(struct kvm *kvm)
3242 kvm_call_hyp(__kvm_flush_vm_context);
3243 }
3244
3245- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3246+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3247 kvm->arch.vmid = kvm_next_vmid;
3248 kvm_next_vmid++;
3249
3250diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3251index 14a0d98..7771a7d 100644
3252--- a/arch/arm/lib/clear_user.S
3253+++ b/arch/arm/lib/clear_user.S
3254@@ -12,14 +12,14 @@
3255
3256 .text
3257
3258-/* Prototype: int __clear_user(void *addr, size_t sz)
3259+/* Prototype: int ___clear_user(void *addr, size_t sz)
3260 * Purpose : clear some user memory
3261 * Params : addr - user memory address to clear
3262 * : sz - number of bytes to clear
3263 * Returns : number of bytes NOT cleared
3264 */
3265 ENTRY(__clear_user_std)
3266-WEAK(__clear_user)
3267+WEAK(___clear_user)
3268 stmfd sp!, {r1, lr}
3269 mov r2, #0
3270 cmp r1, #4
3271@@ -44,7 +44,7 @@ WEAK(__clear_user)
3272 USER( strnebt r2, [r0])
3273 mov r0, #0
3274 ldmfd sp!, {r1, pc}
3275-ENDPROC(__clear_user)
3276+ENDPROC(___clear_user)
3277 ENDPROC(__clear_user_std)
3278
3279 .pushsection .fixup,"ax"
3280diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3281index 66a477a..bee61d3 100644
3282--- a/arch/arm/lib/copy_from_user.S
3283+++ b/arch/arm/lib/copy_from_user.S
3284@@ -16,7 +16,7 @@
3285 /*
3286 * Prototype:
3287 *
3288- * size_t __copy_from_user(void *to, const void *from, size_t n)
3289+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3290 *
3291 * Purpose:
3292 *
3293@@ -84,11 +84,11 @@
3294
3295 .text
3296
3297-ENTRY(__copy_from_user)
3298+ENTRY(___copy_from_user)
3299
3300 #include "copy_template.S"
3301
3302-ENDPROC(__copy_from_user)
3303+ENDPROC(___copy_from_user)
3304
3305 .pushsection .fixup,"ax"
3306 .align 0
3307diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3308index 6ee2f67..d1cce76 100644
3309--- a/arch/arm/lib/copy_page.S
3310+++ b/arch/arm/lib/copy_page.S
3311@@ -10,6 +10,7 @@
3312 * ASM optimised string functions
3313 */
3314 #include <linux/linkage.h>
3315+#include <linux/const.h>
3316 #include <asm/assembler.h>
3317 #include <asm/asm-offsets.h>
3318 #include <asm/cache.h>
3319diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3320index d066df6..df28194 100644
3321--- a/arch/arm/lib/copy_to_user.S
3322+++ b/arch/arm/lib/copy_to_user.S
3323@@ -16,7 +16,7 @@
3324 /*
3325 * Prototype:
3326 *
3327- * size_t __copy_to_user(void *to, const void *from, size_t n)
3328+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3329 *
3330 * Purpose:
3331 *
3332@@ -88,11 +88,11 @@
3333 .text
3334
3335 ENTRY(__copy_to_user_std)
3336-WEAK(__copy_to_user)
3337+WEAK(___copy_to_user)
3338
3339 #include "copy_template.S"
3340
3341-ENDPROC(__copy_to_user)
3342+ENDPROC(___copy_to_user)
3343 ENDPROC(__copy_to_user_std)
3344
3345 .pushsection .fixup,"ax"
3346diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3347index 7d08b43..f7ca7ea 100644
3348--- a/arch/arm/lib/csumpartialcopyuser.S
3349+++ b/arch/arm/lib/csumpartialcopyuser.S
3350@@ -57,8 +57,8 @@
3351 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3352 */
3353
3354-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3355-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3356+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3357+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3358
3359 #include "csumpartialcopygeneric.S"
3360
3361diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3362index 5306de3..aed6d03 100644
3363--- a/arch/arm/lib/delay.c
3364+++ b/arch/arm/lib/delay.c
3365@@ -28,7 +28,7 @@
3366 /*
3367 * Default to the loop-based delay implementation.
3368 */
3369-struct arm_delay_ops arm_delay_ops = {
3370+struct arm_delay_ops arm_delay_ops __read_only = {
3371 .delay = __loop_delay,
3372 .const_udelay = __loop_const_udelay,
3373 .udelay = __loop_udelay,
3374diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3375index 025f742..a9e5b3b 100644
3376--- a/arch/arm/lib/uaccess_with_memcpy.c
3377+++ b/arch/arm/lib/uaccess_with_memcpy.c
3378@@ -104,7 +104,7 @@ out:
3379 }
3380
3381 unsigned long
3382-__copy_to_user(void __user *to, const void *from, unsigned long n)
3383+___copy_to_user(void __user *to, const void *from, unsigned long n)
3384 {
3385 /*
3386 * This test is stubbed out of the main function above to keep
3387@@ -155,7 +155,7 @@ out:
3388 return n;
3389 }
3390
3391-unsigned long __clear_user(void __user *addr, unsigned long n)
3392+unsigned long ___clear_user(void __user *addr, unsigned long n)
3393 {
3394 /* See rational for this in __copy_to_user() above. */
3395 if (n < 64)
3396diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3397index 1767611..d2e7e24 100644
3398--- a/arch/arm/mach-kirkwood/common.c
3399+++ b/arch/arm/mach-kirkwood/common.c
3400@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3401 clk_gate_ops.disable(hw);
3402 }
3403
3404-static struct clk_ops clk_gate_fn_ops;
3405+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3406+{
3407+ return clk_gate_ops.is_enabled(hw);
3408+}
3409+
3410+static struct clk_ops clk_gate_fn_ops = {
3411+ .enable = clk_gate_fn_enable,
3412+ .disable = clk_gate_fn_disable,
3413+ .is_enabled = clk_gate_fn_is_enabled,
3414+};
3415
3416 static struct clk __init *clk_register_gate_fn(struct device *dev,
3417 const char *name,
3418@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3419 gate_fn->fn_en = fn_en;
3420 gate_fn->fn_dis = fn_dis;
3421
3422- /* ops is the gate ops, but with our enable/disable functions */
3423- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3424- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3425- clk_gate_fn_ops = clk_gate_ops;
3426- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3427- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3428- }
3429-
3430 clk = clk_register(dev, &gate_fn->gate.hw);
3431
3432 if (IS_ERR(clk))
3433diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3434index 827d1500..2885dc6 100644
3435--- a/arch/arm/mach-omap2/board-n8x0.c
3436+++ b/arch/arm/mach-omap2/board-n8x0.c
3437@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3438 }
3439 #endif
3440
3441-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3442+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3443 .late_init = n8x0_menelaus_late_init,
3444 };
3445
3446diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3447index 579697a..1d5a3b2 100644
3448--- a/arch/arm/mach-omap2/gpmc.c
3449+++ b/arch/arm/mach-omap2/gpmc.c
3450@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3451 };
3452
3453 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3454-static struct irq_chip gpmc_irq_chip;
3455 static int gpmc_irq_start;
3456
3457 static struct resource gpmc_mem_root;
3458@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3459
3460 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3461
3462+static struct irq_chip gpmc_irq_chip = {
3463+ .name = "gpmc",
3464+ .irq_startup = gpmc_irq_noop_ret,
3465+ .irq_enable = gpmc_irq_enable,
3466+ .irq_disable = gpmc_irq_disable,
3467+ .irq_shutdown = gpmc_irq_noop,
3468+ .irq_ack = gpmc_irq_noop,
3469+ .irq_mask = gpmc_irq_noop,
3470+ .irq_unmask = gpmc_irq_noop,
3471+
3472+};
3473+
3474 static int gpmc_setup_irq(void)
3475 {
3476 int i;
3477@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3478 return gpmc_irq_start;
3479 }
3480
3481- gpmc_irq_chip.name = "gpmc";
3482- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3483- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3484- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3485- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3486- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3487- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3488- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3489-
3490 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3491 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3492
3493diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3494index f991016..145ebeb 100644
3495--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3496+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3497@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3498 int (*finish_suspend)(unsigned long cpu_state);
3499 void (*resume)(void);
3500 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3501-};
3502+} __no_const;
3503
3504 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3505 static struct powerdomain *mpuss_pd;
3506@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3507 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3508 {}
3509
3510-struct cpu_pm_ops omap_pm_ops = {
3511+static struct cpu_pm_ops omap_pm_ops __read_only = {
3512 .finish_suspend = default_finish_suspend,
3513 .resume = dummy_cpu_resume,
3514 .scu_prepare = dummy_scu_prepare,
3515diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3516index 813c615..ce467c6 100644
3517--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3518+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3519@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3520 return NOTIFY_OK;
3521 }
3522
3523-static struct notifier_block __refdata irq_hotplug_notifier = {
3524+static struct notifier_block irq_hotplug_notifier = {
3525 .notifier_call = irq_cpu_hotplug_notify,
3526 };
3527
3528diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3529index b69dd9a..70e5409 100644
3530--- a/arch/arm/mach-omap2/omap_device.c
3531+++ b/arch/arm/mach-omap2/omap_device.c
3532@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3533 struct platform_device __init *omap_device_build(const char *pdev_name,
3534 int pdev_id,
3535 struct omap_hwmod *oh,
3536- void *pdata, int pdata_len)
3537+ const void *pdata, int pdata_len)
3538 {
3539 struct omap_hwmod *ohs[] = { oh };
3540
3541@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3542 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3543 int pdev_id,
3544 struct omap_hwmod **ohs,
3545- int oh_cnt, void *pdata,
3546+ int oh_cnt, const void *pdata,
3547 int pdata_len)
3548 {
3549 int ret = -ENOMEM;
3550diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3551index 17ca1ae..beba869 100644
3552--- a/arch/arm/mach-omap2/omap_device.h
3553+++ b/arch/arm/mach-omap2/omap_device.h
3554@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3555 /* Core code interface */
3556
3557 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3558- struct omap_hwmod *oh, void *pdata,
3559+ struct omap_hwmod *oh, const void *pdata,
3560 int pdata_len);
3561
3562 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3563 struct omap_hwmod **oh, int oh_cnt,
3564- void *pdata, int pdata_len);
3565+ const void *pdata, int pdata_len);
3566
3567 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3568 struct omap_hwmod **ohs, int oh_cnt);
3569diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3570index 3d5db8c..ddfa144 100644
3571--- a/arch/arm/mach-omap2/omap_hwmod.c
3572+++ b/arch/arm/mach-omap2/omap_hwmod.c
3573@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3574 int (*init_clkdm)(struct omap_hwmod *oh);
3575 void (*update_context_lost)(struct omap_hwmod *oh);
3576 int (*get_context_lost)(struct omap_hwmod *oh);
3577-};
3578+} __no_const;
3579
3580 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3581-static struct omap_hwmod_soc_ops soc_ops;
3582+static struct omap_hwmod_soc_ops soc_ops __read_only;
3583
3584 /* omap_hwmod_list contains all registered struct omap_hwmods */
3585 static LIST_HEAD(omap_hwmod_list);
3586diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3587index d15c7bb..b2d1f0c 100644
3588--- a/arch/arm/mach-omap2/wd_timer.c
3589+++ b/arch/arm/mach-omap2/wd_timer.c
3590@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3591 struct omap_hwmod *oh;
3592 char *oh_name = "wd_timer2";
3593 char *dev_name = "omap_wdt";
3594- struct omap_wd_timer_platform_data pdata;
3595+ static struct omap_wd_timer_platform_data pdata = {
3596+ .read_reset_sources = prm_read_reset_sources
3597+ };
3598
3599 if (!cpu_class_is_omap2() || of_have_populated_dt())
3600 return 0;
3601@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3602 return -EINVAL;
3603 }
3604
3605- pdata.read_reset_sources = prm_read_reset_sources;
3606-
3607 pdev = omap_device_build(dev_name, id, oh, &pdata,
3608 sizeof(struct omap_wd_timer_platform_data));
3609 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3610diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3611index b82dcae..44ee5b6 100644
3612--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3613+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3614@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3615 bool entered_lp2 = false;
3616
3617 if (tegra_pending_sgi())
3618- ACCESS_ONCE(abort_flag) = true;
3619+ ACCESS_ONCE_RW(abort_flag) = true;
3620
3621 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3622
3623diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3624index 656324a..0beba28 100644
3625--- a/arch/arm/mach-ux500/setup.h
3626+++ b/arch/arm/mach-ux500/setup.h
3627@@ -40,13 +40,6 @@ extern void ux500_timer_init(void);
3628 .type = MT_DEVICE, \
3629 }
3630
3631-#define __MEM_DEV_DESC(x, sz) { \
3632- .virtual = IO_ADDRESS(x), \
3633- .pfn = __phys_to_pfn(x), \
3634- .length = sz, \
3635- .type = MT_MEMORY, \
3636-}
3637-
3638 extern struct smp_operations ux500_smp_ops;
3639 extern void ux500_cpu_die(unsigned int cpu);
3640
3641diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3642index cd2c88e..4dd9b67 100644
3643--- a/arch/arm/mm/Kconfig
3644+++ b/arch/arm/mm/Kconfig
3645@@ -446,7 +446,7 @@ config CPU_32v5
3646
3647 config CPU_32v6
3648 bool
3649- select CPU_USE_DOMAINS if CPU_V6 && MMU
3650+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3651 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3652
3653 config CPU_32v6K
3654@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3655
3656 config CPU_USE_DOMAINS
3657 bool
3658+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3659 help
3660 This option enables or disables the use of domain switching
3661 via the set_fs() function.
3662@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3663 config KUSER_HELPERS
3664 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3665 default y
3666+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3667 help
3668 Warning: disabling this option may break user programs.
3669
3670@@ -812,7 +814,7 @@ config KUSER_HELPERS
3671 See Documentation/arm/kernel_user_helpers.txt for details.
3672
3673 However, the fixed address nature of these helpers can be used
3674- by ROP (return orientated programming) authors when creating
3675+ by ROP (Return Oriented Programming) authors when creating
3676 exploits.
3677
3678 If all of the binaries and libraries which run on your platform
3679diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3680index 6f4585b..7b6f52b 100644
3681--- a/arch/arm/mm/alignment.c
3682+++ b/arch/arm/mm/alignment.c
3683@@ -211,10 +211,12 @@ union offset_union {
3684 #define __get16_unaligned_check(ins,val,addr) \
3685 do { \
3686 unsigned int err = 0, v, a = addr; \
3687+ pax_open_userland(); \
3688 __get8_unaligned_check(ins,v,a,err); \
3689 val = v << ((BE) ? 8 : 0); \
3690 __get8_unaligned_check(ins,v,a,err); \
3691 val |= v << ((BE) ? 0 : 8); \
3692+ pax_close_userland(); \
3693 if (err) \
3694 goto fault; \
3695 } while (0)
3696@@ -228,6 +230,7 @@ union offset_union {
3697 #define __get32_unaligned_check(ins,val,addr) \
3698 do { \
3699 unsigned int err = 0, v, a = addr; \
3700+ pax_open_userland(); \
3701 __get8_unaligned_check(ins,v,a,err); \
3702 val = v << ((BE) ? 24 : 0); \
3703 __get8_unaligned_check(ins,v,a,err); \
3704@@ -236,6 +239,7 @@ union offset_union {
3705 val |= v << ((BE) ? 8 : 16); \
3706 __get8_unaligned_check(ins,v,a,err); \
3707 val |= v << ((BE) ? 0 : 24); \
3708+ pax_close_userland(); \
3709 if (err) \
3710 goto fault; \
3711 } while (0)
3712@@ -249,6 +253,7 @@ union offset_union {
3713 #define __put16_unaligned_check(ins,val,addr) \
3714 do { \
3715 unsigned int err = 0, v = val, a = addr; \
3716+ pax_open_userland(); \
3717 __asm__( FIRST_BYTE_16 \
3718 ARM( "1: "ins" %1, [%2], #1\n" ) \
3719 THUMB( "1: "ins" %1, [%2]\n" ) \
3720@@ -268,6 +273,7 @@ union offset_union {
3721 " .popsection\n" \
3722 : "=r" (err), "=&r" (v), "=&r" (a) \
3723 : "0" (err), "1" (v), "2" (a)); \
3724+ pax_close_userland(); \
3725 if (err) \
3726 goto fault; \
3727 } while (0)
3728@@ -281,6 +287,7 @@ union offset_union {
3729 #define __put32_unaligned_check(ins,val,addr) \
3730 do { \
3731 unsigned int err = 0, v = val, a = addr; \
3732+ pax_open_userland(); \
3733 __asm__( FIRST_BYTE_32 \
3734 ARM( "1: "ins" %1, [%2], #1\n" ) \
3735 THUMB( "1: "ins" %1, [%2]\n" ) \
3736@@ -310,6 +317,7 @@ union offset_union {
3737 " .popsection\n" \
3738 : "=r" (err), "=&r" (v), "=&r" (a) \
3739 : "0" (err), "1" (v), "2" (a)); \
3740+ pax_close_userland(); \
3741 if (err) \
3742 goto fault; \
3743 } while (0)
3744diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3745index 84e6f77..0b52f31 100644
3746--- a/arch/arm/mm/context.c
3747+++ b/arch/arm/mm/context.c
3748@@ -43,7 +43,7 @@
3749 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3750
3751 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3752-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3753+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3754 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3755
3756 static DEFINE_PER_CPU(atomic64_t, active_asids);
3757@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3758 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3759 {
3760 u64 asid = atomic64_read(&mm->context.id);
3761- u64 generation = atomic64_read(&asid_generation);
3762+ u64 generation = atomic64_read_unchecked(&asid_generation);
3763
3764 if (asid != 0 && is_reserved_asid(asid)) {
3765 /*
3766@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3767 */
3768 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3769 if (asid == NUM_USER_ASIDS) {
3770- generation = atomic64_add_return(ASID_FIRST_VERSION,
3771+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3772 &asid_generation);
3773 flush_context(cpu);
3774 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3775@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3776 cpu_set_reserved_ttbr0();
3777
3778 asid = atomic64_read(&mm->context.id);
3779- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3780+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3781 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3782 goto switch_mm_fastpath;
3783
3784 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3785 /* Check that our ASID belongs to the current generation. */
3786 asid = atomic64_read(&mm->context.id);
3787- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3788+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3789 asid = new_context(mm, cpu);
3790 atomic64_set(&mm->context.id, asid);
3791 }
3792diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3793index eb8830a..5360ce7 100644
3794--- a/arch/arm/mm/fault.c
3795+++ b/arch/arm/mm/fault.c
3796@@ -25,6 +25,7 @@
3797 #include <asm/system_misc.h>
3798 #include <asm/system_info.h>
3799 #include <asm/tlbflush.h>
3800+#include <asm/sections.h>
3801
3802 #include "fault.h"
3803
3804@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3805 if (fixup_exception(regs))
3806 return;
3807
3808+#ifdef CONFIG_PAX_MEMORY_UDEREF
3809+ if (addr < TASK_SIZE) {
3810+ if (current->signal->curr_ip)
3811+ 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),
3812+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3813+ else
3814+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3815+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3816+ }
3817+#endif
3818+
3819+#ifdef CONFIG_PAX_KERNEXEC
3820+ if ((fsr & FSR_WRITE) &&
3821+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3822+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3823+ {
3824+ if (current->signal->curr_ip)
3825+ 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),
3826+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3827+ else
3828+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3829+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3830+ }
3831+#endif
3832+
3833 /*
3834 * No handler, we'll have to terminate things with extreme prejudice.
3835 */
3836@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3837 }
3838 #endif
3839
3840+#ifdef CONFIG_PAX_PAGEEXEC
3841+ if (fsr & FSR_LNX_PF) {
3842+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3843+ do_group_exit(SIGKILL);
3844+ }
3845+#endif
3846+
3847 tsk->thread.address = addr;
3848 tsk->thread.error_code = fsr;
3849 tsk->thread.trap_no = 14;
3850@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3851 }
3852 #endif /* CONFIG_MMU */
3853
3854+#ifdef CONFIG_PAX_PAGEEXEC
3855+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3856+{
3857+ long i;
3858+
3859+ printk(KERN_ERR "PAX: bytes at PC: ");
3860+ for (i = 0; i < 20; i++) {
3861+ unsigned char c;
3862+ if (get_user(c, (__force unsigned char __user *)pc+i))
3863+ printk(KERN_CONT "?? ");
3864+ else
3865+ printk(KERN_CONT "%02x ", c);
3866+ }
3867+ printk("\n");
3868+
3869+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3870+ for (i = -1; i < 20; i++) {
3871+ unsigned long c;
3872+ if (get_user(c, (__force unsigned long __user *)sp+i))
3873+ printk(KERN_CONT "???????? ");
3874+ else
3875+ printk(KERN_CONT "%08lx ", c);
3876+ }
3877+ printk("\n");
3878+}
3879+#endif
3880+
3881 /*
3882 * First Level Translation Fault Handler
3883 *
3884@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3885 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3886 struct siginfo info;
3887
3888+#ifdef CONFIG_PAX_MEMORY_UDEREF
3889+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3890+ if (current->signal->curr_ip)
3891+ 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),
3892+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3893+ else
3894+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3895+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3896+ goto die;
3897+ }
3898+#endif
3899+
3900 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3901 return;
3902
3903+die:
3904 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3905 inf->name, fsr, addr);
3906
3907@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3908 ifsr_info[nr].name = name;
3909 }
3910
3911+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3912+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3913+
3914 asmlinkage void __exception
3915 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3916 {
3917 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3918 struct siginfo info;
3919+ unsigned long pc = instruction_pointer(regs);
3920+
3921+ if (user_mode(regs)) {
3922+ unsigned long sigpage = current->mm->context.sigpage;
3923+
3924+ if (sigpage <= pc && pc < sigpage + 7*4) {
3925+ if (pc < sigpage + 3*4)
3926+ sys_sigreturn(regs);
3927+ else
3928+ sys_rt_sigreturn(regs);
3929+ return;
3930+ }
3931+ if (pc == 0xffff0f60UL) {
3932+ /*
3933+ * PaX: __kuser_cmpxchg64 emulation
3934+ */
3935+ // TODO
3936+ //regs->ARM_pc = regs->ARM_lr;
3937+ //return;
3938+ }
3939+ if (pc == 0xffff0fa0UL) {
3940+ /*
3941+ * PaX: __kuser_memory_barrier emulation
3942+ */
3943+ // dmb(); implied by the exception
3944+ regs->ARM_pc = regs->ARM_lr;
3945+ return;
3946+ }
3947+ if (pc == 0xffff0fc0UL) {
3948+ /*
3949+ * PaX: __kuser_cmpxchg emulation
3950+ */
3951+ // TODO
3952+ //long new;
3953+ //int op;
3954+
3955+ //op = FUTEX_OP_SET << 28;
3956+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3957+ //regs->ARM_r0 = old != new;
3958+ //regs->ARM_pc = regs->ARM_lr;
3959+ //return;
3960+ }
3961+ if (pc == 0xffff0fe0UL) {
3962+ /*
3963+ * PaX: __kuser_get_tls emulation
3964+ */
3965+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3966+ regs->ARM_pc = regs->ARM_lr;
3967+ return;
3968+ }
3969+ }
3970+
3971+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3972+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3973+ if (current->signal->curr_ip)
3974+ 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),
3975+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3976+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3977+ else
3978+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3979+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3980+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3981+ goto die;
3982+ }
3983+#endif
3984+
3985+#ifdef CONFIG_PAX_REFCOUNT
3986+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3987+ unsigned int bkpt;
3988+
3989+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3990+ current->thread.error_code = ifsr;
3991+ current->thread.trap_no = 0;
3992+ pax_report_refcount_overflow(regs);
3993+ fixup_exception(regs);
3994+ return;
3995+ }
3996+ }
3997+#endif
3998
3999 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4000 return;
4001
4002+die:
4003 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4004 inf->name, ifsr, addr);
4005
4006diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4007index cf08bdf..772656c 100644
4008--- a/arch/arm/mm/fault.h
4009+++ b/arch/arm/mm/fault.h
4010@@ -3,6 +3,7 @@
4011
4012 /*
4013 * Fault status register encodings. We steal bit 31 for our own purposes.
4014+ * Set when the FSR value is from an instruction fault.
4015 */
4016 #define FSR_LNX_PF (1 << 31)
4017 #define FSR_WRITE (1 << 11)
4018@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4019 }
4020 #endif
4021
4022+/* valid for LPAE and !LPAE */
4023+static inline int is_xn_fault(unsigned int fsr)
4024+{
4025+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4026+}
4027+
4028+static inline int is_domain_fault(unsigned int fsr)
4029+{
4030+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4031+}
4032+
4033 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4034 unsigned long search_exception_table(unsigned long addr);
4035
4036diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4037index 18ec4c5..479bb6a 100644
4038--- a/arch/arm/mm/init.c
4039+++ b/arch/arm/mm/init.c
4040@@ -30,6 +30,8 @@
4041 #include <asm/setup.h>
4042 #include <asm/tlb.h>
4043 #include <asm/fixmap.h>
4044+#include <asm/system_info.h>
4045+#include <asm/cp15.h>
4046
4047 #include <asm/mach/arch.h>
4048 #include <asm/mach/map.h>
4049@@ -684,7 +686,46 @@ void free_initmem(void)
4050 {
4051 #ifdef CONFIG_HAVE_TCM
4052 extern char __tcm_start, __tcm_end;
4053+#endif
4054
4055+#ifdef CONFIG_PAX_KERNEXEC
4056+ unsigned long addr;
4057+ pgd_t *pgd;
4058+ pud_t *pud;
4059+ pmd_t *pmd;
4060+ int cpu_arch = cpu_architecture();
4061+ unsigned int cr = get_cr();
4062+
4063+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4064+ /* make pages tables, etc before .text NX */
4065+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4066+ pgd = pgd_offset_k(addr);
4067+ pud = pud_offset(pgd, addr);
4068+ pmd = pmd_offset(pud, addr);
4069+ __section_update(pmd, addr, PMD_SECT_XN);
4070+ }
4071+ /* make init NX */
4072+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4073+ pgd = pgd_offset_k(addr);
4074+ pud = pud_offset(pgd, addr);
4075+ pmd = pmd_offset(pud, addr);
4076+ __section_update(pmd, addr, PMD_SECT_XN);
4077+ }
4078+ /* make kernel code/rodata RX */
4079+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4080+ pgd = pgd_offset_k(addr);
4081+ pud = pud_offset(pgd, addr);
4082+ pmd = pmd_offset(pud, addr);
4083+#ifdef CONFIG_ARM_LPAE
4084+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4085+#else
4086+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4087+#endif
4088+ }
4089+ }
4090+#endif
4091+
4092+#ifdef CONFIG_HAVE_TCM
4093 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4094 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4095 #endif
4096diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4097index f123d6e..04bf569 100644
4098--- a/arch/arm/mm/ioremap.c
4099+++ b/arch/arm/mm/ioremap.c
4100@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4101 unsigned int mtype;
4102
4103 if (cached)
4104- mtype = MT_MEMORY;
4105+ mtype = MT_MEMORY_RX;
4106 else
4107- mtype = MT_MEMORY_NONCACHED;
4108+ mtype = MT_MEMORY_NONCACHED_RX;
4109
4110 return __arm_ioremap_caller(phys_addr, size, mtype,
4111 __builtin_return_address(0));
4112diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4113index 0c63562..7128a90 100644
4114--- a/arch/arm/mm/mmap.c
4115+++ b/arch/arm/mm/mmap.c
4116@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4117 struct vm_area_struct *vma;
4118 int do_align = 0;
4119 int aliasing = cache_is_vipt_aliasing();
4120+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4121 struct vm_unmapped_area_info info;
4122
4123 /*
4124@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4125 if (len > TASK_SIZE)
4126 return -ENOMEM;
4127
4128+#ifdef CONFIG_PAX_RANDMMAP
4129+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4130+#endif
4131+
4132 if (addr) {
4133 if (do_align)
4134 addr = COLOUR_ALIGN(addr, pgoff);
4135@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4136 addr = PAGE_ALIGN(addr);
4137
4138 vma = find_vma(mm, addr);
4139- if (TASK_SIZE - len >= addr &&
4140- (!vma || addr + len <= vma->vm_start))
4141+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4142 return addr;
4143 }
4144
4145@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4146 info.high_limit = TASK_SIZE;
4147 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4148 info.align_offset = pgoff << PAGE_SHIFT;
4149+ info.threadstack_offset = offset;
4150 return vm_unmapped_area(&info);
4151 }
4152
4153@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4154 unsigned long addr = addr0;
4155 int do_align = 0;
4156 int aliasing = cache_is_vipt_aliasing();
4157+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4158 struct vm_unmapped_area_info info;
4159
4160 /*
4161@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4162 return addr;
4163 }
4164
4165+#ifdef CONFIG_PAX_RANDMMAP
4166+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4167+#endif
4168+
4169 /* requesting a specific address */
4170 if (addr) {
4171 if (do_align)
4172@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4173 else
4174 addr = PAGE_ALIGN(addr);
4175 vma = find_vma(mm, addr);
4176- if (TASK_SIZE - len >= addr &&
4177- (!vma || addr + len <= vma->vm_start))
4178+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4179 return addr;
4180 }
4181
4182@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4183 info.high_limit = mm->mmap_base;
4184 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4185 info.align_offset = pgoff << PAGE_SHIFT;
4186+ info.threadstack_offset = offset;
4187 addr = vm_unmapped_area(&info);
4188
4189 /*
4190@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4191 {
4192 unsigned long random_factor = 0UL;
4193
4194+#ifdef CONFIG_PAX_RANDMMAP
4195+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4196+#endif
4197+
4198 /* 8 bits of randomness in 20 address space bits */
4199 if ((current->flags & PF_RANDOMIZE) &&
4200 !(current->personality & ADDR_NO_RANDOMIZE))
4201@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4202
4203 if (mmap_is_legacy()) {
4204 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4205+
4206+#ifdef CONFIG_PAX_RANDMMAP
4207+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4208+ mm->mmap_base += mm->delta_mmap;
4209+#endif
4210+
4211 mm->get_unmapped_area = arch_get_unmapped_area;
4212 } else {
4213 mm->mmap_base = mmap_base(random_factor);
4214+
4215+#ifdef CONFIG_PAX_RANDMMAP
4216+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4217+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4218+#endif
4219+
4220 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4221 }
4222 }
4223diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4224index b1d17ee..7a6f4d3 100644
4225--- a/arch/arm/mm/mmu.c
4226+++ b/arch/arm/mm/mmu.c
4227@@ -36,6 +36,22 @@
4228 #include "mm.h"
4229 #include "tcm.h"
4230
4231+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4232+void modify_domain(unsigned int dom, unsigned int type)
4233+{
4234+ struct thread_info *thread = current_thread_info();
4235+ unsigned int domain = thread->cpu_domain;
4236+ /*
4237+ * DOMAIN_MANAGER might be defined to some other value,
4238+ * use the arch-defined constant
4239+ */
4240+ domain &= ~domain_val(dom, 3);
4241+ thread->cpu_domain = domain | domain_val(dom, type);
4242+ set_domain(thread->cpu_domain);
4243+}
4244+EXPORT_SYMBOL(modify_domain);
4245+#endif
4246+
4247 /*
4248 * empty_zero_page is a special page that is used for
4249 * zero-initialized data and COW.
4250@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4251
4252 #endif /* ifdef CONFIG_CPU_CP15 / else */
4253
4254-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4255+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4256 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4257
4258-static struct mem_type mem_types[] = {
4259+#ifdef CONFIG_PAX_KERNEXEC
4260+#define L_PTE_KERNEXEC L_PTE_RDONLY
4261+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4262+#else
4263+#define L_PTE_KERNEXEC L_PTE_DIRTY
4264+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4265+#endif
4266+
4267+static struct mem_type mem_types[] __read_only = {
4268 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4269 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4270 L_PTE_SHARED,
4271@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4272 [MT_UNCACHED] = {
4273 .prot_pte = PROT_PTE_DEVICE,
4274 .prot_l1 = PMD_TYPE_TABLE,
4275- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4276+ .prot_sect = PROT_SECT_DEVICE,
4277 .domain = DOMAIN_IO,
4278 },
4279 [MT_CACHECLEAN] = {
4280- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4281+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4282 .domain = DOMAIN_KERNEL,
4283 },
4284 #ifndef CONFIG_ARM_LPAE
4285 [MT_MINICLEAN] = {
4286- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4287+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4288 .domain = DOMAIN_KERNEL,
4289 },
4290 #endif
4291@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4292 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4293 L_PTE_RDONLY,
4294 .prot_l1 = PMD_TYPE_TABLE,
4295- .domain = DOMAIN_USER,
4296+ .domain = DOMAIN_VECTORS,
4297 },
4298 [MT_HIGH_VECTORS] = {
4299 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4300 L_PTE_USER | L_PTE_RDONLY,
4301 .prot_l1 = PMD_TYPE_TABLE,
4302- .domain = DOMAIN_USER,
4303+ .domain = DOMAIN_VECTORS,
4304 },
4305- [MT_MEMORY] = {
4306+ [MT_MEMORY_RWX] = {
4307 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4308 .prot_l1 = PMD_TYPE_TABLE,
4309 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4310 .domain = DOMAIN_KERNEL,
4311 },
4312+ [MT_MEMORY_RW] = {
4313+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4314+ .prot_l1 = PMD_TYPE_TABLE,
4315+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4316+ .domain = DOMAIN_KERNEL,
4317+ },
4318+ [MT_MEMORY_RX] = {
4319+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4320+ .prot_l1 = PMD_TYPE_TABLE,
4321+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4322+ .domain = DOMAIN_KERNEL,
4323+ },
4324 [MT_ROM] = {
4325- .prot_sect = PMD_TYPE_SECT,
4326+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4327 .domain = DOMAIN_KERNEL,
4328 },
4329- [MT_MEMORY_NONCACHED] = {
4330+ [MT_MEMORY_NONCACHED_RW] = {
4331 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4332 L_PTE_MT_BUFFERABLE,
4333 .prot_l1 = PMD_TYPE_TABLE,
4334 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4335 .domain = DOMAIN_KERNEL,
4336 },
4337+ [MT_MEMORY_NONCACHED_RX] = {
4338+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4339+ L_PTE_MT_BUFFERABLE,
4340+ .prot_l1 = PMD_TYPE_TABLE,
4341+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4342+ .domain = DOMAIN_KERNEL,
4343+ },
4344 [MT_MEMORY_DTCM] = {
4345- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4346- L_PTE_XN,
4347+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4348 .prot_l1 = PMD_TYPE_TABLE,
4349- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4350+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4351 .domain = DOMAIN_KERNEL,
4352 },
4353 [MT_MEMORY_ITCM] = {
4354@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4355 },
4356 [MT_MEMORY_SO] = {
4357 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4358- L_PTE_MT_UNCACHED | L_PTE_XN,
4359+ L_PTE_MT_UNCACHED,
4360 .prot_l1 = PMD_TYPE_TABLE,
4361 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4362- PMD_SECT_UNCACHED | PMD_SECT_XN,
4363+ PMD_SECT_UNCACHED,
4364 .domain = DOMAIN_KERNEL,
4365 },
4366 [MT_MEMORY_DMA_READY] = {
4367@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4368 * to prevent speculative instruction fetches.
4369 */
4370 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4371+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4372 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4373+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4374 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4375+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4376 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4377+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4378+
4379+ /* Mark other regions on ARMv6+ as execute-never */
4380+
4381+#ifdef CONFIG_PAX_KERNEXEC
4382+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4383+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4384+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4385+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4386+#ifndef CONFIG_ARM_LPAE
4387+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4388+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4389+#endif
4390+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4391+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4392+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4393+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4394+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4395+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4396+#endif
4397+
4398+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4399+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4400 }
4401 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4402 /*
4403@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4404 * from SVC mode and no access from userspace.
4405 */
4406 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4407+#ifdef CONFIG_PAX_KERNEXEC
4408+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4409+#endif
4410 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4411 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4412 #endif
4413@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4414 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4415 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4416 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4417- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4418- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4419+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4420+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4421+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4422+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4423+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4424+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4425 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4426- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4427- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4428+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4429+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4430+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4431+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4432 }
4433 }
4434
4435@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4436 if (cpu_arch >= CPU_ARCH_ARMv6) {
4437 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4438 /* Non-cacheable Normal is XCB = 001 */
4439- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4440+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4441+ PMD_SECT_BUFFERED;
4442+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4443 PMD_SECT_BUFFERED;
4444 } else {
4445 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4446- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4447+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4448+ PMD_SECT_TEX(1);
4449+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4450 PMD_SECT_TEX(1);
4451 }
4452 } else {
4453- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4454+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4455+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4456 }
4457
4458 #ifdef CONFIG_ARM_LPAE
4459@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4460 vecs_pgprot |= PTE_EXT_AF;
4461 #endif
4462
4463+ user_pgprot |= __supported_pte_mask;
4464+
4465 for (i = 0; i < 16; i++) {
4466 pteval_t v = pgprot_val(protection_map[i]);
4467 protection_map[i] = __pgprot(v | user_pgprot);
4468@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4469
4470 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4471 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4472- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4473- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4474+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4475+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4476+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4477+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4478+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4479+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4480 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4481- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4482+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4483+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4484 mem_types[MT_ROM].prot_sect |= cp->pmd;
4485
4486 switch (cp->pmd) {
4487@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4488 * called function. This means you can't use any function or debugging
4489 * method which may touch any device, otherwise the kernel _will_ crash.
4490 */
4491+
4492+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4493+
4494 static void __init devicemaps_init(const struct machine_desc *mdesc)
4495 {
4496 struct map_desc map;
4497 unsigned long addr;
4498- void *vectors;
4499
4500- /*
4501- * Allocate the vector page early.
4502- */
4503- vectors = early_alloc(PAGE_SIZE * 2);
4504-
4505- early_trap_init(vectors);
4506+ early_trap_init(&vectors);
4507
4508 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4509 pmd_clear(pmd_off_k(addr));
4510@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4511 * location (0xffff0000). If we aren't using high-vectors, also
4512 * create a mapping at the low-vectors virtual address.
4513 */
4514- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4515+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4516 map.virtual = 0xffff0000;
4517 map.length = PAGE_SIZE;
4518 #ifdef CONFIG_KUSER_HELPERS
4519@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4520 map.pfn = __phys_to_pfn(start);
4521 map.virtual = __phys_to_virt(start);
4522 map.length = end - start;
4523- map.type = MT_MEMORY;
4524
4525+#ifdef CONFIG_PAX_KERNEXEC
4526+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4527+ struct map_desc kernel;
4528+ struct map_desc initmap;
4529+
4530+ /* when freeing initmem we will make this RW */
4531+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4532+ initmap.virtual = (unsigned long)__init_begin;
4533+ initmap.length = _sdata - __init_begin;
4534+ initmap.type = MT_MEMORY_RWX;
4535+ create_mapping(&initmap);
4536+
4537+ /* when freeing initmem we will make this RX */
4538+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4539+ kernel.virtual = (unsigned long)_stext;
4540+ kernel.length = __init_begin - _stext;
4541+ kernel.type = MT_MEMORY_RWX;
4542+ create_mapping(&kernel);
4543+
4544+ if (map.virtual < (unsigned long)_stext) {
4545+ map.length = (unsigned long)_stext - map.virtual;
4546+ map.type = MT_MEMORY_RWX;
4547+ create_mapping(&map);
4548+ }
4549+
4550+ map.pfn = __phys_to_pfn(__pa(_sdata));
4551+ map.virtual = (unsigned long)_sdata;
4552+ map.length = end - __pa(_sdata);
4553+ }
4554+#endif
4555+
4556+ map.type = MT_MEMORY_RW;
4557 create_mapping(&map);
4558 }
4559 }
4560diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4561index a5bc92d..0bb4730 100644
4562--- a/arch/arm/plat-omap/sram.c
4563+++ b/arch/arm/plat-omap/sram.c
4564@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4565 * Looks like we need to preserve some bootloader code at the
4566 * beginning of SRAM for jumping to flash for reboot to work...
4567 */
4568+ pax_open_kernel();
4569 memset_io(omap_sram_base + omap_sram_skip, 0,
4570 omap_sram_size - omap_sram_skip);
4571+ pax_close_kernel();
4572 }
4573diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4574index ce6d763..cfea917 100644
4575--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4576+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4577@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4578 int (*started)(unsigned ch);
4579 int (*flush)(unsigned ch);
4580 int (*stop)(unsigned ch);
4581-};
4582+} __no_const;
4583
4584 extern void *samsung_dmadev_get_ops(void);
4585 extern void *s3c_dma_get_ops(void);
4586diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4587index c3a58a1..78fbf54 100644
4588--- a/arch/avr32/include/asm/cache.h
4589+++ b/arch/avr32/include/asm/cache.h
4590@@ -1,8 +1,10 @@
4591 #ifndef __ASM_AVR32_CACHE_H
4592 #define __ASM_AVR32_CACHE_H
4593
4594+#include <linux/const.h>
4595+
4596 #define L1_CACHE_SHIFT 5
4597-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4598+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4599
4600 /*
4601 * Memory returned by kmalloc() may be used for DMA, so we must make
4602diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4603index d232888..87c8df1 100644
4604--- a/arch/avr32/include/asm/elf.h
4605+++ b/arch/avr32/include/asm/elf.h
4606@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4607 the loader. We need to make sure that it is out of the way of the program
4608 that it will "exec", and that there is sufficient room for the brk. */
4609
4610-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4611+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4612
4613+#ifdef CONFIG_PAX_ASLR
4614+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4615+
4616+#define PAX_DELTA_MMAP_LEN 15
4617+#define PAX_DELTA_STACK_LEN 15
4618+#endif
4619
4620 /* This yields a mask that user programs can use to figure out what
4621 instruction set this CPU supports. This could be done in user space,
4622diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4623index 479330b..53717a8 100644
4624--- a/arch/avr32/include/asm/kmap_types.h
4625+++ b/arch/avr32/include/asm/kmap_types.h
4626@@ -2,9 +2,9 @@
4627 #define __ASM_AVR32_KMAP_TYPES_H
4628
4629 #ifdef CONFIG_DEBUG_HIGHMEM
4630-# define KM_TYPE_NR 29
4631+# define KM_TYPE_NR 30
4632 #else
4633-# define KM_TYPE_NR 14
4634+# define KM_TYPE_NR 15
4635 #endif
4636
4637 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4638diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4639index 0eca933..eb78c7b 100644
4640--- a/arch/avr32/mm/fault.c
4641+++ b/arch/avr32/mm/fault.c
4642@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4643
4644 int exception_trace = 1;
4645
4646+#ifdef CONFIG_PAX_PAGEEXEC
4647+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4648+{
4649+ unsigned long i;
4650+
4651+ printk(KERN_ERR "PAX: bytes at PC: ");
4652+ for (i = 0; i < 20; i++) {
4653+ unsigned char c;
4654+ if (get_user(c, (unsigned char *)pc+i))
4655+ printk(KERN_CONT "???????? ");
4656+ else
4657+ printk(KERN_CONT "%02x ", c);
4658+ }
4659+ printk("\n");
4660+}
4661+#endif
4662+
4663 /*
4664 * This routine handles page faults. It determines the address and the
4665 * problem, and then passes it off to one of the appropriate routines.
4666@@ -176,6 +193,16 @@ bad_area:
4667 up_read(&mm->mmap_sem);
4668
4669 if (user_mode(regs)) {
4670+
4671+#ifdef CONFIG_PAX_PAGEEXEC
4672+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4673+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4674+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4675+ do_group_exit(SIGKILL);
4676+ }
4677+ }
4678+#endif
4679+
4680 if (exception_trace && printk_ratelimit())
4681 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4682 "sp %08lx ecr %lu\n",
4683diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4684index 568885a..f8008df 100644
4685--- a/arch/blackfin/include/asm/cache.h
4686+++ b/arch/blackfin/include/asm/cache.h
4687@@ -7,6 +7,7 @@
4688 #ifndef __ARCH_BLACKFIN_CACHE_H
4689 #define __ARCH_BLACKFIN_CACHE_H
4690
4691+#include <linux/const.h>
4692 #include <linux/linkage.h> /* for asmlinkage */
4693
4694 /*
4695@@ -14,7 +15,7 @@
4696 * Blackfin loads 32 bytes for cache
4697 */
4698 #define L1_CACHE_SHIFT 5
4699-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4700+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4701 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4702
4703 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4704diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4705index aea2718..3639a60 100644
4706--- a/arch/cris/include/arch-v10/arch/cache.h
4707+++ b/arch/cris/include/arch-v10/arch/cache.h
4708@@ -1,8 +1,9 @@
4709 #ifndef _ASM_ARCH_CACHE_H
4710 #define _ASM_ARCH_CACHE_H
4711
4712+#include <linux/const.h>
4713 /* Etrax 100LX have 32-byte cache-lines. */
4714-#define L1_CACHE_BYTES 32
4715 #define L1_CACHE_SHIFT 5
4716+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4717
4718 #endif /* _ASM_ARCH_CACHE_H */
4719diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4720index 7caf25d..ee65ac5 100644
4721--- a/arch/cris/include/arch-v32/arch/cache.h
4722+++ b/arch/cris/include/arch-v32/arch/cache.h
4723@@ -1,11 +1,12 @@
4724 #ifndef _ASM_CRIS_ARCH_CACHE_H
4725 #define _ASM_CRIS_ARCH_CACHE_H
4726
4727+#include <linux/const.h>
4728 #include <arch/hwregs/dma.h>
4729
4730 /* A cache-line is 32 bytes. */
4731-#define L1_CACHE_BYTES 32
4732 #define L1_CACHE_SHIFT 5
4733+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4734
4735 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4736
4737diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4738index b86329d..6709906 100644
4739--- a/arch/frv/include/asm/atomic.h
4740+++ b/arch/frv/include/asm/atomic.h
4741@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4742 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4743 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4744
4745+#define atomic64_read_unchecked(v) atomic64_read(v)
4746+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4747+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4748+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4749+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4750+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4751+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4752+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4753+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4754+
4755 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4756 {
4757 int c, old;
4758diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4759index 2797163..c2a401d 100644
4760--- a/arch/frv/include/asm/cache.h
4761+++ b/arch/frv/include/asm/cache.h
4762@@ -12,10 +12,11 @@
4763 #ifndef __ASM_CACHE_H
4764 #define __ASM_CACHE_H
4765
4766+#include <linux/const.h>
4767
4768 /* bytes per L1 cache line */
4769 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4770-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4771+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4772
4773 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4774 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4775diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4776index 43901f2..0d8b865 100644
4777--- a/arch/frv/include/asm/kmap_types.h
4778+++ b/arch/frv/include/asm/kmap_types.h
4779@@ -2,6 +2,6 @@
4780 #ifndef _ASM_KMAP_TYPES_H
4781 #define _ASM_KMAP_TYPES_H
4782
4783-#define KM_TYPE_NR 17
4784+#define KM_TYPE_NR 18
4785
4786 #endif
4787diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4788index 836f147..4cf23f5 100644
4789--- a/arch/frv/mm/elf-fdpic.c
4790+++ b/arch/frv/mm/elf-fdpic.c
4791@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4792 {
4793 struct vm_area_struct *vma;
4794 struct vm_unmapped_area_info info;
4795+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4796
4797 if (len > TASK_SIZE)
4798 return -ENOMEM;
4799@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4800 if (addr) {
4801 addr = PAGE_ALIGN(addr);
4802 vma = find_vma(current->mm, addr);
4803- if (TASK_SIZE - len >= addr &&
4804- (!vma || addr + len <= vma->vm_start))
4805+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4806 goto success;
4807 }
4808
4809@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4810 info.high_limit = (current->mm->start_stack - 0x00200000);
4811 info.align_mask = 0;
4812 info.align_offset = 0;
4813+ info.threadstack_offset = offset;
4814 addr = vm_unmapped_area(&info);
4815 if (!(addr & ~PAGE_MASK))
4816 goto success;
4817diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4818index f4ca594..adc72fd6 100644
4819--- a/arch/hexagon/include/asm/cache.h
4820+++ b/arch/hexagon/include/asm/cache.h
4821@@ -21,9 +21,11 @@
4822 #ifndef __ASM_CACHE_H
4823 #define __ASM_CACHE_H
4824
4825+#include <linux/const.h>
4826+
4827 /* Bytes per L1 cache line */
4828-#define L1_CACHE_SHIFT (5)
4829-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4830+#define L1_CACHE_SHIFT 5
4831+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4832
4833 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4834 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4835diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4836index 7740ab1..17fa8c5 100644
4837--- a/arch/ia64/Kconfig
4838+++ b/arch/ia64/Kconfig
4839@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4840 config KEXEC
4841 bool "kexec system call"
4842 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4843+ depends on !GRKERNSEC_KMEM
4844 help
4845 kexec is a system call that implements the ability to shutdown your
4846 current kernel, and to start another kernel. It is like a reboot
4847diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4848index 6e6fe18..a6ae668 100644
4849--- a/arch/ia64/include/asm/atomic.h
4850+++ b/arch/ia64/include/asm/atomic.h
4851@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4852 #define atomic64_inc(v) atomic64_add(1, (v))
4853 #define atomic64_dec(v) atomic64_sub(1, (v))
4854
4855+#define atomic64_read_unchecked(v) atomic64_read(v)
4856+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4857+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4858+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4859+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4860+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4861+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4862+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4863+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4864+
4865 /* Atomic operations are already serializing */
4866 #define smp_mb__before_atomic_dec() barrier()
4867 #define smp_mb__after_atomic_dec() barrier()
4868diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4869index 988254a..e1ee885 100644
4870--- a/arch/ia64/include/asm/cache.h
4871+++ b/arch/ia64/include/asm/cache.h
4872@@ -1,6 +1,7 @@
4873 #ifndef _ASM_IA64_CACHE_H
4874 #define _ASM_IA64_CACHE_H
4875
4876+#include <linux/const.h>
4877
4878 /*
4879 * Copyright (C) 1998-2000 Hewlett-Packard Co
4880@@ -9,7 +10,7 @@
4881
4882 /* Bytes per L1 (data) cache line. */
4883 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4884-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4885+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4886
4887 #ifdef CONFIG_SMP
4888 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4889diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4890index 5a83c5c..4d7f553 100644
4891--- a/arch/ia64/include/asm/elf.h
4892+++ b/arch/ia64/include/asm/elf.h
4893@@ -42,6 +42,13 @@
4894 */
4895 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4896
4897+#ifdef CONFIG_PAX_ASLR
4898+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4899+
4900+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4901+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4902+#endif
4903+
4904 #define PT_IA_64_UNWIND 0x70000001
4905
4906 /* IA-64 relocations: */
4907diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4908index 96a8d92..617a1cf 100644
4909--- a/arch/ia64/include/asm/pgalloc.h
4910+++ b/arch/ia64/include/asm/pgalloc.h
4911@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4912 pgd_val(*pgd_entry) = __pa(pud);
4913 }
4914
4915+static inline void
4916+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4917+{
4918+ pgd_populate(mm, pgd_entry, pud);
4919+}
4920+
4921 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4922 {
4923 return quicklist_alloc(0, GFP_KERNEL, NULL);
4924@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4925 pud_val(*pud_entry) = __pa(pmd);
4926 }
4927
4928+static inline void
4929+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4930+{
4931+ pud_populate(mm, pud_entry, pmd);
4932+}
4933+
4934 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4935 {
4936 return quicklist_alloc(0, GFP_KERNEL, NULL);
4937diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4938index 7935115..c0eca6a 100644
4939--- a/arch/ia64/include/asm/pgtable.h
4940+++ b/arch/ia64/include/asm/pgtable.h
4941@@ -12,7 +12,7 @@
4942 * David Mosberger-Tang <davidm@hpl.hp.com>
4943 */
4944
4945-
4946+#include <linux/const.h>
4947 #include <asm/mman.h>
4948 #include <asm/page.h>
4949 #include <asm/processor.h>
4950@@ -142,6 +142,17 @@
4951 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4952 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4953 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4954+
4955+#ifdef CONFIG_PAX_PAGEEXEC
4956+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4957+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4958+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4959+#else
4960+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4961+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4962+# define PAGE_COPY_NOEXEC PAGE_COPY
4963+#endif
4964+
4965 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4966 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4967 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4968diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4969index 45698cd..e8e2dbc 100644
4970--- a/arch/ia64/include/asm/spinlock.h
4971+++ b/arch/ia64/include/asm/spinlock.h
4972@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4973 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4974
4975 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4976- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4977+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4978 }
4979
4980 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4981diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4982index 449c8c0..18965fb 100644
4983--- a/arch/ia64/include/asm/uaccess.h
4984+++ b/arch/ia64/include/asm/uaccess.h
4985@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4986 static inline unsigned long
4987 __copy_to_user (void __user *to, const void *from, unsigned long count)
4988 {
4989+ if (count > INT_MAX)
4990+ return count;
4991+
4992+ if (!__builtin_constant_p(count))
4993+ check_object_size(from, count, true);
4994+
4995 return __copy_user(to, (__force void __user *) from, count);
4996 }
4997
4998 static inline unsigned long
4999 __copy_from_user (void *to, const void __user *from, unsigned long count)
5000 {
5001+ if (count > INT_MAX)
5002+ return count;
5003+
5004+ if (!__builtin_constant_p(count))
5005+ check_object_size(to, count, false);
5006+
5007 return __copy_user((__force void __user *) to, from, count);
5008 }
5009
5010@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5011 ({ \
5012 void __user *__cu_to = (to); \
5013 const void *__cu_from = (from); \
5014- long __cu_len = (n); \
5015+ unsigned long __cu_len = (n); \
5016 \
5017- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5018+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5019+ if (!__builtin_constant_p(n)) \
5020+ check_object_size(__cu_from, __cu_len, true); \
5021 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5022+ } \
5023 __cu_len; \
5024 })
5025
5026@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5027 ({ \
5028 void *__cu_to = (to); \
5029 const void __user *__cu_from = (from); \
5030- long __cu_len = (n); \
5031+ unsigned long __cu_len = (n); \
5032 \
5033 __chk_user_ptr(__cu_from); \
5034- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5035+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5036+ if (!__builtin_constant_p(n)) \
5037+ check_object_size(__cu_to, __cu_len, false); \
5038 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5039+ } \
5040 __cu_len; \
5041 })
5042
5043diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5044index 24603be..948052d 100644
5045--- a/arch/ia64/kernel/module.c
5046+++ b/arch/ia64/kernel/module.c
5047@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5048 void
5049 module_free (struct module *mod, void *module_region)
5050 {
5051- if (mod && mod->arch.init_unw_table &&
5052- module_region == mod->module_init) {
5053+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5054 unw_remove_unwind_table(mod->arch.init_unw_table);
5055 mod->arch.init_unw_table = NULL;
5056 }
5057@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5058 }
5059
5060 static inline int
5061+in_init_rx (const struct module *mod, uint64_t addr)
5062+{
5063+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5064+}
5065+
5066+static inline int
5067+in_init_rw (const struct module *mod, uint64_t addr)
5068+{
5069+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5070+}
5071+
5072+static inline int
5073 in_init (const struct module *mod, uint64_t addr)
5074 {
5075- return addr - (uint64_t) mod->module_init < mod->init_size;
5076+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5077+}
5078+
5079+static inline int
5080+in_core_rx (const struct module *mod, uint64_t addr)
5081+{
5082+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5083+}
5084+
5085+static inline int
5086+in_core_rw (const struct module *mod, uint64_t addr)
5087+{
5088+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5089 }
5090
5091 static inline int
5092 in_core (const struct module *mod, uint64_t addr)
5093 {
5094- return addr - (uint64_t) mod->module_core < mod->core_size;
5095+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5096 }
5097
5098 static inline int
5099@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5100 break;
5101
5102 case RV_BDREL:
5103- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5104+ if (in_init_rx(mod, val))
5105+ val -= (uint64_t) mod->module_init_rx;
5106+ else if (in_init_rw(mod, val))
5107+ val -= (uint64_t) mod->module_init_rw;
5108+ else if (in_core_rx(mod, val))
5109+ val -= (uint64_t) mod->module_core_rx;
5110+ else if (in_core_rw(mod, val))
5111+ val -= (uint64_t) mod->module_core_rw;
5112 break;
5113
5114 case RV_LTV:
5115@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5116 * addresses have been selected...
5117 */
5118 uint64_t gp;
5119- if (mod->core_size > MAX_LTOFF)
5120+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5121 /*
5122 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5123 * at the end of the module.
5124 */
5125- gp = mod->core_size - MAX_LTOFF / 2;
5126+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5127 else
5128- gp = mod->core_size / 2;
5129- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5130+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5131+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5132 mod->arch.gp = gp;
5133 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5134 }
5135diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5136index ab33328..f39506c 100644
5137--- a/arch/ia64/kernel/palinfo.c
5138+++ b/arch/ia64/kernel/palinfo.c
5139@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5140 return NOTIFY_OK;
5141 }
5142
5143-static struct notifier_block __refdata palinfo_cpu_notifier =
5144+static struct notifier_block palinfo_cpu_notifier =
5145 {
5146 .notifier_call = palinfo_cpu_callback,
5147 .priority = 0,
5148diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5149index 41e33f8..65180b2 100644
5150--- a/arch/ia64/kernel/sys_ia64.c
5151+++ b/arch/ia64/kernel/sys_ia64.c
5152@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5153 unsigned long align_mask = 0;
5154 struct mm_struct *mm = current->mm;
5155 struct vm_unmapped_area_info info;
5156+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5157
5158 if (len > RGN_MAP_LIMIT)
5159 return -ENOMEM;
5160@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5161 if (REGION_NUMBER(addr) == RGN_HPAGE)
5162 addr = 0;
5163 #endif
5164+
5165+#ifdef CONFIG_PAX_RANDMMAP
5166+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5167+ addr = mm->free_area_cache;
5168+ else
5169+#endif
5170+
5171 if (!addr)
5172 addr = TASK_UNMAPPED_BASE;
5173
5174@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5175 info.high_limit = TASK_SIZE;
5176 info.align_mask = align_mask;
5177 info.align_offset = 0;
5178+ info.threadstack_offset = offset;
5179 return vm_unmapped_area(&info);
5180 }
5181
5182diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5183index 0ccb28f..8992469 100644
5184--- a/arch/ia64/kernel/vmlinux.lds.S
5185+++ b/arch/ia64/kernel/vmlinux.lds.S
5186@@ -198,7 +198,7 @@ SECTIONS {
5187 /* Per-cpu data: */
5188 . = ALIGN(PERCPU_PAGE_SIZE);
5189 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5190- __phys_per_cpu_start = __per_cpu_load;
5191+ __phys_per_cpu_start = per_cpu_load;
5192 /*
5193 * ensure percpu data fits
5194 * into percpu page size
5195diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5196index 7225dad..2a7c8256 100644
5197--- a/arch/ia64/mm/fault.c
5198+++ b/arch/ia64/mm/fault.c
5199@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5200 return pte_present(pte);
5201 }
5202
5203+#ifdef CONFIG_PAX_PAGEEXEC
5204+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5205+{
5206+ unsigned long i;
5207+
5208+ printk(KERN_ERR "PAX: bytes at PC: ");
5209+ for (i = 0; i < 8; i++) {
5210+ unsigned int c;
5211+ if (get_user(c, (unsigned int *)pc+i))
5212+ printk(KERN_CONT "???????? ");
5213+ else
5214+ printk(KERN_CONT "%08x ", c);
5215+ }
5216+ printk("\n");
5217+}
5218+#endif
5219+
5220 # define VM_READ_BIT 0
5221 # define VM_WRITE_BIT 1
5222 # define VM_EXEC_BIT 2
5223@@ -151,8 +168,21 @@ retry:
5224 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5225 goto bad_area;
5226
5227- if ((vma->vm_flags & mask) != mask)
5228+ if ((vma->vm_flags & mask) != mask) {
5229+
5230+#ifdef CONFIG_PAX_PAGEEXEC
5231+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5232+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5233+ goto bad_area;
5234+
5235+ up_read(&mm->mmap_sem);
5236+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5237+ do_group_exit(SIGKILL);
5238+ }
5239+#endif
5240+
5241 goto bad_area;
5242+ }
5243
5244 /*
5245 * If for any reason at all we couldn't handle the fault, make
5246diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5247index 68232db..6ca80af 100644
5248--- a/arch/ia64/mm/hugetlbpage.c
5249+++ b/arch/ia64/mm/hugetlbpage.c
5250@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5251 unsigned long pgoff, unsigned long flags)
5252 {
5253 struct vm_unmapped_area_info info;
5254+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5255
5256 if (len > RGN_MAP_LIMIT)
5257 return -ENOMEM;
5258@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5259 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5260 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5261 info.align_offset = 0;
5262+ info.threadstack_offset = offset;
5263 return vm_unmapped_area(&info);
5264 }
5265
5266diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5267index b6f7f43..c04320d 100644
5268--- a/arch/ia64/mm/init.c
5269+++ b/arch/ia64/mm/init.c
5270@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5271 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5272 vma->vm_end = vma->vm_start + PAGE_SIZE;
5273 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5274+
5275+#ifdef CONFIG_PAX_PAGEEXEC
5276+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5277+ vma->vm_flags &= ~VM_EXEC;
5278+
5279+#ifdef CONFIG_PAX_MPROTECT
5280+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5281+ vma->vm_flags &= ~VM_MAYEXEC;
5282+#endif
5283+
5284+ }
5285+#endif
5286+
5287 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5288 down_write(&current->mm->mmap_sem);
5289 if (insert_vm_struct(current->mm, vma)) {
5290diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5291index 40b3ee9..8c2c112 100644
5292--- a/arch/m32r/include/asm/cache.h
5293+++ b/arch/m32r/include/asm/cache.h
5294@@ -1,8 +1,10 @@
5295 #ifndef _ASM_M32R_CACHE_H
5296 #define _ASM_M32R_CACHE_H
5297
5298+#include <linux/const.h>
5299+
5300 /* L1 cache line size */
5301 #define L1_CACHE_SHIFT 4
5302-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5303+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5304
5305 #endif /* _ASM_M32R_CACHE_H */
5306diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5307index 82abd15..d95ae5d 100644
5308--- a/arch/m32r/lib/usercopy.c
5309+++ b/arch/m32r/lib/usercopy.c
5310@@ -14,6 +14,9 @@
5311 unsigned long
5312 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5313 {
5314+ if ((long)n < 0)
5315+ return n;
5316+
5317 prefetch(from);
5318 if (access_ok(VERIFY_WRITE, to, n))
5319 __copy_user(to,from,n);
5320@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5321 unsigned long
5322 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5323 {
5324+ if ((long)n < 0)
5325+ return n;
5326+
5327 prefetchw(to);
5328 if (access_ok(VERIFY_READ, from, n))
5329 __copy_user_zeroing(to,from,n);
5330diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5331index 0395c51..5f26031 100644
5332--- a/arch/m68k/include/asm/cache.h
5333+++ b/arch/m68k/include/asm/cache.h
5334@@ -4,9 +4,11 @@
5335 #ifndef __ARCH_M68K_CACHE_H
5336 #define __ARCH_M68K_CACHE_H
5337
5338+#include <linux/const.h>
5339+
5340 /* bytes per L1 cache line */
5341 #define L1_CACHE_SHIFT 4
5342-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5343+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5344
5345 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5346
5347diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5348index 0424315..defcca9 100644
5349--- a/arch/metag/mm/hugetlbpage.c
5350+++ b/arch/metag/mm/hugetlbpage.c
5351@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5352 info.high_limit = TASK_SIZE;
5353 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5354 info.align_offset = 0;
5355+ info.threadstack_offset = 0;
5356 return vm_unmapped_area(&info);
5357 }
5358
5359diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5360index 4efe96a..60e8699 100644
5361--- a/arch/microblaze/include/asm/cache.h
5362+++ b/arch/microblaze/include/asm/cache.h
5363@@ -13,11 +13,12 @@
5364 #ifndef _ASM_MICROBLAZE_CACHE_H
5365 #define _ASM_MICROBLAZE_CACHE_H
5366
5367+#include <linux/const.h>
5368 #include <asm/registers.h>
5369
5370 #define L1_CACHE_SHIFT 5
5371 /* word-granular cache in microblaze */
5372-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5373+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5374
5375 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5376
5377diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5378index f75ab4a..adc6968 100644
5379--- a/arch/mips/Kconfig
5380+++ b/arch/mips/Kconfig
5381@@ -2283,6 +2283,7 @@ source "kernel/Kconfig.preempt"
5382
5383 config KEXEC
5384 bool "Kexec system call"
5385+ depends on !GRKERNSEC_KMEM
5386 help
5387 kexec is a system call that implements the ability to shutdown your
5388 current kernel, and to start another kernel. It is like a reboot
5389diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5390index 08b6079..8b554d2 100644
5391--- a/arch/mips/include/asm/atomic.h
5392+++ b/arch/mips/include/asm/atomic.h
5393@@ -21,15 +21,39 @@
5394 #include <asm/cmpxchg.h>
5395 #include <asm/war.h>
5396
5397+#ifdef CONFIG_GENERIC_ATOMIC64
5398+#include <asm-generic/atomic64.h>
5399+#endif
5400+
5401 #define ATOMIC_INIT(i) { (i) }
5402
5403+#ifdef CONFIG_64BIT
5404+#define _ASM_EXTABLE(from, to) \
5405+" .section __ex_table,\"a\"\n" \
5406+" .dword " #from ", " #to"\n" \
5407+" .previous\n"
5408+#else
5409+#define _ASM_EXTABLE(from, to) \
5410+" .section __ex_table,\"a\"\n" \
5411+" .word " #from ", " #to"\n" \
5412+" .previous\n"
5413+#endif
5414+
5415 /*
5416 * atomic_read - read atomic variable
5417 * @v: pointer of type atomic_t
5418 *
5419 * Atomically reads the value of @v.
5420 */
5421-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5422+static inline int atomic_read(const atomic_t *v)
5423+{
5424+ return (*(volatile const int *) &v->counter);
5425+}
5426+
5427+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5428+{
5429+ return (*(volatile const int *) &v->counter);
5430+}
5431
5432 /*
5433 * atomic_set - set atomic variable
5434@@ -38,7 +62,15 @@
5435 *
5436 * Atomically sets the value of @v to @i.
5437 */
5438-#define atomic_set(v, i) ((v)->counter = (i))
5439+static inline void atomic_set(atomic_t *v, int i)
5440+{
5441+ v->counter = i;
5442+}
5443+
5444+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5445+{
5446+ v->counter = i;
5447+}
5448
5449 /*
5450 * atomic_add - add integer to atomic variable
5451@@ -47,7 +79,67 @@
5452 *
5453 * Atomically adds @i to @v.
5454 */
5455-static __inline__ void atomic_add(int i, atomic_t * v)
5456+static __inline__ void atomic_add(int i, atomic_t *v)
5457+{
5458+ int temp;
5459+
5460+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5461+ __asm__ __volatile__(
5462+ " .set mips3 \n"
5463+ "1: ll %0, %1 # atomic_add \n"
5464+#ifdef CONFIG_PAX_REFCOUNT
5465+ /* Exception on overflow. */
5466+ "2: add %0, %2 \n"
5467+#else
5468+ " addu %0, %2 \n"
5469+#endif
5470+ " sc %0, %1 \n"
5471+ " beqzl %0, 1b \n"
5472+#ifdef CONFIG_PAX_REFCOUNT
5473+ "3: \n"
5474+ _ASM_EXTABLE(2b, 3b)
5475+#endif
5476+ " .set mips0 \n"
5477+ : "=&r" (temp), "+m" (v->counter)
5478+ : "Ir" (i));
5479+ } else if (kernel_uses_llsc) {
5480+ __asm__ __volatile__(
5481+ " .set mips3 \n"
5482+ "1: ll %0, %1 # atomic_add \n"
5483+#ifdef CONFIG_PAX_REFCOUNT
5484+ /* Exception on overflow. */
5485+ "2: add %0, %2 \n"
5486+#else
5487+ " addu %0, %2 \n"
5488+#endif
5489+ " sc %0, %1 \n"
5490+ " beqz %0, 1b \n"
5491+#ifdef CONFIG_PAX_REFCOUNT
5492+ "3: \n"
5493+ _ASM_EXTABLE(2b, 3b)
5494+#endif
5495+ " .set mips0 \n"
5496+ : "=&r" (temp), "+m" (v->counter)
5497+ : "Ir" (i));
5498+ } else {
5499+ unsigned long flags;
5500+
5501+ raw_local_irq_save(flags);
5502+ __asm__ __volatile__(
5503+#ifdef CONFIG_PAX_REFCOUNT
5504+ /* Exception on overflow. */
5505+ "1: add %0, %1 \n"
5506+ "2: \n"
5507+ _ASM_EXTABLE(1b, 2b)
5508+#else
5509+ " addu %0, %1 \n"
5510+#endif
5511+ : "+r" (v->counter) : "Ir" (i));
5512+ raw_local_irq_restore(flags);
5513+ }
5514+}
5515+
5516+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5517 {
5518 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5519 int temp;
5520@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5521 *
5522 * Atomically subtracts @i from @v.
5523 */
5524-static __inline__ void atomic_sub(int i, atomic_t * v)
5525+static __inline__ void atomic_sub(int i, atomic_t *v)
5526+{
5527+ int temp;
5528+
5529+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5530+ __asm__ __volatile__(
5531+ " .set mips3 \n"
5532+ "1: ll %0, %1 # atomic64_sub \n"
5533+#ifdef CONFIG_PAX_REFCOUNT
5534+ /* Exception on overflow. */
5535+ "2: sub %0, %2 \n"
5536+#else
5537+ " subu %0, %2 \n"
5538+#endif
5539+ " sc %0, %1 \n"
5540+ " beqzl %0, 1b \n"
5541+#ifdef CONFIG_PAX_REFCOUNT
5542+ "3: \n"
5543+ _ASM_EXTABLE(2b, 3b)
5544+#endif
5545+ " .set mips0 \n"
5546+ : "=&r" (temp), "+m" (v->counter)
5547+ : "Ir" (i));
5548+ } else if (kernel_uses_llsc) {
5549+ __asm__ __volatile__(
5550+ " .set mips3 \n"
5551+ "1: ll %0, %1 # atomic64_sub \n"
5552+#ifdef CONFIG_PAX_REFCOUNT
5553+ /* Exception on overflow. */
5554+ "2: sub %0, %2 \n"
5555+#else
5556+ " subu %0, %2 \n"
5557+#endif
5558+ " sc %0, %1 \n"
5559+ " beqz %0, 1b \n"
5560+#ifdef CONFIG_PAX_REFCOUNT
5561+ "3: \n"
5562+ _ASM_EXTABLE(2b, 3b)
5563+#endif
5564+ " .set mips0 \n"
5565+ : "=&r" (temp), "+m" (v->counter)
5566+ : "Ir" (i));
5567+ } else {
5568+ unsigned long flags;
5569+
5570+ raw_local_irq_save(flags);
5571+ __asm__ __volatile__(
5572+#ifdef CONFIG_PAX_REFCOUNT
5573+ /* Exception on overflow. */
5574+ "1: sub %0, %1 \n"
5575+ "2: \n"
5576+ _ASM_EXTABLE(1b, 2b)
5577+#else
5578+ " subu %0, %1 \n"
5579+#endif
5580+ : "+r" (v->counter) : "Ir" (i));
5581+ raw_local_irq_restore(flags);
5582+ }
5583+}
5584+
5585+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5586 {
5587 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5588 int temp;
5589@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5590 /*
5591 * Same as above, but return the result value
5592 */
5593-static __inline__ int atomic_add_return(int i, atomic_t * v)
5594+static __inline__ int atomic_add_return(int i, atomic_t *v)
5595+{
5596+ int result;
5597+ int temp;
5598+
5599+ smp_mb__before_llsc();
5600+
5601+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5602+ __asm__ __volatile__(
5603+ " .set mips3 \n"
5604+ "1: ll %1, %2 # atomic_add_return \n"
5605+#ifdef CONFIG_PAX_REFCOUNT
5606+ "2: add %0, %1, %3 \n"
5607+#else
5608+ " addu %0, %1, %3 \n"
5609+#endif
5610+ " sc %0, %2 \n"
5611+ " beqzl %0, 1b \n"
5612+#ifdef CONFIG_PAX_REFCOUNT
5613+ " b 4f \n"
5614+ " .set noreorder \n"
5615+ "3: b 5f \n"
5616+ " move %0, %1 \n"
5617+ " .set reorder \n"
5618+ _ASM_EXTABLE(2b, 3b)
5619+#endif
5620+ "4: addu %0, %1, %3 \n"
5621+#ifdef CONFIG_PAX_REFCOUNT
5622+ "5: \n"
5623+#endif
5624+ " .set mips0 \n"
5625+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5626+ : "Ir" (i));
5627+ } else if (kernel_uses_llsc) {
5628+ __asm__ __volatile__(
5629+ " .set mips3 \n"
5630+ "1: ll %1, %2 # atomic_add_return \n"
5631+#ifdef CONFIG_PAX_REFCOUNT
5632+ "2: add %0, %1, %3 \n"
5633+#else
5634+ " addu %0, %1, %3 \n"
5635+#endif
5636+ " sc %0, %2 \n"
5637+ " bnez %0, 4f \n"
5638+ " b 1b \n"
5639+#ifdef CONFIG_PAX_REFCOUNT
5640+ " .set noreorder \n"
5641+ "3: b 5f \n"
5642+ " move %0, %1 \n"
5643+ " .set reorder \n"
5644+ _ASM_EXTABLE(2b, 3b)
5645+#endif
5646+ "4: addu %0, %1, %3 \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ "5: \n"
5649+#endif
5650+ " .set mips0 \n"
5651+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5652+ : "Ir" (i));
5653+ } else {
5654+ unsigned long flags;
5655+
5656+ raw_local_irq_save(flags);
5657+ __asm__ __volatile__(
5658+ " lw %0, %1 \n"
5659+#ifdef CONFIG_PAX_REFCOUNT
5660+ /* Exception on overflow. */
5661+ "1: add %0, %2 \n"
5662+#else
5663+ " addu %0, %2 \n"
5664+#endif
5665+ " sw %0, %1 \n"
5666+#ifdef CONFIG_PAX_REFCOUNT
5667+ /* Note: Dest reg is not modified on overflow */
5668+ "2: \n"
5669+ _ASM_EXTABLE(1b, 2b)
5670+#endif
5671+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5672+ raw_local_irq_restore(flags);
5673+ }
5674+
5675+ smp_llsc_mb();
5676+
5677+ return result;
5678+}
5679+
5680+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5681 {
5682 int result;
5683
5684@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5685 return result;
5686 }
5687
5688-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5689+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5690+{
5691+ int result;
5692+ int temp;
5693+
5694+ smp_mb__before_llsc();
5695+
5696+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5697+ __asm__ __volatile__(
5698+ " .set mips3 \n"
5699+ "1: ll %1, %2 # atomic_sub_return \n"
5700+#ifdef CONFIG_PAX_REFCOUNT
5701+ "2: sub %0, %1, %3 \n"
5702+#else
5703+ " subu %0, %1, %3 \n"
5704+#endif
5705+ " sc %0, %2 \n"
5706+ " beqzl %0, 1b \n"
5707+#ifdef CONFIG_PAX_REFCOUNT
5708+ " b 4f \n"
5709+ " .set noreorder \n"
5710+ "3: b 5f \n"
5711+ " move %0, %1 \n"
5712+ " .set reorder \n"
5713+ _ASM_EXTABLE(2b, 3b)
5714+#endif
5715+ "4: subu %0, %1, %3 \n"
5716+#ifdef CONFIG_PAX_REFCOUNT
5717+ "5: \n"
5718+#endif
5719+ " .set mips0 \n"
5720+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5721+ : "Ir" (i), "m" (v->counter)
5722+ : "memory");
5723+ } else if (kernel_uses_llsc) {
5724+ __asm__ __volatile__(
5725+ " .set mips3 \n"
5726+ "1: ll %1, %2 # atomic_sub_return \n"
5727+#ifdef CONFIG_PAX_REFCOUNT
5728+ "2: sub %0, %1, %3 \n"
5729+#else
5730+ " subu %0, %1, %3 \n"
5731+#endif
5732+ " sc %0, %2 \n"
5733+ " bnez %0, 4f \n"
5734+ " b 1b \n"
5735+#ifdef CONFIG_PAX_REFCOUNT
5736+ " .set noreorder \n"
5737+ "3: b 5f \n"
5738+ " move %0, %1 \n"
5739+ " .set reorder \n"
5740+ _ASM_EXTABLE(2b, 3b)
5741+#endif
5742+ "4: subu %0, %1, %3 \n"
5743+#ifdef CONFIG_PAX_REFCOUNT
5744+ "5: \n"
5745+#endif
5746+ " .set mips0 \n"
5747+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5748+ : "Ir" (i));
5749+ } else {
5750+ unsigned long flags;
5751+
5752+ raw_local_irq_save(flags);
5753+ __asm__ __volatile__(
5754+ " lw %0, %1 \n"
5755+#ifdef CONFIG_PAX_REFCOUNT
5756+ /* Exception on overflow. */
5757+ "1: sub %0, %2 \n"
5758+#else
5759+ " subu %0, %2 \n"
5760+#endif
5761+ " sw %0, %1 \n"
5762+#ifdef CONFIG_PAX_REFCOUNT
5763+ /* Note: Dest reg is not modified on overflow */
5764+ "2: \n"
5765+ _ASM_EXTABLE(1b, 2b)
5766+#endif
5767+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5768+ raw_local_irq_restore(flags);
5769+ }
5770+
5771+ smp_llsc_mb();
5772+
5773+ return result;
5774+}
5775+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5776 {
5777 int result;
5778
5779@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5780 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5781 * The function returns the old value of @v minus @i.
5782 */
5783-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5784+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5785 {
5786 int result;
5787
5788@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5789 return result;
5790 }
5791
5792-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5793-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5794+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5795+{
5796+ return cmpxchg(&v->counter, old, new);
5797+}
5798+
5799+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5800+ int new)
5801+{
5802+ return cmpxchg(&(v->counter), old, new);
5803+}
5804+
5805+static inline int atomic_xchg(atomic_t *v, int new)
5806+{
5807+ return xchg(&v->counter, new);
5808+}
5809+
5810+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5811+{
5812+ return xchg(&(v->counter), new);
5813+}
5814
5815 /**
5816 * __atomic_add_unless - add unless the number is a given value
5817@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5818
5819 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5820 #define atomic_inc_return(v) atomic_add_return(1, (v))
5821+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5822+{
5823+ return atomic_add_return_unchecked(1, v);
5824+}
5825
5826 /*
5827 * atomic_sub_and_test - subtract value from variable and test result
5828@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5829 * other cases.
5830 */
5831 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5832+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5833+{
5834+ return atomic_add_return_unchecked(1, v) == 0;
5835+}
5836
5837 /*
5838 * atomic_dec_and_test - decrement by 1 and test
5839@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5840 * Atomically increments @v by 1.
5841 */
5842 #define atomic_inc(v) atomic_add(1, (v))
5843+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5844+{
5845+ atomic_add_unchecked(1, v);
5846+}
5847
5848 /*
5849 * atomic_dec - decrement and test
5850@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5851 * Atomically decrements @v by 1.
5852 */
5853 #define atomic_dec(v) atomic_sub(1, (v))
5854+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5855+{
5856+ atomic_sub_unchecked(1, v);
5857+}
5858
5859 /*
5860 * atomic_add_negative - add and test if negative
5861@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5862 * @v: pointer of type atomic64_t
5863 *
5864 */
5865-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5866+static inline long atomic64_read(const atomic64_t *v)
5867+{
5868+ return (*(volatile const long *) &v->counter);
5869+}
5870+
5871+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5872+{
5873+ return (*(volatile const long *) &v->counter);
5874+}
5875
5876 /*
5877 * atomic64_set - set atomic variable
5878 * @v: pointer of type atomic64_t
5879 * @i: required value
5880 */
5881-#define atomic64_set(v, i) ((v)->counter = (i))
5882+static inline void atomic64_set(atomic64_t *v, long i)
5883+{
5884+ v->counter = i;
5885+}
5886+
5887+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5888+{
5889+ v->counter = i;
5890+}
5891
5892 /*
5893 * atomic64_add - add integer to atomic variable
5894@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5895 *
5896 * Atomically adds @i to @v.
5897 */
5898-static __inline__ void atomic64_add(long i, atomic64_t * v)
5899+static __inline__ void atomic64_add(long i, atomic64_t *v)
5900+{
5901+ long temp;
5902+
5903+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5904+ __asm__ __volatile__(
5905+ " .set mips3 \n"
5906+ "1: lld %0, %1 # atomic64_add \n"
5907+#ifdef CONFIG_PAX_REFCOUNT
5908+ /* Exception on overflow. */
5909+ "2: dadd %0, %2 \n"
5910+#else
5911+ " daddu %0, %2 \n"
5912+#endif
5913+ " scd %0, %1 \n"
5914+ " beqzl %0, 1b \n"
5915+#ifdef CONFIG_PAX_REFCOUNT
5916+ "3: \n"
5917+ _ASM_EXTABLE(2b, 3b)
5918+#endif
5919+ " .set mips0 \n"
5920+ : "=&r" (temp), "+m" (v->counter)
5921+ : "Ir" (i));
5922+ } else if (kernel_uses_llsc) {
5923+ __asm__ __volatile__(
5924+ " .set mips3 \n"
5925+ "1: lld %0, %1 # atomic64_add \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Exception on overflow. */
5928+ "2: dadd %0, %2 \n"
5929+#else
5930+ " daddu %0, %2 \n"
5931+#endif
5932+ " scd %0, %1 \n"
5933+ " beqz %0, 1b \n"
5934+#ifdef CONFIG_PAX_REFCOUNT
5935+ "3: \n"
5936+ _ASM_EXTABLE(2b, 3b)
5937+#endif
5938+ " .set mips0 \n"
5939+ : "=&r" (temp), "+m" (v->counter)
5940+ : "Ir" (i));
5941+ } else {
5942+ unsigned long flags;
5943+
5944+ raw_local_irq_save(flags);
5945+ __asm__ __volatile__(
5946+#ifdef CONFIG_PAX_REFCOUNT
5947+ /* Exception on overflow. */
5948+ "1: dadd %0, %1 \n"
5949+ "2: \n"
5950+ _ASM_EXTABLE(1b, 2b)
5951+#else
5952+ " daddu %0, %1 \n"
5953+#endif
5954+ : "+r" (v->counter) : "Ir" (i));
5955+ raw_local_irq_restore(flags);
5956+ }
5957+}
5958+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5959 {
5960 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5961 long temp;
5962@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5963 *
5964 * Atomically subtracts @i from @v.
5965 */
5966-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5967+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5968+{
5969+ long temp;
5970+
5971+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5972+ __asm__ __volatile__(
5973+ " .set mips3 \n"
5974+ "1: lld %0, %1 # atomic64_sub \n"
5975+#ifdef CONFIG_PAX_REFCOUNT
5976+ /* Exception on overflow. */
5977+ "2: dsub %0, %2 \n"
5978+#else
5979+ " dsubu %0, %2 \n"
5980+#endif
5981+ " scd %0, %1 \n"
5982+ " beqzl %0, 1b \n"
5983+#ifdef CONFIG_PAX_REFCOUNT
5984+ "3: \n"
5985+ _ASM_EXTABLE(2b, 3b)
5986+#endif
5987+ " .set mips0 \n"
5988+ : "=&r" (temp), "+m" (v->counter)
5989+ : "Ir" (i));
5990+ } else if (kernel_uses_llsc) {
5991+ __asm__ __volatile__(
5992+ " .set mips3 \n"
5993+ "1: lld %0, %1 # atomic64_sub \n"
5994+#ifdef CONFIG_PAX_REFCOUNT
5995+ /* Exception on overflow. */
5996+ "2: dsub %0, %2 \n"
5997+#else
5998+ " dsubu %0, %2 \n"
5999+#endif
6000+ " scd %0, %1 \n"
6001+ " beqz %0, 1b \n"
6002+#ifdef CONFIG_PAX_REFCOUNT
6003+ "3: \n"
6004+ _ASM_EXTABLE(2b, 3b)
6005+#endif
6006+ " .set mips0 \n"
6007+ : "=&r" (temp), "+m" (v->counter)
6008+ : "Ir" (i));
6009+ } else {
6010+ unsigned long flags;
6011+
6012+ raw_local_irq_save(flags);
6013+ __asm__ __volatile__(
6014+#ifdef CONFIG_PAX_REFCOUNT
6015+ /* Exception on overflow. */
6016+ "1: dsub %0, %1 \n"
6017+ "2: \n"
6018+ _ASM_EXTABLE(1b, 2b)
6019+#else
6020+ " dsubu %0, %1 \n"
6021+#endif
6022+ : "+r" (v->counter) : "Ir" (i));
6023+ raw_local_irq_restore(flags);
6024+ }
6025+}
6026+
6027+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6028 {
6029 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6030 long temp;
6031@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6032 /*
6033 * Same as above, but return the result value
6034 */
6035-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6036+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6037+{
6038+ long result;
6039+ long temp;
6040+
6041+ smp_mb__before_llsc();
6042+
6043+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6044+ __asm__ __volatile__(
6045+ " .set mips3 \n"
6046+ "1: lld %1, %2 # atomic64_add_return \n"
6047+#ifdef CONFIG_PAX_REFCOUNT
6048+ "2: dadd %0, %1, %3 \n"
6049+#else
6050+ " daddu %0, %1, %3 \n"
6051+#endif
6052+ " scd %0, %2 \n"
6053+ " beqzl %0, 1b \n"
6054+#ifdef CONFIG_PAX_REFCOUNT
6055+ " b 4f \n"
6056+ " .set noreorder \n"
6057+ "3: b 5f \n"
6058+ " move %0, %1 \n"
6059+ " .set reorder \n"
6060+ _ASM_EXTABLE(2b, 3b)
6061+#endif
6062+ "4: daddu %0, %1, %3 \n"
6063+#ifdef CONFIG_PAX_REFCOUNT
6064+ "5: \n"
6065+#endif
6066+ " .set mips0 \n"
6067+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6068+ : "Ir" (i));
6069+ } else if (kernel_uses_llsc) {
6070+ __asm__ __volatile__(
6071+ " .set mips3 \n"
6072+ "1: lld %1, %2 # atomic64_add_return \n"
6073+#ifdef CONFIG_PAX_REFCOUNT
6074+ "2: dadd %0, %1, %3 \n"
6075+#else
6076+ " daddu %0, %1, %3 \n"
6077+#endif
6078+ " scd %0, %2 \n"
6079+ " bnez %0, 4f \n"
6080+ " b 1b \n"
6081+#ifdef CONFIG_PAX_REFCOUNT
6082+ " .set noreorder \n"
6083+ "3: b 5f \n"
6084+ " move %0, %1 \n"
6085+ " .set reorder \n"
6086+ _ASM_EXTABLE(2b, 3b)
6087+#endif
6088+ "4: daddu %0, %1, %3 \n"
6089+#ifdef CONFIG_PAX_REFCOUNT
6090+ "5: \n"
6091+#endif
6092+ " .set mips0 \n"
6093+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6094+ : "Ir" (i), "m" (v->counter)
6095+ : "memory");
6096+ } else {
6097+ unsigned long flags;
6098+
6099+ raw_local_irq_save(flags);
6100+ __asm__ __volatile__(
6101+ " ld %0, %1 \n"
6102+#ifdef CONFIG_PAX_REFCOUNT
6103+ /* Exception on overflow. */
6104+ "1: dadd %0, %2 \n"
6105+#else
6106+ " daddu %0, %2 \n"
6107+#endif
6108+ " sd %0, %1 \n"
6109+#ifdef CONFIG_PAX_REFCOUNT
6110+ /* Note: Dest reg is not modified on overflow */
6111+ "2: \n"
6112+ _ASM_EXTABLE(1b, 2b)
6113+#endif
6114+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6115+ raw_local_irq_restore(flags);
6116+ }
6117+
6118+ smp_llsc_mb();
6119+
6120+ return result;
6121+}
6122+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6123 {
6124 long result;
6125
6126@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6127 return result;
6128 }
6129
6130-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6131+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6132+{
6133+ long result;
6134+ long temp;
6135+
6136+ smp_mb__before_llsc();
6137+
6138+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6139+ long temp;
6140+
6141+ __asm__ __volatile__(
6142+ " .set mips3 \n"
6143+ "1: lld %1, %2 # atomic64_sub_return \n"
6144+#ifdef CONFIG_PAX_REFCOUNT
6145+ "2: dsub %0, %1, %3 \n"
6146+#else
6147+ " dsubu %0, %1, %3 \n"
6148+#endif
6149+ " scd %0, %2 \n"
6150+ " beqzl %0, 1b \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ " b 4f \n"
6153+ " .set noreorder \n"
6154+ "3: b 5f \n"
6155+ " move %0, %1 \n"
6156+ " .set reorder \n"
6157+ _ASM_EXTABLE(2b, 3b)
6158+#endif
6159+ "4: dsubu %0, %1, %3 \n"
6160+#ifdef CONFIG_PAX_REFCOUNT
6161+ "5: \n"
6162+#endif
6163+ " .set mips0 \n"
6164+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6165+ : "Ir" (i), "m" (v->counter)
6166+ : "memory");
6167+ } else if (kernel_uses_llsc) {
6168+ __asm__ __volatile__(
6169+ " .set mips3 \n"
6170+ "1: lld %1, %2 # atomic64_sub_return \n"
6171+#ifdef CONFIG_PAX_REFCOUNT
6172+ "2: dsub %0, %1, %3 \n"
6173+#else
6174+ " dsubu %0, %1, %3 \n"
6175+#endif
6176+ " scd %0, %2 \n"
6177+ " bnez %0, 4f \n"
6178+ " b 1b \n"
6179+#ifdef CONFIG_PAX_REFCOUNT
6180+ " .set noreorder \n"
6181+ "3: b 5f \n"
6182+ " move %0, %1 \n"
6183+ " .set reorder \n"
6184+ _ASM_EXTABLE(2b, 3b)
6185+#endif
6186+ "4: dsubu %0, %1, %3 \n"
6187+#ifdef CONFIG_PAX_REFCOUNT
6188+ "5: \n"
6189+#endif
6190+ " .set mips0 \n"
6191+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6192+ : "Ir" (i), "m" (v->counter)
6193+ : "memory");
6194+ } else {
6195+ unsigned long flags;
6196+
6197+ raw_local_irq_save(flags);
6198+ __asm__ __volatile__(
6199+ " ld %0, %1 \n"
6200+#ifdef CONFIG_PAX_REFCOUNT
6201+ /* Exception on overflow. */
6202+ "1: dsub %0, %2 \n"
6203+#else
6204+ " dsubu %0, %2 \n"
6205+#endif
6206+ " sd %0, %1 \n"
6207+#ifdef CONFIG_PAX_REFCOUNT
6208+ /* Note: Dest reg is not modified on overflow */
6209+ "2: \n"
6210+ _ASM_EXTABLE(1b, 2b)
6211+#endif
6212+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6213+ raw_local_irq_restore(flags);
6214+ }
6215+
6216+ smp_llsc_mb();
6217+
6218+ return result;
6219+}
6220+
6221+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6222 {
6223 long result;
6224
6225@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6226 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6227 * The function returns the old value of @v minus @i.
6228 */
6229-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6230+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6231 {
6232 long result;
6233
6234@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6235 return result;
6236 }
6237
6238-#define atomic64_cmpxchg(v, o, n) \
6239- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6240-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6241+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6242+{
6243+ return cmpxchg(&v->counter, old, new);
6244+}
6245+
6246+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6247+ long new)
6248+{
6249+ return cmpxchg(&(v->counter), old, new);
6250+}
6251+
6252+static inline long atomic64_xchg(atomic64_t *v, long new)
6253+{
6254+ return xchg(&v->counter, new);
6255+}
6256+
6257+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6258+{
6259+ return xchg(&(v->counter), new);
6260+}
6261
6262 /**
6263 * atomic64_add_unless - add unless the number is a given value
6264@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6265
6266 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6267 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6268+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6269
6270 /*
6271 * atomic64_sub_and_test - subtract value from variable and test result
6272@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6273 * other cases.
6274 */
6275 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6276+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6277
6278 /*
6279 * atomic64_dec_and_test - decrement by 1 and test
6280@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6281 * Atomically increments @v by 1.
6282 */
6283 #define atomic64_inc(v) atomic64_add(1, (v))
6284+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6285
6286 /*
6287 * atomic64_dec - decrement and test
6288@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6289 * Atomically decrements @v by 1.
6290 */
6291 #define atomic64_dec(v) atomic64_sub(1, (v))
6292+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6293
6294 /*
6295 * atomic64_add_negative - add and test if negative
6296diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6297index b4db69f..8f3b093 100644
6298--- a/arch/mips/include/asm/cache.h
6299+++ b/arch/mips/include/asm/cache.h
6300@@ -9,10 +9,11 @@
6301 #ifndef _ASM_CACHE_H
6302 #define _ASM_CACHE_H
6303
6304+#include <linux/const.h>
6305 #include <kmalloc.h>
6306
6307 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6308-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6309+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6310
6311 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6312 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6313diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6314index cf3ae24..238d22f 100644
6315--- a/arch/mips/include/asm/elf.h
6316+++ b/arch/mips/include/asm/elf.h
6317@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6318 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6319 #endif
6320
6321+#ifdef CONFIG_PAX_ASLR
6322+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6323+
6324+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6325+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6326+#endif
6327+
6328 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6329 struct linux_binprm;
6330 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6331 int uses_interp);
6332
6333-struct mm_struct;
6334-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6335-#define arch_randomize_brk arch_randomize_brk
6336-
6337 #endif /* _ASM_ELF_H */
6338diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6339index c1f6afa..38cc6e9 100644
6340--- a/arch/mips/include/asm/exec.h
6341+++ b/arch/mips/include/asm/exec.h
6342@@ -12,6 +12,6 @@
6343 #ifndef _ASM_EXEC_H
6344 #define _ASM_EXEC_H
6345
6346-extern unsigned long arch_align_stack(unsigned long sp);
6347+#define arch_align_stack(x) ((x) & ~0xfUL)
6348
6349 #endif /* _ASM_EXEC_H */
6350diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6351index d44622c..64990d2 100644
6352--- a/arch/mips/include/asm/local.h
6353+++ b/arch/mips/include/asm/local.h
6354@@ -12,15 +12,25 @@ typedef struct
6355 atomic_long_t a;
6356 } local_t;
6357
6358+typedef struct {
6359+ atomic_long_unchecked_t a;
6360+} local_unchecked_t;
6361+
6362 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6363
6364 #define local_read(l) atomic_long_read(&(l)->a)
6365+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6366 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6367+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6368
6369 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6370+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6371 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6372+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6373 #define local_inc(l) atomic_long_inc(&(l)->a)
6374+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6375 #define local_dec(l) atomic_long_dec(&(l)->a)
6376+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6377
6378 /*
6379 * Same as above, but return the result value
6380@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6381 return result;
6382 }
6383
6384+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6385+{
6386+ unsigned long result;
6387+
6388+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6389+ unsigned long temp;
6390+
6391+ __asm__ __volatile__(
6392+ " .set mips3 \n"
6393+ "1:" __LL "%1, %2 # local_add_return \n"
6394+ " addu %0, %1, %3 \n"
6395+ __SC "%0, %2 \n"
6396+ " beqzl %0, 1b \n"
6397+ " addu %0, %1, %3 \n"
6398+ " .set mips0 \n"
6399+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6400+ : "Ir" (i), "m" (l->a.counter)
6401+ : "memory");
6402+ } else if (kernel_uses_llsc) {
6403+ unsigned long temp;
6404+
6405+ __asm__ __volatile__(
6406+ " .set mips3 \n"
6407+ "1:" __LL "%1, %2 # local_add_return \n"
6408+ " addu %0, %1, %3 \n"
6409+ __SC "%0, %2 \n"
6410+ " beqz %0, 1b \n"
6411+ " addu %0, %1, %3 \n"
6412+ " .set mips0 \n"
6413+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6414+ : "Ir" (i), "m" (l->a.counter)
6415+ : "memory");
6416+ } else {
6417+ unsigned long flags;
6418+
6419+ local_irq_save(flags);
6420+ result = l->a.counter;
6421+ result += i;
6422+ l->a.counter = result;
6423+ local_irq_restore(flags);
6424+ }
6425+
6426+ return result;
6427+}
6428+
6429 static __inline__ long local_sub_return(long i, local_t * l)
6430 {
6431 unsigned long result;
6432@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6433
6434 #define local_cmpxchg(l, o, n) \
6435 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6436+#define local_cmpxchg_unchecked(l, o, n) \
6437+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6438 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6439
6440 /**
6441diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6442index f6be474..12ad554 100644
6443--- a/arch/mips/include/asm/page.h
6444+++ b/arch/mips/include/asm/page.h
6445@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6446 #ifdef CONFIG_CPU_MIPS32
6447 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6448 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6449- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6450+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6451 #else
6452 typedef struct { unsigned long long pte; } pte_t;
6453 #define pte_val(x) ((x).pte)
6454diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6455index 881d18b..cea38bc 100644
6456--- a/arch/mips/include/asm/pgalloc.h
6457+++ b/arch/mips/include/asm/pgalloc.h
6458@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6459 {
6460 set_pud(pud, __pud((unsigned long)pmd));
6461 }
6462+
6463+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6464+{
6465+ pud_populate(mm, pud, pmd);
6466+}
6467 #endif
6468
6469 /*
6470diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6471index 25da651..ae2a259 100644
6472--- a/arch/mips/include/asm/smtc_proc.h
6473+++ b/arch/mips/include/asm/smtc_proc.h
6474@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6475
6476 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6477
6478-extern atomic_t smtc_fpu_recoveries;
6479+extern atomic_unchecked_t smtc_fpu_recoveries;
6480
6481 #endif /* __ASM_SMTC_PROC_H */
6482diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6483index 61215a3..213ee0e 100644
6484--- a/arch/mips/include/asm/thread_info.h
6485+++ b/arch/mips/include/asm/thread_info.h
6486@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6487 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6488 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6489 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6490+/* li takes a 32bit immediate */
6491+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6492 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6493
6494 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6495@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6496 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6497 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6498 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6499+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6500
6501-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6502- _TIF_SYSCALL_AUDIT)
6503+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6504
6505 /* work to do in syscall_trace_leave() */
6506-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6507- _TIF_SYSCALL_AUDIT)
6508+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6509
6510 /* work to do on interrupt/exception return */
6511 #define _TIF_WORK_MASK \
6512 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6513 /* work to do on any return to u-space */
6514-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6515- _TIF_WORK_SYSCALL_EXIT)
6516+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6517
6518 #endif /* __KERNEL__ */
6519
6520diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6521index 1188e00..41cf144 100644
6522--- a/arch/mips/kernel/binfmt_elfn32.c
6523+++ b/arch/mips/kernel/binfmt_elfn32.c
6524@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6525 #undef ELF_ET_DYN_BASE
6526 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6527
6528+#ifdef CONFIG_PAX_ASLR
6529+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6530+
6531+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6532+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6533+#endif
6534+
6535 #include <asm/processor.h>
6536 #include <linux/module.h>
6537 #include <linux/elfcore.h>
6538diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6539index 202e581..689ca79 100644
6540--- a/arch/mips/kernel/binfmt_elfo32.c
6541+++ b/arch/mips/kernel/binfmt_elfo32.c
6542@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6543 #undef ELF_ET_DYN_BASE
6544 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6545
6546+#ifdef CONFIG_PAX_ASLR
6547+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6548+
6549+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6550+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6551+#endif
6552+
6553 #include <asm/processor.h>
6554
6555 /*
6556diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6557index d1fea7a..45602ea 100644
6558--- a/arch/mips/kernel/irq.c
6559+++ b/arch/mips/kernel/irq.c
6560@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6561 printk("unexpected IRQ # %d\n", irq);
6562 }
6563
6564-atomic_t irq_err_count;
6565+atomic_unchecked_t irq_err_count;
6566
6567 int arch_show_interrupts(struct seq_file *p, int prec)
6568 {
6569- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6570+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6571 return 0;
6572 }
6573
6574 asmlinkage void spurious_interrupt(void)
6575 {
6576- atomic_inc(&irq_err_count);
6577+ atomic_inc_unchecked(&irq_err_count);
6578 }
6579
6580 void __init init_IRQ(void)
6581diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6582index ddc7610..8c58f17 100644
6583--- a/arch/mips/kernel/process.c
6584+++ b/arch/mips/kernel/process.c
6585@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6586 out:
6587 return pc;
6588 }
6589-
6590-/*
6591- * Don't forget that the stack pointer must be aligned on a 8 bytes
6592- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6593- */
6594-unsigned long arch_align_stack(unsigned long sp)
6595-{
6596- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6597- sp -= get_random_int() & ~PAGE_MASK;
6598-
6599- return sp & ALMASK;
6600-}
6601diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6602index 8ae1ebe..1bcbf47 100644
6603--- a/arch/mips/kernel/ptrace.c
6604+++ b/arch/mips/kernel/ptrace.c
6605@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6606 return arch;
6607 }
6608
6609+#ifdef CONFIG_GRKERNSEC_SETXID
6610+extern void gr_delayed_cred_worker(void);
6611+#endif
6612+
6613 /*
6614 * Notification of system call entry/exit
6615 * - triggered by current->work.syscall_trace
6616@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6617 /* do the secure computing check first */
6618 secure_computing_strict(regs->regs[2]);
6619
6620+#ifdef CONFIG_GRKERNSEC_SETXID
6621+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6622+ gr_delayed_cred_worker();
6623+#endif
6624+
6625 if (!(current->ptrace & PT_PTRACED))
6626 goto out;
6627
6628diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6629index c10aa84..9ec2e60 100644
6630--- a/arch/mips/kernel/smtc-proc.c
6631+++ b/arch/mips/kernel/smtc-proc.c
6632@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6633
6634 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6635
6636-atomic_t smtc_fpu_recoveries;
6637+atomic_unchecked_t smtc_fpu_recoveries;
6638
6639 static int smtc_proc_show(struct seq_file *m, void *v)
6640 {
6641@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6642 for(i = 0; i < NR_CPUS; i++)
6643 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6644 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6645- atomic_read(&smtc_fpu_recoveries));
6646+ atomic_read_unchecked(&smtc_fpu_recoveries));
6647 return 0;
6648 }
6649
6650@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6651 smtc_cpu_stats[i].selfipis = 0;
6652 }
6653
6654- atomic_set(&smtc_fpu_recoveries, 0);
6655+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6656
6657 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6658 }
6659diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6660index dfc1b91..11a2c07 100644
6661--- a/arch/mips/kernel/smtc.c
6662+++ b/arch/mips/kernel/smtc.c
6663@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6664 }
6665 smtc_ipi_qdump();
6666 printk("%d Recoveries of \"stolen\" FPU\n",
6667- atomic_read(&smtc_fpu_recoveries));
6668+ atomic_read_unchecked(&smtc_fpu_recoveries));
6669 }
6670
6671
6672diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6673index 84536bf..79caa4d 100644
6674--- a/arch/mips/kernel/sync-r4k.c
6675+++ b/arch/mips/kernel/sync-r4k.c
6676@@ -21,8 +21,8 @@
6677 #include <asm/mipsregs.h>
6678
6679 static atomic_t count_start_flag = ATOMIC_INIT(0);
6680-static atomic_t count_count_start = ATOMIC_INIT(0);
6681-static atomic_t count_count_stop = ATOMIC_INIT(0);
6682+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6683+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6684 static atomic_t count_reference = ATOMIC_INIT(0);
6685
6686 #define COUNTON 100
6687@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6688
6689 for (i = 0; i < NR_LOOPS; i++) {
6690 /* slaves loop on '!= 2' */
6691- while (atomic_read(&count_count_start) != 1)
6692+ while (atomic_read_unchecked(&count_count_start) != 1)
6693 mb();
6694- atomic_set(&count_count_stop, 0);
6695+ atomic_set_unchecked(&count_count_stop, 0);
6696 smp_wmb();
6697
6698 /* this lets the slaves write their count register */
6699- atomic_inc(&count_count_start);
6700+ atomic_inc_unchecked(&count_count_start);
6701
6702 /*
6703 * Everyone initialises count in the last loop:
6704@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6705 /*
6706 * Wait for all slaves to leave the synchronization point:
6707 */
6708- while (atomic_read(&count_count_stop) != 1)
6709+ while (atomic_read_unchecked(&count_count_stop) != 1)
6710 mb();
6711- atomic_set(&count_count_start, 0);
6712+ atomic_set_unchecked(&count_count_start, 0);
6713 smp_wmb();
6714- atomic_inc(&count_count_stop);
6715+ atomic_inc_unchecked(&count_count_stop);
6716 }
6717 /* Arrange for an interrupt in a short while */
6718 write_c0_compare(read_c0_count() + COUNTON);
6719@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6720 initcount = atomic_read(&count_reference);
6721
6722 for (i = 0; i < NR_LOOPS; i++) {
6723- atomic_inc(&count_count_start);
6724- while (atomic_read(&count_count_start) != 2)
6725+ atomic_inc_unchecked(&count_count_start);
6726+ while (atomic_read_unchecked(&count_count_start) != 2)
6727 mb();
6728
6729 /*
6730@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6731 if (i == NR_LOOPS-1)
6732 write_c0_count(initcount);
6733
6734- atomic_inc(&count_count_stop);
6735- while (atomic_read(&count_count_stop) != 2)
6736+ atomic_inc_unchecked(&count_count_stop);
6737+ while (atomic_read_unchecked(&count_count_stop) != 2)
6738 mb();
6739 }
6740 /* Arrange for an interrupt in a short while */
6741diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6742index 524841f..3eef41e 100644
6743--- a/arch/mips/kernel/traps.c
6744+++ b/arch/mips/kernel/traps.c
6745@@ -684,7 +684,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6746 siginfo_t info;
6747
6748 prev_state = exception_enter();
6749- die_if_kernel("Integer overflow", regs);
6750+ if (unlikely(!user_mode(regs))) {
6751+
6752+#ifdef CONFIG_PAX_REFCOUNT
6753+ if (fixup_exception(regs)) {
6754+ pax_report_refcount_overflow(regs);
6755+ exception_exit(prev_state);
6756+ return;
6757+ }
6758+#endif
6759+
6760+ die("Integer overflow", regs);
6761+ }
6762
6763 info.si_code = FPE_INTOVF;
6764 info.si_signo = SIGFPE;
6765diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6766index becc42b..9e43d4b 100644
6767--- a/arch/mips/mm/fault.c
6768+++ b/arch/mips/mm/fault.c
6769@@ -28,6 +28,23 @@
6770 #include <asm/highmem.h> /* For VMALLOC_END */
6771 #include <linux/kdebug.h>
6772
6773+#ifdef CONFIG_PAX_PAGEEXEC
6774+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6775+{
6776+ unsigned long i;
6777+
6778+ printk(KERN_ERR "PAX: bytes at PC: ");
6779+ for (i = 0; i < 5; i++) {
6780+ unsigned int c;
6781+ if (get_user(c, (unsigned int *)pc+i))
6782+ printk(KERN_CONT "???????? ");
6783+ else
6784+ printk(KERN_CONT "%08x ", c);
6785+ }
6786+ printk("\n");
6787+}
6788+#endif
6789+
6790 /*
6791 * This routine handles page faults. It determines the address,
6792 * and the problem, and then passes it off to one of the appropriate
6793@@ -199,6 +216,14 @@ bad_area:
6794 bad_area_nosemaphore:
6795 /* User mode accesses just cause a SIGSEGV */
6796 if (user_mode(regs)) {
6797+
6798+#ifdef CONFIG_PAX_PAGEEXEC
6799+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6800+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6801+ do_group_exit(SIGKILL);
6802+ }
6803+#endif
6804+
6805 tsk->thread.cp0_badvaddr = address;
6806 tsk->thread.error_code = write;
6807 #if 0
6808diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6809index f1baadd..8537544 100644
6810--- a/arch/mips/mm/mmap.c
6811+++ b/arch/mips/mm/mmap.c
6812@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6813 struct vm_area_struct *vma;
6814 unsigned long addr = addr0;
6815 int do_color_align;
6816+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6817 struct vm_unmapped_area_info info;
6818
6819 if (unlikely(len > TASK_SIZE))
6820@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6821 do_color_align = 1;
6822
6823 /* requesting a specific address */
6824+
6825+#ifdef CONFIG_PAX_RANDMMAP
6826+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6827+#endif
6828+
6829 if (addr) {
6830 if (do_color_align)
6831 addr = COLOUR_ALIGN(addr, pgoff);
6832@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6833 addr = PAGE_ALIGN(addr);
6834
6835 vma = find_vma(mm, addr);
6836- if (TASK_SIZE - len >= addr &&
6837- (!vma || addr + len <= vma->vm_start))
6838+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6839 return addr;
6840 }
6841
6842 info.length = len;
6843 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6844 info.align_offset = pgoff << PAGE_SHIFT;
6845+ info.threadstack_offset = offset;
6846
6847 if (dir == DOWN) {
6848 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6849@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6850 {
6851 unsigned long random_factor = 0UL;
6852
6853+#ifdef CONFIG_PAX_RANDMMAP
6854+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6855+#endif
6856+
6857 if (current->flags & PF_RANDOMIZE) {
6858 random_factor = get_random_int();
6859 random_factor = random_factor << PAGE_SHIFT;
6860@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6861
6862 if (mmap_is_legacy()) {
6863 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6864+
6865+#ifdef CONFIG_PAX_RANDMMAP
6866+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6867+ mm->mmap_base += mm->delta_mmap;
6868+#endif
6869+
6870 mm->get_unmapped_area = arch_get_unmapped_area;
6871 } else {
6872 mm->mmap_base = mmap_base(random_factor);
6873+
6874+#ifdef CONFIG_PAX_RANDMMAP
6875+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6876+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6877+#endif
6878+
6879 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6880 }
6881 }
6882
6883-static inline unsigned long brk_rnd(void)
6884-{
6885- unsigned long rnd = get_random_int();
6886-
6887- rnd = rnd << PAGE_SHIFT;
6888- /* 8MB for 32bit, 256MB for 64bit */
6889- if (TASK_IS_32BIT_ADDR)
6890- rnd = rnd & 0x7ffffful;
6891- else
6892- rnd = rnd & 0xffffffful;
6893-
6894- return rnd;
6895-}
6896-
6897-unsigned long arch_randomize_brk(struct mm_struct *mm)
6898-{
6899- unsigned long base = mm->brk;
6900- unsigned long ret;
6901-
6902- ret = PAGE_ALIGN(base + brk_rnd());
6903-
6904- if (ret < mm->brk)
6905- return mm->brk;
6906-
6907- return ret;
6908-}
6909-
6910 int __virt_addr_valid(const volatile void *kaddr)
6911 {
6912 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6913diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6914index a2358b4..7cead4f 100644
6915--- a/arch/mips/sgi-ip27/ip27-nmi.c
6916+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6917@@ -187,9 +187,9 @@ void
6918 cont_nmi_dump(void)
6919 {
6920 #ifndef REAL_NMI_SIGNAL
6921- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6922+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6923
6924- atomic_inc(&nmied_cpus);
6925+ atomic_inc_unchecked(&nmied_cpus);
6926 #endif
6927 /*
6928 * Only allow 1 cpu to proceed
6929@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6930 udelay(10000);
6931 }
6932 #else
6933- while (atomic_read(&nmied_cpus) != num_online_cpus());
6934+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6935 #endif
6936
6937 /*
6938diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6939index 967d144..db12197 100644
6940--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6941+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6942@@ -11,12 +11,14 @@
6943 #ifndef _ASM_PROC_CACHE_H
6944 #define _ASM_PROC_CACHE_H
6945
6946+#include <linux/const.h>
6947+
6948 /* L1 cache */
6949
6950 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6951 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6952-#define L1_CACHE_BYTES 16 /* bytes per entry */
6953 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6954+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6955 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6956
6957 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6958diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6959index bcb5df2..84fabd2 100644
6960--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6961+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6962@@ -16,13 +16,15 @@
6963 #ifndef _ASM_PROC_CACHE_H
6964 #define _ASM_PROC_CACHE_H
6965
6966+#include <linux/const.h>
6967+
6968 /*
6969 * L1 cache
6970 */
6971 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6972 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6973-#define L1_CACHE_BYTES 32 /* bytes per entry */
6974 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6975+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6976 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6977
6978 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6979diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6980index 4ce7a01..449202a 100644
6981--- a/arch/openrisc/include/asm/cache.h
6982+++ b/arch/openrisc/include/asm/cache.h
6983@@ -19,11 +19,13 @@
6984 #ifndef __ASM_OPENRISC_CACHE_H
6985 #define __ASM_OPENRISC_CACHE_H
6986
6987+#include <linux/const.h>
6988+
6989 /* FIXME: How can we replace these with values from the CPU...
6990 * they shouldn't be hard-coded!
6991 */
6992
6993-#define L1_CACHE_BYTES 16
6994 #define L1_CACHE_SHIFT 4
6995+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6996
6997 #endif /* __ASM_OPENRISC_CACHE_H */
6998diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6999index 472886c..00e7df9 100644
7000--- a/arch/parisc/include/asm/atomic.h
7001+++ b/arch/parisc/include/asm/atomic.h
7002@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7003 return dec;
7004 }
7005
7006+#define atomic64_read_unchecked(v) atomic64_read(v)
7007+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7008+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7009+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7010+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7011+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7012+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7013+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7014+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7015+
7016 #endif /* !CONFIG_64BIT */
7017
7018
7019diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7020index 47f11c7..3420df2 100644
7021--- a/arch/parisc/include/asm/cache.h
7022+++ b/arch/parisc/include/asm/cache.h
7023@@ -5,6 +5,7 @@
7024 #ifndef __ARCH_PARISC_CACHE_H
7025 #define __ARCH_PARISC_CACHE_H
7026
7027+#include <linux/const.h>
7028
7029 /*
7030 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7031@@ -15,13 +16,13 @@
7032 * just ruin performance.
7033 */
7034 #ifdef CONFIG_PA20
7035-#define L1_CACHE_BYTES 64
7036 #define L1_CACHE_SHIFT 6
7037 #else
7038-#define L1_CACHE_BYTES 32
7039 #define L1_CACHE_SHIFT 5
7040 #endif
7041
7042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7043+
7044 #ifndef __ASSEMBLY__
7045
7046 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7047diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7048index ad2b503..bdf1651 100644
7049--- a/arch/parisc/include/asm/elf.h
7050+++ b/arch/parisc/include/asm/elf.h
7051@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7052
7053 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7054
7055+#ifdef CONFIG_PAX_ASLR
7056+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7057+
7058+#define PAX_DELTA_MMAP_LEN 16
7059+#define PAX_DELTA_STACK_LEN 16
7060+#endif
7061+
7062 /* This yields a mask that user programs can use to figure out what
7063 instruction set this CPU supports. This could be done in user space,
7064 but it's not easy, and we've already done it here. */
7065diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7066index fc987a1..6e068ef 100644
7067--- a/arch/parisc/include/asm/pgalloc.h
7068+++ b/arch/parisc/include/asm/pgalloc.h
7069@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7070 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7071 }
7072
7073+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7074+{
7075+ pgd_populate(mm, pgd, pmd);
7076+}
7077+
7078 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7079 {
7080 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7081@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7082 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7083 #define pmd_free(mm, x) do { } while (0)
7084 #define pgd_populate(mm, pmd, pte) BUG()
7085+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7086
7087 #endif
7088
7089diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7090index 34899b5..02dd060 100644
7091--- a/arch/parisc/include/asm/pgtable.h
7092+++ b/arch/parisc/include/asm/pgtable.h
7093@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7094 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7095 #define PAGE_COPY PAGE_EXECREAD
7096 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7097+
7098+#ifdef CONFIG_PAX_PAGEEXEC
7099+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7100+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7101+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7102+#else
7103+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7104+# define PAGE_COPY_NOEXEC PAGE_COPY
7105+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7106+#endif
7107+
7108 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7109 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7110 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7111diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7112index e0a8235..ce2f1e1 100644
7113--- a/arch/parisc/include/asm/uaccess.h
7114+++ b/arch/parisc/include/asm/uaccess.h
7115@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7116 const void __user *from,
7117 unsigned long n)
7118 {
7119- int sz = __compiletime_object_size(to);
7120+ size_t sz = __compiletime_object_size(to);
7121 int ret = -EFAULT;
7122
7123- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7124+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7125 ret = __copy_from_user(to, from, n);
7126 else
7127 copy_from_user_overflow();
7128diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7129index 2a625fb..9908930 100644
7130--- a/arch/parisc/kernel/module.c
7131+++ b/arch/parisc/kernel/module.c
7132@@ -98,16 +98,38 @@
7133
7134 /* three functions to determine where in the module core
7135 * or init pieces the location is */
7136+static inline int in_init_rx(struct module *me, void *loc)
7137+{
7138+ return (loc >= me->module_init_rx &&
7139+ loc < (me->module_init_rx + me->init_size_rx));
7140+}
7141+
7142+static inline int in_init_rw(struct module *me, void *loc)
7143+{
7144+ return (loc >= me->module_init_rw &&
7145+ loc < (me->module_init_rw + me->init_size_rw));
7146+}
7147+
7148 static inline int in_init(struct module *me, void *loc)
7149 {
7150- return (loc >= me->module_init &&
7151- loc <= (me->module_init + me->init_size));
7152+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7153+}
7154+
7155+static inline int in_core_rx(struct module *me, void *loc)
7156+{
7157+ return (loc >= me->module_core_rx &&
7158+ loc < (me->module_core_rx + me->core_size_rx));
7159+}
7160+
7161+static inline int in_core_rw(struct module *me, void *loc)
7162+{
7163+ return (loc >= me->module_core_rw &&
7164+ loc < (me->module_core_rw + me->core_size_rw));
7165 }
7166
7167 static inline int in_core(struct module *me, void *loc)
7168 {
7169- return (loc >= me->module_core &&
7170- loc <= (me->module_core + me->core_size));
7171+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7172 }
7173
7174 static inline int in_local(struct module *me, void *loc)
7175@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7176 }
7177
7178 /* align things a bit */
7179- me->core_size = ALIGN(me->core_size, 16);
7180- me->arch.got_offset = me->core_size;
7181- me->core_size += gots * sizeof(struct got_entry);
7182+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7183+ me->arch.got_offset = me->core_size_rw;
7184+ me->core_size_rw += gots * sizeof(struct got_entry);
7185
7186- me->core_size = ALIGN(me->core_size, 16);
7187- me->arch.fdesc_offset = me->core_size;
7188- me->core_size += fdescs * sizeof(Elf_Fdesc);
7189+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7190+ me->arch.fdesc_offset = me->core_size_rw;
7191+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7192
7193 me->arch.got_max = gots;
7194 me->arch.fdesc_max = fdescs;
7195@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7196
7197 BUG_ON(value == 0);
7198
7199- got = me->module_core + me->arch.got_offset;
7200+ got = me->module_core_rw + me->arch.got_offset;
7201 for (i = 0; got[i].addr; i++)
7202 if (got[i].addr == value)
7203 goto out;
7204@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7205 #ifdef CONFIG_64BIT
7206 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7207 {
7208- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7209+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7210
7211 if (!value) {
7212 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7213@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7214
7215 /* Create new one */
7216 fdesc->addr = value;
7217- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7218+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7219 return (Elf_Addr)fdesc;
7220 }
7221 #endif /* CONFIG_64BIT */
7222@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7223
7224 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7225 end = table + sechdrs[me->arch.unwind_section].sh_size;
7226- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7227+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7228
7229 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7230 me->arch.unwind_section, table, end, gp);
7231diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7232index 5dfd248..64914ac 100644
7233--- a/arch/parisc/kernel/sys_parisc.c
7234+++ b/arch/parisc/kernel/sys_parisc.c
7235@@ -33,9 +33,11 @@
7236 #include <linux/utsname.h>
7237 #include <linux/personality.h>
7238
7239-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7240+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7241+ unsigned long flags)
7242 {
7243 struct vm_unmapped_area_info info;
7244+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7245
7246 info.flags = 0;
7247 info.length = len;
7248@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7249 info.high_limit = TASK_SIZE;
7250 info.align_mask = 0;
7251 info.align_offset = 0;
7252+ info.threadstack_offset = offset;
7253 return vm_unmapped_area(&info);
7254 }
7255
7256@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7257 return (unsigned long) mapping >> 8;
7258 }
7259
7260-static unsigned long get_shared_area(struct address_space *mapping,
7261- unsigned long addr, unsigned long len, unsigned long pgoff)
7262+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7263+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7264 {
7265 struct vm_unmapped_area_info info;
7266+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7267
7268 info.flags = 0;
7269 info.length = len;
7270@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7271 info.high_limit = TASK_SIZE;
7272 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7273 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7274+ info.threadstack_offset = offset;
7275 return vm_unmapped_area(&info);
7276 }
7277
7278@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7279 return -EINVAL;
7280 return addr;
7281 }
7282- if (!addr)
7283+ if (!addr) {
7284 addr = TASK_UNMAPPED_BASE;
7285
7286+#ifdef CONFIG_PAX_RANDMMAP
7287+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7288+ addr += current->mm->delta_mmap;
7289+#endif
7290+
7291+ }
7292+
7293 if (filp) {
7294- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7295+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7296 } else if(flags & MAP_SHARED) {
7297- addr = get_shared_area(NULL, addr, len, pgoff);
7298+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7299 } else {
7300- addr = get_unshared_area(addr, len);
7301+ addr = get_unshared_area(filp, addr, len, flags);
7302 }
7303 return addr;
7304 }
7305diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7306index 1cd1d0c..44ec918 100644
7307--- a/arch/parisc/kernel/traps.c
7308+++ b/arch/parisc/kernel/traps.c
7309@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7310
7311 down_read(&current->mm->mmap_sem);
7312 vma = find_vma(current->mm,regs->iaoq[0]);
7313- if (vma && (regs->iaoq[0] >= vma->vm_start)
7314- && (vma->vm_flags & VM_EXEC)) {
7315-
7316+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7317 fault_address = regs->iaoq[0];
7318 fault_space = regs->iasq[0];
7319
7320diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7321index 0293588..3b229aa 100644
7322--- a/arch/parisc/mm/fault.c
7323+++ b/arch/parisc/mm/fault.c
7324@@ -15,6 +15,7 @@
7325 #include <linux/sched.h>
7326 #include <linux/interrupt.h>
7327 #include <linux/module.h>
7328+#include <linux/unistd.h>
7329
7330 #include <asm/uaccess.h>
7331 #include <asm/traps.h>
7332@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7333 static unsigned long
7334 parisc_acctyp(unsigned long code, unsigned int inst)
7335 {
7336- if (code == 6 || code == 16)
7337+ if (code == 6 || code == 7 || code == 16)
7338 return VM_EXEC;
7339
7340 switch (inst & 0xf0000000) {
7341@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7342 }
7343 #endif
7344
7345+#ifdef CONFIG_PAX_PAGEEXEC
7346+/*
7347+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7348+ *
7349+ * returns 1 when task should be killed
7350+ * 2 when rt_sigreturn trampoline was detected
7351+ * 3 when unpatched PLT trampoline was detected
7352+ */
7353+static int pax_handle_fetch_fault(struct pt_regs *regs)
7354+{
7355+
7356+#ifdef CONFIG_PAX_EMUPLT
7357+ int err;
7358+
7359+ do { /* PaX: unpatched PLT emulation */
7360+ unsigned int bl, depwi;
7361+
7362+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7363+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7364+
7365+ if (err)
7366+ break;
7367+
7368+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7369+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7370+
7371+ err = get_user(ldw, (unsigned int *)addr);
7372+ err |= get_user(bv, (unsigned int *)(addr+4));
7373+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7374+
7375+ if (err)
7376+ break;
7377+
7378+ if (ldw == 0x0E801096U &&
7379+ bv == 0xEAC0C000U &&
7380+ ldw2 == 0x0E881095U)
7381+ {
7382+ unsigned int resolver, map;
7383+
7384+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7385+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7386+ if (err)
7387+ break;
7388+
7389+ regs->gr[20] = instruction_pointer(regs)+8;
7390+ regs->gr[21] = map;
7391+ regs->gr[22] = resolver;
7392+ regs->iaoq[0] = resolver | 3UL;
7393+ regs->iaoq[1] = regs->iaoq[0] + 4;
7394+ return 3;
7395+ }
7396+ }
7397+ } while (0);
7398+#endif
7399+
7400+#ifdef CONFIG_PAX_EMUTRAMP
7401+
7402+#ifndef CONFIG_PAX_EMUSIGRT
7403+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7404+ return 1;
7405+#endif
7406+
7407+ do { /* PaX: rt_sigreturn emulation */
7408+ unsigned int ldi1, ldi2, bel, nop;
7409+
7410+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7411+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7412+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7413+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7414+
7415+ if (err)
7416+ break;
7417+
7418+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7419+ ldi2 == 0x3414015AU &&
7420+ bel == 0xE4008200U &&
7421+ nop == 0x08000240U)
7422+ {
7423+ regs->gr[25] = (ldi1 & 2) >> 1;
7424+ regs->gr[20] = __NR_rt_sigreturn;
7425+ regs->gr[31] = regs->iaoq[1] + 16;
7426+ regs->sr[0] = regs->iasq[1];
7427+ regs->iaoq[0] = 0x100UL;
7428+ regs->iaoq[1] = regs->iaoq[0] + 4;
7429+ regs->iasq[0] = regs->sr[2];
7430+ regs->iasq[1] = regs->sr[2];
7431+ return 2;
7432+ }
7433+ } while (0);
7434+#endif
7435+
7436+ return 1;
7437+}
7438+
7439+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7440+{
7441+ unsigned long i;
7442+
7443+ printk(KERN_ERR "PAX: bytes at PC: ");
7444+ for (i = 0; i < 5; i++) {
7445+ unsigned int c;
7446+ if (get_user(c, (unsigned int *)pc+i))
7447+ printk(KERN_CONT "???????? ");
7448+ else
7449+ printk(KERN_CONT "%08x ", c);
7450+ }
7451+ printk("\n");
7452+}
7453+#endif
7454+
7455 int fixup_exception(struct pt_regs *regs)
7456 {
7457 const struct exception_table_entry *fix;
7458@@ -204,8 +315,33 @@ retry:
7459
7460 good_area:
7461
7462- if ((vma->vm_flags & acc_type) != acc_type)
7463+ if ((vma->vm_flags & acc_type) != acc_type) {
7464+
7465+#ifdef CONFIG_PAX_PAGEEXEC
7466+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7467+ (address & ~3UL) == instruction_pointer(regs))
7468+ {
7469+ up_read(&mm->mmap_sem);
7470+ switch (pax_handle_fetch_fault(regs)) {
7471+
7472+#ifdef CONFIG_PAX_EMUPLT
7473+ case 3:
7474+ return;
7475+#endif
7476+
7477+#ifdef CONFIG_PAX_EMUTRAMP
7478+ case 2:
7479+ return;
7480+#endif
7481+
7482+ }
7483+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7484+ do_group_exit(SIGKILL);
7485+ }
7486+#endif
7487+
7488 goto bad_area;
7489+ }
7490
7491 /*
7492 * If for any reason at all we couldn't handle the fault, make
7493diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7494index 38f3b7e..7e485c0 100644
7495--- a/arch/powerpc/Kconfig
7496+++ b/arch/powerpc/Kconfig
7497@@ -378,6 +378,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7498 config KEXEC
7499 bool "kexec system call"
7500 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7501+ depends on !GRKERNSEC_KMEM
7502 help
7503 kexec is a system call that implements the ability to shutdown your
7504 current kernel, and to start another kernel. It is like a reboot
7505diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7506index e3b1d41..8e81edf 100644
7507--- a/arch/powerpc/include/asm/atomic.h
7508+++ b/arch/powerpc/include/asm/atomic.h
7509@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7510 return t1;
7511 }
7512
7513+#define atomic64_read_unchecked(v) atomic64_read(v)
7514+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7515+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7516+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7517+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7518+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7519+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7520+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7521+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7522+
7523 #endif /* __powerpc64__ */
7524
7525 #endif /* __KERNEL__ */
7526diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7527index 9e495c9..b6878e5 100644
7528--- a/arch/powerpc/include/asm/cache.h
7529+++ b/arch/powerpc/include/asm/cache.h
7530@@ -3,6 +3,7 @@
7531
7532 #ifdef __KERNEL__
7533
7534+#include <linux/const.h>
7535
7536 /* bytes per L1 cache line */
7537 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7538@@ -22,7 +23,7 @@
7539 #define L1_CACHE_SHIFT 7
7540 #endif
7541
7542-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7543+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544
7545 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7546
7547diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7548index cc0655a..13eac2e 100644
7549--- a/arch/powerpc/include/asm/elf.h
7550+++ b/arch/powerpc/include/asm/elf.h
7551@@ -28,8 +28,19 @@
7552 the loader. We need to make sure that it is out of the way of the program
7553 that it will "exec", and that there is sufficient room for the brk. */
7554
7555-extern unsigned long randomize_et_dyn(unsigned long base);
7556-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7557+#define ELF_ET_DYN_BASE (0x20000000)
7558+
7559+#ifdef CONFIG_PAX_ASLR
7560+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7561+
7562+#ifdef __powerpc64__
7563+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7564+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7565+#else
7566+#define PAX_DELTA_MMAP_LEN 15
7567+#define PAX_DELTA_STACK_LEN 15
7568+#endif
7569+#endif
7570
7571 /*
7572 * Our registers are always unsigned longs, whether we're a 32 bit
7573@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7574 (0x7ff >> (PAGE_SHIFT - 12)) : \
7575 (0x3ffff >> (PAGE_SHIFT - 12)))
7576
7577-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7578-#define arch_randomize_brk arch_randomize_brk
7579-
7580-
7581 #ifdef CONFIG_SPU_BASE
7582 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7583 #define NT_SPU 1
7584diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7585index 8196e9c..d83a9f3 100644
7586--- a/arch/powerpc/include/asm/exec.h
7587+++ b/arch/powerpc/include/asm/exec.h
7588@@ -4,6 +4,6 @@
7589 #ifndef _ASM_POWERPC_EXEC_H
7590 #define _ASM_POWERPC_EXEC_H
7591
7592-extern unsigned long arch_align_stack(unsigned long sp);
7593+#define arch_align_stack(x) ((x) & ~0xfUL)
7594
7595 #endif /* _ASM_POWERPC_EXEC_H */
7596diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7597index 5acabbd..7ea14fa 100644
7598--- a/arch/powerpc/include/asm/kmap_types.h
7599+++ b/arch/powerpc/include/asm/kmap_types.h
7600@@ -10,7 +10,7 @@
7601 * 2 of the License, or (at your option) any later version.
7602 */
7603
7604-#define KM_TYPE_NR 16
7605+#define KM_TYPE_NR 17
7606
7607 #endif /* __KERNEL__ */
7608 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7609diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7610index 8565c25..2865190 100644
7611--- a/arch/powerpc/include/asm/mman.h
7612+++ b/arch/powerpc/include/asm/mman.h
7613@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7614 }
7615 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7616
7617-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7618+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7619 {
7620 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7621 }
7622diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7623index b9f4262..dcf04f7 100644
7624--- a/arch/powerpc/include/asm/page.h
7625+++ b/arch/powerpc/include/asm/page.h
7626@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7627 * and needs to be executable. This means the whole heap ends
7628 * up being executable.
7629 */
7630-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7631- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7632+#define VM_DATA_DEFAULT_FLAGS32 \
7633+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7634+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7635
7636 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7637 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7638@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7639 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7640 #endif
7641
7642+#define ktla_ktva(addr) (addr)
7643+#define ktva_ktla(addr) (addr)
7644+
7645 #ifndef CONFIG_PPC_BOOK3S_64
7646 /*
7647 * Use the top bit of the higher-level page table entries to indicate whether
7648diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7649index 88693ce..ac6f9ab 100644
7650--- a/arch/powerpc/include/asm/page_64.h
7651+++ b/arch/powerpc/include/asm/page_64.h
7652@@ -153,15 +153,18 @@ do { \
7653 * stack by default, so in the absence of a PT_GNU_STACK program header
7654 * we turn execute permission off.
7655 */
7656-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7657- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7658+#define VM_STACK_DEFAULT_FLAGS32 \
7659+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7660+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7661
7662 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7663 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7664
7665+#ifndef CONFIG_PAX_PAGEEXEC
7666 #define VM_STACK_DEFAULT_FLAGS \
7667 (is_32bit_task() ? \
7668 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7669+#endif
7670
7671 #include <asm-generic/getorder.h>
7672
7673diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7674index f65e27b..23ffb5b 100644
7675--- a/arch/powerpc/include/asm/pgalloc-64.h
7676+++ b/arch/powerpc/include/asm/pgalloc-64.h
7677@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7678 #ifndef CONFIG_PPC_64K_PAGES
7679
7680 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7681+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7682
7683 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7684 {
7685@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7686 pud_set(pud, (unsigned long)pmd);
7687 }
7688
7689+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7690+{
7691+ pud_populate(mm, pud, pmd);
7692+}
7693+
7694 #define pmd_populate(mm, pmd, pte_page) \
7695 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7696 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7697@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7698 #endif
7699
7700 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7701+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7702
7703 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7704 pte_t *pte)
7705diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7706index 7d6eacf..14c0240 100644
7707--- a/arch/powerpc/include/asm/pgtable.h
7708+++ b/arch/powerpc/include/asm/pgtable.h
7709@@ -2,6 +2,7 @@
7710 #define _ASM_POWERPC_PGTABLE_H
7711 #ifdef __KERNEL__
7712
7713+#include <linux/const.h>
7714 #ifndef __ASSEMBLY__
7715 #include <asm/processor.h> /* For TASK_SIZE */
7716 #include <asm/mmu.h>
7717diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7718index 4aad413..85d86bf 100644
7719--- a/arch/powerpc/include/asm/pte-hash32.h
7720+++ b/arch/powerpc/include/asm/pte-hash32.h
7721@@ -21,6 +21,7 @@
7722 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7723 #define _PAGE_USER 0x004 /* usermode access allowed */
7724 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7725+#define _PAGE_EXEC _PAGE_GUARDED
7726 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7727 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7728 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7729diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7730index 10d1ef0..8f83abc 100644
7731--- a/arch/powerpc/include/asm/reg.h
7732+++ b/arch/powerpc/include/asm/reg.h
7733@@ -234,6 +234,7 @@
7734 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7735 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7736 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7737+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7738 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7739 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7740 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7741diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7742index 98da78e..dc68271 100644
7743--- a/arch/powerpc/include/asm/smp.h
7744+++ b/arch/powerpc/include/asm/smp.h
7745@@ -50,7 +50,7 @@ struct smp_ops_t {
7746 int (*cpu_disable)(void);
7747 void (*cpu_die)(unsigned int nr);
7748 int (*cpu_bootable)(unsigned int nr);
7749-};
7750+} __no_const;
7751
7752 extern void smp_send_debugger_break(void);
7753 extern void start_secondary_resume(void);
7754diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7755index ba7b197..d292e26 100644
7756--- a/arch/powerpc/include/asm/thread_info.h
7757+++ b/arch/powerpc/include/asm/thread_info.h
7758@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7759 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7760 TIF_NEED_RESCHED */
7761 #define TIF_32BIT 4 /* 32 bit binary */
7762-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7763 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7764 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7765 #define TIF_SINGLESTEP 8 /* singlestepping active */
7766@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7767 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7768 for stack store? */
7769 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7770+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7771+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7772+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7773
7774 /* as above, but as bit values */
7775 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7776@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7777 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7778 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7779 #define _TIF_NOHZ (1<<TIF_NOHZ)
7780+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7781 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7782 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7783- _TIF_NOHZ)
7784+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7785
7786 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7787 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7788diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7789index 9485b43..4718d50 100644
7790--- a/arch/powerpc/include/asm/uaccess.h
7791+++ b/arch/powerpc/include/asm/uaccess.h
7792@@ -318,52 +318,6 @@ do { \
7793 extern unsigned long __copy_tofrom_user(void __user *to,
7794 const void __user *from, unsigned long size);
7795
7796-#ifndef __powerpc64__
7797-
7798-static inline unsigned long copy_from_user(void *to,
7799- const void __user *from, unsigned long n)
7800-{
7801- unsigned long over;
7802-
7803- if (access_ok(VERIFY_READ, from, n))
7804- return __copy_tofrom_user((__force void __user *)to, from, n);
7805- if ((unsigned long)from < TASK_SIZE) {
7806- over = (unsigned long)from + n - TASK_SIZE;
7807- return __copy_tofrom_user((__force void __user *)to, from,
7808- n - over) + over;
7809- }
7810- return n;
7811-}
7812-
7813-static inline unsigned long copy_to_user(void __user *to,
7814- const void *from, unsigned long n)
7815-{
7816- unsigned long over;
7817-
7818- if (access_ok(VERIFY_WRITE, to, n))
7819- return __copy_tofrom_user(to, (__force void __user *)from, n);
7820- if ((unsigned long)to < TASK_SIZE) {
7821- over = (unsigned long)to + n - TASK_SIZE;
7822- return __copy_tofrom_user(to, (__force void __user *)from,
7823- n - over) + over;
7824- }
7825- return n;
7826-}
7827-
7828-#else /* __powerpc64__ */
7829-
7830-#define __copy_in_user(to, from, size) \
7831- __copy_tofrom_user((to), (from), (size))
7832-
7833-extern unsigned long copy_from_user(void *to, const void __user *from,
7834- unsigned long n);
7835-extern unsigned long copy_to_user(void __user *to, const void *from,
7836- unsigned long n);
7837-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7838- unsigned long n);
7839-
7840-#endif /* __powerpc64__ */
7841-
7842 static inline unsigned long __copy_from_user_inatomic(void *to,
7843 const void __user *from, unsigned long n)
7844 {
7845@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7846 if (ret == 0)
7847 return 0;
7848 }
7849+
7850+ if (!__builtin_constant_p(n))
7851+ check_object_size(to, n, false);
7852+
7853 return __copy_tofrom_user((__force void __user *)to, from, n);
7854 }
7855
7856@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7857 if (ret == 0)
7858 return 0;
7859 }
7860+
7861+ if (!__builtin_constant_p(n))
7862+ check_object_size(from, n, true);
7863+
7864 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7865 }
7866
7867@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7868 return __copy_to_user_inatomic(to, from, size);
7869 }
7870
7871+#ifndef __powerpc64__
7872+
7873+static inline unsigned long __must_check copy_from_user(void *to,
7874+ const void __user *from, unsigned long n)
7875+{
7876+ unsigned long over;
7877+
7878+ if ((long)n < 0)
7879+ return n;
7880+
7881+ if (access_ok(VERIFY_READ, from, n)) {
7882+ if (!__builtin_constant_p(n))
7883+ check_object_size(to, n, false);
7884+ return __copy_tofrom_user((__force void __user *)to, from, n);
7885+ }
7886+ if ((unsigned long)from < TASK_SIZE) {
7887+ over = (unsigned long)from + n - TASK_SIZE;
7888+ if (!__builtin_constant_p(n - over))
7889+ check_object_size(to, n - over, false);
7890+ return __copy_tofrom_user((__force void __user *)to, from,
7891+ n - over) + over;
7892+ }
7893+ return n;
7894+}
7895+
7896+static inline unsigned long __must_check copy_to_user(void __user *to,
7897+ const void *from, unsigned long n)
7898+{
7899+ unsigned long over;
7900+
7901+ if ((long)n < 0)
7902+ return n;
7903+
7904+ if (access_ok(VERIFY_WRITE, to, n)) {
7905+ if (!__builtin_constant_p(n))
7906+ check_object_size(from, n, true);
7907+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7908+ }
7909+ if ((unsigned long)to < TASK_SIZE) {
7910+ over = (unsigned long)to + n - TASK_SIZE;
7911+ if (!__builtin_constant_p(n))
7912+ check_object_size(from, n - over, true);
7913+ return __copy_tofrom_user(to, (__force void __user *)from,
7914+ n - over) + over;
7915+ }
7916+ return n;
7917+}
7918+
7919+#else /* __powerpc64__ */
7920+
7921+#define __copy_in_user(to, from, size) \
7922+ __copy_tofrom_user((to), (from), (size))
7923+
7924+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7925+{
7926+ if ((long)n < 0 || n > INT_MAX)
7927+ return n;
7928+
7929+ if (!__builtin_constant_p(n))
7930+ check_object_size(to, n, false);
7931+
7932+ if (likely(access_ok(VERIFY_READ, from, n)))
7933+ n = __copy_from_user(to, from, n);
7934+ else
7935+ memset(to, 0, n);
7936+ return n;
7937+}
7938+
7939+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7940+{
7941+ if ((long)n < 0 || n > INT_MAX)
7942+ return n;
7943+
7944+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7945+ if (!__builtin_constant_p(n))
7946+ check_object_size(from, n, true);
7947+ n = __copy_to_user(to, from, n);
7948+ }
7949+ return n;
7950+}
7951+
7952+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7953+ unsigned long n);
7954+
7955+#endif /* __powerpc64__ */
7956+
7957 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7958
7959 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7960diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7961index 2d06704..1616f1b 100644
7962--- a/arch/powerpc/kernel/exceptions-64e.S
7963+++ b/arch/powerpc/kernel/exceptions-64e.S
7964@@ -757,6 +757,7 @@ storage_fault_common:
7965 std r14,_DAR(r1)
7966 std r15,_DSISR(r1)
7967 addi r3,r1,STACK_FRAME_OVERHEAD
7968+ bl .save_nvgprs
7969 mr r4,r14
7970 mr r5,r15
7971 ld r14,PACA_EXGEN+EX_R14(r13)
7972@@ -765,8 +766,7 @@ storage_fault_common:
7973 cmpdi r3,0
7974 bne- 1f
7975 b .ret_from_except_lite
7976-1: bl .save_nvgprs
7977- mr r5,r3
7978+1: mr r5,r3
7979 addi r3,r1,STACK_FRAME_OVERHEAD
7980 ld r4,_DAR(r1)
7981 bl .bad_page_fault
7982diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7983index 3a9ed6a..b534681 100644
7984--- a/arch/powerpc/kernel/exceptions-64s.S
7985+++ b/arch/powerpc/kernel/exceptions-64s.S
7986@@ -1364,10 +1364,10 @@ handle_page_fault:
7987 11: ld r4,_DAR(r1)
7988 ld r5,_DSISR(r1)
7989 addi r3,r1,STACK_FRAME_OVERHEAD
7990+ bl .save_nvgprs
7991 bl .do_page_fault
7992 cmpdi r3,0
7993 beq+ 12f
7994- bl .save_nvgprs
7995 mr r5,r3
7996 addi r3,r1,STACK_FRAME_OVERHEAD
7997 lwz r4,_DAR(r1)
7998diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7999index 2e3200c..72095ce 100644
8000--- a/arch/powerpc/kernel/module_32.c
8001+++ b/arch/powerpc/kernel/module_32.c
8002@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8003 me->arch.core_plt_section = i;
8004 }
8005 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8006- printk("Module doesn't contain .plt or .init.plt sections.\n");
8007+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8008 return -ENOEXEC;
8009 }
8010
8011@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
8012
8013 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8014 /* Init, or core PLT? */
8015- if (location >= mod->module_core
8016- && location < mod->module_core + mod->core_size)
8017+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8018+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8019 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8020- else
8021+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8022+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8023 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8024+ else {
8025+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8026+ return ~0UL;
8027+ }
8028
8029 /* Find this entry, or if that fails, the next avail. entry */
8030 while (entry->jump[0]) {
8031diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8032index 96d2fdf..f6d10c8 100644
8033--- a/arch/powerpc/kernel/process.c
8034+++ b/arch/powerpc/kernel/process.c
8035@@ -886,8 +886,8 @@ void show_regs(struct pt_regs * regs)
8036 * Lookup NIP late so we have the best change of getting the
8037 * above info out without failing
8038 */
8039- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8040- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8041+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8042+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8043 #endif
8044 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8045 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8046@@ -1352,10 +1352,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8047 newsp = stack[0];
8048 ip = stack[STACK_FRAME_LR_SAVE];
8049 if (!firstframe || ip != lr) {
8050- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8051+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8052 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8053 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8054- printk(" (%pS)",
8055+ printk(" (%pA)",
8056 (void *)current->ret_stack[curr_frame].ret);
8057 curr_frame--;
8058 }
8059@@ -1375,7 +1375,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8060 struct pt_regs *regs = (struct pt_regs *)
8061 (sp + STACK_FRAME_OVERHEAD);
8062 lr = regs->link;
8063- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8064+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8065 regs->trap, (void *)regs->nip, (void *)lr);
8066 firstframe = 1;
8067 }
8068@@ -1411,58 +1411,3 @@ void notrace __ppc64_runlatch_off(void)
8069 mtspr(SPRN_CTRLT, ctrl);
8070 }
8071 #endif /* CONFIG_PPC64 */
8072-
8073-unsigned long arch_align_stack(unsigned long sp)
8074-{
8075- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8076- sp -= get_random_int() & ~PAGE_MASK;
8077- return sp & ~0xf;
8078-}
8079-
8080-static inline unsigned long brk_rnd(void)
8081-{
8082- unsigned long rnd = 0;
8083-
8084- /* 8MB for 32bit, 1GB for 64bit */
8085- if (is_32bit_task())
8086- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8087- else
8088- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8089-
8090- return rnd << PAGE_SHIFT;
8091-}
8092-
8093-unsigned long arch_randomize_brk(struct mm_struct *mm)
8094-{
8095- unsigned long base = mm->brk;
8096- unsigned long ret;
8097-
8098-#ifdef CONFIG_PPC_STD_MMU_64
8099- /*
8100- * If we are using 1TB segments and we are allowed to randomise
8101- * the heap, we can put it above 1TB so it is backed by a 1TB
8102- * segment. Otherwise the heap will be in the bottom 1TB
8103- * which always uses 256MB segments and this may result in a
8104- * performance penalty.
8105- */
8106- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8107- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8108-#endif
8109-
8110- ret = PAGE_ALIGN(base + brk_rnd());
8111-
8112- if (ret < mm->brk)
8113- return mm->brk;
8114-
8115- return ret;
8116-}
8117-
8118-unsigned long randomize_et_dyn(unsigned long base)
8119-{
8120- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8121-
8122- if (ret < base)
8123- return base;
8124-
8125- return ret;
8126-}
8127diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8128index 9a0d24c..e7fbedf 100644
8129--- a/arch/powerpc/kernel/ptrace.c
8130+++ b/arch/powerpc/kernel/ptrace.c
8131@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8132 return ret;
8133 }
8134
8135+#ifdef CONFIG_GRKERNSEC_SETXID
8136+extern void gr_delayed_cred_worker(void);
8137+#endif
8138+
8139 /*
8140 * We must return the syscall number to actually look up in the table.
8141 * This can be -1L to skip running any syscall at all.
8142@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8143
8144 secure_computing_strict(regs->gpr[0]);
8145
8146+#ifdef CONFIG_GRKERNSEC_SETXID
8147+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8148+ gr_delayed_cred_worker();
8149+#endif
8150+
8151 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8152 tracehook_report_syscall_entry(regs))
8153 /*
8154@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8155 {
8156 int step;
8157
8158+#ifdef CONFIG_GRKERNSEC_SETXID
8159+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8160+ gr_delayed_cred_worker();
8161+#endif
8162+
8163 audit_syscall_exit(regs);
8164
8165 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8166diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8167index 36d49e6..9147e39d 100644
8168--- a/arch/powerpc/kernel/signal_32.c
8169+++ b/arch/powerpc/kernel/signal_32.c
8170@@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8171 /* Save user registers on the stack */
8172 frame = &rt_sf->uc.uc_mcontext;
8173 addr = frame;
8174- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8175+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8176 sigret = 0;
8177 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8178 } else {
8179diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8180index f93ec28..97e0fbb 100644
8181--- a/arch/powerpc/kernel/signal_64.c
8182+++ b/arch/powerpc/kernel/signal_64.c
8183@@ -757,7 +757,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8184 #endif
8185
8186 /* Set up to return from userspace. */
8187- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8188+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8189 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8190 } else {
8191 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8192diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8193index f783c93..619baf1 100644
8194--- a/arch/powerpc/kernel/traps.c
8195+++ b/arch/powerpc/kernel/traps.c
8196@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8197 return flags;
8198 }
8199
8200+extern void gr_handle_kernel_exploit(void);
8201+
8202 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8203 int signr)
8204 {
8205@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8206 panic("Fatal exception in interrupt");
8207 if (panic_on_oops)
8208 panic("Fatal exception");
8209+
8210+ gr_handle_kernel_exploit();
8211+
8212 do_exit(signr);
8213 }
8214
8215diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8216index 1d9c926..25f4741 100644
8217--- a/arch/powerpc/kernel/vdso.c
8218+++ b/arch/powerpc/kernel/vdso.c
8219@@ -34,6 +34,7 @@
8220 #include <asm/firmware.h>
8221 #include <asm/vdso.h>
8222 #include <asm/vdso_datapage.h>
8223+#include <asm/mman.h>
8224
8225 #include "setup.h"
8226
8227@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8228 vdso_base = VDSO32_MBASE;
8229 #endif
8230
8231- current->mm->context.vdso_base = 0;
8232+ current->mm->context.vdso_base = ~0UL;
8233
8234 /* vDSO has a problem and was disabled, just don't "enable" it for the
8235 * process
8236@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8237 vdso_base = get_unmapped_area(NULL, vdso_base,
8238 (vdso_pages << PAGE_SHIFT) +
8239 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8240- 0, 0);
8241+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8242 if (IS_ERR_VALUE(vdso_base)) {
8243 rc = vdso_base;
8244 goto fail_mmapsem;
8245diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8246index 5eea6f3..5d10396 100644
8247--- a/arch/powerpc/lib/usercopy_64.c
8248+++ b/arch/powerpc/lib/usercopy_64.c
8249@@ -9,22 +9,6 @@
8250 #include <linux/module.h>
8251 #include <asm/uaccess.h>
8252
8253-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8254-{
8255- if (likely(access_ok(VERIFY_READ, from, n)))
8256- n = __copy_from_user(to, from, n);
8257- else
8258- memset(to, 0, n);
8259- return n;
8260-}
8261-
8262-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8263-{
8264- if (likely(access_ok(VERIFY_WRITE, to, n)))
8265- n = __copy_to_user(to, from, n);
8266- return n;
8267-}
8268-
8269 unsigned long copy_in_user(void __user *to, const void __user *from,
8270 unsigned long n)
8271 {
8272@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8273 return n;
8274 }
8275
8276-EXPORT_SYMBOL(copy_from_user);
8277-EXPORT_SYMBOL(copy_to_user);
8278 EXPORT_SYMBOL(copy_in_user);
8279
8280diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8281index 51ab9e7..7d3c78b 100644
8282--- a/arch/powerpc/mm/fault.c
8283+++ b/arch/powerpc/mm/fault.c
8284@@ -33,6 +33,10 @@
8285 #include <linux/magic.h>
8286 #include <linux/ratelimit.h>
8287 #include <linux/context_tracking.h>
8288+#include <linux/slab.h>
8289+#include <linux/pagemap.h>
8290+#include <linux/compiler.h>
8291+#include <linux/unistd.h>
8292
8293 #include <asm/firmware.h>
8294 #include <asm/page.h>
8295@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8296 }
8297 #endif
8298
8299+#ifdef CONFIG_PAX_PAGEEXEC
8300+/*
8301+ * PaX: decide what to do with offenders (regs->nip = fault address)
8302+ *
8303+ * returns 1 when task should be killed
8304+ */
8305+static int pax_handle_fetch_fault(struct pt_regs *regs)
8306+{
8307+ return 1;
8308+}
8309+
8310+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8311+{
8312+ unsigned long i;
8313+
8314+ printk(KERN_ERR "PAX: bytes at PC: ");
8315+ for (i = 0; i < 5; i++) {
8316+ unsigned int c;
8317+ if (get_user(c, (unsigned int __user *)pc+i))
8318+ printk(KERN_CONT "???????? ");
8319+ else
8320+ printk(KERN_CONT "%08x ", c);
8321+ }
8322+ printk("\n");
8323+}
8324+#endif
8325+
8326 /*
8327 * Check whether the instruction at regs->nip is a store using
8328 * an update addressing form which will update r1.
8329@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8330 * indicate errors in DSISR but can validly be set in SRR1.
8331 */
8332 if (trap == 0x400)
8333- error_code &= 0x48200000;
8334+ error_code &= 0x58200000;
8335 else
8336 is_write = error_code & DSISR_ISSTORE;
8337 #else
8338@@ -378,7 +409,7 @@ good_area:
8339 * "undefined". Of those that can be set, this is the only
8340 * one which seems bad.
8341 */
8342- if (error_code & 0x10000000)
8343+ if (error_code & DSISR_GUARDED)
8344 /* Guarded storage error. */
8345 goto bad_area;
8346 #endif /* CONFIG_8xx */
8347@@ -393,7 +424,7 @@ good_area:
8348 * processors use the same I/D cache coherency mechanism
8349 * as embedded.
8350 */
8351- if (error_code & DSISR_PROTFAULT)
8352+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8353 goto bad_area;
8354 #endif /* CONFIG_PPC_STD_MMU */
8355
8356@@ -483,6 +514,23 @@ bad_area:
8357 bad_area_nosemaphore:
8358 /* User mode accesses cause a SIGSEGV */
8359 if (user_mode(regs)) {
8360+
8361+#ifdef CONFIG_PAX_PAGEEXEC
8362+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8363+#ifdef CONFIG_PPC_STD_MMU
8364+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8365+#else
8366+ if (is_exec && regs->nip == address) {
8367+#endif
8368+ switch (pax_handle_fetch_fault(regs)) {
8369+ }
8370+
8371+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8372+ do_group_exit(SIGKILL);
8373+ }
8374+ }
8375+#endif
8376+
8377 _exception(SIGSEGV, regs, code, address);
8378 goto bail;
8379 }
8380diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8381index cb8bdbe..d770680 100644
8382--- a/arch/powerpc/mm/mmap.c
8383+++ b/arch/powerpc/mm/mmap.c
8384@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8385 {
8386 unsigned long rnd = 0;
8387
8388+#ifdef CONFIG_PAX_RANDMMAP
8389+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8390+#endif
8391+
8392 if (current->flags & PF_RANDOMIZE) {
8393 /* 8MB for 32bit, 1GB for 64bit */
8394 if (is_32bit_task())
8395@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8396 */
8397 if (mmap_is_legacy()) {
8398 mm->mmap_base = TASK_UNMAPPED_BASE;
8399+
8400+#ifdef CONFIG_PAX_RANDMMAP
8401+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8402+ mm->mmap_base += mm->delta_mmap;
8403+#endif
8404+
8405 mm->get_unmapped_area = arch_get_unmapped_area;
8406 } else {
8407 mm->mmap_base = mmap_base();
8408+
8409+#ifdef CONFIG_PAX_RANDMMAP
8410+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8411+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8412+#endif
8413+
8414 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8415 }
8416 }
8417diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8418index 7ce9cf3..a964087 100644
8419--- a/arch/powerpc/mm/slice.c
8420+++ b/arch/powerpc/mm/slice.c
8421@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8422 if ((mm->task_size - len) < addr)
8423 return 0;
8424 vma = find_vma(mm, addr);
8425- return (!vma || (addr + len) <= vma->vm_start);
8426+ return check_heap_stack_gap(vma, addr, len, 0);
8427 }
8428
8429 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8430@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8431 info.align_offset = 0;
8432
8433 addr = TASK_UNMAPPED_BASE;
8434+
8435+#ifdef CONFIG_PAX_RANDMMAP
8436+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8437+ addr += mm->delta_mmap;
8438+#endif
8439+
8440 while (addr < TASK_SIZE) {
8441 info.low_limit = addr;
8442 if (!slice_scan_available(addr, available, 1, &addr))
8443@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8444 if (fixed && addr > (mm->task_size - len))
8445 return -EINVAL;
8446
8447+#ifdef CONFIG_PAX_RANDMMAP
8448+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8449+ addr = 0;
8450+#endif
8451+
8452 /* If hint, make sure it matches our alignment restrictions */
8453 if (!fixed && addr) {
8454 addr = _ALIGN_UP(addr, 1ul << pshift);
8455diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8456index 9098692..3d54cd1 100644
8457--- a/arch/powerpc/platforms/cell/spufs/file.c
8458+++ b/arch/powerpc/platforms/cell/spufs/file.c
8459@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8460 return VM_FAULT_NOPAGE;
8461 }
8462
8463-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8464+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8465 unsigned long address,
8466- void *buf, int len, int write)
8467+ void *buf, size_t len, int write)
8468 {
8469 struct spu_context *ctx = vma->vm_file->private_data;
8470 unsigned long offset = address - vma->vm_start;
8471diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8472index c797832..ce575c8 100644
8473--- a/arch/s390/include/asm/atomic.h
8474+++ b/arch/s390/include/asm/atomic.h
8475@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8476 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8477 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8478
8479+#define atomic64_read_unchecked(v) atomic64_read(v)
8480+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8481+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8482+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8483+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8484+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8485+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8486+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8487+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8488+
8489 #define smp_mb__before_atomic_dec() smp_mb()
8490 #define smp_mb__after_atomic_dec() smp_mb()
8491 #define smp_mb__before_atomic_inc() smp_mb()
8492diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8493index 4d7ccac..d03d0ad 100644
8494--- a/arch/s390/include/asm/cache.h
8495+++ b/arch/s390/include/asm/cache.h
8496@@ -9,8 +9,10 @@
8497 #ifndef __ARCH_S390_CACHE_H
8498 #define __ARCH_S390_CACHE_H
8499
8500-#define L1_CACHE_BYTES 256
8501+#include <linux/const.h>
8502+
8503 #define L1_CACHE_SHIFT 8
8504+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8505 #define NET_SKB_PAD 32
8506
8507 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8508diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8509index 78f4f87..598ce39 100644
8510--- a/arch/s390/include/asm/elf.h
8511+++ b/arch/s390/include/asm/elf.h
8512@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8513 the loader. We need to make sure that it is out of the way of the program
8514 that it will "exec", and that there is sufficient room for the brk. */
8515
8516-extern unsigned long randomize_et_dyn(unsigned long base);
8517-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8518+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8519+
8520+#ifdef CONFIG_PAX_ASLR
8521+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8522+
8523+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8524+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8525+#endif
8526
8527 /* This yields a mask that user programs can use to figure out what
8528 instruction set this CPU supports. */
8529@@ -222,9 +228,6 @@ struct linux_binprm;
8530 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8531 int arch_setup_additional_pages(struct linux_binprm *, int);
8532
8533-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8534-#define arch_randomize_brk arch_randomize_brk
8535-
8536 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8537
8538 #endif
8539diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8540index c4a93d6..4d2a9b4 100644
8541--- a/arch/s390/include/asm/exec.h
8542+++ b/arch/s390/include/asm/exec.h
8543@@ -7,6 +7,6 @@
8544 #ifndef __ASM_EXEC_H
8545 #define __ASM_EXEC_H
8546
8547-extern unsigned long arch_align_stack(unsigned long sp);
8548+#define arch_align_stack(x) ((x) & ~0xfUL)
8549
8550 #endif /* __ASM_EXEC_H */
8551diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8552index 9c33ed4..e40cbef 100644
8553--- a/arch/s390/include/asm/uaccess.h
8554+++ b/arch/s390/include/asm/uaccess.h
8555@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8556 copy_to_user(void __user *to, const void *from, unsigned long n)
8557 {
8558 might_fault();
8559+
8560+ if ((long)n < 0)
8561+ return n;
8562+
8563 return __copy_to_user(to, from, n);
8564 }
8565
8566@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8567 static inline unsigned long __must_check
8568 __copy_from_user(void *to, const void __user *from, unsigned long n)
8569 {
8570+ if ((long)n < 0)
8571+ return n;
8572+
8573 if (__builtin_constant_p(n) && (n <= 256))
8574 return uaccess.copy_from_user_small(n, from, to);
8575 else
8576@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8577 static inline unsigned long __must_check
8578 copy_from_user(void *to, const void __user *from, unsigned long n)
8579 {
8580- unsigned int sz = __compiletime_object_size(to);
8581+ size_t sz = __compiletime_object_size(to);
8582
8583 might_fault();
8584- if (unlikely(sz != -1 && sz < n)) {
8585+
8586+ if ((long)n < 0)
8587+ return n;
8588+
8589+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8590 copy_from_user_overflow();
8591 return n;
8592 }
8593diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8594index 7845e15..59c4353 100644
8595--- a/arch/s390/kernel/module.c
8596+++ b/arch/s390/kernel/module.c
8597@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8598
8599 /* Increase core size by size of got & plt and set start
8600 offsets for got and plt. */
8601- me->core_size = ALIGN(me->core_size, 4);
8602- me->arch.got_offset = me->core_size;
8603- me->core_size += me->arch.got_size;
8604- me->arch.plt_offset = me->core_size;
8605- me->core_size += me->arch.plt_size;
8606+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8607+ me->arch.got_offset = me->core_size_rw;
8608+ me->core_size_rw += me->arch.got_size;
8609+ me->arch.plt_offset = me->core_size_rx;
8610+ me->core_size_rx += me->arch.plt_size;
8611 return 0;
8612 }
8613
8614@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8615 if (info->got_initialized == 0) {
8616 Elf_Addr *gotent;
8617
8618- gotent = me->module_core + me->arch.got_offset +
8619+ gotent = me->module_core_rw + me->arch.got_offset +
8620 info->got_offset;
8621 *gotent = val;
8622 info->got_initialized = 1;
8623@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8624 rc = apply_rela_bits(loc, val, 0, 64, 0);
8625 else if (r_type == R_390_GOTENT ||
8626 r_type == R_390_GOTPLTENT) {
8627- val += (Elf_Addr) me->module_core - loc;
8628+ val += (Elf_Addr) me->module_core_rw - loc;
8629 rc = apply_rela_bits(loc, val, 1, 32, 1);
8630 }
8631 break;
8632@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8633 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8634 if (info->plt_initialized == 0) {
8635 unsigned int *ip;
8636- ip = me->module_core + me->arch.plt_offset +
8637+ ip = me->module_core_rx + me->arch.plt_offset +
8638 info->plt_offset;
8639 #ifndef CONFIG_64BIT
8640 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8641@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8642 val - loc + 0xffffUL < 0x1ffffeUL) ||
8643 (r_type == R_390_PLT32DBL &&
8644 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8645- val = (Elf_Addr) me->module_core +
8646+ val = (Elf_Addr) me->module_core_rx +
8647 me->arch.plt_offset +
8648 info->plt_offset;
8649 val += rela->r_addend - loc;
8650@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8651 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8652 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8653 val = val + rela->r_addend -
8654- ((Elf_Addr) me->module_core + me->arch.got_offset);
8655+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8656 if (r_type == R_390_GOTOFF16)
8657 rc = apply_rela_bits(loc, val, 0, 16, 0);
8658 else if (r_type == R_390_GOTOFF32)
8659@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8660 break;
8661 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8662 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8663- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8664+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8665 rela->r_addend - loc;
8666 if (r_type == R_390_GOTPC)
8667 rc = apply_rela_bits(loc, val, 1, 32, 0);
8668diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8669index c5dbb33..b41f4ee 100644
8670--- a/arch/s390/kernel/process.c
8671+++ b/arch/s390/kernel/process.c
8672@@ -237,39 +237,3 @@ unsigned long get_wchan(struct task_struct *p)
8673 }
8674 return 0;
8675 }
8676-
8677-unsigned long arch_align_stack(unsigned long sp)
8678-{
8679- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8680- sp -= get_random_int() & ~PAGE_MASK;
8681- return sp & ~0xf;
8682-}
8683-
8684-static inline unsigned long brk_rnd(void)
8685-{
8686- /* 8MB for 32bit, 1GB for 64bit */
8687- if (is_32bit_task())
8688- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8689- else
8690- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8691-}
8692-
8693-unsigned long arch_randomize_brk(struct mm_struct *mm)
8694-{
8695- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8696-
8697- if (ret < mm->brk)
8698- return mm->brk;
8699- return ret;
8700-}
8701-
8702-unsigned long randomize_et_dyn(unsigned long base)
8703-{
8704- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8705-
8706- if (!(current->flags & PF_RANDOMIZE))
8707- return base;
8708- if (ret < base)
8709- return base;
8710- return ret;
8711-}
8712diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8713index 4002329..99b67cb 100644
8714--- a/arch/s390/mm/mmap.c
8715+++ b/arch/s390/mm/mmap.c
8716@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8717 */
8718 if (mmap_is_legacy()) {
8719 mm->mmap_base = TASK_UNMAPPED_BASE;
8720+
8721+#ifdef CONFIG_PAX_RANDMMAP
8722+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8723+ mm->mmap_base += mm->delta_mmap;
8724+#endif
8725+
8726 mm->get_unmapped_area = arch_get_unmapped_area;
8727 } else {
8728 mm->mmap_base = mmap_base();
8729+
8730+#ifdef CONFIG_PAX_RANDMMAP
8731+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8732+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8733+#endif
8734+
8735 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8736 }
8737 }
8738@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8739 */
8740 if (mmap_is_legacy()) {
8741 mm->mmap_base = TASK_UNMAPPED_BASE;
8742+
8743+#ifdef CONFIG_PAX_RANDMMAP
8744+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8745+ mm->mmap_base += mm->delta_mmap;
8746+#endif
8747+
8748 mm->get_unmapped_area = s390_get_unmapped_area;
8749 } else {
8750 mm->mmap_base = mmap_base();
8751+
8752+#ifdef CONFIG_PAX_RANDMMAP
8753+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8754+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8755+#endif
8756+
8757 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8758 }
8759 }
8760diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8761index ae3d59f..f65f075 100644
8762--- a/arch/score/include/asm/cache.h
8763+++ b/arch/score/include/asm/cache.h
8764@@ -1,7 +1,9 @@
8765 #ifndef _ASM_SCORE_CACHE_H
8766 #define _ASM_SCORE_CACHE_H
8767
8768+#include <linux/const.h>
8769+
8770 #define L1_CACHE_SHIFT 4
8771-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8772+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8773
8774 #endif /* _ASM_SCORE_CACHE_H */
8775diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8776index f9f3cd5..58ff438 100644
8777--- a/arch/score/include/asm/exec.h
8778+++ b/arch/score/include/asm/exec.h
8779@@ -1,6 +1,6 @@
8780 #ifndef _ASM_SCORE_EXEC_H
8781 #define _ASM_SCORE_EXEC_H
8782
8783-extern unsigned long arch_align_stack(unsigned long sp);
8784+#define arch_align_stack(x) (x)
8785
8786 #endif /* _ASM_SCORE_EXEC_H */
8787diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8788index a1519ad3..e8ac1ff 100644
8789--- a/arch/score/kernel/process.c
8790+++ b/arch/score/kernel/process.c
8791@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8792
8793 return task_pt_regs(task)->cp0_epc;
8794 }
8795-
8796-unsigned long arch_align_stack(unsigned long sp)
8797-{
8798- return sp;
8799-}
8800diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8801index ef9e555..331bd29 100644
8802--- a/arch/sh/include/asm/cache.h
8803+++ b/arch/sh/include/asm/cache.h
8804@@ -9,10 +9,11 @@
8805 #define __ASM_SH_CACHE_H
8806 #ifdef __KERNEL__
8807
8808+#include <linux/const.h>
8809 #include <linux/init.h>
8810 #include <cpu/cache.h>
8811
8812-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8813+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8814
8815 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8816
8817diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8818index 6777177..cb5e44f 100644
8819--- a/arch/sh/mm/mmap.c
8820+++ b/arch/sh/mm/mmap.c
8821@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8822 struct mm_struct *mm = current->mm;
8823 struct vm_area_struct *vma;
8824 int do_colour_align;
8825+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8826 struct vm_unmapped_area_info info;
8827
8828 if (flags & MAP_FIXED) {
8829@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8830 if (filp || (flags & MAP_SHARED))
8831 do_colour_align = 1;
8832
8833+#ifdef CONFIG_PAX_RANDMMAP
8834+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8835+#endif
8836+
8837 if (addr) {
8838 if (do_colour_align)
8839 addr = COLOUR_ALIGN(addr, pgoff);
8840@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8841 addr = PAGE_ALIGN(addr);
8842
8843 vma = find_vma(mm, addr);
8844- if (TASK_SIZE - len >= addr &&
8845- (!vma || addr + len <= vma->vm_start))
8846+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8847 return addr;
8848 }
8849
8850 info.flags = 0;
8851 info.length = len;
8852- info.low_limit = TASK_UNMAPPED_BASE;
8853+ info.low_limit = mm->mmap_base;
8854 info.high_limit = TASK_SIZE;
8855 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8856 info.align_offset = pgoff << PAGE_SHIFT;
8857@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8858 struct mm_struct *mm = current->mm;
8859 unsigned long addr = addr0;
8860 int do_colour_align;
8861+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8862 struct vm_unmapped_area_info info;
8863
8864 if (flags & MAP_FIXED) {
8865@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8866 if (filp || (flags & MAP_SHARED))
8867 do_colour_align = 1;
8868
8869+#ifdef CONFIG_PAX_RANDMMAP
8870+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8871+#endif
8872+
8873 /* requesting a specific address */
8874 if (addr) {
8875 if (do_colour_align)
8876@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8877 addr = PAGE_ALIGN(addr);
8878
8879 vma = find_vma(mm, addr);
8880- if (TASK_SIZE - len >= addr &&
8881- (!vma || addr + len <= vma->vm_start))
8882+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8883 return addr;
8884 }
8885
8886@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8887 VM_BUG_ON(addr != -ENOMEM);
8888 info.flags = 0;
8889 info.low_limit = TASK_UNMAPPED_BASE;
8890+
8891+#ifdef CONFIG_PAX_RANDMMAP
8892+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8893+ info.low_limit += mm->delta_mmap;
8894+#endif
8895+
8896 info.high_limit = TASK_SIZE;
8897 addr = vm_unmapped_area(&info);
8898 }
8899diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8900index be56a24..443328f 100644
8901--- a/arch/sparc/include/asm/atomic_64.h
8902+++ b/arch/sparc/include/asm/atomic_64.h
8903@@ -14,18 +14,40 @@
8904 #define ATOMIC64_INIT(i) { (i) }
8905
8906 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8907+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8908+{
8909+ return v->counter;
8910+}
8911 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8912+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8913+{
8914+ return v->counter;
8915+}
8916
8917 #define atomic_set(v, i) (((v)->counter) = i)
8918+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8919+{
8920+ v->counter = i;
8921+}
8922 #define atomic64_set(v, i) (((v)->counter) = i)
8923+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8924+{
8925+ v->counter = i;
8926+}
8927
8928 extern void atomic_add(int, atomic_t *);
8929+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8930 extern void atomic64_add(long, atomic64_t *);
8931+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8932 extern void atomic_sub(int, atomic_t *);
8933+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8934 extern void atomic64_sub(long, atomic64_t *);
8935+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8936
8937 extern int atomic_add_ret(int, atomic_t *);
8938+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8939 extern long atomic64_add_ret(long, atomic64_t *);
8940+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8941 extern int atomic_sub_ret(int, atomic_t *);
8942 extern long atomic64_sub_ret(long, atomic64_t *);
8943
8944@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8945 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8946
8947 #define atomic_inc_return(v) atomic_add_ret(1, v)
8948+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8949+{
8950+ return atomic_add_ret_unchecked(1, v);
8951+}
8952 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8953+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8954+{
8955+ return atomic64_add_ret_unchecked(1, v);
8956+}
8957
8958 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8959 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8960
8961 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8962+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8963+{
8964+ return atomic_add_ret_unchecked(i, v);
8965+}
8966 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8967+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8968+{
8969+ return atomic64_add_ret_unchecked(i, v);
8970+}
8971
8972 /*
8973 * atomic_inc_and_test - increment and test
8974@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8975 * other cases.
8976 */
8977 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8978+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8979+{
8980+ return atomic_inc_return_unchecked(v) == 0;
8981+}
8982 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8983
8984 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8985@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8986 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8987
8988 #define atomic_inc(v) atomic_add(1, v)
8989+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8990+{
8991+ atomic_add_unchecked(1, v);
8992+}
8993 #define atomic64_inc(v) atomic64_add(1, v)
8994+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8995+{
8996+ atomic64_add_unchecked(1, v);
8997+}
8998
8999 #define atomic_dec(v) atomic_sub(1, v)
9000+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9001+{
9002+ atomic_sub_unchecked(1, v);
9003+}
9004 #define atomic64_dec(v) atomic64_sub(1, v)
9005+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9006+{
9007+ atomic64_sub_unchecked(1, v);
9008+}
9009
9010 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9011 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9012
9013 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9014+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9015+{
9016+ return cmpxchg(&v->counter, old, new);
9017+}
9018 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9019+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9020+{
9021+ return xchg(&v->counter, new);
9022+}
9023
9024 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9025 {
9026- int c, old;
9027+ int c, old, new;
9028 c = atomic_read(v);
9029 for (;;) {
9030- if (unlikely(c == (u)))
9031+ if (unlikely(c == u))
9032 break;
9033- old = atomic_cmpxchg((v), c, c + (a));
9034+
9035+ asm volatile("addcc %2, %0, %0\n"
9036+
9037+#ifdef CONFIG_PAX_REFCOUNT
9038+ "tvs %%icc, 6\n"
9039+#endif
9040+
9041+ : "=r" (new)
9042+ : "0" (c), "ir" (a)
9043+ : "cc");
9044+
9045+ old = atomic_cmpxchg(v, c, new);
9046 if (likely(old == c))
9047 break;
9048 c = old;
9049@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9050 #define atomic64_cmpxchg(v, o, n) \
9051 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9052 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9053+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9054+{
9055+ return xchg(&v->counter, new);
9056+}
9057
9058 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9059 {
9060- long c, old;
9061+ long c, old, new;
9062 c = atomic64_read(v);
9063 for (;;) {
9064- if (unlikely(c == (u)))
9065+ if (unlikely(c == u))
9066 break;
9067- old = atomic64_cmpxchg((v), c, c + (a));
9068+
9069+ asm volatile("addcc %2, %0, %0\n"
9070+
9071+#ifdef CONFIG_PAX_REFCOUNT
9072+ "tvs %%xcc, 6\n"
9073+#endif
9074+
9075+ : "=r" (new)
9076+ : "0" (c), "ir" (a)
9077+ : "cc");
9078+
9079+ old = atomic64_cmpxchg(v, c, new);
9080 if (likely(old == c))
9081 break;
9082 c = old;
9083 }
9084- return c != (u);
9085+ return c != u;
9086 }
9087
9088 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9089diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9090index 5bb6991..5c2132e 100644
9091--- a/arch/sparc/include/asm/cache.h
9092+++ b/arch/sparc/include/asm/cache.h
9093@@ -7,10 +7,12 @@
9094 #ifndef _SPARC_CACHE_H
9095 #define _SPARC_CACHE_H
9096
9097+#include <linux/const.h>
9098+
9099 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9100
9101 #define L1_CACHE_SHIFT 5
9102-#define L1_CACHE_BYTES 32
9103+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9104
9105 #ifdef CONFIG_SPARC32
9106 #define SMP_CACHE_BYTES_SHIFT 5
9107diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9108index a24e41f..47677ff 100644
9109--- a/arch/sparc/include/asm/elf_32.h
9110+++ b/arch/sparc/include/asm/elf_32.h
9111@@ -114,6 +114,13 @@ typedef struct {
9112
9113 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9114
9115+#ifdef CONFIG_PAX_ASLR
9116+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9117+
9118+#define PAX_DELTA_MMAP_LEN 16
9119+#define PAX_DELTA_STACK_LEN 16
9120+#endif
9121+
9122 /* This yields a mask that user programs can use to figure out what
9123 instruction set this cpu supports. This can NOT be done in userspace
9124 on Sparc. */
9125diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9126index 370ca1e..d4f4a98 100644
9127--- a/arch/sparc/include/asm/elf_64.h
9128+++ b/arch/sparc/include/asm/elf_64.h
9129@@ -189,6 +189,13 @@ typedef struct {
9130 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9131 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9132
9133+#ifdef CONFIG_PAX_ASLR
9134+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9135+
9136+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9137+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9138+#endif
9139+
9140 extern unsigned long sparc64_elf_hwcap;
9141 #define ELF_HWCAP sparc64_elf_hwcap
9142
9143diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9144index 9b1c36d..209298b 100644
9145--- a/arch/sparc/include/asm/pgalloc_32.h
9146+++ b/arch/sparc/include/asm/pgalloc_32.h
9147@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9148 }
9149
9150 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9151+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9152
9153 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9154 unsigned long address)
9155diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9156index bcfe063..b333142 100644
9157--- a/arch/sparc/include/asm/pgalloc_64.h
9158+++ b/arch/sparc/include/asm/pgalloc_64.h
9159@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9160 }
9161
9162 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9163+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9164
9165 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9166 {
9167diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9168index 502f632..da1917f 100644
9169--- a/arch/sparc/include/asm/pgtable_32.h
9170+++ b/arch/sparc/include/asm/pgtable_32.h
9171@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9172 #define PAGE_SHARED SRMMU_PAGE_SHARED
9173 #define PAGE_COPY SRMMU_PAGE_COPY
9174 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9175+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9176+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9177+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9178 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9179
9180 /* Top-level page directory - dummy used by init-mm.
9181@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9182
9183 /* xwr */
9184 #define __P000 PAGE_NONE
9185-#define __P001 PAGE_READONLY
9186-#define __P010 PAGE_COPY
9187-#define __P011 PAGE_COPY
9188+#define __P001 PAGE_READONLY_NOEXEC
9189+#define __P010 PAGE_COPY_NOEXEC
9190+#define __P011 PAGE_COPY_NOEXEC
9191 #define __P100 PAGE_READONLY
9192 #define __P101 PAGE_READONLY
9193 #define __P110 PAGE_COPY
9194 #define __P111 PAGE_COPY
9195
9196 #define __S000 PAGE_NONE
9197-#define __S001 PAGE_READONLY
9198-#define __S010 PAGE_SHARED
9199-#define __S011 PAGE_SHARED
9200+#define __S001 PAGE_READONLY_NOEXEC
9201+#define __S010 PAGE_SHARED_NOEXEC
9202+#define __S011 PAGE_SHARED_NOEXEC
9203 #define __S100 PAGE_READONLY
9204 #define __S101 PAGE_READONLY
9205 #define __S110 PAGE_SHARED
9206diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9207index 79da178..c2eede8 100644
9208--- a/arch/sparc/include/asm/pgtsrmmu.h
9209+++ b/arch/sparc/include/asm/pgtsrmmu.h
9210@@ -115,6 +115,11 @@
9211 SRMMU_EXEC | SRMMU_REF)
9212 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9213 SRMMU_EXEC | SRMMU_REF)
9214+
9215+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9216+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9217+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9218+
9219 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9220 SRMMU_DIRTY | SRMMU_REF)
9221
9222diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9223index 9689176..63c18ea 100644
9224--- a/arch/sparc/include/asm/spinlock_64.h
9225+++ b/arch/sparc/include/asm/spinlock_64.h
9226@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9227
9228 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9229
9230-static void inline arch_read_lock(arch_rwlock_t *lock)
9231+static inline void arch_read_lock(arch_rwlock_t *lock)
9232 {
9233 unsigned long tmp1, tmp2;
9234
9235 __asm__ __volatile__ (
9236 "1: ldsw [%2], %0\n"
9237 " brlz,pn %0, 2f\n"
9238-"4: add %0, 1, %1\n"
9239+"4: addcc %0, 1, %1\n"
9240+
9241+#ifdef CONFIG_PAX_REFCOUNT
9242+" tvs %%icc, 6\n"
9243+#endif
9244+
9245 " cas [%2], %0, %1\n"
9246 " cmp %0, %1\n"
9247 " bne,pn %%icc, 1b\n"
9248@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9249 " .previous"
9250 : "=&r" (tmp1), "=&r" (tmp2)
9251 : "r" (lock)
9252- : "memory");
9253+ : "memory", "cc");
9254 }
9255
9256-static int inline arch_read_trylock(arch_rwlock_t *lock)
9257+static inline int arch_read_trylock(arch_rwlock_t *lock)
9258 {
9259 int tmp1, tmp2;
9260
9261@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9262 "1: ldsw [%2], %0\n"
9263 " brlz,a,pn %0, 2f\n"
9264 " mov 0, %0\n"
9265-" add %0, 1, %1\n"
9266+" addcc %0, 1, %1\n"
9267+
9268+#ifdef CONFIG_PAX_REFCOUNT
9269+" tvs %%icc, 6\n"
9270+#endif
9271+
9272 " cas [%2], %0, %1\n"
9273 " cmp %0, %1\n"
9274 " bne,pn %%icc, 1b\n"
9275@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9276 return tmp1;
9277 }
9278
9279-static void inline arch_read_unlock(arch_rwlock_t *lock)
9280+static inline void arch_read_unlock(arch_rwlock_t *lock)
9281 {
9282 unsigned long tmp1, tmp2;
9283
9284 __asm__ __volatile__(
9285 "1: lduw [%2], %0\n"
9286-" sub %0, 1, %1\n"
9287+" subcc %0, 1, %1\n"
9288+
9289+#ifdef CONFIG_PAX_REFCOUNT
9290+" tvs %%icc, 6\n"
9291+#endif
9292+
9293 " cas [%2], %0, %1\n"
9294 " cmp %0, %1\n"
9295 " bne,pn %%xcc, 1b\n"
9296@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9297 : "memory");
9298 }
9299
9300-static void inline arch_write_lock(arch_rwlock_t *lock)
9301+static inline void arch_write_lock(arch_rwlock_t *lock)
9302 {
9303 unsigned long mask, tmp1, tmp2;
9304
9305@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9306 : "memory");
9307 }
9308
9309-static void inline arch_write_unlock(arch_rwlock_t *lock)
9310+static inline void arch_write_unlock(arch_rwlock_t *lock)
9311 {
9312 __asm__ __volatile__(
9313 " stw %%g0, [%0]"
9314@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9315 : "memory");
9316 }
9317
9318-static int inline arch_write_trylock(arch_rwlock_t *lock)
9319+static inline int arch_write_trylock(arch_rwlock_t *lock)
9320 {
9321 unsigned long mask, tmp1, tmp2, result;
9322
9323diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9324index dd38075..e7cac83 100644
9325--- a/arch/sparc/include/asm/thread_info_32.h
9326+++ b/arch/sparc/include/asm/thread_info_32.h
9327@@ -49,6 +49,8 @@ struct thread_info {
9328 unsigned long w_saved;
9329
9330 struct restart_block restart_block;
9331+
9332+ unsigned long lowest_stack;
9333 };
9334
9335 /*
9336diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9337index d5e5042..9bfee76 100644
9338--- a/arch/sparc/include/asm/thread_info_64.h
9339+++ b/arch/sparc/include/asm/thread_info_64.h
9340@@ -63,6 +63,8 @@ struct thread_info {
9341 struct pt_regs *kern_una_regs;
9342 unsigned int kern_una_insn;
9343
9344+ unsigned long lowest_stack;
9345+
9346 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9347 };
9348
9349@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9350 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9351 /* flag bit 6 is available */
9352 #define TIF_32BIT 7 /* 32-bit binary */
9353-/* flag bit 8 is available */
9354+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9355 #define TIF_SECCOMP 9 /* secure computing */
9356 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9357 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9358+
9359 /* NOTE: Thread flags >= 12 should be ones we have no interest
9360 * in using in assembly, else we can't use the mask as
9361 * an immediate value in instructions such as andcc.
9362@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9363 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9364 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9365 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9366+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9367
9368 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9369 _TIF_DO_NOTIFY_RESUME_MASK | \
9370 _TIF_NEED_RESCHED)
9371 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9372
9373+#define _TIF_WORK_SYSCALL \
9374+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9375+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9376+
9377+
9378 /*
9379 * Thread-synchronous status.
9380 *
9381diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9382index 0167d26..767bb0c 100644
9383--- a/arch/sparc/include/asm/uaccess.h
9384+++ b/arch/sparc/include/asm/uaccess.h
9385@@ -1,5 +1,6 @@
9386 #ifndef ___ASM_SPARC_UACCESS_H
9387 #define ___ASM_SPARC_UACCESS_H
9388+
9389 #if defined(__sparc__) && defined(__arch64__)
9390 #include <asm/uaccess_64.h>
9391 #else
9392diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9393index 53a28dd..50c38c3 100644
9394--- a/arch/sparc/include/asm/uaccess_32.h
9395+++ b/arch/sparc/include/asm/uaccess_32.h
9396@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9397
9398 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9399 {
9400- if (n && __access_ok((unsigned long) to, n))
9401+ if ((long)n < 0)
9402+ return n;
9403+
9404+ if (n && __access_ok((unsigned long) to, n)) {
9405+ if (!__builtin_constant_p(n))
9406+ check_object_size(from, n, true);
9407 return __copy_user(to, (__force void __user *) from, n);
9408- else
9409+ } else
9410 return n;
9411 }
9412
9413 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9414 {
9415+ if ((long)n < 0)
9416+ return n;
9417+
9418+ if (!__builtin_constant_p(n))
9419+ check_object_size(from, n, true);
9420+
9421 return __copy_user(to, (__force void __user *) from, n);
9422 }
9423
9424 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9425 {
9426- if (n && __access_ok((unsigned long) from, n))
9427+ if ((long)n < 0)
9428+ return n;
9429+
9430+ if (n && __access_ok((unsigned long) from, n)) {
9431+ if (!__builtin_constant_p(n))
9432+ check_object_size(to, n, false);
9433 return __copy_user((__force void __user *) to, from, n);
9434- else
9435+ } else
9436 return n;
9437 }
9438
9439 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9440 {
9441+ if ((long)n < 0)
9442+ return n;
9443+
9444 return __copy_user((__force void __user *) to, from, n);
9445 }
9446
9447diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9448index e562d3c..191f176 100644
9449--- a/arch/sparc/include/asm/uaccess_64.h
9450+++ b/arch/sparc/include/asm/uaccess_64.h
9451@@ -10,6 +10,7 @@
9452 #include <linux/compiler.h>
9453 #include <linux/string.h>
9454 #include <linux/thread_info.h>
9455+#include <linux/kernel.h>
9456 #include <asm/asi.h>
9457 #include <asm/spitfire.h>
9458 #include <asm-generic/uaccess-unaligned.h>
9459@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9460 static inline unsigned long __must_check
9461 copy_from_user(void *to, const void __user *from, unsigned long size)
9462 {
9463- unsigned long ret = ___copy_from_user(to, from, size);
9464+ unsigned long ret;
9465
9466+ if ((long)size < 0 || size > INT_MAX)
9467+ return size;
9468+
9469+ if (!__builtin_constant_p(size))
9470+ check_object_size(to, size, false);
9471+
9472+ ret = ___copy_from_user(to, from, size);
9473 if (unlikely(ret))
9474 ret = copy_from_user_fixup(to, from, size);
9475
9476@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9477 static inline unsigned long __must_check
9478 copy_to_user(void __user *to, const void *from, unsigned long size)
9479 {
9480- unsigned long ret = ___copy_to_user(to, from, size);
9481+ unsigned long ret;
9482
9483+ if ((long)size < 0 || size > INT_MAX)
9484+ return size;
9485+
9486+ if (!__builtin_constant_p(size))
9487+ check_object_size(from, size, true);
9488+
9489+ ret = ___copy_to_user(to, from, size);
9490 if (unlikely(ret))
9491 ret = copy_to_user_fixup(to, from, size);
9492 return ret;
9493diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9494index d15cc17..d0ae796 100644
9495--- a/arch/sparc/kernel/Makefile
9496+++ b/arch/sparc/kernel/Makefile
9497@@ -4,7 +4,7 @@
9498 #
9499
9500 asflags-y := -ansi
9501-ccflags-y := -Werror
9502+#ccflags-y := -Werror
9503
9504 extra-y := head_$(BITS).o
9505
9506diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9507index fdd819d..5af08c8 100644
9508--- a/arch/sparc/kernel/process_32.c
9509+++ b/arch/sparc/kernel/process_32.c
9510@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9511
9512 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9513 r->psr, r->pc, r->npc, r->y, print_tainted());
9514- printk("PC: <%pS>\n", (void *) r->pc);
9515+ printk("PC: <%pA>\n", (void *) r->pc);
9516 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9517 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9518 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9519 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9520 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9521 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9522- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9523+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9524
9525 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9526 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9527@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9528 rw = (struct reg_window32 *) fp;
9529 pc = rw->ins[7];
9530 printk("[%08lx : ", pc);
9531- printk("%pS ] ", (void *) pc);
9532+ printk("%pA ] ", (void *) pc);
9533 fp = rw->ins[6];
9534 } while (++count < 16);
9535 printk("\n");
9536diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9537index baebab2..9cd13b1 100644
9538--- a/arch/sparc/kernel/process_64.c
9539+++ b/arch/sparc/kernel/process_64.c
9540@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9541 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9542 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9543 if (regs->tstate & TSTATE_PRIV)
9544- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9545+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9546 }
9547
9548 void show_regs(struct pt_regs *regs)
9549@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9550
9551 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9552 regs->tpc, regs->tnpc, regs->y, print_tainted());
9553- printk("TPC: <%pS>\n", (void *) regs->tpc);
9554+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9555 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9556 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9557 regs->u_regs[3]);
9558@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9559 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9560 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9561 regs->u_regs[15]);
9562- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9563+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9564 show_regwindow(regs);
9565 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9566 }
9567@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9568 ((tp && tp->task) ? tp->task->pid : -1));
9569
9570 if (gp->tstate & TSTATE_PRIV) {
9571- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9572+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9573 (void *) gp->tpc,
9574 (void *) gp->o7,
9575 (void *) gp->i7,
9576diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9577index 79cc0d1..ec62734 100644
9578--- a/arch/sparc/kernel/prom_common.c
9579+++ b/arch/sparc/kernel/prom_common.c
9580@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9581
9582 unsigned int prom_early_allocated __initdata;
9583
9584-static struct of_pdt_ops prom_sparc_ops __initdata = {
9585+static struct of_pdt_ops prom_sparc_ops __initconst = {
9586 .nextprop = prom_common_nextprop,
9587 .getproplen = prom_getproplen,
9588 .getproperty = prom_getproperty,
9589diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9590index 773c1f2..a8bdd87 100644
9591--- a/arch/sparc/kernel/ptrace_64.c
9592+++ b/arch/sparc/kernel/ptrace_64.c
9593@@ -1059,6 +1059,10 @@ long arch_ptrace(struct task_struct *child, long request,
9594 return ret;
9595 }
9596
9597+#ifdef CONFIG_GRKERNSEC_SETXID
9598+extern void gr_delayed_cred_worker(void);
9599+#endif
9600+
9601 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9602 {
9603 int ret = 0;
9604@@ -1066,6 +1070,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9605 /* do the secure computing check first */
9606 secure_computing_strict(regs->u_regs[UREG_G1]);
9607
9608+#ifdef CONFIG_GRKERNSEC_SETXID
9609+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9610+ gr_delayed_cred_worker();
9611+#endif
9612+
9613 if (test_thread_flag(TIF_SYSCALL_TRACE))
9614 ret = tracehook_report_syscall_entry(regs);
9615
9616@@ -1086,6 +1095,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9617
9618 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9619 {
9620+#ifdef CONFIG_GRKERNSEC_SETXID
9621+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9622+ gr_delayed_cred_worker();
9623+#endif
9624+
9625 audit_syscall_exit(regs);
9626
9627 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9628diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9629index e142545..fd29654 100644
9630--- a/arch/sparc/kernel/smp_64.c
9631+++ b/arch/sparc/kernel/smp_64.c
9632@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9633 extern unsigned long xcall_flush_dcache_page_spitfire;
9634
9635 #ifdef CONFIG_DEBUG_DCFLUSH
9636-extern atomic_t dcpage_flushes;
9637-extern atomic_t dcpage_flushes_xcall;
9638+extern atomic_unchecked_t dcpage_flushes;
9639+extern atomic_unchecked_t dcpage_flushes_xcall;
9640 #endif
9641
9642 static inline void __local_flush_dcache_page(struct page *page)
9643@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9644 return;
9645
9646 #ifdef CONFIG_DEBUG_DCFLUSH
9647- atomic_inc(&dcpage_flushes);
9648+ atomic_inc_unchecked(&dcpage_flushes);
9649 #endif
9650
9651 this_cpu = get_cpu();
9652@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9653 xcall_deliver(data0, __pa(pg_addr),
9654 (u64) pg_addr, cpumask_of(cpu));
9655 #ifdef CONFIG_DEBUG_DCFLUSH
9656- atomic_inc(&dcpage_flushes_xcall);
9657+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9658 #endif
9659 }
9660 }
9661@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9662 preempt_disable();
9663
9664 #ifdef CONFIG_DEBUG_DCFLUSH
9665- atomic_inc(&dcpage_flushes);
9666+ atomic_inc_unchecked(&dcpage_flushes);
9667 #endif
9668 data0 = 0;
9669 pg_addr = page_address(page);
9670@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9671 xcall_deliver(data0, __pa(pg_addr),
9672 (u64) pg_addr, cpu_online_mask);
9673 #ifdef CONFIG_DEBUG_DCFLUSH
9674- atomic_inc(&dcpage_flushes_xcall);
9675+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9676 #endif
9677 }
9678 __local_flush_dcache_page(page);
9679diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9680index 3a8d184..49498a8 100644
9681--- a/arch/sparc/kernel/sys_sparc_32.c
9682+++ b/arch/sparc/kernel/sys_sparc_32.c
9683@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9684 if (len > TASK_SIZE - PAGE_SIZE)
9685 return -ENOMEM;
9686 if (!addr)
9687- addr = TASK_UNMAPPED_BASE;
9688+ addr = current->mm->mmap_base;
9689
9690 info.flags = 0;
9691 info.length = len;
9692diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9693index 51561b8..8256764 100644
9694--- a/arch/sparc/kernel/sys_sparc_64.c
9695+++ b/arch/sparc/kernel/sys_sparc_64.c
9696@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9697 struct vm_area_struct * vma;
9698 unsigned long task_size = TASK_SIZE;
9699 int do_color_align;
9700+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9701 struct vm_unmapped_area_info info;
9702
9703 if (flags & MAP_FIXED) {
9704 /* We do not accept a shared mapping if it would violate
9705 * cache aliasing constraints.
9706 */
9707- if ((flags & MAP_SHARED) &&
9708+ if ((filp || (flags & MAP_SHARED)) &&
9709 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9710 return -EINVAL;
9711 return addr;
9712@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9713 if (filp || (flags & MAP_SHARED))
9714 do_color_align = 1;
9715
9716+#ifdef CONFIG_PAX_RANDMMAP
9717+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9718+#endif
9719+
9720 if (addr) {
9721 if (do_color_align)
9722 addr = COLOR_ALIGN(addr, pgoff);
9723@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9724 addr = PAGE_ALIGN(addr);
9725
9726 vma = find_vma(mm, addr);
9727- if (task_size - len >= addr &&
9728- (!vma || addr + len <= vma->vm_start))
9729+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9730 return addr;
9731 }
9732
9733 info.flags = 0;
9734 info.length = len;
9735- info.low_limit = TASK_UNMAPPED_BASE;
9736+ info.low_limit = mm->mmap_base;
9737 info.high_limit = min(task_size, VA_EXCLUDE_START);
9738 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9739 info.align_offset = pgoff << PAGE_SHIFT;
9740+ info.threadstack_offset = offset;
9741 addr = vm_unmapped_area(&info);
9742
9743 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9744 VM_BUG_ON(addr != -ENOMEM);
9745 info.low_limit = VA_EXCLUDE_END;
9746+
9747+#ifdef CONFIG_PAX_RANDMMAP
9748+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9749+ info.low_limit += mm->delta_mmap;
9750+#endif
9751+
9752 info.high_limit = task_size;
9753 addr = vm_unmapped_area(&info);
9754 }
9755@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9756 unsigned long task_size = STACK_TOP32;
9757 unsigned long addr = addr0;
9758 int do_color_align;
9759+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9760 struct vm_unmapped_area_info info;
9761
9762 /* This should only ever run for 32-bit processes. */
9763@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9764 /* We do not accept a shared mapping if it would violate
9765 * cache aliasing constraints.
9766 */
9767- if ((flags & MAP_SHARED) &&
9768+ if ((filp || (flags & MAP_SHARED)) &&
9769 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9770 return -EINVAL;
9771 return addr;
9772@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9773 if (filp || (flags & MAP_SHARED))
9774 do_color_align = 1;
9775
9776+#ifdef CONFIG_PAX_RANDMMAP
9777+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9778+#endif
9779+
9780 /* requesting a specific address */
9781 if (addr) {
9782 if (do_color_align)
9783@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9784 addr = PAGE_ALIGN(addr);
9785
9786 vma = find_vma(mm, addr);
9787- if (task_size - len >= addr &&
9788- (!vma || addr + len <= vma->vm_start))
9789+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9790 return addr;
9791 }
9792
9793@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9794 info.high_limit = mm->mmap_base;
9795 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9796 info.align_offset = pgoff << PAGE_SHIFT;
9797+ info.threadstack_offset = offset;
9798 addr = vm_unmapped_area(&info);
9799
9800 /*
9801@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9802 VM_BUG_ON(addr != -ENOMEM);
9803 info.flags = 0;
9804 info.low_limit = TASK_UNMAPPED_BASE;
9805+
9806+#ifdef CONFIG_PAX_RANDMMAP
9807+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9808+ info.low_limit += mm->delta_mmap;
9809+#endif
9810+
9811 info.high_limit = STACK_TOP32;
9812 addr = vm_unmapped_area(&info);
9813 }
9814@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9815 EXPORT_SYMBOL(get_fb_unmapped_area);
9816
9817 /* Essentially the same as PowerPC. */
9818-static unsigned long mmap_rnd(void)
9819+static unsigned long mmap_rnd(struct mm_struct *mm)
9820 {
9821 unsigned long rnd = 0UL;
9822
9823+#ifdef CONFIG_PAX_RANDMMAP
9824+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9825+#endif
9826+
9827 if (current->flags & PF_RANDOMIZE) {
9828 unsigned long val = get_random_int();
9829 if (test_thread_flag(TIF_32BIT))
9830@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9831
9832 void arch_pick_mmap_layout(struct mm_struct *mm)
9833 {
9834- unsigned long random_factor = mmap_rnd();
9835+ unsigned long random_factor = mmap_rnd(mm);
9836 unsigned long gap;
9837
9838 /*
9839@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9840 gap == RLIM_INFINITY ||
9841 sysctl_legacy_va_layout) {
9842 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9843+
9844+#ifdef CONFIG_PAX_RANDMMAP
9845+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9846+ mm->mmap_base += mm->delta_mmap;
9847+#endif
9848+
9849 mm->get_unmapped_area = arch_get_unmapped_area;
9850 } else {
9851 /* We know it's 32-bit */
9852@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9853 gap = (task_size / 6 * 5);
9854
9855 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9856+
9857+#ifdef CONFIG_PAX_RANDMMAP
9858+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9859+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9860+#endif
9861+
9862 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9863 }
9864 }
9865diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9866index d950197..192f9d8 100644
9867--- a/arch/sparc/kernel/syscalls.S
9868+++ b/arch/sparc/kernel/syscalls.S
9869@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9870 #endif
9871 .align 32
9872 1: ldx [%g6 + TI_FLAGS], %l5
9873- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9874+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9875 be,pt %icc, rtrap
9876 nop
9877 call syscall_trace_leave
9878@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9879
9880 srl %i3, 0, %o3 ! IEU0
9881 srl %i2, 0, %o2 ! IEU0 Group
9882- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9883+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9884 bne,pn %icc, linux_syscall_trace32 ! CTI
9885 mov %i0, %l5 ! IEU1
9886 5: call %l7 ! CTI Group brk forced
9887@@ -207,7 +207,7 @@ linux_sparc_syscall:
9888
9889 mov %i3, %o3 ! IEU1
9890 mov %i4, %o4 ! IEU0 Group
9891- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9892+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9893 bne,pn %icc, linux_syscall_trace ! CTI Group
9894 mov %i0, %l5 ! IEU0
9895 2: call %l7 ! CTI Group brk forced
9896@@ -223,7 +223,7 @@ ret_sys_call:
9897
9898 cmp %o0, -ERESTART_RESTARTBLOCK
9899 bgeu,pn %xcc, 1f
9900- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9901+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9902 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9903
9904 2:
9905diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9906index 6629829..036032d 100644
9907--- a/arch/sparc/kernel/traps_32.c
9908+++ b/arch/sparc/kernel/traps_32.c
9909@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9910 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9911 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9912
9913+extern void gr_handle_kernel_exploit(void);
9914+
9915 void die_if_kernel(char *str, struct pt_regs *regs)
9916 {
9917 static int die_counter;
9918@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9919 count++ < 30 &&
9920 (((unsigned long) rw) >= PAGE_OFFSET) &&
9921 !(((unsigned long) rw) & 0x7)) {
9922- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9923+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9924 (void *) rw->ins[7]);
9925 rw = (struct reg_window32 *)rw->ins[6];
9926 }
9927 }
9928 printk("Instruction DUMP:");
9929 instruction_dump ((unsigned long *) regs->pc);
9930- if(regs->psr & PSR_PS)
9931+ if(regs->psr & PSR_PS) {
9932+ gr_handle_kernel_exploit();
9933 do_exit(SIGKILL);
9934+ }
9935 do_exit(SIGSEGV);
9936 }
9937
9938diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9939index b3f833a..f485f80 100644
9940--- a/arch/sparc/kernel/traps_64.c
9941+++ b/arch/sparc/kernel/traps_64.c
9942@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9943 i + 1,
9944 p->trapstack[i].tstate, p->trapstack[i].tpc,
9945 p->trapstack[i].tnpc, p->trapstack[i].tt);
9946- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9947+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9948 }
9949 }
9950
9951@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9952
9953 lvl -= 0x100;
9954 if (regs->tstate & TSTATE_PRIV) {
9955+
9956+#ifdef CONFIG_PAX_REFCOUNT
9957+ if (lvl == 6)
9958+ pax_report_refcount_overflow(regs);
9959+#endif
9960+
9961 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9962 die_if_kernel(buffer, regs);
9963 }
9964@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9965 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9966 {
9967 char buffer[32];
9968-
9969+
9970 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9971 0, lvl, SIGTRAP) == NOTIFY_STOP)
9972 return;
9973
9974+#ifdef CONFIG_PAX_REFCOUNT
9975+ if (lvl == 6)
9976+ pax_report_refcount_overflow(regs);
9977+#endif
9978+
9979 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9980
9981 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9982@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9983 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9984 printk("%s" "ERROR(%d): ",
9985 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9986- printk("TPC<%pS>\n", (void *) regs->tpc);
9987+ printk("TPC<%pA>\n", (void *) regs->tpc);
9988 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9989 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9990 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9991@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9992 smp_processor_id(),
9993 (type & 0x1) ? 'I' : 'D',
9994 regs->tpc);
9995- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9996+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9997 panic("Irrecoverable Cheetah+ parity error.");
9998 }
9999
10000@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10001 smp_processor_id(),
10002 (type & 0x1) ? 'I' : 'D',
10003 regs->tpc);
10004- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10005+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10006 }
10007
10008 struct sun4v_error_entry {
10009@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
10010 /*0x38*/u64 reserved_5;
10011 };
10012
10013-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10014-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10015+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10016+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10017
10018 static const char *sun4v_err_type_to_str(u8 type)
10019 {
10020@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10021 }
10022
10023 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10024- int cpu, const char *pfx, atomic_t *ocnt)
10025+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10026 {
10027 u64 *raw_ptr = (u64 *) ent;
10028 u32 attrs;
10029@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10030
10031 show_regs(regs);
10032
10033- if ((cnt = atomic_read(ocnt)) != 0) {
10034- atomic_set(ocnt, 0);
10035+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10036+ atomic_set_unchecked(ocnt, 0);
10037 wmb();
10038 printk("%s: Queue overflowed %d times.\n",
10039 pfx, cnt);
10040@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10041 */
10042 void sun4v_resum_overflow(struct pt_regs *regs)
10043 {
10044- atomic_inc(&sun4v_resum_oflow_cnt);
10045+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10046 }
10047
10048 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10049@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10050 /* XXX Actually even this can make not that much sense. Perhaps
10051 * XXX we should just pull the plug and panic directly from here?
10052 */
10053- atomic_inc(&sun4v_nonresum_oflow_cnt);
10054+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10055 }
10056
10057 unsigned long sun4v_err_itlb_vaddr;
10058@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10059
10060 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10061 regs->tpc, tl);
10062- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10063+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10064 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10065- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10066+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10067 (void *) regs->u_regs[UREG_I7]);
10068 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10069 "pte[%lx] error[%lx]\n",
10070@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10071
10072 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10073 regs->tpc, tl);
10074- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10075+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10076 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10077- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10078+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10079 (void *) regs->u_regs[UREG_I7]);
10080 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10081 "pte[%lx] error[%lx]\n",
10082@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10083 fp = (unsigned long)sf->fp + STACK_BIAS;
10084 }
10085
10086- printk(" [%016lx] %pS\n", pc, (void *) pc);
10087+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10088 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10089 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10090 int index = tsk->curr_ret_stack;
10091 if (tsk->ret_stack && index >= graph) {
10092 pc = tsk->ret_stack[index - graph].ret;
10093- printk(" [%016lx] %pS\n", pc, (void *) pc);
10094+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10095 graph++;
10096 }
10097 }
10098@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10099 return (struct reg_window *) (fp + STACK_BIAS);
10100 }
10101
10102+extern void gr_handle_kernel_exploit(void);
10103+
10104 void die_if_kernel(char *str, struct pt_regs *regs)
10105 {
10106 static int die_counter;
10107@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10108 while (rw &&
10109 count++ < 30 &&
10110 kstack_valid(tp, (unsigned long) rw)) {
10111- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10112+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10113 (void *) rw->ins[7]);
10114
10115 rw = kernel_stack_up(rw);
10116@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10117 }
10118 user_instruction_dump ((unsigned int __user *) regs->tpc);
10119 }
10120- if (regs->tstate & TSTATE_PRIV)
10121+ if (regs->tstate & TSTATE_PRIV) {
10122+ gr_handle_kernel_exploit();
10123 do_exit(SIGKILL);
10124+ }
10125 do_exit(SIGSEGV);
10126 }
10127 EXPORT_SYMBOL(die_if_kernel);
10128diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10129index 8201c25e..072a2a7 100644
10130--- a/arch/sparc/kernel/unaligned_64.c
10131+++ b/arch/sparc/kernel/unaligned_64.c
10132@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10133 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10134
10135 if (__ratelimit(&ratelimit)) {
10136- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10137+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10138 regs->tpc, (void *) regs->tpc);
10139 }
10140 }
10141diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10142index dbe119b..089c7c1 100644
10143--- a/arch/sparc/lib/Makefile
10144+++ b/arch/sparc/lib/Makefile
10145@@ -2,7 +2,7 @@
10146 #
10147
10148 asflags-y := -ansi -DST_DIV0=0x02
10149-ccflags-y := -Werror
10150+#ccflags-y := -Werror
10151
10152 lib-$(CONFIG_SPARC32) += ashrdi3.o
10153 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10154diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10155index 85c233d..68500e0 100644
10156--- a/arch/sparc/lib/atomic_64.S
10157+++ b/arch/sparc/lib/atomic_64.S
10158@@ -17,7 +17,12 @@
10159 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10160 BACKOFF_SETUP(%o2)
10161 1: lduw [%o1], %g1
10162- add %g1, %o0, %g7
10163+ addcc %g1, %o0, %g7
10164+
10165+#ifdef CONFIG_PAX_REFCOUNT
10166+ tvs %icc, 6
10167+#endif
10168+
10169 cas [%o1], %g1, %g7
10170 cmp %g1, %g7
10171 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10172@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10173 2: BACKOFF_SPIN(%o2, %o3, 1b)
10174 ENDPROC(atomic_add)
10175
10176+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10177+ BACKOFF_SETUP(%o2)
10178+1: lduw [%o1], %g1
10179+ add %g1, %o0, %g7
10180+ cas [%o1], %g1, %g7
10181+ cmp %g1, %g7
10182+ bne,pn %icc, 2f
10183+ nop
10184+ retl
10185+ nop
10186+2: BACKOFF_SPIN(%o2, %o3, 1b)
10187+ENDPROC(atomic_add_unchecked)
10188+
10189 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10190 BACKOFF_SETUP(%o2)
10191 1: lduw [%o1], %g1
10192- sub %g1, %o0, %g7
10193+ subcc %g1, %o0, %g7
10194+
10195+#ifdef CONFIG_PAX_REFCOUNT
10196+ tvs %icc, 6
10197+#endif
10198+
10199 cas [%o1], %g1, %g7
10200 cmp %g1, %g7
10201 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10202@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10203 2: BACKOFF_SPIN(%o2, %o3, 1b)
10204 ENDPROC(atomic_sub)
10205
10206+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10207+ BACKOFF_SETUP(%o2)
10208+1: lduw [%o1], %g1
10209+ sub %g1, %o0, %g7
10210+ cas [%o1], %g1, %g7
10211+ cmp %g1, %g7
10212+ bne,pn %icc, 2f
10213+ nop
10214+ retl
10215+ nop
10216+2: BACKOFF_SPIN(%o2, %o3, 1b)
10217+ENDPROC(atomic_sub_unchecked)
10218+
10219 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10220 BACKOFF_SETUP(%o2)
10221 1: lduw [%o1], %g1
10222- add %g1, %o0, %g7
10223+ addcc %g1, %o0, %g7
10224+
10225+#ifdef CONFIG_PAX_REFCOUNT
10226+ tvs %icc, 6
10227+#endif
10228+
10229 cas [%o1], %g1, %g7
10230 cmp %g1, %g7
10231 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10232@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10233 2: BACKOFF_SPIN(%o2, %o3, 1b)
10234 ENDPROC(atomic_add_ret)
10235
10236+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10237+ BACKOFF_SETUP(%o2)
10238+1: lduw [%o1], %g1
10239+ addcc %g1, %o0, %g7
10240+ cas [%o1], %g1, %g7
10241+ cmp %g1, %g7
10242+ bne,pn %icc, 2f
10243+ add %g7, %o0, %g7
10244+ sra %g7, 0, %o0
10245+ retl
10246+ nop
10247+2: BACKOFF_SPIN(%o2, %o3, 1b)
10248+ENDPROC(atomic_add_ret_unchecked)
10249+
10250 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10251 BACKOFF_SETUP(%o2)
10252 1: lduw [%o1], %g1
10253- sub %g1, %o0, %g7
10254+ subcc %g1, %o0, %g7
10255+
10256+#ifdef CONFIG_PAX_REFCOUNT
10257+ tvs %icc, 6
10258+#endif
10259+
10260 cas [%o1], %g1, %g7
10261 cmp %g1, %g7
10262 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10263@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10264 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10265 BACKOFF_SETUP(%o2)
10266 1: ldx [%o1], %g1
10267- add %g1, %o0, %g7
10268+ addcc %g1, %o0, %g7
10269+
10270+#ifdef CONFIG_PAX_REFCOUNT
10271+ tvs %xcc, 6
10272+#endif
10273+
10274 casx [%o1], %g1, %g7
10275 cmp %g1, %g7
10276 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10277@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10278 2: BACKOFF_SPIN(%o2, %o3, 1b)
10279 ENDPROC(atomic64_add)
10280
10281+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10282+ BACKOFF_SETUP(%o2)
10283+1: ldx [%o1], %g1
10284+ addcc %g1, %o0, %g7
10285+ casx [%o1], %g1, %g7
10286+ cmp %g1, %g7
10287+ bne,pn %xcc, 2f
10288+ nop
10289+ retl
10290+ nop
10291+2: BACKOFF_SPIN(%o2, %o3, 1b)
10292+ENDPROC(atomic64_add_unchecked)
10293+
10294 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10295 BACKOFF_SETUP(%o2)
10296 1: ldx [%o1], %g1
10297- sub %g1, %o0, %g7
10298+ subcc %g1, %o0, %g7
10299+
10300+#ifdef CONFIG_PAX_REFCOUNT
10301+ tvs %xcc, 6
10302+#endif
10303+
10304 casx [%o1], %g1, %g7
10305 cmp %g1, %g7
10306 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10307@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10308 2: BACKOFF_SPIN(%o2, %o3, 1b)
10309 ENDPROC(atomic64_sub)
10310
10311+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10312+ BACKOFF_SETUP(%o2)
10313+1: ldx [%o1], %g1
10314+ subcc %g1, %o0, %g7
10315+ casx [%o1], %g1, %g7
10316+ cmp %g1, %g7
10317+ bne,pn %xcc, 2f
10318+ nop
10319+ retl
10320+ nop
10321+2: BACKOFF_SPIN(%o2, %o3, 1b)
10322+ENDPROC(atomic64_sub_unchecked)
10323+
10324 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10325 BACKOFF_SETUP(%o2)
10326 1: ldx [%o1], %g1
10327- add %g1, %o0, %g7
10328+ addcc %g1, %o0, %g7
10329+
10330+#ifdef CONFIG_PAX_REFCOUNT
10331+ tvs %xcc, 6
10332+#endif
10333+
10334 casx [%o1], %g1, %g7
10335 cmp %g1, %g7
10336 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10337@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10338 2: BACKOFF_SPIN(%o2, %o3, 1b)
10339 ENDPROC(atomic64_add_ret)
10340
10341+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10342+ BACKOFF_SETUP(%o2)
10343+1: ldx [%o1], %g1
10344+ addcc %g1, %o0, %g7
10345+ casx [%o1], %g1, %g7
10346+ cmp %g1, %g7
10347+ bne,pn %xcc, 2f
10348+ add %g7, %o0, %g7
10349+ mov %g7, %o0
10350+ retl
10351+ nop
10352+2: BACKOFF_SPIN(%o2, %o3, 1b)
10353+ENDPROC(atomic64_add_ret_unchecked)
10354+
10355 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10356 BACKOFF_SETUP(%o2)
10357 1: ldx [%o1], %g1
10358- sub %g1, %o0, %g7
10359+ subcc %g1, %o0, %g7
10360+
10361+#ifdef CONFIG_PAX_REFCOUNT
10362+ tvs %xcc, 6
10363+#endif
10364+
10365 casx [%o1], %g1, %g7
10366 cmp %g1, %g7
10367 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10368diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10369index 323335b..ed85ea2 100644
10370--- a/arch/sparc/lib/ksyms.c
10371+++ b/arch/sparc/lib/ksyms.c
10372@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10373
10374 /* Atomic counter implementation. */
10375 EXPORT_SYMBOL(atomic_add);
10376+EXPORT_SYMBOL(atomic_add_unchecked);
10377 EXPORT_SYMBOL(atomic_add_ret);
10378+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10379 EXPORT_SYMBOL(atomic_sub);
10380+EXPORT_SYMBOL(atomic_sub_unchecked);
10381 EXPORT_SYMBOL(atomic_sub_ret);
10382 EXPORT_SYMBOL(atomic64_add);
10383+EXPORT_SYMBOL(atomic64_add_unchecked);
10384 EXPORT_SYMBOL(atomic64_add_ret);
10385+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10386 EXPORT_SYMBOL(atomic64_sub);
10387+EXPORT_SYMBOL(atomic64_sub_unchecked);
10388 EXPORT_SYMBOL(atomic64_sub_ret);
10389 EXPORT_SYMBOL(atomic64_dec_if_positive);
10390
10391diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10392index 30c3ecc..736f015 100644
10393--- a/arch/sparc/mm/Makefile
10394+++ b/arch/sparc/mm/Makefile
10395@@ -2,7 +2,7 @@
10396 #
10397
10398 asflags-y := -ansi
10399-ccflags-y := -Werror
10400+#ccflags-y := -Werror
10401
10402 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10403 obj-y += fault_$(BITS).o
10404diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10405index 59dbd46..1dd7f5e 100644
10406--- a/arch/sparc/mm/fault_32.c
10407+++ b/arch/sparc/mm/fault_32.c
10408@@ -21,6 +21,9 @@
10409 #include <linux/perf_event.h>
10410 #include <linux/interrupt.h>
10411 #include <linux/kdebug.h>
10412+#include <linux/slab.h>
10413+#include <linux/pagemap.h>
10414+#include <linux/compiler.h>
10415
10416 #include <asm/page.h>
10417 #include <asm/pgtable.h>
10418@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10419 return safe_compute_effective_address(regs, insn);
10420 }
10421
10422+#ifdef CONFIG_PAX_PAGEEXEC
10423+#ifdef CONFIG_PAX_DLRESOLVE
10424+static void pax_emuplt_close(struct vm_area_struct *vma)
10425+{
10426+ vma->vm_mm->call_dl_resolve = 0UL;
10427+}
10428+
10429+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10430+{
10431+ unsigned int *kaddr;
10432+
10433+ vmf->page = alloc_page(GFP_HIGHUSER);
10434+ if (!vmf->page)
10435+ return VM_FAULT_OOM;
10436+
10437+ kaddr = kmap(vmf->page);
10438+ memset(kaddr, 0, PAGE_SIZE);
10439+ kaddr[0] = 0x9DE3BFA8U; /* save */
10440+ flush_dcache_page(vmf->page);
10441+ kunmap(vmf->page);
10442+ return VM_FAULT_MAJOR;
10443+}
10444+
10445+static const struct vm_operations_struct pax_vm_ops = {
10446+ .close = pax_emuplt_close,
10447+ .fault = pax_emuplt_fault
10448+};
10449+
10450+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10451+{
10452+ int ret;
10453+
10454+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10455+ vma->vm_mm = current->mm;
10456+ vma->vm_start = addr;
10457+ vma->vm_end = addr + PAGE_SIZE;
10458+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10459+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10460+ vma->vm_ops = &pax_vm_ops;
10461+
10462+ ret = insert_vm_struct(current->mm, vma);
10463+ if (ret)
10464+ return ret;
10465+
10466+ ++current->mm->total_vm;
10467+ return 0;
10468+}
10469+#endif
10470+
10471+/*
10472+ * PaX: decide what to do with offenders (regs->pc = fault address)
10473+ *
10474+ * returns 1 when task should be killed
10475+ * 2 when patched PLT trampoline was detected
10476+ * 3 when unpatched PLT trampoline was detected
10477+ */
10478+static int pax_handle_fetch_fault(struct pt_regs *regs)
10479+{
10480+
10481+#ifdef CONFIG_PAX_EMUPLT
10482+ int err;
10483+
10484+ do { /* PaX: patched PLT emulation #1 */
10485+ unsigned int sethi1, sethi2, jmpl;
10486+
10487+ err = get_user(sethi1, (unsigned int *)regs->pc);
10488+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10489+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10490+
10491+ if (err)
10492+ break;
10493+
10494+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10495+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10496+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10497+ {
10498+ unsigned int addr;
10499+
10500+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10501+ addr = regs->u_regs[UREG_G1];
10502+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10503+ regs->pc = addr;
10504+ regs->npc = addr+4;
10505+ return 2;
10506+ }
10507+ } while (0);
10508+
10509+ do { /* PaX: patched PLT emulation #2 */
10510+ unsigned int ba;
10511+
10512+ err = get_user(ba, (unsigned int *)regs->pc);
10513+
10514+ if (err)
10515+ break;
10516+
10517+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10518+ unsigned int addr;
10519+
10520+ if ((ba & 0xFFC00000U) == 0x30800000U)
10521+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10522+ else
10523+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10524+ regs->pc = addr;
10525+ regs->npc = addr+4;
10526+ return 2;
10527+ }
10528+ } while (0);
10529+
10530+ do { /* PaX: patched PLT emulation #3 */
10531+ unsigned int sethi, bajmpl, nop;
10532+
10533+ err = get_user(sethi, (unsigned int *)regs->pc);
10534+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10535+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10536+
10537+ if (err)
10538+ break;
10539+
10540+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10541+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10542+ nop == 0x01000000U)
10543+ {
10544+ unsigned int addr;
10545+
10546+ addr = (sethi & 0x003FFFFFU) << 10;
10547+ regs->u_regs[UREG_G1] = addr;
10548+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10549+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10550+ else
10551+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10552+ regs->pc = addr;
10553+ regs->npc = addr+4;
10554+ return 2;
10555+ }
10556+ } while (0);
10557+
10558+ do { /* PaX: unpatched PLT emulation step 1 */
10559+ unsigned int sethi, ba, nop;
10560+
10561+ err = get_user(sethi, (unsigned int *)regs->pc);
10562+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10563+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10564+
10565+ if (err)
10566+ break;
10567+
10568+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10569+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10570+ nop == 0x01000000U)
10571+ {
10572+ unsigned int addr, save, call;
10573+
10574+ if ((ba & 0xFFC00000U) == 0x30800000U)
10575+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10576+ else
10577+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10578+
10579+ err = get_user(save, (unsigned int *)addr);
10580+ err |= get_user(call, (unsigned int *)(addr+4));
10581+ err |= get_user(nop, (unsigned int *)(addr+8));
10582+ if (err)
10583+ break;
10584+
10585+#ifdef CONFIG_PAX_DLRESOLVE
10586+ if (save == 0x9DE3BFA8U &&
10587+ (call & 0xC0000000U) == 0x40000000U &&
10588+ nop == 0x01000000U)
10589+ {
10590+ struct vm_area_struct *vma;
10591+ unsigned long call_dl_resolve;
10592+
10593+ down_read(&current->mm->mmap_sem);
10594+ call_dl_resolve = current->mm->call_dl_resolve;
10595+ up_read(&current->mm->mmap_sem);
10596+ if (likely(call_dl_resolve))
10597+ goto emulate;
10598+
10599+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10600+
10601+ down_write(&current->mm->mmap_sem);
10602+ if (current->mm->call_dl_resolve) {
10603+ call_dl_resolve = current->mm->call_dl_resolve;
10604+ up_write(&current->mm->mmap_sem);
10605+ if (vma)
10606+ kmem_cache_free(vm_area_cachep, vma);
10607+ goto emulate;
10608+ }
10609+
10610+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10611+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10612+ up_write(&current->mm->mmap_sem);
10613+ if (vma)
10614+ kmem_cache_free(vm_area_cachep, vma);
10615+ return 1;
10616+ }
10617+
10618+ if (pax_insert_vma(vma, call_dl_resolve)) {
10619+ up_write(&current->mm->mmap_sem);
10620+ kmem_cache_free(vm_area_cachep, vma);
10621+ return 1;
10622+ }
10623+
10624+ current->mm->call_dl_resolve = call_dl_resolve;
10625+ up_write(&current->mm->mmap_sem);
10626+
10627+emulate:
10628+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10629+ regs->pc = call_dl_resolve;
10630+ regs->npc = addr+4;
10631+ return 3;
10632+ }
10633+#endif
10634+
10635+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10636+ if ((save & 0xFFC00000U) == 0x05000000U &&
10637+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10638+ nop == 0x01000000U)
10639+ {
10640+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10641+ regs->u_regs[UREG_G2] = addr + 4;
10642+ addr = (save & 0x003FFFFFU) << 10;
10643+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10644+ regs->pc = addr;
10645+ regs->npc = addr+4;
10646+ return 3;
10647+ }
10648+ }
10649+ } while (0);
10650+
10651+ do { /* PaX: unpatched PLT emulation step 2 */
10652+ unsigned int save, call, nop;
10653+
10654+ err = get_user(save, (unsigned int *)(regs->pc-4));
10655+ err |= get_user(call, (unsigned int *)regs->pc);
10656+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10657+ if (err)
10658+ break;
10659+
10660+ if (save == 0x9DE3BFA8U &&
10661+ (call & 0xC0000000U) == 0x40000000U &&
10662+ nop == 0x01000000U)
10663+ {
10664+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10665+
10666+ regs->u_regs[UREG_RETPC] = regs->pc;
10667+ regs->pc = dl_resolve;
10668+ regs->npc = dl_resolve+4;
10669+ return 3;
10670+ }
10671+ } while (0);
10672+#endif
10673+
10674+ return 1;
10675+}
10676+
10677+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10678+{
10679+ unsigned long i;
10680+
10681+ printk(KERN_ERR "PAX: bytes at PC: ");
10682+ for (i = 0; i < 8; i++) {
10683+ unsigned int c;
10684+ if (get_user(c, (unsigned int *)pc+i))
10685+ printk(KERN_CONT "???????? ");
10686+ else
10687+ printk(KERN_CONT "%08x ", c);
10688+ }
10689+ printk("\n");
10690+}
10691+#endif
10692+
10693 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10694 int text_fault)
10695 {
10696@@ -229,6 +503,24 @@ good_area:
10697 if (!(vma->vm_flags & VM_WRITE))
10698 goto bad_area;
10699 } else {
10700+
10701+#ifdef CONFIG_PAX_PAGEEXEC
10702+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10703+ up_read(&mm->mmap_sem);
10704+ switch (pax_handle_fetch_fault(regs)) {
10705+
10706+#ifdef CONFIG_PAX_EMUPLT
10707+ case 2:
10708+ case 3:
10709+ return;
10710+#endif
10711+
10712+ }
10713+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10714+ do_group_exit(SIGKILL);
10715+ }
10716+#endif
10717+
10718 /* Allow reads even for write-only mappings */
10719 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10720 goto bad_area;
10721diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10722index 2ebec26..b212598 100644
10723--- a/arch/sparc/mm/fault_64.c
10724+++ b/arch/sparc/mm/fault_64.c
10725@@ -21,6 +21,9 @@
10726 #include <linux/kprobes.h>
10727 #include <linux/kdebug.h>
10728 #include <linux/percpu.h>
10729+#include <linux/slab.h>
10730+#include <linux/pagemap.h>
10731+#include <linux/compiler.h>
10732
10733 #include <asm/page.h>
10734 #include <asm/pgtable.h>
10735@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10736 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10737 regs->tpc);
10738 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10739- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10740+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10741 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10742 dump_stack();
10743 unhandled_fault(regs->tpc, current, regs);
10744@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10745 show_regs(regs);
10746 }
10747
10748+#ifdef CONFIG_PAX_PAGEEXEC
10749+#ifdef CONFIG_PAX_DLRESOLVE
10750+static void pax_emuplt_close(struct vm_area_struct *vma)
10751+{
10752+ vma->vm_mm->call_dl_resolve = 0UL;
10753+}
10754+
10755+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10756+{
10757+ unsigned int *kaddr;
10758+
10759+ vmf->page = alloc_page(GFP_HIGHUSER);
10760+ if (!vmf->page)
10761+ return VM_FAULT_OOM;
10762+
10763+ kaddr = kmap(vmf->page);
10764+ memset(kaddr, 0, PAGE_SIZE);
10765+ kaddr[0] = 0x9DE3BFA8U; /* save */
10766+ flush_dcache_page(vmf->page);
10767+ kunmap(vmf->page);
10768+ return VM_FAULT_MAJOR;
10769+}
10770+
10771+static const struct vm_operations_struct pax_vm_ops = {
10772+ .close = pax_emuplt_close,
10773+ .fault = pax_emuplt_fault
10774+};
10775+
10776+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10777+{
10778+ int ret;
10779+
10780+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10781+ vma->vm_mm = current->mm;
10782+ vma->vm_start = addr;
10783+ vma->vm_end = addr + PAGE_SIZE;
10784+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10785+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10786+ vma->vm_ops = &pax_vm_ops;
10787+
10788+ ret = insert_vm_struct(current->mm, vma);
10789+ if (ret)
10790+ return ret;
10791+
10792+ ++current->mm->total_vm;
10793+ return 0;
10794+}
10795+#endif
10796+
10797+/*
10798+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10799+ *
10800+ * returns 1 when task should be killed
10801+ * 2 when patched PLT trampoline was detected
10802+ * 3 when unpatched PLT trampoline was detected
10803+ */
10804+static int pax_handle_fetch_fault(struct pt_regs *regs)
10805+{
10806+
10807+#ifdef CONFIG_PAX_EMUPLT
10808+ int err;
10809+
10810+ do { /* PaX: patched PLT emulation #1 */
10811+ unsigned int sethi1, sethi2, jmpl;
10812+
10813+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10814+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10815+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10816+
10817+ if (err)
10818+ break;
10819+
10820+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10821+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10822+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10823+ {
10824+ unsigned long addr;
10825+
10826+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10827+ addr = regs->u_regs[UREG_G1];
10828+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10829+
10830+ if (test_thread_flag(TIF_32BIT))
10831+ addr &= 0xFFFFFFFFUL;
10832+
10833+ regs->tpc = addr;
10834+ regs->tnpc = addr+4;
10835+ return 2;
10836+ }
10837+ } while (0);
10838+
10839+ do { /* PaX: patched PLT emulation #2 */
10840+ unsigned int ba;
10841+
10842+ err = get_user(ba, (unsigned int *)regs->tpc);
10843+
10844+ if (err)
10845+ break;
10846+
10847+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10848+ unsigned long addr;
10849+
10850+ if ((ba & 0xFFC00000U) == 0x30800000U)
10851+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10852+ else
10853+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10854+
10855+ if (test_thread_flag(TIF_32BIT))
10856+ addr &= 0xFFFFFFFFUL;
10857+
10858+ regs->tpc = addr;
10859+ regs->tnpc = addr+4;
10860+ return 2;
10861+ }
10862+ } while (0);
10863+
10864+ do { /* PaX: patched PLT emulation #3 */
10865+ unsigned int sethi, bajmpl, nop;
10866+
10867+ err = get_user(sethi, (unsigned int *)regs->tpc);
10868+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10869+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10870+
10871+ if (err)
10872+ break;
10873+
10874+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10875+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10876+ nop == 0x01000000U)
10877+ {
10878+ unsigned long addr;
10879+
10880+ addr = (sethi & 0x003FFFFFU) << 10;
10881+ regs->u_regs[UREG_G1] = addr;
10882+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10883+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10884+ else
10885+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10886+
10887+ if (test_thread_flag(TIF_32BIT))
10888+ addr &= 0xFFFFFFFFUL;
10889+
10890+ regs->tpc = addr;
10891+ regs->tnpc = addr+4;
10892+ return 2;
10893+ }
10894+ } while (0);
10895+
10896+ do { /* PaX: patched PLT emulation #4 */
10897+ unsigned int sethi, mov1, call, mov2;
10898+
10899+ err = get_user(sethi, (unsigned int *)regs->tpc);
10900+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10901+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10902+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10903+
10904+ if (err)
10905+ break;
10906+
10907+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10908+ mov1 == 0x8210000FU &&
10909+ (call & 0xC0000000U) == 0x40000000U &&
10910+ mov2 == 0x9E100001U)
10911+ {
10912+ unsigned long addr;
10913+
10914+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10915+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10916+
10917+ if (test_thread_flag(TIF_32BIT))
10918+ addr &= 0xFFFFFFFFUL;
10919+
10920+ regs->tpc = addr;
10921+ regs->tnpc = addr+4;
10922+ return 2;
10923+ }
10924+ } while (0);
10925+
10926+ do { /* PaX: patched PLT emulation #5 */
10927+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10928+
10929+ err = get_user(sethi, (unsigned int *)regs->tpc);
10930+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10931+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10932+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10933+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10934+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10935+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10936+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10937+
10938+ if (err)
10939+ break;
10940+
10941+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10942+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10943+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10944+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10945+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10946+ sllx == 0x83287020U &&
10947+ jmpl == 0x81C04005U &&
10948+ nop == 0x01000000U)
10949+ {
10950+ unsigned long addr;
10951+
10952+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10953+ regs->u_regs[UREG_G1] <<= 32;
10954+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10955+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10956+ regs->tpc = addr;
10957+ regs->tnpc = addr+4;
10958+ return 2;
10959+ }
10960+ } while (0);
10961+
10962+ do { /* PaX: patched PLT emulation #6 */
10963+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10964+
10965+ err = get_user(sethi, (unsigned int *)regs->tpc);
10966+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10967+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10968+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10969+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10970+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10971+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10972+
10973+ if (err)
10974+ break;
10975+
10976+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10977+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10978+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10979+ sllx == 0x83287020U &&
10980+ (or & 0xFFFFE000U) == 0x8A116000U &&
10981+ jmpl == 0x81C04005U &&
10982+ nop == 0x01000000U)
10983+ {
10984+ unsigned long addr;
10985+
10986+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10987+ regs->u_regs[UREG_G1] <<= 32;
10988+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10989+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10990+ regs->tpc = addr;
10991+ regs->tnpc = addr+4;
10992+ return 2;
10993+ }
10994+ } while (0);
10995+
10996+ do { /* PaX: unpatched PLT emulation step 1 */
10997+ unsigned int sethi, ba, nop;
10998+
10999+ err = get_user(sethi, (unsigned int *)regs->tpc);
11000+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11001+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11002+
11003+ if (err)
11004+ break;
11005+
11006+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11007+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11008+ nop == 0x01000000U)
11009+ {
11010+ unsigned long addr;
11011+ unsigned int save, call;
11012+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11013+
11014+ if ((ba & 0xFFC00000U) == 0x30800000U)
11015+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11016+ else
11017+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11018+
11019+ if (test_thread_flag(TIF_32BIT))
11020+ addr &= 0xFFFFFFFFUL;
11021+
11022+ err = get_user(save, (unsigned int *)addr);
11023+ err |= get_user(call, (unsigned int *)(addr+4));
11024+ err |= get_user(nop, (unsigned int *)(addr+8));
11025+ if (err)
11026+ break;
11027+
11028+#ifdef CONFIG_PAX_DLRESOLVE
11029+ if (save == 0x9DE3BFA8U &&
11030+ (call & 0xC0000000U) == 0x40000000U &&
11031+ nop == 0x01000000U)
11032+ {
11033+ struct vm_area_struct *vma;
11034+ unsigned long call_dl_resolve;
11035+
11036+ down_read(&current->mm->mmap_sem);
11037+ call_dl_resolve = current->mm->call_dl_resolve;
11038+ up_read(&current->mm->mmap_sem);
11039+ if (likely(call_dl_resolve))
11040+ goto emulate;
11041+
11042+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11043+
11044+ down_write(&current->mm->mmap_sem);
11045+ if (current->mm->call_dl_resolve) {
11046+ call_dl_resolve = current->mm->call_dl_resolve;
11047+ up_write(&current->mm->mmap_sem);
11048+ if (vma)
11049+ kmem_cache_free(vm_area_cachep, vma);
11050+ goto emulate;
11051+ }
11052+
11053+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11054+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11055+ up_write(&current->mm->mmap_sem);
11056+ if (vma)
11057+ kmem_cache_free(vm_area_cachep, vma);
11058+ return 1;
11059+ }
11060+
11061+ if (pax_insert_vma(vma, call_dl_resolve)) {
11062+ up_write(&current->mm->mmap_sem);
11063+ kmem_cache_free(vm_area_cachep, vma);
11064+ return 1;
11065+ }
11066+
11067+ current->mm->call_dl_resolve = call_dl_resolve;
11068+ up_write(&current->mm->mmap_sem);
11069+
11070+emulate:
11071+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11072+ regs->tpc = call_dl_resolve;
11073+ regs->tnpc = addr+4;
11074+ return 3;
11075+ }
11076+#endif
11077+
11078+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11079+ if ((save & 0xFFC00000U) == 0x05000000U &&
11080+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11081+ nop == 0x01000000U)
11082+ {
11083+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11084+ regs->u_regs[UREG_G2] = addr + 4;
11085+ addr = (save & 0x003FFFFFU) << 10;
11086+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11087+
11088+ if (test_thread_flag(TIF_32BIT))
11089+ addr &= 0xFFFFFFFFUL;
11090+
11091+ regs->tpc = addr;
11092+ regs->tnpc = addr+4;
11093+ return 3;
11094+ }
11095+
11096+ /* PaX: 64-bit PLT stub */
11097+ err = get_user(sethi1, (unsigned int *)addr);
11098+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11099+ err |= get_user(or1, (unsigned int *)(addr+8));
11100+ err |= get_user(or2, (unsigned int *)(addr+12));
11101+ err |= get_user(sllx, (unsigned int *)(addr+16));
11102+ err |= get_user(add, (unsigned int *)(addr+20));
11103+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11104+ err |= get_user(nop, (unsigned int *)(addr+28));
11105+ if (err)
11106+ break;
11107+
11108+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11109+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11110+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11111+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11112+ sllx == 0x89293020U &&
11113+ add == 0x8A010005U &&
11114+ jmpl == 0x89C14000U &&
11115+ nop == 0x01000000U)
11116+ {
11117+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11118+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11119+ regs->u_regs[UREG_G4] <<= 32;
11120+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11121+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11122+ regs->u_regs[UREG_G4] = addr + 24;
11123+ addr = regs->u_regs[UREG_G5];
11124+ regs->tpc = addr;
11125+ regs->tnpc = addr+4;
11126+ return 3;
11127+ }
11128+ }
11129+ } while (0);
11130+
11131+#ifdef CONFIG_PAX_DLRESOLVE
11132+ do { /* PaX: unpatched PLT emulation step 2 */
11133+ unsigned int save, call, nop;
11134+
11135+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11136+ err |= get_user(call, (unsigned int *)regs->tpc);
11137+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11138+ if (err)
11139+ break;
11140+
11141+ if (save == 0x9DE3BFA8U &&
11142+ (call & 0xC0000000U) == 0x40000000U &&
11143+ nop == 0x01000000U)
11144+ {
11145+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11146+
11147+ if (test_thread_flag(TIF_32BIT))
11148+ dl_resolve &= 0xFFFFFFFFUL;
11149+
11150+ regs->u_regs[UREG_RETPC] = regs->tpc;
11151+ regs->tpc = dl_resolve;
11152+ regs->tnpc = dl_resolve+4;
11153+ return 3;
11154+ }
11155+ } while (0);
11156+#endif
11157+
11158+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11159+ unsigned int sethi, ba, nop;
11160+
11161+ err = get_user(sethi, (unsigned int *)regs->tpc);
11162+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11163+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11164+
11165+ if (err)
11166+ break;
11167+
11168+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11169+ (ba & 0xFFF00000U) == 0x30600000U &&
11170+ nop == 0x01000000U)
11171+ {
11172+ unsigned long addr;
11173+
11174+ addr = (sethi & 0x003FFFFFU) << 10;
11175+ regs->u_regs[UREG_G1] = addr;
11176+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11177+
11178+ if (test_thread_flag(TIF_32BIT))
11179+ addr &= 0xFFFFFFFFUL;
11180+
11181+ regs->tpc = addr;
11182+ regs->tnpc = addr+4;
11183+ return 2;
11184+ }
11185+ } while (0);
11186+
11187+#endif
11188+
11189+ return 1;
11190+}
11191+
11192+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11193+{
11194+ unsigned long i;
11195+
11196+ printk(KERN_ERR "PAX: bytes at PC: ");
11197+ for (i = 0; i < 8; i++) {
11198+ unsigned int c;
11199+ if (get_user(c, (unsigned int *)pc+i))
11200+ printk(KERN_CONT "???????? ");
11201+ else
11202+ printk(KERN_CONT "%08x ", c);
11203+ }
11204+ printk("\n");
11205+}
11206+#endif
11207+
11208 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11209 {
11210 struct mm_struct *mm = current->mm;
11211@@ -342,6 +805,29 @@ retry:
11212 if (!vma)
11213 goto bad_area;
11214
11215+#ifdef CONFIG_PAX_PAGEEXEC
11216+ /* PaX: detect ITLB misses on non-exec pages */
11217+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11218+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11219+ {
11220+ if (address != regs->tpc)
11221+ goto good_area;
11222+
11223+ up_read(&mm->mmap_sem);
11224+ switch (pax_handle_fetch_fault(regs)) {
11225+
11226+#ifdef CONFIG_PAX_EMUPLT
11227+ case 2:
11228+ case 3:
11229+ return;
11230+#endif
11231+
11232+ }
11233+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11234+ do_group_exit(SIGKILL);
11235+ }
11236+#endif
11237+
11238 /* Pure DTLB misses do not tell us whether the fault causing
11239 * load/store/atomic was a write or not, it only says that there
11240 * was no match. So in such a case we (carefully) read the
11241diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11242index 9639964..806cd0c 100644
11243--- a/arch/sparc/mm/hugetlbpage.c
11244+++ b/arch/sparc/mm/hugetlbpage.c
11245@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11246 unsigned long addr,
11247 unsigned long len,
11248 unsigned long pgoff,
11249- unsigned long flags)
11250+ unsigned long flags,
11251+ unsigned long offset)
11252 {
11253 unsigned long task_size = TASK_SIZE;
11254 struct vm_unmapped_area_info info;
11255@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11256
11257 info.flags = 0;
11258 info.length = len;
11259- info.low_limit = TASK_UNMAPPED_BASE;
11260+ info.low_limit = mm->mmap_base;
11261 info.high_limit = min(task_size, VA_EXCLUDE_START);
11262 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11263 info.align_offset = 0;
11264+ info.threadstack_offset = offset;
11265 addr = vm_unmapped_area(&info);
11266
11267 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11268 VM_BUG_ON(addr != -ENOMEM);
11269 info.low_limit = VA_EXCLUDE_END;
11270+
11271+#ifdef CONFIG_PAX_RANDMMAP
11272+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11273+ info.low_limit += mm->delta_mmap;
11274+#endif
11275+
11276 info.high_limit = task_size;
11277 addr = vm_unmapped_area(&info);
11278 }
11279@@ -58,7 +66,8 @@ static unsigned long
11280 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11281 const unsigned long len,
11282 const unsigned long pgoff,
11283- const unsigned long flags)
11284+ const unsigned long flags,
11285+ const unsigned long offset)
11286 {
11287 struct mm_struct *mm = current->mm;
11288 unsigned long addr = addr0;
11289@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11290 info.high_limit = mm->mmap_base;
11291 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11292 info.align_offset = 0;
11293+ info.threadstack_offset = offset;
11294 addr = vm_unmapped_area(&info);
11295
11296 /*
11297@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11298 VM_BUG_ON(addr != -ENOMEM);
11299 info.flags = 0;
11300 info.low_limit = TASK_UNMAPPED_BASE;
11301+
11302+#ifdef CONFIG_PAX_RANDMMAP
11303+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11304+ info.low_limit += mm->delta_mmap;
11305+#endif
11306+
11307 info.high_limit = STACK_TOP32;
11308 addr = vm_unmapped_area(&info);
11309 }
11310@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11311 struct mm_struct *mm = current->mm;
11312 struct vm_area_struct *vma;
11313 unsigned long task_size = TASK_SIZE;
11314+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11315
11316 if (test_thread_flag(TIF_32BIT))
11317 task_size = STACK_TOP32;
11318@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11319 return addr;
11320 }
11321
11322+#ifdef CONFIG_PAX_RANDMMAP
11323+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11324+#endif
11325+
11326 if (addr) {
11327 addr = ALIGN(addr, HPAGE_SIZE);
11328 vma = find_vma(mm, addr);
11329- if (task_size - len >= addr &&
11330- (!vma || addr + len <= vma->vm_start))
11331+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11332 return addr;
11333 }
11334 if (mm->get_unmapped_area == arch_get_unmapped_area)
11335 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11336- pgoff, flags);
11337+ pgoff, flags, offset);
11338 else
11339 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11340- pgoff, flags);
11341+ pgoff, flags, offset);
11342 }
11343
11344 pte_t *huge_pte_alloc(struct mm_struct *mm,
11345diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11346index ed82eda..0d80e77 100644
11347--- a/arch/sparc/mm/init_64.c
11348+++ b/arch/sparc/mm/init_64.c
11349@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11350 int num_kernel_image_mappings;
11351
11352 #ifdef CONFIG_DEBUG_DCFLUSH
11353-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11354+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11355 #ifdef CONFIG_SMP
11356-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11357+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11358 #endif
11359 #endif
11360
11361@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11362 {
11363 BUG_ON(tlb_type == hypervisor);
11364 #ifdef CONFIG_DEBUG_DCFLUSH
11365- atomic_inc(&dcpage_flushes);
11366+ atomic_inc_unchecked(&dcpage_flushes);
11367 #endif
11368
11369 #ifdef DCACHE_ALIASING_POSSIBLE
11370@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11371
11372 #ifdef CONFIG_DEBUG_DCFLUSH
11373 seq_printf(m, "DCPageFlushes\t: %d\n",
11374- atomic_read(&dcpage_flushes));
11375+ atomic_read_unchecked(&dcpage_flushes));
11376 #ifdef CONFIG_SMP
11377 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11378- atomic_read(&dcpage_flushes_xcall));
11379+ atomic_read_unchecked(&dcpage_flushes_xcall));
11380 #endif /* CONFIG_SMP */
11381 #endif /* CONFIG_DEBUG_DCFLUSH */
11382 }
11383diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11384index d45a2c4..3c05a78 100644
11385--- a/arch/tile/Kconfig
11386+++ b/arch/tile/Kconfig
11387@@ -185,6 +185,7 @@ source "kernel/Kconfig.hz"
11388
11389 config KEXEC
11390 bool "kexec system call"
11391+ depends on !GRKERNSEC_KMEM
11392 ---help---
11393 kexec is a system call that implements the ability to shutdown your
11394 current kernel, and to start another kernel. It is like a reboot
11395diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11396index ad220ee..2f537b3 100644
11397--- a/arch/tile/include/asm/atomic_64.h
11398+++ b/arch/tile/include/asm/atomic_64.h
11399@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11400
11401 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11402
11403+#define atomic64_read_unchecked(v) atomic64_read(v)
11404+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11405+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11406+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11407+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11408+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11409+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11410+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11411+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11412+
11413 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11414 #define smp_mb__before_atomic_dec() smp_mb()
11415 #define smp_mb__after_atomic_dec() smp_mb()
11416diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11417index 6160761..00cac88 100644
11418--- a/arch/tile/include/asm/cache.h
11419+++ b/arch/tile/include/asm/cache.h
11420@@ -15,11 +15,12 @@
11421 #ifndef _ASM_TILE_CACHE_H
11422 #define _ASM_TILE_CACHE_H
11423
11424+#include <linux/const.h>
11425 #include <arch/chip.h>
11426
11427 /* bytes per L1 data cache line */
11428 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11429-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11430+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11431
11432 /* bytes per L2 cache line */
11433 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11434diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11435index b6cde32..c0cb736 100644
11436--- a/arch/tile/include/asm/uaccess.h
11437+++ b/arch/tile/include/asm/uaccess.h
11438@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11439 const void __user *from,
11440 unsigned long n)
11441 {
11442- int sz = __compiletime_object_size(to);
11443+ size_t sz = __compiletime_object_size(to);
11444
11445- if (likely(sz == -1 || sz >= n))
11446+ if (likely(sz == (size_t)-1 || sz >= n))
11447 n = _copy_from_user(to, from, n);
11448 else
11449 copy_from_user_overflow();
11450diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11451index 0cb3bba..7338b2d 100644
11452--- a/arch/tile/mm/hugetlbpage.c
11453+++ b/arch/tile/mm/hugetlbpage.c
11454@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11455 info.high_limit = TASK_SIZE;
11456 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11457 info.align_offset = 0;
11458+ info.threadstack_offset = 0;
11459 return vm_unmapped_area(&info);
11460 }
11461
11462@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11463 info.high_limit = current->mm->mmap_base;
11464 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11465 info.align_offset = 0;
11466+ info.threadstack_offset = 0;
11467 addr = vm_unmapped_area(&info);
11468
11469 /*
11470diff --git a/arch/um/Makefile b/arch/um/Makefile
11471index 133f7de..1d6f2f1 100644
11472--- a/arch/um/Makefile
11473+++ b/arch/um/Makefile
11474@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11475 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11476 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11477
11478+ifdef CONSTIFY_PLUGIN
11479+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11480+endif
11481+
11482 #This will adjust *FLAGS accordingly to the platform.
11483 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11484
11485diff --git a/arch/um/defconfig b/arch/um/defconfig
11486index 2665e6b..3e3822b 100644
11487--- a/arch/um/defconfig
11488+++ b/arch/um/defconfig
11489@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11490 CONFIG_X86_L1_CACHE_SHIFT=5
11491 CONFIG_X86_XADD=y
11492 CONFIG_X86_PPRO_FENCE=y
11493-CONFIG_X86_WP_WORKS_OK=y
11494 CONFIG_X86_INVLPG=y
11495 CONFIG_X86_BSWAP=y
11496 CONFIG_X86_POPAD_OK=y
11497diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11498index 19e1bdd..3665b77 100644
11499--- a/arch/um/include/asm/cache.h
11500+++ b/arch/um/include/asm/cache.h
11501@@ -1,6 +1,7 @@
11502 #ifndef __UM_CACHE_H
11503 #define __UM_CACHE_H
11504
11505+#include <linux/const.h>
11506
11507 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11508 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11509@@ -12,6 +13,6 @@
11510 # define L1_CACHE_SHIFT 5
11511 #endif
11512
11513-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11514+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11515
11516 #endif
11517diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11518index 2e0a6b1..a64d0f5 100644
11519--- a/arch/um/include/asm/kmap_types.h
11520+++ b/arch/um/include/asm/kmap_types.h
11521@@ -8,6 +8,6 @@
11522
11523 /* No more #include "asm/arch/kmap_types.h" ! */
11524
11525-#define KM_TYPE_NR 14
11526+#define KM_TYPE_NR 15
11527
11528 #endif
11529diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11530index 5ff53d9..5850cdf 100644
11531--- a/arch/um/include/asm/page.h
11532+++ b/arch/um/include/asm/page.h
11533@@ -14,6 +14,9 @@
11534 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11535 #define PAGE_MASK (~(PAGE_SIZE-1))
11536
11537+#define ktla_ktva(addr) (addr)
11538+#define ktva_ktla(addr) (addr)
11539+
11540 #ifndef __ASSEMBLY__
11541
11542 struct page;
11543diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11544index 0032f92..cd151e0 100644
11545--- a/arch/um/include/asm/pgtable-3level.h
11546+++ b/arch/um/include/asm/pgtable-3level.h
11547@@ -58,6 +58,7 @@
11548 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11549 #define pud_populate(mm, pud, pmd) \
11550 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11551+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11552
11553 #ifdef CONFIG_64BIT
11554 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11555diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11556index bbcef52..6a2a483 100644
11557--- a/arch/um/kernel/process.c
11558+++ b/arch/um/kernel/process.c
11559@@ -367,22 +367,6 @@ int singlestepping(void * t)
11560 return 2;
11561 }
11562
11563-/*
11564- * Only x86 and x86_64 have an arch_align_stack().
11565- * All other arches have "#define arch_align_stack(x) (x)"
11566- * in their asm/system.h
11567- * As this is included in UML from asm-um/system-generic.h,
11568- * we can use it to behave as the subarch does.
11569- */
11570-#ifndef arch_align_stack
11571-unsigned long arch_align_stack(unsigned long sp)
11572-{
11573- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11574- sp -= get_random_int() % 8192;
11575- return sp & ~0xf;
11576-}
11577-#endif
11578-
11579 unsigned long get_wchan(struct task_struct *p)
11580 {
11581 unsigned long stack_page, sp, ip;
11582diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11583index ad8f795..2c7eec6 100644
11584--- a/arch/unicore32/include/asm/cache.h
11585+++ b/arch/unicore32/include/asm/cache.h
11586@@ -12,8 +12,10 @@
11587 #ifndef __UNICORE_CACHE_H__
11588 #define __UNICORE_CACHE_H__
11589
11590-#define L1_CACHE_SHIFT (5)
11591-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11592+#include <linux/const.h>
11593+
11594+#define L1_CACHE_SHIFT 5
11595+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11596
11597 /*
11598 * Memory returned by kmalloc() may be used for DMA, so we must make
11599diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11600index f67e839..bfd4748 100644
11601--- a/arch/x86/Kconfig
11602+++ b/arch/x86/Kconfig
11603@@ -247,7 +247,7 @@ config X86_HT
11604
11605 config X86_32_LAZY_GS
11606 def_bool y
11607- depends on X86_32 && !CC_STACKPROTECTOR
11608+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11609
11610 config ARCH_HWEIGHT_CFLAGS
11611 string
11612@@ -1099,6 +1099,7 @@ config MICROCODE_EARLY
11613
11614 config X86_MSR
11615 tristate "/dev/cpu/*/msr - Model-specific register support"
11616+ depends on !GRKERNSEC_KMEM
11617 ---help---
11618 This device gives privileged processes access to the x86
11619 Model-Specific Registers (MSRs). It is a character device with
11620@@ -1122,7 +1123,7 @@ choice
11621
11622 config NOHIGHMEM
11623 bool "off"
11624- depends on !X86_NUMAQ
11625+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11626 ---help---
11627 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11628 However, the address space of 32-bit x86 processors is only 4
11629@@ -1159,7 +1160,7 @@ config NOHIGHMEM
11630
11631 config HIGHMEM4G
11632 bool "4GB"
11633- depends on !X86_NUMAQ
11634+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11635 ---help---
11636 Select this if you have a 32-bit processor and between 1 and 4
11637 gigabytes of physical RAM.
11638@@ -1212,7 +1213,7 @@ config PAGE_OFFSET
11639 hex
11640 default 0xB0000000 if VMSPLIT_3G_OPT
11641 default 0x80000000 if VMSPLIT_2G
11642- default 0x78000000 if VMSPLIT_2G_OPT
11643+ default 0x70000000 if VMSPLIT_2G_OPT
11644 default 0x40000000 if VMSPLIT_1G
11645 default 0xC0000000
11646 depends on X86_32
11647@@ -1614,6 +1615,7 @@ config SECCOMP
11648
11649 config CC_STACKPROTECTOR
11650 bool "Enable -fstack-protector buffer overflow detection"
11651+ depends on X86_64 || !PAX_MEMORY_UDEREF
11652 ---help---
11653 This option turns on the -fstack-protector GCC feature. This
11654 feature puts, at the beginning of functions, a canary value on
11655@@ -1632,6 +1634,7 @@ source kernel/Kconfig.hz
11656
11657 config KEXEC
11658 bool "kexec system call"
11659+ depends on !GRKERNSEC_KMEM
11660 ---help---
11661 kexec is a system call that implements the ability to shutdown your
11662 current kernel, and to start another kernel. It is like a reboot
11663@@ -1733,6 +1736,8 @@ config X86_NEED_RELOCS
11664 config PHYSICAL_ALIGN
11665 hex "Alignment value to which kernel should be aligned"
11666 default "0x1000000"
11667+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11668+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11669 range 0x2000 0x1000000 if X86_32
11670 range 0x200000 0x1000000 if X86_64
11671 ---help---
11672@@ -1812,9 +1817,10 @@ config DEBUG_HOTPLUG_CPU0
11673 If unsure, say N.
11674
11675 config COMPAT_VDSO
11676- def_bool y
11677+ def_bool n
11678 prompt "Compat VDSO support"
11679 depends on X86_32 || IA32_EMULATION
11680+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11681 ---help---
11682 Map the 32-bit VDSO to the predictable old-style address too.
11683
11684diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11685index c026cca..14657ae 100644
11686--- a/arch/x86/Kconfig.cpu
11687+++ b/arch/x86/Kconfig.cpu
11688@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11689
11690 config X86_F00F_BUG
11691 def_bool y
11692- depends on M586MMX || M586TSC || M586 || M486
11693+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11694
11695 config X86_INVD_BUG
11696 def_bool y
11697@@ -327,7 +327,7 @@ config X86_INVD_BUG
11698
11699 config X86_ALIGNMENT_16
11700 def_bool y
11701- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11702+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11703
11704 config X86_INTEL_USERCOPY
11705 def_bool y
11706@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11707 # generates cmov.
11708 config X86_CMOV
11709 def_bool y
11710- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11711+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11712
11713 config X86_MINIMUM_CPU_FAMILY
11714 int
11715diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11716index 78d91af..8ceb94b 100644
11717--- a/arch/x86/Kconfig.debug
11718+++ b/arch/x86/Kconfig.debug
11719@@ -74,7 +74,7 @@ config X86_PTDUMP
11720 config DEBUG_RODATA
11721 bool "Write protect kernel read-only data structures"
11722 default y
11723- depends on DEBUG_KERNEL
11724+ depends on DEBUG_KERNEL && BROKEN
11725 ---help---
11726 Mark the kernel read-only data as write-protected in the pagetables,
11727 in order to catch accidental (and incorrect) writes to such const
11728@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11729
11730 config DEBUG_SET_MODULE_RONX
11731 bool "Set loadable kernel module data as NX and text as RO"
11732- depends on MODULES
11733+ depends on MODULES && BROKEN
11734 ---help---
11735 This option helps catch unintended modifications to loadable
11736 kernel module's text and read-only data. It also prevents execution
11737diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11738index 41250fb..863762e 100644
11739--- a/arch/x86/Makefile
11740+++ b/arch/x86/Makefile
11741@@ -46,14 +46,12 @@ ifeq ($(CONFIG_X86_32),y)
11742 # CPU-specific tuning. Anything which can be shared with UML should go here.
11743 include $(srctree)/arch/x86/Makefile_32.cpu
11744 KBUILD_CFLAGS += $(cflags-y)
11745-
11746- # temporary until string.h is fixed
11747- KBUILD_CFLAGS += -ffreestanding
11748 else
11749 BITS := 64
11750 UTS_MACHINE := x86_64
11751 CHECKFLAGS += -D__x86_64__ -m64
11752
11753+ biarch := $(call cc-option,-m64)
11754 KBUILD_AFLAGS += -m64
11755 KBUILD_CFLAGS += -m64
11756
11757@@ -83,6 +81,9 @@ else
11758 KBUILD_CFLAGS += -maccumulate-outgoing-args
11759 endif
11760
11761+# temporary until string.h is fixed
11762+KBUILD_CFLAGS += -ffreestanding
11763+
11764 ifdef CONFIG_CC_STACKPROTECTOR
11765 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11766 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11767@@ -241,3 +242,12 @@ define archhelp
11768 echo ' FDINITRD=file initrd for the booted kernel'
11769 echo ' kvmconfig - Enable additional options for guest kernel support'
11770 endef
11771+
11772+define OLD_LD
11773+
11774+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11775+*** Please upgrade your binutils to 2.18 or newer
11776+endef
11777+
11778+archprepare:
11779+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11780diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11781index 379814b..add62ce 100644
11782--- a/arch/x86/boot/Makefile
11783+++ b/arch/x86/boot/Makefile
11784@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11785 $(call cc-option, -fno-stack-protector) \
11786 $(call cc-option, -mpreferred-stack-boundary=2)
11787 KBUILD_CFLAGS += $(call cc-option, -m32)
11788+ifdef CONSTIFY_PLUGIN
11789+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11790+endif
11791 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11792 GCOV_PROFILE := n
11793
11794diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11795index 878e4b9..20537ab 100644
11796--- a/arch/x86/boot/bitops.h
11797+++ b/arch/x86/boot/bitops.h
11798@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11799 u8 v;
11800 const u32 *p = (const u32 *)addr;
11801
11802- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11803+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11804 return v;
11805 }
11806
11807@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11808
11809 static inline void set_bit(int nr, void *addr)
11810 {
11811- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11812+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11813 }
11814
11815 #endif /* BOOT_BITOPS_H */
11816diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11817index ef72bae..353a184 100644
11818--- a/arch/x86/boot/boot.h
11819+++ b/arch/x86/boot/boot.h
11820@@ -85,7 +85,7 @@ static inline void io_delay(void)
11821 static inline u16 ds(void)
11822 {
11823 u16 seg;
11824- asm("movw %%ds,%0" : "=rm" (seg));
11825+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11826 return seg;
11827 }
11828
11829@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11830 static inline int memcmp(const void *s1, const void *s2, size_t len)
11831 {
11832 u8 diff;
11833- asm("repe; cmpsb; setnz %0"
11834+ asm volatile("repe; cmpsb; setnz %0"
11835 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11836 return diff;
11837 }
11838diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11839index dcd90df..c830d7d 100644
11840--- a/arch/x86/boot/compressed/Makefile
11841+++ b/arch/x86/boot/compressed/Makefile
11842@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11843 KBUILD_CFLAGS += $(cflags-y)
11844 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11845 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11846+ifdef CONSTIFY_PLUGIN
11847+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11848+endif
11849
11850 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11851 GCOV_PROFILE := n
11852diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11853index b7388a4..03844ec 100644
11854--- a/arch/x86/boot/compressed/eboot.c
11855+++ b/arch/x86/boot/compressed/eboot.c
11856@@ -150,7 +150,6 @@ again:
11857 *addr = max_addr;
11858 }
11859
11860-free_pool:
11861 efi_call_phys1(sys_table->boottime->free_pool, map);
11862
11863 fail:
11864@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11865 if (i == map_size / desc_size)
11866 status = EFI_NOT_FOUND;
11867
11868-free_pool:
11869 efi_call_phys1(sys_table->boottime->free_pool, map);
11870 fail:
11871 return status;
11872diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11873index a53440e..c3dbf1e 100644
11874--- a/arch/x86/boot/compressed/efi_stub_32.S
11875+++ b/arch/x86/boot/compressed/efi_stub_32.S
11876@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11877 * parameter 2, ..., param n. To make things easy, we save the return
11878 * address of efi_call_phys in a global variable.
11879 */
11880- popl %ecx
11881- movl %ecx, saved_return_addr(%edx)
11882- /* get the function pointer into ECX*/
11883- popl %ecx
11884- movl %ecx, efi_rt_function_ptr(%edx)
11885+ popl saved_return_addr(%edx)
11886+ popl efi_rt_function_ptr(%edx)
11887
11888 /*
11889 * 3. Call the physical function.
11890 */
11891- call *%ecx
11892+ call *efi_rt_function_ptr(%edx)
11893
11894 /*
11895 * 4. Balance the stack. And because EAX contain the return value,
11896@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11897 1: popl %edx
11898 subl $1b, %edx
11899
11900- movl efi_rt_function_ptr(%edx), %ecx
11901- pushl %ecx
11902+ pushl efi_rt_function_ptr(%edx)
11903
11904 /*
11905 * 10. Push the saved return address onto the stack and return.
11906 */
11907- movl saved_return_addr(%edx), %ecx
11908- pushl %ecx
11909- ret
11910+ jmpl *saved_return_addr(%edx)
11911 ENDPROC(efi_call_phys)
11912 .previous
11913
11914diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11915index 5d6f689..9d06730 100644
11916--- a/arch/x86/boot/compressed/head_32.S
11917+++ b/arch/x86/boot/compressed/head_32.S
11918@@ -118,7 +118,7 @@ preferred_addr:
11919 notl %eax
11920 andl %eax, %ebx
11921 #else
11922- movl $LOAD_PHYSICAL_ADDR, %ebx
11923+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11924 #endif
11925
11926 /* Target address to relocate to for decompression */
11927diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11928index c337422..2c5be72 100644
11929--- a/arch/x86/boot/compressed/head_64.S
11930+++ b/arch/x86/boot/compressed/head_64.S
11931@@ -95,7 +95,7 @@ ENTRY(startup_32)
11932 notl %eax
11933 andl %eax, %ebx
11934 #else
11935- movl $LOAD_PHYSICAL_ADDR, %ebx
11936+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11937 #endif
11938
11939 /* Target address to relocate to for decompression */
11940@@ -270,7 +270,7 @@ preferred_addr:
11941 notq %rax
11942 andq %rax, %rbp
11943 #else
11944- movq $LOAD_PHYSICAL_ADDR, %rbp
11945+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11946 #endif
11947
11948 /* Target address to relocate to for decompression */
11949@@ -362,8 +362,8 @@ gdt:
11950 .long gdt
11951 .word 0
11952 .quad 0x0000000000000000 /* NULL descriptor */
11953- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11954- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11955+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11956+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11957 .quad 0x0080890000000000 /* TS descriptor */
11958 .quad 0x0000000000000000 /* TS continued */
11959 gdt_end:
11960diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11961index 434f077..b6b4b38 100644
11962--- a/arch/x86/boot/compressed/misc.c
11963+++ b/arch/x86/boot/compressed/misc.c
11964@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
11965 * Calculate the delta between where vmlinux was linked to load
11966 * and where it was actually loaded.
11967 */
11968- delta = min_addr - LOAD_PHYSICAL_ADDR;
11969+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
11970 if (!delta) {
11971 debug_putstr("No relocation needed... ");
11972 return;
11973@@ -380,7 +380,7 @@ static void parse_elf(void *output)
11974 case PT_LOAD:
11975 #ifdef CONFIG_RELOCATABLE
11976 dest = output;
11977- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11978+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11979 #else
11980 dest = (void *)(phdr->p_paddr);
11981 #endif
11982@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11983 error("Destination address too large");
11984 #endif
11985 #ifndef CONFIG_RELOCATABLE
11986- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11987+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11988 error("Wrong destination address");
11989 #endif
11990
11991diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11992index 4d3ff03..e4972ff 100644
11993--- a/arch/x86/boot/cpucheck.c
11994+++ b/arch/x86/boot/cpucheck.c
11995@@ -74,7 +74,7 @@ static int has_fpu(void)
11996 u16 fcw = -1, fsw = -1;
11997 u32 cr0;
11998
11999- asm("movl %%cr0,%0" : "=r" (cr0));
12000+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12001 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12002 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12003 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12004@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12005 {
12006 u32 f0, f1;
12007
12008- asm("pushfl ; "
12009+ asm volatile("pushfl ; "
12010 "pushfl ; "
12011 "popl %0 ; "
12012 "movl %0,%1 ; "
12013@@ -115,7 +115,7 @@ static void get_flags(void)
12014 set_bit(X86_FEATURE_FPU, cpu.flags);
12015
12016 if (has_eflag(X86_EFLAGS_ID)) {
12017- asm("cpuid"
12018+ asm volatile("cpuid"
12019 : "=a" (max_intel_level),
12020 "=b" (cpu_vendor[0]),
12021 "=d" (cpu_vendor[1]),
12022@@ -124,7 +124,7 @@ static void get_flags(void)
12023
12024 if (max_intel_level >= 0x00000001 &&
12025 max_intel_level <= 0x0000ffff) {
12026- asm("cpuid"
12027+ asm volatile("cpuid"
12028 : "=a" (tfms),
12029 "=c" (cpu.flags[4]),
12030 "=d" (cpu.flags[0])
12031@@ -136,7 +136,7 @@ static void get_flags(void)
12032 cpu.model += ((tfms >> 16) & 0xf) << 4;
12033 }
12034
12035- asm("cpuid"
12036+ asm volatile("cpuid"
12037 : "=a" (max_amd_level)
12038 : "a" (0x80000000)
12039 : "ebx", "ecx", "edx");
12040@@ -144,7 +144,7 @@ static void get_flags(void)
12041 if (max_amd_level >= 0x80000001 &&
12042 max_amd_level <= 0x8000ffff) {
12043 u32 eax = 0x80000001;
12044- asm("cpuid"
12045+ asm volatile("cpuid"
12046 : "+a" (eax),
12047 "=c" (cpu.flags[6]),
12048 "=d" (cpu.flags[1])
12049@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12050 u32 ecx = MSR_K7_HWCR;
12051 u32 eax, edx;
12052
12053- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12054+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12055 eax &= ~(1 << 15);
12056- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12057+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12058
12059 get_flags(); /* Make sure it really did something */
12060 err = check_flags();
12061@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12062 u32 ecx = MSR_VIA_FCR;
12063 u32 eax, edx;
12064
12065- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12066+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12067 eax |= (1<<1)|(1<<7);
12068- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12069+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12070
12071 set_bit(X86_FEATURE_CX8, cpu.flags);
12072 err = check_flags();
12073@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12074 u32 eax, edx;
12075 u32 level = 1;
12076
12077- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12078- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12079- asm("cpuid"
12080+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12081+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12082+ asm volatile("cpuid"
12083 : "+a" (level), "=d" (cpu.flags[0])
12084 : : "ecx", "ebx");
12085- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12086+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12087
12088 err = check_flags();
12089 }
12090diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12091index 9ec06a1..2c25e79 100644
12092--- a/arch/x86/boot/header.S
12093+++ b/arch/x86/boot/header.S
12094@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12095 # single linked list of
12096 # struct setup_data
12097
12098-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12099+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12100
12101 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12102+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12103+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12104+#else
12105 #define VO_INIT_SIZE (VO__end - VO__text)
12106+#endif
12107 #if ZO_INIT_SIZE > VO_INIT_SIZE
12108 #define INIT_SIZE ZO_INIT_SIZE
12109 #else
12110diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12111index db75d07..8e6d0af 100644
12112--- a/arch/x86/boot/memory.c
12113+++ b/arch/x86/boot/memory.c
12114@@ -19,7 +19,7 @@
12115
12116 static int detect_memory_e820(void)
12117 {
12118- int count = 0;
12119+ unsigned int count = 0;
12120 struct biosregs ireg, oreg;
12121 struct e820entry *desc = boot_params.e820_map;
12122 static struct e820entry buf; /* static so it is zeroed */
12123diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12124index 11e8c6e..fdbb1ed 100644
12125--- a/arch/x86/boot/video-vesa.c
12126+++ b/arch/x86/boot/video-vesa.c
12127@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12128
12129 boot_params.screen_info.vesapm_seg = oreg.es;
12130 boot_params.screen_info.vesapm_off = oreg.di;
12131+ boot_params.screen_info.vesapm_size = oreg.cx;
12132 }
12133
12134 /*
12135diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12136index 43eda28..5ab5fdb 100644
12137--- a/arch/x86/boot/video.c
12138+++ b/arch/x86/boot/video.c
12139@@ -96,7 +96,7 @@ static void store_mode_params(void)
12140 static unsigned int get_entry(void)
12141 {
12142 char entry_buf[4];
12143- int i, len = 0;
12144+ unsigned int i, len = 0;
12145 int key;
12146 unsigned int v;
12147
12148diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12149index 9105655..5e37f27 100644
12150--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12151+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12152@@ -8,6 +8,8 @@
12153 * including this sentence is retained in full.
12154 */
12155
12156+#include <asm/alternative-asm.h>
12157+
12158 .extern crypto_ft_tab
12159 .extern crypto_it_tab
12160 .extern crypto_fl_tab
12161@@ -70,6 +72,8 @@
12162 je B192; \
12163 leaq 32(r9),r9;
12164
12165+#define ret pax_force_retaddr 0, 1; ret
12166+
12167 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12168 movq r1,r2; \
12169 movq r3,r4; \
12170diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12171index 477e9d7..3ab339f 100644
12172--- a/arch/x86/crypto/aesni-intel_asm.S
12173+++ b/arch/x86/crypto/aesni-intel_asm.S
12174@@ -31,6 +31,7 @@
12175
12176 #include <linux/linkage.h>
12177 #include <asm/inst.h>
12178+#include <asm/alternative-asm.h>
12179
12180 #ifdef __x86_64__
12181 .data
12182@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12183 pop %r14
12184 pop %r13
12185 pop %r12
12186+ pax_force_retaddr 0, 1
12187 ret
12188 ENDPROC(aesni_gcm_dec)
12189
12190@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12191 pop %r14
12192 pop %r13
12193 pop %r12
12194+ pax_force_retaddr 0, 1
12195 ret
12196 ENDPROC(aesni_gcm_enc)
12197
12198@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12199 pxor %xmm1, %xmm0
12200 movaps %xmm0, (TKEYP)
12201 add $0x10, TKEYP
12202+ pax_force_retaddr_bts
12203 ret
12204 ENDPROC(_key_expansion_128)
12205 ENDPROC(_key_expansion_256a)
12206@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12207 shufps $0b01001110, %xmm2, %xmm1
12208 movaps %xmm1, 0x10(TKEYP)
12209 add $0x20, TKEYP
12210+ pax_force_retaddr_bts
12211 ret
12212 ENDPROC(_key_expansion_192a)
12213
12214@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12215
12216 movaps %xmm0, (TKEYP)
12217 add $0x10, TKEYP
12218+ pax_force_retaddr_bts
12219 ret
12220 ENDPROC(_key_expansion_192b)
12221
12222@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12223 pxor %xmm1, %xmm2
12224 movaps %xmm2, (TKEYP)
12225 add $0x10, TKEYP
12226+ pax_force_retaddr_bts
12227 ret
12228 ENDPROC(_key_expansion_256b)
12229
12230@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12231 #ifndef __x86_64__
12232 popl KEYP
12233 #endif
12234+ pax_force_retaddr 0, 1
12235 ret
12236 ENDPROC(aesni_set_key)
12237
12238@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12239 popl KLEN
12240 popl KEYP
12241 #endif
12242+ pax_force_retaddr 0, 1
12243 ret
12244 ENDPROC(aesni_enc)
12245
12246@@ -1974,6 +1983,7 @@ _aesni_enc1:
12247 AESENC KEY STATE
12248 movaps 0x70(TKEYP), KEY
12249 AESENCLAST KEY STATE
12250+ pax_force_retaddr_bts
12251 ret
12252 ENDPROC(_aesni_enc1)
12253
12254@@ -2083,6 +2093,7 @@ _aesni_enc4:
12255 AESENCLAST KEY STATE2
12256 AESENCLAST KEY STATE3
12257 AESENCLAST KEY STATE4
12258+ pax_force_retaddr_bts
12259 ret
12260 ENDPROC(_aesni_enc4)
12261
12262@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12263 popl KLEN
12264 popl KEYP
12265 #endif
12266+ pax_force_retaddr 0, 1
12267 ret
12268 ENDPROC(aesni_dec)
12269
12270@@ -2164,6 +2176,7 @@ _aesni_dec1:
12271 AESDEC KEY STATE
12272 movaps 0x70(TKEYP), KEY
12273 AESDECLAST KEY STATE
12274+ pax_force_retaddr_bts
12275 ret
12276 ENDPROC(_aesni_dec1)
12277
12278@@ -2273,6 +2286,7 @@ _aesni_dec4:
12279 AESDECLAST KEY STATE2
12280 AESDECLAST KEY STATE3
12281 AESDECLAST KEY STATE4
12282+ pax_force_retaddr_bts
12283 ret
12284 ENDPROC(_aesni_dec4)
12285
12286@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12287 popl KEYP
12288 popl LEN
12289 #endif
12290+ pax_force_retaddr 0, 1
12291 ret
12292 ENDPROC(aesni_ecb_enc)
12293
12294@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12295 popl KEYP
12296 popl LEN
12297 #endif
12298+ pax_force_retaddr 0, 1
12299 ret
12300 ENDPROC(aesni_ecb_dec)
12301
12302@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12303 popl LEN
12304 popl IVP
12305 #endif
12306+ pax_force_retaddr 0, 1
12307 ret
12308 ENDPROC(aesni_cbc_enc)
12309
12310@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12311 popl LEN
12312 popl IVP
12313 #endif
12314+ pax_force_retaddr 0, 1
12315 ret
12316 ENDPROC(aesni_cbc_dec)
12317
12318@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12319 mov $1, TCTR_LOW
12320 MOVQ_R64_XMM TCTR_LOW INC
12321 MOVQ_R64_XMM CTR TCTR_LOW
12322+ pax_force_retaddr_bts
12323 ret
12324 ENDPROC(_aesni_inc_init)
12325
12326@@ -2579,6 +2598,7 @@ _aesni_inc:
12327 .Linc_low:
12328 movaps CTR, IV
12329 PSHUFB_XMM BSWAP_MASK IV
12330+ pax_force_retaddr_bts
12331 ret
12332 ENDPROC(_aesni_inc)
12333
12334@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12335 .Lctr_enc_ret:
12336 movups IV, (IVP)
12337 .Lctr_enc_just_ret:
12338+ pax_force_retaddr 0, 1
12339 ret
12340 ENDPROC(aesni_ctr_enc)
12341
12342@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12343 pxor INC, STATE4
12344 movdqu STATE4, 0x70(OUTP)
12345
12346+ pax_force_retaddr 0, 1
12347 ret
12348 ENDPROC(aesni_xts_crypt8)
12349
12350diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12351index 246c670..4d1ed00 100644
12352--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12353+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12354@@ -21,6 +21,7 @@
12355 */
12356
12357 #include <linux/linkage.h>
12358+#include <asm/alternative-asm.h>
12359
12360 .file "blowfish-x86_64-asm.S"
12361 .text
12362@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12363 jnz .L__enc_xor;
12364
12365 write_block();
12366+ pax_force_retaddr 0, 1
12367 ret;
12368 .L__enc_xor:
12369 xor_block();
12370+ pax_force_retaddr 0, 1
12371 ret;
12372 ENDPROC(__blowfish_enc_blk)
12373
12374@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12375
12376 movq %r11, %rbp;
12377
12378+ pax_force_retaddr 0, 1
12379 ret;
12380 ENDPROC(blowfish_dec_blk)
12381
12382@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12383
12384 popq %rbx;
12385 popq %rbp;
12386+ pax_force_retaddr 0, 1
12387 ret;
12388
12389 .L__enc_xor4:
12390@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12391
12392 popq %rbx;
12393 popq %rbp;
12394+ pax_force_retaddr 0, 1
12395 ret;
12396 ENDPROC(__blowfish_enc_blk_4way)
12397
12398@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12399 popq %rbx;
12400 popq %rbp;
12401
12402+ pax_force_retaddr 0, 1
12403 ret;
12404 ENDPROC(blowfish_dec_blk_4way)
12405diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12406index ce71f92..2dd5b1e 100644
12407--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12408+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12409@@ -16,6 +16,7 @@
12410 */
12411
12412 #include <linux/linkage.h>
12413+#include <asm/alternative-asm.h>
12414
12415 #define CAMELLIA_TABLE_BYTE_LEN 272
12416
12417@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12418 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12419 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12420 %rcx, (%r9));
12421+ pax_force_retaddr_bts
12422 ret;
12423 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12424
12425@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12426 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12427 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12428 %rax, (%r9));
12429+ pax_force_retaddr_bts
12430 ret;
12431 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12432
12433@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12434 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12435 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12436
12437+ pax_force_retaddr_bts
12438 ret;
12439
12440 .align 8
12441@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12442 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12443 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12444
12445+ pax_force_retaddr_bts
12446 ret;
12447
12448 .align 8
12449@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12450 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12451 %xmm8, %rsi);
12452
12453+ pax_force_retaddr 0, 1
12454 ret;
12455 ENDPROC(camellia_ecb_enc_16way)
12456
12457@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12458 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12459 %xmm8, %rsi);
12460
12461+ pax_force_retaddr 0, 1
12462 ret;
12463 ENDPROC(camellia_ecb_dec_16way)
12464
12465@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12466 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12467 %xmm8, %rsi);
12468
12469+ pax_force_retaddr 0, 1
12470 ret;
12471 ENDPROC(camellia_cbc_dec_16way)
12472
12473@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12474 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12475 %xmm8, %rsi);
12476
12477+ pax_force_retaddr 0, 1
12478 ret;
12479 ENDPROC(camellia_ctr_16way)
12480
12481@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12482 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12483 %xmm8, %rsi);
12484
12485+ pax_force_retaddr 0, 1
12486 ret;
12487 ENDPROC(camellia_xts_crypt_16way)
12488
12489diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12490index 0e0b886..8fc756a 100644
12491--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12492+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12493@@ -11,6 +11,7 @@
12494 */
12495
12496 #include <linux/linkage.h>
12497+#include <asm/alternative-asm.h>
12498
12499 #define CAMELLIA_TABLE_BYTE_LEN 272
12500
12501@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12502 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12503 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12504 %rcx, (%r9));
12505+ pax_force_retaddr_bts
12506 ret;
12507 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12508
12509@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12510 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12511 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12512 %rax, (%r9));
12513+ pax_force_retaddr_bts
12514 ret;
12515 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12516
12517@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12518 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12519 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12520
12521+ pax_force_retaddr_bts
12522 ret;
12523
12524 .align 8
12525@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12526 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12527 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12528
12529+ pax_force_retaddr_bts
12530 ret;
12531
12532 .align 8
12533@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12534
12535 vzeroupper;
12536
12537+ pax_force_retaddr 0, 1
12538 ret;
12539 ENDPROC(camellia_ecb_enc_32way)
12540
12541@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12542
12543 vzeroupper;
12544
12545+ pax_force_retaddr 0, 1
12546 ret;
12547 ENDPROC(camellia_ecb_dec_32way)
12548
12549@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12550
12551 vzeroupper;
12552
12553+ pax_force_retaddr 0, 1
12554 ret;
12555 ENDPROC(camellia_cbc_dec_32way)
12556
12557@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12558
12559 vzeroupper;
12560
12561+ pax_force_retaddr 0, 1
12562 ret;
12563 ENDPROC(camellia_ctr_32way)
12564
12565@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12566
12567 vzeroupper;
12568
12569+ pax_force_retaddr 0, 1
12570 ret;
12571 ENDPROC(camellia_xts_crypt_32way)
12572
12573diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12574index 310319c..ce174a4 100644
12575--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12576+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12577@@ -21,6 +21,7 @@
12578 */
12579
12580 #include <linux/linkage.h>
12581+#include <asm/alternative-asm.h>
12582
12583 .file "camellia-x86_64-asm_64.S"
12584 .text
12585@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12586 enc_outunpack(mov, RT1);
12587
12588 movq RRBP, %rbp;
12589+ pax_force_retaddr 0, 1
12590 ret;
12591
12592 .L__enc_xor:
12593 enc_outunpack(xor, RT1);
12594
12595 movq RRBP, %rbp;
12596+ pax_force_retaddr 0, 1
12597 ret;
12598 ENDPROC(__camellia_enc_blk)
12599
12600@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12601 dec_outunpack();
12602
12603 movq RRBP, %rbp;
12604+ pax_force_retaddr 0, 1
12605 ret;
12606 ENDPROC(camellia_dec_blk)
12607
12608@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12609
12610 movq RRBP, %rbp;
12611 popq %rbx;
12612+ pax_force_retaddr 0, 1
12613 ret;
12614
12615 .L__enc2_xor:
12616@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12617
12618 movq RRBP, %rbp;
12619 popq %rbx;
12620+ pax_force_retaddr 0, 1
12621 ret;
12622 ENDPROC(__camellia_enc_blk_2way)
12623
12624@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12625
12626 movq RRBP, %rbp;
12627 movq RXOR, %rbx;
12628+ pax_force_retaddr 0, 1
12629 ret;
12630 ENDPROC(camellia_dec_blk_2way)
12631diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12632index c35fd5d..c1ee236 100644
12633--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12634+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12635@@ -24,6 +24,7 @@
12636 */
12637
12638 #include <linux/linkage.h>
12639+#include <asm/alternative-asm.h>
12640
12641 .file "cast5-avx-x86_64-asm_64.S"
12642
12643@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12644 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12645 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12646
12647+ pax_force_retaddr 0, 1
12648 ret;
12649 ENDPROC(__cast5_enc_blk16)
12650
12651@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12652 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12653 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12654
12655+ pax_force_retaddr 0, 1
12656 ret;
12657
12658 .L__skip_dec:
12659@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12660 vmovdqu RR4, (6*4*4)(%r11);
12661 vmovdqu RL4, (7*4*4)(%r11);
12662
12663+ pax_force_retaddr
12664 ret;
12665 ENDPROC(cast5_ecb_enc_16way)
12666
12667@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12668 vmovdqu RR4, (6*4*4)(%r11);
12669 vmovdqu RL4, (7*4*4)(%r11);
12670
12671+ pax_force_retaddr
12672 ret;
12673 ENDPROC(cast5_ecb_dec_16way)
12674
12675@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12676
12677 popq %r12;
12678
12679+ pax_force_retaddr
12680 ret;
12681 ENDPROC(cast5_cbc_dec_16way)
12682
12683@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12684
12685 popq %r12;
12686
12687+ pax_force_retaddr
12688 ret;
12689 ENDPROC(cast5_ctr_16way)
12690diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12691index e3531f8..18ded3a 100644
12692--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12693+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12694@@ -24,6 +24,7 @@
12695 */
12696
12697 #include <linux/linkage.h>
12698+#include <asm/alternative-asm.h>
12699 #include "glue_helper-asm-avx.S"
12700
12701 .file "cast6-avx-x86_64-asm_64.S"
12702@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12703 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12704 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12705
12706+ pax_force_retaddr 0, 1
12707 ret;
12708 ENDPROC(__cast6_enc_blk8)
12709
12710@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12711 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12712 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12713
12714+ pax_force_retaddr 0, 1
12715 ret;
12716 ENDPROC(__cast6_dec_blk8)
12717
12718@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12719
12720 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12721
12722+ pax_force_retaddr
12723 ret;
12724 ENDPROC(cast6_ecb_enc_8way)
12725
12726@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12727
12728 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12729
12730+ pax_force_retaddr
12731 ret;
12732 ENDPROC(cast6_ecb_dec_8way)
12733
12734@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12735
12736 popq %r12;
12737
12738+ pax_force_retaddr
12739 ret;
12740 ENDPROC(cast6_cbc_dec_8way)
12741
12742@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12743
12744 popq %r12;
12745
12746+ pax_force_retaddr
12747 ret;
12748 ENDPROC(cast6_ctr_8way)
12749
12750@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12751 /* dst <= regs xor IVs(in dst) */
12752 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12753
12754+ pax_force_retaddr
12755 ret;
12756 ENDPROC(cast6_xts_enc_8way)
12757
12758@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12759 /* dst <= regs xor IVs(in dst) */
12760 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12761
12762+ pax_force_retaddr
12763 ret;
12764 ENDPROC(cast6_xts_dec_8way)
12765diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12766index dbc4339..3d868c5 100644
12767--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12768+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12769@@ -45,6 +45,7 @@
12770
12771 #include <asm/inst.h>
12772 #include <linux/linkage.h>
12773+#include <asm/alternative-asm.h>
12774
12775 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12776
12777@@ -312,6 +313,7 @@ do_return:
12778 popq %rsi
12779 popq %rdi
12780 popq %rbx
12781+ pax_force_retaddr 0, 1
12782 ret
12783
12784 ################################################################
12785diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12786index 586f41a..d02851e 100644
12787--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12788+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12789@@ -18,6 +18,7 @@
12790
12791 #include <linux/linkage.h>
12792 #include <asm/inst.h>
12793+#include <asm/alternative-asm.h>
12794
12795 .data
12796
12797@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12798 psrlq $1, T2
12799 pxor T2, T1
12800 pxor T1, DATA
12801+ pax_force_retaddr
12802 ret
12803 ENDPROC(__clmul_gf128mul_ble)
12804
12805@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12806 call __clmul_gf128mul_ble
12807 PSHUFB_XMM BSWAP DATA
12808 movups DATA, (%rdi)
12809+ pax_force_retaddr
12810 ret
12811 ENDPROC(clmul_ghash_mul)
12812
12813@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12814 PSHUFB_XMM BSWAP DATA
12815 movups DATA, (%rdi)
12816 .Lupdate_just_ret:
12817+ pax_force_retaddr
12818 ret
12819 ENDPROC(clmul_ghash_update)
12820
12821@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12822 pand .Lpoly, %xmm1
12823 pxor %xmm1, %xmm0
12824 movups %xmm0, (%rdi)
12825+ pax_force_retaddr
12826 ret
12827 ENDPROC(clmul_ghash_setkey)
12828diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12829index 9279e0b..9270820 100644
12830--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12831+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12832@@ -1,4 +1,5 @@
12833 #include <linux/linkage.h>
12834+#include <asm/alternative-asm.h>
12835
12836 # enter salsa20_encrypt_bytes
12837 ENTRY(salsa20_encrypt_bytes)
12838@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12839 add %r11,%rsp
12840 mov %rdi,%rax
12841 mov %rsi,%rdx
12842+ pax_force_retaddr 0, 1
12843 ret
12844 # bytesatleast65:
12845 ._bytesatleast65:
12846@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12847 add %r11,%rsp
12848 mov %rdi,%rax
12849 mov %rsi,%rdx
12850+ pax_force_retaddr
12851 ret
12852 ENDPROC(salsa20_keysetup)
12853
12854@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12855 add %r11,%rsp
12856 mov %rdi,%rax
12857 mov %rsi,%rdx
12858+ pax_force_retaddr
12859 ret
12860 ENDPROC(salsa20_ivsetup)
12861diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12862index 2f202f4..d9164d6 100644
12863--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12864+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12865@@ -24,6 +24,7 @@
12866 */
12867
12868 #include <linux/linkage.h>
12869+#include <asm/alternative-asm.h>
12870 #include "glue_helper-asm-avx.S"
12871
12872 .file "serpent-avx-x86_64-asm_64.S"
12873@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12874 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12875 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12876
12877+ pax_force_retaddr
12878 ret;
12879 ENDPROC(__serpent_enc_blk8_avx)
12880
12881@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12882 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12883 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12884
12885+ pax_force_retaddr
12886 ret;
12887 ENDPROC(__serpent_dec_blk8_avx)
12888
12889@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12890
12891 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12892
12893+ pax_force_retaddr
12894 ret;
12895 ENDPROC(serpent_ecb_enc_8way_avx)
12896
12897@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12898
12899 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12900
12901+ pax_force_retaddr
12902 ret;
12903 ENDPROC(serpent_ecb_dec_8way_avx)
12904
12905@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12906
12907 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12908
12909+ pax_force_retaddr
12910 ret;
12911 ENDPROC(serpent_cbc_dec_8way_avx)
12912
12913@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12914
12915 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12916
12917+ pax_force_retaddr
12918 ret;
12919 ENDPROC(serpent_ctr_8way_avx)
12920
12921@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12922 /* dst <= regs xor IVs(in dst) */
12923 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12924
12925+ pax_force_retaddr
12926 ret;
12927 ENDPROC(serpent_xts_enc_8way_avx)
12928
12929@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12930 /* dst <= regs xor IVs(in dst) */
12931 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12932
12933+ pax_force_retaddr
12934 ret;
12935 ENDPROC(serpent_xts_dec_8way_avx)
12936diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12937index b222085..abd483c 100644
12938--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12939+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12940@@ -15,6 +15,7 @@
12941 */
12942
12943 #include <linux/linkage.h>
12944+#include <asm/alternative-asm.h>
12945 #include "glue_helper-asm-avx2.S"
12946
12947 .file "serpent-avx2-asm_64.S"
12948@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12949 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12950 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12951
12952+ pax_force_retaddr
12953 ret;
12954 ENDPROC(__serpent_enc_blk16)
12955
12956@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12957 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12958 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12959
12960+ pax_force_retaddr
12961 ret;
12962 ENDPROC(__serpent_dec_blk16)
12963
12964@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12965
12966 vzeroupper;
12967
12968+ pax_force_retaddr
12969 ret;
12970 ENDPROC(serpent_ecb_enc_16way)
12971
12972@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12973
12974 vzeroupper;
12975
12976+ pax_force_retaddr
12977 ret;
12978 ENDPROC(serpent_ecb_dec_16way)
12979
12980@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12981
12982 vzeroupper;
12983
12984+ pax_force_retaddr
12985 ret;
12986 ENDPROC(serpent_cbc_dec_16way)
12987
12988@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12989
12990 vzeroupper;
12991
12992+ pax_force_retaddr
12993 ret;
12994 ENDPROC(serpent_ctr_16way)
12995
12996@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12997
12998 vzeroupper;
12999
13000+ pax_force_retaddr
13001 ret;
13002 ENDPROC(serpent_xts_enc_16way)
13003
13004@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13005
13006 vzeroupper;
13007
13008+ pax_force_retaddr
13009 ret;
13010 ENDPROC(serpent_xts_dec_16way)
13011diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13012index acc066c..1559cc4 100644
13013--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13014+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13015@@ -25,6 +25,7 @@
13016 */
13017
13018 #include <linux/linkage.h>
13019+#include <asm/alternative-asm.h>
13020
13021 .file "serpent-sse2-x86_64-asm_64.S"
13022 .text
13023@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13024 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13025 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13026
13027+ pax_force_retaddr
13028 ret;
13029
13030 .L__enc_xor8:
13031 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13032 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13033
13034+ pax_force_retaddr
13035 ret;
13036 ENDPROC(__serpent_enc_blk_8way)
13037
13038@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13039 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13040 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13041
13042+ pax_force_retaddr
13043 ret;
13044 ENDPROC(serpent_dec_blk_8way)
13045diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13046index a410950..3356d42 100644
13047--- a/arch/x86/crypto/sha1_ssse3_asm.S
13048+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13049@@ -29,6 +29,7 @@
13050 */
13051
13052 #include <linux/linkage.h>
13053+#include <asm/alternative-asm.h>
13054
13055 #define CTX %rdi // arg1
13056 #define BUF %rsi // arg2
13057@@ -104,6 +105,7 @@
13058 pop %r12
13059 pop %rbp
13060 pop %rbx
13061+ pax_force_retaddr 0, 1
13062 ret
13063
13064 ENDPROC(\name)
13065diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13066index 642f156..4ab07b9 100644
13067--- a/arch/x86/crypto/sha256-avx-asm.S
13068+++ b/arch/x86/crypto/sha256-avx-asm.S
13069@@ -49,6 +49,7 @@
13070
13071 #ifdef CONFIG_AS_AVX
13072 #include <linux/linkage.h>
13073+#include <asm/alternative-asm.h>
13074
13075 ## assume buffers not aligned
13076 #define VMOVDQ vmovdqu
13077@@ -460,6 +461,7 @@ done_hash:
13078 popq %r13
13079 popq %rbp
13080 popq %rbx
13081+ pax_force_retaddr 0, 1
13082 ret
13083 ENDPROC(sha256_transform_avx)
13084
13085diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13086index 9e86944..2e7f95a 100644
13087--- a/arch/x86/crypto/sha256-avx2-asm.S
13088+++ b/arch/x86/crypto/sha256-avx2-asm.S
13089@@ -50,6 +50,7 @@
13090
13091 #ifdef CONFIG_AS_AVX2
13092 #include <linux/linkage.h>
13093+#include <asm/alternative-asm.h>
13094
13095 ## assume buffers not aligned
13096 #define VMOVDQ vmovdqu
13097@@ -720,6 +721,7 @@ done_hash:
13098 popq %r12
13099 popq %rbp
13100 popq %rbx
13101+ pax_force_retaddr 0, 1
13102 ret
13103 ENDPROC(sha256_transform_rorx)
13104
13105diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13106index f833b74..c36ed14 100644
13107--- a/arch/x86/crypto/sha256-ssse3-asm.S
13108+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13109@@ -47,6 +47,7 @@
13110 ########################################################################
13111
13112 #include <linux/linkage.h>
13113+#include <asm/alternative-asm.h>
13114
13115 ## assume buffers not aligned
13116 #define MOVDQ movdqu
13117@@ -471,6 +472,7 @@ done_hash:
13118 popq %rbp
13119 popq %rbx
13120
13121+ pax_force_retaddr 0, 1
13122 ret
13123 ENDPROC(sha256_transform_ssse3)
13124
13125diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13126index 974dde9..4533d34 100644
13127--- a/arch/x86/crypto/sha512-avx-asm.S
13128+++ b/arch/x86/crypto/sha512-avx-asm.S
13129@@ -49,6 +49,7 @@
13130
13131 #ifdef CONFIG_AS_AVX
13132 #include <linux/linkage.h>
13133+#include <asm/alternative-asm.h>
13134
13135 .text
13136
13137@@ -364,6 +365,7 @@ updateblock:
13138 mov frame_RSPSAVE(%rsp), %rsp
13139
13140 nowork:
13141+ pax_force_retaddr 0, 1
13142 ret
13143 ENDPROC(sha512_transform_avx)
13144
13145diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13146index 568b961..061ef1d 100644
13147--- a/arch/x86/crypto/sha512-avx2-asm.S
13148+++ b/arch/x86/crypto/sha512-avx2-asm.S
13149@@ -51,6 +51,7 @@
13150
13151 #ifdef CONFIG_AS_AVX2
13152 #include <linux/linkage.h>
13153+#include <asm/alternative-asm.h>
13154
13155 .text
13156
13157@@ -678,6 +679,7 @@ done_hash:
13158
13159 # Restore Stack Pointer
13160 mov frame_RSPSAVE(%rsp), %rsp
13161+ pax_force_retaddr 0, 1
13162 ret
13163 ENDPROC(sha512_transform_rorx)
13164
13165diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13166index fb56855..e23914f 100644
13167--- a/arch/x86/crypto/sha512-ssse3-asm.S
13168+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13169@@ -48,6 +48,7 @@
13170 ########################################################################
13171
13172 #include <linux/linkage.h>
13173+#include <asm/alternative-asm.h>
13174
13175 .text
13176
13177@@ -363,6 +364,7 @@ updateblock:
13178 mov frame_RSPSAVE(%rsp), %rsp
13179
13180 nowork:
13181+ pax_force_retaddr 0, 1
13182 ret
13183 ENDPROC(sha512_transform_ssse3)
13184
13185diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13186index 0505813..63b1d00 100644
13187--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13188+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13189@@ -24,6 +24,7 @@
13190 */
13191
13192 #include <linux/linkage.h>
13193+#include <asm/alternative-asm.h>
13194 #include "glue_helper-asm-avx.S"
13195
13196 .file "twofish-avx-x86_64-asm_64.S"
13197@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13198 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13199 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13200
13201+ pax_force_retaddr 0, 1
13202 ret;
13203 ENDPROC(__twofish_enc_blk8)
13204
13205@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13206 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13207 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13208
13209+ pax_force_retaddr 0, 1
13210 ret;
13211 ENDPROC(__twofish_dec_blk8)
13212
13213@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13214
13215 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13216
13217+ pax_force_retaddr 0, 1
13218 ret;
13219 ENDPROC(twofish_ecb_enc_8way)
13220
13221@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13222
13223 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13224
13225+ pax_force_retaddr 0, 1
13226 ret;
13227 ENDPROC(twofish_ecb_dec_8way)
13228
13229@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13230
13231 popq %r12;
13232
13233+ pax_force_retaddr 0, 1
13234 ret;
13235 ENDPROC(twofish_cbc_dec_8way)
13236
13237@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13238
13239 popq %r12;
13240
13241+ pax_force_retaddr 0, 1
13242 ret;
13243 ENDPROC(twofish_ctr_8way)
13244
13245@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13246 /* dst <= regs xor IVs(in dst) */
13247 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13248
13249+ pax_force_retaddr 0, 1
13250 ret;
13251 ENDPROC(twofish_xts_enc_8way)
13252
13253@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13254 /* dst <= regs xor IVs(in dst) */
13255 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13256
13257+ pax_force_retaddr 0, 1
13258 ret;
13259 ENDPROC(twofish_xts_dec_8way)
13260diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13261index 1c3b7ce..b365c5e 100644
13262--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13263+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13264@@ -21,6 +21,7 @@
13265 */
13266
13267 #include <linux/linkage.h>
13268+#include <asm/alternative-asm.h>
13269
13270 .file "twofish-x86_64-asm-3way.S"
13271 .text
13272@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13273 popq %r13;
13274 popq %r14;
13275 popq %r15;
13276+ pax_force_retaddr 0, 1
13277 ret;
13278
13279 .L__enc_xor3:
13280@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13281 popq %r13;
13282 popq %r14;
13283 popq %r15;
13284+ pax_force_retaddr 0, 1
13285 ret;
13286 ENDPROC(__twofish_enc_blk_3way)
13287
13288@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13289 popq %r13;
13290 popq %r14;
13291 popq %r15;
13292+ pax_force_retaddr 0, 1
13293 ret;
13294 ENDPROC(twofish_dec_blk_3way)
13295diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13296index a039d21..29e7615 100644
13297--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13298+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13299@@ -22,6 +22,7 @@
13300
13301 #include <linux/linkage.h>
13302 #include <asm/asm-offsets.h>
13303+#include <asm/alternative-asm.h>
13304
13305 #define a_offset 0
13306 #define b_offset 4
13307@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13308
13309 popq R1
13310 movq $1,%rax
13311+ pax_force_retaddr 0, 1
13312 ret
13313 ENDPROC(twofish_enc_blk)
13314
13315@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13316
13317 popq R1
13318 movq $1,%rax
13319+ pax_force_retaddr 0, 1
13320 ret
13321 ENDPROC(twofish_dec_blk)
13322diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13323index bae3aba..c1788c1 100644
13324--- a/arch/x86/ia32/ia32_aout.c
13325+++ b/arch/x86/ia32/ia32_aout.c
13326@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13327 unsigned long dump_start, dump_size;
13328 struct user32 dump;
13329
13330+ memset(&dump, 0, sizeof(dump));
13331+
13332 fs = get_fs();
13333 set_fs(KERNEL_DS);
13334 has_dumped = 1;
13335diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13336index 665a730..8e7a67a 100644
13337--- a/arch/x86/ia32/ia32_signal.c
13338+++ b/arch/x86/ia32/ia32_signal.c
13339@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13340 sp -= frame_size;
13341 /* Align the stack pointer according to the i386 ABI,
13342 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13343- sp = ((sp + 4) & -16ul) - 4;
13344+ sp = ((sp - 12) & -16ul) - 4;
13345 return (void __user *) sp;
13346 }
13347
13348@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13349 * These are actually not used anymore, but left because some
13350 * gdb versions depend on them as a marker.
13351 */
13352- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13353+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13354 } put_user_catch(err);
13355
13356 if (err)
13357@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13358 0xb8,
13359 __NR_ia32_rt_sigreturn,
13360 0x80cd,
13361- 0,
13362+ 0
13363 };
13364
13365 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13366@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13367
13368 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13369 restorer = ksig->ka.sa.sa_restorer;
13370+ else if (current->mm->context.vdso)
13371+ /* Return stub is in 32bit vsyscall page */
13372+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13373 else
13374- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13375- rt_sigreturn);
13376+ restorer = &frame->retcode;
13377 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13378
13379 /*
13380 * Not actually used anymore, but left because some gdb
13381 * versions need it.
13382 */
13383- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13384+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13385 } put_user_catch(err);
13386
13387 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13388diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13389index 4299eb0..904b82a 100644
13390--- a/arch/x86/ia32/ia32entry.S
13391+++ b/arch/x86/ia32/ia32entry.S
13392@@ -15,8 +15,10 @@
13393 #include <asm/irqflags.h>
13394 #include <asm/asm.h>
13395 #include <asm/smap.h>
13396+#include <asm/pgtable.h>
13397 #include <linux/linkage.h>
13398 #include <linux/err.h>
13399+#include <asm/alternative-asm.h>
13400
13401 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13402 #include <linux/elf-em.h>
13403@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13404 ENDPROC(native_irq_enable_sysexit)
13405 #endif
13406
13407+ .macro pax_enter_kernel_user
13408+ pax_set_fptr_mask
13409+#ifdef CONFIG_PAX_MEMORY_UDEREF
13410+ call pax_enter_kernel_user
13411+#endif
13412+ .endm
13413+
13414+ .macro pax_exit_kernel_user
13415+#ifdef CONFIG_PAX_MEMORY_UDEREF
13416+ call pax_exit_kernel_user
13417+#endif
13418+#ifdef CONFIG_PAX_RANDKSTACK
13419+ pushq %rax
13420+ pushq %r11
13421+ call pax_randomize_kstack
13422+ popq %r11
13423+ popq %rax
13424+#endif
13425+ .endm
13426+
13427+ .macro pax_erase_kstack
13428+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13429+ call pax_erase_kstack
13430+#endif
13431+ .endm
13432+
13433 /*
13434 * 32bit SYSENTER instruction entry.
13435 *
13436@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13437 CFI_REGISTER rsp,rbp
13438 SWAPGS_UNSAFE_STACK
13439 movq PER_CPU_VAR(kernel_stack), %rsp
13440- addq $(KERNEL_STACK_OFFSET),%rsp
13441- /*
13442- * No need to follow this irqs on/off section: the syscall
13443- * disabled irqs, here we enable it straight after entry:
13444- */
13445- ENABLE_INTERRUPTS(CLBR_NONE)
13446 movl %ebp,%ebp /* zero extension */
13447 pushq_cfi $__USER32_DS
13448 /*CFI_REL_OFFSET ss,0*/
13449@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13450 CFI_REL_OFFSET rsp,0
13451 pushfq_cfi
13452 /*CFI_REL_OFFSET rflags,0*/
13453- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13454- CFI_REGISTER rip,r10
13455+ orl $X86_EFLAGS_IF,(%rsp)
13456+ GET_THREAD_INFO(%r11)
13457+ movl TI_sysenter_return(%r11), %r11d
13458+ CFI_REGISTER rip,r11
13459 pushq_cfi $__USER32_CS
13460 /*CFI_REL_OFFSET cs,0*/
13461 movl %eax, %eax
13462- pushq_cfi %r10
13463+ pushq_cfi %r11
13464 CFI_REL_OFFSET rip,0
13465 pushq_cfi %rax
13466 cld
13467 SAVE_ARGS 0,1,0
13468+ pax_enter_kernel_user
13469+
13470+#ifdef CONFIG_PAX_RANDKSTACK
13471+ pax_erase_kstack
13472+#endif
13473+
13474+ /*
13475+ * No need to follow this irqs on/off section: the syscall
13476+ * disabled irqs, here we enable it straight after entry:
13477+ */
13478+ ENABLE_INTERRUPTS(CLBR_NONE)
13479 /* no need to do an access_ok check here because rbp has been
13480 32bit zero extended */
13481+
13482+#ifdef CONFIG_PAX_MEMORY_UDEREF
13483+ addq pax_user_shadow_base,%rbp
13484+ ASM_PAX_OPEN_USERLAND
13485+#endif
13486+
13487 ASM_STAC
13488 1: movl (%rbp),%ebp
13489 _ASM_EXTABLE(1b,ia32_badarg)
13490 ASM_CLAC
13491- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13492- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13493+
13494+#ifdef CONFIG_PAX_MEMORY_UDEREF
13495+ ASM_PAX_CLOSE_USERLAND
13496+#endif
13497+
13498+ GET_THREAD_INFO(%r11)
13499+ orl $TS_COMPAT,TI_status(%r11)
13500+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13501 CFI_REMEMBER_STATE
13502 jnz sysenter_tracesys
13503 cmpq $(IA32_NR_syscalls-1),%rax
13504@@ -162,12 +209,15 @@ sysenter_do_call:
13505 sysenter_dispatch:
13506 call *ia32_sys_call_table(,%rax,8)
13507 movq %rax,RAX-ARGOFFSET(%rsp)
13508+ GET_THREAD_INFO(%r11)
13509 DISABLE_INTERRUPTS(CLBR_NONE)
13510 TRACE_IRQS_OFF
13511- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13512+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13513 jnz sysexit_audit
13514 sysexit_from_sys_call:
13515- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13516+ pax_exit_kernel_user
13517+ pax_erase_kstack
13518+ andl $~TS_COMPAT,TI_status(%r11)
13519 /* clear IF, that popfq doesn't enable interrupts early */
13520 andl $~0x200,EFLAGS-R11(%rsp)
13521 movl RIP-R11(%rsp),%edx /* User %eip */
13522@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13523 movl %eax,%esi /* 2nd arg: syscall number */
13524 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13525 call __audit_syscall_entry
13526+
13527+ pax_erase_kstack
13528+
13529 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13530 cmpq $(IA32_NR_syscalls-1),%rax
13531 ja ia32_badsys
13532@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13533 .endm
13534
13535 .macro auditsys_exit exit
13536- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13537+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13538 jnz ia32_ret_from_sys_call
13539 TRACE_IRQS_ON
13540 ENABLE_INTERRUPTS(CLBR_NONE)
13541@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13542 1: setbe %al /* 1 if error, 0 if not */
13543 movzbl %al,%edi /* zero-extend that into %edi */
13544 call __audit_syscall_exit
13545+ GET_THREAD_INFO(%r11)
13546 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13547 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13548 DISABLE_INTERRUPTS(CLBR_NONE)
13549 TRACE_IRQS_OFF
13550- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13551+ testl %edi,TI_flags(%r11)
13552 jz \exit
13553 CLEAR_RREGS -ARGOFFSET
13554 jmp int_with_check
13555@@ -237,7 +291,7 @@ sysexit_audit:
13556
13557 sysenter_tracesys:
13558 #ifdef CONFIG_AUDITSYSCALL
13559- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13560+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13561 jz sysenter_auditsys
13562 #endif
13563 SAVE_REST
13564@@ -249,6 +303,9 @@ sysenter_tracesys:
13565 RESTORE_REST
13566 cmpq $(IA32_NR_syscalls-1),%rax
13567 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13568+
13569+ pax_erase_kstack
13570+
13571 jmp sysenter_do_call
13572 CFI_ENDPROC
13573 ENDPROC(ia32_sysenter_target)
13574@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13575 ENTRY(ia32_cstar_target)
13576 CFI_STARTPROC32 simple
13577 CFI_SIGNAL_FRAME
13578- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13579+ CFI_DEF_CFA rsp,0
13580 CFI_REGISTER rip,rcx
13581 /*CFI_REGISTER rflags,r11*/
13582 SWAPGS_UNSAFE_STACK
13583 movl %esp,%r8d
13584 CFI_REGISTER rsp,r8
13585 movq PER_CPU_VAR(kernel_stack),%rsp
13586+ SAVE_ARGS 8*6,0,0
13587+ pax_enter_kernel_user
13588+
13589+#ifdef CONFIG_PAX_RANDKSTACK
13590+ pax_erase_kstack
13591+#endif
13592+
13593 /*
13594 * No need to follow this irqs on/off section: the syscall
13595 * disabled irqs and here we enable it straight after entry:
13596 */
13597 ENABLE_INTERRUPTS(CLBR_NONE)
13598- SAVE_ARGS 8,0,0
13599 movl %eax,%eax /* zero extension */
13600 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13601 movq %rcx,RIP-ARGOFFSET(%rsp)
13602@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13603 /* no need to do an access_ok check here because r8 has been
13604 32bit zero extended */
13605 /* hardware stack frame is complete now */
13606+
13607+#ifdef CONFIG_PAX_MEMORY_UDEREF
13608+ ASM_PAX_OPEN_USERLAND
13609+ movq pax_user_shadow_base,%r8
13610+ addq RSP-ARGOFFSET(%rsp),%r8
13611+#endif
13612+
13613 ASM_STAC
13614 1: movl (%r8),%r9d
13615 _ASM_EXTABLE(1b,ia32_badarg)
13616 ASM_CLAC
13617- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13618- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13619+
13620+#ifdef CONFIG_PAX_MEMORY_UDEREF
13621+ ASM_PAX_CLOSE_USERLAND
13622+#endif
13623+
13624+ GET_THREAD_INFO(%r11)
13625+ orl $TS_COMPAT,TI_status(%r11)
13626+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13627 CFI_REMEMBER_STATE
13628 jnz cstar_tracesys
13629 cmpq $IA32_NR_syscalls-1,%rax
13630@@ -319,12 +395,15 @@ cstar_do_call:
13631 cstar_dispatch:
13632 call *ia32_sys_call_table(,%rax,8)
13633 movq %rax,RAX-ARGOFFSET(%rsp)
13634+ GET_THREAD_INFO(%r11)
13635 DISABLE_INTERRUPTS(CLBR_NONE)
13636 TRACE_IRQS_OFF
13637- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13638+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13639 jnz sysretl_audit
13640 sysretl_from_sys_call:
13641- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13642+ pax_exit_kernel_user
13643+ pax_erase_kstack
13644+ andl $~TS_COMPAT,TI_status(%r11)
13645 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13646 movl RIP-ARGOFFSET(%rsp),%ecx
13647 CFI_REGISTER rip,rcx
13648@@ -352,7 +431,7 @@ sysretl_audit:
13649
13650 cstar_tracesys:
13651 #ifdef CONFIG_AUDITSYSCALL
13652- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13653+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13654 jz cstar_auditsys
13655 #endif
13656 xchgl %r9d,%ebp
13657@@ -366,11 +445,19 @@ cstar_tracesys:
13658 xchgl %ebp,%r9d
13659 cmpq $(IA32_NR_syscalls-1),%rax
13660 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13661+
13662+ pax_erase_kstack
13663+
13664 jmp cstar_do_call
13665 END(ia32_cstar_target)
13666
13667 ia32_badarg:
13668 ASM_CLAC
13669+
13670+#ifdef CONFIG_PAX_MEMORY_UDEREF
13671+ ASM_PAX_CLOSE_USERLAND
13672+#endif
13673+
13674 movq $-EFAULT,%rax
13675 jmp ia32_sysret
13676 CFI_ENDPROC
13677@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13678 CFI_REL_OFFSET rip,RIP-RIP
13679 PARAVIRT_ADJUST_EXCEPTION_FRAME
13680 SWAPGS
13681- /*
13682- * No need to follow this irqs on/off section: the syscall
13683- * disabled irqs and here we enable it straight after entry:
13684- */
13685- ENABLE_INTERRUPTS(CLBR_NONE)
13686 movl %eax,%eax
13687 pushq_cfi %rax
13688 cld
13689 /* note the registers are not zero extended to the sf.
13690 this could be a problem. */
13691 SAVE_ARGS 0,1,0
13692- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13693- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13694+ pax_enter_kernel_user
13695+
13696+#ifdef CONFIG_PAX_RANDKSTACK
13697+ pax_erase_kstack
13698+#endif
13699+
13700+ /*
13701+ * No need to follow this irqs on/off section: the syscall
13702+ * disabled irqs and here we enable it straight after entry:
13703+ */
13704+ ENABLE_INTERRUPTS(CLBR_NONE)
13705+ GET_THREAD_INFO(%r11)
13706+ orl $TS_COMPAT,TI_status(%r11)
13707+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13708 jnz ia32_tracesys
13709 cmpq $(IA32_NR_syscalls-1),%rax
13710 ja ia32_badsys
13711@@ -442,6 +536,9 @@ ia32_tracesys:
13712 RESTORE_REST
13713 cmpq $(IA32_NR_syscalls-1),%rax
13714 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13715+
13716+ pax_erase_kstack
13717+
13718 jmp ia32_do_call
13719 END(ia32_syscall)
13720
13721diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13722index 8e0ceec..af13504 100644
13723--- a/arch/x86/ia32/sys_ia32.c
13724+++ b/arch/x86/ia32/sys_ia32.c
13725@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13726 */
13727 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13728 {
13729- typeof(ubuf->st_uid) uid = 0;
13730- typeof(ubuf->st_gid) gid = 0;
13731+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13732+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13733 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13734 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13735 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13736diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13737index 372231c..a5aa1a1 100644
13738--- a/arch/x86/include/asm/alternative-asm.h
13739+++ b/arch/x86/include/asm/alternative-asm.h
13740@@ -18,6 +18,45 @@
13741 .endm
13742 #endif
13743
13744+#ifdef KERNEXEC_PLUGIN
13745+ .macro pax_force_retaddr_bts rip=0
13746+ btsq $63,\rip(%rsp)
13747+ .endm
13748+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13749+ .macro pax_force_retaddr rip=0, reload=0
13750+ btsq $63,\rip(%rsp)
13751+ .endm
13752+ .macro pax_force_fptr ptr
13753+ btsq $63,\ptr
13754+ .endm
13755+ .macro pax_set_fptr_mask
13756+ .endm
13757+#endif
13758+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13759+ .macro pax_force_retaddr rip=0, reload=0
13760+ .if \reload
13761+ pax_set_fptr_mask
13762+ .endif
13763+ orq %r10,\rip(%rsp)
13764+ .endm
13765+ .macro pax_force_fptr ptr
13766+ orq %r10,\ptr
13767+ .endm
13768+ .macro pax_set_fptr_mask
13769+ movabs $0x8000000000000000,%r10
13770+ .endm
13771+#endif
13772+#else
13773+ .macro pax_force_retaddr rip=0, reload=0
13774+ .endm
13775+ .macro pax_force_fptr ptr
13776+ .endm
13777+ .macro pax_force_retaddr_bts rip=0
13778+ .endm
13779+ .macro pax_set_fptr_mask
13780+ .endm
13781+#endif
13782+
13783 .macro altinstruction_entry orig alt feature orig_len alt_len
13784 .long \orig - .
13785 .long \alt - .
13786diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13787index 0a3f9c9..c9d081d 100644
13788--- a/arch/x86/include/asm/alternative.h
13789+++ b/arch/x86/include/asm/alternative.h
13790@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13791 ".pushsection .discard,\"aw\",@progbits\n" \
13792 DISCARD_ENTRY(1) \
13793 ".popsection\n" \
13794- ".pushsection .altinstr_replacement, \"ax\"\n" \
13795+ ".pushsection .altinstr_replacement, \"a\"\n" \
13796 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13797 ".popsection"
13798
13799@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13800 DISCARD_ENTRY(1) \
13801 DISCARD_ENTRY(2) \
13802 ".popsection\n" \
13803- ".pushsection .altinstr_replacement, \"ax\"\n" \
13804+ ".pushsection .altinstr_replacement, \"a\"\n" \
13805 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13806 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13807 ".popsection"
13808diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13809index 1d2091a..f5074c1 100644
13810--- a/arch/x86/include/asm/apic.h
13811+++ b/arch/x86/include/asm/apic.h
13812@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13813
13814 #ifdef CONFIG_X86_LOCAL_APIC
13815
13816-extern unsigned int apic_verbosity;
13817+extern int apic_verbosity;
13818 extern int local_apic_timer_c2_ok;
13819
13820 extern int disable_apic;
13821diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13822index 20370c6..a2eb9b0 100644
13823--- a/arch/x86/include/asm/apm.h
13824+++ b/arch/x86/include/asm/apm.h
13825@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13826 __asm__ __volatile__(APM_DO_ZERO_SEGS
13827 "pushl %%edi\n\t"
13828 "pushl %%ebp\n\t"
13829- "lcall *%%cs:apm_bios_entry\n\t"
13830+ "lcall *%%ss:apm_bios_entry\n\t"
13831 "setc %%al\n\t"
13832 "popl %%ebp\n\t"
13833 "popl %%edi\n\t"
13834@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13835 __asm__ __volatile__(APM_DO_ZERO_SEGS
13836 "pushl %%edi\n\t"
13837 "pushl %%ebp\n\t"
13838- "lcall *%%cs:apm_bios_entry\n\t"
13839+ "lcall *%%ss:apm_bios_entry\n\t"
13840 "setc %%bl\n\t"
13841 "popl %%ebp\n\t"
13842 "popl %%edi\n\t"
13843diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13844index 722aa3b..3a0bb27 100644
13845--- a/arch/x86/include/asm/atomic.h
13846+++ b/arch/x86/include/asm/atomic.h
13847@@ -22,7 +22,18 @@
13848 */
13849 static inline int atomic_read(const atomic_t *v)
13850 {
13851- return (*(volatile int *)&(v)->counter);
13852+ return (*(volatile const int *)&(v)->counter);
13853+}
13854+
13855+/**
13856+ * atomic_read_unchecked - read atomic variable
13857+ * @v: pointer of type atomic_unchecked_t
13858+ *
13859+ * Atomically reads the value of @v.
13860+ */
13861+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13862+{
13863+ return (*(volatile const int *)&(v)->counter);
13864 }
13865
13866 /**
13867@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13868 }
13869
13870 /**
13871+ * atomic_set_unchecked - set atomic variable
13872+ * @v: pointer of type atomic_unchecked_t
13873+ * @i: required value
13874+ *
13875+ * Atomically sets the value of @v to @i.
13876+ */
13877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13878+{
13879+ v->counter = i;
13880+}
13881+
13882+/**
13883 * atomic_add - add integer to atomic variable
13884 * @i: integer value to add
13885 * @v: pointer of type atomic_t
13886@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13887 */
13888 static inline void atomic_add(int i, atomic_t *v)
13889 {
13890- asm volatile(LOCK_PREFIX "addl %1,%0"
13891+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13892+
13893+#ifdef CONFIG_PAX_REFCOUNT
13894+ "jno 0f\n"
13895+ LOCK_PREFIX "subl %1,%0\n"
13896+ "int $4\n0:\n"
13897+ _ASM_EXTABLE(0b, 0b)
13898+#endif
13899+
13900+ : "+m" (v->counter)
13901+ : "ir" (i));
13902+}
13903+
13904+/**
13905+ * atomic_add_unchecked - add integer to atomic variable
13906+ * @i: integer value to add
13907+ * @v: pointer of type atomic_unchecked_t
13908+ *
13909+ * Atomically adds @i to @v.
13910+ */
13911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13912+{
13913+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13914 : "+m" (v->counter)
13915 : "ir" (i));
13916 }
13917@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13918 */
13919 static inline void atomic_sub(int i, atomic_t *v)
13920 {
13921- asm volatile(LOCK_PREFIX "subl %1,%0"
13922+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13923+
13924+#ifdef CONFIG_PAX_REFCOUNT
13925+ "jno 0f\n"
13926+ LOCK_PREFIX "addl %1,%0\n"
13927+ "int $4\n0:\n"
13928+ _ASM_EXTABLE(0b, 0b)
13929+#endif
13930+
13931+ : "+m" (v->counter)
13932+ : "ir" (i));
13933+}
13934+
13935+/**
13936+ * atomic_sub_unchecked - subtract integer from atomic variable
13937+ * @i: integer value to subtract
13938+ * @v: pointer of type atomic_unchecked_t
13939+ *
13940+ * Atomically subtracts @i from @v.
13941+ */
13942+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13943+{
13944+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13945 : "+m" (v->counter)
13946 : "ir" (i));
13947 }
13948@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13949 {
13950 unsigned char c;
13951
13952- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13953+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13954+
13955+#ifdef CONFIG_PAX_REFCOUNT
13956+ "jno 0f\n"
13957+ LOCK_PREFIX "addl %2,%0\n"
13958+ "int $4\n0:\n"
13959+ _ASM_EXTABLE(0b, 0b)
13960+#endif
13961+
13962+ "sete %1\n"
13963 : "+m" (v->counter), "=qm" (c)
13964 : "ir" (i) : "memory");
13965 return c;
13966@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13967 */
13968 static inline void atomic_inc(atomic_t *v)
13969 {
13970- asm volatile(LOCK_PREFIX "incl %0"
13971+ asm volatile(LOCK_PREFIX "incl %0\n"
13972+
13973+#ifdef CONFIG_PAX_REFCOUNT
13974+ "jno 0f\n"
13975+ LOCK_PREFIX "decl %0\n"
13976+ "int $4\n0:\n"
13977+ _ASM_EXTABLE(0b, 0b)
13978+#endif
13979+
13980+ : "+m" (v->counter));
13981+}
13982+
13983+/**
13984+ * atomic_inc_unchecked - increment atomic variable
13985+ * @v: pointer of type atomic_unchecked_t
13986+ *
13987+ * Atomically increments @v by 1.
13988+ */
13989+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13990+{
13991+ asm volatile(LOCK_PREFIX "incl %0\n"
13992 : "+m" (v->counter));
13993 }
13994
13995@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13996 */
13997 static inline void atomic_dec(atomic_t *v)
13998 {
13999- asm volatile(LOCK_PREFIX "decl %0"
14000+ asm volatile(LOCK_PREFIX "decl %0\n"
14001+
14002+#ifdef CONFIG_PAX_REFCOUNT
14003+ "jno 0f\n"
14004+ LOCK_PREFIX "incl %0\n"
14005+ "int $4\n0:\n"
14006+ _ASM_EXTABLE(0b, 0b)
14007+#endif
14008+
14009+ : "+m" (v->counter));
14010+}
14011+
14012+/**
14013+ * atomic_dec_unchecked - decrement atomic variable
14014+ * @v: pointer of type atomic_unchecked_t
14015+ *
14016+ * Atomically decrements @v by 1.
14017+ */
14018+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14019+{
14020+ asm volatile(LOCK_PREFIX "decl %0\n"
14021 : "+m" (v->counter));
14022 }
14023
14024@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
14025 {
14026 unsigned char c;
14027
14028- asm volatile(LOCK_PREFIX "decl %0; sete %1"
14029+ asm volatile(LOCK_PREFIX "decl %0\n"
14030+
14031+#ifdef CONFIG_PAX_REFCOUNT
14032+ "jno 0f\n"
14033+ LOCK_PREFIX "incl %0\n"
14034+ "int $4\n0:\n"
14035+ _ASM_EXTABLE(0b, 0b)
14036+#endif
14037+
14038+ "sete %1\n"
14039 : "+m" (v->counter), "=qm" (c)
14040 : : "memory");
14041 return c != 0;
14042@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
14043 {
14044 unsigned char c;
14045
14046- asm volatile(LOCK_PREFIX "incl %0; sete %1"
14047+ asm volatile(LOCK_PREFIX "incl %0\n"
14048+
14049+#ifdef CONFIG_PAX_REFCOUNT
14050+ "jno 0f\n"
14051+ LOCK_PREFIX "decl %0\n"
14052+ "int $4\n0:\n"
14053+ _ASM_EXTABLE(0b, 0b)
14054+#endif
14055+
14056+ "sete %1\n"
14057+ : "+m" (v->counter), "=qm" (c)
14058+ : : "memory");
14059+ return c != 0;
14060+}
14061+
14062+/**
14063+ * atomic_inc_and_test_unchecked - increment and test
14064+ * @v: pointer of type atomic_unchecked_t
14065+ *
14066+ * Atomically increments @v by 1
14067+ * and returns true if the result is zero, or false for all
14068+ * other cases.
14069+ */
14070+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14071+{
14072+ unsigned char c;
14073+
14074+ asm volatile(LOCK_PREFIX "incl %0\n"
14075+ "sete %1\n"
14076 : "+m" (v->counter), "=qm" (c)
14077 : : "memory");
14078 return c != 0;
14079@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14080 {
14081 unsigned char c;
14082
14083- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14084+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14085+
14086+#ifdef CONFIG_PAX_REFCOUNT
14087+ "jno 0f\n"
14088+ LOCK_PREFIX "subl %2,%0\n"
14089+ "int $4\n0:\n"
14090+ _ASM_EXTABLE(0b, 0b)
14091+#endif
14092+
14093+ "sets %1\n"
14094 : "+m" (v->counter), "=qm" (c)
14095 : "ir" (i) : "memory");
14096 return c;
14097@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14098 */
14099 static inline int atomic_add_return(int i, atomic_t *v)
14100 {
14101+ return i + xadd_check_overflow(&v->counter, i);
14102+}
14103+
14104+/**
14105+ * atomic_add_return_unchecked - add integer and return
14106+ * @i: integer value to add
14107+ * @v: pointer of type atomic_unchecked_t
14108+ *
14109+ * Atomically adds @i to @v and returns @i + @v
14110+ */
14111+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14112+{
14113 return i + xadd(&v->counter, i);
14114 }
14115
14116@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14117 }
14118
14119 #define atomic_inc_return(v) (atomic_add_return(1, v))
14120+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14121+{
14122+ return atomic_add_return_unchecked(1, v);
14123+}
14124 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14125
14126 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14127@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14128 return cmpxchg(&v->counter, old, new);
14129 }
14130
14131+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14132+{
14133+ return cmpxchg(&v->counter, old, new);
14134+}
14135+
14136 static inline int atomic_xchg(atomic_t *v, int new)
14137 {
14138 return xchg(&v->counter, new);
14139 }
14140
14141+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14142+{
14143+ return xchg(&v->counter, new);
14144+}
14145+
14146 /**
14147 * __atomic_add_unless - add unless the number is already a given value
14148 * @v: pointer of type atomic_t
14149@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14150 */
14151 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14152 {
14153- int c, old;
14154+ int c, old, new;
14155 c = atomic_read(v);
14156 for (;;) {
14157- if (unlikely(c == (u)))
14158+ if (unlikely(c == u))
14159 break;
14160- old = atomic_cmpxchg((v), c, c + (a));
14161+
14162+ asm volatile("addl %2,%0\n"
14163+
14164+#ifdef CONFIG_PAX_REFCOUNT
14165+ "jno 0f\n"
14166+ "subl %2,%0\n"
14167+ "int $4\n0:\n"
14168+ _ASM_EXTABLE(0b, 0b)
14169+#endif
14170+
14171+ : "=r" (new)
14172+ : "0" (c), "ir" (a));
14173+
14174+ old = atomic_cmpxchg(v, c, new);
14175 if (likely(old == c))
14176 break;
14177 c = old;
14178@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14179 }
14180
14181 /**
14182+ * atomic_inc_not_zero_hint - increment if not null
14183+ * @v: pointer of type atomic_t
14184+ * @hint: probable value of the atomic before the increment
14185+ *
14186+ * This version of atomic_inc_not_zero() gives a hint of probable
14187+ * value of the atomic. This helps processor to not read the memory
14188+ * before doing the atomic read/modify/write cycle, lowering
14189+ * number of bus transactions on some arches.
14190+ *
14191+ * Returns: 0 if increment was not done, 1 otherwise.
14192+ */
14193+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14194+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14195+{
14196+ int val, c = hint, new;
14197+
14198+ /* sanity test, should be removed by compiler if hint is a constant */
14199+ if (!hint)
14200+ return __atomic_add_unless(v, 1, 0);
14201+
14202+ do {
14203+ asm volatile("incl %0\n"
14204+
14205+#ifdef CONFIG_PAX_REFCOUNT
14206+ "jno 0f\n"
14207+ "decl %0\n"
14208+ "int $4\n0:\n"
14209+ _ASM_EXTABLE(0b, 0b)
14210+#endif
14211+
14212+ : "=r" (new)
14213+ : "0" (c));
14214+
14215+ val = atomic_cmpxchg(v, c, new);
14216+ if (val == c)
14217+ return 1;
14218+ c = val;
14219+ } while (c);
14220+
14221+ return 0;
14222+}
14223+
14224+/**
14225 * atomic_inc_short - increment of a short integer
14226 * @v: pointer to type int
14227 *
14228@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14229 #endif
14230
14231 /* These are x86-specific, used by some header files */
14232-#define atomic_clear_mask(mask, addr) \
14233- asm volatile(LOCK_PREFIX "andl %0,%1" \
14234- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14235+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14236+{
14237+ asm volatile(LOCK_PREFIX "andl %1,%0"
14238+ : "+m" (v->counter)
14239+ : "r" (~(mask))
14240+ : "memory");
14241+}
14242
14243-#define atomic_set_mask(mask, addr) \
14244- asm volatile(LOCK_PREFIX "orl %0,%1" \
14245- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14246- : "memory")
14247+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14248+{
14249+ asm volatile(LOCK_PREFIX "andl %1,%0"
14250+ : "+m" (v->counter)
14251+ : "r" (~(mask))
14252+ : "memory");
14253+}
14254+
14255+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14256+{
14257+ asm volatile(LOCK_PREFIX "orl %1,%0"
14258+ : "+m" (v->counter)
14259+ : "r" (mask)
14260+ : "memory");
14261+}
14262+
14263+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14264+{
14265+ asm volatile(LOCK_PREFIX "orl %1,%0"
14266+ : "+m" (v->counter)
14267+ : "r" (mask)
14268+ : "memory");
14269+}
14270
14271 /* Atomic operations are already serializing on x86 */
14272 #define smp_mb__before_atomic_dec() barrier()
14273diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14274index b154de7..a7cef48 100644
14275--- a/arch/x86/include/asm/atomic64_32.h
14276+++ b/arch/x86/include/asm/atomic64_32.h
14277@@ -12,6 +12,14 @@ typedef struct {
14278 u64 __aligned(8) counter;
14279 } atomic64_t;
14280
14281+#ifdef CONFIG_PAX_REFCOUNT
14282+typedef struct {
14283+ u64 __aligned(8) counter;
14284+} atomic64_unchecked_t;
14285+#else
14286+typedef atomic64_t atomic64_unchecked_t;
14287+#endif
14288+
14289 #define ATOMIC64_INIT(val) { (val) }
14290
14291 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14292@@ -37,21 +45,31 @@ typedef struct {
14293 ATOMIC64_DECL_ONE(sym##_386)
14294
14295 ATOMIC64_DECL_ONE(add_386);
14296+ATOMIC64_DECL_ONE(add_unchecked_386);
14297 ATOMIC64_DECL_ONE(sub_386);
14298+ATOMIC64_DECL_ONE(sub_unchecked_386);
14299 ATOMIC64_DECL_ONE(inc_386);
14300+ATOMIC64_DECL_ONE(inc_unchecked_386);
14301 ATOMIC64_DECL_ONE(dec_386);
14302+ATOMIC64_DECL_ONE(dec_unchecked_386);
14303 #endif
14304
14305 #define alternative_atomic64(f, out, in...) \
14306 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14307
14308 ATOMIC64_DECL(read);
14309+ATOMIC64_DECL(read_unchecked);
14310 ATOMIC64_DECL(set);
14311+ATOMIC64_DECL(set_unchecked);
14312 ATOMIC64_DECL(xchg);
14313 ATOMIC64_DECL(add_return);
14314+ATOMIC64_DECL(add_return_unchecked);
14315 ATOMIC64_DECL(sub_return);
14316+ATOMIC64_DECL(sub_return_unchecked);
14317 ATOMIC64_DECL(inc_return);
14318+ATOMIC64_DECL(inc_return_unchecked);
14319 ATOMIC64_DECL(dec_return);
14320+ATOMIC64_DECL(dec_return_unchecked);
14321 ATOMIC64_DECL(dec_if_positive);
14322 ATOMIC64_DECL(inc_not_zero);
14323 ATOMIC64_DECL(add_unless);
14324@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14325 }
14326
14327 /**
14328+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14329+ * @p: pointer to type atomic64_unchecked_t
14330+ * @o: expected value
14331+ * @n: new value
14332+ *
14333+ * Atomically sets @v to @n if it was equal to @o and returns
14334+ * the old value.
14335+ */
14336+
14337+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14338+{
14339+ return cmpxchg64(&v->counter, o, n);
14340+}
14341+
14342+/**
14343 * atomic64_xchg - xchg atomic64 variable
14344 * @v: pointer to type atomic64_t
14345 * @n: value to assign
14346@@ -112,12 +145,41 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14347 }
14348
14349 /**
14350+ * atomic64_set_unchecked - set atomic64 variable
14351+ * @v: pointer to type atomic64_unchecked_t
14352+ * @n: value to assign
14353+ *
14354+ * Atomically sets the value of @v to @n.
14355+ */
14356+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14357+{
14358+ unsigned high = (unsigned)(i >> 32);
14359+ unsigned low = (unsigned)i;
14360+ alternative_atomic64(set, /* no output */,
14361+ "S" (v), "b" (low), "c" (high)
14362+ : "eax", "edx", "memory");
14363+}
14364+
14365+/**
14366 * atomic64_read - read atomic64 variable
14367 * @v: pointer to type atomic64_t
14368 *
14369 * Atomically reads the value of @v and returns it.
14370 */
14371-static inline long long atomic64_read(const atomic64_t *v)
14372+static inline long long __intentional_overflow(-1) atomic64_read(const atomic64_t *v)
14373+{
14374+ long long r;
14375+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14376+ return r;
14377+ }
14378+
14379+/**
14380+ * atomic64_read_unchecked - read atomic64 variable
14381+ * @v: pointer to type atomic64_unchecked_t
14382+ *
14383+ * Atomically reads the value of @v and returns it.
14384+ */
14385+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14386 {
14387 long long r;
14388 alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14389@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14390 return i;
14391 }
14392
14393+/**
14394+ * atomic64_add_return_unchecked - add and return
14395+ * @i: integer value to add
14396+ * @v: pointer to type atomic64_unchecked_t
14397+ *
14398+ * Atomically adds @i to @v and returns @i + *@v
14399+ */
14400+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14401+{
14402+ alternative_atomic64(add_return_unchecked,
14403+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14404+ ASM_NO_INPUT_CLOBBER("memory"));
14405+ return i;
14406+}
14407+
14408 /*
14409 * Other variants with different arithmetic operators:
14410 */
14411@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14412 return a;
14413 }
14414
14415+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14416+{
14417+ long long a;
14418+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14419+ "S" (v) : "memory", "ecx");
14420+ return a;
14421+}
14422+
14423 static inline long long atomic64_dec_return(atomic64_t *v)
14424 {
14425 long long a;
14426@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14427 }
14428
14429 /**
14430+ * atomic64_add_unchecked - add integer to atomic64 variable
14431+ * @i: integer value to add
14432+ * @v: pointer to type atomic64_unchecked_t
14433+ *
14434+ * Atomically adds @i to @v.
14435+ */
14436+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14437+{
14438+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14439+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14440+ ASM_NO_INPUT_CLOBBER("memory"));
14441+ return i;
14442+}
14443+
14444+/**
14445 * atomic64_sub - subtract the atomic64 variable
14446 * @i: integer value to subtract
14447 * @v: pointer to type atomic64_t
14448diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14449index 0e1cbfc..adf5aa7 100644
14450--- a/arch/x86/include/asm/atomic64_64.h
14451+++ b/arch/x86/include/asm/atomic64_64.h
14452@@ -16,9 +16,21 @@
14453 * Atomically reads the value of @v.
14454 * Doesn't imply a read memory barrier.
14455 */
14456-static inline long atomic64_read(const atomic64_t *v)
14457+static inline long __intentional_overflow(-1) atomic64_read(const atomic64_t *v)
14458 {
14459- return (*(volatile long *)&(v)->counter);
14460+ return (*(volatile const long *)&(v)->counter);
14461+}
14462+
14463+/**
14464+ * atomic64_read_unchecked - read atomic64 variable
14465+ * @v: pointer of type atomic64_unchecked_t
14466+ *
14467+ * Atomically reads the value of @v.
14468+ * Doesn't imply a read memory barrier.
14469+ */
14470+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14471+{
14472+ return (*(volatile const long *)&(v)->counter);
14473 }
14474
14475 /**
14476@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14477 }
14478
14479 /**
14480+ * atomic64_set_unchecked - set atomic64 variable
14481+ * @v: pointer to type atomic64_unchecked_t
14482+ * @i: required value
14483+ *
14484+ * Atomically sets the value of @v to @i.
14485+ */
14486+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14487+{
14488+ v->counter = i;
14489+}
14490+
14491+/**
14492 * atomic64_add - add integer to atomic64 variable
14493 * @i: integer value to add
14494 * @v: pointer to type atomic64_t
14495@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14496 */
14497 static inline void atomic64_add(long i, atomic64_t *v)
14498 {
14499+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14500+
14501+#ifdef CONFIG_PAX_REFCOUNT
14502+ "jno 0f\n"
14503+ LOCK_PREFIX "subq %1,%0\n"
14504+ "int $4\n0:\n"
14505+ _ASM_EXTABLE(0b, 0b)
14506+#endif
14507+
14508+ : "=m" (v->counter)
14509+ : "er" (i), "m" (v->counter));
14510+}
14511+
14512+/**
14513+ * atomic64_add_unchecked - add integer to atomic64 variable
14514+ * @i: integer value to add
14515+ * @v: pointer to type atomic64_unchecked_t
14516+ *
14517+ * Atomically adds @i to @v.
14518+ */
14519+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14520+{
14521 asm volatile(LOCK_PREFIX "addq %1,%0"
14522 : "=m" (v->counter)
14523 : "er" (i), "m" (v->counter));
14524@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14525 */
14526 static inline void atomic64_sub(long i, atomic64_t *v)
14527 {
14528- asm volatile(LOCK_PREFIX "subq %1,%0"
14529+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14530+
14531+#ifdef CONFIG_PAX_REFCOUNT
14532+ "jno 0f\n"
14533+ LOCK_PREFIX "addq %1,%0\n"
14534+ "int $4\n0:\n"
14535+ _ASM_EXTABLE(0b, 0b)
14536+#endif
14537+
14538+ : "=m" (v->counter)
14539+ : "er" (i), "m" (v->counter));
14540+}
14541+
14542+/**
14543+ * atomic64_sub_unchecked - subtract the atomic64 variable
14544+ * @i: integer value to subtract
14545+ * @v: pointer to type atomic64_unchecked_t
14546+ *
14547+ * Atomically subtracts @i from @v.
14548+ */
14549+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14550+{
14551+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14552 : "=m" (v->counter)
14553 : "er" (i), "m" (v->counter));
14554 }
14555@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14556 {
14557 unsigned char c;
14558
14559- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14560+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14561+
14562+#ifdef CONFIG_PAX_REFCOUNT
14563+ "jno 0f\n"
14564+ LOCK_PREFIX "addq %2,%0\n"
14565+ "int $4\n0:\n"
14566+ _ASM_EXTABLE(0b, 0b)
14567+#endif
14568+
14569+ "sete %1\n"
14570 : "=m" (v->counter), "=qm" (c)
14571 : "er" (i), "m" (v->counter) : "memory");
14572 return c;
14573@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14574 */
14575 static inline void atomic64_inc(atomic64_t *v)
14576 {
14577+ asm volatile(LOCK_PREFIX "incq %0\n"
14578+
14579+#ifdef CONFIG_PAX_REFCOUNT
14580+ "jno 0f\n"
14581+ LOCK_PREFIX "decq %0\n"
14582+ "int $4\n0:\n"
14583+ _ASM_EXTABLE(0b, 0b)
14584+#endif
14585+
14586+ : "=m" (v->counter)
14587+ : "m" (v->counter));
14588+}
14589+
14590+/**
14591+ * atomic64_inc_unchecked - increment atomic64 variable
14592+ * @v: pointer to type atomic64_unchecked_t
14593+ *
14594+ * Atomically increments @v by 1.
14595+ */
14596+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14597+{
14598 asm volatile(LOCK_PREFIX "incq %0"
14599 : "=m" (v->counter)
14600 : "m" (v->counter));
14601@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14602 */
14603 static inline void atomic64_dec(atomic64_t *v)
14604 {
14605- asm volatile(LOCK_PREFIX "decq %0"
14606+ asm volatile(LOCK_PREFIX "decq %0\n"
14607+
14608+#ifdef CONFIG_PAX_REFCOUNT
14609+ "jno 0f\n"
14610+ LOCK_PREFIX "incq %0\n"
14611+ "int $4\n0:\n"
14612+ _ASM_EXTABLE(0b, 0b)
14613+#endif
14614+
14615+ : "=m" (v->counter)
14616+ : "m" (v->counter));
14617+}
14618+
14619+/**
14620+ * atomic64_dec_unchecked - decrement atomic64 variable
14621+ * @v: pointer to type atomic64_t
14622+ *
14623+ * Atomically decrements @v by 1.
14624+ */
14625+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14626+{
14627+ asm volatile(LOCK_PREFIX "decq %0\n"
14628 : "=m" (v->counter)
14629 : "m" (v->counter));
14630 }
14631@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14632 {
14633 unsigned char c;
14634
14635- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14636+ asm volatile(LOCK_PREFIX "decq %0\n"
14637+
14638+#ifdef CONFIG_PAX_REFCOUNT
14639+ "jno 0f\n"
14640+ LOCK_PREFIX "incq %0\n"
14641+ "int $4\n0:\n"
14642+ _ASM_EXTABLE(0b, 0b)
14643+#endif
14644+
14645+ "sete %1\n"
14646 : "=m" (v->counter), "=qm" (c)
14647 : "m" (v->counter) : "memory");
14648 return c != 0;
14649@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14650 {
14651 unsigned char c;
14652
14653- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14654+ asm volatile(LOCK_PREFIX "incq %0\n"
14655+
14656+#ifdef CONFIG_PAX_REFCOUNT
14657+ "jno 0f\n"
14658+ LOCK_PREFIX "decq %0\n"
14659+ "int $4\n0:\n"
14660+ _ASM_EXTABLE(0b, 0b)
14661+#endif
14662+
14663+ "sete %1\n"
14664 : "=m" (v->counter), "=qm" (c)
14665 : "m" (v->counter) : "memory");
14666 return c != 0;
14667@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14668 {
14669 unsigned char c;
14670
14671- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14672+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14673+
14674+#ifdef CONFIG_PAX_REFCOUNT
14675+ "jno 0f\n"
14676+ LOCK_PREFIX "subq %2,%0\n"
14677+ "int $4\n0:\n"
14678+ _ASM_EXTABLE(0b, 0b)
14679+#endif
14680+
14681+ "sets %1\n"
14682 : "=m" (v->counter), "=qm" (c)
14683 : "er" (i), "m" (v->counter) : "memory");
14684 return c;
14685@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14686 */
14687 static inline long atomic64_add_return(long i, atomic64_t *v)
14688 {
14689+ return i + xadd_check_overflow(&v->counter, i);
14690+}
14691+
14692+/**
14693+ * atomic64_add_return_unchecked - add and return
14694+ * @i: integer value to add
14695+ * @v: pointer to type atomic64_unchecked_t
14696+ *
14697+ * Atomically adds @i to @v and returns @i + @v
14698+ */
14699+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14700+{
14701 return i + xadd(&v->counter, i);
14702 }
14703
14704@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14705 }
14706
14707 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14708+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14709+{
14710+ return atomic64_add_return_unchecked(1, v);
14711+}
14712 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14713
14714 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14715@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14716 return cmpxchg(&v->counter, old, new);
14717 }
14718
14719+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14720+{
14721+ return cmpxchg(&v->counter, old, new);
14722+}
14723+
14724 static inline long atomic64_xchg(atomic64_t *v, long new)
14725 {
14726 return xchg(&v->counter, new);
14727@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14728 */
14729 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14730 {
14731- long c, old;
14732+ long c, old, new;
14733 c = atomic64_read(v);
14734 for (;;) {
14735- if (unlikely(c == (u)))
14736+ if (unlikely(c == u))
14737 break;
14738- old = atomic64_cmpxchg((v), c, c + (a));
14739+
14740+ asm volatile("add %2,%0\n"
14741+
14742+#ifdef CONFIG_PAX_REFCOUNT
14743+ "jno 0f\n"
14744+ "sub %2,%0\n"
14745+ "int $4\n0:\n"
14746+ _ASM_EXTABLE(0b, 0b)
14747+#endif
14748+
14749+ : "=r" (new)
14750+ : "0" (c), "ir" (a));
14751+
14752+ old = atomic64_cmpxchg(v, c, new);
14753 if (likely(old == c))
14754 break;
14755 c = old;
14756 }
14757- return c != (u);
14758+ return c != u;
14759 }
14760
14761 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14762diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14763index 41639ce..0bd8c87 100644
14764--- a/arch/x86/include/asm/bitops.h
14765+++ b/arch/x86/include/asm/bitops.h
14766@@ -48,7 +48,7 @@
14767 * a mask operation on a byte.
14768 */
14769 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14770-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14771+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14772 #define CONST_MASK(nr) (1 << ((nr) & 7))
14773
14774 /**
14775@@ -361,7 +361,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
14776 *
14777 * Undefined if no bit exists, so code should check against 0 first.
14778 */
14779-static inline unsigned long __ffs(unsigned long word)
14780+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
14781 {
14782 asm("rep; bsf %1,%0"
14783 : "=r" (word)
14784@@ -375,7 +375,7 @@ static inline unsigned long __ffs(unsigned long word)
14785 *
14786 * Undefined if no zero exists, so code should check against ~0UL first.
14787 */
14788-static inline unsigned long ffz(unsigned long word)
14789+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
14790 {
14791 asm("rep; bsf %1,%0"
14792 : "=r" (word)
14793@@ -494,7 +494,7 @@ static inline int fls(int x)
14794 * at position 64.
14795 */
14796 #ifdef CONFIG_X86_64
14797-static __always_inline int fls64(__u64 x)
14798+static __always_inline long fls64(__u64 x)
14799 {
14800 int bitpos = -1;
14801 /*
14802diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14803index 4fa687a..60f2d39 100644
14804--- a/arch/x86/include/asm/boot.h
14805+++ b/arch/x86/include/asm/boot.h
14806@@ -6,10 +6,15 @@
14807 #include <uapi/asm/boot.h>
14808
14809 /* Physical address where kernel should be loaded. */
14810-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14811+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14812 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14813 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14814
14815+#ifndef __ASSEMBLY__
14816+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14817+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14818+#endif
14819+
14820 /* Minimum kernel alignment, as a power of two */
14821 #ifdef CONFIG_X86_64
14822 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14823diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14824index 48f99f1..d78ebf9 100644
14825--- a/arch/x86/include/asm/cache.h
14826+++ b/arch/x86/include/asm/cache.h
14827@@ -5,12 +5,13 @@
14828
14829 /* L1 cache line size */
14830 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14831-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14832+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14833
14834 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14835+#define __read_only __attribute__((__section__(".data..read_only")))
14836
14837 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14838-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14839+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14840
14841 #ifdef CONFIG_X86_VSMP
14842 #ifdef CONFIG_SMP
14843diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14844index 9863ee3..4a1f8e1 100644
14845--- a/arch/x86/include/asm/cacheflush.h
14846+++ b/arch/x86/include/asm/cacheflush.h
14847@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14848 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14849
14850 if (pg_flags == _PGMT_DEFAULT)
14851- return -1;
14852+ return ~0UL;
14853 else if (pg_flags == _PGMT_WC)
14854 return _PAGE_CACHE_WC;
14855 else if (pg_flags == _PGMT_UC_MINUS)
14856diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14857index f50de69..2b0a458 100644
14858--- a/arch/x86/include/asm/checksum_32.h
14859+++ b/arch/x86/include/asm/checksum_32.h
14860@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14861 int len, __wsum sum,
14862 int *src_err_ptr, int *dst_err_ptr);
14863
14864+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14865+ int len, __wsum sum,
14866+ int *src_err_ptr, int *dst_err_ptr);
14867+
14868+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14869+ int len, __wsum sum,
14870+ int *src_err_ptr, int *dst_err_ptr);
14871+
14872 /*
14873 * Note: when you get a NULL pointer exception here this means someone
14874 * passed in an incorrect kernel address to one of these functions.
14875@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14876
14877 might_sleep();
14878 stac();
14879- ret = csum_partial_copy_generic((__force void *)src, dst,
14880+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
14881 len, sum, err_ptr, NULL);
14882 clac();
14883
14884@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14885 might_sleep();
14886 if (access_ok(VERIFY_WRITE, dst, len)) {
14887 stac();
14888- ret = csum_partial_copy_generic(src, (__force void *)dst,
14889+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
14890 len, sum, NULL, err_ptr);
14891 clac();
14892 return ret;
14893diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14894index d47786a..ce1b05d 100644
14895--- a/arch/x86/include/asm/cmpxchg.h
14896+++ b/arch/x86/include/asm/cmpxchg.h
14897@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14898 __compiletime_error("Bad argument size for cmpxchg");
14899 extern void __xadd_wrong_size(void)
14900 __compiletime_error("Bad argument size for xadd");
14901+extern void __xadd_check_overflow_wrong_size(void)
14902+ __compiletime_error("Bad argument size for xadd_check_overflow");
14903 extern void __add_wrong_size(void)
14904 __compiletime_error("Bad argument size for add");
14905+extern void __add_check_overflow_wrong_size(void)
14906+ __compiletime_error("Bad argument size for add_check_overflow");
14907
14908 /*
14909 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14910@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14911 __ret; \
14912 })
14913
14914+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14915+ ({ \
14916+ __typeof__ (*(ptr)) __ret = (arg); \
14917+ switch (sizeof(*(ptr))) { \
14918+ case __X86_CASE_L: \
14919+ asm volatile (lock #op "l %0, %1\n" \
14920+ "jno 0f\n" \
14921+ "mov %0,%1\n" \
14922+ "int $4\n0:\n" \
14923+ _ASM_EXTABLE(0b, 0b) \
14924+ : "+r" (__ret), "+m" (*(ptr)) \
14925+ : : "memory", "cc"); \
14926+ break; \
14927+ case __X86_CASE_Q: \
14928+ asm volatile (lock #op "q %q0, %1\n" \
14929+ "jno 0f\n" \
14930+ "mov %0,%1\n" \
14931+ "int $4\n0:\n" \
14932+ _ASM_EXTABLE(0b, 0b) \
14933+ : "+r" (__ret), "+m" (*(ptr)) \
14934+ : : "memory", "cc"); \
14935+ break; \
14936+ default: \
14937+ __ ## op ## _check_overflow_wrong_size(); \
14938+ } \
14939+ __ret; \
14940+ })
14941+
14942 /*
14943 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14944 * Since this is generally used to protect other memory information, we
14945@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14946 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14947 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14948
14949+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14950+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14951+
14952 #define __add(ptr, inc, lock) \
14953 ({ \
14954 __typeof__ (*(ptr)) __ret = (inc); \
14955diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14956index 59c6c40..5e0b22c 100644
14957--- a/arch/x86/include/asm/compat.h
14958+++ b/arch/x86/include/asm/compat.h
14959@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14960 typedef u32 compat_uint_t;
14961 typedef u32 compat_ulong_t;
14962 typedef u64 __attribute__((aligned(4))) compat_u64;
14963-typedef u32 compat_uptr_t;
14964+typedef u32 __user compat_uptr_t;
14965
14966 struct compat_timespec {
14967 compat_time_t tv_sec;
14968diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14969index 89270b4..f0abf8e 100644
14970--- a/arch/x86/include/asm/cpufeature.h
14971+++ b/arch/x86/include/asm/cpufeature.h
14972@@ -203,7 +203,7 @@
14973 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14974 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14975 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14976-
14977+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14978
14979 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14980 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14981@@ -211,7 +211,7 @@
14982 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14983 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14984 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14985-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14986+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14987 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14988 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14989 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14990@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14991 #undef cpu_has_centaur_mcr
14992 #define cpu_has_centaur_mcr 0
14993
14994+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14995 #endif /* CONFIG_X86_64 */
14996
14997 #if __GNUC__ >= 4
14998@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14999
15000 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15001 t_warn:
15002- warn_pre_alternatives();
15003+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15004+ warn_pre_alternatives();
15005 return false;
15006 #endif
15007
15008@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15009 ".section .discard,\"aw\",@progbits\n"
15010 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15011 ".previous\n"
15012- ".section .altinstr_replacement,\"ax\"\n"
15013+ ".section .altinstr_replacement,\"a\"\n"
15014 "3: movb $1,%0\n"
15015 "4:\n"
15016 ".previous\n"
15017@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15018 " .byte 2b - 1b\n" /* src len */
15019 " .byte 4f - 3f\n" /* repl len */
15020 ".previous\n"
15021- ".section .altinstr_replacement,\"ax\"\n"
15022+ ".section .altinstr_replacement,\"a\"\n"
15023 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15024 "4:\n"
15025 ".previous\n"
15026@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15027 ".section .discard,\"aw\",@progbits\n"
15028 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15029 ".previous\n"
15030- ".section .altinstr_replacement,\"ax\"\n"
15031+ ".section .altinstr_replacement,\"a\"\n"
15032 "3: movb $0,%0\n"
15033 "4:\n"
15034 ".previous\n"
15035@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15036 ".section .discard,\"aw\",@progbits\n"
15037 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15038 ".previous\n"
15039- ".section .altinstr_replacement,\"ax\"\n"
15040+ ".section .altinstr_replacement,\"a\"\n"
15041 "5: movb $1,%0\n"
15042 "6:\n"
15043 ".previous\n"
15044diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15045index b90e5df..b462c91 100644
15046--- a/arch/x86/include/asm/desc.h
15047+++ b/arch/x86/include/asm/desc.h
15048@@ -4,6 +4,7 @@
15049 #include <asm/desc_defs.h>
15050 #include <asm/ldt.h>
15051 #include <asm/mmu.h>
15052+#include <asm/pgtable.h>
15053
15054 #include <linux/smp.h>
15055 #include <linux/percpu.h>
15056@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15057
15058 desc->type = (info->read_exec_only ^ 1) << 1;
15059 desc->type |= info->contents << 2;
15060+ desc->type |= info->seg_not_present ^ 1;
15061
15062 desc->s = 1;
15063 desc->dpl = 0x3;
15064@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15065 }
15066
15067 extern struct desc_ptr idt_descr;
15068-extern gate_desc idt_table[];
15069-extern struct desc_ptr debug_idt_descr;
15070-extern gate_desc debug_idt_table[];
15071-
15072-struct gdt_page {
15073- struct desc_struct gdt[GDT_ENTRIES];
15074-} __attribute__((aligned(PAGE_SIZE)));
15075-
15076-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15077+extern gate_desc idt_table[IDT_ENTRIES];
15078+extern const struct desc_ptr debug_idt_descr;
15079+extern gate_desc debug_idt_table[IDT_ENTRIES];
15080
15081+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15082 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15083 {
15084- return per_cpu(gdt_page, cpu).gdt;
15085+ return cpu_gdt_table[cpu];
15086 }
15087
15088 #ifdef CONFIG_X86_64
15089@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15090 unsigned long base, unsigned dpl, unsigned flags,
15091 unsigned short seg)
15092 {
15093- gate->a = (seg << 16) | (base & 0xffff);
15094- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15095+ gate->gate.offset_low = base;
15096+ gate->gate.seg = seg;
15097+ gate->gate.reserved = 0;
15098+ gate->gate.type = type;
15099+ gate->gate.s = 0;
15100+ gate->gate.dpl = dpl;
15101+ gate->gate.p = 1;
15102+ gate->gate.offset_high = base >> 16;
15103 }
15104
15105 #endif
15106@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15107
15108 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15109 {
15110+ pax_open_kernel();
15111 memcpy(&idt[entry], gate, sizeof(*gate));
15112+ pax_close_kernel();
15113 }
15114
15115 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15116 {
15117+ pax_open_kernel();
15118 memcpy(&ldt[entry], desc, 8);
15119+ pax_close_kernel();
15120 }
15121
15122 static inline void
15123@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15124 default: size = sizeof(*gdt); break;
15125 }
15126
15127+ pax_open_kernel();
15128 memcpy(&gdt[entry], desc, size);
15129+ pax_close_kernel();
15130 }
15131
15132 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15133@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15134
15135 static inline void native_load_tr_desc(void)
15136 {
15137+ pax_open_kernel();
15138 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15139+ pax_close_kernel();
15140 }
15141
15142 static inline void native_load_gdt(const struct desc_ptr *dtr)
15143@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15144 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15145 unsigned int i;
15146
15147+ pax_open_kernel();
15148 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15149 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15150+ pax_close_kernel();
15151 }
15152
15153 #define _LDT_empty(info) \
15154@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15155 preempt_enable();
15156 }
15157
15158-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15159+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15160 {
15161 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15162 }
15163@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15164 }
15165
15166 #ifdef CONFIG_X86_64
15167-static inline void set_nmi_gate(int gate, void *addr)
15168+static inline void set_nmi_gate(int gate, const void *addr)
15169 {
15170 gate_desc s;
15171
15172@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15173 #endif
15174
15175 #ifdef CONFIG_TRACING
15176-extern struct desc_ptr trace_idt_descr;
15177-extern gate_desc trace_idt_table[];
15178+extern const struct desc_ptr trace_idt_descr;
15179+extern gate_desc trace_idt_table[IDT_ENTRIES];
15180 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15181 {
15182 write_idt_entry(trace_idt_table, entry, gate);
15183@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15184 }
15185 #endif
15186
15187-static inline void _set_gate(int gate, unsigned type, void *addr,
15188+static inline void _set_gate(int gate, unsigned type, const void *addr,
15189 unsigned dpl, unsigned ist, unsigned seg)
15190 {
15191 gate_desc s;
15192@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15193 * Pentium F0 0F bugfix can have resulted in the mapped
15194 * IDT being write-protected.
15195 */
15196-static inline void set_intr_gate(unsigned int n, void *addr)
15197+static inline void set_intr_gate(unsigned int n, const void *addr)
15198 {
15199 BUG_ON((unsigned)n > 0xFF);
15200 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15201@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15202 /*
15203 * This routine sets up an interrupt gate at directory privilege level 3.
15204 */
15205-static inline void set_system_intr_gate(unsigned int n, void *addr)
15206+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15207 {
15208 BUG_ON((unsigned)n > 0xFF);
15209 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15210 }
15211
15212-static inline void set_system_trap_gate(unsigned int n, void *addr)
15213+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15214 {
15215 BUG_ON((unsigned)n > 0xFF);
15216 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15217 }
15218
15219-static inline void set_trap_gate(unsigned int n, void *addr)
15220+static inline void set_trap_gate(unsigned int n, const void *addr)
15221 {
15222 BUG_ON((unsigned)n > 0xFF);
15223 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15224@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15225 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15226 {
15227 BUG_ON((unsigned)n > 0xFF);
15228- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15229+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15230 }
15231
15232-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15233+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15234 {
15235 BUG_ON((unsigned)n > 0xFF);
15236 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15237 }
15238
15239-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15240+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15241 {
15242 BUG_ON((unsigned)n > 0xFF);
15243 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15244@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15245 else
15246 load_idt((const struct desc_ptr *)&idt_descr);
15247 }
15248+
15249+#ifdef CONFIG_X86_32
15250+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15251+{
15252+ struct desc_struct d;
15253+
15254+ if (likely(limit))
15255+ limit = (limit - 1UL) >> PAGE_SHIFT;
15256+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15257+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15258+}
15259+#endif
15260+
15261 #endif /* _ASM_X86_DESC_H */
15262diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15263index 278441f..b95a174 100644
15264--- a/arch/x86/include/asm/desc_defs.h
15265+++ b/arch/x86/include/asm/desc_defs.h
15266@@ -31,6 +31,12 @@ struct desc_struct {
15267 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15268 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15269 };
15270+ struct {
15271+ u16 offset_low;
15272+ u16 seg;
15273+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15274+ unsigned offset_high: 16;
15275+ } gate;
15276 };
15277 } __attribute__((packed));
15278
15279diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15280index ced283a..ffe04cc 100644
15281--- a/arch/x86/include/asm/div64.h
15282+++ b/arch/x86/include/asm/div64.h
15283@@ -39,7 +39,7 @@
15284 __mod; \
15285 })
15286
15287-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15288+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15289 {
15290 union {
15291 u64 v64;
15292diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15293index 9c999c1..3860cb8 100644
15294--- a/arch/x86/include/asm/elf.h
15295+++ b/arch/x86/include/asm/elf.h
15296@@ -243,7 +243,25 @@ extern int force_personality32;
15297 the loader. We need to make sure that it is out of the way of the program
15298 that it will "exec", and that there is sufficient room for the brk. */
15299
15300+#ifdef CONFIG_PAX_SEGMEXEC
15301+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15302+#else
15303 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15304+#endif
15305+
15306+#ifdef CONFIG_PAX_ASLR
15307+#ifdef CONFIG_X86_32
15308+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15309+
15310+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15311+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15312+#else
15313+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15314+
15315+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15316+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15317+#endif
15318+#endif
15319
15320 /* This yields a mask that user programs can use to figure out what
15321 instruction set this CPU supports. This could be done in user space,
15322@@ -296,16 +314,12 @@ do { \
15323
15324 #define ARCH_DLINFO \
15325 do { \
15326- if (vdso_enabled) \
15327- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15328- (unsigned long)current->mm->context.vdso); \
15329+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15330 } while (0)
15331
15332 #define ARCH_DLINFO_X32 \
15333 do { \
15334- if (vdso_enabled) \
15335- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15336- (unsigned long)current->mm->context.vdso); \
15337+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15338 } while (0)
15339
15340 #define AT_SYSINFO 32
15341@@ -320,7 +334,7 @@ else \
15342
15343 #endif /* !CONFIG_X86_32 */
15344
15345-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15346+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15347
15348 #define VDSO_ENTRY \
15349 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15350@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15351 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15352 #define compat_arch_setup_additional_pages syscall32_setup_pages
15353
15354-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15355-#define arch_randomize_brk arch_randomize_brk
15356-
15357 /*
15358 * True on X86_32 or when emulating IA32 on X86_64
15359 */
15360diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15361index 77a99ac..39ff7f5 100644
15362--- a/arch/x86/include/asm/emergency-restart.h
15363+++ b/arch/x86/include/asm/emergency-restart.h
15364@@ -1,6 +1,6 @@
15365 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15366 #define _ASM_X86_EMERGENCY_RESTART_H
15367
15368-extern void machine_emergency_restart(void);
15369+extern void machine_emergency_restart(void) __noreturn;
15370
15371 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15372diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15373index 4d0bda7..221da4d 100644
15374--- a/arch/x86/include/asm/fpu-internal.h
15375+++ b/arch/x86/include/asm/fpu-internal.h
15376@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15377 #define user_insn(insn, output, input...) \
15378 ({ \
15379 int err; \
15380+ pax_open_userland(); \
15381 asm volatile(ASM_STAC "\n" \
15382- "1:" #insn "\n\t" \
15383+ "1:" \
15384+ __copyuser_seg \
15385+ #insn "\n\t" \
15386 "2: " ASM_CLAC "\n" \
15387 ".section .fixup,\"ax\"\n" \
15388 "3: movl $-1,%[err]\n" \
15389@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15390 _ASM_EXTABLE(1b, 3b) \
15391 : [err] "=r" (err), output \
15392 : "0"(0), input); \
15393+ pax_close_userland(); \
15394 err; \
15395 })
15396
15397@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15398 "emms\n\t" /* clear stack tags */
15399 "fildl %P[addr]", /* set F?P to defined value */
15400 X86_FEATURE_FXSAVE_LEAK,
15401- [addr] "m" (tsk->thread.fpu.has_fpu));
15402+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15403
15404 return fpu_restore_checking(&tsk->thread.fpu);
15405 }
15406diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15407index be27ba1..04a8801 100644
15408--- a/arch/x86/include/asm/futex.h
15409+++ b/arch/x86/include/asm/futex.h
15410@@ -12,6 +12,7 @@
15411 #include <asm/smap.h>
15412
15413 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15414+ typecheck(u32 __user *, uaddr); \
15415 asm volatile("\t" ASM_STAC "\n" \
15416 "1:\t" insn "\n" \
15417 "2:\t" ASM_CLAC "\n" \
15418@@ -20,15 +21,16 @@
15419 "\tjmp\t2b\n" \
15420 "\t.previous\n" \
15421 _ASM_EXTABLE(1b, 3b) \
15422- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15423+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15424 : "i" (-EFAULT), "0" (oparg), "1" (0))
15425
15426 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15427+ typecheck(u32 __user *, uaddr); \
15428 asm volatile("\t" ASM_STAC "\n" \
15429 "1:\tmovl %2, %0\n" \
15430 "\tmovl\t%0, %3\n" \
15431 "\t" insn "\n" \
15432- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15433+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15434 "\tjnz\t1b\n" \
15435 "3:\t" ASM_CLAC "\n" \
15436 "\t.section .fixup,\"ax\"\n" \
15437@@ -38,7 +40,7 @@
15438 _ASM_EXTABLE(1b, 4b) \
15439 _ASM_EXTABLE(2b, 4b) \
15440 : "=&a" (oldval), "=&r" (ret), \
15441- "+m" (*uaddr), "=&r" (tem) \
15442+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15443 : "r" (oparg), "i" (-EFAULT), "1" (0))
15444
15445 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15446@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15447
15448 pagefault_disable();
15449
15450+ pax_open_userland();
15451 switch (op) {
15452 case FUTEX_OP_SET:
15453- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15454+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15455 break;
15456 case FUTEX_OP_ADD:
15457- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15458+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15459 uaddr, oparg);
15460 break;
15461 case FUTEX_OP_OR:
15462@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15463 default:
15464 ret = -ENOSYS;
15465 }
15466+ pax_close_userland();
15467
15468 pagefault_enable();
15469
15470@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15471 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15472 return -EFAULT;
15473
15474+ pax_open_userland();
15475 asm volatile("\t" ASM_STAC "\n"
15476- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15477+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15478 "2:\t" ASM_CLAC "\n"
15479 "\t.section .fixup, \"ax\"\n"
15480 "3:\tmov %3, %0\n"
15481 "\tjmp 2b\n"
15482 "\t.previous\n"
15483 _ASM_EXTABLE(1b, 3b)
15484- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15485+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15486 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15487 : "memory"
15488 );
15489+ pax_close_userland();
15490
15491 *uval = oldval;
15492 return ret;
15493diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15494index 92b3bae..3866449 100644
15495--- a/arch/x86/include/asm/hw_irq.h
15496+++ b/arch/x86/include/asm/hw_irq.h
15497@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15498 extern void enable_IO_APIC(void);
15499
15500 /* Statistics */
15501-extern atomic_t irq_err_count;
15502-extern atomic_t irq_mis_count;
15503+extern atomic_unchecked_t irq_err_count;
15504+extern atomic_unchecked_t irq_mis_count;
15505
15506 /* EISA */
15507 extern void eisa_set_level_irq(unsigned int irq);
15508diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15509index a203659..9889f1c 100644
15510--- a/arch/x86/include/asm/i8259.h
15511+++ b/arch/x86/include/asm/i8259.h
15512@@ -62,7 +62,7 @@ struct legacy_pic {
15513 void (*init)(int auto_eoi);
15514 int (*irq_pending)(unsigned int irq);
15515 void (*make_irq)(unsigned int irq);
15516-};
15517+} __do_const;
15518
15519 extern struct legacy_pic *legacy_pic;
15520 extern struct legacy_pic null_legacy_pic;
15521diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15522index 34f69cb..6d95446 100644
15523--- a/arch/x86/include/asm/io.h
15524+++ b/arch/x86/include/asm/io.h
15525@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15526 "m" (*(volatile type __force *)addr) barrier); }
15527
15528 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15529-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15530-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15531+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15532+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15533
15534 build_mmio_read(__readb, "b", unsigned char, "=q", )
15535-build_mmio_read(__readw, "w", unsigned short, "=r", )
15536-build_mmio_read(__readl, "l", unsigned int, "=r", )
15537+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15538+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15539
15540 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15541 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15542@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15543 return ioremap_nocache(offset, size);
15544 }
15545
15546-extern void iounmap(volatile void __iomem *addr);
15547+extern void iounmap(const volatile void __iomem *addr);
15548
15549 extern void set_iounmap_nonlazy(void);
15550
15551@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15552
15553 #include <linux/vmalloc.h>
15554
15555+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15556+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15557+{
15558+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15559+}
15560+
15561+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15562+{
15563+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15564+}
15565+
15566 /*
15567 * Convert a virtual cached pointer to an uncached pointer
15568 */
15569diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15570index bba3cf8..06bc8da 100644
15571--- a/arch/x86/include/asm/irqflags.h
15572+++ b/arch/x86/include/asm/irqflags.h
15573@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15574 sti; \
15575 sysexit
15576
15577+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15578+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15579+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15580+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15581+
15582 #else
15583 #define INTERRUPT_RETURN iret
15584 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15585diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15586index 9454c16..e4100e3 100644
15587--- a/arch/x86/include/asm/kprobes.h
15588+++ b/arch/x86/include/asm/kprobes.h
15589@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15590 #define RELATIVEJUMP_SIZE 5
15591 #define RELATIVECALL_OPCODE 0xe8
15592 #define RELATIVE_ADDR_SIZE 4
15593-#define MAX_STACK_SIZE 64
15594-#define MIN_STACK_SIZE(ADDR) \
15595- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15596- THREAD_SIZE - (unsigned long)(ADDR))) \
15597- ? (MAX_STACK_SIZE) \
15598- : (((unsigned long)current_thread_info()) + \
15599- THREAD_SIZE - (unsigned long)(ADDR)))
15600+#define MAX_STACK_SIZE 64UL
15601+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15602
15603 #define flush_insn_slot(p) do { } while (0)
15604
15605diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15606index 2d89e39..baee879 100644
15607--- a/arch/x86/include/asm/local.h
15608+++ b/arch/x86/include/asm/local.h
15609@@ -10,33 +10,97 @@ typedef struct {
15610 atomic_long_t a;
15611 } local_t;
15612
15613+typedef struct {
15614+ atomic_long_unchecked_t a;
15615+} local_unchecked_t;
15616+
15617 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15618
15619 #define local_read(l) atomic_long_read(&(l)->a)
15620+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15621 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15622+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15623
15624 static inline void local_inc(local_t *l)
15625 {
15626- asm volatile(_ASM_INC "%0"
15627+ asm volatile(_ASM_INC "%0\n"
15628+
15629+#ifdef CONFIG_PAX_REFCOUNT
15630+ "jno 0f\n"
15631+ _ASM_DEC "%0\n"
15632+ "int $4\n0:\n"
15633+ _ASM_EXTABLE(0b, 0b)
15634+#endif
15635+
15636+ : "+m" (l->a.counter));
15637+}
15638+
15639+static inline void local_inc_unchecked(local_unchecked_t *l)
15640+{
15641+ asm volatile(_ASM_INC "%0\n"
15642 : "+m" (l->a.counter));
15643 }
15644
15645 static inline void local_dec(local_t *l)
15646 {
15647- asm volatile(_ASM_DEC "%0"
15648+ asm volatile(_ASM_DEC "%0\n"
15649+
15650+#ifdef CONFIG_PAX_REFCOUNT
15651+ "jno 0f\n"
15652+ _ASM_INC "%0\n"
15653+ "int $4\n0:\n"
15654+ _ASM_EXTABLE(0b, 0b)
15655+#endif
15656+
15657+ : "+m" (l->a.counter));
15658+}
15659+
15660+static inline void local_dec_unchecked(local_unchecked_t *l)
15661+{
15662+ asm volatile(_ASM_DEC "%0\n"
15663 : "+m" (l->a.counter));
15664 }
15665
15666 static inline void local_add(long i, local_t *l)
15667 {
15668- asm volatile(_ASM_ADD "%1,%0"
15669+ asm volatile(_ASM_ADD "%1,%0\n"
15670+
15671+#ifdef CONFIG_PAX_REFCOUNT
15672+ "jno 0f\n"
15673+ _ASM_SUB "%1,%0\n"
15674+ "int $4\n0:\n"
15675+ _ASM_EXTABLE(0b, 0b)
15676+#endif
15677+
15678+ : "+m" (l->a.counter)
15679+ : "ir" (i));
15680+}
15681+
15682+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15683+{
15684+ asm volatile(_ASM_ADD "%1,%0\n"
15685 : "+m" (l->a.counter)
15686 : "ir" (i));
15687 }
15688
15689 static inline void local_sub(long i, local_t *l)
15690 {
15691- asm volatile(_ASM_SUB "%1,%0"
15692+ asm volatile(_ASM_SUB "%1,%0\n"
15693+
15694+#ifdef CONFIG_PAX_REFCOUNT
15695+ "jno 0f\n"
15696+ _ASM_ADD "%1,%0\n"
15697+ "int $4\n0:\n"
15698+ _ASM_EXTABLE(0b, 0b)
15699+#endif
15700+
15701+ : "+m" (l->a.counter)
15702+ : "ir" (i));
15703+}
15704+
15705+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15706+{
15707+ asm volatile(_ASM_SUB "%1,%0\n"
15708 : "+m" (l->a.counter)
15709 : "ir" (i));
15710 }
15711@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15712 {
15713 unsigned char c;
15714
15715- asm volatile(_ASM_SUB "%2,%0; sete %1"
15716+ asm volatile(_ASM_SUB "%2,%0\n"
15717+
15718+#ifdef CONFIG_PAX_REFCOUNT
15719+ "jno 0f\n"
15720+ _ASM_ADD "%2,%0\n"
15721+ "int $4\n0:\n"
15722+ _ASM_EXTABLE(0b, 0b)
15723+#endif
15724+
15725+ "sete %1\n"
15726 : "+m" (l->a.counter), "=qm" (c)
15727 : "ir" (i) : "memory");
15728 return c;
15729@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15730 {
15731 unsigned char c;
15732
15733- asm volatile(_ASM_DEC "%0; sete %1"
15734+ asm volatile(_ASM_DEC "%0\n"
15735+
15736+#ifdef CONFIG_PAX_REFCOUNT
15737+ "jno 0f\n"
15738+ _ASM_INC "%0\n"
15739+ "int $4\n0:\n"
15740+ _ASM_EXTABLE(0b, 0b)
15741+#endif
15742+
15743+ "sete %1\n"
15744 : "+m" (l->a.counter), "=qm" (c)
15745 : : "memory");
15746 return c != 0;
15747@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15748 {
15749 unsigned char c;
15750
15751- asm volatile(_ASM_INC "%0; sete %1"
15752+ asm volatile(_ASM_INC "%0\n"
15753+
15754+#ifdef CONFIG_PAX_REFCOUNT
15755+ "jno 0f\n"
15756+ _ASM_DEC "%0\n"
15757+ "int $4\n0:\n"
15758+ _ASM_EXTABLE(0b, 0b)
15759+#endif
15760+
15761+ "sete %1\n"
15762 : "+m" (l->a.counter), "=qm" (c)
15763 : : "memory");
15764 return c != 0;
15765@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15766 {
15767 unsigned char c;
15768
15769- asm volatile(_ASM_ADD "%2,%0; sets %1"
15770+ asm volatile(_ASM_ADD "%2,%0\n"
15771+
15772+#ifdef CONFIG_PAX_REFCOUNT
15773+ "jno 0f\n"
15774+ _ASM_SUB "%2,%0\n"
15775+ "int $4\n0:\n"
15776+ _ASM_EXTABLE(0b, 0b)
15777+#endif
15778+
15779+ "sets %1\n"
15780 : "+m" (l->a.counter), "=qm" (c)
15781 : "ir" (i) : "memory");
15782 return c;
15783@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15784 static inline long local_add_return(long i, local_t *l)
15785 {
15786 long __i = i;
15787+ asm volatile(_ASM_XADD "%0, %1\n"
15788+
15789+#ifdef CONFIG_PAX_REFCOUNT
15790+ "jno 0f\n"
15791+ _ASM_MOV "%0,%1\n"
15792+ "int $4\n0:\n"
15793+ _ASM_EXTABLE(0b, 0b)
15794+#endif
15795+
15796+ : "+r" (i), "+m" (l->a.counter)
15797+ : : "memory");
15798+ return i + __i;
15799+}
15800+
15801+/**
15802+ * local_add_return_unchecked - add and return
15803+ * @i: integer value to add
15804+ * @l: pointer to type local_unchecked_t
15805+ *
15806+ * Atomically adds @i to @l and returns @i + @l
15807+ */
15808+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15809+{
15810+ long __i = i;
15811 asm volatile(_ASM_XADD "%0, %1;"
15812 : "+r" (i), "+m" (l->a.counter)
15813 : : "memory");
15814@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15815
15816 #define local_cmpxchg(l, o, n) \
15817 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15818+#define local_cmpxchg_unchecked(l, o, n) \
15819+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15820 /* Always has a lock prefix */
15821 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15822
15823diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15824new file mode 100644
15825index 0000000..2bfd3ba
15826--- /dev/null
15827+++ b/arch/x86/include/asm/mman.h
15828@@ -0,0 +1,15 @@
15829+#ifndef _X86_MMAN_H
15830+#define _X86_MMAN_H
15831+
15832+#include <uapi/asm/mman.h>
15833+
15834+#ifdef __KERNEL__
15835+#ifndef __ASSEMBLY__
15836+#ifdef CONFIG_X86_32
15837+#define arch_mmap_check i386_mmap_check
15838+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15839+#endif
15840+#endif
15841+#endif
15842+
15843+#endif /* X86_MMAN_H */
15844diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15845index 5f55e69..e20bfb1 100644
15846--- a/arch/x86/include/asm/mmu.h
15847+++ b/arch/x86/include/asm/mmu.h
15848@@ -9,7 +9,7 @@
15849 * we put the segment information here.
15850 */
15851 typedef struct {
15852- void *ldt;
15853+ struct desc_struct *ldt;
15854 int size;
15855
15856 #ifdef CONFIG_X86_64
15857@@ -18,7 +18,19 @@ typedef struct {
15858 #endif
15859
15860 struct mutex lock;
15861- void *vdso;
15862+ unsigned long vdso;
15863+
15864+#ifdef CONFIG_X86_32
15865+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15866+ unsigned long user_cs_base;
15867+ unsigned long user_cs_limit;
15868+
15869+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15870+ cpumask_t cpu_user_cs_mask;
15871+#endif
15872+
15873+#endif
15874+#endif
15875 } mm_context_t;
15876
15877 #ifdef CONFIG_SMP
15878diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15879index be12c53..4d24039 100644
15880--- a/arch/x86/include/asm/mmu_context.h
15881+++ b/arch/x86/include/asm/mmu_context.h
15882@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15883
15884 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15885 {
15886+
15887+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15888+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15889+ unsigned int i;
15890+ pgd_t *pgd;
15891+
15892+ pax_open_kernel();
15893+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15894+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15895+ set_pgd_batched(pgd+i, native_make_pgd(0));
15896+ pax_close_kernel();
15897+ }
15898+#endif
15899+
15900 #ifdef CONFIG_SMP
15901 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15902 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15903@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15904 struct task_struct *tsk)
15905 {
15906 unsigned cpu = smp_processor_id();
15907+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15908+ int tlbstate = TLBSTATE_OK;
15909+#endif
15910
15911 if (likely(prev != next)) {
15912 #ifdef CONFIG_SMP
15913+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15914+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15915+#endif
15916 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15917 this_cpu_write(cpu_tlbstate.active_mm, next);
15918 #endif
15919 cpumask_set_cpu(cpu, mm_cpumask(next));
15920
15921 /* Re-load page tables */
15922+#ifdef CONFIG_PAX_PER_CPU_PGD
15923+ pax_open_kernel();
15924+
15925+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15926+ if (static_cpu_has(X86_FEATURE_PCID))
15927+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15928+ else
15929+#endif
15930+
15931+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15932+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15933+ pax_close_kernel();
15934+ 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));
15935+
15936+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15937+ if (static_cpu_has(X86_FEATURE_PCID)) {
15938+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15939+ u64 descriptor[2];
15940+ descriptor[0] = PCID_USER;
15941+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15942+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
15943+ descriptor[0] = PCID_KERNEL;
15944+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15945+ }
15946+ } else {
15947+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15948+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15949+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15950+ else
15951+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15952+ }
15953+ } else
15954+#endif
15955+
15956+ load_cr3(get_cpu_pgd(cpu, kernel));
15957+#else
15958 load_cr3(next->pgd);
15959+#endif
15960
15961 /* Stop flush ipis for the previous mm */
15962 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15963@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15964 /* Load the LDT, if the LDT is different: */
15965 if (unlikely(prev->context.ldt != next->context.ldt))
15966 load_LDT_nolock(&next->context);
15967+
15968+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15969+ if (!(__supported_pte_mask & _PAGE_NX)) {
15970+ smp_mb__before_clear_bit();
15971+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15972+ smp_mb__after_clear_bit();
15973+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15974+ }
15975+#endif
15976+
15977+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15978+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15979+ prev->context.user_cs_limit != next->context.user_cs_limit))
15980+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15981+#ifdef CONFIG_SMP
15982+ else if (unlikely(tlbstate != TLBSTATE_OK))
15983+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15984+#endif
15985+#endif
15986+
15987 }
15988+ else {
15989+
15990+#ifdef CONFIG_PAX_PER_CPU_PGD
15991+ pax_open_kernel();
15992+
15993+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15994+ if (static_cpu_has(X86_FEATURE_PCID))
15995+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15996+ else
15997+#endif
15998+
15999+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16000+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16001+ pax_close_kernel();
16002+ 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));
16003+
16004+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16005+ if (static_cpu_has(X86_FEATURE_PCID)) {
16006+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16007+ u64 descriptor[2];
16008+ descriptor[0] = PCID_USER;
16009+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16010+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16011+ descriptor[0] = PCID_KERNEL;
16012+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16013+ }
16014+ } else {
16015+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16016+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16017+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16018+ else
16019+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16020+ }
16021+ } else
16022+#endif
16023+
16024+ load_cr3(get_cpu_pgd(cpu, kernel));
16025+#endif
16026+
16027 #ifdef CONFIG_SMP
16028- else {
16029 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16030 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16031
16032@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16033 * tlb flush IPI delivery. We must reload CR3
16034 * to make sure to use no freed page tables.
16035 */
16036+
16037+#ifndef CONFIG_PAX_PER_CPU_PGD
16038 load_cr3(next->pgd);
16039+#endif
16040+
16041 load_LDT_nolock(&next->context);
16042+
16043+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16044+ if (!(__supported_pte_mask & _PAGE_NX))
16045+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16046+#endif
16047+
16048+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16049+#ifdef CONFIG_PAX_PAGEEXEC
16050+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16051+#endif
16052+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16053+#endif
16054+
16055 }
16056+#endif
16057 }
16058-#endif
16059 }
16060
16061 #define activate_mm(prev, next) \
16062diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16063index e3b7819..b257c64 100644
16064--- a/arch/x86/include/asm/module.h
16065+++ b/arch/x86/include/asm/module.h
16066@@ -5,6 +5,7 @@
16067
16068 #ifdef CONFIG_X86_64
16069 /* X86_64 does not define MODULE_PROC_FAMILY */
16070+#define MODULE_PROC_FAMILY ""
16071 #elif defined CONFIG_M486
16072 #define MODULE_PROC_FAMILY "486 "
16073 #elif defined CONFIG_M586
16074@@ -57,8 +58,20 @@
16075 #error unknown processor family
16076 #endif
16077
16078-#ifdef CONFIG_X86_32
16079-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16080+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16081+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16082+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16083+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16084+#else
16085+#define MODULE_PAX_KERNEXEC ""
16086 #endif
16087
16088+#ifdef CONFIG_PAX_MEMORY_UDEREF
16089+#define MODULE_PAX_UDEREF "UDEREF "
16090+#else
16091+#define MODULE_PAX_UDEREF ""
16092+#endif
16093+
16094+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16095+
16096 #endif /* _ASM_X86_MODULE_H */
16097diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16098index 86f9301..b365cda 100644
16099--- a/arch/x86/include/asm/nmi.h
16100+++ b/arch/x86/include/asm/nmi.h
16101@@ -40,11 +40,11 @@ struct nmiaction {
16102 nmi_handler_t handler;
16103 unsigned long flags;
16104 const char *name;
16105-};
16106+} __do_const;
16107
16108 #define register_nmi_handler(t, fn, fg, n, init...) \
16109 ({ \
16110- static struct nmiaction init fn##_na = { \
16111+ static const struct nmiaction init fn##_na = { \
16112 .handler = (fn), \
16113 .name = (n), \
16114 .flags = (fg), \
16115@@ -52,7 +52,7 @@ struct nmiaction {
16116 __register_nmi_handler((t), &fn##_na); \
16117 })
16118
16119-int __register_nmi_handler(unsigned int, struct nmiaction *);
16120+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16121
16122 void unregister_nmi_handler(unsigned int, const char *);
16123
16124diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16125index c878924..21f4889 100644
16126--- a/arch/x86/include/asm/page.h
16127+++ b/arch/x86/include/asm/page.h
16128@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16129 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16130
16131 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16132+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16133
16134 #define __boot_va(x) __va(x)
16135 #define __boot_pa(x) __pa(x)
16136diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16137index 0f1ddee..e2fc3d1 100644
16138--- a/arch/x86/include/asm/page_64.h
16139+++ b/arch/x86/include/asm/page_64.h
16140@@ -7,9 +7,9 @@
16141
16142 /* duplicated to the one in bootmem.h */
16143 extern unsigned long max_pfn;
16144-extern unsigned long phys_base;
16145+extern const unsigned long phys_base;
16146
16147-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16148+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16149 {
16150 unsigned long y = x - __START_KERNEL_map;
16151
16152diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16153index 401f350..dee5d13 100644
16154--- a/arch/x86/include/asm/paravirt.h
16155+++ b/arch/x86/include/asm/paravirt.h
16156@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16157 return (pmd_t) { ret };
16158 }
16159
16160-static inline pmdval_t pmd_val(pmd_t pmd)
16161+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16162 {
16163 pmdval_t ret;
16164
16165@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16166 val);
16167 }
16168
16169+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16170+{
16171+ pgdval_t val = native_pgd_val(pgd);
16172+
16173+ if (sizeof(pgdval_t) > sizeof(long))
16174+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16175+ val, (u64)val >> 32);
16176+ else
16177+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16178+ val);
16179+}
16180+
16181 static inline void pgd_clear(pgd_t *pgdp)
16182 {
16183 set_pgd(pgdp, __pgd(0));
16184@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16185 pv_mmu_ops.set_fixmap(idx, phys, flags);
16186 }
16187
16188+#ifdef CONFIG_PAX_KERNEXEC
16189+static inline unsigned long pax_open_kernel(void)
16190+{
16191+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16192+}
16193+
16194+static inline unsigned long pax_close_kernel(void)
16195+{
16196+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16197+}
16198+#else
16199+static inline unsigned long pax_open_kernel(void) { return 0; }
16200+static inline unsigned long pax_close_kernel(void) { return 0; }
16201+#endif
16202+
16203 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16204
16205 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16206@@ -906,7 +933,7 @@ extern void default_banner(void);
16207
16208 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16209 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16210-#define PARA_INDIRECT(addr) *%cs:addr
16211+#define PARA_INDIRECT(addr) *%ss:addr
16212 #endif
16213
16214 #define INTERRUPT_RETURN \
16215@@ -981,6 +1008,21 @@ extern void default_banner(void);
16216 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16217 CLBR_NONE, \
16218 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16219+
16220+#define GET_CR0_INTO_RDI \
16221+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16222+ mov %rax,%rdi
16223+
16224+#define SET_RDI_INTO_CR0 \
16225+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16226+
16227+#define GET_CR3_INTO_RDI \
16228+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16229+ mov %rax,%rdi
16230+
16231+#define SET_RDI_INTO_CR3 \
16232+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16233+
16234 #endif /* CONFIG_X86_32 */
16235
16236 #endif /* __ASSEMBLY__ */
16237diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16238index aab8f67..2531748 100644
16239--- a/arch/x86/include/asm/paravirt_types.h
16240+++ b/arch/x86/include/asm/paravirt_types.h
16241@@ -84,7 +84,7 @@ struct pv_init_ops {
16242 */
16243 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16244 unsigned long addr, unsigned len);
16245-};
16246+} __no_const;
16247
16248
16249 struct pv_lazy_ops {
16250@@ -98,7 +98,7 @@ struct pv_time_ops {
16251 unsigned long long (*sched_clock)(void);
16252 unsigned long long (*steal_clock)(int cpu);
16253 unsigned long (*get_tsc_khz)(void);
16254-};
16255+} __no_const;
16256
16257 struct pv_cpu_ops {
16258 /* hooks for various privileged instructions */
16259@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16260
16261 void (*start_context_switch)(struct task_struct *prev);
16262 void (*end_context_switch)(struct task_struct *next);
16263-};
16264+} __no_const;
16265
16266 struct pv_irq_ops {
16267 /*
16268@@ -223,7 +223,7 @@ struct pv_apic_ops {
16269 unsigned long start_eip,
16270 unsigned long start_esp);
16271 #endif
16272-};
16273+} __no_const;
16274
16275 struct pv_mmu_ops {
16276 unsigned long (*read_cr2)(void);
16277@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16278 struct paravirt_callee_save make_pud;
16279
16280 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16281+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16282 #endif /* PAGETABLE_LEVELS == 4 */
16283 #endif /* PAGETABLE_LEVELS >= 3 */
16284
16285@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16286 an mfn. We can tell which is which from the index. */
16287 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16288 phys_addr_t phys, pgprot_t flags);
16289+
16290+#ifdef CONFIG_PAX_KERNEXEC
16291+ unsigned long (*pax_open_kernel)(void);
16292+ unsigned long (*pax_close_kernel)(void);
16293+#endif
16294+
16295 };
16296
16297 struct arch_spinlock;
16298diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16299index b4389a4..7024269 100644
16300--- a/arch/x86/include/asm/pgalloc.h
16301+++ b/arch/x86/include/asm/pgalloc.h
16302@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16303 pmd_t *pmd, pte_t *pte)
16304 {
16305 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16306+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16307+}
16308+
16309+static inline void pmd_populate_user(struct mm_struct *mm,
16310+ pmd_t *pmd, pte_t *pte)
16311+{
16312+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16313 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16314 }
16315
16316@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16317
16318 #ifdef CONFIG_X86_PAE
16319 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16320+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16321+{
16322+ pud_populate(mm, pudp, pmd);
16323+}
16324 #else /* !CONFIG_X86_PAE */
16325 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16326 {
16327 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16328 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16329 }
16330+
16331+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16332+{
16333+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16334+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16335+}
16336 #endif /* CONFIG_X86_PAE */
16337
16338 #if PAGETABLE_LEVELS > 3
16339@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16340 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16341 }
16342
16343+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16344+{
16345+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16346+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16347+}
16348+
16349 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16350 {
16351 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16352diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16353index 3bf2dd0..23d2a9f 100644
16354--- a/arch/x86/include/asm/pgtable-2level.h
16355+++ b/arch/x86/include/asm/pgtable-2level.h
16356@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16357
16358 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16359 {
16360+ pax_open_kernel();
16361 *pmdp = pmd;
16362+ pax_close_kernel();
16363 }
16364
16365 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16366diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16367index 81bb91b..9392125 100644
16368--- a/arch/x86/include/asm/pgtable-3level.h
16369+++ b/arch/x86/include/asm/pgtable-3level.h
16370@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16371
16372 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16373 {
16374+ pax_open_kernel();
16375 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16376+ pax_close_kernel();
16377 }
16378
16379 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16380 {
16381+ pax_open_kernel();
16382 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16383+ pax_close_kernel();
16384 }
16385
16386 /*
16387diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16388index 3d19994..732a48c 100644
16389--- a/arch/x86/include/asm/pgtable.h
16390+++ b/arch/x86/include/asm/pgtable.h
16391@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16392
16393 #ifndef __PAGETABLE_PUD_FOLDED
16394 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16395+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16396 #define pgd_clear(pgd) native_pgd_clear(pgd)
16397 #endif
16398
16399@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16400
16401 #define arch_end_context_switch(prev) do {} while(0)
16402
16403+#define pax_open_kernel() native_pax_open_kernel()
16404+#define pax_close_kernel() native_pax_close_kernel()
16405 #endif /* CONFIG_PARAVIRT */
16406
16407+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16408+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16409+
16410+#ifdef CONFIG_PAX_KERNEXEC
16411+static inline unsigned long native_pax_open_kernel(void)
16412+{
16413+ unsigned long cr0;
16414+
16415+ preempt_disable();
16416+ barrier();
16417+ cr0 = read_cr0() ^ X86_CR0_WP;
16418+ BUG_ON(cr0 & X86_CR0_WP);
16419+ write_cr0(cr0);
16420+ return cr0 ^ X86_CR0_WP;
16421+}
16422+
16423+static inline unsigned long native_pax_close_kernel(void)
16424+{
16425+ unsigned long cr0;
16426+
16427+ cr0 = read_cr0() ^ X86_CR0_WP;
16428+ BUG_ON(!(cr0 & X86_CR0_WP));
16429+ write_cr0(cr0);
16430+ barrier();
16431+ preempt_enable_no_resched();
16432+ return cr0 ^ X86_CR0_WP;
16433+}
16434+#else
16435+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16436+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16437+#endif
16438+
16439 /*
16440 * The following only work if pte_present() is true.
16441 * Undefined behaviour if not..
16442 */
16443+static inline int pte_user(pte_t pte)
16444+{
16445+ return pte_val(pte) & _PAGE_USER;
16446+}
16447+
16448 static inline int pte_dirty(pte_t pte)
16449 {
16450 return pte_flags(pte) & _PAGE_DIRTY;
16451@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16452 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16453 }
16454
16455+static inline unsigned long pgd_pfn(pgd_t pgd)
16456+{
16457+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16458+}
16459+
16460 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16461
16462 static inline int pmd_large(pmd_t pte)
16463@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16464 return pte_clear_flags(pte, _PAGE_RW);
16465 }
16466
16467+static inline pte_t pte_mkread(pte_t pte)
16468+{
16469+ return __pte(pte_val(pte) | _PAGE_USER);
16470+}
16471+
16472 static inline pte_t pte_mkexec(pte_t pte)
16473 {
16474- return pte_clear_flags(pte, _PAGE_NX);
16475+#ifdef CONFIG_X86_PAE
16476+ if (__supported_pte_mask & _PAGE_NX)
16477+ return pte_clear_flags(pte, _PAGE_NX);
16478+ else
16479+#endif
16480+ return pte_set_flags(pte, _PAGE_USER);
16481+}
16482+
16483+static inline pte_t pte_exprotect(pte_t pte)
16484+{
16485+#ifdef CONFIG_X86_PAE
16486+ if (__supported_pte_mask & _PAGE_NX)
16487+ return pte_set_flags(pte, _PAGE_NX);
16488+ else
16489+#endif
16490+ return pte_clear_flags(pte, _PAGE_USER);
16491 }
16492
16493 static inline pte_t pte_mkdirty(pte_t pte)
16494@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16495 #endif
16496
16497 #ifndef __ASSEMBLY__
16498+
16499+#ifdef CONFIG_PAX_PER_CPU_PGD
16500+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16501+enum cpu_pgd_type {kernel = 0, user = 1};
16502+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16503+{
16504+ return cpu_pgd[cpu][type];
16505+}
16506+#endif
16507+
16508 #include <linux/mm_types.h>
16509 #include <linux/mmdebug.h>
16510 #include <linux/log2.h>
16511@@ -563,7 +638,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16512 * Currently stuck as a macro due to indirect forward reference to
16513 * linux/mmzone.h's __section_mem_map_addr() definition:
16514 */
16515-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16516+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16517
16518 /* Find an entry in the second-level page table.. */
16519 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16520@@ -603,7 +678,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16521 * Currently stuck as a macro due to indirect forward reference to
16522 * linux/mmzone.h's __section_mem_map_addr() definition:
16523 */
16524-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16525+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16526
16527 /* to find an entry in a page-table-directory. */
16528 static inline unsigned long pud_index(unsigned long address)
16529@@ -618,7 +693,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16530
16531 static inline int pgd_bad(pgd_t pgd)
16532 {
16533- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16534+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16535 }
16536
16537 static inline int pgd_none(pgd_t pgd)
16538@@ -641,7 +716,12 @@ static inline int pgd_none(pgd_t pgd)
16539 * pgd_offset() returns a (pgd_t *)
16540 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16541 */
16542-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16543+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16544+
16545+#ifdef CONFIG_PAX_PER_CPU_PGD
16546+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16547+#endif
16548+
16549 /*
16550 * a shortcut which implies the use of the kernel's pgd, instead
16551 * of a process's
16552@@ -652,6 +732,23 @@ static inline int pgd_none(pgd_t pgd)
16553 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16554 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16555
16556+#ifdef CONFIG_X86_32
16557+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16558+#else
16559+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16560+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16561+
16562+#ifdef CONFIG_PAX_MEMORY_UDEREF
16563+#ifdef __ASSEMBLY__
16564+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16565+#else
16566+extern unsigned long pax_user_shadow_base;
16567+extern pgdval_t clone_pgd_mask;
16568+#endif
16569+#endif
16570+
16571+#endif
16572+
16573 #ifndef __ASSEMBLY__
16574
16575 extern int direct_gbpages;
16576@@ -818,11 +915,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16577 * dst and src can be on the same page, but the range must not overlap,
16578 * and must not cross a page boundary.
16579 */
16580-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16581+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16582 {
16583- memcpy(dst, src, count * sizeof(pgd_t));
16584+ pax_open_kernel();
16585+ while (count--)
16586+ *dst++ = *src++;
16587+ pax_close_kernel();
16588 }
16589
16590+#ifdef CONFIG_PAX_PER_CPU_PGD
16591+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16592+#endif
16593+
16594+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16595+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16596+#else
16597+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16598+#endif
16599+
16600 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16601 static inline int page_level_shift(enum pg_level level)
16602 {
16603diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16604index 9ee3221..b979c6b 100644
16605--- a/arch/x86/include/asm/pgtable_32.h
16606+++ b/arch/x86/include/asm/pgtable_32.h
16607@@ -25,9 +25,6 @@
16608 struct mm_struct;
16609 struct vm_area_struct;
16610
16611-extern pgd_t swapper_pg_dir[1024];
16612-extern pgd_t initial_page_table[1024];
16613-
16614 static inline void pgtable_cache_init(void) { }
16615 static inline void check_pgt_cache(void) { }
16616 void paging_init(void);
16617@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16618 # include <asm/pgtable-2level.h>
16619 #endif
16620
16621+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16622+extern pgd_t initial_page_table[PTRS_PER_PGD];
16623+#ifdef CONFIG_X86_PAE
16624+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16625+#endif
16626+
16627 #if defined(CONFIG_HIGHPTE)
16628 #define pte_offset_map(dir, address) \
16629 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16630@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16631 /* Clear a kernel PTE and flush it from the TLB */
16632 #define kpte_clear_flush(ptep, vaddr) \
16633 do { \
16634+ pax_open_kernel(); \
16635 pte_clear(&init_mm, (vaddr), (ptep)); \
16636+ pax_close_kernel(); \
16637 __flush_tlb_one((vaddr)); \
16638 } while (0)
16639
16640 #endif /* !__ASSEMBLY__ */
16641
16642+#define HAVE_ARCH_UNMAPPED_AREA
16643+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16644+
16645 /*
16646 * kern_addr_valid() is (1) for FLATMEM and (0) for
16647 * SPARSEMEM and DISCONTIGMEM
16648diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16649index ed5903b..c7fe163 100644
16650--- a/arch/x86/include/asm/pgtable_32_types.h
16651+++ b/arch/x86/include/asm/pgtable_32_types.h
16652@@ -8,7 +8,7 @@
16653 */
16654 #ifdef CONFIG_X86_PAE
16655 # include <asm/pgtable-3level_types.h>
16656-# define PMD_SIZE (1UL << PMD_SHIFT)
16657+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16658 # define PMD_MASK (~(PMD_SIZE - 1))
16659 #else
16660 # include <asm/pgtable-2level_types.h>
16661@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16662 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16663 #endif
16664
16665+#ifdef CONFIG_PAX_KERNEXEC
16666+#ifndef __ASSEMBLY__
16667+extern unsigned char MODULES_EXEC_VADDR[];
16668+extern unsigned char MODULES_EXEC_END[];
16669+#endif
16670+#include <asm/boot.h>
16671+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16672+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16673+#else
16674+#define ktla_ktva(addr) (addr)
16675+#define ktva_ktla(addr) (addr)
16676+#endif
16677+
16678 #define MODULES_VADDR VMALLOC_START
16679 #define MODULES_END VMALLOC_END
16680 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16681diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16682index e22c1db..23a625a 100644
16683--- a/arch/x86/include/asm/pgtable_64.h
16684+++ b/arch/x86/include/asm/pgtable_64.h
16685@@ -16,10 +16,14 @@
16686
16687 extern pud_t level3_kernel_pgt[512];
16688 extern pud_t level3_ident_pgt[512];
16689+extern pud_t level3_vmalloc_start_pgt[512];
16690+extern pud_t level3_vmalloc_end_pgt[512];
16691+extern pud_t level3_vmemmap_pgt[512];
16692+extern pud_t level2_vmemmap_pgt[512];
16693 extern pmd_t level2_kernel_pgt[512];
16694 extern pmd_t level2_fixmap_pgt[512];
16695-extern pmd_t level2_ident_pgt[512];
16696-extern pgd_t init_level4_pgt[];
16697+extern pmd_t level2_ident_pgt[512*2];
16698+extern pgd_t init_level4_pgt[512];
16699
16700 #define swapper_pg_dir init_level4_pgt
16701
16702@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16703
16704 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16705 {
16706+ pax_open_kernel();
16707 *pmdp = pmd;
16708+ pax_close_kernel();
16709 }
16710
16711 static inline void native_pmd_clear(pmd_t *pmd)
16712@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16713
16714 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16715 {
16716+ pax_open_kernel();
16717 *pudp = pud;
16718+ pax_close_kernel();
16719 }
16720
16721 static inline void native_pud_clear(pud_t *pud)
16722@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16723
16724 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16725 {
16726+ pax_open_kernel();
16727+ *pgdp = pgd;
16728+ pax_close_kernel();
16729+}
16730+
16731+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16732+{
16733 *pgdp = pgd;
16734 }
16735
16736diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16737index 2d88344..4679fc3 100644
16738--- a/arch/x86/include/asm/pgtable_64_types.h
16739+++ b/arch/x86/include/asm/pgtable_64_types.h
16740@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16741 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16742 #define MODULES_END _AC(0xffffffffff000000, UL)
16743 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16744+#define MODULES_EXEC_VADDR MODULES_VADDR
16745+#define MODULES_EXEC_END MODULES_END
16746+
16747+#define ktla_ktva(addr) (addr)
16748+#define ktva_ktla(addr) (addr)
16749
16750 #define EARLY_DYNAMIC_PAGE_TABLES 64
16751
16752diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16753index 0ecac25..306c276 100644
16754--- a/arch/x86/include/asm/pgtable_types.h
16755+++ b/arch/x86/include/asm/pgtable_types.h
16756@@ -16,13 +16,12 @@
16757 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16758 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16759 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16760-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16761+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16762 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16763 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16764 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16765-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16766-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16767-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16768+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16769+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16770 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16771
16772 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16773@@ -40,7 +39,6 @@
16774 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16775 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16776 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16777-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16778 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16779 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16780 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16781@@ -87,8 +85,10 @@
16782
16783 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16784 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16785-#else
16786+#elif defined(CONFIG_KMEMCHECK)
16787 #define _PAGE_NX (_AT(pteval_t, 0))
16788+#else
16789+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16790 #endif
16791
16792 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16793@@ -146,6 +146,9 @@
16794 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16795 _PAGE_ACCESSED)
16796
16797+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16798+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16799+
16800 #define __PAGE_KERNEL_EXEC \
16801 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16802 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16803@@ -156,7 +159,7 @@
16804 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16805 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16806 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16807-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16808+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16809 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16810 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16811 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16812@@ -218,8 +221,8 @@
16813 * bits are combined, this will alow user to access the high address mapped
16814 * VDSO in the presence of CONFIG_COMPAT_VDSO
16815 */
16816-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16817-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16818+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16819+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16820 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16821 #endif
16822
16823@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16824 {
16825 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16826 }
16827+#endif
16828
16829+#if PAGETABLE_LEVELS == 3
16830+#include <asm-generic/pgtable-nopud.h>
16831+#endif
16832+
16833+#if PAGETABLE_LEVELS == 2
16834+#include <asm-generic/pgtable-nopmd.h>
16835+#endif
16836+
16837+#ifndef __ASSEMBLY__
16838 #if PAGETABLE_LEVELS > 3
16839 typedef struct { pudval_t pud; } pud_t;
16840
16841@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16842 return pud.pud;
16843 }
16844 #else
16845-#include <asm-generic/pgtable-nopud.h>
16846-
16847 static inline pudval_t native_pud_val(pud_t pud)
16848 {
16849 return native_pgd_val(pud.pgd);
16850@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16851 return pmd.pmd;
16852 }
16853 #else
16854-#include <asm-generic/pgtable-nopmd.h>
16855-
16856 static inline pmdval_t native_pmd_val(pmd_t pmd)
16857 {
16858 return native_pgd_val(pmd.pud.pgd);
16859@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
16860
16861 extern pteval_t __supported_pte_mask;
16862 extern void set_nx(void);
16863-extern int nx_enabled;
16864
16865 #define pgprot_writecombine pgprot_writecombine
16866 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16867diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16868index 987c75e..2723054 100644
16869--- a/arch/x86/include/asm/processor.h
16870+++ b/arch/x86/include/asm/processor.h
16871@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16872 : "memory");
16873 }
16874
16875+/* invpcid (%rdx),%rax */
16876+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16877+
16878+#define INVPCID_SINGLE_ADDRESS 0UL
16879+#define INVPCID_SINGLE_CONTEXT 1UL
16880+#define INVPCID_ALL_GLOBAL 2UL
16881+#define INVPCID_ALL_MONGLOBAL 3UL
16882+
16883+#define PCID_KERNEL 0UL
16884+#define PCID_USER 1UL
16885+#define PCID_NOFLUSH (1UL << 63)
16886+
16887 static inline void load_cr3(pgd_t *pgdir)
16888 {
16889- write_cr3(__pa(pgdir));
16890+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16891 }
16892
16893 #ifdef CONFIG_X86_32
16894@@ -283,7 +295,7 @@ struct tss_struct {
16895
16896 } ____cacheline_aligned;
16897
16898-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16899+extern struct tss_struct init_tss[NR_CPUS];
16900
16901 /*
16902 * Save the original ist values for checking stack pointers during debugging
16903@@ -453,6 +465,7 @@ struct thread_struct {
16904 unsigned short ds;
16905 unsigned short fsindex;
16906 unsigned short gsindex;
16907+ unsigned short ss;
16908 #endif
16909 #ifdef CONFIG_X86_32
16910 unsigned long ip;
16911@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16912 extern unsigned long mmu_cr4_features;
16913 extern u32 *trampoline_cr4_features;
16914
16915-static inline void set_in_cr4(unsigned long mask)
16916-{
16917- unsigned long cr4;
16918-
16919- mmu_cr4_features |= mask;
16920- if (trampoline_cr4_features)
16921- *trampoline_cr4_features = mmu_cr4_features;
16922- cr4 = read_cr4();
16923- cr4 |= mask;
16924- write_cr4(cr4);
16925-}
16926-
16927-static inline void clear_in_cr4(unsigned long mask)
16928-{
16929- unsigned long cr4;
16930-
16931- mmu_cr4_features &= ~mask;
16932- if (trampoline_cr4_features)
16933- *trampoline_cr4_features = mmu_cr4_features;
16934- cr4 = read_cr4();
16935- cr4 &= ~mask;
16936- write_cr4(cr4);
16937-}
16938+extern void set_in_cr4(unsigned long mask);
16939+extern void clear_in_cr4(unsigned long mask);
16940
16941 typedef struct {
16942 unsigned long seg;
16943@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16944 */
16945 #define TASK_SIZE PAGE_OFFSET
16946 #define TASK_SIZE_MAX TASK_SIZE
16947+
16948+#ifdef CONFIG_PAX_SEGMEXEC
16949+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16950+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16951+#else
16952 #define STACK_TOP TASK_SIZE
16953-#define STACK_TOP_MAX STACK_TOP
16954+#endif
16955+
16956+#define STACK_TOP_MAX TASK_SIZE
16957
16958 #define INIT_THREAD { \
16959- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16960+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16961 .vm86_info = NULL, \
16962 .sysenter_cs = __KERNEL_CS, \
16963 .io_bitmap_ptr = NULL, \
16964@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16965 */
16966 #define INIT_TSS { \
16967 .x86_tss = { \
16968- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16969+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16970 .ss0 = __KERNEL_DS, \
16971 .ss1 = __KERNEL_CS, \
16972 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16973@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16974 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16975
16976 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16977-#define KSTK_TOP(info) \
16978-({ \
16979- unsigned long *__ptr = (unsigned long *)(info); \
16980- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16981-})
16982+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16983
16984 /*
16985 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16986@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16987 #define task_pt_regs(task) \
16988 ({ \
16989 struct pt_regs *__regs__; \
16990- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16991+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16992 __regs__ - 1; \
16993 })
16994
16995@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16996 /*
16997 * User space process size. 47bits minus one guard page.
16998 */
16999-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17000+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17001
17002 /* This decides where the kernel will search for a free chunk of vm
17003 * space during mmap's.
17004 */
17005 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17006- 0xc0000000 : 0xFFFFe000)
17007+ 0xc0000000 : 0xFFFFf000)
17008
17009 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17010 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17011@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17012 #define STACK_TOP_MAX TASK_SIZE_MAX
17013
17014 #define INIT_THREAD { \
17015- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17016+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17017 }
17018
17019 #define INIT_TSS { \
17020- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17021+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17022 }
17023
17024 /*
17025@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17026 */
17027 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17028
17029+#ifdef CONFIG_PAX_SEGMEXEC
17030+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17031+#endif
17032+
17033 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17034
17035 /* Get/set a process' ability to use the timestamp counter instruction */
17036@@ -957,7 +956,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17037 return 0;
17038 }
17039
17040-extern unsigned long arch_align_stack(unsigned long sp);
17041+#define arch_align_stack(x) ((x) & ~0xfUL)
17042 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17043
17044 void default_idle(void);
17045@@ -967,6 +966,6 @@ bool xen_set_default_idle(void);
17046 #define xen_set_default_idle 0
17047 #endif
17048
17049-void stop_this_cpu(void *dummy);
17050+void stop_this_cpu(void *dummy) __noreturn;
17051 void df_debug(struct pt_regs *regs, long error_code);
17052 #endif /* _ASM_X86_PROCESSOR_H */
17053diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17054index 942a086..6c26446 100644
17055--- a/arch/x86/include/asm/ptrace.h
17056+++ b/arch/x86/include/asm/ptrace.h
17057@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17058 }
17059
17060 /*
17061- * user_mode_vm(regs) determines whether a register set came from user mode.
17062+ * user_mode(regs) determines whether a register set came from user mode.
17063 * This is true if V8086 mode was enabled OR if the register set was from
17064 * protected mode with RPL-3 CS value. This tricky test checks that with
17065 * one comparison. Many places in the kernel can bypass this full check
17066- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17067+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17068+ * be used.
17069 */
17070-static inline int user_mode(struct pt_regs *regs)
17071+static inline int user_mode_novm(struct pt_regs *regs)
17072 {
17073 #ifdef CONFIG_X86_32
17074 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17075 #else
17076- return !!(regs->cs & 3);
17077+ return !!(regs->cs & SEGMENT_RPL_MASK);
17078 #endif
17079 }
17080
17081-static inline int user_mode_vm(struct pt_regs *regs)
17082+static inline int user_mode(struct pt_regs *regs)
17083 {
17084 #ifdef CONFIG_X86_32
17085 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17086 USER_RPL;
17087 #else
17088- return user_mode(regs);
17089+ return user_mode_novm(regs);
17090 #endif
17091 }
17092
17093@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17094 #ifdef CONFIG_X86_64
17095 static inline bool user_64bit_mode(struct pt_regs *regs)
17096 {
17097+ unsigned long cs = regs->cs & 0xffff;
17098 #ifndef CONFIG_PARAVIRT
17099 /*
17100 * On non-paravirt systems, this is the only long mode CPL 3
17101 * selector. We do not allow long mode selectors in the LDT.
17102 */
17103- return regs->cs == __USER_CS;
17104+ return cs == __USER_CS;
17105 #else
17106 /* Headers are too twisted for this to go in paravirt.h. */
17107- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17108+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17109 #endif
17110 }
17111
17112@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17113 * Traps from the kernel do not save sp and ss.
17114 * Use the helper function to retrieve sp.
17115 */
17116- if (offset == offsetof(struct pt_regs, sp) &&
17117- regs->cs == __KERNEL_CS)
17118- return kernel_stack_pointer(regs);
17119+ if (offset == offsetof(struct pt_regs, sp)) {
17120+ unsigned long cs = regs->cs & 0xffff;
17121+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17122+ return kernel_stack_pointer(regs);
17123+ }
17124 #endif
17125 return *(unsigned long *)((unsigned long)regs + offset);
17126 }
17127diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17128index 9c6b890..5305f53 100644
17129--- a/arch/x86/include/asm/realmode.h
17130+++ b/arch/x86/include/asm/realmode.h
17131@@ -22,16 +22,14 @@ struct real_mode_header {
17132 #endif
17133 /* APM/BIOS reboot */
17134 u32 machine_real_restart_asm;
17135-#ifdef CONFIG_X86_64
17136 u32 machine_real_restart_seg;
17137-#endif
17138 };
17139
17140 /* This must match data at trampoline_32/64.S */
17141 struct trampoline_header {
17142 #ifdef CONFIG_X86_32
17143 u32 start;
17144- u16 gdt_pad;
17145+ u16 boot_cs;
17146 u16 gdt_limit;
17147 u32 gdt_base;
17148 #else
17149diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17150index a82c4f1..ac45053 100644
17151--- a/arch/x86/include/asm/reboot.h
17152+++ b/arch/x86/include/asm/reboot.h
17153@@ -6,13 +6,13 @@
17154 struct pt_regs;
17155
17156 struct machine_ops {
17157- void (*restart)(char *cmd);
17158- void (*halt)(void);
17159- void (*power_off)(void);
17160+ void (* __noreturn restart)(char *cmd);
17161+ void (* __noreturn halt)(void);
17162+ void (* __noreturn power_off)(void);
17163 void (*shutdown)(void);
17164 void (*crash_shutdown)(struct pt_regs *);
17165- void (*emergency_restart)(void);
17166-};
17167+ void (* __noreturn emergency_restart)(void);
17168+} __no_const;
17169
17170 extern struct machine_ops machine_ops;
17171
17172diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17173index cad82c9..2e5c5c1 100644
17174--- a/arch/x86/include/asm/rwsem.h
17175+++ b/arch/x86/include/asm/rwsem.h
17176@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17177 {
17178 asm volatile("# beginning down_read\n\t"
17179 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17180+
17181+#ifdef CONFIG_PAX_REFCOUNT
17182+ "jno 0f\n"
17183+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17184+ "int $4\n0:\n"
17185+ _ASM_EXTABLE(0b, 0b)
17186+#endif
17187+
17188 /* adds 0x00000001 */
17189 " jns 1f\n"
17190 " call call_rwsem_down_read_failed\n"
17191@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17192 "1:\n\t"
17193 " mov %1,%2\n\t"
17194 " add %3,%2\n\t"
17195+
17196+#ifdef CONFIG_PAX_REFCOUNT
17197+ "jno 0f\n"
17198+ "sub %3,%2\n"
17199+ "int $4\n0:\n"
17200+ _ASM_EXTABLE(0b, 0b)
17201+#endif
17202+
17203 " jle 2f\n\t"
17204 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17205 " jnz 1b\n\t"
17206@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17207 long tmp;
17208 asm volatile("# beginning down_write\n\t"
17209 LOCK_PREFIX " xadd %1,(%2)\n\t"
17210+
17211+#ifdef CONFIG_PAX_REFCOUNT
17212+ "jno 0f\n"
17213+ "mov %1,(%2)\n"
17214+ "int $4\n0:\n"
17215+ _ASM_EXTABLE(0b, 0b)
17216+#endif
17217+
17218 /* adds 0xffff0001, returns the old value */
17219 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17220 /* was the active mask 0 before? */
17221@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17222 long tmp;
17223 asm volatile("# beginning __up_read\n\t"
17224 LOCK_PREFIX " xadd %1,(%2)\n\t"
17225+
17226+#ifdef CONFIG_PAX_REFCOUNT
17227+ "jno 0f\n"
17228+ "mov %1,(%2)\n"
17229+ "int $4\n0:\n"
17230+ _ASM_EXTABLE(0b, 0b)
17231+#endif
17232+
17233 /* subtracts 1, returns the old value */
17234 " jns 1f\n\t"
17235 " call call_rwsem_wake\n" /* expects old value in %edx */
17236@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17237 long tmp;
17238 asm volatile("# beginning __up_write\n\t"
17239 LOCK_PREFIX " xadd %1,(%2)\n\t"
17240+
17241+#ifdef CONFIG_PAX_REFCOUNT
17242+ "jno 0f\n"
17243+ "mov %1,(%2)\n"
17244+ "int $4\n0:\n"
17245+ _ASM_EXTABLE(0b, 0b)
17246+#endif
17247+
17248 /* subtracts 0xffff0001, returns the old value */
17249 " jns 1f\n\t"
17250 " call call_rwsem_wake\n" /* expects old value in %edx */
17251@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17252 {
17253 asm volatile("# beginning __downgrade_write\n\t"
17254 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17255+
17256+#ifdef CONFIG_PAX_REFCOUNT
17257+ "jno 0f\n"
17258+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17259+ "int $4\n0:\n"
17260+ _ASM_EXTABLE(0b, 0b)
17261+#endif
17262+
17263 /*
17264 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17265 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17266@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17267 */
17268 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17269 {
17270- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17271+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17272+
17273+#ifdef CONFIG_PAX_REFCOUNT
17274+ "jno 0f\n"
17275+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17276+ "int $4\n0:\n"
17277+ _ASM_EXTABLE(0b, 0b)
17278+#endif
17279+
17280 : "+m" (sem->count)
17281 : "er" (delta));
17282 }
17283@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17284 */
17285 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17286 {
17287- return delta + xadd(&sem->count, delta);
17288+ return delta + xadd_check_overflow(&sem->count, delta);
17289 }
17290
17291 #endif /* __KERNEL__ */
17292diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17293index c48a950..bc40804 100644
17294--- a/arch/x86/include/asm/segment.h
17295+++ b/arch/x86/include/asm/segment.h
17296@@ -64,10 +64,15 @@
17297 * 26 - ESPFIX small SS
17298 * 27 - per-cpu [ offset to per-cpu data area ]
17299 * 28 - stack_canary-20 [ for stack protector ]
17300- * 29 - unused
17301- * 30 - unused
17302+ * 29 - PCI BIOS CS
17303+ * 30 - PCI BIOS DS
17304 * 31 - TSS for double fault handler
17305 */
17306+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17307+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17308+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17309+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17310+
17311 #define GDT_ENTRY_TLS_MIN 6
17312 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17313
17314@@ -79,6 +84,8 @@
17315
17316 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17317
17318+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17319+
17320 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17321
17322 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17323@@ -104,6 +111,12 @@
17324 #define __KERNEL_STACK_CANARY 0
17325 #endif
17326
17327+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17328+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17329+
17330+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17331+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17332+
17333 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17334
17335 /*
17336@@ -141,7 +154,7 @@
17337 */
17338
17339 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17340-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17341+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17342
17343
17344 #else
17345@@ -165,6 +178,8 @@
17346 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17347 #define __USER32_DS __USER_DS
17348
17349+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17350+
17351 #define GDT_ENTRY_TSS 8 /* needs two entries */
17352 #define GDT_ENTRY_LDT 10 /* needs two entries */
17353 #define GDT_ENTRY_TLS_MIN 12
17354@@ -173,6 +188,8 @@
17355 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17356 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17357
17358+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17359+
17360 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17361 #define FS_TLS 0
17362 #define GS_TLS 1
17363@@ -180,12 +197,14 @@
17364 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17365 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17366
17367-#define GDT_ENTRIES 16
17368+#define GDT_ENTRIES 17
17369
17370 #endif
17371
17372 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17373+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17374 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17375+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17376 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17377 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17378 #ifndef CONFIG_PARAVIRT
17379@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17380 {
17381 unsigned long __limit;
17382 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17383- return __limit + 1;
17384+ return __limit;
17385 }
17386
17387 #endif /* !__ASSEMBLY__ */
17388diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17389index 8d3120f..352b440 100644
17390--- a/arch/x86/include/asm/smap.h
17391+++ b/arch/x86/include/asm/smap.h
17392@@ -25,11 +25,40 @@
17393
17394 #include <asm/alternative-asm.h>
17395
17396+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17397+#define ASM_PAX_OPEN_USERLAND \
17398+ 661: jmp 663f; \
17399+ .pushsection .altinstr_replacement, "a" ; \
17400+ 662: pushq %rax; nop; \
17401+ .popsection ; \
17402+ .pushsection .altinstructions, "a" ; \
17403+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17404+ .popsection ; \
17405+ call __pax_open_userland; \
17406+ popq %rax; \
17407+ 663:
17408+
17409+#define ASM_PAX_CLOSE_USERLAND \
17410+ 661: jmp 663f; \
17411+ .pushsection .altinstr_replacement, "a" ; \
17412+ 662: pushq %rax; nop; \
17413+ .popsection; \
17414+ .pushsection .altinstructions, "a" ; \
17415+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17416+ .popsection; \
17417+ call __pax_close_userland; \
17418+ popq %rax; \
17419+ 663:
17420+#else
17421+#define ASM_PAX_OPEN_USERLAND
17422+#define ASM_PAX_CLOSE_USERLAND
17423+#endif
17424+
17425 #ifdef CONFIG_X86_SMAP
17426
17427 #define ASM_CLAC \
17428 661: ASM_NOP3 ; \
17429- .pushsection .altinstr_replacement, "ax" ; \
17430+ .pushsection .altinstr_replacement, "a" ; \
17431 662: __ASM_CLAC ; \
17432 .popsection ; \
17433 .pushsection .altinstructions, "a" ; \
17434@@ -38,7 +67,7 @@
17435
17436 #define ASM_STAC \
17437 661: ASM_NOP3 ; \
17438- .pushsection .altinstr_replacement, "ax" ; \
17439+ .pushsection .altinstr_replacement, "a" ; \
17440 662: __ASM_STAC ; \
17441 .popsection ; \
17442 .pushsection .altinstructions, "a" ; \
17443@@ -56,6 +85,37 @@
17444
17445 #include <asm/alternative.h>
17446
17447+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17448+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17449+
17450+extern void __pax_open_userland(void);
17451+static __always_inline unsigned long pax_open_userland(void)
17452+{
17453+
17454+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17455+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17456+ :
17457+ : [open] "i" (__pax_open_userland)
17458+ : "memory", "rax");
17459+#endif
17460+
17461+ return 0;
17462+}
17463+
17464+extern void __pax_close_userland(void);
17465+static __always_inline unsigned long pax_close_userland(void)
17466+{
17467+
17468+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17469+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17470+ :
17471+ : [close] "i" (__pax_close_userland)
17472+ : "memory", "rax");
17473+#endif
17474+
17475+ return 0;
17476+}
17477+
17478 #ifdef CONFIG_X86_SMAP
17479
17480 static __always_inline void clac(void)
17481diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17482index 4137890..03fa172 100644
17483--- a/arch/x86/include/asm/smp.h
17484+++ b/arch/x86/include/asm/smp.h
17485@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17486 /* cpus sharing the last level cache: */
17487 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17488 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17489-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17490+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17491
17492 static inline struct cpumask *cpu_sibling_mask(int cpu)
17493 {
17494@@ -79,7 +79,7 @@ struct smp_ops {
17495
17496 void (*send_call_func_ipi)(const struct cpumask *mask);
17497 void (*send_call_func_single_ipi)(int cpu);
17498-};
17499+} __no_const;
17500
17501 /* Globals due to paravirt */
17502 extern void set_cpu_sibling_map(int cpu);
17503@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17504 extern int safe_smp_processor_id(void);
17505
17506 #elif defined(CONFIG_X86_64_SMP)
17507-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17508-
17509-#define stack_smp_processor_id() \
17510-({ \
17511- struct thread_info *ti; \
17512- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17513- ti->cpu; \
17514-})
17515+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17516+#define stack_smp_processor_id() raw_smp_processor_id()
17517 #define safe_smp_processor_id() smp_processor_id()
17518
17519 #endif
17520diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17521index bf156de..1a782ab 100644
17522--- a/arch/x86/include/asm/spinlock.h
17523+++ b/arch/x86/include/asm/spinlock.h
17524@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17525 static inline void arch_read_lock(arch_rwlock_t *rw)
17526 {
17527 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17528+
17529+#ifdef CONFIG_PAX_REFCOUNT
17530+ "jno 0f\n"
17531+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17532+ "int $4\n0:\n"
17533+ _ASM_EXTABLE(0b, 0b)
17534+#endif
17535+
17536 "jns 1f\n"
17537 "call __read_lock_failed\n\t"
17538 "1:\n"
17539@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17540 static inline void arch_write_lock(arch_rwlock_t *rw)
17541 {
17542 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17543+
17544+#ifdef CONFIG_PAX_REFCOUNT
17545+ "jno 0f\n"
17546+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17547+ "int $4\n0:\n"
17548+ _ASM_EXTABLE(0b, 0b)
17549+#endif
17550+
17551 "jz 1f\n"
17552 "call __write_lock_failed\n\t"
17553 "1:\n"
17554@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17555
17556 static inline void arch_read_unlock(arch_rwlock_t *rw)
17557 {
17558- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17559+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17560+
17561+#ifdef CONFIG_PAX_REFCOUNT
17562+ "jno 0f\n"
17563+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17564+ "int $4\n0:\n"
17565+ _ASM_EXTABLE(0b, 0b)
17566+#endif
17567+
17568 :"+m" (rw->lock) : : "memory");
17569 }
17570
17571 static inline void arch_write_unlock(arch_rwlock_t *rw)
17572 {
17573- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17574+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17575+
17576+#ifdef CONFIG_PAX_REFCOUNT
17577+ "jno 0f\n"
17578+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17579+ "int $4\n0:\n"
17580+ _ASM_EXTABLE(0b, 0b)
17581+#endif
17582+
17583 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17584 }
17585
17586diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17587index 6a99859..03cb807 100644
17588--- a/arch/x86/include/asm/stackprotector.h
17589+++ b/arch/x86/include/asm/stackprotector.h
17590@@ -47,7 +47,7 @@
17591 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17592 */
17593 #define GDT_STACK_CANARY_INIT \
17594- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17595+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17596
17597 /*
17598 * Initialize the stackprotector canary value.
17599@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17600
17601 static inline void load_stack_canary_segment(void)
17602 {
17603-#ifdef CONFIG_X86_32
17604+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17605 asm volatile ("mov %0, %%gs" : : "r" (0));
17606 #endif
17607 }
17608diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17609index 70bbe39..4ae2bd4 100644
17610--- a/arch/x86/include/asm/stacktrace.h
17611+++ b/arch/x86/include/asm/stacktrace.h
17612@@ -11,28 +11,20 @@
17613
17614 extern int kstack_depth_to_print;
17615
17616-struct thread_info;
17617+struct task_struct;
17618 struct stacktrace_ops;
17619
17620-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17621- unsigned long *stack,
17622- unsigned long bp,
17623- const struct stacktrace_ops *ops,
17624- void *data,
17625- unsigned long *end,
17626- int *graph);
17627+typedef unsigned long walk_stack_t(struct task_struct *task,
17628+ void *stack_start,
17629+ unsigned long *stack,
17630+ unsigned long bp,
17631+ const struct stacktrace_ops *ops,
17632+ void *data,
17633+ unsigned long *end,
17634+ int *graph);
17635
17636-extern unsigned long
17637-print_context_stack(struct thread_info *tinfo,
17638- unsigned long *stack, unsigned long bp,
17639- const struct stacktrace_ops *ops, void *data,
17640- unsigned long *end, int *graph);
17641-
17642-extern unsigned long
17643-print_context_stack_bp(struct thread_info *tinfo,
17644- unsigned long *stack, unsigned long bp,
17645- const struct stacktrace_ops *ops, void *data,
17646- unsigned long *end, int *graph);
17647+extern walk_stack_t print_context_stack;
17648+extern walk_stack_t print_context_stack_bp;
17649
17650 /* Generic stack tracer with callbacks */
17651
17652@@ -40,7 +32,7 @@ struct stacktrace_ops {
17653 void (*address)(void *data, unsigned long address, int reliable);
17654 /* On negative return stop dumping */
17655 int (*stack)(void *data, char *name);
17656- walk_stack_t walk_stack;
17657+ walk_stack_t *walk_stack;
17658 };
17659
17660 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17661diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17662index d7f3b3b..3cc39f1 100644
17663--- a/arch/x86/include/asm/switch_to.h
17664+++ b/arch/x86/include/asm/switch_to.h
17665@@ -108,7 +108,7 @@ do { \
17666 "call __switch_to\n\t" \
17667 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17668 __switch_canary \
17669- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17670+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17671 "movq %%rax,%%rdi\n\t" \
17672 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17673 "jnz ret_from_fork\n\t" \
17674@@ -119,7 +119,7 @@ do { \
17675 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17676 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17677 [_tif_fork] "i" (_TIF_FORK), \
17678- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17679+ [thread_info] "m" (current_tinfo), \
17680 [current_task] "m" (current_task) \
17681 __switch_canary_iparam \
17682 : "memory", "cc" __EXTRA_CLOBBER)
17683diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17684index 2781119..618b59b 100644
17685--- a/arch/x86/include/asm/thread_info.h
17686+++ b/arch/x86/include/asm/thread_info.h
17687@@ -10,6 +10,7 @@
17688 #include <linux/compiler.h>
17689 #include <asm/page.h>
17690 #include <asm/types.h>
17691+#include <asm/percpu.h>
17692
17693 /*
17694 * low level task data that entry.S needs immediate access to
17695@@ -23,7 +24,6 @@ struct exec_domain;
17696 #include <linux/atomic.h>
17697
17698 struct thread_info {
17699- struct task_struct *task; /* main task structure */
17700 struct exec_domain *exec_domain; /* execution domain */
17701 __u32 flags; /* low level flags */
17702 __u32 status; /* thread synchronous flags */
17703@@ -33,19 +33,13 @@ struct thread_info {
17704 mm_segment_t addr_limit;
17705 struct restart_block restart_block;
17706 void __user *sysenter_return;
17707-#ifdef CONFIG_X86_32
17708- unsigned long previous_esp; /* ESP of the previous stack in
17709- case of nested (IRQ) stacks
17710- */
17711- __u8 supervisor_stack[0];
17712-#endif
17713+ unsigned long lowest_stack;
17714 unsigned int sig_on_uaccess_error:1;
17715 unsigned int uaccess_err:1; /* uaccess failed */
17716 };
17717
17718-#define INIT_THREAD_INFO(tsk) \
17719+#define INIT_THREAD_INFO \
17720 { \
17721- .task = &tsk, \
17722 .exec_domain = &default_exec_domain, \
17723 .flags = 0, \
17724 .cpu = 0, \
17725@@ -56,7 +50,7 @@ struct thread_info {
17726 }, \
17727 }
17728
17729-#define init_thread_info (init_thread_union.thread_info)
17730+#define init_thread_info (init_thread_union.stack)
17731 #define init_stack (init_thread_union.stack)
17732
17733 #else /* !__ASSEMBLY__ */
17734@@ -96,6 +90,7 @@ struct thread_info {
17735 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17736 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17737 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17738+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17739
17740 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17741 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17742@@ -119,17 +114,18 @@ struct thread_info {
17743 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17744 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17745 #define _TIF_X32 (1 << TIF_X32)
17746+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17747
17748 /* work to do in syscall_trace_enter() */
17749 #define _TIF_WORK_SYSCALL_ENTRY \
17750 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17751 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17752- _TIF_NOHZ)
17753+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17754
17755 /* work to do in syscall_trace_leave() */
17756 #define _TIF_WORK_SYSCALL_EXIT \
17757 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17758- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17759+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17760
17761 /* work to do on interrupt/exception return */
17762 #define _TIF_WORK_MASK \
17763@@ -140,7 +136,7 @@ struct thread_info {
17764 /* work to do on any return to user space */
17765 #define _TIF_ALLWORK_MASK \
17766 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17767- _TIF_NOHZ)
17768+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17769
17770 /* Only used for 64 bit */
17771 #define _TIF_DO_NOTIFY_MASK \
17772@@ -156,45 +152,40 @@ struct thread_info {
17773
17774 #define PREEMPT_ACTIVE 0x10000000
17775
17776-#ifdef CONFIG_X86_32
17777-
17778-#define STACK_WARN (THREAD_SIZE/8)
17779-/*
17780- * macros/functions for gaining access to the thread information structure
17781- *
17782- * preempt_count needs to be 1 initially, until the scheduler is functional.
17783- */
17784-#ifndef __ASSEMBLY__
17785-
17786-
17787-/* how to get the current stack pointer from C */
17788-register unsigned long current_stack_pointer asm("esp") __used;
17789-
17790-/* how to get the thread information struct from C */
17791-static inline struct thread_info *current_thread_info(void)
17792-{
17793- return (struct thread_info *)
17794- (current_stack_pointer & ~(THREAD_SIZE - 1));
17795-}
17796-
17797-#else /* !__ASSEMBLY__ */
17798-
17799+#ifdef __ASSEMBLY__
17800 /* how to get the thread information struct from ASM */
17801 #define GET_THREAD_INFO(reg) \
17802- movl $-THREAD_SIZE, reg; \
17803- andl %esp, reg
17804+ mov PER_CPU_VAR(current_tinfo), reg
17805
17806 /* use this one if reg already contains %esp */
17807-#define GET_THREAD_INFO_WITH_ESP(reg) \
17808- andl $-THREAD_SIZE, reg
17809+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17810+#else
17811+/* how to get the thread information struct from C */
17812+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17813+
17814+static __always_inline struct thread_info *current_thread_info(void)
17815+{
17816+ return this_cpu_read_stable(current_tinfo);
17817+}
17818+#endif
17819+
17820+#ifdef CONFIG_X86_32
17821+
17822+#define STACK_WARN (THREAD_SIZE/8)
17823+/*
17824+ * macros/functions for gaining access to the thread information structure
17825+ *
17826+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17827+ */
17828+#ifndef __ASSEMBLY__
17829+
17830+/* how to get the current stack pointer from C */
17831+register unsigned long current_stack_pointer asm("esp") __used;
17832
17833 #endif
17834
17835 #else /* X86_32 */
17836
17837-#include <asm/percpu.h>
17838-#define KERNEL_STACK_OFFSET (5*8)
17839-
17840 /*
17841 * macros/functions for gaining access to the thread information structure
17842 * preempt_count needs to be 1 initially, until the scheduler is functional.
17843@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17844 #ifndef __ASSEMBLY__
17845 DECLARE_PER_CPU(unsigned long, kernel_stack);
17846
17847-static inline struct thread_info *current_thread_info(void)
17848-{
17849- struct thread_info *ti;
17850- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17851- KERNEL_STACK_OFFSET - THREAD_SIZE);
17852- return ti;
17853-}
17854-
17855-#else /* !__ASSEMBLY__ */
17856-
17857-/* how to get the thread information struct from ASM */
17858-#define GET_THREAD_INFO(reg) \
17859- movq PER_CPU_VAR(kernel_stack),reg ; \
17860- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17861-
17862-/*
17863- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17864- * a certain register (to be used in assembler memory operands).
17865- */
17866-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17867-
17868+/* how to get the current stack pointer from C */
17869+register unsigned long current_stack_pointer asm("rsp") __used;
17870 #endif
17871
17872 #endif /* !X86_32 */
17873@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17874 extern void arch_task_cache_init(void);
17875 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17876 extern void arch_release_task_struct(struct task_struct *tsk);
17877+
17878+#define __HAVE_THREAD_FUNCTIONS
17879+#define task_thread_info(task) (&(task)->tinfo)
17880+#define task_stack_page(task) ((task)->stack)
17881+#define setup_thread_stack(p, org) do {} while (0)
17882+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17883+
17884 #endif
17885 #endif /* _ASM_X86_THREAD_INFO_H */
17886diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17887index e6d90ba..0897f44 100644
17888--- a/arch/x86/include/asm/tlbflush.h
17889+++ b/arch/x86/include/asm/tlbflush.h
17890@@ -17,18 +17,44 @@
17891
17892 static inline void __native_flush_tlb(void)
17893 {
17894+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17895+ u64 descriptor[2];
17896+
17897+ descriptor[0] = PCID_KERNEL;
17898+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17899+ return;
17900+ }
17901+
17902+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17903+ if (static_cpu_has(X86_FEATURE_PCID)) {
17904+ unsigned int cpu = raw_get_cpu();
17905+
17906+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17907+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17908+ raw_put_cpu_no_resched();
17909+ return;
17910+ }
17911+#endif
17912+
17913 native_write_cr3(native_read_cr3());
17914 }
17915
17916 static inline void __native_flush_tlb_global_irq_disabled(void)
17917 {
17918- unsigned long cr4;
17919+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17920+ u64 descriptor[2];
17921
17922- cr4 = native_read_cr4();
17923- /* clear PGE */
17924- native_write_cr4(cr4 & ~X86_CR4_PGE);
17925- /* write old PGE again and flush TLBs */
17926- native_write_cr4(cr4);
17927+ descriptor[0] = PCID_KERNEL;
17928+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17929+ } else {
17930+ unsigned long cr4;
17931+
17932+ cr4 = native_read_cr4();
17933+ /* clear PGE */
17934+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17935+ /* write old PGE again and flush TLBs */
17936+ native_write_cr4(cr4);
17937+ }
17938 }
17939
17940 static inline void __native_flush_tlb_global(void)
17941@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17942
17943 static inline void __native_flush_tlb_single(unsigned long addr)
17944 {
17945+
17946+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17947+ u64 descriptor[2];
17948+
17949+ descriptor[0] = PCID_KERNEL;
17950+ descriptor[1] = addr;
17951+
17952+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17953+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17954+ if (addr < TASK_SIZE_MAX)
17955+ descriptor[1] += pax_user_shadow_base;
17956+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17957+ }
17958+
17959+ descriptor[0] = PCID_USER;
17960+ descriptor[1] = addr;
17961+#endif
17962+
17963+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17964+ return;
17965+ }
17966+
17967+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17968+ if (static_cpu_has(X86_FEATURE_PCID)) {
17969+ unsigned int cpu = raw_get_cpu();
17970+
17971+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17972+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17973+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17974+ raw_put_cpu_no_resched();
17975+
17976+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17977+ addr += pax_user_shadow_base;
17978+ }
17979+#endif
17980+
17981 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17982 }
17983
17984diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17985index 5838fa9..f7ae572 100644
17986--- a/arch/x86/include/asm/uaccess.h
17987+++ b/arch/x86/include/asm/uaccess.h
17988@@ -7,6 +7,7 @@
17989 #include <linux/compiler.h>
17990 #include <linux/thread_info.h>
17991 #include <linux/string.h>
17992+#include <linux/sched.h>
17993 #include <asm/asm.h>
17994 #include <asm/page.h>
17995 #include <asm/smap.h>
17996@@ -29,7 +30,12 @@
17997
17998 #define get_ds() (KERNEL_DS)
17999 #define get_fs() (current_thread_info()->addr_limit)
18000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18001+void __set_fs(mm_segment_t x);
18002+void set_fs(mm_segment_t x);
18003+#else
18004 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18005+#endif
18006
18007 #define segment_eq(a, b) ((a).seg == (b).seg)
18008
18009@@ -77,8 +83,33 @@
18010 * checks that the pointer is in the user space range - after calling
18011 * this function, memory access functions may still return -EFAULT.
18012 */
18013-#define access_ok(type, addr, size) \
18014- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18015+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18016+#define access_ok(type, addr, size) \
18017+({ \
18018+ long __size = size; \
18019+ unsigned long __addr = (unsigned long)addr; \
18020+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18021+ unsigned long __end_ao = __addr + __size - 1; \
18022+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18023+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18024+ while(__addr_ao <= __end_ao) { \
18025+ char __c_ao; \
18026+ __addr_ao += PAGE_SIZE; \
18027+ if (__size > PAGE_SIZE) \
18028+ cond_resched(); \
18029+ if (__get_user(__c_ao, (char __user *)__addr)) \
18030+ break; \
18031+ if (type != VERIFY_WRITE) { \
18032+ __addr = __addr_ao; \
18033+ continue; \
18034+ } \
18035+ if (__put_user(__c_ao, (char __user *)__addr)) \
18036+ break; \
18037+ __addr = __addr_ao; \
18038+ } \
18039+ } \
18040+ __ret_ao; \
18041+})
18042
18043 /*
18044 * The exception table consists of pairs of addresses relative to the
18045@@ -168,10 +199,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18046 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18047 __chk_user_ptr(ptr); \
18048 might_fault(); \
18049+ pax_open_userland(); \
18050 asm volatile("call __get_user_%P3" \
18051 : "=a" (__ret_gu), "=r" (__val_gu) \
18052 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18053 (x) = (__typeof__(*(ptr))) __val_gu; \
18054+ pax_close_userland(); \
18055 __ret_gu; \
18056 })
18057
18058@@ -179,13 +212,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18059 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18060 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18061
18062-
18063+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18064+#define __copyuser_seg "gs;"
18065+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18066+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18067+#else
18068+#define __copyuser_seg
18069+#define __COPYUSER_SET_ES
18070+#define __COPYUSER_RESTORE_ES
18071+#endif
18072
18073 #ifdef CONFIG_X86_32
18074 #define __put_user_asm_u64(x, addr, err, errret) \
18075 asm volatile(ASM_STAC "\n" \
18076- "1: movl %%eax,0(%2)\n" \
18077- "2: movl %%edx,4(%2)\n" \
18078+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18079+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18080 "3: " ASM_CLAC "\n" \
18081 ".section .fixup,\"ax\"\n" \
18082 "4: movl %3,%0\n" \
18083@@ -198,8 +239,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18084
18085 #define __put_user_asm_ex_u64(x, addr) \
18086 asm volatile(ASM_STAC "\n" \
18087- "1: movl %%eax,0(%1)\n" \
18088- "2: movl %%edx,4(%1)\n" \
18089+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18090+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18091 "3: " ASM_CLAC "\n" \
18092 _ASM_EXTABLE_EX(1b, 2b) \
18093 _ASM_EXTABLE_EX(2b, 3b) \
18094@@ -249,7 +290,8 @@ extern void __put_user_8(void);
18095 __typeof__(*(ptr)) __pu_val; \
18096 __chk_user_ptr(ptr); \
18097 might_fault(); \
18098- __pu_val = x; \
18099+ __pu_val = (x); \
18100+ pax_open_userland(); \
18101 switch (sizeof(*(ptr))) { \
18102 case 1: \
18103 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18104@@ -267,6 +309,7 @@ extern void __put_user_8(void);
18105 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18106 break; \
18107 } \
18108+ pax_close_userland(); \
18109 __ret_pu; \
18110 })
18111
18112@@ -347,8 +390,10 @@ do { \
18113 } while (0)
18114
18115 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18116+do { \
18117+ pax_open_userland(); \
18118 asm volatile(ASM_STAC "\n" \
18119- "1: mov"itype" %2,%"rtype"1\n" \
18120+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18121 "2: " ASM_CLAC "\n" \
18122 ".section .fixup,\"ax\"\n" \
18123 "3: mov %3,%0\n" \
18124@@ -356,8 +401,10 @@ do { \
18125 " jmp 2b\n" \
18126 ".previous\n" \
18127 _ASM_EXTABLE(1b, 3b) \
18128- : "=r" (err), ltype(x) \
18129- : "m" (__m(addr)), "i" (errret), "0" (err))
18130+ : "=r" (err), ltype (x) \
18131+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18132+ pax_close_userland(); \
18133+} while (0)
18134
18135 #define __get_user_size_ex(x, ptr, size) \
18136 do { \
18137@@ -381,7 +428,7 @@ do { \
18138 } while (0)
18139
18140 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18141- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18142+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18143 "2:\n" \
18144 _ASM_EXTABLE_EX(1b, 2b) \
18145 : ltype(x) : "m" (__m(addr)))
18146@@ -398,13 +445,24 @@ do { \
18147 int __gu_err; \
18148 unsigned long __gu_val; \
18149 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18150- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18151+ (x) = (__typeof__(*(ptr)))__gu_val; \
18152 __gu_err; \
18153 })
18154
18155 /* FIXME: this hack is definitely wrong -AK */
18156 struct __large_struct { unsigned long buf[100]; };
18157-#define __m(x) (*(struct __large_struct __user *)(x))
18158+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18159+#define ____m(x) \
18160+({ \
18161+ unsigned long ____x = (unsigned long)(x); \
18162+ if (____x < pax_user_shadow_base) \
18163+ ____x += pax_user_shadow_base; \
18164+ (typeof(x))____x; \
18165+})
18166+#else
18167+#define ____m(x) (x)
18168+#endif
18169+#define __m(x) (*(struct __large_struct __user *)____m(x))
18170
18171 /*
18172 * Tell gcc we read from memory instead of writing: this is because
18173@@ -412,8 +470,10 @@ struct __large_struct { unsigned long buf[100]; };
18174 * aliasing issues.
18175 */
18176 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18177+do { \
18178+ pax_open_userland(); \
18179 asm volatile(ASM_STAC "\n" \
18180- "1: mov"itype" %"rtype"1,%2\n" \
18181+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18182 "2: " ASM_CLAC "\n" \
18183 ".section .fixup,\"ax\"\n" \
18184 "3: mov %3,%0\n" \
18185@@ -421,10 +481,12 @@ struct __large_struct { unsigned long buf[100]; };
18186 ".previous\n" \
18187 _ASM_EXTABLE(1b, 3b) \
18188 : "=r"(err) \
18189- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18190+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18191+ pax_close_userland(); \
18192+} while (0)
18193
18194 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18195- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18196+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18197 "2:\n" \
18198 _ASM_EXTABLE_EX(1b, 2b) \
18199 : : ltype(x), "m" (__m(addr)))
18200@@ -434,11 +496,13 @@ struct __large_struct { unsigned long buf[100]; };
18201 */
18202 #define uaccess_try do { \
18203 current_thread_info()->uaccess_err = 0; \
18204+ pax_open_userland(); \
18205 stac(); \
18206 barrier();
18207
18208 #define uaccess_catch(err) \
18209 clac(); \
18210+ pax_close_userland(); \
18211 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18212 } while (0)
18213
18214@@ -463,8 +527,12 @@ struct __large_struct { unsigned long buf[100]; };
18215 * On error, the variable @x is set to zero.
18216 */
18217
18218+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18219+#define __get_user(x, ptr) get_user((x), (ptr))
18220+#else
18221 #define __get_user(x, ptr) \
18222 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18223+#endif
18224
18225 /**
18226 * __put_user: - Write a simple value into user space, with less checking.
18227@@ -486,8 +554,12 @@ struct __large_struct { unsigned long buf[100]; };
18228 * Returns zero on success, or -EFAULT on error.
18229 */
18230
18231+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18232+#define __put_user(x, ptr) put_user((x), (ptr))
18233+#else
18234 #define __put_user(x, ptr) \
18235 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18236+#endif
18237
18238 #define __get_user_unaligned __get_user
18239 #define __put_user_unaligned __put_user
18240@@ -505,7 +577,7 @@ struct __large_struct { unsigned long buf[100]; };
18241 #define get_user_ex(x, ptr) do { \
18242 unsigned long __gue_val; \
18243 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18244- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18245+ (x) = (__typeof__(*(ptr)))__gue_val; \
18246 } while (0)
18247
18248 #define put_user_try uaccess_try
18249diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18250index 7f760a9..b596b9a 100644
18251--- a/arch/x86/include/asm/uaccess_32.h
18252+++ b/arch/x86/include/asm/uaccess_32.h
18253@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18254 static __always_inline unsigned long __must_check
18255 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18256 {
18257+ if ((long)n < 0)
18258+ return n;
18259+
18260+ check_object_size(from, n, true);
18261+
18262 if (__builtin_constant_p(n)) {
18263 unsigned long ret;
18264
18265@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18266 __copy_to_user(void __user *to, const void *from, unsigned long n)
18267 {
18268 might_fault();
18269+
18270 return __copy_to_user_inatomic(to, from, n);
18271 }
18272
18273 static __always_inline unsigned long
18274 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18275 {
18276+ if ((long)n < 0)
18277+ return n;
18278+
18279 /* Avoid zeroing the tail if the copy fails..
18280 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18281 * but as the zeroing behaviour is only significant when n is not
18282@@ -137,6 +146,12 @@ static __always_inline unsigned long
18283 __copy_from_user(void *to, const void __user *from, unsigned long n)
18284 {
18285 might_fault();
18286+
18287+ if ((long)n < 0)
18288+ return n;
18289+
18290+ check_object_size(to, n, false);
18291+
18292 if (__builtin_constant_p(n)) {
18293 unsigned long ret;
18294
18295@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18296 const void __user *from, unsigned long n)
18297 {
18298 might_fault();
18299+
18300+ if ((long)n < 0)
18301+ return n;
18302+
18303 if (__builtin_constant_p(n)) {
18304 unsigned long ret;
18305
18306@@ -181,15 +200,19 @@ static __always_inline unsigned long
18307 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18308 unsigned long n)
18309 {
18310- return __copy_from_user_ll_nocache_nozero(to, from, n);
18311+ if ((long)n < 0)
18312+ return n;
18313+
18314+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18315 }
18316
18317-unsigned long __must_check copy_to_user(void __user *to,
18318- const void *from, unsigned long n);
18319-unsigned long __must_check _copy_from_user(void *to,
18320- const void __user *from,
18321- unsigned long n);
18322-
18323+extern void copy_to_user_overflow(void)
18324+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18325+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18326+#else
18327+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18328+#endif
18329+;
18330
18331 extern void copy_from_user_overflow(void)
18332 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18333@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18334 #endif
18335 ;
18336
18337-static inline unsigned long __must_check copy_from_user(void *to,
18338- const void __user *from,
18339- unsigned long n)
18340+/**
18341+ * copy_to_user: - Copy a block of data into user space.
18342+ * @to: Destination address, in user space.
18343+ * @from: Source address, in kernel space.
18344+ * @n: Number of bytes to copy.
18345+ *
18346+ * Context: User context only. This function may sleep.
18347+ *
18348+ * Copy data from kernel space to user space.
18349+ *
18350+ * Returns number of bytes that could not be copied.
18351+ * On success, this will be zero.
18352+ */
18353+static inline unsigned long __must_check
18354+copy_to_user(void __user *to, const void *from, unsigned long n)
18355 {
18356- int sz = __compiletime_object_size(to);
18357+ size_t sz = __compiletime_object_size(from);
18358
18359- if (likely(sz == -1 || sz >= n))
18360- n = _copy_from_user(to, from, n);
18361- else
18362+ if (unlikely(sz != (size_t)-1 && sz < n))
18363+ copy_to_user_overflow();
18364+ else if (access_ok(VERIFY_WRITE, to, n))
18365+ n = __copy_to_user(to, from, n);
18366+ return n;
18367+}
18368+
18369+/**
18370+ * copy_from_user: - Copy a block of data from user space.
18371+ * @to: Destination address, in kernel space.
18372+ * @from: Source address, in user space.
18373+ * @n: Number of bytes to copy.
18374+ *
18375+ * Context: User context only. This function may sleep.
18376+ *
18377+ * Copy data from user space to kernel space.
18378+ *
18379+ * Returns number of bytes that could not be copied.
18380+ * On success, this will be zero.
18381+ *
18382+ * If some data could not be copied, this function will pad the copied
18383+ * data to the requested size using zero bytes.
18384+ */
18385+static inline unsigned long __must_check
18386+copy_from_user(void *to, const void __user *from, unsigned long n)
18387+{
18388+ size_t sz = __compiletime_object_size(to);
18389+
18390+ check_object_size(to, n, false);
18391+
18392+ if (unlikely(sz != (size_t)-1 && sz < n))
18393 copy_from_user_overflow();
18394-
18395+ else if (access_ok(VERIFY_READ, from, n))
18396+ n = __copy_from_user(to, from, n);
18397+ else if ((long)n > 0)
18398+ memset(to, 0, n);
18399 return n;
18400 }
18401
18402diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18403index 4f7923d..201b58d 100644
18404--- a/arch/x86/include/asm/uaccess_64.h
18405+++ b/arch/x86/include/asm/uaccess_64.h
18406@@ -10,6 +10,9 @@
18407 #include <asm/alternative.h>
18408 #include <asm/cpufeature.h>
18409 #include <asm/page.h>
18410+#include <asm/pgtable.h>
18411+
18412+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18413
18414 /*
18415 * Copy To/From Userspace
18416@@ -17,14 +20,14 @@
18417
18418 /* Handles exceptions in both to and from, but doesn't do access_ok */
18419 __must_check unsigned long
18420-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18421+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18422 __must_check unsigned long
18423-copy_user_generic_string(void *to, const void *from, unsigned len);
18424+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18425 __must_check unsigned long
18426-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18427+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18428
18429-static __always_inline __must_check unsigned long
18430-copy_user_generic(void *to, const void *from, unsigned len)
18431+static __always_inline __must_check unsigned long
18432+copy_user_generic(void *to, const void *from, unsigned long len)
18433 {
18434 unsigned ret;
18435
18436@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
18437 return ret;
18438 }
18439
18440+static __always_inline __must_check unsigned long
18441+__copy_to_user(void __user *to, const void *from, unsigned long len);
18442+static __always_inline __must_check unsigned long
18443+__copy_from_user(void *to, const void __user *from, unsigned long len);
18444 __must_check unsigned long
18445-_copy_to_user(void __user *to, const void *from, unsigned len);
18446-__must_check unsigned long
18447-_copy_from_user(void *to, const void __user *from, unsigned len);
18448-__must_check unsigned long
18449-copy_in_user(void __user *to, const void __user *from, unsigned len);
18450+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18451+
18452+extern void copy_to_user_overflow(void)
18453+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18454+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18455+#else
18456+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18457+#endif
18458+;
18459+
18460+extern void copy_from_user_overflow(void)
18461+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18462+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18463+#else
18464+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18465+#endif
18466+;
18467
18468 static inline unsigned long __must_check copy_from_user(void *to,
18469 const void __user *from,
18470 unsigned long n)
18471 {
18472- int sz = __compiletime_object_size(to);
18473-
18474 might_fault();
18475- if (likely(sz == -1 || sz >= n))
18476- n = _copy_from_user(to, from, n);
18477-#ifdef CONFIG_DEBUG_VM
18478- else
18479- WARN(1, "Buffer overflow detected!\n");
18480-#endif
18481+
18482+ check_object_size(to, n, false);
18483+
18484+ if (access_ok(VERIFY_READ, from, n))
18485+ n = __copy_from_user(to, from, n);
18486+ else if (n < INT_MAX)
18487+ memset(to, 0, n);
18488 return n;
18489 }
18490
18491 static __always_inline __must_check
18492-int copy_to_user(void __user *dst, const void *src, unsigned size)
18493+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18494 {
18495 might_fault();
18496
18497- return _copy_to_user(dst, src, size);
18498+ if (access_ok(VERIFY_WRITE, dst, size))
18499+ size = __copy_to_user(dst, src, size);
18500+ return size;
18501 }
18502
18503 static __always_inline __must_check
18504-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18505+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18506 {
18507- int ret = 0;
18508+ size_t sz = __compiletime_object_size(dst);
18509+ unsigned ret = 0;
18510
18511 might_fault();
18512+
18513+ if (size > INT_MAX)
18514+ return size;
18515+
18516+ check_object_size(dst, size, false);
18517+
18518+#ifdef CONFIG_PAX_MEMORY_UDEREF
18519+ if (!__access_ok(VERIFY_READ, src, size))
18520+ return size;
18521+#endif
18522+
18523+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18524+ copy_from_user_overflow();
18525+ return size;
18526+ }
18527+
18528 if (!__builtin_constant_p(size))
18529- return copy_user_generic(dst, (__force void *)src, size);
18530+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18531 switch (size) {
18532- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18533+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18534 ret, "b", "b", "=q", 1);
18535 return ret;
18536- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18537+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18538 ret, "w", "w", "=r", 2);
18539 return ret;
18540- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18541+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18542 ret, "l", "k", "=r", 4);
18543 return ret;
18544- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18545+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18546 ret, "q", "", "=r", 8);
18547 return ret;
18548 case 10:
18549- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18550+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18551 ret, "q", "", "=r", 10);
18552 if (unlikely(ret))
18553 return ret;
18554 __get_user_asm(*(u16 *)(8 + (char *)dst),
18555- (u16 __user *)(8 + (char __user *)src),
18556+ (const u16 __user *)(8 + (const char __user *)src),
18557 ret, "w", "w", "=r", 2);
18558 return ret;
18559 case 16:
18560- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18561+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18562 ret, "q", "", "=r", 16);
18563 if (unlikely(ret))
18564 return ret;
18565 __get_user_asm(*(u64 *)(8 + (char *)dst),
18566- (u64 __user *)(8 + (char __user *)src),
18567+ (const u64 __user *)(8 + (const char __user *)src),
18568 ret, "q", "", "=r", 8);
18569 return ret;
18570 default:
18571- return copy_user_generic(dst, (__force void *)src, size);
18572+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18573 }
18574 }
18575
18576 static __always_inline __must_check
18577-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18578+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18579 {
18580- int ret = 0;
18581+ size_t sz = __compiletime_object_size(src);
18582+ unsigned ret = 0;
18583
18584 might_fault();
18585+
18586+ if (size > INT_MAX)
18587+ return size;
18588+
18589+ check_object_size(src, size, true);
18590+
18591+#ifdef CONFIG_PAX_MEMORY_UDEREF
18592+ if (!__access_ok(VERIFY_WRITE, dst, size))
18593+ return size;
18594+#endif
18595+
18596+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18597+ copy_to_user_overflow();
18598+ return size;
18599+ }
18600+
18601 if (!__builtin_constant_p(size))
18602- return copy_user_generic((__force void *)dst, src, size);
18603+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18604 switch (size) {
18605- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18606+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18607 ret, "b", "b", "iq", 1);
18608 return ret;
18609- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18610+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18611 ret, "w", "w", "ir", 2);
18612 return ret;
18613- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18614+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18615 ret, "l", "k", "ir", 4);
18616 return ret;
18617- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18618+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18619 ret, "q", "", "er", 8);
18620 return ret;
18621 case 10:
18622- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18623+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18624 ret, "q", "", "er", 10);
18625 if (unlikely(ret))
18626 return ret;
18627 asm("":::"memory");
18628- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18629+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18630 ret, "w", "w", "ir", 2);
18631 return ret;
18632 case 16:
18633- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18634+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18635 ret, "q", "", "er", 16);
18636 if (unlikely(ret))
18637 return ret;
18638 asm("":::"memory");
18639- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18640+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18641 ret, "q", "", "er", 8);
18642 return ret;
18643 default:
18644- return copy_user_generic((__force void *)dst, src, size);
18645+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18646 }
18647 }
18648
18649 static __always_inline __must_check
18650-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18651+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18652 {
18653- int ret = 0;
18654+ unsigned ret = 0;
18655
18656 might_fault();
18657+
18658+ if (size > INT_MAX)
18659+ return size;
18660+
18661+#ifdef CONFIG_PAX_MEMORY_UDEREF
18662+ if (!__access_ok(VERIFY_READ, src, size))
18663+ return size;
18664+ if (!__access_ok(VERIFY_WRITE, dst, size))
18665+ return size;
18666+#endif
18667+
18668 if (!__builtin_constant_p(size))
18669- return copy_user_generic((__force void *)dst,
18670- (__force void *)src, size);
18671+ return copy_user_generic((__force_kernel void *)____m(dst),
18672+ (__force_kernel const void *)____m(src), size);
18673 switch (size) {
18674 case 1: {
18675 u8 tmp;
18676- __get_user_asm(tmp, (u8 __user *)src,
18677+ __get_user_asm(tmp, (const u8 __user *)src,
18678 ret, "b", "b", "=q", 1);
18679 if (likely(!ret))
18680 __put_user_asm(tmp, (u8 __user *)dst,
18681@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18682 }
18683 case 2: {
18684 u16 tmp;
18685- __get_user_asm(tmp, (u16 __user *)src,
18686+ __get_user_asm(tmp, (const u16 __user *)src,
18687 ret, "w", "w", "=r", 2);
18688 if (likely(!ret))
18689 __put_user_asm(tmp, (u16 __user *)dst,
18690@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18691
18692 case 4: {
18693 u32 tmp;
18694- __get_user_asm(tmp, (u32 __user *)src,
18695+ __get_user_asm(tmp, (const u32 __user *)src,
18696 ret, "l", "k", "=r", 4);
18697 if (likely(!ret))
18698 __put_user_asm(tmp, (u32 __user *)dst,
18699@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18700 }
18701 case 8: {
18702 u64 tmp;
18703- __get_user_asm(tmp, (u64 __user *)src,
18704+ __get_user_asm(tmp, (const u64 __user *)src,
18705 ret, "q", "", "=r", 8);
18706 if (likely(!ret))
18707 __put_user_asm(tmp, (u64 __user *)dst,
18708@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18709 return ret;
18710 }
18711 default:
18712- return copy_user_generic((__force void *)dst,
18713- (__force void *)src, size);
18714+ return copy_user_generic((__force_kernel void *)____m(dst),
18715+ (__force_kernel const void *)____m(src), size);
18716 }
18717 }
18718
18719-static __must_check __always_inline int
18720-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18721+static __must_check __always_inline unsigned long
18722+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18723 {
18724- return copy_user_generic(dst, (__force const void *)src, size);
18725+ if (size > INT_MAX)
18726+ return size;
18727+
18728+#ifdef CONFIG_PAX_MEMORY_UDEREF
18729+ if (!__access_ok(VERIFY_READ, src, size))
18730+ return size;
18731+#endif
18732+
18733+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18734 }
18735
18736-static __must_check __always_inline int
18737-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18738+static __must_check __always_inline unsigned long
18739+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18740 {
18741- return copy_user_generic((__force void *)dst, src, size);
18742+ if (size > INT_MAX)
18743+ return size;
18744+
18745+#ifdef CONFIG_PAX_MEMORY_UDEREF
18746+ if (!__access_ok(VERIFY_WRITE, dst, size))
18747+ return size;
18748+#endif
18749+
18750+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18751 }
18752
18753-extern long __copy_user_nocache(void *dst, const void __user *src,
18754- unsigned size, int zerorest);
18755+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18756+ unsigned long size, int zerorest);
18757
18758-static inline int
18759-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18760+static inline unsigned long
18761+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18762 {
18763 might_fault();
18764+
18765+ if (size > INT_MAX)
18766+ return size;
18767+
18768+#ifdef CONFIG_PAX_MEMORY_UDEREF
18769+ if (!__access_ok(VERIFY_READ, src, size))
18770+ return size;
18771+#endif
18772+
18773 return __copy_user_nocache(dst, src, size, 1);
18774 }
18775
18776-static inline int
18777+static inline unsigned long
18778 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18779- unsigned size)
18780+ unsigned long size)
18781 {
18782+ if (size > INT_MAX)
18783+ return size;
18784+
18785+#ifdef CONFIG_PAX_MEMORY_UDEREF
18786+ if (!__access_ok(VERIFY_READ, src, size))
18787+ return size;
18788+#endif
18789+
18790 return __copy_user_nocache(dst, src, size, 0);
18791 }
18792
18793 unsigned long
18794-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18795+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18796
18797 #endif /* _ASM_X86_UACCESS_64_H */
18798diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18799index 5b238981..77fdd78 100644
18800--- a/arch/x86/include/asm/word-at-a-time.h
18801+++ b/arch/x86/include/asm/word-at-a-time.h
18802@@ -11,7 +11,7 @@
18803 * and shift, for example.
18804 */
18805 struct word_at_a_time {
18806- const unsigned long one_bits, high_bits;
18807+ unsigned long one_bits, high_bits;
18808 };
18809
18810 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18811diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18812index 828a156..650e625 100644
18813--- a/arch/x86/include/asm/x86_init.h
18814+++ b/arch/x86/include/asm/x86_init.h
18815@@ -129,7 +129,7 @@ struct x86_init_ops {
18816 struct x86_init_timers timers;
18817 struct x86_init_iommu iommu;
18818 struct x86_init_pci pci;
18819-};
18820+} __no_const;
18821
18822 /**
18823 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18824@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18825 void (*setup_percpu_clockev)(void);
18826 void (*early_percpu_clock_init)(void);
18827 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18828-};
18829+} __no_const;
18830
18831 struct timespec;
18832
18833@@ -168,7 +168,7 @@ struct x86_platform_ops {
18834 void (*save_sched_clock_state)(void);
18835 void (*restore_sched_clock_state)(void);
18836 void (*apic_post_init)(void);
18837-};
18838+} __no_const;
18839
18840 struct pci_dev;
18841 struct msi_msg;
18842@@ -182,7 +182,7 @@ struct x86_msi_ops {
18843 void (*teardown_msi_irqs)(struct pci_dev *dev);
18844 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18845 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18846-};
18847+} __no_const;
18848
18849 struct IO_APIC_route_entry;
18850 struct io_apic_irq_attr;
18851@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18852 unsigned int destination, int vector,
18853 struct io_apic_irq_attr *attr);
18854 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18855-};
18856+} __no_const;
18857
18858 extern struct x86_init_ops x86_init;
18859 extern struct x86_cpuinit_ops x86_cpuinit;
18860diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
18861index b913915..4f5a581 100644
18862--- a/arch/x86/include/asm/xen/page.h
18863+++ b/arch/x86/include/asm/xen/page.h
18864@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
18865 extern struct page *m2p_find_override(unsigned long mfn);
18866 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
18867
18868-static inline unsigned long pfn_to_mfn(unsigned long pfn)
18869+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
18870 {
18871 unsigned long mfn;
18872
18873diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18874index 0415cda..3b22adc 100644
18875--- a/arch/x86/include/asm/xsave.h
18876+++ b/arch/x86/include/asm/xsave.h
18877@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18878 if (unlikely(err))
18879 return -EFAULT;
18880
18881+ pax_open_userland();
18882 __asm__ __volatile__(ASM_STAC "\n"
18883- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18884+ "1:"
18885+ __copyuser_seg
18886+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18887 "2: " ASM_CLAC "\n"
18888 ".section .fixup,\"ax\"\n"
18889 "3: movl $-1,%[err]\n"
18890@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18891 : [err] "=r" (err)
18892 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18893 : "memory");
18894+ pax_close_userland();
18895 return err;
18896 }
18897
18898 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18899 {
18900 int err;
18901- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18902+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18903 u32 lmask = mask;
18904 u32 hmask = mask >> 32;
18905
18906+ pax_open_userland();
18907 __asm__ __volatile__(ASM_STAC "\n"
18908- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18909+ "1:"
18910+ __copyuser_seg
18911+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18912 "2: " ASM_CLAC "\n"
18913 ".section .fixup,\"ax\"\n"
18914 "3: movl $-1,%[err]\n"
18915@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18916 : [err] "=r" (err)
18917 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18918 : "memory"); /* memory required? */
18919+ pax_close_userland();
18920 return err;
18921 }
18922
18923diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18924index bbae024..e1528f9 100644
18925--- a/arch/x86/include/uapi/asm/e820.h
18926+++ b/arch/x86/include/uapi/asm/e820.h
18927@@ -63,7 +63,7 @@ struct e820map {
18928 #define ISA_START_ADDRESS 0xa0000
18929 #define ISA_END_ADDRESS 0x100000
18930
18931-#define BIOS_BEGIN 0x000a0000
18932+#define BIOS_BEGIN 0x000c0000
18933 #define BIOS_END 0x00100000
18934
18935 #define BIOS_ROM_BASE 0xffe00000
18936diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18937index a5408b9..5133813 100644
18938--- a/arch/x86/kernel/Makefile
18939+++ b/arch/x86/kernel/Makefile
18940@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18941 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18942 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18943 obj-y += probe_roms.o
18944-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18945+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18946 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18947 obj-y += syscall_$(BITS).o
18948 obj-$(CONFIG_X86_64) += vsyscall_64.o
18949diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18950index 40c7660..f709f4b 100644
18951--- a/arch/x86/kernel/acpi/boot.c
18952+++ b/arch/x86/kernel/acpi/boot.c
18953@@ -1365,7 +1365,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18954 * If your system is blacklisted here, but you find that acpi=force
18955 * works for you, please contact linux-acpi@vger.kernel.org
18956 */
18957-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18958+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18959 /*
18960 * Boxes that need ACPI disabled
18961 */
18962@@ -1440,7 +1440,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18963 };
18964
18965 /* second table for DMI checks that should run after early-quirks */
18966-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18967+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18968 /*
18969 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18970 * which includes some code which overrides all temperature
18971diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18972index 3312010..a65ca7b 100644
18973--- a/arch/x86/kernel/acpi/sleep.c
18974+++ b/arch/x86/kernel/acpi/sleep.c
18975@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18976 #else /* CONFIG_64BIT */
18977 #ifdef CONFIG_SMP
18978 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18979+
18980+ pax_open_kernel();
18981 early_gdt_descr.address =
18982 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18983+ pax_close_kernel();
18984+
18985 initial_gs = per_cpu_offset(smp_processor_id());
18986 #endif
18987 initial_code = (unsigned long)wakeup_long64;
18988diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18989index d1daa66..59fecba 100644
18990--- a/arch/x86/kernel/acpi/wakeup_32.S
18991+++ b/arch/x86/kernel/acpi/wakeup_32.S
18992@@ -29,13 +29,11 @@ wakeup_pmode_return:
18993 # and restore the stack ... but you need gdt for this to work
18994 movl saved_context_esp, %esp
18995
18996- movl %cs:saved_magic, %eax
18997- cmpl $0x12345678, %eax
18998+ cmpl $0x12345678, saved_magic
18999 jne bogus_magic
19000
19001 # jump to place where we left off
19002- movl saved_eip, %eax
19003- jmp *%eax
19004+ jmp *(saved_eip)
19005
19006 bogus_magic:
19007 jmp bogus_magic
19008diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19009index 15e8563..323cbe1 100644
19010--- a/arch/x86/kernel/alternative.c
19011+++ b/arch/x86/kernel/alternative.c
19012@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19013 */
19014 for (a = start; a < end; a++) {
19015 instr = (u8 *)&a->instr_offset + a->instr_offset;
19016+
19017+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19018+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19019+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19020+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19021+#endif
19022+
19023 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19024 BUG_ON(a->replacementlen > a->instrlen);
19025 BUG_ON(a->instrlen > sizeof(insnbuf));
19026@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19027 for (poff = start; poff < end; poff++) {
19028 u8 *ptr = (u8 *)poff + *poff;
19029
19030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19031+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19032+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19033+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19034+#endif
19035+
19036 if (!*poff || ptr < text || ptr >= text_end)
19037 continue;
19038 /* turn DS segment override prefix into lock prefix */
19039- if (*ptr == 0x3e)
19040+ if (*ktla_ktva(ptr) == 0x3e)
19041 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19042 }
19043 mutex_unlock(&text_mutex);
19044@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19045 for (poff = start; poff < end; poff++) {
19046 u8 *ptr = (u8 *)poff + *poff;
19047
19048+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19049+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19050+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19051+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19052+#endif
19053+
19054 if (!*poff || ptr < text || ptr >= text_end)
19055 continue;
19056 /* turn lock prefix into DS segment override prefix */
19057- if (*ptr == 0xf0)
19058+ if (*ktla_ktva(ptr) == 0xf0)
19059 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19060 }
19061 mutex_unlock(&text_mutex);
19062@@ -469,7 +488,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19063
19064 BUG_ON(p->len > MAX_PATCH_LEN);
19065 /* prep the buffer with the original instructions */
19066- memcpy(insnbuf, p->instr, p->len);
19067+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19068 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19069 (unsigned long)p->instr, p->len);
19070
19071@@ -516,7 +535,7 @@ void __init alternative_instructions(void)
19072 if (!uniproc_patched || num_possible_cpus() == 1)
19073 free_init_pages("SMP alternatives",
19074 (unsigned long)__smp_locks,
19075- (unsigned long)__smp_locks_end);
19076+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19077 #endif
19078
19079 apply_paravirt(__parainstructions, __parainstructions_end);
19080@@ -536,13 +555,17 @@ void __init alternative_instructions(void)
19081 * instructions. And on the local CPU you need to be protected again NMI or MCE
19082 * handlers seeing an inconsistent instruction while you patch.
19083 */
19084-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19085+void *__kprobes text_poke_early(void *addr, const void *opcode,
19086 size_t len)
19087 {
19088 unsigned long flags;
19089 local_irq_save(flags);
19090- memcpy(addr, opcode, len);
19091+
19092+ pax_open_kernel();
19093+ memcpy(ktla_ktva(addr), opcode, len);
19094 sync_core();
19095+ pax_close_kernel();
19096+
19097 local_irq_restore(flags);
19098 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19099 that causes hangs on some VIA CPUs. */
19100@@ -564,36 +587,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19101 */
19102 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19103 {
19104- unsigned long flags;
19105- char *vaddr;
19106+ unsigned char *vaddr = ktla_ktva(addr);
19107 struct page *pages[2];
19108- int i;
19109+ size_t i;
19110
19111 if (!core_kernel_text((unsigned long)addr)) {
19112- pages[0] = vmalloc_to_page(addr);
19113- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19114+ pages[0] = vmalloc_to_page(vaddr);
19115+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19116 } else {
19117- pages[0] = virt_to_page(addr);
19118+ pages[0] = virt_to_page(vaddr);
19119 WARN_ON(!PageReserved(pages[0]));
19120- pages[1] = virt_to_page(addr + PAGE_SIZE);
19121+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19122 }
19123 BUG_ON(!pages[0]);
19124- local_irq_save(flags);
19125- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19126- if (pages[1])
19127- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19128- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19129- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19130- clear_fixmap(FIX_TEXT_POKE0);
19131- if (pages[1])
19132- clear_fixmap(FIX_TEXT_POKE1);
19133- local_flush_tlb();
19134- sync_core();
19135- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19136- that causes hangs on some VIA CPUs. */
19137+ text_poke_early(addr, opcode, len);
19138 for (i = 0; i < len; i++)
19139- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19140- local_irq_restore(flags);
19141+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19142 return addr;
19143 }
19144
19145@@ -613,7 +622,7 @@ int poke_int3_handler(struct pt_regs *regs)
19146 if (likely(!bp_patching_in_progress))
19147 return 0;
19148
19149- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19150+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19151 return 0;
19152
19153 /* set up the specified breakpoint handler */
19154@@ -647,7 +656,7 @@ int poke_int3_handler(struct pt_regs *regs)
19155 */
19156 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19157 {
19158- unsigned char int3 = 0xcc;
19159+ const unsigned char int3 = 0xcc;
19160
19161 bp_int3_handler = handler;
19162 bp_int3_addr = (u8 *)addr + sizeof(int3);
19163diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19164index a7eb82d..f6e52d4 100644
19165--- a/arch/x86/kernel/apic/apic.c
19166+++ b/arch/x86/kernel/apic/apic.c
19167@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19168 /*
19169 * Debug level, exported for io_apic.c
19170 */
19171-unsigned int apic_verbosity;
19172+int apic_verbosity;
19173
19174 int pic_mode;
19175
19176@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19177 apic_write(APIC_ESR, 0);
19178 v1 = apic_read(APIC_ESR);
19179 ack_APIC_irq();
19180- atomic_inc(&irq_err_count);
19181+ atomic_inc_unchecked(&irq_err_count);
19182
19183 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19184 smp_processor_id(), v0 , v1);
19185diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19186index 00c77cf..2dc6a2d 100644
19187--- a/arch/x86/kernel/apic/apic_flat_64.c
19188+++ b/arch/x86/kernel/apic/apic_flat_64.c
19189@@ -157,7 +157,7 @@ static int flat_probe(void)
19190 return 1;
19191 }
19192
19193-static struct apic apic_flat = {
19194+static struct apic apic_flat __read_only = {
19195 .name = "flat",
19196 .probe = flat_probe,
19197 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19198@@ -271,7 +271,7 @@ static int physflat_probe(void)
19199 return 0;
19200 }
19201
19202-static struct apic apic_physflat = {
19203+static struct apic apic_physflat __read_only = {
19204
19205 .name = "physical flat",
19206 .probe = physflat_probe,
19207diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19208index e145f28..2752888 100644
19209--- a/arch/x86/kernel/apic/apic_noop.c
19210+++ b/arch/x86/kernel/apic/apic_noop.c
19211@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19212 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19213 }
19214
19215-struct apic apic_noop = {
19216+struct apic apic_noop __read_only = {
19217 .name = "noop",
19218 .probe = noop_probe,
19219 .acpi_madt_oem_check = NULL,
19220diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19221index d50e364..543bee3 100644
19222--- a/arch/x86/kernel/apic/bigsmp_32.c
19223+++ b/arch/x86/kernel/apic/bigsmp_32.c
19224@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19225 return dmi_bigsmp;
19226 }
19227
19228-static struct apic apic_bigsmp = {
19229+static struct apic apic_bigsmp __read_only = {
19230
19231 .name = "bigsmp",
19232 .probe = probe_bigsmp,
19233diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19234index c552247..587a316 100644
19235--- a/arch/x86/kernel/apic/es7000_32.c
19236+++ b/arch/x86/kernel/apic/es7000_32.c
19237@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19238 return ret && es7000_apic_is_cluster();
19239 }
19240
19241-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19242-static struct apic __refdata apic_es7000_cluster = {
19243+static struct apic apic_es7000_cluster __read_only = {
19244
19245 .name = "es7000",
19246 .probe = probe_es7000,
19247@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19248 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19249 };
19250
19251-static struct apic __refdata apic_es7000 = {
19252+static struct apic apic_es7000 __read_only = {
19253
19254 .name = "es7000",
19255 .probe = probe_es7000,
19256diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19257index e63a5bd..c0babf8 100644
19258--- a/arch/x86/kernel/apic/io_apic.c
19259+++ b/arch/x86/kernel/apic/io_apic.c
19260@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19261 }
19262 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19263
19264-void lock_vector_lock(void)
19265+void lock_vector_lock(void) __acquires(vector_lock)
19266 {
19267 /* Used to the online set of cpus does not change
19268 * during assign_irq_vector.
19269@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19270 raw_spin_lock(&vector_lock);
19271 }
19272
19273-void unlock_vector_lock(void)
19274+void unlock_vector_lock(void) __releases(vector_lock)
19275 {
19276 raw_spin_unlock(&vector_lock);
19277 }
19278@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
19279 ack_APIC_irq();
19280 }
19281
19282-atomic_t irq_mis_count;
19283+atomic_unchecked_t irq_mis_count;
19284
19285 #ifdef CONFIG_GENERIC_PENDING_IRQ
19286 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19287@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
19288 * at the cpu.
19289 */
19290 if (!(v & (1 << (i & 0x1f)))) {
19291- atomic_inc(&irq_mis_count);
19292+ atomic_inc_unchecked(&irq_mis_count);
19293
19294 eoi_ioapic_irq(irq, cfg);
19295 }
19296diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19297index 1e42e8f..daacf44 100644
19298--- a/arch/x86/kernel/apic/numaq_32.c
19299+++ b/arch/x86/kernel/apic/numaq_32.c
19300@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19301 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19302 }
19303
19304-/* Use __refdata to keep false positive warning calm. */
19305-static struct apic __refdata apic_numaq = {
19306+static struct apic apic_numaq __read_only = {
19307
19308 .name = "NUMAQ",
19309 .probe = probe_numaq,
19310diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19311index eb35ef9..f184a21 100644
19312--- a/arch/x86/kernel/apic/probe_32.c
19313+++ b/arch/x86/kernel/apic/probe_32.c
19314@@ -72,7 +72,7 @@ static int probe_default(void)
19315 return 1;
19316 }
19317
19318-static struct apic apic_default = {
19319+static struct apic apic_default __read_only = {
19320
19321 .name = "default",
19322 .probe = probe_default,
19323diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19324index 77c95c0..434f8a4 100644
19325--- a/arch/x86/kernel/apic/summit_32.c
19326+++ b/arch/x86/kernel/apic/summit_32.c
19327@@ -486,7 +486,7 @@ void setup_summit(void)
19328 }
19329 #endif
19330
19331-static struct apic apic_summit = {
19332+static struct apic apic_summit __read_only = {
19333
19334 .name = "summit",
19335 .probe = probe_summit,
19336diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19337index 140e29d..d88bc95 100644
19338--- a/arch/x86/kernel/apic/x2apic_cluster.c
19339+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19340@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19341 return notifier_from_errno(err);
19342 }
19343
19344-static struct notifier_block __refdata x2apic_cpu_notifier = {
19345+static struct notifier_block x2apic_cpu_notifier = {
19346 .notifier_call = update_clusterinfo,
19347 };
19348
19349@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19350 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19351 }
19352
19353-static struct apic apic_x2apic_cluster = {
19354+static struct apic apic_x2apic_cluster __read_only = {
19355
19356 .name = "cluster x2apic",
19357 .probe = x2apic_cluster_probe,
19358diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19359index 562a76d..a003c0f 100644
19360--- a/arch/x86/kernel/apic/x2apic_phys.c
19361+++ b/arch/x86/kernel/apic/x2apic_phys.c
19362@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19363 return apic == &apic_x2apic_phys;
19364 }
19365
19366-static struct apic apic_x2apic_phys = {
19367+static struct apic apic_x2apic_phys __read_only = {
19368
19369 .name = "physical x2apic",
19370 .probe = x2apic_phys_probe,
19371diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19372index a419814..1dd34a0 100644
19373--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19374+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19375@@ -357,7 +357,7 @@ static int uv_probe(void)
19376 return apic == &apic_x2apic_uv_x;
19377 }
19378
19379-static struct apic __refdata apic_x2apic_uv_x = {
19380+static struct apic apic_x2apic_uv_x __read_only = {
19381
19382 .name = "UV large system",
19383 .probe = uv_probe,
19384diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19385index 3ab0343..814c4787 100644
19386--- a/arch/x86/kernel/apm_32.c
19387+++ b/arch/x86/kernel/apm_32.c
19388@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19389 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19390 * even though they are called in protected mode.
19391 */
19392-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19393+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19394 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19395
19396 static const char driver_version[] = "1.16ac"; /* no spaces */
19397@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19398 BUG_ON(cpu != 0);
19399 gdt = get_cpu_gdt_table(cpu);
19400 save_desc_40 = gdt[0x40 / 8];
19401+
19402+ pax_open_kernel();
19403 gdt[0x40 / 8] = bad_bios_desc;
19404+ pax_close_kernel();
19405
19406 apm_irq_save(flags);
19407 APM_DO_SAVE_SEGS;
19408@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19409 &call->esi);
19410 APM_DO_RESTORE_SEGS;
19411 apm_irq_restore(flags);
19412+
19413+ pax_open_kernel();
19414 gdt[0x40 / 8] = save_desc_40;
19415+ pax_close_kernel();
19416+
19417 put_cpu();
19418
19419 return call->eax & 0xff;
19420@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19421 BUG_ON(cpu != 0);
19422 gdt = get_cpu_gdt_table(cpu);
19423 save_desc_40 = gdt[0x40 / 8];
19424+
19425+ pax_open_kernel();
19426 gdt[0x40 / 8] = bad_bios_desc;
19427+ pax_close_kernel();
19428
19429 apm_irq_save(flags);
19430 APM_DO_SAVE_SEGS;
19431@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19432 &call->eax);
19433 APM_DO_RESTORE_SEGS;
19434 apm_irq_restore(flags);
19435+
19436+ pax_open_kernel();
19437 gdt[0x40 / 8] = save_desc_40;
19438+ pax_close_kernel();
19439+
19440 put_cpu();
19441 return error;
19442 }
19443@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19444 * code to that CPU.
19445 */
19446 gdt = get_cpu_gdt_table(0);
19447+
19448+ pax_open_kernel();
19449 set_desc_base(&gdt[APM_CS >> 3],
19450 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19451 set_desc_base(&gdt[APM_CS_16 >> 3],
19452 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19453 set_desc_base(&gdt[APM_DS >> 3],
19454 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19455+ pax_close_kernel();
19456
19457 proc_create("apm", 0, NULL, &apm_file_ops);
19458
19459diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19460index 2861082..6d4718e 100644
19461--- a/arch/x86/kernel/asm-offsets.c
19462+++ b/arch/x86/kernel/asm-offsets.c
19463@@ -33,6 +33,8 @@ void common(void) {
19464 OFFSET(TI_status, thread_info, status);
19465 OFFSET(TI_addr_limit, thread_info, addr_limit);
19466 OFFSET(TI_preempt_count, thread_info, preempt_count);
19467+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19468+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19469
19470 BLANK();
19471 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19472@@ -53,8 +55,26 @@ void common(void) {
19473 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19474 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19475 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19476+
19477+#ifdef CONFIG_PAX_KERNEXEC
19478+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19479 #endif
19480
19481+#ifdef CONFIG_PAX_MEMORY_UDEREF
19482+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19483+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19484+#ifdef CONFIG_X86_64
19485+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19486+#endif
19487+#endif
19488+
19489+#endif
19490+
19491+ BLANK();
19492+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19493+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19494+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19495+
19496 #ifdef CONFIG_XEN
19497 BLANK();
19498 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19499diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19500index e7c798b..2b2019b 100644
19501--- a/arch/x86/kernel/asm-offsets_64.c
19502+++ b/arch/x86/kernel/asm-offsets_64.c
19503@@ -77,6 +77,7 @@ int main(void)
19504 BLANK();
19505 #undef ENTRY
19506
19507+ DEFINE(TSS_size, sizeof(struct tss_struct));
19508 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19509 BLANK();
19510
19511diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19512index 47b56a7..efc2bc6 100644
19513--- a/arch/x86/kernel/cpu/Makefile
19514+++ b/arch/x86/kernel/cpu/Makefile
19515@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19516 CFLAGS_REMOVE_perf_event.o = -pg
19517 endif
19518
19519-# Make sure load_percpu_segment has no stackprotector
19520-nostackp := $(call cc-option, -fno-stack-protector)
19521-CFLAGS_common.o := $(nostackp)
19522-
19523 obj-y := intel_cacheinfo.o scattered.o topology.o
19524 obj-y += proc.o capflags.o powerflags.o common.o
19525 obj-y += rdrand.o
19526diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19527index 903a264..fc955f3 100644
19528--- a/arch/x86/kernel/cpu/amd.c
19529+++ b/arch/x86/kernel/cpu/amd.c
19530@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19531 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19532 {
19533 /* AMD errata T13 (order #21922) */
19534- if ((c->x86 == 6)) {
19535+ if (c->x86 == 6) {
19536 /* Duron Rev A0 */
19537 if (c->x86_model == 3 && c->x86_mask == 0)
19538 size = 64;
19539diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19540index 2793d1f..5c04a30 100644
19541--- a/arch/x86/kernel/cpu/common.c
19542+++ b/arch/x86/kernel/cpu/common.c
19543@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19544
19545 static const struct cpu_dev *this_cpu = &default_cpu;
19546
19547-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19548-#ifdef CONFIG_X86_64
19549- /*
19550- * We need valid kernel segments for data and code in long mode too
19551- * IRET will check the segment types kkeil 2000/10/28
19552- * Also sysret mandates a special GDT layout
19553- *
19554- * TLS descriptors are currently at a different place compared to i386.
19555- * Hopefully nobody expects them at a fixed place (Wine?)
19556- */
19557- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19558- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19559- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19560- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19561- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19562- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19563-#else
19564- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19565- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19566- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19567- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19568- /*
19569- * Segments used for calling PnP BIOS have byte granularity.
19570- * They code segments and data segments have fixed 64k limits,
19571- * the transfer segment sizes are set at run time.
19572- */
19573- /* 32-bit code */
19574- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19575- /* 16-bit code */
19576- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19577- /* 16-bit data */
19578- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19579- /* 16-bit data */
19580- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19581- /* 16-bit data */
19582- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19583- /*
19584- * The APM segments have byte granularity and their bases
19585- * are set at run time. All have 64k limits.
19586- */
19587- /* 32-bit code */
19588- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19589- /* 16-bit code */
19590- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19591- /* data */
19592- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19593-
19594- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19595- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19596- GDT_STACK_CANARY_INIT
19597-#endif
19598-} };
19599-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19600-
19601 static int __init x86_xsave_setup(char *s)
19602 {
19603 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19604@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19605 set_in_cr4(X86_CR4_SMAP);
19606 }
19607
19608+#ifdef CONFIG_X86_64
19609+static __init int setup_disable_pcid(char *arg)
19610+{
19611+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19612+
19613+#ifdef CONFIG_PAX_MEMORY_UDEREF
19614+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19615+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19616+#endif
19617+
19618+ return 1;
19619+}
19620+__setup("nopcid", setup_disable_pcid);
19621+
19622+static void setup_pcid(struct cpuinfo_x86 *c)
19623+{
19624+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19625+
19626+#ifdef CONFIG_PAX_MEMORY_UDEREF
19627+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19628+ pax_open_kernel();
19629+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19630+ pax_close_kernel();
19631+ printk("PAX: slow and weak UDEREF enabled\n");
19632+ } else
19633+ printk("PAX: UDEREF disabled\n");
19634+#endif
19635+
19636+ return;
19637+ }
19638+
19639+ printk("PAX: PCID detected\n");
19640+ set_in_cr4(X86_CR4_PCIDE);
19641+
19642+#ifdef CONFIG_PAX_MEMORY_UDEREF
19643+ pax_open_kernel();
19644+ clone_pgd_mask = ~(pgdval_t)0UL;
19645+ pax_close_kernel();
19646+ if (pax_user_shadow_base)
19647+ printk("PAX: weak UDEREF enabled\n");
19648+ else {
19649+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19650+ printk("PAX: strong UDEREF enabled\n");
19651+ }
19652+#endif
19653+
19654+ if (cpu_has(c, X86_FEATURE_INVPCID))
19655+ printk("PAX: INVPCID detected\n");
19656+}
19657+#endif
19658+
19659 /*
19660 * Some CPU features depend on higher CPUID levels, which may not always
19661 * be available due to CPUID level capping or broken virtualization
19662@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19663 {
19664 struct desc_ptr gdt_descr;
19665
19666- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19667+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19668 gdt_descr.size = GDT_SIZE - 1;
19669 load_gdt(&gdt_descr);
19670 /* Reload the per-cpu base */
19671@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19672 setup_smep(c);
19673 setup_smap(c);
19674
19675+#ifdef CONFIG_X86_64
19676+ setup_pcid(c);
19677+#endif
19678+
19679 /*
19680 * The vendor-specific functions might have changed features.
19681 * Now we do "generic changes."
19682@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19683 /* Filter out anything that depends on CPUID levels we don't have */
19684 filter_cpuid_features(c, true);
19685
19686+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19687+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19688+#endif
19689+
19690 /* If the model name is still unset, do table lookup. */
19691 if (!c->x86_model_id[0]) {
19692 const char *p;
19693@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19694 }
19695 __setup("clearcpuid=", setup_disablecpuid);
19696
19697+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19698+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19699+
19700 #ifdef CONFIG_X86_64
19701-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19702-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19703- (unsigned long) debug_idt_table };
19704+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19705+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19706
19707 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19708 irq_stack_union) __aligned(PAGE_SIZE) __visible;
19709@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19710 EXPORT_PER_CPU_SYMBOL(current_task);
19711
19712 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19713- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19714+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19715 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19716
19717 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19718@@ -1232,7 +1239,7 @@ void cpu_init(void)
19719 load_ucode_ap();
19720
19721 cpu = stack_smp_processor_id();
19722- t = &per_cpu(init_tss, cpu);
19723+ t = init_tss + cpu;
19724 oist = &per_cpu(orig_ist, cpu);
19725
19726 #ifdef CONFIG_NUMA
19727@@ -1267,7 +1274,6 @@ void cpu_init(void)
19728 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19729 barrier();
19730
19731- x86_configure_nx();
19732 enable_x2apic();
19733
19734 /*
19735@@ -1319,7 +1325,7 @@ void cpu_init(void)
19736 {
19737 int cpu = smp_processor_id();
19738 struct task_struct *curr = current;
19739- struct tss_struct *t = &per_cpu(init_tss, cpu);
19740+ struct tss_struct *t = init_tss + cpu;
19741 struct thread_struct *thread = &curr->thread;
19742
19743 show_ucode_info_early();
19744diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19745index 1414c90..1159406 100644
19746--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19747+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19748@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19749 };
19750
19751 #ifdef CONFIG_AMD_NB
19752+static struct attribute *default_attrs_amd_nb[] = {
19753+ &type.attr,
19754+ &level.attr,
19755+ &coherency_line_size.attr,
19756+ &physical_line_partition.attr,
19757+ &ways_of_associativity.attr,
19758+ &number_of_sets.attr,
19759+ &size.attr,
19760+ &shared_cpu_map.attr,
19761+ &shared_cpu_list.attr,
19762+ NULL,
19763+ NULL,
19764+ NULL,
19765+ NULL
19766+};
19767+
19768 static struct attribute **amd_l3_attrs(void)
19769 {
19770 static struct attribute **attrs;
19771@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19772
19773 n = ARRAY_SIZE(default_attrs);
19774
19775- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19776- n += 2;
19777-
19778- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19779- n += 1;
19780-
19781- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19782- if (attrs == NULL)
19783- return attrs = default_attrs;
19784-
19785- for (n = 0; default_attrs[n]; n++)
19786- attrs[n] = default_attrs[n];
19787+ attrs = default_attrs_amd_nb;
19788
19789 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19790 attrs[n++] = &cache_disable_0.attr;
19791@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19792 .default_attrs = default_attrs,
19793 };
19794
19795+#ifdef CONFIG_AMD_NB
19796+static struct kobj_type ktype_cache_amd_nb = {
19797+ .sysfs_ops = &sysfs_ops,
19798+ .default_attrs = default_attrs_amd_nb,
19799+};
19800+#endif
19801+
19802 static struct kobj_type ktype_percpu_entry = {
19803 .sysfs_ops = &sysfs_ops,
19804 };
19805@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19806 return retval;
19807 }
19808
19809+#ifdef CONFIG_AMD_NB
19810+ amd_l3_attrs();
19811+#endif
19812+
19813 for (i = 0; i < num_cache_leaves; i++) {
19814+ struct kobj_type *ktype;
19815+
19816 this_object = INDEX_KOBJECT_PTR(cpu, i);
19817 this_object->cpu = cpu;
19818 this_object->index = i;
19819
19820 this_leaf = CPUID4_INFO_IDX(cpu, i);
19821
19822- ktype_cache.default_attrs = default_attrs;
19823+ ktype = &ktype_cache;
19824 #ifdef CONFIG_AMD_NB
19825 if (this_leaf->base.nb)
19826- ktype_cache.default_attrs = amd_l3_attrs();
19827+ ktype = &ktype_cache_amd_nb;
19828 #endif
19829 retval = kobject_init_and_add(&(this_object->kobj),
19830- &ktype_cache,
19831+ ktype,
19832 per_cpu(ici_cache_kobject, cpu),
19833 "index%1lu", i);
19834 if (unlikely(retval)) {
19835diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19836index b3218cd..99a75de 100644
19837--- a/arch/x86/kernel/cpu/mcheck/mce.c
19838+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19839@@ -45,6 +45,7 @@
19840 #include <asm/processor.h>
19841 #include <asm/mce.h>
19842 #include <asm/msr.h>
19843+#include <asm/local.h>
19844
19845 #include "mce-internal.h"
19846
19847@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
19848 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19849 m->cs, m->ip);
19850
19851- if (m->cs == __KERNEL_CS)
19852+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19853 print_symbol("{%s}", m->ip);
19854 pr_cont("\n");
19855 }
19856@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
19857
19858 #define PANIC_TIMEOUT 5 /* 5 seconds */
19859
19860-static atomic_t mce_paniced;
19861+static atomic_unchecked_t mce_paniced;
19862
19863 static int fake_panic;
19864-static atomic_t mce_fake_paniced;
19865+static atomic_unchecked_t mce_fake_paniced;
19866
19867 /* Panic in progress. Enable interrupts and wait for final IPI */
19868 static void wait_for_panic(void)
19869@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19870 /*
19871 * Make sure only one CPU runs in machine check panic
19872 */
19873- if (atomic_inc_return(&mce_paniced) > 1)
19874+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19875 wait_for_panic();
19876 barrier();
19877
19878@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19879 console_verbose();
19880 } else {
19881 /* Don't log too much for fake panic */
19882- if (atomic_inc_return(&mce_fake_paniced) > 1)
19883+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19884 return;
19885 }
19886 /* First print corrected ones that are still unlogged */
19887@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19888 if (!fake_panic) {
19889 if (panic_timeout == 0)
19890 panic_timeout = mca_cfg.panic_timeout;
19891- panic(msg);
19892+ panic("%s", msg);
19893 } else
19894 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19895 }
19896@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
19897 * might have been modified by someone else.
19898 */
19899 rmb();
19900- if (atomic_read(&mce_paniced))
19901+ if (atomic_read_unchecked(&mce_paniced))
19902 wait_for_panic();
19903 if (!mca_cfg.monarch_timeout)
19904 goto out;
19905@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19906 }
19907
19908 /* Call the installed machine check handler for this CPU setup. */
19909-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19910+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19911 unexpected_machine_check;
19912
19913 /*
19914@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19915 return;
19916 }
19917
19918+ pax_open_kernel();
19919 machine_check_vector = do_machine_check;
19920+ pax_close_kernel();
19921
19922 __mcheck_cpu_init_generic();
19923 __mcheck_cpu_init_vendor(c);
19924@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19925 */
19926
19927 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19928-static int mce_chrdev_open_count; /* #times opened */
19929+static local_t mce_chrdev_open_count; /* #times opened */
19930 static int mce_chrdev_open_exclu; /* already open exclusive? */
19931
19932 static int mce_chrdev_open(struct inode *inode, struct file *file)
19933@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19934 spin_lock(&mce_chrdev_state_lock);
19935
19936 if (mce_chrdev_open_exclu ||
19937- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19938+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19939 spin_unlock(&mce_chrdev_state_lock);
19940
19941 return -EBUSY;
19942@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19943
19944 if (file->f_flags & O_EXCL)
19945 mce_chrdev_open_exclu = 1;
19946- mce_chrdev_open_count++;
19947+ local_inc(&mce_chrdev_open_count);
19948
19949 spin_unlock(&mce_chrdev_state_lock);
19950
19951@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19952 {
19953 spin_lock(&mce_chrdev_state_lock);
19954
19955- mce_chrdev_open_count--;
19956+ local_dec(&mce_chrdev_open_count);
19957 mce_chrdev_open_exclu = 0;
19958
19959 spin_unlock(&mce_chrdev_state_lock);
19960@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
19961
19962 for (i = 0; i < mca_cfg.banks; i++) {
19963 struct mce_bank *b = &mce_banks[i];
19964- struct device_attribute *a = &b->attr;
19965+ device_attribute_no_const *a = &b->attr;
19966
19967 sysfs_attr_init(&a->attr);
19968 a->attr.name = b->attrname;
19969@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
19970 static void mce_reset(void)
19971 {
19972 cpu_missing = 0;
19973- atomic_set(&mce_fake_paniced, 0);
19974+ atomic_set_unchecked(&mce_fake_paniced, 0);
19975 atomic_set(&mce_executing, 0);
19976 atomic_set(&mce_callin, 0);
19977 atomic_set(&global_nwo, 0);
19978diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19979index 1c044b1..37a2a43 100644
19980--- a/arch/x86/kernel/cpu/mcheck/p5.c
19981+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19982@@ -11,6 +11,7 @@
19983 #include <asm/processor.h>
19984 #include <asm/mce.h>
19985 #include <asm/msr.h>
19986+#include <asm/pgtable.h>
19987
19988 /* By default disabled */
19989 int mce_p5_enabled __read_mostly;
19990@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19991 if (!cpu_has(c, X86_FEATURE_MCE))
19992 return;
19993
19994+ pax_open_kernel();
19995 machine_check_vector = pentium_machine_check;
19996+ pax_close_kernel();
19997 /* Make sure the vector pointer is visible before we enable MCEs: */
19998 wmb();
19999
20000diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20001index e9a701a..35317d6 100644
20002--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20003+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20004@@ -10,6 +10,7 @@
20005 #include <asm/processor.h>
20006 #include <asm/mce.h>
20007 #include <asm/msr.h>
20008+#include <asm/pgtable.h>
20009
20010 /* Machine check handler for WinChip C6: */
20011 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20012@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20013 {
20014 u32 lo, hi;
20015
20016+ pax_open_kernel();
20017 machine_check_vector = winchip_machine_check;
20018+ pax_close_kernel();
20019 /* Make sure the vector pointer is visible before we enable MCEs: */
20020 wmb();
20021
20022diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20023index f961de9..8a9d332 100644
20024--- a/arch/x86/kernel/cpu/mtrr/main.c
20025+++ b/arch/x86/kernel/cpu/mtrr/main.c
20026@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20027 u64 size_or_mask, size_and_mask;
20028 static bool mtrr_aps_delayed_init;
20029
20030-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20031+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20032
20033 const struct mtrr_ops *mtrr_if;
20034
20035diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20036index df5e41f..816c719 100644
20037--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20038+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20039@@ -25,7 +25,7 @@ struct mtrr_ops {
20040 int (*validate_add_page)(unsigned long base, unsigned long size,
20041 unsigned int type);
20042 int (*have_wrcomb)(void);
20043-};
20044+} __do_const;
20045
20046 extern int generic_get_free_region(unsigned long base, unsigned long size,
20047 int replace_reg);
20048diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20049index 8a87a32..682a22a 100644
20050--- a/arch/x86/kernel/cpu/perf_event.c
20051+++ b/arch/x86/kernel/cpu/perf_event.c
20052@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20053 pr_info("no hardware sampling interrupt available.\n");
20054 }
20055
20056-static struct attribute_group x86_pmu_format_group = {
20057+static attribute_group_no_const x86_pmu_format_group = {
20058 .name = "format",
20059 .attrs = NULL,
20060 };
20061@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20062 NULL,
20063 };
20064
20065-static struct attribute_group x86_pmu_events_group = {
20066+static attribute_group_no_const x86_pmu_events_group = {
20067 .name = "events",
20068 .attrs = events_attr,
20069 };
20070@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20071 if (idx > GDT_ENTRIES)
20072 return 0;
20073
20074- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20075+ desc = get_cpu_gdt_table(smp_processor_id());
20076 }
20077
20078 return get_desc_base(desc + idx);
20079@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20080 break;
20081
20082 perf_callchain_store(entry, frame.return_address);
20083- fp = frame.next_frame;
20084+ fp = (const void __force_user *)frame.next_frame;
20085 }
20086 }
20087
20088diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20089index 639d128..e92d7e5 100644
20090--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20091+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20092@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20093 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20094 {
20095 struct attribute **attrs;
20096- struct attribute_group *attr_group;
20097+ attribute_group_no_const *attr_group;
20098 int i = 0, j;
20099
20100 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20101diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20102index f31a165..7b46cd8 100644
20103--- a/arch/x86/kernel/cpu/perf_event_intel.c
20104+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20105@@ -2247,10 +2247,10 @@ __init int intel_pmu_init(void)
20106 * v2 and above have a perf capabilities MSR
20107 */
20108 if (version > 1) {
20109- u64 capabilities;
20110+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20111
20112- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20113- x86_pmu.intel_cap.capabilities = capabilities;
20114+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20115+ x86_pmu.intel_cap.capabilities = capabilities;
20116 }
20117
20118 intel_ds_init();
20119diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20120index 4118f9f..f91d0ab 100644
20121--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20122+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20123@@ -3204,7 +3204,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20124 static int __init uncore_type_init(struct intel_uncore_type *type)
20125 {
20126 struct intel_uncore_pmu *pmus;
20127- struct attribute_group *attr_group;
20128+ attribute_group_no_const *attr_group;
20129 struct attribute **attrs;
20130 int i, j;
20131
20132diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20133index a80ab71..4089da5 100644
20134--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20135+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20136@@ -498,7 +498,7 @@ struct intel_uncore_box {
20137 struct uncore_event_desc {
20138 struct kobj_attribute attr;
20139 const char *config;
20140-};
20141+} __do_const;
20142
20143 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20144 { \
20145diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20146index 7d9481c..99c7e4b 100644
20147--- a/arch/x86/kernel/cpuid.c
20148+++ b/arch/x86/kernel/cpuid.c
20149@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20150 return notifier_from_errno(err);
20151 }
20152
20153-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20154+static struct notifier_block cpuid_class_cpu_notifier =
20155 {
20156 .notifier_call = cpuid_class_cpu_callback,
20157 };
20158diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20159index 18677a9..f67c45b 100644
20160--- a/arch/x86/kernel/crash.c
20161+++ b/arch/x86/kernel/crash.c
20162@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20163 {
20164 #ifdef CONFIG_X86_32
20165 struct pt_regs fixed_regs;
20166-#endif
20167
20168-#ifdef CONFIG_X86_32
20169- if (!user_mode_vm(regs)) {
20170+ if (!user_mode(regs)) {
20171 crash_fixup_ss_esp(&fixed_regs, regs);
20172 regs = &fixed_regs;
20173 }
20174diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20175index afa64ad..dce67dd 100644
20176--- a/arch/x86/kernel/crash_dump_64.c
20177+++ b/arch/x86/kernel/crash_dump_64.c
20178@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20179 return -ENOMEM;
20180
20181 if (userbuf) {
20182- if (copy_to_user(buf, vaddr + offset, csize)) {
20183+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20184 iounmap(vaddr);
20185 return -EFAULT;
20186 }
20187diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20188index 5d3fe8d..02e1429 100644
20189--- a/arch/x86/kernel/doublefault.c
20190+++ b/arch/x86/kernel/doublefault.c
20191@@ -13,7 +13,7 @@
20192
20193 #define DOUBLEFAULT_STACKSIZE (1024)
20194 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20195-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20196+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20197
20198 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20199
20200@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20201 unsigned long gdt, tss;
20202
20203 native_store_gdt(&gdt_desc);
20204- gdt = gdt_desc.address;
20205+ gdt = (unsigned long)gdt_desc.address;
20206
20207 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20208
20209@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20210 /* 0x2 bit is always set */
20211 .flags = X86_EFLAGS_SF | 0x2,
20212 .sp = STACK_START,
20213- .es = __USER_DS,
20214+ .es = __KERNEL_DS,
20215 .cs = __KERNEL_CS,
20216 .ss = __KERNEL_DS,
20217- .ds = __USER_DS,
20218+ .ds = __KERNEL_DS,
20219 .fs = __KERNEL_PERCPU,
20220
20221 .__cr3 = __pa_nodebug(swapper_pg_dir),
20222diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20223index deb6421..76bbc12 100644
20224--- a/arch/x86/kernel/dumpstack.c
20225+++ b/arch/x86/kernel/dumpstack.c
20226@@ -2,6 +2,9 @@
20227 * Copyright (C) 1991, 1992 Linus Torvalds
20228 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20229 */
20230+#ifdef CONFIG_GRKERNSEC_HIDESYM
20231+#define __INCLUDED_BY_HIDESYM 1
20232+#endif
20233 #include <linux/kallsyms.h>
20234 #include <linux/kprobes.h>
20235 #include <linux/uaccess.h>
20236@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20237 static void
20238 print_ftrace_graph_addr(unsigned long addr, void *data,
20239 const struct stacktrace_ops *ops,
20240- struct thread_info *tinfo, int *graph)
20241+ struct task_struct *task, int *graph)
20242 {
20243- struct task_struct *task;
20244 unsigned long ret_addr;
20245 int index;
20246
20247 if (addr != (unsigned long)return_to_handler)
20248 return;
20249
20250- task = tinfo->task;
20251 index = task->curr_ret_stack;
20252
20253 if (!task->ret_stack || index < *graph)
20254@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20255 static inline void
20256 print_ftrace_graph_addr(unsigned long addr, void *data,
20257 const struct stacktrace_ops *ops,
20258- struct thread_info *tinfo, int *graph)
20259+ struct task_struct *task, int *graph)
20260 { }
20261 #endif
20262
20263@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20264 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20265 */
20266
20267-static inline int valid_stack_ptr(struct thread_info *tinfo,
20268- void *p, unsigned int size, void *end)
20269+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20270 {
20271- void *t = tinfo;
20272 if (end) {
20273 if (p < end && p >= (end-THREAD_SIZE))
20274 return 1;
20275@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20276 }
20277
20278 unsigned long
20279-print_context_stack(struct thread_info *tinfo,
20280+print_context_stack(struct task_struct *task, void *stack_start,
20281 unsigned long *stack, unsigned long bp,
20282 const struct stacktrace_ops *ops, void *data,
20283 unsigned long *end, int *graph)
20284 {
20285 struct stack_frame *frame = (struct stack_frame *)bp;
20286
20287- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20288+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20289 unsigned long addr;
20290
20291 addr = *stack;
20292@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20293 } else {
20294 ops->address(data, addr, 0);
20295 }
20296- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20297+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20298 }
20299 stack++;
20300 }
20301@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20302 EXPORT_SYMBOL_GPL(print_context_stack);
20303
20304 unsigned long
20305-print_context_stack_bp(struct thread_info *tinfo,
20306+print_context_stack_bp(struct task_struct *task, void *stack_start,
20307 unsigned long *stack, unsigned long bp,
20308 const struct stacktrace_ops *ops, void *data,
20309 unsigned long *end, int *graph)
20310@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20311 struct stack_frame *frame = (struct stack_frame *)bp;
20312 unsigned long *ret_addr = &frame->return_address;
20313
20314- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20315+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20316 unsigned long addr = *ret_addr;
20317
20318 if (!__kernel_text_address(addr))
20319@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20320 ops->address(data, addr, 1);
20321 frame = frame->next_frame;
20322 ret_addr = &frame->return_address;
20323- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20324+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20325 }
20326
20327 return (unsigned long)frame;
20328@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20329 static void print_trace_address(void *data, unsigned long addr, int reliable)
20330 {
20331 touch_nmi_watchdog();
20332- printk(data);
20333+ printk("%s", (char *)data);
20334 printk_address(addr, reliable);
20335 }
20336
20337@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20338 }
20339 EXPORT_SYMBOL_GPL(oops_begin);
20340
20341+extern void gr_handle_kernel_exploit(void);
20342+
20343 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20344 {
20345 if (regs && kexec_should_crash(current))
20346@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20347 panic("Fatal exception in interrupt");
20348 if (panic_on_oops)
20349 panic("Fatal exception");
20350- do_exit(signr);
20351+
20352+ gr_handle_kernel_exploit();
20353+
20354+ do_group_exit(signr);
20355 }
20356
20357 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20358@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20359 print_modules();
20360 show_regs(regs);
20361 #ifdef CONFIG_X86_32
20362- if (user_mode_vm(regs)) {
20363+ if (user_mode(regs)) {
20364 sp = regs->sp;
20365 ss = regs->ss & 0xffff;
20366 } else {
20367@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20368 unsigned long flags = oops_begin();
20369 int sig = SIGSEGV;
20370
20371- if (!user_mode_vm(regs))
20372+ if (!user_mode(regs))
20373 report_bug(regs->ip, regs);
20374
20375 if (__die(str, regs, err))
20376diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20377index f2a1770..540657f 100644
20378--- a/arch/x86/kernel/dumpstack_32.c
20379+++ b/arch/x86/kernel/dumpstack_32.c
20380@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20381 bp = stack_frame(task, regs);
20382
20383 for (;;) {
20384- struct thread_info *context;
20385+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20386
20387- context = (struct thread_info *)
20388- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20389- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20390+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20391
20392- stack = (unsigned long *)context->previous_esp;
20393- if (!stack)
20394+ if (stack_start == task_stack_page(task))
20395 break;
20396+ stack = *(unsigned long **)stack_start;
20397 if (ops->stack(data, "IRQ") < 0)
20398 break;
20399 touch_nmi_watchdog();
20400@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20401 int i;
20402
20403 show_regs_print_info(KERN_EMERG);
20404- __show_regs(regs, !user_mode_vm(regs));
20405+ __show_regs(regs, !user_mode(regs));
20406
20407 /*
20408 * When in-kernel, we also print out the stack and code at the
20409 * time of the fault..
20410 */
20411- if (!user_mode_vm(regs)) {
20412+ if (!user_mode(regs)) {
20413 unsigned int code_prologue = code_bytes * 43 / 64;
20414 unsigned int code_len = code_bytes;
20415 unsigned char c;
20416 u8 *ip;
20417+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20418
20419 pr_emerg("Stack:\n");
20420 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20421
20422 pr_emerg("Code:");
20423
20424- ip = (u8 *)regs->ip - code_prologue;
20425+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20426 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20427 /* try starting at IP */
20428- ip = (u8 *)regs->ip;
20429+ ip = (u8 *)regs->ip + cs_base;
20430 code_len = code_len - code_prologue + 1;
20431 }
20432 for (i = 0; i < code_len; i++, ip++) {
20433@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20434 pr_cont(" Bad EIP value.");
20435 break;
20436 }
20437- if (ip == (u8 *)regs->ip)
20438+ if (ip == (u8 *)regs->ip + cs_base)
20439 pr_cont(" <%02x>", c);
20440 else
20441 pr_cont(" %02x", c);
20442@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20443 {
20444 unsigned short ud2;
20445
20446+ ip = ktla_ktva(ip);
20447 if (ip < PAGE_OFFSET)
20448 return 0;
20449 if (probe_kernel_address((unsigned short *)ip, ud2))
20450@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20451
20452 return ud2 == 0x0b0f;
20453 }
20454+
20455+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20456+void pax_check_alloca(unsigned long size)
20457+{
20458+ unsigned long sp = (unsigned long)&sp, stack_left;
20459+
20460+ /* all kernel stacks are of the same size */
20461+ stack_left = sp & (THREAD_SIZE - 1);
20462+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20463+}
20464+EXPORT_SYMBOL(pax_check_alloca);
20465+#endif
20466diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20467index addb207..99635fa 100644
20468--- a/arch/x86/kernel/dumpstack_64.c
20469+++ b/arch/x86/kernel/dumpstack_64.c
20470@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20471 unsigned long *irq_stack_end =
20472 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20473 unsigned used = 0;
20474- struct thread_info *tinfo;
20475 int graph = 0;
20476 unsigned long dummy;
20477+ void *stack_start;
20478
20479 if (!task)
20480 task = current;
20481@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20482 * current stack address. If the stacks consist of nested
20483 * exceptions
20484 */
20485- tinfo = task_thread_info(task);
20486 for (;;) {
20487 char *id;
20488 unsigned long *estack_end;
20489+
20490 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20491 &used, &id);
20492
20493@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20494 if (ops->stack(data, id) < 0)
20495 break;
20496
20497- bp = ops->walk_stack(tinfo, stack, bp, ops,
20498+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20499 data, estack_end, &graph);
20500 ops->stack(data, "<EOE>");
20501 /*
20502@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20503 * second-to-last pointer (index -2 to end) in the
20504 * exception stack:
20505 */
20506+ if ((u16)estack_end[-1] != __KERNEL_DS)
20507+ goto out;
20508 stack = (unsigned long *) estack_end[-2];
20509 continue;
20510 }
20511@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20512 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20513 if (ops->stack(data, "IRQ") < 0)
20514 break;
20515- bp = ops->walk_stack(tinfo, stack, bp,
20516+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20517 ops, data, irq_stack_end, &graph);
20518 /*
20519 * We link to the next stack (which would be
20520@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20521 /*
20522 * This handles the process stack:
20523 */
20524- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20525+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20526+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20527+out:
20528 put_cpu();
20529 }
20530 EXPORT_SYMBOL(dump_trace);
20531@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20532
20533 return ud2 == 0x0b0f;
20534 }
20535+
20536+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20537+void pax_check_alloca(unsigned long size)
20538+{
20539+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20540+ unsigned cpu, used;
20541+ char *id;
20542+
20543+ /* check the process stack first */
20544+ stack_start = (unsigned long)task_stack_page(current);
20545+ stack_end = stack_start + THREAD_SIZE;
20546+ if (likely(stack_start <= sp && sp < stack_end)) {
20547+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20548+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20549+ return;
20550+ }
20551+
20552+ cpu = get_cpu();
20553+
20554+ /* check the irq stacks */
20555+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20556+ stack_start = stack_end - IRQ_STACK_SIZE;
20557+ if (stack_start <= sp && sp < stack_end) {
20558+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20559+ put_cpu();
20560+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20561+ return;
20562+ }
20563+
20564+ /* check the exception stacks */
20565+ used = 0;
20566+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20567+ stack_start = stack_end - EXCEPTION_STKSZ;
20568+ if (stack_end && stack_start <= sp && sp < stack_end) {
20569+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20570+ put_cpu();
20571+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20572+ return;
20573+ }
20574+
20575+ put_cpu();
20576+
20577+ /* unknown stack */
20578+ BUG();
20579+}
20580+EXPORT_SYMBOL(pax_check_alloca);
20581+#endif
20582diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20583index 174da5f..5e55606 100644
20584--- a/arch/x86/kernel/e820.c
20585+++ b/arch/x86/kernel/e820.c
20586@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20587
20588 static void early_panic(char *msg)
20589 {
20590- early_printk(msg);
20591- panic(msg);
20592+ early_printk("%s", msg);
20593+ panic("%s", msg);
20594 }
20595
20596 static int userdef __initdata;
20597diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20598index d15f575..d692043 100644
20599--- a/arch/x86/kernel/early_printk.c
20600+++ b/arch/x86/kernel/early_printk.c
20601@@ -7,6 +7,7 @@
20602 #include <linux/pci_regs.h>
20603 #include <linux/pci_ids.h>
20604 #include <linux/errno.h>
20605+#include <linux/sched.h>
20606 #include <asm/io.h>
20607 #include <asm/processor.h>
20608 #include <asm/fcntl.h>
20609diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20610index f0dcb0c..9f39b80 100644
20611--- a/arch/x86/kernel/entry_32.S
20612+++ b/arch/x86/kernel/entry_32.S
20613@@ -177,13 +177,153 @@
20614 /*CFI_REL_OFFSET gs, PT_GS*/
20615 .endm
20616 .macro SET_KERNEL_GS reg
20617+
20618+#ifdef CONFIG_CC_STACKPROTECTOR
20619 movl $(__KERNEL_STACK_CANARY), \reg
20620+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20621+ movl $(__USER_DS), \reg
20622+#else
20623+ xorl \reg, \reg
20624+#endif
20625+
20626 movl \reg, %gs
20627 .endm
20628
20629 #endif /* CONFIG_X86_32_LAZY_GS */
20630
20631-.macro SAVE_ALL
20632+.macro pax_enter_kernel
20633+#ifdef CONFIG_PAX_KERNEXEC
20634+ call pax_enter_kernel
20635+#endif
20636+.endm
20637+
20638+.macro pax_exit_kernel
20639+#ifdef CONFIG_PAX_KERNEXEC
20640+ call pax_exit_kernel
20641+#endif
20642+.endm
20643+
20644+#ifdef CONFIG_PAX_KERNEXEC
20645+ENTRY(pax_enter_kernel)
20646+#ifdef CONFIG_PARAVIRT
20647+ pushl %eax
20648+ pushl %ecx
20649+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20650+ mov %eax, %esi
20651+#else
20652+ mov %cr0, %esi
20653+#endif
20654+ bts $16, %esi
20655+ jnc 1f
20656+ mov %cs, %esi
20657+ cmp $__KERNEL_CS, %esi
20658+ jz 3f
20659+ ljmp $__KERNEL_CS, $3f
20660+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20661+2:
20662+#ifdef CONFIG_PARAVIRT
20663+ mov %esi, %eax
20664+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20665+#else
20666+ mov %esi, %cr0
20667+#endif
20668+3:
20669+#ifdef CONFIG_PARAVIRT
20670+ popl %ecx
20671+ popl %eax
20672+#endif
20673+ ret
20674+ENDPROC(pax_enter_kernel)
20675+
20676+ENTRY(pax_exit_kernel)
20677+#ifdef CONFIG_PARAVIRT
20678+ pushl %eax
20679+ pushl %ecx
20680+#endif
20681+ mov %cs, %esi
20682+ cmp $__KERNEXEC_KERNEL_CS, %esi
20683+ jnz 2f
20684+#ifdef CONFIG_PARAVIRT
20685+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20686+ mov %eax, %esi
20687+#else
20688+ mov %cr0, %esi
20689+#endif
20690+ btr $16, %esi
20691+ ljmp $__KERNEL_CS, $1f
20692+1:
20693+#ifdef CONFIG_PARAVIRT
20694+ mov %esi, %eax
20695+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20696+#else
20697+ mov %esi, %cr0
20698+#endif
20699+2:
20700+#ifdef CONFIG_PARAVIRT
20701+ popl %ecx
20702+ popl %eax
20703+#endif
20704+ ret
20705+ENDPROC(pax_exit_kernel)
20706+#endif
20707+
20708+ .macro pax_erase_kstack
20709+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20710+ call pax_erase_kstack
20711+#endif
20712+ .endm
20713+
20714+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20715+/*
20716+ * ebp: thread_info
20717+ */
20718+ENTRY(pax_erase_kstack)
20719+ pushl %edi
20720+ pushl %ecx
20721+ pushl %eax
20722+
20723+ mov TI_lowest_stack(%ebp), %edi
20724+ mov $-0xBEEF, %eax
20725+ std
20726+
20727+1: mov %edi, %ecx
20728+ and $THREAD_SIZE_asm - 1, %ecx
20729+ shr $2, %ecx
20730+ repne scasl
20731+ jecxz 2f
20732+
20733+ cmp $2*16, %ecx
20734+ jc 2f
20735+
20736+ mov $2*16, %ecx
20737+ repe scasl
20738+ jecxz 2f
20739+ jne 1b
20740+
20741+2: cld
20742+ mov %esp, %ecx
20743+ sub %edi, %ecx
20744+
20745+ cmp $THREAD_SIZE_asm, %ecx
20746+ jb 3f
20747+ ud2
20748+3:
20749+
20750+ shr $2, %ecx
20751+ rep stosl
20752+
20753+ mov TI_task_thread_sp0(%ebp), %edi
20754+ sub $128, %edi
20755+ mov %edi, TI_lowest_stack(%ebp)
20756+
20757+ popl %eax
20758+ popl %ecx
20759+ popl %edi
20760+ ret
20761+ENDPROC(pax_erase_kstack)
20762+#endif
20763+
20764+.macro __SAVE_ALL _DS
20765 cld
20766 PUSH_GS
20767 pushl_cfi %fs
20768@@ -206,7 +346,7 @@
20769 CFI_REL_OFFSET ecx, 0
20770 pushl_cfi %ebx
20771 CFI_REL_OFFSET ebx, 0
20772- movl $(__USER_DS), %edx
20773+ movl $\_DS, %edx
20774 movl %edx, %ds
20775 movl %edx, %es
20776 movl $(__KERNEL_PERCPU), %edx
20777@@ -214,6 +354,15 @@
20778 SET_KERNEL_GS %edx
20779 .endm
20780
20781+.macro SAVE_ALL
20782+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20783+ __SAVE_ALL __KERNEL_DS
20784+ pax_enter_kernel
20785+#else
20786+ __SAVE_ALL __USER_DS
20787+#endif
20788+.endm
20789+
20790 .macro RESTORE_INT_REGS
20791 popl_cfi %ebx
20792 CFI_RESTORE ebx
20793@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20794 popfl_cfi
20795 jmp syscall_exit
20796 CFI_ENDPROC
20797-END(ret_from_fork)
20798+ENDPROC(ret_from_fork)
20799
20800 ENTRY(ret_from_kernel_thread)
20801 CFI_STARTPROC
20802@@ -344,7 +493,15 @@ ret_from_intr:
20803 andl $SEGMENT_RPL_MASK, %eax
20804 #endif
20805 cmpl $USER_RPL, %eax
20806+
20807+#ifdef CONFIG_PAX_KERNEXEC
20808+ jae resume_userspace
20809+
20810+ pax_exit_kernel
20811+ jmp resume_kernel
20812+#else
20813 jb resume_kernel # not returning to v8086 or userspace
20814+#endif
20815
20816 ENTRY(resume_userspace)
20817 LOCKDEP_SYS_EXIT
20818@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20819 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20820 # int/exception return?
20821 jne work_pending
20822- jmp restore_all
20823-END(ret_from_exception)
20824+ jmp restore_all_pax
20825+ENDPROC(ret_from_exception)
20826
20827 #ifdef CONFIG_PREEMPT
20828 ENTRY(resume_kernel)
20829@@ -372,7 +529,7 @@ need_resched:
20830 jz restore_all
20831 call preempt_schedule_irq
20832 jmp need_resched
20833-END(resume_kernel)
20834+ENDPROC(resume_kernel)
20835 #endif
20836 CFI_ENDPROC
20837 /*
20838@@ -406,30 +563,45 @@ sysenter_past_esp:
20839 /*CFI_REL_OFFSET cs, 0*/
20840 /*
20841 * Push current_thread_info()->sysenter_return to the stack.
20842- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20843- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20844 */
20845- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20846+ pushl_cfi $0
20847 CFI_REL_OFFSET eip, 0
20848
20849 pushl_cfi %eax
20850 SAVE_ALL
20851+ GET_THREAD_INFO(%ebp)
20852+ movl TI_sysenter_return(%ebp),%ebp
20853+ movl %ebp,PT_EIP(%esp)
20854 ENABLE_INTERRUPTS(CLBR_NONE)
20855
20856 /*
20857 * Load the potential sixth argument from user stack.
20858 * Careful about security.
20859 */
20860+ movl PT_OLDESP(%esp),%ebp
20861+
20862+#ifdef CONFIG_PAX_MEMORY_UDEREF
20863+ mov PT_OLDSS(%esp),%ds
20864+1: movl %ds:(%ebp),%ebp
20865+ push %ss
20866+ pop %ds
20867+#else
20868 cmpl $__PAGE_OFFSET-3,%ebp
20869 jae syscall_fault
20870 ASM_STAC
20871 1: movl (%ebp),%ebp
20872 ASM_CLAC
20873+#endif
20874+
20875 movl %ebp,PT_EBP(%esp)
20876 _ASM_EXTABLE(1b,syscall_fault)
20877
20878 GET_THREAD_INFO(%ebp)
20879
20880+#ifdef CONFIG_PAX_RANDKSTACK
20881+ pax_erase_kstack
20882+#endif
20883+
20884 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20885 jnz sysenter_audit
20886 sysenter_do_call:
20887@@ -444,12 +616,24 @@ sysenter_do_call:
20888 testl $_TIF_ALLWORK_MASK, %ecx
20889 jne sysexit_audit
20890 sysenter_exit:
20891+
20892+#ifdef CONFIG_PAX_RANDKSTACK
20893+ pushl_cfi %eax
20894+ movl %esp, %eax
20895+ call pax_randomize_kstack
20896+ popl_cfi %eax
20897+#endif
20898+
20899+ pax_erase_kstack
20900+
20901 /* if something modifies registers it must also disable sysexit */
20902 movl PT_EIP(%esp), %edx
20903 movl PT_OLDESP(%esp), %ecx
20904 xorl %ebp,%ebp
20905 TRACE_IRQS_ON
20906 1: mov PT_FS(%esp), %fs
20907+2: mov PT_DS(%esp), %ds
20908+3: mov PT_ES(%esp), %es
20909 PTGS_TO_GS
20910 ENABLE_INTERRUPTS_SYSEXIT
20911
20912@@ -466,6 +650,9 @@ sysenter_audit:
20913 movl %eax,%edx /* 2nd arg: syscall number */
20914 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20915 call __audit_syscall_entry
20916+
20917+ pax_erase_kstack
20918+
20919 pushl_cfi %ebx
20920 movl PT_EAX(%esp),%eax /* reload syscall number */
20921 jmp sysenter_do_call
20922@@ -491,10 +678,16 @@ sysexit_audit:
20923
20924 CFI_ENDPROC
20925 .pushsection .fixup,"ax"
20926-2: movl $0,PT_FS(%esp)
20927+4: movl $0,PT_FS(%esp)
20928+ jmp 1b
20929+5: movl $0,PT_DS(%esp)
20930+ jmp 1b
20931+6: movl $0,PT_ES(%esp)
20932 jmp 1b
20933 .popsection
20934- _ASM_EXTABLE(1b,2b)
20935+ _ASM_EXTABLE(1b,4b)
20936+ _ASM_EXTABLE(2b,5b)
20937+ _ASM_EXTABLE(3b,6b)
20938 PTGS_TO_GS_EX
20939 ENDPROC(ia32_sysenter_target)
20940
20941@@ -509,6 +702,11 @@ ENTRY(system_call)
20942 pushl_cfi %eax # save orig_eax
20943 SAVE_ALL
20944 GET_THREAD_INFO(%ebp)
20945+
20946+#ifdef CONFIG_PAX_RANDKSTACK
20947+ pax_erase_kstack
20948+#endif
20949+
20950 # system call tracing in operation / emulation
20951 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20952 jnz syscall_trace_entry
20953@@ -527,6 +725,15 @@ syscall_exit:
20954 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20955 jne syscall_exit_work
20956
20957+restore_all_pax:
20958+
20959+#ifdef CONFIG_PAX_RANDKSTACK
20960+ movl %esp, %eax
20961+ call pax_randomize_kstack
20962+#endif
20963+
20964+ pax_erase_kstack
20965+
20966 restore_all:
20967 TRACE_IRQS_IRET
20968 restore_all_notrace:
20969@@ -583,14 +790,34 @@ ldt_ss:
20970 * compensating for the offset by changing to the ESPFIX segment with
20971 * a base address that matches for the difference.
20972 */
20973-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20974+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20975 mov %esp, %edx /* load kernel esp */
20976 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20977 mov %dx, %ax /* eax: new kernel esp */
20978 sub %eax, %edx /* offset (low word is 0) */
20979+#ifdef CONFIG_SMP
20980+ movl PER_CPU_VAR(cpu_number), %ebx
20981+ shll $PAGE_SHIFT_asm, %ebx
20982+ addl $cpu_gdt_table, %ebx
20983+#else
20984+ movl $cpu_gdt_table, %ebx
20985+#endif
20986 shr $16, %edx
20987- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20988- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20989+
20990+#ifdef CONFIG_PAX_KERNEXEC
20991+ mov %cr0, %esi
20992+ btr $16, %esi
20993+ mov %esi, %cr0
20994+#endif
20995+
20996+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20997+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20998+
20999+#ifdef CONFIG_PAX_KERNEXEC
21000+ bts $16, %esi
21001+ mov %esi, %cr0
21002+#endif
21003+
21004 pushl_cfi $__ESPFIX_SS
21005 pushl_cfi %eax /* new kernel esp */
21006 /* Disable interrupts, but do not irqtrace this section: we
21007@@ -619,20 +846,18 @@ work_resched:
21008 movl TI_flags(%ebp), %ecx
21009 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21010 # than syscall tracing?
21011- jz restore_all
21012+ jz restore_all_pax
21013 testb $_TIF_NEED_RESCHED, %cl
21014 jnz work_resched
21015
21016 work_notifysig: # deal with pending signals and
21017 # notify-resume requests
21018+ movl %esp, %eax
21019 #ifdef CONFIG_VM86
21020 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21021- movl %esp, %eax
21022 jne work_notifysig_v86 # returning to kernel-space or
21023 # vm86-space
21024 1:
21025-#else
21026- movl %esp, %eax
21027 #endif
21028 TRACE_IRQS_ON
21029 ENABLE_INTERRUPTS(CLBR_NONE)
21030@@ -653,7 +878,7 @@ work_notifysig_v86:
21031 movl %eax, %esp
21032 jmp 1b
21033 #endif
21034-END(work_pending)
21035+ENDPROC(work_pending)
21036
21037 # perform syscall exit tracing
21038 ALIGN
21039@@ -661,11 +886,14 @@ syscall_trace_entry:
21040 movl $-ENOSYS,PT_EAX(%esp)
21041 movl %esp, %eax
21042 call syscall_trace_enter
21043+
21044+ pax_erase_kstack
21045+
21046 /* What it returned is what we'll actually use. */
21047 cmpl $(NR_syscalls), %eax
21048 jnae syscall_call
21049 jmp syscall_exit
21050-END(syscall_trace_entry)
21051+ENDPROC(syscall_trace_entry)
21052
21053 # perform syscall exit tracing
21054 ALIGN
21055@@ -678,21 +906,25 @@ syscall_exit_work:
21056 movl %esp, %eax
21057 call syscall_trace_leave
21058 jmp resume_userspace
21059-END(syscall_exit_work)
21060+ENDPROC(syscall_exit_work)
21061 CFI_ENDPROC
21062
21063 RING0_INT_FRAME # can't unwind into user space anyway
21064 syscall_fault:
21065+#ifdef CONFIG_PAX_MEMORY_UDEREF
21066+ push %ss
21067+ pop %ds
21068+#endif
21069 ASM_CLAC
21070 GET_THREAD_INFO(%ebp)
21071 movl $-EFAULT,PT_EAX(%esp)
21072 jmp resume_userspace
21073-END(syscall_fault)
21074+ENDPROC(syscall_fault)
21075
21076 syscall_badsys:
21077 movl $-ENOSYS,PT_EAX(%esp)
21078 jmp resume_userspace
21079-END(syscall_badsys)
21080+ENDPROC(syscall_badsys)
21081 CFI_ENDPROC
21082 /*
21083 * End of kprobes section
21084@@ -708,8 +940,15 @@ END(syscall_badsys)
21085 * normal stack and adjusts ESP with the matching offset.
21086 */
21087 /* fixup the stack */
21088- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21089- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21090+#ifdef CONFIG_SMP
21091+ movl PER_CPU_VAR(cpu_number), %ebx
21092+ shll $PAGE_SHIFT_asm, %ebx
21093+ addl $cpu_gdt_table, %ebx
21094+#else
21095+ movl $cpu_gdt_table, %ebx
21096+#endif
21097+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21098+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21099 shl $16, %eax
21100 addl %esp, %eax /* the adjusted stack pointer */
21101 pushl_cfi $__KERNEL_DS
21102@@ -762,7 +1001,7 @@ vector=vector+1
21103 .endr
21104 2: jmp common_interrupt
21105 .endr
21106-END(irq_entries_start)
21107+ENDPROC(irq_entries_start)
21108
21109 .previous
21110 END(interrupt)
21111@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21112 pushl_cfi $do_coprocessor_error
21113 jmp error_code
21114 CFI_ENDPROC
21115-END(coprocessor_error)
21116+ENDPROC(coprocessor_error)
21117
21118 ENTRY(simd_coprocessor_error)
21119 RING0_INT_FRAME
21120@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21121 .section .altinstructions,"a"
21122 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21123 .previous
21124-.section .altinstr_replacement,"ax"
21125+.section .altinstr_replacement,"a"
21126 663: pushl $do_simd_coprocessor_error
21127 664:
21128 .previous
21129@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21130 #endif
21131 jmp error_code
21132 CFI_ENDPROC
21133-END(simd_coprocessor_error)
21134+ENDPROC(simd_coprocessor_error)
21135
21136 ENTRY(device_not_available)
21137 RING0_INT_FRAME
21138@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21139 pushl_cfi $do_device_not_available
21140 jmp error_code
21141 CFI_ENDPROC
21142-END(device_not_available)
21143+ENDPROC(device_not_available)
21144
21145 #ifdef CONFIG_PARAVIRT
21146 ENTRY(native_iret)
21147 iret
21148 _ASM_EXTABLE(native_iret, iret_exc)
21149-END(native_iret)
21150+ENDPROC(native_iret)
21151
21152 ENTRY(native_irq_enable_sysexit)
21153 sti
21154 sysexit
21155-END(native_irq_enable_sysexit)
21156+ENDPROC(native_irq_enable_sysexit)
21157 #endif
21158
21159 ENTRY(overflow)
21160@@ -875,7 +1114,7 @@ ENTRY(overflow)
21161 pushl_cfi $do_overflow
21162 jmp error_code
21163 CFI_ENDPROC
21164-END(overflow)
21165+ENDPROC(overflow)
21166
21167 ENTRY(bounds)
21168 RING0_INT_FRAME
21169@@ -884,7 +1123,7 @@ ENTRY(bounds)
21170 pushl_cfi $do_bounds
21171 jmp error_code
21172 CFI_ENDPROC
21173-END(bounds)
21174+ENDPROC(bounds)
21175
21176 ENTRY(invalid_op)
21177 RING0_INT_FRAME
21178@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21179 pushl_cfi $do_invalid_op
21180 jmp error_code
21181 CFI_ENDPROC
21182-END(invalid_op)
21183+ENDPROC(invalid_op)
21184
21185 ENTRY(coprocessor_segment_overrun)
21186 RING0_INT_FRAME
21187@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21188 pushl_cfi $do_coprocessor_segment_overrun
21189 jmp error_code
21190 CFI_ENDPROC
21191-END(coprocessor_segment_overrun)
21192+ENDPROC(coprocessor_segment_overrun)
21193
21194 ENTRY(invalid_TSS)
21195 RING0_EC_FRAME
21196@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21197 pushl_cfi $do_invalid_TSS
21198 jmp error_code
21199 CFI_ENDPROC
21200-END(invalid_TSS)
21201+ENDPROC(invalid_TSS)
21202
21203 ENTRY(segment_not_present)
21204 RING0_EC_FRAME
21205@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21206 pushl_cfi $do_segment_not_present
21207 jmp error_code
21208 CFI_ENDPROC
21209-END(segment_not_present)
21210+ENDPROC(segment_not_present)
21211
21212 ENTRY(stack_segment)
21213 RING0_EC_FRAME
21214@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21215 pushl_cfi $do_stack_segment
21216 jmp error_code
21217 CFI_ENDPROC
21218-END(stack_segment)
21219+ENDPROC(stack_segment)
21220
21221 ENTRY(alignment_check)
21222 RING0_EC_FRAME
21223@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21224 pushl_cfi $do_alignment_check
21225 jmp error_code
21226 CFI_ENDPROC
21227-END(alignment_check)
21228+ENDPROC(alignment_check)
21229
21230 ENTRY(divide_error)
21231 RING0_INT_FRAME
21232@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21233 pushl_cfi $do_divide_error
21234 jmp error_code
21235 CFI_ENDPROC
21236-END(divide_error)
21237+ENDPROC(divide_error)
21238
21239 #ifdef CONFIG_X86_MCE
21240 ENTRY(machine_check)
21241@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21242 pushl_cfi machine_check_vector
21243 jmp error_code
21244 CFI_ENDPROC
21245-END(machine_check)
21246+ENDPROC(machine_check)
21247 #endif
21248
21249 ENTRY(spurious_interrupt_bug)
21250@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21251 pushl_cfi $do_spurious_interrupt_bug
21252 jmp error_code
21253 CFI_ENDPROC
21254-END(spurious_interrupt_bug)
21255+ENDPROC(spurious_interrupt_bug)
21256 /*
21257 * End of kprobes section
21258 */
21259@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21260
21261 ENTRY(mcount)
21262 ret
21263-END(mcount)
21264+ENDPROC(mcount)
21265
21266 ENTRY(ftrace_caller)
21267 cmpl $0, function_trace_stop
21268@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21269 .globl ftrace_stub
21270 ftrace_stub:
21271 ret
21272-END(ftrace_caller)
21273+ENDPROC(ftrace_caller)
21274
21275 ENTRY(ftrace_regs_caller)
21276 pushf /* push flags before compare (in cs location) */
21277@@ -1210,7 +1449,7 @@ trace:
21278 popl %ecx
21279 popl %eax
21280 jmp ftrace_stub
21281-END(mcount)
21282+ENDPROC(mcount)
21283 #endif /* CONFIG_DYNAMIC_FTRACE */
21284 #endif /* CONFIG_FUNCTION_TRACER */
21285
21286@@ -1228,7 +1467,7 @@ ENTRY(ftrace_graph_caller)
21287 popl %ecx
21288 popl %eax
21289 ret
21290-END(ftrace_graph_caller)
21291+ENDPROC(ftrace_graph_caller)
21292
21293 .globl return_to_handler
21294 return_to_handler:
21295@@ -1284,15 +1523,18 @@ error_code:
21296 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21297 REG_TO_PTGS %ecx
21298 SET_KERNEL_GS %ecx
21299- movl $(__USER_DS), %ecx
21300+ movl $(__KERNEL_DS), %ecx
21301 movl %ecx, %ds
21302 movl %ecx, %es
21303+
21304+ pax_enter_kernel
21305+
21306 TRACE_IRQS_OFF
21307 movl %esp,%eax # pt_regs pointer
21308 call *%edi
21309 jmp ret_from_exception
21310 CFI_ENDPROC
21311-END(page_fault)
21312+ENDPROC(page_fault)
21313
21314 /*
21315 * Debug traps and NMI can happen at the one SYSENTER instruction
21316@@ -1335,7 +1577,7 @@ debug_stack_correct:
21317 call do_debug
21318 jmp ret_from_exception
21319 CFI_ENDPROC
21320-END(debug)
21321+ENDPROC(debug)
21322
21323 /*
21324 * NMI is doubly nasty. It can happen _while_ we're handling
21325@@ -1373,6 +1615,9 @@ nmi_stack_correct:
21326 xorl %edx,%edx # zero error code
21327 movl %esp,%eax # pt_regs pointer
21328 call do_nmi
21329+
21330+ pax_exit_kernel
21331+
21332 jmp restore_all_notrace
21333 CFI_ENDPROC
21334
21335@@ -1409,12 +1654,15 @@ nmi_espfix_stack:
21336 FIXUP_ESPFIX_STACK # %eax == %esp
21337 xorl %edx,%edx # zero error code
21338 call do_nmi
21339+
21340+ pax_exit_kernel
21341+
21342 RESTORE_REGS
21343 lss 12+4(%esp), %esp # back to espfix stack
21344 CFI_ADJUST_CFA_OFFSET -24
21345 jmp irq_return
21346 CFI_ENDPROC
21347-END(nmi)
21348+ENDPROC(nmi)
21349
21350 ENTRY(int3)
21351 RING0_INT_FRAME
21352@@ -1427,14 +1675,14 @@ ENTRY(int3)
21353 call do_int3
21354 jmp ret_from_exception
21355 CFI_ENDPROC
21356-END(int3)
21357+ENDPROC(int3)
21358
21359 ENTRY(general_protection)
21360 RING0_EC_FRAME
21361 pushl_cfi $do_general_protection
21362 jmp error_code
21363 CFI_ENDPROC
21364-END(general_protection)
21365+ENDPROC(general_protection)
21366
21367 #ifdef CONFIG_KVM_GUEST
21368 ENTRY(async_page_fault)
21369@@ -1443,7 +1691,7 @@ ENTRY(async_page_fault)
21370 pushl_cfi $do_async_page_fault
21371 jmp error_code
21372 CFI_ENDPROC
21373-END(async_page_fault)
21374+ENDPROC(async_page_fault)
21375 #endif
21376
21377 /*
21378diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21379index b077f4c..feb26c1 100644
21380--- a/arch/x86/kernel/entry_64.S
21381+++ b/arch/x86/kernel/entry_64.S
21382@@ -59,6 +59,8 @@
21383 #include <asm/context_tracking.h>
21384 #include <asm/smap.h>
21385 #include <linux/err.h>
21386+#include <asm/pgtable.h>
21387+#include <asm/alternative-asm.h>
21388
21389 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21390 #include <linux/elf-em.h>
21391@@ -80,8 +82,9 @@
21392 #ifdef CONFIG_DYNAMIC_FTRACE
21393
21394 ENTRY(function_hook)
21395+ pax_force_retaddr
21396 retq
21397-END(function_hook)
21398+ENDPROC(function_hook)
21399
21400 /* skip is set if stack has been adjusted */
21401 .macro ftrace_caller_setup skip=0
21402@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21403 #endif
21404
21405 GLOBAL(ftrace_stub)
21406+ pax_force_retaddr
21407 retq
21408-END(ftrace_caller)
21409+ENDPROC(ftrace_caller)
21410
21411 ENTRY(ftrace_regs_caller)
21412 /* Save the current flags before compare (in SS location)*/
21413@@ -191,7 +195,7 @@ ftrace_restore_flags:
21414 popfq
21415 jmp ftrace_stub
21416
21417-END(ftrace_regs_caller)
21418+ENDPROC(ftrace_regs_caller)
21419
21420
21421 #else /* ! CONFIG_DYNAMIC_FTRACE */
21422@@ -212,6 +216,7 @@ ENTRY(function_hook)
21423 #endif
21424
21425 GLOBAL(ftrace_stub)
21426+ pax_force_retaddr
21427 retq
21428
21429 trace:
21430@@ -225,12 +230,13 @@ trace:
21431 #endif
21432 subq $MCOUNT_INSN_SIZE, %rdi
21433
21434+ pax_force_fptr ftrace_trace_function
21435 call *ftrace_trace_function
21436
21437 MCOUNT_RESTORE_FRAME
21438
21439 jmp ftrace_stub
21440-END(function_hook)
21441+ENDPROC(function_hook)
21442 #endif /* CONFIG_DYNAMIC_FTRACE */
21443 #endif /* CONFIG_FUNCTION_TRACER */
21444
21445@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21446
21447 MCOUNT_RESTORE_FRAME
21448
21449+ pax_force_retaddr
21450 retq
21451-END(ftrace_graph_caller)
21452+ENDPROC(ftrace_graph_caller)
21453
21454 GLOBAL(return_to_handler)
21455 subq $24, %rsp
21456@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21457 movq 8(%rsp), %rdx
21458 movq (%rsp), %rax
21459 addq $24, %rsp
21460+ pax_force_fptr %rdi
21461 jmp *%rdi
21462+ENDPROC(return_to_handler)
21463 #endif
21464
21465
21466@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21467 ENDPROC(native_usergs_sysret64)
21468 #endif /* CONFIG_PARAVIRT */
21469
21470+ .macro ljmpq sel, off
21471+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21472+ .byte 0x48; ljmp *1234f(%rip)
21473+ .pushsection .rodata
21474+ .align 16
21475+ 1234: .quad \off; .word \sel
21476+ .popsection
21477+#else
21478+ pushq $\sel
21479+ pushq $\off
21480+ lretq
21481+#endif
21482+ .endm
21483+
21484+ .macro pax_enter_kernel
21485+ pax_set_fptr_mask
21486+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21487+ call pax_enter_kernel
21488+#endif
21489+ .endm
21490+
21491+ .macro pax_exit_kernel
21492+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21493+ call pax_exit_kernel
21494+#endif
21495+
21496+ .endm
21497+
21498+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21499+ENTRY(pax_enter_kernel)
21500+ pushq %rdi
21501+
21502+#ifdef CONFIG_PARAVIRT
21503+ PV_SAVE_REGS(CLBR_RDI)
21504+#endif
21505+
21506+#ifdef CONFIG_PAX_KERNEXEC
21507+ GET_CR0_INTO_RDI
21508+ bts $16,%rdi
21509+ jnc 3f
21510+ mov %cs,%edi
21511+ cmp $__KERNEL_CS,%edi
21512+ jnz 2f
21513+1:
21514+#endif
21515+
21516+#ifdef CONFIG_PAX_MEMORY_UDEREF
21517+ 661: jmp 111f
21518+ .pushsection .altinstr_replacement, "a"
21519+ 662: ASM_NOP2
21520+ .popsection
21521+ .pushsection .altinstructions, "a"
21522+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21523+ .popsection
21524+ GET_CR3_INTO_RDI
21525+ cmp $0,%dil
21526+ jnz 112f
21527+ mov $__KERNEL_DS,%edi
21528+ mov %edi,%ss
21529+ jmp 111f
21530+112: cmp $1,%dil
21531+ jz 113f
21532+ ud2
21533+113: sub $4097,%rdi
21534+ bts $63,%rdi
21535+ SET_RDI_INTO_CR3
21536+ mov $__UDEREF_KERNEL_DS,%edi
21537+ mov %edi,%ss
21538+111:
21539+#endif
21540+
21541+#ifdef CONFIG_PARAVIRT
21542+ PV_RESTORE_REGS(CLBR_RDI)
21543+#endif
21544+
21545+ popq %rdi
21546+ pax_force_retaddr
21547+ retq
21548+
21549+#ifdef CONFIG_PAX_KERNEXEC
21550+2: ljmpq __KERNEL_CS,1b
21551+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21552+4: SET_RDI_INTO_CR0
21553+ jmp 1b
21554+#endif
21555+ENDPROC(pax_enter_kernel)
21556+
21557+ENTRY(pax_exit_kernel)
21558+ pushq %rdi
21559+
21560+#ifdef CONFIG_PARAVIRT
21561+ PV_SAVE_REGS(CLBR_RDI)
21562+#endif
21563+
21564+#ifdef CONFIG_PAX_KERNEXEC
21565+ mov %cs,%rdi
21566+ cmp $__KERNEXEC_KERNEL_CS,%edi
21567+ jz 2f
21568+ GET_CR0_INTO_RDI
21569+ bts $16,%rdi
21570+ jnc 4f
21571+1:
21572+#endif
21573+
21574+#ifdef CONFIG_PAX_MEMORY_UDEREF
21575+ 661: jmp 111f
21576+ .pushsection .altinstr_replacement, "a"
21577+ 662: ASM_NOP2
21578+ .popsection
21579+ .pushsection .altinstructions, "a"
21580+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21581+ .popsection
21582+ mov %ss,%edi
21583+ cmp $__UDEREF_KERNEL_DS,%edi
21584+ jnz 111f
21585+ GET_CR3_INTO_RDI
21586+ cmp $0,%dil
21587+ jz 112f
21588+ ud2
21589+112: add $4097,%rdi
21590+ bts $63,%rdi
21591+ SET_RDI_INTO_CR3
21592+ mov $__KERNEL_DS,%edi
21593+ mov %edi,%ss
21594+111:
21595+#endif
21596+
21597+#ifdef CONFIG_PARAVIRT
21598+ PV_RESTORE_REGS(CLBR_RDI);
21599+#endif
21600+
21601+ popq %rdi
21602+ pax_force_retaddr
21603+ retq
21604+
21605+#ifdef CONFIG_PAX_KERNEXEC
21606+2: GET_CR0_INTO_RDI
21607+ btr $16,%rdi
21608+ jnc 4f
21609+ ljmpq __KERNEL_CS,3f
21610+3: SET_RDI_INTO_CR0
21611+ jmp 1b
21612+4: ud2
21613+ jmp 4b
21614+#endif
21615+ENDPROC(pax_exit_kernel)
21616+#endif
21617+
21618+ .macro pax_enter_kernel_user
21619+ pax_set_fptr_mask
21620+#ifdef CONFIG_PAX_MEMORY_UDEREF
21621+ call pax_enter_kernel_user
21622+#endif
21623+ .endm
21624+
21625+ .macro pax_exit_kernel_user
21626+#ifdef CONFIG_PAX_MEMORY_UDEREF
21627+ call pax_exit_kernel_user
21628+#endif
21629+#ifdef CONFIG_PAX_RANDKSTACK
21630+ pushq %rax
21631+ pushq %r11
21632+ call pax_randomize_kstack
21633+ popq %r11
21634+ popq %rax
21635+#endif
21636+ .endm
21637+
21638+#ifdef CONFIG_PAX_MEMORY_UDEREF
21639+ENTRY(pax_enter_kernel_user)
21640+ pushq %rdi
21641+ pushq %rbx
21642+
21643+#ifdef CONFIG_PARAVIRT
21644+ PV_SAVE_REGS(CLBR_RDI)
21645+#endif
21646+
21647+ 661: jmp 111f
21648+ .pushsection .altinstr_replacement, "a"
21649+ 662: ASM_NOP2
21650+ .popsection
21651+ .pushsection .altinstructions, "a"
21652+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21653+ .popsection
21654+ GET_CR3_INTO_RDI
21655+ cmp $1,%dil
21656+ jnz 4f
21657+ sub $4097,%rdi
21658+ bts $63,%rdi
21659+ SET_RDI_INTO_CR3
21660+ jmp 3f
21661+111:
21662+
21663+ GET_CR3_INTO_RDI
21664+ mov %rdi,%rbx
21665+ add $__START_KERNEL_map,%rbx
21666+ sub phys_base(%rip),%rbx
21667+
21668+#ifdef CONFIG_PARAVIRT
21669+ cmpl $0, pv_info+PARAVIRT_enabled
21670+ jz 1f
21671+ pushq %rdi
21672+ i = 0
21673+ .rept USER_PGD_PTRS
21674+ mov i*8(%rbx),%rsi
21675+ mov $0,%sil
21676+ lea i*8(%rbx),%rdi
21677+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21678+ i = i + 1
21679+ .endr
21680+ popq %rdi
21681+ jmp 2f
21682+1:
21683+#endif
21684+
21685+ i = 0
21686+ .rept USER_PGD_PTRS
21687+ movb $0,i*8(%rbx)
21688+ i = i + 1
21689+ .endr
21690+
21691+2: SET_RDI_INTO_CR3
21692+
21693+#ifdef CONFIG_PAX_KERNEXEC
21694+ GET_CR0_INTO_RDI
21695+ bts $16,%rdi
21696+ SET_RDI_INTO_CR0
21697+#endif
21698+
21699+3:
21700+
21701+#ifdef CONFIG_PARAVIRT
21702+ PV_RESTORE_REGS(CLBR_RDI)
21703+#endif
21704+
21705+ popq %rbx
21706+ popq %rdi
21707+ pax_force_retaddr
21708+ retq
21709+4: ud2
21710+ENDPROC(pax_enter_kernel_user)
21711+
21712+ENTRY(pax_exit_kernel_user)
21713+ pushq %rdi
21714+ pushq %rbx
21715+
21716+#ifdef CONFIG_PARAVIRT
21717+ PV_SAVE_REGS(CLBR_RDI)
21718+#endif
21719+
21720+ GET_CR3_INTO_RDI
21721+ 661: jmp 1f
21722+ .pushsection .altinstr_replacement, "a"
21723+ 662: ASM_NOP2
21724+ .popsection
21725+ .pushsection .altinstructions, "a"
21726+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21727+ .popsection
21728+ cmp $0,%dil
21729+ jnz 3f
21730+ add $4097,%rdi
21731+ bts $63,%rdi
21732+ SET_RDI_INTO_CR3
21733+ jmp 2f
21734+1:
21735+
21736+ mov %rdi,%rbx
21737+
21738+#ifdef CONFIG_PAX_KERNEXEC
21739+ GET_CR0_INTO_RDI
21740+ btr $16,%rdi
21741+ jnc 3f
21742+ SET_RDI_INTO_CR0
21743+#endif
21744+
21745+ add $__START_KERNEL_map,%rbx
21746+ sub phys_base(%rip),%rbx
21747+
21748+#ifdef CONFIG_PARAVIRT
21749+ cmpl $0, pv_info+PARAVIRT_enabled
21750+ jz 1f
21751+ i = 0
21752+ .rept USER_PGD_PTRS
21753+ mov i*8(%rbx),%rsi
21754+ mov $0x67,%sil
21755+ lea i*8(%rbx),%rdi
21756+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21757+ i = i + 1
21758+ .endr
21759+ jmp 2f
21760+1:
21761+#endif
21762+
21763+ i = 0
21764+ .rept USER_PGD_PTRS
21765+ movb $0x67,i*8(%rbx)
21766+ i = i + 1
21767+ .endr
21768+2:
21769+
21770+#ifdef CONFIG_PARAVIRT
21771+ PV_RESTORE_REGS(CLBR_RDI)
21772+#endif
21773+
21774+ popq %rbx
21775+ popq %rdi
21776+ pax_force_retaddr
21777+ retq
21778+3: ud2
21779+ENDPROC(pax_exit_kernel_user)
21780+#endif
21781+
21782+ .macro pax_enter_kernel_nmi
21783+ pax_set_fptr_mask
21784+
21785+#ifdef CONFIG_PAX_KERNEXEC
21786+ GET_CR0_INTO_RDI
21787+ bts $16,%rdi
21788+ jc 110f
21789+ SET_RDI_INTO_CR0
21790+ or $2,%ebx
21791+110:
21792+#endif
21793+
21794+#ifdef CONFIG_PAX_MEMORY_UDEREF
21795+ 661: jmp 111f
21796+ .pushsection .altinstr_replacement, "a"
21797+ 662: ASM_NOP2
21798+ .popsection
21799+ .pushsection .altinstructions, "a"
21800+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21801+ .popsection
21802+ GET_CR3_INTO_RDI
21803+ cmp $0,%dil
21804+ jz 111f
21805+ sub $4097,%rdi
21806+ or $4,%ebx
21807+ bts $63,%rdi
21808+ SET_RDI_INTO_CR3
21809+ mov $__UDEREF_KERNEL_DS,%edi
21810+ mov %edi,%ss
21811+111:
21812+#endif
21813+ .endm
21814+
21815+ .macro pax_exit_kernel_nmi
21816+#ifdef CONFIG_PAX_KERNEXEC
21817+ btr $1,%ebx
21818+ jnc 110f
21819+ GET_CR0_INTO_RDI
21820+ btr $16,%rdi
21821+ SET_RDI_INTO_CR0
21822+110:
21823+#endif
21824+
21825+#ifdef CONFIG_PAX_MEMORY_UDEREF
21826+ btr $2,%ebx
21827+ jnc 111f
21828+ GET_CR3_INTO_RDI
21829+ add $4097,%rdi
21830+ bts $63,%rdi
21831+ SET_RDI_INTO_CR3
21832+ mov $__KERNEL_DS,%edi
21833+ mov %edi,%ss
21834+111:
21835+#endif
21836+ .endm
21837+
21838+ .macro pax_erase_kstack
21839+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21840+ call pax_erase_kstack
21841+#endif
21842+ .endm
21843+
21844+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21845+ENTRY(pax_erase_kstack)
21846+ pushq %rdi
21847+ pushq %rcx
21848+ pushq %rax
21849+ pushq %r11
21850+
21851+ GET_THREAD_INFO(%r11)
21852+ mov TI_lowest_stack(%r11), %rdi
21853+ mov $-0xBEEF, %rax
21854+ std
21855+
21856+1: mov %edi, %ecx
21857+ and $THREAD_SIZE_asm - 1, %ecx
21858+ shr $3, %ecx
21859+ repne scasq
21860+ jecxz 2f
21861+
21862+ cmp $2*8, %ecx
21863+ jc 2f
21864+
21865+ mov $2*8, %ecx
21866+ repe scasq
21867+ jecxz 2f
21868+ jne 1b
21869+
21870+2: cld
21871+ mov %esp, %ecx
21872+ sub %edi, %ecx
21873+
21874+ cmp $THREAD_SIZE_asm, %rcx
21875+ jb 3f
21876+ ud2
21877+3:
21878+
21879+ shr $3, %ecx
21880+ rep stosq
21881+
21882+ mov TI_task_thread_sp0(%r11), %rdi
21883+ sub $256, %rdi
21884+ mov %rdi, TI_lowest_stack(%r11)
21885+
21886+ popq %r11
21887+ popq %rax
21888+ popq %rcx
21889+ popq %rdi
21890+ pax_force_retaddr
21891+ ret
21892+ENDPROC(pax_erase_kstack)
21893+#endif
21894
21895 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21896 #ifdef CONFIG_TRACE_IRQFLAGS
21897@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21898 .endm
21899
21900 .macro UNFAKE_STACK_FRAME
21901- addq $8*6, %rsp
21902- CFI_ADJUST_CFA_OFFSET -(6*8)
21903+ addq $8*6 + ARG_SKIP, %rsp
21904+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21905 .endm
21906
21907 /*
21908@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21909 movq %rsp, %rsi
21910
21911 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21912- testl $3, CS-RBP(%rsi)
21913+ testb $3, CS-RBP(%rsi)
21914 je 1f
21915 SWAPGS
21916 /*
21917@@ -514,9 +947,10 @@ ENTRY(save_paranoid)
21918 js 1f /* negative -> in kernel */
21919 SWAPGS
21920 xorl %ebx,%ebx
21921-1: ret
21922+1: pax_force_retaddr_bts
21923+ ret
21924 CFI_ENDPROC
21925-END(save_paranoid)
21926+ENDPROC(save_paranoid)
21927 .popsection
21928
21929 /*
21930@@ -538,7 +972,7 @@ ENTRY(ret_from_fork)
21931
21932 RESTORE_REST
21933
21934- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21935+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21936 jz 1f
21937
21938 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21939@@ -556,7 +990,7 @@ ENTRY(ret_from_fork)
21940 RESTORE_REST
21941 jmp int_ret_from_sys_call
21942 CFI_ENDPROC
21943-END(ret_from_fork)
21944+ENDPROC(ret_from_fork)
21945
21946 /*
21947 * System call entry. Up to 6 arguments in registers are supported.
21948@@ -593,7 +1027,7 @@ END(ret_from_fork)
21949 ENTRY(system_call)
21950 CFI_STARTPROC simple
21951 CFI_SIGNAL_FRAME
21952- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21953+ CFI_DEF_CFA rsp,0
21954 CFI_REGISTER rip,rcx
21955 /*CFI_REGISTER rflags,r11*/
21956 SWAPGS_UNSAFE_STACK
21957@@ -606,16 +1040,23 @@ GLOBAL(system_call_after_swapgs)
21958
21959 movq %rsp,PER_CPU_VAR(old_rsp)
21960 movq PER_CPU_VAR(kernel_stack),%rsp
21961+ SAVE_ARGS 8*6,0
21962+ pax_enter_kernel_user
21963+
21964+#ifdef CONFIG_PAX_RANDKSTACK
21965+ pax_erase_kstack
21966+#endif
21967+
21968 /*
21969 * No need to follow this irqs off/on section - it's straight
21970 * and short:
21971 */
21972 ENABLE_INTERRUPTS(CLBR_NONE)
21973- SAVE_ARGS 8,0
21974 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21975 movq %rcx,RIP-ARGOFFSET(%rsp)
21976 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21977- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21978+ GET_THREAD_INFO(%rcx)
21979+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21980 jnz tracesys
21981 system_call_fastpath:
21982 #if __SYSCALL_MASK == ~0
21983@@ -625,7 +1066,7 @@ system_call_fastpath:
21984 cmpl $__NR_syscall_max,%eax
21985 #endif
21986 ja badsys
21987- movq %r10,%rcx
21988+ movq R10-ARGOFFSET(%rsp),%rcx
21989 call *sys_call_table(,%rax,8) # XXX: rip relative
21990 movq %rax,RAX-ARGOFFSET(%rsp)
21991 /*
21992@@ -639,10 +1080,13 @@ sysret_check:
21993 LOCKDEP_SYS_EXIT
21994 DISABLE_INTERRUPTS(CLBR_NONE)
21995 TRACE_IRQS_OFF
21996- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21997+ GET_THREAD_INFO(%rcx)
21998+ movl TI_flags(%rcx),%edx
21999 andl %edi,%edx
22000 jnz sysret_careful
22001 CFI_REMEMBER_STATE
22002+ pax_exit_kernel_user
22003+ pax_erase_kstack
22004 /*
22005 * sysretq will re-enable interrupts:
22006 */
22007@@ -694,14 +1138,18 @@ badsys:
22008 * jump back to the normal fast path.
22009 */
22010 auditsys:
22011- movq %r10,%r9 /* 6th arg: 4th syscall arg */
22012+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
22013 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
22014 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
22015 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
22016 movq %rax,%rsi /* 2nd arg: syscall number */
22017 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22018 call __audit_syscall_entry
22019+
22020+ pax_erase_kstack
22021+
22022 LOAD_ARGS 0 /* reload call-clobbered registers */
22023+ pax_set_fptr_mask
22024 jmp system_call_fastpath
22025
22026 /*
22027@@ -722,7 +1170,7 @@ sysret_audit:
22028 /* Do syscall tracing */
22029 tracesys:
22030 #ifdef CONFIG_AUDITSYSCALL
22031- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22032+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22033 jz auditsys
22034 #endif
22035 SAVE_REST
22036@@ -730,12 +1178,16 @@ tracesys:
22037 FIXUP_TOP_OF_STACK %rdi
22038 movq %rsp,%rdi
22039 call syscall_trace_enter
22040+
22041+ pax_erase_kstack
22042+
22043 /*
22044 * Reload arg registers from stack in case ptrace changed them.
22045 * We don't reload %rax because syscall_trace_enter() returned
22046 * the value it wants us to use in the table lookup.
22047 */
22048 LOAD_ARGS ARGOFFSET, 1
22049+ pax_set_fptr_mask
22050 RESTORE_REST
22051 #if __SYSCALL_MASK == ~0
22052 cmpq $__NR_syscall_max,%rax
22053@@ -744,7 +1196,7 @@ tracesys:
22054 cmpl $__NR_syscall_max,%eax
22055 #endif
22056 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
22057- movq %r10,%rcx /* fixup for C */
22058+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
22059 call *sys_call_table(,%rax,8)
22060 movq %rax,RAX-ARGOFFSET(%rsp)
22061 /* Use IRET because user could have changed frame */
22062@@ -765,7 +1217,9 @@ GLOBAL(int_with_check)
22063 andl %edi,%edx
22064 jnz int_careful
22065 andl $~TS_COMPAT,TI_status(%rcx)
22066- jmp retint_swapgs
22067+ pax_exit_kernel_user
22068+ pax_erase_kstack
22069+ jmp retint_swapgs_pax
22070
22071 /* Either reschedule or signal or syscall exit tracking needed. */
22072 /* First do a reschedule test. */
22073@@ -811,7 +1265,7 @@ int_restore_rest:
22074 TRACE_IRQS_OFF
22075 jmp int_with_check
22076 CFI_ENDPROC
22077-END(system_call)
22078+ENDPROC(system_call)
22079
22080 .macro FORK_LIKE func
22081 ENTRY(stub_\func)
22082@@ -824,9 +1278,10 @@ ENTRY(stub_\func)
22083 DEFAULT_FRAME 0 8 /* offset 8: return address */
22084 call sys_\func
22085 RESTORE_TOP_OF_STACK %r11, 8
22086+ pax_force_retaddr
22087 ret $REST_SKIP /* pop extended registers */
22088 CFI_ENDPROC
22089-END(stub_\func)
22090+ENDPROC(stub_\func)
22091 .endm
22092
22093 .macro FIXED_FRAME label,func
22094@@ -836,9 +1291,10 @@ ENTRY(\label)
22095 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22096 call \func
22097 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22098+ pax_force_retaddr
22099 ret
22100 CFI_ENDPROC
22101-END(\label)
22102+ENDPROC(\label)
22103 .endm
22104
22105 FORK_LIKE clone
22106@@ -855,9 +1311,10 @@ ENTRY(ptregscall_common)
22107 movq_cfi_restore R12+8, r12
22108 movq_cfi_restore RBP+8, rbp
22109 movq_cfi_restore RBX+8, rbx
22110+ pax_force_retaddr
22111 ret $REST_SKIP /* pop extended registers */
22112 CFI_ENDPROC
22113-END(ptregscall_common)
22114+ENDPROC(ptregscall_common)
22115
22116 ENTRY(stub_execve)
22117 CFI_STARTPROC
22118@@ -870,7 +1327,7 @@ ENTRY(stub_execve)
22119 RESTORE_REST
22120 jmp int_ret_from_sys_call
22121 CFI_ENDPROC
22122-END(stub_execve)
22123+ENDPROC(stub_execve)
22124
22125 /*
22126 * sigreturn is special because it needs to restore all registers on return.
22127@@ -887,7 +1344,7 @@ ENTRY(stub_rt_sigreturn)
22128 RESTORE_REST
22129 jmp int_ret_from_sys_call
22130 CFI_ENDPROC
22131-END(stub_rt_sigreturn)
22132+ENDPROC(stub_rt_sigreturn)
22133
22134 #ifdef CONFIG_X86_X32_ABI
22135 ENTRY(stub_x32_rt_sigreturn)
22136@@ -901,7 +1358,7 @@ ENTRY(stub_x32_rt_sigreturn)
22137 RESTORE_REST
22138 jmp int_ret_from_sys_call
22139 CFI_ENDPROC
22140-END(stub_x32_rt_sigreturn)
22141+ENDPROC(stub_x32_rt_sigreturn)
22142
22143 ENTRY(stub_x32_execve)
22144 CFI_STARTPROC
22145@@ -915,7 +1372,7 @@ ENTRY(stub_x32_execve)
22146 RESTORE_REST
22147 jmp int_ret_from_sys_call
22148 CFI_ENDPROC
22149-END(stub_x32_execve)
22150+ENDPROC(stub_x32_execve)
22151
22152 #endif
22153
22154@@ -952,7 +1409,7 @@ vector=vector+1
22155 2: jmp common_interrupt
22156 .endr
22157 CFI_ENDPROC
22158-END(irq_entries_start)
22159+ENDPROC(irq_entries_start)
22160
22161 .previous
22162 END(interrupt)
22163@@ -972,6 +1429,16 @@ END(interrupt)
22164 subq $ORIG_RAX-RBP, %rsp
22165 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22166 SAVE_ARGS_IRQ
22167+#ifdef CONFIG_PAX_MEMORY_UDEREF
22168+ testb $3, CS(%rdi)
22169+ jnz 1f
22170+ pax_enter_kernel
22171+ jmp 2f
22172+1: pax_enter_kernel_user
22173+2:
22174+#else
22175+ pax_enter_kernel
22176+#endif
22177 call \func
22178 .endm
22179
22180@@ -1004,7 +1471,7 @@ ret_from_intr:
22181
22182 exit_intr:
22183 GET_THREAD_INFO(%rcx)
22184- testl $3,CS-ARGOFFSET(%rsp)
22185+ testb $3,CS-ARGOFFSET(%rsp)
22186 je retint_kernel
22187
22188 /* Interrupt came from user space */
22189@@ -1026,12 +1493,16 @@ retint_swapgs: /* return to user-space */
22190 * The iretq could re-enable interrupts:
22191 */
22192 DISABLE_INTERRUPTS(CLBR_ANY)
22193+ pax_exit_kernel_user
22194+retint_swapgs_pax:
22195 TRACE_IRQS_IRETQ
22196 SWAPGS
22197 jmp restore_args
22198
22199 retint_restore_args: /* return to kernel space */
22200 DISABLE_INTERRUPTS(CLBR_ANY)
22201+ pax_exit_kernel
22202+ pax_force_retaddr (RIP-ARGOFFSET)
22203 /*
22204 * The iretq could re-enable interrupts:
22205 */
22206@@ -1114,7 +1585,7 @@ ENTRY(retint_kernel)
22207 #endif
22208
22209 CFI_ENDPROC
22210-END(common_interrupt)
22211+ENDPROC(common_interrupt)
22212 /*
22213 * End of kprobes section
22214 */
22215@@ -1132,7 +1603,7 @@ ENTRY(\sym)
22216 interrupt \do_sym
22217 jmp ret_from_intr
22218 CFI_ENDPROC
22219-END(\sym)
22220+ENDPROC(\sym)
22221 .endm
22222
22223 #ifdef CONFIG_TRACING
22224@@ -1215,12 +1686,22 @@ ENTRY(\sym)
22225 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22226 call error_entry
22227 DEFAULT_FRAME 0
22228+#ifdef CONFIG_PAX_MEMORY_UDEREF
22229+ testb $3, CS(%rsp)
22230+ jnz 1f
22231+ pax_enter_kernel
22232+ jmp 2f
22233+1: pax_enter_kernel_user
22234+2:
22235+#else
22236+ pax_enter_kernel
22237+#endif
22238 movq %rsp,%rdi /* pt_regs pointer */
22239 xorl %esi,%esi /* no error code */
22240 call \do_sym
22241 jmp error_exit /* %ebx: no swapgs flag */
22242 CFI_ENDPROC
22243-END(\sym)
22244+ENDPROC(\sym)
22245 .endm
22246
22247 .macro paranoidzeroentry sym do_sym
22248@@ -1233,15 +1714,25 @@ ENTRY(\sym)
22249 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22250 call save_paranoid
22251 TRACE_IRQS_OFF
22252+#ifdef CONFIG_PAX_MEMORY_UDEREF
22253+ testb $3, CS(%rsp)
22254+ jnz 1f
22255+ pax_enter_kernel
22256+ jmp 2f
22257+1: pax_enter_kernel_user
22258+2:
22259+#else
22260+ pax_enter_kernel
22261+#endif
22262 movq %rsp,%rdi /* pt_regs pointer */
22263 xorl %esi,%esi /* no error code */
22264 call \do_sym
22265 jmp paranoid_exit /* %ebx: no swapgs flag */
22266 CFI_ENDPROC
22267-END(\sym)
22268+ENDPROC(\sym)
22269 .endm
22270
22271-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22272+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22273 .macro paranoidzeroentry_ist sym do_sym ist
22274 ENTRY(\sym)
22275 INTR_FRAME
22276@@ -1252,14 +1743,30 @@ ENTRY(\sym)
22277 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22278 call save_paranoid
22279 TRACE_IRQS_OFF_DEBUG
22280+#ifdef CONFIG_PAX_MEMORY_UDEREF
22281+ testb $3, CS(%rsp)
22282+ jnz 1f
22283+ pax_enter_kernel
22284+ jmp 2f
22285+1: pax_enter_kernel_user
22286+2:
22287+#else
22288+ pax_enter_kernel
22289+#endif
22290 movq %rsp,%rdi /* pt_regs pointer */
22291 xorl %esi,%esi /* no error code */
22292+#ifdef CONFIG_SMP
22293+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22294+ lea init_tss(%r12), %r12
22295+#else
22296+ lea init_tss(%rip), %r12
22297+#endif
22298 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22299 call \do_sym
22300 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22301 jmp paranoid_exit /* %ebx: no swapgs flag */
22302 CFI_ENDPROC
22303-END(\sym)
22304+ENDPROC(\sym)
22305 .endm
22306
22307 .macro errorentry sym do_sym
22308@@ -1271,13 +1778,23 @@ ENTRY(\sym)
22309 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22310 call error_entry
22311 DEFAULT_FRAME 0
22312+#ifdef CONFIG_PAX_MEMORY_UDEREF
22313+ testb $3, CS(%rsp)
22314+ jnz 1f
22315+ pax_enter_kernel
22316+ jmp 2f
22317+1: pax_enter_kernel_user
22318+2:
22319+#else
22320+ pax_enter_kernel
22321+#endif
22322 movq %rsp,%rdi /* pt_regs pointer */
22323 movq ORIG_RAX(%rsp),%rsi /* get error code */
22324 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22325 call \do_sym
22326 jmp error_exit /* %ebx: no swapgs flag */
22327 CFI_ENDPROC
22328-END(\sym)
22329+ENDPROC(\sym)
22330 .endm
22331
22332 /* error code is on the stack already */
22333@@ -1291,13 +1808,23 @@ ENTRY(\sym)
22334 call save_paranoid
22335 DEFAULT_FRAME 0
22336 TRACE_IRQS_OFF
22337+#ifdef CONFIG_PAX_MEMORY_UDEREF
22338+ testb $3, CS(%rsp)
22339+ jnz 1f
22340+ pax_enter_kernel
22341+ jmp 2f
22342+1: pax_enter_kernel_user
22343+2:
22344+#else
22345+ pax_enter_kernel
22346+#endif
22347 movq %rsp,%rdi /* pt_regs pointer */
22348 movq ORIG_RAX(%rsp),%rsi /* get error code */
22349 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22350 call \do_sym
22351 jmp paranoid_exit /* %ebx: no swapgs flag */
22352 CFI_ENDPROC
22353-END(\sym)
22354+ENDPROC(\sym)
22355 .endm
22356
22357 zeroentry divide_error do_divide_error
22358@@ -1327,9 +1854,10 @@ gs_change:
22359 2: mfence /* workaround */
22360 SWAPGS
22361 popfq_cfi
22362+ pax_force_retaddr
22363 ret
22364 CFI_ENDPROC
22365-END(native_load_gs_index)
22366+ENDPROC(native_load_gs_index)
22367
22368 _ASM_EXTABLE(gs_change,bad_gs)
22369 .section .fixup,"ax"
22370@@ -1357,9 +1885,10 @@ ENTRY(call_softirq)
22371 CFI_DEF_CFA_REGISTER rsp
22372 CFI_ADJUST_CFA_OFFSET -8
22373 decl PER_CPU_VAR(irq_count)
22374+ pax_force_retaddr
22375 ret
22376 CFI_ENDPROC
22377-END(call_softirq)
22378+ENDPROC(call_softirq)
22379
22380 #ifdef CONFIG_XEN
22381 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22382@@ -1397,7 +1926,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22383 decl PER_CPU_VAR(irq_count)
22384 jmp error_exit
22385 CFI_ENDPROC
22386-END(xen_do_hypervisor_callback)
22387+ENDPROC(xen_do_hypervisor_callback)
22388
22389 /*
22390 * Hypervisor uses this for application faults while it executes.
22391@@ -1456,7 +1985,7 @@ ENTRY(xen_failsafe_callback)
22392 SAVE_ALL
22393 jmp error_exit
22394 CFI_ENDPROC
22395-END(xen_failsafe_callback)
22396+ENDPROC(xen_failsafe_callback)
22397
22398 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22399 xen_hvm_callback_vector xen_evtchn_do_upcall
22400@@ -1508,18 +2037,33 @@ ENTRY(paranoid_exit)
22401 DEFAULT_FRAME
22402 DISABLE_INTERRUPTS(CLBR_NONE)
22403 TRACE_IRQS_OFF_DEBUG
22404- testl %ebx,%ebx /* swapgs needed? */
22405+ testl $1,%ebx /* swapgs needed? */
22406 jnz paranoid_restore
22407- testl $3,CS(%rsp)
22408+ testb $3,CS(%rsp)
22409 jnz paranoid_userspace
22410+#ifdef CONFIG_PAX_MEMORY_UDEREF
22411+ pax_exit_kernel
22412+ TRACE_IRQS_IRETQ 0
22413+ SWAPGS_UNSAFE_STACK
22414+ RESTORE_ALL 8
22415+ pax_force_retaddr_bts
22416+ jmp irq_return
22417+#endif
22418 paranoid_swapgs:
22419+#ifdef CONFIG_PAX_MEMORY_UDEREF
22420+ pax_exit_kernel_user
22421+#else
22422+ pax_exit_kernel
22423+#endif
22424 TRACE_IRQS_IRETQ 0
22425 SWAPGS_UNSAFE_STACK
22426 RESTORE_ALL 8
22427 jmp irq_return
22428 paranoid_restore:
22429+ pax_exit_kernel
22430 TRACE_IRQS_IRETQ_DEBUG 0
22431 RESTORE_ALL 8
22432+ pax_force_retaddr_bts
22433 jmp irq_return
22434 paranoid_userspace:
22435 GET_THREAD_INFO(%rcx)
22436@@ -1548,7 +2092,7 @@ paranoid_schedule:
22437 TRACE_IRQS_OFF
22438 jmp paranoid_userspace
22439 CFI_ENDPROC
22440-END(paranoid_exit)
22441+ENDPROC(paranoid_exit)
22442
22443 /*
22444 * Exception entry point. This expects an error code/orig_rax on the stack.
22445@@ -1575,12 +2119,13 @@ ENTRY(error_entry)
22446 movq_cfi r14, R14+8
22447 movq_cfi r15, R15+8
22448 xorl %ebx,%ebx
22449- testl $3,CS+8(%rsp)
22450+ testb $3,CS+8(%rsp)
22451 je error_kernelspace
22452 error_swapgs:
22453 SWAPGS
22454 error_sti:
22455 TRACE_IRQS_OFF
22456+ pax_force_retaddr_bts
22457 ret
22458
22459 /*
22460@@ -1607,7 +2152,7 @@ bstep_iret:
22461 movq %rcx,RIP+8(%rsp)
22462 jmp error_swapgs
22463 CFI_ENDPROC
22464-END(error_entry)
22465+ENDPROC(error_entry)
22466
22467
22468 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22469@@ -1618,7 +2163,7 @@ ENTRY(error_exit)
22470 DISABLE_INTERRUPTS(CLBR_NONE)
22471 TRACE_IRQS_OFF
22472 GET_THREAD_INFO(%rcx)
22473- testl %eax,%eax
22474+ testl $1,%eax
22475 jne retint_kernel
22476 LOCKDEP_SYS_EXIT_IRQ
22477 movl TI_flags(%rcx),%edx
22478@@ -1627,7 +2172,7 @@ ENTRY(error_exit)
22479 jnz retint_careful
22480 jmp retint_swapgs
22481 CFI_ENDPROC
22482-END(error_exit)
22483+ENDPROC(error_exit)
22484
22485 /*
22486 * Test if a given stack is an NMI stack or not.
22487@@ -1685,9 +2230,11 @@ ENTRY(nmi)
22488 * If %cs was not the kernel segment, then the NMI triggered in user
22489 * space, which means it is definitely not nested.
22490 */
22491+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22492+ je 1f
22493 cmpl $__KERNEL_CS, 16(%rsp)
22494 jne first_nmi
22495-
22496+1:
22497 /*
22498 * Check the special variable on the stack to see if NMIs are
22499 * executing.
22500@@ -1721,8 +2268,7 @@ nested_nmi:
22501
22502 1:
22503 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22504- leaq -1*8(%rsp), %rdx
22505- movq %rdx, %rsp
22506+ subq $8, %rsp
22507 CFI_ADJUST_CFA_OFFSET 1*8
22508 leaq -10*8(%rsp), %rdx
22509 pushq_cfi $__KERNEL_DS
22510@@ -1740,6 +2286,7 @@ nested_nmi_out:
22511 CFI_RESTORE rdx
22512
22513 /* No need to check faults here */
22514+# pax_force_retaddr_bts
22515 INTERRUPT_RETURN
22516
22517 CFI_RESTORE_STATE
22518@@ -1856,6 +2403,8 @@ end_repeat_nmi:
22519 */
22520 movq %cr2, %r12
22521
22522+ pax_enter_kernel_nmi
22523+
22524 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22525 movq %rsp,%rdi
22526 movq $-1,%rsi
22527@@ -1868,26 +2417,31 @@ end_repeat_nmi:
22528 movq %r12, %cr2
22529 1:
22530
22531- testl %ebx,%ebx /* swapgs needed? */
22532+ testl $1,%ebx /* swapgs needed? */
22533 jnz nmi_restore
22534 nmi_swapgs:
22535 SWAPGS_UNSAFE_STACK
22536 nmi_restore:
22537+ pax_exit_kernel_nmi
22538 /* Pop the extra iret frame at once */
22539 RESTORE_ALL 6*8
22540+ testb $3, 8(%rsp)
22541+ jnz 1f
22542+ pax_force_retaddr_bts
22543+1:
22544
22545 /* Clear the NMI executing stack variable */
22546 movq $0, 5*8(%rsp)
22547 jmp irq_return
22548 CFI_ENDPROC
22549-END(nmi)
22550+ENDPROC(nmi)
22551
22552 ENTRY(ignore_sysret)
22553 CFI_STARTPROC
22554 mov $-ENOSYS,%eax
22555 sysret
22556 CFI_ENDPROC
22557-END(ignore_sysret)
22558+ENDPROC(ignore_sysret)
22559
22560 /*
22561 * End of kprobes section
22562diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22563index d4bdd25..912664c 100644
22564--- a/arch/x86/kernel/ftrace.c
22565+++ b/arch/x86/kernel/ftrace.c
22566@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22567 {
22568 unsigned char replaced[MCOUNT_INSN_SIZE];
22569
22570+ ip = ktla_ktva(ip);
22571+
22572 /*
22573 * Note: Due to modules and __init, code can
22574 * disappear and change, we need to protect against faulting
22575@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22576 unsigned char old[MCOUNT_INSN_SIZE], *new;
22577 int ret;
22578
22579- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22580+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22581 new = ftrace_call_replace(ip, (unsigned long)func);
22582
22583 /* See comment above by declaration of modifying_ftrace_code */
22584@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22585 /* Also update the regs callback function */
22586 if (!ret) {
22587 ip = (unsigned long)(&ftrace_regs_call);
22588- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22589+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22590 new = ftrace_call_replace(ip, (unsigned long)func);
22591 ret = ftrace_modify_code(ip, old, new);
22592 }
22593@@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22594 * kernel identity mapping to modify code.
22595 */
22596 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22597- ip = (unsigned long)__va(__pa_symbol(ip));
22598+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22599
22600 return probe_kernel_write((void *)ip, val, size);
22601 }
22602@@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
22603 unsigned char replaced[MCOUNT_INSN_SIZE];
22604 unsigned char brk = BREAKPOINT_INSTRUCTION;
22605
22606- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22607+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22608 return -EFAULT;
22609
22610 /* Make sure it is what we expect it to be */
22611@@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22612 return ret;
22613
22614 fail_update:
22615- probe_kernel_write((void *)ip, &old_code[0], 1);
22616+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22617 goto out;
22618 }
22619
22620@@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22621 {
22622 unsigned char code[MCOUNT_INSN_SIZE];
22623
22624+ ip = ktla_ktva(ip);
22625+
22626 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22627 return -EFAULT;
22628
22629diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22630index 1be8e43..d9b9ef6 100644
22631--- a/arch/x86/kernel/head64.c
22632+++ b/arch/x86/kernel/head64.c
22633@@ -67,12 +67,12 @@ again:
22634 pgd = *pgd_p;
22635
22636 /*
22637- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22638- * critical -- __PAGE_OFFSET would point us back into the dynamic
22639+ * The use of __early_va rather than __va here is critical:
22640+ * __va would point us back into the dynamic
22641 * range and we might end up looping forever...
22642 */
22643 if (pgd)
22644- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22645+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22646 else {
22647 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22648 reset_early_page_tables();
22649@@ -82,13 +82,13 @@ again:
22650 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22651 for (i = 0; i < PTRS_PER_PUD; i++)
22652 pud_p[i] = 0;
22653- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22654+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22655 }
22656 pud_p += pud_index(address);
22657 pud = *pud_p;
22658
22659 if (pud)
22660- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22661+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22662 else {
22663 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22664 reset_early_page_tables();
22665@@ -98,7 +98,7 @@ again:
22666 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22667 for (i = 0; i < PTRS_PER_PMD; i++)
22668 pmd_p[i] = 0;
22669- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22670+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22671 }
22672 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22673 pmd_p[pmd_index(address)] = pmd;
22674@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
22675 if (console_loglevel == 10)
22676 early_printk("Kernel alive\n");
22677
22678- clear_page(init_level4_pgt);
22679 /* set init_level4_pgt kernel high mapping*/
22680 init_level4_pgt[511] = early_level4_pgt[511];
22681
22682diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22683index 81ba276..30c5411 100644
22684--- a/arch/x86/kernel/head_32.S
22685+++ b/arch/x86/kernel/head_32.S
22686@@ -26,6 +26,12 @@
22687 /* Physical address */
22688 #define pa(X) ((X) - __PAGE_OFFSET)
22689
22690+#ifdef CONFIG_PAX_KERNEXEC
22691+#define ta(X) (X)
22692+#else
22693+#define ta(X) ((X) - __PAGE_OFFSET)
22694+#endif
22695+
22696 /*
22697 * References to members of the new_cpu_data structure.
22698 */
22699@@ -55,11 +61,7 @@
22700 * and small than max_low_pfn, otherwise will waste some page table entries
22701 */
22702
22703-#if PTRS_PER_PMD > 1
22704-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22705-#else
22706-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22707-#endif
22708+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22709
22710 /* Number of possible pages in the lowmem region */
22711 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22712@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22713 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22714
22715 /*
22716+ * Real beginning of normal "text" segment
22717+ */
22718+ENTRY(stext)
22719+ENTRY(_stext)
22720+
22721+/*
22722 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22723 * %esi points to the real-mode code as a 32-bit pointer.
22724 * CS and DS must be 4 GB flat segments, but we don't depend on
22725@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22726 * can.
22727 */
22728 __HEAD
22729+
22730+#ifdef CONFIG_PAX_KERNEXEC
22731+ jmp startup_32
22732+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22733+.fill PAGE_SIZE-5,1,0xcc
22734+#endif
22735+
22736 ENTRY(startup_32)
22737 movl pa(stack_start),%ecx
22738
22739@@ -106,6 +121,59 @@ ENTRY(startup_32)
22740 2:
22741 leal -__PAGE_OFFSET(%ecx),%esp
22742
22743+#ifdef CONFIG_SMP
22744+ movl $pa(cpu_gdt_table),%edi
22745+ movl $__per_cpu_load,%eax
22746+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22747+ rorl $16,%eax
22748+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22749+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22750+ movl $__per_cpu_end - 1,%eax
22751+ subl $__per_cpu_start,%eax
22752+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22753+#endif
22754+
22755+#ifdef CONFIG_PAX_MEMORY_UDEREF
22756+ movl $NR_CPUS,%ecx
22757+ movl $pa(cpu_gdt_table),%edi
22758+1:
22759+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22760+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22761+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22762+ addl $PAGE_SIZE_asm,%edi
22763+ loop 1b
22764+#endif
22765+
22766+#ifdef CONFIG_PAX_KERNEXEC
22767+ movl $pa(boot_gdt),%edi
22768+ movl $__LOAD_PHYSICAL_ADDR,%eax
22769+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22770+ rorl $16,%eax
22771+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22772+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22773+ rorl $16,%eax
22774+
22775+ ljmp $(__BOOT_CS),$1f
22776+1:
22777+
22778+ movl $NR_CPUS,%ecx
22779+ movl $pa(cpu_gdt_table),%edi
22780+ addl $__PAGE_OFFSET,%eax
22781+1:
22782+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22783+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22784+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22785+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22786+ rorl $16,%eax
22787+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22788+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22789+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22790+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22791+ rorl $16,%eax
22792+ addl $PAGE_SIZE_asm,%edi
22793+ loop 1b
22794+#endif
22795+
22796 /*
22797 * Clear BSS first so that there are no surprises...
22798 */
22799@@ -201,8 +269,11 @@ ENTRY(startup_32)
22800 movl %eax, pa(max_pfn_mapped)
22801
22802 /* Do early initialization of the fixmap area */
22803- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22804- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22805+#ifdef CONFIG_COMPAT_VDSO
22806+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22807+#else
22808+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22809+#endif
22810 #else /* Not PAE */
22811
22812 page_pde_offset = (__PAGE_OFFSET >> 20);
22813@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22814 movl %eax, pa(max_pfn_mapped)
22815
22816 /* Do early initialization of the fixmap area */
22817- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22818- movl %eax,pa(initial_page_table+0xffc)
22819+#ifdef CONFIG_COMPAT_VDSO
22820+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22821+#else
22822+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22823+#endif
22824 #endif
22825
22826 #ifdef CONFIG_PARAVIRT
22827@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22828 cmpl $num_subarch_entries, %eax
22829 jae bad_subarch
22830
22831- movl pa(subarch_entries)(,%eax,4), %eax
22832- subl $__PAGE_OFFSET, %eax
22833- jmp *%eax
22834+ jmp *pa(subarch_entries)(,%eax,4)
22835
22836 bad_subarch:
22837 WEAK(lguest_entry)
22838@@ -261,10 +333,10 @@ WEAK(xen_entry)
22839 __INITDATA
22840
22841 subarch_entries:
22842- .long default_entry /* normal x86/PC */
22843- .long lguest_entry /* lguest hypervisor */
22844- .long xen_entry /* Xen hypervisor */
22845- .long default_entry /* Moorestown MID */
22846+ .long ta(default_entry) /* normal x86/PC */
22847+ .long ta(lguest_entry) /* lguest hypervisor */
22848+ .long ta(xen_entry) /* Xen hypervisor */
22849+ .long ta(default_entry) /* Moorestown MID */
22850 num_subarch_entries = (. - subarch_entries) / 4
22851 .previous
22852 #else
22853@@ -354,6 +426,7 @@ default_entry:
22854 movl pa(mmu_cr4_features),%eax
22855 movl %eax,%cr4
22856
22857+#ifdef CONFIG_X86_PAE
22858 testb $X86_CR4_PAE, %al # check if PAE is enabled
22859 jz enable_paging
22860
22861@@ -382,6 +455,9 @@ default_entry:
22862 /* Make changes effective */
22863 wrmsr
22864
22865+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22866+#endif
22867+
22868 enable_paging:
22869
22870 /*
22871@@ -449,14 +525,20 @@ is486:
22872 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22873 movl %eax,%ss # after changing gdt.
22874
22875- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22876+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22877 movl %eax,%ds
22878 movl %eax,%es
22879
22880 movl $(__KERNEL_PERCPU), %eax
22881 movl %eax,%fs # set this cpu's percpu
22882
22883+#ifdef CONFIG_CC_STACKPROTECTOR
22884 movl $(__KERNEL_STACK_CANARY),%eax
22885+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22886+ movl $(__USER_DS),%eax
22887+#else
22888+ xorl %eax,%eax
22889+#endif
22890 movl %eax,%gs
22891
22892 xorl %eax,%eax # Clear LDT
22893@@ -512,8 +594,11 @@ setup_once:
22894 * relocation. Manually set base address in stack canary
22895 * segment descriptor.
22896 */
22897- movl $gdt_page,%eax
22898+ movl $cpu_gdt_table,%eax
22899 movl $stack_canary,%ecx
22900+#ifdef CONFIG_SMP
22901+ addl $__per_cpu_load,%ecx
22902+#endif
22903 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22904 shrl $16, %ecx
22905 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22906@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22907 /* This is global to keep gas from relaxing the jumps */
22908 ENTRY(early_idt_handler)
22909 cld
22910- cmpl $2,%ss:early_recursion_flag
22911+ cmpl $1,%ss:early_recursion_flag
22912 je hlt_loop
22913 incl %ss:early_recursion_flag
22914
22915@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22916 pushl (20+6*4)(%esp) /* trapno */
22917 pushl $fault_msg
22918 call printk
22919-#endif
22920 call dump_stack
22921+#endif
22922 hlt_loop:
22923 hlt
22924 jmp hlt_loop
22925@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22926 /* This is the default interrupt "handler" :-) */
22927 ALIGN
22928 ignore_int:
22929- cld
22930 #ifdef CONFIG_PRINTK
22931+ cmpl $2,%ss:early_recursion_flag
22932+ je hlt_loop
22933+ incl %ss:early_recursion_flag
22934+ cld
22935 pushl %eax
22936 pushl %ecx
22937 pushl %edx
22938@@ -612,9 +700,6 @@ ignore_int:
22939 movl $(__KERNEL_DS),%eax
22940 movl %eax,%ds
22941 movl %eax,%es
22942- cmpl $2,early_recursion_flag
22943- je hlt_loop
22944- incl early_recursion_flag
22945 pushl 16(%esp)
22946 pushl 24(%esp)
22947 pushl 32(%esp)
22948@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22949 /*
22950 * BSS section
22951 */
22952-__PAGE_ALIGNED_BSS
22953- .align PAGE_SIZE
22954 #ifdef CONFIG_X86_PAE
22955+.section .initial_pg_pmd,"a",@progbits
22956 initial_pg_pmd:
22957 .fill 1024*KPMDS,4,0
22958 #else
22959+.section .initial_page_table,"a",@progbits
22960 ENTRY(initial_page_table)
22961 .fill 1024,4,0
22962 #endif
22963+.section .initial_pg_fixmap,"a",@progbits
22964 initial_pg_fixmap:
22965 .fill 1024,4,0
22966+.section .empty_zero_page,"a",@progbits
22967 ENTRY(empty_zero_page)
22968 .fill 4096,1,0
22969+.section .swapper_pg_dir,"a",@progbits
22970 ENTRY(swapper_pg_dir)
22971+#ifdef CONFIG_X86_PAE
22972+ .fill 4,8,0
22973+#else
22974 .fill 1024,4,0
22975+#endif
22976
22977 /*
22978 * This starts the data section.
22979 */
22980 #ifdef CONFIG_X86_PAE
22981-__PAGE_ALIGNED_DATA
22982- /* Page-aligned for the benefit of paravirt? */
22983- .align PAGE_SIZE
22984+.section .initial_page_table,"a",@progbits
22985 ENTRY(initial_page_table)
22986 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22987 # if KPMDS == 3
22988@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22989 # error "Kernel PMDs should be 1, 2 or 3"
22990 # endif
22991 .align PAGE_SIZE /* needs to be page-sized too */
22992+
22993+#ifdef CONFIG_PAX_PER_CPU_PGD
22994+ENTRY(cpu_pgd)
22995+ .rept 2*NR_CPUS
22996+ .fill 4,8,0
22997+ .endr
22998+#endif
22999+
23000 #endif
23001
23002 .data
23003 .balign 4
23004 ENTRY(stack_start)
23005- .long init_thread_union+THREAD_SIZE
23006+ .long init_thread_union+THREAD_SIZE-8
23007
23008 __INITRODATA
23009 int_msg:
23010@@ -722,7 +820,7 @@ fault_msg:
23011 * segment size, and 32-bit linear address value:
23012 */
23013
23014- .data
23015+.section .rodata,"a",@progbits
23016 .globl boot_gdt_descr
23017 .globl idt_descr
23018
23019@@ -731,7 +829,7 @@ fault_msg:
23020 .word 0 # 32 bit align gdt_desc.address
23021 boot_gdt_descr:
23022 .word __BOOT_DS+7
23023- .long boot_gdt - __PAGE_OFFSET
23024+ .long pa(boot_gdt)
23025
23026 .word 0 # 32-bit align idt_desc.address
23027 idt_descr:
23028@@ -742,7 +840,7 @@ idt_descr:
23029 .word 0 # 32 bit align gdt_desc.address
23030 ENTRY(early_gdt_descr)
23031 .word GDT_ENTRIES*8-1
23032- .long gdt_page /* Overwritten for secondary CPUs */
23033+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23034
23035 /*
23036 * The boot_gdt must mirror the equivalent in setup.S and is
23037@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23038 .align L1_CACHE_BYTES
23039 ENTRY(boot_gdt)
23040 .fill GDT_ENTRY_BOOT_CS,8,0
23041- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23042- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23043+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23044+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23045+
23046+ .align PAGE_SIZE_asm
23047+ENTRY(cpu_gdt_table)
23048+ .rept NR_CPUS
23049+ .quad 0x0000000000000000 /* NULL descriptor */
23050+ .quad 0x0000000000000000 /* 0x0b reserved */
23051+ .quad 0x0000000000000000 /* 0x13 reserved */
23052+ .quad 0x0000000000000000 /* 0x1b reserved */
23053+
23054+#ifdef CONFIG_PAX_KERNEXEC
23055+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23056+#else
23057+ .quad 0x0000000000000000 /* 0x20 unused */
23058+#endif
23059+
23060+ .quad 0x0000000000000000 /* 0x28 unused */
23061+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23062+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23063+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23064+ .quad 0x0000000000000000 /* 0x4b reserved */
23065+ .quad 0x0000000000000000 /* 0x53 reserved */
23066+ .quad 0x0000000000000000 /* 0x5b reserved */
23067+
23068+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23069+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23070+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23071+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23072+
23073+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23074+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23075+
23076+ /*
23077+ * Segments used for calling PnP BIOS have byte granularity.
23078+ * The code segments and data segments have fixed 64k limits,
23079+ * the transfer segment sizes are set at run time.
23080+ */
23081+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23082+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23083+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23084+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23085+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23086+
23087+ /*
23088+ * The APM segments have byte granularity and their bases
23089+ * are set at run time. All have 64k limits.
23090+ */
23091+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23092+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23093+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23094+
23095+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23096+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23097+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23098+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23099+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23100+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23101+
23102+ /* Be sure this is zeroed to avoid false validations in Xen */
23103+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23104+ .endr
23105diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23106index e1aabdb..fee4fee 100644
23107--- a/arch/x86/kernel/head_64.S
23108+++ b/arch/x86/kernel/head_64.S
23109@@ -20,6 +20,8 @@
23110 #include <asm/processor-flags.h>
23111 #include <asm/percpu.h>
23112 #include <asm/nops.h>
23113+#include <asm/cpufeature.h>
23114+#include <asm/alternative-asm.h>
23115
23116 #ifdef CONFIG_PARAVIRT
23117 #include <asm/asm-offsets.h>
23118@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23119 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23120 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23121 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23122+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23123+L3_VMALLOC_START = pud_index(VMALLOC_START)
23124+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23125+L3_VMALLOC_END = pud_index(VMALLOC_END)
23126+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23127+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23128
23129 .text
23130 __HEAD
23131@@ -89,11 +97,24 @@ startup_64:
23132 * Fixup the physical addresses in the page table
23133 */
23134 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23135+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23136+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23137+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23138+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23139+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23140
23141- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23142- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23143+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23144+#ifndef CONFIG_XEN
23145+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23146+#endif
23147+
23148+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23149+
23150+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23151+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23152
23153 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23154+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23155
23156 /*
23157 * Set up the identity mapping for the switchover. These
23158@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
23159 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23160 1:
23161
23162- /* Enable PAE mode and PGE */
23163- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23164+ /* Enable PAE mode and PSE/PGE */
23165+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23166 movq %rcx, %cr4
23167
23168 /* Setup early boot stage 4 level pagetables. */
23169@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
23170 movl $MSR_EFER, %ecx
23171 rdmsr
23172 btsl $_EFER_SCE, %eax /* Enable System Call */
23173- btl $20,%edi /* No Execute supported? */
23174+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23175 jnc 1f
23176 btsl $_EFER_NX, %eax
23177 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23178+#ifndef CONFIG_EFI
23179+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
23180+#endif
23181+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
23182+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
23183+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
23184+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
23185+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
23186+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23187 1: wrmsr /* Make changes effective */
23188
23189 /* Setup cr0 */
23190@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
23191 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23192 * address given in m16:64.
23193 */
23194+ pax_set_fptr_mask
23195 movq initial_code(%rip),%rax
23196 pushq $0 # fake return address to stop unwinder
23197 pushq $__KERNEL_CS # set correct cs
23198@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
23199 call dump_stack
23200 #ifdef CONFIG_KALLSYMS
23201 leaq early_idt_ripmsg(%rip),%rdi
23202- movq 40(%rsp),%rsi # %rip again
23203+ movq 88(%rsp),%rsi # %rip again
23204 call __print_symbol
23205 #endif
23206 #endif /* EARLY_PRINTK */
23207@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
23208 early_recursion_flag:
23209 .long 0
23210
23211+ .section .rodata,"a",@progbits
23212 #ifdef CONFIG_EARLY_PRINTK
23213 early_idt_msg:
23214 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23215@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
23216 NEXT_PAGE(early_dynamic_pgts)
23217 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23218
23219- .data
23220+ .section .rodata,"a",@progbits
23221
23222-#ifndef CONFIG_XEN
23223 NEXT_PAGE(init_level4_pgt)
23224- .fill 512,8,0
23225-#else
23226-NEXT_PAGE(init_level4_pgt)
23227- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23228 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23229 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23230+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23231+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23232+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23233+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23234+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23235+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23236 .org init_level4_pgt + L4_START_KERNEL*8, 0
23237 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23238 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23239
23240+#ifdef CONFIG_PAX_PER_CPU_PGD
23241+NEXT_PAGE(cpu_pgd)
23242+ .rept 2*NR_CPUS
23243+ .fill 512,8,0
23244+ .endr
23245+#endif
23246+
23247 NEXT_PAGE(level3_ident_pgt)
23248 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23249+#ifdef CONFIG_XEN
23250 .fill 511, 8, 0
23251+#else
23252+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23253+ .fill 510,8,0
23254+#endif
23255+
23256+NEXT_PAGE(level3_vmalloc_start_pgt)
23257+ .fill 512,8,0
23258+
23259+NEXT_PAGE(level3_vmalloc_end_pgt)
23260+ .fill 512,8,0
23261+
23262+NEXT_PAGE(level3_vmemmap_pgt)
23263+ .fill L3_VMEMMAP_START,8,0
23264+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23265+
23266 NEXT_PAGE(level2_ident_pgt)
23267- /* Since I easily can, map the first 1G.
23268+ /* Since I easily can, map the first 2G.
23269 * Don't set NX because code runs from these pages.
23270 */
23271- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23272-#endif
23273+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23274
23275 NEXT_PAGE(level3_kernel_pgt)
23276 .fill L3_START_KERNEL,8,0
23277@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
23278 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23279 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23280
23281+NEXT_PAGE(level2_vmemmap_pgt)
23282+ .fill 512,8,0
23283+
23284 NEXT_PAGE(level2_kernel_pgt)
23285 /*
23286 * 512 MB kernel mapping. We spend a full page on this pagetable
23287@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
23288 NEXT_PAGE(level2_fixmap_pgt)
23289 .fill 506,8,0
23290 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23291- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23292- .fill 5,8,0
23293+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23294+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23295+ .fill 4,8,0
23296
23297 NEXT_PAGE(level1_fixmap_pgt)
23298 .fill 512,8,0
23299
23300+NEXT_PAGE(level1_vsyscall_pgt)
23301+ .fill 512,8,0
23302+
23303 #undef PMDS
23304
23305- .data
23306+ .align PAGE_SIZE
23307+ENTRY(cpu_gdt_table)
23308+ .rept NR_CPUS
23309+ .quad 0x0000000000000000 /* NULL descriptor */
23310+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23311+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23312+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23313+ .quad 0x00cffb000000ffff /* __USER32_CS */
23314+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23315+ .quad 0x00affb000000ffff /* __USER_CS */
23316+
23317+#ifdef CONFIG_PAX_KERNEXEC
23318+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23319+#else
23320+ .quad 0x0 /* unused */
23321+#endif
23322+
23323+ .quad 0,0 /* TSS */
23324+ .quad 0,0 /* LDT */
23325+ .quad 0,0,0 /* three TLS descriptors */
23326+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23327+ /* asm/segment.h:GDT_ENTRIES must match this */
23328+
23329+#ifdef CONFIG_PAX_MEMORY_UDEREF
23330+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23331+#else
23332+ .quad 0x0 /* unused */
23333+#endif
23334+
23335+ /* zero the remaining page */
23336+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23337+ .endr
23338+
23339 .align 16
23340 .globl early_gdt_descr
23341 early_gdt_descr:
23342 .word GDT_ENTRIES*8-1
23343 early_gdt_descr_base:
23344- .quad INIT_PER_CPU_VAR(gdt_page)
23345+ .quad cpu_gdt_table
23346
23347 ENTRY(phys_base)
23348 /* This must match the first entry in level2_kernel_pgt */
23349 .quad 0x0000000000000000
23350
23351 #include "../../x86/xen/xen-head.S"
23352-
23353- __PAGE_ALIGNED_BSS
23354+
23355+ .section .rodata,"a",@progbits
23356 NEXT_PAGE(empty_zero_page)
23357 .skip PAGE_SIZE
23358diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23359index 0fa6912..b37438b 100644
23360--- a/arch/x86/kernel/i386_ksyms_32.c
23361+++ b/arch/x86/kernel/i386_ksyms_32.c
23362@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23363 EXPORT_SYMBOL(cmpxchg8b_emu);
23364 #endif
23365
23366+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23367+
23368 /* Networking helper routines. */
23369 EXPORT_SYMBOL(csum_partial_copy_generic);
23370+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23371+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23372
23373 EXPORT_SYMBOL(__get_user_1);
23374 EXPORT_SYMBOL(__get_user_2);
23375@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23376
23377 EXPORT_SYMBOL(csum_partial);
23378 EXPORT_SYMBOL(empty_zero_page);
23379+
23380+#ifdef CONFIG_PAX_KERNEXEC
23381+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23382+#endif
23383+
23384+#ifdef CONFIG_PAX_PER_CPU_PGD
23385+EXPORT_SYMBOL(cpu_pgd);
23386+#endif
23387diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23388index 5d576ab..1403a03 100644
23389--- a/arch/x86/kernel/i387.c
23390+++ b/arch/x86/kernel/i387.c
23391@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23392 static inline bool interrupted_user_mode(void)
23393 {
23394 struct pt_regs *regs = get_irq_regs();
23395- return regs && user_mode_vm(regs);
23396+ return regs && user_mode(regs);
23397 }
23398
23399 /*
23400diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23401index 9a5c460..84868423 100644
23402--- a/arch/x86/kernel/i8259.c
23403+++ b/arch/x86/kernel/i8259.c
23404@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23405 static void make_8259A_irq(unsigned int irq)
23406 {
23407 disable_irq_nosync(irq);
23408- io_apic_irqs &= ~(1<<irq);
23409+ io_apic_irqs &= ~(1UL<<irq);
23410 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23411 i8259A_chip.name);
23412 enable_irq(irq);
23413@@ -209,7 +209,7 @@ spurious_8259A_irq:
23414 "spurious 8259A interrupt: IRQ%d.\n", irq);
23415 spurious_irq_mask |= irqmask;
23416 }
23417- atomic_inc(&irq_err_count);
23418+ atomic_inc_unchecked(&irq_err_count);
23419 /*
23420 * Theoretically we do not have to handle this IRQ,
23421 * but in Linux this does not cause problems and is
23422@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23423 /* (slave's support for AEOI in flat mode is to be investigated) */
23424 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23425
23426+ pax_open_kernel();
23427 if (auto_eoi)
23428 /*
23429 * In AEOI mode we just have to mask the interrupt
23430 * when acking.
23431 */
23432- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23433+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23434 else
23435- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23436+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23437+ pax_close_kernel();
23438
23439 udelay(100); /* wait for 8259A to initialize */
23440
23441diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23442index a979b5b..1d6db75 100644
23443--- a/arch/x86/kernel/io_delay.c
23444+++ b/arch/x86/kernel/io_delay.c
23445@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23446 * Quirk table for systems that misbehave (lock up, etc.) if port
23447 * 0x80 is used:
23448 */
23449-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23450+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23451 {
23452 .callback = dmi_io_delay_0xed_port,
23453 .ident = "Compaq Presario V6000",
23454diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23455index 4ddaf66..49d5c18 100644
23456--- a/arch/x86/kernel/ioport.c
23457+++ b/arch/x86/kernel/ioport.c
23458@@ -6,6 +6,7 @@
23459 #include <linux/sched.h>
23460 #include <linux/kernel.h>
23461 #include <linux/capability.h>
23462+#include <linux/security.h>
23463 #include <linux/errno.h>
23464 #include <linux/types.h>
23465 #include <linux/ioport.h>
23466@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23467 return -EINVAL;
23468 if (turn_on && !capable(CAP_SYS_RAWIO))
23469 return -EPERM;
23470+#ifdef CONFIG_GRKERNSEC_IO
23471+ if (turn_on && grsec_disable_privio) {
23472+ gr_handle_ioperm();
23473+ return -ENODEV;
23474+ }
23475+#endif
23476
23477 /*
23478 * If it's the first ioperm() call in this thread's lifetime, set the
23479@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23480 * because the ->io_bitmap_max value must match the bitmap
23481 * contents:
23482 */
23483- tss = &per_cpu(init_tss, get_cpu());
23484+ tss = init_tss + get_cpu();
23485
23486 if (turn_on)
23487 bitmap_clear(t->io_bitmap_ptr, from, num);
23488@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23489 if (level > old) {
23490 if (!capable(CAP_SYS_RAWIO))
23491 return -EPERM;
23492+#ifdef CONFIG_GRKERNSEC_IO
23493+ if (grsec_disable_privio) {
23494+ gr_handle_iopl();
23495+ return -ENODEV;
23496+ }
23497+#endif
23498 }
23499 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
23500 t->iopl = level << 12;
23501diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23502index 22d0687..e07b2a5 100644
23503--- a/arch/x86/kernel/irq.c
23504+++ b/arch/x86/kernel/irq.c
23505@@ -21,7 +21,7 @@
23506 #define CREATE_TRACE_POINTS
23507 #include <asm/trace/irq_vectors.h>
23508
23509-atomic_t irq_err_count;
23510+atomic_unchecked_t irq_err_count;
23511
23512 /* Function pointer for generic interrupt vector handling */
23513 void (*x86_platform_ipi_callback)(void) = NULL;
23514@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23515 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23516 seq_printf(p, " Machine check polls\n");
23517 #endif
23518- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23519+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23520 #if defined(CONFIG_X86_IO_APIC)
23521- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23522+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23523 #endif
23524 return 0;
23525 }
23526@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23527
23528 u64 arch_irq_stat(void)
23529 {
23530- u64 sum = atomic_read(&irq_err_count);
23531+ u64 sum = atomic_read_unchecked(&irq_err_count);
23532 return sum;
23533 }
23534
23535diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23536index 4186755..784efa0 100644
23537--- a/arch/x86/kernel/irq_32.c
23538+++ b/arch/x86/kernel/irq_32.c
23539@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23540 __asm__ __volatile__("andl %%esp,%0" :
23541 "=r" (sp) : "0" (THREAD_SIZE - 1));
23542
23543- return sp < (sizeof(struct thread_info) + STACK_WARN);
23544+ return sp < STACK_WARN;
23545 }
23546
23547 static void print_stack_overflow(void)
23548@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23549 * per-CPU IRQ handling contexts (thread information and stack)
23550 */
23551 union irq_ctx {
23552- struct thread_info tinfo;
23553- u32 stack[THREAD_SIZE/sizeof(u32)];
23554+ unsigned long previous_esp;
23555+ u32 stack[THREAD_SIZE/sizeof(u32)];
23556 } __attribute__((aligned(THREAD_SIZE)));
23557
23558 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23559@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23560 static inline int
23561 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23562 {
23563- union irq_ctx *curctx, *irqctx;
23564+ union irq_ctx *irqctx;
23565 u32 *isp, arg1, arg2;
23566
23567- curctx = (union irq_ctx *) current_thread_info();
23568 irqctx = __this_cpu_read(hardirq_ctx);
23569
23570 /*
23571@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23572 * handler) we can't do that and just have to keep using the
23573 * current stack (which is the irq stack already after all)
23574 */
23575- if (unlikely(curctx == irqctx))
23576+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23577 return 0;
23578
23579 /* build the stack frame on the IRQ stack */
23580- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23581- irqctx->tinfo.task = curctx->tinfo.task;
23582- irqctx->tinfo.previous_esp = current_stack_pointer;
23583+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23584+ irqctx->previous_esp = current_stack_pointer;
23585
23586- /* Copy the preempt_count so that the [soft]irq checks work. */
23587- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23588+#ifdef CONFIG_PAX_MEMORY_UDEREF
23589+ __set_fs(MAKE_MM_SEG(0));
23590+#endif
23591
23592 if (unlikely(overflow))
23593 call_on_stack(print_stack_overflow, isp);
23594@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23595 : "0" (irq), "1" (desc), "2" (isp),
23596 "D" (desc->handle_irq)
23597 : "memory", "cc", "ecx");
23598+
23599+#ifdef CONFIG_PAX_MEMORY_UDEREF
23600+ __set_fs(current_thread_info()->addr_limit);
23601+#endif
23602+
23603 return 1;
23604 }
23605
23606@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23607 */
23608 void irq_ctx_init(int cpu)
23609 {
23610- union irq_ctx *irqctx;
23611-
23612 if (per_cpu(hardirq_ctx, cpu))
23613 return;
23614
23615- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23616- THREADINFO_GFP,
23617- THREAD_SIZE_ORDER));
23618- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23619- irqctx->tinfo.cpu = cpu;
23620- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23621- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23622+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23623+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23624
23625- per_cpu(hardirq_ctx, cpu) = irqctx;
23626-
23627- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23628- THREADINFO_GFP,
23629- THREAD_SIZE_ORDER));
23630- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23631- irqctx->tinfo.cpu = cpu;
23632- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23633-
23634- per_cpu(softirq_ctx, cpu) = irqctx;
23635+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23636+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23637
23638 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23639 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23640@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23641 asmlinkage void do_softirq(void)
23642 {
23643 unsigned long flags;
23644- struct thread_info *curctx;
23645 union irq_ctx *irqctx;
23646 u32 *isp;
23647
23648@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23649 local_irq_save(flags);
23650
23651 if (local_softirq_pending()) {
23652- curctx = current_thread_info();
23653 irqctx = __this_cpu_read(softirq_ctx);
23654- irqctx->tinfo.task = curctx->task;
23655- irqctx->tinfo.previous_esp = current_stack_pointer;
23656+ irqctx->previous_esp = current_stack_pointer;
23657
23658 /* build the stack frame on the softirq stack */
23659- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23660+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23661+
23662+#ifdef CONFIG_PAX_MEMORY_UDEREF
23663+ __set_fs(MAKE_MM_SEG(0));
23664+#endif
23665
23666 call_on_stack(__do_softirq, isp);
23667+
23668+#ifdef CONFIG_PAX_MEMORY_UDEREF
23669+ __set_fs(current_thread_info()->addr_limit);
23670+#endif
23671+
23672 /*
23673 * Shouldn't happen, we returned above if in_interrupt():
23674 */
23675@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23676 if (unlikely(!desc))
23677 return false;
23678
23679- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23680+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23681 if (unlikely(overflow))
23682 print_stack_overflow();
23683 desc->handle_irq(irq, desc);
23684diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23685index d04d3ec..ea4b374 100644
23686--- a/arch/x86/kernel/irq_64.c
23687+++ b/arch/x86/kernel/irq_64.c
23688@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23689 u64 estack_top, estack_bottom;
23690 u64 curbase = (u64)task_stack_page(current);
23691
23692- if (user_mode_vm(regs))
23693+ if (user_mode(regs))
23694 return;
23695
23696 if (regs->sp >= curbase + sizeof(struct thread_info) +
23697diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
23698index ee11b7d..4df4d0c 100644
23699--- a/arch/x86/kernel/jump_label.c
23700+++ b/arch/x86/kernel/jump_label.c
23701@@ -49,7 +49,7 @@ static void __jump_label_transform(struct jump_entry *entry,
23702 * We are enabling this jump label. If it is not a nop
23703 * then something must have gone wrong.
23704 */
23705- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) != 0))
23706+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5) != 0))
23707 bug_at((void *)entry->code, __LINE__);
23708
23709 code.jump = 0xe9;
23710@@ -64,13 +64,13 @@ static void __jump_label_transform(struct jump_entry *entry,
23711 */
23712 if (init) {
23713 const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
23714- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
23715+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
23716 bug_at((void *)entry->code, __LINE__);
23717 } else {
23718 code.jump = 0xe9;
23719 code.offset = entry->target -
23720 (entry->code + JUMP_LABEL_NOP_SIZE);
23721- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
23722+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
23723 bug_at((void *)entry->code, __LINE__);
23724 }
23725 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
23726diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23727index 836f832..a8bda67 100644
23728--- a/arch/x86/kernel/kgdb.c
23729+++ b/arch/x86/kernel/kgdb.c
23730@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23731 #ifdef CONFIG_X86_32
23732 switch (regno) {
23733 case GDB_SS:
23734- if (!user_mode_vm(regs))
23735+ if (!user_mode(regs))
23736 *(unsigned long *)mem = __KERNEL_DS;
23737 break;
23738 case GDB_SP:
23739- if (!user_mode_vm(regs))
23740+ if (!user_mode(regs))
23741 *(unsigned long *)mem = kernel_stack_pointer(regs);
23742 break;
23743 case GDB_GS:
23744@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23745 bp->attr.bp_addr = breakinfo[breakno].addr;
23746 bp->attr.bp_len = breakinfo[breakno].len;
23747 bp->attr.bp_type = breakinfo[breakno].type;
23748- info->address = breakinfo[breakno].addr;
23749+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23750+ info->address = ktla_ktva(breakinfo[breakno].addr);
23751+ else
23752+ info->address = breakinfo[breakno].addr;
23753 info->len = breakinfo[breakno].len;
23754 info->type = breakinfo[breakno].type;
23755 val = arch_install_hw_breakpoint(bp);
23756@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23757 case 'k':
23758 /* clear the trace bit */
23759 linux_regs->flags &= ~X86_EFLAGS_TF;
23760- atomic_set(&kgdb_cpu_doing_single_step, -1);
23761+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23762
23763 /* set the trace bit if we're stepping */
23764 if (remcomInBuffer[0] == 's') {
23765 linux_regs->flags |= X86_EFLAGS_TF;
23766- atomic_set(&kgdb_cpu_doing_single_step,
23767+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23768 raw_smp_processor_id());
23769 }
23770
23771@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23772
23773 switch (cmd) {
23774 case DIE_DEBUG:
23775- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23776+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23777 if (user_mode(regs))
23778 return single_step_cont(regs, args);
23779 break;
23780@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23781 #endif /* CONFIG_DEBUG_RODATA */
23782
23783 bpt->type = BP_BREAKPOINT;
23784- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23785+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23786 BREAK_INSTR_SIZE);
23787 if (err)
23788 return err;
23789- err = probe_kernel_write((char *)bpt->bpt_addr,
23790+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23791 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23792 #ifdef CONFIG_DEBUG_RODATA
23793 if (!err)
23794@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23795 return -EBUSY;
23796 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23797 BREAK_INSTR_SIZE);
23798- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23799+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23800 if (err)
23801 return err;
23802 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23803@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23804 if (mutex_is_locked(&text_mutex))
23805 goto knl_write;
23806 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23807- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23808+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23809 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23810 goto knl_write;
23811 return err;
23812 knl_write:
23813 #endif /* CONFIG_DEBUG_RODATA */
23814- return probe_kernel_write((char *)bpt->bpt_addr,
23815+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23816 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23817 }
23818
23819diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23820index 79a3f96..6ba030a 100644
23821--- a/arch/x86/kernel/kprobes/core.c
23822+++ b/arch/x86/kernel/kprobes/core.c
23823@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23824 s32 raddr;
23825 } __packed *insn;
23826
23827- insn = (struct __arch_relative_insn *)from;
23828+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23829+
23830+ pax_open_kernel();
23831 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23832 insn->op = op;
23833+ pax_close_kernel();
23834 }
23835
23836 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23837@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23838 kprobe_opcode_t opcode;
23839 kprobe_opcode_t *orig_opcodes = opcodes;
23840
23841- if (search_exception_tables((unsigned long)opcodes))
23842+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23843 return 0; /* Page fault may occur on this address. */
23844
23845 retry:
23846@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23847 * for the first byte, we can recover the original instruction
23848 * from it and kp->opcode.
23849 */
23850- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23851+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23852 buf[0] = kp->opcode;
23853- return (unsigned long)buf;
23854+ return ktva_ktla((unsigned long)buf);
23855 }
23856
23857 /*
23858@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23859 /* Another subsystem puts a breakpoint, failed to recover */
23860 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23861 return 0;
23862+ pax_open_kernel();
23863 memcpy(dest, insn.kaddr, insn.length);
23864+ pax_close_kernel();
23865
23866 #ifdef CONFIG_X86_64
23867 if (insn_rip_relative(&insn)) {
23868@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23869 return 0;
23870 }
23871 disp = (u8 *) dest + insn_offset_displacement(&insn);
23872+ pax_open_kernel();
23873 *(s32 *) disp = (s32) newdisp;
23874+ pax_close_kernel();
23875 }
23876 #endif
23877 return insn.length;
23878@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23879 * nor set current_kprobe, because it doesn't use single
23880 * stepping.
23881 */
23882- regs->ip = (unsigned long)p->ainsn.insn;
23883+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23884 preempt_enable_no_resched();
23885 return;
23886 }
23887@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23888 regs->flags &= ~X86_EFLAGS_IF;
23889 /* single step inline if the instruction is an int3 */
23890 if (p->opcode == BREAKPOINT_INSTRUCTION)
23891- regs->ip = (unsigned long)p->addr;
23892+ regs->ip = ktla_ktva((unsigned long)p->addr);
23893 else
23894- regs->ip = (unsigned long)p->ainsn.insn;
23895+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23896 }
23897
23898 /*
23899@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23900 setup_singlestep(p, regs, kcb, 0);
23901 return 1;
23902 }
23903- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23904+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23905 /*
23906 * The breakpoint instruction was removed right
23907 * after we hit it. Another cpu has removed
23908@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23909 " movq %rax, 152(%rsp)\n"
23910 RESTORE_REGS_STRING
23911 " popfq\n"
23912+#ifdef KERNEXEC_PLUGIN
23913+ " btsq $63,(%rsp)\n"
23914+#endif
23915 #else
23916 " pushf\n"
23917 SAVE_REGS_STRING
23918@@ -779,7 +789,7 @@ static void __kprobes
23919 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23920 {
23921 unsigned long *tos = stack_addr(regs);
23922- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23923+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23924 unsigned long orig_ip = (unsigned long)p->addr;
23925 kprobe_opcode_t *insn = p->ainsn.insn;
23926
23927@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23928 struct die_args *args = data;
23929 int ret = NOTIFY_DONE;
23930
23931- if (args->regs && user_mode_vm(args->regs))
23932+ if (args->regs && user_mode(args->regs))
23933 return ret;
23934
23935 switch (val) {
23936diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23937index 898160b..758cde8 100644
23938--- a/arch/x86/kernel/kprobes/opt.c
23939+++ b/arch/x86/kernel/kprobes/opt.c
23940@@ -79,6 +79,7 @@ found:
23941 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23942 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23943 {
23944+ pax_open_kernel();
23945 #ifdef CONFIG_X86_64
23946 *addr++ = 0x48;
23947 *addr++ = 0xbf;
23948@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23949 *addr++ = 0xb8;
23950 #endif
23951 *(unsigned long *)addr = val;
23952+ pax_close_kernel();
23953 }
23954
23955 asm (
23956@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23957 * Verify if the address gap is in 2GB range, because this uses
23958 * a relative jump.
23959 */
23960- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23961+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23962 if (abs(rel) > 0x7fffffff)
23963 return -ERANGE;
23964
23965@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23966 op->optinsn.size = ret;
23967
23968 /* Copy arch-dep-instance from template */
23969- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23970+ pax_open_kernel();
23971+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23972+ pax_close_kernel();
23973
23974 /* Set probe information */
23975 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23976
23977 /* Set probe function call */
23978- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23979+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23980
23981 /* Set returning jmp instruction at the tail of out-of-line buffer */
23982- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23983+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23984 (u8 *)op->kp.addr + op->optinsn.size);
23985
23986 flush_icache_range((unsigned long) buf,
23987@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
23988 WARN_ON(kprobe_disabled(&op->kp));
23989
23990 /* Backup instructions which will be replaced by jump address */
23991- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23992+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23993 RELATIVE_ADDR_SIZE);
23994
23995 insn_buf[0] = RELATIVEJUMP_OPCODE;
23996@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23997 /* This kprobe is really able to run optimized path. */
23998 op = container_of(p, struct optimized_kprobe, kp);
23999 /* Detour through copied instructions */
24000- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24001+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24002 if (!reenter)
24003 reset_current_kprobe();
24004 preempt_enable_no_resched();
24005diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24006index ebc9873..1b9724b 100644
24007--- a/arch/x86/kernel/ldt.c
24008+++ b/arch/x86/kernel/ldt.c
24009@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24010 if (reload) {
24011 #ifdef CONFIG_SMP
24012 preempt_disable();
24013- load_LDT(pc);
24014+ load_LDT_nolock(pc);
24015 if (!cpumask_equal(mm_cpumask(current->mm),
24016 cpumask_of(smp_processor_id())))
24017 smp_call_function(flush_ldt, current->mm, 1);
24018 preempt_enable();
24019 #else
24020- load_LDT(pc);
24021+ load_LDT_nolock(pc);
24022 #endif
24023 }
24024 if (oldsize) {
24025@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24026 return err;
24027
24028 for (i = 0; i < old->size; i++)
24029- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24030+ write_ldt_entry(new->ldt, i, old->ldt + i);
24031 return 0;
24032 }
24033
24034@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24035 retval = copy_ldt(&mm->context, &old_mm->context);
24036 mutex_unlock(&old_mm->context.lock);
24037 }
24038+
24039+ if (tsk == current) {
24040+ mm->context.vdso = 0;
24041+
24042+#ifdef CONFIG_X86_32
24043+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24044+ mm->context.user_cs_base = 0UL;
24045+ mm->context.user_cs_limit = ~0UL;
24046+
24047+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24048+ cpus_clear(mm->context.cpu_user_cs_mask);
24049+#endif
24050+
24051+#endif
24052+#endif
24053+
24054+ }
24055+
24056 return retval;
24057 }
24058
24059@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24060 }
24061 }
24062
24063+#ifdef CONFIG_PAX_SEGMEXEC
24064+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24065+ error = -EINVAL;
24066+ goto out_unlock;
24067+ }
24068+#endif
24069+
24070 fill_ldt(&ldt, &ldt_info);
24071 if (oldmode)
24072 ldt.avl = 0;
24073diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24074index 5b19e4d..6476a76 100644
24075--- a/arch/x86/kernel/machine_kexec_32.c
24076+++ b/arch/x86/kernel/machine_kexec_32.c
24077@@ -26,7 +26,7 @@
24078 #include <asm/cacheflush.h>
24079 #include <asm/debugreg.h>
24080
24081-static void set_idt(void *newidt, __u16 limit)
24082+static void set_idt(struct desc_struct *newidt, __u16 limit)
24083 {
24084 struct desc_ptr curidt;
24085
24086@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24087 }
24088
24089
24090-static void set_gdt(void *newgdt, __u16 limit)
24091+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24092 {
24093 struct desc_ptr curgdt;
24094
24095@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24096 }
24097
24098 control_page = page_address(image->control_code_page);
24099- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24100+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24101
24102 relocate_kernel_ptr = control_page;
24103 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24104diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24105index 15c9876..0a43909 100644
24106--- a/arch/x86/kernel/microcode_core.c
24107+++ b/arch/x86/kernel/microcode_core.c
24108@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24109 return NOTIFY_OK;
24110 }
24111
24112-static struct notifier_block __refdata mc_cpu_notifier = {
24113+static struct notifier_block mc_cpu_notifier = {
24114 .notifier_call = mc_cpu_callback,
24115 };
24116
24117diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24118index 5fb2ceb..3ae90bb 100644
24119--- a/arch/x86/kernel/microcode_intel.c
24120+++ b/arch/x86/kernel/microcode_intel.c
24121@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24122
24123 static int get_ucode_user(void *to, const void *from, size_t n)
24124 {
24125- return copy_from_user(to, from, n);
24126+ return copy_from_user(to, (const void __force_user *)from, n);
24127 }
24128
24129 static enum ucode_state
24130 request_microcode_user(int cpu, const void __user *buf, size_t size)
24131 {
24132- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24133+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24134 }
24135
24136 static void microcode_fini_cpu(int cpu)
24137diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24138index 216a4d7..228255a 100644
24139--- a/arch/x86/kernel/module.c
24140+++ b/arch/x86/kernel/module.c
24141@@ -43,15 +43,60 @@ do { \
24142 } while (0)
24143 #endif
24144
24145-void *module_alloc(unsigned long size)
24146+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24147 {
24148- if (PAGE_ALIGN(size) > MODULES_LEN)
24149+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24150 return NULL;
24151 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24152- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24153+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24154 -1, __builtin_return_address(0));
24155 }
24156
24157+void *module_alloc(unsigned long size)
24158+{
24159+
24160+#ifdef CONFIG_PAX_KERNEXEC
24161+ return __module_alloc(size, PAGE_KERNEL);
24162+#else
24163+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24164+#endif
24165+
24166+}
24167+
24168+#ifdef CONFIG_PAX_KERNEXEC
24169+#ifdef CONFIG_X86_32
24170+void *module_alloc_exec(unsigned long size)
24171+{
24172+ struct vm_struct *area;
24173+
24174+ if (size == 0)
24175+ return NULL;
24176+
24177+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24178+ return area ? area->addr : NULL;
24179+}
24180+EXPORT_SYMBOL(module_alloc_exec);
24181+
24182+void module_free_exec(struct module *mod, void *module_region)
24183+{
24184+ vunmap(module_region);
24185+}
24186+EXPORT_SYMBOL(module_free_exec);
24187+#else
24188+void module_free_exec(struct module *mod, void *module_region)
24189+{
24190+ module_free(mod, module_region);
24191+}
24192+EXPORT_SYMBOL(module_free_exec);
24193+
24194+void *module_alloc_exec(unsigned long size)
24195+{
24196+ return __module_alloc(size, PAGE_KERNEL_RX);
24197+}
24198+EXPORT_SYMBOL(module_alloc_exec);
24199+#endif
24200+#endif
24201+
24202 #ifdef CONFIG_X86_32
24203 int apply_relocate(Elf32_Shdr *sechdrs,
24204 const char *strtab,
24205@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24206 unsigned int i;
24207 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24208 Elf32_Sym *sym;
24209- uint32_t *location;
24210+ uint32_t *plocation, location;
24211
24212 DEBUGP("Applying relocate section %u to %u\n",
24213 relsec, sechdrs[relsec].sh_info);
24214 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24215 /* This is where to make the change */
24216- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24217- + rel[i].r_offset;
24218+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24219+ location = (uint32_t)plocation;
24220+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24221+ plocation = ktla_ktva((void *)plocation);
24222 /* This is the symbol it is referring to. Note that all
24223 undefined symbols have been resolved. */
24224 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24225@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24226 switch (ELF32_R_TYPE(rel[i].r_info)) {
24227 case R_386_32:
24228 /* We add the value into the location given */
24229- *location += sym->st_value;
24230+ pax_open_kernel();
24231+ *plocation += sym->st_value;
24232+ pax_close_kernel();
24233 break;
24234 case R_386_PC32:
24235 /* Add the value, subtract its position */
24236- *location += sym->st_value - (uint32_t)location;
24237+ pax_open_kernel();
24238+ *plocation += sym->st_value - location;
24239+ pax_close_kernel();
24240 break;
24241 default:
24242 pr_err("%s: Unknown relocation: %u\n",
24243@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24244 case R_X86_64_NONE:
24245 break;
24246 case R_X86_64_64:
24247+ pax_open_kernel();
24248 *(u64 *)loc = val;
24249+ pax_close_kernel();
24250 break;
24251 case R_X86_64_32:
24252+ pax_open_kernel();
24253 *(u32 *)loc = val;
24254+ pax_close_kernel();
24255 if (val != *(u32 *)loc)
24256 goto overflow;
24257 break;
24258 case R_X86_64_32S:
24259+ pax_open_kernel();
24260 *(s32 *)loc = val;
24261+ pax_close_kernel();
24262 if ((s64)val != *(s32 *)loc)
24263 goto overflow;
24264 break;
24265 case R_X86_64_PC32:
24266 val -= (u64)loc;
24267+ pax_open_kernel();
24268 *(u32 *)loc = val;
24269+ pax_close_kernel();
24270+
24271 #if 0
24272 if ((s64)val != *(s32 *)loc)
24273 goto overflow;
24274diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24275index 88458fa..349f7a4 100644
24276--- a/arch/x86/kernel/msr.c
24277+++ b/arch/x86/kernel/msr.c
24278@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24279 return notifier_from_errno(err);
24280 }
24281
24282-static struct notifier_block __refdata msr_class_cpu_notifier = {
24283+static struct notifier_block msr_class_cpu_notifier = {
24284 .notifier_call = msr_class_cpu_callback,
24285 };
24286
24287diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24288index 6fcb49c..5b3f4ff 100644
24289--- a/arch/x86/kernel/nmi.c
24290+++ b/arch/x86/kernel/nmi.c
24291@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24292 return handled;
24293 }
24294
24295-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24296+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24297 {
24298 struct nmi_desc *desc = nmi_to_desc(type);
24299 unsigned long flags;
24300@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24301 * event confuses some handlers (kdump uses this flag)
24302 */
24303 if (action->flags & NMI_FLAG_FIRST)
24304- list_add_rcu(&action->list, &desc->head);
24305+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24306 else
24307- list_add_tail_rcu(&action->list, &desc->head);
24308+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24309
24310 spin_unlock_irqrestore(&desc->lock, flags);
24311 return 0;
24312@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24313 if (!strcmp(n->name, name)) {
24314 WARN(in_nmi(),
24315 "Trying to free NMI (%s) from NMI context!\n", n->name);
24316- list_del_rcu(&n->list);
24317+ pax_list_del_rcu((struct list_head *)&n->list);
24318 break;
24319 }
24320 }
24321@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24322 dotraplinkage notrace __kprobes void
24323 do_nmi(struct pt_regs *regs, long error_code)
24324 {
24325+
24326+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24327+ if (!user_mode(regs)) {
24328+ unsigned long cs = regs->cs & 0xFFFF;
24329+ unsigned long ip = ktva_ktla(regs->ip);
24330+
24331+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24332+ regs->ip = ip;
24333+ }
24334+#endif
24335+
24336 nmi_nesting_preprocess(regs);
24337
24338 nmi_enter();
24339diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24340index 6d9582e..f746287 100644
24341--- a/arch/x86/kernel/nmi_selftest.c
24342+++ b/arch/x86/kernel/nmi_selftest.c
24343@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24344 {
24345 /* trap all the unknown NMIs we may generate */
24346 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24347- __initdata);
24348+ __initconst);
24349 }
24350
24351 static void __init cleanup_nmi_testsuite(void)
24352@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24353 unsigned long timeout;
24354
24355 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24356- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24357+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24358 nmi_fail = FAILURE;
24359 return;
24360 }
24361diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24362index bbb6c73..24a58ef 100644
24363--- a/arch/x86/kernel/paravirt-spinlocks.c
24364+++ b/arch/x86/kernel/paravirt-spinlocks.c
24365@@ -8,7 +8,7 @@
24366
24367 #include <asm/paravirt.h>
24368
24369-struct pv_lock_ops pv_lock_ops = {
24370+struct pv_lock_ops pv_lock_ops __read_only = {
24371 #ifdef CONFIG_SMP
24372 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
24373 .unlock_kick = paravirt_nop,
24374diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24375index 1b10af8..0b58cbc 100644
24376--- a/arch/x86/kernel/paravirt.c
24377+++ b/arch/x86/kernel/paravirt.c
24378@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24379 {
24380 return x;
24381 }
24382+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24383+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24384+#endif
24385
24386 void __init default_banner(void)
24387 {
24388@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24389 if (opfunc == NULL)
24390 /* If there's no function, patch it with a ud2a (BUG) */
24391 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24392- else if (opfunc == _paravirt_nop)
24393+ else if (opfunc == (void *)_paravirt_nop)
24394 /* If the operation is a nop, then nop the callsite */
24395 ret = paravirt_patch_nop();
24396
24397 /* identity functions just return their single argument */
24398- else if (opfunc == _paravirt_ident_32)
24399+ else if (opfunc == (void *)_paravirt_ident_32)
24400 ret = paravirt_patch_ident_32(insnbuf, len);
24401- else if (opfunc == _paravirt_ident_64)
24402+ else if (opfunc == (void *)_paravirt_ident_64)
24403 ret = paravirt_patch_ident_64(insnbuf, len);
24404+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24405+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24406+ ret = paravirt_patch_ident_64(insnbuf, len);
24407+#endif
24408
24409 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24410 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24411@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24412 if (insn_len > len || start == NULL)
24413 insn_len = len;
24414 else
24415- memcpy(insnbuf, start, insn_len);
24416+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24417
24418 return insn_len;
24419 }
24420@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24421 return this_cpu_read(paravirt_lazy_mode);
24422 }
24423
24424-struct pv_info pv_info = {
24425+struct pv_info pv_info __read_only = {
24426 .name = "bare hardware",
24427 .paravirt_enabled = 0,
24428 .kernel_rpl = 0,
24429@@ -310,16 +317,16 @@ struct pv_info pv_info = {
24430 #endif
24431 };
24432
24433-struct pv_init_ops pv_init_ops = {
24434+struct pv_init_ops pv_init_ops __read_only = {
24435 .patch = native_patch,
24436 };
24437
24438-struct pv_time_ops pv_time_ops = {
24439+struct pv_time_ops pv_time_ops __read_only = {
24440 .sched_clock = native_sched_clock,
24441 .steal_clock = native_steal_clock,
24442 };
24443
24444-__visible struct pv_irq_ops pv_irq_ops = {
24445+__visible struct pv_irq_ops pv_irq_ops __read_only = {
24446 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24447 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24448 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24449@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
24450 #endif
24451 };
24452
24453-__visible struct pv_cpu_ops pv_cpu_ops = {
24454+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
24455 .cpuid = native_cpuid,
24456 .get_debugreg = native_get_debugreg,
24457 .set_debugreg = native_set_debugreg,
24458@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
24459 .end_context_switch = paravirt_nop,
24460 };
24461
24462-struct pv_apic_ops pv_apic_ops = {
24463+struct pv_apic_ops pv_apic_ops __read_only= {
24464 #ifdef CONFIG_X86_LOCAL_APIC
24465 .startup_ipi_hook = paravirt_nop,
24466 #endif
24467 };
24468
24469-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24470+#ifdef CONFIG_X86_32
24471+#ifdef CONFIG_X86_PAE
24472+/* 64-bit pagetable entries */
24473+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24474+#else
24475 /* 32-bit pagetable entries */
24476 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24477+#endif
24478 #else
24479 /* 64-bit pagetable entries */
24480 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24481 #endif
24482
24483-struct pv_mmu_ops pv_mmu_ops = {
24484+struct pv_mmu_ops pv_mmu_ops __read_only = {
24485
24486 .read_cr2 = native_read_cr2,
24487 .write_cr2 = native_write_cr2,
24488@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24489 .make_pud = PTE_IDENT,
24490
24491 .set_pgd = native_set_pgd,
24492+ .set_pgd_batched = native_set_pgd_batched,
24493 #endif
24494 #endif /* PAGETABLE_LEVELS >= 3 */
24495
24496@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24497 },
24498
24499 .set_fixmap = native_set_fixmap,
24500+
24501+#ifdef CONFIG_PAX_KERNEXEC
24502+ .pax_open_kernel = native_pax_open_kernel,
24503+ .pax_close_kernel = native_pax_close_kernel,
24504+#endif
24505+
24506 };
24507
24508 EXPORT_SYMBOL_GPL(pv_time_ops);
24509diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24510index 299d493..2ccb0ee 100644
24511--- a/arch/x86/kernel/pci-calgary_64.c
24512+++ b/arch/x86/kernel/pci-calgary_64.c
24513@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24514 tce_space = be64_to_cpu(readq(target));
24515 tce_space = tce_space & TAR_SW_BITS;
24516
24517- tce_space = tce_space & (~specified_table_size);
24518+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24519 info->tce_space = (u64 *)__va(tce_space);
24520 }
24521 }
24522diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24523index 35ccf75..7a15747 100644
24524--- a/arch/x86/kernel/pci-iommu_table.c
24525+++ b/arch/x86/kernel/pci-iommu_table.c
24526@@ -2,7 +2,7 @@
24527 #include <asm/iommu_table.h>
24528 #include <linux/string.h>
24529 #include <linux/kallsyms.h>
24530-
24531+#include <linux/sched.h>
24532
24533 #define DEBUG 1
24534
24535diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24536index 6c483ba..d10ce2f 100644
24537--- a/arch/x86/kernel/pci-swiotlb.c
24538+++ b/arch/x86/kernel/pci-swiotlb.c
24539@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24540 void *vaddr, dma_addr_t dma_addr,
24541 struct dma_attrs *attrs)
24542 {
24543- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24544+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24545 }
24546
24547 static struct dma_map_ops swiotlb_dma_ops = {
24548diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24549index 3fb8d95..254dc51 100644
24550--- a/arch/x86/kernel/process.c
24551+++ b/arch/x86/kernel/process.c
24552@@ -36,7 +36,8 @@
24553 * section. Since TSS's are completely CPU-local, we want them
24554 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24555 */
24556-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24557+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24558+EXPORT_SYMBOL(init_tss);
24559
24560 #ifdef CONFIG_X86_64
24561 static DEFINE_PER_CPU(unsigned char, is_idle);
24562@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24563 task_xstate_cachep =
24564 kmem_cache_create("task_xstate", xstate_size,
24565 __alignof__(union thread_xstate),
24566- SLAB_PANIC | SLAB_NOTRACK, NULL);
24567+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24568 }
24569
24570 /*
24571@@ -105,7 +106,7 @@ void exit_thread(void)
24572 unsigned long *bp = t->io_bitmap_ptr;
24573
24574 if (bp) {
24575- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24576+ struct tss_struct *tss = init_tss + get_cpu();
24577
24578 t->io_bitmap_ptr = NULL;
24579 clear_thread_flag(TIF_IO_BITMAP);
24580@@ -125,6 +126,9 @@ void flush_thread(void)
24581 {
24582 struct task_struct *tsk = current;
24583
24584+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24585+ loadsegment(gs, 0);
24586+#endif
24587 flush_ptrace_hw_breakpoint(tsk);
24588 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24589 drop_init_fpu(tsk);
24590@@ -271,7 +275,7 @@ static void __exit_idle(void)
24591 void exit_idle(void)
24592 {
24593 /* idle loop has pid 0 */
24594- if (current->pid)
24595+ if (task_pid_nr(current))
24596 return;
24597 __exit_idle();
24598 }
24599@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24600 return ret;
24601 }
24602 #endif
24603-void stop_this_cpu(void *dummy)
24604+__noreturn void stop_this_cpu(void *dummy)
24605 {
24606 local_irq_disable();
24607 /*
24608@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24609 }
24610 early_param("idle", idle_setup);
24611
24612-unsigned long arch_align_stack(unsigned long sp)
24613+#ifdef CONFIG_PAX_RANDKSTACK
24614+void pax_randomize_kstack(struct pt_regs *regs)
24615 {
24616- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24617- sp -= get_random_int() % 8192;
24618- return sp & ~0xf;
24619-}
24620+ struct thread_struct *thread = &current->thread;
24621+ unsigned long time;
24622
24623-unsigned long arch_randomize_brk(struct mm_struct *mm)
24624-{
24625- unsigned long range_end = mm->brk + 0x02000000;
24626- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24627-}
24628+ if (!randomize_va_space)
24629+ return;
24630+
24631+ if (v8086_mode(regs))
24632+ return;
24633
24634+ rdtscl(time);
24635+
24636+ /* P4 seems to return a 0 LSB, ignore it */
24637+#ifdef CONFIG_MPENTIUM4
24638+ time &= 0x3EUL;
24639+ time <<= 2;
24640+#elif defined(CONFIG_X86_64)
24641+ time &= 0xFUL;
24642+ time <<= 4;
24643+#else
24644+ time &= 0x1FUL;
24645+ time <<= 3;
24646+#endif
24647+
24648+ thread->sp0 ^= time;
24649+ load_sp0(init_tss + smp_processor_id(), thread);
24650+
24651+#ifdef CONFIG_X86_64
24652+ this_cpu_write(kernel_stack, thread->sp0);
24653+#endif
24654+}
24655+#endif
24656diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24657index 884f98f..ec23e04 100644
24658--- a/arch/x86/kernel/process_32.c
24659+++ b/arch/x86/kernel/process_32.c
24660@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24661 unsigned long thread_saved_pc(struct task_struct *tsk)
24662 {
24663 return ((unsigned long *)tsk->thread.sp)[3];
24664+//XXX return tsk->thread.eip;
24665 }
24666
24667 void __show_regs(struct pt_regs *regs, int all)
24668@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24669 unsigned long sp;
24670 unsigned short ss, gs;
24671
24672- if (user_mode_vm(regs)) {
24673+ if (user_mode(regs)) {
24674 sp = regs->sp;
24675 ss = regs->ss & 0xffff;
24676- gs = get_user_gs(regs);
24677 } else {
24678 sp = kernel_stack_pointer(regs);
24679 savesegment(ss, ss);
24680- savesegment(gs, gs);
24681 }
24682+ gs = get_user_gs(regs);
24683
24684 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24685 (u16)regs->cs, regs->ip, regs->flags,
24686- smp_processor_id());
24687+ raw_smp_processor_id());
24688 print_symbol("EIP is at %s\n", regs->ip);
24689
24690 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24691@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24692 int copy_thread(unsigned long clone_flags, unsigned long sp,
24693 unsigned long arg, struct task_struct *p)
24694 {
24695- struct pt_regs *childregs = task_pt_regs(p);
24696+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24697 struct task_struct *tsk;
24698 int err;
24699
24700 p->thread.sp = (unsigned long) childregs;
24701 p->thread.sp0 = (unsigned long) (childregs+1);
24702+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24703
24704 if (unlikely(p->flags & PF_KTHREAD)) {
24705 /* kernel thread */
24706 memset(childregs, 0, sizeof(struct pt_regs));
24707 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24708- task_user_gs(p) = __KERNEL_STACK_CANARY;
24709- childregs->ds = __USER_DS;
24710- childregs->es = __USER_DS;
24711+ savesegment(gs, childregs->gs);
24712+ childregs->ds = __KERNEL_DS;
24713+ childregs->es = __KERNEL_DS;
24714 childregs->fs = __KERNEL_PERCPU;
24715 childregs->bx = sp; /* function */
24716 childregs->bp = arg;
24717@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24718 struct thread_struct *prev = &prev_p->thread,
24719 *next = &next_p->thread;
24720 int cpu = smp_processor_id();
24721- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24722+ struct tss_struct *tss = init_tss + cpu;
24723 fpu_switch_t fpu;
24724
24725 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24726@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24727 */
24728 lazy_save_gs(prev->gs);
24729
24730+#ifdef CONFIG_PAX_MEMORY_UDEREF
24731+ __set_fs(task_thread_info(next_p)->addr_limit);
24732+#endif
24733+
24734 /*
24735 * Load the per-thread Thread-Local Storage descriptor.
24736 */
24737@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24738 */
24739 arch_end_context_switch(next_p);
24740
24741+ this_cpu_write(current_task, next_p);
24742+ this_cpu_write(current_tinfo, &next_p->tinfo);
24743+
24744 /*
24745 * Restore %gs if needed (which is common)
24746 */
24747@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24748
24749 switch_fpu_finish(next_p, fpu);
24750
24751- this_cpu_write(current_task, next_p);
24752-
24753 return prev_p;
24754 }
24755
24756@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24757 } while (count++ < 16);
24758 return 0;
24759 }
24760-
24761diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24762index bb1dc51..08dda7f 100644
24763--- a/arch/x86/kernel/process_64.c
24764+++ b/arch/x86/kernel/process_64.c
24765@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24766 struct pt_regs *childregs;
24767 struct task_struct *me = current;
24768
24769- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24770+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24771 childregs = task_pt_regs(p);
24772 p->thread.sp = (unsigned long) childregs;
24773 p->thread.usersp = me->thread.usersp;
24774+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24775 set_tsk_thread_flag(p, TIF_FORK);
24776 p->fpu_counter = 0;
24777 p->thread.io_bitmap_ptr = NULL;
24778@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24779 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24780 savesegment(es, p->thread.es);
24781 savesegment(ds, p->thread.ds);
24782+ savesegment(ss, p->thread.ss);
24783+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24784 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24785
24786 if (unlikely(p->flags & PF_KTHREAD)) {
24787@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24788 struct thread_struct *prev = &prev_p->thread;
24789 struct thread_struct *next = &next_p->thread;
24790 int cpu = smp_processor_id();
24791- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24792+ struct tss_struct *tss = init_tss + cpu;
24793 unsigned fsindex, gsindex;
24794 fpu_switch_t fpu;
24795
24796@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24797 if (unlikely(next->ds | prev->ds))
24798 loadsegment(ds, next->ds);
24799
24800+ savesegment(ss, prev->ss);
24801+ if (unlikely(next->ss != prev->ss))
24802+ loadsegment(ss, next->ss);
24803
24804 /* We must save %fs and %gs before load_TLS() because
24805 * %fs and %gs may be cleared by load_TLS().
24806@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24807 prev->usersp = this_cpu_read(old_rsp);
24808 this_cpu_write(old_rsp, next->usersp);
24809 this_cpu_write(current_task, next_p);
24810+ this_cpu_write(current_tinfo, &next_p->tinfo);
24811
24812- this_cpu_write(kernel_stack,
24813- (unsigned long)task_stack_page(next_p) +
24814- THREAD_SIZE - KERNEL_STACK_OFFSET);
24815+ this_cpu_write(kernel_stack, next->sp0);
24816
24817 /*
24818 * Now maybe reload the debug registers and handle I/O bitmaps
24819@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24820 if (!p || p == current || p->state == TASK_RUNNING)
24821 return 0;
24822 stack = (unsigned long)task_stack_page(p);
24823- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24824+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24825 return 0;
24826 fp = *(u64 *)(p->thread.sp);
24827 do {
24828- if (fp < (unsigned long)stack ||
24829- fp >= (unsigned long)stack+THREAD_SIZE)
24830+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24831 return 0;
24832 ip = *(u64 *)(fp+8);
24833 if (!in_sched_functions(ip))
24834diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24835index 7461f50..1334029 100644
24836--- a/arch/x86/kernel/ptrace.c
24837+++ b/arch/x86/kernel/ptrace.c
24838@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24839 {
24840 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24841 unsigned long sp = (unsigned long)&regs->sp;
24842- struct thread_info *tinfo;
24843
24844- if (context == (sp & ~(THREAD_SIZE - 1)))
24845+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24846 return sp;
24847
24848- tinfo = (struct thread_info *)context;
24849- if (tinfo->previous_esp)
24850- return tinfo->previous_esp;
24851+ sp = *(unsigned long *)context;
24852+ if (sp)
24853+ return sp;
24854
24855 return (unsigned long)regs;
24856 }
24857@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24858 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24859 {
24860 int i;
24861- int dr7 = 0;
24862+ unsigned long dr7 = 0;
24863 struct arch_hw_breakpoint *info;
24864
24865 for (i = 0; i < HBP_NUM; i++) {
24866@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24867 unsigned long addr, unsigned long data)
24868 {
24869 int ret;
24870- unsigned long __user *datap = (unsigned long __user *)data;
24871+ unsigned long __user *datap = (__force unsigned long __user *)data;
24872
24873 switch (request) {
24874 /* read the word at location addr in the USER area. */
24875@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24876 if ((int) addr < 0)
24877 return -EIO;
24878 ret = do_get_thread_area(child, addr,
24879- (struct user_desc __user *)data);
24880+ (__force struct user_desc __user *) data);
24881 break;
24882
24883 case PTRACE_SET_THREAD_AREA:
24884 if ((int) addr < 0)
24885 return -EIO;
24886 ret = do_set_thread_area(child, addr,
24887- (struct user_desc __user *)data, 0);
24888+ (__force struct user_desc __user *) data, 0);
24889 break;
24890 #endif
24891
24892@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24893
24894 #ifdef CONFIG_X86_64
24895
24896-static struct user_regset x86_64_regsets[] __read_mostly = {
24897+static user_regset_no_const x86_64_regsets[] __read_only = {
24898 [REGSET_GENERAL] = {
24899 .core_note_type = NT_PRSTATUS,
24900 .n = sizeof(struct user_regs_struct) / sizeof(long),
24901@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24902 #endif /* CONFIG_X86_64 */
24903
24904 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24905-static struct user_regset x86_32_regsets[] __read_mostly = {
24906+static user_regset_no_const x86_32_regsets[] __read_only = {
24907 [REGSET_GENERAL] = {
24908 .core_note_type = NT_PRSTATUS,
24909 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24910@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24911 */
24912 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24913
24914-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24915+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24916 {
24917 #ifdef CONFIG_X86_64
24918 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24919@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24920 memset(info, 0, sizeof(*info));
24921 info->si_signo = SIGTRAP;
24922 info->si_code = si_code;
24923- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24924+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24925 }
24926
24927 void user_single_step_siginfo(struct task_struct *tsk,
24928@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24929 # define IS_IA32 0
24930 #endif
24931
24932+#ifdef CONFIG_GRKERNSEC_SETXID
24933+extern void gr_delayed_cred_worker(void);
24934+#endif
24935+
24936 /*
24937 * We must return the syscall number to actually look up in the table.
24938 * This can be -1L to skip running any syscall at all.
24939@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24940
24941 user_exit();
24942
24943+#ifdef CONFIG_GRKERNSEC_SETXID
24944+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24945+ gr_delayed_cred_worker();
24946+#endif
24947+
24948 /*
24949 * If we stepped into a sysenter/syscall insn, it trapped in
24950 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24951@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24952 */
24953 user_exit();
24954
24955+#ifdef CONFIG_GRKERNSEC_SETXID
24956+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24957+ gr_delayed_cred_worker();
24958+#endif
24959+
24960 audit_syscall_exit(regs);
24961
24962 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24963diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24964index a16bae3..1f65f25 100644
24965--- a/arch/x86/kernel/pvclock.c
24966+++ b/arch/x86/kernel/pvclock.c
24967@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24968 return pv_tsc_khz;
24969 }
24970
24971-static atomic64_t last_value = ATOMIC64_INIT(0);
24972+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24973
24974 void pvclock_resume(void)
24975 {
24976- atomic64_set(&last_value, 0);
24977+ atomic64_set_unchecked(&last_value, 0);
24978 }
24979
24980 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24981@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24982 * updating at the same time, and one of them could be slightly behind,
24983 * making the assumption that last_value always go forward fail to hold.
24984 */
24985- last = atomic64_read(&last_value);
24986+ last = atomic64_read_unchecked(&last_value);
24987 do {
24988 if (ret < last)
24989 return last;
24990- last = atomic64_cmpxchg(&last_value, last, ret);
24991+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24992 } while (unlikely(last != ret));
24993
24994 return ret;
24995diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24996index 618ce26..ec7e21c 100644
24997--- a/arch/x86/kernel/reboot.c
24998+++ b/arch/x86/kernel/reboot.c
24999@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25000
25001 void __noreturn machine_real_restart(unsigned int type)
25002 {
25003+
25004+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25005+ struct desc_struct *gdt;
25006+#endif
25007+
25008 local_irq_disable();
25009
25010 /*
25011@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25012
25013 /* Jump to the identity-mapped low memory code */
25014 #ifdef CONFIG_X86_32
25015- asm volatile("jmpl *%0" : :
25016+
25017+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25018+ gdt = get_cpu_gdt_table(smp_processor_id());
25019+ pax_open_kernel();
25020+#ifdef CONFIG_PAX_MEMORY_UDEREF
25021+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25022+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25023+ loadsegment(ds, __KERNEL_DS);
25024+ loadsegment(es, __KERNEL_DS);
25025+ loadsegment(ss, __KERNEL_DS);
25026+#endif
25027+#ifdef CONFIG_PAX_KERNEXEC
25028+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25029+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25030+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25031+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25032+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25033+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25034+#endif
25035+ pax_close_kernel();
25036+#endif
25037+
25038+ asm volatile("ljmpl *%0" : :
25039 "rm" (real_mode_header->machine_real_restart_asm),
25040 "a" (type));
25041 #else
25042@@ -466,7 +493,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25043 * try to force a triple fault and then cycle between hitting the keyboard
25044 * controller and doing that
25045 */
25046-static void native_machine_emergency_restart(void)
25047+static void __noreturn native_machine_emergency_restart(void)
25048 {
25049 int i;
25050 int attempt = 0;
25051@@ -575,13 +602,13 @@ void native_machine_shutdown(void)
25052 #endif
25053 }
25054
25055-static void __machine_emergency_restart(int emergency)
25056+static void __noreturn __machine_emergency_restart(int emergency)
25057 {
25058 reboot_emergency = emergency;
25059 machine_ops.emergency_restart();
25060 }
25061
25062-static void native_machine_restart(char *__unused)
25063+static void __noreturn native_machine_restart(char *__unused)
25064 {
25065 pr_notice("machine restart\n");
25066
25067@@ -590,7 +617,7 @@ static void native_machine_restart(char *__unused)
25068 __machine_emergency_restart(0);
25069 }
25070
25071-static void native_machine_halt(void)
25072+static void __noreturn native_machine_halt(void)
25073 {
25074 /* Stop other cpus and apics */
25075 machine_shutdown();
25076@@ -600,7 +627,7 @@ static void native_machine_halt(void)
25077 stop_this_cpu(NULL);
25078 }
25079
25080-static void native_machine_power_off(void)
25081+static void __noreturn native_machine_power_off(void)
25082 {
25083 if (pm_power_off) {
25084 if (!reboot_force)
25085@@ -609,9 +636,10 @@ static void native_machine_power_off(void)
25086 }
25087 /* A fallback in case there is no PM info available */
25088 tboot_shutdown(TB_SHUTDOWN_HALT);
25089+ unreachable();
25090 }
25091
25092-struct machine_ops machine_ops = {
25093+struct machine_ops machine_ops __read_only = {
25094 .power_off = native_machine_power_off,
25095 .shutdown = native_machine_shutdown,
25096 .emergency_restart = native_machine_emergency_restart,
25097diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25098index c8e41e9..64049ef 100644
25099--- a/arch/x86/kernel/reboot_fixups_32.c
25100+++ b/arch/x86/kernel/reboot_fixups_32.c
25101@@ -57,7 +57,7 @@ struct device_fixup {
25102 unsigned int vendor;
25103 unsigned int device;
25104 void (*reboot_fixup)(struct pci_dev *);
25105-};
25106+} __do_const;
25107
25108 /*
25109 * PCI ids solely used for fixups_table go here
25110diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25111index 3fd2c69..16ef367 100644
25112--- a/arch/x86/kernel/relocate_kernel_64.S
25113+++ b/arch/x86/kernel/relocate_kernel_64.S
25114@@ -11,6 +11,7 @@
25115 #include <asm/kexec.h>
25116 #include <asm/processor-flags.h>
25117 #include <asm/pgtable_types.h>
25118+#include <asm/alternative-asm.h>
25119
25120 /*
25121 * Must be relocatable PIC code callable as a C function
25122@@ -96,8 +97,7 @@ relocate_kernel:
25123
25124 /* jump to identity mapped page */
25125 addq $(identity_mapped - relocate_kernel), %r8
25126- pushq %r8
25127- ret
25128+ jmp *%r8
25129
25130 identity_mapped:
25131 /* set return address to 0 if not preserving context */
25132@@ -167,6 +167,7 @@ identity_mapped:
25133 xorl %r14d, %r14d
25134 xorl %r15d, %r15d
25135
25136+ pax_force_retaddr 0, 1
25137 ret
25138
25139 1:
25140diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25141index f0de629..a4978a8f 100644
25142--- a/arch/x86/kernel/setup.c
25143+++ b/arch/x86/kernel/setup.c
25144@@ -110,6 +110,7 @@
25145 #include <asm/mce.h>
25146 #include <asm/alternative.h>
25147 #include <asm/prom.h>
25148+#include <asm/boot.h>
25149
25150 /*
25151 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25152@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25153 #endif
25154
25155
25156-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25157-__visible unsigned long mmu_cr4_features;
25158+#ifdef CONFIG_X86_64
25159+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25160+#elif defined(CONFIG_X86_PAE)
25161+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25162 #else
25163-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
25164+__visible unsigned long mmu_cr4_features __read_only;
25165 #endif
25166
25167+void set_in_cr4(unsigned long mask)
25168+{
25169+ unsigned long cr4 = read_cr4();
25170+
25171+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25172+ return;
25173+
25174+ pax_open_kernel();
25175+ mmu_cr4_features |= mask;
25176+ pax_close_kernel();
25177+
25178+ if (trampoline_cr4_features)
25179+ *trampoline_cr4_features = mmu_cr4_features;
25180+ cr4 |= mask;
25181+ write_cr4(cr4);
25182+}
25183+EXPORT_SYMBOL(set_in_cr4);
25184+
25185+void clear_in_cr4(unsigned long mask)
25186+{
25187+ unsigned long cr4 = read_cr4();
25188+
25189+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25190+ return;
25191+
25192+ pax_open_kernel();
25193+ mmu_cr4_features &= ~mask;
25194+ pax_close_kernel();
25195+
25196+ if (trampoline_cr4_features)
25197+ *trampoline_cr4_features = mmu_cr4_features;
25198+ cr4 &= ~mask;
25199+ write_cr4(cr4);
25200+}
25201+EXPORT_SYMBOL(clear_in_cr4);
25202+
25203 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25204 int bootloader_type, bootloader_version;
25205
25206@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25207 * area (640->1Mb) as ram even though it is not.
25208 * take them out.
25209 */
25210- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25211+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25212
25213 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25214 }
25215@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25216 /* called before trim_bios_range() to spare extra sanitize */
25217 static void __init e820_add_kernel_range(void)
25218 {
25219- u64 start = __pa_symbol(_text);
25220+ u64 start = __pa_symbol(ktla_ktva(_text));
25221 u64 size = __pa_symbol(_end) - start;
25222
25223 /*
25224@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25225
25226 void __init setup_arch(char **cmdline_p)
25227 {
25228+#ifdef CONFIG_X86_32
25229+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25230+#else
25231 memblock_reserve(__pa_symbol(_text),
25232 (unsigned long)__bss_stop - (unsigned long)_text);
25233+#endif
25234
25235 early_reserve_initrd();
25236
25237@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25238
25239 if (!boot_params.hdr.root_flags)
25240 root_mountflags &= ~MS_RDONLY;
25241- init_mm.start_code = (unsigned long) _text;
25242- init_mm.end_code = (unsigned long) _etext;
25243+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25244+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25245 init_mm.end_data = (unsigned long) _edata;
25246 init_mm.brk = _brk_end;
25247
25248- code_resource.start = __pa_symbol(_text);
25249- code_resource.end = __pa_symbol(_etext)-1;
25250- data_resource.start = __pa_symbol(_etext);
25251+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25252+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25253+ data_resource.start = __pa_symbol(_sdata);
25254 data_resource.end = __pa_symbol(_edata)-1;
25255 bss_resource.start = __pa_symbol(__bss_start);
25256 bss_resource.end = __pa_symbol(__bss_stop)-1;
25257diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25258index 5cdff03..80fa283 100644
25259--- a/arch/x86/kernel/setup_percpu.c
25260+++ b/arch/x86/kernel/setup_percpu.c
25261@@ -21,19 +21,17 @@
25262 #include <asm/cpu.h>
25263 #include <asm/stackprotector.h>
25264
25265-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25266+#ifdef CONFIG_SMP
25267+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25268 EXPORT_PER_CPU_SYMBOL(cpu_number);
25269+#endif
25270
25271-#ifdef CONFIG_X86_64
25272 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25273-#else
25274-#define BOOT_PERCPU_OFFSET 0
25275-#endif
25276
25277 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25278 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25279
25280-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25281+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25282 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25283 };
25284 EXPORT_SYMBOL(__per_cpu_offset);
25285@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25286 {
25287 #ifdef CONFIG_NEED_MULTIPLE_NODES
25288 pg_data_t *last = NULL;
25289- unsigned int cpu;
25290+ int cpu;
25291
25292 for_each_possible_cpu(cpu) {
25293 int node = early_cpu_to_node(cpu);
25294@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25295 {
25296 #ifdef CONFIG_X86_32
25297 struct desc_struct gdt;
25298+ unsigned long base = per_cpu_offset(cpu);
25299
25300- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25301- 0x2 | DESCTYPE_S, 0x8);
25302- gdt.s = 1;
25303+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25304+ 0x83 | DESCTYPE_S, 0xC);
25305 write_gdt_entry(get_cpu_gdt_table(cpu),
25306 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25307 #endif
25308@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25309 /* alrighty, percpu areas up and running */
25310 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25311 for_each_possible_cpu(cpu) {
25312+#ifdef CONFIG_CC_STACKPROTECTOR
25313+#ifdef CONFIG_X86_32
25314+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25315+#endif
25316+#endif
25317 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25318 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25319 per_cpu(cpu_number, cpu) = cpu;
25320@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25321 */
25322 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25323 #endif
25324+#ifdef CONFIG_CC_STACKPROTECTOR
25325+#ifdef CONFIG_X86_32
25326+ if (!cpu)
25327+ per_cpu(stack_canary.canary, cpu) = canary;
25328+#endif
25329+#endif
25330 /*
25331 * Up to this point, the boot CPU has been using .init.data
25332 * area. Reload any changed state for the boot CPU.
25333diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25334index 9e5de68..16c53cb 100644
25335--- a/arch/x86/kernel/signal.c
25336+++ b/arch/x86/kernel/signal.c
25337@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25338 * Align the stack pointer according to the i386 ABI,
25339 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25340 */
25341- sp = ((sp + 4) & -16ul) - 4;
25342+ sp = ((sp - 12) & -16ul) - 4;
25343 #else /* !CONFIG_X86_32 */
25344 sp = round_down(sp, 16) - 8;
25345 #endif
25346@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25347 }
25348
25349 if (current->mm->context.vdso)
25350- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25351+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25352 else
25353- restorer = &frame->retcode;
25354+ restorer = (void __user *)&frame->retcode;
25355 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25356 restorer = ksig->ka.sa.sa_restorer;
25357
25358@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25359 * reasons and because gdb uses it as a signature to notice
25360 * signal handler stack frames.
25361 */
25362- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25363+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25364
25365 if (err)
25366 return -EFAULT;
25367@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25368 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25369
25370 /* Set up to return from userspace. */
25371- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25372+ if (current->mm->context.vdso)
25373+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25374+ else
25375+ restorer = (void __user *)&frame->retcode;
25376 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25377 restorer = ksig->ka.sa.sa_restorer;
25378 put_user_ex(restorer, &frame->pretcode);
25379@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25380 * reasons and because gdb uses it as a signature to notice
25381 * signal handler stack frames.
25382 */
25383- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25384+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25385 } put_user_catch(err);
25386
25387 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25388@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25389 {
25390 int usig = signr_convert(ksig->sig);
25391 sigset_t *set = sigmask_to_save();
25392- compat_sigset_t *cset = (compat_sigset_t *) set;
25393+ sigset_t sigcopy;
25394+ compat_sigset_t *cset;
25395+
25396+ sigcopy = *set;
25397+
25398+ cset = (compat_sigset_t *) &sigcopy;
25399
25400 /* Set up the stack frame */
25401 if (is_ia32_frame()) {
25402@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25403 } else if (is_x32_frame()) {
25404 return x32_setup_rt_frame(ksig, cset, regs);
25405 } else {
25406- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25407+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25408 }
25409 }
25410
25411diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25412index 7c3a5a6..f0a8961 100644
25413--- a/arch/x86/kernel/smp.c
25414+++ b/arch/x86/kernel/smp.c
25415@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25416
25417 __setup("nonmi_ipi", nonmi_ipi_setup);
25418
25419-struct smp_ops smp_ops = {
25420+struct smp_ops smp_ops __read_only = {
25421 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25422 .smp_prepare_cpus = native_smp_prepare_cpus,
25423 .smp_cpus_done = native_smp_cpus_done,
25424diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25425index 6cacab6..750636a 100644
25426--- a/arch/x86/kernel/smpboot.c
25427+++ b/arch/x86/kernel/smpboot.c
25428@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25429
25430 enable_start_cpu0 = 0;
25431
25432-#ifdef CONFIG_X86_32
25433- /* switch away from the initial page table */
25434- load_cr3(swapper_pg_dir);
25435- __flush_tlb_all();
25436-#endif
25437-
25438 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25439 barrier();
25440+
25441+ /* switch away from the initial page table */
25442+#ifdef CONFIG_PAX_PER_CPU_PGD
25443+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25444+ __flush_tlb_all();
25445+#elif defined(CONFIG_X86_32)
25446+ load_cr3(swapper_pg_dir);
25447+ __flush_tlb_all();
25448+#endif
25449+
25450 /*
25451 * Check TSC synchronization with the BP:
25452 */
25453@@ -749,6 +753,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25454 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25455 (THREAD_SIZE + task_stack_page(idle))) - 1);
25456 per_cpu(current_task, cpu) = idle;
25457+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25458
25459 #ifdef CONFIG_X86_32
25460 /* Stack for startup_32 can be just as for start_secondary onwards */
25461@@ -756,11 +761,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25462 #else
25463 clear_tsk_thread_flag(idle, TIF_FORK);
25464 initial_gs = per_cpu_offset(cpu);
25465- per_cpu(kernel_stack, cpu) =
25466- (unsigned long)task_stack_page(idle) -
25467- KERNEL_STACK_OFFSET + THREAD_SIZE;
25468+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25469 #endif
25470+
25471+ pax_open_kernel();
25472 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25473+ pax_close_kernel();
25474+
25475 initial_code = (unsigned long)start_secondary;
25476 stack_start = idle->thread.sp;
25477
25478@@ -909,6 +916,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25479 /* the FPU context is blank, nobody can own it */
25480 __cpu_disable_lazy_restore(cpu);
25481
25482+#ifdef CONFIG_PAX_PER_CPU_PGD
25483+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25484+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25485+ KERNEL_PGD_PTRS);
25486+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25487+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25488+ KERNEL_PGD_PTRS);
25489+#endif
25490+
25491 err = do_boot_cpu(apicid, cpu, tidle);
25492 if (err) {
25493 pr_debug("do_boot_cpu failed %d\n", err);
25494diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25495index 9b4d51d..5d28b58 100644
25496--- a/arch/x86/kernel/step.c
25497+++ b/arch/x86/kernel/step.c
25498@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25499 struct desc_struct *desc;
25500 unsigned long base;
25501
25502- seg &= ~7UL;
25503+ seg >>= 3;
25504
25505 mutex_lock(&child->mm->context.lock);
25506- if (unlikely((seg >> 3) >= child->mm->context.size))
25507+ if (unlikely(seg >= child->mm->context.size))
25508 addr = -1L; /* bogus selector, access would fault */
25509 else {
25510 desc = child->mm->context.ldt + seg;
25511@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25512 addr += base;
25513 }
25514 mutex_unlock(&child->mm->context.lock);
25515- }
25516+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25517+ addr = ktla_ktva(addr);
25518
25519 return addr;
25520 }
25521@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25522 unsigned char opcode[15];
25523 unsigned long addr = convert_ip_to_linear(child, regs);
25524
25525+ if (addr == -EINVAL)
25526+ return 0;
25527+
25528 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25529 for (i = 0; i < copied; i++) {
25530 switch (opcode[i]) {
25531diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25532new file mode 100644
25533index 0000000..5877189
25534--- /dev/null
25535+++ b/arch/x86/kernel/sys_i386_32.c
25536@@ -0,0 +1,189 @@
25537+/*
25538+ * This file contains various random system calls that
25539+ * have a non-standard calling sequence on the Linux/i386
25540+ * platform.
25541+ */
25542+
25543+#include <linux/errno.h>
25544+#include <linux/sched.h>
25545+#include <linux/mm.h>
25546+#include <linux/fs.h>
25547+#include <linux/smp.h>
25548+#include <linux/sem.h>
25549+#include <linux/msg.h>
25550+#include <linux/shm.h>
25551+#include <linux/stat.h>
25552+#include <linux/syscalls.h>
25553+#include <linux/mman.h>
25554+#include <linux/file.h>
25555+#include <linux/utsname.h>
25556+#include <linux/ipc.h>
25557+#include <linux/elf.h>
25558+
25559+#include <linux/uaccess.h>
25560+#include <linux/unistd.h>
25561+
25562+#include <asm/syscalls.h>
25563+
25564+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25565+{
25566+ unsigned long pax_task_size = TASK_SIZE;
25567+
25568+#ifdef CONFIG_PAX_SEGMEXEC
25569+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25570+ pax_task_size = SEGMEXEC_TASK_SIZE;
25571+#endif
25572+
25573+ if (flags & MAP_FIXED)
25574+ if (len > pax_task_size || addr > pax_task_size - len)
25575+ return -EINVAL;
25576+
25577+ return 0;
25578+}
25579+
25580+/*
25581+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25582+ */
25583+static unsigned long get_align_mask(void)
25584+{
25585+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25586+ return 0;
25587+
25588+ if (!(current->flags & PF_RANDOMIZE))
25589+ return 0;
25590+
25591+ return va_align.mask;
25592+}
25593+
25594+unsigned long
25595+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25596+ unsigned long len, unsigned long pgoff, unsigned long flags)
25597+{
25598+ struct mm_struct *mm = current->mm;
25599+ struct vm_area_struct *vma;
25600+ unsigned long pax_task_size = TASK_SIZE;
25601+ struct vm_unmapped_area_info info;
25602+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25603+
25604+#ifdef CONFIG_PAX_SEGMEXEC
25605+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25606+ pax_task_size = SEGMEXEC_TASK_SIZE;
25607+#endif
25608+
25609+ pax_task_size -= PAGE_SIZE;
25610+
25611+ if (len > pax_task_size)
25612+ return -ENOMEM;
25613+
25614+ if (flags & MAP_FIXED)
25615+ return addr;
25616+
25617+#ifdef CONFIG_PAX_RANDMMAP
25618+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25619+#endif
25620+
25621+ if (addr) {
25622+ addr = PAGE_ALIGN(addr);
25623+ if (pax_task_size - len >= addr) {
25624+ vma = find_vma(mm, addr);
25625+ if (check_heap_stack_gap(vma, addr, len, offset))
25626+ return addr;
25627+ }
25628+ }
25629+
25630+ info.flags = 0;
25631+ info.length = len;
25632+ info.align_mask = filp ? get_align_mask() : 0;
25633+ info.align_offset = pgoff << PAGE_SHIFT;
25634+ info.threadstack_offset = offset;
25635+
25636+#ifdef CONFIG_PAX_PAGEEXEC
25637+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25638+ info.low_limit = 0x00110000UL;
25639+ info.high_limit = mm->start_code;
25640+
25641+#ifdef CONFIG_PAX_RANDMMAP
25642+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25643+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25644+#endif
25645+
25646+ if (info.low_limit < info.high_limit) {
25647+ addr = vm_unmapped_area(&info);
25648+ if (!IS_ERR_VALUE(addr))
25649+ return addr;
25650+ }
25651+ } else
25652+#endif
25653+
25654+ info.low_limit = mm->mmap_base;
25655+ info.high_limit = pax_task_size;
25656+
25657+ return vm_unmapped_area(&info);
25658+}
25659+
25660+unsigned long
25661+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25662+ const unsigned long len, const unsigned long pgoff,
25663+ const unsigned long flags)
25664+{
25665+ struct vm_area_struct *vma;
25666+ struct mm_struct *mm = current->mm;
25667+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25668+ struct vm_unmapped_area_info info;
25669+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25670+
25671+#ifdef CONFIG_PAX_SEGMEXEC
25672+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25673+ pax_task_size = SEGMEXEC_TASK_SIZE;
25674+#endif
25675+
25676+ pax_task_size -= PAGE_SIZE;
25677+
25678+ /* requested length too big for entire address space */
25679+ if (len > pax_task_size)
25680+ return -ENOMEM;
25681+
25682+ if (flags & MAP_FIXED)
25683+ return addr;
25684+
25685+#ifdef CONFIG_PAX_PAGEEXEC
25686+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25687+ goto bottomup;
25688+#endif
25689+
25690+#ifdef CONFIG_PAX_RANDMMAP
25691+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25692+#endif
25693+
25694+ /* requesting a specific address */
25695+ if (addr) {
25696+ addr = PAGE_ALIGN(addr);
25697+ if (pax_task_size - len >= addr) {
25698+ vma = find_vma(mm, addr);
25699+ if (check_heap_stack_gap(vma, addr, len, offset))
25700+ return addr;
25701+ }
25702+ }
25703+
25704+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25705+ info.length = len;
25706+ info.low_limit = PAGE_SIZE;
25707+ info.high_limit = mm->mmap_base;
25708+ info.align_mask = filp ? get_align_mask() : 0;
25709+ info.align_offset = pgoff << PAGE_SHIFT;
25710+ info.threadstack_offset = offset;
25711+
25712+ addr = vm_unmapped_area(&info);
25713+ if (!(addr & ~PAGE_MASK))
25714+ return addr;
25715+ VM_BUG_ON(addr != -ENOMEM);
25716+
25717+bottomup:
25718+ /*
25719+ * A failed mmap() very likely causes application failure,
25720+ * so fall back to the bottom-up function here. This scenario
25721+ * can happen with large stack limits and large mmap()
25722+ * allocations.
25723+ */
25724+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25725+}
25726diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25727index 30277e2..5664a29 100644
25728--- a/arch/x86/kernel/sys_x86_64.c
25729+++ b/arch/x86/kernel/sys_x86_64.c
25730@@ -81,8 +81,8 @@ out:
25731 return error;
25732 }
25733
25734-static void find_start_end(unsigned long flags, unsigned long *begin,
25735- unsigned long *end)
25736+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25737+ unsigned long *begin, unsigned long *end)
25738 {
25739 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25740 unsigned long new_begin;
25741@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25742 *begin = new_begin;
25743 }
25744 } else {
25745- *begin = current->mm->mmap_legacy_base;
25746+ *begin = mm->mmap_legacy_base;
25747 *end = TASK_SIZE;
25748 }
25749 }
25750@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25751 struct vm_area_struct *vma;
25752 struct vm_unmapped_area_info info;
25753 unsigned long begin, end;
25754+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25755
25756 if (flags & MAP_FIXED)
25757 return addr;
25758
25759- find_start_end(flags, &begin, &end);
25760+ find_start_end(mm, flags, &begin, &end);
25761
25762 if (len > end)
25763 return -ENOMEM;
25764
25765+#ifdef CONFIG_PAX_RANDMMAP
25766+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25767+#endif
25768+
25769 if (addr) {
25770 addr = PAGE_ALIGN(addr);
25771 vma = find_vma(mm, addr);
25772- if (end - len >= addr &&
25773- (!vma || addr + len <= vma->vm_start))
25774+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25775 return addr;
25776 }
25777
25778@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25779 info.high_limit = end;
25780 info.align_mask = filp ? get_align_mask() : 0;
25781 info.align_offset = pgoff << PAGE_SHIFT;
25782+ info.threadstack_offset = offset;
25783 return vm_unmapped_area(&info);
25784 }
25785
25786@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25787 struct mm_struct *mm = current->mm;
25788 unsigned long addr = addr0;
25789 struct vm_unmapped_area_info info;
25790+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25791
25792 /* requested length too big for entire address space */
25793 if (len > TASK_SIZE)
25794@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25795 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25796 goto bottomup;
25797
25798+#ifdef CONFIG_PAX_RANDMMAP
25799+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25800+#endif
25801+
25802 /* requesting a specific address */
25803 if (addr) {
25804 addr = PAGE_ALIGN(addr);
25805 vma = find_vma(mm, addr);
25806- if (TASK_SIZE - len >= addr &&
25807- (!vma || addr + len <= vma->vm_start))
25808+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25809 return addr;
25810 }
25811
25812@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25813 info.high_limit = mm->mmap_base;
25814 info.align_mask = filp ? get_align_mask() : 0;
25815 info.align_offset = pgoff << PAGE_SHIFT;
25816+ info.threadstack_offset = offset;
25817 addr = vm_unmapped_area(&info);
25818 if (!(addr & ~PAGE_MASK))
25819 return addr;
25820diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25821index 91a4496..1730bff 100644
25822--- a/arch/x86/kernel/tboot.c
25823+++ b/arch/x86/kernel/tboot.c
25824@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25825
25826 void tboot_shutdown(u32 shutdown_type)
25827 {
25828- void (*shutdown)(void);
25829+ void (* __noreturn shutdown)(void);
25830
25831 if (!tboot_enabled())
25832 return;
25833@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25834
25835 switch_to_tboot_pt();
25836
25837- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25838+ shutdown = (void *)tboot->shutdown_entry;
25839 shutdown();
25840
25841 /* should not reach here */
25842@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
25843 return -ENODEV;
25844 }
25845
25846-static atomic_t ap_wfs_count;
25847+static atomic_unchecked_t ap_wfs_count;
25848
25849 static int tboot_wait_for_aps(int num_aps)
25850 {
25851@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25852 {
25853 switch (action) {
25854 case CPU_DYING:
25855- atomic_inc(&ap_wfs_count);
25856+ atomic_inc_unchecked(&ap_wfs_count);
25857 if (num_online_cpus() == 1)
25858- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25859+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25860 return NOTIFY_BAD;
25861 break;
25862 }
25863@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
25864
25865 tboot_create_trampoline();
25866
25867- atomic_set(&ap_wfs_count, 0);
25868+ atomic_set_unchecked(&ap_wfs_count, 0);
25869 register_hotcpu_notifier(&tboot_cpu_notifier);
25870
25871 #ifdef CONFIG_DEBUG_FS
25872diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25873index 24d3c91..d06b473 100644
25874--- a/arch/x86/kernel/time.c
25875+++ b/arch/x86/kernel/time.c
25876@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25877 {
25878 unsigned long pc = instruction_pointer(regs);
25879
25880- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25881+ if (!user_mode(regs) && in_lock_functions(pc)) {
25882 #ifdef CONFIG_FRAME_POINTER
25883- return *(unsigned long *)(regs->bp + sizeof(long));
25884+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25885 #else
25886 unsigned long *sp =
25887 (unsigned long *)kernel_stack_pointer(regs);
25888@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25889 * or above a saved flags. Eflags has bits 22-31 zero,
25890 * kernel addresses don't.
25891 */
25892+
25893+#ifdef CONFIG_PAX_KERNEXEC
25894+ return ktla_ktva(sp[0]);
25895+#else
25896 if (sp[0] >> 22)
25897 return sp[0];
25898 if (sp[1] >> 22)
25899 return sp[1];
25900 #endif
25901+
25902+#endif
25903 }
25904 return pc;
25905 }
25906diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25907index f7fec09..9991981 100644
25908--- a/arch/x86/kernel/tls.c
25909+++ b/arch/x86/kernel/tls.c
25910@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25911 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25912 return -EINVAL;
25913
25914+#ifdef CONFIG_PAX_SEGMEXEC
25915+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25916+ return -EINVAL;
25917+#endif
25918+
25919 set_tls_desc(p, idx, &info, 1);
25920
25921 return 0;
25922@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25923
25924 if (kbuf)
25925 info = kbuf;
25926- else if (__copy_from_user(infobuf, ubuf, count))
25927+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25928 return -EFAULT;
25929 else
25930 info = infobuf;
25931diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25932index 1c113db..287b42e 100644
25933--- a/arch/x86/kernel/tracepoint.c
25934+++ b/arch/x86/kernel/tracepoint.c
25935@@ -9,11 +9,11 @@
25936 #include <linux/atomic.h>
25937
25938 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25939-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25940+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25941 (unsigned long) trace_idt_table };
25942
25943 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25944-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25945+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25946
25947 static int trace_irq_vector_refcount;
25948 static DEFINE_MUTEX(irq_vector_mutex);
25949diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25950index 8c8093b..c93f581 100644
25951--- a/arch/x86/kernel/traps.c
25952+++ b/arch/x86/kernel/traps.c
25953@@ -66,7 +66,7 @@
25954 #include <asm/proto.h>
25955
25956 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25957-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25958+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25959 #else
25960 #include <asm/processor-flags.h>
25961 #include <asm/setup.h>
25962@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
25963 #endif
25964
25965 /* Must be page-aligned because the real IDT is used in a fixmap. */
25966-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25967+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25968
25969 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25970 EXPORT_SYMBOL_GPL(used_vectors);
25971@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25972 }
25973
25974 static int __kprobes
25975-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25976+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25977 struct pt_regs *regs, long error_code)
25978 {
25979 #ifdef CONFIG_X86_32
25980- if (regs->flags & X86_VM_MASK) {
25981+ if (v8086_mode(regs)) {
25982 /*
25983 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25984 * On nmi (interrupt 2), do_trap should not be called.
25985@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25986 return -1;
25987 }
25988 #endif
25989- if (!user_mode(regs)) {
25990+ if (!user_mode_novm(regs)) {
25991 if (!fixup_exception(regs)) {
25992 tsk->thread.error_code = error_code;
25993 tsk->thread.trap_nr = trapnr;
25994+
25995+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25996+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25997+ str = "PAX: suspicious stack segment fault";
25998+#endif
25999+
26000 die(str, regs, error_code);
26001 }
26002+
26003+#ifdef CONFIG_PAX_REFCOUNT
26004+ if (trapnr == 4)
26005+ pax_report_refcount_overflow(regs);
26006+#endif
26007+
26008 return 0;
26009 }
26010
26011@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26012 }
26013
26014 static void __kprobes
26015-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26016+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26017 long error_code, siginfo_t *info)
26018 {
26019 struct task_struct *tsk = current;
26020@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26021 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26022 printk_ratelimit()) {
26023 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26024- tsk->comm, tsk->pid, str,
26025+ tsk->comm, task_pid_nr(tsk), str,
26026 regs->ip, regs->sp, error_code);
26027 print_vma_addr(" in ", regs->ip);
26028 pr_cont("\n");
26029@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26030 conditional_sti(regs);
26031
26032 #ifdef CONFIG_X86_32
26033- if (regs->flags & X86_VM_MASK) {
26034+ if (v8086_mode(regs)) {
26035 local_irq_enable();
26036 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26037 goto exit;
26038@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26039 #endif
26040
26041 tsk = current;
26042- if (!user_mode(regs)) {
26043+ if (!user_mode_novm(regs)) {
26044 if (fixup_exception(regs))
26045 goto exit;
26046
26047 tsk->thread.error_code = error_code;
26048 tsk->thread.trap_nr = X86_TRAP_GP;
26049 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26050- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26051+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26052+
26053+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26054+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26055+ die("PAX: suspicious general protection fault", regs, error_code);
26056+ else
26057+#endif
26058+
26059 die("general protection fault", regs, error_code);
26060+ }
26061 goto exit;
26062 }
26063
26064+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26065+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26066+ struct mm_struct *mm = tsk->mm;
26067+ unsigned long limit;
26068+
26069+ down_write(&mm->mmap_sem);
26070+ limit = mm->context.user_cs_limit;
26071+ if (limit < TASK_SIZE) {
26072+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26073+ up_write(&mm->mmap_sem);
26074+ return;
26075+ }
26076+ up_write(&mm->mmap_sem);
26077+ }
26078+#endif
26079+
26080 tsk->thread.error_code = error_code;
26081 tsk->thread.trap_nr = X86_TRAP_GP;
26082
26083@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26084 /* It's safe to allow irq's after DR6 has been saved */
26085 preempt_conditional_sti(regs);
26086
26087- if (regs->flags & X86_VM_MASK) {
26088+ if (v8086_mode(regs)) {
26089 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26090 X86_TRAP_DB);
26091 preempt_conditional_cli(regs);
26092@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26093 * We already checked v86 mode above, so we can check for kernel mode
26094 * by just checking the CPL of CS.
26095 */
26096- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26097+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26098 tsk->thread.debugreg6 &= ~DR_STEP;
26099 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26100 regs->flags &= ~X86_EFLAGS_TF;
26101@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26102 return;
26103 conditional_sti(regs);
26104
26105- if (!user_mode_vm(regs))
26106+ if (!user_mode(regs))
26107 {
26108 if (!fixup_exception(regs)) {
26109 task->thread.error_code = error_code;
26110diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26111index 2ed8459..7cf329f 100644
26112--- a/arch/x86/kernel/uprobes.c
26113+++ b/arch/x86/kernel/uprobes.c
26114@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26115 int ret = NOTIFY_DONE;
26116
26117 /* We are only interested in userspace traps */
26118- if (regs && !user_mode_vm(regs))
26119+ if (regs && !user_mode(regs))
26120 return NOTIFY_DONE;
26121
26122 switch (val) {
26123@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26124
26125 if (ncopied != rasize) {
26126 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26127- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26128+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26129
26130 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26131 }
26132diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26133index b9242ba..50c5edd 100644
26134--- a/arch/x86/kernel/verify_cpu.S
26135+++ b/arch/x86/kernel/verify_cpu.S
26136@@ -20,6 +20,7 @@
26137 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26138 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26139 * arch/x86/kernel/head_32.S: processor startup
26140+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26141 *
26142 * verify_cpu, returns the status of longmode and SSE in register %eax.
26143 * 0: Success 1: Failure
26144diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26145index e8edcf5..27f9344 100644
26146--- a/arch/x86/kernel/vm86_32.c
26147+++ b/arch/x86/kernel/vm86_32.c
26148@@ -44,6 +44,7 @@
26149 #include <linux/ptrace.h>
26150 #include <linux/audit.h>
26151 #include <linux/stddef.h>
26152+#include <linux/grsecurity.h>
26153
26154 #include <asm/uaccess.h>
26155 #include <asm/io.h>
26156@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26157 do_exit(SIGSEGV);
26158 }
26159
26160- tss = &per_cpu(init_tss, get_cpu());
26161+ tss = init_tss + get_cpu();
26162 current->thread.sp0 = current->thread.saved_sp0;
26163 current->thread.sysenter_cs = __KERNEL_CS;
26164 load_sp0(tss, &current->thread);
26165@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26166
26167 if (tsk->thread.saved_sp0)
26168 return -EPERM;
26169+
26170+#ifdef CONFIG_GRKERNSEC_VM86
26171+ if (!capable(CAP_SYS_RAWIO)) {
26172+ gr_handle_vm86();
26173+ return -EPERM;
26174+ }
26175+#endif
26176+
26177 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26178 offsetof(struct kernel_vm86_struct, vm86plus) -
26179 sizeof(info.regs));
26180@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26181 int tmp;
26182 struct vm86plus_struct __user *v86;
26183
26184+#ifdef CONFIG_GRKERNSEC_VM86
26185+ if (!capable(CAP_SYS_RAWIO)) {
26186+ gr_handle_vm86();
26187+ return -EPERM;
26188+ }
26189+#endif
26190+
26191 tsk = current;
26192 switch (cmd) {
26193 case VM86_REQUEST_IRQ:
26194@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26195 tsk->thread.saved_fs = info->regs32->fs;
26196 tsk->thread.saved_gs = get_user_gs(info->regs32);
26197
26198- tss = &per_cpu(init_tss, get_cpu());
26199+ tss = init_tss + get_cpu();
26200 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26201 if (cpu_has_sep)
26202 tsk->thread.sysenter_cs = 0;
26203@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26204 goto cannot_handle;
26205 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26206 goto cannot_handle;
26207- intr_ptr = (unsigned long __user *) (i << 2);
26208+ intr_ptr = (__force unsigned long __user *) (i << 2);
26209 if (get_user(segoffs, intr_ptr))
26210 goto cannot_handle;
26211 if ((segoffs >> 16) == BIOSSEG)
26212diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26213index 10c4f30..65408b9 100644
26214--- a/arch/x86/kernel/vmlinux.lds.S
26215+++ b/arch/x86/kernel/vmlinux.lds.S
26216@@ -26,6 +26,13 @@
26217 #include <asm/page_types.h>
26218 #include <asm/cache.h>
26219 #include <asm/boot.h>
26220+#include <asm/segment.h>
26221+
26222+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26223+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26224+#else
26225+#define __KERNEL_TEXT_OFFSET 0
26226+#endif
26227
26228 #undef i386 /* in case the preprocessor is a 32bit one */
26229
26230@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26231
26232 PHDRS {
26233 text PT_LOAD FLAGS(5); /* R_E */
26234+#ifdef CONFIG_X86_32
26235+ module PT_LOAD FLAGS(5); /* R_E */
26236+#endif
26237+#ifdef CONFIG_XEN
26238+ rodata PT_LOAD FLAGS(5); /* R_E */
26239+#else
26240+ rodata PT_LOAD FLAGS(4); /* R__ */
26241+#endif
26242 data PT_LOAD FLAGS(6); /* RW_ */
26243-#ifdef CONFIG_X86_64
26244+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26245 #ifdef CONFIG_SMP
26246 percpu PT_LOAD FLAGS(6); /* RW_ */
26247 #endif
26248+ text.init PT_LOAD FLAGS(5); /* R_E */
26249+ text.exit PT_LOAD FLAGS(5); /* R_E */
26250 init PT_LOAD FLAGS(7); /* RWE */
26251-#endif
26252 note PT_NOTE FLAGS(0); /* ___ */
26253 }
26254
26255 SECTIONS
26256 {
26257 #ifdef CONFIG_X86_32
26258- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26259- phys_startup_32 = startup_32 - LOAD_OFFSET;
26260+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26261 #else
26262- . = __START_KERNEL;
26263- phys_startup_64 = startup_64 - LOAD_OFFSET;
26264+ . = __START_KERNEL;
26265 #endif
26266
26267 /* Text and read-only data */
26268- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26269- _text = .;
26270+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26271 /* bootstrapping code */
26272+#ifdef CONFIG_X86_32
26273+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26274+#else
26275+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26276+#endif
26277+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26278+ _text = .;
26279 HEAD_TEXT
26280 . = ALIGN(8);
26281 _stext = .;
26282@@ -104,13 +124,47 @@ SECTIONS
26283 IRQENTRY_TEXT
26284 *(.fixup)
26285 *(.gnu.warning)
26286- /* End of text section */
26287- _etext = .;
26288 } :text = 0x9090
26289
26290- NOTES :text :note
26291+ . += __KERNEL_TEXT_OFFSET;
26292
26293- EXCEPTION_TABLE(16) :text = 0x9090
26294+#ifdef CONFIG_X86_32
26295+ . = ALIGN(PAGE_SIZE);
26296+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26297+
26298+#ifdef CONFIG_PAX_KERNEXEC
26299+ MODULES_EXEC_VADDR = .;
26300+ BYTE(0)
26301+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26302+ . = ALIGN(HPAGE_SIZE) - 1;
26303+ MODULES_EXEC_END = .;
26304+#endif
26305+
26306+ } :module
26307+#endif
26308+
26309+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26310+ /* End of text section */
26311+ BYTE(0)
26312+ _etext = . - __KERNEL_TEXT_OFFSET;
26313+ }
26314+
26315+#ifdef CONFIG_X86_32
26316+ . = ALIGN(PAGE_SIZE);
26317+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26318+ . = ALIGN(PAGE_SIZE);
26319+ *(.empty_zero_page)
26320+ *(.initial_pg_fixmap)
26321+ *(.initial_pg_pmd)
26322+ *(.initial_page_table)
26323+ *(.swapper_pg_dir)
26324+ } :rodata
26325+#endif
26326+
26327+ . = ALIGN(PAGE_SIZE);
26328+ NOTES :rodata :note
26329+
26330+ EXCEPTION_TABLE(16) :rodata
26331
26332 #if defined(CONFIG_DEBUG_RODATA)
26333 /* .text should occupy whole number of pages */
26334@@ -122,16 +176,20 @@ SECTIONS
26335
26336 /* Data */
26337 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26338+
26339+#ifdef CONFIG_PAX_KERNEXEC
26340+ . = ALIGN(HPAGE_SIZE);
26341+#else
26342+ . = ALIGN(PAGE_SIZE);
26343+#endif
26344+
26345 /* Start of data section */
26346 _sdata = .;
26347
26348 /* init_task */
26349 INIT_TASK_DATA(THREAD_SIZE)
26350
26351-#ifdef CONFIG_X86_32
26352- /* 32 bit has nosave before _edata */
26353 NOSAVE_DATA
26354-#endif
26355
26356 PAGE_ALIGNED_DATA(PAGE_SIZE)
26357
26358@@ -172,12 +230,19 @@ SECTIONS
26359 #endif /* CONFIG_X86_64 */
26360
26361 /* Init code and data - will be freed after init */
26362- . = ALIGN(PAGE_SIZE);
26363 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26364+ BYTE(0)
26365+
26366+#ifdef CONFIG_PAX_KERNEXEC
26367+ . = ALIGN(HPAGE_SIZE);
26368+#else
26369+ . = ALIGN(PAGE_SIZE);
26370+#endif
26371+
26372 __init_begin = .; /* paired with __init_end */
26373- }
26374+ } :init.begin
26375
26376-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26377+#ifdef CONFIG_SMP
26378 /*
26379 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26380 * output PHDR, so the next output section - .init.text - should
26381@@ -186,12 +251,27 @@ SECTIONS
26382 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26383 #endif
26384
26385- INIT_TEXT_SECTION(PAGE_SIZE)
26386-#ifdef CONFIG_X86_64
26387- :init
26388-#endif
26389+ . = ALIGN(PAGE_SIZE);
26390+ init_begin = .;
26391+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26392+ VMLINUX_SYMBOL(_sinittext) = .;
26393+ INIT_TEXT
26394+ VMLINUX_SYMBOL(_einittext) = .;
26395+ . = ALIGN(PAGE_SIZE);
26396+ } :text.init
26397
26398- INIT_DATA_SECTION(16)
26399+ /*
26400+ * .exit.text is discard at runtime, not link time, to deal with
26401+ * references from .altinstructions and .eh_frame
26402+ */
26403+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26404+ EXIT_TEXT
26405+ . = ALIGN(16);
26406+ } :text.exit
26407+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26408+
26409+ . = ALIGN(PAGE_SIZE);
26410+ INIT_DATA_SECTION(16) :init
26411
26412 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26413 __x86_cpu_dev_start = .;
26414@@ -253,19 +333,12 @@ SECTIONS
26415 }
26416
26417 . = ALIGN(8);
26418- /*
26419- * .exit.text is discard at runtime, not link time, to deal with
26420- * references from .altinstructions and .eh_frame
26421- */
26422- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26423- EXIT_TEXT
26424- }
26425
26426 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26427 EXIT_DATA
26428 }
26429
26430-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26431+#ifndef CONFIG_SMP
26432 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26433 #endif
26434
26435@@ -284,16 +357,10 @@ SECTIONS
26436 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26437 __smp_locks = .;
26438 *(.smp_locks)
26439- . = ALIGN(PAGE_SIZE);
26440 __smp_locks_end = .;
26441+ . = ALIGN(PAGE_SIZE);
26442 }
26443
26444-#ifdef CONFIG_X86_64
26445- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26446- NOSAVE_DATA
26447- }
26448-#endif
26449-
26450 /* BSS */
26451 . = ALIGN(PAGE_SIZE);
26452 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26453@@ -309,6 +376,7 @@ SECTIONS
26454 __brk_base = .;
26455 . += 64 * 1024; /* 64k alignment slop space */
26456 *(.brk_reservation) /* areas brk users have reserved */
26457+ . = ALIGN(HPAGE_SIZE);
26458 __brk_limit = .;
26459 }
26460
26461@@ -335,13 +403,12 @@ SECTIONS
26462 * for the boot processor.
26463 */
26464 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26465-INIT_PER_CPU(gdt_page);
26466 INIT_PER_CPU(irq_stack_union);
26467
26468 /*
26469 * Build-time check on the image size:
26470 */
26471-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26472+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26473 "kernel image bigger than KERNEL_IMAGE_SIZE");
26474
26475 #ifdef CONFIG_SMP
26476diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26477index 1f96f93..d5c8f7a 100644
26478--- a/arch/x86/kernel/vsyscall_64.c
26479+++ b/arch/x86/kernel/vsyscall_64.c
26480@@ -56,15 +56,13 @@
26481 DEFINE_VVAR(int, vgetcpu_mode);
26482 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26483
26484-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26485+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26486
26487 static int __init vsyscall_setup(char *str)
26488 {
26489 if (str) {
26490 if (!strcmp("emulate", str))
26491 vsyscall_mode = EMULATE;
26492- else if (!strcmp("native", str))
26493- vsyscall_mode = NATIVE;
26494 else if (!strcmp("none", str))
26495 vsyscall_mode = NONE;
26496 else
26497@@ -323,8 +321,7 @@ do_ret:
26498 return true;
26499
26500 sigsegv:
26501- force_sig(SIGSEGV, current);
26502- return true;
26503+ do_group_exit(SIGKILL);
26504 }
26505
26506 /*
26507@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26508 extern char __vvar_page;
26509 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26510
26511- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26512- vsyscall_mode == NATIVE
26513- ? PAGE_KERNEL_VSYSCALL
26514- : PAGE_KERNEL_VVAR);
26515+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26516 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26517 (unsigned long)VSYSCALL_START);
26518
26519diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26520index b014d94..e775258 100644
26521--- a/arch/x86/kernel/x8664_ksyms_64.c
26522+++ b/arch/x86/kernel/x8664_ksyms_64.c
26523@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26524 EXPORT_SYMBOL(copy_user_generic_unrolled);
26525 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26526 EXPORT_SYMBOL(__copy_user_nocache);
26527-EXPORT_SYMBOL(_copy_from_user);
26528-EXPORT_SYMBOL(_copy_to_user);
26529
26530 EXPORT_SYMBOL(copy_page);
26531 EXPORT_SYMBOL(clear_page);
26532@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26533 #ifndef CONFIG_PARAVIRT
26534 EXPORT_SYMBOL(native_load_gs_index);
26535 #endif
26536+
26537+#ifdef CONFIG_PAX_PER_CPU_PGD
26538+EXPORT_SYMBOL(cpu_pgd);
26539+#endif
26540diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26541index 8ce0072..431a0e7 100644
26542--- a/arch/x86/kernel/x86_init.c
26543+++ b/arch/x86/kernel/x86_init.c
26544@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26545 static void default_nmi_init(void) { };
26546 static int default_i8042_detect(void) { return 1; };
26547
26548-struct x86_platform_ops x86_platform = {
26549+struct x86_platform_ops x86_platform __read_only = {
26550 .calibrate_tsc = native_calibrate_tsc,
26551 .get_wallclock = mach_get_cmos_time,
26552 .set_wallclock = mach_set_rtc_mmss,
26553@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
26554 EXPORT_SYMBOL_GPL(x86_platform);
26555
26556 #if defined(CONFIG_PCI_MSI)
26557-struct x86_msi_ops x86_msi = {
26558+struct x86_msi_ops x86_msi __read_only = {
26559 .setup_msi_irqs = native_setup_msi_irqs,
26560 .compose_msi_msg = native_compose_msi_msg,
26561 .teardown_msi_irq = native_teardown_msi_irq,
26562@@ -140,7 +140,7 @@ void arch_restore_msi_irqs(struct pci_dev *dev, int irq)
26563 }
26564 #endif
26565
26566-struct x86_io_apic_ops x86_io_apic_ops = {
26567+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26568 .init = native_io_apic_init_mappings,
26569 .read = native_io_apic_read,
26570 .write = native_io_apic_write,
26571diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26572index 422fd82..c3687ca 100644
26573--- a/arch/x86/kernel/xsave.c
26574+++ b/arch/x86/kernel/xsave.c
26575@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26576 {
26577 int err;
26578
26579+ buf = (struct xsave_struct __user *)____m(buf);
26580 if (use_xsave())
26581 err = xsave_user(buf);
26582 else if (use_fxsr())
26583@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26584 */
26585 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26586 {
26587+ buf = (void __user *)____m(buf);
26588 if (use_xsave()) {
26589 if ((unsigned long)buf % 64 || fx_only) {
26590 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26591diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26592index b110fe6..d9c19f2 100644
26593--- a/arch/x86/kvm/cpuid.c
26594+++ b/arch/x86/kvm/cpuid.c
26595@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26596 struct kvm_cpuid2 *cpuid,
26597 struct kvm_cpuid_entry2 __user *entries)
26598 {
26599- int r;
26600+ int r, i;
26601
26602 r = -E2BIG;
26603 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26604 goto out;
26605 r = -EFAULT;
26606- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26607- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26608+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26609 goto out;
26610+ for (i = 0; i < cpuid->nent; ++i) {
26611+ struct kvm_cpuid_entry2 cpuid_entry;
26612+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26613+ goto out;
26614+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26615+ }
26616 vcpu->arch.cpuid_nent = cpuid->nent;
26617 kvm_apic_set_version(vcpu);
26618 kvm_x86_ops->cpuid_update(vcpu);
26619@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26620 struct kvm_cpuid2 *cpuid,
26621 struct kvm_cpuid_entry2 __user *entries)
26622 {
26623- int r;
26624+ int r, i;
26625
26626 r = -E2BIG;
26627 if (cpuid->nent < vcpu->arch.cpuid_nent)
26628 goto out;
26629 r = -EFAULT;
26630- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26631- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26632+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26633 goto out;
26634+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26635+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26636+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26637+ goto out;
26638+ }
26639 return 0;
26640
26641 out:
26642diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26643index 5439117..d08f3d4 100644
26644--- a/arch/x86/kvm/lapic.c
26645+++ b/arch/x86/kvm/lapic.c
26646@@ -55,7 +55,7 @@
26647 #define APIC_BUS_CYCLE_NS 1
26648
26649 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26650-#define apic_debug(fmt, arg...)
26651+#define apic_debug(fmt, arg...) do {} while (0)
26652
26653 #define APIC_LVT_NUM 6
26654 /* 14 is the version for Xeon and Pentium 8.4.8*/
26655diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26656index ad75d77..a679d32 100644
26657--- a/arch/x86/kvm/paging_tmpl.h
26658+++ b/arch/x86/kvm/paging_tmpl.h
26659@@ -331,7 +331,7 @@ retry_walk:
26660 if (unlikely(kvm_is_error_hva(host_addr)))
26661 goto error;
26662
26663- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26664+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26665 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26666 goto error;
26667 walker->ptep_user[walker->level - 1] = ptep_user;
26668diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26669index c0bc803..6837a50 100644
26670--- a/arch/x86/kvm/svm.c
26671+++ b/arch/x86/kvm/svm.c
26672@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26673 int cpu = raw_smp_processor_id();
26674
26675 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26676+
26677+ pax_open_kernel();
26678 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26679+ pax_close_kernel();
26680+
26681 load_TR_desc();
26682 }
26683
26684@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26685 #endif
26686 #endif
26687
26688+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26689+ __set_fs(current_thread_info()->addr_limit);
26690+#endif
26691+
26692 reload_tss(vcpu);
26693
26694 local_irq_disable();
26695diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26696index 2b2fce1..da76be4 100644
26697--- a/arch/x86/kvm/vmx.c
26698+++ b/arch/x86/kvm/vmx.c
26699@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26700 #endif
26701 }
26702
26703-static void vmcs_clear_bits(unsigned long field, u32 mask)
26704+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26705 {
26706 vmcs_writel(field, vmcs_readl(field) & ~mask);
26707 }
26708
26709-static void vmcs_set_bits(unsigned long field, u32 mask)
26710+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26711 {
26712 vmcs_writel(field, vmcs_readl(field) | mask);
26713 }
26714@@ -1522,7 +1522,11 @@ static void reload_tss(void)
26715 struct desc_struct *descs;
26716
26717 descs = (void *)gdt->address;
26718+
26719+ pax_open_kernel();
26720 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26721+ pax_close_kernel();
26722+
26723 load_TR_desc();
26724 }
26725
26726@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26727 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26728 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26729
26730+#ifdef CONFIG_PAX_PER_CPU_PGD
26731+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26732+#endif
26733+
26734 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26735 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26736 vmx->loaded_vmcs->cpu = cpu;
26737@@ -2037,7 +2045,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
26738 * reads and returns guest's timestamp counter "register"
26739 * guest_tsc = host_tsc + tsc_offset -- 21.3
26740 */
26741-static u64 guest_read_tsc(void)
26742+static u64 __intentional_overflow(-1) guest_read_tsc(void)
26743 {
26744 u64 host_tsc, tsc_offset;
26745
26746@@ -2982,8 +2990,11 @@ static __init int hardware_setup(void)
26747 if (!cpu_has_vmx_flexpriority())
26748 flexpriority_enabled = 0;
26749
26750- if (!cpu_has_vmx_tpr_shadow())
26751- kvm_x86_ops->update_cr8_intercept = NULL;
26752+ if (!cpu_has_vmx_tpr_shadow()) {
26753+ pax_open_kernel();
26754+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26755+ pax_close_kernel();
26756+ }
26757
26758 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26759 kvm_disable_largepages();
26760@@ -2994,13 +3005,15 @@ static __init int hardware_setup(void)
26761 if (!cpu_has_vmx_apicv())
26762 enable_apicv = 0;
26763
26764+ pax_open_kernel();
26765 if (enable_apicv)
26766- kvm_x86_ops->update_cr8_intercept = NULL;
26767+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26768 else {
26769- kvm_x86_ops->hwapic_irr_update = NULL;
26770- kvm_x86_ops->deliver_posted_interrupt = NULL;
26771- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26772+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26773+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26774+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26775 }
26776+ pax_close_kernel();
26777
26778 if (nested)
26779 nested_vmx_setup_ctls_msrs();
26780@@ -4127,7 +4140,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26781
26782 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26783 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26784+
26785+#ifndef CONFIG_PAX_PER_CPU_PGD
26786 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26787+#endif
26788
26789 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26790 #ifdef CONFIG_X86_64
26791@@ -4149,7 +4165,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26792 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26793 vmx->host_idt_base = dt.address;
26794
26795- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26796+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26797
26798 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26799 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26800@@ -7191,6 +7207,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26801 "jmp 2f \n\t"
26802 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26803 "2: "
26804+
26805+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26806+ "ljmp %[cs],$3f\n\t"
26807+ "3: "
26808+#endif
26809+
26810 /* Save guest registers, load host registers, keep flags */
26811 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26812 "pop %0 \n\t"
26813@@ -7243,6 +7265,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26814 #endif
26815 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26816 [wordsize]"i"(sizeof(ulong))
26817+
26818+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26819+ ,[cs]"i"(__KERNEL_CS)
26820+#endif
26821+
26822 : "cc", "memory"
26823 #ifdef CONFIG_X86_64
26824 , "rax", "rbx", "rdi", "rsi"
26825@@ -7256,7 +7283,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26826 if (debugctlmsr)
26827 update_debugctlmsr(debugctlmsr);
26828
26829-#ifndef CONFIG_X86_64
26830+#ifdef CONFIG_X86_32
26831 /*
26832 * The sysexit path does not restore ds/es, so we must set them to
26833 * a reasonable value ourselves.
26834@@ -7265,8 +7292,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26835 * may be executed in interrupt context, which saves and restore segments
26836 * around it, nullifying its effect.
26837 */
26838- loadsegment(ds, __USER_DS);
26839- loadsegment(es, __USER_DS);
26840+ loadsegment(ds, __KERNEL_DS);
26841+ loadsegment(es, __KERNEL_DS);
26842+ loadsegment(ss, __KERNEL_DS);
26843+
26844+#ifdef CONFIG_PAX_KERNEXEC
26845+ loadsegment(fs, __KERNEL_PERCPU);
26846+#endif
26847+
26848+#ifdef CONFIG_PAX_MEMORY_UDEREF
26849+ __set_fs(current_thread_info()->addr_limit);
26850+#endif
26851+
26852 #endif
26853
26854 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26855diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26856index e5ca72a..83d5177 100644
26857--- a/arch/x86/kvm/x86.c
26858+++ b/arch/x86/kvm/x86.c
26859@@ -1779,8 +1779,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26860 {
26861 struct kvm *kvm = vcpu->kvm;
26862 int lm = is_long_mode(vcpu);
26863- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26864- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26865+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26866+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26867 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26868 : kvm->arch.xen_hvm_config.blob_size_32;
26869 u32 page_num = data & ~PAGE_MASK;
26870@@ -2663,6 +2663,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26871 if (n < msr_list.nmsrs)
26872 goto out;
26873 r = -EFAULT;
26874+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26875+ goto out;
26876 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26877 num_msrs_to_save * sizeof(u32)))
26878 goto out;
26879@@ -5462,7 +5464,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26880 };
26881 #endif
26882
26883-int kvm_arch_init(void *opaque)
26884+int kvm_arch_init(const void *opaque)
26885 {
26886 int r;
26887 struct kvm_x86_ops *ops = opaque;
26888diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26889index bdf8532..f63c587 100644
26890--- a/arch/x86/lguest/boot.c
26891+++ b/arch/x86/lguest/boot.c
26892@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26893 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26894 * Launcher to reboot us.
26895 */
26896-static void lguest_restart(char *reason)
26897+static __noreturn void lguest_restart(char *reason)
26898 {
26899 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26900+ BUG();
26901 }
26902
26903 /*G:050
26904diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26905index 00933d5..3a64af9 100644
26906--- a/arch/x86/lib/atomic64_386_32.S
26907+++ b/arch/x86/lib/atomic64_386_32.S
26908@@ -48,6 +48,10 @@ BEGIN(read)
26909 movl (v), %eax
26910 movl 4(v), %edx
26911 RET_ENDP
26912+BEGIN(read_unchecked)
26913+ movl (v), %eax
26914+ movl 4(v), %edx
26915+RET_ENDP
26916 #undef v
26917
26918 #define v %esi
26919@@ -55,6 +59,10 @@ BEGIN(set)
26920 movl %ebx, (v)
26921 movl %ecx, 4(v)
26922 RET_ENDP
26923+BEGIN(set_unchecked)
26924+ movl %ebx, (v)
26925+ movl %ecx, 4(v)
26926+RET_ENDP
26927 #undef v
26928
26929 #define v %esi
26930@@ -70,6 +78,20 @@ RET_ENDP
26931 BEGIN(add)
26932 addl %eax, (v)
26933 adcl %edx, 4(v)
26934+
26935+#ifdef CONFIG_PAX_REFCOUNT
26936+ jno 0f
26937+ subl %eax, (v)
26938+ sbbl %edx, 4(v)
26939+ int $4
26940+0:
26941+ _ASM_EXTABLE(0b, 0b)
26942+#endif
26943+
26944+RET_ENDP
26945+BEGIN(add_unchecked)
26946+ addl %eax, (v)
26947+ adcl %edx, 4(v)
26948 RET_ENDP
26949 #undef v
26950
26951@@ -77,6 +99,24 @@ RET_ENDP
26952 BEGIN(add_return)
26953 addl (v), %eax
26954 adcl 4(v), %edx
26955+
26956+#ifdef CONFIG_PAX_REFCOUNT
26957+ into
26958+1234:
26959+ _ASM_EXTABLE(1234b, 2f)
26960+#endif
26961+
26962+ movl %eax, (v)
26963+ movl %edx, 4(v)
26964+
26965+#ifdef CONFIG_PAX_REFCOUNT
26966+2:
26967+#endif
26968+
26969+RET_ENDP
26970+BEGIN(add_return_unchecked)
26971+ addl (v), %eax
26972+ adcl 4(v), %edx
26973 movl %eax, (v)
26974 movl %edx, 4(v)
26975 RET_ENDP
26976@@ -86,6 +126,20 @@ RET_ENDP
26977 BEGIN(sub)
26978 subl %eax, (v)
26979 sbbl %edx, 4(v)
26980+
26981+#ifdef CONFIG_PAX_REFCOUNT
26982+ jno 0f
26983+ addl %eax, (v)
26984+ adcl %edx, 4(v)
26985+ int $4
26986+0:
26987+ _ASM_EXTABLE(0b, 0b)
26988+#endif
26989+
26990+RET_ENDP
26991+BEGIN(sub_unchecked)
26992+ subl %eax, (v)
26993+ sbbl %edx, 4(v)
26994 RET_ENDP
26995 #undef v
26996
26997@@ -96,6 +150,27 @@ BEGIN(sub_return)
26998 sbbl $0, %edx
26999 addl (v), %eax
27000 adcl 4(v), %edx
27001+
27002+#ifdef CONFIG_PAX_REFCOUNT
27003+ into
27004+1234:
27005+ _ASM_EXTABLE(1234b, 2f)
27006+#endif
27007+
27008+ movl %eax, (v)
27009+ movl %edx, 4(v)
27010+
27011+#ifdef CONFIG_PAX_REFCOUNT
27012+2:
27013+#endif
27014+
27015+RET_ENDP
27016+BEGIN(sub_return_unchecked)
27017+ negl %edx
27018+ negl %eax
27019+ sbbl $0, %edx
27020+ addl (v), %eax
27021+ adcl 4(v), %edx
27022 movl %eax, (v)
27023 movl %edx, 4(v)
27024 RET_ENDP
27025@@ -105,6 +180,20 @@ RET_ENDP
27026 BEGIN(inc)
27027 addl $1, (v)
27028 adcl $0, 4(v)
27029+
27030+#ifdef CONFIG_PAX_REFCOUNT
27031+ jno 0f
27032+ subl $1, (v)
27033+ sbbl $0, 4(v)
27034+ int $4
27035+0:
27036+ _ASM_EXTABLE(0b, 0b)
27037+#endif
27038+
27039+RET_ENDP
27040+BEGIN(inc_unchecked)
27041+ addl $1, (v)
27042+ adcl $0, 4(v)
27043 RET_ENDP
27044 #undef v
27045
27046@@ -114,6 +203,26 @@ BEGIN(inc_return)
27047 movl 4(v), %edx
27048 addl $1, %eax
27049 adcl $0, %edx
27050+
27051+#ifdef CONFIG_PAX_REFCOUNT
27052+ into
27053+1234:
27054+ _ASM_EXTABLE(1234b, 2f)
27055+#endif
27056+
27057+ movl %eax, (v)
27058+ movl %edx, 4(v)
27059+
27060+#ifdef CONFIG_PAX_REFCOUNT
27061+2:
27062+#endif
27063+
27064+RET_ENDP
27065+BEGIN(inc_return_unchecked)
27066+ movl (v), %eax
27067+ movl 4(v), %edx
27068+ addl $1, %eax
27069+ adcl $0, %edx
27070 movl %eax, (v)
27071 movl %edx, 4(v)
27072 RET_ENDP
27073@@ -123,6 +232,20 @@ RET_ENDP
27074 BEGIN(dec)
27075 subl $1, (v)
27076 sbbl $0, 4(v)
27077+
27078+#ifdef CONFIG_PAX_REFCOUNT
27079+ jno 0f
27080+ addl $1, (v)
27081+ adcl $0, 4(v)
27082+ int $4
27083+0:
27084+ _ASM_EXTABLE(0b, 0b)
27085+#endif
27086+
27087+RET_ENDP
27088+BEGIN(dec_unchecked)
27089+ subl $1, (v)
27090+ sbbl $0, 4(v)
27091 RET_ENDP
27092 #undef v
27093
27094@@ -132,6 +255,26 @@ BEGIN(dec_return)
27095 movl 4(v), %edx
27096 subl $1, %eax
27097 sbbl $0, %edx
27098+
27099+#ifdef CONFIG_PAX_REFCOUNT
27100+ into
27101+1234:
27102+ _ASM_EXTABLE(1234b, 2f)
27103+#endif
27104+
27105+ movl %eax, (v)
27106+ movl %edx, 4(v)
27107+
27108+#ifdef CONFIG_PAX_REFCOUNT
27109+2:
27110+#endif
27111+
27112+RET_ENDP
27113+BEGIN(dec_return_unchecked)
27114+ movl (v), %eax
27115+ movl 4(v), %edx
27116+ subl $1, %eax
27117+ sbbl $0, %edx
27118 movl %eax, (v)
27119 movl %edx, 4(v)
27120 RET_ENDP
27121@@ -143,6 +286,13 @@ BEGIN(add_unless)
27122 adcl %edx, %edi
27123 addl (v), %eax
27124 adcl 4(v), %edx
27125+
27126+#ifdef CONFIG_PAX_REFCOUNT
27127+ into
27128+1234:
27129+ _ASM_EXTABLE(1234b, 2f)
27130+#endif
27131+
27132 cmpl %eax, %ecx
27133 je 3f
27134 1:
27135@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27136 1:
27137 addl $1, %eax
27138 adcl $0, %edx
27139+
27140+#ifdef CONFIG_PAX_REFCOUNT
27141+ into
27142+1234:
27143+ _ASM_EXTABLE(1234b, 2f)
27144+#endif
27145+
27146 movl %eax, (v)
27147 movl %edx, 4(v)
27148 movl $1, %eax
27149@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27150 movl 4(v), %edx
27151 subl $1, %eax
27152 sbbl $0, %edx
27153+
27154+#ifdef CONFIG_PAX_REFCOUNT
27155+ into
27156+1234:
27157+ _ASM_EXTABLE(1234b, 1f)
27158+#endif
27159+
27160 js 1f
27161 movl %eax, (v)
27162 movl %edx, 4(v)
27163diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27164index f5cc9eb..51fa319 100644
27165--- a/arch/x86/lib/atomic64_cx8_32.S
27166+++ b/arch/x86/lib/atomic64_cx8_32.S
27167@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27168 CFI_STARTPROC
27169
27170 read64 %ecx
27171+ pax_force_retaddr
27172 ret
27173 CFI_ENDPROC
27174 ENDPROC(atomic64_read_cx8)
27175
27176+ENTRY(atomic64_read_unchecked_cx8)
27177+ CFI_STARTPROC
27178+
27179+ read64 %ecx
27180+ pax_force_retaddr
27181+ ret
27182+ CFI_ENDPROC
27183+ENDPROC(atomic64_read_unchecked_cx8)
27184+
27185 ENTRY(atomic64_set_cx8)
27186 CFI_STARTPROC
27187
27188@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27189 cmpxchg8b (%esi)
27190 jne 1b
27191
27192+ pax_force_retaddr
27193 ret
27194 CFI_ENDPROC
27195 ENDPROC(atomic64_set_cx8)
27196
27197+ENTRY(atomic64_set_unchecked_cx8)
27198+ CFI_STARTPROC
27199+
27200+1:
27201+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27202+ * are atomic on 586 and newer */
27203+ cmpxchg8b (%esi)
27204+ jne 1b
27205+
27206+ pax_force_retaddr
27207+ ret
27208+ CFI_ENDPROC
27209+ENDPROC(atomic64_set_unchecked_cx8)
27210+
27211 ENTRY(atomic64_xchg_cx8)
27212 CFI_STARTPROC
27213
27214@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27215 cmpxchg8b (%esi)
27216 jne 1b
27217
27218+ pax_force_retaddr
27219 ret
27220 CFI_ENDPROC
27221 ENDPROC(atomic64_xchg_cx8)
27222
27223-.macro addsub_return func ins insc
27224-ENTRY(atomic64_\func\()_return_cx8)
27225+.macro addsub_return func ins insc unchecked=""
27226+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27227 CFI_STARTPROC
27228 SAVE ebp
27229 SAVE ebx
27230@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27231 movl %edx, %ecx
27232 \ins\()l %esi, %ebx
27233 \insc\()l %edi, %ecx
27234+
27235+.ifb \unchecked
27236+#ifdef CONFIG_PAX_REFCOUNT
27237+ into
27238+2:
27239+ _ASM_EXTABLE(2b, 3f)
27240+#endif
27241+.endif
27242+
27243 LOCK_PREFIX
27244 cmpxchg8b (%ebp)
27245 jne 1b
27246-
27247-10:
27248 movl %ebx, %eax
27249 movl %ecx, %edx
27250+
27251+.ifb \unchecked
27252+#ifdef CONFIG_PAX_REFCOUNT
27253+3:
27254+#endif
27255+.endif
27256+
27257 RESTORE edi
27258 RESTORE esi
27259 RESTORE ebx
27260 RESTORE ebp
27261+ pax_force_retaddr
27262 ret
27263 CFI_ENDPROC
27264-ENDPROC(atomic64_\func\()_return_cx8)
27265+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27266 .endm
27267
27268 addsub_return add add adc
27269 addsub_return sub sub sbb
27270+addsub_return add add adc _unchecked
27271+addsub_return sub sub sbb _unchecked
27272
27273-.macro incdec_return func ins insc
27274-ENTRY(atomic64_\func\()_return_cx8)
27275+.macro incdec_return func ins insc unchecked=""
27276+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27277 CFI_STARTPROC
27278 SAVE ebx
27279
27280@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27281 movl %edx, %ecx
27282 \ins\()l $1, %ebx
27283 \insc\()l $0, %ecx
27284+
27285+.ifb \unchecked
27286+#ifdef CONFIG_PAX_REFCOUNT
27287+ into
27288+2:
27289+ _ASM_EXTABLE(2b, 3f)
27290+#endif
27291+.endif
27292+
27293 LOCK_PREFIX
27294 cmpxchg8b (%esi)
27295 jne 1b
27296
27297-10:
27298 movl %ebx, %eax
27299 movl %ecx, %edx
27300+
27301+.ifb \unchecked
27302+#ifdef CONFIG_PAX_REFCOUNT
27303+3:
27304+#endif
27305+.endif
27306+
27307 RESTORE ebx
27308+ pax_force_retaddr
27309 ret
27310 CFI_ENDPROC
27311-ENDPROC(atomic64_\func\()_return_cx8)
27312+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27313 .endm
27314
27315 incdec_return inc add adc
27316 incdec_return dec sub sbb
27317+incdec_return inc add adc _unchecked
27318+incdec_return dec sub sbb _unchecked
27319
27320 ENTRY(atomic64_dec_if_positive_cx8)
27321 CFI_STARTPROC
27322@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27323 movl %edx, %ecx
27324 subl $1, %ebx
27325 sbb $0, %ecx
27326+
27327+#ifdef CONFIG_PAX_REFCOUNT
27328+ into
27329+1234:
27330+ _ASM_EXTABLE(1234b, 2f)
27331+#endif
27332+
27333 js 2f
27334 LOCK_PREFIX
27335 cmpxchg8b (%esi)
27336@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27337 movl %ebx, %eax
27338 movl %ecx, %edx
27339 RESTORE ebx
27340+ pax_force_retaddr
27341 ret
27342 CFI_ENDPROC
27343 ENDPROC(atomic64_dec_if_positive_cx8)
27344@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27345 movl %edx, %ecx
27346 addl %ebp, %ebx
27347 adcl %edi, %ecx
27348+
27349+#ifdef CONFIG_PAX_REFCOUNT
27350+ into
27351+1234:
27352+ _ASM_EXTABLE(1234b, 3f)
27353+#endif
27354+
27355 LOCK_PREFIX
27356 cmpxchg8b (%esi)
27357 jne 1b
27358@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27359 CFI_ADJUST_CFA_OFFSET -8
27360 RESTORE ebx
27361 RESTORE ebp
27362+ pax_force_retaddr
27363 ret
27364 4:
27365 cmpl %edx, 4(%esp)
27366@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27367 xorl %ecx, %ecx
27368 addl $1, %ebx
27369 adcl %edx, %ecx
27370+
27371+#ifdef CONFIG_PAX_REFCOUNT
27372+ into
27373+1234:
27374+ _ASM_EXTABLE(1234b, 3f)
27375+#endif
27376+
27377 LOCK_PREFIX
27378 cmpxchg8b (%esi)
27379 jne 1b
27380@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27381 movl $1, %eax
27382 3:
27383 RESTORE ebx
27384+ pax_force_retaddr
27385 ret
27386 CFI_ENDPROC
27387 ENDPROC(atomic64_inc_not_zero_cx8)
27388diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27389index e78b8ee..7e173a8 100644
27390--- a/arch/x86/lib/checksum_32.S
27391+++ b/arch/x86/lib/checksum_32.S
27392@@ -29,7 +29,8 @@
27393 #include <asm/dwarf2.h>
27394 #include <asm/errno.h>
27395 #include <asm/asm.h>
27396-
27397+#include <asm/segment.h>
27398+
27399 /*
27400 * computes a partial checksum, e.g. for TCP/UDP fragments
27401 */
27402@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27403
27404 #define ARGBASE 16
27405 #define FP 12
27406-
27407-ENTRY(csum_partial_copy_generic)
27408+
27409+ENTRY(csum_partial_copy_generic_to_user)
27410 CFI_STARTPROC
27411+
27412+#ifdef CONFIG_PAX_MEMORY_UDEREF
27413+ pushl_cfi %gs
27414+ popl_cfi %es
27415+ jmp csum_partial_copy_generic
27416+#endif
27417+
27418+ENTRY(csum_partial_copy_generic_from_user)
27419+
27420+#ifdef CONFIG_PAX_MEMORY_UDEREF
27421+ pushl_cfi %gs
27422+ popl_cfi %ds
27423+#endif
27424+
27425+ENTRY(csum_partial_copy_generic)
27426 subl $4,%esp
27427 CFI_ADJUST_CFA_OFFSET 4
27428 pushl_cfi %edi
27429@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27430 jmp 4f
27431 SRC(1: movw (%esi), %bx )
27432 addl $2, %esi
27433-DST( movw %bx, (%edi) )
27434+DST( movw %bx, %es:(%edi) )
27435 addl $2, %edi
27436 addw %bx, %ax
27437 adcl $0, %eax
27438@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27439 SRC(1: movl (%esi), %ebx )
27440 SRC( movl 4(%esi), %edx )
27441 adcl %ebx, %eax
27442-DST( movl %ebx, (%edi) )
27443+DST( movl %ebx, %es:(%edi) )
27444 adcl %edx, %eax
27445-DST( movl %edx, 4(%edi) )
27446+DST( movl %edx, %es:4(%edi) )
27447
27448 SRC( movl 8(%esi), %ebx )
27449 SRC( movl 12(%esi), %edx )
27450 adcl %ebx, %eax
27451-DST( movl %ebx, 8(%edi) )
27452+DST( movl %ebx, %es:8(%edi) )
27453 adcl %edx, %eax
27454-DST( movl %edx, 12(%edi) )
27455+DST( movl %edx, %es:12(%edi) )
27456
27457 SRC( movl 16(%esi), %ebx )
27458 SRC( movl 20(%esi), %edx )
27459 adcl %ebx, %eax
27460-DST( movl %ebx, 16(%edi) )
27461+DST( movl %ebx, %es:16(%edi) )
27462 adcl %edx, %eax
27463-DST( movl %edx, 20(%edi) )
27464+DST( movl %edx, %es:20(%edi) )
27465
27466 SRC( movl 24(%esi), %ebx )
27467 SRC( movl 28(%esi), %edx )
27468 adcl %ebx, %eax
27469-DST( movl %ebx, 24(%edi) )
27470+DST( movl %ebx, %es:24(%edi) )
27471 adcl %edx, %eax
27472-DST( movl %edx, 28(%edi) )
27473+DST( movl %edx, %es:28(%edi) )
27474
27475 lea 32(%esi), %esi
27476 lea 32(%edi), %edi
27477@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27478 shrl $2, %edx # This clears CF
27479 SRC(3: movl (%esi), %ebx )
27480 adcl %ebx, %eax
27481-DST( movl %ebx, (%edi) )
27482+DST( movl %ebx, %es:(%edi) )
27483 lea 4(%esi), %esi
27484 lea 4(%edi), %edi
27485 dec %edx
27486@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27487 jb 5f
27488 SRC( movw (%esi), %cx )
27489 leal 2(%esi), %esi
27490-DST( movw %cx, (%edi) )
27491+DST( movw %cx, %es:(%edi) )
27492 leal 2(%edi), %edi
27493 je 6f
27494 shll $16,%ecx
27495 SRC(5: movb (%esi), %cl )
27496-DST( movb %cl, (%edi) )
27497+DST( movb %cl, %es:(%edi) )
27498 6: addl %ecx, %eax
27499 adcl $0, %eax
27500 7:
27501@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27502
27503 6001:
27504 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27505- movl $-EFAULT, (%ebx)
27506+ movl $-EFAULT, %ss:(%ebx)
27507
27508 # zero the complete destination - computing the rest
27509 # is too much work
27510@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27511
27512 6002:
27513 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27514- movl $-EFAULT,(%ebx)
27515+ movl $-EFAULT,%ss:(%ebx)
27516 jmp 5000b
27517
27518 .previous
27519
27520+ pushl_cfi %ss
27521+ popl_cfi %ds
27522+ pushl_cfi %ss
27523+ popl_cfi %es
27524 popl_cfi %ebx
27525 CFI_RESTORE ebx
27526 popl_cfi %esi
27527@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27528 popl_cfi %ecx # equivalent to addl $4,%esp
27529 ret
27530 CFI_ENDPROC
27531-ENDPROC(csum_partial_copy_generic)
27532+ENDPROC(csum_partial_copy_generic_to_user)
27533
27534 #else
27535
27536 /* Version for PentiumII/PPro */
27537
27538 #define ROUND1(x) \
27539+ nop; nop; nop; \
27540 SRC(movl x(%esi), %ebx ) ; \
27541 addl %ebx, %eax ; \
27542- DST(movl %ebx, x(%edi) ) ;
27543+ DST(movl %ebx, %es:x(%edi)) ;
27544
27545 #define ROUND(x) \
27546+ nop; nop; nop; \
27547 SRC(movl x(%esi), %ebx ) ; \
27548 adcl %ebx, %eax ; \
27549- DST(movl %ebx, x(%edi) ) ;
27550+ DST(movl %ebx, %es:x(%edi)) ;
27551
27552 #define ARGBASE 12
27553-
27554-ENTRY(csum_partial_copy_generic)
27555+
27556+ENTRY(csum_partial_copy_generic_to_user)
27557 CFI_STARTPROC
27558+
27559+#ifdef CONFIG_PAX_MEMORY_UDEREF
27560+ pushl_cfi %gs
27561+ popl_cfi %es
27562+ jmp csum_partial_copy_generic
27563+#endif
27564+
27565+ENTRY(csum_partial_copy_generic_from_user)
27566+
27567+#ifdef CONFIG_PAX_MEMORY_UDEREF
27568+ pushl_cfi %gs
27569+ popl_cfi %ds
27570+#endif
27571+
27572+ENTRY(csum_partial_copy_generic)
27573 pushl_cfi %ebx
27574 CFI_REL_OFFSET ebx, 0
27575 pushl_cfi %edi
27576@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27577 subl %ebx, %edi
27578 lea -1(%esi),%edx
27579 andl $-32,%edx
27580- lea 3f(%ebx,%ebx), %ebx
27581+ lea 3f(%ebx,%ebx,2), %ebx
27582 testl %esi, %esi
27583 jmp *%ebx
27584 1: addl $64,%esi
27585@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27586 jb 5f
27587 SRC( movw (%esi), %dx )
27588 leal 2(%esi), %esi
27589-DST( movw %dx, (%edi) )
27590+DST( movw %dx, %es:(%edi) )
27591 leal 2(%edi), %edi
27592 je 6f
27593 shll $16,%edx
27594 5:
27595 SRC( movb (%esi), %dl )
27596-DST( movb %dl, (%edi) )
27597+DST( movb %dl, %es:(%edi) )
27598 6: addl %edx, %eax
27599 adcl $0, %eax
27600 7:
27601 .section .fixup, "ax"
27602 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27603- movl $-EFAULT, (%ebx)
27604+ movl $-EFAULT, %ss:(%ebx)
27605 # zero the complete destination (computing the rest is too much work)
27606 movl ARGBASE+8(%esp),%edi # dst
27607 movl ARGBASE+12(%esp),%ecx # len
27608@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27609 rep; stosb
27610 jmp 7b
27611 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27612- movl $-EFAULT, (%ebx)
27613+ movl $-EFAULT, %ss:(%ebx)
27614 jmp 7b
27615 .previous
27616
27617+#ifdef CONFIG_PAX_MEMORY_UDEREF
27618+ pushl_cfi %ss
27619+ popl_cfi %ds
27620+ pushl_cfi %ss
27621+ popl_cfi %es
27622+#endif
27623+
27624 popl_cfi %esi
27625 CFI_RESTORE esi
27626 popl_cfi %edi
27627@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27628 CFI_RESTORE ebx
27629 ret
27630 CFI_ENDPROC
27631-ENDPROC(csum_partial_copy_generic)
27632+ENDPROC(csum_partial_copy_generic_to_user)
27633
27634 #undef ROUND
27635 #undef ROUND1
27636diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27637index f2145cf..cea889d 100644
27638--- a/arch/x86/lib/clear_page_64.S
27639+++ b/arch/x86/lib/clear_page_64.S
27640@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27641 movl $4096/8,%ecx
27642 xorl %eax,%eax
27643 rep stosq
27644+ pax_force_retaddr
27645 ret
27646 CFI_ENDPROC
27647 ENDPROC(clear_page_c)
27648@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27649 movl $4096,%ecx
27650 xorl %eax,%eax
27651 rep stosb
27652+ pax_force_retaddr
27653 ret
27654 CFI_ENDPROC
27655 ENDPROC(clear_page_c_e)
27656@@ -43,6 +45,7 @@ ENTRY(clear_page)
27657 leaq 64(%rdi),%rdi
27658 jnz .Lloop
27659 nop
27660+ pax_force_retaddr
27661 ret
27662 CFI_ENDPROC
27663 .Lclear_page_end:
27664@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27665
27666 #include <asm/cpufeature.h>
27667
27668- .section .altinstr_replacement,"ax"
27669+ .section .altinstr_replacement,"a"
27670 1: .byte 0xeb /* jmp <disp8> */
27671 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27672 2: .byte 0xeb /* jmp <disp8> */
27673diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27674index 1e572c5..2a162cd 100644
27675--- a/arch/x86/lib/cmpxchg16b_emu.S
27676+++ b/arch/x86/lib/cmpxchg16b_emu.S
27677@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27678
27679 popf
27680 mov $1, %al
27681+ pax_force_retaddr
27682 ret
27683
27684 not_same:
27685 popf
27686 xor %al,%al
27687+ pax_force_retaddr
27688 ret
27689
27690 CFI_ENDPROC
27691diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27692index 176cca6..1166c50 100644
27693--- a/arch/x86/lib/copy_page_64.S
27694+++ b/arch/x86/lib/copy_page_64.S
27695@@ -9,6 +9,7 @@ copy_page_rep:
27696 CFI_STARTPROC
27697 movl $4096/8, %ecx
27698 rep movsq
27699+ pax_force_retaddr
27700 ret
27701 CFI_ENDPROC
27702 ENDPROC(copy_page_rep)
27703@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27704
27705 ENTRY(copy_page)
27706 CFI_STARTPROC
27707- subq $2*8, %rsp
27708- CFI_ADJUST_CFA_OFFSET 2*8
27709+ subq $3*8, %rsp
27710+ CFI_ADJUST_CFA_OFFSET 3*8
27711 movq %rbx, (%rsp)
27712 CFI_REL_OFFSET rbx, 0
27713 movq %r12, 1*8(%rsp)
27714 CFI_REL_OFFSET r12, 1*8
27715+ movq %r13, 2*8(%rsp)
27716+ CFI_REL_OFFSET r13, 2*8
27717
27718 movl $(4096/64)-5, %ecx
27719 .p2align 4
27720@@ -36,7 +39,7 @@ ENTRY(copy_page)
27721 movq 0x8*2(%rsi), %rdx
27722 movq 0x8*3(%rsi), %r8
27723 movq 0x8*4(%rsi), %r9
27724- movq 0x8*5(%rsi), %r10
27725+ movq 0x8*5(%rsi), %r13
27726 movq 0x8*6(%rsi), %r11
27727 movq 0x8*7(%rsi), %r12
27728
27729@@ -47,7 +50,7 @@ ENTRY(copy_page)
27730 movq %rdx, 0x8*2(%rdi)
27731 movq %r8, 0x8*3(%rdi)
27732 movq %r9, 0x8*4(%rdi)
27733- movq %r10, 0x8*5(%rdi)
27734+ movq %r13, 0x8*5(%rdi)
27735 movq %r11, 0x8*6(%rdi)
27736 movq %r12, 0x8*7(%rdi)
27737
27738@@ -66,7 +69,7 @@ ENTRY(copy_page)
27739 movq 0x8*2(%rsi), %rdx
27740 movq 0x8*3(%rsi), %r8
27741 movq 0x8*4(%rsi), %r9
27742- movq 0x8*5(%rsi), %r10
27743+ movq 0x8*5(%rsi), %r13
27744 movq 0x8*6(%rsi), %r11
27745 movq 0x8*7(%rsi), %r12
27746
27747@@ -75,7 +78,7 @@ ENTRY(copy_page)
27748 movq %rdx, 0x8*2(%rdi)
27749 movq %r8, 0x8*3(%rdi)
27750 movq %r9, 0x8*4(%rdi)
27751- movq %r10, 0x8*5(%rdi)
27752+ movq %r13, 0x8*5(%rdi)
27753 movq %r11, 0x8*6(%rdi)
27754 movq %r12, 0x8*7(%rdi)
27755
27756@@ -87,8 +90,11 @@ ENTRY(copy_page)
27757 CFI_RESTORE rbx
27758 movq 1*8(%rsp), %r12
27759 CFI_RESTORE r12
27760- addq $2*8, %rsp
27761- CFI_ADJUST_CFA_OFFSET -2*8
27762+ movq 2*8(%rsp), %r13
27763+ CFI_RESTORE r13
27764+ addq $3*8, %rsp
27765+ CFI_ADJUST_CFA_OFFSET -3*8
27766+ pax_force_retaddr
27767 ret
27768 .Lcopy_page_end:
27769 CFI_ENDPROC
27770@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27771
27772 #include <asm/cpufeature.h>
27773
27774- .section .altinstr_replacement,"ax"
27775+ .section .altinstr_replacement,"a"
27776 1: .byte 0xeb /* jmp <disp8> */
27777 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27778 2:
27779diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27780index a30ca15..6b3f4e1 100644
27781--- a/arch/x86/lib/copy_user_64.S
27782+++ b/arch/x86/lib/copy_user_64.S
27783@@ -18,31 +18,7 @@
27784 #include <asm/alternative-asm.h>
27785 #include <asm/asm.h>
27786 #include <asm/smap.h>
27787-
27788-/*
27789- * By placing feature2 after feature1 in altinstructions section, we logically
27790- * implement:
27791- * If CPU has feature2, jmp to alt2 is used
27792- * else if CPU has feature1, jmp to alt1 is used
27793- * else jmp to orig is used.
27794- */
27795- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27796-0:
27797- .byte 0xe9 /* 32bit jump */
27798- .long \orig-1f /* by default jump to orig */
27799-1:
27800- .section .altinstr_replacement,"ax"
27801-2: .byte 0xe9 /* near jump with 32bit immediate */
27802- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27803-3: .byte 0xe9 /* near jump with 32bit immediate */
27804- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27805- .previous
27806-
27807- .section .altinstructions,"a"
27808- altinstruction_entry 0b,2b,\feature1,5,5
27809- altinstruction_entry 0b,3b,\feature2,5,5
27810- .previous
27811- .endm
27812+#include <asm/pgtable.h>
27813
27814 .macro ALIGN_DESTINATION
27815 #ifdef FIX_ALIGNMENT
27816@@ -70,52 +46,6 @@
27817 #endif
27818 .endm
27819
27820-/* Standard copy_to_user with segment limit checking */
27821-ENTRY(_copy_to_user)
27822- CFI_STARTPROC
27823- GET_THREAD_INFO(%rax)
27824- movq %rdi,%rcx
27825- addq %rdx,%rcx
27826- jc bad_to_user
27827- cmpq TI_addr_limit(%rax),%rcx
27828- ja bad_to_user
27829- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27830- copy_user_generic_unrolled,copy_user_generic_string, \
27831- copy_user_enhanced_fast_string
27832- CFI_ENDPROC
27833-ENDPROC(_copy_to_user)
27834-
27835-/* Standard copy_from_user with segment limit checking */
27836-ENTRY(_copy_from_user)
27837- CFI_STARTPROC
27838- GET_THREAD_INFO(%rax)
27839- movq %rsi,%rcx
27840- addq %rdx,%rcx
27841- jc bad_from_user
27842- cmpq TI_addr_limit(%rax),%rcx
27843- ja bad_from_user
27844- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27845- copy_user_generic_unrolled,copy_user_generic_string, \
27846- copy_user_enhanced_fast_string
27847- CFI_ENDPROC
27848-ENDPROC(_copy_from_user)
27849-
27850- .section .fixup,"ax"
27851- /* must zero dest */
27852-ENTRY(bad_from_user)
27853-bad_from_user:
27854- CFI_STARTPROC
27855- movl %edx,%ecx
27856- xorl %eax,%eax
27857- rep
27858- stosb
27859-bad_to_user:
27860- movl %edx,%eax
27861- ret
27862- CFI_ENDPROC
27863-ENDPROC(bad_from_user)
27864- .previous
27865-
27866 /*
27867 * copy_user_generic_unrolled - memory copy with exception handling.
27868 * This version is for CPUs like P4 that don't have efficient micro
27869@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27870 */
27871 ENTRY(copy_user_generic_unrolled)
27872 CFI_STARTPROC
27873+ ASM_PAX_OPEN_USERLAND
27874 ASM_STAC
27875 cmpl $8,%edx
27876 jb 20f /* less then 8 bytes, go to byte copy loop */
27877@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27878 jz 17f
27879 1: movq (%rsi),%r8
27880 2: movq 1*8(%rsi),%r9
27881-3: movq 2*8(%rsi),%r10
27882+3: movq 2*8(%rsi),%rax
27883 4: movq 3*8(%rsi),%r11
27884 5: movq %r8,(%rdi)
27885 6: movq %r9,1*8(%rdi)
27886-7: movq %r10,2*8(%rdi)
27887+7: movq %rax,2*8(%rdi)
27888 8: movq %r11,3*8(%rdi)
27889 9: movq 4*8(%rsi),%r8
27890 10: movq 5*8(%rsi),%r9
27891-11: movq 6*8(%rsi),%r10
27892+11: movq 6*8(%rsi),%rax
27893 12: movq 7*8(%rsi),%r11
27894 13: movq %r8,4*8(%rdi)
27895 14: movq %r9,5*8(%rdi)
27896-15: movq %r10,6*8(%rdi)
27897+15: movq %rax,6*8(%rdi)
27898 16: movq %r11,7*8(%rdi)
27899 leaq 64(%rsi),%rsi
27900 leaq 64(%rdi),%rdi
27901@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27902 jnz 21b
27903 23: xor %eax,%eax
27904 ASM_CLAC
27905+ ASM_PAX_CLOSE_USERLAND
27906+ pax_force_retaddr
27907 ret
27908
27909 .section .fixup,"ax"
27910@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27911 */
27912 ENTRY(copy_user_generic_string)
27913 CFI_STARTPROC
27914+ ASM_PAX_OPEN_USERLAND
27915 ASM_STAC
27916 andl %edx,%edx
27917 jz 4f
27918@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27919 movsb
27920 4: xorl %eax,%eax
27921 ASM_CLAC
27922+ ASM_PAX_CLOSE_USERLAND
27923+ pax_force_retaddr
27924 ret
27925
27926 .section .fixup,"ax"
27927@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27928 */
27929 ENTRY(copy_user_enhanced_fast_string)
27930 CFI_STARTPROC
27931+ ASM_PAX_OPEN_USERLAND
27932 ASM_STAC
27933 andl %edx,%edx
27934 jz 2f
27935@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27936 movsb
27937 2: xorl %eax,%eax
27938 ASM_CLAC
27939+ ASM_PAX_CLOSE_USERLAND
27940+ pax_force_retaddr
27941 ret
27942
27943 .section .fixup,"ax"
27944diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27945index 6a4f43c..55d26f2 100644
27946--- a/arch/x86/lib/copy_user_nocache_64.S
27947+++ b/arch/x86/lib/copy_user_nocache_64.S
27948@@ -8,6 +8,7 @@
27949
27950 #include <linux/linkage.h>
27951 #include <asm/dwarf2.h>
27952+#include <asm/alternative-asm.h>
27953
27954 #define FIX_ALIGNMENT 1
27955
27956@@ -16,6 +17,7 @@
27957 #include <asm/thread_info.h>
27958 #include <asm/asm.h>
27959 #include <asm/smap.h>
27960+#include <asm/pgtable.h>
27961
27962 .macro ALIGN_DESTINATION
27963 #ifdef FIX_ALIGNMENT
27964@@ -49,6 +51,16 @@
27965 */
27966 ENTRY(__copy_user_nocache)
27967 CFI_STARTPROC
27968+
27969+#ifdef CONFIG_PAX_MEMORY_UDEREF
27970+ mov pax_user_shadow_base,%rcx
27971+ cmp %rcx,%rsi
27972+ jae 1f
27973+ add %rcx,%rsi
27974+1:
27975+#endif
27976+
27977+ ASM_PAX_OPEN_USERLAND
27978 ASM_STAC
27979 cmpl $8,%edx
27980 jb 20f /* less then 8 bytes, go to byte copy loop */
27981@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27982 jz 17f
27983 1: movq (%rsi),%r8
27984 2: movq 1*8(%rsi),%r9
27985-3: movq 2*8(%rsi),%r10
27986+3: movq 2*8(%rsi),%rax
27987 4: movq 3*8(%rsi),%r11
27988 5: movnti %r8,(%rdi)
27989 6: movnti %r9,1*8(%rdi)
27990-7: movnti %r10,2*8(%rdi)
27991+7: movnti %rax,2*8(%rdi)
27992 8: movnti %r11,3*8(%rdi)
27993 9: movq 4*8(%rsi),%r8
27994 10: movq 5*8(%rsi),%r9
27995-11: movq 6*8(%rsi),%r10
27996+11: movq 6*8(%rsi),%rax
27997 12: movq 7*8(%rsi),%r11
27998 13: movnti %r8,4*8(%rdi)
27999 14: movnti %r9,5*8(%rdi)
28000-15: movnti %r10,6*8(%rdi)
28001+15: movnti %rax,6*8(%rdi)
28002 16: movnti %r11,7*8(%rdi)
28003 leaq 64(%rsi),%rsi
28004 leaq 64(%rdi),%rdi
28005@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28006 jnz 21b
28007 23: xorl %eax,%eax
28008 ASM_CLAC
28009+ ASM_PAX_CLOSE_USERLAND
28010 sfence
28011+ pax_force_retaddr
28012 ret
28013
28014 .section .fixup,"ax"
28015diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28016index 2419d5f..953ee51 100644
28017--- a/arch/x86/lib/csum-copy_64.S
28018+++ b/arch/x86/lib/csum-copy_64.S
28019@@ -9,6 +9,7 @@
28020 #include <asm/dwarf2.h>
28021 #include <asm/errno.h>
28022 #include <asm/asm.h>
28023+#include <asm/alternative-asm.h>
28024
28025 /*
28026 * Checksum copy with exception handling.
28027@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28028 CFI_RESTORE rbp
28029 addq $7*8, %rsp
28030 CFI_ADJUST_CFA_OFFSET -7*8
28031+ pax_force_retaddr 0, 1
28032 ret
28033 CFI_RESTORE_STATE
28034
28035diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28036index 7609e0e..b449b98 100644
28037--- a/arch/x86/lib/csum-wrappers_64.c
28038+++ b/arch/x86/lib/csum-wrappers_64.c
28039@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28040 len -= 2;
28041 }
28042 }
28043+ pax_open_userland();
28044 stac();
28045- isum = csum_partial_copy_generic((__force const void *)src,
28046+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28047 dst, len, isum, errp, NULL);
28048 clac();
28049+ pax_close_userland();
28050 if (unlikely(*errp))
28051 goto out_err;
28052
28053@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28054 }
28055
28056 *errp = 0;
28057+ pax_open_userland();
28058 stac();
28059- ret = csum_partial_copy_generic(src, (void __force *)dst,
28060+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28061 len, isum, NULL, errp);
28062 clac();
28063+ pax_close_userland();
28064 return ret;
28065 }
28066 EXPORT_SYMBOL(csum_partial_copy_to_user);
28067diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28068index a451235..1daa956 100644
28069--- a/arch/x86/lib/getuser.S
28070+++ b/arch/x86/lib/getuser.S
28071@@ -33,17 +33,40 @@
28072 #include <asm/thread_info.h>
28073 #include <asm/asm.h>
28074 #include <asm/smap.h>
28075+#include <asm/segment.h>
28076+#include <asm/pgtable.h>
28077+#include <asm/alternative-asm.h>
28078+
28079+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28080+#define __copyuser_seg gs;
28081+#else
28082+#define __copyuser_seg
28083+#endif
28084
28085 .text
28086 ENTRY(__get_user_1)
28087 CFI_STARTPROC
28088+
28089+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28090 GET_THREAD_INFO(%_ASM_DX)
28091 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28092 jae bad_get_user
28093 ASM_STAC
28094-1: movzbl (%_ASM_AX),%edx
28095+
28096+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28097+ mov pax_user_shadow_base,%_ASM_DX
28098+ cmp %_ASM_DX,%_ASM_AX
28099+ jae 1234f
28100+ add %_ASM_DX,%_ASM_AX
28101+1234:
28102+#endif
28103+
28104+#endif
28105+
28106+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28107 xor %eax,%eax
28108 ASM_CLAC
28109+ pax_force_retaddr
28110 ret
28111 CFI_ENDPROC
28112 ENDPROC(__get_user_1)
28113@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28114 ENTRY(__get_user_2)
28115 CFI_STARTPROC
28116 add $1,%_ASM_AX
28117+
28118+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28119 jc bad_get_user
28120 GET_THREAD_INFO(%_ASM_DX)
28121 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28122 jae bad_get_user
28123 ASM_STAC
28124-2: movzwl -1(%_ASM_AX),%edx
28125+
28126+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28127+ mov pax_user_shadow_base,%_ASM_DX
28128+ cmp %_ASM_DX,%_ASM_AX
28129+ jae 1234f
28130+ add %_ASM_DX,%_ASM_AX
28131+1234:
28132+#endif
28133+
28134+#endif
28135+
28136+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28137 xor %eax,%eax
28138 ASM_CLAC
28139+ pax_force_retaddr
28140 ret
28141 CFI_ENDPROC
28142 ENDPROC(__get_user_2)
28143@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28144 ENTRY(__get_user_4)
28145 CFI_STARTPROC
28146 add $3,%_ASM_AX
28147+
28148+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28149 jc bad_get_user
28150 GET_THREAD_INFO(%_ASM_DX)
28151 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28152 jae bad_get_user
28153 ASM_STAC
28154-3: movl -3(%_ASM_AX),%edx
28155+
28156+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28157+ mov pax_user_shadow_base,%_ASM_DX
28158+ cmp %_ASM_DX,%_ASM_AX
28159+ jae 1234f
28160+ add %_ASM_DX,%_ASM_AX
28161+1234:
28162+#endif
28163+
28164+#endif
28165+
28166+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28167 xor %eax,%eax
28168 ASM_CLAC
28169+ pax_force_retaddr
28170 ret
28171 CFI_ENDPROC
28172 ENDPROC(__get_user_4)
28173@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28174 GET_THREAD_INFO(%_ASM_DX)
28175 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28176 jae bad_get_user
28177+
28178+#ifdef CONFIG_PAX_MEMORY_UDEREF
28179+ mov pax_user_shadow_base,%_ASM_DX
28180+ cmp %_ASM_DX,%_ASM_AX
28181+ jae 1234f
28182+ add %_ASM_DX,%_ASM_AX
28183+1234:
28184+#endif
28185+
28186 ASM_STAC
28187 4: movq -7(%_ASM_AX),%rdx
28188 xor %eax,%eax
28189 ASM_CLAC
28190+ pax_force_retaddr
28191 ret
28192 #else
28193 add $7,%_ASM_AX
28194@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28195 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28196 jae bad_get_user_8
28197 ASM_STAC
28198-4: movl -7(%_ASM_AX),%edx
28199-5: movl -3(%_ASM_AX),%ecx
28200+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28201+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28202 xor %eax,%eax
28203 ASM_CLAC
28204+ pax_force_retaddr
28205 ret
28206 #endif
28207 CFI_ENDPROC
28208@@ -113,6 +175,7 @@ bad_get_user:
28209 xor %edx,%edx
28210 mov $(-EFAULT),%_ASM_AX
28211 ASM_CLAC
28212+ pax_force_retaddr
28213 ret
28214 CFI_ENDPROC
28215 END(bad_get_user)
28216@@ -124,6 +187,7 @@ bad_get_user_8:
28217 xor %ecx,%ecx
28218 mov $(-EFAULT),%_ASM_AX
28219 ASM_CLAC
28220+ pax_force_retaddr
28221 ret
28222 CFI_ENDPROC
28223 END(bad_get_user_8)
28224diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28225index 54fcffe..7be149e 100644
28226--- a/arch/x86/lib/insn.c
28227+++ b/arch/x86/lib/insn.c
28228@@ -20,8 +20,10 @@
28229
28230 #ifdef __KERNEL__
28231 #include <linux/string.h>
28232+#include <asm/pgtable_types.h>
28233 #else
28234 #include <string.h>
28235+#define ktla_ktva(addr) addr
28236 #endif
28237 #include <asm/inat.h>
28238 #include <asm/insn.h>
28239@@ -53,8 +55,8 @@
28240 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28241 {
28242 memset(insn, 0, sizeof(*insn));
28243- insn->kaddr = kaddr;
28244- insn->next_byte = kaddr;
28245+ insn->kaddr = ktla_ktva(kaddr);
28246+ insn->next_byte = ktla_ktva(kaddr);
28247 insn->x86_64 = x86_64 ? 1 : 0;
28248 insn->opnd_bytes = 4;
28249 if (x86_64)
28250diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28251index 05a95e7..326f2fa 100644
28252--- a/arch/x86/lib/iomap_copy_64.S
28253+++ b/arch/x86/lib/iomap_copy_64.S
28254@@ -17,6 +17,7 @@
28255
28256 #include <linux/linkage.h>
28257 #include <asm/dwarf2.h>
28258+#include <asm/alternative-asm.h>
28259
28260 /*
28261 * override generic version in lib/iomap_copy.c
28262@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28263 CFI_STARTPROC
28264 movl %edx,%ecx
28265 rep movsd
28266+ pax_force_retaddr
28267 ret
28268 CFI_ENDPROC
28269 ENDPROC(__iowrite32_copy)
28270diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28271index 56313a3..9b59269 100644
28272--- a/arch/x86/lib/memcpy_64.S
28273+++ b/arch/x86/lib/memcpy_64.S
28274@@ -24,7 +24,7 @@
28275 * This gets patched over the unrolled variant (below) via the
28276 * alternative instructions framework:
28277 */
28278- .section .altinstr_replacement, "ax", @progbits
28279+ .section .altinstr_replacement, "a", @progbits
28280 .Lmemcpy_c:
28281 movq %rdi, %rax
28282 movq %rdx, %rcx
28283@@ -33,6 +33,7 @@
28284 rep movsq
28285 movl %edx, %ecx
28286 rep movsb
28287+ pax_force_retaddr
28288 ret
28289 .Lmemcpy_e:
28290 .previous
28291@@ -44,11 +45,12 @@
28292 * This gets patched over the unrolled variant (below) via the
28293 * alternative instructions framework:
28294 */
28295- .section .altinstr_replacement, "ax", @progbits
28296+ .section .altinstr_replacement, "a", @progbits
28297 .Lmemcpy_c_e:
28298 movq %rdi, %rax
28299 movq %rdx, %rcx
28300 rep movsb
28301+ pax_force_retaddr
28302 ret
28303 .Lmemcpy_e_e:
28304 .previous
28305@@ -76,13 +78,13 @@ ENTRY(memcpy)
28306 */
28307 movq 0*8(%rsi), %r8
28308 movq 1*8(%rsi), %r9
28309- movq 2*8(%rsi), %r10
28310+ movq 2*8(%rsi), %rcx
28311 movq 3*8(%rsi), %r11
28312 leaq 4*8(%rsi), %rsi
28313
28314 movq %r8, 0*8(%rdi)
28315 movq %r9, 1*8(%rdi)
28316- movq %r10, 2*8(%rdi)
28317+ movq %rcx, 2*8(%rdi)
28318 movq %r11, 3*8(%rdi)
28319 leaq 4*8(%rdi), %rdi
28320 jae .Lcopy_forward_loop
28321@@ -105,12 +107,12 @@ ENTRY(memcpy)
28322 subq $0x20, %rdx
28323 movq -1*8(%rsi), %r8
28324 movq -2*8(%rsi), %r9
28325- movq -3*8(%rsi), %r10
28326+ movq -3*8(%rsi), %rcx
28327 movq -4*8(%rsi), %r11
28328 leaq -4*8(%rsi), %rsi
28329 movq %r8, -1*8(%rdi)
28330 movq %r9, -2*8(%rdi)
28331- movq %r10, -3*8(%rdi)
28332+ movq %rcx, -3*8(%rdi)
28333 movq %r11, -4*8(%rdi)
28334 leaq -4*8(%rdi), %rdi
28335 jae .Lcopy_backward_loop
28336@@ -130,12 +132,13 @@ ENTRY(memcpy)
28337 */
28338 movq 0*8(%rsi), %r8
28339 movq 1*8(%rsi), %r9
28340- movq -2*8(%rsi, %rdx), %r10
28341+ movq -2*8(%rsi, %rdx), %rcx
28342 movq -1*8(%rsi, %rdx), %r11
28343 movq %r8, 0*8(%rdi)
28344 movq %r9, 1*8(%rdi)
28345- movq %r10, -2*8(%rdi, %rdx)
28346+ movq %rcx, -2*8(%rdi, %rdx)
28347 movq %r11, -1*8(%rdi, %rdx)
28348+ pax_force_retaddr
28349 retq
28350 .p2align 4
28351 .Lless_16bytes:
28352@@ -148,6 +151,7 @@ ENTRY(memcpy)
28353 movq -1*8(%rsi, %rdx), %r9
28354 movq %r8, 0*8(%rdi)
28355 movq %r9, -1*8(%rdi, %rdx)
28356+ pax_force_retaddr
28357 retq
28358 .p2align 4
28359 .Lless_8bytes:
28360@@ -161,6 +165,7 @@ ENTRY(memcpy)
28361 movl -4(%rsi, %rdx), %r8d
28362 movl %ecx, (%rdi)
28363 movl %r8d, -4(%rdi, %rdx)
28364+ pax_force_retaddr
28365 retq
28366 .p2align 4
28367 .Lless_3bytes:
28368@@ -179,6 +184,7 @@ ENTRY(memcpy)
28369 movb %cl, (%rdi)
28370
28371 .Lend:
28372+ pax_force_retaddr
28373 retq
28374 CFI_ENDPROC
28375 ENDPROC(memcpy)
28376diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28377index 65268a6..5aa7815 100644
28378--- a/arch/x86/lib/memmove_64.S
28379+++ b/arch/x86/lib/memmove_64.S
28380@@ -61,13 +61,13 @@ ENTRY(memmove)
28381 5:
28382 sub $0x20, %rdx
28383 movq 0*8(%rsi), %r11
28384- movq 1*8(%rsi), %r10
28385+ movq 1*8(%rsi), %rcx
28386 movq 2*8(%rsi), %r9
28387 movq 3*8(%rsi), %r8
28388 leaq 4*8(%rsi), %rsi
28389
28390 movq %r11, 0*8(%rdi)
28391- movq %r10, 1*8(%rdi)
28392+ movq %rcx, 1*8(%rdi)
28393 movq %r9, 2*8(%rdi)
28394 movq %r8, 3*8(%rdi)
28395 leaq 4*8(%rdi), %rdi
28396@@ -81,10 +81,10 @@ ENTRY(memmove)
28397 4:
28398 movq %rdx, %rcx
28399 movq -8(%rsi, %rdx), %r11
28400- lea -8(%rdi, %rdx), %r10
28401+ lea -8(%rdi, %rdx), %r9
28402 shrq $3, %rcx
28403 rep movsq
28404- movq %r11, (%r10)
28405+ movq %r11, (%r9)
28406 jmp 13f
28407 .Lmemmove_end_forward:
28408
28409@@ -95,14 +95,14 @@ ENTRY(memmove)
28410 7:
28411 movq %rdx, %rcx
28412 movq (%rsi), %r11
28413- movq %rdi, %r10
28414+ movq %rdi, %r9
28415 leaq -8(%rsi, %rdx), %rsi
28416 leaq -8(%rdi, %rdx), %rdi
28417 shrq $3, %rcx
28418 std
28419 rep movsq
28420 cld
28421- movq %r11, (%r10)
28422+ movq %r11, (%r9)
28423 jmp 13f
28424
28425 /*
28426@@ -127,13 +127,13 @@ ENTRY(memmove)
28427 8:
28428 subq $0x20, %rdx
28429 movq -1*8(%rsi), %r11
28430- movq -2*8(%rsi), %r10
28431+ movq -2*8(%rsi), %rcx
28432 movq -3*8(%rsi), %r9
28433 movq -4*8(%rsi), %r8
28434 leaq -4*8(%rsi), %rsi
28435
28436 movq %r11, -1*8(%rdi)
28437- movq %r10, -2*8(%rdi)
28438+ movq %rcx, -2*8(%rdi)
28439 movq %r9, -3*8(%rdi)
28440 movq %r8, -4*8(%rdi)
28441 leaq -4*8(%rdi), %rdi
28442@@ -151,11 +151,11 @@ ENTRY(memmove)
28443 * Move data from 16 bytes to 31 bytes.
28444 */
28445 movq 0*8(%rsi), %r11
28446- movq 1*8(%rsi), %r10
28447+ movq 1*8(%rsi), %rcx
28448 movq -2*8(%rsi, %rdx), %r9
28449 movq -1*8(%rsi, %rdx), %r8
28450 movq %r11, 0*8(%rdi)
28451- movq %r10, 1*8(%rdi)
28452+ movq %rcx, 1*8(%rdi)
28453 movq %r9, -2*8(%rdi, %rdx)
28454 movq %r8, -1*8(%rdi, %rdx)
28455 jmp 13f
28456@@ -167,9 +167,9 @@ ENTRY(memmove)
28457 * Move data from 8 bytes to 15 bytes.
28458 */
28459 movq 0*8(%rsi), %r11
28460- movq -1*8(%rsi, %rdx), %r10
28461+ movq -1*8(%rsi, %rdx), %r9
28462 movq %r11, 0*8(%rdi)
28463- movq %r10, -1*8(%rdi, %rdx)
28464+ movq %r9, -1*8(%rdi, %rdx)
28465 jmp 13f
28466 10:
28467 cmpq $4, %rdx
28468@@ -178,9 +178,9 @@ ENTRY(memmove)
28469 * Move data from 4 bytes to 7 bytes.
28470 */
28471 movl (%rsi), %r11d
28472- movl -4(%rsi, %rdx), %r10d
28473+ movl -4(%rsi, %rdx), %r9d
28474 movl %r11d, (%rdi)
28475- movl %r10d, -4(%rdi, %rdx)
28476+ movl %r9d, -4(%rdi, %rdx)
28477 jmp 13f
28478 11:
28479 cmp $2, %rdx
28480@@ -189,9 +189,9 @@ ENTRY(memmove)
28481 * Move data from 2 bytes to 3 bytes.
28482 */
28483 movw (%rsi), %r11w
28484- movw -2(%rsi, %rdx), %r10w
28485+ movw -2(%rsi, %rdx), %r9w
28486 movw %r11w, (%rdi)
28487- movw %r10w, -2(%rdi, %rdx)
28488+ movw %r9w, -2(%rdi, %rdx)
28489 jmp 13f
28490 12:
28491 cmp $1, %rdx
28492@@ -202,14 +202,16 @@ ENTRY(memmove)
28493 movb (%rsi), %r11b
28494 movb %r11b, (%rdi)
28495 13:
28496+ pax_force_retaddr
28497 retq
28498 CFI_ENDPROC
28499
28500- .section .altinstr_replacement,"ax"
28501+ .section .altinstr_replacement,"a"
28502 .Lmemmove_begin_forward_efs:
28503 /* Forward moving data. */
28504 movq %rdx, %rcx
28505 rep movsb
28506+ pax_force_retaddr
28507 retq
28508 .Lmemmove_end_forward_efs:
28509 .previous
28510diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28511index 2dcb380..50a78bc 100644
28512--- a/arch/x86/lib/memset_64.S
28513+++ b/arch/x86/lib/memset_64.S
28514@@ -16,7 +16,7 @@
28515 *
28516 * rax original destination
28517 */
28518- .section .altinstr_replacement, "ax", @progbits
28519+ .section .altinstr_replacement, "a", @progbits
28520 .Lmemset_c:
28521 movq %rdi,%r9
28522 movq %rdx,%rcx
28523@@ -30,6 +30,7 @@
28524 movl %edx,%ecx
28525 rep stosb
28526 movq %r9,%rax
28527+ pax_force_retaddr
28528 ret
28529 .Lmemset_e:
28530 .previous
28531@@ -45,13 +46,14 @@
28532 *
28533 * rax original destination
28534 */
28535- .section .altinstr_replacement, "ax", @progbits
28536+ .section .altinstr_replacement, "a", @progbits
28537 .Lmemset_c_e:
28538 movq %rdi,%r9
28539 movb %sil,%al
28540 movq %rdx,%rcx
28541 rep stosb
28542 movq %r9,%rax
28543+ pax_force_retaddr
28544 ret
28545 .Lmemset_e_e:
28546 .previous
28547@@ -59,7 +61,7 @@
28548 ENTRY(memset)
28549 ENTRY(__memset)
28550 CFI_STARTPROC
28551- movq %rdi,%r10
28552+ movq %rdi,%r11
28553
28554 /* expand byte value */
28555 movzbl %sil,%ecx
28556@@ -117,7 +119,8 @@ ENTRY(__memset)
28557 jnz .Lloop_1
28558
28559 .Lende:
28560- movq %r10,%rax
28561+ movq %r11,%rax
28562+ pax_force_retaddr
28563 ret
28564
28565 CFI_RESTORE_STATE
28566diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28567index c9f2d9b..e7fd2c0 100644
28568--- a/arch/x86/lib/mmx_32.c
28569+++ b/arch/x86/lib/mmx_32.c
28570@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28571 {
28572 void *p;
28573 int i;
28574+ unsigned long cr0;
28575
28576 if (unlikely(in_interrupt()))
28577 return __memcpy(to, from, len);
28578@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28579 kernel_fpu_begin();
28580
28581 __asm__ __volatile__ (
28582- "1: prefetch (%0)\n" /* This set is 28 bytes */
28583- " prefetch 64(%0)\n"
28584- " prefetch 128(%0)\n"
28585- " prefetch 192(%0)\n"
28586- " prefetch 256(%0)\n"
28587+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28588+ " prefetch 64(%1)\n"
28589+ " prefetch 128(%1)\n"
28590+ " prefetch 192(%1)\n"
28591+ " prefetch 256(%1)\n"
28592 "2: \n"
28593 ".section .fixup, \"ax\"\n"
28594- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28595+ "3: \n"
28596+
28597+#ifdef CONFIG_PAX_KERNEXEC
28598+ " movl %%cr0, %0\n"
28599+ " movl %0, %%eax\n"
28600+ " andl $0xFFFEFFFF, %%eax\n"
28601+ " movl %%eax, %%cr0\n"
28602+#endif
28603+
28604+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28605+
28606+#ifdef CONFIG_PAX_KERNEXEC
28607+ " movl %0, %%cr0\n"
28608+#endif
28609+
28610 " jmp 2b\n"
28611 ".previous\n"
28612 _ASM_EXTABLE(1b, 3b)
28613- : : "r" (from));
28614+ : "=&r" (cr0) : "r" (from) : "ax");
28615
28616 for ( ; i > 5; i--) {
28617 __asm__ __volatile__ (
28618- "1: prefetch 320(%0)\n"
28619- "2: movq (%0), %%mm0\n"
28620- " movq 8(%0), %%mm1\n"
28621- " movq 16(%0), %%mm2\n"
28622- " movq 24(%0), %%mm3\n"
28623- " movq %%mm0, (%1)\n"
28624- " movq %%mm1, 8(%1)\n"
28625- " movq %%mm2, 16(%1)\n"
28626- " movq %%mm3, 24(%1)\n"
28627- " movq 32(%0), %%mm0\n"
28628- " movq 40(%0), %%mm1\n"
28629- " movq 48(%0), %%mm2\n"
28630- " movq 56(%0), %%mm3\n"
28631- " movq %%mm0, 32(%1)\n"
28632- " movq %%mm1, 40(%1)\n"
28633- " movq %%mm2, 48(%1)\n"
28634- " movq %%mm3, 56(%1)\n"
28635+ "1: prefetch 320(%1)\n"
28636+ "2: movq (%1), %%mm0\n"
28637+ " movq 8(%1), %%mm1\n"
28638+ " movq 16(%1), %%mm2\n"
28639+ " movq 24(%1), %%mm3\n"
28640+ " movq %%mm0, (%2)\n"
28641+ " movq %%mm1, 8(%2)\n"
28642+ " movq %%mm2, 16(%2)\n"
28643+ " movq %%mm3, 24(%2)\n"
28644+ " movq 32(%1), %%mm0\n"
28645+ " movq 40(%1), %%mm1\n"
28646+ " movq 48(%1), %%mm2\n"
28647+ " movq 56(%1), %%mm3\n"
28648+ " movq %%mm0, 32(%2)\n"
28649+ " movq %%mm1, 40(%2)\n"
28650+ " movq %%mm2, 48(%2)\n"
28651+ " movq %%mm3, 56(%2)\n"
28652 ".section .fixup, \"ax\"\n"
28653- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28654+ "3:\n"
28655+
28656+#ifdef CONFIG_PAX_KERNEXEC
28657+ " movl %%cr0, %0\n"
28658+ " movl %0, %%eax\n"
28659+ " andl $0xFFFEFFFF, %%eax\n"
28660+ " movl %%eax, %%cr0\n"
28661+#endif
28662+
28663+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28664+
28665+#ifdef CONFIG_PAX_KERNEXEC
28666+ " movl %0, %%cr0\n"
28667+#endif
28668+
28669 " jmp 2b\n"
28670 ".previous\n"
28671 _ASM_EXTABLE(1b, 3b)
28672- : : "r" (from), "r" (to) : "memory");
28673+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28674
28675 from += 64;
28676 to += 64;
28677@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28678 static void fast_copy_page(void *to, void *from)
28679 {
28680 int i;
28681+ unsigned long cr0;
28682
28683 kernel_fpu_begin();
28684
28685@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28686 * but that is for later. -AV
28687 */
28688 __asm__ __volatile__(
28689- "1: prefetch (%0)\n"
28690- " prefetch 64(%0)\n"
28691- " prefetch 128(%0)\n"
28692- " prefetch 192(%0)\n"
28693- " prefetch 256(%0)\n"
28694+ "1: prefetch (%1)\n"
28695+ " prefetch 64(%1)\n"
28696+ " prefetch 128(%1)\n"
28697+ " prefetch 192(%1)\n"
28698+ " prefetch 256(%1)\n"
28699 "2: \n"
28700 ".section .fixup, \"ax\"\n"
28701- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28702+ "3: \n"
28703+
28704+#ifdef CONFIG_PAX_KERNEXEC
28705+ " movl %%cr0, %0\n"
28706+ " movl %0, %%eax\n"
28707+ " andl $0xFFFEFFFF, %%eax\n"
28708+ " movl %%eax, %%cr0\n"
28709+#endif
28710+
28711+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28712+
28713+#ifdef CONFIG_PAX_KERNEXEC
28714+ " movl %0, %%cr0\n"
28715+#endif
28716+
28717 " jmp 2b\n"
28718 ".previous\n"
28719- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28720+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28721
28722 for (i = 0; i < (4096-320)/64; i++) {
28723 __asm__ __volatile__ (
28724- "1: prefetch 320(%0)\n"
28725- "2: movq (%0), %%mm0\n"
28726- " movntq %%mm0, (%1)\n"
28727- " movq 8(%0), %%mm1\n"
28728- " movntq %%mm1, 8(%1)\n"
28729- " movq 16(%0), %%mm2\n"
28730- " movntq %%mm2, 16(%1)\n"
28731- " movq 24(%0), %%mm3\n"
28732- " movntq %%mm3, 24(%1)\n"
28733- " movq 32(%0), %%mm4\n"
28734- " movntq %%mm4, 32(%1)\n"
28735- " movq 40(%0), %%mm5\n"
28736- " movntq %%mm5, 40(%1)\n"
28737- " movq 48(%0), %%mm6\n"
28738- " movntq %%mm6, 48(%1)\n"
28739- " movq 56(%0), %%mm7\n"
28740- " movntq %%mm7, 56(%1)\n"
28741+ "1: prefetch 320(%1)\n"
28742+ "2: movq (%1), %%mm0\n"
28743+ " movntq %%mm0, (%2)\n"
28744+ " movq 8(%1), %%mm1\n"
28745+ " movntq %%mm1, 8(%2)\n"
28746+ " movq 16(%1), %%mm2\n"
28747+ " movntq %%mm2, 16(%2)\n"
28748+ " movq 24(%1), %%mm3\n"
28749+ " movntq %%mm3, 24(%2)\n"
28750+ " movq 32(%1), %%mm4\n"
28751+ " movntq %%mm4, 32(%2)\n"
28752+ " movq 40(%1), %%mm5\n"
28753+ " movntq %%mm5, 40(%2)\n"
28754+ " movq 48(%1), %%mm6\n"
28755+ " movntq %%mm6, 48(%2)\n"
28756+ " movq 56(%1), %%mm7\n"
28757+ " movntq %%mm7, 56(%2)\n"
28758 ".section .fixup, \"ax\"\n"
28759- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28760+ "3:\n"
28761+
28762+#ifdef CONFIG_PAX_KERNEXEC
28763+ " movl %%cr0, %0\n"
28764+ " movl %0, %%eax\n"
28765+ " andl $0xFFFEFFFF, %%eax\n"
28766+ " movl %%eax, %%cr0\n"
28767+#endif
28768+
28769+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28770+
28771+#ifdef CONFIG_PAX_KERNEXEC
28772+ " movl %0, %%cr0\n"
28773+#endif
28774+
28775 " jmp 2b\n"
28776 ".previous\n"
28777- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28778+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28779
28780 from += 64;
28781 to += 64;
28782@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28783 static void fast_copy_page(void *to, void *from)
28784 {
28785 int i;
28786+ unsigned long cr0;
28787
28788 kernel_fpu_begin();
28789
28790 __asm__ __volatile__ (
28791- "1: prefetch (%0)\n"
28792- " prefetch 64(%0)\n"
28793- " prefetch 128(%0)\n"
28794- " prefetch 192(%0)\n"
28795- " prefetch 256(%0)\n"
28796+ "1: prefetch (%1)\n"
28797+ " prefetch 64(%1)\n"
28798+ " prefetch 128(%1)\n"
28799+ " prefetch 192(%1)\n"
28800+ " prefetch 256(%1)\n"
28801 "2: \n"
28802 ".section .fixup, \"ax\"\n"
28803- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28804+ "3: \n"
28805+
28806+#ifdef CONFIG_PAX_KERNEXEC
28807+ " movl %%cr0, %0\n"
28808+ " movl %0, %%eax\n"
28809+ " andl $0xFFFEFFFF, %%eax\n"
28810+ " movl %%eax, %%cr0\n"
28811+#endif
28812+
28813+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28814+
28815+#ifdef CONFIG_PAX_KERNEXEC
28816+ " movl %0, %%cr0\n"
28817+#endif
28818+
28819 " jmp 2b\n"
28820 ".previous\n"
28821- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28822+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28823
28824 for (i = 0; i < 4096/64; i++) {
28825 __asm__ __volatile__ (
28826- "1: prefetch 320(%0)\n"
28827- "2: movq (%0), %%mm0\n"
28828- " movq 8(%0), %%mm1\n"
28829- " movq 16(%0), %%mm2\n"
28830- " movq 24(%0), %%mm3\n"
28831- " movq %%mm0, (%1)\n"
28832- " movq %%mm1, 8(%1)\n"
28833- " movq %%mm2, 16(%1)\n"
28834- " movq %%mm3, 24(%1)\n"
28835- " movq 32(%0), %%mm0\n"
28836- " movq 40(%0), %%mm1\n"
28837- " movq 48(%0), %%mm2\n"
28838- " movq 56(%0), %%mm3\n"
28839- " movq %%mm0, 32(%1)\n"
28840- " movq %%mm1, 40(%1)\n"
28841- " movq %%mm2, 48(%1)\n"
28842- " movq %%mm3, 56(%1)\n"
28843+ "1: prefetch 320(%1)\n"
28844+ "2: movq (%1), %%mm0\n"
28845+ " movq 8(%1), %%mm1\n"
28846+ " movq 16(%1), %%mm2\n"
28847+ " movq 24(%1), %%mm3\n"
28848+ " movq %%mm0, (%2)\n"
28849+ " movq %%mm1, 8(%2)\n"
28850+ " movq %%mm2, 16(%2)\n"
28851+ " movq %%mm3, 24(%2)\n"
28852+ " movq 32(%1), %%mm0\n"
28853+ " movq 40(%1), %%mm1\n"
28854+ " movq 48(%1), %%mm2\n"
28855+ " movq 56(%1), %%mm3\n"
28856+ " movq %%mm0, 32(%2)\n"
28857+ " movq %%mm1, 40(%2)\n"
28858+ " movq %%mm2, 48(%2)\n"
28859+ " movq %%mm3, 56(%2)\n"
28860 ".section .fixup, \"ax\"\n"
28861- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28862+ "3:\n"
28863+
28864+#ifdef CONFIG_PAX_KERNEXEC
28865+ " movl %%cr0, %0\n"
28866+ " movl %0, %%eax\n"
28867+ " andl $0xFFFEFFFF, %%eax\n"
28868+ " movl %%eax, %%cr0\n"
28869+#endif
28870+
28871+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28872+
28873+#ifdef CONFIG_PAX_KERNEXEC
28874+ " movl %0, %%cr0\n"
28875+#endif
28876+
28877 " jmp 2b\n"
28878 ".previous\n"
28879 _ASM_EXTABLE(1b, 3b)
28880- : : "r" (from), "r" (to) : "memory");
28881+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28882
28883 from += 64;
28884 to += 64;
28885diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28886index f6d13ee..aca5f0b 100644
28887--- a/arch/x86/lib/msr-reg.S
28888+++ b/arch/x86/lib/msr-reg.S
28889@@ -3,6 +3,7 @@
28890 #include <asm/dwarf2.h>
28891 #include <asm/asm.h>
28892 #include <asm/msr.h>
28893+#include <asm/alternative-asm.h>
28894
28895 #ifdef CONFIG_X86_64
28896 /*
28897@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28898 CFI_STARTPROC
28899 pushq_cfi %rbx
28900 pushq_cfi %rbp
28901- movq %rdi, %r10 /* Save pointer */
28902+ movq %rdi, %r9 /* Save pointer */
28903 xorl %r11d, %r11d /* Return value */
28904 movl (%rdi), %eax
28905 movl 4(%rdi), %ecx
28906@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28907 movl 28(%rdi), %edi
28908 CFI_REMEMBER_STATE
28909 1: \op
28910-2: movl %eax, (%r10)
28911+2: movl %eax, (%r9)
28912 movl %r11d, %eax /* Return value */
28913- movl %ecx, 4(%r10)
28914- movl %edx, 8(%r10)
28915- movl %ebx, 12(%r10)
28916- movl %ebp, 20(%r10)
28917- movl %esi, 24(%r10)
28918- movl %edi, 28(%r10)
28919+ movl %ecx, 4(%r9)
28920+ movl %edx, 8(%r9)
28921+ movl %ebx, 12(%r9)
28922+ movl %ebp, 20(%r9)
28923+ movl %esi, 24(%r9)
28924+ movl %edi, 28(%r9)
28925 popq_cfi %rbp
28926 popq_cfi %rbx
28927+ pax_force_retaddr
28928 ret
28929 3:
28930 CFI_RESTORE_STATE
28931diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28932index fc6ba17..d4d989d 100644
28933--- a/arch/x86/lib/putuser.S
28934+++ b/arch/x86/lib/putuser.S
28935@@ -16,7 +16,9 @@
28936 #include <asm/errno.h>
28937 #include <asm/asm.h>
28938 #include <asm/smap.h>
28939-
28940+#include <asm/segment.h>
28941+#include <asm/pgtable.h>
28942+#include <asm/alternative-asm.h>
28943
28944 /*
28945 * __put_user_X
28946@@ -30,57 +32,125 @@
28947 * as they get called from within inline assembly.
28948 */
28949
28950-#define ENTER CFI_STARTPROC ; \
28951- GET_THREAD_INFO(%_ASM_BX)
28952-#define EXIT ASM_CLAC ; \
28953- ret ; \
28954+#define ENTER CFI_STARTPROC
28955+#define EXIT ASM_CLAC ; \
28956+ pax_force_retaddr ; \
28957+ ret ; \
28958 CFI_ENDPROC
28959
28960+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28961+#define _DEST %_ASM_CX,%_ASM_BX
28962+#else
28963+#define _DEST %_ASM_CX
28964+#endif
28965+
28966+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28967+#define __copyuser_seg gs;
28968+#else
28969+#define __copyuser_seg
28970+#endif
28971+
28972 .text
28973 ENTRY(__put_user_1)
28974 ENTER
28975+
28976+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28977+ GET_THREAD_INFO(%_ASM_BX)
28978 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28979 jae bad_put_user
28980 ASM_STAC
28981-1: movb %al,(%_ASM_CX)
28982+
28983+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28984+ mov pax_user_shadow_base,%_ASM_BX
28985+ cmp %_ASM_BX,%_ASM_CX
28986+ jb 1234f
28987+ xor %ebx,%ebx
28988+1234:
28989+#endif
28990+
28991+#endif
28992+
28993+1: __copyuser_seg movb %al,(_DEST)
28994 xor %eax,%eax
28995 EXIT
28996 ENDPROC(__put_user_1)
28997
28998 ENTRY(__put_user_2)
28999 ENTER
29000+
29001+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29002+ GET_THREAD_INFO(%_ASM_BX)
29003 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29004 sub $1,%_ASM_BX
29005 cmp %_ASM_BX,%_ASM_CX
29006 jae bad_put_user
29007 ASM_STAC
29008-2: movw %ax,(%_ASM_CX)
29009+
29010+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29011+ mov pax_user_shadow_base,%_ASM_BX
29012+ cmp %_ASM_BX,%_ASM_CX
29013+ jb 1234f
29014+ xor %ebx,%ebx
29015+1234:
29016+#endif
29017+
29018+#endif
29019+
29020+2: __copyuser_seg movw %ax,(_DEST)
29021 xor %eax,%eax
29022 EXIT
29023 ENDPROC(__put_user_2)
29024
29025 ENTRY(__put_user_4)
29026 ENTER
29027+
29028+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29029+ GET_THREAD_INFO(%_ASM_BX)
29030 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29031 sub $3,%_ASM_BX
29032 cmp %_ASM_BX,%_ASM_CX
29033 jae bad_put_user
29034 ASM_STAC
29035-3: movl %eax,(%_ASM_CX)
29036+
29037+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29038+ mov pax_user_shadow_base,%_ASM_BX
29039+ cmp %_ASM_BX,%_ASM_CX
29040+ jb 1234f
29041+ xor %ebx,%ebx
29042+1234:
29043+#endif
29044+
29045+#endif
29046+
29047+3: __copyuser_seg movl %eax,(_DEST)
29048 xor %eax,%eax
29049 EXIT
29050 ENDPROC(__put_user_4)
29051
29052 ENTRY(__put_user_8)
29053 ENTER
29054+
29055+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29056+ GET_THREAD_INFO(%_ASM_BX)
29057 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29058 sub $7,%_ASM_BX
29059 cmp %_ASM_BX,%_ASM_CX
29060 jae bad_put_user
29061 ASM_STAC
29062-4: mov %_ASM_AX,(%_ASM_CX)
29063+
29064+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29065+ mov pax_user_shadow_base,%_ASM_BX
29066+ cmp %_ASM_BX,%_ASM_CX
29067+ jb 1234f
29068+ xor %ebx,%ebx
29069+1234:
29070+#endif
29071+
29072+#endif
29073+
29074+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29075 #ifdef CONFIG_X86_32
29076-5: movl %edx,4(%_ASM_CX)
29077+5: __copyuser_seg movl %edx,4(_DEST)
29078 #endif
29079 xor %eax,%eax
29080 EXIT
29081diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29082index 1cad221..de671ee 100644
29083--- a/arch/x86/lib/rwlock.S
29084+++ b/arch/x86/lib/rwlock.S
29085@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29086 FRAME
29087 0: LOCK_PREFIX
29088 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29089+
29090+#ifdef CONFIG_PAX_REFCOUNT
29091+ jno 1234f
29092+ LOCK_PREFIX
29093+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29094+ int $4
29095+1234:
29096+ _ASM_EXTABLE(1234b, 1234b)
29097+#endif
29098+
29099 1: rep; nop
29100 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29101 jne 1b
29102 LOCK_PREFIX
29103 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29104+
29105+#ifdef CONFIG_PAX_REFCOUNT
29106+ jno 1234f
29107+ LOCK_PREFIX
29108+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29109+ int $4
29110+1234:
29111+ _ASM_EXTABLE(1234b, 1234b)
29112+#endif
29113+
29114 jnz 0b
29115 ENDFRAME
29116+ pax_force_retaddr
29117 ret
29118 CFI_ENDPROC
29119 END(__write_lock_failed)
29120@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29121 FRAME
29122 0: LOCK_PREFIX
29123 READ_LOCK_SIZE(inc) (%__lock_ptr)
29124+
29125+#ifdef CONFIG_PAX_REFCOUNT
29126+ jno 1234f
29127+ LOCK_PREFIX
29128+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29129+ int $4
29130+1234:
29131+ _ASM_EXTABLE(1234b, 1234b)
29132+#endif
29133+
29134 1: rep; nop
29135 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29136 js 1b
29137 LOCK_PREFIX
29138 READ_LOCK_SIZE(dec) (%__lock_ptr)
29139+
29140+#ifdef CONFIG_PAX_REFCOUNT
29141+ jno 1234f
29142+ LOCK_PREFIX
29143+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29144+ int $4
29145+1234:
29146+ _ASM_EXTABLE(1234b, 1234b)
29147+#endif
29148+
29149 js 0b
29150 ENDFRAME
29151+ pax_force_retaddr
29152 ret
29153 CFI_ENDPROC
29154 END(__read_lock_failed)
29155diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29156index 5dff5f0..cadebf4 100644
29157--- a/arch/x86/lib/rwsem.S
29158+++ b/arch/x86/lib/rwsem.S
29159@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29160 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29161 CFI_RESTORE __ASM_REG(dx)
29162 restore_common_regs
29163+ pax_force_retaddr
29164 ret
29165 CFI_ENDPROC
29166 ENDPROC(call_rwsem_down_read_failed)
29167@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29168 movq %rax,%rdi
29169 call rwsem_down_write_failed
29170 restore_common_regs
29171+ pax_force_retaddr
29172 ret
29173 CFI_ENDPROC
29174 ENDPROC(call_rwsem_down_write_failed)
29175@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29176 movq %rax,%rdi
29177 call rwsem_wake
29178 restore_common_regs
29179-1: ret
29180+1: pax_force_retaddr
29181+ ret
29182 CFI_ENDPROC
29183 ENDPROC(call_rwsem_wake)
29184
29185@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29186 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29187 CFI_RESTORE __ASM_REG(dx)
29188 restore_common_regs
29189+ pax_force_retaddr
29190 ret
29191 CFI_ENDPROC
29192 ENDPROC(call_rwsem_downgrade_wake)
29193diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29194index a63efd6..ccecad8 100644
29195--- a/arch/x86/lib/thunk_64.S
29196+++ b/arch/x86/lib/thunk_64.S
29197@@ -8,6 +8,7 @@
29198 #include <linux/linkage.h>
29199 #include <asm/dwarf2.h>
29200 #include <asm/calling.h>
29201+#include <asm/alternative-asm.h>
29202
29203 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29204 .macro THUNK name, func, put_ret_addr_in_rdi=0
29205@@ -41,5 +42,6 @@
29206 SAVE_ARGS
29207 restore:
29208 RESTORE_ARGS
29209+ pax_force_retaddr
29210 ret
29211 CFI_ENDPROC
29212diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29213index 3eb18ac..4b22130 100644
29214--- a/arch/x86/lib/usercopy_32.c
29215+++ b/arch/x86/lib/usercopy_32.c
29216@@ -42,11 +42,13 @@ do { \
29217 int __d0; \
29218 might_fault(); \
29219 __asm__ __volatile__( \
29220+ __COPYUSER_SET_ES \
29221 ASM_STAC "\n" \
29222 "0: rep; stosl\n" \
29223 " movl %2,%0\n" \
29224 "1: rep; stosb\n" \
29225 "2: " ASM_CLAC "\n" \
29226+ __COPYUSER_RESTORE_ES \
29227 ".section .fixup,\"ax\"\n" \
29228 "3: lea 0(%2,%0,4),%0\n" \
29229 " jmp 2b\n" \
29230@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29231
29232 #ifdef CONFIG_X86_INTEL_USERCOPY
29233 static unsigned long
29234-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29235+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29236 {
29237 int d0, d1;
29238 __asm__ __volatile__(
29239@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29240 " .align 2,0x90\n"
29241 "3: movl 0(%4), %%eax\n"
29242 "4: movl 4(%4), %%edx\n"
29243- "5: movl %%eax, 0(%3)\n"
29244- "6: movl %%edx, 4(%3)\n"
29245+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29246+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29247 "7: movl 8(%4), %%eax\n"
29248 "8: movl 12(%4),%%edx\n"
29249- "9: movl %%eax, 8(%3)\n"
29250- "10: movl %%edx, 12(%3)\n"
29251+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29252+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29253 "11: movl 16(%4), %%eax\n"
29254 "12: movl 20(%4), %%edx\n"
29255- "13: movl %%eax, 16(%3)\n"
29256- "14: movl %%edx, 20(%3)\n"
29257+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29258+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29259 "15: movl 24(%4), %%eax\n"
29260 "16: movl 28(%4), %%edx\n"
29261- "17: movl %%eax, 24(%3)\n"
29262- "18: movl %%edx, 28(%3)\n"
29263+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29264+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29265 "19: movl 32(%4), %%eax\n"
29266 "20: movl 36(%4), %%edx\n"
29267- "21: movl %%eax, 32(%3)\n"
29268- "22: movl %%edx, 36(%3)\n"
29269+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29270+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29271 "23: movl 40(%4), %%eax\n"
29272 "24: movl 44(%4), %%edx\n"
29273- "25: movl %%eax, 40(%3)\n"
29274- "26: movl %%edx, 44(%3)\n"
29275+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29276+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29277 "27: movl 48(%4), %%eax\n"
29278 "28: movl 52(%4), %%edx\n"
29279- "29: movl %%eax, 48(%3)\n"
29280- "30: movl %%edx, 52(%3)\n"
29281+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29282+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29283 "31: movl 56(%4), %%eax\n"
29284 "32: movl 60(%4), %%edx\n"
29285- "33: movl %%eax, 56(%3)\n"
29286- "34: movl %%edx, 60(%3)\n"
29287+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29288+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29289 " addl $-64, %0\n"
29290 " addl $64, %4\n"
29291 " addl $64, %3\n"
29292@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29293 " shrl $2, %0\n"
29294 " andl $3, %%eax\n"
29295 " cld\n"
29296+ __COPYUSER_SET_ES
29297 "99: rep; movsl\n"
29298 "36: movl %%eax, %0\n"
29299 "37: rep; movsb\n"
29300 "100:\n"
29301+ __COPYUSER_RESTORE_ES
29302+ ".section .fixup,\"ax\"\n"
29303+ "101: lea 0(%%eax,%0,4),%0\n"
29304+ " jmp 100b\n"
29305+ ".previous\n"
29306+ _ASM_EXTABLE(1b,100b)
29307+ _ASM_EXTABLE(2b,100b)
29308+ _ASM_EXTABLE(3b,100b)
29309+ _ASM_EXTABLE(4b,100b)
29310+ _ASM_EXTABLE(5b,100b)
29311+ _ASM_EXTABLE(6b,100b)
29312+ _ASM_EXTABLE(7b,100b)
29313+ _ASM_EXTABLE(8b,100b)
29314+ _ASM_EXTABLE(9b,100b)
29315+ _ASM_EXTABLE(10b,100b)
29316+ _ASM_EXTABLE(11b,100b)
29317+ _ASM_EXTABLE(12b,100b)
29318+ _ASM_EXTABLE(13b,100b)
29319+ _ASM_EXTABLE(14b,100b)
29320+ _ASM_EXTABLE(15b,100b)
29321+ _ASM_EXTABLE(16b,100b)
29322+ _ASM_EXTABLE(17b,100b)
29323+ _ASM_EXTABLE(18b,100b)
29324+ _ASM_EXTABLE(19b,100b)
29325+ _ASM_EXTABLE(20b,100b)
29326+ _ASM_EXTABLE(21b,100b)
29327+ _ASM_EXTABLE(22b,100b)
29328+ _ASM_EXTABLE(23b,100b)
29329+ _ASM_EXTABLE(24b,100b)
29330+ _ASM_EXTABLE(25b,100b)
29331+ _ASM_EXTABLE(26b,100b)
29332+ _ASM_EXTABLE(27b,100b)
29333+ _ASM_EXTABLE(28b,100b)
29334+ _ASM_EXTABLE(29b,100b)
29335+ _ASM_EXTABLE(30b,100b)
29336+ _ASM_EXTABLE(31b,100b)
29337+ _ASM_EXTABLE(32b,100b)
29338+ _ASM_EXTABLE(33b,100b)
29339+ _ASM_EXTABLE(34b,100b)
29340+ _ASM_EXTABLE(35b,100b)
29341+ _ASM_EXTABLE(36b,100b)
29342+ _ASM_EXTABLE(37b,100b)
29343+ _ASM_EXTABLE(99b,101b)
29344+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29345+ : "1"(to), "2"(from), "0"(size)
29346+ : "eax", "edx", "memory");
29347+ return size;
29348+}
29349+
29350+static unsigned long
29351+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29352+{
29353+ int d0, d1;
29354+ __asm__ __volatile__(
29355+ " .align 2,0x90\n"
29356+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29357+ " cmpl $67, %0\n"
29358+ " jbe 3f\n"
29359+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29360+ " .align 2,0x90\n"
29361+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29362+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29363+ "5: movl %%eax, 0(%3)\n"
29364+ "6: movl %%edx, 4(%3)\n"
29365+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29366+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29367+ "9: movl %%eax, 8(%3)\n"
29368+ "10: movl %%edx, 12(%3)\n"
29369+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29370+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29371+ "13: movl %%eax, 16(%3)\n"
29372+ "14: movl %%edx, 20(%3)\n"
29373+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29374+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29375+ "17: movl %%eax, 24(%3)\n"
29376+ "18: movl %%edx, 28(%3)\n"
29377+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29378+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29379+ "21: movl %%eax, 32(%3)\n"
29380+ "22: movl %%edx, 36(%3)\n"
29381+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29382+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29383+ "25: movl %%eax, 40(%3)\n"
29384+ "26: movl %%edx, 44(%3)\n"
29385+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29386+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29387+ "29: movl %%eax, 48(%3)\n"
29388+ "30: movl %%edx, 52(%3)\n"
29389+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29390+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29391+ "33: movl %%eax, 56(%3)\n"
29392+ "34: movl %%edx, 60(%3)\n"
29393+ " addl $-64, %0\n"
29394+ " addl $64, %4\n"
29395+ " addl $64, %3\n"
29396+ " cmpl $63, %0\n"
29397+ " ja 1b\n"
29398+ "35: movl %0, %%eax\n"
29399+ " shrl $2, %0\n"
29400+ " andl $3, %%eax\n"
29401+ " cld\n"
29402+ "99: rep; "__copyuser_seg" movsl\n"
29403+ "36: movl %%eax, %0\n"
29404+ "37: rep; "__copyuser_seg" movsb\n"
29405+ "100:\n"
29406 ".section .fixup,\"ax\"\n"
29407 "101: lea 0(%%eax,%0,4),%0\n"
29408 " jmp 100b\n"
29409@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29410 int d0, d1;
29411 __asm__ __volatile__(
29412 " .align 2,0x90\n"
29413- "0: movl 32(%4), %%eax\n"
29414+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29415 " cmpl $67, %0\n"
29416 " jbe 2f\n"
29417- "1: movl 64(%4), %%eax\n"
29418+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29419 " .align 2,0x90\n"
29420- "2: movl 0(%4), %%eax\n"
29421- "21: movl 4(%4), %%edx\n"
29422+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29423+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29424 " movl %%eax, 0(%3)\n"
29425 " movl %%edx, 4(%3)\n"
29426- "3: movl 8(%4), %%eax\n"
29427- "31: movl 12(%4),%%edx\n"
29428+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29429+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29430 " movl %%eax, 8(%3)\n"
29431 " movl %%edx, 12(%3)\n"
29432- "4: movl 16(%4), %%eax\n"
29433- "41: movl 20(%4), %%edx\n"
29434+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29435+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29436 " movl %%eax, 16(%3)\n"
29437 " movl %%edx, 20(%3)\n"
29438- "10: movl 24(%4), %%eax\n"
29439- "51: movl 28(%4), %%edx\n"
29440+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29441+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29442 " movl %%eax, 24(%3)\n"
29443 " movl %%edx, 28(%3)\n"
29444- "11: movl 32(%4), %%eax\n"
29445- "61: movl 36(%4), %%edx\n"
29446+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29447+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29448 " movl %%eax, 32(%3)\n"
29449 " movl %%edx, 36(%3)\n"
29450- "12: movl 40(%4), %%eax\n"
29451- "71: movl 44(%4), %%edx\n"
29452+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29453+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29454 " movl %%eax, 40(%3)\n"
29455 " movl %%edx, 44(%3)\n"
29456- "13: movl 48(%4), %%eax\n"
29457- "81: movl 52(%4), %%edx\n"
29458+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29459+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29460 " movl %%eax, 48(%3)\n"
29461 " movl %%edx, 52(%3)\n"
29462- "14: movl 56(%4), %%eax\n"
29463- "91: movl 60(%4), %%edx\n"
29464+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29465+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29466 " movl %%eax, 56(%3)\n"
29467 " movl %%edx, 60(%3)\n"
29468 " addl $-64, %0\n"
29469@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29470 " shrl $2, %0\n"
29471 " andl $3, %%eax\n"
29472 " cld\n"
29473- "6: rep; movsl\n"
29474+ "6: rep; "__copyuser_seg" movsl\n"
29475 " movl %%eax,%0\n"
29476- "7: rep; movsb\n"
29477+ "7: rep; "__copyuser_seg" movsb\n"
29478 "8:\n"
29479 ".section .fixup,\"ax\"\n"
29480 "9: lea 0(%%eax,%0,4),%0\n"
29481@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29482
29483 __asm__ __volatile__(
29484 " .align 2,0x90\n"
29485- "0: movl 32(%4), %%eax\n"
29486+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29487 " cmpl $67, %0\n"
29488 " jbe 2f\n"
29489- "1: movl 64(%4), %%eax\n"
29490+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29491 " .align 2,0x90\n"
29492- "2: movl 0(%4), %%eax\n"
29493- "21: movl 4(%4), %%edx\n"
29494+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29495+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29496 " movnti %%eax, 0(%3)\n"
29497 " movnti %%edx, 4(%3)\n"
29498- "3: movl 8(%4), %%eax\n"
29499- "31: movl 12(%4),%%edx\n"
29500+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29501+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29502 " movnti %%eax, 8(%3)\n"
29503 " movnti %%edx, 12(%3)\n"
29504- "4: movl 16(%4), %%eax\n"
29505- "41: movl 20(%4), %%edx\n"
29506+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29507+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29508 " movnti %%eax, 16(%3)\n"
29509 " movnti %%edx, 20(%3)\n"
29510- "10: movl 24(%4), %%eax\n"
29511- "51: movl 28(%4), %%edx\n"
29512+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29513+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29514 " movnti %%eax, 24(%3)\n"
29515 " movnti %%edx, 28(%3)\n"
29516- "11: movl 32(%4), %%eax\n"
29517- "61: movl 36(%4), %%edx\n"
29518+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29519+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29520 " movnti %%eax, 32(%3)\n"
29521 " movnti %%edx, 36(%3)\n"
29522- "12: movl 40(%4), %%eax\n"
29523- "71: movl 44(%4), %%edx\n"
29524+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29525+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29526 " movnti %%eax, 40(%3)\n"
29527 " movnti %%edx, 44(%3)\n"
29528- "13: movl 48(%4), %%eax\n"
29529- "81: movl 52(%4), %%edx\n"
29530+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29531+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29532 " movnti %%eax, 48(%3)\n"
29533 " movnti %%edx, 52(%3)\n"
29534- "14: movl 56(%4), %%eax\n"
29535- "91: movl 60(%4), %%edx\n"
29536+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29537+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29538 " movnti %%eax, 56(%3)\n"
29539 " movnti %%edx, 60(%3)\n"
29540 " addl $-64, %0\n"
29541@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29542 " shrl $2, %0\n"
29543 " andl $3, %%eax\n"
29544 " cld\n"
29545- "6: rep; movsl\n"
29546+ "6: rep; "__copyuser_seg" movsl\n"
29547 " movl %%eax,%0\n"
29548- "7: rep; movsb\n"
29549+ "7: rep; "__copyuser_seg" movsb\n"
29550 "8:\n"
29551 ".section .fixup,\"ax\"\n"
29552 "9: lea 0(%%eax,%0,4),%0\n"
29553@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
29554
29555 __asm__ __volatile__(
29556 " .align 2,0x90\n"
29557- "0: movl 32(%4), %%eax\n"
29558+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29559 " cmpl $67, %0\n"
29560 " jbe 2f\n"
29561- "1: movl 64(%4), %%eax\n"
29562+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29563 " .align 2,0x90\n"
29564- "2: movl 0(%4), %%eax\n"
29565- "21: movl 4(%4), %%edx\n"
29566+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29567+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29568 " movnti %%eax, 0(%3)\n"
29569 " movnti %%edx, 4(%3)\n"
29570- "3: movl 8(%4), %%eax\n"
29571- "31: movl 12(%4),%%edx\n"
29572+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29573+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29574 " movnti %%eax, 8(%3)\n"
29575 " movnti %%edx, 12(%3)\n"
29576- "4: movl 16(%4), %%eax\n"
29577- "41: movl 20(%4), %%edx\n"
29578+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29579+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29580 " movnti %%eax, 16(%3)\n"
29581 " movnti %%edx, 20(%3)\n"
29582- "10: movl 24(%4), %%eax\n"
29583- "51: movl 28(%4), %%edx\n"
29584+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29585+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29586 " movnti %%eax, 24(%3)\n"
29587 " movnti %%edx, 28(%3)\n"
29588- "11: movl 32(%4), %%eax\n"
29589- "61: movl 36(%4), %%edx\n"
29590+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29591+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29592 " movnti %%eax, 32(%3)\n"
29593 " movnti %%edx, 36(%3)\n"
29594- "12: movl 40(%4), %%eax\n"
29595- "71: movl 44(%4), %%edx\n"
29596+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29597+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29598 " movnti %%eax, 40(%3)\n"
29599 " movnti %%edx, 44(%3)\n"
29600- "13: movl 48(%4), %%eax\n"
29601- "81: movl 52(%4), %%edx\n"
29602+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29603+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29604 " movnti %%eax, 48(%3)\n"
29605 " movnti %%edx, 52(%3)\n"
29606- "14: movl 56(%4), %%eax\n"
29607- "91: movl 60(%4), %%edx\n"
29608+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29609+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29610 " movnti %%eax, 56(%3)\n"
29611 " movnti %%edx, 60(%3)\n"
29612 " addl $-64, %0\n"
29613@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29614 " shrl $2, %0\n"
29615 " andl $3, %%eax\n"
29616 " cld\n"
29617- "6: rep; movsl\n"
29618+ "6: rep; "__copyuser_seg" movsl\n"
29619 " movl %%eax,%0\n"
29620- "7: rep; movsb\n"
29621+ "7: rep; "__copyuser_seg" movsb\n"
29622 "8:\n"
29623 ".section .fixup,\"ax\"\n"
29624 "9: lea 0(%%eax,%0,4),%0\n"
29625@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29626 */
29627 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29628 unsigned long size);
29629-unsigned long __copy_user_intel(void __user *to, const void *from,
29630+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29631+ unsigned long size);
29632+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29633 unsigned long size);
29634 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29635 const void __user *from, unsigned long size);
29636 #endif /* CONFIG_X86_INTEL_USERCOPY */
29637
29638 /* Generic arbitrary sized copy. */
29639-#define __copy_user(to, from, size) \
29640+#define __copy_user(to, from, size, prefix, set, restore) \
29641 do { \
29642 int __d0, __d1, __d2; \
29643 __asm__ __volatile__( \
29644+ set \
29645 " cmp $7,%0\n" \
29646 " jbe 1f\n" \
29647 " movl %1,%0\n" \
29648 " negl %0\n" \
29649 " andl $7,%0\n" \
29650 " subl %0,%3\n" \
29651- "4: rep; movsb\n" \
29652+ "4: rep; "prefix"movsb\n" \
29653 " movl %3,%0\n" \
29654 " shrl $2,%0\n" \
29655 " andl $3,%3\n" \
29656 " .align 2,0x90\n" \
29657- "0: rep; movsl\n" \
29658+ "0: rep; "prefix"movsl\n" \
29659 " movl %3,%0\n" \
29660- "1: rep; movsb\n" \
29661+ "1: rep; "prefix"movsb\n" \
29662 "2:\n" \
29663+ restore \
29664 ".section .fixup,\"ax\"\n" \
29665 "5: addl %3,%0\n" \
29666 " jmp 2b\n" \
29667@@ -538,14 +650,14 @@ do { \
29668 " negl %0\n" \
29669 " andl $7,%0\n" \
29670 " subl %0,%3\n" \
29671- "4: rep; movsb\n" \
29672+ "4: rep; "__copyuser_seg"movsb\n" \
29673 " movl %3,%0\n" \
29674 " shrl $2,%0\n" \
29675 " andl $3,%3\n" \
29676 " .align 2,0x90\n" \
29677- "0: rep; movsl\n" \
29678+ "0: rep; "__copyuser_seg"movsl\n" \
29679 " movl %3,%0\n" \
29680- "1: rep; movsb\n" \
29681+ "1: rep; "__copyuser_seg"movsb\n" \
29682 "2:\n" \
29683 ".section .fixup,\"ax\"\n" \
29684 "5: addl %3,%0\n" \
29685@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29686 {
29687 stac();
29688 if (movsl_is_ok(to, from, n))
29689- __copy_user(to, from, n);
29690+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29691 else
29692- n = __copy_user_intel(to, from, n);
29693+ n = __generic_copy_to_user_intel(to, from, n);
29694 clac();
29695 return n;
29696 }
29697@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29698 {
29699 stac();
29700 if (movsl_is_ok(to, from, n))
29701- __copy_user(to, from, n);
29702+ __copy_user(to, from, n, __copyuser_seg, "", "");
29703 else
29704- n = __copy_user_intel((void __user *)to,
29705- (const void *)from, n);
29706+ n = __generic_copy_from_user_intel(to, from, n);
29707 clac();
29708 return n;
29709 }
29710@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29711 if (n > 64 && cpu_has_xmm2)
29712 n = __copy_user_intel_nocache(to, from, n);
29713 else
29714- __copy_user(to, from, n);
29715+ __copy_user(to, from, n, __copyuser_seg, "", "");
29716 #else
29717- __copy_user(to, from, n);
29718+ __copy_user(to, from, n, __copyuser_seg, "", "");
29719 #endif
29720 clac();
29721 return n;
29722 }
29723 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29724
29725-/**
29726- * copy_to_user: - Copy a block of data into user space.
29727- * @to: Destination address, in user space.
29728- * @from: Source address, in kernel space.
29729- * @n: Number of bytes to copy.
29730- *
29731- * Context: User context only. This function may sleep.
29732- *
29733- * Copy data from kernel space to user space.
29734- *
29735- * Returns number of bytes that could not be copied.
29736- * On success, this will be zero.
29737- */
29738-unsigned long
29739-copy_to_user(void __user *to, const void *from, unsigned long n)
29740+#ifdef CONFIG_PAX_MEMORY_UDEREF
29741+void __set_fs(mm_segment_t x)
29742 {
29743- if (access_ok(VERIFY_WRITE, to, n))
29744- n = __copy_to_user(to, from, n);
29745- return n;
29746+ switch (x.seg) {
29747+ case 0:
29748+ loadsegment(gs, 0);
29749+ break;
29750+ case TASK_SIZE_MAX:
29751+ loadsegment(gs, __USER_DS);
29752+ break;
29753+ case -1UL:
29754+ loadsegment(gs, __KERNEL_DS);
29755+ break;
29756+ default:
29757+ BUG();
29758+ }
29759 }
29760-EXPORT_SYMBOL(copy_to_user);
29761+EXPORT_SYMBOL(__set_fs);
29762
29763-/**
29764- * copy_from_user: - Copy a block of data from user space.
29765- * @to: Destination address, in kernel space.
29766- * @from: Source address, in user space.
29767- * @n: Number of bytes to copy.
29768- *
29769- * Context: User context only. This function may sleep.
29770- *
29771- * Copy data from user space to kernel space.
29772- *
29773- * Returns number of bytes that could not be copied.
29774- * On success, this will be zero.
29775- *
29776- * If some data could not be copied, this function will pad the copied
29777- * data to the requested size using zero bytes.
29778- */
29779-unsigned long
29780-_copy_from_user(void *to, const void __user *from, unsigned long n)
29781+void set_fs(mm_segment_t x)
29782 {
29783- if (access_ok(VERIFY_READ, from, n))
29784- n = __copy_from_user(to, from, n);
29785- else
29786- memset(to, 0, n);
29787- return n;
29788+ current_thread_info()->addr_limit = x;
29789+ __set_fs(x);
29790 }
29791-EXPORT_SYMBOL(_copy_from_user);
29792+EXPORT_SYMBOL(set_fs);
29793+#endif
29794diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29795index c905e89..01ab928 100644
29796--- a/arch/x86/lib/usercopy_64.c
29797+++ b/arch/x86/lib/usercopy_64.c
29798@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29799 might_fault();
29800 /* no memory constraint because it doesn't change any memory gcc knows
29801 about */
29802+ pax_open_userland();
29803 stac();
29804 asm volatile(
29805 " testq %[size8],%[size8]\n"
29806@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29807 _ASM_EXTABLE(0b,3b)
29808 _ASM_EXTABLE(1b,2b)
29809 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29810- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29811+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29812 [zero] "r" (0UL), [eight] "r" (8UL));
29813 clac();
29814+ pax_close_userland();
29815 return size;
29816 }
29817 EXPORT_SYMBOL(__clear_user);
29818@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29819 }
29820 EXPORT_SYMBOL(clear_user);
29821
29822-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29823+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29824 {
29825- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29826- return copy_user_generic((__force void *)to, (__force void *)from, len);
29827- }
29828- return len;
29829+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29830+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29831+ return len;
29832 }
29833 EXPORT_SYMBOL(copy_in_user);
29834
29835@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29836 * it is not necessary to optimize tail handling.
29837 */
29838 __visible unsigned long
29839-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29840+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29841 {
29842 char c;
29843 unsigned zero_len;
29844
29845+ clac();
29846+ pax_close_userland();
29847 for (; len; --len, to++) {
29848 if (__get_user_nocheck(c, from++, sizeof(char)))
29849 break;
29850@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29851 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29852 if (__put_user_nocheck(c, to++, sizeof(char)))
29853 break;
29854- clac();
29855 return len;
29856 }
29857diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29858index 23d8e5f..9ccc13a 100644
29859--- a/arch/x86/mm/Makefile
29860+++ b/arch/x86/mm/Makefile
29861@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29862 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29863
29864 obj-$(CONFIG_MEMTEST) += memtest.o
29865+
29866+quote:="
29867+obj-$(CONFIG_X86_64) += uderef_64.o
29868+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29869diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29870index 903ec1e..c4166b2 100644
29871--- a/arch/x86/mm/extable.c
29872+++ b/arch/x86/mm/extable.c
29873@@ -6,12 +6,24 @@
29874 static inline unsigned long
29875 ex_insn_addr(const struct exception_table_entry *x)
29876 {
29877- return (unsigned long)&x->insn + x->insn;
29878+ unsigned long reloc = 0;
29879+
29880+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29881+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29882+#endif
29883+
29884+ return (unsigned long)&x->insn + x->insn + reloc;
29885 }
29886 static inline unsigned long
29887 ex_fixup_addr(const struct exception_table_entry *x)
29888 {
29889- return (unsigned long)&x->fixup + x->fixup;
29890+ unsigned long reloc = 0;
29891+
29892+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29893+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29894+#endif
29895+
29896+ return (unsigned long)&x->fixup + x->fixup + reloc;
29897 }
29898
29899 int fixup_exception(struct pt_regs *regs)
29900@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29901 unsigned long new_ip;
29902
29903 #ifdef CONFIG_PNPBIOS
29904- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29905+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29906 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29907 extern u32 pnp_bios_is_utter_crap;
29908 pnp_bios_is_utter_crap = 1;
29909@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29910 i += 4;
29911 p->fixup -= i;
29912 i += 4;
29913+
29914+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29915+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29916+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29917+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29918+#endif
29919+
29920 }
29921 }
29922
29923diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29924index 3aaeffc..42ea9fb 100644
29925--- a/arch/x86/mm/fault.c
29926+++ b/arch/x86/mm/fault.c
29927@@ -14,11 +14,18 @@
29928 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29929 #include <linux/prefetch.h> /* prefetchw */
29930 #include <linux/context_tracking.h> /* exception_enter(), ... */
29931+#include <linux/unistd.h>
29932+#include <linux/compiler.h>
29933
29934 #include <asm/traps.h> /* dotraplinkage, ... */
29935 #include <asm/pgalloc.h> /* pgd_*(), ... */
29936 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29937 #include <asm/fixmap.h> /* VSYSCALL_START */
29938+#include <asm/tlbflush.h>
29939+
29940+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29941+#include <asm/stacktrace.h>
29942+#endif
29943
29944 /*
29945 * Page fault error code bits:
29946@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29947 int ret = 0;
29948
29949 /* kprobe_running() needs smp_processor_id() */
29950- if (kprobes_built_in() && !user_mode_vm(regs)) {
29951+ if (kprobes_built_in() && !user_mode(regs)) {
29952 preempt_disable();
29953 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29954 ret = 1;
29955@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29956 return !instr_lo || (instr_lo>>1) == 1;
29957 case 0x00:
29958 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29959- if (probe_kernel_address(instr, opcode))
29960+ if (user_mode(regs)) {
29961+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29962+ return 0;
29963+ } else if (probe_kernel_address(instr, opcode))
29964 return 0;
29965
29966 *prefetch = (instr_lo == 0xF) &&
29967@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29968 while (instr < max_instr) {
29969 unsigned char opcode;
29970
29971- if (probe_kernel_address(instr, opcode))
29972+ if (user_mode(regs)) {
29973+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29974+ break;
29975+ } else if (probe_kernel_address(instr, opcode))
29976 break;
29977
29978 instr++;
29979@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29980 force_sig_info(si_signo, &info, tsk);
29981 }
29982
29983+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29984+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29985+#endif
29986+
29987+#ifdef CONFIG_PAX_EMUTRAMP
29988+static int pax_handle_fetch_fault(struct pt_regs *regs);
29989+#endif
29990+
29991+#ifdef CONFIG_PAX_PAGEEXEC
29992+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29993+{
29994+ pgd_t *pgd;
29995+ pud_t *pud;
29996+ pmd_t *pmd;
29997+
29998+ pgd = pgd_offset(mm, address);
29999+ if (!pgd_present(*pgd))
30000+ return NULL;
30001+ pud = pud_offset(pgd, address);
30002+ if (!pud_present(*pud))
30003+ return NULL;
30004+ pmd = pmd_offset(pud, address);
30005+ if (!pmd_present(*pmd))
30006+ return NULL;
30007+ return pmd;
30008+}
30009+#endif
30010+
30011 DEFINE_SPINLOCK(pgd_lock);
30012 LIST_HEAD(pgd_list);
30013
30014@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
30015 for (address = VMALLOC_START & PMD_MASK;
30016 address >= TASK_SIZE && address < FIXADDR_TOP;
30017 address += PMD_SIZE) {
30018+
30019+#ifdef CONFIG_PAX_PER_CPU_PGD
30020+ unsigned long cpu;
30021+#else
30022 struct page *page;
30023+#endif
30024
30025 spin_lock(&pgd_lock);
30026+
30027+#ifdef CONFIG_PAX_PER_CPU_PGD
30028+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30029+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30030+ pmd_t *ret;
30031+
30032+ ret = vmalloc_sync_one(pgd, address);
30033+ if (!ret)
30034+ break;
30035+ pgd = get_cpu_pgd(cpu, kernel);
30036+#else
30037 list_for_each_entry(page, &pgd_list, lru) {
30038+ pgd_t *pgd;
30039 spinlock_t *pgt_lock;
30040 pmd_t *ret;
30041
30042@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
30043 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30044
30045 spin_lock(pgt_lock);
30046- ret = vmalloc_sync_one(page_address(page), address);
30047+ pgd = page_address(page);
30048+#endif
30049+
30050+ ret = vmalloc_sync_one(pgd, address);
30051+
30052+#ifndef CONFIG_PAX_PER_CPU_PGD
30053 spin_unlock(pgt_lock);
30054+#endif
30055
30056 if (!ret)
30057 break;
30058@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30059 * an interrupt in the middle of a task switch..
30060 */
30061 pgd_paddr = read_cr3();
30062+
30063+#ifdef CONFIG_PAX_PER_CPU_PGD
30064+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30065+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30066+#endif
30067+
30068 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30069 if (!pmd_k)
30070 return -1;
30071@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30072 * happen within a race in page table update. In the later
30073 * case just flush:
30074 */
30075- pgd = pgd_offset(current->active_mm, address);
30076+
30077 pgd_ref = pgd_offset_k(address);
30078 if (pgd_none(*pgd_ref))
30079 return -1;
30080
30081+#ifdef CONFIG_PAX_PER_CPU_PGD
30082+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30083+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30084+ if (pgd_none(*pgd)) {
30085+ set_pgd(pgd, *pgd_ref);
30086+ arch_flush_lazy_mmu_mode();
30087+ } else {
30088+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30089+ }
30090+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30091+#else
30092+ pgd = pgd_offset(current->active_mm, address);
30093+#endif
30094+
30095 if (pgd_none(*pgd)) {
30096 set_pgd(pgd, *pgd_ref);
30097 arch_flush_lazy_mmu_mode();
30098@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30099 static int is_errata100(struct pt_regs *regs, unsigned long address)
30100 {
30101 #ifdef CONFIG_X86_64
30102- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30103+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30104 return 1;
30105 #endif
30106 return 0;
30107@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30108 }
30109
30110 static const char nx_warning[] = KERN_CRIT
30111-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30112+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30113
30114 static void
30115 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30116@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30117 if (!oops_may_print())
30118 return;
30119
30120- if (error_code & PF_INSTR) {
30121+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30122 unsigned int level;
30123
30124 pte_t *pte = lookup_address(address, &level);
30125
30126 if (pte && pte_present(*pte) && !pte_exec(*pte))
30127- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30128+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30129 }
30130
30131+#ifdef CONFIG_PAX_KERNEXEC
30132+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30133+ if (current->signal->curr_ip)
30134+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30135+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30136+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30137+ else
30138+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30139+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30140+ }
30141+#endif
30142+
30143 printk(KERN_ALERT "BUG: unable to handle kernel ");
30144 if (address < PAGE_SIZE)
30145 printk(KERN_CONT "NULL pointer dereference");
30146@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30147 return;
30148 }
30149 #endif
30150+
30151+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30152+ if (pax_is_fetch_fault(regs, error_code, address)) {
30153+
30154+#ifdef CONFIG_PAX_EMUTRAMP
30155+ switch (pax_handle_fetch_fault(regs)) {
30156+ case 2:
30157+ return;
30158+ }
30159+#endif
30160+
30161+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30162+ do_group_exit(SIGKILL);
30163+ }
30164+#endif
30165+
30166 /* Kernel addresses are always protection faults: */
30167 if (address >= TASK_SIZE)
30168 error_code |= PF_PROT;
30169@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30170 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30171 printk(KERN_ERR
30172 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30173- tsk->comm, tsk->pid, address);
30174+ tsk->comm, task_pid_nr(tsk), address);
30175 code = BUS_MCEERR_AR;
30176 }
30177 #endif
30178@@ -889,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30179 return 1;
30180 }
30181
30182+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30183+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30184+{
30185+ pte_t *pte;
30186+ pmd_t *pmd;
30187+ spinlock_t *ptl;
30188+ unsigned char pte_mask;
30189+
30190+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30191+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30192+ return 0;
30193+
30194+ /* PaX: it's our fault, let's handle it if we can */
30195+
30196+ /* PaX: take a look at read faults before acquiring any locks */
30197+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30198+ /* instruction fetch attempt from a protected page in user mode */
30199+ up_read(&mm->mmap_sem);
30200+
30201+#ifdef CONFIG_PAX_EMUTRAMP
30202+ switch (pax_handle_fetch_fault(regs)) {
30203+ case 2:
30204+ return 1;
30205+ }
30206+#endif
30207+
30208+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30209+ do_group_exit(SIGKILL);
30210+ }
30211+
30212+ pmd = pax_get_pmd(mm, address);
30213+ if (unlikely(!pmd))
30214+ return 0;
30215+
30216+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30217+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30218+ pte_unmap_unlock(pte, ptl);
30219+ return 0;
30220+ }
30221+
30222+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30223+ /* write attempt to a protected page in user mode */
30224+ pte_unmap_unlock(pte, ptl);
30225+ return 0;
30226+ }
30227+
30228+#ifdef CONFIG_SMP
30229+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30230+#else
30231+ if (likely(address > get_limit(regs->cs)))
30232+#endif
30233+ {
30234+ set_pte(pte, pte_mkread(*pte));
30235+ __flush_tlb_one(address);
30236+ pte_unmap_unlock(pte, ptl);
30237+ up_read(&mm->mmap_sem);
30238+ return 1;
30239+ }
30240+
30241+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30242+
30243+ /*
30244+ * PaX: fill DTLB with user rights and retry
30245+ */
30246+ __asm__ __volatile__ (
30247+ "orb %2,(%1)\n"
30248+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30249+/*
30250+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30251+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30252+ * page fault when examined during a TLB load attempt. this is true not only
30253+ * for PTEs holding a non-present entry but also present entries that will
30254+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30255+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30256+ * for our target pages since their PTEs are simply not in the TLBs at all.
30257+
30258+ * the best thing in omitting it is that we gain around 15-20% speed in the
30259+ * fast path of the page fault handler and can get rid of tracing since we
30260+ * can no longer flush unintended entries.
30261+ */
30262+ "invlpg (%0)\n"
30263+#endif
30264+ __copyuser_seg"testb $0,(%0)\n"
30265+ "xorb %3,(%1)\n"
30266+ :
30267+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30268+ : "memory", "cc");
30269+ pte_unmap_unlock(pte, ptl);
30270+ up_read(&mm->mmap_sem);
30271+ return 1;
30272+}
30273+#endif
30274+
30275 /*
30276 * Handle a spurious fault caused by a stale TLB entry.
30277 *
30278@@ -955,6 +1160,9 @@ int show_unhandled_signals = 1;
30279 static inline int
30280 access_error(unsigned long error_code, struct vm_area_struct *vma)
30281 {
30282+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30283+ return 1;
30284+
30285 if (error_code & PF_WRITE) {
30286 /* write, present and write, not present: */
30287 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30288@@ -983,7 +1191,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30289 if (error_code & PF_USER)
30290 return false;
30291
30292- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30293+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30294 return false;
30295
30296 return true;
30297@@ -1010,6 +1218,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30298 /* Get the faulting address: */
30299 address = read_cr2();
30300
30301+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30302+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30303+ if (!search_exception_tables(regs->ip)) {
30304+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30305+ bad_area_nosemaphore(regs, error_code, address);
30306+ return;
30307+ }
30308+ if (address < pax_user_shadow_base) {
30309+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30310+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30311+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30312+ } else
30313+ address -= pax_user_shadow_base;
30314+ }
30315+#endif
30316+
30317 /*
30318 * Detect and handle instructions that would cause a page fault for
30319 * both a tracked kernel page and a userspace page.
30320@@ -1069,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30321 * User-mode registers count as a user access even for any
30322 * potential system fault or CPU buglet:
30323 */
30324- if (user_mode_vm(regs)) {
30325+ if (user_mode(regs)) {
30326 local_irq_enable();
30327 error_code |= PF_USER;
30328 flags |= FAULT_FLAG_USER;
30329@@ -1135,6 +1359,11 @@ retry:
30330 might_sleep();
30331 }
30332
30333+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30334+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30335+ return;
30336+#endif
30337+
30338 vma = find_vma(mm, address);
30339 if (unlikely(!vma)) {
30340 bad_area(regs, error_code, address);
30341@@ -1146,18 +1375,24 @@ retry:
30342 bad_area(regs, error_code, address);
30343 return;
30344 }
30345- if (error_code & PF_USER) {
30346- /*
30347- * Accessing the stack below %sp is always a bug.
30348- * The large cushion allows instructions like enter
30349- * and pusha to work. ("enter $65535, $31" pushes
30350- * 32 pointers and then decrements %sp by 65535.)
30351- */
30352- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30353- bad_area(regs, error_code, address);
30354- return;
30355- }
30356+ /*
30357+ * Accessing the stack below %sp is always a bug.
30358+ * The large cushion allows instructions like enter
30359+ * and pusha to work. ("enter $65535, $31" pushes
30360+ * 32 pointers and then decrements %sp by 65535.)
30361+ */
30362+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30363+ bad_area(regs, error_code, address);
30364+ return;
30365 }
30366+
30367+#ifdef CONFIG_PAX_SEGMEXEC
30368+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30369+ bad_area(regs, error_code, address);
30370+ return;
30371+ }
30372+#endif
30373+
30374 if (unlikely(expand_stack(vma, address))) {
30375 bad_area(regs, error_code, address);
30376 return;
30377@@ -1231,3 +1466,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30378 __do_page_fault(regs, error_code);
30379 exception_exit(prev_state);
30380 }
30381+
30382+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30383+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30384+{
30385+ struct mm_struct *mm = current->mm;
30386+ unsigned long ip = regs->ip;
30387+
30388+ if (v8086_mode(regs))
30389+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30390+
30391+#ifdef CONFIG_PAX_PAGEEXEC
30392+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30393+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30394+ return true;
30395+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30396+ return true;
30397+ return false;
30398+ }
30399+#endif
30400+
30401+#ifdef CONFIG_PAX_SEGMEXEC
30402+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30403+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30404+ return true;
30405+ return false;
30406+ }
30407+#endif
30408+
30409+ return false;
30410+}
30411+#endif
30412+
30413+#ifdef CONFIG_PAX_EMUTRAMP
30414+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30415+{
30416+ int err;
30417+
30418+ do { /* PaX: libffi trampoline emulation */
30419+ unsigned char mov, jmp;
30420+ unsigned int addr1, addr2;
30421+
30422+#ifdef CONFIG_X86_64
30423+ if ((regs->ip + 9) >> 32)
30424+ break;
30425+#endif
30426+
30427+ err = get_user(mov, (unsigned char __user *)regs->ip);
30428+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30429+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30430+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30431+
30432+ if (err)
30433+ break;
30434+
30435+ if (mov == 0xB8 && jmp == 0xE9) {
30436+ regs->ax = addr1;
30437+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30438+ return 2;
30439+ }
30440+ } while (0);
30441+
30442+ do { /* PaX: gcc trampoline emulation #1 */
30443+ unsigned char mov1, mov2;
30444+ unsigned short jmp;
30445+ unsigned int addr1, addr2;
30446+
30447+#ifdef CONFIG_X86_64
30448+ if ((regs->ip + 11) >> 32)
30449+ break;
30450+#endif
30451+
30452+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30453+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30454+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30455+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30456+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30457+
30458+ if (err)
30459+ break;
30460+
30461+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30462+ regs->cx = addr1;
30463+ regs->ax = addr2;
30464+ regs->ip = addr2;
30465+ return 2;
30466+ }
30467+ } while (0);
30468+
30469+ do { /* PaX: gcc trampoline emulation #2 */
30470+ unsigned char mov, jmp;
30471+ unsigned int addr1, addr2;
30472+
30473+#ifdef CONFIG_X86_64
30474+ if ((regs->ip + 9) >> 32)
30475+ break;
30476+#endif
30477+
30478+ err = get_user(mov, (unsigned char __user *)regs->ip);
30479+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30480+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30481+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30482+
30483+ if (err)
30484+ break;
30485+
30486+ if (mov == 0xB9 && jmp == 0xE9) {
30487+ regs->cx = addr1;
30488+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30489+ return 2;
30490+ }
30491+ } while (0);
30492+
30493+ return 1; /* PaX in action */
30494+}
30495+
30496+#ifdef CONFIG_X86_64
30497+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30498+{
30499+ int err;
30500+
30501+ do { /* PaX: libffi trampoline emulation */
30502+ unsigned short mov1, mov2, jmp1;
30503+ unsigned char stcclc, jmp2;
30504+ unsigned long addr1, addr2;
30505+
30506+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30507+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30508+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30509+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30510+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30511+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30512+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30513+
30514+ if (err)
30515+ break;
30516+
30517+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30518+ regs->r11 = addr1;
30519+ regs->r10 = addr2;
30520+ if (stcclc == 0xF8)
30521+ regs->flags &= ~X86_EFLAGS_CF;
30522+ else
30523+ regs->flags |= X86_EFLAGS_CF;
30524+ regs->ip = addr1;
30525+ return 2;
30526+ }
30527+ } while (0);
30528+
30529+ do { /* PaX: gcc trampoline emulation #1 */
30530+ unsigned short mov1, mov2, jmp1;
30531+ unsigned char jmp2;
30532+ unsigned int addr1;
30533+ unsigned long addr2;
30534+
30535+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30536+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30537+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30538+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30539+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30540+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30541+
30542+ if (err)
30543+ break;
30544+
30545+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30546+ regs->r11 = addr1;
30547+ regs->r10 = addr2;
30548+ regs->ip = addr1;
30549+ return 2;
30550+ }
30551+ } while (0);
30552+
30553+ do { /* PaX: gcc trampoline emulation #2 */
30554+ unsigned short mov1, mov2, jmp1;
30555+ unsigned char jmp2;
30556+ unsigned long addr1, addr2;
30557+
30558+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30559+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30560+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30561+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30562+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30563+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30564+
30565+ if (err)
30566+ break;
30567+
30568+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30569+ regs->r11 = addr1;
30570+ regs->r10 = addr2;
30571+ regs->ip = addr1;
30572+ return 2;
30573+ }
30574+ } while (0);
30575+
30576+ return 1; /* PaX in action */
30577+}
30578+#endif
30579+
30580+/*
30581+ * PaX: decide what to do with offenders (regs->ip = fault address)
30582+ *
30583+ * returns 1 when task should be killed
30584+ * 2 when gcc trampoline was detected
30585+ */
30586+static int pax_handle_fetch_fault(struct pt_regs *regs)
30587+{
30588+ if (v8086_mode(regs))
30589+ return 1;
30590+
30591+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30592+ return 1;
30593+
30594+#ifdef CONFIG_X86_32
30595+ return pax_handle_fetch_fault_32(regs);
30596+#else
30597+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30598+ return pax_handle_fetch_fault_32(regs);
30599+ else
30600+ return pax_handle_fetch_fault_64(regs);
30601+#endif
30602+}
30603+#endif
30604+
30605+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30606+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30607+{
30608+ long i;
30609+
30610+ printk(KERN_ERR "PAX: bytes at PC: ");
30611+ for (i = 0; i < 20; i++) {
30612+ unsigned char c;
30613+ if (get_user(c, (unsigned char __force_user *)pc+i))
30614+ printk(KERN_CONT "?? ");
30615+ else
30616+ printk(KERN_CONT "%02x ", c);
30617+ }
30618+ printk("\n");
30619+
30620+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30621+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30622+ unsigned long c;
30623+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30624+#ifdef CONFIG_X86_32
30625+ printk(KERN_CONT "???????? ");
30626+#else
30627+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30628+ printk(KERN_CONT "???????? ???????? ");
30629+ else
30630+ printk(KERN_CONT "???????????????? ");
30631+#endif
30632+ } else {
30633+#ifdef CONFIG_X86_64
30634+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30635+ printk(KERN_CONT "%08x ", (unsigned int)c);
30636+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30637+ } else
30638+#endif
30639+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30640+ }
30641+ }
30642+ printk("\n");
30643+}
30644+#endif
30645+
30646+/**
30647+ * probe_kernel_write(): safely attempt to write to a location
30648+ * @dst: address to write to
30649+ * @src: pointer to the data that shall be written
30650+ * @size: size of the data chunk
30651+ *
30652+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30653+ * happens, handle that and return -EFAULT.
30654+ */
30655+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30656+{
30657+ long ret;
30658+ mm_segment_t old_fs = get_fs();
30659+
30660+ set_fs(KERNEL_DS);
30661+ pagefault_disable();
30662+ pax_open_kernel();
30663+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30664+ pax_close_kernel();
30665+ pagefault_enable();
30666+ set_fs(old_fs);
30667+
30668+ return ret ? -EFAULT : 0;
30669+}
30670diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30671index dd74e46..7d26398 100644
30672--- a/arch/x86/mm/gup.c
30673+++ b/arch/x86/mm/gup.c
30674@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30675 addr = start;
30676 len = (unsigned long) nr_pages << PAGE_SHIFT;
30677 end = start + len;
30678- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30679+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30680 (void __user *)start, len)))
30681 return 0;
30682
30683diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30684index 4500142..53a363c 100644
30685--- a/arch/x86/mm/highmem_32.c
30686+++ b/arch/x86/mm/highmem_32.c
30687@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30688 idx = type + KM_TYPE_NR*smp_processor_id();
30689 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30690 BUG_ON(!pte_none(*(kmap_pte-idx)));
30691+
30692+ pax_open_kernel();
30693 set_pte(kmap_pte-idx, mk_pte(page, prot));
30694+ pax_close_kernel();
30695+
30696 arch_flush_lazy_mmu_mode();
30697
30698 return (void *)vaddr;
30699diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30700index 9d980d8..6bbfacb 100644
30701--- a/arch/x86/mm/hugetlbpage.c
30702+++ b/arch/x86/mm/hugetlbpage.c
30703@@ -92,23 +92,30 @@ int pmd_huge_support(void)
30704 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30705 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30706 unsigned long addr, unsigned long len,
30707- unsigned long pgoff, unsigned long flags)
30708+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30709 {
30710 struct hstate *h = hstate_file(file);
30711 struct vm_unmapped_area_info info;
30712-
30713+
30714 info.flags = 0;
30715 info.length = len;
30716 info.low_limit = TASK_UNMAPPED_BASE;
30717+
30718+#ifdef CONFIG_PAX_RANDMMAP
30719+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30720+ info.low_limit += current->mm->delta_mmap;
30721+#endif
30722+
30723 info.high_limit = TASK_SIZE;
30724 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30725 info.align_offset = 0;
30726+ info.threadstack_offset = offset;
30727 return vm_unmapped_area(&info);
30728 }
30729
30730 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30731 unsigned long addr0, unsigned long len,
30732- unsigned long pgoff, unsigned long flags)
30733+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30734 {
30735 struct hstate *h = hstate_file(file);
30736 struct vm_unmapped_area_info info;
30737@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30738 info.high_limit = current->mm->mmap_base;
30739 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30740 info.align_offset = 0;
30741+ info.threadstack_offset = offset;
30742 addr = vm_unmapped_area(&info);
30743
30744 /*
30745@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30746 VM_BUG_ON(addr != -ENOMEM);
30747 info.flags = 0;
30748 info.low_limit = TASK_UNMAPPED_BASE;
30749+
30750+#ifdef CONFIG_PAX_RANDMMAP
30751+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30752+ info.low_limit += current->mm->delta_mmap;
30753+#endif
30754+
30755 info.high_limit = TASK_SIZE;
30756 addr = vm_unmapped_area(&info);
30757 }
30758@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30759 struct hstate *h = hstate_file(file);
30760 struct mm_struct *mm = current->mm;
30761 struct vm_area_struct *vma;
30762+ unsigned long pax_task_size = TASK_SIZE;
30763+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30764
30765 if (len & ~huge_page_mask(h))
30766 return -EINVAL;
30767- if (len > TASK_SIZE)
30768+
30769+#ifdef CONFIG_PAX_SEGMEXEC
30770+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30771+ pax_task_size = SEGMEXEC_TASK_SIZE;
30772+#endif
30773+
30774+ pax_task_size -= PAGE_SIZE;
30775+
30776+ if (len > pax_task_size)
30777 return -ENOMEM;
30778
30779 if (flags & MAP_FIXED) {
30780@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30781 return addr;
30782 }
30783
30784+#ifdef CONFIG_PAX_RANDMMAP
30785+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30786+#endif
30787+
30788 if (addr) {
30789 addr = ALIGN(addr, huge_page_size(h));
30790 vma = find_vma(mm, addr);
30791- if (TASK_SIZE - len >= addr &&
30792- (!vma || addr + len <= vma->vm_start))
30793+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30794 return addr;
30795 }
30796 if (mm->get_unmapped_area == arch_get_unmapped_area)
30797 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30798- pgoff, flags);
30799+ pgoff, flags, offset);
30800 else
30801 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30802- pgoff, flags);
30803+ pgoff, flags, offset);
30804 }
30805
30806 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30807diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30808index 04664cd..dae6e5d 100644
30809--- a/arch/x86/mm/init.c
30810+++ b/arch/x86/mm/init.c
30811@@ -4,6 +4,7 @@
30812 #include <linux/swap.h>
30813 #include <linux/memblock.h>
30814 #include <linux/bootmem.h> /* for max_low_pfn */
30815+#include <linux/tboot.h>
30816
30817 #include <asm/cacheflush.h>
30818 #include <asm/e820.h>
30819@@ -17,6 +18,8 @@
30820 #include <asm/proto.h>
30821 #include <asm/dma.h> /* for MAX_DMA_PFN */
30822 #include <asm/microcode.h>
30823+#include <asm/desc.h>
30824+#include <asm/bios_ebda.h>
30825
30826 #include "mm_internal.h"
30827
30828@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30829 early_ioremap_page_table_range_init();
30830 #endif
30831
30832+#ifdef CONFIG_PAX_PER_CPU_PGD
30833+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30834+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30835+ KERNEL_PGD_PTRS);
30836+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30837+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30838+ KERNEL_PGD_PTRS);
30839+ load_cr3(get_cpu_pgd(0, kernel));
30840+#else
30841 load_cr3(swapper_pg_dir);
30842+#endif
30843+
30844 __flush_tlb_all();
30845
30846 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30847@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30848 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30849 * mmio resources as well as potential bios/acpi data regions.
30850 */
30851+
30852+#ifdef CONFIG_GRKERNSEC_KMEM
30853+static unsigned int ebda_start __read_only;
30854+static unsigned int ebda_end __read_only;
30855+#endif
30856+
30857 int devmem_is_allowed(unsigned long pagenr)
30858 {
30859- if (pagenr < 256)
30860+#ifdef CONFIG_GRKERNSEC_KMEM
30861+ /* allow BDA */
30862+ if (!pagenr)
30863 return 1;
30864+ /* allow EBDA */
30865+ if (pagenr >= ebda_start && pagenr < ebda_end)
30866+ return 1;
30867+ /* if tboot is in use, allow access to its hardcoded serial log range */
30868+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30869+ return 1;
30870+#else
30871+ if (!pagenr)
30872+ return 1;
30873+#ifdef CONFIG_VM86
30874+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30875+ return 1;
30876+#endif
30877+#endif
30878+
30879+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30880+ return 1;
30881+#ifdef CONFIG_GRKERNSEC_KMEM
30882+ /* throw out everything else below 1MB */
30883+ if (pagenr <= 256)
30884+ return 0;
30885+#endif
30886 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30887 return 0;
30888 if (!page_is_ram(pagenr))
30889@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30890 #endif
30891 }
30892
30893+#ifdef CONFIG_GRKERNSEC_KMEM
30894+static inline void gr_init_ebda(void)
30895+{
30896+ unsigned int ebda_addr;
30897+ unsigned int ebda_size = 0;
30898+
30899+ ebda_addr = get_bios_ebda();
30900+ if (ebda_addr) {
30901+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30902+ ebda_size <<= 10;
30903+ }
30904+ if (ebda_addr && ebda_size) {
30905+ ebda_start = ebda_addr >> PAGE_SHIFT;
30906+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30907+ } else {
30908+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30909+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30910+ }
30911+}
30912+#else
30913+static inline void gr_init_ebda(void) { }
30914+#endif
30915+
30916 void free_initmem(void)
30917 {
30918+#ifdef CONFIG_PAX_KERNEXEC
30919+#ifdef CONFIG_X86_32
30920+ /* PaX: limit KERNEL_CS to actual size */
30921+ unsigned long addr, limit;
30922+ struct desc_struct d;
30923+ int cpu;
30924+#else
30925+ pgd_t *pgd;
30926+ pud_t *pud;
30927+ pmd_t *pmd;
30928+ unsigned long addr, end;
30929+#endif
30930+#endif
30931+
30932+ gr_init_ebda();
30933+
30934+#ifdef CONFIG_PAX_KERNEXEC
30935+#ifdef CONFIG_X86_32
30936+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30937+ limit = (limit - 1UL) >> PAGE_SHIFT;
30938+
30939+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30940+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30941+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30942+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30943+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30944+ }
30945+
30946+ /* PaX: make KERNEL_CS read-only */
30947+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30948+ if (!paravirt_enabled())
30949+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30950+/*
30951+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30952+ pgd = pgd_offset_k(addr);
30953+ pud = pud_offset(pgd, addr);
30954+ pmd = pmd_offset(pud, addr);
30955+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30956+ }
30957+*/
30958+#ifdef CONFIG_X86_PAE
30959+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30960+/*
30961+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30962+ pgd = pgd_offset_k(addr);
30963+ pud = pud_offset(pgd, addr);
30964+ pmd = pmd_offset(pud, addr);
30965+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30966+ }
30967+*/
30968+#endif
30969+
30970+#ifdef CONFIG_MODULES
30971+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30972+#endif
30973+
30974+#else
30975+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30976+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30977+ pgd = pgd_offset_k(addr);
30978+ pud = pud_offset(pgd, addr);
30979+ pmd = pmd_offset(pud, addr);
30980+ if (!pmd_present(*pmd))
30981+ continue;
30982+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30983+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30984+ else
30985+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30986+ }
30987+
30988+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30989+ end = addr + KERNEL_IMAGE_SIZE;
30990+ for (; addr < end; addr += PMD_SIZE) {
30991+ pgd = pgd_offset_k(addr);
30992+ pud = pud_offset(pgd, addr);
30993+ pmd = pmd_offset(pud, addr);
30994+ if (!pmd_present(*pmd))
30995+ continue;
30996+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30997+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30998+ }
30999+#endif
31000+
31001+ flush_tlb_all();
31002+#endif
31003+
31004 free_init_pages("unused kernel",
31005 (unsigned long)(&__init_begin),
31006 (unsigned long)(&__init_end));
31007diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31008index 4287f1f..3b99c71 100644
31009--- a/arch/x86/mm/init_32.c
31010+++ b/arch/x86/mm/init_32.c
31011@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31012 bool __read_mostly __vmalloc_start_set = false;
31013
31014 /*
31015- * Creates a middle page table and puts a pointer to it in the
31016- * given global directory entry. This only returns the gd entry
31017- * in non-PAE compilation mode, since the middle layer is folded.
31018- */
31019-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31020-{
31021- pud_t *pud;
31022- pmd_t *pmd_table;
31023-
31024-#ifdef CONFIG_X86_PAE
31025- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31026- pmd_table = (pmd_t *)alloc_low_page();
31027- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31028- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31029- pud = pud_offset(pgd, 0);
31030- BUG_ON(pmd_table != pmd_offset(pud, 0));
31031-
31032- return pmd_table;
31033- }
31034-#endif
31035- pud = pud_offset(pgd, 0);
31036- pmd_table = pmd_offset(pud, 0);
31037-
31038- return pmd_table;
31039-}
31040-
31041-/*
31042 * Create a page table and place a pointer to it in a middle page
31043 * directory entry:
31044 */
31045@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31046 pte_t *page_table = (pte_t *)alloc_low_page();
31047
31048 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31049+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31050+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31051+#else
31052 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31053+#endif
31054 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31055 }
31056
31057 return pte_offset_kernel(pmd, 0);
31058 }
31059
31060+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31061+{
31062+ pud_t *pud;
31063+ pmd_t *pmd_table;
31064+
31065+ pud = pud_offset(pgd, 0);
31066+ pmd_table = pmd_offset(pud, 0);
31067+
31068+ return pmd_table;
31069+}
31070+
31071 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31072 {
31073 int pgd_idx = pgd_index(vaddr);
31074@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31075 int pgd_idx, pmd_idx;
31076 unsigned long vaddr;
31077 pgd_t *pgd;
31078+ pud_t *pud;
31079 pmd_t *pmd;
31080 pte_t *pte = NULL;
31081 unsigned long count = page_table_range_init_count(start, end);
31082@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31083 pgd = pgd_base + pgd_idx;
31084
31085 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31086- pmd = one_md_table_init(pgd);
31087- pmd = pmd + pmd_index(vaddr);
31088+ pud = pud_offset(pgd, vaddr);
31089+ pmd = pmd_offset(pud, vaddr);
31090+
31091+#ifdef CONFIG_X86_PAE
31092+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31093+#endif
31094+
31095 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31096 pmd++, pmd_idx++) {
31097 pte = page_table_kmap_check(one_page_table_init(pmd),
31098@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31099 }
31100 }
31101
31102-static inline int is_kernel_text(unsigned long addr)
31103+static inline int is_kernel_text(unsigned long start, unsigned long end)
31104 {
31105- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31106- return 1;
31107- return 0;
31108+ if ((start > ktla_ktva((unsigned long)_etext) ||
31109+ end <= ktla_ktva((unsigned long)_stext)) &&
31110+ (start > ktla_ktva((unsigned long)_einittext) ||
31111+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31112+
31113+#ifdef CONFIG_ACPI_SLEEP
31114+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31115+#endif
31116+
31117+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31118+ return 0;
31119+ return 1;
31120 }
31121
31122 /*
31123@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31124 unsigned long last_map_addr = end;
31125 unsigned long start_pfn, end_pfn;
31126 pgd_t *pgd_base = swapper_pg_dir;
31127- int pgd_idx, pmd_idx, pte_ofs;
31128+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31129 unsigned long pfn;
31130 pgd_t *pgd;
31131+ pud_t *pud;
31132 pmd_t *pmd;
31133 pte_t *pte;
31134 unsigned pages_2m, pages_4k;
31135@@ -291,8 +295,13 @@ repeat:
31136 pfn = start_pfn;
31137 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31138 pgd = pgd_base + pgd_idx;
31139- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31140- pmd = one_md_table_init(pgd);
31141+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31142+ pud = pud_offset(pgd, 0);
31143+ pmd = pmd_offset(pud, 0);
31144+
31145+#ifdef CONFIG_X86_PAE
31146+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31147+#endif
31148
31149 if (pfn >= end_pfn)
31150 continue;
31151@@ -304,14 +313,13 @@ repeat:
31152 #endif
31153 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31154 pmd++, pmd_idx++) {
31155- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31156+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31157
31158 /*
31159 * Map with big pages if possible, otherwise
31160 * create normal page tables:
31161 */
31162 if (use_pse) {
31163- unsigned int addr2;
31164 pgprot_t prot = PAGE_KERNEL_LARGE;
31165 /*
31166 * first pass will use the same initial
31167@@ -322,11 +330,7 @@ repeat:
31168 _PAGE_PSE);
31169
31170 pfn &= PMD_MASK >> PAGE_SHIFT;
31171- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31172- PAGE_OFFSET + PAGE_SIZE-1;
31173-
31174- if (is_kernel_text(addr) ||
31175- is_kernel_text(addr2))
31176+ if (is_kernel_text(address, address + PMD_SIZE))
31177 prot = PAGE_KERNEL_LARGE_EXEC;
31178
31179 pages_2m++;
31180@@ -343,7 +347,7 @@ repeat:
31181 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31182 pte += pte_ofs;
31183 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31184- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31185+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31186 pgprot_t prot = PAGE_KERNEL;
31187 /*
31188 * first pass will use the same initial
31189@@ -351,7 +355,7 @@ repeat:
31190 */
31191 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31192
31193- if (is_kernel_text(addr))
31194+ if (is_kernel_text(address, address + PAGE_SIZE))
31195 prot = PAGE_KERNEL_EXEC;
31196
31197 pages_4k++;
31198@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31199
31200 pud = pud_offset(pgd, va);
31201 pmd = pmd_offset(pud, va);
31202- if (!pmd_present(*pmd))
31203+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31204 break;
31205
31206 /* should not be large page here */
31207@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31208
31209 static void __init pagetable_init(void)
31210 {
31211- pgd_t *pgd_base = swapper_pg_dir;
31212-
31213- permanent_kmaps_init(pgd_base);
31214+ permanent_kmaps_init(swapper_pg_dir);
31215 }
31216
31217-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31218+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31219 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31220
31221 /* user-defined highmem size */
31222@@ -787,10 +789,10 @@ void __init mem_init(void)
31223 ((unsigned long)&__init_end -
31224 (unsigned long)&__init_begin) >> 10,
31225
31226- (unsigned long)&_etext, (unsigned long)&_edata,
31227- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31228+ (unsigned long)&_sdata, (unsigned long)&_edata,
31229+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31230
31231- (unsigned long)&_text, (unsigned long)&_etext,
31232+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31233 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31234
31235 /*
31236@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31237 if (!kernel_set_to_readonly)
31238 return;
31239
31240+ start = ktla_ktva(start);
31241 pr_debug("Set kernel text: %lx - %lx for read write\n",
31242 start, start+size);
31243
31244@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31245 if (!kernel_set_to_readonly)
31246 return;
31247
31248+ start = ktla_ktva(start);
31249 pr_debug("Set kernel text: %lx - %lx for read only\n",
31250 start, start+size);
31251
31252@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31253 unsigned long start = PFN_ALIGN(_text);
31254 unsigned long size = PFN_ALIGN(_etext) - start;
31255
31256+ start = ktla_ktva(start);
31257 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31258 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31259 size >> 10);
31260diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31261index 104d56a..62ba13f1 100644
31262--- a/arch/x86/mm/init_64.c
31263+++ b/arch/x86/mm/init_64.c
31264@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31265 * around without checking the pgd every time.
31266 */
31267
31268-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31269+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31270 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31271
31272 int force_personality32;
31273@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31274
31275 for (address = start; address <= end; address += PGDIR_SIZE) {
31276 const pgd_t *pgd_ref = pgd_offset_k(address);
31277+
31278+#ifdef CONFIG_PAX_PER_CPU_PGD
31279+ unsigned long cpu;
31280+#else
31281 struct page *page;
31282+#endif
31283
31284 if (pgd_none(*pgd_ref))
31285 continue;
31286
31287 spin_lock(&pgd_lock);
31288+
31289+#ifdef CONFIG_PAX_PER_CPU_PGD
31290+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31291+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31292+
31293+ if (pgd_none(*pgd))
31294+ set_pgd(pgd, *pgd_ref);
31295+ else
31296+ BUG_ON(pgd_page_vaddr(*pgd)
31297+ != pgd_page_vaddr(*pgd_ref));
31298+ pgd = pgd_offset_cpu(cpu, kernel, address);
31299+#else
31300 list_for_each_entry(page, &pgd_list, lru) {
31301 pgd_t *pgd;
31302 spinlock_t *pgt_lock;
31303@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31304 /* the pgt_lock only for Xen */
31305 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31306 spin_lock(pgt_lock);
31307+#endif
31308
31309 if (pgd_none(*pgd))
31310 set_pgd(pgd, *pgd_ref);
31311@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31312 BUG_ON(pgd_page_vaddr(*pgd)
31313 != pgd_page_vaddr(*pgd_ref));
31314
31315+#ifndef CONFIG_PAX_PER_CPU_PGD
31316 spin_unlock(pgt_lock);
31317+#endif
31318+
31319 }
31320 spin_unlock(&pgd_lock);
31321 }
31322@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31323 {
31324 if (pgd_none(*pgd)) {
31325 pud_t *pud = (pud_t *)spp_getpage();
31326- pgd_populate(&init_mm, pgd, pud);
31327+ pgd_populate_kernel(&init_mm, pgd, pud);
31328 if (pud != pud_offset(pgd, 0))
31329 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31330 pud, pud_offset(pgd, 0));
31331@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31332 {
31333 if (pud_none(*pud)) {
31334 pmd_t *pmd = (pmd_t *) spp_getpage();
31335- pud_populate(&init_mm, pud, pmd);
31336+ pud_populate_kernel(&init_mm, pud, pmd);
31337 if (pmd != pmd_offset(pud, 0))
31338 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31339 pmd, pmd_offset(pud, 0));
31340@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31341 pmd = fill_pmd(pud, vaddr);
31342 pte = fill_pte(pmd, vaddr);
31343
31344+ pax_open_kernel();
31345 set_pte(pte, new_pte);
31346+ pax_close_kernel();
31347
31348 /*
31349 * It's enough to flush this one mapping.
31350@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31351 pgd = pgd_offset_k((unsigned long)__va(phys));
31352 if (pgd_none(*pgd)) {
31353 pud = (pud_t *) spp_getpage();
31354- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31355- _PAGE_USER));
31356+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31357 }
31358 pud = pud_offset(pgd, (unsigned long)__va(phys));
31359 if (pud_none(*pud)) {
31360 pmd = (pmd_t *) spp_getpage();
31361- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31362- _PAGE_USER));
31363+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31364 }
31365 pmd = pmd_offset(pud, phys);
31366 BUG_ON(!pmd_none(*pmd));
31367@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31368 prot);
31369
31370 spin_lock(&init_mm.page_table_lock);
31371- pud_populate(&init_mm, pud, pmd);
31372+ pud_populate_kernel(&init_mm, pud, pmd);
31373 spin_unlock(&init_mm.page_table_lock);
31374 }
31375 __flush_tlb_all();
31376@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31377 page_size_mask);
31378
31379 spin_lock(&init_mm.page_table_lock);
31380- pgd_populate(&init_mm, pgd, pud);
31381+ pgd_populate_kernel(&init_mm, pgd, pud);
31382 spin_unlock(&init_mm.page_table_lock);
31383 pgd_changed = true;
31384 }
31385@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31386 static struct vm_area_struct gate_vma = {
31387 .vm_start = VSYSCALL_START,
31388 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31389- .vm_page_prot = PAGE_READONLY_EXEC,
31390- .vm_flags = VM_READ | VM_EXEC
31391+ .vm_page_prot = PAGE_READONLY,
31392+ .vm_flags = VM_READ
31393 };
31394
31395 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31396@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31397
31398 const char *arch_vma_name(struct vm_area_struct *vma)
31399 {
31400- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31401+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31402 return "[vdso]";
31403 if (vma == &gate_vma)
31404 return "[vsyscall]";
31405diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31406index 7b179b4..6bd17777 100644
31407--- a/arch/x86/mm/iomap_32.c
31408+++ b/arch/x86/mm/iomap_32.c
31409@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31410 type = kmap_atomic_idx_push();
31411 idx = type + KM_TYPE_NR * smp_processor_id();
31412 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31413+
31414+ pax_open_kernel();
31415 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31416+ pax_close_kernel();
31417+
31418 arch_flush_lazy_mmu_mode();
31419
31420 return (void *)vaddr;
31421diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31422index 799580c..72f9fe0 100644
31423--- a/arch/x86/mm/ioremap.c
31424+++ b/arch/x86/mm/ioremap.c
31425@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31426 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31427 int is_ram = page_is_ram(pfn);
31428
31429- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31430+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31431 return NULL;
31432 WARN_ON_ONCE(is_ram);
31433 }
31434@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31435 *
31436 * Caller must ensure there is only one unmapping for the same pointer.
31437 */
31438-void iounmap(volatile void __iomem *addr)
31439+void iounmap(const volatile void __iomem *addr)
31440 {
31441 struct vm_struct *p, *o;
31442
31443@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31444
31445 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31446 if (page_is_ram(start >> PAGE_SHIFT))
31447+#ifdef CONFIG_HIGHMEM
31448+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31449+#endif
31450 return __va(phys);
31451
31452 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31453@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31454 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31455 {
31456 if (page_is_ram(phys >> PAGE_SHIFT))
31457+#ifdef CONFIG_HIGHMEM
31458+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31459+#endif
31460 return;
31461
31462 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31463@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31464 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31465
31466 static __initdata int after_paging_init;
31467-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31468+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31469
31470 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31471 {
31472@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31473 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31474
31475 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31476- memset(bm_pte, 0, sizeof(bm_pte));
31477- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31478+ pmd_populate_user(&init_mm, pmd, bm_pte);
31479
31480 /*
31481 * The boot-ioremap range spans multiple pmds, for which
31482diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31483index d87dd6d..bf3fa66 100644
31484--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31485+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31486@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31487 * memory (e.g. tracked pages)? For now, we need this to avoid
31488 * invoking kmemcheck for PnP BIOS calls.
31489 */
31490- if (regs->flags & X86_VM_MASK)
31491+ if (v8086_mode(regs))
31492 return false;
31493- if (regs->cs != __KERNEL_CS)
31494+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31495 return false;
31496
31497 pte = kmemcheck_pte_lookup(address);
31498diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31499index 25e7e13..1964579 100644
31500--- a/arch/x86/mm/mmap.c
31501+++ b/arch/x86/mm/mmap.c
31502@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31503 * Leave an at least ~128 MB hole with possible stack randomization.
31504 */
31505 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31506-#define MAX_GAP (TASK_SIZE/6*5)
31507+#define MAX_GAP (pax_task_size/6*5)
31508
31509 static int mmap_is_legacy(void)
31510 {
31511@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31512 return rnd << PAGE_SHIFT;
31513 }
31514
31515-static unsigned long mmap_base(void)
31516+static unsigned long mmap_base(struct mm_struct *mm)
31517 {
31518 unsigned long gap = rlimit(RLIMIT_STACK);
31519+ unsigned long pax_task_size = TASK_SIZE;
31520+
31521+#ifdef CONFIG_PAX_SEGMEXEC
31522+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31523+ pax_task_size = SEGMEXEC_TASK_SIZE;
31524+#endif
31525
31526 if (gap < MIN_GAP)
31527 gap = MIN_GAP;
31528 else if (gap > MAX_GAP)
31529 gap = MAX_GAP;
31530
31531- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31532+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31533 }
31534
31535 /*
31536 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31537 * does, but not when emulating X86_32
31538 */
31539-static unsigned long mmap_legacy_base(void)
31540+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31541 {
31542- if (mmap_is_ia32())
31543+ if (mmap_is_ia32()) {
31544+
31545+#ifdef CONFIG_PAX_SEGMEXEC
31546+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31547+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31548+ else
31549+#endif
31550+
31551 return TASK_UNMAPPED_BASE;
31552- else
31553+ } else
31554 return TASK_UNMAPPED_BASE + mmap_rnd();
31555 }
31556
31557@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31558 */
31559 void arch_pick_mmap_layout(struct mm_struct *mm)
31560 {
31561- mm->mmap_legacy_base = mmap_legacy_base();
31562- mm->mmap_base = mmap_base();
31563+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31564+ mm->mmap_base = mmap_base(mm);
31565+
31566+#ifdef CONFIG_PAX_RANDMMAP
31567+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31568+ mm->mmap_legacy_base += mm->delta_mmap;
31569+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31570+ }
31571+#endif
31572
31573 if (mmap_is_legacy()) {
31574 mm->mmap_base = mm->mmap_legacy_base;
31575diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31576index 0057a7a..95c7edd 100644
31577--- a/arch/x86/mm/mmio-mod.c
31578+++ b/arch/x86/mm/mmio-mod.c
31579@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31580 break;
31581 default:
31582 {
31583- unsigned char *ip = (unsigned char *)instptr;
31584+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31585 my_trace->opcode = MMIO_UNKNOWN_OP;
31586 my_trace->width = 0;
31587 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31588@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31589 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31590 void __iomem *addr)
31591 {
31592- static atomic_t next_id;
31593+ static atomic_unchecked_t next_id;
31594 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31595 /* These are page-unaligned. */
31596 struct mmiotrace_map map = {
31597@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31598 .private = trace
31599 },
31600 .phys = offset,
31601- .id = atomic_inc_return(&next_id)
31602+ .id = atomic_inc_return_unchecked(&next_id)
31603 };
31604 map.map_id = trace->id;
31605
31606@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31607 ioremap_trace_core(offset, size, addr);
31608 }
31609
31610-static void iounmap_trace_core(volatile void __iomem *addr)
31611+static void iounmap_trace_core(const volatile void __iomem *addr)
31612 {
31613 struct mmiotrace_map map = {
31614 .phys = 0,
31615@@ -328,7 +328,7 @@ not_enabled:
31616 }
31617 }
31618
31619-void mmiotrace_iounmap(volatile void __iomem *addr)
31620+void mmiotrace_iounmap(const volatile void __iomem *addr)
31621 {
31622 might_sleep();
31623 if (is_enabled()) /* recheck and proper locking in *_core() */
31624diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31625index 8bf93ba..dbcd670 100644
31626--- a/arch/x86/mm/numa.c
31627+++ b/arch/x86/mm/numa.c
31628@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31629 return true;
31630 }
31631
31632-static int __init numa_register_memblks(struct numa_meminfo *mi)
31633+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31634 {
31635 unsigned long uninitialized_var(pfn_align);
31636 int i, nid;
31637diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31638index d0b1773..4c3327c 100644
31639--- a/arch/x86/mm/pageattr-test.c
31640+++ b/arch/x86/mm/pageattr-test.c
31641@@ -36,7 +36,7 @@ enum {
31642
31643 static int pte_testbit(pte_t pte)
31644 {
31645- return pte_flags(pte) & _PAGE_UNUSED1;
31646+ return pte_flags(pte) & _PAGE_CPA_TEST;
31647 }
31648
31649 struct split_state {
31650diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31651index bb32480..75f2f5e 100644
31652--- a/arch/x86/mm/pageattr.c
31653+++ b/arch/x86/mm/pageattr.c
31654@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31655 */
31656 #ifdef CONFIG_PCI_BIOS
31657 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31658- pgprot_val(forbidden) |= _PAGE_NX;
31659+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31660 #endif
31661
31662 /*
31663@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31664 * Does not cover __inittext since that is gone later on. On
31665 * 64bit we do not enforce !NX on the low mapping
31666 */
31667- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31668- pgprot_val(forbidden) |= _PAGE_NX;
31669+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31670+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31671
31672+#ifdef CONFIG_DEBUG_RODATA
31673 /*
31674 * The .rodata section needs to be read-only. Using the pfn
31675 * catches all aliases.
31676@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31677 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31678 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31679 pgprot_val(forbidden) |= _PAGE_RW;
31680+#endif
31681
31682 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31683 /*
31684@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31685 }
31686 #endif
31687
31688+#ifdef CONFIG_PAX_KERNEXEC
31689+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31690+ pgprot_val(forbidden) |= _PAGE_RW;
31691+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31692+ }
31693+#endif
31694+
31695 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31696
31697 return prot;
31698@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31699 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31700 {
31701 /* change init_mm */
31702+ pax_open_kernel();
31703 set_pte_atomic(kpte, pte);
31704+
31705 #ifdef CONFIG_X86_32
31706 if (!SHARED_KERNEL_PMD) {
31707+
31708+#ifdef CONFIG_PAX_PER_CPU_PGD
31709+ unsigned long cpu;
31710+#else
31711 struct page *page;
31712+#endif
31713
31714+#ifdef CONFIG_PAX_PER_CPU_PGD
31715+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31716+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31717+#else
31718 list_for_each_entry(page, &pgd_list, lru) {
31719- pgd_t *pgd;
31720+ pgd_t *pgd = (pgd_t *)page_address(page);
31721+#endif
31722+
31723 pud_t *pud;
31724 pmd_t *pmd;
31725
31726- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31727+ pgd += pgd_index(address);
31728 pud = pud_offset(pgd, address);
31729 pmd = pmd_offset(pud, address);
31730 set_pte_atomic((pte_t *)pmd, pte);
31731 }
31732 }
31733 #endif
31734+ pax_close_kernel();
31735 }
31736
31737 static int
31738diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31739index 6574388..87e9bef 100644
31740--- a/arch/x86/mm/pat.c
31741+++ b/arch/x86/mm/pat.c
31742@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31743
31744 if (!entry) {
31745 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31746- current->comm, current->pid, start, end - 1);
31747+ current->comm, task_pid_nr(current), start, end - 1);
31748 return -EINVAL;
31749 }
31750
31751@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31752
31753 while (cursor < to) {
31754 if (!devmem_is_allowed(pfn)) {
31755- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31756- current->comm, from, to - 1);
31757+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31758+ current->comm, from, to - 1, cursor);
31759 return 0;
31760 }
31761 cursor += PAGE_SIZE;
31762@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31763 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31764 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31765 "for [mem %#010Lx-%#010Lx]\n",
31766- current->comm, current->pid,
31767+ current->comm, task_pid_nr(current),
31768 cattr_name(flags),
31769 base, (unsigned long long)(base + size-1));
31770 return -EINVAL;
31771@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31772 flags = lookup_memtype(paddr);
31773 if (want_flags != flags) {
31774 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31775- current->comm, current->pid,
31776+ current->comm, task_pid_nr(current),
31777 cattr_name(want_flags),
31778 (unsigned long long)paddr,
31779 (unsigned long long)(paddr + size - 1),
31780@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31781 free_memtype(paddr, paddr + size);
31782 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31783 " for [mem %#010Lx-%#010Lx], got %s\n",
31784- current->comm, current->pid,
31785+ current->comm, task_pid_nr(current),
31786 cattr_name(want_flags),
31787 (unsigned long long)paddr,
31788 (unsigned long long)(paddr + size - 1),
31789diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31790index 415f6c4..d319983 100644
31791--- a/arch/x86/mm/pat_rbtree.c
31792+++ b/arch/x86/mm/pat_rbtree.c
31793@@ -160,7 +160,7 @@ success:
31794
31795 failure:
31796 printk(KERN_INFO "%s:%d conflicting memory types "
31797- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31798+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31799 end, cattr_name(found_type), cattr_name(match->type));
31800 return -EBUSY;
31801 }
31802diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31803index 9f0614d..92ae64a 100644
31804--- a/arch/x86/mm/pf_in.c
31805+++ b/arch/x86/mm/pf_in.c
31806@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31807 int i;
31808 enum reason_type rv = OTHERS;
31809
31810- p = (unsigned char *)ins_addr;
31811+ p = (unsigned char *)ktla_ktva(ins_addr);
31812 p += skip_prefix(p, &prf);
31813 p += get_opcode(p, &opcode);
31814
31815@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31816 struct prefix_bits prf;
31817 int i;
31818
31819- p = (unsigned char *)ins_addr;
31820+ p = (unsigned char *)ktla_ktva(ins_addr);
31821 p += skip_prefix(p, &prf);
31822 p += get_opcode(p, &opcode);
31823
31824@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31825 struct prefix_bits prf;
31826 int i;
31827
31828- p = (unsigned char *)ins_addr;
31829+ p = (unsigned char *)ktla_ktva(ins_addr);
31830 p += skip_prefix(p, &prf);
31831 p += get_opcode(p, &opcode);
31832
31833@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31834 struct prefix_bits prf;
31835 int i;
31836
31837- p = (unsigned char *)ins_addr;
31838+ p = (unsigned char *)ktla_ktva(ins_addr);
31839 p += skip_prefix(p, &prf);
31840 p += get_opcode(p, &opcode);
31841 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31842@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31843 struct prefix_bits prf;
31844 int i;
31845
31846- p = (unsigned char *)ins_addr;
31847+ p = (unsigned char *)ktla_ktva(ins_addr);
31848 p += skip_prefix(p, &prf);
31849 p += get_opcode(p, &opcode);
31850 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31851diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31852index dfa537a..fd45c64 100644
31853--- a/arch/x86/mm/pgtable.c
31854+++ b/arch/x86/mm/pgtable.c
31855@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31856 list_del(&page->lru);
31857 }
31858
31859-#define UNSHARED_PTRS_PER_PGD \
31860- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31861+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31862+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31863
31864+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31865+{
31866+ unsigned int count = USER_PGD_PTRS;
31867
31868+ if (!pax_user_shadow_base)
31869+ return;
31870+
31871+ while (count--)
31872+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31873+}
31874+#endif
31875+
31876+#ifdef CONFIG_PAX_PER_CPU_PGD
31877+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31878+{
31879+ unsigned int count = USER_PGD_PTRS;
31880+
31881+ while (count--) {
31882+ pgd_t pgd;
31883+
31884+#ifdef CONFIG_X86_64
31885+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31886+#else
31887+ pgd = *src++;
31888+#endif
31889+
31890+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31891+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31892+#endif
31893+
31894+ *dst++ = pgd;
31895+ }
31896+
31897+}
31898+#endif
31899+
31900+#ifdef CONFIG_X86_64
31901+#define pxd_t pud_t
31902+#define pyd_t pgd_t
31903+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31904+#define pxd_free(mm, pud) pud_free((mm), (pud))
31905+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31906+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31907+#define PYD_SIZE PGDIR_SIZE
31908+#else
31909+#define pxd_t pmd_t
31910+#define pyd_t pud_t
31911+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31912+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31913+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31914+#define pyd_offset(mm, address) pud_offset((mm), (address))
31915+#define PYD_SIZE PUD_SIZE
31916+#endif
31917+
31918+#ifdef CONFIG_PAX_PER_CPU_PGD
31919+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31920+static inline void pgd_dtor(pgd_t *pgd) {}
31921+#else
31922 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31923 {
31924 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31925@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31926 pgd_list_del(pgd);
31927 spin_unlock(&pgd_lock);
31928 }
31929+#endif
31930
31931 /*
31932 * List of all pgd's needed for non-PAE so it can invalidate entries
31933@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31934 * -- nyc
31935 */
31936
31937-#ifdef CONFIG_X86_PAE
31938+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31939 /*
31940 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31941 * updating the top-level pagetable entries to guarantee the
31942@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31943 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31944 * and initialize the kernel pmds here.
31945 */
31946-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31947+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31948
31949 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31950 {
31951@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31952 */
31953 flush_tlb_mm(mm);
31954 }
31955+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31956+#define PREALLOCATED_PXDS USER_PGD_PTRS
31957 #else /* !CONFIG_X86_PAE */
31958
31959 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31960-#define PREALLOCATED_PMDS 0
31961+#define PREALLOCATED_PXDS 0
31962
31963 #endif /* CONFIG_X86_PAE */
31964
31965-static void free_pmds(pmd_t *pmds[])
31966+static void free_pxds(pxd_t *pxds[])
31967 {
31968 int i;
31969
31970- for(i = 0; i < PREALLOCATED_PMDS; i++)
31971- if (pmds[i])
31972- free_page((unsigned long)pmds[i]);
31973+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31974+ if (pxds[i])
31975+ free_page((unsigned long)pxds[i]);
31976 }
31977
31978-static int preallocate_pmds(pmd_t *pmds[])
31979+static int preallocate_pxds(pxd_t *pxds[])
31980 {
31981 int i;
31982 bool failed = false;
31983
31984- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31985- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31986- if (pmd == NULL)
31987+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31988+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31989+ if (pxd == NULL)
31990 failed = true;
31991- pmds[i] = pmd;
31992+ pxds[i] = pxd;
31993 }
31994
31995 if (failed) {
31996- free_pmds(pmds);
31997+ free_pxds(pxds);
31998 return -ENOMEM;
31999 }
32000
32001@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32002 * preallocate which never got a corresponding vma will need to be
32003 * freed manually.
32004 */
32005-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32006+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32007 {
32008 int i;
32009
32010- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32011+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32012 pgd_t pgd = pgdp[i];
32013
32014 if (pgd_val(pgd) != 0) {
32015- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32016+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32017
32018- pgdp[i] = native_make_pgd(0);
32019+ set_pgd(pgdp + i, native_make_pgd(0));
32020
32021- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32022- pmd_free(mm, pmd);
32023+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32024+ pxd_free(mm, pxd);
32025 }
32026 }
32027 }
32028
32029-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32030+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32031 {
32032- pud_t *pud;
32033+ pyd_t *pyd;
32034 int i;
32035
32036- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32037+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32038 return;
32039
32040- pud = pud_offset(pgd, 0);
32041-
32042- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32043- pmd_t *pmd = pmds[i];
32044+#ifdef CONFIG_X86_64
32045+ pyd = pyd_offset(mm, 0L);
32046+#else
32047+ pyd = pyd_offset(pgd, 0L);
32048+#endif
32049
32050+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32051+ pxd_t *pxd = pxds[i];
32052 if (i >= KERNEL_PGD_BOUNDARY)
32053- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32054- sizeof(pmd_t) * PTRS_PER_PMD);
32055+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32056+ sizeof(pxd_t) * PTRS_PER_PMD);
32057
32058- pud_populate(mm, pud, pmd);
32059+ pyd_populate(mm, pyd, pxd);
32060 }
32061 }
32062
32063 pgd_t *pgd_alloc(struct mm_struct *mm)
32064 {
32065 pgd_t *pgd;
32066- pmd_t *pmds[PREALLOCATED_PMDS];
32067+ pxd_t *pxds[PREALLOCATED_PXDS];
32068
32069 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32070
32071@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32072
32073 mm->pgd = pgd;
32074
32075- if (preallocate_pmds(pmds) != 0)
32076+ if (preallocate_pxds(pxds) != 0)
32077 goto out_free_pgd;
32078
32079 if (paravirt_pgd_alloc(mm) != 0)
32080- goto out_free_pmds;
32081+ goto out_free_pxds;
32082
32083 /*
32084 * Make sure that pre-populating the pmds is atomic with
32085@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32086 spin_lock(&pgd_lock);
32087
32088 pgd_ctor(mm, pgd);
32089- pgd_prepopulate_pmd(mm, pgd, pmds);
32090+ pgd_prepopulate_pxd(mm, pgd, pxds);
32091
32092 spin_unlock(&pgd_lock);
32093
32094 return pgd;
32095
32096-out_free_pmds:
32097- free_pmds(pmds);
32098+out_free_pxds:
32099+ free_pxds(pxds);
32100 out_free_pgd:
32101 free_page((unsigned long)pgd);
32102 out:
32103@@ -300,7 +363,7 @@ out:
32104
32105 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32106 {
32107- pgd_mop_up_pmds(mm, pgd);
32108+ pgd_mop_up_pxds(mm, pgd);
32109 pgd_dtor(pgd);
32110 paravirt_pgd_free(mm, pgd);
32111 free_page((unsigned long)pgd);
32112diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32113index a69bcb8..19068ab 100644
32114--- a/arch/x86/mm/pgtable_32.c
32115+++ b/arch/x86/mm/pgtable_32.c
32116@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32117 return;
32118 }
32119 pte = pte_offset_kernel(pmd, vaddr);
32120+
32121+ pax_open_kernel();
32122 if (pte_val(pteval))
32123 set_pte_at(&init_mm, vaddr, pte, pteval);
32124 else
32125 pte_clear(&init_mm, vaddr, pte);
32126+ pax_close_kernel();
32127
32128 /*
32129 * It's enough to flush this one mapping.
32130diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32131index e666cbb..61788c45 100644
32132--- a/arch/x86/mm/physaddr.c
32133+++ b/arch/x86/mm/physaddr.c
32134@@ -10,7 +10,7 @@
32135 #ifdef CONFIG_X86_64
32136
32137 #ifdef CONFIG_DEBUG_VIRTUAL
32138-unsigned long __phys_addr(unsigned long x)
32139+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32140 {
32141 unsigned long y = x - __START_KERNEL_map;
32142
32143@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32144 #else
32145
32146 #ifdef CONFIG_DEBUG_VIRTUAL
32147-unsigned long __phys_addr(unsigned long x)
32148+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32149 {
32150 unsigned long phys_addr = x - PAGE_OFFSET;
32151 /* VMALLOC_* aren't constants */
32152diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32153index 90555bf..f5f1828 100644
32154--- a/arch/x86/mm/setup_nx.c
32155+++ b/arch/x86/mm/setup_nx.c
32156@@ -5,8 +5,10 @@
32157 #include <asm/pgtable.h>
32158 #include <asm/proto.h>
32159
32160+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32161 static int disable_nx;
32162
32163+#ifndef CONFIG_PAX_PAGEEXEC
32164 /*
32165 * noexec = on|off
32166 *
32167@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32168 return 0;
32169 }
32170 early_param("noexec", noexec_setup);
32171+#endif
32172+
32173+#endif
32174
32175 void x86_configure_nx(void)
32176 {
32177+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32178 if (cpu_has_nx && !disable_nx)
32179 __supported_pte_mask |= _PAGE_NX;
32180 else
32181+#endif
32182 __supported_pte_mask &= ~_PAGE_NX;
32183 }
32184
32185diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32186index ae699b3..f1b2ad2 100644
32187--- a/arch/x86/mm/tlb.c
32188+++ b/arch/x86/mm/tlb.c
32189@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32190 BUG();
32191 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32192 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32193+
32194+#ifndef CONFIG_PAX_PER_CPU_PGD
32195 load_cr3(swapper_pg_dir);
32196+#endif
32197+
32198 }
32199 }
32200 EXPORT_SYMBOL_GPL(leave_mm);
32201diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32202new file mode 100644
32203index 0000000..dace51c
32204--- /dev/null
32205+++ b/arch/x86/mm/uderef_64.c
32206@@ -0,0 +1,37 @@
32207+#include <linux/mm.h>
32208+#include <asm/pgtable.h>
32209+#include <asm/uaccess.h>
32210+
32211+#ifdef CONFIG_PAX_MEMORY_UDEREF
32212+/* PaX: due to the special call convention these functions must
32213+ * - remain leaf functions under all configurations,
32214+ * - never be called directly, only dereferenced from the wrappers.
32215+ */
32216+void __pax_open_userland(void)
32217+{
32218+ unsigned int cpu;
32219+
32220+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32221+ return;
32222+
32223+ cpu = raw_get_cpu();
32224+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32225+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32226+ raw_put_cpu_no_resched();
32227+}
32228+EXPORT_SYMBOL(__pax_open_userland);
32229+
32230+void __pax_close_userland(void)
32231+{
32232+ unsigned int cpu;
32233+
32234+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32235+ return;
32236+
32237+ cpu = raw_get_cpu();
32238+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32239+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32240+ raw_put_cpu_no_resched();
32241+}
32242+EXPORT_SYMBOL(__pax_close_userland);
32243+#endif
32244diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32245index 877b9a1..a8ecf42 100644
32246--- a/arch/x86/net/bpf_jit.S
32247+++ b/arch/x86/net/bpf_jit.S
32248@@ -9,6 +9,7 @@
32249 */
32250 #include <linux/linkage.h>
32251 #include <asm/dwarf2.h>
32252+#include <asm/alternative-asm.h>
32253
32254 /*
32255 * Calling convention :
32256@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32257 jle bpf_slow_path_word
32258 mov (SKBDATA,%rsi),%eax
32259 bswap %eax /* ntohl() */
32260+ pax_force_retaddr
32261 ret
32262
32263 sk_load_half:
32264@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32265 jle bpf_slow_path_half
32266 movzwl (SKBDATA,%rsi),%eax
32267 rol $8,%ax # ntohs()
32268+ pax_force_retaddr
32269 ret
32270
32271 sk_load_byte:
32272@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32273 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32274 jle bpf_slow_path_byte
32275 movzbl (SKBDATA,%rsi),%eax
32276+ pax_force_retaddr
32277 ret
32278
32279 /**
32280@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32281 movzbl (SKBDATA,%rsi),%ebx
32282 and $15,%bl
32283 shl $2,%bl
32284+ pax_force_retaddr
32285 ret
32286
32287 /* rsi contains offset and can be scratched */
32288@@ -109,6 +114,7 @@ bpf_slow_path_word:
32289 js bpf_error
32290 mov -12(%rbp),%eax
32291 bswap %eax
32292+ pax_force_retaddr
32293 ret
32294
32295 bpf_slow_path_half:
32296@@ -117,12 +123,14 @@ bpf_slow_path_half:
32297 mov -12(%rbp),%ax
32298 rol $8,%ax
32299 movzwl %ax,%eax
32300+ pax_force_retaddr
32301 ret
32302
32303 bpf_slow_path_byte:
32304 bpf_slow_path_common(1)
32305 js bpf_error
32306 movzbl -12(%rbp),%eax
32307+ pax_force_retaddr
32308 ret
32309
32310 bpf_slow_path_byte_msh:
32311@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32312 and $15,%al
32313 shl $2,%al
32314 xchg %eax,%ebx
32315+ pax_force_retaddr
32316 ret
32317
32318 #define sk_negative_common(SIZE) \
32319@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32320 sk_negative_common(4)
32321 mov (%rax), %eax
32322 bswap %eax
32323+ pax_force_retaddr
32324 ret
32325
32326 bpf_slow_path_half_neg:
32327@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32328 mov (%rax),%ax
32329 rol $8,%ax
32330 movzwl %ax,%eax
32331+ pax_force_retaddr
32332 ret
32333
32334 bpf_slow_path_byte_neg:
32335@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32336 .globl sk_load_byte_negative_offset
32337 sk_negative_common(1)
32338 movzbl (%rax), %eax
32339+ pax_force_retaddr
32340 ret
32341
32342 bpf_slow_path_byte_msh_neg:
32343@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32344 and $15,%al
32345 shl $2,%al
32346 xchg %eax,%ebx
32347+ pax_force_retaddr
32348 ret
32349
32350 bpf_error:
32351@@ -197,4 +210,5 @@ bpf_error:
32352 xor %eax,%eax
32353 mov -8(%rbp),%rbx
32354 leaveq
32355+ pax_force_retaddr
32356 ret
32357diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32358index 516593e..29d3c55 100644
32359--- a/arch/x86/net/bpf_jit_comp.c
32360+++ b/arch/x86/net/bpf_jit_comp.c
32361@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32362 return ptr + len;
32363 }
32364
32365+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32366+#define MAX_INSTR_CODE_SIZE 96
32367+#else
32368+#define MAX_INSTR_CODE_SIZE 64
32369+#endif
32370+
32371 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32372
32373 #define EMIT1(b1) EMIT(b1, 1)
32374 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32375 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32376 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32377+
32378+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32379+/* original constant will appear in ecx */
32380+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32381+do { \
32382+ /* mov ecx, randkey */ \
32383+ EMIT1(0xb9); \
32384+ EMIT(_key, 4); \
32385+ /* xor ecx, randkey ^ off */ \
32386+ EMIT2(0x81, 0xf1); \
32387+ EMIT((_key) ^ (_off), 4); \
32388+} while (0)
32389+
32390+#define EMIT1_off32(b1, _off) \
32391+do { \
32392+ switch (b1) { \
32393+ case 0x05: /* add eax, imm32 */ \
32394+ case 0x2d: /* sub eax, imm32 */ \
32395+ case 0x25: /* and eax, imm32 */ \
32396+ case 0x0d: /* or eax, imm32 */ \
32397+ case 0xb8: /* mov eax, imm32 */ \
32398+ case 0x35: /* xor eax, imm32 */ \
32399+ case 0x3d: /* cmp eax, imm32 */ \
32400+ case 0xa9: /* test eax, imm32 */ \
32401+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32402+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32403+ break; \
32404+ case 0xbb: /* mov ebx, imm32 */ \
32405+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32406+ /* mov ebx, ecx */ \
32407+ EMIT2(0x89, 0xcb); \
32408+ break; \
32409+ case 0xbe: /* mov esi, imm32 */ \
32410+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32411+ /* mov esi, ecx */ \
32412+ EMIT2(0x89, 0xce); \
32413+ break; \
32414+ case 0xe8: /* call rel imm32, always to known funcs */ \
32415+ EMIT1(b1); \
32416+ EMIT(_off, 4); \
32417+ break; \
32418+ case 0xe9: /* jmp rel imm32 */ \
32419+ EMIT1(b1); \
32420+ EMIT(_off, 4); \
32421+ /* prevent fall-through, we're not called if off = 0 */ \
32422+ EMIT(0xcccccccc, 4); \
32423+ EMIT(0xcccccccc, 4); \
32424+ break; \
32425+ default: \
32426+ BUILD_BUG(); \
32427+ } \
32428+} while (0)
32429+
32430+#define EMIT2_off32(b1, b2, _off) \
32431+do { \
32432+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32433+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32434+ EMIT(randkey, 4); \
32435+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32436+ EMIT((_off) - randkey, 4); \
32437+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32438+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32439+ /* imul eax, ecx */ \
32440+ EMIT3(0x0f, 0xaf, 0xc1); \
32441+ } else { \
32442+ BUILD_BUG(); \
32443+ } \
32444+} while (0)
32445+#else
32446 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32447+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32448+#endif
32449
32450 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32451 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32452@@ -91,6 +168,24 @@ do { \
32453 #define X86_JBE 0x76
32454 #define X86_JA 0x77
32455
32456+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32457+#define APPEND_FLOW_VERIFY() \
32458+do { \
32459+ /* mov ecx, randkey */ \
32460+ EMIT1(0xb9); \
32461+ EMIT(randkey, 4); \
32462+ /* cmp ecx, randkey */ \
32463+ EMIT2(0x81, 0xf9); \
32464+ EMIT(randkey, 4); \
32465+ /* jz after 8 int 3s */ \
32466+ EMIT2(0x74, 0x08); \
32467+ EMIT(0xcccccccc, 4); \
32468+ EMIT(0xcccccccc, 4); \
32469+} while (0)
32470+#else
32471+#define APPEND_FLOW_VERIFY() do { } while (0)
32472+#endif
32473+
32474 #define EMIT_COND_JMP(op, offset) \
32475 do { \
32476 if (is_near(offset)) \
32477@@ -98,6 +193,7 @@ do { \
32478 else { \
32479 EMIT2(0x0f, op + 0x10); \
32480 EMIT(offset, 4); /* jxx .+off32 */ \
32481+ APPEND_FLOW_VERIFY(); \
32482 } \
32483 } while (0)
32484
32485@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32486 return -1;
32487 }
32488
32489-struct bpf_binary_header {
32490- unsigned int pages;
32491- /* Note : for security reasons, bpf code will follow a randomly
32492- * sized amount of int3 instructions
32493- */
32494- u8 image[];
32495-};
32496-
32497-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32498+/* Note : for security reasons, bpf code will follow a randomly
32499+ * sized amount of int3 instructions
32500+ */
32501+static u8 *bpf_alloc_binary(unsigned int proglen,
32502 u8 **image_ptr)
32503 {
32504 unsigned int sz, hole;
32505- struct bpf_binary_header *header;
32506+ u8 *header;
32507
32508 /* Most of BPF filters are really small,
32509 * but if some of them fill a page, allow at least
32510 * 128 extra bytes to insert a random section of int3
32511 */
32512- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32513- header = module_alloc(sz);
32514+ sz = round_up(proglen + 128, PAGE_SIZE);
32515+ header = module_alloc_exec(sz);
32516 if (!header)
32517 return NULL;
32518
32519+ pax_open_kernel();
32520 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32521+ pax_close_kernel();
32522
32523- header->pages = sz / PAGE_SIZE;
32524- hole = sz - (proglen + sizeof(*header));
32525+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32526
32527 /* insert a random number of int3 instructions before BPF code */
32528- *image_ptr = &header->image[prandom_u32() % hole];
32529+ *image_ptr = &header[prandom_u32() % hole];
32530 return header;
32531 }
32532
32533 void bpf_jit_compile(struct sk_filter *fp)
32534 {
32535- u8 temp[64];
32536+ u8 temp[MAX_INSTR_CODE_SIZE];
32537 u8 *prog;
32538 unsigned int proglen, oldproglen = 0;
32539 int ilen, i;
32540 int t_offset, f_offset;
32541 u8 t_op, f_op, seen = 0, pass;
32542 u8 *image = NULL;
32543- struct bpf_binary_header *header = NULL;
32544+ u8 *header = NULL;
32545 u8 *func;
32546 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32547 unsigned int cleanup_addr; /* epilogue code offset */
32548 unsigned int *addrs;
32549 const struct sock_filter *filter = fp->insns;
32550 int flen = fp->len;
32551+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32552+ unsigned int randkey;
32553+#endif
32554
32555 if (!bpf_jit_enable)
32556 return;
32557@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32558 if (addrs == NULL)
32559 return;
32560
32561+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32562+ randkey = get_random_int();
32563+#endif
32564+
32565 /* Before first pass, make a rough estimation of addrs[]
32566- * each bpf instruction is translated to less than 64 bytes
32567+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32568 */
32569 for (proglen = 0, i = 0; i < flen; i++) {
32570- proglen += 64;
32571+ proglen += MAX_INSTR_CODE_SIZE;
32572 addrs[i] = proglen;
32573 }
32574 cleanup_addr = proglen; /* epilogue address */
32575@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32576 case BPF_S_ALU_MUL_K: /* A *= K */
32577 if (is_imm8(K))
32578 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32579- else {
32580- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32581- EMIT(K, 4);
32582- }
32583+ else
32584+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32585 break;
32586 case BPF_S_ALU_DIV_X: /* A /= X; */
32587 seen |= SEEN_XREG;
32588@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32589 break;
32590 case BPF_S_ALU_MOD_K: /* A %= K; */
32591 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32592+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32593+ DILUTE_CONST_SEQUENCE(K, randkey);
32594+#else
32595 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32596+#endif
32597 EMIT2(0xf7, 0xf1); /* div %ecx */
32598 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32599 break;
32600 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32601+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32602+ DILUTE_CONST_SEQUENCE(K, randkey);
32603+ // imul rax, rcx
32604+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32605+#else
32606 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32607 EMIT(K, 4);
32608+#endif
32609 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32610 break;
32611 case BPF_S_ALU_AND_X:
32612@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32613 if (is_imm8(K)) {
32614 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32615 } else {
32616- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32617- EMIT(K, 4);
32618+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32619 }
32620 } else {
32621 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32622@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32623 if (unlikely(proglen + ilen > oldproglen)) {
32624 pr_err("bpb_jit_compile fatal error\n");
32625 kfree(addrs);
32626- module_free(NULL, header);
32627+ module_free_exec(NULL, image);
32628 return;
32629 }
32630+ pax_open_kernel();
32631 memcpy(image + proglen, temp, ilen);
32632+ pax_close_kernel();
32633 }
32634 proglen += ilen;
32635 addrs[i] = proglen;
32636@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32637
32638 if (image) {
32639 bpf_flush_icache(header, image + proglen);
32640- set_memory_ro((unsigned long)header, header->pages);
32641 fp->bpf_func = (void *)image;
32642 }
32643 out:
32644@@ -776,10 +883,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
32645 {
32646 struct sk_filter *fp = container_of(work, struct sk_filter, work);
32647 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32648- struct bpf_binary_header *header = (void *)addr;
32649
32650- set_memory_rw(addr, header->pages);
32651- module_free(NULL, header);
32652+ set_memory_rw(addr, 1);
32653+ module_free_exec(NULL, (void *)addr);
32654 kfree(fp);
32655 }
32656
32657diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32658index d6aa6e8..266395a 100644
32659--- a/arch/x86/oprofile/backtrace.c
32660+++ b/arch/x86/oprofile/backtrace.c
32661@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32662 struct stack_frame_ia32 *fp;
32663 unsigned long bytes;
32664
32665- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32666+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32667 if (bytes != sizeof(bufhead))
32668 return NULL;
32669
32670- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32671+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32672
32673 oprofile_add_trace(bufhead[0].return_address);
32674
32675@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32676 struct stack_frame bufhead[2];
32677 unsigned long bytes;
32678
32679- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32680+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32681 if (bytes != sizeof(bufhead))
32682 return NULL;
32683
32684@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32685 {
32686 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32687
32688- if (!user_mode_vm(regs)) {
32689+ if (!user_mode(regs)) {
32690 unsigned long stack = kernel_stack_pointer(regs);
32691 if (depth)
32692 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32693diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32694index 6890d84..1dad1f1 100644
32695--- a/arch/x86/oprofile/nmi_int.c
32696+++ b/arch/x86/oprofile/nmi_int.c
32697@@ -23,6 +23,7 @@
32698 #include <asm/nmi.h>
32699 #include <asm/msr.h>
32700 #include <asm/apic.h>
32701+#include <asm/pgtable.h>
32702
32703 #include "op_counter.h"
32704 #include "op_x86_model.h"
32705@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32706 if (ret)
32707 return ret;
32708
32709- if (!model->num_virt_counters)
32710- model->num_virt_counters = model->num_counters;
32711+ if (!model->num_virt_counters) {
32712+ pax_open_kernel();
32713+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32714+ pax_close_kernel();
32715+ }
32716
32717 mux_init(ops);
32718
32719diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32720index 50d86c0..7985318 100644
32721--- a/arch/x86/oprofile/op_model_amd.c
32722+++ b/arch/x86/oprofile/op_model_amd.c
32723@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32724 num_counters = AMD64_NUM_COUNTERS;
32725 }
32726
32727- op_amd_spec.num_counters = num_counters;
32728- op_amd_spec.num_controls = num_counters;
32729- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32730+ pax_open_kernel();
32731+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32732+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32733+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32734+ pax_close_kernel();
32735
32736 return 0;
32737 }
32738diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32739index d90528e..0127e2b 100644
32740--- a/arch/x86/oprofile/op_model_ppro.c
32741+++ b/arch/x86/oprofile/op_model_ppro.c
32742@@ -19,6 +19,7 @@
32743 #include <asm/msr.h>
32744 #include <asm/apic.h>
32745 #include <asm/nmi.h>
32746+#include <asm/pgtable.h>
32747
32748 #include "op_x86_model.h"
32749 #include "op_counter.h"
32750@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32751
32752 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32753
32754- op_arch_perfmon_spec.num_counters = num_counters;
32755- op_arch_perfmon_spec.num_controls = num_counters;
32756+ pax_open_kernel();
32757+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32758+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32759+ pax_close_kernel();
32760 }
32761
32762 static int arch_perfmon_init(struct oprofile_operations *ignore)
32763diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32764index 71e8a67..6a313bb 100644
32765--- a/arch/x86/oprofile/op_x86_model.h
32766+++ b/arch/x86/oprofile/op_x86_model.h
32767@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32768 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32769 struct op_msrs const * const msrs);
32770 #endif
32771-};
32772+} __do_const;
32773
32774 struct op_counter_config;
32775
32776diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32777index 372e9b8..e775a6c 100644
32778--- a/arch/x86/pci/irq.c
32779+++ b/arch/x86/pci/irq.c
32780@@ -50,7 +50,7 @@ struct irq_router {
32781 struct irq_router_handler {
32782 u16 vendor;
32783 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32784-};
32785+} __do_const;
32786
32787 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32788 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32789@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32790 return 0;
32791 }
32792
32793-static __initdata struct irq_router_handler pirq_routers[] = {
32794+static __initconst const struct irq_router_handler pirq_routers[] = {
32795 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32796 { PCI_VENDOR_ID_AL, ali_router_probe },
32797 { PCI_VENDOR_ID_ITE, ite_router_probe },
32798@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32799 static void __init pirq_find_router(struct irq_router *r)
32800 {
32801 struct irq_routing_table *rt = pirq_table;
32802- struct irq_router_handler *h;
32803+ const struct irq_router_handler *h;
32804
32805 #ifdef CONFIG_PCI_BIOS
32806 if (!rt->signature) {
32807@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32808 return 0;
32809 }
32810
32811-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32812+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32813 {
32814 .callback = fix_broken_hp_bios_irq9,
32815 .ident = "HP Pavilion N5400 Series Laptop",
32816diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32817index 903fded..94b0d88 100644
32818--- a/arch/x86/pci/mrst.c
32819+++ b/arch/x86/pci/mrst.c
32820@@ -241,7 +241,9 @@ int __init pci_mrst_init(void)
32821 pr_info("Intel MID platform detected, using MID PCI ops\n");
32822 pci_mmcfg_late_init();
32823 pcibios_enable_irq = mrst_pci_irq_enable;
32824- pci_root_ops = pci_mrst_ops;
32825+ pax_open_kernel();
32826+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32827+ pax_close_kernel();
32828 pci_soc_mode = 1;
32829 /* Continue with standard init */
32830 return 1;
32831diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32832index c77b24a..c979855 100644
32833--- a/arch/x86/pci/pcbios.c
32834+++ b/arch/x86/pci/pcbios.c
32835@@ -79,7 +79,7 @@ union bios32 {
32836 static struct {
32837 unsigned long address;
32838 unsigned short segment;
32839-} bios32_indirect = { 0, __KERNEL_CS };
32840+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32841
32842 /*
32843 * Returns the entry point for the given service, NULL on error
32844@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32845 unsigned long length; /* %ecx */
32846 unsigned long entry; /* %edx */
32847 unsigned long flags;
32848+ struct desc_struct d, *gdt;
32849
32850 local_irq_save(flags);
32851- __asm__("lcall *(%%edi); cld"
32852+
32853+ gdt = get_cpu_gdt_table(smp_processor_id());
32854+
32855+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32856+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32857+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32858+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32859+
32860+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32861 : "=a" (return_code),
32862 "=b" (address),
32863 "=c" (length),
32864 "=d" (entry)
32865 : "0" (service),
32866 "1" (0),
32867- "D" (&bios32_indirect));
32868+ "D" (&bios32_indirect),
32869+ "r"(__PCIBIOS_DS)
32870+ : "memory");
32871+
32872+ pax_open_kernel();
32873+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32874+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32875+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32876+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32877+ pax_close_kernel();
32878+
32879 local_irq_restore(flags);
32880
32881 switch (return_code) {
32882- case 0:
32883- return address + entry;
32884- case 0x80: /* Not present */
32885- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32886- return 0;
32887- default: /* Shouldn't happen */
32888- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32889- service, return_code);
32890+ case 0: {
32891+ int cpu;
32892+ unsigned char flags;
32893+
32894+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32895+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32896+ printk(KERN_WARNING "bios32_service: not valid\n");
32897 return 0;
32898+ }
32899+ address = address + PAGE_OFFSET;
32900+ length += 16UL; /* some BIOSs underreport this... */
32901+ flags = 4;
32902+ if (length >= 64*1024*1024) {
32903+ length >>= PAGE_SHIFT;
32904+ flags |= 8;
32905+ }
32906+
32907+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32908+ gdt = get_cpu_gdt_table(cpu);
32909+ pack_descriptor(&d, address, length, 0x9b, flags);
32910+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32911+ pack_descriptor(&d, address, length, 0x93, flags);
32912+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32913+ }
32914+ return entry;
32915+ }
32916+ case 0x80: /* Not present */
32917+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32918+ return 0;
32919+ default: /* Shouldn't happen */
32920+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32921+ service, return_code);
32922+ return 0;
32923 }
32924 }
32925
32926 static struct {
32927 unsigned long address;
32928 unsigned short segment;
32929-} pci_indirect = { 0, __KERNEL_CS };
32930+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32931
32932-static int pci_bios_present;
32933+static int pci_bios_present __read_only;
32934
32935 static int check_pcibios(void)
32936 {
32937@@ -131,11 +174,13 @@ static int check_pcibios(void)
32938 unsigned long flags, pcibios_entry;
32939
32940 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32941- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32942+ pci_indirect.address = pcibios_entry;
32943
32944 local_irq_save(flags);
32945- __asm__(
32946- "lcall *(%%edi); cld\n\t"
32947+ __asm__("movw %w6, %%ds\n\t"
32948+ "lcall *%%ss:(%%edi); cld\n\t"
32949+ "push %%ss\n\t"
32950+ "pop %%ds\n\t"
32951 "jc 1f\n\t"
32952 "xor %%ah, %%ah\n"
32953 "1:"
32954@@ -144,7 +189,8 @@ static int check_pcibios(void)
32955 "=b" (ebx),
32956 "=c" (ecx)
32957 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32958- "D" (&pci_indirect)
32959+ "D" (&pci_indirect),
32960+ "r" (__PCIBIOS_DS)
32961 : "memory");
32962 local_irq_restore(flags);
32963
32964@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32965
32966 switch (len) {
32967 case 1:
32968- __asm__("lcall *(%%esi); cld\n\t"
32969+ __asm__("movw %w6, %%ds\n\t"
32970+ "lcall *%%ss:(%%esi); cld\n\t"
32971+ "push %%ss\n\t"
32972+ "pop %%ds\n\t"
32973 "jc 1f\n\t"
32974 "xor %%ah, %%ah\n"
32975 "1:"
32976@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32977 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32978 "b" (bx),
32979 "D" ((long)reg),
32980- "S" (&pci_indirect));
32981+ "S" (&pci_indirect),
32982+ "r" (__PCIBIOS_DS));
32983 /*
32984 * Zero-extend the result beyond 8 bits, do not trust the
32985 * BIOS having done it:
32986@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32987 *value &= 0xff;
32988 break;
32989 case 2:
32990- __asm__("lcall *(%%esi); cld\n\t"
32991+ __asm__("movw %w6, %%ds\n\t"
32992+ "lcall *%%ss:(%%esi); cld\n\t"
32993+ "push %%ss\n\t"
32994+ "pop %%ds\n\t"
32995 "jc 1f\n\t"
32996 "xor %%ah, %%ah\n"
32997 "1:"
32998@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32999 : "1" (PCIBIOS_READ_CONFIG_WORD),
33000 "b" (bx),
33001 "D" ((long)reg),
33002- "S" (&pci_indirect));
33003+ "S" (&pci_indirect),
33004+ "r" (__PCIBIOS_DS));
33005 /*
33006 * Zero-extend the result beyond 16 bits, do not trust the
33007 * BIOS having done it:
33008@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33009 *value &= 0xffff;
33010 break;
33011 case 4:
33012- __asm__("lcall *(%%esi); cld\n\t"
33013+ __asm__("movw %w6, %%ds\n\t"
33014+ "lcall *%%ss:(%%esi); cld\n\t"
33015+ "push %%ss\n\t"
33016+ "pop %%ds\n\t"
33017 "jc 1f\n\t"
33018 "xor %%ah, %%ah\n"
33019 "1:"
33020@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33021 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33022 "b" (bx),
33023 "D" ((long)reg),
33024- "S" (&pci_indirect));
33025+ "S" (&pci_indirect),
33026+ "r" (__PCIBIOS_DS));
33027 break;
33028 }
33029
33030@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33031
33032 switch (len) {
33033 case 1:
33034- __asm__("lcall *(%%esi); cld\n\t"
33035+ __asm__("movw %w6, %%ds\n\t"
33036+ "lcall *%%ss:(%%esi); cld\n\t"
33037+ "push %%ss\n\t"
33038+ "pop %%ds\n\t"
33039 "jc 1f\n\t"
33040 "xor %%ah, %%ah\n"
33041 "1:"
33042@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33043 "c" (value),
33044 "b" (bx),
33045 "D" ((long)reg),
33046- "S" (&pci_indirect));
33047+ "S" (&pci_indirect),
33048+ "r" (__PCIBIOS_DS));
33049 break;
33050 case 2:
33051- __asm__("lcall *(%%esi); cld\n\t"
33052+ __asm__("movw %w6, %%ds\n\t"
33053+ "lcall *%%ss:(%%esi); cld\n\t"
33054+ "push %%ss\n\t"
33055+ "pop %%ds\n\t"
33056 "jc 1f\n\t"
33057 "xor %%ah, %%ah\n"
33058 "1:"
33059@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33060 "c" (value),
33061 "b" (bx),
33062 "D" ((long)reg),
33063- "S" (&pci_indirect));
33064+ "S" (&pci_indirect),
33065+ "r" (__PCIBIOS_DS));
33066 break;
33067 case 4:
33068- __asm__("lcall *(%%esi); cld\n\t"
33069+ __asm__("movw %w6, %%ds\n\t"
33070+ "lcall *%%ss:(%%esi); cld\n\t"
33071+ "push %%ss\n\t"
33072+ "pop %%ds\n\t"
33073 "jc 1f\n\t"
33074 "xor %%ah, %%ah\n"
33075 "1:"
33076@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33077 "c" (value),
33078 "b" (bx),
33079 "D" ((long)reg),
33080- "S" (&pci_indirect));
33081+ "S" (&pci_indirect),
33082+ "r" (__PCIBIOS_DS));
33083 break;
33084 }
33085
33086@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33087
33088 DBG("PCI: Fetching IRQ routing table... ");
33089 __asm__("push %%es\n\t"
33090+ "movw %w8, %%ds\n\t"
33091 "push %%ds\n\t"
33092 "pop %%es\n\t"
33093- "lcall *(%%esi); cld\n\t"
33094+ "lcall *%%ss:(%%esi); cld\n\t"
33095 "pop %%es\n\t"
33096+ "push %%ss\n\t"
33097+ "pop %%ds\n"
33098 "jc 1f\n\t"
33099 "xor %%ah, %%ah\n"
33100 "1:"
33101@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33102 "1" (0),
33103 "D" ((long) &opt),
33104 "S" (&pci_indirect),
33105- "m" (opt)
33106+ "m" (opt),
33107+ "r" (__PCIBIOS_DS)
33108 : "memory");
33109 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33110 if (ret & 0xff00)
33111@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33112 {
33113 int ret;
33114
33115- __asm__("lcall *(%%esi); cld\n\t"
33116+ __asm__("movw %w5, %%ds\n\t"
33117+ "lcall *%%ss:(%%esi); cld\n\t"
33118+ "push %%ss\n\t"
33119+ "pop %%ds\n"
33120 "jc 1f\n\t"
33121 "xor %%ah, %%ah\n"
33122 "1:"
33123@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33124 : "0" (PCIBIOS_SET_PCI_HW_INT),
33125 "b" ((dev->bus->number << 8) | dev->devfn),
33126 "c" ((irq << 8) | (pin + 10)),
33127- "S" (&pci_indirect));
33128+ "S" (&pci_indirect),
33129+ "r" (__PCIBIOS_DS));
33130 return !(ret & 0xff00);
33131 }
33132 EXPORT_SYMBOL(pcibios_set_irq_routing);
33133diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33134index 40e4469..d915bf9 100644
33135--- a/arch/x86/platform/efi/efi_32.c
33136+++ b/arch/x86/platform/efi/efi_32.c
33137@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33138 {
33139 struct desc_ptr gdt_descr;
33140
33141+#ifdef CONFIG_PAX_KERNEXEC
33142+ struct desc_struct d;
33143+#endif
33144+
33145 local_irq_save(efi_rt_eflags);
33146
33147 load_cr3(initial_page_table);
33148 __flush_tlb_all();
33149
33150+#ifdef CONFIG_PAX_KERNEXEC
33151+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33152+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33153+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33154+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33155+#endif
33156+
33157 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33158 gdt_descr.size = GDT_SIZE - 1;
33159 load_gdt(&gdt_descr);
33160@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33161 {
33162 struct desc_ptr gdt_descr;
33163
33164+#ifdef CONFIG_PAX_KERNEXEC
33165+ struct desc_struct d;
33166+
33167+ memset(&d, 0, sizeof d);
33168+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33169+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33170+#endif
33171+
33172 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33173 gdt_descr.size = GDT_SIZE - 1;
33174 load_gdt(&gdt_descr);
33175
33176+#ifdef CONFIG_PAX_PER_CPU_PGD
33177+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33178+#else
33179 load_cr3(swapper_pg_dir);
33180+#endif
33181+
33182 __flush_tlb_all();
33183
33184 local_irq_restore(efi_rt_eflags);
33185diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33186index 39a0e7f1..872396e 100644
33187--- a/arch/x86/platform/efi/efi_64.c
33188+++ b/arch/x86/platform/efi/efi_64.c
33189@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33190 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33191 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33192 }
33193+
33194+#ifdef CONFIG_PAX_PER_CPU_PGD
33195+ load_cr3(swapper_pg_dir);
33196+#endif
33197+
33198 __flush_tlb_all();
33199 }
33200
33201@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33202 for (pgd = 0; pgd < n_pgds; pgd++)
33203 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33204 kfree(save_pgd);
33205+
33206+#ifdef CONFIG_PAX_PER_CPU_PGD
33207+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33208+#endif
33209+
33210 __flush_tlb_all();
33211 local_irq_restore(efi_flags);
33212 early_code_mapping_set_exec(0);
33213diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33214index fbe66e6..eae5e38 100644
33215--- a/arch/x86/platform/efi/efi_stub_32.S
33216+++ b/arch/x86/platform/efi/efi_stub_32.S
33217@@ -6,7 +6,9 @@
33218 */
33219
33220 #include <linux/linkage.h>
33221+#include <linux/init.h>
33222 #include <asm/page_types.h>
33223+#include <asm/segment.h>
33224
33225 /*
33226 * efi_call_phys(void *, ...) is a function with variable parameters.
33227@@ -20,7 +22,7 @@
33228 * service functions will comply with gcc calling convention, too.
33229 */
33230
33231-.text
33232+__INIT
33233 ENTRY(efi_call_phys)
33234 /*
33235 * 0. The function can only be called in Linux kernel. So CS has been
33236@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33237 * The mapping of lower virtual memory has been created in prelog and
33238 * epilog.
33239 */
33240- movl $1f, %edx
33241- subl $__PAGE_OFFSET, %edx
33242- jmp *%edx
33243+#ifdef CONFIG_PAX_KERNEXEC
33244+ movl $(__KERNEXEC_EFI_DS), %edx
33245+ mov %edx, %ds
33246+ mov %edx, %es
33247+ mov %edx, %ss
33248+ addl $2f,(1f)
33249+ ljmp *(1f)
33250+
33251+__INITDATA
33252+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33253+.previous
33254+
33255+2:
33256+ subl $2b,(1b)
33257+#else
33258+ jmp 1f-__PAGE_OFFSET
33259 1:
33260+#endif
33261
33262 /*
33263 * 2. Now on the top of stack is the return
33264@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33265 * parameter 2, ..., param n. To make things easy, we save the return
33266 * address of efi_call_phys in a global variable.
33267 */
33268- popl %edx
33269- movl %edx, saved_return_addr
33270- /* get the function pointer into ECX*/
33271- popl %ecx
33272- movl %ecx, efi_rt_function_ptr
33273- movl $2f, %edx
33274- subl $__PAGE_OFFSET, %edx
33275- pushl %edx
33276+ popl (saved_return_addr)
33277+ popl (efi_rt_function_ptr)
33278
33279 /*
33280 * 3. Clear PG bit in %CR0.
33281@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33282 /*
33283 * 5. Call the physical function.
33284 */
33285- jmp *%ecx
33286+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33287
33288-2:
33289 /*
33290 * 6. After EFI runtime service returns, control will return to
33291 * following instruction. We'd better readjust stack pointer first.
33292@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33293 movl %cr0, %edx
33294 orl $0x80000000, %edx
33295 movl %edx, %cr0
33296- jmp 1f
33297-1:
33298+
33299 /*
33300 * 8. Now restore the virtual mode from flat mode by
33301 * adding EIP with PAGE_OFFSET.
33302 */
33303- movl $1f, %edx
33304- jmp *%edx
33305+#ifdef CONFIG_PAX_KERNEXEC
33306+ movl $(__KERNEL_DS), %edx
33307+ mov %edx, %ds
33308+ mov %edx, %es
33309+ mov %edx, %ss
33310+ ljmp $(__KERNEL_CS),$1f
33311+#else
33312+ jmp 1f+__PAGE_OFFSET
33313+#endif
33314 1:
33315
33316 /*
33317 * 9. Balance the stack. And because EAX contain the return value,
33318 * we'd better not clobber it.
33319 */
33320- leal efi_rt_function_ptr, %edx
33321- movl (%edx), %ecx
33322- pushl %ecx
33323+ pushl (efi_rt_function_ptr)
33324
33325 /*
33326- * 10. Push the saved return address onto the stack and return.
33327+ * 10. Return to the saved return address.
33328 */
33329- leal saved_return_addr, %edx
33330- movl (%edx), %ecx
33331- pushl %ecx
33332- ret
33333+ jmpl *(saved_return_addr)
33334 ENDPROC(efi_call_phys)
33335 .previous
33336
33337-.data
33338+__INITDATA
33339 saved_return_addr:
33340 .long 0
33341 efi_rt_function_ptr:
33342diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33343index 4c07cca..2c8427d 100644
33344--- a/arch/x86/platform/efi/efi_stub_64.S
33345+++ b/arch/x86/platform/efi/efi_stub_64.S
33346@@ -7,6 +7,7 @@
33347 */
33348
33349 #include <linux/linkage.h>
33350+#include <asm/alternative-asm.h>
33351
33352 #define SAVE_XMM \
33353 mov %rsp, %rax; \
33354@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33355 call *%rdi
33356 addq $32, %rsp
33357 RESTORE_XMM
33358+ pax_force_retaddr 0, 1
33359 ret
33360 ENDPROC(efi_call0)
33361
33362@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33363 call *%rdi
33364 addq $32, %rsp
33365 RESTORE_XMM
33366+ pax_force_retaddr 0, 1
33367 ret
33368 ENDPROC(efi_call1)
33369
33370@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33371 call *%rdi
33372 addq $32, %rsp
33373 RESTORE_XMM
33374+ pax_force_retaddr 0, 1
33375 ret
33376 ENDPROC(efi_call2)
33377
33378@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33379 call *%rdi
33380 addq $32, %rsp
33381 RESTORE_XMM
33382+ pax_force_retaddr 0, 1
33383 ret
33384 ENDPROC(efi_call3)
33385
33386@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33387 call *%rdi
33388 addq $32, %rsp
33389 RESTORE_XMM
33390+ pax_force_retaddr 0, 1
33391 ret
33392 ENDPROC(efi_call4)
33393
33394@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33395 call *%rdi
33396 addq $48, %rsp
33397 RESTORE_XMM
33398+ pax_force_retaddr 0, 1
33399 ret
33400 ENDPROC(efi_call5)
33401
33402@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33403 call *%rdi
33404 addq $48, %rsp
33405 RESTORE_XMM
33406+ pax_force_retaddr 0, 1
33407 ret
33408 ENDPROC(efi_call6)
33409diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33410index 3ca5957..7909c18 100644
33411--- a/arch/x86/platform/mrst/mrst.c
33412+++ b/arch/x86/platform/mrst/mrst.c
33413@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33414 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33415 int sfi_mrtc_num;
33416
33417-static void mrst_power_off(void)
33418+static __noreturn void mrst_power_off(void)
33419 {
33420+ BUG();
33421 }
33422
33423-static void mrst_reboot(void)
33424+static __noreturn void mrst_reboot(void)
33425 {
33426 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33427+ BUG();
33428 }
33429
33430 /* parse all the mtimer info to a static mtimer array */
33431diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33432index d6ee929..3637cb5 100644
33433--- a/arch/x86/platform/olpc/olpc_dt.c
33434+++ b/arch/x86/platform/olpc/olpc_dt.c
33435@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33436 return res;
33437 }
33438
33439-static struct of_pdt_ops prom_olpc_ops __initdata = {
33440+static struct of_pdt_ops prom_olpc_ops __initconst = {
33441 .nextprop = olpc_dt_nextprop,
33442 .getproplen = olpc_dt_getproplen,
33443 .getproperty = olpc_dt_getproperty,
33444diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33445index 424f4c9..f2a2988 100644
33446--- a/arch/x86/power/cpu.c
33447+++ b/arch/x86/power/cpu.c
33448@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33449 static void fix_processor_context(void)
33450 {
33451 int cpu = smp_processor_id();
33452- struct tss_struct *t = &per_cpu(init_tss, cpu);
33453-#ifdef CONFIG_X86_64
33454- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33455- tss_desc tss;
33456-#endif
33457+ struct tss_struct *t = init_tss + cpu;
33458+
33459 set_tss_desc(cpu, t); /*
33460 * This just modifies memory; should not be
33461 * necessary. But... This is necessary, because
33462@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33463 */
33464
33465 #ifdef CONFIG_X86_64
33466- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33467- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33468- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33469-
33470 syscall_init(); /* This sets MSR_*STAR and related */
33471 #endif
33472 load_TR_desc(); /* This does ltr */
33473diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33474index a44f457..9140171 100644
33475--- a/arch/x86/realmode/init.c
33476+++ b/arch/x86/realmode/init.c
33477@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33478 __va(real_mode_header->trampoline_header);
33479
33480 #ifdef CONFIG_X86_32
33481- trampoline_header->start = __pa_symbol(startup_32_smp);
33482+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33483+
33484+#ifdef CONFIG_PAX_KERNEXEC
33485+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33486+#endif
33487+
33488+ trampoline_header->boot_cs = __BOOT_CS;
33489 trampoline_header->gdt_limit = __BOOT_DS + 7;
33490 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33491 #else
33492@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33493 *trampoline_cr4_features = read_cr4();
33494
33495 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33496- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33497+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33498 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33499 #endif
33500 }
33501diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33502index 8869287..d577672 100644
33503--- a/arch/x86/realmode/rm/Makefile
33504+++ b/arch/x86/realmode/rm/Makefile
33505@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33506 $(call cc-option, -fno-unit-at-a-time)) \
33507 $(call cc-option, -fno-stack-protector) \
33508 $(call cc-option, -mpreferred-stack-boundary=2)
33509+ifdef CONSTIFY_PLUGIN
33510+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33511+endif
33512 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33513 GCOV_PROFILE := n
33514diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33515index a28221d..93c40f1 100644
33516--- a/arch/x86/realmode/rm/header.S
33517+++ b/arch/x86/realmode/rm/header.S
33518@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33519 #endif
33520 /* APM/BIOS reboot */
33521 .long pa_machine_real_restart_asm
33522-#ifdef CONFIG_X86_64
33523+#ifdef CONFIG_X86_32
33524+ .long __KERNEL_CS
33525+#else
33526 .long __KERNEL32_CS
33527 #endif
33528 END(real_mode_header)
33529diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33530index c1b2791..f9e31c7 100644
33531--- a/arch/x86/realmode/rm/trampoline_32.S
33532+++ b/arch/x86/realmode/rm/trampoline_32.S
33533@@ -25,6 +25,12 @@
33534 #include <asm/page_types.h>
33535 #include "realmode.h"
33536
33537+#ifdef CONFIG_PAX_KERNEXEC
33538+#define ta(X) (X)
33539+#else
33540+#define ta(X) (pa_ ## X)
33541+#endif
33542+
33543 .text
33544 .code16
33545
33546@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33547
33548 cli # We should be safe anyway
33549
33550- movl tr_start, %eax # where we need to go
33551-
33552 movl $0xA5A5A5A5, trampoline_status
33553 # write marker for master knows we're running
33554
33555@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33556 movw $1, %dx # protected mode (PE) bit
33557 lmsw %dx # into protected mode
33558
33559- ljmpl $__BOOT_CS, $pa_startup_32
33560+ ljmpl *(trampoline_header)
33561
33562 .section ".text32","ax"
33563 .code32
33564@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33565 .balign 8
33566 GLOBAL(trampoline_header)
33567 tr_start: .space 4
33568- tr_gdt_pad: .space 2
33569+ tr_boot_cs: .space 2
33570 tr_gdt: .space 6
33571 END(trampoline_header)
33572
33573diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33574index bb360dc..d0fd8f8 100644
33575--- a/arch/x86/realmode/rm/trampoline_64.S
33576+++ b/arch/x86/realmode/rm/trampoline_64.S
33577@@ -94,6 +94,7 @@ ENTRY(startup_32)
33578 movl %edx, %gs
33579
33580 movl pa_tr_cr4, %eax
33581+ andl $~X86_CR4_PCIDE, %eax
33582 movl %eax, %cr4 # Enable PAE mode
33583
33584 # Setup trampoline 4 level pagetables
33585@@ -107,7 +108,7 @@ ENTRY(startup_32)
33586 wrmsr
33587
33588 # Enable paging and in turn activate Long Mode
33589- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33590+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33591 movl %eax, %cr0
33592
33593 /*
33594diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33595index e812034..c747134 100644
33596--- a/arch/x86/tools/Makefile
33597+++ b/arch/x86/tools/Makefile
33598@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33599
33600 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
33601
33602-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33603+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33604 hostprogs-y += relocs
33605 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33606 relocs: $(obj)/relocs
33607diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33608index f7bab68..b6d9886 100644
33609--- a/arch/x86/tools/relocs.c
33610+++ b/arch/x86/tools/relocs.c
33611@@ -1,5 +1,7 @@
33612 /* This is included from relocs_32/64.c */
33613
33614+#include "../../../include/generated/autoconf.h"
33615+
33616 #define ElfW(type) _ElfW(ELF_BITS, type)
33617 #define _ElfW(bits, type) __ElfW(bits, type)
33618 #define __ElfW(bits, type) Elf##bits##_##type
33619@@ -11,6 +13,7 @@
33620 #define Elf_Sym ElfW(Sym)
33621
33622 static Elf_Ehdr ehdr;
33623+static Elf_Phdr *phdr;
33624
33625 struct relocs {
33626 uint32_t *offset;
33627@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33628 }
33629 }
33630
33631+static void read_phdrs(FILE *fp)
33632+{
33633+ unsigned int i;
33634+
33635+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33636+ if (!phdr) {
33637+ die("Unable to allocate %d program headers\n",
33638+ ehdr.e_phnum);
33639+ }
33640+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33641+ die("Seek to %d failed: %s\n",
33642+ ehdr.e_phoff, strerror(errno));
33643+ }
33644+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33645+ die("Cannot read ELF program headers: %s\n",
33646+ strerror(errno));
33647+ }
33648+ for(i = 0; i < ehdr.e_phnum; i++) {
33649+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33650+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33651+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33652+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33653+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33654+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33655+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33656+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33657+ }
33658+
33659+}
33660+
33661 static void read_shdrs(FILE *fp)
33662 {
33663- int i;
33664+ unsigned int i;
33665 Elf_Shdr shdr;
33666
33667 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33668@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33669
33670 static void read_strtabs(FILE *fp)
33671 {
33672- int i;
33673+ unsigned int i;
33674 for (i = 0; i < ehdr.e_shnum; i++) {
33675 struct section *sec = &secs[i];
33676 if (sec->shdr.sh_type != SHT_STRTAB) {
33677@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33678
33679 static void read_symtabs(FILE *fp)
33680 {
33681- int i,j;
33682+ unsigned int i,j;
33683 for (i = 0; i < ehdr.e_shnum; i++) {
33684 struct section *sec = &secs[i];
33685 if (sec->shdr.sh_type != SHT_SYMTAB) {
33686@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33687 }
33688
33689
33690-static void read_relocs(FILE *fp)
33691+static void read_relocs(FILE *fp, int use_real_mode)
33692 {
33693- int i,j;
33694+ unsigned int i,j;
33695+ uint32_t base;
33696+
33697 for (i = 0; i < ehdr.e_shnum; i++) {
33698 struct section *sec = &secs[i];
33699 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33700@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33701 die("Cannot read symbol table: %s\n",
33702 strerror(errno));
33703 }
33704+ base = 0;
33705+
33706+#ifdef CONFIG_X86_32
33707+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33708+ if (phdr[j].p_type != PT_LOAD )
33709+ continue;
33710+ if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
33711+ continue;
33712+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33713+ break;
33714+ }
33715+#endif
33716+
33717 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33718 Elf_Rel *rel = &sec->reltab[j];
33719- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33720+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33721 rel->r_info = elf_xword_to_cpu(rel->r_info);
33722 #if (SHT_REL_TYPE == SHT_RELA)
33723 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33724@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33725
33726 static void print_absolute_symbols(void)
33727 {
33728- int i;
33729+ unsigned int i;
33730 const char *format;
33731
33732 if (ELF_BITS == 64)
33733@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33734 for (i = 0; i < ehdr.e_shnum; i++) {
33735 struct section *sec = &secs[i];
33736 char *sym_strtab;
33737- int j;
33738+ unsigned int j;
33739
33740 if (sec->shdr.sh_type != SHT_SYMTAB) {
33741 continue;
33742@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33743
33744 static void print_absolute_relocs(void)
33745 {
33746- int i, printed = 0;
33747+ unsigned int i, printed = 0;
33748 const char *format;
33749
33750 if (ELF_BITS == 64)
33751@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33752 struct section *sec_applies, *sec_symtab;
33753 char *sym_strtab;
33754 Elf_Sym *sh_symtab;
33755- int j;
33756+ unsigned int j;
33757 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33758 continue;
33759 }
33760@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33761 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33762 Elf_Sym *sym, const char *symname))
33763 {
33764- int i;
33765+ unsigned int i;
33766 /* Walk through the relocations */
33767 for (i = 0; i < ehdr.e_shnum; i++) {
33768 char *sym_strtab;
33769 Elf_Sym *sh_symtab;
33770 struct section *sec_applies, *sec_symtab;
33771- int j;
33772+ unsigned int j;
33773 struct section *sec = &secs[i];
33774
33775 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33776@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33777 {
33778 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33779 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33780+ char *sym_strtab = sec->link->link->strtab;
33781+
33782+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33783+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33784+ return 0;
33785+
33786+#ifdef CONFIG_PAX_KERNEXEC
33787+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33788+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33789+ return 0;
33790+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33791+ return 0;
33792+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33793+ return 0;
33794+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33795+ return 0;
33796+#endif
33797
33798 switch (r_type) {
33799 case R_386_NONE:
33800@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33801
33802 static void emit_relocs(int as_text, int use_real_mode)
33803 {
33804- int i;
33805+ unsigned int i;
33806 int (*write_reloc)(uint32_t, FILE *) = write32;
33807 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33808 const char *symname);
33809@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33810 {
33811 regex_init(use_real_mode);
33812 read_ehdr(fp);
33813+ read_phdrs(fp);
33814 read_shdrs(fp);
33815 read_strtabs(fp);
33816 read_symtabs(fp);
33817- read_relocs(fp);
33818+ read_relocs(fp, use_real_mode);
33819 if (ELF_BITS == 64)
33820 percpu_init();
33821 if (show_absolute_syms) {
33822diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33823index 80ffa5b..a33bd15 100644
33824--- a/arch/x86/um/tls_32.c
33825+++ b/arch/x86/um/tls_32.c
33826@@ -260,7 +260,7 @@ out:
33827 if (unlikely(task == current &&
33828 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33829 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33830- "without flushed TLS.", current->pid);
33831+ "without flushed TLS.", task_pid_nr(current));
33832 }
33833
33834 return 0;
33835diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33836index fd14be1..e3c79c0 100644
33837--- a/arch/x86/vdso/Makefile
33838+++ b/arch/x86/vdso/Makefile
33839@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33840 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33841 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33842
33843-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33844+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33845 GCOV_PROFILE := n
33846
33847 #
33848diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33849index d6bfb87..876ee18 100644
33850--- a/arch/x86/vdso/vdso32-setup.c
33851+++ b/arch/x86/vdso/vdso32-setup.c
33852@@ -25,6 +25,7 @@
33853 #include <asm/tlbflush.h>
33854 #include <asm/vdso.h>
33855 #include <asm/proto.h>
33856+#include <asm/mman.h>
33857
33858 enum {
33859 VDSO_DISABLED = 0,
33860@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33861 void enable_sep_cpu(void)
33862 {
33863 int cpu = get_cpu();
33864- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33865+ struct tss_struct *tss = init_tss + cpu;
33866
33867 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33868 put_cpu();
33869@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33870 gate_vma.vm_start = FIXADDR_USER_START;
33871 gate_vma.vm_end = FIXADDR_USER_END;
33872 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33873- gate_vma.vm_page_prot = __P101;
33874+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33875
33876 return 0;
33877 }
33878@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33879 if (compat)
33880 addr = VDSO_HIGH_BASE;
33881 else {
33882- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33883+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33884 if (IS_ERR_VALUE(addr)) {
33885 ret = addr;
33886 goto up_fail;
33887 }
33888 }
33889
33890- current->mm->context.vdso = (void *)addr;
33891+ current->mm->context.vdso = addr;
33892
33893 if (compat_uses_vma || !compat) {
33894 /*
33895@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33896 }
33897
33898 current_thread_info()->sysenter_return =
33899- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33900+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33901
33902 up_fail:
33903 if (ret)
33904- current->mm->context.vdso = NULL;
33905+ current->mm->context.vdso = 0;
33906
33907 up_write(&mm->mmap_sem);
33908
33909@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33910
33911 const char *arch_vma_name(struct vm_area_struct *vma)
33912 {
33913- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33914+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33915 return "[vdso]";
33916+
33917+#ifdef CONFIG_PAX_SEGMEXEC
33918+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33919+ return "[vdso]";
33920+#endif
33921+
33922 return NULL;
33923 }
33924
33925@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33926 * Check to see if the corresponding task was created in compat vdso
33927 * mode.
33928 */
33929- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33930+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33931 return &gate_vma;
33932 return NULL;
33933 }
33934diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33935index 431e875..cbb23f3 100644
33936--- a/arch/x86/vdso/vma.c
33937+++ b/arch/x86/vdso/vma.c
33938@@ -16,8 +16,6 @@
33939 #include <asm/vdso.h>
33940 #include <asm/page.h>
33941
33942-unsigned int __read_mostly vdso_enabled = 1;
33943-
33944 extern char vdso_start[], vdso_end[];
33945 extern unsigned short vdso_sync_cpuid;
33946
33947@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33948 * unaligned here as a result of stack start randomization.
33949 */
33950 addr = PAGE_ALIGN(addr);
33951- addr = align_vdso_addr(addr);
33952
33953 return addr;
33954 }
33955@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33956 unsigned size)
33957 {
33958 struct mm_struct *mm = current->mm;
33959- unsigned long addr;
33960+ unsigned long addr = 0;
33961 int ret;
33962
33963- if (!vdso_enabled)
33964- return 0;
33965-
33966 down_write(&mm->mmap_sem);
33967+
33968+#ifdef CONFIG_PAX_RANDMMAP
33969+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33970+#endif
33971+
33972 addr = vdso_addr(mm->start_stack, size);
33973+ addr = align_vdso_addr(addr);
33974 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33975 if (IS_ERR_VALUE(addr)) {
33976 ret = addr;
33977 goto up_fail;
33978 }
33979
33980- current->mm->context.vdso = (void *)addr;
33981+ mm->context.vdso = addr;
33982
33983 ret = install_special_mapping(mm, addr, size,
33984 VM_READ|VM_EXEC|
33985 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33986 pages);
33987- if (ret) {
33988- current->mm->context.vdso = NULL;
33989- goto up_fail;
33990- }
33991+ if (ret)
33992+ mm->context.vdso = 0;
33993
33994 up_fail:
33995 up_write(&mm->mmap_sem);
33996@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33997 vdsox32_size);
33998 }
33999 #endif
34000-
34001-static __init int vdso_setup(char *s)
34002-{
34003- vdso_enabled = simple_strtoul(s, NULL, 0);
34004- return 0;
34005-}
34006-__setup("vdso=", vdso_setup);
34007diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34008index fa6ade7..73da73a5 100644
34009--- a/arch/x86/xen/enlighten.c
34010+++ b/arch/x86/xen/enlighten.c
34011@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34012
34013 struct shared_info xen_dummy_shared_info;
34014
34015-void *xen_initial_gdt;
34016-
34017 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34018 __read_mostly int xen_have_vector_callback;
34019 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34020@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34021 {
34022 unsigned long va = dtr->address;
34023 unsigned int size = dtr->size + 1;
34024- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34025- unsigned long frames[pages];
34026+ unsigned long frames[65536 / PAGE_SIZE];
34027 int f;
34028
34029 /*
34030@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34031 {
34032 unsigned long va = dtr->address;
34033 unsigned int size = dtr->size + 1;
34034- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34035- unsigned long frames[pages];
34036+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34037 int f;
34038
34039 /*
34040@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34041 * 8-byte entries, or 16 4k pages..
34042 */
34043
34044- BUG_ON(size > 65536);
34045+ BUG_ON(size > GDT_SIZE);
34046 BUG_ON(va & ~PAGE_MASK);
34047
34048 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34049@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34050 return 0;
34051 }
34052
34053-static void set_xen_basic_apic_ops(void)
34054+static void __init set_xen_basic_apic_ops(void)
34055 {
34056 apic->read = xen_apic_read;
34057 apic->write = xen_apic_write;
34058@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34059 #endif
34060 };
34061
34062-static void xen_reboot(int reason)
34063+static __noreturn void xen_reboot(int reason)
34064 {
34065 struct sched_shutdown r = { .reason = reason };
34066
34067- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34068- BUG();
34069+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34070+ BUG();
34071 }
34072
34073-static void xen_restart(char *msg)
34074+static __noreturn void xen_restart(char *msg)
34075 {
34076 xen_reboot(SHUTDOWN_reboot);
34077 }
34078
34079-static void xen_emergency_restart(void)
34080+static __noreturn void xen_emergency_restart(void)
34081 {
34082 xen_reboot(SHUTDOWN_reboot);
34083 }
34084
34085-static void xen_machine_halt(void)
34086+static __noreturn void xen_machine_halt(void)
34087 {
34088 xen_reboot(SHUTDOWN_poweroff);
34089 }
34090
34091-static void xen_machine_power_off(void)
34092+static __noreturn void xen_machine_power_off(void)
34093 {
34094 if (pm_power_off)
34095 pm_power_off();
34096@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34097 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34098
34099 /* Work out if we support NX */
34100- x86_configure_nx();
34101+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34102+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34103+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34104+ unsigned l, h;
34105+
34106+ __supported_pte_mask |= _PAGE_NX;
34107+ rdmsr(MSR_EFER, l, h);
34108+ l |= EFER_NX;
34109+ wrmsr(MSR_EFER, l, h);
34110+ }
34111+#endif
34112
34113 xen_setup_features();
34114
34115@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34116
34117 machine_ops = xen_machine_ops;
34118
34119- /*
34120- * The only reliable way to retain the initial address of the
34121- * percpu gdt_page is to remember it here, so we can go and
34122- * mark it RW later, when the initial percpu area is freed.
34123- */
34124- xen_initial_gdt = &per_cpu(gdt_page, 0);
34125-
34126 xen_smp_init();
34127
34128 #ifdef CONFIG_ACPI_NUMA
34129diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34130index fdc3ba2..23cae00 100644
34131--- a/arch/x86/xen/mmu.c
34132+++ b/arch/x86/xen/mmu.c
34133@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34134 return val;
34135 }
34136
34137-static pteval_t pte_pfn_to_mfn(pteval_t val)
34138+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34139 {
34140 if (val & _PAGE_PRESENT) {
34141 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34142@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34143 /* L3_k[510] -> level2_kernel_pgt
34144 * L3_i[511] -> level2_fixmap_pgt */
34145 convert_pfn_mfn(level3_kernel_pgt);
34146+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34147+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34148+ convert_pfn_mfn(level3_vmemmap_pgt);
34149
34150 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34151 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34152@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34153 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34154 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34155 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34156+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34157+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34158+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34159 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34160 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34161+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34162 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34163 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34164
34165@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34166 pv_mmu_ops.set_pud = xen_set_pud;
34167 #if PAGETABLE_LEVELS == 4
34168 pv_mmu_ops.set_pgd = xen_set_pgd;
34169+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34170 #endif
34171
34172 /* This will work as long as patching hasn't happened yet
34173@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34174 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34175 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34176 .set_pgd = xen_set_pgd_hyper,
34177+ .set_pgd_batched = xen_set_pgd_hyper,
34178
34179 .alloc_pud = xen_alloc_pmd_init,
34180 .release_pud = xen_release_pmd_init,
34181diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34182index 31d0475..51af671 100644
34183--- a/arch/x86/xen/smp.c
34184+++ b/arch/x86/xen/smp.c
34185@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34186 native_smp_prepare_boot_cpu();
34187
34188 if (xen_pv_domain()) {
34189- /* We've switched to the "real" per-cpu gdt, so make sure the
34190- old memory can be recycled */
34191- make_lowmem_page_readwrite(xen_initial_gdt);
34192-
34193 #ifdef CONFIG_X86_32
34194 /*
34195 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34196 * expects __USER_DS
34197 */
34198- loadsegment(ds, __USER_DS);
34199- loadsegment(es, __USER_DS);
34200+ loadsegment(ds, __KERNEL_DS);
34201+ loadsegment(es, __KERNEL_DS);
34202 #endif
34203
34204 xen_filter_cpu_maps();
34205@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34206 ctxt->user_regs.ss = __KERNEL_DS;
34207 #ifdef CONFIG_X86_32
34208 ctxt->user_regs.fs = __KERNEL_PERCPU;
34209- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34210+ savesegment(gs, ctxt->user_regs.gs);
34211 #else
34212 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34213 #endif
34214@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34215
34216 {
34217 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34218- ctxt->user_regs.ds = __USER_DS;
34219- ctxt->user_regs.es = __USER_DS;
34220+ ctxt->user_regs.ds = __KERNEL_DS;
34221+ ctxt->user_regs.es = __KERNEL_DS;
34222
34223 xen_copy_trap_info(ctxt->trap_ctxt);
34224
34225@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34226 int rc;
34227
34228 per_cpu(current_task, cpu) = idle;
34229+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34230 #ifdef CONFIG_X86_32
34231 irq_ctx_init(cpu);
34232 #else
34233 clear_tsk_thread_flag(idle, TIF_FORK);
34234- per_cpu(kernel_stack, cpu) =
34235- (unsigned long)task_stack_page(idle) -
34236- KERNEL_STACK_OFFSET + THREAD_SIZE;
34237+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34238 #endif
34239 xen_setup_runstate_info(cpu);
34240 xen_setup_timer(cpu);
34241@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34242
34243 void __init xen_smp_init(void)
34244 {
34245- smp_ops = xen_smp_ops;
34246+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34247 xen_fill_possible_map();
34248 }
34249
34250diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34251index 33ca6e4..0ded929 100644
34252--- a/arch/x86/xen/xen-asm_32.S
34253+++ b/arch/x86/xen/xen-asm_32.S
34254@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34255 ESP_OFFSET=4 # bytes pushed onto stack
34256
34257 /*
34258- * Store vcpu_info pointer for easy access. Do it this way to
34259- * avoid having to reload %fs
34260+ * Store vcpu_info pointer for easy access.
34261 */
34262 #ifdef CONFIG_SMP
34263- GET_THREAD_INFO(%eax)
34264- movl %ss:TI_cpu(%eax), %eax
34265- movl %ss:__per_cpu_offset(,%eax,4), %eax
34266- mov %ss:xen_vcpu(%eax), %eax
34267+ push %fs
34268+ mov $(__KERNEL_PERCPU), %eax
34269+ mov %eax, %fs
34270+ mov PER_CPU_VAR(xen_vcpu), %eax
34271+ pop %fs
34272 #else
34273 movl %ss:xen_vcpu, %eax
34274 #endif
34275diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34276index 7faed58..ba4427c 100644
34277--- a/arch/x86/xen/xen-head.S
34278+++ b/arch/x86/xen/xen-head.S
34279@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34280 #ifdef CONFIG_X86_32
34281 mov %esi,xen_start_info
34282 mov $init_thread_union+THREAD_SIZE,%esp
34283+#ifdef CONFIG_SMP
34284+ movl $cpu_gdt_table,%edi
34285+ movl $__per_cpu_load,%eax
34286+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34287+ rorl $16,%eax
34288+ movb %al,__KERNEL_PERCPU + 4(%edi)
34289+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34290+ movl $__per_cpu_end - 1,%eax
34291+ subl $__per_cpu_start,%eax
34292+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34293+#endif
34294 #else
34295 mov %rsi,xen_start_info
34296 mov $init_thread_union+THREAD_SIZE,%rsp
34297diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34298index 95f8c61..611d6e8 100644
34299--- a/arch/x86/xen/xen-ops.h
34300+++ b/arch/x86/xen/xen-ops.h
34301@@ -10,8 +10,6 @@
34302 extern const char xen_hypervisor_callback[];
34303 extern const char xen_failsafe_callback[];
34304
34305-extern void *xen_initial_gdt;
34306-
34307 struct trap_info;
34308 void xen_copy_trap_info(struct trap_info *traps);
34309
34310diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34311index 525bd3d..ef888b1 100644
34312--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34313+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34314@@ -119,9 +119,9 @@
34315 ----------------------------------------------------------------------*/
34316
34317 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34318-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34319 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34320 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34321+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34322
34323 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34324 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34325diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34326index 2f33760..835e50a 100644
34327--- a/arch/xtensa/variants/fsf/include/variant/core.h
34328+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34329@@ -11,6 +11,7 @@
34330 #ifndef _XTENSA_CORE_H
34331 #define _XTENSA_CORE_H
34332
34333+#include <linux/const.h>
34334
34335 /****************************************************************************
34336 Parameters Useful for Any Code, USER or PRIVILEGED
34337@@ -112,9 +113,9 @@
34338 ----------------------------------------------------------------------*/
34339
34340 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34341-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34342 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34343 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34344+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34345
34346 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34347 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34348diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34349index af00795..2bb8105 100644
34350--- a/arch/xtensa/variants/s6000/include/variant/core.h
34351+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34352@@ -11,6 +11,7 @@
34353 #ifndef _XTENSA_CORE_CONFIGURATION_H
34354 #define _XTENSA_CORE_CONFIGURATION_H
34355
34356+#include <linux/const.h>
34357
34358 /****************************************************************************
34359 Parameters Useful for Any Code, USER or PRIVILEGED
34360@@ -118,9 +119,9 @@
34361 ----------------------------------------------------------------------*/
34362
34363 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34364-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34365 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34366 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34367+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34368
34369 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34370 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34371diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34372index 4e491d9..c8e18e4 100644
34373--- a/block/blk-cgroup.c
34374+++ b/block/blk-cgroup.c
34375@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
34376 static struct cgroup_subsys_state *
34377 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
34378 {
34379- static atomic64_t id_seq = ATOMIC64_INIT(0);
34380+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34381 struct blkcg *blkcg;
34382
34383 if (!parent_css) {
34384@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
34385
34386 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34387 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34388- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34389+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34390 done:
34391 spin_lock_init(&blkcg->lock);
34392 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34393diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34394index 4b8d9b54..a7178c0 100644
34395--- a/block/blk-iopoll.c
34396+++ b/block/blk-iopoll.c
34397@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34398 }
34399 EXPORT_SYMBOL(blk_iopoll_complete);
34400
34401-static void blk_iopoll_softirq(struct softirq_action *h)
34402+static __latent_entropy void blk_iopoll_softirq(void)
34403 {
34404 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34405 int rearm = 0, budget = blk_iopoll_budget;
34406diff --git a/block/blk-map.c b/block/blk-map.c
34407index 623e1cd..ca1e109 100644
34408--- a/block/blk-map.c
34409+++ b/block/blk-map.c
34410@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34411 if (!len || !kbuf)
34412 return -EINVAL;
34413
34414- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34415+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34416 if (do_copy)
34417 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34418 else
34419diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34420index ec9e606..3f38839 100644
34421--- a/block/blk-softirq.c
34422+++ b/block/blk-softirq.c
34423@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34424 * Softirq action handler - move entries to local list and loop over them
34425 * while passing them to the queue registered handler.
34426 */
34427-static void blk_done_softirq(struct softirq_action *h)
34428+static __latent_entropy void blk_done_softirq(void)
34429 {
34430 struct list_head *cpu_list, local_list;
34431
34432diff --git a/block/bsg.c b/block/bsg.c
34433index 420a5a9..23834aa 100644
34434--- a/block/bsg.c
34435+++ b/block/bsg.c
34436@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34437 struct sg_io_v4 *hdr, struct bsg_device *bd,
34438 fmode_t has_write_perm)
34439 {
34440+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34441+ unsigned char *cmdptr;
34442+
34443 if (hdr->request_len > BLK_MAX_CDB) {
34444 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34445 if (!rq->cmd)
34446 return -ENOMEM;
34447- }
34448+ cmdptr = rq->cmd;
34449+ } else
34450+ cmdptr = tmpcmd;
34451
34452- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34453+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34454 hdr->request_len))
34455 return -EFAULT;
34456
34457+ if (cmdptr != rq->cmd)
34458+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34459+
34460 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34461 if (blk_verify_command(rq->cmd, has_write_perm))
34462 return -EPERM;
34463diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34464index fbd5a67..5d631b5 100644
34465--- a/block/compat_ioctl.c
34466+++ b/block/compat_ioctl.c
34467@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34468 err |= __get_user(f->spec1, &uf->spec1);
34469 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34470 err |= __get_user(name, &uf->name);
34471- f->name = compat_ptr(name);
34472+ f->name = (void __force_kernel *)compat_ptr(name);
34473 if (err) {
34474 err = -EFAULT;
34475 goto out;
34476diff --git a/block/genhd.c b/block/genhd.c
34477index 791f419..89f21c4 100644
34478--- a/block/genhd.c
34479+++ b/block/genhd.c
34480@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34481
34482 /*
34483 * Register device numbers dev..(dev+range-1)
34484- * range must be nonzero
34485+ * Noop if @range is zero.
34486 * The hash chain is sorted on range, so that subranges can override.
34487 */
34488 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34489 struct kobject *(*probe)(dev_t, int *, void *),
34490 int (*lock)(dev_t, void *), void *data)
34491 {
34492- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34493+ if (range)
34494+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34495 }
34496
34497 EXPORT_SYMBOL(blk_register_region);
34498
34499+/* undo blk_register_region(), noop if @range is zero */
34500 void blk_unregister_region(dev_t devt, unsigned long range)
34501 {
34502- kobj_unmap(bdev_map, devt, range);
34503+ if (range)
34504+ kobj_unmap(bdev_map, devt, range);
34505 }
34506
34507 EXPORT_SYMBOL(blk_unregister_region);
34508diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34509index a8287b4..241a48e 100644
34510--- a/block/partitions/efi.c
34511+++ b/block/partitions/efi.c
34512@@ -292,14 +292,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34513 if (!gpt)
34514 return NULL;
34515
34516+ if (!le32_to_cpu(gpt->num_partition_entries))
34517+ return NULL;
34518+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34519+ if (!pte)
34520+ return NULL;
34521+
34522 count = le32_to_cpu(gpt->num_partition_entries) *
34523 le32_to_cpu(gpt->sizeof_partition_entry);
34524- if (!count)
34525- return NULL;
34526- pte = kmalloc(count, GFP_KERNEL);
34527- if (!pte)
34528- return NULL;
34529-
34530 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34531 (u8 *) pte, count) < count) {
34532 kfree(pte);
34533diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34534index a5ffcc9..e057498 100644
34535--- a/block/scsi_ioctl.c
34536+++ b/block/scsi_ioctl.c
34537@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
34538 return put_user(0, p);
34539 }
34540
34541-static int sg_get_timeout(struct request_queue *q)
34542+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
34543 {
34544 return jiffies_to_clock_t(q->sg_timeout);
34545 }
34546@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34547 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34548 struct sg_io_hdr *hdr, fmode_t mode)
34549 {
34550- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34551+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34552+ unsigned char *cmdptr;
34553+
34554+ if (rq->cmd != rq->__cmd)
34555+ cmdptr = rq->cmd;
34556+ else
34557+ cmdptr = tmpcmd;
34558+
34559+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34560 return -EFAULT;
34561+
34562+ if (cmdptr != rq->cmd)
34563+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34564+
34565 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34566 return -EPERM;
34567
34568@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34569 int err;
34570 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34571 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34572+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34573+ unsigned char *cmdptr;
34574
34575 if (!sic)
34576 return -EINVAL;
34577@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34578 */
34579 err = -EFAULT;
34580 rq->cmd_len = cmdlen;
34581- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34582+
34583+ if (rq->cmd != rq->__cmd)
34584+ cmdptr = rq->cmd;
34585+ else
34586+ cmdptr = tmpcmd;
34587+
34588+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34589 goto error;
34590
34591+ if (rq->cmd != cmdptr)
34592+ memcpy(rq->cmd, cmdptr, cmdlen);
34593+
34594 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34595 goto error;
34596
34597diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34598index 7bdd61b..afec999 100644
34599--- a/crypto/cryptd.c
34600+++ b/crypto/cryptd.c
34601@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34602
34603 struct cryptd_blkcipher_request_ctx {
34604 crypto_completion_t complete;
34605-};
34606+} __no_const;
34607
34608 struct cryptd_hash_ctx {
34609 struct crypto_shash *child;
34610@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34611
34612 struct cryptd_aead_request_ctx {
34613 crypto_completion_t complete;
34614-};
34615+} __no_const;
34616
34617 static void cryptd_queue_worker(struct work_struct *work);
34618
34619diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34620index f8c920c..ab2cb5a 100644
34621--- a/crypto/pcrypt.c
34622+++ b/crypto/pcrypt.c
34623@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34624 int ret;
34625
34626 pinst->kobj.kset = pcrypt_kset;
34627- ret = kobject_add(&pinst->kobj, NULL, name);
34628+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34629 if (!ret)
34630 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34631
34632diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34633index f220d64..d359ad6 100644
34634--- a/drivers/acpi/apei/apei-internal.h
34635+++ b/drivers/acpi/apei/apei-internal.h
34636@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34637 struct apei_exec_ins_type {
34638 u32 flags;
34639 apei_exec_ins_func_t run;
34640-};
34641+} __do_const;
34642
34643 struct apei_exec_context {
34644 u32 ip;
34645diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34646index 33dc6a0..4b24b47 100644
34647--- a/drivers/acpi/apei/cper.c
34648+++ b/drivers/acpi/apei/cper.c
34649@@ -39,12 +39,12 @@
34650 */
34651 u64 cper_next_record_id(void)
34652 {
34653- static atomic64_t seq;
34654+ static atomic64_unchecked_t seq;
34655
34656- if (!atomic64_read(&seq))
34657- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34658+ if (!atomic64_read_unchecked(&seq))
34659+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34660
34661- return atomic64_inc_return(&seq);
34662+ return atomic64_inc_return_unchecked(&seq);
34663 }
34664 EXPORT_SYMBOL_GPL(cper_next_record_id);
34665
34666diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34667index 8ec37bb..b0716e5 100644
34668--- a/drivers/acpi/apei/ghes.c
34669+++ b/drivers/acpi/apei/ghes.c
34670@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
34671 const struct acpi_hest_generic *generic,
34672 const struct acpi_hest_generic_status *estatus)
34673 {
34674- static atomic_t seqno;
34675+ static atomic_unchecked_t seqno;
34676 unsigned int curr_seqno;
34677 char pfx_seq[64];
34678
34679@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
34680 else
34681 pfx = KERN_ERR;
34682 }
34683- curr_seqno = atomic_inc_return(&seqno);
34684+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34685 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34686 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34687 pfx_seq, generic->header.source_id);
34688diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34689index a83e3c6..c3d617f 100644
34690--- a/drivers/acpi/bgrt.c
34691+++ b/drivers/acpi/bgrt.c
34692@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
34693 if (!bgrt_image)
34694 return -ENODEV;
34695
34696- bin_attr_image.private = bgrt_image;
34697- bin_attr_image.size = bgrt_image_size;
34698+ pax_open_kernel();
34699+ *(void **)&bin_attr_image.private = bgrt_image;
34700+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
34701+ pax_close_kernel();
34702
34703 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34704 if (!bgrt_kobj)
34705diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34706index 9515f18..4b149c9 100644
34707--- a/drivers/acpi/blacklist.c
34708+++ b/drivers/acpi/blacklist.c
34709@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34710 u32 is_critical_error;
34711 };
34712
34713-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34714+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34715
34716 /*
34717 * POLICY: If *anything* doesn't work, put it on the blacklist.
34718@@ -199,7 +199,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
34719 return 0;
34720 }
34721
34722-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34723+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34724 {
34725 .callback = dmi_disable_osi_vista,
34726 .ident = "Fujitsu Siemens",
34727diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34728index c7414a5..d5afd71 100644
34729--- a/drivers/acpi/processor_idle.c
34730+++ b/drivers/acpi/processor_idle.c
34731@@ -966,7 +966,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34732 {
34733 int i, count = CPUIDLE_DRIVER_STATE_START;
34734 struct acpi_processor_cx *cx;
34735- struct cpuidle_state *state;
34736+ cpuidle_state_no_const *state;
34737 struct cpuidle_driver *drv = &acpi_idle_driver;
34738
34739 if (!pr->flags.power_setup_done)
34740diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34741index 05306a5..733d1f0 100644
34742--- a/drivers/acpi/sysfs.c
34743+++ b/drivers/acpi/sysfs.c
34744@@ -423,11 +423,11 @@ static u32 num_counters;
34745 static struct attribute **all_attrs;
34746 static u32 acpi_gpe_count;
34747
34748-static struct attribute_group interrupt_stats_attr_group = {
34749+static attribute_group_no_const interrupt_stats_attr_group = {
34750 .name = "interrupts",
34751 };
34752
34753-static struct kobj_attribute *counter_attrs;
34754+static kobj_attribute_no_const *counter_attrs;
34755
34756 static void delete_gpe_attr_array(void)
34757 {
34758diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34759index aaac4fb..e325c00 100644
34760--- a/drivers/ata/libahci.c
34761+++ b/drivers/ata/libahci.c
34762@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
34763 }
34764 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34765
34766-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34767+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34768 struct ata_taskfile *tf, int is_cmd, u16 flags,
34769 unsigned long timeout_msec)
34770 {
34771diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34772index 83b1a9f..005b1ec 100644
34773--- a/drivers/ata/libata-core.c
34774+++ b/drivers/ata/libata-core.c
34775@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34776 static void ata_dev_xfermask(struct ata_device *dev);
34777 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34778
34779-atomic_t ata_print_id = ATOMIC_INIT(0);
34780+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34781
34782 struct ata_force_param {
34783 const char *name;
34784@@ -4808,7 +4808,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34785 struct ata_port *ap;
34786 unsigned int tag;
34787
34788- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34789+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34790 ap = qc->ap;
34791
34792 qc->flags = 0;
34793@@ -4824,7 +4824,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34794 struct ata_port *ap;
34795 struct ata_link *link;
34796
34797- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34798+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34799 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34800 ap = qc->ap;
34801 link = qc->dev->link;
34802@@ -5943,6 +5943,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34803 return;
34804
34805 spin_lock(&lock);
34806+ pax_open_kernel();
34807
34808 for (cur = ops->inherits; cur; cur = cur->inherits) {
34809 void **inherit = (void **)cur;
34810@@ -5956,8 +5957,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34811 if (IS_ERR(*pp))
34812 *pp = NULL;
34813
34814- ops->inherits = NULL;
34815+ *(struct ata_port_operations **)&ops->inherits = NULL;
34816
34817+ pax_close_kernel();
34818 spin_unlock(&lock);
34819 }
34820
34821@@ -6150,7 +6152,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34822
34823 /* give ports names and add SCSI hosts */
34824 for (i = 0; i < host->n_ports; i++) {
34825- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34826+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34827 host->ports[i]->local_port_no = i + 1;
34828 }
34829
34830diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34831index db6dfcf..770d1f0 100644
34832--- a/drivers/ata/libata-scsi.c
34833+++ b/drivers/ata/libata-scsi.c
34834@@ -4113,7 +4113,7 @@ int ata_sas_port_init(struct ata_port *ap)
34835
34836 if (rc)
34837 return rc;
34838- ap->print_id = atomic_inc_return(&ata_print_id);
34839+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34840 return 0;
34841 }
34842 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34843diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34844index 45b5ab3..98446b8 100644
34845--- a/drivers/ata/libata.h
34846+++ b/drivers/ata/libata.h
34847@@ -53,7 +53,7 @@ enum {
34848 ATA_DNXFER_QUIET = (1 << 31),
34849 };
34850
34851-extern atomic_t ata_print_id;
34852+extern atomic_unchecked_t ata_print_id;
34853 extern int atapi_passthru16;
34854 extern int libata_fua;
34855 extern int libata_noacpi;
34856diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34857index 853f610..97d24da 100644
34858--- a/drivers/ata/pata_arasan_cf.c
34859+++ b/drivers/ata/pata_arasan_cf.c
34860@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34861 /* Handle platform specific quirks */
34862 if (quirk) {
34863 if (quirk & CF_BROKEN_PIO) {
34864- ap->ops->set_piomode = NULL;
34865+ pax_open_kernel();
34866+ *(void **)&ap->ops->set_piomode = NULL;
34867+ pax_close_kernel();
34868 ap->pio_mask = 0;
34869 }
34870 if (quirk & CF_BROKEN_MWDMA)
34871diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34872index f9b983a..887b9d8 100644
34873--- a/drivers/atm/adummy.c
34874+++ b/drivers/atm/adummy.c
34875@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34876 vcc->pop(vcc, skb);
34877 else
34878 dev_kfree_skb_any(skb);
34879- atomic_inc(&vcc->stats->tx);
34880+ atomic_inc_unchecked(&vcc->stats->tx);
34881
34882 return 0;
34883 }
34884diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34885index 62a7607..cc4be104 100644
34886--- a/drivers/atm/ambassador.c
34887+++ b/drivers/atm/ambassador.c
34888@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34889 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34890
34891 // VC layer stats
34892- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34893+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34894
34895 // free the descriptor
34896 kfree (tx_descr);
34897@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34898 dump_skb ("<<<", vc, skb);
34899
34900 // VC layer stats
34901- atomic_inc(&atm_vcc->stats->rx);
34902+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34903 __net_timestamp(skb);
34904 // end of our responsibility
34905 atm_vcc->push (atm_vcc, skb);
34906@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34907 } else {
34908 PRINTK (KERN_INFO, "dropped over-size frame");
34909 // should we count this?
34910- atomic_inc(&atm_vcc->stats->rx_drop);
34911+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34912 }
34913
34914 } else {
34915@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34916 }
34917
34918 if (check_area (skb->data, skb->len)) {
34919- atomic_inc(&atm_vcc->stats->tx_err);
34920+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34921 return -ENOMEM; // ?
34922 }
34923
34924diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34925index 0e3f8f9..765a7a5 100644
34926--- a/drivers/atm/atmtcp.c
34927+++ b/drivers/atm/atmtcp.c
34928@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34929 if (vcc->pop) vcc->pop(vcc,skb);
34930 else dev_kfree_skb(skb);
34931 if (dev_data) return 0;
34932- atomic_inc(&vcc->stats->tx_err);
34933+ atomic_inc_unchecked(&vcc->stats->tx_err);
34934 return -ENOLINK;
34935 }
34936 size = skb->len+sizeof(struct atmtcp_hdr);
34937@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34938 if (!new_skb) {
34939 if (vcc->pop) vcc->pop(vcc,skb);
34940 else dev_kfree_skb(skb);
34941- atomic_inc(&vcc->stats->tx_err);
34942+ atomic_inc_unchecked(&vcc->stats->tx_err);
34943 return -ENOBUFS;
34944 }
34945 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34946@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34947 if (vcc->pop) vcc->pop(vcc,skb);
34948 else dev_kfree_skb(skb);
34949 out_vcc->push(out_vcc,new_skb);
34950- atomic_inc(&vcc->stats->tx);
34951- atomic_inc(&out_vcc->stats->rx);
34952+ atomic_inc_unchecked(&vcc->stats->tx);
34953+ atomic_inc_unchecked(&out_vcc->stats->rx);
34954 return 0;
34955 }
34956
34957@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34958 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34959 read_unlock(&vcc_sklist_lock);
34960 if (!out_vcc) {
34961- atomic_inc(&vcc->stats->tx_err);
34962+ atomic_inc_unchecked(&vcc->stats->tx_err);
34963 goto done;
34964 }
34965 skb_pull(skb,sizeof(struct atmtcp_hdr));
34966@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34967 __net_timestamp(new_skb);
34968 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34969 out_vcc->push(out_vcc,new_skb);
34970- atomic_inc(&vcc->stats->tx);
34971- atomic_inc(&out_vcc->stats->rx);
34972+ atomic_inc_unchecked(&vcc->stats->tx);
34973+ atomic_inc_unchecked(&out_vcc->stats->rx);
34974 done:
34975 if (vcc->pop) vcc->pop(vcc,skb);
34976 else dev_kfree_skb(skb);
34977diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34978index b1955ba..b179940 100644
34979--- a/drivers/atm/eni.c
34980+++ b/drivers/atm/eni.c
34981@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34982 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34983 vcc->dev->number);
34984 length = 0;
34985- atomic_inc(&vcc->stats->rx_err);
34986+ atomic_inc_unchecked(&vcc->stats->rx_err);
34987 }
34988 else {
34989 length = ATM_CELL_SIZE-1; /* no HEC */
34990@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34991 size);
34992 }
34993 eff = length = 0;
34994- atomic_inc(&vcc->stats->rx_err);
34995+ atomic_inc_unchecked(&vcc->stats->rx_err);
34996 }
34997 else {
34998 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34999@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35000 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35001 vcc->dev->number,vcc->vci,length,size << 2,descr);
35002 length = eff = 0;
35003- atomic_inc(&vcc->stats->rx_err);
35004+ atomic_inc_unchecked(&vcc->stats->rx_err);
35005 }
35006 }
35007 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35008@@ -767,7 +767,7 @@ rx_dequeued++;
35009 vcc->push(vcc,skb);
35010 pushed++;
35011 }
35012- atomic_inc(&vcc->stats->rx);
35013+ atomic_inc_unchecked(&vcc->stats->rx);
35014 }
35015 wake_up(&eni_dev->rx_wait);
35016 }
35017@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35018 PCI_DMA_TODEVICE);
35019 if (vcc->pop) vcc->pop(vcc,skb);
35020 else dev_kfree_skb_irq(skb);
35021- atomic_inc(&vcc->stats->tx);
35022+ atomic_inc_unchecked(&vcc->stats->tx);
35023 wake_up(&eni_dev->tx_wait);
35024 dma_complete++;
35025 }
35026diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35027index b41c948..a002b17 100644
35028--- a/drivers/atm/firestream.c
35029+++ b/drivers/atm/firestream.c
35030@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35031 }
35032 }
35033
35034- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35035+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35036
35037 fs_dprintk (FS_DEBUG_TXMEM, "i");
35038 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35039@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35040 #endif
35041 skb_put (skb, qe->p1 & 0xffff);
35042 ATM_SKB(skb)->vcc = atm_vcc;
35043- atomic_inc(&atm_vcc->stats->rx);
35044+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35045 __net_timestamp(skb);
35046 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35047 atm_vcc->push (atm_vcc, skb);
35048@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35049 kfree (pe);
35050 }
35051 if (atm_vcc)
35052- atomic_inc(&atm_vcc->stats->rx_drop);
35053+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35054 break;
35055 case 0x1f: /* Reassembly abort: no buffers. */
35056 /* Silently increment error counter. */
35057 if (atm_vcc)
35058- atomic_inc(&atm_vcc->stats->rx_drop);
35059+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35060 break;
35061 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35062 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35063diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35064index 204814e..cede831 100644
35065--- a/drivers/atm/fore200e.c
35066+++ b/drivers/atm/fore200e.c
35067@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35068 #endif
35069 /* check error condition */
35070 if (*entry->status & STATUS_ERROR)
35071- atomic_inc(&vcc->stats->tx_err);
35072+ atomic_inc_unchecked(&vcc->stats->tx_err);
35073 else
35074- atomic_inc(&vcc->stats->tx);
35075+ atomic_inc_unchecked(&vcc->stats->tx);
35076 }
35077 }
35078
35079@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35080 if (skb == NULL) {
35081 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35082
35083- atomic_inc(&vcc->stats->rx_drop);
35084+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35085 return -ENOMEM;
35086 }
35087
35088@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35089
35090 dev_kfree_skb_any(skb);
35091
35092- atomic_inc(&vcc->stats->rx_drop);
35093+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35094 return -ENOMEM;
35095 }
35096
35097 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35098
35099 vcc->push(vcc, skb);
35100- atomic_inc(&vcc->stats->rx);
35101+ atomic_inc_unchecked(&vcc->stats->rx);
35102
35103 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35104
35105@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35106 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35107 fore200e->atm_dev->number,
35108 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35109- atomic_inc(&vcc->stats->rx_err);
35110+ atomic_inc_unchecked(&vcc->stats->rx_err);
35111 }
35112 }
35113
35114@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35115 goto retry_here;
35116 }
35117
35118- atomic_inc(&vcc->stats->tx_err);
35119+ atomic_inc_unchecked(&vcc->stats->tx_err);
35120
35121 fore200e->tx_sat++;
35122 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35123diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35124index 8557adc..3fb5d55 100644
35125--- a/drivers/atm/he.c
35126+++ b/drivers/atm/he.c
35127@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35128
35129 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35130 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35131- atomic_inc(&vcc->stats->rx_drop);
35132+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35133 goto return_host_buffers;
35134 }
35135
35136@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35137 RBRQ_LEN_ERR(he_dev->rbrq_head)
35138 ? "LEN_ERR" : "",
35139 vcc->vpi, vcc->vci);
35140- atomic_inc(&vcc->stats->rx_err);
35141+ atomic_inc_unchecked(&vcc->stats->rx_err);
35142 goto return_host_buffers;
35143 }
35144
35145@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35146 vcc->push(vcc, skb);
35147 spin_lock(&he_dev->global_lock);
35148
35149- atomic_inc(&vcc->stats->rx);
35150+ atomic_inc_unchecked(&vcc->stats->rx);
35151
35152 return_host_buffers:
35153 ++pdus_assembled;
35154@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35155 tpd->vcc->pop(tpd->vcc, tpd->skb);
35156 else
35157 dev_kfree_skb_any(tpd->skb);
35158- atomic_inc(&tpd->vcc->stats->tx_err);
35159+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35160 }
35161 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35162 return;
35163@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35164 vcc->pop(vcc, skb);
35165 else
35166 dev_kfree_skb_any(skb);
35167- atomic_inc(&vcc->stats->tx_err);
35168+ atomic_inc_unchecked(&vcc->stats->tx_err);
35169 return -EINVAL;
35170 }
35171
35172@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35173 vcc->pop(vcc, skb);
35174 else
35175 dev_kfree_skb_any(skb);
35176- atomic_inc(&vcc->stats->tx_err);
35177+ atomic_inc_unchecked(&vcc->stats->tx_err);
35178 return -EINVAL;
35179 }
35180 #endif
35181@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35182 vcc->pop(vcc, skb);
35183 else
35184 dev_kfree_skb_any(skb);
35185- atomic_inc(&vcc->stats->tx_err);
35186+ atomic_inc_unchecked(&vcc->stats->tx_err);
35187 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35188 return -ENOMEM;
35189 }
35190@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35191 vcc->pop(vcc, skb);
35192 else
35193 dev_kfree_skb_any(skb);
35194- atomic_inc(&vcc->stats->tx_err);
35195+ atomic_inc_unchecked(&vcc->stats->tx_err);
35196 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35197 return -ENOMEM;
35198 }
35199@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35200 __enqueue_tpd(he_dev, tpd, cid);
35201 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35202
35203- atomic_inc(&vcc->stats->tx);
35204+ atomic_inc_unchecked(&vcc->stats->tx);
35205
35206 return 0;
35207 }
35208diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35209index 1dc0519..1aadaf7 100644
35210--- a/drivers/atm/horizon.c
35211+++ b/drivers/atm/horizon.c
35212@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35213 {
35214 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35215 // VC layer stats
35216- atomic_inc(&vcc->stats->rx);
35217+ atomic_inc_unchecked(&vcc->stats->rx);
35218 __net_timestamp(skb);
35219 // end of our responsibility
35220 vcc->push (vcc, skb);
35221@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35222 dev->tx_iovec = NULL;
35223
35224 // VC layer stats
35225- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35226+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35227
35228 // free the skb
35229 hrz_kfree_skb (skb);
35230diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35231index 272f009..a18ba55 100644
35232--- a/drivers/atm/idt77252.c
35233+++ b/drivers/atm/idt77252.c
35234@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35235 else
35236 dev_kfree_skb(skb);
35237
35238- atomic_inc(&vcc->stats->tx);
35239+ atomic_inc_unchecked(&vcc->stats->tx);
35240 }
35241
35242 atomic_dec(&scq->used);
35243@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35244 if ((sb = dev_alloc_skb(64)) == NULL) {
35245 printk("%s: Can't allocate buffers for aal0.\n",
35246 card->name);
35247- atomic_add(i, &vcc->stats->rx_drop);
35248+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35249 break;
35250 }
35251 if (!atm_charge(vcc, sb->truesize)) {
35252 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35253 card->name);
35254- atomic_add(i - 1, &vcc->stats->rx_drop);
35255+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35256 dev_kfree_skb(sb);
35257 break;
35258 }
35259@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35260 ATM_SKB(sb)->vcc = vcc;
35261 __net_timestamp(sb);
35262 vcc->push(vcc, sb);
35263- atomic_inc(&vcc->stats->rx);
35264+ atomic_inc_unchecked(&vcc->stats->rx);
35265
35266 cell += ATM_CELL_PAYLOAD;
35267 }
35268@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35269 "(CDC: %08x)\n",
35270 card->name, len, rpp->len, readl(SAR_REG_CDC));
35271 recycle_rx_pool_skb(card, rpp);
35272- atomic_inc(&vcc->stats->rx_err);
35273+ atomic_inc_unchecked(&vcc->stats->rx_err);
35274 return;
35275 }
35276 if (stat & SAR_RSQE_CRC) {
35277 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35278 recycle_rx_pool_skb(card, rpp);
35279- atomic_inc(&vcc->stats->rx_err);
35280+ atomic_inc_unchecked(&vcc->stats->rx_err);
35281 return;
35282 }
35283 if (skb_queue_len(&rpp->queue) > 1) {
35284@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35285 RXPRINTK("%s: Can't alloc RX skb.\n",
35286 card->name);
35287 recycle_rx_pool_skb(card, rpp);
35288- atomic_inc(&vcc->stats->rx_err);
35289+ atomic_inc_unchecked(&vcc->stats->rx_err);
35290 return;
35291 }
35292 if (!atm_charge(vcc, skb->truesize)) {
35293@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35294 __net_timestamp(skb);
35295
35296 vcc->push(vcc, skb);
35297- atomic_inc(&vcc->stats->rx);
35298+ atomic_inc_unchecked(&vcc->stats->rx);
35299
35300 return;
35301 }
35302@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35303 __net_timestamp(skb);
35304
35305 vcc->push(vcc, skb);
35306- atomic_inc(&vcc->stats->rx);
35307+ atomic_inc_unchecked(&vcc->stats->rx);
35308
35309 if (skb->truesize > SAR_FB_SIZE_3)
35310 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35311@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35312 if (vcc->qos.aal != ATM_AAL0) {
35313 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35314 card->name, vpi, vci);
35315- atomic_inc(&vcc->stats->rx_drop);
35316+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35317 goto drop;
35318 }
35319
35320 if ((sb = dev_alloc_skb(64)) == NULL) {
35321 printk("%s: Can't allocate buffers for AAL0.\n",
35322 card->name);
35323- atomic_inc(&vcc->stats->rx_err);
35324+ atomic_inc_unchecked(&vcc->stats->rx_err);
35325 goto drop;
35326 }
35327
35328@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35329 ATM_SKB(sb)->vcc = vcc;
35330 __net_timestamp(sb);
35331 vcc->push(vcc, sb);
35332- atomic_inc(&vcc->stats->rx);
35333+ atomic_inc_unchecked(&vcc->stats->rx);
35334
35335 drop:
35336 skb_pull(queue, 64);
35337@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35338
35339 if (vc == NULL) {
35340 printk("%s: NULL connection in send().\n", card->name);
35341- atomic_inc(&vcc->stats->tx_err);
35342+ atomic_inc_unchecked(&vcc->stats->tx_err);
35343 dev_kfree_skb(skb);
35344 return -EINVAL;
35345 }
35346 if (!test_bit(VCF_TX, &vc->flags)) {
35347 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35348- atomic_inc(&vcc->stats->tx_err);
35349+ atomic_inc_unchecked(&vcc->stats->tx_err);
35350 dev_kfree_skb(skb);
35351 return -EINVAL;
35352 }
35353@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35354 break;
35355 default:
35356 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35357- atomic_inc(&vcc->stats->tx_err);
35358+ atomic_inc_unchecked(&vcc->stats->tx_err);
35359 dev_kfree_skb(skb);
35360 return -EINVAL;
35361 }
35362
35363 if (skb_shinfo(skb)->nr_frags != 0) {
35364 printk("%s: No scatter-gather yet.\n", card->name);
35365- atomic_inc(&vcc->stats->tx_err);
35366+ atomic_inc_unchecked(&vcc->stats->tx_err);
35367 dev_kfree_skb(skb);
35368 return -EINVAL;
35369 }
35370@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35371
35372 err = queue_skb(card, vc, skb, oam);
35373 if (err) {
35374- atomic_inc(&vcc->stats->tx_err);
35375+ atomic_inc_unchecked(&vcc->stats->tx_err);
35376 dev_kfree_skb(skb);
35377 return err;
35378 }
35379@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35380 skb = dev_alloc_skb(64);
35381 if (!skb) {
35382 printk("%s: Out of memory in send_oam().\n", card->name);
35383- atomic_inc(&vcc->stats->tx_err);
35384+ atomic_inc_unchecked(&vcc->stats->tx_err);
35385 return -ENOMEM;
35386 }
35387 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35388diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35389index 4217f29..88f547a 100644
35390--- a/drivers/atm/iphase.c
35391+++ b/drivers/atm/iphase.c
35392@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35393 status = (u_short) (buf_desc_ptr->desc_mode);
35394 if (status & (RX_CER | RX_PTE | RX_OFL))
35395 {
35396- atomic_inc(&vcc->stats->rx_err);
35397+ atomic_inc_unchecked(&vcc->stats->rx_err);
35398 IF_ERR(printk("IA: bad packet, dropping it");)
35399 if (status & RX_CER) {
35400 IF_ERR(printk(" cause: packet CRC error\n");)
35401@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35402 len = dma_addr - buf_addr;
35403 if (len > iadev->rx_buf_sz) {
35404 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35405- atomic_inc(&vcc->stats->rx_err);
35406+ atomic_inc_unchecked(&vcc->stats->rx_err);
35407 goto out_free_desc;
35408 }
35409
35410@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35411 ia_vcc = INPH_IA_VCC(vcc);
35412 if (ia_vcc == NULL)
35413 {
35414- atomic_inc(&vcc->stats->rx_err);
35415+ atomic_inc_unchecked(&vcc->stats->rx_err);
35416 atm_return(vcc, skb->truesize);
35417 dev_kfree_skb_any(skb);
35418 goto INCR_DLE;
35419@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35420 if ((length > iadev->rx_buf_sz) || (length >
35421 (skb->len - sizeof(struct cpcs_trailer))))
35422 {
35423- atomic_inc(&vcc->stats->rx_err);
35424+ atomic_inc_unchecked(&vcc->stats->rx_err);
35425 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35426 length, skb->len);)
35427 atm_return(vcc, skb->truesize);
35428@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35429
35430 IF_RX(printk("rx_dle_intr: skb push");)
35431 vcc->push(vcc,skb);
35432- atomic_inc(&vcc->stats->rx);
35433+ atomic_inc_unchecked(&vcc->stats->rx);
35434 iadev->rx_pkt_cnt++;
35435 }
35436 INCR_DLE:
35437@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35438 {
35439 struct k_sonet_stats *stats;
35440 stats = &PRIV(_ia_dev[board])->sonet_stats;
35441- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35442- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35443- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35444- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35445- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35446- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35447- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35448- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35449- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35450+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35451+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35452+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35453+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35454+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35455+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35456+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35457+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35458+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35459 }
35460 ia_cmds.status = 0;
35461 break;
35462@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35463 if ((desc == 0) || (desc > iadev->num_tx_desc))
35464 {
35465 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35466- atomic_inc(&vcc->stats->tx);
35467+ atomic_inc_unchecked(&vcc->stats->tx);
35468 if (vcc->pop)
35469 vcc->pop(vcc, skb);
35470 else
35471@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35472 ATM_DESC(skb) = vcc->vci;
35473 skb_queue_tail(&iadev->tx_dma_q, skb);
35474
35475- atomic_inc(&vcc->stats->tx);
35476+ atomic_inc_unchecked(&vcc->stats->tx);
35477 iadev->tx_pkt_cnt++;
35478 /* Increment transaction counter */
35479 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35480
35481 #if 0
35482 /* add flow control logic */
35483- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35484+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35485 if (iavcc->vc_desc_cnt > 10) {
35486 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35487 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35488diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35489index fa7d701..1e404c7 100644
35490--- a/drivers/atm/lanai.c
35491+++ b/drivers/atm/lanai.c
35492@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35493 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35494 lanai_endtx(lanai, lvcc);
35495 lanai_free_skb(lvcc->tx.atmvcc, skb);
35496- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35497+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35498 }
35499
35500 /* Try to fill the buffer - don't call unless there is backlog */
35501@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35502 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35503 __net_timestamp(skb);
35504 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35505- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35506+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35507 out:
35508 lvcc->rx.buf.ptr = end;
35509 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35510@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35511 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35512 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35513 lanai->stats.service_rxnotaal5++;
35514- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35515+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35516 return 0;
35517 }
35518 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35519@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35520 int bytes;
35521 read_unlock(&vcc_sklist_lock);
35522 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35523- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35524+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35525 lvcc->stats.x.aal5.service_trash++;
35526 bytes = (SERVICE_GET_END(s) * 16) -
35527 (((unsigned long) lvcc->rx.buf.ptr) -
35528@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35529 }
35530 if (s & SERVICE_STREAM) {
35531 read_unlock(&vcc_sklist_lock);
35532- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35533+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35534 lvcc->stats.x.aal5.service_stream++;
35535 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35536 "PDU on VCI %d!\n", lanai->number, vci);
35537@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35538 return 0;
35539 }
35540 DPRINTK("got rx crc error on vci %d\n", vci);
35541- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35542+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35543 lvcc->stats.x.aal5.service_rxcrc++;
35544 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35545 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35546diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35547index 5aca5f4..ce3a6b0 100644
35548--- a/drivers/atm/nicstar.c
35549+++ b/drivers/atm/nicstar.c
35550@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35551 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35552 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35553 card->index);
35554- atomic_inc(&vcc->stats->tx_err);
35555+ atomic_inc_unchecked(&vcc->stats->tx_err);
35556 dev_kfree_skb_any(skb);
35557 return -EINVAL;
35558 }
35559@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35560 if (!vc->tx) {
35561 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35562 card->index);
35563- atomic_inc(&vcc->stats->tx_err);
35564+ atomic_inc_unchecked(&vcc->stats->tx_err);
35565 dev_kfree_skb_any(skb);
35566 return -EINVAL;
35567 }
35568@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35569 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35570 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35571 card->index);
35572- atomic_inc(&vcc->stats->tx_err);
35573+ atomic_inc_unchecked(&vcc->stats->tx_err);
35574 dev_kfree_skb_any(skb);
35575 return -EINVAL;
35576 }
35577
35578 if (skb_shinfo(skb)->nr_frags != 0) {
35579 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35580- atomic_inc(&vcc->stats->tx_err);
35581+ atomic_inc_unchecked(&vcc->stats->tx_err);
35582 dev_kfree_skb_any(skb);
35583 return -EINVAL;
35584 }
35585@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35586 }
35587
35588 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35589- atomic_inc(&vcc->stats->tx_err);
35590+ atomic_inc_unchecked(&vcc->stats->tx_err);
35591 dev_kfree_skb_any(skb);
35592 return -EIO;
35593 }
35594- atomic_inc(&vcc->stats->tx);
35595+ atomic_inc_unchecked(&vcc->stats->tx);
35596
35597 return 0;
35598 }
35599@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35600 printk
35601 ("nicstar%d: Can't allocate buffers for aal0.\n",
35602 card->index);
35603- atomic_add(i, &vcc->stats->rx_drop);
35604+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35605 break;
35606 }
35607 if (!atm_charge(vcc, sb->truesize)) {
35608 RXPRINTK
35609 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35610 card->index);
35611- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35612+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35613 dev_kfree_skb_any(sb);
35614 break;
35615 }
35616@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35617 ATM_SKB(sb)->vcc = vcc;
35618 __net_timestamp(sb);
35619 vcc->push(vcc, sb);
35620- atomic_inc(&vcc->stats->rx);
35621+ atomic_inc_unchecked(&vcc->stats->rx);
35622 cell += ATM_CELL_PAYLOAD;
35623 }
35624
35625@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35626 if (iovb == NULL) {
35627 printk("nicstar%d: Out of iovec buffers.\n",
35628 card->index);
35629- atomic_inc(&vcc->stats->rx_drop);
35630+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35631 recycle_rx_buf(card, skb);
35632 return;
35633 }
35634@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35635 small or large buffer itself. */
35636 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35637 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35638- atomic_inc(&vcc->stats->rx_err);
35639+ atomic_inc_unchecked(&vcc->stats->rx_err);
35640 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35641 NS_MAX_IOVECS);
35642 NS_PRV_IOVCNT(iovb) = 0;
35643@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35644 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35645 card->index);
35646 which_list(card, skb);
35647- atomic_inc(&vcc->stats->rx_err);
35648+ atomic_inc_unchecked(&vcc->stats->rx_err);
35649 recycle_rx_buf(card, skb);
35650 vc->rx_iov = NULL;
35651 recycle_iov_buf(card, iovb);
35652@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35653 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35654 card->index);
35655 which_list(card, skb);
35656- atomic_inc(&vcc->stats->rx_err);
35657+ atomic_inc_unchecked(&vcc->stats->rx_err);
35658 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35659 NS_PRV_IOVCNT(iovb));
35660 vc->rx_iov = NULL;
35661@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35662 printk(" - PDU size mismatch.\n");
35663 else
35664 printk(".\n");
35665- atomic_inc(&vcc->stats->rx_err);
35666+ atomic_inc_unchecked(&vcc->stats->rx_err);
35667 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35668 NS_PRV_IOVCNT(iovb));
35669 vc->rx_iov = NULL;
35670@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35671 /* skb points to a small buffer */
35672 if (!atm_charge(vcc, skb->truesize)) {
35673 push_rxbufs(card, skb);
35674- atomic_inc(&vcc->stats->rx_drop);
35675+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35676 } else {
35677 skb_put(skb, len);
35678 dequeue_sm_buf(card, skb);
35679@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35680 ATM_SKB(skb)->vcc = vcc;
35681 __net_timestamp(skb);
35682 vcc->push(vcc, skb);
35683- atomic_inc(&vcc->stats->rx);
35684+ atomic_inc_unchecked(&vcc->stats->rx);
35685 }
35686 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35687 struct sk_buff *sb;
35688@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35689 if (len <= NS_SMBUFSIZE) {
35690 if (!atm_charge(vcc, sb->truesize)) {
35691 push_rxbufs(card, sb);
35692- atomic_inc(&vcc->stats->rx_drop);
35693+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35694 } else {
35695 skb_put(sb, len);
35696 dequeue_sm_buf(card, sb);
35697@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35698 ATM_SKB(sb)->vcc = vcc;
35699 __net_timestamp(sb);
35700 vcc->push(vcc, sb);
35701- atomic_inc(&vcc->stats->rx);
35702+ atomic_inc_unchecked(&vcc->stats->rx);
35703 }
35704
35705 push_rxbufs(card, skb);
35706@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35707
35708 if (!atm_charge(vcc, skb->truesize)) {
35709 push_rxbufs(card, skb);
35710- atomic_inc(&vcc->stats->rx_drop);
35711+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35712 } else {
35713 dequeue_lg_buf(card, skb);
35714 #ifdef NS_USE_DESTRUCTORS
35715@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35716 ATM_SKB(skb)->vcc = vcc;
35717 __net_timestamp(skb);
35718 vcc->push(vcc, skb);
35719- atomic_inc(&vcc->stats->rx);
35720+ atomic_inc_unchecked(&vcc->stats->rx);
35721 }
35722
35723 push_rxbufs(card, sb);
35724@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35725 printk
35726 ("nicstar%d: Out of huge buffers.\n",
35727 card->index);
35728- atomic_inc(&vcc->stats->rx_drop);
35729+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35730 recycle_iovec_rx_bufs(card,
35731 (struct iovec *)
35732 iovb->data,
35733@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35734 card->hbpool.count++;
35735 } else
35736 dev_kfree_skb_any(hb);
35737- atomic_inc(&vcc->stats->rx_drop);
35738+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35739 } else {
35740 /* Copy the small buffer to the huge buffer */
35741 sb = (struct sk_buff *)iov->iov_base;
35742@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35743 #endif /* NS_USE_DESTRUCTORS */
35744 __net_timestamp(hb);
35745 vcc->push(vcc, hb);
35746- atomic_inc(&vcc->stats->rx);
35747+ atomic_inc_unchecked(&vcc->stats->rx);
35748 }
35749 }
35750
35751diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35752index 32784d1..4a8434a 100644
35753--- a/drivers/atm/solos-pci.c
35754+++ b/drivers/atm/solos-pci.c
35755@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35756 }
35757 atm_charge(vcc, skb->truesize);
35758 vcc->push(vcc, skb);
35759- atomic_inc(&vcc->stats->rx);
35760+ atomic_inc_unchecked(&vcc->stats->rx);
35761 break;
35762
35763 case PKT_STATUS:
35764@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35765 vcc = SKB_CB(oldskb)->vcc;
35766
35767 if (vcc) {
35768- atomic_inc(&vcc->stats->tx);
35769+ atomic_inc_unchecked(&vcc->stats->tx);
35770 solos_pop(vcc, oldskb);
35771 } else {
35772 dev_kfree_skb_irq(oldskb);
35773diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35774index 0215934..ce9f5b1 100644
35775--- a/drivers/atm/suni.c
35776+++ b/drivers/atm/suni.c
35777@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35778
35779
35780 #define ADD_LIMITED(s,v) \
35781- atomic_add((v),&stats->s); \
35782- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35783+ atomic_add_unchecked((v),&stats->s); \
35784+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35785
35786
35787 static void suni_hz(unsigned long from_timer)
35788diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35789index 5120a96..e2572bd 100644
35790--- a/drivers/atm/uPD98402.c
35791+++ b/drivers/atm/uPD98402.c
35792@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35793 struct sonet_stats tmp;
35794 int error = 0;
35795
35796- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35797+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35798 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35799 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35800 if (zero && !error) {
35801@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35802
35803
35804 #define ADD_LIMITED(s,v) \
35805- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35806- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35807- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35808+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35809+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35810+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35811
35812
35813 static void stat_event(struct atm_dev *dev)
35814@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35815 if (reason & uPD98402_INT_PFM) stat_event(dev);
35816 if (reason & uPD98402_INT_PCO) {
35817 (void) GET(PCOCR); /* clear interrupt cause */
35818- atomic_add(GET(HECCT),
35819+ atomic_add_unchecked(GET(HECCT),
35820 &PRIV(dev)->sonet_stats.uncorr_hcs);
35821 }
35822 if ((reason & uPD98402_INT_RFO) &&
35823@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35824 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35825 uPD98402_INT_LOS),PIMR); /* enable them */
35826 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35827- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35828- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35829- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35830+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35831+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35832+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35833 return 0;
35834 }
35835
35836diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35837index 969c3c2..9b72956 100644
35838--- a/drivers/atm/zatm.c
35839+++ b/drivers/atm/zatm.c
35840@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35841 }
35842 if (!size) {
35843 dev_kfree_skb_irq(skb);
35844- if (vcc) atomic_inc(&vcc->stats->rx_err);
35845+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35846 continue;
35847 }
35848 if (!atm_charge(vcc,skb->truesize)) {
35849@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35850 skb->len = size;
35851 ATM_SKB(skb)->vcc = vcc;
35852 vcc->push(vcc,skb);
35853- atomic_inc(&vcc->stats->rx);
35854+ atomic_inc_unchecked(&vcc->stats->rx);
35855 }
35856 zout(pos & 0xffff,MTA(mbx));
35857 #if 0 /* probably a stupid idea */
35858@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35859 skb_queue_head(&zatm_vcc->backlog,skb);
35860 break;
35861 }
35862- atomic_inc(&vcc->stats->tx);
35863+ atomic_inc_unchecked(&vcc->stats->tx);
35864 wake_up(&zatm_vcc->tx_wait);
35865 }
35866
35867diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35868index 4c289ab..de1c333 100644
35869--- a/drivers/base/bus.c
35870+++ b/drivers/base/bus.c
35871@@ -1193,7 +1193,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35872 return -EINVAL;
35873
35874 mutex_lock(&subsys->p->mutex);
35875- list_add_tail(&sif->node, &subsys->p->interfaces);
35876+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35877 if (sif->add_dev) {
35878 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35879 while ((dev = subsys_dev_iter_next(&iter)))
35880@@ -1218,7 +1218,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35881 subsys = sif->subsys;
35882
35883 mutex_lock(&subsys->p->mutex);
35884- list_del_init(&sif->node);
35885+ pax_list_del_init((struct list_head *)&sif->node);
35886 if (sif->remove_dev) {
35887 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35888 while ((dev = subsys_dev_iter_next(&iter)))
35889diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35890index 7413d06..79155fa 100644
35891--- a/drivers/base/devtmpfs.c
35892+++ b/drivers/base/devtmpfs.c
35893@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35894 if (!thread)
35895 return 0;
35896
35897- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35898+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35899 if (err)
35900 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35901 else
35902@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35903 *err = sys_unshare(CLONE_NEWNS);
35904 if (*err)
35905 goto out;
35906- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35907+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35908 if (*err)
35909 goto out;
35910- sys_chdir("/.."); /* will traverse into overmounted root */
35911- sys_chroot(".");
35912+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35913+ sys_chroot((char __force_user *)".");
35914 complete(&setup_done);
35915 while (1) {
35916 spin_lock(&req_lock);
35917diff --git a/drivers/base/node.c b/drivers/base/node.c
35918index bc9f43b..29703b8 100644
35919--- a/drivers/base/node.c
35920+++ b/drivers/base/node.c
35921@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35922 struct node_attr {
35923 struct device_attribute attr;
35924 enum node_states state;
35925-};
35926+} __do_const;
35927
35928 static ssize_t show_node_state(struct device *dev,
35929 struct device_attribute *attr, char *buf)
35930diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35931index bfb8955..42c9b9a 100644
35932--- a/drivers/base/power/domain.c
35933+++ b/drivers/base/power/domain.c
35934@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35935 {
35936 struct cpuidle_driver *cpuidle_drv;
35937 struct gpd_cpu_data *cpu_data;
35938- struct cpuidle_state *idle_state;
35939+ cpuidle_state_no_const *idle_state;
35940 int ret = 0;
35941
35942 if (IS_ERR_OR_NULL(genpd) || state < 0)
35943@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35944 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35945 {
35946 struct gpd_cpu_data *cpu_data;
35947- struct cpuidle_state *idle_state;
35948+ cpuidle_state_no_const *idle_state;
35949 int ret = 0;
35950
35951 if (IS_ERR_OR_NULL(genpd))
35952diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35953index 03e089a..0e9560c 100644
35954--- a/drivers/base/power/sysfs.c
35955+++ b/drivers/base/power/sysfs.c
35956@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35957 return -EIO;
35958 }
35959 }
35960- return sprintf(buf, p);
35961+ return sprintf(buf, "%s", p);
35962 }
35963
35964 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35965diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35966index 2d56f41..8830f19 100644
35967--- a/drivers/base/power/wakeup.c
35968+++ b/drivers/base/power/wakeup.c
35969@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35970 * They need to be modified together atomically, so it's better to use one
35971 * atomic variable to hold them both.
35972 */
35973-static atomic_t combined_event_count = ATOMIC_INIT(0);
35974+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35975
35976 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35977 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35978
35979 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35980 {
35981- unsigned int comb = atomic_read(&combined_event_count);
35982+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35983
35984 *cnt = (comb >> IN_PROGRESS_BITS);
35985 *inpr = comb & MAX_IN_PROGRESS;
35986@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35987 ws->start_prevent_time = ws->last_time;
35988
35989 /* Increment the counter of events in progress. */
35990- cec = atomic_inc_return(&combined_event_count);
35991+ cec = atomic_inc_return_unchecked(&combined_event_count);
35992
35993 trace_wakeup_source_activate(ws->name, cec);
35994 }
35995@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35996 * Increment the counter of registered wakeup events and decrement the
35997 * couter of wakeup events in progress simultaneously.
35998 */
35999- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36000+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36001 trace_wakeup_source_deactivate(ws->name, cec);
36002
36003 split_counters(&cnt, &inpr);
36004diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36005index e8d11b6..7b1b36f 100644
36006--- a/drivers/base/syscore.c
36007+++ b/drivers/base/syscore.c
36008@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36009 void register_syscore_ops(struct syscore_ops *ops)
36010 {
36011 mutex_lock(&syscore_ops_lock);
36012- list_add_tail(&ops->node, &syscore_ops_list);
36013+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36014 mutex_unlock(&syscore_ops_lock);
36015 }
36016 EXPORT_SYMBOL_GPL(register_syscore_ops);
36017@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36018 void unregister_syscore_ops(struct syscore_ops *ops)
36019 {
36020 mutex_lock(&syscore_ops_lock);
36021- list_del(&ops->node);
36022+ pax_list_del((struct list_head *)&ops->node);
36023 mutex_unlock(&syscore_ops_lock);
36024 }
36025 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36026diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36027index edfa251..1734d4d 100644
36028--- a/drivers/block/cciss.c
36029+++ b/drivers/block/cciss.c
36030@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36031 while (!list_empty(&h->reqQ)) {
36032 c = list_entry(h->reqQ.next, CommandList_struct, list);
36033 /* can't do anything if fifo is full */
36034- if ((h->access.fifo_full(h))) {
36035+ if ((h->access->fifo_full(h))) {
36036 dev_warn(&h->pdev->dev, "fifo full\n");
36037 break;
36038 }
36039@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36040 h->Qdepth--;
36041
36042 /* Tell the controller execute command */
36043- h->access.submit_command(h, c);
36044+ h->access->submit_command(h, c);
36045
36046 /* Put job onto the completed Q */
36047 addQ(&h->cmpQ, c);
36048@@ -3447,17 +3447,17 @@ startio:
36049
36050 static inline unsigned long get_next_completion(ctlr_info_t *h)
36051 {
36052- return h->access.command_completed(h);
36053+ return h->access->command_completed(h);
36054 }
36055
36056 static inline int interrupt_pending(ctlr_info_t *h)
36057 {
36058- return h->access.intr_pending(h);
36059+ return h->access->intr_pending(h);
36060 }
36061
36062 static inline long interrupt_not_for_us(ctlr_info_t *h)
36063 {
36064- return ((h->access.intr_pending(h) == 0) ||
36065+ return ((h->access->intr_pending(h) == 0) ||
36066 (h->interrupts_enabled == 0));
36067 }
36068
36069@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36070 u32 a;
36071
36072 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36073- return h->access.command_completed(h);
36074+ return h->access->command_completed(h);
36075
36076 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36077 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36078@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36079 trans_support & CFGTBL_Trans_use_short_tags);
36080
36081 /* Change the access methods to the performant access methods */
36082- h->access = SA5_performant_access;
36083+ h->access = &SA5_performant_access;
36084 h->transMethod = CFGTBL_Trans_Performant;
36085
36086 return;
36087@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36088 if (prod_index < 0)
36089 return -ENODEV;
36090 h->product_name = products[prod_index].product_name;
36091- h->access = *(products[prod_index].access);
36092+ h->access = products[prod_index].access;
36093
36094 if (cciss_board_disabled(h)) {
36095 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36096@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36097 }
36098
36099 /* make sure the board interrupts are off */
36100- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36101+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36102 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36103 if (rc)
36104 goto clean2;
36105@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36106 * fake ones to scoop up any residual completions.
36107 */
36108 spin_lock_irqsave(&h->lock, flags);
36109- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36110+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36111 spin_unlock_irqrestore(&h->lock, flags);
36112 free_irq(h->intr[h->intr_mode], h);
36113 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36114@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36115 dev_info(&h->pdev->dev, "Board READY.\n");
36116 dev_info(&h->pdev->dev,
36117 "Waiting for stale completions to drain.\n");
36118- h->access.set_intr_mask(h, CCISS_INTR_ON);
36119+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36120 msleep(10000);
36121- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36122+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36123
36124 rc = controller_reset_failed(h->cfgtable);
36125 if (rc)
36126@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36127 cciss_scsi_setup(h);
36128
36129 /* Turn the interrupts on so we can service requests */
36130- h->access.set_intr_mask(h, CCISS_INTR_ON);
36131+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36132
36133 /* Get the firmware version */
36134 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36135@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36136 kfree(flush_buf);
36137 if (return_code != IO_OK)
36138 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36139- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36140+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36141 free_irq(h->intr[h->intr_mode], h);
36142 }
36143
36144diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36145index 7fda30e..eb5dfe0 100644
36146--- a/drivers/block/cciss.h
36147+++ b/drivers/block/cciss.h
36148@@ -101,7 +101,7 @@ struct ctlr_info
36149 /* information about each logical volume */
36150 drive_info_struct *drv[CISS_MAX_LUN];
36151
36152- struct access_method access;
36153+ struct access_method *access;
36154
36155 /* queue and queue Info */
36156 struct list_head reqQ;
36157diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36158index 2b94403..fd6ad1f 100644
36159--- a/drivers/block/cpqarray.c
36160+++ b/drivers/block/cpqarray.c
36161@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36162 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36163 goto Enomem4;
36164 }
36165- hba[i]->access.set_intr_mask(hba[i], 0);
36166+ hba[i]->access->set_intr_mask(hba[i], 0);
36167 if (request_irq(hba[i]->intr, do_ida_intr,
36168 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36169 {
36170@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36171 add_timer(&hba[i]->timer);
36172
36173 /* Enable IRQ now that spinlock and rate limit timer are set up */
36174- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36175+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36176
36177 for(j=0; j<NWD; j++) {
36178 struct gendisk *disk = ida_gendisk[i][j];
36179@@ -694,7 +694,7 @@ DBGINFO(
36180 for(i=0; i<NR_PRODUCTS; i++) {
36181 if (board_id == products[i].board_id) {
36182 c->product_name = products[i].product_name;
36183- c->access = *(products[i].access);
36184+ c->access = products[i].access;
36185 break;
36186 }
36187 }
36188@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36189 hba[ctlr]->intr = intr;
36190 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36191 hba[ctlr]->product_name = products[j].product_name;
36192- hba[ctlr]->access = *(products[j].access);
36193+ hba[ctlr]->access = products[j].access;
36194 hba[ctlr]->ctlr = ctlr;
36195 hba[ctlr]->board_id = board_id;
36196 hba[ctlr]->pci_dev = NULL; /* not PCI */
36197@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36198
36199 while((c = h->reqQ) != NULL) {
36200 /* Can't do anything if we're busy */
36201- if (h->access.fifo_full(h) == 0)
36202+ if (h->access->fifo_full(h) == 0)
36203 return;
36204
36205 /* Get the first entry from the request Q */
36206@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36207 h->Qdepth--;
36208
36209 /* Tell the controller to do our bidding */
36210- h->access.submit_command(h, c);
36211+ h->access->submit_command(h, c);
36212
36213 /* Get onto the completion Q */
36214 addQ(&h->cmpQ, c);
36215@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36216 unsigned long flags;
36217 __u32 a,a1;
36218
36219- istat = h->access.intr_pending(h);
36220+ istat = h->access->intr_pending(h);
36221 /* Is this interrupt for us? */
36222 if (istat == 0)
36223 return IRQ_NONE;
36224@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36225 */
36226 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36227 if (istat & FIFO_NOT_EMPTY) {
36228- while((a = h->access.command_completed(h))) {
36229+ while((a = h->access->command_completed(h))) {
36230 a1 = a; a &= ~3;
36231 if ((c = h->cmpQ) == NULL)
36232 {
36233@@ -1448,11 +1448,11 @@ static int sendcmd(
36234 /*
36235 * Disable interrupt
36236 */
36237- info_p->access.set_intr_mask(info_p, 0);
36238+ info_p->access->set_intr_mask(info_p, 0);
36239 /* Make sure there is room in the command FIFO */
36240 /* Actually it should be completely empty at this time. */
36241 for (i = 200000; i > 0; i--) {
36242- temp = info_p->access.fifo_full(info_p);
36243+ temp = info_p->access->fifo_full(info_p);
36244 if (temp != 0) {
36245 break;
36246 }
36247@@ -1465,7 +1465,7 @@ DBG(
36248 /*
36249 * Send the cmd
36250 */
36251- info_p->access.submit_command(info_p, c);
36252+ info_p->access->submit_command(info_p, c);
36253 complete = pollcomplete(ctlr);
36254
36255 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36256@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36257 * we check the new geometry. Then turn interrupts back on when
36258 * we're done.
36259 */
36260- host->access.set_intr_mask(host, 0);
36261+ host->access->set_intr_mask(host, 0);
36262 getgeometry(ctlr);
36263- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36264+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36265
36266 for(i=0; i<NWD; i++) {
36267 struct gendisk *disk = ida_gendisk[ctlr][i];
36268@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36269 /* Wait (up to 2 seconds) for a command to complete */
36270
36271 for (i = 200000; i > 0; i--) {
36272- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36273+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36274 if (done == 0) {
36275 udelay(10); /* a short fixed delay */
36276 } else
36277diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36278index be73e9d..7fbf140 100644
36279--- a/drivers/block/cpqarray.h
36280+++ b/drivers/block/cpqarray.h
36281@@ -99,7 +99,7 @@ struct ctlr_info {
36282 drv_info_t drv[NWD];
36283 struct proc_dir_entry *proc;
36284
36285- struct access_method access;
36286+ struct access_method *access;
36287
36288 cmdlist_t *reqQ;
36289 cmdlist_t *cmpQ;
36290diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36291index 2d7f608..11245fe 100644
36292--- a/drivers/block/drbd/drbd_int.h
36293+++ b/drivers/block/drbd/drbd_int.h
36294@@ -582,7 +582,7 @@ struct drbd_epoch {
36295 struct drbd_tconn *tconn;
36296 struct list_head list;
36297 unsigned int barrier_nr;
36298- atomic_t epoch_size; /* increased on every request added. */
36299+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36300 atomic_t active; /* increased on every req. added, and dec on every finished. */
36301 unsigned long flags;
36302 };
36303@@ -1022,7 +1022,7 @@ struct drbd_conf {
36304 unsigned int al_tr_number;
36305 int al_tr_cycle;
36306 wait_queue_head_t seq_wait;
36307- atomic_t packet_seq;
36308+ atomic_unchecked_t packet_seq;
36309 unsigned int peer_seq;
36310 spinlock_t peer_seq_lock;
36311 unsigned int minor;
36312@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36313 char __user *uoptval;
36314 int err;
36315
36316- uoptval = (char __user __force *)optval;
36317+ uoptval = (char __force_user *)optval;
36318
36319 set_fs(KERNEL_DS);
36320 if (level == SOL_SOCKET)
36321diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36322index 55635ed..40e837c 100644
36323--- a/drivers/block/drbd/drbd_main.c
36324+++ b/drivers/block/drbd/drbd_main.c
36325@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36326 p->sector = sector;
36327 p->block_id = block_id;
36328 p->blksize = blksize;
36329- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36330+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36331 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36332 }
36333
36334@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36335 return -EIO;
36336 p->sector = cpu_to_be64(req->i.sector);
36337 p->block_id = (unsigned long)req;
36338- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36339+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36340 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36341 if (mdev->state.conn >= C_SYNC_SOURCE &&
36342 mdev->state.conn <= C_PAUSED_SYNC_T)
36343@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36344 {
36345 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36346
36347- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36348- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36349+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36350+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36351 kfree(tconn->current_epoch);
36352
36353 idr_destroy(&tconn->volumes);
36354diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36355index 8cc1e64..ba7ffa9 100644
36356--- a/drivers/block/drbd/drbd_nl.c
36357+++ b/drivers/block/drbd/drbd_nl.c
36358@@ -3440,7 +3440,7 @@ out:
36359
36360 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36361 {
36362- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36363+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36364 struct sk_buff *msg;
36365 struct drbd_genlmsghdr *d_out;
36366 unsigned seq;
36367@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36368 return;
36369 }
36370
36371- seq = atomic_inc_return(&drbd_genl_seq);
36372+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36373 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36374 if (!msg)
36375 goto failed;
36376diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36377index cc29cd3..d4b058b 100644
36378--- a/drivers/block/drbd/drbd_receiver.c
36379+++ b/drivers/block/drbd/drbd_receiver.c
36380@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36381 {
36382 int err;
36383
36384- atomic_set(&mdev->packet_seq, 0);
36385+ atomic_set_unchecked(&mdev->packet_seq, 0);
36386 mdev->peer_seq = 0;
36387
36388 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36389@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36390 do {
36391 next_epoch = NULL;
36392
36393- epoch_size = atomic_read(&epoch->epoch_size);
36394+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36395
36396 switch (ev & ~EV_CLEANUP) {
36397 case EV_PUT:
36398@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36399 rv = FE_DESTROYED;
36400 } else {
36401 epoch->flags = 0;
36402- atomic_set(&epoch->epoch_size, 0);
36403+ atomic_set_unchecked(&epoch->epoch_size, 0);
36404 /* atomic_set(&epoch->active, 0); is already zero */
36405 if (rv == FE_STILL_LIVE)
36406 rv = FE_RECYCLED;
36407@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36408 conn_wait_active_ee_empty(tconn);
36409 drbd_flush(tconn);
36410
36411- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36412+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36413 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36414 if (epoch)
36415 break;
36416@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36417 }
36418
36419 epoch->flags = 0;
36420- atomic_set(&epoch->epoch_size, 0);
36421+ atomic_set_unchecked(&epoch->epoch_size, 0);
36422 atomic_set(&epoch->active, 0);
36423
36424 spin_lock(&tconn->epoch_lock);
36425- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36426+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36427 list_add(&epoch->list, &tconn->current_epoch->list);
36428 tconn->current_epoch = epoch;
36429 tconn->epochs++;
36430@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36431
36432 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36433 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36434- atomic_inc(&tconn->current_epoch->epoch_size);
36435+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36436 err2 = drbd_drain_block(mdev, pi->size);
36437 if (!err)
36438 err = err2;
36439@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36440
36441 spin_lock(&tconn->epoch_lock);
36442 peer_req->epoch = tconn->current_epoch;
36443- atomic_inc(&peer_req->epoch->epoch_size);
36444+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36445 atomic_inc(&peer_req->epoch->active);
36446 spin_unlock(&tconn->epoch_lock);
36447
36448@@ -4347,7 +4347,7 @@ struct data_cmd {
36449 int expect_payload;
36450 size_t pkt_size;
36451 int (*fn)(struct drbd_tconn *, struct packet_info *);
36452-};
36453+} __do_const;
36454
36455 static struct data_cmd drbd_cmd_handler[] = {
36456 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36457@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36458 if (!list_empty(&tconn->current_epoch->list))
36459 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36460 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36461- atomic_set(&tconn->current_epoch->epoch_size, 0);
36462+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36463 tconn->send.seen_any_write_yet = false;
36464
36465 conn_info(tconn, "Connection closed\n");
36466@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36467 struct asender_cmd {
36468 size_t pkt_size;
36469 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36470-};
36471+} __do_const;
36472
36473 static struct asender_cmd asender_tbl[] = {
36474 [P_PING] = { 0, got_Ping },
36475diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36476index 2f036ca..68d3f40 100644
36477--- a/drivers/block/loop.c
36478+++ b/drivers/block/loop.c
36479@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36480
36481 file_start_write(file);
36482 set_fs(get_ds());
36483- bw = file->f_op->write(file, buf, len, &pos);
36484+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36485 set_fs(old_fs);
36486 file_end_write(file);
36487 if (likely(bw == len))
36488diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36489index 5618847..5a46f3b 100644
36490--- a/drivers/block/pktcdvd.c
36491+++ b/drivers/block/pktcdvd.c
36492@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
36493
36494 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
36495 {
36496- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
36497+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
36498 }
36499
36500 /*
36501@@ -1897,7 +1897,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
36502 return -EROFS;
36503 }
36504 pd->settings.fp = ti.fp;
36505- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
36506+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
36507
36508 if (ti.nwa_v) {
36509 pd->nwa = be32_to_cpu(ti.next_writable);
36510diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
36511index 60abf59..80789e1 100644
36512--- a/drivers/bluetooth/btwilink.c
36513+++ b/drivers/bluetooth/btwilink.c
36514@@ -293,7 +293,7 @@ static int ti_st_send_frame(struct sk_buff *skb)
36515
36516 static int bt_ti_probe(struct platform_device *pdev)
36517 {
36518- static struct ti_st *hst;
36519+ struct ti_st *hst;
36520 struct hci_dev *hdev;
36521 int err;
36522
36523diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36524index 2009266..7be9ca2 100644
36525--- a/drivers/bus/arm-cci.c
36526+++ b/drivers/bus/arm-cci.c
36527@@ -405,7 +405,7 @@ static int __init cci_probe(void)
36528
36529 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36530
36531- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36532+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36533 if (!ports)
36534 return -ENOMEM;
36535
36536diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36537index 8a3aff7..d7538c2 100644
36538--- a/drivers/cdrom/cdrom.c
36539+++ b/drivers/cdrom/cdrom.c
36540@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36541 ENSURE(reset, CDC_RESET);
36542 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36543 cdi->mc_flags = 0;
36544- cdo->n_minors = 0;
36545 cdi->options = CDO_USE_FFLAGS;
36546
36547 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36548@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36549 else
36550 cdi->cdda_method = CDDA_OLD;
36551
36552- if (!cdo->generic_packet)
36553- cdo->generic_packet = cdrom_dummy_generic_packet;
36554+ if (!cdo->generic_packet) {
36555+ pax_open_kernel();
36556+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36557+ pax_close_kernel();
36558+ }
36559
36560 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36561 mutex_lock(&cdrom_mutex);
36562@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36563 if (cdi->exit)
36564 cdi->exit(cdi);
36565
36566- cdi->ops->n_minors--;
36567 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36568 }
36569
36570@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36571 */
36572 nr = nframes;
36573 do {
36574- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36575+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36576 if (cgc.buffer)
36577 break;
36578
36579@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36580 struct cdrom_device_info *cdi;
36581 int ret;
36582
36583- ret = scnprintf(info + *pos, max_size - *pos, header);
36584+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36585 if (!ret)
36586 return 1;
36587
36588diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36589index 5980cb9..6d7bd7e 100644
36590--- a/drivers/cdrom/gdrom.c
36591+++ b/drivers/cdrom/gdrom.c
36592@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36593 .audio_ioctl = gdrom_audio_ioctl,
36594 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36595 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36596- .n_minors = 1,
36597 };
36598
36599 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36600diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36601index 1421997..33f5d6d 100644
36602--- a/drivers/char/Kconfig
36603+++ b/drivers/char/Kconfig
36604@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36605
36606 config DEVKMEM
36607 bool "/dev/kmem virtual device support"
36608- default y
36609+ default n
36610+ depends on !GRKERNSEC_KMEM
36611 help
36612 Say Y here if you want to support the /dev/kmem device. The
36613 /dev/kmem device is rarely used, but can be used for certain
36614@@ -570,6 +571,7 @@ config DEVPORT
36615 bool
36616 depends on !M68K
36617 depends on ISA || PCI
36618+ depends on !GRKERNSEC_KMEM
36619 default y
36620
36621 source "drivers/s390/char/Kconfig"
36622diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36623index a48e05b..6bac831 100644
36624--- a/drivers/char/agp/compat_ioctl.c
36625+++ b/drivers/char/agp/compat_ioctl.c
36626@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36627 return -ENOMEM;
36628 }
36629
36630- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36631+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36632 sizeof(*usegment) * ureserve.seg_count)) {
36633 kfree(usegment);
36634 kfree(ksegment);
36635diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36636index 1b19239..b87b143 100644
36637--- a/drivers/char/agp/frontend.c
36638+++ b/drivers/char/agp/frontend.c
36639@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36640 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36641 return -EFAULT;
36642
36643- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36644+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36645 return -EFAULT;
36646
36647 client = agp_find_client_by_pid(reserve.pid);
36648@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36649 if (segment == NULL)
36650 return -ENOMEM;
36651
36652- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36653+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36654 sizeof(struct agp_segment) * reserve.seg_count)) {
36655 kfree(segment);
36656 return -EFAULT;
36657diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36658index 4f94375..413694e 100644
36659--- a/drivers/char/genrtc.c
36660+++ b/drivers/char/genrtc.c
36661@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36662 switch (cmd) {
36663
36664 case RTC_PLL_GET:
36665+ memset(&pll, 0, sizeof(pll));
36666 if (get_rtc_pll(&pll))
36667 return -EINVAL;
36668 else
36669diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36670index 448ce5e..3a76625 100644
36671--- a/drivers/char/hpet.c
36672+++ b/drivers/char/hpet.c
36673@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36674 }
36675
36676 static int
36677-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36678+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36679 struct hpet_info *info)
36680 {
36681 struct hpet_timer __iomem *timer;
36682diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36683index 86fe45c..c0ea948 100644
36684--- a/drivers/char/hw_random/intel-rng.c
36685+++ b/drivers/char/hw_random/intel-rng.c
36686@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36687
36688 if (no_fwh_detect)
36689 return -ENODEV;
36690- printk(warning);
36691+ printk("%s", warning);
36692 return -EBUSY;
36693 }
36694
36695diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36696index ec4e10f..f2a763b 100644
36697--- a/drivers/char/ipmi/ipmi_msghandler.c
36698+++ b/drivers/char/ipmi/ipmi_msghandler.c
36699@@ -420,7 +420,7 @@ struct ipmi_smi {
36700 struct proc_dir_entry *proc_dir;
36701 char proc_dir_name[10];
36702
36703- atomic_t stats[IPMI_NUM_STATS];
36704+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36705
36706 /*
36707 * run_to_completion duplicate of smb_info, smi_info
36708@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36709
36710
36711 #define ipmi_inc_stat(intf, stat) \
36712- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36713+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36714 #define ipmi_get_stat(intf, stat) \
36715- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36716+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36717
36718 static int is_lan_addr(struct ipmi_addr *addr)
36719 {
36720@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36721 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36722 init_waitqueue_head(&intf->waitq);
36723 for (i = 0; i < IPMI_NUM_STATS; i++)
36724- atomic_set(&intf->stats[i], 0);
36725+ atomic_set_unchecked(&intf->stats[i], 0);
36726
36727 intf->proc_dir = NULL;
36728
36729diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36730index 15e4a60..b046093 100644
36731--- a/drivers/char/ipmi/ipmi_si_intf.c
36732+++ b/drivers/char/ipmi/ipmi_si_intf.c
36733@@ -280,7 +280,7 @@ struct smi_info {
36734 unsigned char slave_addr;
36735
36736 /* Counters and things for the proc filesystem. */
36737- atomic_t stats[SI_NUM_STATS];
36738+ atomic_unchecked_t stats[SI_NUM_STATS];
36739
36740 struct task_struct *thread;
36741
36742@@ -289,9 +289,9 @@ struct smi_info {
36743 };
36744
36745 #define smi_inc_stat(smi, stat) \
36746- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36747+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36748 #define smi_get_stat(smi, stat) \
36749- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36750+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36751
36752 #define SI_MAX_PARMS 4
36753
36754@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
36755 atomic_set(&new_smi->req_events, 0);
36756 new_smi->run_to_completion = 0;
36757 for (i = 0; i < SI_NUM_STATS; i++)
36758- atomic_set(&new_smi->stats[i], 0);
36759+ atomic_set_unchecked(&new_smi->stats[i], 0);
36760
36761 new_smi->interrupt_disabled = 1;
36762 atomic_set(&new_smi->stop_operation, 0);
36763diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36764index f895a8c..2bc9147 100644
36765--- a/drivers/char/mem.c
36766+++ b/drivers/char/mem.c
36767@@ -18,6 +18,7 @@
36768 #include <linux/raw.h>
36769 #include <linux/tty.h>
36770 #include <linux/capability.h>
36771+#include <linux/security.h>
36772 #include <linux/ptrace.h>
36773 #include <linux/device.h>
36774 #include <linux/highmem.h>
36775@@ -37,6 +38,10 @@
36776
36777 #define DEVPORT_MINOR 4
36778
36779+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36780+extern const struct file_operations grsec_fops;
36781+#endif
36782+
36783 static inline unsigned long size_inside_page(unsigned long start,
36784 unsigned long size)
36785 {
36786@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36787
36788 while (cursor < to) {
36789 if (!devmem_is_allowed(pfn)) {
36790+#ifdef CONFIG_GRKERNSEC_KMEM
36791+ gr_handle_mem_readwrite(from, to);
36792+#else
36793 printk(KERN_INFO
36794 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36795 current->comm, from, to);
36796+#endif
36797 return 0;
36798 }
36799 cursor += PAGE_SIZE;
36800@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36801 }
36802 return 1;
36803 }
36804+#elif defined(CONFIG_GRKERNSEC_KMEM)
36805+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36806+{
36807+ return 0;
36808+}
36809 #else
36810 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36811 {
36812@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36813
36814 while (count > 0) {
36815 unsigned long remaining;
36816+ char *temp;
36817
36818 sz = size_inside_page(p, count);
36819
36820@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36821 if (!ptr)
36822 return -EFAULT;
36823
36824- remaining = copy_to_user(buf, ptr, sz);
36825+#ifdef CONFIG_PAX_USERCOPY
36826+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36827+ if (!temp) {
36828+ unxlate_dev_mem_ptr(p, ptr);
36829+ return -ENOMEM;
36830+ }
36831+ memcpy(temp, ptr, sz);
36832+#else
36833+ temp = ptr;
36834+#endif
36835+
36836+ remaining = copy_to_user(buf, temp, sz);
36837+
36838+#ifdef CONFIG_PAX_USERCOPY
36839+ kfree(temp);
36840+#endif
36841+
36842 unxlate_dev_mem_ptr(p, ptr);
36843 if (remaining)
36844 return -EFAULT;
36845@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36846 size_t count, loff_t *ppos)
36847 {
36848 unsigned long p = *ppos;
36849- ssize_t low_count, read, sz;
36850+ ssize_t low_count, read, sz, err = 0;
36851 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36852- int err = 0;
36853
36854 read = 0;
36855 if (p < (unsigned long) high_memory) {
36856@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36857 }
36858 #endif
36859 while (low_count > 0) {
36860+ char *temp;
36861+
36862 sz = size_inside_page(p, low_count);
36863
36864 /*
36865@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36866 */
36867 kbuf = xlate_dev_kmem_ptr((char *)p);
36868
36869- if (copy_to_user(buf, kbuf, sz))
36870+#ifdef CONFIG_PAX_USERCOPY
36871+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36872+ if (!temp)
36873+ return -ENOMEM;
36874+ memcpy(temp, kbuf, sz);
36875+#else
36876+ temp = kbuf;
36877+#endif
36878+
36879+ err = copy_to_user(buf, temp, sz);
36880+
36881+#ifdef CONFIG_PAX_USERCOPY
36882+ kfree(temp);
36883+#endif
36884+
36885+ if (err)
36886 return -EFAULT;
36887 buf += sz;
36888 p += sz;
36889@@ -822,6 +869,9 @@ static const struct memdev {
36890 #ifdef CONFIG_PRINTK
36891 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36892 #endif
36893+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36894+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36895+#endif
36896 };
36897
36898 static int memory_open(struct inode *inode, struct file *filp)
36899@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36900 continue;
36901
36902 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36903- NULL, devlist[minor].name);
36904+ NULL, "%s", devlist[minor].name);
36905 }
36906
36907 return tty_init();
36908diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36909index 9df78e2..01ba9ae 100644
36910--- a/drivers/char/nvram.c
36911+++ b/drivers/char/nvram.c
36912@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36913
36914 spin_unlock_irq(&rtc_lock);
36915
36916- if (copy_to_user(buf, contents, tmp - contents))
36917+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36918 return -EFAULT;
36919
36920 *ppos = i;
36921diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36922index d39cca6..8c1e269 100644
36923--- a/drivers/char/pcmcia/synclink_cs.c
36924+++ b/drivers/char/pcmcia/synclink_cs.c
36925@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36926
36927 if (debug_level >= DEBUG_LEVEL_INFO)
36928 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36929- __FILE__, __LINE__, info->device_name, port->count);
36930+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36931
36932- WARN_ON(!port->count);
36933+ WARN_ON(!atomic_read(&port->count));
36934
36935 if (tty_port_close_start(port, tty, filp) == 0)
36936 goto cleanup;
36937@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36938 cleanup:
36939 if (debug_level >= DEBUG_LEVEL_INFO)
36940 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36941- tty->driver->name, port->count);
36942+ tty->driver->name, atomic_read(&port->count));
36943 }
36944
36945 /* Wait until the transmitter is empty.
36946@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36947
36948 if (debug_level >= DEBUG_LEVEL_INFO)
36949 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36950- __FILE__, __LINE__, tty->driver->name, port->count);
36951+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36952
36953 /* If port is closing, signal caller to try again */
36954 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36955@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36956 goto cleanup;
36957 }
36958 spin_lock(&port->lock);
36959- port->count++;
36960+ atomic_inc(&port->count);
36961 spin_unlock(&port->lock);
36962 spin_unlock_irqrestore(&info->netlock, flags);
36963
36964- if (port->count == 1) {
36965+ if (atomic_read(&port->count) == 1) {
36966 /* 1st open on this device, init hardware */
36967 retval = startup(info, tty);
36968 if (retval < 0)
36969@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36970 unsigned short new_crctype;
36971
36972 /* return error if TTY interface open */
36973- if (info->port.count)
36974+ if (atomic_read(&info->port.count))
36975 return -EBUSY;
36976
36977 switch (encoding)
36978@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36979
36980 /* arbitrate between network and tty opens */
36981 spin_lock_irqsave(&info->netlock, flags);
36982- if (info->port.count != 0 || info->netcount != 0) {
36983+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36984 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36985 spin_unlock_irqrestore(&info->netlock, flags);
36986 return -EBUSY;
36987@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36988 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36989
36990 /* return error if TTY interface open */
36991- if (info->port.count)
36992+ if (atomic_read(&info->port.count))
36993 return -EBUSY;
36994
36995 if (cmd != SIOCWANDEV)
36996diff --git a/drivers/char/random.c b/drivers/char/random.c
36997index 7a744d3..35a177ee 100644
36998--- a/drivers/char/random.c
36999+++ b/drivers/char/random.c
37000@@ -269,8 +269,13 @@
37001 /*
37002 * Configuration information
37003 */
37004+#ifdef CONFIG_GRKERNSEC_RANDNET
37005+#define INPUT_POOL_WORDS 512
37006+#define OUTPUT_POOL_WORDS 128
37007+#else
37008 #define INPUT_POOL_WORDS 128
37009 #define OUTPUT_POOL_WORDS 32
37010+#endif
37011 #define SEC_XFER_SIZE 512
37012 #define EXTRACT_SIZE 10
37013
37014@@ -310,10 +315,17 @@ static struct poolinfo {
37015 int poolwords;
37016 int tap1, tap2, tap3, tap4, tap5;
37017 } poolinfo_table[] = {
37018+#ifdef CONFIG_GRKERNSEC_RANDNET
37019+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37020+ { 512, 411, 308, 208, 104, 1 },
37021+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37022+ { 128, 103, 76, 51, 25, 1 },
37023+#else
37024 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
37025 { 128, 103, 76, 51, 25, 1 },
37026 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
37027 { 32, 26, 20, 14, 7, 1 },
37028+#endif
37029 #if 0
37030 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37031 { 2048, 1638, 1231, 819, 411, 1 },
37032@@ -521,8 +533,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37033 input_rotate += i ? 7 : 14;
37034 }
37035
37036- ACCESS_ONCE(r->input_rotate) = input_rotate;
37037- ACCESS_ONCE(r->add_ptr) = i;
37038+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37039+ ACCESS_ONCE_RW(r->add_ptr) = i;
37040 smp_wmb();
37041
37042 if (out)
37043@@ -1029,7 +1041,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37044
37045 extract_buf(r, tmp);
37046 i = min_t(int, nbytes, EXTRACT_SIZE);
37047- if (copy_to_user(buf, tmp, i)) {
37048+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37049 ret = -EFAULT;
37050 break;
37051 }
37052@@ -1365,7 +1377,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37053 #include <linux/sysctl.h>
37054
37055 static int min_read_thresh = 8, min_write_thresh;
37056-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37057+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37058 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37059 static char sysctl_bootid[16];
37060
37061@@ -1381,7 +1393,7 @@ static char sysctl_bootid[16];
37062 static int proc_do_uuid(struct ctl_table *table, int write,
37063 void __user *buffer, size_t *lenp, loff_t *ppos)
37064 {
37065- struct ctl_table fake_table;
37066+ ctl_table_no_const fake_table;
37067 unsigned char buf[64], tmp_uuid[16], *uuid;
37068
37069 uuid = table->data;
37070diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37071index 7cc1fe22..b602d6b 100644
37072--- a/drivers/char/sonypi.c
37073+++ b/drivers/char/sonypi.c
37074@@ -54,6 +54,7 @@
37075
37076 #include <asm/uaccess.h>
37077 #include <asm/io.h>
37078+#include <asm/local.h>
37079
37080 #include <linux/sonypi.h>
37081
37082@@ -490,7 +491,7 @@ static struct sonypi_device {
37083 spinlock_t fifo_lock;
37084 wait_queue_head_t fifo_proc_list;
37085 struct fasync_struct *fifo_async;
37086- int open_count;
37087+ local_t open_count;
37088 int model;
37089 struct input_dev *input_jog_dev;
37090 struct input_dev *input_key_dev;
37091@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37092 static int sonypi_misc_release(struct inode *inode, struct file *file)
37093 {
37094 mutex_lock(&sonypi_device.lock);
37095- sonypi_device.open_count--;
37096+ local_dec(&sonypi_device.open_count);
37097 mutex_unlock(&sonypi_device.lock);
37098 return 0;
37099 }
37100@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37101 {
37102 mutex_lock(&sonypi_device.lock);
37103 /* Flush input queue on first open */
37104- if (!sonypi_device.open_count)
37105+ if (!local_read(&sonypi_device.open_count))
37106 kfifo_reset(&sonypi_device.fifo);
37107- sonypi_device.open_count++;
37108+ local_inc(&sonypi_device.open_count);
37109 mutex_unlock(&sonypi_device.lock);
37110
37111 return 0;
37112diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37113index 64420b3..5c40b56 100644
37114--- a/drivers/char/tpm/tpm_acpi.c
37115+++ b/drivers/char/tpm/tpm_acpi.c
37116@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37117 virt = acpi_os_map_memory(start, len);
37118 if (!virt) {
37119 kfree(log->bios_event_log);
37120+ log->bios_event_log = NULL;
37121 printk("%s: ERROR - Unable to map memory\n", __func__);
37122 return -EIO;
37123 }
37124
37125- memcpy_fromio(log->bios_event_log, virt, len);
37126+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37127
37128 acpi_os_unmap_memory(virt, len);
37129 return 0;
37130diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37131index 84ddc55..1d32f1e 100644
37132--- a/drivers/char/tpm/tpm_eventlog.c
37133+++ b/drivers/char/tpm/tpm_eventlog.c
37134@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37135 event = addr;
37136
37137 if ((event->event_type == 0 && event->event_size == 0) ||
37138- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37139+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37140 return NULL;
37141
37142 return addr;
37143@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37144 return NULL;
37145
37146 if ((event->event_type == 0 && event->event_size == 0) ||
37147- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37148+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37149 return NULL;
37150
37151 (*pos)++;
37152@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37153 int i;
37154
37155 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37156- seq_putc(m, data[i]);
37157+ if (!seq_putc(m, data[i]))
37158+ return -EFAULT;
37159
37160 return 0;
37161 }
37162diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37163index b79cf3e..de172d64f 100644
37164--- a/drivers/char/virtio_console.c
37165+++ b/drivers/char/virtio_console.c
37166@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37167 if (to_user) {
37168 ssize_t ret;
37169
37170- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37171+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37172 if (ret)
37173 return -EFAULT;
37174 } else {
37175@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37176 if (!port_has_data(port) && !port->host_connected)
37177 return 0;
37178
37179- return fill_readbuf(port, ubuf, count, true);
37180+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37181 }
37182
37183 static int wait_port_writable(struct port *port, bool nonblock)
37184diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37185index a33f46f..a720eed 100644
37186--- a/drivers/clk/clk-composite.c
37187+++ b/drivers/clk/clk-composite.c
37188@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37189 struct clk *clk;
37190 struct clk_init_data init;
37191 struct clk_composite *composite;
37192- struct clk_ops *clk_composite_ops;
37193+ clk_ops_no_const *clk_composite_ops;
37194
37195 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37196 if (!composite) {
37197diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37198index 81dd31a..ef5c542 100644
37199--- a/drivers/clk/socfpga/clk.c
37200+++ b/drivers/clk/socfpga/clk.c
37201@@ -22,6 +22,7 @@
37202 #include <linux/clk-provider.h>
37203 #include <linux/io.h>
37204 #include <linux/of.h>
37205+#include <asm/pgtable.h>
37206
37207 /* Clock Manager offsets */
37208 #define CLKMGR_CTRL 0x0
37209@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37210 streq(clk_name, "periph_pll") ||
37211 streq(clk_name, "sdram_pll")) {
37212 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37213- clk_pll_ops.enable = clk_gate_ops.enable;
37214- clk_pll_ops.disable = clk_gate_ops.disable;
37215+ pax_open_kernel();
37216+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37217+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37218+ pax_close_kernel();
37219 }
37220
37221 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37222@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37223 return parent_rate / div;
37224 }
37225
37226-static struct clk_ops gateclk_ops = {
37227+static clk_ops_no_const gateclk_ops __read_only = {
37228 .recalc_rate = socfpga_clk_recalc_rate,
37229 .get_parent = socfpga_clk_get_parent,
37230 .set_parent = socfpga_clk_set_parent,
37231diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37232index 506fd23..01a593f 100644
37233--- a/drivers/cpufreq/acpi-cpufreq.c
37234+++ b/drivers/cpufreq/acpi-cpufreq.c
37235@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37236 return sprintf(buf, "%u\n", boost_enabled);
37237 }
37238
37239-static struct global_attr global_boost = __ATTR(boost, 0644,
37240+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37241 show_global_boost,
37242 store_global_boost);
37243
37244@@ -721,8 +721,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37245 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37246 per_cpu(acfreq_data, cpu) = data;
37247
37248- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37249- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37250+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37251+ pax_open_kernel();
37252+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37253+ pax_close_kernel();
37254+ }
37255
37256 result = acpi_processor_register_performance(data->acpi_data, cpu);
37257 if (result)
37258@@ -850,7 +853,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37259 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37260 break;
37261 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37262- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37263+ pax_open_kernel();
37264+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37265+ pax_close_kernel();
37266 policy->cur = get_cur_freq_on_cpu(cpu);
37267 break;
37268 default:
37269diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37270index 04548f7..457a342 100644
37271--- a/drivers/cpufreq/cpufreq.c
37272+++ b/drivers/cpufreq/cpufreq.c
37273@@ -2069,7 +2069,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37274 return NOTIFY_OK;
37275 }
37276
37277-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37278+static struct notifier_block cpufreq_cpu_notifier = {
37279 .notifier_call = cpufreq_cpu_callback,
37280 };
37281
37282@@ -2101,8 +2101,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37283
37284 pr_debug("trying to register driver %s\n", driver_data->name);
37285
37286- if (driver_data->setpolicy)
37287- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37288+ if (driver_data->setpolicy) {
37289+ pax_open_kernel();
37290+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37291+ pax_close_kernel();
37292+ }
37293
37294 write_lock_irqsave(&cpufreq_driver_lock, flags);
37295 if (cpufreq_driver) {
37296diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37297index 0806c31..6a73276 100644
37298--- a/drivers/cpufreq/cpufreq_governor.c
37299+++ b/drivers/cpufreq/cpufreq_governor.c
37300@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37301 struct dbs_data *dbs_data;
37302 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37303 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37304- struct od_ops *od_ops = NULL;
37305+ const struct od_ops *od_ops = NULL;
37306 struct od_dbs_tuners *od_tuners = NULL;
37307 struct cs_dbs_tuners *cs_tuners = NULL;
37308 struct cpu_dbs_common_info *cpu_cdbs;
37309@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37310
37311 if ((cdata->governor == GOV_CONSERVATIVE) &&
37312 (!policy->governor->initialized)) {
37313- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37314+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37315
37316 cpufreq_register_notifier(cs_ops->notifier_block,
37317 CPUFREQ_TRANSITION_NOTIFIER);
37318@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37319
37320 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37321 (policy->governor->initialized == 1)) {
37322- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37323+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37324
37325 cpufreq_unregister_notifier(cs_ops->notifier_block,
37326 CPUFREQ_TRANSITION_NOTIFIER);
37327diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37328index 88cd39f..87f0393 100644
37329--- a/drivers/cpufreq/cpufreq_governor.h
37330+++ b/drivers/cpufreq/cpufreq_governor.h
37331@@ -202,7 +202,7 @@ struct common_dbs_data {
37332 void (*exit)(struct dbs_data *dbs_data);
37333
37334 /* Governor specific ops, see below */
37335- void *gov_ops;
37336+ const void *gov_ops;
37337 };
37338
37339 /* Governor Per policy data */
37340@@ -222,7 +222,7 @@ struct od_ops {
37341 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37342 unsigned int freq_next, unsigned int relation);
37343 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
37344-};
37345+} __no_const;
37346
37347 struct cs_ops {
37348 struct notifier_block *notifier_block;
37349diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37350index 32f26f6..feb657b 100644
37351--- a/drivers/cpufreq/cpufreq_ondemand.c
37352+++ b/drivers/cpufreq/cpufreq_ondemand.c
37353@@ -522,7 +522,7 @@ static void od_exit(struct dbs_data *dbs_data)
37354
37355 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37356
37357-static struct od_ops od_ops = {
37358+static struct od_ops od_ops __read_only = {
37359 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37360 .powersave_bias_target = generic_powersave_bias_target,
37361 .freq_increase = dbs_freq_increase,
37362@@ -577,14 +577,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37363 (struct cpufreq_policy *, unsigned int, unsigned int),
37364 unsigned int powersave_bias)
37365 {
37366- od_ops.powersave_bias_target = f;
37367+ pax_open_kernel();
37368+ *(void **)&od_ops.powersave_bias_target = f;
37369+ pax_close_kernel();
37370 od_set_powersave_bias(powersave_bias);
37371 }
37372 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37373
37374 void od_unregister_powersave_bias_handler(void)
37375 {
37376- od_ops.powersave_bias_target = generic_powersave_bias_target;
37377+ pax_open_kernel();
37378+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37379+ pax_close_kernel();
37380 od_set_powersave_bias(0);
37381 }
37382 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37383diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37384index 4cf0d28..5830372 100644
37385--- a/drivers/cpufreq/cpufreq_stats.c
37386+++ b/drivers/cpufreq/cpufreq_stats.c
37387@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37388 }
37389
37390 /* priority=1 so this will get called before cpufreq_remove_dev */
37391-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37392+static struct notifier_block cpufreq_stat_cpu_notifier = {
37393 .notifier_call = cpufreq_stat_cpu_callback,
37394 .priority = 1,
37395 };
37396diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37397index 2f0a2a6..93d728e 100644
37398--- a/drivers/cpufreq/p4-clockmod.c
37399+++ b/drivers/cpufreq/p4-clockmod.c
37400@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37401 case 0x0F: /* Core Duo */
37402 case 0x16: /* Celeron Core */
37403 case 0x1C: /* Atom */
37404- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37405+ pax_open_kernel();
37406+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37407+ pax_close_kernel();
37408 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37409 case 0x0D: /* Pentium M (Dothan) */
37410- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37411+ pax_open_kernel();
37412+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37413+ pax_close_kernel();
37414 /* fall through */
37415 case 0x09: /* Pentium M (Banias) */
37416 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37417@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37418
37419 /* on P-4s, the TSC runs with constant frequency independent whether
37420 * throttling is active or not. */
37421- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37422+ pax_open_kernel();
37423+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37424+ pax_close_kernel();
37425
37426 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37427 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37428diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37429index ac76b48..2445bc6 100644
37430--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37431+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37432@@ -18,14 +18,12 @@
37433 #include <asm/head.h>
37434 #include <asm/timer.h>
37435
37436-static struct cpufreq_driver *cpufreq_us3_driver;
37437-
37438 struct us3_freq_percpu_info {
37439 struct cpufreq_frequency_table table[4];
37440 };
37441
37442 /* Indexed by cpu number. */
37443-static struct us3_freq_percpu_info *us3_freq_table;
37444+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37445
37446 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37447 * in the Safari config register.
37448@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37449
37450 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37451 {
37452- if (cpufreq_us3_driver)
37453- us3_set_cpu_divider_index(policy, 0);
37454+ us3_set_cpu_divider_index(policy->cpu, 0);
37455
37456 return 0;
37457 }
37458
37459+static int __init us3_freq_init(void);
37460+static void __exit us3_freq_exit(void);
37461+
37462+static struct cpufreq_driver cpufreq_us3_driver = {
37463+ .init = us3_freq_cpu_init,
37464+ .verify = us3_freq_verify,
37465+ .target = us3_freq_target,
37466+ .get = us3_freq_get,
37467+ .exit = us3_freq_cpu_exit,
37468+ .owner = THIS_MODULE,
37469+ .name = "UltraSPARC-III",
37470+
37471+};
37472+
37473 static int __init us3_freq_init(void)
37474 {
37475 unsigned long manuf, impl, ver;
37476@@ -208,55 +219,15 @@ static int __init us3_freq_init(void)
37477 (impl == CHEETAH_IMPL ||
37478 impl == CHEETAH_PLUS_IMPL ||
37479 impl == JAGUAR_IMPL ||
37480- impl == PANTHER_IMPL)) {
37481- struct cpufreq_driver *driver;
37482-
37483- ret = -ENOMEM;
37484- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
37485- if (!driver)
37486- goto err_out;
37487-
37488- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
37489- GFP_KERNEL);
37490- if (!us3_freq_table)
37491- goto err_out;
37492-
37493- driver->init = us3_freq_cpu_init;
37494- driver->verify = us3_freq_verify;
37495- driver->target = us3_freq_target;
37496- driver->get = us3_freq_get;
37497- driver->exit = us3_freq_cpu_exit;
37498- strcpy(driver->name, "UltraSPARC-III");
37499-
37500- cpufreq_us3_driver = driver;
37501- ret = cpufreq_register_driver(driver);
37502- if (ret)
37503- goto err_out;
37504-
37505- return 0;
37506-
37507-err_out:
37508- if (driver) {
37509- kfree(driver);
37510- cpufreq_us3_driver = NULL;
37511- }
37512- kfree(us3_freq_table);
37513- us3_freq_table = NULL;
37514- return ret;
37515- }
37516+ impl == PANTHER_IMPL))
37517+ return cpufreq_register_driver(&cpufreq_us3_driver);
37518
37519 return -ENODEV;
37520 }
37521
37522 static void __exit us3_freq_exit(void)
37523 {
37524- if (cpufreq_us3_driver) {
37525- cpufreq_unregister_driver(cpufreq_us3_driver);
37526- kfree(cpufreq_us3_driver);
37527- cpufreq_us3_driver = NULL;
37528- kfree(us3_freq_table);
37529- us3_freq_table = NULL;
37530- }
37531+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37532 }
37533
37534 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37535diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37536index f897d51..15da295 100644
37537--- a/drivers/cpufreq/speedstep-centrino.c
37538+++ b/drivers/cpufreq/speedstep-centrino.c
37539@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37540 !cpu_has(cpu, X86_FEATURE_EST))
37541 return -ENODEV;
37542
37543- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37544- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37545+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37546+ pax_open_kernel();
37547+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37548+ pax_close_kernel();
37549+ }
37550
37551 if (policy->cpu != 0)
37552 return -ENODEV;
37553diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37554index d75040d..4738ca5 100644
37555--- a/drivers/cpuidle/cpuidle.c
37556+++ b/drivers/cpuidle/cpuidle.c
37557@@ -252,7 +252,7 @@ static int poll_idle(struct cpuidle_device *dev,
37558
37559 static void poll_idle_init(struct cpuidle_driver *drv)
37560 {
37561- struct cpuidle_state *state = &drv->states[0];
37562+ cpuidle_state_no_const *state = &drv->states[0];
37563
37564 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37565 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37566diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37567index ea2f8e7..70ac501 100644
37568--- a/drivers/cpuidle/governor.c
37569+++ b/drivers/cpuidle/governor.c
37570@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37571 mutex_lock(&cpuidle_lock);
37572 if (__cpuidle_find_governor(gov->name) == NULL) {
37573 ret = 0;
37574- list_add_tail(&gov->governor_list, &cpuidle_governors);
37575+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37576 if (!cpuidle_curr_governor ||
37577 cpuidle_curr_governor->rating < gov->rating)
37578 cpuidle_switch_governor(gov);
37579@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37580 new_gov = cpuidle_replace_governor(gov->rating);
37581 cpuidle_switch_governor(new_gov);
37582 }
37583- list_del(&gov->governor_list);
37584+ pax_list_del((struct list_head *)&gov->governor_list);
37585 mutex_unlock(&cpuidle_lock);
37586 }
37587
37588diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37589index 8739cc0..dc859d0 100644
37590--- a/drivers/cpuidle/sysfs.c
37591+++ b/drivers/cpuidle/sysfs.c
37592@@ -134,7 +134,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37593 NULL
37594 };
37595
37596-static struct attribute_group cpuidle_attr_group = {
37597+static attribute_group_no_const cpuidle_attr_group = {
37598 .attrs = cpuidle_default_attrs,
37599 .name = "cpuidle",
37600 };
37601diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37602index 12fea3e..1e28f47 100644
37603--- a/drivers/crypto/hifn_795x.c
37604+++ b/drivers/crypto/hifn_795x.c
37605@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37606 MODULE_PARM_DESC(hifn_pll_ref,
37607 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37608
37609-static atomic_t hifn_dev_number;
37610+static atomic_unchecked_t hifn_dev_number;
37611
37612 #define ACRYPTO_OP_DECRYPT 0
37613 #define ACRYPTO_OP_ENCRYPT 1
37614@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37615 goto err_out_disable_pci_device;
37616
37617 snprintf(name, sizeof(name), "hifn%d",
37618- atomic_inc_return(&hifn_dev_number)-1);
37619+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37620
37621 err = pci_request_regions(pdev, name);
37622 if (err)
37623diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37624index c99c00d..990a4b2 100644
37625--- a/drivers/devfreq/devfreq.c
37626+++ b/drivers/devfreq/devfreq.c
37627@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37628 goto err_out;
37629 }
37630
37631- list_add(&governor->node, &devfreq_governor_list);
37632+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37633
37634 list_for_each_entry(devfreq, &devfreq_list, node) {
37635 int ret = 0;
37636@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37637 }
37638 }
37639
37640- list_del(&governor->node);
37641+ pax_list_del((struct list_head *)&governor->node);
37642 err_out:
37643 mutex_unlock(&devfreq_list_lock);
37644
37645diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
37646index 1069e88..dfcd642 100644
37647--- a/drivers/dma/sh/shdmac.c
37648+++ b/drivers/dma/sh/shdmac.c
37649@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37650 return ret;
37651 }
37652
37653-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37654+static struct notifier_block sh_dmae_nmi_notifier = {
37655 .notifier_call = sh_dmae_nmi_handler,
37656
37657 /* Run before NMI debug handler and KGDB */
37658diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37659index 211021d..201d47f 100644
37660--- a/drivers/edac/edac_device.c
37661+++ b/drivers/edac/edac_device.c
37662@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37663 */
37664 int edac_device_alloc_index(void)
37665 {
37666- static atomic_t device_indexes = ATOMIC_INIT(0);
37667+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37668
37669- return atomic_inc_return(&device_indexes) - 1;
37670+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37671 }
37672 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37673
37674diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37675index 9f7e0e60..348c875 100644
37676--- a/drivers/edac/edac_mc_sysfs.c
37677+++ b/drivers/edac/edac_mc_sysfs.c
37678@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
37679 struct dev_ch_attribute {
37680 struct device_attribute attr;
37681 int channel;
37682-};
37683+} __do_const;
37684
37685 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37686 struct dev_ch_attribute dev_attr_legacy_##_name = \
37687@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37688 }
37689
37690 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37691+ pax_open_kernel();
37692 if (mci->get_sdram_scrub_rate) {
37693- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37694- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37695+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37696+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37697 }
37698 if (mci->set_sdram_scrub_rate) {
37699- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37700- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37701+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37702+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37703 }
37704+ pax_close_kernel();
37705 err = device_create_file(&mci->dev,
37706 &dev_attr_sdram_scrub_rate);
37707 if (err) {
37708diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37709index dd370f9..0281629 100644
37710--- a/drivers/edac/edac_pci.c
37711+++ b/drivers/edac/edac_pci.c
37712@@ -29,7 +29,7 @@
37713
37714 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37715 static LIST_HEAD(edac_pci_list);
37716-static atomic_t pci_indexes = ATOMIC_INIT(0);
37717+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37718
37719 /*
37720 * edac_pci_alloc_ctl_info
37721@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37722 */
37723 int edac_pci_alloc_index(void)
37724 {
37725- return atomic_inc_return(&pci_indexes) - 1;
37726+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37727 }
37728 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37729
37730diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37731index e8658e4..22746d6 100644
37732--- a/drivers/edac/edac_pci_sysfs.c
37733+++ b/drivers/edac/edac_pci_sysfs.c
37734@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37735 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37736 static int edac_pci_poll_msec = 1000; /* one second workq period */
37737
37738-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37739-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37740+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37741+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37742
37743 static struct kobject *edac_pci_top_main_kobj;
37744 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37745@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37746 void *value;
37747 ssize_t(*show) (void *, char *);
37748 ssize_t(*store) (void *, const char *, size_t);
37749-};
37750+} __do_const;
37751
37752 /* Set of show/store abstract level functions for PCI Parity object */
37753 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37754@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37755 edac_printk(KERN_CRIT, EDAC_PCI,
37756 "Signaled System Error on %s\n",
37757 pci_name(dev));
37758- atomic_inc(&pci_nonparity_count);
37759+ atomic_inc_unchecked(&pci_nonparity_count);
37760 }
37761
37762 if (status & (PCI_STATUS_PARITY)) {
37763@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37764 "Master Data Parity Error on %s\n",
37765 pci_name(dev));
37766
37767- atomic_inc(&pci_parity_count);
37768+ atomic_inc_unchecked(&pci_parity_count);
37769 }
37770
37771 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37772@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37773 "Detected Parity Error on %s\n",
37774 pci_name(dev));
37775
37776- atomic_inc(&pci_parity_count);
37777+ atomic_inc_unchecked(&pci_parity_count);
37778 }
37779 }
37780
37781@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37782 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37783 "Signaled System Error on %s\n",
37784 pci_name(dev));
37785- atomic_inc(&pci_nonparity_count);
37786+ atomic_inc_unchecked(&pci_nonparity_count);
37787 }
37788
37789 if (status & (PCI_STATUS_PARITY)) {
37790@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37791 "Master Data Parity Error on "
37792 "%s\n", pci_name(dev));
37793
37794- atomic_inc(&pci_parity_count);
37795+ atomic_inc_unchecked(&pci_parity_count);
37796 }
37797
37798 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37799@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37800 "Detected Parity Error on %s\n",
37801 pci_name(dev));
37802
37803- atomic_inc(&pci_parity_count);
37804+ atomic_inc_unchecked(&pci_parity_count);
37805 }
37806 }
37807 }
37808@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37809 if (!check_pci_errors)
37810 return;
37811
37812- before_count = atomic_read(&pci_parity_count);
37813+ before_count = atomic_read_unchecked(&pci_parity_count);
37814
37815 /* scan all PCI devices looking for a Parity Error on devices and
37816 * bridges.
37817@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37818 /* Only if operator has selected panic on PCI Error */
37819 if (edac_pci_get_panic_on_pe()) {
37820 /* If the count is different 'after' from 'before' */
37821- if (before_count != atomic_read(&pci_parity_count))
37822+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37823 panic("EDAC: PCI Parity Error");
37824 }
37825 }
37826diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37827index 51b7e3a..aa8a3e8 100644
37828--- a/drivers/edac/mce_amd.h
37829+++ b/drivers/edac/mce_amd.h
37830@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37831 bool (*mc0_mce)(u16, u8);
37832 bool (*mc1_mce)(u16, u8);
37833 bool (*mc2_mce)(u16, u8);
37834-};
37835+} __no_const;
37836
37837 void amd_report_gart_errors(bool);
37838 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37839diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37840index 57ea7f4..af06b76 100644
37841--- a/drivers/firewire/core-card.c
37842+++ b/drivers/firewire/core-card.c
37843@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37844 const struct fw_card_driver *driver,
37845 struct device *device)
37846 {
37847- static atomic_t index = ATOMIC_INIT(-1);
37848+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37849
37850- card->index = atomic_inc_return(&index);
37851+ card->index = atomic_inc_return_unchecked(&index);
37852 card->driver = driver;
37853 card->device = device;
37854 card->current_tlabel = 0;
37855@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37856
37857 void fw_core_remove_card(struct fw_card *card)
37858 {
37859- struct fw_card_driver dummy_driver = dummy_driver_template;
37860+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37861
37862 card->driver->update_phy_reg(card, 4,
37863 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37864diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37865index de4aa40..49ab1f2 100644
37866--- a/drivers/firewire/core-device.c
37867+++ b/drivers/firewire/core-device.c
37868@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37869 struct config_rom_attribute {
37870 struct device_attribute attr;
37871 u32 key;
37872-};
37873+} __do_const;
37874
37875 static ssize_t show_immediate(struct device *dev,
37876 struct device_attribute *dattr, char *buf)
37877diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37878index e5af0e3..d318058 100644
37879--- a/drivers/firewire/core-transaction.c
37880+++ b/drivers/firewire/core-transaction.c
37881@@ -38,6 +38,7 @@
37882 #include <linux/timer.h>
37883 #include <linux/types.h>
37884 #include <linux/workqueue.h>
37885+#include <linux/sched.h>
37886
37887 #include <asm/byteorder.h>
37888
37889diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37890index 515a42c..5ecf3ba 100644
37891--- a/drivers/firewire/core.h
37892+++ b/drivers/firewire/core.h
37893@@ -111,6 +111,7 @@ struct fw_card_driver {
37894
37895 int (*stop_iso)(struct fw_iso_context *ctx);
37896 };
37897+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37898
37899 void fw_card_initialize(struct fw_card *card,
37900 const struct fw_card_driver *driver, struct device *device);
37901diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37902index 94a58a0..f5eba42 100644
37903--- a/drivers/firmware/dmi-id.c
37904+++ b/drivers/firmware/dmi-id.c
37905@@ -16,7 +16,7 @@
37906 struct dmi_device_attribute{
37907 struct device_attribute dev_attr;
37908 int field;
37909-};
37910+} __do_const;
37911 #define to_dmi_dev_attr(_dev_attr) \
37912 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37913
37914diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37915index fa0affb..aa448eb 100644
37916--- a/drivers/firmware/dmi_scan.c
37917+++ b/drivers/firmware/dmi_scan.c
37918@@ -791,7 +791,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37919 if (buf == NULL)
37920 return -1;
37921
37922- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37923+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37924
37925 iounmap(buf);
37926 return 0;
37927diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37928index 5145fa3..0d3babd 100644
37929--- a/drivers/firmware/efi/efi.c
37930+++ b/drivers/firmware/efi/efi.c
37931@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37932 };
37933
37934 static struct efivars generic_efivars;
37935-static struct efivar_operations generic_ops;
37936+static efivar_operations_no_const generic_ops __read_only;
37937
37938 static int generic_ops_register(void)
37939 {
37940- generic_ops.get_variable = efi.get_variable;
37941- generic_ops.set_variable = efi.set_variable;
37942- generic_ops.get_next_variable = efi.get_next_variable;
37943- generic_ops.query_variable_store = efi_query_variable_store;
37944+ pax_open_kernel();
37945+ *(void **)&generic_ops.get_variable = efi.get_variable;
37946+ *(void **)&generic_ops.set_variable = efi.set_variable;
37947+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37948+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37949+ pax_close_kernel();
37950
37951 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37952 }
37953diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37954index 8a7432a..28fb839 100644
37955--- a/drivers/firmware/efi/efivars.c
37956+++ b/drivers/firmware/efi/efivars.c
37957@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37958 static int
37959 create_efivars_bin_attributes(void)
37960 {
37961- struct bin_attribute *attr;
37962+ bin_attribute_no_const *attr;
37963 int error;
37964
37965 /* new_var */
37966diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37967index 2a90ba6..07f3733 100644
37968--- a/drivers/firmware/google/memconsole.c
37969+++ b/drivers/firmware/google/memconsole.c
37970@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37971 if (!found_memconsole())
37972 return -ENODEV;
37973
37974- memconsole_bin_attr.size = memconsole_length;
37975+ pax_open_kernel();
37976+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37977+ pax_close_kernel();
37978
37979 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37980
37981diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37982index 814addb..0937d7f 100644
37983--- a/drivers/gpio/gpio-ich.c
37984+++ b/drivers/gpio/gpio-ich.c
37985@@ -71,7 +71,7 @@ struct ichx_desc {
37986 /* Some chipsets have quirks, let these use their own request/get */
37987 int (*request)(struct gpio_chip *chip, unsigned offset);
37988 int (*get)(struct gpio_chip *chip, unsigned offset);
37989-};
37990+} __do_const;
37991
37992 static struct {
37993 spinlock_t lock;
37994diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37995index 9902732..64b62dd 100644
37996--- a/drivers/gpio/gpio-vr41xx.c
37997+++ b/drivers/gpio/gpio-vr41xx.c
37998@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37999 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38000 maskl, pendl, maskh, pendh);
38001
38002- atomic_inc(&irq_err_count);
38003+ atomic_inc_unchecked(&irq_err_count);
38004
38005 return -EINVAL;
38006 }
38007diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38008index c722c3b..2ec6040 100644
38009--- a/drivers/gpu/drm/drm_crtc_helper.c
38010+++ b/drivers/gpu/drm/drm_crtc_helper.c
38011@@ -328,7 +328,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38012 struct drm_crtc *tmp;
38013 int crtc_mask = 1;
38014
38015- WARN(!crtc, "checking null crtc?\n");
38016+ BUG_ON(!crtc);
38017
38018 dev = crtc->dev;
38019
38020diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38021index fe58d08..07bc38e 100644
38022--- a/drivers/gpu/drm/drm_drv.c
38023+++ b/drivers/gpu/drm/drm_drv.c
38024@@ -186,7 +186,7 @@ static void drm_legacy_dev_reinit(struct drm_device *dev)
38025 atomic_set(&dev->vma_count, 0);
38026
38027 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38028- atomic_set(&dev->counts[i], 0);
38029+ atomic_set_unchecked(&dev->counts[i], 0);
38030
38031 dev->sigdata.lock = NULL;
38032
38033@@ -302,7 +302,7 @@ module_exit(drm_core_exit);
38034 /**
38035 * Copy and IOCTL return string to user space
38036 */
38037-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38038+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38039 {
38040 int len;
38041
38042@@ -372,7 +372,7 @@ long drm_ioctl(struct file *filp,
38043 struct drm_file *file_priv = filp->private_data;
38044 struct drm_device *dev;
38045 const struct drm_ioctl_desc *ioctl = NULL;
38046- drm_ioctl_t *func;
38047+ drm_ioctl_no_const_t func;
38048 unsigned int nr = DRM_IOCTL_NR(cmd);
38049 int retcode = -EINVAL;
38050 char stack_kdata[128];
38051@@ -385,7 +385,7 @@ long drm_ioctl(struct file *filp,
38052 return -ENODEV;
38053
38054 atomic_inc(&dev->ioctl_count);
38055- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38056+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38057 ++file_priv->ioctl_count;
38058
38059 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38060diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38061index 3f84277..c627c54 100644
38062--- a/drivers/gpu/drm/drm_fops.c
38063+++ b/drivers/gpu/drm/drm_fops.c
38064@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
38065 if (drm_device_is_unplugged(dev))
38066 return -ENODEV;
38067
38068- if (!dev->open_count++)
38069+ if (local_inc_return(&dev->open_count) == 1)
38070 need_setup = 1;
38071 mutex_lock(&dev->struct_mutex);
38072 old_imapping = inode->i_mapping;
38073@@ -113,7 +113,7 @@ int drm_open(struct inode *inode, struct file *filp)
38074 retcode = drm_open_helper(inode, filp, dev);
38075 if (retcode)
38076 goto err_undo;
38077- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38078+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38079 if (need_setup) {
38080 retcode = drm_setup(dev);
38081 if (retcode)
38082@@ -128,7 +128,7 @@ err_undo:
38083 iput(container_of(dev->dev_mapping, struct inode, i_data));
38084 dev->dev_mapping = old_mapping;
38085 mutex_unlock(&dev->struct_mutex);
38086- dev->open_count--;
38087+ local_dec(&dev->open_count);
38088 return retcode;
38089 }
38090 EXPORT_SYMBOL(drm_open);
38091@@ -405,7 +405,7 @@ int drm_release(struct inode *inode, struct file *filp)
38092
38093 mutex_lock(&drm_global_mutex);
38094
38095- DRM_DEBUG("open_count = %d\n", dev->open_count);
38096+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38097
38098 if (dev->driver->preclose)
38099 dev->driver->preclose(dev, file_priv);
38100@@ -414,10 +414,10 @@ int drm_release(struct inode *inode, struct file *filp)
38101 * Begin inline drm_release
38102 */
38103
38104- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38105+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38106 task_pid_nr(current),
38107 (long)old_encode_dev(file_priv->minor->device),
38108- dev->open_count);
38109+ local_read(&dev->open_count));
38110
38111 /* Release any auth tokens that might point to this file_priv,
38112 (do that under the drm_global_mutex) */
38113@@ -516,8 +516,8 @@ int drm_release(struct inode *inode, struct file *filp)
38114 * End inline drm_release
38115 */
38116
38117- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38118- if (!--dev->open_count) {
38119+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38120+ if (local_dec_and_test(&dev->open_count)) {
38121 if (atomic_read(&dev->ioctl_count)) {
38122 DRM_ERROR("Device busy: %d\n",
38123 atomic_read(&dev->ioctl_count));
38124diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38125index f731116..629842c 100644
38126--- a/drivers/gpu/drm/drm_global.c
38127+++ b/drivers/gpu/drm/drm_global.c
38128@@ -36,7 +36,7 @@
38129 struct drm_global_item {
38130 struct mutex mutex;
38131 void *object;
38132- int refcount;
38133+ atomic_t refcount;
38134 };
38135
38136 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38137@@ -49,7 +49,7 @@ void drm_global_init(void)
38138 struct drm_global_item *item = &glob[i];
38139 mutex_init(&item->mutex);
38140 item->object = NULL;
38141- item->refcount = 0;
38142+ atomic_set(&item->refcount, 0);
38143 }
38144 }
38145
38146@@ -59,7 +59,7 @@ void drm_global_release(void)
38147 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38148 struct drm_global_item *item = &glob[i];
38149 BUG_ON(item->object != NULL);
38150- BUG_ON(item->refcount != 0);
38151+ BUG_ON(atomic_read(&item->refcount) != 0);
38152 }
38153 }
38154
38155@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38156 void *object;
38157
38158 mutex_lock(&item->mutex);
38159- if (item->refcount == 0) {
38160+ if (atomic_read(&item->refcount) == 0) {
38161 item->object = kzalloc(ref->size, GFP_KERNEL);
38162 if (unlikely(item->object == NULL)) {
38163 ret = -ENOMEM;
38164@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38165 goto out_err;
38166
38167 }
38168- ++item->refcount;
38169+ atomic_inc(&item->refcount);
38170 ref->object = item->object;
38171 object = item->object;
38172 mutex_unlock(&item->mutex);
38173@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38174 struct drm_global_item *item = &glob[ref->global_type];
38175
38176 mutex_lock(&item->mutex);
38177- BUG_ON(item->refcount == 0);
38178+ BUG_ON(atomic_read(&item->refcount) == 0);
38179 BUG_ON(ref->object != item->object);
38180- if (--item->refcount == 0) {
38181+ if (atomic_dec_and_test(&item->refcount)) {
38182 ref->release(ref);
38183 item->object = NULL;
38184 }
38185diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38186index 5329832..b503f49 100644
38187--- a/drivers/gpu/drm/drm_info.c
38188+++ b/drivers/gpu/drm/drm_info.c
38189@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38190 struct drm_local_map *map;
38191 struct drm_map_list *r_list;
38192
38193- /* Hardcoded from _DRM_FRAME_BUFFER,
38194- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38195- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38196- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38197+ static const char * const types[] = {
38198+ [_DRM_FRAME_BUFFER] = "FB",
38199+ [_DRM_REGISTERS] = "REG",
38200+ [_DRM_SHM] = "SHM",
38201+ [_DRM_AGP] = "AGP",
38202+ [_DRM_SCATTER_GATHER] = "SG",
38203+ [_DRM_CONSISTENT] = "PCI",
38204+ [_DRM_GEM] = "GEM" };
38205 const char *type;
38206 int i;
38207
38208@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38209 map = r_list->map;
38210 if (!map)
38211 continue;
38212- if (map->type < 0 || map->type > 5)
38213+ if (map->type >= ARRAY_SIZE(types))
38214 type = "??";
38215 else
38216 type = types[map->type];
38217@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38218 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38219 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38220 vma->vm_flags & VM_IO ? 'i' : '-',
38221+#ifdef CONFIG_GRKERNSEC_HIDESYM
38222+ 0);
38223+#else
38224 vma->vm_pgoff);
38225+#endif
38226
38227 #if defined(__i386__)
38228 pgprot = pgprot_val(vma->vm_page_prot);
38229diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38230index 2f4c434..dd12cd2 100644
38231--- a/drivers/gpu/drm/drm_ioc32.c
38232+++ b/drivers/gpu/drm/drm_ioc32.c
38233@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38234 request = compat_alloc_user_space(nbytes);
38235 if (!access_ok(VERIFY_WRITE, request, nbytes))
38236 return -EFAULT;
38237- list = (struct drm_buf_desc *) (request + 1);
38238+ list = (struct drm_buf_desc __user *) (request + 1);
38239
38240 if (__put_user(count, &request->count)
38241 || __put_user(list, &request->list))
38242@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38243 request = compat_alloc_user_space(nbytes);
38244 if (!access_ok(VERIFY_WRITE, request, nbytes))
38245 return -EFAULT;
38246- list = (struct drm_buf_pub *) (request + 1);
38247+ list = (struct drm_buf_pub __user *) (request + 1);
38248
38249 if (__put_user(count, &request->count)
38250 || __put_user(list, &request->list))
38251@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38252 return 0;
38253 }
38254
38255-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38256+drm_ioctl_compat_t drm_compat_ioctls[] = {
38257 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38258 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38259 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38260@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38261 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38262 {
38263 unsigned int nr = DRM_IOCTL_NR(cmd);
38264- drm_ioctl_compat_t *fn;
38265 int ret;
38266
38267 /* Assume that ioctls without an explicit compat routine will just
38268@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38269 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38270 return drm_ioctl(filp, cmd, arg);
38271
38272- fn = drm_compat_ioctls[nr];
38273-
38274- if (fn != NULL)
38275- ret = (*fn) (filp, cmd, arg);
38276+ if (drm_compat_ioctls[nr] != NULL)
38277+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38278 else
38279 ret = drm_ioctl(filp, cmd, arg);
38280
38281diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38282index d752c96..fe08455 100644
38283--- a/drivers/gpu/drm/drm_lock.c
38284+++ b/drivers/gpu/drm/drm_lock.c
38285@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38286 if (drm_lock_take(&master->lock, lock->context)) {
38287 master->lock.file_priv = file_priv;
38288 master->lock.lock_time = jiffies;
38289- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38290+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38291 break; /* Got lock */
38292 }
38293
38294@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38295 return -EINVAL;
38296 }
38297
38298- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38299+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38300
38301 if (drm_lock_free(&master->lock, lock->context)) {
38302 /* FIXME: Should really bail out here. */
38303diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38304index 39d8645..59e06fa 100644
38305--- a/drivers/gpu/drm/drm_stub.c
38306+++ b/drivers/gpu/drm/drm_stub.c
38307@@ -484,7 +484,7 @@ void drm_unplug_dev(struct drm_device *dev)
38308
38309 drm_device_set_unplugged(dev);
38310
38311- if (dev->open_count == 0) {
38312+ if (local_read(&dev->open_count) == 0) {
38313 drm_put_dev(dev);
38314 }
38315 mutex_unlock(&drm_global_mutex);
38316diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38317index 2290b3b..22056a1 100644
38318--- a/drivers/gpu/drm/drm_sysfs.c
38319+++ b/drivers/gpu/drm/drm_sysfs.c
38320@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38321 int drm_sysfs_device_add(struct drm_minor *minor)
38322 {
38323 int err;
38324- char *minor_str;
38325+ const char *minor_str;
38326
38327 minor->kdev.parent = minor->dev->dev;
38328
38329diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38330index ab1892eb..d7009ca 100644
38331--- a/drivers/gpu/drm/i810/i810_dma.c
38332+++ b/drivers/gpu/drm/i810/i810_dma.c
38333@@ -944,8 +944,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38334 dma->buflist[vertex->idx],
38335 vertex->discard, vertex->used);
38336
38337- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38338- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38339+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38340+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38341 sarea_priv->last_enqueue = dev_priv->counter - 1;
38342 sarea_priv->last_dispatch = (int)hw_status[5];
38343
38344@@ -1105,8 +1105,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38345 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38346 mc->last_render);
38347
38348- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38349- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38350+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38351+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38352 sarea_priv->last_enqueue = dev_priv->counter - 1;
38353 sarea_priv->last_dispatch = (int)hw_status[5];
38354
38355diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38356index d4d16ed..8fb0b51 100644
38357--- a/drivers/gpu/drm/i810/i810_drv.h
38358+++ b/drivers/gpu/drm/i810/i810_drv.h
38359@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38360 int page_flipping;
38361
38362 wait_queue_head_t irq_queue;
38363- atomic_t irq_received;
38364- atomic_t irq_emitted;
38365+ atomic_unchecked_t irq_received;
38366+ atomic_unchecked_t irq_emitted;
38367
38368 int front_offset;
38369 } drm_i810_private_t;
38370diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38371index a6f4cb5..6b2beb2 100644
38372--- a/drivers/gpu/drm/i915/i915_debugfs.c
38373+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38374@@ -624,7 +624,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38375 I915_READ(GTIMR));
38376 }
38377 seq_printf(m, "Interrupts received: %d\n",
38378- atomic_read(&dev_priv->irq_received));
38379+ atomic_read_unchecked(&dev_priv->irq_received));
38380 for_each_ring(ring, dev_priv, i) {
38381 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38382 seq_printf(m,
38383diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38384index d5c784d..06e5c36 100644
38385--- a/drivers/gpu/drm/i915/i915_dma.c
38386+++ b/drivers/gpu/drm/i915/i915_dma.c
38387@@ -1263,7 +1263,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38388 bool can_switch;
38389
38390 spin_lock(&dev->count_lock);
38391- can_switch = (dev->open_count == 0);
38392+ can_switch = (local_read(&dev->open_count) == 0);
38393 spin_unlock(&dev->count_lock);
38394 return can_switch;
38395 }
38396diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38397index ab0f2c0..53c1bda 100644
38398--- a/drivers/gpu/drm/i915/i915_drv.h
38399+++ b/drivers/gpu/drm/i915/i915_drv.h
38400@@ -1181,7 +1181,7 @@ typedef struct drm_i915_private {
38401 drm_dma_handle_t *status_page_dmah;
38402 struct resource mch_res;
38403
38404- atomic_t irq_received;
38405+ atomic_unchecked_t irq_received;
38406
38407 /* protects the irq masks */
38408 spinlock_t irq_lock;
38409diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38410index bf34577..3fd2ffa 100644
38411--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38412+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38413@@ -768,9 +768,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38414
38415 static int
38416 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38417- int count)
38418+ unsigned int count)
38419 {
38420- int i;
38421+ unsigned int i;
38422 int relocs_total = 0;
38423 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38424
38425diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38426index 3c59584..500f2e9 100644
38427--- a/drivers/gpu/drm/i915/i915_ioc32.c
38428+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38429@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38430 (unsigned long)request);
38431 }
38432
38433-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38434+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38435 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38436 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38437 [DRM_I915_GETPARAM] = compat_i915_getparam,
38438@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38439 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38440 {
38441 unsigned int nr = DRM_IOCTL_NR(cmd);
38442- drm_ioctl_compat_t *fn = NULL;
38443 int ret;
38444
38445 if (nr < DRM_COMMAND_BASE)
38446 return drm_compat_ioctl(filp, cmd, arg);
38447
38448- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38449- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38450-
38451- if (fn != NULL)
38452+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38453+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38454 ret = (*fn) (filp, cmd, arg);
38455- else
38456+ } else
38457 ret = drm_ioctl(filp, cmd, arg);
38458
38459 return ret;
38460diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38461index 4b91228..590c643 100644
38462--- a/drivers/gpu/drm/i915/i915_irq.c
38463+++ b/drivers/gpu/drm/i915/i915_irq.c
38464@@ -1085,7 +1085,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38465 int pipe;
38466 u32 pipe_stats[I915_MAX_PIPES];
38467
38468- atomic_inc(&dev_priv->irq_received);
38469+ atomic_inc_unchecked(&dev_priv->irq_received);
38470
38471 while (true) {
38472 iir = I915_READ(VLV_IIR);
38473@@ -1390,7 +1390,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38474 irqreturn_t ret = IRQ_NONE;
38475 bool err_int_reenable = false;
38476
38477- atomic_inc(&dev_priv->irq_received);
38478+ atomic_inc_unchecked(&dev_priv->irq_received);
38479
38480 /* We get interrupts on unclaimed registers, so check for this before we
38481 * do any I915_{READ,WRITE}. */
38482@@ -2146,7 +2146,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38483 {
38484 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38485
38486- atomic_set(&dev_priv->irq_received, 0);
38487+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38488
38489 I915_WRITE(HWSTAM, 0xeffe);
38490
38491@@ -2164,7 +2164,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38492 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38493 int pipe;
38494
38495- atomic_set(&dev_priv->irq_received, 0);
38496+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38497
38498 /* VLV magic */
38499 I915_WRITE(VLV_IMR, 0);
38500@@ -2452,7 +2452,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38501 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38502 int pipe;
38503
38504- atomic_set(&dev_priv->irq_received, 0);
38505+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38506
38507 for_each_pipe(pipe)
38508 I915_WRITE(PIPESTAT(pipe), 0);
38509@@ -2530,7 +2530,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38510 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38511 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38512
38513- atomic_inc(&dev_priv->irq_received);
38514+ atomic_inc_unchecked(&dev_priv->irq_received);
38515
38516 iir = I915_READ16(IIR);
38517 if (iir == 0)
38518@@ -2604,7 +2604,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38519 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38520 int pipe;
38521
38522- atomic_set(&dev_priv->irq_received, 0);
38523+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38524
38525 if (I915_HAS_HOTPLUG(dev)) {
38526 I915_WRITE(PORT_HOTPLUG_EN, 0);
38527@@ -2703,7 +2703,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38528 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38529 int pipe, ret = IRQ_NONE;
38530
38531- atomic_inc(&dev_priv->irq_received);
38532+ atomic_inc_unchecked(&dev_priv->irq_received);
38533
38534 iir = I915_READ(IIR);
38535 do {
38536@@ -2827,7 +2827,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38537 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38538 int pipe;
38539
38540- atomic_set(&dev_priv->irq_received, 0);
38541+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38542
38543 I915_WRITE(PORT_HOTPLUG_EN, 0);
38544 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38545@@ -2941,7 +2941,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38546 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38547 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38548
38549- atomic_inc(&dev_priv->irq_received);
38550+ atomic_inc_unchecked(&dev_priv->irq_received);
38551
38552 iir = I915_READ(IIR);
38553
38554diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38555index d78d33f..01d7c58 100644
38556--- a/drivers/gpu/drm/i915/intel_display.c
38557+++ b/drivers/gpu/drm/i915/intel_display.c
38558@@ -9972,13 +9972,13 @@ struct intel_quirk {
38559 int subsystem_vendor;
38560 int subsystem_device;
38561 void (*hook)(struct drm_device *dev);
38562-};
38563+} __do_const;
38564
38565 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38566 struct intel_dmi_quirk {
38567 void (*hook)(struct drm_device *dev);
38568 const struct dmi_system_id (*dmi_id_list)[];
38569-};
38570+} __do_const;
38571
38572 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38573 {
38574@@ -9986,18 +9986,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38575 return 1;
38576 }
38577
38578-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38579+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38580 {
38581- .dmi_id_list = &(const struct dmi_system_id[]) {
38582- {
38583- .callback = intel_dmi_reverse_brightness,
38584- .ident = "NCR Corporation",
38585- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38586- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38587- },
38588- },
38589- { } /* terminating entry */
38590+ .callback = intel_dmi_reverse_brightness,
38591+ .ident = "NCR Corporation",
38592+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38593+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38594 },
38595+ },
38596+ { } /* terminating entry */
38597+};
38598+
38599+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38600+ {
38601+ .dmi_id_list = &intel_dmi_quirks_table,
38602 .hook = quirk_invert_brightness,
38603 },
38604 };
38605diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38606index ca4bc54..ee598a2 100644
38607--- a/drivers/gpu/drm/mga/mga_drv.h
38608+++ b/drivers/gpu/drm/mga/mga_drv.h
38609@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38610 u32 clear_cmd;
38611 u32 maccess;
38612
38613- atomic_t vbl_received; /**< Number of vblanks received. */
38614+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38615 wait_queue_head_t fence_queue;
38616- atomic_t last_fence_retired;
38617+ atomic_unchecked_t last_fence_retired;
38618 u32 next_fence_to_post;
38619
38620 unsigned int fb_cpp;
38621diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38622index 709e90d..89a1c0d 100644
38623--- a/drivers/gpu/drm/mga/mga_ioc32.c
38624+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38625@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38626 return 0;
38627 }
38628
38629-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38630+drm_ioctl_compat_t mga_compat_ioctls[] = {
38631 [DRM_MGA_INIT] = compat_mga_init,
38632 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38633 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38634@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38635 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38636 {
38637 unsigned int nr = DRM_IOCTL_NR(cmd);
38638- drm_ioctl_compat_t *fn = NULL;
38639 int ret;
38640
38641 if (nr < DRM_COMMAND_BASE)
38642 return drm_compat_ioctl(filp, cmd, arg);
38643
38644- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38645- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38646-
38647- if (fn != NULL)
38648+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38649+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38650 ret = (*fn) (filp, cmd, arg);
38651- else
38652+ } else
38653 ret = drm_ioctl(filp, cmd, arg);
38654
38655 return ret;
38656diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38657index 598c281..60d590e 100644
38658--- a/drivers/gpu/drm/mga/mga_irq.c
38659+++ b/drivers/gpu/drm/mga/mga_irq.c
38660@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38661 if (crtc != 0)
38662 return 0;
38663
38664- return atomic_read(&dev_priv->vbl_received);
38665+ return atomic_read_unchecked(&dev_priv->vbl_received);
38666 }
38667
38668
38669@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38670 /* VBLANK interrupt */
38671 if (status & MGA_VLINEPEN) {
38672 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38673- atomic_inc(&dev_priv->vbl_received);
38674+ atomic_inc_unchecked(&dev_priv->vbl_received);
38675 drm_handle_vblank(dev, 0);
38676 handled = 1;
38677 }
38678@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38679 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38680 MGA_WRITE(MGA_PRIMEND, prim_end);
38681
38682- atomic_inc(&dev_priv->last_fence_retired);
38683+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38684 DRM_WAKEUP(&dev_priv->fence_queue);
38685 handled = 1;
38686 }
38687@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38688 * using fences.
38689 */
38690 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38691- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38692+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38693 - *sequence) <= (1 << 23)));
38694
38695 *sequence = cur_fence;
38696diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38697index 3e72876..d1c15ad 100644
38698--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38699+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38700@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38701 struct bit_table {
38702 const char id;
38703 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38704-};
38705+} __no_const;
38706
38707 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38708
38709diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38710index 994fd6e..6e12565 100644
38711--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38712+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38713@@ -94,7 +94,6 @@ struct nouveau_drm {
38714 struct drm_global_reference mem_global_ref;
38715 struct ttm_bo_global_ref bo_global_ref;
38716 struct ttm_bo_device bdev;
38717- atomic_t validate_sequence;
38718 int (*move)(struct nouveau_channel *,
38719 struct ttm_buffer_object *,
38720 struct ttm_mem_reg *, struct ttm_mem_reg *);
38721diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38722index c1a7e5a..38b8539 100644
38723--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38724+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38725@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38726 unsigned long arg)
38727 {
38728 unsigned int nr = DRM_IOCTL_NR(cmd);
38729- drm_ioctl_compat_t *fn = NULL;
38730+ drm_ioctl_compat_t fn = NULL;
38731 int ret;
38732
38733 if (nr < DRM_COMMAND_BASE)
38734diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38735index 81638d7..2e45854 100644
38736--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38737+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38738@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38739 bool can_switch;
38740
38741 spin_lock(&dev->count_lock);
38742- can_switch = (dev->open_count == 0);
38743+ can_switch = (local_read(&dev->open_count) == 0);
38744 spin_unlock(&dev->count_lock);
38745 return can_switch;
38746 }
38747diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
38748index eb89653..613cf71 100644
38749--- a/drivers/gpu/drm/qxl/qxl_cmd.c
38750+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
38751@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
38752 int ret;
38753
38754 mutex_lock(&qdev->async_io_mutex);
38755- irq_num = atomic_read(&qdev->irq_received_io_cmd);
38756+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
38757 if (qdev->last_sent_io_cmd > irq_num) {
38758 if (intr)
38759 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
38760- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38761+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38762 else
38763 ret = wait_event_timeout(qdev->io_cmd_event,
38764- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38765+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38766 /* 0 is timeout, just bail the "hw" has gone away */
38767 if (ret <= 0)
38768 goto out;
38769- irq_num = atomic_read(&qdev->irq_received_io_cmd);
38770+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
38771 }
38772 outb(val, addr);
38773 qdev->last_sent_io_cmd = irq_num + 1;
38774 if (intr)
38775 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
38776- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38777+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38778 else
38779 ret = wait_event_timeout(qdev->io_cmd_event,
38780- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38781+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38782 out:
38783 if (ret > 0)
38784 ret = 0;
38785diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
38786index c3c2bbd..bc3c0fb 100644
38787--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
38788+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
38789@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
38790 struct drm_info_node *node = (struct drm_info_node *) m->private;
38791 struct qxl_device *qdev = node->minor->dev->dev_private;
38792
38793- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
38794- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
38795- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
38796- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
38797+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
38798+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
38799+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
38800+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
38801 seq_printf(m, "%d\n", qdev->irq_received_error);
38802 return 0;
38803 }
38804diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
38805index f7c9add..fb971d2 100644
38806--- a/drivers/gpu/drm/qxl/qxl_drv.h
38807+++ b/drivers/gpu/drm/qxl/qxl_drv.h
38808@@ -290,10 +290,10 @@ struct qxl_device {
38809 unsigned int last_sent_io_cmd;
38810
38811 /* interrupt handling */
38812- atomic_t irq_received;
38813- atomic_t irq_received_display;
38814- atomic_t irq_received_cursor;
38815- atomic_t irq_received_io_cmd;
38816+ atomic_unchecked_t irq_received;
38817+ atomic_unchecked_t irq_received_display;
38818+ atomic_unchecked_t irq_received_cursor;
38819+ atomic_unchecked_t irq_received_io_cmd;
38820 unsigned irq_received_error;
38821 wait_queue_head_t display_event;
38822 wait_queue_head_t cursor_event;
38823diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
38824index 21393dc..329f3a9 100644
38825--- a/drivers/gpu/drm/qxl/qxl_irq.c
38826+++ b/drivers/gpu/drm/qxl/qxl_irq.c
38827@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
38828
38829 pending = xchg(&qdev->ram_header->int_pending, 0);
38830
38831- atomic_inc(&qdev->irq_received);
38832+ atomic_inc_unchecked(&qdev->irq_received);
38833
38834 if (pending & QXL_INTERRUPT_DISPLAY) {
38835- atomic_inc(&qdev->irq_received_display);
38836+ atomic_inc_unchecked(&qdev->irq_received_display);
38837 wake_up_all(&qdev->display_event);
38838 qxl_queue_garbage_collect(qdev, false);
38839 }
38840 if (pending & QXL_INTERRUPT_CURSOR) {
38841- atomic_inc(&qdev->irq_received_cursor);
38842+ atomic_inc_unchecked(&qdev->irq_received_cursor);
38843 wake_up_all(&qdev->cursor_event);
38844 }
38845 if (pending & QXL_INTERRUPT_IO_CMD) {
38846- atomic_inc(&qdev->irq_received_io_cmd);
38847+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
38848 wake_up_all(&qdev->io_cmd_event);
38849 }
38850 if (pending & QXL_INTERRUPT_ERROR) {
38851@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
38852 init_waitqueue_head(&qdev->io_cmd_event);
38853 INIT_WORK(&qdev->client_monitors_config_work,
38854 qxl_client_monitors_config_work_func);
38855- atomic_set(&qdev->irq_received, 0);
38856- atomic_set(&qdev->irq_received_display, 0);
38857- atomic_set(&qdev->irq_received_cursor, 0);
38858- atomic_set(&qdev->irq_received_io_cmd, 0);
38859+ atomic_set_unchecked(&qdev->irq_received, 0);
38860+ atomic_set_unchecked(&qdev->irq_received_display, 0);
38861+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
38862+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
38863 qdev->irq_received_error = 0;
38864 ret = drm_irq_install(qdev->ddev);
38865 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
38866diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38867index 037786d..2a95e33 100644
38868--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38869+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38870@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38871 }
38872 }
38873
38874-static struct vm_operations_struct qxl_ttm_vm_ops;
38875+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38876 static const struct vm_operations_struct *ttm_vm_ops;
38877
38878 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38879@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38880 return r;
38881 if (unlikely(ttm_vm_ops == NULL)) {
38882 ttm_vm_ops = vma->vm_ops;
38883+ pax_open_kernel();
38884 qxl_ttm_vm_ops = *ttm_vm_ops;
38885 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38886+ pax_close_kernel();
38887 }
38888 vma->vm_ops = &qxl_ttm_vm_ops;
38889 return 0;
38890@@ -558,25 +560,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38891 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38892 {
38893 #if defined(CONFIG_DEBUG_FS)
38894- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38895- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38896- unsigned i;
38897+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38898+ {
38899+ .name = "qxl_mem_mm",
38900+ .show = &qxl_mm_dump_table,
38901+ },
38902+ {
38903+ .name = "qxl_surf_mm",
38904+ .show = &qxl_mm_dump_table,
38905+ }
38906+ };
38907
38908- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38909- if (i == 0)
38910- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38911- else
38912- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38913- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38914- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38915- qxl_mem_types_list[i].driver_features = 0;
38916- if (i == 0)
38917- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38918- else
38919- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38920+ pax_open_kernel();
38921+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38922+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38923+ pax_close_kernel();
38924
38925- }
38926- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38927+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38928 #else
38929 return 0;
38930 #endif
38931diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38932index c451257..0ad2134 100644
38933--- a/drivers/gpu/drm/r128/r128_cce.c
38934+++ b/drivers/gpu/drm/r128/r128_cce.c
38935@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38936
38937 /* GH: Simple idle check.
38938 */
38939- atomic_set(&dev_priv->idle_count, 0);
38940+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38941
38942 /* We don't support anything other than bus-mastering ring mode,
38943 * but the ring can be in either AGP or PCI space for the ring
38944diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38945index 56eb5e3..c4ec43d 100644
38946--- a/drivers/gpu/drm/r128/r128_drv.h
38947+++ b/drivers/gpu/drm/r128/r128_drv.h
38948@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38949 int is_pci;
38950 unsigned long cce_buffers_offset;
38951
38952- atomic_t idle_count;
38953+ atomic_unchecked_t idle_count;
38954
38955 int page_flipping;
38956 int current_page;
38957 u32 crtc_offset;
38958 u32 crtc_offset_cntl;
38959
38960- atomic_t vbl_received;
38961+ atomic_unchecked_t vbl_received;
38962
38963 u32 color_fmt;
38964 unsigned int front_offset;
38965diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38966index a954c54..9cc595c 100644
38967--- a/drivers/gpu/drm/r128/r128_ioc32.c
38968+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38969@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38970 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38971 }
38972
38973-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38974+drm_ioctl_compat_t r128_compat_ioctls[] = {
38975 [DRM_R128_INIT] = compat_r128_init,
38976 [DRM_R128_DEPTH] = compat_r128_depth,
38977 [DRM_R128_STIPPLE] = compat_r128_stipple,
38978@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38979 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38980 {
38981 unsigned int nr = DRM_IOCTL_NR(cmd);
38982- drm_ioctl_compat_t *fn = NULL;
38983 int ret;
38984
38985 if (nr < DRM_COMMAND_BASE)
38986 return drm_compat_ioctl(filp, cmd, arg);
38987
38988- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38989- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38990-
38991- if (fn != NULL)
38992+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38993+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38994 ret = (*fn) (filp, cmd, arg);
38995- else
38996+ } else
38997 ret = drm_ioctl(filp, cmd, arg);
38998
38999 return ret;
39000diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39001index 2ea4f09..d391371 100644
39002--- a/drivers/gpu/drm/r128/r128_irq.c
39003+++ b/drivers/gpu/drm/r128/r128_irq.c
39004@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39005 if (crtc != 0)
39006 return 0;
39007
39008- return atomic_read(&dev_priv->vbl_received);
39009+ return atomic_read_unchecked(&dev_priv->vbl_received);
39010 }
39011
39012 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39013@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39014 /* VBLANK interrupt */
39015 if (status & R128_CRTC_VBLANK_INT) {
39016 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39017- atomic_inc(&dev_priv->vbl_received);
39018+ atomic_inc_unchecked(&dev_priv->vbl_received);
39019 drm_handle_vblank(dev, 0);
39020 return IRQ_HANDLED;
39021 }
39022diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39023index 01dd9ae..6352f04 100644
39024--- a/drivers/gpu/drm/r128/r128_state.c
39025+++ b/drivers/gpu/drm/r128/r128_state.c
39026@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39027
39028 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39029 {
39030- if (atomic_read(&dev_priv->idle_count) == 0)
39031+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39032 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39033 else
39034- atomic_set(&dev_priv->idle_count, 0);
39035+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39036 }
39037
39038 #endif
39039diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39040index af85299..ed9ac8d 100644
39041--- a/drivers/gpu/drm/radeon/mkregtable.c
39042+++ b/drivers/gpu/drm/radeon/mkregtable.c
39043@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
39044 regex_t mask_rex;
39045 regmatch_t match[4];
39046 char buf[1024];
39047- size_t end;
39048+ long end;
39049 int len;
39050 int done = 0;
39051 int r;
39052 unsigned o;
39053 struct offset *offset;
39054 char last_reg_s[10];
39055- int last_reg;
39056+ unsigned long last_reg;
39057
39058 if (regcomp
39059 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39060diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39061index 841d0e0..9eaa268 100644
39062--- a/drivers/gpu/drm/radeon/radeon_device.c
39063+++ b/drivers/gpu/drm/radeon/radeon_device.c
39064@@ -1117,7 +1117,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39065 bool can_switch;
39066
39067 spin_lock(&dev->count_lock);
39068- can_switch = (dev->open_count == 0);
39069+ can_switch = (local_read(&dev->open_count) == 0);
39070 spin_unlock(&dev->count_lock);
39071 return can_switch;
39072 }
39073diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39074index b369d42..8dd04eb 100644
39075--- a/drivers/gpu/drm/radeon/radeon_drv.h
39076+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39077@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39078
39079 /* SW interrupt */
39080 wait_queue_head_t swi_queue;
39081- atomic_t swi_emitted;
39082+ atomic_unchecked_t swi_emitted;
39083 int vblank_crtc;
39084 uint32_t irq_enable_reg;
39085 uint32_t r500_disp_irq_reg;
39086diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39087index c180df8..5fd8186 100644
39088--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39089+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39090@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39091 request = compat_alloc_user_space(sizeof(*request));
39092 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39093 || __put_user(req32.param, &request->param)
39094- || __put_user((void __user *)(unsigned long)req32.value,
39095+ || __put_user((unsigned long)req32.value,
39096 &request->value))
39097 return -EFAULT;
39098
39099@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39100 #define compat_radeon_cp_setparam NULL
39101 #endif /* X86_64 || IA64 */
39102
39103-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39104+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39105 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39106 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39107 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39108@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39109 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39110 {
39111 unsigned int nr = DRM_IOCTL_NR(cmd);
39112- drm_ioctl_compat_t *fn = NULL;
39113 int ret;
39114
39115 if (nr < DRM_COMMAND_BASE)
39116 return drm_compat_ioctl(filp, cmd, arg);
39117
39118- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39119- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39120-
39121- if (fn != NULL)
39122+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39123+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39124 ret = (*fn) (filp, cmd, arg);
39125- else
39126+ } else
39127 ret = drm_ioctl(filp, cmd, arg);
39128
39129 return ret;
39130diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39131index 8d68e97..9dcfed8 100644
39132--- a/drivers/gpu/drm/radeon/radeon_irq.c
39133+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39134@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39135 unsigned int ret;
39136 RING_LOCALS;
39137
39138- atomic_inc(&dev_priv->swi_emitted);
39139- ret = atomic_read(&dev_priv->swi_emitted);
39140+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39141+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39142
39143 BEGIN_RING(4);
39144 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39145@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39146 drm_radeon_private_t *dev_priv =
39147 (drm_radeon_private_t *) dev->dev_private;
39148
39149- atomic_set(&dev_priv->swi_emitted, 0);
39150+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39151 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39152
39153 dev->max_vblank_count = 0x001fffff;
39154diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39155index 4d20910..6726b6d 100644
39156--- a/drivers/gpu/drm/radeon/radeon_state.c
39157+++ b/drivers/gpu/drm/radeon/radeon_state.c
39158@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39159 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39160 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39161
39162- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39163+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39164 sarea_priv->nbox * sizeof(depth_boxes[0])))
39165 return -EFAULT;
39166
39167@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39168 {
39169 drm_radeon_private_t *dev_priv = dev->dev_private;
39170 drm_radeon_getparam_t *param = data;
39171- int value;
39172+ int value = 0;
39173
39174 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39175
39176diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39177index 71245d6..94c556d 100644
39178--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39179+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39180@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39181 man->size = size >> PAGE_SHIFT;
39182 }
39183
39184-static struct vm_operations_struct radeon_ttm_vm_ops;
39185+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39186 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39187
39188 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39189@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39190 }
39191 if (unlikely(ttm_vm_ops == NULL)) {
39192 ttm_vm_ops = vma->vm_ops;
39193+ pax_open_kernel();
39194 radeon_ttm_vm_ops = *ttm_vm_ops;
39195 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39196+ pax_close_kernel();
39197 }
39198 vma->vm_ops = &radeon_ttm_vm_ops;
39199 return 0;
39200@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39201 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39202 {
39203 #if defined(CONFIG_DEBUG_FS)
39204- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39205- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39206- unsigned i;
39207+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39208+ {
39209+ .name = "radeon_vram_mm",
39210+ .show = &radeon_mm_dump_table,
39211+ },
39212+ {
39213+ .name = "radeon_gtt_mm",
39214+ .show = &radeon_mm_dump_table,
39215+ },
39216+ {
39217+ .name = "ttm_page_pool",
39218+ .show = &ttm_page_alloc_debugfs,
39219+ },
39220+ {
39221+ .name = "ttm_dma_page_pool",
39222+ .show = &ttm_dma_page_alloc_debugfs,
39223+ },
39224+ };
39225+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
39226
39227- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39228- if (i == 0)
39229- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39230- else
39231- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39232- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39233- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39234- radeon_mem_types_list[i].driver_features = 0;
39235- if (i == 0)
39236- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39237- else
39238- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39239-
39240- }
39241- /* Add ttm page pool to debugfs */
39242- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39243- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39244- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39245- radeon_mem_types_list[i].driver_features = 0;
39246- radeon_mem_types_list[i++].data = NULL;
39247+ pax_open_kernel();
39248+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39249+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39250+ pax_close_kernel();
39251 #ifdef CONFIG_SWIOTLB
39252- if (swiotlb_nr_tbl()) {
39253- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39254- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39255- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39256- radeon_mem_types_list[i].driver_features = 0;
39257- radeon_mem_types_list[i++].data = NULL;
39258- }
39259+ if (swiotlb_nr_tbl())
39260+ i++;
39261 #endif
39262 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39263
39264diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39265index 1447d79..40b2a5b 100644
39266--- a/drivers/gpu/drm/radeon/rs690.c
39267+++ b/drivers/gpu/drm/radeon/rs690.c
39268@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39269 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39270 rdev->pm.sideport_bandwidth.full)
39271 max_bandwidth = rdev->pm.sideport_bandwidth;
39272- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39273+ read_delay_latency.full = dfixed_const(800 * 1000);
39274 read_delay_latency.full = dfixed_div(read_delay_latency,
39275 rdev->pm.igp_sideport_mclk);
39276+ a.full = dfixed_const(370);
39277+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39278 } else {
39279 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39280 rdev->pm.k8_bandwidth.full)
39281diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39282index dbc2def..0a9f710 100644
39283--- a/drivers/gpu/drm/ttm/ttm_memory.c
39284+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39285@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39286 zone->glob = glob;
39287 glob->zone_kernel = zone;
39288 ret = kobject_init_and_add(
39289- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39290+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39291 if (unlikely(ret != 0)) {
39292 kobject_put(&zone->kobj);
39293 return ret;
39294@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39295 zone->glob = glob;
39296 glob->zone_dma32 = zone;
39297 ret = kobject_init_and_add(
39298- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39299+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39300 if (unlikely(ret != 0)) {
39301 kobject_put(&zone->kobj);
39302 return ret;
39303diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39304index 863bef9..cba15cf 100644
39305--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39306+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39307@@ -391,9 +391,9 @@ out:
39308 static unsigned long
39309 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
39310 {
39311- static atomic_t start_pool = ATOMIC_INIT(0);
39312+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39313 unsigned i;
39314- unsigned pool_offset = atomic_add_return(1, &start_pool);
39315+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39316 struct ttm_page_pool *pool;
39317 int shrink_pages = sc->nr_to_scan;
39318 unsigned long freed = 0;
39319diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39320index 97e9d61..bf23c461 100644
39321--- a/drivers/gpu/drm/udl/udl_fb.c
39322+++ b/drivers/gpu/drm/udl/udl_fb.c
39323@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39324 fb_deferred_io_cleanup(info);
39325 kfree(info->fbdefio);
39326 info->fbdefio = NULL;
39327- info->fbops->fb_mmap = udl_fb_mmap;
39328 }
39329
39330 pr_warn("released /dev/fb%d user=%d count=%d\n",
39331diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39332index a811ef2..ff99b05 100644
39333--- a/drivers/gpu/drm/via/via_drv.h
39334+++ b/drivers/gpu/drm/via/via_drv.h
39335@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39336 typedef uint32_t maskarray_t[5];
39337
39338 typedef struct drm_via_irq {
39339- atomic_t irq_received;
39340+ atomic_unchecked_t irq_received;
39341 uint32_t pending_mask;
39342 uint32_t enable_mask;
39343 wait_queue_head_t irq_queue;
39344@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39345 struct timeval last_vblank;
39346 int last_vblank_valid;
39347 unsigned usec_per_vblank;
39348- atomic_t vbl_received;
39349+ atomic_unchecked_t vbl_received;
39350 drm_via_state_t hc_state;
39351 char pci_buf[VIA_PCI_BUF_SIZE];
39352 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39353diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39354index ac98964..5dbf512 100644
39355--- a/drivers/gpu/drm/via/via_irq.c
39356+++ b/drivers/gpu/drm/via/via_irq.c
39357@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39358 if (crtc != 0)
39359 return 0;
39360
39361- return atomic_read(&dev_priv->vbl_received);
39362+ return atomic_read_unchecked(&dev_priv->vbl_received);
39363 }
39364
39365 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39366@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39367
39368 status = VIA_READ(VIA_REG_INTERRUPT);
39369 if (status & VIA_IRQ_VBLANK_PENDING) {
39370- atomic_inc(&dev_priv->vbl_received);
39371- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39372+ atomic_inc_unchecked(&dev_priv->vbl_received);
39373+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39374 do_gettimeofday(&cur_vblank);
39375 if (dev_priv->last_vblank_valid) {
39376 dev_priv->usec_per_vblank =
39377@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39378 dev_priv->last_vblank = cur_vblank;
39379 dev_priv->last_vblank_valid = 1;
39380 }
39381- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39382+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39383 DRM_DEBUG("US per vblank is: %u\n",
39384 dev_priv->usec_per_vblank);
39385 }
39386@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39387
39388 for (i = 0; i < dev_priv->num_irqs; ++i) {
39389 if (status & cur_irq->pending_mask) {
39390- atomic_inc(&cur_irq->irq_received);
39391+ atomic_inc_unchecked(&cur_irq->irq_received);
39392 DRM_WAKEUP(&cur_irq->irq_queue);
39393 handled = 1;
39394 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39395@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39396 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39397 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39398 masks[irq][4]));
39399- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39400+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39401 } else {
39402 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39403 (((cur_irq_sequence =
39404- atomic_read(&cur_irq->irq_received)) -
39405+ atomic_read_unchecked(&cur_irq->irq_received)) -
39406 *sequence) <= (1 << 23)));
39407 }
39408 *sequence = cur_irq_sequence;
39409@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39410 }
39411
39412 for (i = 0; i < dev_priv->num_irqs; ++i) {
39413- atomic_set(&cur_irq->irq_received, 0);
39414+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39415 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39416 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39417 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39418@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39419 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39420 case VIA_IRQ_RELATIVE:
39421 irqwait->request.sequence +=
39422- atomic_read(&cur_irq->irq_received);
39423+ atomic_read_unchecked(&cur_irq->irq_received);
39424 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39425 case VIA_IRQ_ABSOLUTE:
39426 break;
39427diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39428index 150ec64..f5165f2 100644
39429--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39430+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39431@@ -290,7 +290,7 @@ struct vmw_private {
39432 * Fencing and IRQs.
39433 */
39434
39435- atomic_t marker_seq;
39436+ atomic_unchecked_t marker_seq;
39437 wait_queue_head_t fence_queue;
39438 wait_queue_head_t fifo_queue;
39439 int fence_queue_waiters; /* Protected by hw_mutex */
39440diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39441index 3eb1486..0a47ee9 100644
39442--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39443+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39444@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39445 (unsigned int) min,
39446 (unsigned int) fifo->capabilities);
39447
39448- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39449+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39450 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39451 vmw_marker_queue_init(&fifo->marker_queue);
39452 return vmw_fifo_send_fence(dev_priv, &dummy);
39453@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39454 if (reserveable)
39455 iowrite32(bytes, fifo_mem +
39456 SVGA_FIFO_RESERVED);
39457- return fifo_mem + (next_cmd >> 2);
39458+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39459 } else {
39460 need_bounce = true;
39461 }
39462@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39463
39464 fm = vmw_fifo_reserve(dev_priv, bytes);
39465 if (unlikely(fm == NULL)) {
39466- *seqno = atomic_read(&dev_priv->marker_seq);
39467+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39468 ret = -ENOMEM;
39469 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39470 false, 3*HZ);
39471@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39472 }
39473
39474 do {
39475- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39476+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39477 } while (*seqno == 0);
39478
39479 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39480diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39481index c509d40..3b640c3 100644
39482--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39483+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39484@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39485 int ret;
39486
39487 num_clips = arg->num_clips;
39488- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39489+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39490
39491 if (unlikely(num_clips == 0))
39492 return 0;
39493@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39494 int ret;
39495
39496 num_clips = arg->num_clips;
39497- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39498+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39499
39500 if (unlikely(num_clips == 0))
39501 return 0;
39502diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39503index 4640adb..e1384ed 100644
39504--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39505+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39506@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39507 * emitted. Then the fence is stale and signaled.
39508 */
39509
39510- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39511+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39512 > VMW_FENCE_WRAP);
39513
39514 return ret;
39515@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39516
39517 if (fifo_idle)
39518 down_read(&fifo_state->rwsem);
39519- signal_seq = atomic_read(&dev_priv->marker_seq);
39520+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39521 ret = 0;
39522
39523 for (;;) {
39524diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39525index 8a8725c2..afed796 100644
39526--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39527+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39528@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39529 while (!vmw_lag_lt(queue, us)) {
39530 spin_lock(&queue->lock);
39531 if (list_empty(&queue->head))
39532- seqno = atomic_read(&dev_priv->marker_seq);
39533+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39534 else {
39535 marker = list_first_entry(&queue->head,
39536 struct vmw_marker, head);
39537diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39538index b1a05ad..1c9d899 100644
39539--- a/drivers/gpu/host1x/drm/dc.c
39540+++ b/drivers/gpu/host1x/drm/dc.c
39541@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39542 }
39543
39544 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39545- dc->debugfs_files[i].data = dc;
39546+ *(void **)&dc->debugfs_files[i].data = dc;
39547
39548 err = drm_debugfs_create_files(dc->debugfs_files,
39549 ARRAY_SIZE(debugfs_files),
39550diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
39551index ec0ae2d..dc0780b 100644
39552--- a/drivers/gpu/vga/vga_switcheroo.c
39553+++ b/drivers/gpu/vga/vga_switcheroo.c
39554@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
39555
39556 /* this version is for the case where the power switch is separate
39557 to the device being powered down. */
39558-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
39559+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
39560 {
39561 /* copy over all the bus versions */
39562 if (dev->bus && dev->bus->pm) {
39563@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
39564 return ret;
39565 }
39566
39567-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
39568+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
39569 {
39570 /* copy over all the bus versions */
39571 if (dev->bus && dev->bus->pm) {
39572diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39573index e80da62..bbcba01 100644
39574--- a/drivers/hid/hid-core.c
39575+++ b/drivers/hid/hid-core.c
39576@@ -2417,7 +2417,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39577
39578 int hid_add_device(struct hid_device *hdev)
39579 {
39580- static atomic_t id = ATOMIC_INIT(0);
39581+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39582 int ret;
39583
39584 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39585@@ -2451,7 +2451,7 @@ int hid_add_device(struct hid_device *hdev)
39586 /* XXX hack, any other cleaner solution after the driver core
39587 * is converted to allow more than 20 bytes as the device name? */
39588 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39589- hdev->vendor, hdev->product, atomic_inc_return(&id));
39590+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39591
39592 hid_debug_register(hdev, dev_name(&hdev->dev));
39593 ret = device_add(&hdev->dev);
39594diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39595index c13fb5b..55a3802 100644
39596--- a/drivers/hid/hid-wiimote-debug.c
39597+++ b/drivers/hid/hid-wiimote-debug.c
39598@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39599 else if (size == 0)
39600 return -EIO;
39601
39602- if (copy_to_user(u, buf, size))
39603+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39604 return -EFAULT;
39605
39606 *off += size;
39607diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39608index 93b00d7..0a71596 100644
39609--- a/drivers/hid/uhid.c
39610+++ b/drivers/hid/uhid.c
39611@@ -47,7 +47,7 @@ struct uhid_device {
39612 struct mutex report_lock;
39613 wait_queue_head_t report_wait;
39614 atomic_t report_done;
39615- atomic_t report_id;
39616+ atomic_unchecked_t report_id;
39617 struct uhid_event report_buf;
39618 };
39619
39620@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39621
39622 spin_lock_irqsave(&uhid->qlock, flags);
39623 ev->type = UHID_FEATURE;
39624- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39625+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39626 ev->u.feature.rnum = rnum;
39627 ev->u.feature.rtype = report_type;
39628
39629@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39630 spin_lock_irqsave(&uhid->qlock, flags);
39631
39632 /* id for old report; drop it silently */
39633- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39634+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39635 goto unlock;
39636 if (atomic_read(&uhid->report_done))
39637 goto unlock;
39638diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39639index 6de6c98..18319e9 100644
39640--- a/drivers/hv/channel.c
39641+++ b/drivers/hv/channel.c
39642@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39643 int ret = 0;
39644 int t;
39645
39646- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39647- atomic_inc(&vmbus_connection.next_gpadl_handle);
39648+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39649+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39650
39651 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39652 if (ret)
39653diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39654index 88f4096..e50452e 100644
39655--- a/drivers/hv/hv.c
39656+++ b/drivers/hv/hv.c
39657@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39658 u64 output_address = (output) ? virt_to_phys(output) : 0;
39659 u32 output_address_hi = output_address >> 32;
39660 u32 output_address_lo = output_address & 0xFFFFFFFF;
39661- void *hypercall_page = hv_context.hypercall_page;
39662+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39663
39664 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39665 "=a"(hv_status_lo) : "d" (control_hi),
39666diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39667index 7e17a54..a50a33d 100644
39668--- a/drivers/hv/hv_balloon.c
39669+++ b/drivers/hv/hv_balloon.c
39670@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39671
39672 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39673 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39674-static atomic_t trans_id = ATOMIC_INIT(0);
39675+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39676
39677 static int dm_ring_size = (5 * PAGE_SIZE);
39678
39679@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
39680 pr_info("Memory hot add failed\n");
39681
39682 dm->state = DM_INITIALIZED;
39683- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39684+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39685 vmbus_sendpacket(dm->dev->channel, &resp,
39686 sizeof(struct dm_hot_add_response),
39687 (unsigned long)NULL,
39688@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39689 memset(&status, 0, sizeof(struct dm_status));
39690 status.hdr.type = DM_STATUS_REPORT;
39691 status.hdr.size = sizeof(struct dm_status);
39692- status.hdr.trans_id = atomic_inc_return(&trans_id);
39693+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39694
39695 /*
39696 * The host expects the guest to report free memory.
39697@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39698 * send the status. This can happen if we were interrupted
39699 * after we picked our transaction ID.
39700 */
39701- if (status.hdr.trans_id != atomic_read(&trans_id))
39702+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39703 return;
39704
39705 vmbus_sendpacket(dm->dev->channel, &status,
39706@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
39707 */
39708
39709 do {
39710- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39711+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39712 ret = vmbus_sendpacket(dm_device.dev->channel,
39713 bl_resp,
39714 bl_resp->hdr.size,
39715@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39716
39717 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39718 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39719- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39720+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39721 resp.hdr.size = sizeof(struct dm_unballoon_response);
39722
39723 vmbus_sendpacket(dm_device.dev->channel, &resp,
39724@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39725 memset(&version_req, 0, sizeof(struct dm_version_request));
39726 version_req.hdr.type = DM_VERSION_REQUEST;
39727 version_req.hdr.size = sizeof(struct dm_version_request);
39728- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39729+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39730 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39731 version_req.is_last_attempt = 1;
39732
39733@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39734 memset(&version_req, 0, sizeof(struct dm_version_request));
39735 version_req.hdr.type = DM_VERSION_REQUEST;
39736 version_req.hdr.size = sizeof(struct dm_version_request);
39737- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39738+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39739 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39740 version_req.is_last_attempt = 0;
39741
39742@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39743 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39744 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39745 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39746- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39747+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39748
39749 cap_msg.caps.cap_bits.balloon = 1;
39750 cap_msg.caps.cap_bits.hot_add = 1;
39751diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39752index d84918f..7f38f9f 100644
39753--- a/drivers/hv/hyperv_vmbus.h
39754+++ b/drivers/hv/hyperv_vmbus.h
39755@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39756 struct vmbus_connection {
39757 enum vmbus_connect_state conn_state;
39758
39759- atomic_t next_gpadl_handle;
39760+ atomic_unchecked_t next_gpadl_handle;
39761
39762 /*
39763 * Represents channel interrupts. Each bit position represents a
39764diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39765index f9fe46f..356b119 100644
39766--- a/drivers/hv/vmbus_drv.c
39767+++ b/drivers/hv/vmbus_drv.c
39768@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39769 {
39770 int ret = 0;
39771
39772- static atomic_t device_num = ATOMIC_INIT(0);
39773+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39774
39775 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39776- atomic_inc_return(&device_num));
39777+ atomic_inc_return_unchecked(&device_num));
39778
39779 child_device_obj->device.bus = &hv_bus;
39780 child_device_obj->device.parent = &hv_acpi_dev->dev;
39781diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39782index a9e3d01..9dd246e 100644
39783--- a/drivers/hwmon/acpi_power_meter.c
39784+++ b/drivers/hwmon/acpi_power_meter.c
39785@@ -117,7 +117,7 @@ struct sensor_template {
39786 struct device_attribute *devattr,
39787 const char *buf, size_t count);
39788 int index;
39789-};
39790+} __do_const;
39791
39792 /* Averaging interval */
39793 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39794@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39795 struct sensor_template *attrs)
39796 {
39797 struct device *dev = &resource->acpi_dev->dev;
39798- struct sensor_device_attribute *sensors =
39799+ sensor_device_attribute_no_const *sensors =
39800 &resource->sensors[resource->num_sensors];
39801 int res = 0;
39802
39803diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39804index 3288f13..71cfb4e 100644
39805--- a/drivers/hwmon/applesmc.c
39806+++ b/drivers/hwmon/applesmc.c
39807@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39808 {
39809 struct applesmc_node_group *grp;
39810 struct applesmc_dev_attr *node;
39811- struct attribute *attr;
39812+ attribute_no_const *attr;
39813 int ret, i;
39814
39815 for (grp = groups; grp->format; grp++) {
39816diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39817index b25c643..a13460d 100644
39818--- a/drivers/hwmon/asus_atk0110.c
39819+++ b/drivers/hwmon/asus_atk0110.c
39820@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39821 struct atk_sensor_data {
39822 struct list_head list;
39823 struct atk_data *data;
39824- struct device_attribute label_attr;
39825- struct device_attribute input_attr;
39826- struct device_attribute limit1_attr;
39827- struct device_attribute limit2_attr;
39828+ device_attribute_no_const label_attr;
39829+ device_attribute_no_const input_attr;
39830+ device_attribute_no_const limit1_attr;
39831+ device_attribute_no_const limit2_attr;
39832 char label_attr_name[ATTR_NAME_SIZE];
39833 char input_attr_name[ATTR_NAME_SIZE];
39834 char limit1_attr_name[ATTR_NAME_SIZE];
39835@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39836 static struct device_attribute atk_name_attr =
39837 __ATTR(name, 0444, atk_name_show, NULL);
39838
39839-static void atk_init_attribute(struct device_attribute *attr, char *name,
39840+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39841 sysfs_show_func show)
39842 {
39843 sysfs_attr_init(&attr->attr);
39844diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39845index 78be661..4dd032f 100644
39846--- a/drivers/hwmon/coretemp.c
39847+++ b/drivers/hwmon/coretemp.c
39848@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39849 return NOTIFY_OK;
39850 }
39851
39852-static struct notifier_block coretemp_cpu_notifier __refdata = {
39853+static struct notifier_block coretemp_cpu_notifier = {
39854 .notifier_call = coretemp_cpu_callback,
39855 };
39856
39857diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39858index 632f1dc..57e6a58 100644
39859--- a/drivers/hwmon/ibmaem.c
39860+++ b/drivers/hwmon/ibmaem.c
39861@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39862 struct aem_rw_sensor_template *rw)
39863 {
39864 struct device *dev = &data->pdev->dev;
39865- struct sensor_device_attribute *sensors = data->sensors;
39866+ sensor_device_attribute_no_const *sensors = data->sensors;
39867 int err;
39868
39869 /* Set up read-only sensors */
39870diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39871index 708081b..fe2d4ab 100644
39872--- a/drivers/hwmon/iio_hwmon.c
39873+++ b/drivers/hwmon/iio_hwmon.c
39874@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39875 {
39876 struct device *dev = &pdev->dev;
39877 struct iio_hwmon_state *st;
39878- struct sensor_device_attribute *a;
39879+ sensor_device_attribute_no_const *a;
39880 int ret, i;
39881 int in_i = 1, temp_i = 1, curr_i = 1;
39882 enum iio_chan_type type;
39883diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
39884index 6eb03ce..bea7e3e 100644
39885--- a/drivers/hwmon/nct6775.c
39886+++ b/drivers/hwmon/nct6775.c
39887@@ -936,10 +936,10 @@ static struct attribute_group *
39888 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
39889 int repeat)
39890 {
39891- struct attribute_group *group;
39892+ attribute_group_no_const *group;
39893 struct sensor_device_attr_u *su;
39894- struct sensor_device_attribute *a;
39895- struct sensor_device_attribute_2 *a2;
39896+ sensor_device_attribute_no_const *a;
39897+ sensor_device_attribute_2_no_const *a2;
39898 struct attribute **attrs;
39899 struct sensor_device_template **t;
39900 int err, i, j, count;
39901diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39902index 9319fcf..189ff45 100644
39903--- a/drivers/hwmon/pmbus/pmbus_core.c
39904+++ b/drivers/hwmon/pmbus/pmbus_core.c
39905@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39906 return 0;
39907 }
39908
39909-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39910+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39911 const char *name,
39912 umode_t mode,
39913 ssize_t (*show)(struct device *dev,
39914@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39915 dev_attr->store = store;
39916 }
39917
39918-static void pmbus_attr_init(struct sensor_device_attribute *a,
39919+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39920 const char *name,
39921 umode_t mode,
39922 ssize_t (*show)(struct device *dev,
39923@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39924 u16 reg, u8 mask)
39925 {
39926 struct pmbus_boolean *boolean;
39927- struct sensor_device_attribute *a;
39928+ sensor_device_attribute_no_const *a;
39929
39930 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39931 if (!boolean)
39932@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39933 bool update, bool readonly)
39934 {
39935 struct pmbus_sensor *sensor;
39936- struct device_attribute *a;
39937+ device_attribute_no_const *a;
39938
39939 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39940 if (!sensor)
39941@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39942 const char *lstring, int index)
39943 {
39944 struct pmbus_label *label;
39945- struct device_attribute *a;
39946+ device_attribute_no_const *a;
39947
39948 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39949 if (!label)
39950diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39951index 97cd45a..ac54d8b 100644
39952--- a/drivers/hwmon/sht15.c
39953+++ b/drivers/hwmon/sht15.c
39954@@ -169,7 +169,7 @@ struct sht15_data {
39955 int supply_uv;
39956 bool supply_uv_valid;
39957 struct work_struct update_supply_work;
39958- atomic_t interrupt_handled;
39959+ atomic_unchecked_t interrupt_handled;
39960 };
39961
39962 /**
39963@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39964 ret = gpio_direction_input(data->pdata->gpio_data);
39965 if (ret)
39966 return ret;
39967- atomic_set(&data->interrupt_handled, 0);
39968+ atomic_set_unchecked(&data->interrupt_handled, 0);
39969
39970 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39971 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39972 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39973 /* Only relevant if the interrupt hasn't occurred. */
39974- if (!atomic_read(&data->interrupt_handled))
39975+ if (!atomic_read_unchecked(&data->interrupt_handled))
39976 schedule_work(&data->read_work);
39977 }
39978 ret = wait_event_timeout(data->wait_queue,
39979@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
39980
39981 /* First disable the interrupt */
39982 disable_irq_nosync(irq);
39983- atomic_inc(&data->interrupt_handled);
39984+ atomic_inc_unchecked(&data->interrupt_handled);
39985 /* Then schedule a reading work struct */
39986 if (data->state != SHT15_READING_NOTHING)
39987 schedule_work(&data->read_work);
39988@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
39989 * If not, then start the interrupt again - care here as could
39990 * have gone low in meantime so verify it hasn't!
39991 */
39992- atomic_set(&data->interrupt_handled, 0);
39993+ atomic_set_unchecked(&data->interrupt_handled, 0);
39994 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39995 /* If still not occurred or another handler was scheduled */
39996 if (gpio_get_value(data->pdata->gpio_data)
39997- || atomic_read(&data->interrupt_handled))
39998+ || atomic_read_unchecked(&data->interrupt_handled))
39999 return;
40000 }
40001
40002diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40003index 38944e9..ae9e5ed 100644
40004--- a/drivers/hwmon/via-cputemp.c
40005+++ b/drivers/hwmon/via-cputemp.c
40006@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40007 return NOTIFY_OK;
40008 }
40009
40010-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40011+static struct notifier_block via_cputemp_cpu_notifier = {
40012 .notifier_call = via_cputemp_cpu_callback,
40013 };
40014
40015diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40016index 07f01ac..d79ad3d 100644
40017--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40018+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40019@@ -43,7 +43,7 @@
40020 extern struct i2c_adapter amd756_smbus;
40021
40022 static struct i2c_adapter *s4882_adapter;
40023-static struct i2c_algorithm *s4882_algo;
40024+static i2c_algorithm_no_const *s4882_algo;
40025
40026 /* Wrapper access functions for multiplexed SMBus */
40027 static DEFINE_MUTEX(amd756_lock);
40028diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
40029index dae3ddf..26e21d1 100644
40030--- a/drivers/i2c/busses/i2c-diolan-u2c.c
40031+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
40032@@ -99,7 +99,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
40033 /* usb layer */
40034
40035 /* Send command to device, and get response. */
40036-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
40037+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
40038 {
40039 int ret = 0;
40040 int actual;
40041diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40042index 2ca268d..c6acbdf 100644
40043--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40044+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40045@@ -41,7 +41,7 @@
40046 extern struct i2c_adapter *nforce2_smbus;
40047
40048 static struct i2c_adapter *s4985_adapter;
40049-static struct i2c_algorithm *s4985_algo;
40050+static i2c_algorithm_no_const *s4985_algo;
40051
40052 /* Wrapper access functions for multiplexed SMBus */
40053 static DEFINE_MUTEX(nforce2_lock);
40054diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40055index c3ccdea..5b3dc1a 100644
40056--- a/drivers/i2c/i2c-dev.c
40057+++ b/drivers/i2c/i2c-dev.c
40058@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40059 break;
40060 }
40061
40062- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40063+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40064 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40065 if (IS_ERR(rdwr_pa[i].buf)) {
40066 res = PTR_ERR(rdwr_pa[i].buf);
40067diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40068index 0b510ba..4fbb5085 100644
40069--- a/drivers/ide/ide-cd.c
40070+++ b/drivers/ide/ide-cd.c
40071@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40072 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40073 if ((unsigned long)buf & alignment
40074 || blk_rq_bytes(rq) & q->dma_pad_mask
40075- || object_is_on_stack(buf))
40076+ || object_starts_on_stack(buf))
40077 drive->dma = 0;
40078 }
40079 }
40080diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40081index f95c697..0a1b05c 100644
40082--- a/drivers/iio/industrialio-core.c
40083+++ b/drivers/iio/industrialio-core.c
40084@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40085 }
40086
40087 static
40088-int __iio_device_attr_init(struct device_attribute *dev_attr,
40089+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40090 const char *postfix,
40091 struct iio_chan_spec const *chan,
40092 ssize_t (*readfunc)(struct device *dev,
40093diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40094index 784b97c..c9ceadf 100644
40095--- a/drivers/infiniband/core/cm.c
40096+++ b/drivers/infiniband/core/cm.c
40097@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40098
40099 struct cm_counter_group {
40100 struct kobject obj;
40101- atomic_long_t counter[CM_ATTR_COUNT];
40102+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40103 };
40104
40105 struct cm_counter_attribute {
40106@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40107 struct ib_mad_send_buf *msg = NULL;
40108 int ret;
40109
40110- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40111+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40112 counter[CM_REQ_COUNTER]);
40113
40114 /* Quick state check to discard duplicate REQs. */
40115@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40116 if (!cm_id_priv)
40117 return;
40118
40119- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40120+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40121 counter[CM_REP_COUNTER]);
40122 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40123 if (ret)
40124@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40125 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40126 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40127 spin_unlock_irq(&cm_id_priv->lock);
40128- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40129+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40130 counter[CM_RTU_COUNTER]);
40131 goto out;
40132 }
40133@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40134 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40135 dreq_msg->local_comm_id);
40136 if (!cm_id_priv) {
40137- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40138+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40139 counter[CM_DREQ_COUNTER]);
40140 cm_issue_drep(work->port, work->mad_recv_wc);
40141 return -EINVAL;
40142@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40143 case IB_CM_MRA_REP_RCVD:
40144 break;
40145 case IB_CM_TIMEWAIT:
40146- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40147+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40148 counter[CM_DREQ_COUNTER]);
40149 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40150 goto unlock;
40151@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40152 cm_free_msg(msg);
40153 goto deref;
40154 case IB_CM_DREQ_RCVD:
40155- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40156+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40157 counter[CM_DREQ_COUNTER]);
40158 goto unlock;
40159 default:
40160@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40161 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40162 cm_id_priv->msg, timeout)) {
40163 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40164- atomic_long_inc(&work->port->
40165+ atomic_long_inc_unchecked(&work->port->
40166 counter_group[CM_RECV_DUPLICATES].
40167 counter[CM_MRA_COUNTER]);
40168 goto out;
40169@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40170 break;
40171 case IB_CM_MRA_REQ_RCVD:
40172 case IB_CM_MRA_REP_RCVD:
40173- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40174+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40175 counter[CM_MRA_COUNTER]);
40176 /* fall through */
40177 default:
40178@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40179 case IB_CM_LAP_IDLE:
40180 break;
40181 case IB_CM_MRA_LAP_SENT:
40182- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40183+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40184 counter[CM_LAP_COUNTER]);
40185 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40186 goto unlock;
40187@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40188 cm_free_msg(msg);
40189 goto deref;
40190 case IB_CM_LAP_RCVD:
40191- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40192+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40193 counter[CM_LAP_COUNTER]);
40194 goto unlock;
40195 default:
40196@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40197 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40198 if (cur_cm_id_priv) {
40199 spin_unlock_irq(&cm.lock);
40200- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40201+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40202 counter[CM_SIDR_REQ_COUNTER]);
40203 goto out; /* Duplicate message. */
40204 }
40205@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40206 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40207 msg->retries = 1;
40208
40209- atomic_long_add(1 + msg->retries,
40210+ atomic_long_add_unchecked(1 + msg->retries,
40211 &port->counter_group[CM_XMIT].counter[attr_index]);
40212 if (msg->retries)
40213- atomic_long_add(msg->retries,
40214+ atomic_long_add_unchecked(msg->retries,
40215 &port->counter_group[CM_XMIT_RETRIES].
40216 counter[attr_index]);
40217
40218@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40219 }
40220
40221 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40222- atomic_long_inc(&port->counter_group[CM_RECV].
40223+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40224 counter[attr_id - CM_ATTR_ID_OFFSET]);
40225
40226 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40227@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40228 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40229
40230 return sprintf(buf, "%ld\n",
40231- atomic_long_read(&group->counter[cm_attr->index]));
40232+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40233 }
40234
40235 static const struct sysfs_ops cm_counter_ops = {
40236diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40237index 9f5ad7c..588cd84 100644
40238--- a/drivers/infiniband/core/fmr_pool.c
40239+++ b/drivers/infiniband/core/fmr_pool.c
40240@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40241
40242 struct task_struct *thread;
40243
40244- atomic_t req_ser;
40245- atomic_t flush_ser;
40246+ atomic_unchecked_t req_ser;
40247+ atomic_unchecked_t flush_ser;
40248
40249 wait_queue_head_t force_wait;
40250 };
40251@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40252 struct ib_fmr_pool *pool = pool_ptr;
40253
40254 do {
40255- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40256+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40257 ib_fmr_batch_release(pool);
40258
40259- atomic_inc(&pool->flush_ser);
40260+ atomic_inc_unchecked(&pool->flush_ser);
40261 wake_up_interruptible(&pool->force_wait);
40262
40263 if (pool->flush_function)
40264@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40265 }
40266
40267 set_current_state(TASK_INTERRUPTIBLE);
40268- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40269+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40270 !kthread_should_stop())
40271 schedule();
40272 __set_current_state(TASK_RUNNING);
40273@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40274 pool->dirty_watermark = params->dirty_watermark;
40275 pool->dirty_len = 0;
40276 spin_lock_init(&pool->pool_lock);
40277- atomic_set(&pool->req_ser, 0);
40278- atomic_set(&pool->flush_ser, 0);
40279+ atomic_set_unchecked(&pool->req_ser, 0);
40280+ atomic_set_unchecked(&pool->flush_ser, 0);
40281 init_waitqueue_head(&pool->force_wait);
40282
40283 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40284@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40285 }
40286 spin_unlock_irq(&pool->pool_lock);
40287
40288- serial = atomic_inc_return(&pool->req_ser);
40289+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40290 wake_up_process(pool->thread);
40291
40292 if (wait_event_interruptible(pool->force_wait,
40293- atomic_read(&pool->flush_ser) - serial >= 0))
40294+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40295 return -EINTR;
40296
40297 return 0;
40298@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40299 } else {
40300 list_add_tail(&fmr->list, &pool->dirty_list);
40301 if (++pool->dirty_len >= pool->dirty_watermark) {
40302- atomic_inc(&pool->req_ser);
40303+ atomic_inc_unchecked(&pool->req_ser);
40304 wake_up_process(pool->thread);
40305 }
40306 }
40307diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40308index 4cb8eb2..146bf60 100644
40309--- a/drivers/infiniband/hw/cxgb4/mem.c
40310+++ b/drivers/infiniband/hw/cxgb4/mem.c
40311@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40312 int err;
40313 struct fw_ri_tpte tpt;
40314 u32 stag_idx;
40315- static atomic_t key;
40316+ static atomic_unchecked_t key;
40317
40318 if (c4iw_fatal_error(rdev))
40319 return -EIO;
40320@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40321 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40322 rdev->stats.stag.max = rdev->stats.stag.cur;
40323 mutex_unlock(&rdev->stats.lock);
40324- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40325+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40326 }
40327 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40328 __func__, stag_state, type, pdid, stag_idx);
40329diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40330index 79b3dbc..96e5fcc 100644
40331--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40332+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40333@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40334 struct ib_atomic_eth *ateth;
40335 struct ipath_ack_entry *e;
40336 u64 vaddr;
40337- atomic64_t *maddr;
40338+ atomic64_unchecked_t *maddr;
40339 u64 sdata;
40340 u32 rkey;
40341 u8 next;
40342@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40343 IB_ACCESS_REMOTE_ATOMIC)))
40344 goto nack_acc_unlck;
40345 /* Perform atomic OP and save result. */
40346- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40347+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40348 sdata = be64_to_cpu(ateth->swap_data);
40349 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40350 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40351- (u64) atomic64_add_return(sdata, maddr) - sdata :
40352+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40353 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40354 be64_to_cpu(ateth->compare_data),
40355 sdata);
40356diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40357index 1f95bba..9530f87 100644
40358--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40359+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40360@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40361 unsigned long flags;
40362 struct ib_wc wc;
40363 u64 sdata;
40364- atomic64_t *maddr;
40365+ atomic64_unchecked_t *maddr;
40366 enum ib_wc_status send_status;
40367
40368 /*
40369@@ -382,11 +382,11 @@ again:
40370 IB_ACCESS_REMOTE_ATOMIC)))
40371 goto acc_err;
40372 /* Perform atomic OP and save result. */
40373- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40374+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40375 sdata = wqe->wr.wr.atomic.compare_add;
40376 *(u64 *) sqp->s_sge.sge.vaddr =
40377 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40378- (u64) atomic64_add_return(sdata, maddr) - sdata :
40379+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40380 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40381 sdata, wqe->wr.wr.atomic.swap);
40382 goto send_comp;
40383diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40384index f2a3f48..673ec79 100644
40385--- a/drivers/infiniband/hw/mlx4/mad.c
40386+++ b/drivers/infiniband/hw/mlx4/mad.c
40387@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40388
40389 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40390 {
40391- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40392+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40393 cpu_to_be64(0xff00000000000000LL);
40394 }
40395
40396diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40397index 25b2cdf..099ff97 100644
40398--- a/drivers/infiniband/hw/mlx4/mcg.c
40399+++ b/drivers/infiniband/hw/mlx4/mcg.c
40400@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40401 {
40402 char name[20];
40403
40404- atomic_set(&ctx->tid, 0);
40405+ atomic_set_unchecked(&ctx->tid, 0);
40406 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40407 ctx->mcg_wq = create_singlethread_workqueue(name);
40408 if (!ctx->mcg_wq)
40409diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40410index 036b663..c9a8c73 100644
40411--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40412+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40413@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
40414 struct list_head mcg_mgid0_list;
40415 struct workqueue_struct *mcg_wq;
40416 struct mlx4_ib_demux_pv_ctx **tun;
40417- atomic_t tid;
40418+ atomic_unchecked_t tid;
40419 int flushing; /* flushing the work queue */
40420 };
40421
40422diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40423index 9d3e5c1..6f166df 100644
40424--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40425+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40426@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40427 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40428 }
40429
40430-int mthca_QUERY_FW(struct mthca_dev *dev)
40431+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40432 {
40433 struct mthca_mailbox *mailbox;
40434 u32 *outbox;
40435@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40436 CMD_TIME_CLASS_B);
40437 }
40438
40439-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40440+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40441 int num_mtt)
40442 {
40443 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
40444@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
40445 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
40446 }
40447
40448-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40449+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40450 int eq_num)
40451 {
40452 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
40453@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
40454 CMD_TIME_CLASS_B);
40455 }
40456
40457-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
40458+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
40459 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
40460 void *in_mad, void *response_mad)
40461 {
40462diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
40463index 87897b9..7e79542 100644
40464--- a/drivers/infiniband/hw/mthca/mthca_main.c
40465+++ b/drivers/infiniband/hw/mthca/mthca_main.c
40466@@ -692,7 +692,7 @@ err_close:
40467 return err;
40468 }
40469
40470-static int mthca_setup_hca(struct mthca_dev *dev)
40471+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
40472 {
40473 int err;
40474
40475diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40476index ed9a989..6aa5dc2 100644
40477--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40478+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40479@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
40480 * through the bitmaps)
40481 */
40482
40483-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
40484+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
40485 {
40486 int o;
40487 int m;
40488@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40489 return key;
40490 }
40491
40492-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40493+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40494 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40495 {
40496 struct mthca_mailbox *mailbox;
40497@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
40498 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
40499 }
40500
40501-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
40502+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
40503 u64 *buffer_list, int buffer_size_shift,
40504 int list_len, u64 iova, u64 total_size,
40505 u32 access, struct mthca_mr *mr)
40506diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
40507index 5b71d43..35a9e14 100644
40508--- a/drivers/infiniband/hw/mthca/mthca_provider.c
40509+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
40510@@ -763,7 +763,7 @@ unlock:
40511 return 0;
40512 }
40513
40514-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
40515+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
40516 {
40517 struct mthca_dev *dev = to_mdev(ibcq->device);
40518 struct mthca_cq *cq = to_mcq(ibcq);
40519diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40520index 4291410..d2ab1fb 100644
40521--- a/drivers/infiniband/hw/nes/nes.c
40522+++ b/drivers/infiniband/hw/nes/nes.c
40523@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40524 LIST_HEAD(nes_adapter_list);
40525 static LIST_HEAD(nes_dev_list);
40526
40527-atomic_t qps_destroyed;
40528+atomic_unchecked_t qps_destroyed;
40529
40530 static unsigned int ee_flsh_adapter;
40531 static unsigned int sysfs_nonidx_addr;
40532@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40533 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40534 struct nes_adapter *nesadapter = nesdev->nesadapter;
40535
40536- atomic_inc(&qps_destroyed);
40537+ atomic_inc_unchecked(&qps_destroyed);
40538
40539 /* Free the control structures */
40540
40541diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40542index 33cc589..3bd6538 100644
40543--- a/drivers/infiniband/hw/nes/nes.h
40544+++ b/drivers/infiniband/hw/nes/nes.h
40545@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40546 extern unsigned int wqm_quanta;
40547 extern struct list_head nes_adapter_list;
40548
40549-extern atomic_t cm_connects;
40550-extern atomic_t cm_accepts;
40551-extern atomic_t cm_disconnects;
40552-extern atomic_t cm_closes;
40553-extern atomic_t cm_connecteds;
40554-extern atomic_t cm_connect_reqs;
40555-extern atomic_t cm_rejects;
40556-extern atomic_t mod_qp_timouts;
40557-extern atomic_t qps_created;
40558-extern atomic_t qps_destroyed;
40559-extern atomic_t sw_qps_destroyed;
40560+extern atomic_unchecked_t cm_connects;
40561+extern atomic_unchecked_t cm_accepts;
40562+extern atomic_unchecked_t cm_disconnects;
40563+extern atomic_unchecked_t cm_closes;
40564+extern atomic_unchecked_t cm_connecteds;
40565+extern atomic_unchecked_t cm_connect_reqs;
40566+extern atomic_unchecked_t cm_rejects;
40567+extern atomic_unchecked_t mod_qp_timouts;
40568+extern atomic_unchecked_t qps_created;
40569+extern atomic_unchecked_t qps_destroyed;
40570+extern atomic_unchecked_t sw_qps_destroyed;
40571 extern u32 mh_detected;
40572 extern u32 mh_pauses_sent;
40573 extern u32 cm_packets_sent;
40574@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40575 extern u32 cm_packets_received;
40576 extern u32 cm_packets_dropped;
40577 extern u32 cm_packets_retrans;
40578-extern atomic_t cm_listens_created;
40579-extern atomic_t cm_listens_destroyed;
40580+extern atomic_unchecked_t cm_listens_created;
40581+extern atomic_unchecked_t cm_listens_destroyed;
40582 extern u32 cm_backlog_drops;
40583-extern atomic_t cm_loopbacks;
40584-extern atomic_t cm_nodes_created;
40585-extern atomic_t cm_nodes_destroyed;
40586-extern atomic_t cm_accel_dropped_pkts;
40587-extern atomic_t cm_resets_recvd;
40588-extern atomic_t pau_qps_created;
40589-extern atomic_t pau_qps_destroyed;
40590+extern atomic_unchecked_t cm_loopbacks;
40591+extern atomic_unchecked_t cm_nodes_created;
40592+extern atomic_unchecked_t cm_nodes_destroyed;
40593+extern atomic_unchecked_t cm_accel_dropped_pkts;
40594+extern atomic_unchecked_t cm_resets_recvd;
40595+extern atomic_unchecked_t pau_qps_created;
40596+extern atomic_unchecked_t pau_qps_destroyed;
40597
40598 extern u32 int_mod_timer_init;
40599 extern u32 int_mod_cq_depth_256;
40600diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40601index 6b29249..57081dd 100644
40602--- a/drivers/infiniband/hw/nes/nes_cm.c
40603+++ b/drivers/infiniband/hw/nes/nes_cm.c
40604@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40605 u32 cm_packets_retrans;
40606 u32 cm_packets_created;
40607 u32 cm_packets_received;
40608-atomic_t cm_listens_created;
40609-atomic_t cm_listens_destroyed;
40610+atomic_unchecked_t cm_listens_created;
40611+atomic_unchecked_t cm_listens_destroyed;
40612 u32 cm_backlog_drops;
40613-atomic_t cm_loopbacks;
40614-atomic_t cm_nodes_created;
40615-atomic_t cm_nodes_destroyed;
40616-atomic_t cm_accel_dropped_pkts;
40617-atomic_t cm_resets_recvd;
40618+atomic_unchecked_t cm_loopbacks;
40619+atomic_unchecked_t cm_nodes_created;
40620+atomic_unchecked_t cm_nodes_destroyed;
40621+atomic_unchecked_t cm_accel_dropped_pkts;
40622+atomic_unchecked_t cm_resets_recvd;
40623
40624 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40625 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40626@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40627
40628 static struct nes_cm_core *g_cm_core;
40629
40630-atomic_t cm_connects;
40631-atomic_t cm_accepts;
40632-atomic_t cm_disconnects;
40633-atomic_t cm_closes;
40634-atomic_t cm_connecteds;
40635-atomic_t cm_connect_reqs;
40636-atomic_t cm_rejects;
40637+atomic_unchecked_t cm_connects;
40638+atomic_unchecked_t cm_accepts;
40639+atomic_unchecked_t cm_disconnects;
40640+atomic_unchecked_t cm_closes;
40641+atomic_unchecked_t cm_connecteds;
40642+atomic_unchecked_t cm_connect_reqs;
40643+atomic_unchecked_t cm_rejects;
40644
40645 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40646 {
40647@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40648 kfree(listener);
40649 listener = NULL;
40650 ret = 0;
40651- atomic_inc(&cm_listens_destroyed);
40652+ atomic_inc_unchecked(&cm_listens_destroyed);
40653 } else {
40654 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40655 }
40656@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40657 cm_node->rem_mac);
40658
40659 add_hte_node(cm_core, cm_node);
40660- atomic_inc(&cm_nodes_created);
40661+ atomic_inc_unchecked(&cm_nodes_created);
40662
40663 return cm_node;
40664 }
40665@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40666 }
40667
40668 atomic_dec(&cm_core->node_cnt);
40669- atomic_inc(&cm_nodes_destroyed);
40670+ atomic_inc_unchecked(&cm_nodes_destroyed);
40671 nesqp = cm_node->nesqp;
40672 if (nesqp) {
40673 nesqp->cm_node = NULL;
40674@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40675
40676 static void drop_packet(struct sk_buff *skb)
40677 {
40678- atomic_inc(&cm_accel_dropped_pkts);
40679+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40680 dev_kfree_skb_any(skb);
40681 }
40682
40683@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40684 {
40685
40686 int reset = 0; /* whether to send reset in case of err.. */
40687- atomic_inc(&cm_resets_recvd);
40688+ atomic_inc_unchecked(&cm_resets_recvd);
40689 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40690 " refcnt=%d\n", cm_node, cm_node->state,
40691 atomic_read(&cm_node->ref_count));
40692@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40693 rem_ref_cm_node(cm_node->cm_core, cm_node);
40694 return NULL;
40695 }
40696- atomic_inc(&cm_loopbacks);
40697+ atomic_inc_unchecked(&cm_loopbacks);
40698 loopbackremotenode->loopbackpartner = cm_node;
40699 loopbackremotenode->tcp_cntxt.rcv_wscale =
40700 NES_CM_DEFAULT_RCV_WND_SCALE;
40701@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40702 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40703 else {
40704 rem_ref_cm_node(cm_core, cm_node);
40705- atomic_inc(&cm_accel_dropped_pkts);
40706+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40707 dev_kfree_skb_any(skb);
40708 }
40709 break;
40710@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40711
40712 if ((cm_id) && (cm_id->event_handler)) {
40713 if (issue_disconn) {
40714- atomic_inc(&cm_disconnects);
40715+ atomic_inc_unchecked(&cm_disconnects);
40716 cm_event.event = IW_CM_EVENT_DISCONNECT;
40717 cm_event.status = disconn_status;
40718 cm_event.local_addr = cm_id->local_addr;
40719@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40720 }
40721
40722 if (issue_close) {
40723- atomic_inc(&cm_closes);
40724+ atomic_inc_unchecked(&cm_closes);
40725 nes_disconnect(nesqp, 1);
40726
40727 cm_id->provider_data = nesqp;
40728@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40729
40730 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40731 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40732- atomic_inc(&cm_accepts);
40733+ atomic_inc_unchecked(&cm_accepts);
40734
40735 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40736 netdev_refcnt_read(nesvnic->netdev));
40737@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40738 struct nes_cm_core *cm_core;
40739 u8 *start_buff;
40740
40741- atomic_inc(&cm_rejects);
40742+ atomic_inc_unchecked(&cm_rejects);
40743 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40744 loopback = cm_node->loopbackpartner;
40745 cm_core = cm_node->cm_core;
40746@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40747 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
40748 ntohs(laddr->sin_port));
40749
40750- atomic_inc(&cm_connects);
40751+ atomic_inc_unchecked(&cm_connects);
40752 nesqp->active_conn = 1;
40753
40754 /* cache the cm_id in the qp */
40755@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40756 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40757 return err;
40758 }
40759- atomic_inc(&cm_listens_created);
40760+ atomic_inc_unchecked(&cm_listens_created);
40761 }
40762
40763 cm_id->add_ref(cm_id);
40764@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40765
40766 if (nesqp->destroyed)
40767 return;
40768- atomic_inc(&cm_connecteds);
40769+ atomic_inc_unchecked(&cm_connecteds);
40770 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40771 " local port 0x%04X. jiffies = %lu.\n",
40772 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
40773@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40774
40775 cm_id->add_ref(cm_id);
40776 ret = cm_id->event_handler(cm_id, &cm_event);
40777- atomic_inc(&cm_closes);
40778+ atomic_inc_unchecked(&cm_closes);
40779 cm_event.event = IW_CM_EVENT_CLOSE;
40780 cm_event.status = 0;
40781 cm_event.provider_data = cm_id->provider_data;
40782@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40783 return;
40784 cm_id = cm_node->cm_id;
40785
40786- atomic_inc(&cm_connect_reqs);
40787+ atomic_inc_unchecked(&cm_connect_reqs);
40788 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40789 cm_node, cm_id, jiffies);
40790
40791@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40792 return;
40793 cm_id = cm_node->cm_id;
40794
40795- atomic_inc(&cm_connect_reqs);
40796+ atomic_inc_unchecked(&cm_connect_reqs);
40797 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40798 cm_node, cm_id, jiffies);
40799
40800diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40801index 4166452..fc952c3 100644
40802--- a/drivers/infiniband/hw/nes/nes_mgt.c
40803+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40804@@ -40,8 +40,8 @@
40805 #include "nes.h"
40806 #include "nes_mgt.h"
40807
40808-atomic_t pau_qps_created;
40809-atomic_t pau_qps_destroyed;
40810+atomic_unchecked_t pau_qps_created;
40811+atomic_unchecked_t pau_qps_destroyed;
40812
40813 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40814 {
40815@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40816 {
40817 struct sk_buff *skb;
40818 unsigned long flags;
40819- atomic_inc(&pau_qps_destroyed);
40820+ atomic_inc_unchecked(&pau_qps_destroyed);
40821
40822 /* Free packets that have not yet been forwarded */
40823 /* Lock is acquired by skb_dequeue when removing the skb */
40824@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40825 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40826 skb_queue_head_init(&nesqp->pau_list);
40827 spin_lock_init(&nesqp->pau_lock);
40828- atomic_inc(&pau_qps_created);
40829+ atomic_inc_unchecked(&pau_qps_created);
40830 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40831 }
40832
40833diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40834index 49eb511..a774366 100644
40835--- a/drivers/infiniband/hw/nes/nes_nic.c
40836+++ b/drivers/infiniband/hw/nes/nes_nic.c
40837@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40838 target_stat_values[++index] = mh_detected;
40839 target_stat_values[++index] = mh_pauses_sent;
40840 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40841- target_stat_values[++index] = atomic_read(&cm_connects);
40842- target_stat_values[++index] = atomic_read(&cm_accepts);
40843- target_stat_values[++index] = atomic_read(&cm_disconnects);
40844- target_stat_values[++index] = atomic_read(&cm_connecteds);
40845- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40846- target_stat_values[++index] = atomic_read(&cm_rejects);
40847- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40848- target_stat_values[++index] = atomic_read(&qps_created);
40849- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40850- target_stat_values[++index] = atomic_read(&qps_destroyed);
40851- target_stat_values[++index] = atomic_read(&cm_closes);
40852+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40853+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40854+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40855+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40856+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40857+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40858+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40859+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40860+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40861+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40862+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40863 target_stat_values[++index] = cm_packets_sent;
40864 target_stat_values[++index] = cm_packets_bounced;
40865 target_stat_values[++index] = cm_packets_created;
40866 target_stat_values[++index] = cm_packets_received;
40867 target_stat_values[++index] = cm_packets_dropped;
40868 target_stat_values[++index] = cm_packets_retrans;
40869- target_stat_values[++index] = atomic_read(&cm_listens_created);
40870- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40871+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40872+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40873 target_stat_values[++index] = cm_backlog_drops;
40874- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40875- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40876- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40877- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40878- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40879+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40880+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40881+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40882+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40883+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40884 target_stat_values[++index] = nesadapter->free_4kpbl;
40885 target_stat_values[++index] = nesadapter->free_256pbl;
40886 target_stat_values[++index] = int_mod_timer_init;
40887 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40888 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40889 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40890- target_stat_values[++index] = atomic_read(&pau_qps_created);
40891- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40892+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40893+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40894 }
40895
40896 /**
40897diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40898index 5b53ca5..443da3c 100644
40899--- a/drivers/infiniband/hw/nes/nes_verbs.c
40900+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40901@@ -46,9 +46,9 @@
40902
40903 #include <rdma/ib_umem.h>
40904
40905-atomic_t mod_qp_timouts;
40906-atomic_t qps_created;
40907-atomic_t sw_qps_destroyed;
40908+atomic_unchecked_t mod_qp_timouts;
40909+atomic_unchecked_t qps_created;
40910+atomic_unchecked_t sw_qps_destroyed;
40911
40912 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40913
40914@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40915 if (init_attr->create_flags)
40916 return ERR_PTR(-EINVAL);
40917
40918- atomic_inc(&qps_created);
40919+ atomic_inc_unchecked(&qps_created);
40920 switch (init_attr->qp_type) {
40921 case IB_QPT_RC:
40922 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40923@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40924 struct iw_cm_event cm_event;
40925 int ret = 0;
40926
40927- atomic_inc(&sw_qps_destroyed);
40928+ atomic_inc_unchecked(&sw_qps_destroyed);
40929 nesqp->destroyed = 1;
40930
40931 /* Blow away the connection if it exists. */
40932diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40933index 1946101..09766d2 100644
40934--- a/drivers/infiniband/hw/qib/qib.h
40935+++ b/drivers/infiniband/hw/qib/qib.h
40936@@ -52,6 +52,7 @@
40937 #include <linux/kref.h>
40938 #include <linux/sched.h>
40939 #include <linux/kthread.h>
40940+#include <linux/slab.h>
40941
40942 #include "qib_common.h"
40943 #include "qib_verbs.h"
40944diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40945index 922a7fe..bb035db 100644
40946--- a/drivers/input/gameport/gameport.c
40947+++ b/drivers/input/gameport/gameport.c
40948@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40949 */
40950 static void gameport_init_port(struct gameport *gameport)
40951 {
40952- static atomic_t gameport_no = ATOMIC_INIT(0);
40953+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40954
40955 __module_get(THIS_MODULE);
40956
40957 mutex_init(&gameport->drv_mutex);
40958 device_initialize(&gameport->dev);
40959 dev_set_name(&gameport->dev, "gameport%lu",
40960- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40961+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40962 gameport->dev.bus = &gameport_bus;
40963 gameport->dev.release = gameport_release_port;
40964 if (gameport->parent)
40965diff --git a/drivers/input/input.c b/drivers/input/input.c
40966index e75d015..57d1c28 100644
40967--- a/drivers/input/input.c
40968+++ b/drivers/input/input.c
40969@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
40970 */
40971 struct input_dev *input_allocate_device(void)
40972 {
40973- static atomic_t input_no = ATOMIC_INIT(0);
40974+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40975 struct input_dev *dev;
40976
40977 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
40978@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
40979 INIT_LIST_HEAD(&dev->node);
40980
40981 dev_set_name(&dev->dev, "input%ld",
40982- (unsigned long) atomic_inc_return(&input_no) - 1);
40983+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40984
40985 __module_get(THIS_MODULE);
40986 }
40987diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40988index 04c69af..5f92d00 100644
40989--- a/drivers/input/joystick/sidewinder.c
40990+++ b/drivers/input/joystick/sidewinder.c
40991@@ -30,6 +30,7 @@
40992 #include <linux/kernel.h>
40993 #include <linux/module.h>
40994 #include <linux/slab.h>
40995+#include <linux/sched.h>
40996 #include <linux/init.h>
40997 #include <linux/input.h>
40998 #include <linux/gameport.h>
40999diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41000index 75e3b10..fb390fd 100644
41001--- a/drivers/input/joystick/xpad.c
41002+++ b/drivers/input/joystick/xpad.c
41003@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41004
41005 static int xpad_led_probe(struct usb_xpad *xpad)
41006 {
41007- static atomic_t led_seq = ATOMIC_INIT(0);
41008+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41009 long led_no;
41010 struct xpad_led *led;
41011 struct led_classdev *led_cdev;
41012@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41013 if (!led)
41014 return -ENOMEM;
41015
41016- led_no = (long)atomic_inc_return(&led_seq) - 1;
41017+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41018
41019 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41020 led->xpad = xpad;
41021diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41022index e204f26..8459f15 100644
41023--- a/drivers/input/misc/ims-pcu.c
41024+++ b/drivers/input/misc/ims-pcu.c
41025@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41026
41027 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41028 {
41029- static atomic_t device_no = ATOMIC_INIT(0);
41030+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41031
41032 const struct ims_pcu_device_info *info;
41033 u8 device_id;
41034@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41035 }
41036
41037 /* Device appears to be operable, complete initialization */
41038- pcu->device_no = atomic_inc_return(&device_no) - 1;
41039+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41040
41041 error = ims_pcu_setup_backlight(pcu);
41042 if (error)
41043diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41044index 2f0b39d..7370f13 100644
41045--- a/drivers/input/mouse/psmouse.h
41046+++ b/drivers/input/mouse/psmouse.h
41047@@ -116,7 +116,7 @@ struct psmouse_attribute {
41048 ssize_t (*set)(struct psmouse *psmouse, void *data,
41049 const char *buf, size_t count);
41050 bool protect;
41051-};
41052+} __do_const;
41053 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41054
41055 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41056diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41057index 4c842c3..590b0bf 100644
41058--- a/drivers/input/mousedev.c
41059+++ b/drivers/input/mousedev.c
41060@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41061
41062 spin_unlock_irq(&client->packet_lock);
41063
41064- if (copy_to_user(buffer, data, count))
41065+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41066 return -EFAULT;
41067
41068 return count;
41069diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41070index 2b56855..5a55837 100644
41071--- a/drivers/input/serio/serio.c
41072+++ b/drivers/input/serio/serio.c
41073@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41074 */
41075 static void serio_init_port(struct serio *serio)
41076 {
41077- static atomic_t serio_no = ATOMIC_INIT(0);
41078+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41079
41080 __module_get(THIS_MODULE);
41081
41082@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41083 mutex_init(&serio->drv_mutex);
41084 device_initialize(&serio->dev);
41085 dev_set_name(&serio->dev, "serio%ld",
41086- (long)atomic_inc_return(&serio_no) - 1);
41087+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41088 serio->dev.bus = &serio_bus;
41089 serio->dev.release = serio_release_port;
41090 serio->dev.groups = serio_device_attr_groups;
41091diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41092index 59df2e7..8f1cafb 100644
41093--- a/drivers/input/serio/serio_raw.c
41094+++ b/drivers/input/serio/serio_raw.c
41095@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41096
41097 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41098 {
41099- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41100+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41101 struct serio_raw *serio_raw;
41102 int err;
41103
41104@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41105 }
41106
41107 snprintf(serio_raw->name, sizeof(serio_raw->name),
41108- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41109+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41110 kref_init(&serio_raw->kref);
41111 INIT_LIST_HEAD(&serio_raw->client_list);
41112 init_waitqueue_head(&serio_raw->wait);
41113diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41114index fbe9ca7..dbee61d 100644
41115--- a/drivers/iommu/iommu.c
41116+++ b/drivers/iommu/iommu.c
41117@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41118 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41119 {
41120 bus_register_notifier(bus, &iommu_bus_nb);
41121- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41122+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41123 }
41124
41125 /**
41126diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41127index 39f81ae..2660096 100644
41128--- a/drivers/iommu/irq_remapping.c
41129+++ b/drivers/iommu/irq_remapping.c
41130@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41131 void panic_if_irq_remap(const char *msg)
41132 {
41133 if (irq_remapping_enabled)
41134- panic(msg);
41135+ panic("%s", msg);
41136 }
41137
41138 static void ir_ack_apic_edge(struct irq_data *data)
41139@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41140
41141 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41142 {
41143- chip->irq_print_chip = ir_print_prefix;
41144- chip->irq_ack = ir_ack_apic_edge;
41145- chip->irq_eoi = ir_ack_apic_level;
41146- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41147+ pax_open_kernel();
41148+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41149+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41150+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41151+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41152+ pax_close_kernel();
41153 }
41154
41155 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41156diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41157index d0e9480..d2b6340 100644
41158--- a/drivers/irqchip/irq-gic.c
41159+++ b/drivers/irqchip/irq-gic.c
41160@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41161 * Supported arch specific GIC irq extension.
41162 * Default make them NULL.
41163 */
41164-struct irq_chip gic_arch_extn = {
41165+irq_chip_no_const gic_arch_extn = {
41166 .irq_eoi = NULL,
41167 .irq_mask = NULL,
41168 .irq_unmask = NULL,
41169@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41170 chained_irq_exit(chip, desc);
41171 }
41172
41173-static struct irq_chip gic_chip = {
41174+static irq_chip_no_const gic_chip __read_only = {
41175 .name = "GIC",
41176 .irq_mask = gic_mask_irq,
41177 .irq_unmask = gic_unmask_irq,
41178diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41179index ac6f72b..81150f2 100644
41180--- a/drivers/isdn/capi/capi.c
41181+++ b/drivers/isdn/capi/capi.c
41182@@ -81,8 +81,8 @@ struct capiminor {
41183
41184 struct capi20_appl *ap;
41185 u32 ncci;
41186- atomic_t datahandle;
41187- atomic_t msgid;
41188+ atomic_unchecked_t datahandle;
41189+ atomic_unchecked_t msgid;
41190
41191 struct tty_port port;
41192 int ttyinstop;
41193@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41194 capimsg_setu16(s, 2, mp->ap->applid);
41195 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41196 capimsg_setu8 (s, 5, CAPI_RESP);
41197- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41198+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41199 capimsg_setu32(s, 8, mp->ncci);
41200 capimsg_setu16(s, 12, datahandle);
41201 }
41202@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41203 mp->outbytes -= len;
41204 spin_unlock_bh(&mp->outlock);
41205
41206- datahandle = atomic_inc_return(&mp->datahandle);
41207+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41208 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41209 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41210 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41211 capimsg_setu16(skb->data, 2, mp->ap->applid);
41212 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41213 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41214- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41215+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41216 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41217 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41218 capimsg_setu16(skb->data, 16, len); /* Data length */
41219diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41220index 600c79b..3752bab 100644
41221--- a/drivers/isdn/gigaset/interface.c
41222+++ b/drivers/isdn/gigaset/interface.c
41223@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41224 }
41225 tty->driver_data = cs;
41226
41227- ++cs->port.count;
41228+ atomic_inc(&cs->port.count);
41229
41230- if (cs->port.count == 1) {
41231+ if (atomic_read(&cs->port.count) == 1) {
41232 tty_port_tty_set(&cs->port, tty);
41233 cs->port.low_latency = 1;
41234 }
41235@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41236
41237 if (!cs->connected)
41238 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41239- else if (!cs->port.count)
41240+ else if (!atomic_read(&cs->port.count))
41241 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41242- else if (!--cs->port.count)
41243+ else if (!atomic_dec_return(&cs->port.count))
41244 tty_port_tty_set(&cs->port, NULL);
41245
41246 mutex_unlock(&cs->mutex);
41247diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41248index d0a41cb..f0cdb8c 100644
41249--- a/drivers/isdn/gigaset/usb-gigaset.c
41250+++ b/drivers/isdn/gigaset/usb-gigaset.c
41251@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41252 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41253 memcpy(cs->hw.usb->bchars, buf, 6);
41254 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41255- 0, 0, &buf, 6, 2000);
41256+ 0, 0, buf, 6, 2000);
41257 }
41258
41259 static void gigaset_freebcshw(struct bc_state *bcs)
41260diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41261index 4d9b195..455075c 100644
41262--- a/drivers/isdn/hardware/avm/b1.c
41263+++ b/drivers/isdn/hardware/avm/b1.c
41264@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41265 }
41266 if (left) {
41267 if (t4file->user) {
41268- if (copy_from_user(buf, dp, left))
41269+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41270 return -EFAULT;
41271 } else {
41272 memcpy(buf, dp, left);
41273@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41274 }
41275 if (left) {
41276 if (config->user) {
41277- if (copy_from_user(buf, dp, left))
41278+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41279 return -EFAULT;
41280 } else {
41281 memcpy(buf, dp, left);
41282diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41283index 9bb12ba..d4262f7 100644
41284--- a/drivers/isdn/i4l/isdn_common.c
41285+++ b/drivers/isdn/i4l/isdn_common.c
41286@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41287 } else
41288 return -EINVAL;
41289 case IIOCDBGVAR:
41290+ if (!capable(CAP_SYS_RAWIO))
41291+ return -EPERM;
41292 if (arg) {
41293 if (copy_to_user(argp, &dev, sizeof(ulong)))
41294 return -EFAULT;
41295diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41296index 3c5f249..5fac4d0 100644
41297--- a/drivers/isdn/i4l/isdn_tty.c
41298+++ b/drivers/isdn/i4l/isdn_tty.c
41299@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41300
41301 #ifdef ISDN_DEBUG_MODEM_OPEN
41302 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41303- port->count);
41304+ atomic_read(&port->count));
41305 #endif
41306- port->count++;
41307+ atomic_inc(&port->count);
41308 port->tty = tty;
41309 /*
41310 * Start up serial port
41311@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41312 #endif
41313 return;
41314 }
41315- if ((tty->count == 1) && (port->count != 1)) {
41316+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41317 /*
41318 * Uh, oh. tty->count is 1, which means that the tty
41319 * structure will be freed. Info->count should always
41320@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41321 * serial port won't be shutdown.
41322 */
41323 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41324- "info->count is %d\n", port->count);
41325- port->count = 1;
41326+ "info->count is %d\n", atomic_read(&port->count));
41327+ atomic_set(&port->count, 1);
41328 }
41329- if (--port->count < 0) {
41330+ if (atomic_dec_return(&port->count) < 0) {
41331 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41332- info->line, port->count);
41333- port->count = 0;
41334+ info->line, atomic_read(&port->count));
41335+ atomic_set(&port->count, 0);
41336 }
41337- if (port->count) {
41338+ if (atomic_read(&port->count)) {
41339 #ifdef ISDN_DEBUG_MODEM_OPEN
41340 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41341 #endif
41342@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41343 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41344 return;
41345 isdn_tty_shutdown(info);
41346- port->count = 0;
41347+ atomic_set(&port->count, 0);
41348 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41349 port->tty = NULL;
41350 wake_up_interruptible(&port->open_wait);
41351@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41352 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41353 modem_info *info = &dev->mdm.info[i];
41354
41355- if (info->port.count == 0)
41356+ if (atomic_read(&info->port.count) == 0)
41357 continue;
41358 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41359 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41360diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41361index e74df7c..03a03ba 100644
41362--- a/drivers/isdn/icn/icn.c
41363+++ b/drivers/isdn/icn/icn.c
41364@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41365 if (count > len)
41366 count = len;
41367 if (user) {
41368- if (copy_from_user(msg, buf, count))
41369+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41370 return -EFAULT;
41371 } else
41372 memcpy(msg, buf, count);
41373diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
41374index baf2686..02125e6 100644
41375--- a/drivers/isdn/isdnloop/isdnloop.c
41376+++ b/drivers/isdn/isdnloop/isdnloop.c
41377@@ -1083,8 +1083,10 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
41378 spin_unlock_irqrestore(&card->isdnloop_lock, flags);
41379 return -ENOMEM;
41380 }
41381- for (i = 0; i < 3; i++)
41382- strcpy(card->s0num[i], sdef.num[i]);
41383+ for (i = 0; i < 3; i++) {
41384+ strlcpy(card->s0num[i], sdef.num[i],
41385+ sizeof(card->s0num[0]));
41386+ }
41387 break;
41388 case ISDN_PTYPE_1TR6:
41389 if (isdnloop_fake(card, "DRV1.04TC-1TR6-CAPI-CNS-BASIS-29.11.95",
41390@@ -1097,7 +1099,7 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
41391 spin_unlock_irqrestore(&card->isdnloop_lock, flags);
41392 return -ENOMEM;
41393 }
41394- strcpy(card->s0num[0], sdef.num[0]);
41395+ strlcpy(card->s0num[0], sdef.num[0], sizeof(card->s0num[0]));
41396 card->s0num[1][0] = '\0';
41397 card->s0num[2][0] = '\0';
41398 break;
41399diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
41400index a4f05c5..1433bc5 100644
41401--- a/drivers/isdn/mISDN/dsp_cmx.c
41402+++ b/drivers/isdn/mISDN/dsp_cmx.c
41403@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
41404 static u16 dsp_count; /* last sample count */
41405 static int dsp_count_valid; /* if we have last sample count */
41406
41407-void
41408+void __intentional_overflow(-1)
41409 dsp_cmx_send(void *arg)
41410 {
41411 struct dsp_conf *conf;
41412diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41413index d93e245..e7ece6b 100644
41414--- a/drivers/leds/leds-clevo-mail.c
41415+++ b/drivers/leds/leds-clevo-mail.c
41416@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41417 * detected as working, but in reality it is not) as low as
41418 * possible.
41419 */
41420-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
41421+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
41422 {
41423 .callback = clevo_mail_led_dmi_callback,
41424 .ident = "Clevo D410J",
41425diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41426index 5b8f938..b73d657 100644
41427--- a/drivers/leds/leds-ss4200.c
41428+++ b/drivers/leds/leds-ss4200.c
41429@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41430 * detected as working, but in reality it is not) as low as
41431 * possible.
41432 */
41433-static struct dmi_system_id nas_led_whitelist[] __initdata = {
41434+static struct dmi_system_id nas_led_whitelist[] __initconst = {
41435 {
41436 .callback = ss4200_led_dmi_callback,
41437 .ident = "Intel SS4200-E",
41438diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41439index 0bf1e4e..b4bf44e 100644
41440--- a/drivers/lguest/core.c
41441+++ b/drivers/lguest/core.c
41442@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41443 * The end address needs +1 because __get_vm_area allocates an
41444 * extra guard page, so we need space for that.
41445 */
41446+
41447+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41448+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41449+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41450+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41451+#else
41452 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41453 VM_ALLOC, switcher_addr, switcher_addr
41454 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41455+#endif
41456+
41457 if (!switcher_vma) {
41458 err = -ENOMEM;
41459 printk("lguest: could not map switcher pages high\n");
41460@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41461 * Now the Switcher is mapped at the right address, we can't fail!
41462 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41463 */
41464- memcpy(switcher_vma->addr, start_switcher_text,
41465+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41466 end_switcher_text - start_switcher_text);
41467
41468 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41469diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41470index bfb39bb..08a603b 100644
41471--- a/drivers/lguest/page_tables.c
41472+++ b/drivers/lguest/page_tables.c
41473@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41474 /*:*/
41475
41476 #ifdef CONFIG_X86_PAE
41477-static void release_pmd(pmd_t *spmd)
41478+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41479 {
41480 /* If the entry's not present, there's nothing to release. */
41481 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41482diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41483index 5169239..47cb4db 100644
41484--- a/drivers/lguest/x86/core.c
41485+++ b/drivers/lguest/x86/core.c
41486@@ -59,7 +59,7 @@ static struct {
41487 /* Offset from where switcher.S was compiled to where we've copied it */
41488 static unsigned long switcher_offset(void)
41489 {
41490- return switcher_addr - (unsigned long)start_switcher_text;
41491+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41492 }
41493
41494 /* This cpu's struct lguest_pages (after the Switcher text page) */
41495@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
41496 * These copies are pretty cheap, so we do them unconditionally: */
41497 /* Save the current Host top-level page directory.
41498 */
41499+
41500+#ifdef CONFIG_PAX_PER_CPU_PGD
41501+ pages->state.host_cr3 = read_cr3();
41502+#else
41503 pages->state.host_cr3 = __pa(current->mm->pgd);
41504+#endif
41505+
41506 /*
41507 * Set up the Guest's page tables to see this CPU's pages (and no
41508 * other CPU's pages).
41509@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
41510 * compiled-in switcher code and the high-mapped copy we just made.
41511 */
41512 for (i = 0; i < IDT_ENTRIES; i++)
41513- default_idt_entries[i] += switcher_offset();
41514+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
41515
41516 /*
41517 * Set up the Switcher's per-cpu areas.
41518@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
41519 * it will be undisturbed when we switch. To change %cs and jump we
41520 * need this structure to feed to Intel's "lcall" instruction.
41521 */
41522- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
41523+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
41524 lguest_entry.segment = LGUEST_CS;
41525
41526 /*
41527diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
41528index 40634b0..4f5855e 100644
41529--- a/drivers/lguest/x86/switcher_32.S
41530+++ b/drivers/lguest/x86/switcher_32.S
41531@@ -87,6 +87,7 @@
41532 #include <asm/page.h>
41533 #include <asm/segment.h>
41534 #include <asm/lguest.h>
41535+#include <asm/processor-flags.h>
41536
41537 // We mark the start of the code to copy
41538 // It's placed in .text tho it's never run here
41539@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
41540 // Changes type when we load it: damn Intel!
41541 // For after we switch over our page tables
41542 // That entry will be read-only: we'd crash.
41543+
41544+#ifdef CONFIG_PAX_KERNEXEC
41545+ mov %cr0, %edx
41546+ xor $X86_CR0_WP, %edx
41547+ mov %edx, %cr0
41548+#endif
41549+
41550 movl $(GDT_ENTRY_TSS*8), %edx
41551 ltr %dx
41552
41553@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
41554 // Let's clear it again for our return.
41555 // The GDT descriptor of the Host
41556 // Points to the table after two "size" bytes
41557- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
41558+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
41559 // Clear "used" from type field (byte 5, bit 2)
41560- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
41561+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
41562+
41563+#ifdef CONFIG_PAX_KERNEXEC
41564+ mov %cr0, %eax
41565+ xor $X86_CR0_WP, %eax
41566+ mov %eax, %cr0
41567+#endif
41568
41569 // Once our page table's switched, the Guest is live!
41570 // The Host fades as we run this final step.
41571@@ -295,13 +309,12 @@ deliver_to_host:
41572 // I consulted gcc, and it gave
41573 // These instructions, which I gladly credit:
41574 leal (%edx,%ebx,8), %eax
41575- movzwl (%eax),%edx
41576- movl 4(%eax), %eax
41577- xorw %ax, %ax
41578- orl %eax, %edx
41579+ movl 4(%eax), %edx
41580+ movw (%eax), %dx
41581 // Now the address of the handler's in %edx
41582 // We call it now: its "iret" drops us home.
41583- jmp *%edx
41584+ ljmp $__KERNEL_CS, $1f
41585+1: jmp *%edx
41586
41587 // Every interrupt can come to us here
41588 // But we must truly tell each apart.
41589diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
41590index 0003992..854bbce 100644
41591--- a/drivers/md/bcache/closure.h
41592+++ b/drivers/md/bcache/closure.h
41593@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
41594 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
41595 struct workqueue_struct *wq)
41596 {
41597- BUG_ON(object_is_on_stack(cl));
41598+ BUG_ON(object_starts_on_stack(cl));
41599 closure_set_ip(cl);
41600 cl->fn = fn;
41601 cl->wq = wq;
41602diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
41603index 547c4c5..5be1de4 100644
41604--- a/drivers/md/bcache/super.c
41605+++ b/drivers/md/bcache/super.c
41606@@ -1644,7 +1644,7 @@ err_unlock_gc:
41607 err:
41608 closure_sync(&op.cl);
41609 /* XXX: test this, it's broken */
41610- bch_cache_set_error(c, err);
41611+ bch_cache_set_error(c, "%s", err);
41612 }
41613
41614 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
41615diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
41616index a7fd821..9dcf6c3 100644
41617--- a/drivers/md/bitmap.c
41618+++ b/drivers/md/bitmap.c
41619@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
41620 chunk_kb ? "KB" : "B");
41621 if (bitmap->storage.file) {
41622 seq_printf(seq, ", file: ");
41623- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
41624+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
41625 }
41626
41627 seq_printf(seq, "\n");
41628diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
41629index afe0814..8cf3794 100644
41630--- a/drivers/md/dm-ioctl.c
41631+++ b/drivers/md/dm-ioctl.c
41632@@ -1745,7 +1745,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
41633 cmd == DM_LIST_VERSIONS_CMD)
41634 return 0;
41635
41636- if ((cmd == DM_DEV_CREATE_CMD)) {
41637+ if (cmd == DM_DEV_CREATE_CMD) {
41638 if (!*param->name) {
41639 DMWARN("name not supplied when creating device");
41640 return -EINVAL;
41641diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
41642index 9584443..9fc9ac9 100644
41643--- a/drivers/md/dm-raid1.c
41644+++ b/drivers/md/dm-raid1.c
41645@@ -40,7 +40,7 @@ enum dm_raid1_error {
41646
41647 struct mirror {
41648 struct mirror_set *ms;
41649- atomic_t error_count;
41650+ atomic_unchecked_t error_count;
41651 unsigned long error_type;
41652 struct dm_dev *dev;
41653 sector_t offset;
41654@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
41655 struct mirror *m;
41656
41657 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
41658- if (!atomic_read(&m->error_count))
41659+ if (!atomic_read_unchecked(&m->error_count))
41660 return m;
41661
41662 return NULL;
41663@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
41664 * simple way to tell if a device has encountered
41665 * errors.
41666 */
41667- atomic_inc(&m->error_count);
41668+ atomic_inc_unchecked(&m->error_count);
41669
41670 if (test_and_set_bit(error_type, &m->error_type))
41671 return;
41672@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
41673 struct mirror *m = get_default_mirror(ms);
41674
41675 do {
41676- if (likely(!atomic_read(&m->error_count)))
41677+ if (likely(!atomic_read_unchecked(&m->error_count)))
41678 return m;
41679
41680 if (m-- == ms->mirror)
41681@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
41682 {
41683 struct mirror *default_mirror = get_default_mirror(m->ms);
41684
41685- return !atomic_read(&default_mirror->error_count);
41686+ return !atomic_read_unchecked(&default_mirror->error_count);
41687 }
41688
41689 static int mirror_available(struct mirror_set *ms, struct bio *bio)
41690@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
41691 */
41692 if (likely(region_in_sync(ms, region, 1)))
41693 m = choose_mirror(ms, bio->bi_sector);
41694- else if (m && atomic_read(&m->error_count))
41695+ else if (m && atomic_read_unchecked(&m->error_count))
41696 m = NULL;
41697
41698 if (likely(m))
41699@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
41700 }
41701
41702 ms->mirror[mirror].ms = ms;
41703- atomic_set(&(ms->mirror[mirror].error_count), 0);
41704+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
41705 ms->mirror[mirror].error_type = 0;
41706 ms->mirror[mirror].offset = offset;
41707
41708@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
41709 */
41710 static char device_status_char(struct mirror *m)
41711 {
41712- if (!atomic_read(&(m->error_count)))
41713+ if (!atomic_read_unchecked(&(m->error_count)))
41714 return 'A';
41715
41716 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
41717diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
41718index 3d404c1..b62af0e 100644
41719--- a/drivers/md/dm-stats.c
41720+++ b/drivers/md/dm-stats.c
41721@@ -382,7 +382,7 @@ do_sync_free:
41722 synchronize_rcu_expedited();
41723 dm_stat_free(&s->rcu_head);
41724 } else {
41725- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
41726+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
41727 call_rcu(&s->rcu_head, dm_stat_free);
41728 }
41729 return 0;
41730@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
41731 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
41732 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
41733 ));
41734- ACCESS_ONCE(last->last_sector) = end_sector;
41735- ACCESS_ONCE(last->last_rw) = bi_rw;
41736+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
41737+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
41738 }
41739
41740 rcu_read_lock();
41741diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
41742index 73c1712..7347292 100644
41743--- a/drivers/md/dm-stripe.c
41744+++ b/drivers/md/dm-stripe.c
41745@@ -21,7 +21,7 @@ struct stripe {
41746 struct dm_dev *dev;
41747 sector_t physical_start;
41748
41749- atomic_t error_count;
41750+ atomic_unchecked_t error_count;
41751 };
41752
41753 struct stripe_c {
41754@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
41755 kfree(sc);
41756 return r;
41757 }
41758- atomic_set(&(sc->stripe[i].error_count), 0);
41759+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
41760 }
41761
41762 ti->private = sc;
41763@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
41764 DMEMIT("%d ", sc->stripes);
41765 for (i = 0; i < sc->stripes; i++) {
41766 DMEMIT("%s ", sc->stripe[i].dev->name);
41767- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
41768+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
41769 'D' : 'A';
41770 }
41771 buffer[i] = '\0';
41772@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
41773 */
41774 for (i = 0; i < sc->stripes; i++)
41775 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
41776- atomic_inc(&(sc->stripe[i].error_count));
41777- if (atomic_read(&(sc->stripe[i].error_count)) <
41778+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
41779+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
41780 DM_IO_ERROR_THRESHOLD)
41781 schedule_work(&sc->trigger_event);
41782 }
41783diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
41784index 8f87835..531854d 100644
41785--- a/drivers/md/dm-table.c
41786+++ b/drivers/md/dm-table.c
41787@@ -286,7 +286,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
41788 static int open_dev(struct dm_dev_internal *d, dev_t dev,
41789 struct mapped_device *md)
41790 {
41791- static char *_claim_ptr = "I belong to device-mapper";
41792+ static char _claim_ptr[] = "I belong to device-mapper";
41793 struct block_device *bdev;
41794
41795 int r;
41796@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
41797 if (!dev_size)
41798 return 0;
41799
41800- if ((start >= dev_size) || (start + len > dev_size)) {
41801+ if ((start >= dev_size) || (len > dev_size - start)) {
41802 DMWARN("%s: %s too small for target: "
41803 "start=%llu, len=%llu, dev_size=%llu",
41804 dm_device_name(ti->table->md), bdevname(bdev, b),
41805diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
41806index 60bce43..9b997d0 100644
41807--- a/drivers/md/dm-thin-metadata.c
41808+++ b/drivers/md/dm-thin-metadata.c
41809@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
41810 {
41811 pmd->info.tm = pmd->tm;
41812 pmd->info.levels = 2;
41813- pmd->info.value_type.context = pmd->data_sm;
41814+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
41815 pmd->info.value_type.size = sizeof(__le64);
41816 pmd->info.value_type.inc = data_block_inc;
41817 pmd->info.value_type.dec = data_block_dec;
41818@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
41819
41820 pmd->bl_info.tm = pmd->tm;
41821 pmd->bl_info.levels = 1;
41822- pmd->bl_info.value_type.context = pmd->data_sm;
41823+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
41824 pmd->bl_info.value_type.size = sizeof(__le64);
41825 pmd->bl_info.value_type.inc = data_block_inc;
41826 pmd->bl_info.value_type.dec = data_block_dec;
41827diff --git a/drivers/md/dm.c b/drivers/md/dm.c
41828index b3e26c7..1efca94 100644
41829--- a/drivers/md/dm.c
41830+++ b/drivers/md/dm.c
41831@@ -179,9 +179,9 @@ struct mapped_device {
41832 /*
41833 * Event handling.
41834 */
41835- atomic_t event_nr;
41836+ atomic_unchecked_t event_nr;
41837 wait_queue_head_t eventq;
41838- atomic_t uevent_seq;
41839+ atomic_unchecked_t uevent_seq;
41840 struct list_head uevent_list;
41841 spinlock_t uevent_lock; /* Protect access to uevent_list */
41842
41843@@ -1985,8 +1985,8 @@ static struct mapped_device *alloc_dev(int minor)
41844 spin_lock_init(&md->deferred_lock);
41845 atomic_set(&md->holders, 1);
41846 atomic_set(&md->open_count, 0);
41847- atomic_set(&md->event_nr, 0);
41848- atomic_set(&md->uevent_seq, 0);
41849+ atomic_set_unchecked(&md->event_nr, 0);
41850+ atomic_set_unchecked(&md->uevent_seq, 0);
41851 INIT_LIST_HEAD(&md->uevent_list);
41852 spin_lock_init(&md->uevent_lock);
41853
41854@@ -2139,7 +2139,7 @@ static void event_callback(void *context)
41855
41856 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
41857
41858- atomic_inc(&md->event_nr);
41859+ atomic_inc_unchecked(&md->event_nr);
41860 wake_up(&md->eventq);
41861 }
41862
41863@@ -2832,18 +2832,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
41864
41865 uint32_t dm_next_uevent_seq(struct mapped_device *md)
41866 {
41867- return atomic_add_return(1, &md->uevent_seq);
41868+ return atomic_add_return_unchecked(1, &md->uevent_seq);
41869 }
41870
41871 uint32_t dm_get_event_nr(struct mapped_device *md)
41872 {
41873- return atomic_read(&md->event_nr);
41874+ return atomic_read_unchecked(&md->event_nr);
41875 }
41876
41877 int dm_wait_event(struct mapped_device *md, int event_nr)
41878 {
41879 return wait_event_interruptible(md->eventq,
41880- (event_nr != atomic_read(&md->event_nr)));
41881+ (event_nr != atomic_read_unchecked(&md->event_nr)));
41882 }
41883
41884 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
41885diff --git a/drivers/md/md.c b/drivers/md/md.c
41886index 561a65f..f4e8c71 100644
41887--- a/drivers/md/md.c
41888+++ b/drivers/md/md.c
41889@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
41890 * start build, activate spare
41891 */
41892 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
41893-static atomic_t md_event_count;
41894+static atomic_unchecked_t md_event_count;
41895 void md_new_event(struct mddev *mddev)
41896 {
41897- atomic_inc(&md_event_count);
41898+ atomic_inc_unchecked(&md_event_count);
41899 wake_up(&md_event_waiters);
41900 }
41901 EXPORT_SYMBOL_GPL(md_new_event);
41902@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
41903 */
41904 static void md_new_event_inintr(struct mddev *mddev)
41905 {
41906- atomic_inc(&md_event_count);
41907+ atomic_inc_unchecked(&md_event_count);
41908 wake_up(&md_event_waiters);
41909 }
41910
41911@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
41912 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
41913 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
41914 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
41915- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
41916+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
41917
41918 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
41919 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
41920@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
41921 else
41922 sb->resync_offset = cpu_to_le64(0);
41923
41924- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
41925+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
41926
41927 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
41928 sb->size = cpu_to_le64(mddev->dev_sectors);
41929@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
41930 static ssize_t
41931 errors_show(struct md_rdev *rdev, char *page)
41932 {
41933- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
41934+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
41935 }
41936
41937 static ssize_t
41938@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
41939 char *e;
41940 unsigned long n = simple_strtoul(buf, &e, 10);
41941 if (*buf && (*e == 0 || *e == '\n')) {
41942- atomic_set(&rdev->corrected_errors, n);
41943+ atomic_set_unchecked(&rdev->corrected_errors, n);
41944 return len;
41945 }
41946 return -EINVAL;
41947@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
41948 rdev->sb_loaded = 0;
41949 rdev->bb_page = NULL;
41950 atomic_set(&rdev->nr_pending, 0);
41951- atomic_set(&rdev->read_errors, 0);
41952- atomic_set(&rdev->corrected_errors, 0);
41953+ atomic_set_unchecked(&rdev->read_errors, 0);
41954+ atomic_set_unchecked(&rdev->corrected_errors, 0);
41955
41956 INIT_LIST_HEAD(&rdev->same_set);
41957 init_waitqueue_head(&rdev->blocked_wait);
41958@@ -7042,7 +7042,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
41959
41960 spin_unlock(&pers_lock);
41961 seq_printf(seq, "\n");
41962- seq->poll_event = atomic_read(&md_event_count);
41963+ seq->poll_event = atomic_read_unchecked(&md_event_count);
41964 return 0;
41965 }
41966 if (v == (void*)2) {
41967@@ -7145,7 +7145,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
41968 return error;
41969
41970 seq = file->private_data;
41971- seq->poll_event = atomic_read(&md_event_count);
41972+ seq->poll_event = atomic_read_unchecked(&md_event_count);
41973 return error;
41974 }
41975
41976@@ -7159,7 +7159,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
41977 /* always allow read */
41978 mask = POLLIN | POLLRDNORM;
41979
41980- if (seq->poll_event != atomic_read(&md_event_count))
41981+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
41982 mask |= POLLERR | POLLPRI;
41983 return mask;
41984 }
41985@@ -7203,7 +7203,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
41986 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
41987 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
41988 (int)part_stat_read(&disk->part0, sectors[1]) -
41989- atomic_read(&disk->sync_io);
41990+ atomic_read_unchecked(&disk->sync_io);
41991 /* sync IO will cause sync_io to increase before the disk_stats
41992 * as sync_io is counted when a request starts, and
41993 * disk_stats is counted when it completes.
41994diff --git a/drivers/md/md.h b/drivers/md/md.h
41995index 608050c..6e77db5d 100644
41996--- a/drivers/md/md.h
41997+++ b/drivers/md/md.h
41998@@ -94,13 +94,13 @@ struct md_rdev {
41999 * only maintained for arrays that
42000 * support hot removal
42001 */
42002- atomic_t read_errors; /* number of consecutive read errors that
42003+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42004 * we have tried to ignore.
42005 */
42006 struct timespec last_read_error; /* monotonic time since our
42007 * last read error
42008 */
42009- atomic_t corrected_errors; /* number of corrected read errors,
42010+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42011 * for reporting to userspace and storing
42012 * in superblock.
42013 */
42014@@ -446,7 +446,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42015
42016 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42017 {
42018- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42019+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42020 }
42021
42022 struct md_personality
42023diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42024index 3e6d115..ffecdeb 100644
42025--- a/drivers/md/persistent-data/dm-space-map.h
42026+++ b/drivers/md/persistent-data/dm-space-map.h
42027@@ -71,6 +71,7 @@ struct dm_space_map {
42028 dm_sm_threshold_fn fn,
42029 void *context);
42030 };
42031+typedef struct dm_space_map __no_const dm_space_map_no_const;
42032
42033 /*----------------------------------------------------------------*/
42034
42035diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42036index aacf6bf..67d63f2 100644
42037--- a/drivers/md/raid1.c
42038+++ b/drivers/md/raid1.c
42039@@ -1824,7 +1824,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42040 if (r1_sync_page_io(rdev, sect, s,
42041 bio->bi_io_vec[idx].bv_page,
42042 READ) != 0)
42043- atomic_add(s, &rdev->corrected_errors);
42044+ atomic_add_unchecked(s, &rdev->corrected_errors);
42045 }
42046 sectors -= s;
42047 sect += s;
42048@@ -2051,7 +2051,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42049 test_bit(In_sync, &rdev->flags)) {
42050 if (r1_sync_page_io(rdev, sect, s,
42051 conf->tmppage, READ)) {
42052- atomic_add(s, &rdev->corrected_errors);
42053+ atomic_add_unchecked(s, &rdev->corrected_errors);
42054 printk(KERN_INFO
42055 "md/raid1:%s: read error corrected "
42056 "(%d sectors at %llu on %s)\n",
42057diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42058index 73dc8a3..bdd515a 100644
42059--- a/drivers/md/raid10.c
42060+++ b/drivers/md/raid10.c
42061@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
42062 /* The write handler will notice the lack of
42063 * R10BIO_Uptodate and record any errors etc
42064 */
42065- atomic_add(r10_bio->sectors,
42066+ atomic_add_unchecked(r10_bio->sectors,
42067 &conf->mirrors[d].rdev->corrected_errors);
42068
42069 /* for reconstruct, we always reschedule after a read.
42070@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42071 {
42072 struct timespec cur_time_mon;
42073 unsigned long hours_since_last;
42074- unsigned int read_errors = atomic_read(&rdev->read_errors);
42075+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42076
42077 ktime_get_ts(&cur_time_mon);
42078
42079@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42080 * overflowing the shift of read_errors by hours_since_last.
42081 */
42082 if (hours_since_last >= 8 * sizeof(read_errors))
42083- atomic_set(&rdev->read_errors, 0);
42084+ atomic_set_unchecked(&rdev->read_errors, 0);
42085 else
42086- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42087+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42088 }
42089
42090 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42091@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42092 return;
42093
42094 check_decay_read_errors(mddev, rdev);
42095- atomic_inc(&rdev->read_errors);
42096- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42097+ atomic_inc_unchecked(&rdev->read_errors);
42098+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42099 char b[BDEVNAME_SIZE];
42100 bdevname(rdev->bdev, b);
42101
42102@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42103 "md/raid10:%s: %s: Raid device exceeded "
42104 "read_error threshold [cur %d:max %d]\n",
42105 mdname(mddev), b,
42106- atomic_read(&rdev->read_errors), max_read_errors);
42107+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42108 printk(KERN_NOTICE
42109 "md/raid10:%s: %s: Failing raid device\n",
42110 mdname(mddev), b);
42111@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42112 sect +
42113 choose_data_offset(r10_bio, rdev)),
42114 bdevname(rdev->bdev, b));
42115- atomic_add(s, &rdev->corrected_errors);
42116+ atomic_add_unchecked(s, &rdev->corrected_errors);
42117 }
42118
42119 rdev_dec_pending(rdev, mddev);
42120diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42121index f8b9068..7a2b9fc 100644
42122--- a/drivers/md/raid5.c
42123+++ b/drivers/md/raid5.c
42124@@ -1886,21 +1886,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42125 mdname(conf->mddev), STRIPE_SECTORS,
42126 (unsigned long long)s,
42127 bdevname(rdev->bdev, b));
42128- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42129+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42130 clear_bit(R5_ReadError, &sh->dev[i].flags);
42131 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42132 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42133 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42134
42135- if (atomic_read(&rdev->read_errors))
42136- atomic_set(&rdev->read_errors, 0);
42137+ if (atomic_read_unchecked(&rdev->read_errors))
42138+ atomic_set_unchecked(&rdev->read_errors, 0);
42139 } else {
42140 const char *bdn = bdevname(rdev->bdev, b);
42141 int retry = 0;
42142 int set_bad = 0;
42143
42144 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42145- atomic_inc(&rdev->read_errors);
42146+ atomic_inc_unchecked(&rdev->read_errors);
42147 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42148 printk_ratelimited(
42149 KERN_WARNING
42150@@ -1928,7 +1928,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42151 mdname(conf->mddev),
42152 (unsigned long long)s,
42153 bdn);
42154- } else if (atomic_read(&rdev->read_errors)
42155+ } else if (atomic_read_unchecked(&rdev->read_errors)
42156 > conf->max_nr_stripes)
42157 printk(KERN_WARNING
42158 "md/raid:%s: Too many read errors, failing device %s.\n",
42159diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42160index 401ef64..836e563 100644
42161--- a/drivers/media/dvb-core/dvbdev.c
42162+++ b/drivers/media/dvb-core/dvbdev.c
42163@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42164 const struct dvb_device *template, void *priv, int type)
42165 {
42166 struct dvb_device *dvbdev;
42167- struct file_operations *dvbdevfops;
42168+ file_operations_no_const *dvbdevfops;
42169 struct device *clsdev;
42170 int minor;
42171 int id;
42172diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42173index 9b6c3bb..baeb5c7 100644
42174--- a/drivers/media/dvb-frontends/dib3000.h
42175+++ b/drivers/media/dvb-frontends/dib3000.h
42176@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42177 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42178 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42179 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42180-};
42181+} __no_const;
42182
42183 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42184 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42185diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42186index ecf21d9..b992428d 100644
42187--- a/drivers/media/pci/cx88/cx88-video.c
42188+++ b/drivers/media/pci/cx88/cx88-video.c
42189@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42190
42191 /* ------------------------------------------------------------------ */
42192
42193-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42194-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42195-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42196+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42197+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42198+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42199
42200 module_param_array(video_nr, int, NULL, 0444);
42201 module_param_array(vbi_nr, int, NULL, 0444);
42202diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42203index c08ae3e..eb59af1 100644
42204--- a/drivers/media/pci/ivtv/ivtv-driver.c
42205+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42206@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42207 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42208
42209 /* ivtv instance counter */
42210-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42211+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42212
42213 /* Parameter declarations */
42214 static int cardtype[IVTV_MAX_CARDS];
42215diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42216index dfd0a21..6bbb465 100644
42217--- a/drivers/media/platform/omap/omap_vout.c
42218+++ b/drivers/media/platform/omap/omap_vout.c
42219@@ -63,7 +63,6 @@ enum omap_vout_channels {
42220 OMAP_VIDEO2,
42221 };
42222
42223-static struct videobuf_queue_ops video_vbq_ops;
42224 /* Variables configurable through module params*/
42225 static u32 video1_numbuffers = 3;
42226 static u32 video2_numbuffers = 3;
42227@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42228 {
42229 struct videobuf_queue *q;
42230 struct omap_vout_device *vout = NULL;
42231+ static struct videobuf_queue_ops video_vbq_ops = {
42232+ .buf_setup = omap_vout_buffer_setup,
42233+ .buf_prepare = omap_vout_buffer_prepare,
42234+ .buf_release = omap_vout_buffer_release,
42235+ .buf_queue = omap_vout_buffer_queue,
42236+ };
42237
42238 vout = video_drvdata(file);
42239 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42240@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42241 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42242
42243 q = &vout->vbq;
42244- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42245- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42246- video_vbq_ops.buf_release = omap_vout_buffer_release;
42247- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42248 spin_lock_init(&vout->vbq_lock);
42249
42250 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42251diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42252index 04e6490..2df65bf 100644
42253--- a/drivers/media/platform/s5p-tv/mixer.h
42254+++ b/drivers/media/platform/s5p-tv/mixer.h
42255@@ -156,7 +156,7 @@ struct mxr_layer {
42256 /** layer index (unique identifier) */
42257 int idx;
42258 /** callbacks for layer methods */
42259- struct mxr_layer_ops ops;
42260+ struct mxr_layer_ops *ops;
42261 /** format array */
42262 const struct mxr_format **fmt_array;
42263 /** size of format array */
42264diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42265index b93a21f..2535195 100644
42266--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42267+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42268@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42269 {
42270 struct mxr_layer *layer;
42271 int ret;
42272- struct mxr_layer_ops ops = {
42273+ static struct mxr_layer_ops ops = {
42274 .release = mxr_graph_layer_release,
42275 .buffer_set = mxr_graph_buffer_set,
42276 .stream_set = mxr_graph_stream_set,
42277diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42278index b713403..53cb5ad 100644
42279--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42280+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42281@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42282 layer->update_buf = next;
42283 }
42284
42285- layer->ops.buffer_set(layer, layer->update_buf);
42286+ layer->ops->buffer_set(layer, layer->update_buf);
42287
42288 if (done && done != layer->shadow_buf)
42289 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42290diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42291index 641b1f0..49cff30 100644
42292--- a/drivers/media/platform/s5p-tv/mixer_video.c
42293+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42294@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42295 layer->geo.src.height = layer->geo.src.full_height;
42296
42297 mxr_geometry_dump(mdev, &layer->geo);
42298- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42299+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42300 mxr_geometry_dump(mdev, &layer->geo);
42301 }
42302
42303@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42304 layer->geo.dst.full_width = mbus_fmt.width;
42305 layer->geo.dst.full_height = mbus_fmt.height;
42306 layer->geo.dst.field = mbus_fmt.field;
42307- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42308+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42309
42310 mxr_geometry_dump(mdev, &layer->geo);
42311 }
42312@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42313 /* set source size to highest accepted value */
42314 geo->src.full_width = max(geo->dst.full_width, pix->width);
42315 geo->src.full_height = max(geo->dst.full_height, pix->height);
42316- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42317+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42318 mxr_geometry_dump(mdev, &layer->geo);
42319 /* set cropping to total visible screen */
42320 geo->src.width = pix->width;
42321@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42322 geo->src.x_offset = 0;
42323 geo->src.y_offset = 0;
42324 /* assure consistency of geometry */
42325- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42326+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42327 mxr_geometry_dump(mdev, &layer->geo);
42328 /* set full size to lowest possible value */
42329 geo->src.full_width = 0;
42330 geo->src.full_height = 0;
42331- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42332+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42333 mxr_geometry_dump(mdev, &layer->geo);
42334
42335 /* returning results */
42336@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42337 target->width = s->r.width;
42338 target->height = s->r.height;
42339
42340- layer->ops.fix_geometry(layer, stage, s->flags);
42341+ layer->ops->fix_geometry(layer, stage, s->flags);
42342
42343 /* retrieve update selection rectangle */
42344 res.left = target->x_offset;
42345@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42346 mxr_output_get(mdev);
42347
42348 mxr_layer_update_output(layer);
42349- layer->ops.format_set(layer);
42350+ layer->ops->format_set(layer);
42351 /* enabling layer in hardware */
42352 spin_lock_irqsave(&layer->enq_slock, flags);
42353 layer->state = MXR_LAYER_STREAMING;
42354 spin_unlock_irqrestore(&layer->enq_slock, flags);
42355
42356- layer->ops.stream_set(layer, MXR_ENABLE);
42357+ layer->ops->stream_set(layer, MXR_ENABLE);
42358 mxr_streamer_get(mdev);
42359
42360 return 0;
42361@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42362 spin_unlock_irqrestore(&layer->enq_slock, flags);
42363
42364 /* disabling layer in hardware */
42365- layer->ops.stream_set(layer, MXR_DISABLE);
42366+ layer->ops->stream_set(layer, MXR_DISABLE);
42367 /* remove one streamer */
42368 mxr_streamer_put(mdev);
42369 /* allow changes in output configuration */
42370@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42371
42372 void mxr_layer_release(struct mxr_layer *layer)
42373 {
42374- if (layer->ops.release)
42375- layer->ops.release(layer);
42376+ if (layer->ops->release)
42377+ layer->ops->release(layer);
42378 }
42379
42380 void mxr_base_layer_release(struct mxr_layer *layer)
42381@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42382
42383 layer->mdev = mdev;
42384 layer->idx = idx;
42385- layer->ops = *ops;
42386+ layer->ops = ops;
42387
42388 spin_lock_init(&layer->enq_slock);
42389 INIT_LIST_HEAD(&layer->enq_list);
42390diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42391index 3d13a63..da31bf1 100644
42392--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42393+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42394@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42395 {
42396 struct mxr_layer *layer;
42397 int ret;
42398- struct mxr_layer_ops ops = {
42399+ static struct mxr_layer_ops ops = {
42400 .release = mxr_vp_layer_release,
42401 .buffer_set = mxr_vp_buffer_set,
42402 .stream_set = mxr_vp_stream_set,
42403diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42404index 545c04c..a14bded 100644
42405--- a/drivers/media/radio/radio-cadet.c
42406+++ b/drivers/media/radio/radio-cadet.c
42407@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42408 unsigned char readbuf[RDS_BUFFER];
42409 int i = 0;
42410
42411+ if (count > RDS_BUFFER)
42412+ return -EFAULT;
42413 mutex_lock(&dev->lock);
42414 if (dev->rdsstat == 0)
42415 cadet_start_rds(dev);
42416@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42417 while (i < count && dev->rdsin != dev->rdsout)
42418 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42419
42420- if (i && copy_to_user(data, readbuf, i))
42421+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42422 i = -EFAULT;
42423 unlock:
42424 mutex_unlock(&dev->lock);
42425diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42426index 5236035..c622c74 100644
42427--- a/drivers/media/radio/radio-maxiradio.c
42428+++ b/drivers/media/radio/radio-maxiradio.c
42429@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42430 /* TEA5757 pin mappings */
42431 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42432
42433-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42434+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42435
42436 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42437 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42438diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42439index b914772..7ddbf9b 100644
42440--- a/drivers/media/radio/radio-shark.c
42441+++ b/drivers/media/radio/radio-shark.c
42442@@ -79,7 +79,7 @@ struct shark_device {
42443 u32 last_val;
42444 };
42445
42446-static atomic_t shark_instance = ATOMIC_INIT(0);
42447+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42448
42449 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42450 {
42451diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42452index 9fb6697..f167415 100644
42453--- a/drivers/media/radio/radio-shark2.c
42454+++ b/drivers/media/radio/radio-shark2.c
42455@@ -74,7 +74,7 @@ struct shark_device {
42456 u8 *transfer_buffer;
42457 };
42458
42459-static atomic_t shark_instance = ATOMIC_INIT(0);
42460+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42461
42462 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42463 {
42464diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42465index 9c9084c..a9e8dfb 100644
42466--- a/drivers/media/radio/radio-si476x.c
42467+++ b/drivers/media/radio/radio-si476x.c
42468@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42469 struct si476x_radio *radio;
42470 struct v4l2_ctrl *ctrl;
42471
42472- static atomic_t instance = ATOMIC_INIT(0);
42473+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42474
42475 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42476 if (!radio)
42477diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42478index 46da365..3ba4206 100644
42479--- a/drivers/media/rc/rc-main.c
42480+++ b/drivers/media/rc/rc-main.c
42481@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42482 int rc_register_device(struct rc_dev *dev)
42483 {
42484 static bool raw_init = false; /* raw decoders loaded? */
42485- static atomic_t devno = ATOMIC_INIT(0);
42486+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42487 struct rc_map *rc_map;
42488 const char *path;
42489 int rc;
42490@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
42491 */
42492 mutex_lock(&dev->lock);
42493
42494- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42495+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42496 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42497 dev_set_drvdata(&dev->dev, dev);
42498 rc = device_add(&dev->dev);
42499diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42500index 3940bb0..fb3952a 100644
42501--- a/drivers/media/usb/dvb-usb/cxusb.c
42502+++ b/drivers/media/usb/dvb-usb/cxusb.c
42503@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42504
42505 struct dib0700_adapter_state {
42506 int (*set_param_save) (struct dvb_frontend *);
42507-};
42508+} __no_const;
42509
42510 static int dib7070_set_param_override(struct dvb_frontend *fe)
42511 {
42512diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42513index 6e237b6..dc25556 100644
42514--- a/drivers/media/usb/dvb-usb/dw2102.c
42515+++ b/drivers/media/usb/dvb-usb/dw2102.c
42516@@ -118,7 +118,7 @@ struct su3000_state {
42517
42518 struct s6x0_state {
42519 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42520-};
42521+} __no_const;
42522
42523 /* debug */
42524 static int dvb_usb_dw2102_debug;
42525diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42526index 8f7a6a4..59502dd 100644
42527--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42528+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42529@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
42530 __u32 reserved;
42531 };
42532
42533-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42534+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42535 enum v4l2_memory memory)
42536 {
42537 void __user *up_pln;
42538@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42539 return 0;
42540 }
42541
42542-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42543+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42544 enum v4l2_memory memory)
42545 {
42546 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
42547@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
42548 put_user(kp->start_block, &up->start_block) ||
42549 put_user(kp->blocks, &up->blocks) ||
42550 put_user(tmp, &up->edid) ||
42551- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
42552+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
42553 return -EFAULT;
42554 return 0;
42555 }
42556diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
42557index 02d1b63..5fd6b16 100644
42558--- a/drivers/media/v4l2-core/v4l2-device.c
42559+++ b/drivers/media/v4l2-core/v4l2-device.c
42560@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
42561 EXPORT_SYMBOL_GPL(v4l2_device_put);
42562
42563 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
42564- atomic_t *instance)
42565+ atomic_unchecked_t *instance)
42566 {
42567- int num = atomic_inc_return(instance) - 1;
42568+ int num = atomic_inc_return_unchecked(instance) - 1;
42569 int len = strlen(basename);
42570
42571 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
42572diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
42573index 68e6b5e..d8b923e 100644
42574--- a/drivers/media/v4l2-core/v4l2-ioctl.c
42575+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
42576@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
42577 struct file *file, void *fh, void *p);
42578 } u;
42579 void (*debug)(const void *arg, bool write_only);
42580-};
42581+} __do_const;
42582+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
42583
42584 /* This control needs a priority check */
42585 #define INFO_FL_PRIO (1 << 0)
42586@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
42587 struct video_device *vfd = video_devdata(file);
42588 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
42589 bool write_only = false;
42590- struct v4l2_ioctl_info default_info;
42591+ v4l2_ioctl_info_no_const default_info;
42592 const struct v4l2_ioctl_info *info;
42593 void *fh = file->private_data;
42594 struct v4l2_fh *vfh = NULL;
42595@@ -2194,7 +2195,7 @@ done:
42596 }
42597
42598 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42599- void * __user *user_ptr, void ***kernel_ptr)
42600+ void __user **user_ptr, void ***kernel_ptr)
42601 {
42602 int ret = 0;
42603
42604@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42605 ret = -EINVAL;
42606 break;
42607 }
42608- *user_ptr = (void __user *)buf->m.planes;
42609+ *user_ptr = (void __force_user *)buf->m.planes;
42610 *kernel_ptr = (void *)&buf->m.planes;
42611 *array_size = sizeof(struct v4l2_plane) * buf->length;
42612 ret = 1;
42613@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42614 ret = -EINVAL;
42615 break;
42616 }
42617- *user_ptr = (void __user *)ctrls->controls;
42618+ *user_ptr = (void __force_user *)ctrls->controls;
42619 *kernel_ptr = (void *)&ctrls->controls;
42620 *array_size = sizeof(struct v4l2_ext_control)
42621 * ctrls->count;
42622diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
42623index 767ff4d..c69d259 100644
42624--- a/drivers/message/fusion/mptbase.c
42625+++ b/drivers/message/fusion/mptbase.c
42626@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42627 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
42628 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
42629
42630+#ifdef CONFIG_GRKERNSEC_HIDESYM
42631+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
42632+#else
42633 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
42634 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
42635+#endif
42636+
42637 /*
42638 * Rounding UP to nearest 4-kB boundary here...
42639 */
42640@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42641 ioc->facts.GlobalCredits);
42642
42643 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
42644+#ifdef CONFIG_GRKERNSEC_HIDESYM
42645+ NULL, NULL);
42646+#else
42647 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
42648+#endif
42649 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
42650 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
42651 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
42652diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
42653index dd239bd..689c4f7 100644
42654--- a/drivers/message/fusion/mptsas.c
42655+++ b/drivers/message/fusion/mptsas.c
42656@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
42657 return 0;
42658 }
42659
42660+static inline void
42661+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42662+{
42663+ if (phy_info->port_details) {
42664+ phy_info->port_details->rphy = rphy;
42665+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42666+ ioc->name, rphy));
42667+ }
42668+
42669+ if (rphy) {
42670+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42671+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42672+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42673+ ioc->name, rphy, rphy->dev.release));
42674+ }
42675+}
42676+
42677 /* no mutex */
42678 static void
42679 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
42680@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
42681 return NULL;
42682 }
42683
42684-static inline void
42685-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42686-{
42687- if (phy_info->port_details) {
42688- phy_info->port_details->rphy = rphy;
42689- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42690- ioc->name, rphy));
42691- }
42692-
42693- if (rphy) {
42694- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42695- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42696- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42697- ioc->name, rphy, rphy->dev.release));
42698- }
42699-}
42700-
42701 static inline struct sas_port *
42702 mptsas_get_port(struct mptsas_phyinfo *phy_info)
42703 {
42704diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
42705index 727819c..ad74694 100644
42706--- a/drivers/message/fusion/mptscsih.c
42707+++ b/drivers/message/fusion/mptscsih.c
42708@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
42709
42710 h = shost_priv(SChost);
42711
42712- if (h) {
42713- if (h->info_kbuf == NULL)
42714- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42715- return h->info_kbuf;
42716- h->info_kbuf[0] = '\0';
42717+ if (!h)
42718+ return NULL;
42719
42720- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42721- h->info_kbuf[size-1] = '\0';
42722- }
42723+ if (h->info_kbuf == NULL)
42724+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42725+ return h->info_kbuf;
42726+ h->info_kbuf[0] = '\0';
42727+
42728+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42729+ h->info_kbuf[size-1] = '\0';
42730
42731 return h->info_kbuf;
42732 }
42733diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
42734index b7d87cd..3fb36da 100644
42735--- a/drivers/message/i2o/i2o_proc.c
42736+++ b/drivers/message/i2o/i2o_proc.c
42737@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
42738 "Array Controller Device"
42739 };
42740
42741-static char *chtostr(char *tmp, u8 *chars, int n)
42742-{
42743- tmp[0] = 0;
42744- return strncat(tmp, (char *)chars, n);
42745-}
42746-
42747 static int i2o_report_query_status(struct seq_file *seq, int block_status,
42748 char *group)
42749 {
42750@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
42751 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
42752 {
42753 struct i2o_controller *c = (struct i2o_controller *)seq->private;
42754- static u32 work32[5];
42755- static u8 *work8 = (u8 *) work32;
42756- static u16 *work16 = (u16 *) work32;
42757+ u32 work32[5];
42758+ u8 *work8 = (u8 *) work32;
42759+ u16 *work16 = (u16 *) work32;
42760 int token;
42761 u32 hwcap;
42762
42763@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
42764 } *result;
42765
42766 i2o_exec_execute_ddm_table ddm_table;
42767- char tmp[28 + 1];
42768
42769 result = kmalloc(sizeof(*result), GFP_KERNEL);
42770 if (!result)
42771@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
42772
42773 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
42774 seq_printf(seq, "%-#8x", ddm_table.module_id);
42775- seq_printf(seq, "%-29s",
42776- chtostr(tmp, ddm_table.module_name_version, 28));
42777+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
42778 seq_printf(seq, "%9d ", ddm_table.data_size);
42779 seq_printf(seq, "%8d", ddm_table.code_size);
42780
42781@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
42782
42783 i2o_driver_result_table *result;
42784 i2o_driver_store_table *dst;
42785- char tmp[28 + 1];
42786
42787 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
42788 if (result == NULL)
42789@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
42790
42791 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
42792 seq_printf(seq, "%-#8x", dst->module_id);
42793- seq_printf(seq, "%-29s",
42794- chtostr(tmp, dst->module_name_version, 28));
42795- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
42796+ seq_printf(seq, "%-.28s", dst->module_name_version);
42797+ seq_printf(seq, "%-.8s", dst->date);
42798 seq_printf(seq, "%8d ", dst->module_size);
42799 seq_printf(seq, "%8d ", dst->mpb_size);
42800 seq_printf(seq, "0x%04x", dst->module_flags);
42801@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
42802 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
42803 {
42804 struct i2o_device *d = (struct i2o_device *)seq->private;
42805- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
42806+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
42807 // == (allow) 512d bytes (max)
42808- static u16 *work16 = (u16 *) work32;
42809+ u16 *work16 = (u16 *) work32;
42810 int token;
42811- char tmp[16 + 1];
42812
42813 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
42814
42815@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
42816 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
42817 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
42818 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
42819- seq_printf(seq, "Vendor info : %s\n",
42820- chtostr(tmp, (u8 *) (work32 + 2), 16));
42821- seq_printf(seq, "Product info : %s\n",
42822- chtostr(tmp, (u8 *) (work32 + 6), 16));
42823- seq_printf(seq, "Description : %s\n",
42824- chtostr(tmp, (u8 *) (work32 + 10), 16));
42825- seq_printf(seq, "Product rev. : %s\n",
42826- chtostr(tmp, (u8 *) (work32 + 14), 8));
42827+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
42828+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
42829+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
42830+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
42831
42832 seq_printf(seq, "Serial number : ");
42833 print_serial_number(seq, (u8 *) (work32 + 16),
42834@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
42835 u8 pad[256]; // allow up to 256 byte (max) serial number
42836 } result;
42837
42838- char tmp[24 + 1];
42839-
42840 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
42841
42842 if (token < 0) {
42843@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
42844 }
42845
42846 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
42847- seq_printf(seq, "Module name : %s\n",
42848- chtostr(tmp, result.module_name, 24));
42849- seq_printf(seq, "Module revision : %s\n",
42850- chtostr(tmp, result.module_rev, 8));
42851+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
42852+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
42853
42854 seq_printf(seq, "Serial number : ");
42855 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
42856@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
42857 u8 instance_number[4];
42858 } result;
42859
42860- char tmp[64 + 1];
42861-
42862 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
42863
42864 if (token < 0) {
42865@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
42866 return 0;
42867 }
42868
42869- seq_printf(seq, "Device name : %s\n",
42870- chtostr(tmp, result.device_name, 64));
42871- seq_printf(seq, "Service name : %s\n",
42872- chtostr(tmp, result.service_name, 64));
42873- seq_printf(seq, "Physical name : %s\n",
42874- chtostr(tmp, result.physical_location, 64));
42875- seq_printf(seq, "Instance number : %s\n",
42876- chtostr(tmp, result.instance_number, 4));
42877+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
42878+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
42879+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
42880+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
42881
42882 return 0;
42883 }
42884@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
42885 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
42886 {
42887 struct i2o_device *d = (struct i2o_device *)seq->private;
42888- static u32 work32[12];
42889- static u16 *work16 = (u16 *) work32;
42890- static u8 *work8 = (u8 *) work32;
42891+ u32 work32[12];
42892+ u16 *work16 = (u16 *) work32;
42893+ u8 *work8 = (u8 *) work32;
42894 int token;
42895
42896 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
42897diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
42898index a8c08f3..155fe3d 100644
42899--- a/drivers/message/i2o/iop.c
42900+++ b/drivers/message/i2o/iop.c
42901@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
42902
42903 spin_lock_irqsave(&c->context_list_lock, flags);
42904
42905- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
42906- atomic_inc(&c->context_list_counter);
42907+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
42908+ atomic_inc_unchecked(&c->context_list_counter);
42909
42910- entry->context = atomic_read(&c->context_list_counter);
42911+ entry->context = atomic_read_unchecked(&c->context_list_counter);
42912
42913 list_add(&entry->list, &c->context_list);
42914
42915@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
42916
42917 #if BITS_PER_LONG == 64
42918 spin_lock_init(&c->context_list_lock);
42919- atomic_set(&c->context_list_counter, 0);
42920+ atomic_set_unchecked(&c->context_list_counter, 0);
42921 INIT_LIST_HEAD(&c->context_list);
42922 #endif
42923
42924diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
42925index fcbb2e9..2635e11 100644
42926--- a/drivers/mfd/janz-cmodio.c
42927+++ b/drivers/mfd/janz-cmodio.c
42928@@ -13,6 +13,7 @@
42929
42930 #include <linux/kernel.h>
42931 #include <linux/module.h>
42932+#include <linux/slab.h>
42933 #include <linux/init.h>
42934 #include <linux/pci.h>
42935 #include <linux/interrupt.h>
42936diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
42937index de7fb80..7c1b931 100644
42938--- a/drivers/mfd/max8925-i2c.c
42939+++ b/drivers/mfd/max8925-i2c.c
42940@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
42941 const struct i2c_device_id *id)
42942 {
42943 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
42944- static struct max8925_chip *chip;
42945+ struct max8925_chip *chip;
42946 struct device_node *node = client->dev.of_node;
42947
42948 if (node && !pdata) {
42949diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
42950index d792772..cd73ba3 100644
42951--- a/drivers/mfd/tps65910.c
42952+++ b/drivers/mfd/tps65910.c
42953@@ -229,7 +229,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
42954 struct tps65910_platform_data *pdata)
42955 {
42956 int ret = 0;
42957- static struct regmap_irq_chip *tps6591x_irqs_chip;
42958+ struct regmap_irq_chip *tps6591x_irqs_chip;
42959
42960 if (!irq) {
42961 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
42962diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
42963index 9aa6d1e..1631bfc 100644
42964--- a/drivers/mfd/twl4030-irq.c
42965+++ b/drivers/mfd/twl4030-irq.c
42966@@ -35,6 +35,7 @@
42967 #include <linux/of.h>
42968 #include <linux/irqdomain.h>
42969 #include <linux/i2c/twl.h>
42970+#include <asm/pgtable.h>
42971
42972 #include "twl-core.h"
42973
42974@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
42975 * Install an irq handler for each of the SIH modules;
42976 * clone dummy irq_chip since PIH can't *do* anything
42977 */
42978- twl4030_irq_chip = dummy_irq_chip;
42979- twl4030_irq_chip.name = "twl4030";
42980+ pax_open_kernel();
42981+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
42982+ *(const char **)&twl4030_irq_chip.name = "twl4030";
42983
42984- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
42985+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
42986+ pax_close_kernel();
42987
42988 for (i = irq_base; i < irq_end; i++) {
42989 irq_set_chip_and_handler(i, &twl4030_irq_chip,
42990diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
42991index 464419b..64bae8d 100644
42992--- a/drivers/misc/c2port/core.c
42993+++ b/drivers/misc/c2port/core.c
42994@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
42995 goto error_idr_alloc;
42996 c2dev->id = ret;
42997
42998- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
42999+ pax_open_kernel();
43000+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
43001+ pax_close_kernel();
43002
43003 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
43004 "c2port%d", c2dev->id);
43005diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43006index 36f5d52..32311c3 100644
43007--- a/drivers/misc/kgdbts.c
43008+++ b/drivers/misc/kgdbts.c
43009@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43010 char before[BREAK_INSTR_SIZE];
43011 char after[BREAK_INSTR_SIZE];
43012
43013- probe_kernel_read(before, (char *)kgdbts_break_test,
43014+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43015 BREAK_INSTR_SIZE);
43016 init_simple_test();
43017 ts.tst = plant_and_detach_test;
43018@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43019 /* Activate test with initial breakpoint */
43020 if (!is_early)
43021 kgdb_breakpoint();
43022- probe_kernel_read(after, (char *)kgdbts_break_test,
43023+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43024 BREAK_INSTR_SIZE);
43025 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43026 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43027diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43028index 036effe..b3a6336 100644
43029--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43030+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43031@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43032 * the lid is closed. This leads to interrupts as soon as a little move
43033 * is done.
43034 */
43035- atomic_inc(&lis3->count);
43036+ atomic_inc_unchecked(&lis3->count);
43037
43038 wake_up_interruptible(&lis3->misc_wait);
43039 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43040@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43041 if (lis3->pm_dev)
43042 pm_runtime_get_sync(lis3->pm_dev);
43043
43044- atomic_set(&lis3->count, 0);
43045+ atomic_set_unchecked(&lis3->count, 0);
43046 return 0;
43047 }
43048
43049@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43050 add_wait_queue(&lis3->misc_wait, &wait);
43051 while (true) {
43052 set_current_state(TASK_INTERRUPTIBLE);
43053- data = atomic_xchg(&lis3->count, 0);
43054+ data = atomic_xchg_unchecked(&lis3->count, 0);
43055 if (data)
43056 break;
43057
43058@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43059 struct lis3lv02d, miscdev);
43060
43061 poll_wait(file, &lis3->misc_wait, wait);
43062- if (atomic_read(&lis3->count))
43063+ if (atomic_read_unchecked(&lis3->count))
43064 return POLLIN | POLLRDNORM;
43065 return 0;
43066 }
43067diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43068index c439c82..1f20f57 100644
43069--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43070+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43071@@ -297,7 +297,7 @@ struct lis3lv02d {
43072 struct input_polled_dev *idev; /* input device */
43073 struct platform_device *pdev; /* platform device */
43074 struct regulator_bulk_data regulators[2];
43075- atomic_t count; /* interrupt count after last read */
43076+ atomic_unchecked_t count; /* interrupt count after last read */
43077 union axis_conversion ac; /* hw -> logical axis */
43078 int mapped_btns[3];
43079
43080diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43081index 2f30bad..c4c13d0 100644
43082--- a/drivers/misc/sgi-gru/gruhandles.c
43083+++ b/drivers/misc/sgi-gru/gruhandles.c
43084@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43085 unsigned long nsec;
43086
43087 nsec = CLKS2NSEC(clks);
43088- atomic_long_inc(&mcs_op_statistics[op].count);
43089- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43090+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43091+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43092 if (mcs_op_statistics[op].max < nsec)
43093 mcs_op_statistics[op].max = nsec;
43094 }
43095diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43096index 4f76359..cdfcb2e 100644
43097--- a/drivers/misc/sgi-gru/gruprocfs.c
43098+++ b/drivers/misc/sgi-gru/gruprocfs.c
43099@@ -32,9 +32,9 @@
43100
43101 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43102
43103-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43104+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43105 {
43106- unsigned long val = atomic_long_read(v);
43107+ unsigned long val = atomic_long_read_unchecked(v);
43108
43109 seq_printf(s, "%16lu %s\n", val, id);
43110 }
43111@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43112
43113 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43114 for (op = 0; op < mcsop_last; op++) {
43115- count = atomic_long_read(&mcs_op_statistics[op].count);
43116- total = atomic_long_read(&mcs_op_statistics[op].total);
43117+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43118+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43119 max = mcs_op_statistics[op].max;
43120 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43121 count ? total / count : 0, max);
43122diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43123index 5c3ce24..4915ccb 100644
43124--- a/drivers/misc/sgi-gru/grutables.h
43125+++ b/drivers/misc/sgi-gru/grutables.h
43126@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43127 * GRU statistics.
43128 */
43129 struct gru_stats_s {
43130- atomic_long_t vdata_alloc;
43131- atomic_long_t vdata_free;
43132- atomic_long_t gts_alloc;
43133- atomic_long_t gts_free;
43134- atomic_long_t gms_alloc;
43135- atomic_long_t gms_free;
43136- atomic_long_t gts_double_allocate;
43137- atomic_long_t assign_context;
43138- atomic_long_t assign_context_failed;
43139- atomic_long_t free_context;
43140- atomic_long_t load_user_context;
43141- atomic_long_t load_kernel_context;
43142- atomic_long_t lock_kernel_context;
43143- atomic_long_t unlock_kernel_context;
43144- atomic_long_t steal_user_context;
43145- atomic_long_t steal_kernel_context;
43146- atomic_long_t steal_context_failed;
43147- atomic_long_t nopfn;
43148- atomic_long_t asid_new;
43149- atomic_long_t asid_next;
43150- atomic_long_t asid_wrap;
43151- atomic_long_t asid_reuse;
43152- atomic_long_t intr;
43153- atomic_long_t intr_cbr;
43154- atomic_long_t intr_tfh;
43155- atomic_long_t intr_spurious;
43156- atomic_long_t intr_mm_lock_failed;
43157- atomic_long_t call_os;
43158- atomic_long_t call_os_wait_queue;
43159- atomic_long_t user_flush_tlb;
43160- atomic_long_t user_unload_context;
43161- atomic_long_t user_exception;
43162- atomic_long_t set_context_option;
43163- atomic_long_t check_context_retarget_intr;
43164- atomic_long_t check_context_unload;
43165- atomic_long_t tlb_dropin;
43166- atomic_long_t tlb_preload_page;
43167- atomic_long_t tlb_dropin_fail_no_asid;
43168- atomic_long_t tlb_dropin_fail_upm;
43169- atomic_long_t tlb_dropin_fail_invalid;
43170- atomic_long_t tlb_dropin_fail_range_active;
43171- atomic_long_t tlb_dropin_fail_idle;
43172- atomic_long_t tlb_dropin_fail_fmm;
43173- atomic_long_t tlb_dropin_fail_no_exception;
43174- atomic_long_t tfh_stale_on_fault;
43175- atomic_long_t mmu_invalidate_range;
43176- atomic_long_t mmu_invalidate_page;
43177- atomic_long_t flush_tlb;
43178- atomic_long_t flush_tlb_gru;
43179- atomic_long_t flush_tlb_gru_tgh;
43180- atomic_long_t flush_tlb_gru_zero_asid;
43181+ atomic_long_unchecked_t vdata_alloc;
43182+ atomic_long_unchecked_t vdata_free;
43183+ atomic_long_unchecked_t gts_alloc;
43184+ atomic_long_unchecked_t gts_free;
43185+ atomic_long_unchecked_t gms_alloc;
43186+ atomic_long_unchecked_t gms_free;
43187+ atomic_long_unchecked_t gts_double_allocate;
43188+ atomic_long_unchecked_t assign_context;
43189+ atomic_long_unchecked_t assign_context_failed;
43190+ atomic_long_unchecked_t free_context;
43191+ atomic_long_unchecked_t load_user_context;
43192+ atomic_long_unchecked_t load_kernel_context;
43193+ atomic_long_unchecked_t lock_kernel_context;
43194+ atomic_long_unchecked_t unlock_kernel_context;
43195+ atomic_long_unchecked_t steal_user_context;
43196+ atomic_long_unchecked_t steal_kernel_context;
43197+ atomic_long_unchecked_t steal_context_failed;
43198+ atomic_long_unchecked_t nopfn;
43199+ atomic_long_unchecked_t asid_new;
43200+ atomic_long_unchecked_t asid_next;
43201+ atomic_long_unchecked_t asid_wrap;
43202+ atomic_long_unchecked_t asid_reuse;
43203+ atomic_long_unchecked_t intr;
43204+ atomic_long_unchecked_t intr_cbr;
43205+ atomic_long_unchecked_t intr_tfh;
43206+ atomic_long_unchecked_t intr_spurious;
43207+ atomic_long_unchecked_t intr_mm_lock_failed;
43208+ atomic_long_unchecked_t call_os;
43209+ atomic_long_unchecked_t call_os_wait_queue;
43210+ atomic_long_unchecked_t user_flush_tlb;
43211+ atomic_long_unchecked_t user_unload_context;
43212+ atomic_long_unchecked_t user_exception;
43213+ atomic_long_unchecked_t set_context_option;
43214+ atomic_long_unchecked_t check_context_retarget_intr;
43215+ atomic_long_unchecked_t check_context_unload;
43216+ atomic_long_unchecked_t tlb_dropin;
43217+ atomic_long_unchecked_t tlb_preload_page;
43218+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43219+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43220+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43221+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43222+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43223+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43224+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43225+ atomic_long_unchecked_t tfh_stale_on_fault;
43226+ atomic_long_unchecked_t mmu_invalidate_range;
43227+ atomic_long_unchecked_t mmu_invalidate_page;
43228+ atomic_long_unchecked_t flush_tlb;
43229+ atomic_long_unchecked_t flush_tlb_gru;
43230+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43231+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43232
43233- atomic_long_t copy_gpa;
43234- atomic_long_t read_gpa;
43235+ atomic_long_unchecked_t copy_gpa;
43236+ atomic_long_unchecked_t read_gpa;
43237
43238- atomic_long_t mesq_receive;
43239- atomic_long_t mesq_receive_none;
43240- atomic_long_t mesq_send;
43241- atomic_long_t mesq_send_failed;
43242- atomic_long_t mesq_noop;
43243- atomic_long_t mesq_send_unexpected_error;
43244- atomic_long_t mesq_send_lb_overflow;
43245- atomic_long_t mesq_send_qlimit_reached;
43246- atomic_long_t mesq_send_amo_nacked;
43247- atomic_long_t mesq_send_put_nacked;
43248- atomic_long_t mesq_page_overflow;
43249- atomic_long_t mesq_qf_locked;
43250- atomic_long_t mesq_qf_noop_not_full;
43251- atomic_long_t mesq_qf_switch_head_failed;
43252- atomic_long_t mesq_qf_unexpected_error;
43253- atomic_long_t mesq_noop_unexpected_error;
43254- atomic_long_t mesq_noop_lb_overflow;
43255- atomic_long_t mesq_noop_qlimit_reached;
43256- atomic_long_t mesq_noop_amo_nacked;
43257- atomic_long_t mesq_noop_put_nacked;
43258- atomic_long_t mesq_noop_page_overflow;
43259+ atomic_long_unchecked_t mesq_receive;
43260+ atomic_long_unchecked_t mesq_receive_none;
43261+ atomic_long_unchecked_t mesq_send;
43262+ atomic_long_unchecked_t mesq_send_failed;
43263+ atomic_long_unchecked_t mesq_noop;
43264+ atomic_long_unchecked_t mesq_send_unexpected_error;
43265+ atomic_long_unchecked_t mesq_send_lb_overflow;
43266+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43267+ atomic_long_unchecked_t mesq_send_amo_nacked;
43268+ atomic_long_unchecked_t mesq_send_put_nacked;
43269+ atomic_long_unchecked_t mesq_page_overflow;
43270+ atomic_long_unchecked_t mesq_qf_locked;
43271+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43272+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43273+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43274+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43275+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43276+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43277+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43278+ atomic_long_unchecked_t mesq_noop_put_nacked;
43279+ atomic_long_unchecked_t mesq_noop_page_overflow;
43280
43281 };
43282
43283@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43284 tghop_invalidate, mcsop_last};
43285
43286 struct mcs_op_statistic {
43287- atomic_long_t count;
43288- atomic_long_t total;
43289+ atomic_long_unchecked_t count;
43290+ atomic_long_unchecked_t total;
43291 unsigned long max;
43292 };
43293
43294@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43295
43296 #define STAT(id) do { \
43297 if (gru_options & OPT_STATS) \
43298- atomic_long_inc(&gru_stats.id); \
43299+ atomic_long_inc_unchecked(&gru_stats.id); \
43300 } while (0)
43301
43302 #ifdef CONFIG_SGI_GRU_DEBUG
43303diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43304index c862cd4..0d176fe 100644
43305--- a/drivers/misc/sgi-xp/xp.h
43306+++ b/drivers/misc/sgi-xp/xp.h
43307@@ -288,7 +288,7 @@ struct xpc_interface {
43308 xpc_notify_func, void *);
43309 void (*received) (short, int, void *);
43310 enum xp_retval (*partid_to_nasids) (short, void *);
43311-};
43312+} __no_const;
43313
43314 extern struct xpc_interface xpc_interface;
43315
43316diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43317index b94d5f7..7f494c5 100644
43318--- a/drivers/misc/sgi-xp/xpc.h
43319+++ b/drivers/misc/sgi-xp/xpc.h
43320@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43321 void (*received_payload) (struct xpc_channel *, void *);
43322 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43323 };
43324+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43325
43326 /* struct xpc_partition act_state values (for XPC HB) */
43327
43328@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43329 /* found in xpc_main.c */
43330 extern struct device *xpc_part;
43331 extern struct device *xpc_chan;
43332-extern struct xpc_arch_operations xpc_arch_ops;
43333+extern xpc_arch_operations_no_const xpc_arch_ops;
43334 extern int xpc_disengage_timelimit;
43335 extern int xpc_disengage_timedout;
43336 extern int xpc_activate_IRQ_rcvd;
43337diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43338index 82dc574..8539ab2 100644
43339--- a/drivers/misc/sgi-xp/xpc_main.c
43340+++ b/drivers/misc/sgi-xp/xpc_main.c
43341@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43342 .notifier_call = xpc_system_die,
43343 };
43344
43345-struct xpc_arch_operations xpc_arch_ops;
43346+xpc_arch_operations_no_const xpc_arch_ops;
43347
43348 /*
43349 * Timer function to enforce the timelimit on the partition disengage.
43350@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43351
43352 if (((die_args->trapnr == X86_TRAP_MF) ||
43353 (die_args->trapnr == X86_TRAP_XF)) &&
43354- !user_mode_vm(die_args->regs))
43355+ !user_mode(die_args->regs))
43356 xpc_die_deactivate();
43357
43358 break;
43359diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43360index ef18348..1b53cf0 100644
43361--- a/drivers/mmc/core/mmc_ops.c
43362+++ b/drivers/mmc/core/mmc_ops.c
43363@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43364 void *data_buf;
43365 int is_on_stack;
43366
43367- is_on_stack = object_is_on_stack(buf);
43368+ is_on_stack = object_starts_on_stack(buf);
43369 if (is_on_stack) {
43370 /*
43371 * dma onto stack is unsafe/nonportable, but callers to this
43372diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43373index 81b2994..dce857e 100644
43374--- a/drivers/mmc/host/dw_mmc.h
43375+++ b/drivers/mmc/host/dw_mmc.h
43376@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43377 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43378 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43379 int (*parse_dt)(struct dw_mci *host);
43380-};
43381+} __do_const;
43382 #endif /* _DW_MMC_H_ */
43383diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43384index c3785ed..1984c44 100644
43385--- a/drivers/mmc/host/mmci.c
43386+++ b/drivers/mmc/host/mmci.c
43387@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43388 }
43389
43390 if (variant->busy_detect) {
43391- mmci_ops.card_busy = mmci_card_busy;
43392+ pax_open_kernel();
43393+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43394+ pax_close_kernel();
43395 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43396 }
43397
43398diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43399index 6debda9..2ba7427 100644
43400--- a/drivers/mmc/host/sdhci-s3c.c
43401+++ b/drivers/mmc/host/sdhci-s3c.c
43402@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43403 * we can use overriding functions instead of default.
43404 */
43405 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43406- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43407- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43408- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43409+ pax_open_kernel();
43410+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43411+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43412+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43413+ pax_close_kernel();
43414 }
43415
43416 /* It supports additional host capabilities if needed */
43417diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
43418index 096993f..f02c23b 100644
43419--- a/drivers/mtd/chips/cfi_cmdset_0020.c
43420+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
43421@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
43422 size_t totlen = 0, thislen;
43423 int ret = 0;
43424 size_t buflen = 0;
43425- static char *buffer;
43426+ char *buffer;
43427
43428 if (!ECCBUF_SIZE) {
43429 /* We should fall back to a general writev implementation.
43430diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43431index 2ed2bb3..2d0b82e 100644
43432--- a/drivers/mtd/nand/denali.c
43433+++ b/drivers/mtd/nand/denali.c
43434@@ -24,6 +24,7 @@
43435 #include <linux/slab.h>
43436 #include <linux/mtd/mtd.h>
43437 #include <linux/module.h>
43438+#include <linux/slab.h>
43439
43440 #include "denali.h"
43441
43442diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43443index 51b9d6a..52af9a7 100644
43444--- a/drivers/mtd/nftlmount.c
43445+++ b/drivers/mtd/nftlmount.c
43446@@ -24,6 +24,7 @@
43447 #include <asm/errno.h>
43448 #include <linux/delay.h>
43449 #include <linux/slab.h>
43450+#include <linux/sched.h>
43451 #include <linux/mtd/mtd.h>
43452 #include <linux/mtd/nand.h>
43453 #include <linux/mtd/nftl.h>
43454diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43455index 4b8e895..6b3c498 100644
43456--- a/drivers/mtd/sm_ftl.c
43457+++ b/drivers/mtd/sm_ftl.c
43458@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43459 #define SM_CIS_VENDOR_OFFSET 0x59
43460 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43461 {
43462- struct attribute_group *attr_group;
43463+ attribute_group_no_const *attr_group;
43464 struct attribute **attributes;
43465 struct sm_sysfs_attribute *vendor_attribute;
43466
43467diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43468index e883bfe..e51a1ec 100644
43469--- a/drivers/net/bonding/bond_main.c
43470+++ b/drivers/net/bonding/bond_main.c
43471@@ -4511,7 +4511,7 @@ static unsigned int bond_get_num_tx_queues(void)
43472 return tx_queues;
43473 }
43474
43475-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43476+static struct rtnl_link_ops bond_link_ops = {
43477 .kind = "bond",
43478 .priv_size = sizeof(struct bonding),
43479 .setup = bond_setup,
43480@@ -4636,8 +4636,8 @@ static void __exit bonding_exit(void)
43481
43482 bond_destroy_debugfs();
43483
43484- rtnl_link_unregister(&bond_link_ops);
43485 unregister_pernet_subsys(&bond_net_ops);
43486+ rtnl_link_unregister(&bond_link_ops);
43487
43488 #ifdef CONFIG_NET_POLL_CONTROLLER
43489 /*
43490diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43491index f92f001..0b2f9bf 100644
43492--- a/drivers/net/ethernet/8390/ax88796.c
43493+++ b/drivers/net/ethernet/8390/ax88796.c
43494@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43495 if (ax->plat->reg_offsets)
43496 ei_local->reg_offset = ax->plat->reg_offsets;
43497 else {
43498+ resource_size_t _mem_size = mem_size;
43499+ do_div(_mem_size, 0x18);
43500 ei_local->reg_offset = ax->reg_offsets;
43501 for (ret = 0; ret < 0x18; ret++)
43502- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43503+ ax->reg_offsets[ret] = _mem_size * ret;
43504 }
43505
43506 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43507diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43508index da8fcaa..f4b5d3b 100644
43509--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43510+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43511@@ -1138,7 +1138,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43512 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43513 {
43514 /* RX_MODE controlling object */
43515- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43516+ bnx2x_init_rx_mode_obj(bp);
43517
43518 /* multicast configuration controlling object */
43519 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43520diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43521index 9fbeee5..5e3e37a 100644
43522--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43523+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43524@@ -2590,15 +2590,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43525 return rc;
43526 }
43527
43528-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43529- struct bnx2x_rx_mode_obj *o)
43530+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43531 {
43532 if (CHIP_IS_E1x(bp)) {
43533- o->wait_comp = bnx2x_empty_rx_mode_wait;
43534- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43535+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43536+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43537 } else {
43538- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43539- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43540+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43541+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43542 }
43543 }
43544
43545diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43546index 658f4e3..15074a6 100644
43547--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43548+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43549@@ -1325,8 +1325,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43550
43551 /********************* RX MODE ****************/
43552
43553-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43554- struct bnx2x_rx_mode_obj *o);
43555+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43556
43557 /**
43558 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43559diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43560index 7025780..e55a71c 100644
43561--- a/drivers/net/ethernet/broadcom/tg3.h
43562+++ b/drivers/net/ethernet/broadcom/tg3.h
43563@@ -147,6 +147,7 @@
43564 #define CHIPREV_ID_5750_A0 0x4000
43565 #define CHIPREV_ID_5750_A1 0x4001
43566 #define CHIPREV_ID_5750_A3 0x4003
43567+#define CHIPREV_ID_5750_C1 0x4201
43568 #define CHIPREV_ID_5750_C2 0x4202
43569 #define CHIPREV_ID_5752_A0_HW 0x5000
43570 #define CHIPREV_ID_5752_A0 0x6000
43571diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43572index 8cffcdf..aadf043 100644
43573--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43574+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43575@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
43576 */
43577 struct l2t_skb_cb {
43578 arp_failure_handler_func arp_failure_handler;
43579-};
43580+} __no_const;
43581
43582 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
43583
43584diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
43585index c73cabd..cd278b1 100644
43586--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
43587+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
43588@@ -2186,7 +2186,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
43589
43590 int i;
43591 struct adapter *ap = netdev2adap(dev);
43592- static const unsigned int *reg_ranges;
43593+ const unsigned int *reg_ranges;
43594 int arr_size = 0, buf_size = 0;
43595
43596 if (is_t4(ap->chip)) {
43597diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
43598index 263b92c..f05134b 100644
43599--- a/drivers/net/ethernet/dec/tulip/de4x5.c
43600+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
43601@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43602 for (i=0; i<ETH_ALEN; i++) {
43603 tmp.addr[i] = dev->dev_addr[i];
43604 }
43605- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43606+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43607 break;
43608
43609 case DE4X5_SET_HWADDR: /* Set the hardware address */
43610@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43611 spin_lock_irqsave(&lp->lock, flags);
43612 memcpy(&statbuf, &lp->pktStats, ioc->len);
43613 spin_unlock_irqrestore(&lp->lock, flags);
43614- if (copy_to_user(ioc->data, &statbuf, ioc->len))
43615+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
43616 return -EFAULT;
43617 break;
43618 }
43619diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
43620index 2c38cc4..0323f6e 100644
43621--- a/drivers/net/ethernet/emulex/benet/be_main.c
43622+++ b/drivers/net/ethernet/emulex/benet/be_main.c
43623@@ -470,7 +470,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
43624
43625 if (wrapped)
43626 newacc += 65536;
43627- ACCESS_ONCE(*acc) = newacc;
43628+ ACCESS_ONCE_RW(*acc) = newacc;
43629 }
43630
43631 static void populate_erx_stats(struct be_adapter *adapter,
43632diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
43633index 212f44b..fb69959 100644
43634--- a/drivers/net/ethernet/faraday/ftgmac100.c
43635+++ b/drivers/net/ethernet/faraday/ftgmac100.c
43636@@ -31,6 +31,8 @@
43637 #include <linux/netdevice.h>
43638 #include <linux/phy.h>
43639 #include <linux/platform_device.h>
43640+#include <linux/interrupt.h>
43641+#include <linux/irqreturn.h>
43642 #include <net/ip.h>
43643
43644 #include "ftgmac100.h"
43645diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
43646index 8be5b40..081bc1b 100644
43647--- a/drivers/net/ethernet/faraday/ftmac100.c
43648+++ b/drivers/net/ethernet/faraday/ftmac100.c
43649@@ -31,6 +31,8 @@
43650 #include <linux/module.h>
43651 #include <linux/netdevice.h>
43652 #include <linux/platform_device.h>
43653+#include <linux/interrupt.h>
43654+#include <linux/irqreturn.h>
43655
43656 #include "ftmac100.h"
43657
43658diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43659index 5184e2a..acb28c3 100644
43660--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43661+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43662@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
43663 }
43664
43665 /* update the base incval used to calculate frequency adjustment */
43666- ACCESS_ONCE(adapter->base_incval) = incval;
43667+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
43668 smp_mb();
43669
43670 /* need lock to prevent incorrect read while modifying cyclecounter */
43671diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43672index fbe5363..266b4e3 100644
43673--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
43674+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43675@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43676 struct __vxge_hw_fifo *fifo;
43677 struct vxge_hw_fifo_config *config;
43678 u32 txdl_size, txdl_per_memblock;
43679- struct vxge_hw_mempool_cbs fifo_mp_callback;
43680+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
43681+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
43682+ };
43683+
43684 struct __vxge_hw_virtualpath *vpath;
43685
43686 if ((vp == NULL) || (attr == NULL)) {
43687@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43688 goto exit;
43689 }
43690
43691- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
43692-
43693 fifo->mempool =
43694 __vxge_hw_mempool_create(vpath->hldev,
43695 fifo->config->memblock_size,
43696diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43697index f09e787..f3916a8 100644
43698--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43699+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43700@@ -2055,7 +2055,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
43701
43702 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
43703 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
43704- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43705+ pax_open_kernel();
43706+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43707+ pax_close_kernel();
43708 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43709 } else {
43710 return -EIO;
43711diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43712index 0248a4c..9648d96 100644
43713--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43714+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43715@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
43716 case QLCNIC_NON_PRIV_FUNC:
43717 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
43718 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43719- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43720+ pax_open_kernel();
43721+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43722+ pax_close_kernel();
43723 break;
43724 case QLCNIC_PRIV_FUNC:
43725 ahw->op_mode = QLCNIC_PRIV_FUNC;
43726 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
43727- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43728+ pax_open_kernel();
43729+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43730+ pax_close_kernel();
43731 break;
43732 case QLCNIC_MGMT_FUNC:
43733 ahw->op_mode = QLCNIC_MGMT_FUNC;
43734 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43735- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43736+ pax_open_kernel();
43737+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43738+ pax_close_kernel();
43739 break;
43740 default:
43741 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
43742diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
43743index 1551360..ed6510f 100644
43744--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
43745+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
43746@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
43747 struct qlcnic_dump_entry *entry;
43748 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
43749 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
43750- static const struct qlcnic_dump_operations *fw_dump_ops;
43751+ const struct qlcnic_dump_operations *fw_dump_ops;
43752 struct device *dev = &adapter->pdev->dev;
43753 struct qlcnic_hardware_context *ahw;
43754 void *temp_buffer;
43755diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
43756index 3397cee..101f8fa 100644
43757--- a/drivers/net/ethernet/realtek/r8169.c
43758+++ b/drivers/net/ethernet/realtek/r8169.c
43759@@ -759,22 +759,22 @@ struct rtl8169_private {
43760 struct mdio_ops {
43761 void (*write)(struct rtl8169_private *, int, int);
43762 int (*read)(struct rtl8169_private *, int);
43763- } mdio_ops;
43764+ } __no_const mdio_ops;
43765
43766 struct pll_power_ops {
43767 void (*down)(struct rtl8169_private *);
43768 void (*up)(struct rtl8169_private *);
43769- } pll_power_ops;
43770+ } __no_const pll_power_ops;
43771
43772 struct jumbo_ops {
43773 void (*enable)(struct rtl8169_private *);
43774 void (*disable)(struct rtl8169_private *);
43775- } jumbo_ops;
43776+ } __no_const jumbo_ops;
43777
43778 struct csi_ops {
43779 void (*write)(struct rtl8169_private *, int, int);
43780 u32 (*read)(struct rtl8169_private *, int);
43781- } csi_ops;
43782+ } __no_const csi_ops;
43783
43784 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
43785 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
43786diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
43787index 03acf57..e1251ff 100644
43788--- a/drivers/net/ethernet/sfc/ptp.c
43789+++ b/drivers/net/ethernet/sfc/ptp.c
43790@@ -539,7 +539,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
43791 ptp->start.dma_addr);
43792
43793 /* Clear flag that signals MC ready */
43794- ACCESS_ONCE(*start) = 0;
43795+ ACCESS_ONCE_RW(*start) = 0;
43796 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
43797 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
43798 EFX_BUG_ON_PARANOID(rc);
43799diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
43800index 50617c5..b13724c 100644
43801--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
43802+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
43803@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
43804
43805 writel(value, ioaddr + MMC_CNTRL);
43806
43807- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
43808- MMC_CNTRL, value);
43809+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
43810+// MMC_CNTRL, value);
43811 }
43812
43813 /* To mask all all interrupts.*/
43814diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
43815index e6fe0d8..2b7d752 100644
43816--- a/drivers/net/hyperv/hyperv_net.h
43817+++ b/drivers/net/hyperv/hyperv_net.h
43818@@ -101,7 +101,7 @@ struct rndis_device {
43819
43820 enum rndis_device_state state;
43821 bool link_state;
43822- atomic_t new_req_id;
43823+ atomic_unchecked_t new_req_id;
43824
43825 spinlock_t request_lock;
43826 struct list_head req_list;
43827diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
43828index 0775f0a..d4fb316 100644
43829--- a/drivers/net/hyperv/rndis_filter.c
43830+++ b/drivers/net/hyperv/rndis_filter.c
43831@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
43832 * template
43833 */
43834 set = &rndis_msg->msg.set_req;
43835- set->req_id = atomic_inc_return(&dev->new_req_id);
43836+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
43837
43838 /* Add to the request list */
43839 spin_lock_irqsave(&dev->request_lock, flags);
43840@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
43841
43842 /* Setup the rndis set */
43843 halt = &request->request_msg.msg.halt_req;
43844- halt->req_id = atomic_inc_return(&dev->new_req_id);
43845+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
43846
43847 /* Ignore return since this msg is optional. */
43848 rndis_filter_send_request(dev, request);
43849diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
43850index bf0d55e..82bcfbd1 100644
43851--- a/drivers/net/ieee802154/fakehard.c
43852+++ b/drivers/net/ieee802154/fakehard.c
43853@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
43854 phy->transmit_power = 0xbf;
43855
43856 dev->netdev_ops = &fake_ops;
43857- dev->ml_priv = &fake_mlme;
43858+ dev->ml_priv = (void *)&fake_mlme;
43859
43860 priv = netdev_priv(dev);
43861 priv->phy = phy;
43862diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
43863index 9bf46bd..bfdaa84 100644
43864--- a/drivers/net/macvlan.c
43865+++ b/drivers/net/macvlan.c
43866@@ -939,13 +939,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
43867 int macvlan_link_register(struct rtnl_link_ops *ops)
43868 {
43869 /* common fields */
43870- ops->priv_size = sizeof(struct macvlan_dev);
43871- ops->validate = macvlan_validate;
43872- ops->maxtype = IFLA_MACVLAN_MAX;
43873- ops->policy = macvlan_policy;
43874- ops->changelink = macvlan_changelink;
43875- ops->get_size = macvlan_get_size;
43876- ops->fill_info = macvlan_fill_info;
43877+ pax_open_kernel();
43878+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
43879+ *(void **)&ops->validate = macvlan_validate;
43880+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
43881+ *(const void **)&ops->policy = macvlan_policy;
43882+ *(void **)&ops->changelink = macvlan_changelink;
43883+ *(void **)&ops->get_size = macvlan_get_size;
43884+ *(void **)&ops->fill_info = macvlan_fill_info;
43885+ pax_close_kernel();
43886
43887 return rtnl_link_register(ops);
43888 };
43889@@ -1001,7 +1003,7 @@ static int macvlan_device_event(struct notifier_block *unused,
43890 return NOTIFY_DONE;
43891 }
43892
43893-static struct notifier_block macvlan_notifier_block __read_mostly = {
43894+static struct notifier_block macvlan_notifier_block = {
43895 .notifier_call = macvlan_device_event,
43896 };
43897
43898diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
43899index 9dccb1e..19fd4c9 100644
43900--- a/drivers/net/macvtap.c
43901+++ b/drivers/net/macvtap.c
43902@@ -1183,7 +1183,7 @@ static int macvtap_device_event(struct notifier_block *unused,
43903 return NOTIFY_DONE;
43904 }
43905
43906-static struct notifier_block macvtap_notifier_block __read_mostly = {
43907+static struct notifier_block macvtap_notifier_block = {
43908 .notifier_call = macvtap_device_event,
43909 };
43910
43911diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
43912index daec9b0..6428fcb 100644
43913--- a/drivers/net/phy/mdio-bitbang.c
43914+++ b/drivers/net/phy/mdio-bitbang.c
43915@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
43916 struct mdiobb_ctrl *ctrl = bus->priv;
43917
43918 module_put(ctrl->ops->owner);
43919+ mdiobus_unregister(bus);
43920 mdiobus_free(bus);
43921 }
43922 EXPORT_SYMBOL(free_mdio_bitbang);
43923diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
43924index 72ff14b..11d442d 100644
43925--- a/drivers/net/ppp/ppp_generic.c
43926+++ b/drivers/net/ppp/ppp_generic.c
43927@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43928 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
43929 struct ppp_stats stats;
43930 struct ppp_comp_stats cstats;
43931- char *vers;
43932
43933 switch (cmd) {
43934 case SIOCGPPPSTATS:
43935@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43936 break;
43937
43938 case SIOCGPPPVER:
43939- vers = PPP_VERSION;
43940- if (copy_to_user(addr, vers, strlen(vers) + 1))
43941+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
43942 break;
43943 err = 0;
43944 break;
43945diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
43946index 1252d9c..80e660b 100644
43947--- a/drivers/net/slip/slhc.c
43948+++ b/drivers/net/slip/slhc.c
43949@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
43950 register struct tcphdr *thp;
43951 register struct iphdr *ip;
43952 register struct cstate *cs;
43953- int len, hdrlen;
43954+ long len, hdrlen;
43955 unsigned char *cp = icp;
43956
43957 /* We've got a compressed packet; read the change byte */
43958diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
43959index 50e43e6..e1a5807 100644
43960--- a/drivers/net/team/team.c
43961+++ b/drivers/net/team/team.c
43962@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
43963 return NOTIFY_DONE;
43964 }
43965
43966-static struct notifier_block team_notifier_block __read_mostly = {
43967+static struct notifier_block team_notifier_block = {
43968 .notifier_call = team_device_event,
43969 };
43970
43971diff --git a/drivers/net/tun.c b/drivers/net/tun.c
43972index 7cb105c..11214ff 100644
43973--- a/drivers/net/tun.c
43974+++ b/drivers/net/tun.c
43975@@ -1826,7 +1826,7 @@ unlock:
43976 }
43977
43978 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
43979- unsigned long arg, int ifreq_len)
43980+ unsigned long arg, size_t ifreq_len)
43981 {
43982 struct tun_file *tfile = file->private_data;
43983 struct tun_struct *tun;
43984@@ -1839,6 +1839,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
43985 unsigned int ifindex;
43986 int ret;
43987
43988+ if (ifreq_len > sizeof ifr)
43989+ return -EFAULT;
43990+
43991 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
43992 if (copy_from_user(&ifr, argp, ifreq_len))
43993 return -EFAULT;
43994diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
43995index 86292e6..8d34433 100644
43996--- a/drivers/net/usb/hso.c
43997+++ b/drivers/net/usb/hso.c
43998@@ -71,7 +71,7 @@
43999 #include <asm/byteorder.h>
44000 #include <linux/serial_core.h>
44001 #include <linux/serial.h>
44002-
44003+#include <asm/local.h>
44004
44005 #define MOD_AUTHOR "Option Wireless"
44006 #define MOD_DESCRIPTION "USB High Speed Option driver"
44007@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44008 struct urb *urb;
44009
44010 urb = serial->rx_urb[0];
44011- if (serial->port.count > 0) {
44012+ if (atomic_read(&serial->port.count) > 0) {
44013 count = put_rxbuf_data(urb, serial);
44014 if (count == -1)
44015 return;
44016@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44017 DUMP1(urb->transfer_buffer, urb->actual_length);
44018
44019 /* Anyone listening? */
44020- if (serial->port.count == 0)
44021+ if (atomic_read(&serial->port.count) == 0)
44022 return;
44023
44024 if (status == 0) {
44025@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44026 tty_port_tty_set(&serial->port, tty);
44027
44028 /* check for port already opened, if not set the termios */
44029- serial->port.count++;
44030- if (serial->port.count == 1) {
44031+ if (atomic_inc_return(&serial->port.count) == 1) {
44032 serial->rx_state = RX_IDLE;
44033 /* Force default termio settings */
44034 _hso_serial_set_termios(tty, NULL);
44035@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44036 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44037 if (result) {
44038 hso_stop_serial_device(serial->parent);
44039- serial->port.count--;
44040+ atomic_dec(&serial->port.count);
44041 kref_put(&serial->parent->ref, hso_serial_ref_free);
44042 }
44043 } else {
44044@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44045
44046 /* reset the rts and dtr */
44047 /* do the actual close */
44048- serial->port.count--;
44049+ atomic_dec(&serial->port.count);
44050
44051- if (serial->port.count <= 0) {
44052- serial->port.count = 0;
44053+ if (atomic_read(&serial->port.count) <= 0) {
44054+ atomic_set(&serial->port.count, 0);
44055 tty_port_tty_set(&serial->port, NULL);
44056 if (!usb_gone)
44057 hso_stop_serial_device(serial->parent);
44058@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44059
44060 /* the actual setup */
44061 spin_lock_irqsave(&serial->serial_lock, flags);
44062- if (serial->port.count)
44063+ if (atomic_read(&serial->port.count))
44064 _hso_serial_set_termios(tty, old);
44065 else
44066 tty->termios = *old;
44067@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44068 D1("Pending read interrupt on port %d\n", i);
44069 spin_lock(&serial->serial_lock);
44070 if (serial->rx_state == RX_IDLE &&
44071- serial->port.count > 0) {
44072+ atomic_read(&serial->port.count) > 0) {
44073 /* Setup and send a ctrl req read on
44074 * port i */
44075 if (!serial->rx_urb_filled[0]) {
44076@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44077 /* Start all serial ports */
44078 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44079 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44080- if (dev2ser(serial_table[i])->port.count) {
44081+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44082 result =
44083 hso_start_serial_device(serial_table[i], GFP_NOIO);
44084 hso_kick_transmit(dev2ser(serial_table[i]));
44085diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44086index a79e9d3..78cd4fa 100644
44087--- a/drivers/net/usb/sierra_net.c
44088+++ b/drivers/net/usb/sierra_net.c
44089@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44090 /* atomic counter partially included in MAC address to make sure 2 devices
44091 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44092 */
44093-static atomic_t iface_counter = ATOMIC_INIT(0);
44094+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44095
44096 /*
44097 * SYNC Timer Delay definition used to set the expiry time
44098@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44099 dev->net->netdev_ops = &sierra_net_device_ops;
44100
44101 /* change MAC addr to include, ifacenum, and to be unique */
44102- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44103+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44104 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44105
44106 /* we will have to manufacture ethernet headers, prepare template */
44107diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44108index 2ef5b62..6fa0ec3 100644
44109--- a/drivers/net/vxlan.c
44110+++ b/drivers/net/vxlan.c
44111@@ -2615,7 +2615,7 @@ nla_put_failure:
44112 return -EMSGSIZE;
44113 }
44114
44115-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44116+static struct rtnl_link_ops vxlan_link_ops = {
44117 .kind = "vxlan",
44118 .maxtype = IFLA_VXLAN_MAX,
44119 .policy = vxlan_policy,
44120diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44121index 0b60295..b8bfa5b 100644
44122--- a/drivers/net/wimax/i2400m/rx.c
44123+++ b/drivers/net/wimax/i2400m/rx.c
44124@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44125 if (i2400m->rx_roq == NULL)
44126 goto error_roq_alloc;
44127
44128- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44129+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44130 GFP_KERNEL);
44131 if (rd == NULL) {
44132 result = -ENOMEM;
44133diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
44134index 7fe1964..7016de0 100644
44135--- a/drivers/net/wireless/airo.c
44136+++ b/drivers/net/wireless/airo.c
44137@@ -7844,7 +7844,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
44138 struct airo_info *ai = dev->ml_priv;
44139 int ridcode;
44140 int enabled;
44141- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44142+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44143 unsigned char *iobuf;
44144
44145 /* Only super-user can write RIDs */
44146diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44147index 34c8a33..3261fdc 100644
44148--- a/drivers/net/wireless/at76c50x-usb.c
44149+++ b/drivers/net/wireless/at76c50x-usb.c
44150@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44151 }
44152
44153 /* Convert timeout from the DFU status to jiffies */
44154-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44155+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44156 {
44157 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44158 | (s->poll_timeout[1] << 8)
44159diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44160index ef3329e..c28ff5d 100644
44161--- a/drivers/net/wireless/ath/ath10k/htc.c
44162+++ b/drivers/net/wireless/ath/ath10k/htc.c
44163@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44164 /* registered target arrival callback from the HIF layer */
44165 int ath10k_htc_init(struct ath10k *ar)
44166 {
44167- struct ath10k_hif_cb htc_callbacks;
44168+ static struct ath10k_hif_cb htc_callbacks = {
44169+ .rx_completion = ath10k_htc_rx_completion_handler,
44170+ .tx_completion = ath10k_htc_tx_completion_handler,
44171+ };
44172 struct ath10k_htc_ep *ep = NULL;
44173 struct ath10k_htc *htc = &ar->htc;
44174
44175@@ -973,8 +976,6 @@ int ath10k_htc_init(struct ath10k *ar)
44176 ath10k_htc_reset_endpoint_states(htc);
44177
44178 /* setup HIF layer callbacks */
44179- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44180- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44181 htc->ar = ar;
44182
44183 /* Get HIF default pipe for HTC message exchange */
44184diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
44185index e1dd8c7..9f91b3f 100644
44186--- a/drivers/net/wireless/ath/ath10k/htc.h
44187+++ b/drivers/net/wireless/ath/ath10k/htc.h
44188@@ -271,12 +271,12 @@ enum ath10k_htc_ep_id {
44189
44190 struct ath10k_htc_ops {
44191 void (*target_send_suspend_complete)(struct ath10k *ar);
44192-};
44193+} __no_const;
44194
44195 struct ath10k_htc_ep_ops {
44196 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
44197 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
44198-};
44199+} __no_const;
44200
44201 /* service connection information */
44202 struct ath10k_htc_svc_conn_req {
44203diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44204index 8d78253..bebbb68 100644
44205--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44206+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44207@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44208 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44209 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44210
44211- ACCESS_ONCE(ads->ds_link) = i->link;
44212- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44213+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44214+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44215
44216 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44217 ctl6 = SM(i->keytype, AR_EncrType);
44218@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44219
44220 if ((i->is_first || i->is_last) &&
44221 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44222- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44223+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44224 | set11nTries(i->rates, 1)
44225 | set11nTries(i->rates, 2)
44226 | set11nTries(i->rates, 3)
44227 | (i->dur_update ? AR_DurUpdateEna : 0)
44228 | SM(0, AR_BurstDur);
44229
44230- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44231+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44232 | set11nRate(i->rates, 1)
44233 | set11nRate(i->rates, 2)
44234 | set11nRate(i->rates, 3);
44235 } else {
44236- ACCESS_ONCE(ads->ds_ctl2) = 0;
44237- ACCESS_ONCE(ads->ds_ctl3) = 0;
44238+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44239+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44240 }
44241
44242 if (!i->is_first) {
44243- ACCESS_ONCE(ads->ds_ctl0) = 0;
44244- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44245- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44246+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44247+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44248+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44249 return;
44250 }
44251
44252@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44253 break;
44254 }
44255
44256- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44257+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44258 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44259 | SM(i->txpower, AR_XmitPower)
44260 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44261@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44262 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44263 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44264
44265- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44266- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44267+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44268+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44269
44270 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44271 return;
44272
44273- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44274+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44275 | set11nPktDurRTSCTS(i->rates, 1);
44276
44277- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44278+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44279 | set11nPktDurRTSCTS(i->rates, 3);
44280
44281- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44282+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44283 | set11nRateFlags(i->rates, 1)
44284 | set11nRateFlags(i->rates, 2)
44285 | set11nRateFlags(i->rates, 3)
44286diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44287index f6c5c1b..6058354 100644
44288--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44289+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44290@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44291 (i->qcu << AR_TxQcuNum_S) | desc_len;
44292
44293 checksum += val;
44294- ACCESS_ONCE(ads->info) = val;
44295+ ACCESS_ONCE_RW(ads->info) = val;
44296
44297 checksum += i->link;
44298- ACCESS_ONCE(ads->link) = i->link;
44299+ ACCESS_ONCE_RW(ads->link) = i->link;
44300
44301 checksum += i->buf_addr[0];
44302- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44303+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44304 checksum += i->buf_addr[1];
44305- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44306+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44307 checksum += i->buf_addr[2];
44308- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44309+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44310 checksum += i->buf_addr[3];
44311- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44312+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44313
44314 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44315- ACCESS_ONCE(ads->ctl3) = val;
44316+ ACCESS_ONCE_RW(ads->ctl3) = val;
44317 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44318- ACCESS_ONCE(ads->ctl5) = val;
44319+ ACCESS_ONCE_RW(ads->ctl5) = val;
44320 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44321- ACCESS_ONCE(ads->ctl7) = val;
44322+ ACCESS_ONCE_RW(ads->ctl7) = val;
44323 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44324- ACCESS_ONCE(ads->ctl9) = val;
44325+ ACCESS_ONCE_RW(ads->ctl9) = val;
44326
44327 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44328- ACCESS_ONCE(ads->ctl10) = checksum;
44329+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44330
44331 if (i->is_first || i->is_last) {
44332- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44333+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44334 | set11nTries(i->rates, 1)
44335 | set11nTries(i->rates, 2)
44336 | set11nTries(i->rates, 3)
44337 | (i->dur_update ? AR_DurUpdateEna : 0)
44338 | SM(0, AR_BurstDur);
44339
44340- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44341+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44342 | set11nRate(i->rates, 1)
44343 | set11nRate(i->rates, 2)
44344 | set11nRate(i->rates, 3);
44345 } else {
44346- ACCESS_ONCE(ads->ctl13) = 0;
44347- ACCESS_ONCE(ads->ctl14) = 0;
44348+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44349+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44350 }
44351
44352 ads->ctl20 = 0;
44353@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44354
44355 ctl17 = SM(i->keytype, AR_EncrType);
44356 if (!i->is_first) {
44357- ACCESS_ONCE(ads->ctl11) = 0;
44358- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44359- ACCESS_ONCE(ads->ctl15) = 0;
44360- ACCESS_ONCE(ads->ctl16) = 0;
44361- ACCESS_ONCE(ads->ctl17) = ctl17;
44362- ACCESS_ONCE(ads->ctl18) = 0;
44363- ACCESS_ONCE(ads->ctl19) = 0;
44364+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44365+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44366+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44367+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44368+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44369+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44370+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44371 return;
44372 }
44373
44374- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44375+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44376 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44377 | SM(i->txpower, AR_XmitPower)
44378 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44379@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44380 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44381 ctl12 |= SM(val, AR_PAPRDChainMask);
44382
44383- ACCESS_ONCE(ads->ctl12) = ctl12;
44384- ACCESS_ONCE(ads->ctl17) = ctl17;
44385+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44386+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44387
44388- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44389+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44390 | set11nPktDurRTSCTS(i->rates, 1);
44391
44392- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44393+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44394 | set11nPktDurRTSCTS(i->rates, 3);
44395
44396- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44397+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44398 | set11nRateFlags(i->rates, 1)
44399 | set11nRateFlags(i->rates, 2)
44400 | set11nRateFlags(i->rates, 3)
44401 | SM(i->rtscts_rate, AR_RTSCTSRate);
44402
44403- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44404+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44405 }
44406
44407 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44408diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44409index 69a907b..91e071c 100644
44410--- a/drivers/net/wireless/ath/ath9k/hw.h
44411+++ b/drivers/net/wireless/ath/ath9k/hw.h
44412@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
44413
44414 /* ANI */
44415 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44416-};
44417+} __no_const;
44418
44419 /**
44420 * struct ath_spec_scan - parameters for Atheros spectral scan
44421@@ -729,7 +729,7 @@ struct ath_hw_ops {
44422 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
44423 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
44424 #endif
44425-};
44426+} __no_const;
44427
44428 struct ath_nf_limits {
44429 s16 max;
44430diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
44431index 92190da..f3a4c4c 100644
44432--- a/drivers/net/wireless/b43/phy_lp.c
44433+++ b/drivers/net/wireless/b43/phy_lp.c
44434@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
44435 {
44436 struct ssb_bus *bus = dev->dev->sdev->bus;
44437
44438- static const struct b206x_channel *chandata = NULL;
44439+ const struct b206x_channel *chandata = NULL;
44440 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
44441 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
44442 u16 old_comm15, scale;
44443diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44444index 9581d07..84f6a76 100644
44445--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44446+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44447@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44448 */
44449 if (il3945_mod_params.disable_hw_scan) {
44450 D_INFO("Disabling hw_scan\n");
44451- il3945_mac_ops.hw_scan = NULL;
44452+ pax_open_kernel();
44453+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44454+ pax_close_kernel();
44455 }
44456
44457 D_INFO("*** LOAD DRIVER ***\n");
44458diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44459index d94f8ab..5b568c8 100644
44460--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44461+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44462@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44463 {
44464 struct iwl_priv *priv = file->private_data;
44465 char buf[64];
44466- int buf_size;
44467+ size_t buf_size;
44468 u32 offset, len;
44469
44470 memset(buf, 0, sizeof(buf));
44471@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44472 struct iwl_priv *priv = file->private_data;
44473
44474 char buf[8];
44475- int buf_size;
44476+ size_t buf_size;
44477 u32 reset_flag;
44478
44479 memset(buf, 0, sizeof(buf));
44480@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44481 {
44482 struct iwl_priv *priv = file->private_data;
44483 char buf[8];
44484- int buf_size;
44485+ size_t buf_size;
44486 int ht40;
44487
44488 memset(buf, 0, sizeof(buf));
44489@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44490 {
44491 struct iwl_priv *priv = file->private_data;
44492 char buf[8];
44493- int buf_size;
44494+ size_t buf_size;
44495 int value;
44496
44497 memset(buf, 0, sizeof(buf));
44498@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44499 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44500 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44501
44502-static const char *fmt_value = " %-30s %10u\n";
44503-static const char *fmt_hex = " %-30s 0x%02X\n";
44504-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44505-static const char *fmt_header =
44506+static const char fmt_value[] = " %-30s %10u\n";
44507+static const char fmt_hex[] = " %-30s 0x%02X\n";
44508+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44509+static const char fmt_header[] =
44510 "%-32s current cumulative delta max\n";
44511
44512 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44513@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44514 {
44515 struct iwl_priv *priv = file->private_data;
44516 char buf[8];
44517- int buf_size;
44518+ size_t buf_size;
44519 int clear;
44520
44521 memset(buf, 0, sizeof(buf));
44522@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44523 {
44524 struct iwl_priv *priv = file->private_data;
44525 char buf[8];
44526- int buf_size;
44527+ size_t buf_size;
44528 int trace;
44529
44530 memset(buf, 0, sizeof(buf));
44531@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44532 {
44533 struct iwl_priv *priv = file->private_data;
44534 char buf[8];
44535- int buf_size;
44536+ size_t buf_size;
44537 int missed;
44538
44539 memset(buf, 0, sizeof(buf));
44540@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44541
44542 struct iwl_priv *priv = file->private_data;
44543 char buf[8];
44544- int buf_size;
44545+ size_t buf_size;
44546 int plcp;
44547
44548 memset(buf, 0, sizeof(buf));
44549@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44550
44551 struct iwl_priv *priv = file->private_data;
44552 char buf[8];
44553- int buf_size;
44554+ size_t buf_size;
44555 int flush;
44556
44557 memset(buf, 0, sizeof(buf));
44558@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44559
44560 struct iwl_priv *priv = file->private_data;
44561 char buf[8];
44562- int buf_size;
44563+ size_t buf_size;
44564 int rts;
44565
44566 if (!priv->cfg->ht_params)
44567@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44568 {
44569 struct iwl_priv *priv = file->private_data;
44570 char buf[8];
44571- int buf_size;
44572+ size_t buf_size;
44573
44574 memset(buf, 0, sizeof(buf));
44575 buf_size = min(count, sizeof(buf) - 1);
44576@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44577 struct iwl_priv *priv = file->private_data;
44578 u32 event_log_flag;
44579 char buf[8];
44580- int buf_size;
44581+ size_t buf_size;
44582
44583 /* check that the interface is up */
44584 if (!iwl_is_ready(priv))
44585@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44586 struct iwl_priv *priv = file->private_data;
44587 char buf[8];
44588 u32 calib_disabled;
44589- int buf_size;
44590+ size_t buf_size;
44591
44592 memset(buf, 0, sizeof(buf));
44593 buf_size = min(count, sizeof(buf) - 1);
44594diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44595index 7aad766..06addb4 100644
44596--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44597+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44598@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44599 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44600 {
44601 struct iwl_nvm_data *data = priv->nvm_data;
44602- char *debug_msg;
44603+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44604
44605 if (data->sku_cap_11n_enable &&
44606 !priv->cfg->ht_params) {
44607@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44608 return -EINVAL;
44609 }
44610
44611- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44612 IWL_DEBUG_INFO(priv, debug_msg,
44613 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44614 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
44615diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
44616index c3f904d..4cadf83 100644
44617--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
44618+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
44619@@ -1252,7 +1252,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
44620 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
44621
44622 char buf[8];
44623- int buf_size;
44624+ size_t buf_size;
44625 u32 reset_flag;
44626
44627 memset(buf, 0, sizeof(buf));
44628@@ -1273,7 +1273,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
44629 {
44630 struct iwl_trans *trans = file->private_data;
44631 char buf[8];
44632- int buf_size;
44633+ size_t buf_size;
44634 int csr;
44635
44636 memset(buf, 0, sizeof(buf));
44637diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
44638index 2cd3f54..e936f90 100644
44639--- a/drivers/net/wireless/mac80211_hwsim.c
44640+++ b/drivers/net/wireless/mac80211_hwsim.c
44641@@ -2196,25 +2196,19 @@ static int __init init_mac80211_hwsim(void)
44642
44643 if (channels > 1) {
44644 hwsim_if_comb.num_different_channels = channels;
44645- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44646- mac80211_hwsim_ops.cancel_hw_scan =
44647- mac80211_hwsim_cancel_hw_scan;
44648- mac80211_hwsim_ops.sw_scan_start = NULL;
44649- mac80211_hwsim_ops.sw_scan_complete = NULL;
44650- mac80211_hwsim_ops.remain_on_channel =
44651- mac80211_hwsim_roc;
44652- mac80211_hwsim_ops.cancel_remain_on_channel =
44653- mac80211_hwsim_croc;
44654- mac80211_hwsim_ops.add_chanctx =
44655- mac80211_hwsim_add_chanctx;
44656- mac80211_hwsim_ops.remove_chanctx =
44657- mac80211_hwsim_remove_chanctx;
44658- mac80211_hwsim_ops.change_chanctx =
44659- mac80211_hwsim_change_chanctx;
44660- mac80211_hwsim_ops.assign_vif_chanctx =
44661- mac80211_hwsim_assign_vif_chanctx;
44662- mac80211_hwsim_ops.unassign_vif_chanctx =
44663- mac80211_hwsim_unassign_vif_chanctx;
44664+ pax_open_kernel();
44665+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44666+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
44667+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
44668+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
44669+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
44670+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
44671+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
44672+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
44673+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
44674+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
44675+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
44676+ pax_close_kernel();
44677 }
44678
44679 spin_lock_init(&hwsim_radio_lock);
44680diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
44681index 8169a85..7fa3b47 100644
44682--- a/drivers/net/wireless/rndis_wlan.c
44683+++ b/drivers/net/wireless/rndis_wlan.c
44684@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
44685
44686 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
44687
44688- if (rts_threshold < 0 || rts_threshold > 2347)
44689+ if (rts_threshold > 2347)
44690 rts_threshold = 2347;
44691
44692 tmp = cpu_to_le32(rts_threshold);
44693diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
44694index fe4c572..99dedfa 100644
44695--- a/drivers/net/wireless/rt2x00/rt2x00.h
44696+++ b/drivers/net/wireless/rt2x00/rt2x00.h
44697@@ -387,7 +387,7 @@ struct rt2x00_intf {
44698 * for hardware which doesn't support hardware
44699 * sequence counting.
44700 */
44701- atomic_t seqno;
44702+ atomic_unchecked_t seqno;
44703 };
44704
44705 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
44706diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
44707index 66a2db8..70cad04 100644
44708--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
44709+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
44710@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
44711 * sequence counter given by mac80211.
44712 */
44713 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
44714- seqno = atomic_add_return(0x10, &intf->seqno);
44715+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
44716 else
44717- seqno = atomic_read(&intf->seqno);
44718+ seqno = atomic_read_unchecked(&intf->seqno);
44719
44720 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
44721 hdr->seq_ctrl |= cpu_to_le16(seqno);
44722diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
44723index e2b3d9c..67a5184 100644
44724--- a/drivers/net/wireless/ti/wl1251/sdio.c
44725+++ b/drivers/net/wireless/ti/wl1251/sdio.c
44726@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
44727
44728 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
44729
44730- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44731- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44732+ pax_open_kernel();
44733+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44734+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44735+ pax_close_kernel();
44736
44737 wl1251_info("using dedicated interrupt line");
44738 } else {
44739- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44740- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44741+ pax_open_kernel();
44742+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44743+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44744+ pax_close_kernel();
44745
44746 wl1251_info("using SDIO interrupt");
44747 }
44748diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
44749index 1c627da..69f7d17 100644
44750--- a/drivers/net/wireless/ti/wl12xx/main.c
44751+++ b/drivers/net/wireless/ti/wl12xx/main.c
44752@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44753 sizeof(wl->conf.mem));
44754
44755 /* read data preparation is only needed by wl127x */
44756- wl->ops->prepare_read = wl127x_prepare_read;
44757+ pax_open_kernel();
44758+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44759+ pax_close_kernel();
44760
44761 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44762 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44763@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44764 sizeof(wl->conf.mem));
44765
44766 /* read data preparation is only needed by wl127x */
44767- wl->ops->prepare_read = wl127x_prepare_read;
44768+ pax_open_kernel();
44769+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44770+ pax_close_kernel();
44771
44772 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44773 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44774diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
44775index 7aa0eb8..5a9ef38 100644
44776--- a/drivers/net/wireless/ti/wl18xx/main.c
44777+++ b/drivers/net/wireless/ti/wl18xx/main.c
44778@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
44779 }
44780
44781 if (!checksum_param) {
44782- wl18xx_ops.set_rx_csum = NULL;
44783- wl18xx_ops.init_vif = NULL;
44784+ pax_open_kernel();
44785+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
44786+ *(void **)&wl18xx_ops.init_vif = NULL;
44787+ pax_close_kernel();
44788 }
44789
44790 /* Enable 11a Band only if we have 5G antennas */
44791diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
44792index 7ef0b4a..ff65c28 100644
44793--- a/drivers/net/wireless/zd1211rw/zd_usb.c
44794+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
44795@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
44796 {
44797 struct zd_usb *usb = urb->context;
44798 struct zd_usb_interrupt *intr = &usb->intr;
44799- int len;
44800+ unsigned int len;
44801 u16 int_num;
44802
44803 ZD_ASSERT(in_interrupt());
44804diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
44805index 59f95d8..53e0e7f 100644
44806--- a/drivers/nfc/nfcwilink.c
44807+++ b/drivers/nfc/nfcwilink.c
44808@@ -513,7 +513,7 @@ static struct nci_ops nfcwilink_ops = {
44809
44810 static int nfcwilink_probe(struct platform_device *pdev)
44811 {
44812- static struct nfcwilink *drv;
44813+ struct nfcwilink *drv;
44814 int rc;
44815 __u32 protocols;
44816
44817diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
44818index d93b2b6..ae50401 100644
44819--- a/drivers/oprofile/buffer_sync.c
44820+++ b/drivers/oprofile/buffer_sync.c
44821@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
44822 if (cookie == NO_COOKIE)
44823 offset = pc;
44824 if (cookie == INVALID_COOKIE) {
44825- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
44826+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
44827 offset = pc;
44828 }
44829 if (cookie != last_cookie) {
44830@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
44831 /* add userspace sample */
44832
44833 if (!mm) {
44834- atomic_inc(&oprofile_stats.sample_lost_no_mm);
44835+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
44836 return 0;
44837 }
44838
44839 cookie = lookup_dcookie(mm, s->eip, &offset);
44840
44841 if (cookie == INVALID_COOKIE) {
44842- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
44843+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
44844 return 0;
44845 }
44846
44847@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
44848 /* ignore backtraces if failed to add a sample */
44849 if (state == sb_bt_start) {
44850 state = sb_bt_ignore;
44851- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
44852+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
44853 }
44854 }
44855 release_mm(mm);
44856diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
44857index c0cc4e7..44d4e54 100644
44858--- a/drivers/oprofile/event_buffer.c
44859+++ b/drivers/oprofile/event_buffer.c
44860@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
44861 }
44862
44863 if (buffer_pos == buffer_size) {
44864- atomic_inc(&oprofile_stats.event_lost_overflow);
44865+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
44866 return;
44867 }
44868
44869diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
44870index ed2c3ec..deda85a 100644
44871--- a/drivers/oprofile/oprof.c
44872+++ b/drivers/oprofile/oprof.c
44873@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
44874 if (oprofile_ops.switch_events())
44875 return;
44876
44877- atomic_inc(&oprofile_stats.multiplex_counter);
44878+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
44879 start_switch_worker();
44880 }
44881
44882diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
44883index ee2cfce..7f8f699 100644
44884--- a/drivers/oprofile/oprofile_files.c
44885+++ b/drivers/oprofile/oprofile_files.c
44886@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
44887
44888 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
44889
44890-static ssize_t timeout_read(struct file *file, char __user *buf,
44891+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
44892 size_t count, loff_t *offset)
44893 {
44894 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
44895diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
44896index 59659ce..6c860a0 100644
44897--- a/drivers/oprofile/oprofile_stats.c
44898+++ b/drivers/oprofile/oprofile_stats.c
44899@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
44900 cpu_buf->sample_invalid_eip = 0;
44901 }
44902
44903- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
44904- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
44905- atomic_set(&oprofile_stats.event_lost_overflow, 0);
44906- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
44907- atomic_set(&oprofile_stats.multiplex_counter, 0);
44908+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
44909+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
44910+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
44911+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
44912+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
44913 }
44914
44915
44916diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
44917index 1fc622b..8c48fc3 100644
44918--- a/drivers/oprofile/oprofile_stats.h
44919+++ b/drivers/oprofile/oprofile_stats.h
44920@@ -13,11 +13,11 @@
44921 #include <linux/atomic.h>
44922
44923 struct oprofile_stat_struct {
44924- atomic_t sample_lost_no_mm;
44925- atomic_t sample_lost_no_mapping;
44926- atomic_t bt_lost_no_mapping;
44927- atomic_t event_lost_overflow;
44928- atomic_t multiplex_counter;
44929+ atomic_unchecked_t sample_lost_no_mm;
44930+ atomic_unchecked_t sample_lost_no_mapping;
44931+ atomic_unchecked_t bt_lost_no_mapping;
44932+ atomic_unchecked_t event_lost_overflow;
44933+ atomic_unchecked_t multiplex_counter;
44934 };
44935
44936 extern struct oprofile_stat_struct oprofile_stats;
44937diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
44938index 3f49345..c750d0b 100644
44939--- a/drivers/oprofile/oprofilefs.c
44940+++ b/drivers/oprofile/oprofilefs.c
44941@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
44942
44943 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
44944 {
44945- atomic_t *val = file->private_data;
44946- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
44947+ atomic_unchecked_t *val = file->private_data;
44948+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
44949 }
44950
44951
44952@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
44953
44954
44955 int oprofilefs_create_ro_atomic(struct dentry *root,
44956- char const *name, atomic_t *val)
44957+ char const *name, atomic_unchecked_t *val)
44958 {
44959 return __oprofilefs_create_file(root, name,
44960 &atomic_ro_fops, 0444, val);
44961diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
44962index 61be1d9..dec05d7 100644
44963--- a/drivers/oprofile/timer_int.c
44964+++ b/drivers/oprofile/timer_int.c
44965@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
44966 return NOTIFY_OK;
44967 }
44968
44969-static struct notifier_block __refdata oprofile_cpu_notifier = {
44970+static struct notifier_block oprofile_cpu_notifier = {
44971 .notifier_call = oprofile_cpu_notify,
44972 };
44973
44974diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
44975index 92ed045..62d39bd7 100644
44976--- a/drivers/parport/procfs.c
44977+++ b/drivers/parport/procfs.c
44978@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
44979
44980 *ppos += len;
44981
44982- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
44983+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
44984 }
44985
44986 #ifdef CONFIG_PARPORT_1284
44987@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
44988
44989 *ppos += len;
44990
44991- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
44992+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
44993 }
44994 #endif /* IEEE1284.3 support. */
44995
44996diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
44997index 2f5786c..61ab4d1 100644
44998--- a/drivers/pci/hotplug/acpiphp_ibm.c
44999+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45000@@ -463,7 +463,9 @@ static int __init ibm_acpiphp_init(void)
45001 goto init_cleanup;
45002 }
45003
45004- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45005+ pax_open_kernel();
45006+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45007+ pax_close_kernel();
45008 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45009
45010 return retval;
45011diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45012index a6a71c4..c91097b 100644
45013--- a/drivers/pci/hotplug/cpcihp_generic.c
45014+++ b/drivers/pci/hotplug/cpcihp_generic.c
45015@@ -73,7 +73,6 @@ static u16 port;
45016 static unsigned int enum_bit;
45017 static u8 enum_mask;
45018
45019-static struct cpci_hp_controller_ops generic_hpc_ops;
45020 static struct cpci_hp_controller generic_hpc;
45021
45022 static int __init validate_parameters(void)
45023@@ -139,6 +138,10 @@ static int query_enum(void)
45024 return ((value & enum_mask) == enum_mask);
45025 }
45026
45027+static struct cpci_hp_controller_ops generic_hpc_ops = {
45028+ .query_enum = query_enum,
45029+};
45030+
45031 static int __init cpcihp_generic_init(void)
45032 {
45033 int status;
45034@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45035 pci_dev_put(dev);
45036
45037 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45038- generic_hpc_ops.query_enum = query_enum;
45039 generic_hpc.ops = &generic_hpc_ops;
45040
45041 status = cpci_hp_register_controller(&generic_hpc);
45042diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45043index 449b4bb..257e2e8 100644
45044--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45045+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45046@@ -59,7 +59,6 @@
45047 /* local variables */
45048 static bool debug;
45049 static bool poll;
45050-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45051 static struct cpci_hp_controller zt5550_hpc;
45052
45053 /* Primary cPCI bus bridge device */
45054@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45055 return 0;
45056 }
45057
45058+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45059+ .query_enum = zt5550_hc_query_enum,
45060+};
45061+
45062 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45063 {
45064 int status;
45065@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45066 dbg("returned from zt5550_hc_config");
45067
45068 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45069- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45070 zt5550_hpc.ops = &zt5550_hpc_ops;
45071 if(!poll) {
45072 zt5550_hpc.irq = hc_dev->irq;
45073 zt5550_hpc.irq_flags = IRQF_SHARED;
45074 zt5550_hpc.dev_id = hc_dev;
45075
45076- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45077- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45078- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45079+ pax_open_kernel();
45080+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45081+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45082+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45083+ pax_open_kernel();
45084 } else {
45085 info("using ENUM# polling mode");
45086 }
45087diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45088index 76ba8a1..20ca857 100644
45089--- a/drivers/pci/hotplug/cpqphp_nvram.c
45090+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45091@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45092
45093 void compaq_nvram_init (void __iomem *rom_start)
45094 {
45095+
45096+#ifndef CONFIG_PAX_KERNEXEC
45097 if (rom_start) {
45098 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45099 }
45100+#endif
45101+
45102 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45103
45104 /* initialize our int15 lock */
45105diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45106index ec20f74..c1d961e 100644
45107--- a/drivers/pci/hotplug/pci_hotplug_core.c
45108+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45109@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45110 return -EINVAL;
45111 }
45112
45113- slot->ops->owner = owner;
45114- slot->ops->mod_name = mod_name;
45115+ pax_open_kernel();
45116+ *(struct module **)&slot->ops->owner = owner;
45117+ *(const char **)&slot->ops->mod_name = mod_name;
45118+ pax_close_kernel();
45119
45120 mutex_lock(&pci_hp_mutex);
45121 /*
45122diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45123index f4a18f5..ff2463c 100644
45124--- a/drivers/pci/hotplug/pciehp_core.c
45125+++ b/drivers/pci/hotplug/pciehp_core.c
45126@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
45127 struct slot *slot = ctrl->slot;
45128 struct hotplug_slot *hotplug = NULL;
45129 struct hotplug_slot_info *info = NULL;
45130- struct hotplug_slot_ops *ops = NULL;
45131+ hotplug_slot_ops_no_const *ops = NULL;
45132 char name[SLOT_NAME_SIZE];
45133 int retval = -ENOMEM;
45134
45135diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45136index 7128cfd..a0640d6 100644
45137--- a/drivers/pci/pci-sysfs.c
45138+++ b/drivers/pci/pci-sysfs.c
45139@@ -1083,7 +1083,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45140 {
45141 /* allocate attribute structure, piggyback attribute name */
45142 int name_len = write_combine ? 13 : 10;
45143- struct bin_attribute *res_attr;
45144+ bin_attribute_no_const *res_attr;
45145 int retval;
45146
45147 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45148@@ -1268,7 +1268,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45149 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45150 {
45151 int retval;
45152- struct bin_attribute *attr;
45153+ bin_attribute_no_const *attr;
45154
45155 /* If the device has VPD, try to expose it in sysfs. */
45156 if (dev->vpd) {
45157@@ -1315,7 +1315,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45158 {
45159 int retval;
45160 int rom_size = 0;
45161- struct bin_attribute *attr;
45162+ bin_attribute_no_const *attr;
45163
45164 if (!sysfs_initialized)
45165 return -EACCES;
45166diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45167index 8a00c06..18a9715 100644
45168--- a/drivers/pci/pci.h
45169+++ b/drivers/pci/pci.h
45170@@ -95,7 +95,7 @@ struct pci_vpd_ops {
45171 struct pci_vpd {
45172 unsigned int len;
45173 const struct pci_vpd_ops *ops;
45174- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45175+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45176 };
45177
45178 int pci_vpd_pci22_init(struct pci_dev *dev);
45179diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45180index 403a443..034e050 100644
45181--- a/drivers/pci/pcie/aspm.c
45182+++ b/drivers/pci/pcie/aspm.c
45183@@ -27,9 +27,9 @@
45184 #define MODULE_PARAM_PREFIX "pcie_aspm."
45185
45186 /* Note: those are not register definitions */
45187-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45188-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45189-#define ASPM_STATE_L1 (4) /* L1 state */
45190+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45191+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45192+#define ASPM_STATE_L1 (4U) /* L1 state */
45193 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45194 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45195
45196diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45197index 7ef0f86..17b710f 100644
45198--- a/drivers/pci/probe.c
45199+++ b/drivers/pci/probe.c
45200@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45201 struct pci_bus_region region, inverted_region;
45202 bool bar_too_big = false, bar_disabled = false;
45203
45204- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45205+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45206
45207 /* No printks while decoding is disabled! */
45208 if (!dev->mmio_always_on) {
45209diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45210index cdc7836..528635c 100644
45211--- a/drivers/pci/proc.c
45212+++ b/drivers/pci/proc.c
45213@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45214 static int __init pci_proc_init(void)
45215 {
45216 struct pci_dev *dev = NULL;
45217+
45218+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45219+#ifdef CONFIG_GRKERNSEC_PROC_USER
45220+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45221+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45222+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45223+#endif
45224+#else
45225 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45226+#endif
45227 proc_create("devices", 0, proc_bus_pci_dir,
45228 &proc_bus_pci_dev_operations);
45229 proc_initialized = 1;
45230diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45231index 3e5b4497..dcdfb70 100644
45232--- a/drivers/platform/x86/chromeos_laptop.c
45233+++ b/drivers/platform/x86/chromeos_laptop.c
45234@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45235 return 0;
45236 }
45237
45238-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45239+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45240 {
45241 .ident = "Samsung Series 5 550 - Touchpad",
45242 .matches = {
45243diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45244index 62f8030..c7f2a45 100644
45245--- a/drivers/platform/x86/msi-laptop.c
45246+++ b/drivers/platform/x86/msi-laptop.c
45247@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45248
45249 if (!quirks->ec_read_only) {
45250 /* allow userland write sysfs file */
45251- dev_attr_bluetooth.store = store_bluetooth;
45252- dev_attr_wlan.store = store_wlan;
45253- dev_attr_threeg.store = store_threeg;
45254- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45255- dev_attr_wlan.attr.mode |= S_IWUSR;
45256- dev_attr_threeg.attr.mode |= S_IWUSR;
45257+ pax_open_kernel();
45258+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45259+ *(void **)&dev_attr_wlan.store = store_wlan;
45260+ *(void **)&dev_attr_threeg.store = store_threeg;
45261+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45262+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45263+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45264+ pax_close_kernel();
45265 }
45266
45267 /* disable hardware control by fn key */
45268diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
45269index 70222f2..8c8ce66 100644
45270--- a/drivers/platform/x86/msi-wmi.c
45271+++ b/drivers/platform/x86/msi-wmi.c
45272@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
45273 static void msi_wmi_notify(u32 value, void *context)
45274 {
45275 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
45276- static struct key_entry *key;
45277+ struct key_entry *key;
45278 union acpi_object *obj;
45279 acpi_status status;
45280
45281diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45282index 13ec195..6af61af 100644
45283--- a/drivers/platform/x86/sony-laptop.c
45284+++ b/drivers/platform/x86/sony-laptop.c
45285@@ -2475,7 +2475,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45286 }
45287
45288 /* High speed charging function */
45289-static struct device_attribute *hsc_handle;
45290+static device_attribute_no_const *hsc_handle;
45291
45292 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45293 struct device_attribute *attr,
45294diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45295index 4e86e97..04d50d1 100644
45296--- a/drivers/platform/x86/thinkpad_acpi.c
45297+++ b/drivers/platform/x86/thinkpad_acpi.c
45298@@ -2091,7 +2091,7 @@ static int hotkey_mask_get(void)
45299 return 0;
45300 }
45301
45302-void static hotkey_mask_warn_incomplete_mask(void)
45303+static void hotkey_mask_warn_incomplete_mask(void)
45304 {
45305 /* log only what the user can fix... */
45306 const u32 wantedmask = hotkey_driver_mask &
45307@@ -2318,11 +2318,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45308 }
45309 }
45310
45311-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45312- struct tp_nvram_state *newn,
45313- const u32 event_mask)
45314-{
45315-
45316 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45317 do { \
45318 if ((event_mask & (1 << __scancode)) && \
45319@@ -2336,36 +2331,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45320 tpacpi_hotkey_send_key(__scancode); \
45321 } while (0)
45322
45323- void issue_volchange(const unsigned int oldvol,
45324- const unsigned int newvol)
45325- {
45326- unsigned int i = oldvol;
45327+static void issue_volchange(const unsigned int oldvol,
45328+ const unsigned int newvol,
45329+ const u32 event_mask)
45330+{
45331+ unsigned int i = oldvol;
45332
45333- while (i > newvol) {
45334- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45335- i--;
45336- }
45337- while (i < newvol) {
45338- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45339- i++;
45340- }
45341+ while (i > newvol) {
45342+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45343+ i--;
45344 }
45345+ while (i < newvol) {
45346+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45347+ i++;
45348+ }
45349+}
45350
45351- void issue_brightnesschange(const unsigned int oldbrt,
45352- const unsigned int newbrt)
45353- {
45354- unsigned int i = oldbrt;
45355+static void issue_brightnesschange(const unsigned int oldbrt,
45356+ const unsigned int newbrt,
45357+ const u32 event_mask)
45358+{
45359+ unsigned int i = oldbrt;
45360
45361- while (i > newbrt) {
45362- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45363- i--;
45364- }
45365- while (i < newbrt) {
45366- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45367- i++;
45368- }
45369+ while (i > newbrt) {
45370+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45371+ i--;
45372+ }
45373+ while (i < newbrt) {
45374+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45375+ i++;
45376 }
45377+}
45378
45379+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45380+ struct tp_nvram_state *newn,
45381+ const u32 event_mask)
45382+{
45383 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45384 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45385 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45386@@ -2399,7 +2400,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45387 oldn->volume_level != newn->volume_level) {
45388 /* recently muted, or repeated mute keypress, or
45389 * multiple presses ending in mute */
45390- issue_volchange(oldn->volume_level, newn->volume_level);
45391+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45392 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45393 }
45394 } else {
45395@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45396 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45397 }
45398 if (oldn->volume_level != newn->volume_level) {
45399- issue_volchange(oldn->volume_level, newn->volume_level);
45400+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45401 } else if (oldn->volume_toggle != newn->volume_toggle) {
45402 /* repeated vol up/down keypress at end of scale ? */
45403 if (newn->volume_level == 0)
45404@@ -2422,7 +2423,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45405 /* handle brightness */
45406 if (oldn->brightness_level != newn->brightness_level) {
45407 issue_brightnesschange(oldn->brightness_level,
45408- newn->brightness_level);
45409+ newn->brightness_level,
45410+ event_mask);
45411 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45412 /* repeated key presses that didn't change state */
45413 if (newn->brightness_level == 0)
45414@@ -2431,10 +2433,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45415 && !tp_features.bright_unkfw)
45416 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45417 }
45418+}
45419
45420 #undef TPACPI_COMPARE_KEY
45421 #undef TPACPI_MAY_SEND_KEY
45422-}
45423
45424 /*
45425 * Polling driver
45426diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45427index 769d265..a3a05ca 100644
45428--- a/drivers/pnp/pnpbios/bioscalls.c
45429+++ b/drivers/pnp/pnpbios/bioscalls.c
45430@@ -58,7 +58,7 @@ do { \
45431 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45432 } while(0)
45433
45434-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45435+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45436 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45437
45438 /*
45439@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45440
45441 cpu = get_cpu();
45442 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45443+
45444+ pax_open_kernel();
45445 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45446+ pax_close_kernel();
45447
45448 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45449 spin_lock_irqsave(&pnp_bios_lock, flags);
45450@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45451 :"memory");
45452 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45453
45454+ pax_open_kernel();
45455 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45456+ pax_close_kernel();
45457+
45458 put_cpu();
45459
45460 /* If we get here and this is set then the PnP BIOS faulted on us. */
45461@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45462 return status;
45463 }
45464
45465-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45466+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45467 {
45468 int i;
45469
45470@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45471 pnp_bios_callpoint.offset = header->fields.pm16offset;
45472 pnp_bios_callpoint.segment = PNP_CS16;
45473
45474+ pax_open_kernel();
45475+
45476 for_each_possible_cpu(i) {
45477 struct desc_struct *gdt = get_cpu_gdt_table(i);
45478 if (!gdt)
45479@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45480 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45481 (unsigned long)__va(header->fields.pm16dseg));
45482 }
45483+
45484+ pax_close_kernel();
45485 }
45486diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45487index d95e101..67f0c3f 100644
45488--- a/drivers/pnp/resource.c
45489+++ b/drivers/pnp/resource.c
45490@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45491 return 1;
45492
45493 /* check if the resource is valid */
45494- if (*irq < 0 || *irq > 15)
45495+ if (*irq > 15)
45496 return 0;
45497
45498 /* check if the resource is reserved */
45499@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45500 return 1;
45501
45502 /* check if the resource is valid */
45503- if (*dma < 0 || *dma == 4 || *dma > 7)
45504+ if (*dma == 4 || *dma > 7)
45505 return 0;
45506
45507 /* check if the resource is reserved */
45508diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45509index 0c52e2a..3421ab7 100644
45510--- a/drivers/power/pda_power.c
45511+++ b/drivers/power/pda_power.c
45512@@ -37,7 +37,11 @@ static int polling;
45513
45514 #if IS_ENABLED(CONFIG_USB_PHY)
45515 static struct usb_phy *transceiver;
45516-static struct notifier_block otg_nb;
45517+static int otg_handle_notification(struct notifier_block *nb,
45518+ unsigned long event, void *unused);
45519+static struct notifier_block otg_nb = {
45520+ .notifier_call = otg_handle_notification
45521+};
45522 #endif
45523
45524 static struct regulator *ac_draw;
45525@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45526
45527 #if IS_ENABLED(CONFIG_USB_PHY)
45528 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45529- otg_nb.notifier_call = otg_handle_notification;
45530 ret = usb_register_notifier(transceiver, &otg_nb);
45531 if (ret) {
45532 dev_err(dev, "failure to register otg notifier\n");
45533diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45534index cc439fd..8fa30df 100644
45535--- a/drivers/power/power_supply.h
45536+++ b/drivers/power/power_supply.h
45537@@ -16,12 +16,12 @@ struct power_supply;
45538
45539 #ifdef CONFIG_SYSFS
45540
45541-extern void power_supply_init_attrs(struct device_type *dev_type);
45542+extern void power_supply_init_attrs(void);
45543 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45544
45545 #else
45546
45547-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45548+static inline void power_supply_init_attrs(void) {}
45549 #define power_supply_uevent NULL
45550
45551 #endif /* CONFIG_SYSFS */
45552diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45553index 00e6672..2642c08 100644
45554--- a/drivers/power/power_supply_core.c
45555+++ b/drivers/power/power_supply_core.c
45556@@ -24,7 +24,10 @@
45557 struct class *power_supply_class;
45558 EXPORT_SYMBOL_GPL(power_supply_class);
45559
45560-static struct device_type power_supply_dev_type;
45561+extern const struct attribute_group *power_supply_attr_groups[];
45562+static struct device_type power_supply_dev_type = {
45563+ .groups = power_supply_attr_groups,
45564+};
45565
45566 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45567 struct power_supply *supply)
45568@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
45569 return PTR_ERR(power_supply_class);
45570
45571 power_supply_class->dev_uevent = power_supply_uevent;
45572- power_supply_init_attrs(&power_supply_dev_type);
45573+ power_supply_init_attrs();
45574
45575 return 0;
45576 }
45577diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45578index 44420d1..967126e 100644
45579--- a/drivers/power/power_supply_sysfs.c
45580+++ b/drivers/power/power_supply_sysfs.c
45581@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45582 .is_visible = power_supply_attr_is_visible,
45583 };
45584
45585-static const struct attribute_group *power_supply_attr_groups[] = {
45586+const struct attribute_group *power_supply_attr_groups[] = {
45587 &power_supply_attr_group,
45588 NULL,
45589 };
45590
45591-void power_supply_init_attrs(struct device_type *dev_type)
45592+void power_supply_init_attrs(void)
45593 {
45594 int i;
45595
45596- dev_type->groups = power_supply_attr_groups;
45597-
45598 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45599 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45600 }
45601diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45602index a01b8b3..37c2afe 100644
45603--- a/drivers/regulator/core.c
45604+++ b/drivers/regulator/core.c
45605@@ -3307,7 +3307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45606 {
45607 const struct regulation_constraints *constraints = NULL;
45608 const struct regulator_init_data *init_data;
45609- static atomic_t regulator_no = ATOMIC_INIT(0);
45610+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45611 struct regulator_dev *rdev;
45612 struct device *dev;
45613 int ret, i;
45614@@ -3377,7 +3377,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45615 rdev->dev.of_node = config->of_node;
45616 rdev->dev.parent = dev;
45617 dev_set_name(&rdev->dev, "regulator.%d",
45618- atomic_inc_return(&regulator_no) - 1);
45619+ atomic_inc_return_unchecked(&regulator_no) - 1);
45620 ret = device_register(&rdev->dev);
45621 if (ret != 0) {
45622 put_device(&rdev->dev);
45623diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45624index 144bcac..d20e7db 100644
45625--- a/drivers/regulator/max8660.c
45626+++ b/drivers/regulator/max8660.c
45627@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
45628 max8660->shadow_regs[MAX8660_OVER1] = 5;
45629 } else {
45630 /* Otherwise devices can be toggled via software */
45631- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45632- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45633+ pax_open_kernel();
45634+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45635+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45636+ pax_close_kernel();
45637 }
45638
45639 /*
45640diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45641index 5b77ab7..a62f061 100644
45642--- a/drivers/regulator/max8973-regulator.c
45643+++ b/drivers/regulator/max8973-regulator.c
45644@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45645 if (!pdata || !pdata->enable_ext_control) {
45646 max->desc.enable_reg = MAX8973_VOUT;
45647 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45648- max->ops.enable = regulator_enable_regmap;
45649- max->ops.disable = regulator_disable_regmap;
45650- max->ops.is_enabled = regulator_is_enabled_regmap;
45651+ pax_open_kernel();
45652+ *(void **)&max->ops.enable = regulator_enable_regmap;
45653+ *(void **)&max->ops.disable = regulator_disable_regmap;
45654+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
45655+ pax_close_kernel();
45656 }
45657
45658 if (pdata) {
45659diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
45660index 1037e07..e64dea1 100644
45661--- a/drivers/regulator/mc13892-regulator.c
45662+++ b/drivers/regulator/mc13892-regulator.c
45663@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
45664 }
45665 mc13xxx_unlock(mc13892);
45666
45667- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45668+ pax_open_kernel();
45669+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45670 = mc13892_vcam_set_mode;
45671- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45672+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45673 = mc13892_vcam_get_mode;
45674+ pax_close_kernel();
45675
45676 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
45677 ARRAY_SIZE(mc13892_regulators));
45678diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
45679index 24e733c..bfbaa3e 100644
45680--- a/drivers/rtc/rtc-cmos.c
45681+++ b/drivers/rtc/rtc-cmos.c
45682@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
45683 hpet_rtc_timer_init();
45684
45685 /* export at least the first block of NVRAM */
45686- nvram.size = address_space - NVRAM_OFFSET;
45687+ pax_open_kernel();
45688+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
45689+ pax_close_kernel();
45690 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
45691 if (retval < 0) {
45692 dev_dbg(dev, "can't create nvram file? %d\n", retval);
45693diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
45694index d049393..bb20be0 100644
45695--- a/drivers/rtc/rtc-dev.c
45696+++ b/drivers/rtc/rtc-dev.c
45697@@ -16,6 +16,7 @@
45698 #include <linux/module.h>
45699 #include <linux/rtc.h>
45700 #include <linux/sched.h>
45701+#include <linux/grsecurity.h>
45702 #include "rtc-core.h"
45703
45704 static dev_t rtc_devt;
45705@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
45706 if (copy_from_user(&tm, uarg, sizeof(tm)))
45707 return -EFAULT;
45708
45709+ gr_log_timechange();
45710+
45711 return rtc_set_time(rtc, &tm);
45712
45713 case RTC_PIE_ON:
45714diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
45715index ca18fd1..055e42d 100644
45716--- a/drivers/rtc/rtc-ds1307.c
45717+++ b/drivers/rtc/rtc-ds1307.c
45718@@ -107,7 +107,7 @@ struct ds1307 {
45719 u8 offset; /* register's offset */
45720 u8 regs[11];
45721 u16 nvram_offset;
45722- struct bin_attribute *nvram;
45723+ bin_attribute_no_const *nvram;
45724 enum ds_type type;
45725 unsigned long flags;
45726 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
45727diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
45728index fcb0329..d77b7f2 100644
45729--- a/drivers/rtc/rtc-m48t59.c
45730+++ b/drivers/rtc/rtc-m48t59.c
45731@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
45732 if (IS_ERR(m48t59->rtc))
45733 return PTR_ERR(m48t59->rtc);
45734
45735- m48t59_nvram_attr.size = pdata->offset;
45736+ pax_open_kernel();
45737+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
45738+ pax_close_kernel();
45739
45740 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
45741 if (ret)
45742diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
45743index 14b5f8d..cc9bd26 100644
45744--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
45745+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
45746@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
45747 for (bit = 0; bit < 8; bit++) {
45748
45749 if ((pci_status[i] & (0x1 << bit)) != 0) {
45750- static const char *s;
45751+ const char *s;
45752
45753 s = pci_status_strings[bit];
45754 if (i == 7/*TARG*/ && bit == 3)
45755@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
45756
45757 for (bit = 0; bit < 8; bit++) {
45758
45759- if ((split_status[i] & (0x1 << bit)) != 0) {
45760- static const char *s;
45761-
45762- s = split_status_strings[bit];
45763- printk(s, ahd_name(ahd),
45764+ if ((split_status[i] & (0x1 << bit)) != 0)
45765+ printk(split_status_strings[bit], ahd_name(ahd),
45766 split_status_source[i]);
45767- }
45768
45769 if (i > 1)
45770 continue;
45771
45772- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
45773- static const char *s;
45774-
45775- s = split_status_strings[bit];
45776- printk(s, ahd_name(ahd), "SG");
45777- }
45778+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
45779+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
45780 }
45781 }
45782 /*
45783diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
45784index e693af6..2e525b6 100644
45785--- a/drivers/scsi/bfa/bfa_fcpim.h
45786+++ b/drivers/scsi/bfa/bfa_fcpim.h
45787@@ -36,7 +36,7 @@ struct bfa_iotag_s {
45788
45789 struct bfa_itn_s {
45790 bfa_isr_func_t isr;
45791-};
45792+} __no_const;
45793
45794 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
45795 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
45796diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
45797index 90814fe..4384138 100644
45798--- a/drivers/scsi/bfa/bfa_ioc.h
45799+++ b/drivers/scsi/bfa/bfa_ioc.h
45800@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
45801 bfa_ioc_disable_cbfn_t disable_cbfn;
45802 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
45803 bfa_ioc_reset_cbfn_t reset_cbfn;
45804-};
45805+} __no_const;
45806
45807 /*
45808 * IOC event notification mechanism.
45809@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
45810 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
45811 enum bfi_ioc_state fwstate);
45812 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
45813-};
45814+} __no_const;
45815
45816 /*
45817 * Queue element to wait for room in request queue. FIFO order is
45818diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
45819index c9382d6..6619864 100644
45820--- a/drivers/scsi/fcoe/fcoe_sysfs.c
45821+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
45822@@ -33,8 +33,8 @@
45823 */
45824 #include "libfcoe.h"
45825
45826-static atomic_t ctlr_num;
45827-static atomic_t fcf_num;
45828+static atomic_unchecked_t ctlr_num;
45829+static atomic_unchecked_t fcf_num;
45830
45831 /*
45832 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
45833@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
45834 if (!ctlr)
45835 goto out;
45836
45837- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
45838+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
45839 ctlr->f = f;
45840 ctlr->mode = FIP_CONN_TYPE_FABRIC;
45841 INIT_LIST_HEAD(&ctlr->fcfs);
45842@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
45843 fcf->dev.parent = &ctlr->dev;
45844 fcf->dev.bus = &fcoe_bus_type;
45845 fcf->dev.type = &fcoe_fcf_device_type;
45846- fcf->id = atomic_inc_return(&fcf_num) - 1;
45847+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
45848 fcf->state = FCOE_FCF_STATE_UNKNOWN;
45849
45850 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
45851@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
45852 {
45853 int error;
45854
45855- atomic_set(&ctlr_num, 0);
45856- atomic_set(&fcf_num, 0);
45857+ atomic_set_unchecked(&ctlr_num, 0);
45858+ atomic_set_unchecked(&fcf_num, 0);
45859
45860 error = bus_register(&fcoe_bus_type);
45861 if (error)
45862diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
45863index df0c3c7..b00e1d0 100644
45864--- a/drivers/scsi/hosts.c
45865+++ b/drivers/scsi/hosts.c
45866@@ -42,7 +42,7 @@
45867 #include "scsi_logging.h"
45868
45869
45870-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
45871+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
45872
45873
45874 static void scsi_host_cls_release(struct device *dev)
45875@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
45876 * subtract one because we increment first then return, but we need to
45877 * know what the next host number was before increment
45878 */
45879- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
45880+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
45881 shost->dma_channel = 0xff;
45882
45883 /* These three are default values which can be overridden */
45884diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
45885index 891c86b..dd1224a0 100644
45886--- a/drivers/scsi/hpsa.c
45887+++ b/drivers/scsi/hpsa.c
45888@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
45889 unsigned long flags;
45890
45891 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
45892- return h->access.command_completed(h, q);
45893+ return h->access->command_completed(h, q);
45894
45895 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
45896 a = rq->head[rq->current_entry];
45897@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
45898 while (!list_empty(&h->reqQ)) {
45899 c = list_entry(h->reqQ.next, struct CommandList, list);
45900 /* can't do anything if fifo is full */
45901- if ((h->access.fifo_full(h))) {
45902+ if ((h->access->fifo_full(h))) {
45903 dev_warn(&h->pdev->dev, "fifo full\n");
45904 break;
45905 }
45906@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
45907
45908 /* Tell the controller execute command */
45909 spin_unlock_irqrestore(&h->lock, flags);
45910- h->access.submit_command(h, c);
45911+ h->access->submit_command(h, c);
45912 spin_lock_irqsave(&h->lock, flags);
45913 }
45914 spin_unlock_irqrestore(&h->lock, flags);
45915@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
45916
45917 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
45918 {
45919- return h->access.command_completed(h, q);
45920+ return h->access->command_completed(h, q);
45921 }
45922
45923 static inline bool interrupt_pending(struct ctlr_info *h)
45924 {
45925- return h->access.intr_pending(h);
45926+ return h->access->intr_pending(h);
45927 }
45928
45929 static inline long interrupt_not_for_us(struct ctlr_info *h)
45930 {
45931- return (h->access.intr_pending(h) == 0) ||
45932+ return (h->access->intr_pending(h) == 0) ||
45933 (h->interrupts_enabled == 0);
45934 }
45935
45936@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
45937 if (prod_index < 0)
45938 return -ENODEV;
45939 h->product_name = products[prod_index].product_name;
45940- h->access = *(products[prod_index].access);
45941+ h->access = products[prod_index].access;
45942
45943 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
45944 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
45945@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
45946
45947 assert_spin_locked(&lockup_detector_lock);
45948 remove_ctlr_from_lockup_detector_list(h);
45949- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45950+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45951 spin_lock_irqsave(&h->lock, flags);
45952 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
45953 spin_unlock_irqrestore(&h->lock, flags);
45954@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
45955 }
45956
45957 /* make sure the board interrupts are off */
45958- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45959+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45960
45961 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
45962 goto clean2;
45963@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
45964 * fake ones to scoop up any residual completions.
45965 */
45966 spin_lock_irqsave(&h->lock, flags);
45967- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45968+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45969 spin_unlock_irqrestore(&h->lock, flags);
45970 free_irqs(h);
45971 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
45972@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
45973 dev_info(&h->pdev->dev, "Board READY.\n");
45974 dev_info(&h->pdev->dev,
45975 "Waiting for stale completions to drain.\n");
45976- h->access.set_intr_mask(h, HPSA_INTR_ON);
45977+ h->access->set_intr_mask(h, HPSA_INTR_ON);
45978 msleep(10000);
45979- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45980+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45981
45982 rc = controller_reset_failed(h->cfgtable);
45983 if (rc)
45984@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
45985 }
45986
45987 /* Turn the interrupts on so we can service requests */
45988- h->access.set_intr_mask(h, HPSA_INTR_ON);
45989+ h->access->set_intr_mask(h, HPSA_INTR_ON);
45990
45991 hpsa_hba_inquiry(h);
45992 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
45993@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
45994 * To write all data in the battery backed cache to disks
45995 */
45996 hpsa_flush_cache(h);
45997- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45998+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45999 hpsa_free_irqs_and_disable_msix(h);
46000 }
46001
46002@@ -5144,7 +5144,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46003 return;
46004 }
46005 /* Change the access methods to the performant access methods */
46006- h->access = SA5_performant_access;
46007+ h->access = &SA5_performant_access;
46008 h->transMethod = CFGTBL_Trans_Performant;
46009 }
46010
46011diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46012index bc85e72..ae04a39 100644
46013--- a/drivers/scsi/hpsa.h
46014+++ b/drivers/scsi/hpsa.h
46015@@ -79,7 +79,7 @@ struct ctlr_info {
46016 unsigned int msix_vector;
46017 unsigned int msi_vector;
46018 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46019- struct access_method access;
46020+ struct access_method *access;
46021
46022 /* queue and queue Info */
46023 struct list_head reqQ;
46024diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46025index 5879929..32b241d 100644
46026--- a/drivers/scsi/libfc/fc_exch.c
46027+++ b/drivers/scsi/libfc/fc_exch.c
46028@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46029 u16 pool_max_index;
46030
46031 struct {
46032- atomic_t no_free_exch;
46033- atomic_t no_free_exch_xid;
46034- atomic_t xid_not_found;
46035- atomic_t xid_busy;
46036- atomic_t seq_not_found;
46037- atomic_t non_bls_resp;
46038+ atomic_unchecked_t no_free_exch;
46039+ atomic_unchecked_t no_free_exch_xid;
46040+ atomic_unchecked_t xid_not_found;
46041+ atomic_unchecked_t xid_busy;
46042+ atomic_unchecked_t seq_not_found;
46043+ atomic_unchecked_t non_bls_resp;
46044 } stats;
46045 };
46046
46047@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46048 /* allocate memory for exchange */
46049 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46050 if (!ep) {
46051- atomic_inc(&mp->stats.no_free_exch);
46052+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46053 goto out;
46054 }
46055 memset(ep, 0, sizeof(*ep));
46056@@ -797,7 +797,7 @@ out:
46057 return ep;
46058 err:
46059 spin_unlock_bh(&pool->lock);
46060- atomic_inc(&mp->stats.no_free_exch_xid);
46061+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46062 mempool_free(ep, mp->ep_pool);
46063 return NULL;
46064 }
46065@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46066 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46067 ep = fc_exch_find(mp, xid);
46068 if (!ep) {
46069- atomic_inc(&mp->stats.xid_not_found);
46070+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46071 reject = FC_RJT_OX_ID;
46072 goto out;
46073 }
46074@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46075 ep = fc_exch_find(mp, xid);
46076 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46077 if (ep) {
46078- atomic_inc(&mp->stats.xid_busy);
46079+ atomic_inc_unchecked(&mp->stats.xid_busy);
46080 reject = FC_RJT_RX_ID;
46081 goto rel;
46082 }
46083@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46084 }
46085 xid = ep->xid; /* get our XID */
46086 } else if (!ep) {
46087- atomic_inc(&mp->stats.xid_not_found);
46088+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46089 reject = FC_RJT_RX_ID; /* XID not found */
46090 goto out;
46091 }
46092@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46093 } else {
46094 sp = &ep->seq;
46095 if (sp->id != fh->fh_seq_id) {
46096- atomic_inc(&mp->stats.seq_not_found);
46097+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46098 if (f_ctl & FC_FC_END_SEQ) {
46099 /*
46100 * Update sequence_id based on incoming last
46101@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46102
46103 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46104 if (!ep) {
46105- atomic_inc(&mp->stats.xid_not_found);
46106+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46107 goto out;
46108 }
46109 if (ep->esb_stat & ESB_ST_COMPLETE) {
46110- atomic_inc(&mp->stats.xid_not_found);
46111+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46112 goto rel;
46113 }
46114 if (ep->rxid == FC_XID_UNKNOWN)
46115 ep->rxid = ntohs(fh->fh_rx_id);
46116 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46117- atomic_inc(&mp->stats.xid_not_found);
46118+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46119 goto rel;
46120 }
46121 if (ep->did != ntoh24(fh->fh_s_id) &&
46122 ep->did != FC_FID_FLOGI) {
46123- atomic_inc(&mp->stats.xid_not_found);
46124+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46125 goto rel;
46126 }
46127 sof = fr_sof(fp);
46128@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46129 sp->ssb_stat |= SSB_ST_RESP;
46130 sp->id = fh->fh_seq_id;
46131 } else if (sp->id != fh->fh_seq_id) {
46132- atomic_inc(&mp->stats.seq_not_found);
46133+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46134 goto rel;
46135 }
46136
46137@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46138 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46139
46140 if (!sp)
46141- atomic_inc(&mp->stats.xid_not_found);
46142+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46143 else
46144- atomic_inc(&mp->stats.non_bls_resp);
46145+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46146
46147 fc_frame_free(fp);
46148 }
46149@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46150
46151 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46152 mp = ema->mp;
46153- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46154+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46155 st->fc_no_free_exch_xid +=
46156- atomic_read(&mp->stats.no_free_exch_xid);
46157- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46158- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46159- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46160- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46161+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46162+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46163+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46164+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46165+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46166 }
46167 }
46168 EXPORT_SYMBOL(fc_exch_update_stats);
46169diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46170index 161c98e..6d563b3 100644
46171--- a/drivers/scsi/libsas/sas_ata.c
46172+++ b/drivers/scsi/libsas/sas_ata.c
46173@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46174 .postreset = ata_std_postreset,
46175 .error_handler = ata_std_error_handler,
46176 .post_internal_cmd = sas_ata_post_internal,
46177- .qc_defer = ata_std_qc_defer,
46178+ .qc_defer = ata_std_qc_defer,
46179 .qc_prep = ata_noop_qc_prep,
46180 .qc_issue = sas_ata_qc_issue,
46181 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46182diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46183index 4e1b75c..0bbdfa9 100644
46184--- a/drivers/scsi/lpfc/lpfc.h
46185+++ b/drivers/scsi/lpfc/lpfc.h
46186@@ -432,7 +432,7 @@ struct lpfc_vport {
46187 struct dentry *debug_nodelist;
46188 struct dentry *vport_debugfs_root;
46189 struct lpfc_debugfs_trc *disc_trc;
46190- atomic_t disc_trc_cnt;
46191+ atomic_unchecked_t disc_trc_cnt;
46192 #endif
46193 uint8_t stat_data_enabled;
46194 uint8_t stat_data_blocked;
46195@@ -865,8 +865,8 @@ struct lpfc_hba {
46196 struct timer_list fabric_block_timer;
46197 unsigned long bit_flags;
46198 #define FABRIC_COMANDS_BLOCKED 0
46199- atomic_t num_rsrc_err;
46200- atomic_t num_cmd_success;
46201+ atomic_unchecked_t num_rsrc_err;
46202+ atomic_unchecked_t num_cmd_success;
46203 unsigned long last_rsrc_error_time;
46204 unsigned long last_ramp_down_time;
46205 unsigned long last_ramp_up_time;
46206@@ -902,7 +902,7 @@ struct lpfc_hba {
46207
46208 struct dentry *debug_slow_ring_trc;
46209 struct lpfc_debugfs_trc *slow_ring_trc;
46210- atomic_t slow_ring_trc_cnt;
46211+ atomic_unchecked_t slow_ring_trc_cnt;
46212 /* iDiag debugfs sub-directory */
46213 struct dentry *idiag_root;
46214 struct dentry *idiag_pci_cfg;
46215diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46216index 60084e6..0e2e700 100644
46217--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46218+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46219@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46220
46221 #include <linux/debugfs.h>
46222
46223-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46224+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46225 static unsigned long lpfc_debugfs_start_time = 0L;
46226
46227 /* iDiag */
46228@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46229 lpfc_debugfs_enable = 0;
46230
46231 len = 0;
46232- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46233+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46234 (lpfc_debugfs_max_disc_trc - 1);
46235 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46236 dtp = vport->disc_trc + i;
46237@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46238 lpfc_debugfs_enable = 0;
46239
46240 len = 0;
46241- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46242+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46243 (lpfc_debugfs_max_slow_ring_trc - 1);
46244 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46245 dtp = phba->slow_ring_trc + i;
46246@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46247 !vport || !vport->disc_trc)
46248 return;
46249
46250- index = atomic_inc_return(&vport->disc_trc_cnt) &
46251+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46252 (lpfc_debugfs_max_disc_trc - 1);
46253 dtp = vport->disc_trc + index;
46254 dtp->fmt = fmt;
46255 dtp->data1 = data1;
46256 dtp->data2 = data2;
46257 dtp->data3 = data3;
46258- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46259+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46260 dtp->jif = jiffies;
46261 #endif
46262 return;
46263@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46264 !phba || !phba->slow_ring_trc)
46265 return;
46266
46267- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46268+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46269 (lpfc_debugfs_max_slow_ring_trc - 1);
46270 dtp = phba->slow_ring_trc + index;
46271 dtp->fmt = fmt;
46272 dtp->data1 = data1;
46273 dtp->data2 = data2;
46274 dtp->data3 = data3;
46275- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46276+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46277 dtp->jif = jiffies;
46278 #endif
46279 return;
46280@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46281 "slow_ring buffer\n");
46282 goto debug_failed;
46283 }
46284- atomic_set(&phba->slow_ring_trc_cnt, 0);
46285+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46286 memset(phba->slow_ring_trc, 0,
46287 (sizeof(struct lpfc_debugfs_trc) *
46288 lpfc_debugfs_max_slow_ring_trc));
46289@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46290 "buffer\n");
46291 goto debug_failed;
46292 }
46293- atomic_set(&vport->disc_trc_cnt, 0);
46294+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46295
46296 snprintf(name, sizeof(name), "discovery_trace");
46297 vport->debug_disc_trc =
46298diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46299index 647f5bf..d0068b9 100644
46300--- a/drivers/scsi/lpfc/lpfc_init.c
46301+++ b/drivers/scsi/lpfc/lpfc_init.c
46302@@ -10952,8 +10952,10 @@ lpfc_init(void)
46303 "misc_register returned with status %d", error);
46304
46305 if (lpfc_enable_npiv) {
46306- lpfc_transport_functions.vport_create = lpfc_vport_create;
46307- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46308+ pax_open_kernel();
46309+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46310+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46311+ pax_close_kernel();
46312 }
46313 lpfc_transport_template =
46314 fc_attach_transport(&lpfc_transport_functions);
46315diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46316index c913e8c..d34a119 100644
46317--- a/drivers/scsi/lpfc/lpfc_scsi.c
46318+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46319@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46320 uint32_t evt_posted;
46321
46322 spin_lock_irqsave(&phba->hbalock, flags);
46323- atomic_inc(&phba->num_rsrc_err);
46324+ atomic_inc_unchecked(&phba->num_rsrc_err);
46325 phba->last_rsrc_error_time = jiffies;
46326
46327 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46328@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46329 unsigned long flags;
46330 struct lpfc_hba *phba = vport->phba;
46331 uint32_t evt_posted;
46332- atomic_inc(&phba->num_cmd_success);
46333+ atomic_inc_unchecked(&phba->num_cmd_success);
46334
46335 if (vport->cfg_lun_queue_depth <= queue_depth)
46336 return;
46337@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46338 unsigned long num_rsrc_err, num_cmd_success;
46339 int i;
46340
46341- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46342- num_cmd_success = atomic_read(&phba->num_cmd_success);
46343+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46344+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46345
46346 /*
46347 * The error and success command counters are global per
46348@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46349 }
46350 }
46351 lpfc_destroy_vport_work_array(phba, vports);
46352- atomic_set(&phba->num_rsrc_err, 0);
46353- atomic_set(&phba->num_cmd_success, 0);
46354+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46355+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46356 }
46357
46358 /**
46359@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46360 }
46361 }
46362 lpfc_destroy_vport_work_array(phba, vports);
46363- atomic_set(&phba->num_rsrc_err, 0);
46364- atomic_set(&phba->num_cmd_success, 0);
46365+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46366+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46367 }
46368
46369 /**
46370diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46371index 7f0af4f..193ac3e 100644
46372--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46373+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46374@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
46375 {
46376 struct scsi_device *sdev = to_scsi_device(dev);
46377 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
46378- static struct _raid_device *raid_device;
46379+ struct _raid_device *raid_device;
46380 unsigned long flags;
46381 Mpi2RaidVolPage0_t vol_pg0;
46382 Mpi2ConfigReply_t mpi_reply;
46383@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
46384 {
46385 struct scsi_device *sdev = to_scsi_device(dev);
46386 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
46387- static struct _raid_device *raid_device;
46388+ struct _raid_device *raid_device;
46389 unsigned long flags;
46390 Mpi2RaidVolPage0_t vol_pg0;
46391 Mpi2ConfigReply_t mpi_reply;
46392@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
46393 struct fw_event_work *fw_event)
46394 {
46395 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
46396- static struct _raid_device *raid_device;
46397+ struct _raid_device *raid_device;
46398 unsigned long flags;
46399 u16 handle;
46400
46401@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
46402 u64 sas_address;
46403 struct _sas_device *sas_device;
46404 struct _sas_node *expander_device;
46405- static struct _raid_device *raid_device;
46406+ struct _raid_device *raid_device;
46407 u8 retry_count;
46408 unsigned long flags;
46409
46410diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46411index 1eb7b028..b2a6080 100644
46412--- a/drivers/scsi/pmcraid.c
46413+++ b/drivers/scsi/pmcraid.c
46414@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46415 res->scsi_dev = scsi_dev;
46416 scsi_dev->hostdata = res;
46417 res->change_detected = 0;
46418- atomic_set(&res->read_failures, 0);
46419- atomic_set(&res->write_failures, 0);
46420+ atomic_set_unchecked(&res->read_failures, 0);
46421+ atomic_set_unchecked(&res->write_failures, 0);
46422 rc = 0;
46423 }
46424 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46425@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46426
46427 /* If this was a SCSI read/write command keep count of errors */
46428 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46429- atomic_inc(&res->read_failures);
46430+ atomic_inc_unchecked(&res->read_failures);
46431 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46432- atomic_inc(&res->write_failures);
46433+ atomic_inc_unchecked(&res->write_failures);
46434
46435 if (!RES_IS_GSCSI(res->cfg_entry) &&
46436 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46437@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46438 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46439 * hrrq_id assigned here in queuecommand
46440 */
46441- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46442+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46443 pinstance->num_hrrq;
46444 cmd->cmd_done = pmcraid_io_done;
46445
46446@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46447 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46448 * hrrq_id assigned here in queuecommand
46449 */
46450- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46451+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46452 pinstance->num_hrrq;
46453
46454 if (request_size) {
46455@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46456
46457 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46458 /* add resources only after host is added into system */
46459- if (!atomic_read(&pinstance->expose_resources))
46460+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46461 return;
46462
46463 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46464@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46465 init_waitqueue_head(&pinstance->reset_wait_q);
46466
46467 atomic_set(&pinstance->outstanding_cmds, 0);
46468- atomic_set(&pinstance->last_message_id, 0);
46469- atomic_set(&pinstance->expose_resources, 0);
46470+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46471+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46472
46473 INIT_LIST_HEAD(&pinstance->free_res_q);
46474 INIT_LIST_HEAD(&pinstance->used_res_q);
46475@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46476 /* Schedule worker thread to handle CCN and take care of adding and
46477 * removing devices to OS
46478 */
46479- atomic_set(&pinstance->expose_resources, 1);
46480+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46481 schedule_work(&pinstance->worker_q);
46482 return rc;
46483
46484diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46485index e1d150f..6c6df44 100644
46486--- a/drivers/scsi/pmcraid.h
46487+++ b/drivers/scsi/pmcraid.h
46488@@ -748,7 +748,7 @@ struct pmcraid_instance {
46489 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46490
46491 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46492- atomic_t last_message_id;
46493+ atomic_unchecked_t last_message_id;
46494
46495 /* configuration table */
46496 struct pmcraid_config_table *cfg_table;
46497@@ -777,7 +777,7 @@ struct pmcraid_instance {
46498 atomic_t outstanding_cmds;
46499
46500 /* should add/delete resources to mid-layer now ?*/
46501- atomic_t expose_resources;
46502+ atomic_unchecked_t expose_resources;
46503
46504
46505
46506@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46507 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46508 };
46509 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46510- atomic_t read_failures; /* count of failed READ commands */
46511- atomic_t write_failures; /* count of failed WRITE commands */
46512+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46513+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46514
46515 /* To indicate add/delete/modify during CCN */
46516 u8 change_detected;
46517diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46518index 5f174b8..98d32b0 100644
46519--- a/drivers/scsi/qla2xxx/qla_attr.c
46520+++ b/drivers/scsi/qla2xxx/qla_attr.c
46521@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46522 return 0;
46523 }
46524
46525-struct fc_function_template qla2xxx_transport_functions = {
46526+fc_function_template_no_const qla2xxx_transport_functions = {
46527
46528 .show_host_node_name = 1,
46529 .show_host_port_name = 1,
46530@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46531 .bsg_timeout = qla24xx_bsg_timeout,
46532 };
46533
46534-struct fc_function_template qla2xxx_transport_vport_functions = {
46535+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46536
46537 .show_host_node_name = 1,
46538 .show_host_port_name = 1,
46539diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46540index 4446bf5..9a3574d 100644
46541--- a/drivers/scsi/qla2xxx/qla_gbl.h
46542+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46543@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46544 struct device_attribute;
46545 extern struct device_attribute *qla2x00_host_attrs[];
46546 struct fc_function_template;
46547-extern struct fc_function_template qla2xxx_transport_functions;
46548-extern struct fc_function_template qla2xxx_transport_vport_functions;
46549+extern fc_function_template_no_const qla2xxx_transport_functions;
46550+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46551 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46552 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46553 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46554diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46555index 9f01bbb..5e1dcee 100644
46556--- a/drivers/scsi/qla2xxx/qla_os.c
46557+++ b/drivers/scsi/qla2xxx/qla_os.c
46558@@ -1572,8 +1572,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46559 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46560 /* Ok, a 64bit DMA mask is applicable. */
46561 ha->flags.enable_64bit_addressing = 1;
46562- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46563- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46564+ pax_open_kernel();
46565+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46566+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46567+ pax_close_kernel();
46568 return;
46569 }
46570 }
46571diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46572index 41327d4..feb03d479 100644
46573--- a/drivers/scsi/qla4xxx/ql4_def.h
46574+++ b/drivers/scsi/qla4xxx/ql4_def.h
46575@@ -296,7 +296,7 @@ struct ddb_entry {
46576 * (4000 only) */
46577 atomic_t relogin_timer; /* Max Time to wait for
46578 * relogin to complete */
46579- atomic_t relogin_retry_count; /* Num of times relogin has been
46580+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46581 * retried */
46582 uint32_t default_time2wait; /* Default Min time between
46583 * relogins (+aens) */
46584diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46585index f8a0a26..ec03cee 100644
46586--- a/drivers/scsi/qla4xxx/ql4_os.c
46587+++ b/drivers/scsi/qla4xxx/ql4_os.c
46588@@ -3066,12 +3066,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46589 */
46590 if (!iscsi_is_session_online(cls_sess)) {
46591 /* Reset retry relogin timer */
46592- atomic_inc(&ddb_entry->relogin_retry_count);
46593+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46594 DEBUG2(ql4_printk(KERN_INFO, ha,
46595 "%s: index[%d] relogin timed out-retrying"
46596 " relogin (%d), retry (%d)\n", __func__,
46597 ddb_entry->fw_ddb_index,
46598- atomic_read(&ddb_entry->relogin_retry_count),
46599+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46600 ddb_entry->default_time2wait + 4));
46601 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46602 atomic_set(&ddb_entry->retry_relogin_timer,
46603@@ -5209,7 +5209,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46604
46605 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46606 atomic_set(&ddb_entry->relogin_timer, 0);
46607- atomic_set(&ddb_entry->relogin_retry_count, 0);
46608+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46609 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46610 ddb_entry->default_relogin_timeout =
46611 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46612diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46613index eaa808e..95f8841 100644
46614--- a/drivers/scsi/scsi.c
46615+++ b/drivers/scsi/scsi.c
46616@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46617 unsigned long timeout;
46618 int rtn = 0;
46619
46620- atomic_inc(&cmd->device->iorequest_cnt);
46621+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46622
46623 /* check if the device is still usable */
46624 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46625diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46626index d1549b7..2f60767 100644
46627--- a/drivers/scsi/scsi_lib.c
46628+++ b/drivers/scsi/scsi_lib.c
46629@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46630 shost = sdev->host;
46631 scsi_init_cmd_errh(cmd);
46632 cmd->result = DID_NO_CONNECT << 16;
46633- atomic_inc(&cmd->device->iorequest_cnt);
46634+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46635
46636 /*
46637 * SCSI request completion path will do scsi_device_unbusy(),
46638@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46639
46640 INIT_LIST_HEAD(&cmd->eh_entry);
46641
46642- atomic_inc(&cmd->device->iodone_cnt);
46643+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46644 if (cmd->result)
46645- atomic_inc(&cmd->device->ioerr_cnt);
46646+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46647
46648 disposition = scsi_decide_disposition(cmd);
46649 if (disposition != SUCCESS &&
46650diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46651index 40c6394..62356c2 100644
46652--- a/drivers/scsi/scsi_sysfs.c
46653+++ b/drivers/scsi/scsi_sysfs.c
46654@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46655 char *buf) \
46656 { \
46657 struct scsi_device *sdev = to_scsi_device(dev); \
46658- unsigned long long count = atomic_read(&sdev->field); \
46659+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46660 return snprintf(buf, 20, "0x%llx\n", count); \
46661 } \
46662 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46663diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46664index 84a1fdf..693b0d6 100644
46665--- a/drivers/scsi/scsi_tgt_lib.c
46666+++ b/drivers/scsi/scsi_tgt_lib.c
46667@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46668 int err;
46669
46670 dprintk("%lx %u\n", uaddr, len);
46671- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46672+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46673 if (err) {
46674 /*
46675 * TODO: need to fixup sg_tablesize, max_segment_size,
46676diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46677index 4628fd5..a94a1c2 100644
46678--- a/drivers/scsi/scsi_transport_fc.c
46679+++ b/drivers/scsi/scsi_transport_fc.c
46680@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46681 * Netlink Infrastructure
46682 */
46683
46684-static atomic_t fc_event_seq;
46685+static atomic_unchecked_t fc_event_seq;
46686
46687 /**
46688 * fc_get_event_number - Obtain the next sequential FC event number
46689@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46690 u32
46691 fc_get_event_number(void)
46692 {
46693- return atomic_add_return(1, &fc_event_seq);
46694+ return atomic_add_return_unchecked(1, &fc_event_seq);
46695 }
46696 EXPORT_SYMBOL(fc_get_event_number);
46697
46698@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46699 {
46700 int error;
46701
46702- atomic_set(&fc_event_seq, 0);
46703+ atomic_set_unchecked(&fc_event_seq, 0);
46704
46705 error = transport_class_register(&fc_host_class);
46706 if (error)
46707@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46708 char *cp;
46709
46710 *val = simple_strtoul(buf, &cp, 0);
46711- if ((*cp && (*cp != '\n')) || (*val < 0))
46712+ if (*cp && (*cp != '\n'))
46713 return -EINVAL;
46714 /*
46715 * Check for overflow; dev_loss_tmo is u32
46716diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46717index e4a989f..293090c 100644
46718--- a/drivers/scsi/scsi_transport_iscsi.c
46719+++ b/drivers/scsi/scsi_transport_iscsi.c
46720@@ -79,7 +79,7 @@ struct iscsi_internal {
46721 struct transport_container session_cont;
46722 };
46723
46724-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46725+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46726 static struct workqueue_struct *iscsi_eh_timer_workq;
46727
46728 static DEFINE_IDA(iscsi_sess_ida);
46729@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46730 int err;
46731
46732 ihost = shost->shost_data;
46733- session->sid = atomic_add_return(1, &iscsi_session_nr);
46734+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
46735
46736 if (target_id == ISCSI_MAX_TARGET) {
46737 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
46738@@ -4077,7 +4077,7 @@ static __init int iscsi_transport_init(void)
46739 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
46740 ISCSI_TRANSPORT_VERSION);
46741
46742- atomic_set(&iscsi_session_nr, 0);
46743+ atomic_set_unchecked(&iscsi_session_nr, 0);
46744
46745 err = class_register(&iscsi_transport_class);
46746 if (err)
46747diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
46748index f379c7f..e8fc69c 100644
46749--- a/drivers/scsi/scsi_transport_srp.c
46750+++ b/drivers/scsi/scsi_transport_srp.c
46751@@ -33,7 +33,7 @@
46752 #include "scsi_transport_srp_internal.h"
46753
46754 struct srp_host_attrs {
46755- atomic_t next_port_id;
46756+ atomic_unchecked_t next_port_id;
46757 };
46758 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
46759
46760@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
46761 struct Scsi_Host *shost = dev_to_shost(dev);
46762 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
46763
46764- atomic_set(&srp_host->next_port_id, 0);
46765+ atomic_set_unchecked(&srp_host->next_port_id, 0);
46766 return 0;
46767 }
46768
46769@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
46770 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
46771 rport->roles = ids->roles;
46772
46773- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
46774+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
46775 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
46776
46777 transport_setup_device(&rport->dev);
46778diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
46779index 5693f6d7..b0bf05a 100644
46780--- a/drivers/scsi/sd.c
46781+++ b/drivers/scsi/sd.c
46782@@ -2934,7 +2934,7 @@ static int sd_probe(struct device *dev)
46783 sdkp->disk = gd;
46784 sdkp->index = index;
46785 atomic_set(&sdkp->openers, 0);
46786- atomic_set(&sdkp->device->ioerr_cnt, 0);
46787+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
46788
46789 if (!sdp->request_queue->rq_timeout) {
46790 if (sdp->type != TYPE_MOD)
46791diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
46792index df5e961..df6b97f 100644
46793--- a/drivers/scsi/sg.c
46794+++ b/drivers/scsi/sg.c
46795@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
46796 sdp->disk->disk_name,
46797 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
46798 NULL,
46799- (char *)arg);
46800+ (char __user *)arg);
46801 case BLKTRACESTART:
46802 return blk_trace_startstop(sdp->device->request_queue, 1);
46803 case BLKTRACESTOP:
46804diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
46805index 9e039c6..ae9e800 100644
46806--- a/drivers/spi/spi.c
46807+++ b/drivers/spi/spi.c
46808@@ -1762,7 +1762,7 @@ int spi_bus_unlock(struct spi_master *master)
46809 EXPORT_SYMBOL_GPL(spi_bus_unlock);
46810
46811 /* portable code must never pass more than 32 bytes */
46812-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
46813+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
46814
46815 static u8 *buf;
46816
46817diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
46818index 2c61783..4d49e4e 100644
46819--- a/drivers/staging/android/timed_output.c
46820+++ b/drivers/staging/android/timed_output.c
46821@@ -25,7 +25,7 @@
46822 #include "timed_output.h"
46823
46824 static struct class *timed_output_class;
46825-static atomic_t device_count;
46826+static atomic_unchecked_t device_count;
46827
46828 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
46829 char *buf)
46830@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
46831 timed_output_class = class_create(THIS_MODULE, "timed_output");
46832 if (IS_ERR(timed_output_class))
46833 return PTR_ERR(timed_output_class);
46834- atomic_set(&device_count, 0);
46835+ atomic_set_unchecked(&device_count, 0);
46836 timed_output_class->dev_groups = timed_output_groups;
46837 }
46838
46839@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
46840 if (ret < 0)
46841 return ret;
46842
46843- tdev->index = atomic_inc_return(&device_count);
46844+ tdev->index = atomic_inc_return_unchecked(&device_count);
46845 tdev->dev = device_create(timed_output_class, NULL,
46846 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
46847 if (IS_ERR(tdev->dev))
46848diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
46849index 0247a20..cb9595c 100644
46850--- a/drivers/staging/gdm724x/gdm_tty.c
46851+++ b/drivers/staging/gdm724x/gdm_tty.c
46852@@ -45,7 +45,7 @@
46853 #define gdm_tty_send_control(n, r, v, d, l) (\
46854 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
46855
46856-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
46857+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
46858
46859 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
46860 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
46861diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
46862index ef5064e..fce01db 100644
46863--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
46864+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
46865@@ -478,13 +478,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
46866 return 0;
46867 }
46868
46869-sfw_test_client_ops_t brw_test_client;
46870-void brw_init_test_client(void)
46871-{
46872- brw_test_client.tso_init = brw_client_init;
46873- brw_test_client.tso_fini = brw_client_fini;
46874- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
46875- brw_test_client.tso_done_rpc = brw_client_done_rpc;
46876+sfw_test_client_ops_t brw_test_client = {
46877+ .tso_init = brw_client_init,
46878+ .tso_fini = brw_client_fini,
46879+ .tso_prep_rpc = brw_client_prep_rpc,
46880+ .tso_done_rpc = brw_client_done_rpc,
46881 };
46882
46883 srpc_service_t brw_test_service;
46884diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
46885index 483c785..e1a2a7b 100644
46886--- a/drivers/staging/lustre/lnet/selftest/framework.c
46887+++ b/drivers/staging/lustre/lnet/selftest/framework.c
46888@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
46889
46890 extern sfw_test_client_ops_t ping_test_client;
46891 extern srpc_service_t ping_test_service;
46892-extern void ping_init_test_client(void);
46893 extern void ping_init_test_service(void);
46894
46895 extern sfw_test_client_ops_t brw_test_client;
46896 extern srpc_service_t brw_test_service;
46897-extern void brw_init_test_client(void);
46898 extern void brw_init_test_service(void);
46899
46900
46901@@ -1684,12 +1682,10 @@ sfw_startup (void)
46902 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
46903 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
46904
46905- brw_init_test_client();
46906 brw_init_test_service();
46907 rc = sfw_register_test(&brw_test_service, &brw_test_client);
46908 LASSERT (rc == 0);
46909
46910- ping_init_test_client();
46911 ping_init_test_service();
46912 rc = sfw_register_test(&ping_test_service, &ping_test_client);
46913 LASSERT (rc == 0);
46914diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
46915index f0f9194..b589047 100644
46916--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
46917+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
46918@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
46919 return 0;
46920 }
46921
46922-sfw_test_client_ops_t ping_test_client;
46923-void ping_init_test_client(void)
46924-{
46925- ping_test_client.tso_init = ping_client_init;
46926- ping_test_client.tso_fini = ping_client_fini;
46927- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
46928- ping_test_client.tso_done_rpc = ping_client_done_rpc;
46929-}
46930+sfw_test_client_ops_t ping_test_client = {
46931+ .tso_init = ping_client_init,
46932+ .tso_fini = ping_client_fini,
46933+ .tso_prep_rpc = ping_client_prep_rpc,
46934+ .tso_done_rpc = ping_client_done_rpc,
46935+};
46936
46937 srpc_service_t ping_test_service;
46938 void ping_init_test_service(void)
46939diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
46940index 7020d9c..0d3b580 100644
46941--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
46942+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
46943@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
46944 ldlm_completion_callback lcs_completion;
46945 ldlm_blocking_callback lcs_blocking;
46946 ldlm_glimpse_callback lcs_glimpse;
46947-};
46948+} __no_const;
46949
46950 /* ldlm_lockd.c */
46951 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
46952diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
46953index a612255..9a9e2dd 100644
46954--- a/drivers/staging/lustre/lustre/include/obd.h
46955+++ b/drivers/staging/lustre/lustre/include/obd.h
46956@@ -1417,7 +1417,7 @@ struct md_ops {
46957 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
46958 * wrapper function in include/linux/obd_class.h.
46959 */
46960-};
46961+} __no_const;
46962
46963 struct lsm_operations {
46964 void (*lsm_free)(struct lov_stripe_md *);
46965diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
46966index fc6c977..df1f956 100644
46967--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
46968+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
46969@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
46970 int LL_PROC_PROTO(proc_console_max_delay_cs)
46971 {
46972 int rc, max_delay_cs;
46973- ctl_table_t dummy = *table;
46974+ ctl_table_no_const dummy = *table;
46975 cfs_duration_t d;
46976
46977 dummy.data = &max_delay_cs;
46978@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
46979 int LL_PROC_PROTO(proc_console_min_delay_cs)
46980 {
46981 int rc, min_delay_cs;
46982- ctl_table_t dummy = *table;
46983+ ctl_table_no_const dummy = *table;
46984 cfs_duration_t d;
46985
46986 dummy.data = &min_delay_cs;
46987@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
46988 int LL_PROC_PROTO(proc_console_backoff)
46989 {
46990 int rc, backoff;
46991- ctl_table_t dummy = *table;
46992+ ctl_table_no_const dummy = *table;
46993
46994 dummy.data = &backoff;
46995 dummy.proc_handler = &proc_dointvec;
46996diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
46997index 3675020..e80d92c 100644
46998--- a/drivers/staging/media/solo6x10/solo6x10-core.c
46999+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47000@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47001
47002 static int solo_sysfs_init(struct solo_dev *solo_dev)
47003 {
47004- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47005+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47006 struct device *dev = &solo_dev->dev;
47007 const char *driver;
47008 int i;
47009diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47010index 3335941..2b26186 100644
47011--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47012+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47013@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47014
47015 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47016 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47017- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47018+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47019 if (p2m_id < 0)
47020 p2m_id = -p2m_id;
47021 }
47022diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47023index 6f91d2e..3f011d2 100644
47024--- a/drivers/staging/media/solo6x10/solo6x10.h
47025+++ b/drivers/staging/media/solo6x10/solo6x10.h
47026@@ -238,7 +238,7 @@ struct solo_dev {
47027
47028 /* P2M DMA Engine */
47029 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47030- atomic_t p2m_count;
47031+ atomic_unchecked_t p2m_count;
47032 int p2m_jiffies;
47033 unsigned int p2m_timeouts;
47034
47035diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47036index e14a1bb..9cb9bbe 100644
47037--- a/drivers/staging/octeon/ethernet-rx.c
47038+++ b/drivers/staging/octeon/ethernet-rx.c
47039@@ -419,11 +419,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47040 /* Increment RX stats for virtual ports */
47041 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47042 #ifdef CONFIG_64BIT
47043- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47044- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47045+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47046+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47047 #else
47048- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47049- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47050+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47051+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47052 #endif
47053 }
47054 netif_receive_skb(skb);
47055@@ -434,9 +434,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47056 dev->name);
47057 */
47058 #ifdef CONFIG_64BIT
47059- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47060+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47061 #else
47062- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47063+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47064 #endif
47065 dev_kfree_skb_irq(skb);
47066 }
47067diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47068index c3a90e7..023619a 100644
47069--- a/drivers/staging/octeon/ethernet.c
47070+++ b/drivers/staging/octeon/ethernet.c
47071@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47072 * since the RX tasklet also increments it.
47073 */
47074 #ifdef CONFIG_64BIT
47075- atomic64_add(rx_status.dropped_packets,
47076- (atomic64_t *)&priv->stats.rx_dropped);
47077+ atomic64_add_unchecked(rx_status.dropped_packets,
47078+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47079 #else
47080- atomic_add(rx_status.dropped_packets,
47081- (atomic_t *)&priv->stats.rx_dropped);
47082+ atomic_add_unchecked(rx_status.dropped_packets,
47083+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47084 #endif
47085 }
47086
47087diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
47088index 439c3c9..2d74293 100644
47089--- a/drivers/staging/rtl8188eu/include/hal_intf.h
47090+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
47091@@ -271,7 +271,7 @@ struct hal_ops {
47092 s32 (*c2h_handler)(struct adapter *padapter,
47093 struct c2h_evt_hdr *c2h_evt);
47094 c2h_id_filter c2h_id_filter_ccx;
47095-};
47096+} __no_const;
47097
47098 enum rt_eeprom_type {
47099 EEPROM_93C46,
47100diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
47101index eb6f0e5..e6a0958 100644
47102--- a/drivers/staging/rtl8188eu/include/rtw_io.h
47103+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
47104@@ -126,7 +126,7 @@ struct _io_ops {
47105 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
47106 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
47107 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
47108-};
47109+} __no_const;
47110
47111 struct io_req {
47112 struct list_head list;
47113diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47114index dc23395..cf7e9b1 100644
47115--- a/drivers/staging/rtl8712/rtl871x_io.h
47116+++ b/drivers/staging/rtl8712/rtl871x_io.h
47117@@ -108,7 +108,7 @@ struct _io_ops {
47118 u8 *pmem);
47119 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47120 u8 *pmem);
47121-};
47122+} __no_const;
47123
47124 struct io_req {
47125 struct list_head list;
47126diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47127index 1f5088b..0e59820 100644
47128--- a/drivers/staging/sbe-2t3e3/netdev.c
47129+++ b/drivers/staging/sbe-2t3e3/netdev.c
47130@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47131 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47132
47133 if (rlen)
47134- if (copy_to_user(data, &resp, rlen))
47135+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47136 return -EFAULT;
47137
47138 return 0;
47139diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47140index a863a98..d272795 100644
47141--- a/drivers/staging/usbip/vhci.h
47142+++ b/drivers/staging/usbip/vhci.h
47143@@ -83,7 +83,7 @@ struct vhci_hcd {
47144 unsigned resuming:1;
47145 unsigned long re_timeout;
47146
47147- atomic_t seqnum;
47148+ atomic_unchecked_t seqnum;
47149
47150 /*
47151 * NOTE:
47152diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47153index d7974cb..d78076b 100644
47154--- a/drivers/staging/usbip/vhci_hcd.c
47155+++ b/drivers/staging/usbip/vhci_hcd.c
47156@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47157
47158 spin_lock(&vdev->priv_lock);
47159
47160- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47161+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47162 if (priv->seqnum == 0xffff)
47163 dev_info(&urb->dev->dev, "seqnum max\n");
47164
47165@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47166 return -ENOMEM;
47167 }
47168
47169- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47170+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47171 if (unlink->seqnum == 0xffff)
47172 pr_info("seqnum max\n");
47173
47174@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47175 vdev->rhport = rhport;
47176 }
47177
47178- atomic_set(&vhci->seqnum, 0);
47179+ atomic_set_unchecked(&vhci->seqnum, 0);
47180 spin_lock_init(&vhci->lock);
47181
47182 hcd->power_budget = 0; /* no limit */
47183diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47184index d07fcb5..358e1e1 100644
47185--- a/drivers/staging/usbip/vhci_rx.c
47186+++ b/drivers/staging/usbip/vhci_rx.c
47187@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47188 if (!urb) {
47189 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47190 pr_info("max seqnum %d\n",
47191- atomic_read(&the_controller->seqnum));
47192+ atomic_read_unchecked(&the_controller->seqnum));
47193 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47194 return;
47195 }
47196diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47197index 8acff44..bdb2fca 100644
47198--- a/drivers/staging/vt6655/hostap.c
47199+++ b/drivers/staging/vt6655/hostap.c
47200@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47201 *
47202 */
47203
47204+static net_device_ops_no_const apdev_netdev_ops;
47205+
47206 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47207 {
47208 PSDevice apdev_priv;
47209 struct net_device *dev = pDevice->dev;
47210 int ret;
47211- const struct net_device_ops apdev_netdev_ops = {
47212- .ndo_start_xmit = pDevice->tx_80211,
47213- };
47214
47215 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47216
47217@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47218 *apdev_priv = *pDevice;
47219 eth_hw_addr_inherit(pDevice->apdev, dev);
47220
47221+ /* only half broken now */
47222+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47223 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47224
47225 pDevice->apdev->type = ARPHRD_IEEE80211;
47226diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47227index c699a30..b90a5fd 100644
47228--- a/drivers/staging/vt6656/hostap.c
47229+++ b/drivers/staging/vt6656/hostap.c
47230@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47231 *
47232 */
47233
47234+static net_device_ops_no_const apdev_netdev_ops;
47235+
47236 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47237 {
47238 struct vnt_private *apdev_priv;
47239 struct net_device *dev = pDevice->dev;
47240 int ret;
47241- const struct net_device_ops apdev_netdev_ops = {
47242- .ndo_start_xmit = pDevice->tx_80211,
47243- };
47244
47245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47246
47247@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47248 *apdev_priv = *pDevice;
47249 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47250
47251+ /* only half broken now */
47252+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47253 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47254
47255 pDevice->apdev->type = ARPHRD_IEEE80211;
47256diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47257index e51b09a..5ebac31 100644
47258--- a/drivers/target/sbp/sbp_target.c
47259+++ b/drivers/target/sbp/sbp_target.c
47260@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47261
47262 #define SESSION_MAINTENANCE_INTERVAL HZ
47263
47264-static atomic_t login_id = ATOMIC_INIT(0);
47265+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47266
47267 static void session_maintenance_work(struct work_struct *);
47268 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47269@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47270 login->lun = se_lun;
47271 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47272 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47273- login->login_id = atomic_inc_return(&login_id);
47274+ login->login_id = atomic_inc_return_unchecked(&login_id);
47275
47276 login->tgt_agt = sbp_target_agent_register(login);
47277 if (IS_ERR(login->tgt_agt)) {
47278diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47279index d90dbb0..6cbe585 100644
47280--- a/drivers/target/target_core_device.c
47281+++ b/drivers/target/target_core_device.c
47282@@ -1431,7 +1431,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47283 spin_lock_init(&dev->se_tmr_lock);
47284 spin_lock_init(&dev->qf_cmd_lock);
47285 sema_init(&dev->caw_sem, 1);
47286- atomic_set(&dev->dev_ordered_id, 0);
47287+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47288 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47289 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47290 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47291diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47292index 81e945e..e40c92f 100644
47293--- a/drivers/target/target_core_transport.c
47294+++ b/drivers/target/target_core_transport.c
47295@@ -1137,7 +1137,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47296 * Used to determine when ORDERED commands should go from
47297 * Dormant to Active status.
47298 */
47299- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47300+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47301 smp_mb__after_atomic_inc();
47302 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47303 cmd->se_ordered_id, cmd->sam_task_attr,
47304diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47305index 33f83fe..d80f8e1 100644
47306--- a/drivers/tty/cyclades.c
47307+++ b/drivers/tty/cyclades.c
47308@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47309 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47310 info->port.count);
47311 #endif
47312- info->port.count++;
47313+ atomic_inc(&info->port.count);
47314 #ifdef CY_DEBUG_COUNT
47315 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47316- current->pid, info->port.count);
47317+ current->pid, atomic_read(&info->port.count));
47318 #endif
47319
47320 /*
47321@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47322 for (j = 0; j < cy_card[i].nports; j++) {
47323 info = &cy_card[i].ports[j];
47324
47325- if (info->port.count) {
47326+ if (atomic_read(&info->port.count)) {
47327 /* XXX is the ldisc num worth this? */
47328 struct tty_struct *tty;
47329 struct tty_ldisc *ld;
47330diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47331index 9eba119..5070303 100644
47332--- a/drivers/tty/hvc/hvc_console.c
47333+++ b/drivers/tty/hvc/hvc_console.c
47334@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47335
47336 spin_lock_irqsave(&hp->port.lock, flags);
47337 /* Check and then increment for fast path open. */
47338- if (hp->port.count++ > 0) {
47339+ if (atomic_inc_return(&hp->port.count) > 1) {
47340 spin_unlock_irqrestore(&hp->port.lock, flags);
47341 hvc_kick();
47342 return 0;
47343@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47344
47345 spin_lock_irqsave(&hp->port.lock, flags);
47346
47347- if (--hp->port.count == 0) {
47348+ if (atomic_dec_return(&hp->port.count) == 0) {
47349 spin_unlock_irqrestore(&hp->port.lock, flags);
47350 /* We are done with the tty pointer now. */
47351 tty_port_tty_set(&hp->port, NULL);
47352@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47353 */
47354 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47355 } else {
47356- if (hp->port.count < 0)
47357+ if (atomic_read(&hp->port.count) < 0)
47358 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47359- hp->vtermno, hp->port.count);
47360+ hp->vtermno, atomic_read(&hp->port.count));
47361 spin_unlock_irqrestore(&hp->port.lock, flags);
47362 }
47363 }
47364@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
47365 * open->hangup case this can be called after the final close so prevent
47366 * that from happening for now.
47367 */
47368- if (hp->port.count <= 0) {
47369+ if (atomic_read(&hp->port.count) <= 0) {
47370 spin_unlock_irqrestore(&hp->port.lock, flags);
47371 return;
47372 }
47373
47374- hp->port.count = 0;
47375+ atomic_set(&hp->port.count, 0);
47376 spin_unlock_irqrestore(&hp->port.lock, flags);
47377 tty_port_tty_set(&hp->port, NULL);
47378
47379@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47380 return -EPIPE;
47381
47382 /* FIXME what's this (unprotected) check for? */
47383- if (hp->port.count <= 0)
47384+ if (atomic_read(&hp->port.count) <= 0)
47385 return -EIO;
47386
47387 spin_lock_irqsave(&hp->lock, flags);
47388diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47389index 81e939e..95ead10 100644
47390--- a/drivers/tty/hvc/hvcs.c
47391+++ b/drivers/tty/hvc/hvcs.c
47392@@ -83,6 +83,7 @@
47393 #include <asm/hvcserver.h>
47394 #include <asm/uaccess.h>
47395 #include <asm/vio.h>
47396+#include <asm/local.h>
47397
47398 /*
47399 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47400@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47401
47402 spin_lock_irqsave(&hvcsd->lock, flags);
47403
47404- if (hvcsd->port.count > 0) {
47405+ if (atomic_read(&hvcsd->port.count) > 0) {
47406 spin_unlock_irqrestore(&hvcsd->lock, flags);
47407 printk(KERN_INFO "HVCS: vterm state unchanged. "
47408 "The hvcs device node is still in use.\n");
47409@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47410 }
47411 }
47412
47413- hvcsd->port.count = 0;
47414+ atomic_set(&hvcsd->port.count, 0);
47415 hvcsd->port.tty = tty;
47416 tty->driver_data = hvcsd;
47417
47418@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47419 unsigned long flags;
47420
47421 spin_lock_irqsave(&hvcsd->lock, flags);
47422- hvcsd->port.count++;
47423+ atomic_inc(&hvcsd->port.count);
47424 hvcsd->todo_mask |= HVCS_SCHED_READ;
47425 spin_unlock_irqrestore(&hvcsd->lock, flags);
47426
47427@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47428 hvcsd = tty->driver_data;
47429
47430 spin_lock_irqsave(&hvcsd->lock, flags);
47431- if (--hvcsd->port.count == 0) {
47432+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47433
47434 vio_disable_interrupts(hvcsd->vdev);
47435
47436@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47437
47438 free_irq(irq, hvcsd);
47439 return;
47440- } else if (hvcsd->port.count < 0) {
47441+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47442 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47443 " is missmanaged.\n",
47444- hvcsd->vdev->unit_address, hvcsd->port.count);
47445+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47446 }
47447
47448 spin_unlock_irqrestore(&hvcsd->lock, flags);
47449@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47450
47451 spin_lock_irqsave(&hvcsd->lock, flags);
47452 /* Preserve this so that we know how many kref refs to put */
47453- temp_open_count = hvcsd->port.count;
47454+ temp_open_count = atomic_read(&hvcsd->port.count);
47455
47456 /*
47457 * Don't kref put inside the spinlock because the destruction
47458@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47459 tty->driver_data = NULL;
47460 hvcsd->port.tty = NULL;
47461
47462- hvcsd->port.count = 0;
47463+ atomic_set(&hvcsd->port.count, 0);
47464
47465 /* This will drop any buffered data on the floor which is OK in a hangup
47466 * scenario. */
47467@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47468 * the middle of a write operation? This is a crummy place to do this
47469 * but we want to keep it all in the spinlock.
47470 */
47471- if (hvcsd->port.count <= 0) {
47472+ if (atomic_read(&hvcsd->port.count) <= 0) {
47473 spin_unlock_irqrestore(&hvcsd->lock, flags);
47474 return -ENODEV;
47475 }
47476@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47477 {
47478 struct hvcs_struct *hvcsd = tty->driver_data;
47479
47480- if (!hvcsd || hvcsd->port.count <= 0)
47481+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47482 return 0;
47483
47484 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47485diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47486index 4190199..48f2920 100644
47487--- a/drivers/tty/hvc/hvsi.c
47488+++ b/drivers/tty/hvc/hvsi.c
47489@@ -85,7 +85,7 @@ struct hvsi_struct {
47490 int n_outbuf;
47491 uint32_t vtermno;
47492 uint32_t virq;
47493- atomic_t seqno; /* HVSI packet sequence number */
47494+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47495 uint16_t mctrl;
47496 uint8_t state; /* HVSI protocol state */
47497 uint8_t flags;
47498@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47499
47500 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47501 packet.hdr.len = sizeof(struct hvsi_query_response);
47502- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47503+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47504 packet.verb = VSV_SEND_VERSION_NUMBER;
47505 packet.u.version = HVSI_VERSION;
47506 packet.query_seqno = query_seqno+1;
47507@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47508
47509 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47510 packet.hdr.len = sizeof(struct hvsi_query);
47511- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47512+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47513 packet.verb = verb;
47514
47515 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47516@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47517 int wrote;
47518
47519 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47520- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47521+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47522 packet.hdr.len = sizeof(struct hvsi_control);
47523 packet.verb = VSV_SET_MODEM_CTL;
47524 packet.mask = HVSI_TSDTR;
47525@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47526 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47527
47528 packet.hdr.type = VS_DATA_PACKET_HEADER;
47529- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47530+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47531 packet.hdr.len = count + sizeof(struct hvsi_header);
47532 memcpy(&packet.data, buf, count);
47533
47534@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47535 struct hvsi_control packet __ALIGNED__;
47536
47537 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47538- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47539+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47540 packet.hdr.len = 6;
47541 packet.verb = VSV_CLOSE_PROTOCOL;
47542
47543diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47544index ac27671..0f627ee 100644
47545--- a/drivers/tty/hvc/hvsi_lib.c
47546+++ b/drivers/tty/hvc/hvsi_lib.c
47547@@ -9,7 +9,7 @@
47548
47549 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47550 {
47551- packet->seqno = atomic_inc_return(&pv->seqno);
47552+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47553
47554 /* Assumes that always succeeds, works in practice */
47555 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47556@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47557
47558 /* Reset state */
47559 pv->established = 0;
47560- atomic_set(&pv->seqno, 0);
47561+ atomic_set_unchecked(&pv->seqno, 0);
47562
47563 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47564
47565@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47566 pv->mctrl_update = 0;
47567 q.hdr.type = VS_QUERY_PACKET_HEADER;
47568 q.hdr.len = sizeof(struct hvsi_query);
47569- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47570+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47571 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47572 rc = hvsi_send_packet(pv, &q.hdr);
47573 if (rc <= 0) {
47574diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47575index 8fd72ff..34a0bed 100644
47576--- a/drivers/tty/ipwireless/tty.c
47577+++ b/drivers/tty/ipwireless/tty.c
47578@@ -29,6 +29,7 @@
47579 #include <linux/tty_driver.h>
47580 #include <linux/tty_flip.h>
47581 #include <linux/uaccess.h>
47582+#include <asm/local.h>
47583
47584 #include "tty.h"
47585 #include "network.h"
47586@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47587 mutex_unlock(&tty->ipw_tty_mutex);
47588 return -ENODEV;
47589 }
47590- if (tty->port.count == 0)
47591+ if (atomic_read(&tty->port.count) == 0)
47592 tty->tx_bytes_queued = 0;
47593
47594- tty->port.count++;
47595+ atomic_inc(&tty->port.count);
47596
47597 tty->port.tty = linux_tty;
47598 linux_tty->driver_data = tty;
47599@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47600
47601 static void do_ipw_close(struct ipw_tty *tty)
47602 {
47603- tty->port.count--;
47604-
47605- if (tty->port.count == 0) {
47606+ if (atomic_dec_return(&tty->port.count) == 0) {
47607 struct tty_struct *linux_tty = tty->port.tty;
47608
47609 if (linux_tty != NULL) {
47610@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47611 return;
47612
47613 mutex_lock(&tty->ipw_tty_mutex);
47614- if (tty->port.count == 0) {
47615+ if (atomic_read(&tty->port.count) == 0) {
47616 mutex_unlock(&tty->ipw_tty_mutex);
47617 return;
47618 }
47619@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47620
47621 mutex_lock(&tty->ipw_tty_mutex);
47622
47623- if (!tty->port.count) {
47624+ if (!atomic_read(&tty->port.count)) {
47625 mutex_unlock(&tty->ipw_tty_mutex);
47626 return;
47627 }
47628@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47629 return -ENODEV;
47630
47631 mutex_lock(&tty->ipw_tty_mutex);
47632- if (!tty->port.count) {
47633+ if (!atomic_read(&tty->port.count)) {
47634 mutex_unlock(&tty->ipw_tty_mutex);
47635 return -EINVAL;
47636 }
47637@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47638 if (!tty)
47639 return -ENODEV;
47640
47641- if (!tty->port.count)
47642+ if (!atomic_read(&tty->port.count))
47643 return -EINVAL;
47644
47645 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47646@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47647 if (!tty)
47648 return 0;
47649
47650- if (!tty->port.count)
47651+ if (!atomic_read(&tty->port.count))
47652 return 0;
47653
47654 return tty->tx_bytes_queued;
47655@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47656 if (!tty)
47657 return -ENODEV;
47658
47659- if (!tty->port.count)
47660+ if (!atomic_read(&tty->port.count))
47661 return -EINVAL;
47662
47663 return get_control_lines(tty);
47664@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47665 if (!tty)
47666 return -ENODEV;
47667
47668- if (!tty->port.count)
47669+ if (!atomic_read(&tty->port.count))
47670 return -EINVAL;
47671
47672 return set_control_lines(tty, set, clear);
47673@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47674 if (!tty)
47675 return -ENODEV;
47676
47677- if (!tty->port.count)
47678+ if (!atomic_read(&tty->port.count))
47679 return -EINVAL;
47680
47681 /* FIXME: Exactly how is the tty object locked here .. */
47682@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47683 * are gone */
47684 mutex_lock(&ttyj->ipw_tty_mutex);
47685 }
47686- while (ttyj->port.count)
47687+ while (atomic_read(&ttyj->port.count))
47688 do_ipw_close(ttyj);
47689 ipwireless_disassociate_network_ttys(network,
47690 ttyj->channel_idx);
47691diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47692index 1deaca4..c8582d4 100644
47693--- a/drivers/tty/moxa.c
47694+++ b/drivers/tty/moxa.c
47695@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47696 }
47697
47698 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47699- ch->port.count++;
47700+ atomic_inc(&ch->port.count);
47701 tty->driver_data = ch;
47702 tty_port_tty_set(&ch->port, tty);
47703 mutex_lock(&ch->port.mutex);
47704diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47705index c0f76da..d974c32 100644
47706--- a/drivers/tty/n_gsm.c
47707+++ b/drivers/tty/n_gsm.c
47708@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47709 spin_lock_init(&dlci->lock);
47710 mutex_init(&dlci->mutex);
47711 dlci->fifo = &dlci->_fifo;
47712- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47713+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47714 kfree(dlci);
47715 return NULL;
47716 }
47717@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47718 struct gsm_dlci *dlci = tty->driver_data;
47719 struct tty_port *port = &dlci->port;
47720
47721- port->count++;
47722+ atomic_inc(&port->count);
47723 dlci_get(dlci);
47724 dlci_get(dlci->gsm->dlci[0]);
47725 mux_get(dlci->gsm);
47726diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47727index 7a744b6..6aa4aa9 100644
47728--- a/drivers/tty/n_tty.c
47729+++ b/drivers/tty/n_tty.c
47730@@ -2498,6 +2498,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47731 {
47732 *ops = tty_ldisc_N_TTY;
47733 ops->owner = NULL;
47734- ops->refcount = ops->flags = 0;
47735+ atomic_set(&ops->refcount, 0);
47736+ ops->flags = 0;
47737 }
47738 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47739diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47740index 25c9bc7..24077b7 100644
47741--- a/drivers/tty/pty.c
47742+++ b/drivers/tty/pty.c
47743@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
47744 panic("Couldn't register Unix98 pts driver");
47745
47746 /* Now create the /dev/ptmx special device */
47747+ pax_open_kernel();
47748 tty_default_fops(&ptmx_fops);
47749- ptmx_fops.open = ptmx_open;
47750+ *(void **)&ptmx_fops.open = ptmx_open;
47751+ pax_close_kernel();
47752
47753 cdev_init(&ptmx_cdev, &ptmx_fops);
47754 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47755diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47756index 354564e..fe50d9a 100644
47757--- a/drivers/tty/rocket.c
47758+++ b/drivers/tty/rocket.c
47759@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47760 tty->driver_data = info;
47761 tty_port_tty_set(port, tty);
47762
47763- if (port->count++ == 0) {
47764+ if (atomic_inc_return(&port->count) == 1) {
47765 atomic_inc(&rp_num_ports_open);
47766
47767 #ifdef ROCKET_DEBUG_OPEN
47768@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47769 #endif
47770 }
47771 #ifdef ROCKET_DEBUG_OPEN
47772- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47773+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47774 #endif
47775
47776 /*
47777@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47778 spin_unlock_irqrestore(&info->port.lock, flags);
47779 return;
47780 }
47781- if (info->port.count)
47782+ if (atomic_read(&info->port.count))
47783 atomic_dec(&rp_num_ports_open);
47784 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47785 spin_unlock_irqrestore(&info->port.lock, flags);
47786diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47787index 1274499..f541382 100644
47788--- a/drivers/tty/serial/ioc4_serial.c
47789+++ b/drivers/tty/serial/ioc4_serial.c
47790@@ -437,7 +437,7 @@ struct ioc4_soft {
47791 } is_intr_info[MAX_IOC4_INTR_ENTS];
47792
47793 /* Number of entries active in the above array */
47794- atomic_t is_num_intrs;
47795+ atomic_unchecked_t is_num_intrs;
47796 } is_intr_type[IOC4_NUM_INTR_TYPES];
47797
47798 /* is_ir_lock must be held while
47799@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47800 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47801 || (type == IOC4_OTHER_INTR_TYPE)));
47802
47803- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47804+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47805 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47806
47807 /* Save off the lower level interrupt handler */
47808@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47809
47810 soft = arg;
47811 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47812- num_intrs = (int)atomic_read(
47813+ num_intrs = (int)atomic_read_unchecked(
47814 &soft->is_intr_type[intr_type].is_num_intrs);
47815
47816 this_mir = this_ir = pending_intrs(soft, intr_type);
47817diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47818index a260cde..6b2b5ce 100644
47819--- a/drivers/tty/serial/kgdboc.c
47820+++ b/drivers/tty/serial/kgdboc.c
47821@@ -24,8 +24,9 @@
47822 #define MAX_CONFIG_LEN 40
47823
47824 static struct kgdb_io kgdboc_io_ops;
47825+static struct kgdb_io kgdboc_io_ops_console;
47826
47827-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47828+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47829 static int configured = -1;
47830
47831 static char config[MAX_CONFIG_LEN];
47832@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47833 kgdboc_unregister_kbd();
47834 if (configured == 1)
47835 kgdb_unregister_io_module(&kgdboc_io_ops);
47836+ else if (configured == 2)
47837+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47838 }
47839
47840 static int configure_kgdboc(void)
47841@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47842 int err;
47843 char *cptr = config;
47844 struct console *cons;
47845+ int is_console = 0;
47846
47847 err = kgdboc_option_setup(config);
47848 if (err || !strlen(config) || isspace(config[0]))
47849 goto noconfig;
47850
47851 err = -ENODEV;
47852- kgdboc_io_ops.is_console = 0;
47853 kgdb_tty_driver = NULL;
47854
47855 kgdboc_use_kms = 0;
47856@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47857 int idx;
47858 if (cons->device && cons->device(cons, &idx) == p &&
47859 idx == tty_line) {
47860- kgdboc_io_ops.is_console = 1;
47861+ is_console = 1;
47862 break;
47863 }
47864 cons = cons->next;
47865@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47866 kgdb_tty_line = tty_line;
47867
47868 do_register:
47869- err = kgdb_register_io_module(&kgdboc_io_ops);
47870+ if (is_console) {
47871+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47872+ configured = 2;
47873+ } else {
47874+ err = kgdb_register_io_module(&kgdboc_io_ops);
47875+ configured = 1;
47876+ }
47877 if (err)
47878 goto noconfig;
47879
47880@@ -205,8 +214,6 @@ do_register:
47881 if (err)
47882 goto nmi_con_failed;
47883
47884- configured = 1;
47885-
47886 return 0;
47887
47888 nmi_con_failed:
47889@@ -223,7 +230,7 @@ noconfig:
47890 static int __init init_kgdboc(void)
47891 {
47892 /* Already configured? */
47893- if (configured == 1)
47894+ if (configured >= 1)
47895 return 0;
47896
47897 return configure_kgdboc();
47898@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
47899 if (config[len - 1] == '\n')
47900 config[len - 1] = '\0';
47901
47902- if (configured == 1)
47903+ if (configured >= 1)
47904 cleanup_kgdboc();
47905
47906 /* Go and configure with the new params. */
47907@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
47908 .post_exception = kgdboc_post_exp_handler,
47909 };
47910
47911+static struct kgdb_io kgdboc_io_ops_console = {
47912+ .name = "kgdboc",
47913+ .read_char = kgdboc_get_char,
47914+ .write_char = kgdboc_put_char,
47915+ .pre_exception = kgdboc_pre_exp_handler,
47916+ .post_exception = kgdboc_post_exp_handler,
47917+ .is_console = 1
47918+};
47919+
47920 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
47921 /* This is only available if kgdboc is a built in for early debugging */
47922 static int __init kgdboc_early_init(char *opt)
47923diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
47924index b5d779c..3622cfe 100644
47925--- a/drivers/tty/serial/msm_serial.c
47926+++ b/drivers/tty/serial/msm_serial.c
47927@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
47928 .cons = MSM_CONSOLE,
47929 };
47930
47931-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
47932+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
47933
47934 static const struct of_device_id msm_uartdm_table[] = {
47935 { .compatible = "qcom,msm-uartdm" },
47936@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
47937 int irq;
47938
47939 if (pdev->id == -1)
47940- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
47941+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
47942
47943 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
47944 return -ENXIO;
47945diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
47946index f3dfa19..342f2ff 100644
47947--- a/drivers/tty/serial/samsung.c
47948+++ b/drivers/tty/serial/samsung.c
47949@@ -456,11 +456,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
47950 }
47951 }
47952
47953+static int s3c64xx_serial_startup(struct uart_port *port);
47954 static int s3c24xx_serial_startup(struct uart_port *port)
47955 {
47956 struct s3c24xx_uart_port *ourport = to_ourport(port);
47957 int ret;
47958
47959+ /* Startup sequence is different for s3c64xx and higher SoC's */
47960+ if (s3c24xx_serial_has_interrupt_mask(port))
47961+ return s3c64xx_serial_startup(port);
47962+
47963 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
47964 port->mapbase, port->membase);
47965
47966@@ -1127,10 +1132,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
47967 /* setup info for port */
47968 port->dev = &platdev->dev;
47969
47970- /* Startup sequence is different for s3c64xx and higher SoC's */
47971- if (s3c24xx_serial_has_interrupt_mask(port))
47972- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
47973-
47974 port->uartclk = 1;
47975
47976 if (cfg->uart_flags & UPF_CONS_FLOW) {
47977diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
47978index 0f02351..07c59c5 100644
47979--- a/drivers/tty/serial/serial_core.c
47980+++ b/drivers/tty/serial/serial_core.c
47981@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
47982 uart_flush_buffer(tty);
47983 uart_shutdown(tty, state);
47984 spin_lock_irqsave(&port->lock, flags);
47985- port->count = 0;
47986+ atomic_set(&port->count, 0);
47987 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
47988 spin_unlock_irqrestore(&port->lock, flags);
47989 tty_port_tty_set(port, NULL);
47990@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47991 goto end;
47992 }
47993
47994- port->count++;
47995+ atomic_inc(&port->count);
47996 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
47997 retval = -ENXIO;
47998 goto err_dec_count;
47999@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48000 /*
48001 * Make sure the device is in D0 state.
48002 */
48003- if (port->count == 1)
48004+ if (atomic_read(&port->count) == 1)
48005 uart_change_pm(state, UART_PM_STATE_ON);
48006
48007 /*
48008@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48009 end:
48010 return retval;
48011 err_dec_count:
48012- port->count--;
48013+ atomic_inc(&port->count);
48014 mutex_unlock(&port->mutex);
48015 goto end;
48016 }
48017diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48018index e1ce141..6d4ed80 100644
48019--- a/drivers/tty/synclink.c
48020+++ b/drivers/tty/synclink.c
48021@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48022
48023 if (debug_level >= DEBUG_LEVEL_INFO)
48024 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48025- __FILE__,__LINE__, info->device_name, info->port.count);
48026+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48027
48028 if (tty_port_close_start(&info->port, tty, filp) == 0)
48029 goto cleanup;
48030@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48031 cleanup:
48032 if (debug_level >= DEBUG_LEVEL_INFO)
48033 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48034- tty->driver->name, info->port.count);
48035+ tty->driver->name, atomic_read(&info->port.count));
48036
48037 } /* end of mgsl_close() */
48038
48039@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48040
48041 mgsl_flush_buffer(tty);
48042 shutdown(info);
48043-
48044- info->port.count = 0;
48045+
48046+ atomic_set(&info->port.count, 0);
48047 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48048 info->port.tty = NULL;
48049
48050@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48051
48052 if (debug_level >= DEBUG_LEVEL_INFO)
48053 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48054- __FILE__,__LINE__, tty->driver->name, port->count );
48055+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48056
48057 spin_lock_irqsave(&info->irq_spinlock, flags);
48058 if (!tty_hung_up_p(filp)) {
48059 extra_count = true;
48060- port->count--;
48061+ atomic_dec(&port->count);
48062 }
48063 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48064 port->blocked_open++;
48065@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48066
48067 if (debug_level >= DEBUG_LEVEL_INFO)
48068 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48069- __FILE__,__LINE__, tty->driver->name, port->count );
48070+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48071
48072 tty_unlock(tty);
48073 schedule();
48074@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48075
48076 /* FIXME: Racy on hangup during close wait */
48077 if (extra_count)
48078- port->count++;
48079+ atomic_inc(&port->count);
48080 port->blocked_open--;
48081
48082 if (debug_level >= DEBUG_LEVEL_INFO)
48083 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48084- __FILE__,__LINE__, tty->driver->name, port->count );
48085+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48086
48087 if (!retval)
48088 port->flags |= ASYNC_NORMAL_ACTIVE;
48089@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48090
48091 if (debug_level >= DEBUG_LEVEL_INFO)
48092 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48093- __FILE__,__LINE__,tty->driver->name, info->port.count);
48094+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48095
48096 /* If port is closing, signal caller to try again */
48097 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48098@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48099 spin_unlock_irqrestore(&info->netlock, flags);
48100 goto cleanup;
48101 }
48102- info->port.count++;
48103+ atomic_inc(&info->port.count);
48104 spin_unlock_irqrestore(&info->netlock, flags);
48105
48106- if (info->port.count == 1) {
48107+ if (atomic_read(&info->port.count) == 1) {
48108 /* 1st open on this device, init hardware */
48109 retval = startup(info);
48110 if (retval < 0)
48111@@ -3446,8 +3446,8 @@ cleanup:
48112 if (retval) {
48113 if (tty->count == 1)
48114 info->port.tty = NULL; /* tty layer will release tty struct */
48115- if(info->port.count)
48116- info->port.count--;
48117+ if (atomic_read(&info->port.count))
48118+ atomic_dec(&info->port.count);
48119 }
48120
48121 return retval;
48122@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48123 unsigned short new_crctype;
48124
48125 /* return error if TTY interface open */
48126- if (info->port.count)
48127+ if (atomic_read(&info->port.count))
48128 return -EBUSY;
48129
48130 switch (encoding)
48131@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48132
48133 /* arbitrate between network and tty opens */
48134 spin_lock_irqsave(&info->netlock, flags);
48135- if (info->port.count != 0 || info->netcount != 0) {
48136+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48137 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48138 spin_unlock_irqrestore(&info->netlock, flags);
48139 return -EBUSY;
48140@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48141 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48142
48143 /* return error if TTY interface open */
48144- if (info->port.count)
48145+ if (atomic_read(&info->port.count))
48146 return -EBUSY;
48147
48148 if (cmd != SIOCWANDEV)
48149diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48150index 1abf946..1ee34fc 100644
48151--- a/drivers/tty/synclink_gt.c
48152+++ b/drivers/tty/synclink_gt.c
48153@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48154 tty->driver_data = info;
48155 info->port.tty = tty;
48156
48157- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48158+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48159
48160 /* If port is closing, signal caller to try again */
48161 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48162@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48163 mutex_unlock(&info->port.mutex);
48164 goto cleanup;
48165 }
48166- info->port.count++;
48167+ atomic_inc(&info->port.count);
48168 spin_unlock_irqrestore(&info->netlock, flags);
48169
48170- if (info->port.count == 1) {
48171+ if (atomic_read(&info->port.count) == 1) {
48172 /* 1st open on this device, init hardware */
48173 retval = startup(info);
48174 if (retval < 0) {
48175@@ -715,8 +715,8 @@ cleanup:
48176 if (retval) {
48177 if (tty->count == 1)
48178 info->port.tty = NULL; /* tty layer will release tty struct */
48179- if(info->port.count)
48180- info->port.count--;
48181+ if(atomic_read(&info->port.count))
48182+ atomic_dec(&info->port.count);
48183 }
48184
48185 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48186@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48187
48188 if (sanity_check(info, tty->name, "close"))
48189 return;
48190- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48191+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48192
48193 if (tty_port_close_start(&info->port, tty, filp) == 0)
48194 goto cleanup;
48195@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48196 tty_port_close_end(&info->port, tty);
48197 info->port.tty = NULL;
48198 cleanup:
48199- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48200+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48201 }
48202
48203 static void hangup(struct tty_struct *tty)
48204@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48205 shutdown(info);
48206
48207 spin_lock_irqsave(&info->port.lock, flags);
48208- info->port.count = 0;
48209+ atomic_set(&info->port.count, 0);
48210 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48211 info->port.tty = NULL;
48212 spin_unlock_irqrestore(&info->port.lock, flags);
48213@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48214 unsigned short new_crctype;
48215
48216 /* return error if TTY interface open */
48217- if (info->port.count)
48218+ if (atomic_read(&info->port.count))
48219 return -EBUSY;
48220
48221 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48222@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48223
48224 /* arbitrate between network and tty opens */
48225 spin_lock_irqsave(&info->netlock, flags);
48226- if (info->port.count != 0 || info->netcount != 0) {
48227+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48228 DBGINFO(("%s hdlc_open busy\n", dev->name));
48229 spin_unlock_irqrestore(&info->netlock, flags);
48230 return -EBUSY;
48231@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48232 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48233
48234 /* return error if TTY interface open */
48235- if (info->port.count)
48236+ if (atomic_read(&info->port.count))
48237 return -EBUSY;
48238
48239 if (cmd != SIOCWANDEV)
48240@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48241 if (port == NULL)
48242 continue;
48243 spin_lock(&port->lock);
48244- if ((port->port.count || port->netcount) &&
48245+ if ((atomic_read(&port->port.count) || port->netcount) &&
48246 port->pending_bh && !port->bh_running &&
48247 !port->bh_requested) {
48248 DBGISR(("%s bh queued\n", port->device_name));
48249@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48250 spin_lock_irqsave(&info->lock, flags);
48251 if (!tty_hung_up_p(filp)) {
48252 extra_count = true;
48253- port->count--;
48254+ atomic_dec(&port->count);
48255 }
48256 spin_unlock_irqrestore(&info->lock, flags);
48257 port->blocked_open++;
48258@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48259 remove_wait_queue(&port->open_wait, &wait);
48260
48261 if (extra_count)
48262- port->count++;
48263+ atomic_inc(&port->count);
48264 port->blocked_open--;
48265
48266 if (!retval)
48267diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48268index dc6e969..5dc8786 100644
48269--- a/drivers/tty/synclinkmp.c
48270+++ b/drivers/tty/synclinkmp.c
48271@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48272
48273 if (debug_level >= DEBUG_LEVEL_INFO)
48274 printk("%s(%d):%s open(), old ref count = %d\n",
48275- __FILE__,__LINE__,tty->driver->name, info->port.count);
48276+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48277
48278 /* If port is closing, signal caller to try again */
48279 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48280@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48281 spin_unlock_irqrestore(&info->netlock, flags);
48282 goto cleanup;
48283 }
48284- info->port.count++;
48285+ atomic_inc(&info->port.count);
48286 spin_unlock_irqrestore(&info->netlock, flags);
48287
48288- if (info->port.count == 1) {
48289+ if (atomic_read(&info->port.count) == 1) {
48290 /* 1st open on this device, init hardware */
48291 retval = startup(info);
48292 if (retval < 0)
48293@@ -796,8 +796,8 @@ cleanup:
48294 if (retval) {
48295 if (tty->count == 1)
48296 info->port.tty = NULL; /* tty layer will release tty struct */
48297- if(info->port.count)
48298- info->port.count--;
48299+ if(atomic_read(&info->port.count))
48300+ atomic_dec(&info->port.count);
48301 }
48302
48303 return retval;
48304@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48305
48306 if (debug_level >= DEBUG_LEVEL_INFO)
48307 printk("%s(%d):%s close() entry, count=%d\n",
48308- __FILE__,__LINE__, info->device_name, info->port.count);
48309+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48310
48311 if (tty_port_close_start(&info->port, tty, filp) == 0)
48312 goto cleanup;
48313@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48314 cleanup:
48315 if (debug_level >= DEBUG_LEVEL_INFO)
48316 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48317- tty->driver->name, info->port.count);
48318+ tty->driver->name, atomic_read(&info->port.count));
48319 }
48320
48321 /* Called by tty_hangup() when a hangup is signaled.
48322@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48323 shutdown(info);
48324
48325 spin_lock_irqsave(&info->port.lock, flags);
48326- info->port.count = 0;
48327+ atomic_set(&info->port.count, 0);
48328 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48329 info->port.tty = NULL;
48330 spin_unlock_irqrestore(&info->port.lock, flags);
48331@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48332 unsigned short new_crctype;
48333
48334 /* return error if TTY interface open */
48335- if (info->port.count)
48336+ if (atomic_read(&info->port.count))
48337 return -EBUSY;
48338
48339 switch (encoding)
48340@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48341
48342 /* arbitrate between network and tty opens */
48343 spin_lock_irqsave(&info->netlock, flags);
48344- if (info->port.count != 0 || info->netcount != 0) {
48345+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48346 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48347 spin_unlock_irqrestore(&info->netlock, flags);
48348 return -EBUSY;
48349@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48350 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48351
48352 /* return error if TTY interface open */
48353- if (info->port.count)
48354+ if (atomic_read(&info->port.count))
48355 return -EBUSY;
48356
48357 if (cmd != SIOCWANDEV)
48358@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48359 * do not request bottom half processing if the
48360 * device is not open in a normal mode.
48361 */
48362- if ( port && (port->port.count || port->netcount) &&
48363+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48364 port->pending_bh && !port->bh_running &&
48365 !port->bh_requested ) {
48366 if ( debug_level >= DEBUG_LEVEL_ISR )
48367@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48368
48369 if (debug_level >= DEBUG_LEVEL_INFO)
48370 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48371- __FILE__,__LINE__, tty->driver->name, port->count );
48372+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48373
48374 spin_lock_irqsave(&info->lock, flags);
48375 if (!tty_hung_up_p(filp)) {
48376 extra_count = true;
48377- port->count--;
48378+ atomic_dec(&port->count);
48379 }
48380 spin_unlock_irqrestore(&info->lock, flags);
48381 port->blocked_open++;
48382@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48383
48384 if (debug_level >= DEBUG_LEVEL_INFO)
48385 printk("%s(%d):%s block_til_ready() count=%d\n",
48386- __FILE__,__LINE__, tty->driver->name, port->count );
48387+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48388
48389 tty_unlock(tty);
48390 schedule();
48391@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48392 remove_wait_queue(&port->open_wait, &wait);
48393
48394 if (extra_count)
48395- port->count++;
48396+ atomic_inc(&port->count);
48397 port->blocked_open--;
48398
48399 if (debug_level >= DEBUG_LEVEL_INFO)
48400 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48401- __FILE__,__LINE__, tty->driver->name, port->count );
48402+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48403
48404 if (!retval)
48405 port->flags |= ASYNC_NORMAL_ACTIVE;
48406diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48407index 40a9fe9..a3f10cc 100644
48408--- a/drivers/tty/sysrq.c
48409+++ b/drivers/tty/sysrq.c
48410@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48411 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48412 size_t count, loff_t *ppos)
48413 {
48414- if (count) {
48415+ if (count && capable(CAP_SYS_ADMIN)) {
48416 char c;
48417
48418 if (get_user(c, buf))
48419diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48420index 3a1a01a..b12cda2 100644
48421--- a/drivers/tty/tty_io.c
48422+++ b/drivers/tty/tty_io.c
48423@@ -3473,7 +3473,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48424
48425 void tty_default_fops(struct file_operations *fops)
48426 {
48427- *fops = tty_fops;
48428+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48429 }
48430
48431 /*
48432diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48433index 6458e11..6cfc218 100644
48434--- a/drivers/tty/tty_ldisc.c
48435+++ b/drivers/tty/tty_ldisc.c
48436@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48437 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
48438 tty_ldiscs[disc] = new_ldisc;
48439 new_ldisc->num = disc;
48440- new_ldisc->refcount = 0;
48441+ atomic_set(&new_ldisc->refcount, 0);
48442 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
48443
48444 return ret;
48445@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
48446 return -EINVAL;
48447
48448 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
48449- if (tty_ldiscs[disc]->refcount)
48450+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48451 ret = -EBUSY;
48452 else
48453 tty_ldiscs[disc] = NULL;
48454@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48455 if (ldops) {
48456 ret = ERR_PTR(-EAGAIN);
48457 if (try_module_get(ldops->owner)) {
48458- ldops->refcount++;
48459+ atomic_inc(&ldops->refcount);
48460 ret = ldops;
48461 }
48462 }
48463@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48464 unsigned long flags;
48465
48466 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
48467- ldops->refcount--;
48468+ atomic_dec(&ldops->refcount);
48469 module_put(ldops->owner);
48470 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
48471 }
48472diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48473index f597e88..b7f68ed 100644
48474--- a/drivers/tty/tty_port.c
48475+++ b/drivers/tty/tty_port.c
48476@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48477 unsigned long flags;
48478
48479 spin_lock_irqsave(&port->lock, flags);
48480- port->count = 0;
48481+ atomic_set(&port->count, 0);
48482 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48483 tty = port->tty;
48484 if (tty)
48485@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48486 /* The port lock protects the port counts */
48487 spin_lock_irqsave(&port->lock, flags);
48488 if (!tty_hung_up_p(filp))
48489- port->count--;
48490+ atomic_dec(&port->count);
48491 port->blocked_open++;
48492 spin_unlock_irqrestore(&port->lock, flags);
48493
48494@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48495 we must not mess that up further */
48496 spin_lock_irqsave(&port->lock, flags);
48497 if (!tty_hung_up_p(filp))
48498- port->count++;
48499+ atomic_inc(&port->count);
48500 port->blocked_open--;
48501 if (retval == 0)
48502 port->flags |= ASYNC_NORMAL_ACTIVE;
48503@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48504 return 0;
48505 }
48506
48507- if (tty->count == 1 && port->count != 1) {
48508+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48509 printk(KERN_WARNING
48510 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48511- port->count);
48512- port->count = 1;
48513+ atomic_read(&port->count));
48514+ atomic_set(&port->count, 1);
48515 }
48516- if (--port->count < 0) {
48517+ if (atomic_dec_return(&port->count) < 0) {
48518 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48519- port->count);
48520- port->count = 0;
48521+ atomic_read(&port->count));
48522+ atomic_set(&port->count, 0);
48523 }
48524
48525- if (port->count) {
48526+ if (atomic_read(&port->count)) {
48527 spin_unlock_irqrestore(&port->lock, flags);
48528 if (port->ops->drop)
48529 port->ops->drop(port);
48530@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48531 {
48532 spin_lock_irq(&port->lock);
48533 if (!tty_hung_up_p(filp))
48534- ++port->count;
48535+ atomic_inc(&port->count);
48536 spin_unlock_irq(&port->lock);
48537 tty_port_tty_set(port, tty);
48538
48539diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48540index d0e3a44..5f8b754 100644
48541--- a/drivers/tty/vt/keyboard.c
48542+++ b/drivers/tty/vt/keyboard.c
48543@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48544 kbd->kbdmode == VC_OFF) &&
48545 value != KVAL(K_SAK))
48546 return; /* SAK is allowed even in raw mode */
48547+
48548+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48549+ {
48550+ void *func = fn_handler[value];
48551+ if (func == fn_show_state || func == fn_show_ptregs ||
48552+ func == fn_show_mem)
48553+ return;
48554+ }
48555+#endif
48556+
48557 fn_handler[value](vc);
48558 }
48559
48560@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48561 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48562 return -EFAULT;
48563
48564- if (!capable(CAP_SYS_TTY_CONFIG))
48565- perm = 0;
48566-
48567 switch (cmd) {
48568 case KDGKBENT:
48569 /* Ensure another thread doesn't free it under us */
48570@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48571 spin_unlock_irqrestore(&kbd_event_lock, flags);
48572 return put_user(val, &user_kbe->kb_value);
48573 case KDSKBENT:
48574+ if (!capable(CAP_SYS_TTY_CONFIG))
48575+ perm = 0;
48576+
48577 if (!perm)
48578 return -EPERM;
48579 if (!i && v == K_NOSUCHMAP) {
48580@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48581 int i, j, k;
48582 int ret;
48583
48584- if (!capable(CAP_SYS_TTY_CONFIG))
48585- perm = 0;
48586-
48587 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48588 if (!kbs) {
48589 ret = -ENOMEM;
48590@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48591 kfree(kbs);
48592 return ((p && *p) ? -EOVERFLOW : 0);
48593 case KDSKBSENT:
48594+ if (!capable(CAP_SYS_TTY_CONFIG))
48595+ perm = 0;
48596+
48597 if (!perm) {
48598 ret = -EPERM;
48599 goto reterr;
48600diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48601index 0e808cf..26c24ab 100644
48602--- a/drivers/uio/uio.c
48603+++ b/drivers/uio/uio.c
48604@@ -25,6 +25,7 @@
48605 #include <linux/kobject.h>
48606 #include <linux/cdev.h>
48607 #include <linux/uio_driver.h>
48608+#include <asm/local.h>
48609
48610 #define UIO_MAX_DEVICES (1U << MINORBITS)
48611
48612@@ -32,7 +33,7 @@ struct uio_device {
48613 struct module *owner;
48614 struct device *dev;
48615 int minor;
48616- atomic_t event;
48617+ atomic_unchecked_t event;
48618 struct fasync_struct *async_queue;
48619 wait_queue_head_t wait;
48620 struct uio_info *info;
48621@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
48622 struct device_attribute *attr, char *buf)
48623 {
48624 struct uio_device *idev = dev_get_drvdata(dev);
48625- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48626+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48627 }
48628 static DEVICE_ATTR_RO(event);
48629
48630@@ -401,7 +402,7 @@ void uio_event_notify(struct uio_info *info)
48631 {
48632 struct uio_device *idev = info->uio_dev;
48633
48634- atomic_inc(&idev->event);
48635+ atomic_inc_unchecked(&idev->event);
48636 wake_up_interruptible(&idev->wait);
48637 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48638 }
48639@@ -454,7 +455,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48640 }
48641
48642 listener->dev = idev;
48643- listener->event_count = atomic_read(&idev->event);
48644+ listener->event_count = atomic_read_unchecked(&idev->event);
48645 filep->private_data = listener;
48646
48647 if (idev->info->open) {
48648@@ -505,7 +506,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48649 return -EIO;
48650
48651 poll_wait(filep, &idev->wait, wait);
48652- if (listener->event_count != atomic_read(&idev->event))
48653+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48654 return POLLIN | POLLRDNORM;
48655 return 0;
48656 }
48657@@ -530,7 +531,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48658 do {
48659 set_current_state(TASK_INTERRUPTIBLE);
48660
48661- event_count = atomic_read(&idev->event);
48662+ event_count = atomic_read_unchecked(&idev->event);
48663 if (event_count != listener->event_count) {
48664 if (copy_to_user(buf, &event_count, count))
48665 retval = -EFAULT;
48666@@ -587,9 +588,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
48667 static int uio_find_mem_index(struct vm_area_struct *vma)
48668 {
48669 struct uio_device *idev = vma->vm_private_data;
48670+ unsigned long size;
48671
48672 if (vma->vm_pgoff < MAX_UIO_MAPS) {
48673- if (idev->info->mem[vma->vm_pgoff].size == 0)
48674+ size = idev->info->mem[vma->vm_pgoff].size;
48675+ if (size == 0)
48676+ return -1;
48677+ if (vma->vm_end - vma->vm_start > size)
48678 return -1;
48679 return (int)vma->vm_pgoff;
48680 }
48681@@ -818,7 +823,7 @@ int __uio_register_device(struct module *owner,
48682 idev->owner = owner;
48683 idev->info = info;
48684 init_waitqueue_head(&idev->wait);
48685- atomic_set(&idev->event, 0);
48686+ atomic_set_unchecked(&idev->event, 0);
48687
48688 ret = uio_get_minor(idev);
48689 if (ret)
48690diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48691index 8a7eb77..c00402f 100644
48692--- a/drivers/usb/atm/cxacru.c
48693+++ b/drivers/usb/atm/cxacru.c
48694@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48695 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48696 if (ret < 2)
48697 return -EINVAL;
48698- if (index < 0 || index > 0x7f)
48699+ if (index > 0x7f)
48700 return -EINVAL;
48701 pos += tmp;
48702
48703diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48704index 25a7bfc..57f3cf5 100644
48705--- a/drivers/usb/atm/usbatm.c
48706+++ b/drivers/usb/atm/usbatm.c
48707@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48708 if (printk_ratelimit())
48709 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48710 __func__, vpi, vci);
48711- atomic_inc(&vcc->stats->rx_err);
48712+ atomic_inc_unchecked(&vcc->stats->rx_err);
48713 return;
48714 }
48715
48716@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48717 if (length > ATM_MAX_AAL5_PDU) {
48718 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48719 __func__, length, vcc);
48720- atomic_inc(&vcc->stats->rx_err);
48721+ atomic_inc_unchecked(&vcc->stats->rx_err);
48722 goto out;
48723 }
48724
48725@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48726 if (sarb->len < pdu_length) {
48727 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48728 __func__, pdu_length, sarb->len, vcc);
48729- atomic_inc(&vcc->stats->rx_err);
48730+ atomic_inc_unchecked(&vcc->stats->rx_err);
48731 goto out;
48732 }
48733
48734 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48735 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48736 __func__, vcc);
48737- atomic_inc(&vcc->stats->rx_err);
48738+ atomic_inc_unchecked(&vcc->stats->rx_err);
48739 goto out;
48740 }
48741
48742@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48743 if (printk_ratelimit())
48744 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48745 __func__, length);
48746- atomic_inc(&vcc->stats->rx_drop);
48747+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48748 goto out;
48749 }
48750
48751@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48752
48753 vcc->push(vcc, skb);
48754
48755- atomic_inc(&vcc->stats->rx);
48756+ atomic_inc_unchecked(&vcc->stats->rx);
48757 out:
48758 skb_trim(sarb, 0);
48759 }
48760@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
48761 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48762
48763 usbatm_pop(vcc, skb);
48764- atomic_inc(&vcc->stats->tx);
48765+ atomic_inc_unchecked(&vcc->stats->tx);
48766
48767 skb = skb_dequeue(&instance->sndqueue);
48768 }
48769@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48770 if (!left--)
48771 return sprintf(page,
48772 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48773- atomic_read(&atm_dev->stats.aal5.tx),
48774- atomic_read(&atm_dev->stats.aal5.tx_err),
48775- atomic_read(&atm_dev->stats.aal5.rx),
48776- atomic_read(&atm_dev->stats.aal5.rx_err),
48777- atomic_read(&atm_dev->stats.aal5.rx_drop));
48778+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48779+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48780+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48781+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48782+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48783
48784 if (!left--) {
48785 if (instance->disconnected)
48786diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48787index 2a3bbdf..91d72cf 100644
48788--- a/drivers/usb/core/devices.c
48789+++ b/drivers/usb/core/devices.c
48790@@ -126,7 +126,7 @@ static const char format_endpt[] =
48791 * time it gets called.
48792 */
48793 static struct device_connect_event {
48794- atomic_t count;
48795+ atomic_unchecked_t count;
48796 wait_queue_head_t wait;
48797 } device_event = {
48798 .count = ATOMIC_INIT(1),
48799@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48800
48801 void usbfs_conn_disc_event(void)
48802 {
48803- atomic_add(2, &device_event.count);
48804+ atomic_add_unchecked(2, &device_event.count);
48805 wake_up(&device_event.wait);
48806 }
48807
48808@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48809
48810 poll_wait(file, &device_event.wait, wait);
48811
48812- event_count = atomic_read(&device_event.count);
48813+ event_count = atomic_read_unchecked(&device_event.count);
48814 if (file->f_version != event_count) {
48815 file->f_version = event_count;
48816 return POLLIN | POLLRDNORM;
48817diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48818index f20a044..d1059aa 100644
48819--- a/drivers/usb/core/hcd.c
48820+++ b/drivers/usb/core/hcd.c
48821@@ -1552,7 +1552,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48822 */
48823 usb_get_urb(urb);
48824 atomic_inc(&urb->use_count);
48825- atomic_inc(&urb->dev->urbnum);
48826+ atomic_inc_unchecked(&urb->dev->urbnum);
48827 usbmon_urb_submit(&hcd->self, urb);
48828
48829 /* NOTE requirements on root-hub callers (usbfs and the hub
48830@@ -1579,7 +1579,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48831 urb->hcpriv = NULL;
48832 INIT_LIST_HEAD(&urb->urb_list);
48833 atomic_dec(&urb->use_count);
48834- atomic_dec(&urb->dev->urbnum);
48835+ atomic_dec_unchecked(&urb->dev->urbnum);
48836 if (atomic_read(&urb->reject))
48837 wake_up(&usb_kill_urb_queue);
48838 usb_put_urb(urb);
48839diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48840index 243c672..8b66fbb 100644
48841--- a/drivers/usb/core/hub.c
48842+++ b/drivers/usb/core/hub.c
48843@@ -27,6 +27,7 @@
48844 #include <linux/freezer.h>
48845 #include <linux/random.h>
48846 #include <linux/pm_qos.h>
48847+#include <linux/grsecurity.h>
48848
48849 #include <asm/uaccess.h>
48850 #include <asm/byteorder.h>
48851@@ -4467,6 +4468,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48852 goto done;
48853 return;
48854 }
48855+
48856+ if (gr_handle_new_usb())
48857+ goto done;
48858+
48859 if (hub_is_superspeed(hub->hdev))
48860 unit_load = 150;
48861 else
48862diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48863index 82927e1..4993dbf 100644
48864--- a/drivers/usb/core/message.c
48865+++ b/drivers/usb/core/message.c
48866@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48867 * Return: If successful, the number of bytes transferred. Otherwise, a negative
48868 * error number.
48869 */
48870-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48871+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48872 __u8 requesttype, __u16 value, __u16 index, void *data,
48873 __u16 size, int timeout)
48874 {
48875@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
48876 * If successful, 0. Otherwise a negative error number. The number of actual
48877 * bytes transferred will be stored in the @actual_length paramater.
48878 */
48879-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
48880+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
48881 void *data, int len, int *actual_length, int timeout)
48882 {
48883 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
48884@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
48885 * bytes transferred will be stored in the @actual_length paramater.
48886 *
48887 */
48888-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
48889+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
48890 void *data, int len, int *actual_length, int timeout)
48891 {
48892 struct urb *urb;
48893diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
48894index ca516ac..6c36ee4 100644
48895--- a/drivers/usb/core/sysfs.c
48896+++ b/drivers/usb/core/sysfs.c
48897@@ -236,7 +236,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
48898 struct usb_device *udev;
48899
48900 udev = to_usb_device(dev);
48901- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
48902+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
48903 }
48904 static DEVICE_ATTR_RO(urbnum);
48905
48906diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
48907index 0a6ee2e..6f8d7e8 100644
48908--- a/drivers/usb/core/usb.c
48909+++ b/drivers/usb/core/usb.c
48910@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
48911 set_dev_node(&dev->dev, dev_to_node(bus->controller));
48912 dev->state = USB_STATE_ATTACHED;
48913 dev->lpm_disable_count = 1;
48914- atomic_set(&dev->urbnum, 0);
48915+ atomic_set_unchecked(&dev->urbnum, 0);
48916
48917 INIT_LIST_HEAD(&dev->ep0.urb_list);
48918 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
48919diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
48920index 5452c0f..34c9145 100644
48921--- a/drivers/usb/dwc3/gadget.c
48922+++ b/drivers/usb/dwc3/gadget.c
48923@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
48924 if (!usb_endpoint_xfer_isoc(desc))
48925 return 0;
48926
48927- memset(&trb_link, 0, sizeof(trb_link));
48928-
48929 /* Link TRB for ISOC. The HWO bit is never reset */
48930 trb_st_hw = &dep->trb_pool[0];
48931
48932diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
48933index 5e29dde..eca992f 100644
48934--- a/drivers/usb/early/ehci-dbgp.c
48935+++ b/drivers/usb/early/ehci-dbgp.c
48936@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
48937
48938 #ifdef CONFIG_KGDB
48939 static struct kgdb_io kgdbdbgp_io_ops;
48940-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
48941+static struct kgdb_io kgdbdbgp_io_ops_console;
48942+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
48943 #else
48944 #define dbgp_kgdb_mode (0)
48945 #endif
48946@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
48947 .write_char = kgdbdbgp_write_char,
48948 };
48949
48950+static struct kgdb_io kgdbdbgp_io_ops_console = {
48951+ .name = "kgdbdbgp",
48952+ .read_char = kgdbdbgp_read_char,
48953+ .write_char = kgdbdbgp_write_char,
48954+ .is_console = 1
48955+};
48956+
48957 static int kgdbdbgp_wait_time;
48958
48959 static int __init kgdbdbgp_parse_config(char *str)
48960@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
48961 ptr++;
48962 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
48963 }
48964- kgdb_register_io_module(&kgdbdbgp_io_ops);
48965- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
48966+ if (early_dbgp_console.index != -1)
48967+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
48968+ else
48969+ kgdb_register_io_module(&kgdbdbgp_io_ops);
48970
48971 return 0;
48972 }
48973diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
48974index b369292..9f3ba40 100644
48975--- a/drivers/usb/gadget/u_serial.c
48976+++ b/drivers/usb/gadget/u_serial.c
48977@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
48978 spin_lock_irq(&port->port_lock);
48979
48980 /* already open? Great. */
48981- if (port->port.count) {
48982+ if (atomic_read(&port->port.count)) {
48983 status = 0;
48984- port->port.count++;
48985+ atomic_inc(&port->port.count);
48986
48987 /* currently opening/closing? wait ... */
48988 } else if (port->openclose) {
48989@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
48990 tty->driver_data = port;
48991 port->port.tty = tty;
48992
48993- port->port.count = 1;
48994+ atomic_set(&port->port.count, 1);
48995 port->openclose = false;
48996
48997 /* if connected, start the I/O stream */
48998@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
48999
49000 spin_lock_irq(&port->port_lock);
49001
49002- if (port->port.count != 1) {
49003- if (port->port.count == 0)
49004+ if (atomic_read(&port->port.count) != 1) {
49005+ if (atomic_read(&port->port.count) == 0)
49006 WARN_ON(1);
49007 else
49008- --port->port.count;
49009+ atomic_dec(&port->port.count);
49010 goto exit;
49011 }
49012
49013@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49014 * and sleep if necessary
49015 */
49016 port->openclose = true;
49017- port->port.count = 0;
49018+ atomic_set(&port->port.count, 0);
49019
49020 gser = port->port_usb;
49021 if (gser && gser->disconnect)
49022@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49023 int cond;
49024
49025 spin_lock_irq(&port->port_lock);
49026- cond = (port->port.count == 0) && !port->openclose;
49027+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49028 spin_unlock_irq(&port->port_lock);
49029 return cond;
49030 }
49031@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49032 /* if it's already open, start I/O ... and notify the serial
49033 * protocol about open/close status (connect/disconnect).
49034 */
49035- if (port->port.count) {
49036+ if (atomic_read(&port->port.count)) {
49037 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49038 gs_start_io(port);
49039 if (gser->connect)
49040@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49041
49042 port->port_usb = NULL;
49043 gser->ioport = NULL;
49044- if (port->port.count > 0 || port->openclose) {
49045+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49046 wake_up_interruptible(&port->drain_wait);
49047 if (port->port.tty)
49048 tty_hangup(port->port.tty);
49049@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49050
49051 /* finally, free any unused/unusable I/O buffers */
49052 spin_lock_irqsave(&port->port_lock, flags);
49053- if (port->port.count == 0 && !port->openclose)
49054+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49055 gs_buf_free(&port->port_write_buf);
49056 gs_free_requests(gser->out, &port->read_pool, NULL);
49057 gs_free_requests(gser->out, &port->read_queue, NULL);
49058diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
49059index 835fc08..f8b22bf 100644
49060--- a/drivers/usb/host/ehci-hub.c
49061+++ b/drivers/usb/host/ehci-hub.c
49062@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
49063 urb->transfer_flags = URB_DIR_IN;
49064 usb_get_urb(urb);
49065 atomic_inc(&urb->use_count);
49066- atomic_inc(&urb->dev->urbnum);
49067+ atomic_inc_unchecked(&urb->dev->urbnum);
49068 urb->setup_dma = dma_map_single(
49069 hcd->self.controller,
49070 urb->setup_packet,
49071@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
49072 urb->status = -EINPROGRESS;
49073 usb_get_urb(urb);
49074 atomic_inc(&urb->use_count);
49075- atomic_inc(&urb->dev->urbnum);
49076+ atomic_inc_unchecked(&urb->dev->urbnum);
49077 retval = submit_single_step_set_feature(hcd, urb, 0);
49078 if (!retval && !wait_for_completion_timeout(&done,
49079 msecs_to_jiffies(2000))) {
49080diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49081index ba6a5d6..f88f7f3 100644
49082--- a/drivers/usb/misc/appledisplay.c
49083+++ b/drivers/usb/misc/appledisplay.c
49084@@ -83,7 +83,7 @@ struct appledisplay {
49085 spinlock_t lock;
49086 };
49087
49088-static atomic_t count_displays = ATOMIC_INIT(0);
49089+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49090 static struct workqueue_struct *wq;
49091
49092 static void appledisplay_complete(struct urb *urb)
49093@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49094
49095 /* Register backlight device */
49096 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49097- atomic_inc_return(&count_displays) - 1);
49098+ atomic_inc_return_unchecked(&count_displays) - 1);
49099 memset(&props, 0, sizeof(struct backlight_properties));
49100 props.type = BACKLIGHT_RAW;
49101 props.max_brightness = 0xff;
49102diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49103index c69bb50..215ef37 100644
49104--- a/drivers/usb/serial/console.c
49105+++ b/drivers/usb/serial/console.c
49106@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49107
49108 info->port = port;
49109
49110- ++port->port.count;
49111+ atomic_inc(&port->port.count);
49112 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49113 if (serial->type->set_termios) {
49114 /*
49115@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
49116 }
49117 /* Now that any required fake tty operations are completed restore
49118 * the tty port count */
49119- --port->port.count;
49120+ atomic_dec(&port->port.count);
49121 /* The console is special in terms of closing the device so
49122 * indicate this port is now acting as a system console. */
49123 port->port.console = 1;
49124@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
49125 free_tty:
49126 kfree(tty);
49127 reset_open_count:
49128- port->port.count = 0;
49129+ atomic_set(&port->port.count, 0);
49130 usb_autopm_put_interface(serial->interface);
49131 error_get_interface:
49132 usb_serial_put(serial);
49133@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
49134 static void usb_console_write(struct console *co,
49135 const char *buf, unsigned count)
49136 {
49137- static struct usbcons_info *info = &usbcons_info;
49138+ struct usbcons_info *info = &usbcons_info;
49139 struct usb_serial_port *port = info->port;
49140 struct usb_serial *serial;
49141 int retval = -ENODEV;
49142diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49143index 75f70f0..d467e1a 100644
49144--- a/drivers/usb/storage/usb.h
49145+++ b/drivers/usb/storage/usb.h
49146@@ -63,7 +63,7 @@ struct us_unusual_dev {
49147 __u8 useProtocol;
49148 __u8 useTransport;
49149 int (*initFunction)(struct us_data *);
49150-};
49151+} __do_const;
49152
49153
49154 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49155diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49156index cf250c2..ad9d904 100644
49157--- a/drivers/usb/wusbcore/wa-hc.h
49158+++ b/drivers/usb/wusbcore/wa-hc.h
49159@@ -199,7 +199,7 @@ struct wahc {
49160 spinlock_t xfer_list_lock;
49161 struct work_struct xfer_enqueue_work;
49162 struct work_struct xfer_error_work;
49163- atomic_t xfer_id_count;
49164+ atomic_unchecked_t xfer_id_count;
49165 };
49166
49167
49168@@ -255,7 +255,7 @@ static inline void wa_init(struct wahc *wa)
49169 spin_lock_init(&wa->xfer_list_lock);
49170 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
49171 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
49172- atomic_set(&wa->xfer_id_count, 1);
49173+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49174 }
49175
49176 /**
49177diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49178index 6ad02f5..cc52c8b 100644
49179--- a/drivers/usb/wusbcore/wa-xfer.c
49180+++ b/drivers/usb/wusbcore/wa-xfer.c
49181@@ -299,7 +299,7 @@ out:
49182 */
49183 static void wa_xfer_id_init(struct wa_xfer *xfer)
49184 {
49185- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49186+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49187 }
49188
49189 /*
49190diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49191index 1eab4ac..e21efc9 100644
49192--- a/drivers/vfio/vfio.c
49193+++ b/drivers/vfio/vfio.c
49194@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49195 return 0;
49196
49197 /* TODO Prevent device auto probing */
49198- WARN("Device %s added to live group %d!\n", dev_name(dev),
49199+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49200 iommu_group_id(group->iommu_group));
49201
49202 return 0;
49203diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49204index 5174eba..86e764a 100644
49205--- a/drivers/vhost/vringh.c
49206+++ b/drivers/vhost/vringh.c
49207@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49208
49209 static inline int putu16_kern(u16 *p, u16 val)
49210 {
49211- ACCESS_ONCE(*p) = val;
49212+ ACCESS_ONCE_RW(*p) = val;
49213 return 0;
49214 }
49215
49216diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
49217index e43401a..dd49b3f 100644
49218--- a/drivers/video/arcfb.c
49219+++ b/drivers/video/arcfb.c
49220@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
49221 return -ENOSPC;
49222
49223 err = 0;
49224- if ((count + p) > fbmemlength) {
49225+ if (count > (fbmemlength - p)) {
49226 count = fbmemlength - p;
49227 err = -ENOSPC;
49228 }
49229diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49230index a4dfe8c..297ddd9 100644
49231--- a/drivers/video/aty/aty128fb.c
49232+++ b/drivers/video/aty/aty128fb.c
49233@@ -149,7 +149,7 @@ enum {
49234 };
49235
49236 /* Must match above enum */
49237-static char * const r128_family[] = {
49238+static const char * const r128_family[] = {
49239 "AGP",
49240 "PCI",
49241 "PRO AGP",
49242diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49243index 9b0f12c..024673d 100644
49244--- a/drivers/video/aty/atyfb_base.c
49245+++ b/drivers/video/aty/atyfb_base.c
49246@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49247 par->accel_flags = var->accel_flags; /* hack */
49248
49249 if (var->accel_flags) {
49250- info->fbops->fb_sync = atyfb_sync;
49251+ pax_open_kernel();
49252+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49253+ pax_close_kernel();
49254 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49255 } else {
49256- info->fbops->fb_sync = NULL;
49257+ pax_open_kernel();
49258+ *(void **)&info->fbops->fb_sync = NULL;
49259+ pax_close_kernel();
49260 info->flags |= FBINFO_HWACCEL_DISABLED;
49261 }
49262
49263diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49264index 95ec042..e6affdd 100644
49265--- a/drivers/video/aty/mach64_cursor.c
49266+++ b/drivers/video/aty/mach64_cursor.c
49267@@ -7,6 +7,7 @@
49268 #include <linux/string.h>
49269
49270 #include <asm/io.h>
49271+#include <asm/pgtable.h>
49272
49273 #ifdef __sparc__
49274 #include <asm/fbio.h>
49275@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49276 info->sprite.buf_align = 16; /* and 64 lines tall. */
49277 info->sprite.flags = FB_PIXMAP_IO;
49278
49279- info->fbops->fb_cursor = atyfb_cursor;
49280+ pax_open_kernel();
49281+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49282+ pax_close_kernel();
49283
49284 return 0;
49285 }
49286diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49287index bca6ccc..252107e 100644
49288--- a/drivers/video/backlight/kb3886_bl.c
49289+++ b/drivers/video/backlight/kb3886_bl.c
49290@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49291 static unsigned long kb3886bl_flags;
49292 #define KB3886BL_SUSPENDED 0x01
49293
49294-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49295+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49296 {
49297 .ident = "Sahara Touch-iT",
49298 .matches = {
49299diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49300index 900aa4e..6d49418 100644
49301--- a/drivers/video/fb_defio.c
49302+++ b/drivers/video/fb_defio.c
49303@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49304
49305 BUG_ON(!fbdefio);
49306 mutex_init(&fbdefio->lock);
49307- info->fbops->fb_mmap = fb_deferred_io_mmap;
49308+ pax_open_kernel();
49309+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49310+ pax_close_kernel();
49311 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49312 INIT_LIST_HEAD(&fbdefio->pagelist);
49313 if (fbdefio->delay == 0) /* set a default of 1 s */
49314@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49315 page->mapping = NULL;
49316 }
49317
49318- info->fbops->fb_mmap = NULL;
49319+ *(void **)&info->fbops->fb_mmap = NULL;
49320 mutex_destroy(&fbdefio->lock);
49321 }
49322 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49323diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49324index dacaf74..8478a46 100644
49325--- a/drivers/video/fbmem.c
49326+++ b/drivers/video/fbmem.c
49327@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49328 image->dx += image->width + 8;
49329 }
49330 } else if (rotate == FB_ROTATE_UD) {
49331- for (x = 0; x < num && image->dx >= 0; x++) {
49332+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49333 info->fbops->fb_imageblit(info, image);
49334 image->dx -= image->width + 8;
49335 }
49336@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49337 image->dy += image->height + 8;
49338 }
49339 } else if (rotate == FB_ROTATE_CCW) {
49340- for (x = 0; x < num && image->dy >= 0; x++) {
49341+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49342 info->fbops->fb_imageblit(info, image);
49343 image->dy -= image->height + 8;
49344 }
49345@@ -1175,7 +1175,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49346 return -EFAULT;
49347 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49348 return -EINVAL;
49349- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49350+ if (con2fb.framebuffer >= FB_MAX)
49351 return -EINVAL;
49352 if (!registered_fb[con2fb.framebuffer])
49353 request_module("fb%d", con2fb.framebuffer);
49354diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49355index 8d456dc..b4fa44b 100644
49356--- a/drivers/video/hyperv_fb.c
49357+++ b/drivers/video/hyperv_fb.c
49358@@ -233,7 +233,7 @@ static uint screen_fb_size;
49359 static inline int synthvid_send(struct hv_device *hdev,
49360 struct synthvid_msg *msg)
49361 {
49362- static atomic64_t request_id = ATOMIC64_INIT(0);
49363+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49364 int ret;
49365
49366 msg->pipe_hdr.type = PIPE_MSG_DATA;
49367@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49368
49369 ret = vmbus_sendpacket(hdev->channel, msg,
49370 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49371- atomic64_inc_return(&request_id),
49372+ atomic64_inc_return_unchecked(&request_id),
49373 VM_PKT_DATA_INBAND, 0);
49374
49375 if (ret)
49376diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49377index 7672d2e..b56437f 100644
49378--- a/drivers/video/i810/i810_accel.c
49379+++ b/drivers/video/i810/i810_accel.c
49380@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49381 }
49382 }
49383 printk("ringbuffer lockup!!!\n");
49384+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49385 i810_report_error(mmio);
49386 par->dev_flags |= LOCKUP;
49387 info->pixmap.scan_align = 1;
49388diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49389index 3c14e43..2630570 100644
49390--- a/drivers/video/logo/logo_linux_clut224.ppm
49391+++ b/drivers/video/logo/logo_linux_clut224.ppm
49392@@ -2,1603 +2,1123 @@ P3
49393 # Standard 224-color Linux logo
49394 80 80
49395 255
49396- 0 0 0 0 0 0 0 0 0 0 0 0
49397- 0 0 0 0 0 0 0 0 0 0 0 0
49398- 0 0 0 0 0 0 0 0 0 0 0 0
49399- 0 0 0 0 0 0 0 0 0 0 0 0
49400- 0 0 0 0 0 0 0 0 0 0 0 0
49401- 0 0 0 0 0 0 0 0 0 0 0 0
49402- 0 0 0 0 0 0 0 0 0 0 0 0
49403- 0 0 0 0 0 0 0 0 0 0 0 0
49404- 0 0 0 0 0 0 0 0 0 0 0 0
49405- 6 6 6 6 6 6 10 10 10 10 10 10
49406- 10 10 10 6 6 6 6 6 6 6 6 6
49407- 0 0 0 0 0 0 0 0 0 0 0 0
49408- 0 0 0 0 0 0 0 0 0 0 0 0
49409- 0 0 0 0 0 0 0 0 0 0 0 0
49410- 0 0 0 0 0 0 0 0 0 0 0 0
49411- 0 0 0 0 0 0 0 0 0 0 0 0
49412- 0 0 0 0 0 0 0 0 0 0 0 0
49413- 0 0 0 0 0 0 0 0 0 0 0 0
49414- 0 0 0 0 0 0 0 0 0 0 0 0
49415- 0 0 0 0 0 0 0 0 0 0 0 0
49416- 0 0 0 0 0 0 0 0 0 0 0 0
49417- 0 0 0 0 0 0 0 0 0 0 0 0
49418- 0 0 0 0 0 0 0 0 0 0 0 0
49419- 0 0 0 0 0 0 0 0 0 0 0 0
49420- 0 0 0 0 0 0 0 0 0 0 0 0
49421- 0 0 0 0 0 0 0 0 0 0 0 0
49422- 0 0 0 0 0 0 0 0 0 0 0 0
49423- 0 0 0 0 0 0 0 0 0 0 0 0
49424- 0 0 0 6 6 6 10 10 10 14 14 14
49425- 22 22 22 26 26 26 30 30 30 34 34 34
49426- 30 30 30 30 30 30 26 26 26 18 18 18
49427- 14 14 14 10 10 10 6 6 6 0 0 0
49428- 0 0 0 0 0 0 0 0 0 0 0 0
49429- 0 0 0 0 0 0 0 0 0 0 0 0
49430- 0 0 0 0 0 0 0 0 0 0 0 0
49431- 0 0 0 0 0 0 0 0 0 0 0 0
49432- 0 0 0 0 0 0 0 0 0 0 0 0
49433- 0 0 0 0 0 0 0 0 0 0 0 0
49434- 0 0 0 0 0 0 0 0 0 0 0 0
49435- 0 0 0 0 0 0 0 0 0 0 0 0
49436- 0 0 0 0 0 0 0 0 0 0 0 0
49437- 0 0 0 0 0 1 0 0 1 0 0 0
49438- 0 0 0 0 0 0 0 0 0 0 0 0
49439- 0 0 0 0 0 0 0 0 0 0 0 0
49440- 0 0 0 0 0 0 0 0 0 0 0 0
49441- 0 0 0 0 0 0 0 0 0 0 0 0
49442- 0 0 0 0 0 0 0 0 0 0 0 0
49443- 0 0 0 0 0 0 0 0 0 0 0 0
49444- 6 6 6 14 14 14 26 26 26 42 42 42
49445- 54 54 54 66 66 66 78 78 78 78 78 78
49446- 78 78 78 74 74 74 66 66 66 54 54 54
49447- 42 42 42 26 26 26 18 18 18 10 10 10
49448- 6 6 6 0 0 0 0 0 0 0 0 0
49449- 0 0 0 0 0 0 0 0 0 0 0 0
49450- 0 0 0 0 0 0 0 0 0 0 0 0
49451- 0 0 0 0 0 0 0 0 0 0 0 0
49452- 0 0 0 0 0 0 0 0 0 0 0 0
49453- 0 0 0 0 0 0 0 0 0 0 0 0
49454- 0 0 0 0 0 0 0 0 0 0 0 0
49455- 0 0 0 0 0 0 0 0 0 0 0 0
49456- 0 0 0 0 0 0 0 0 0 0 0 0
49457- 0 0 1 0 0 0 0 0 0 0 0 0
49458- 0 0 0 0 0 0 0 0 0 0 0 0
49459- 0 0 0 0 0 0 0 0 0 0 0 0
49460- 0 0 0 0 0 0 0 0 0 0 0 0
49461- 0 0 0 0 0 0 0 0 0 0 0 0
49462- 0 0 0 0 0 0 0 0 0 0 0 0
49463- 0 0 0 0 0 0 0 0 0 10 10 10
49464- 22 22 22 42 42 42 66 66 66 86 86 86
49465- 66 66 66 38 38 38 38 38 38 22 22 22
49466- 26 26 26 34 34 34 54 54 54 66 66 66
49467- 86 86 86 70 70 70 46 46 46 26 26 26
49468- 14 14 14 6 6 6 0 0 0 0 0 0
49469- 0 0 0 0 0 0 0 0 0 0 0 0
49470- 0 0 0 0 0 0 0 0 0 0 0 0
49471- 0 0 0 0 0 0 0 0 0 0 0 0
49472- 0 0 0 0 0 0 0 0 0 0 0 0
49473- 0 0 0 0 0 0 0 0 0 0 0 0
49474- 0 0 0 0 0 0 0 0 0 0 0 0
49475- 0 0 0 0 0 0 0 0 0 0 0 0
49476- 0 0 0 0 0 0 0 0 0 0 0 0
49477- 0 0 1 0 0 1 0 0 1 0 0 0
49478- 0 0 0 0 0 0 0 0 0 0 0 0
49479- 0 0 0 0 0 0 0 0 0 0 0 0
49480- 0 0 0 0 0 0 0 0 0 0 0 0
49481- 0 0 0 0 0 0 0 0 0 0 0 0
49482- 0 0 0 0 0 0 0 0 0 0 0 0
49483- 0 0 0 0 0 0 10 10 10 26 26 26
49484- 50 50 50 82 82 82 58 58 58 6 6 6
49485- 2 2 6 2 2 6 2 2 6 2 2 6
49486- 2 2 6 2 2 6 2 2 6 2 2 6
49487- 6 6 6 54 54 54 86 86 86 66 66 66
49488- 38 38 38 18 18 18 6 6 6 0 0 0
49489- 0 0 0 0 0 0 0 0 0 0 0 0
49490- 0 0 0 0 0 0 0 0 0 0 0 0
49491- 0 0 0 0 0 0 0 0 0 0 0 0
49492- 0 0 0 0 0 0 0 0 0 0 0 0
49493- 0 0 0 0 0 0 0 0 0 0 0 0
49494- 0 0 0 0 0 0 0 0 0 0 0 0
49495- 0 0 0 0 0 0 0 0 0 0 0 0
49496- 0 0 0 0 0 0 0 0 0 0 0 0
49497- 0 0 0 0 0 0 0 0 0 0 0 0
49498- 0 0 0 0 0 0 0 0 0 0 0 0
49499- 0 0 0 0 0 0 0 0 0 0 0 0
49500- 0 0 0 0 0 0 0 0 0 0 0 0
49501- 0 0 0 0 0 0 0 0 0 0 0 0
49502- 0 0 0 0 0 0 0 0 0 0 0 0
49503- 0 0 0 6 6 6 22 22 22 50 50 50
49504- 78 78 78 34 34 34 2 2 6 2 2 6
49505- 2 2 6 2 2 6 2 2 6 2 2 6
49506- 2 2 6 2 2 6 2 2 6 2 2 6
49507- 2 2 6 2 2 6 6 6 6 70 70 70
49508- 78 78 78 46 46 46 22 22 22 6 6 6
49509- 0 0 0 0 0 0 0 0 0 0 0 0
49510- 0 0 0 0 0 0 0 0 0 0 0 0
49511- 0 0 0 0 0 0 0 0 0 0 0 0
49512- 0 0 0 0 0 0 0 0 0 0 0 0
49513- 0 0 0 0 0 0 0 0 0 0 0 0
49514- 0 0 0 0 0 0 0 0 0 0 0 0
49515- 0 0 0 0 0 0 0 0 0 0 0 0
49516- 0 0 0 0 0 0 0 0 0 0 0 0
49517- 0 0 1 0 0 1 0 0 1 0 0 0
49518- 0 0 0 0 0 0 0 0 0 0 0 0
49519- 0 0 0 0 0 0 0 0 0 0 0 0
49520- 0 0 0 0 0 0 0 0 0 0 0 0
49521- 0 0 0 0 0 0 0 0 0 0 0 0
49522- 0 0 0 0 0 0 0 0 0 0 0 0
49523- 6 6 6 18 18 18 42 42 42 82 82 82
49524- 26 26 26 2 2 6 2 2 6 2 2 6
49525- 2 2 6 2 2 6 2 2 6 2 2 6
49526- 2 2 6 2 2 6 2 2 6 14 14 14
49527- 46 46 46 34 34 34 6 6 6 2 2 6
49528- 42 42 42 78 78 78 42 42 42 18 18 18
49529- 6 6 6 0 0 0 0 0 0 0 0 0
49530- 0 0 0 0 0 0 0 0 0 0 0 0
49531- 0 0 0 0 0 0 0 0 0 0 0 0
49532- 0 0 0 0 0 0 0 0 0 0 0 0
49533- 0 0 0 0 0 0 0 0 0 0 0 0
49534- 0 0 0 0 0 0 0 0 0 0 0 0
49535- 0 0 0 0 0 0 0 0 0 0 0 0
49536- 0 0 0 0 0 0 0 0 0 0 0 0
49537- 0 0 1 0 0 0 0 0 1 0 0 0
49538- 0 0 0 0 0 0 0 0 0 0 0 0
49539- 0 0 0 0 0 0 0 0 0 0 0 0
49540- 0 0 0 0 0 0 0 0 0 0 0 0
49541- 0 0 0 0 0 0 0 0 0 0 0 0
49542- 0 0 0 0 0 0 0 0 0 0 0 0
49543- 10 10 10 30 30 30 66 66 66 58 58 58
49544- 2 2 6 2 2 6 2 2 6 2 2 6
49545- 2 2 6 2 2 6 2 2 6 2 2 6
49546- 2 2 6 2 2 6 2 2 6 26 26 26
49547- 86 86 86 101 101 101 46 46 46 10 10 10
49548- 2 2 6 58 58 58 70 70 70 34 34 34
49549- 10 10 10 0 0 0 0 0 0 0 0 0
49550- 0 0 0 0 0 0 0 0 0 0 0 0
49551- 0 0 0 0 0 0 0 0 0 0 0 0
49552- 0 0 0 0 0 0 0 0 0 0 0 0
49553- 0 0 0 0 0 0 0 0 0 0 0 0
49554- 0 0 0 0 0 0 0 0 0 0 0 0
49555- 0 0 0 0 0 0 0 0 0 0 0 0
49556- 0 0 0 0 0 0 0 0 0 0 0 0
49557- 0 0 1 0 0 1 0 0 1 0 0 0
49558- 0 0 0 0 0 0 0 0 0 0 0 0
49559- 0 0 0 0 0 0 0 0 0 0 0 0
49560- 0 0 0 0 0 0 0 0 0 0 0 0
49561- 0 0 0 0 0 0 0 0 0 0 0 0
49562- 0 0 0 0 0 0 0 0 0 0 0 0
49563- 14 14 14 42 42 42 86 86 86 10 10 10
49564- 2 2 6 2 2 6 2 2 6 2 2 6
49565- 2 2 6 2 2 6 2 2 6 2 2 6
49566- 2 2 6 2 2 6 2 2 6 30 30 30
49567- 94 94 94 94 94 94 58 58 58 26 26 26
49568- 2 2 6 6 6 6 78 78 78 54 54 54
49569- 22 22 22 6 6 6 0 0 0 0 0 0
49570- 0 0 0 0 0 0 0 0 0 0 0 0
49571- 0 0 0 0 0 0 0 0 0 0 0 0
49572- 0 0 0 0 0 0 0 0 0 0 0 0
49573- 0 0 0 0 0 0 0 0 0 0 0 0
49574- 0 0 0 0 0 0 0 0 0 0 0 0
49575- 0 0 0 0 0 0 0 0 0 0 0 0
49576- 0 0 0 0 0 0 0 0 0 0 0 0
49577- 0 0 0 0 0 0 0 0 0 0 0 0
49578- 0 0 0 0 0 0 0 0 0 0 0 0
49579- 0 0 0 0 0 0 0 0 0 0 0 0
49580- 0 0 0 0 0 0 0 0 0 0 0 0
49581- 0 0 0 0 0 0 0 0 0 0 0 0
49582- 0 0 0 0 0 0 0 0 0 6 6 6
49583- 22 22 22 62 62 62 62 62 62 2 2 6
49584- 2 2 6 2 2 6 2 2 6 2 2 6
49585- 2 2 6 2 2 6 2 2 6 2 2 6
49586- 2 2 6 2 2 6 2 2 6 26 26 26
49587- 54 54 54 38 38 38 18 18 18 10 10 10
49588- 2 2 6 2 2 6 34 34 34 82 82 82
49589- 38 38 38 14 14 14 0 0 0 0 0 0
49590- 0 0 0 0 0 0 0 0 0 0 0 0
49591- 0 0 0 0 0 0 0 0 0 0 0 0
49592- 0 0 0 0 0 0 0 0 0 0 0 0
49593- 0 0 0 0 0 0 0 0 0 0 0 0
49594- 0 0 0 0 0 0 0 0 0 0 0 0
49595- 0 0 0 0 0 0 0 0 0 0 0 0
49596- 0 0 0 0 0 0 0 0 0 0 0 0
49597- 0 0 0 0 0 1 0 0 1 0 0 0
49598- 0 0 0 0 0 0 0 0 0 0 0 0
49599- 0 0 0 0 0 0 0 0 0 0 0 0
49600- 0 0 0 0 0 0 0 0 0 0 0 0
49601- 0 0 0 0 0 0 0 0 0 0 0 0
49602- 0 0 0 0 0 0 0 0 0 6 6 6
49603- 30 30 30 78 78 78 30 30 30 2 2 6
49604- 2 2 6 2 2 6 2 2 6 2 2 6
49605- 2 2 6 2 2 6 2 2 6 2 2 6
49606- 2 2 6 2 2 6 2 2 6 10 10 10
49607- 10 10 10 2 2 6 2 2 6 2 2 6
49608- 2 2 6 2 2 6 2 2 6 78 78 78
49609- 50 50 50 18 18 18 6 6 6 0 0 0
49610- 0 0 0 0 0 0 0 0 0 0 0 0
49611- 0 0 0 0 0 0 0 0 0 0 0 0
49612- 0 0 0 0 0 0 0 0 0 0 0 0
49613- 0 0 0 0 0 0 0 0 0 0 0 0
49614- 0 0 0 0 0 0 0 0 0 0 0 0
49615- 0 0 0 0 0 0 0 0 0 0 0 0
49616- 0 0 0 0 0 0 0 0 0 0 0 0
49617- 0 0 1 0 0 0 0 0 0 0 0 0
49618- 0 0 0 0 0 0 0 0 0 0 0 0
49619- 0 0 0 0 0 0 0 0 0 0 0 0
49620- 0 0 0 0 0 0 0 0 0 0 0 0
49621- 0 0 0 0 0 0 0 0 0 0 0 0
49622- 0 0 0 0 0 0 0 0 0 10 10 10
49623- 38 38 38 86 86 86 14 14 14 2 2 6
49624- 2 2 6 2 2 6 2 2 6 2 2 6
49625- 2 2 6 2 2 6 2 2 6 2 2 6
49626- 2 2 6 2 2 6 2 2 6 2 2 6
49627- 2 2 6 2 2 6 2 2 6 2 2 6
49628- 2 2 6 2 2 6 2 2 6 54 54 54
49629- 66 66 66 26 26 26 6 6 6 0 0 0
49630- 0 0 0 0 0 0 0 0 0 0 0 0
49631- 0 0 0 0 0 0 0 0 0 0 0 0
49632- 0 0 0 0 0 0 0 0 0 0 0 0
49633- 0 0 0 0 0 0 0 0 0 0 0 0
49634- 0 0 0 0 0 0 0 0 0 0 0 0
49635- 0 0 0 0 0 0 0 0 0 0 0 0
49636- 0 0 0 0 0 0 0 0 0 0 0 0
49637- 0 0 0 0 0 1 0 0 1 0 0 0
49638- 0 0 0 0 0 0 0 0 0 0 0 0
49639- 0 0 0 0 0 0 0 0 0 0 0 0
49640- 0 0 0 0 0 0 0 0 0 0 0 0
49641- 0 0 0 0 0 0 0 0 0 0 0 0
49642- 0 0 0 0 0 0 0 0 0 14 14 14
49643- 42 42 42 82 82 82 2 2 6 2 2 6
49644- 2 2 6 6 6 6 10 10 10 2 2 6
49645- 2 2 6 2 2 6 2 2 6 2 2 6
49646- 2 2 6 2 2 6 2 2 6 6 6 6
49647- 14 14 14 10 10 10 2 2 6 2 2 6
49648- 2 2 6 2 2 6 2 2 6 18 18 18
49649- 82 82 82 34 34 34 10 10 10 0 0 0
49650- 0 0 0 0 0 0 0 0 0 0 0 0
49651- 0 0 0 0 0 0 0 0 0 0 0 0
49652- 0 0 0 0 0 0 0 0 0 0 0 0
49653- 0 0 0 0 0 0 0 0 0 0 0 0
49654- 0 0 0 0 0 0 0 0 0 0 0 0
49655- 0 0 0 0 0 0 0 0 0 0 0 0
49656- 0 0 0 0 0 0 0 0 0 0 0 0
49657- 0 0 1 0 0 0 0 0 0 0 0 0
49658- 0 0 0 0 0 0 0 0 0 0 0 0
49659- 0 0 0 0 0 0 0 0 0 0 0 0
49660- 0 0 0 0 0 0 0 0 0 0 0 0
49661- 0 0 0 0 0 0 0 0 0 0 0 0
49662- 0 0 0 0 0 0 0 0 0 14 14 14
49663- 46 46 46 86 86 86 2 2 6 2 2 6
49664- 6 6 6 6 6 6 22 22 22 34 34 34
49665- 6 6 6 2 2 6 2 2 6 2 2 6
49666- 2 2 6 2 2 6 18 18 18 34 34 34
49667- 10 10 10 50 50 50 22 22 22 2 2 6
49668- 2 2 6 2 2 6 2 2 6 10 10 10
49669- 86 86 86 42 42 42 14 14 14 0 0 0
49670- 0 0 0 0 0 0 0 0 0 0 0 0
49671- 0 0 0 0 0 0 0 0 0 0 0 0
49672- 0 0 0 0 0 0 0 0 0 0 0 0
49673- 0 0 0 0 0 0 0 0 0 0 0 0
49674- 0 0 0 0 0 0 0 0 0 0 0 0
49675- 0 0 0 0 0 0 0 0 0 0 0 0
49676- 0 0 0 0 0 0 0 0 0 0 0 0
49677- 0 0 1 0 0 1 0 0 1 0 0 0
49678- 0 0 0 0 0 0 0 0 0 0 0 0
49679- 0 0 0 0 0 0 0 0 0 0 0 0
49680- 0 0 0 0 0 0 0 0 0 0 0 0
49681- 0 0 0 0 0 0 0 0 0 0 0 0
49682- 0 0 0 0 0 0 0 0 0 14 14 14
49683- 46 46 46 86 86 86 2 2 6 2 2 6
49684- 38 38 38 116 116 116 94 94 94 22 22 22
49685- 22 22 22 2 2 6 2 2 6 2 2 6
49686- 14 14 14 86 86 86 138 138 138 162 162 162
49687-154 154 154 38 38 38 26 26 26 6 6 6
49688- 2 2 6 2 2 6 2 2 6 2 2 6
49689- 86 86 86 46 46 46 14 14 14 0 0 0
49690- 0 0 0 0 0 0 0 0 0 0 0 0
49691- 0 0 0 0 0 0 0 0 0 0 0 0
49692- 0 0 0 0 0 0 0 0 0 0 0 0
49693- 0 0 0 0 0 0 0 0 0 0 0 0
49694- 0 0 0 0 0 0 0 0 0 0 0 0
49695- 0 0 0 0 0 0 0 0 0 0 0 0
49696- 0 0 0 0 0 0 0 0 0 0 0 0
49697- 0 0 0 0 0 0 0 0 0 0 0 0
49698- 0 0 0 0 0 0 0 0 0 0 0 0
49699- 0 0 0 0 0 0 0 0 0 0 0 0
49700- 0 0 0 0 0 0 0 0 0 0 0 0
49701- 0 0 0 0 0 0 0 0 0 0 0 0
49702- 0 0 0 0 0 0 0 0 0 14 14 14
49703- 46 46 46 86 86 86 2 2 6 14 14 14
49704-134 134 134 198 198 198 195 195 195 116 116 116
49705- 10 10 10 2 2 6 2 2 6 6 6 6
49706-101 98 89 187 187 187 210 210 210 218 218 218
49707-214 214 214 134 134 134 14 14 14 6 6 6
49708- 2 2 6 2 2 6 2 2 6 2 2 6
49709- 86 86 86 50 50 50 18 18 18 6 6 6
49710- 0 0 0 0 0 0 0 0 0 0 0 0
49711- 0 0 0 0 0 0 0 0 0 0 0 0
49712- 0 0 0 0 0 0 0 0 0 0 0 0
49713- 0 0 0 0 0 0 0 0 0 0 0 0
49714- 0 0 0 0 0 0 0 0 0 0 0 0
49715- 0 0 0 0 0 0 0 0 0 0 0 0
49716- 0 0 0 0 0 0 0 0 1 0 0 0
49717- 0 0 1 0 0 1 0 0 1 0 0 0
49718- 0 0 0 0 0 0 0 0 0 0 0 0
49719- 0 0 0 0 0 0 0 0 0 0 0 0
49720- 0 0 0 0 0 0 0 0 0 0 0 0
49721- 0 0 0 0 0 0 0 0 0 0 0 0
49722- 0 0 0 0 0 0 0 0 0 14 14 14
49723- 46 46 46 86 86 86 2 2 6 54 54 54
49724-218 218 218 195 195 195 226 226 226 246 246 246
49725- 58 58 58 2 2 6 2 2 6 30 30 30
49726-210 210 210 253 253 253 174 174 174 123 123 123
49727-221 221 221 234 234 234 74 74 74 2 2 6
49728- 2 2 6 2 2 6 2 2 6 2 2 6
49729- 70 70 70 58 58 58 22 22 22 6 6 6
49730- 0 0 0 0 0 0 0 0 0 0 0 0
49731- 0 0 0 0 0 0 0 0 0 0 0 0
49732- 0 0 0 0 0 0 0 0 0 0 0 0
49733- 0 0 0 0 0 0 0 0 0 0 0 0
49734- 0 0 0 0 0 0 0 0 0 0 0 0
49735- 0 0 0 0 0 0 0 0 0 0 0 0
49736- 0 0 0 0 0 0 0 0 0 0 0 0
49737- 0 0 0 0 0 0 0 0 0 0 0 0
49738- 0 0 0 0 0 0 0 0 0 0 0 0
49739- 0 0 0 0 0 0 0 0 0 0 0 0
49740- 0 0 0 0 0 0 0 0 0 0 0 0
49741- 0 0 0 0 0 0 0 0 0 0 0 0
49742- 0 0 0 0 0 0 0 0 0 14 14 14
49743- 46 46 46 82 82 82 2 2 6 106 106 106
49744-170 170 170 26 26 26 86 86 86 226 226 226
49745-123 123 123 10 10 10 14 14 14 46 46 46
49746-231 231 231 190 190 190 6 6 6 70 70 70
49747- 90 90 90 238 238 238 158 158 158 2 2 6
49748- 2 2 6 2 2 6 2 2 6 2 2 6
49749- 70 70 70 58 58 58 22 22 22 6 6 6
49750- 0 0 0 0 0 0 0 0 0 0 0 0
49751- 0 0 0 0 0 0 0 0 0 0 0 0
49752- 0 0 0 0 0 0 0 0 0 0 0 0
49753- 0 0 0 0 0 0 0 0 0 0 0 0
49754- 0 0 0 0 0 0 0 0 0 0 0 0
49755- 0 0 0 0 0 0 0 0 0 0 0 0
49756- 0 0 0 0 0 0 0 0 1 0 0 0
49757- 0 0 1 0 0 1 0 0 1 0 0 0
49758- 0 0 0 0 0 0 0 0 0 0 0 0
49759- 0 0 0 0 0 0 0 0 0 0 0 0
49760- 0 0 0 0 0 0 0 0 0 0 0 0
49761- 0 0 0 0 0 0 0 0 0 0 0 0
49762- 0 0 0 0 0 0 0 0 0 14 14 14
49763- 42 42 42 86 86 86 6 6 6 116 116 116
49764-106 106 106 6 6 6 70 70 70 149 149 149
49765-128 128 128 18 18 18 38 38 38 54 54 54
49766-221 221 221 106 106 106 2 2 6 14 14 14
49767- 46 46 46 190 190 190 198 198 198 2 2 6
49768- 2 2 6 2 2 6 2 2 6 2 2 6
49769- 74 74 74 62 62 62 22 22 22 6 6 6
49770- 0 0 0 0 0 0 0 0 0 0 0 0
49771- 0 0 0 0 0 0 0 0 0 0 0 0
49772- 0 0 0 0 0 0 0 0 0 0 0 0
49773- 0 0 0 0 0 0 0 0 0 0 0 0
49774- 0 0 0 0 0 0 0 0 0 0 0 0
49775- 0 0 0 0 0 0 0 0 0 0 0 0
49776- 0 0 0 0 0 0 0 0 1 0 0 0
49777- 0 0 1 0 0 0 0 0 1 0 0 0
49778- 0 0 0 0 0 0 0 0 0 0 0 0
49779- 0 0 0 0 0 0 0 0 0 0 0 0
49780- 0 0 0 0 0 0 0 0 0 0 0 0
49781- 0 0 0 0 0 0 0 0 0 0 0 0
49782- 0 0 0 0 0 0 0 0 0 14 14 14
49783- 42 42 42 94 94 94 14 14 14 101 101 101
49784-128 128 128 2 2 6 18 18 18 116 116 116
49785-118 98 46 121 92 8 121 92 8 98 78 10
49786-162 162 162 106 106 106 2 2 6 2 2 6
49787- 2 2 6 195 195 195 195 195 195 6 6 6
49788- 2 2 6 2 2 6 2 2 6 2 2 6
49789- 74 74 74 62 62 62 22 22 22 6 6 6
49790- 0 0 0 0 0 0 0 0 0 0 0 0
49791- 0 0 0 0 0 0 0 0 0 0 0 0
49792- 0 0 0 0 0 0 0 0 0 0 0 0
49793- 0 0 0 0 0 0 0 0 0 0 0 0
49794- 0 0 0 0 0 0 0 0 0 0 0 0
49795- 0 0 0 0 0 0 0 0 0 0 0 0
49796- 0 0 0 0 0 0 0 0 1 0 0 1
49797- 0 0 1 0 0 0 0 0 1 0 0 0
49798- 0 0 0 0 0 0 0 0 0 0 0 0
49799- 0 0 0 0 0 0 0 0 0 0 0 0
49800- 0 0 0 0 0 0 0 0 0 0 0 0
49801- 0 0 0 0 0 0 0 0 0 0 0 0
49802- 0 0 0 0 0 0 0 0 0 10 10 10
49803- 38 38 38 90 90 90 14 14 14 58 58 58
49804-210 210 210 26 26 26 54 38 6 154 114 10
49805-226 170 11 236 186 11 225 175 15 184 144 12
49806-215 174 15 175 146 61 37 26 9 2 2 6
49807- 70 70 70 246 246 246 138 138 138 2 2 6
49808- 2 2 6 2 2 6 2 2 6 2 2 6
49809- 70 70 70 66 66 66 26 26 26 6 6 6
49810- 0 0 0 0 0 0 0 0 0 0 0 0
49811- 0 0 0 0 0 0 0 0 0 0 0 0
49812- 0 0 0 0 0 0 0 0 0 0 0 0
49813- 0 0 0 0 0 0 0 0 0 0 0 0
49814- 0 0 0 0 0 0 0 0 0 0 0 0
49815- 0 0 0 0 0 0 0 0 0 0 0 0
49816- 0 0 0 0 0 0 0 0 0 0 0 0
49817- 0 0 0 0 0 0 0 0 0 0 0 0
49818- 0 0 0 0 0 0 0 0 0 0 0 0
49819- 0 0 0 0 0 0 0 0 0 0 0 0
49820- 0 0 0 0 0 0 0 0 0 0 0 0
49821- 0 0 0 0 0 0 0 0 0 0 0 0
49822- 0 0 0 0 0 0 0 0 0 10 10 10
49823- 38 38 38 86 86 86 14 14 14 10 10 10
49824-195 195 195 188 164 115 192 133 9 225 175 15
49825-239 182 13 234 190 10 232 195 16 232 200 30
49826-245 207 45 241 208 19 232 195 16 184 144 12
49827-218 194 134 211 206 186 42 42 42 2 2 6
49828- 2 2 6 2 2 6 2 2 6 2 2 6
49829- 50 50 50 74 74 74 30 30 30 6 6 6
49830- 0 0 0 0 0 0 0 0 0 0 0 0
49831- 0 0 0 0 0 0 0 0 0 0 0 0
49832- 0 0 0 0 0 0 0 0 0 0 0 0
49833- 0 0 0 0 0 0 0 0 0 0 0 0
49834- 0 0 0 0 0 0 0 0 0 0 0 0
49835- 0 0 0 0 0 0 0 0 0 0 0 0
49836- 0 0 0 0 0 0 0 0 0 0 0 0
49837- 0 0 0 0 0 0 0 0 0 0 0 0
49838- 0 0 0 0 0 0 0 0 0 0 0 0
49839- 0 0 0 0 0 0 0 0 0 0 0 0
49840- 0 0 0 0 0 0 0 0 0 0 0 0
49841- 0 0 0 0 0 0 0 0 0 0 0 0
49842- 0 0 0 0 0 0 0 0 0 10 10 10
49843- 34 34 34 86 86 86 14 14 14 2 2 6
49844-121 87 25 192 133 9 219 162 10 239 182 13
49845-236 186 11 232 195 16 241 208 19 244 214 54
49846-246 218 60 246 218 38 246 215 20 241 208 19
49847-241 208 19 226 184 13 121 87 25 2 2 6
49848- 2 2 6 2 2 6 2 2 6 2 2 6
49849- 50 50 50 82 82 82 34 34 34 10 10 10
49850- 0 0 0 0 0 0 0 0 0 0 0 0
49851- 0 0 0 0 0 0 0 0 0 0 0 0
49852- 0 0 0 0 0 0 0 0 0 0 0 0
49853- 0 0 0 0 0 0 0 0 0 0 0 0
49854- 0 0 0 0 0 0 0 0 0 0 0 0
49855- 0 0 0 0 0 0 0 0 0 0 0 0
49856- 0 0 0 0 0 0 0 0 0 0 0 0
49857- 0 0 0 0 0 0 0 0 0 0 0 0
49858- 0 0 0 0 0 0 0 0 0 0 0 0
49859- 0 0 0 0 0 0 0 0 0 0 0 0
49860- 0 0 0 0 0 0 0 0 0 0 0 0
49861- 0 0 0 0 0 0 0 0 0 0 0 0
49862- 0 0 0 0 0 0 0 0 0 10 10 10
49863- 34 34 34 82 82 82 30 30 30 61 42 6
49864-180 123 7 206 145 10 230 174 11 239 182 13
49865-234 190 10 238 202 15 241 208 19 246 218 74
49866-246 218 38 246 215 20 246 215 20 246 215 20
49867-226 184 13 215 174 15 184 144 12 6 6 6
49868- 2 2 6 2 2 6 2 2 6 2 2 6
49869- 26 26 26 94 94 94 42 42 42 14 14 14
49870- 0 0 0 0 0 0 0 0 0 0 0 0
49871- 0 0 0 0 0 0 0 0 0 0 0 0
49872- 0 0 0 0 0 0 0 0 0 0 0 0
49873- 0 0 0 0 0 0 0 0 0 0 0 0
49874- 0 0 0 0 0 0 0 0 0 0 0 0
49875- 0 0 0 0 0 0 0 0 0 0 0 0
49876- 0 0 0 0 0 0 0 0 0 0 0 0
49877- 0 0 0 0 0 0 0 0 0 0 0 0
49878- 0 0 0 0 0 0 0 0 0 0 0 0
49879- 0 0 0 0 0 0 0 0 0 0 0 0
49880- 0 0 0 0 0 0 0 0 0 0 0 0
49881- 0 0 0 0 0 0 0 0 0 0 0 0
49882- 0 0 0 0 0 0 0 0 0 10 10 10
49883- 30 30 30 78 78 78 50 50 50 104 69 6
49884-192 133 9 216 158 10 236 178 12 236 186 11
49885-232 195 16 241 208 19 244 214 54 245 215 43
49886-246 215 20 246 215 20 241 208 19 198 155 10
49887-200 144 11 216 158 10 156 118 10 2 2 6
49888- 2 2 6 2 2 6 2 2 6 2 2 6
49889- 6 6 6 90 90 90 54 54 54 18 18 18
49890- 6 6 6 0 0 0 0 0 0 0 0 0
49891- 0 0 0 0 0 0 0 0 0 0 0 0
49892- 0 0 0 0 0 0 0 0 0 0 0 0
49893- 0 0 0 0 0 0 0 0 0 0 0 0
49894- 0 0 0 0 0 0 0 0 0 0 0 0
49895- 0 0 0 0 0 0 0 0 0 0 0 0
49896- 0 0 0 0 0 0 0 0 0 0 0 0
49897- 0 0 0 0 0 0 0 0 0 0 0 0
49898- 0 0 0 0 0 0 0 0 0 0 0 0
49899- 0 0 0 0 0 0 0 0 0 0 0 0
49900- 0 0 0 0 0 0 0 0 0 0 0 0
49901- 0 0 0 0 0 0 0 0 0 0 0 0
49902- 0 0 0 0 0 0 0 0 0 10 10 10
49903- 30 30 30 78 78 78 46 46 46 22 22 22
49904-137 92 6 210 162 10 239 182 13 238 190 10
49905-238 202 15 241 208 19 246 215 20 246 215 20
49906-241 208 19 203 166 17 185 133 11 210 150 10
49907-216 158 10 210 150 10 102 78 10 2 2 6
49908- 6 6 6 54 54 54 14 14 14 2 2 6
49909- 2 2 6 62 62 62 74 74 74 30 30 30
49910- 10 10 10 0 0 0 0 0 0 0 0 0
49911- 0 0 0 0 0 0 0 0 0 0 0 0
49912- 0 0 0 0 0 0 0 0 0 0 0 0
49913- 0 0 0 0 0 0 0 0 0 0 0 0
49914- 0 0 0 0 0 0 0 0 0 0 0 0
49915- 0 0 0 0 0 0 0 0 0 0 0 0
49916- 0 0 0 0 0 0 0 0 0 0 0 0
49917- 0 0 0 0 0 0 0 0 0 0 0 0
49918- 0 0 0 0 0 0 0 0 0 0 0 0
49919- 0 0 0 0 0 0 0 0 0 0 0 0
49920- 0 0 0 0 0 0 0 0 0 0 0 0
49921- 0 0 0 0 0 0 0 0 0 0 0 0
49922- 0 0 0 0 0 0 0 0 0 10 10 10
49923- 34 34 34 78 78 78 50 50 50 6 6 6
49924- 94 70 30 139 102 15 190 146 13 226 184 13
49925-232 200 30 232 195 16 215 174 15 190 146 13
49926-168 122 10 192 133 9 210 150 10 213 154 11
49927-202 150 34 182 157 106 101 98 89 2 2 6
49928- 2 2 6 78 78 78 116 116 116 58 58 58
49929- 2 2 6 22 22 22 90 90 90 46 46 46
49930- 18 18 18 6 6 6 0 0 0 0 0 0
49931- 0 0 0 0 0 0 0 0 0 0 0 0
49932- 0 0 0 0 0 0 0 0 0 0 0 0
49933- 0 0 0 0 0 0 0 0 0 0 0 0
49934- 0 0 0 0 0 0 0 0 0 0 0 0
49935- 0 0 0 0 0 0 0 0 0 0 0 0
49936- 0 0 0 0 0 0 0 0 0 0 0 0
49937- 0 0 0 0 0 0 0 0 0 0 0 0
49938- 0 0 0 0 0 0 0 0 0 0 0 0
49939- 0 0 0 0 0 0 0 0 0 0 0 0
49940- 0 0 0 0 0 0 0 0 0 0 0 0
49941- 0 0 0 0 0 0 0 0 0 0 0 0
49942- 0 0 0 0 0 0 0 0 0 10 10 10
49943- 38 38 38 86 86 86 50 50 50 6 6 6
49944-128 128 128 174 154 114 156 107 11 168 122 10
49945-198 155 10 184 144 12 197 138 11 200 144 11
49946-206 145 10 206 145 10 197 138 11 188 164 115
49947-195 195 195 198 198 198 174 174 174 14 14 14
49948- 2 2 6 22 22 22 116 116 116 116 116 116
49949- 22 22 22 2 2 6 74 74 74 70 70 70
49950- 30 30 30 10 10 10 0 0 0 0 0 0
49951- 0 0 0 0 0 0 0 0 0 0 0 0
49952- 0 0 0 0 0 0 0 0 0 0 0 0
49953- 0 0 0 0 0 0 0 0 0 0 0 0
49954- 0 0 0 0 0 0 0 0 0 0 0 0
49955- 0 0 0 0 0 0 0 0 0 0 0 0
49956- 0 0 0 0 0 0 0 0 0 0 0 0
49957- 0 0 0 0 0 0 0 0 0 0 0 0
49958- 0 0 0 0 0 0 0 0 0 0 0 0
49959- 0 0 0 0 0 0 0 0 0 0 0 0
49960- 0 0 0 0 0 0 0 0 0 0 0 0
49961- 0 0 0 0 0 0 0 0 0 0 0 0
49962- 0 0 0 0 0 0 6 6 6 18 18 18
49963- 50 50 50 101 101 101 26 26 26 10 10 10
49964-138 138 138 190 190 190 174 154 114 156 107 11
49965-197 138 11 200 144 11 197 138 11 192 133 9
49966-180 123 7 190 142 34 190 178 144 187 187 187
49967-202 202 202 221 221 221 214 214 214 66 66 66
49968- 2 2 6 2 2 6 50 50 50 62 62 62
49969- 6 6 6 2 2 6 10 10 10 90 90 90
49970- 50 50 50 18 18 18 6 6 6 0 0 0
49971- 0 0 0 0 0 0 0 0 0 0 0 0
49972- 0 0 0 0 0 0 0 0 0 0 0 0
49973- 0 0 0 0 0 0 0 0 0 0 0 0
49974- 0 0 0 0 0 0 0 0 0 0 0 0
49975- 0 0 0 0 0 0 0 0 0 0 0 0
49976- 0 0 0 0 0 0 0 0 0 0 0 0
49977- 0 0 0 0 0 0 0 0 0 0 0 0
49978- 0 0 0 0 0 0 0 0 0 0 0 0
49979- 0 0 0 0 0 0 0 0 0 0 0 0
49980- 0 0 0 0 0 0 0 0 0 0 0 0
49981- 0 0 0 0 0 0 0 0 0 0 0 0
49982- 0 0 0 0 0 0 10 10 10 34 34 34
49983- 74 74 74 74 74 74 2 2 6 6 6 6
49984-144 144 144 198 198 198 190 190 190 178 166 146
49985-154 121 60 156 107 11 156 107 11 168 124 44
49986-174 154 114 187 187 187 190 190 190 210 210 210
49987-246 246 246 253 253 253 253 253 253 182 182 182
49988- 6 6 6 2 2 6 2 2 6 2 2 6
49989- 2 2 6 2 2 6 2 2 6 62 62 62
49990- 74 74 74 34 34 34 14 14 14 0 0 0
49991- 0 0 0 0 0 0 0 0 0 0 0 0
49992- 0 0 0 0 0 0 0 0 0 0 0 0
49993- 0 0 0 0 0 0 0 0 0 0 0 0
49994- 0 0 0 0 0 0 0 0 0 0 0 0
49995- 0 0 0 0 0 0 0 0 0 0 0 0
49996- 0 0 0 0 0 0 0 0 0 0 0 0
49997- 0 0 0 0 0 0 0 0 0 0 0 0
49998- 0 0 0 0 0 0 0 0 0 0 0 0
49999- 0 0 0 0 0 0 0 0 0 0 0 0
50000- 0 0 0 0 0 0 0 0 0 0 0 0
50001- 0 0 0 0 0 0 0 0 0 0 0 0
50002- 0 0 0 10 10 10 22 22 22 54 54 54
50003- 94 94 94 18 18 18 2 2 6 46 46 46
50004-234 234 234 221 221 221 190 190 190 190 190 190
50005-190 190 190 187 187 187 187 187 187 190 190 190
50006-190 190 190 195 195 195 214 214 214 242 242 242
50007-253 253 253 253 253 253 253 253 253 253 253 253
50008- 82 82 82 2 2 6 2 2 6 2 2 6
50009- 2 2 6 2 2 6 2 2 6 14 14 14
50010- 86 86 86 54 54 54 22 22 22 6 6 6
50011- 0 0 0 0 0 0 0 0 0 0 0 0
50012- 0 0 0 0 0 0 0 0 0 0 0 0
50013- 0 0 0 0 0 0 0 0 0 0 0 0
50014- 0 0 0 0 0 0 0 0 0 0 0 0
50015- 0 0 0 0 0 0 0 0 0 0 0 0
50016- 0 0 0 0 0 0 0 0 0 0 0 0
50017- 0 0 0 0 0 0 0 0 0 0 0 0
50018- 0 0 0 0 0 0 0 0 0 0 0 0
50019- 0 0 0 0 0 0 0 0 0 0 0 0
50020- 0 0 0 0 0 0 0 0 0 0 0 0
50021- 0 0 0 0 0 0 0 0 0 0 0 0
50022- 6 6 6 18 18 18 46 46 46 90 90 90
50023- 46 46 46 18 18 18 6 6 6 182 182 182
50024-253 253 253 246 246 246 206 206 206 190 190 190
50025-190 190 190 190 190 190 190 190 190 190 190 190
50026-206 206 206 231 231 231 250 250 250 253 253 253
50027-253 253 253 253 253 253 253 253 253 253 253 253
50028-202 202 202 14 14 14 2 2 6 2 2 6
50029- 2 2 6 2 2 6 2 2 6 2 2 6
50030- 42 42 42 86 86 86 42 42 42 18 18 18
50031- 6 6 6 0 0 0 0 0 0 0 0 0
50032- 0 0 0 0 0 0 0 0 0 0 0 0
50033- 0 0 0 0 0 0 0 0 0 0 0 0
50034- 0 0 0 0 0 0 0 0 0 0 0 0
50035- 0 0 0 0 0 0 0 0 0 0 0 0
50036- 0 0 0 0 0 0 0 0 0 0 0 0
50037- 0 0 0 0 0 0 0 0 0 0 0 0
50038- 0 0 0 0 0 0 0 0 0 0 0 0
50039- 0 0 0 0 0 0 0 0 0 0 0 0
50040- 0 0 0 0 0 0 0 0 0 0 0 0
50041- 0 0 0 0 0 0 0 0 0 6 6 6
50042- 14 14 14 38 38 38 74 74 74 66 66 66
50043- 2 2 6 6 6 6 90 90 90 250 250 250
50044-253 253 253 253 253 253 238 238 238 198 198 198
50045-190 190 190 190 190 190 195 195 195 221 221 221
50046-246 246 246 253 253 253 253 253 253 253 253 253
50047-253 253 253 253 253 253 253 253 253 253 253 253
50048-253 253 253 82 82 82 2 2 6 2 2 6
50049- 2 2 6 2 2 6 2 2 6 2 2 6
50050- 2 2 6 78 78 78 70 70 70 34 34 34
50051- 14 14 14 6 6 6 0 0 0 0 0 0
50052- 0 0 0 0 0 0 0 0 0 0 0 0
50053- 0 0 0 0 0 0 0 0 0 0 0 0
50054- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
50062- 34 34 34 66 66 66 78 78 78 6 6 6
50063- 2 2 6 18 18 18 218 218 218 253 253 253
50064-253 253 253 253 253 253 253 253 253 246 246 246
50065-226 226 226 231 231 231 246 246 246 253 253 253
50066-253 253 253 253 253 253 253 253 253 253 253 253
50067-253 253 253 253 253 253 253 253 253 253 253 253
50068-253 253 253 178 178 178 2 2 6 2 2 6
50069- 2 2 6 2 2 6 2 2 6 2 2 6
50070- 2 2 6 18 18 18 90 90 90 62 62 62
50071- 30 30 30 10 10 10 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 10 10 10 26 26 26
50082- 58 58 58 90 90 90 18 18 18 2 2 6
50083- 2 2 6 110 110 110 253 253 253 253 253 253
50084-253 253 253 253 253 253 253 253 253 253 253 253
50085-250 250 250 253 253 253 253 253 253 253 253 253
50086-253 253 253 253 253 253 253 253 253 253 253 253
50087-253 253 253 253 253 253 253 253 253 253 253 253
50088-253 253 253 231 231 231 18 18 18 2 2 6
50089- 2 2 6 2 2 6 2 2 6 2 2 6
50090- 2 2 6 2 2 6 18 18 18 94 94 94
50091- 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0
50097- 0 0 0 0 0 0 0 0 0 0 0 0
50098- 0 0 0 0 0 0 0 0 0 0 0 0
50099- 0 0 0 0 0 0 0 0 0 0 0 0
50100- 0 0 0 0 0 0 0 0 0 0 0 0
50101- 0 0 0 6 6 6 22 22 22 50 50 50
50102- 90 90 90 26 26 26 2 2 6 2 2 6
50103- 14 14 14 195 195 195 250 250 250 253 253 253
50104-253 253 253 253 253 253 253 253 253 253 253 253
50105-253 253 253 253 253 253 253 253 253 253 253 253
50106-253 253 253 253 253 253 253 253 253 253 253 253
50107-253 253 253 253 253 253 253 253 253 253 253 253
50108-250 250 250 242 242 242 54 54 54 2 2 6
50109- 2 2 6 2 2 6 2 2 6 2 2 6
50110- 2 2 6 2 2 6 2 2 6 38 38 38
50111- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
50117- 0 0 0 0 0 0 0 0 0 0 0 0
50118- 0 0 0 0 0 0 0 0 0 0 0 0
50119- 0 0 0 0 0 0 0 0 0 0 0 0
50120- 0 0 0 0 0 0 0 0 0 0 0 0
50121- 6 6 6 14 14 14 38 38 38 82 82 82
50122- 34 34 34 2 2 6 2 2 6 2 2 6
50123- 42 42 42 195 195 195 246 246 246 253 253 253
50124-253 253 253 253 253 253 253 253 253 250 250 250
50125-242 242 242 242 242 242 250 250 250 253 253 253
50126-253 253 253 253 253 253 253 253 253 253 253 253
50127-253 253 253 250 250 250 246 246 246 238 238 238
50128-226 226 226 231 231 231 101 101 101 6 6 6
50129- 2 2 6 2 2 6 2 2 6 2 2 6
50130- 2 2 6 2 2 6 2 2 6 2 2 6
50131- 38 38 38 82 82 82 42 42 42 14 14 14
50132- 6 6 6 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 0 0 0 0 0 0 0 0 0 0
50137- 0 0 0 0 0 0 0 0 0 0 0 0
50138- 0 0 0 0 0 0 0 0 0 0 0 0
50139- 0 0 0 0 0 0 0 0 0 0 0 0
50140- 0 0 0 0 0 0 0 0 0 0 0 0
50141- 10 10 10 26 26 26 62 62 62 66 66 66
50142- 2 2 6 2 2 6 2 2 6 6 6 6
50143- 70 70 70 170 170 170 206 206 206 234 234 234
50144-246 246 246 250 250 250 250 250 250 238 238 238
50145-226 226 226 231 231 231 238 238 238 250 250 250
50146-250 250 250 250 250 250 246 246 246 231 231 231
50147-214 214 214 206 206 206 202 202 202 202 202 202
50148-198 198 198 202 202 202 182 182 182 18 18 18
50149- 2 2 6 2 2 6 2 2 6 2 2 6
50150- 2 2 6 2 2 6 2 2 6 2 2 6
50151- 2 2 6 62 62 62 66 66 66 30 30 30
50152- 10 10 10 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- 14 14 14 42 42 42 82 82 82 18 18 18
50162- 2 2 6 2 2 6 2 2 6 10 10 10
50163- 94 94 94 182 182 182 218 218 218 242 242 242
50164-250 250 250 253 253 253 253 253 253 250 250 250
50165-234 234 234 253 253 253 253 253 253 253 253 253
50166-253 253 253 253 253 253 253 253 253 246 246 246
50167-238 238 238 226 226 226 210 210 210 202 202 202
50168-195 195 195 195 195 195 210 210 210 158 158 158
50169- 6 6 6 14 14 14 50 50 50 14 14 14
50170- 2 2 6 2 2 6 2 2 6 2 2 6
50171- 2 2 6 6 6 6 86 86 86 46 46 46
50172- 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
50177- 0 0 0 0 0 0 0 0 0 0 0 0
50178- 0 0 0 0 0 0 0 0 0 0 0 0
50179- 0 0 0 0 0 0 0 0 0 0 0 0
50180- 0 0 0 0 0 0 0 0 0 6 6 6
50181- 22 22 22 54 54 54 70 70 70 2 2 6
50182- 2 2 6 10 10 10 2 2 6 22 22 22
50183-166 166 166 231 231 231 250 250 250 253 253 253
50184-253 253 253 253 253 253 253 253 253 250 250 250
50185-242 242 242 253 253 253 253 253 253 253 253 253
50186-253 253 253 253 253 253 253 253 253 253 253 253
50187-253 253 253 253 253 253 253 253 253 246 246 246
50188-231 231 231 206 206 206 198 198 198 226 226 226
50189- 94 94 94 2 2 6 6 6 6 38 38 38
50190- 30 30 30 2 2 6 2 2 6 2 2 6
50191- 2 2 6 2 2 6 62 62 62 66 66 66
50192- 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0 0
50197- 0 0 0 0 0 0 0 0 0 0 0 0
50198- 0 0 0 0 0 0 0 0 0 0 0 0
50199- 0 0 0 0 0 0 0 0 0 0 0 0
50200- 0 0 0 0 0 0 0 0 0 10 10 10
50201- 30 30 30 74 74 74 50 50 50 2 2 6
50202- 26 26 26 26 26 26 2 2 6 106 106 106
50203-238 238 238 253 253 253 253 253 253 253 253 253
50204-253 253 253 253 253 253 253 253 253 253 253 253
50205-253 253 253 253 253 253 253 253 253 253 253 253
50206-253 253 253 253 253 253 253 253 253 253 253 253
50207-253 253 253 253 253 253 253 253 253 253 253 253
50208-253 253 253 246 246 246 218 218 218 202 202 202
50209-210 210 210 14 14 14 2 2 6 2 2 6
50210- 30 30 30 22 22 22 2 2 6 2 2 6
50211- 2 2 6 2 2 6 18 18 18 86 86 86
50212- 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0 0
50217- 0 0 0 0 0 0 0 0 0 0 0 0
50218- 0 0 0 0 0 0 0 0 0 0 0 0
50219- 0 0 0 0 0 0 0 0 0 0 0 0
50220- 0 0 0 0 0 0 0 0 0 14 14 14
50221- 42 42 42 90 90 90 22 22 22 2 2 6
50222- 42 42 42 2 2 6 18 18 18 218 218 218
50223-253 253 253 253 253 253 253 253 253 253 253 253
50224-253 253 253 253 253 253 253 253 253 253 253 253
50225-253 253 253 253 253 253 253 253 253 253 253 253
50226-253 253 253 253 253 253 253 253 253 253 253 253
50227-253 253 253 253 253 253 253 253 253 253 253 253
50228-253 253 253 253 253 253 250 250 250 221 221 221
50229-218 218 218 101 101 101 2 2 6 14 14 14
50230- 18 18 18 38 38 38 10 10 10 2 2 6
50231- 2 2 6 2 2 6 2 2 6 78 78 78
50232- 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
50241- 54 54 54 82 82 82 2 2 6 26 26 26
50242- 22 22 22 2 2 6 123 123 123 253 253 253
50243-253 253 253 253 253 253 253 253 253 253 253 253
50244-253 253 253 253 253 253 253 253 253 253 253 253
50245-253 253 253 253 253 253 253 253 253 253 253 253
50246-253 253 253 253 253 253 253 253 253 253 253 253
50247-253 253 253 253 253 253 253 253 253 253 253 253
50248-253 253 253 253 253 253 253 253 253 250 250 250
50249-238 238 238 198 198 198 6 6 6 38 38 38
50250- 58 58 58 26 26 26 38 38 38 2 2 6
50251- 2 2 6 2 2 6 2 2 6 46 46 46
50252- 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0
50257- 0 0 0 0 0 0 0 0 0 0 0 0
50258- 0 0 0 0 0 0 0 0 0 0 0 0
50259- 0 0 0 0 0 0 0 0 0 0 0 0
50260- 0 0 0 0 0 0 10 10 10 30 30 30
50261- 74 74 74 58 58 58 2 2 6 42 42 42
50262- 2 2 6 22 22 22 231 231 231 253 253 253
50263-253 253 253 253 253 253 253 253 253 253 253 253
50264-253 253 253 253 253 253 253 253 253 250 250 250
50265-253 253 253 253 253 253 253 253 253 253 253 253
50266-253 253 253 253 253 253 253 253 253 253 253 253
50267-253 253 253 253 253 253 253 253 253 253 253 253
50268-253 253 253 253 253 253 253 253 253 253 253 253
50269-253 253 253 246 246 246 46 46 46 38 38 38
50270- 42 42 42 14 14 14 38 38 38 14 14 14
50271- 2 2 6 2 2 6 2 2 6 6 6 6
50272- 86 86 86 46 46 46 14 14 14 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 0 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 6 6 6 14 14 14 42 42 42
50281- 90 90 90 18 18 18 18 18 18 26 26 26
50282- 2 2 6 116 116 116 253 253 253 253 253 253
50283-253 253 253 253 253 253 253 253 253 253 253 253
50284-253 253 253 253 253 253 250 250 250 238 238 238
50285-253 253 253 253 253 253 253 253 253 253 253 253
50286-253 253 253 253 253 253 253 253 253 253 253 253
50287-253 253 253 253 253 253 253 253 253 253 253 253
50288-253 253 253 253 253 253 253 253 253 253 253 253
50289-253 253 253 253 253 253 94 94 94 6 6 6
50290- 2 2 6 2 2 6 10 10 10 34 34 34
50291- 2 2 6 2 2 6 2 2 6 2 2 6
50292- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0
50297- 0 0 0 0 0 0 0 0 0 0 0 0
50298- 0 0 0 0 0 0 0 0 0 0 0 0
50299- 0 0 0 0 0 0 0 0 0 0 0 0
50300- 0 0 0 10 10 10 26 26 26 66 66 66
50301- 82 82 82 2 2 6 38 38 38 6 6 6
50302- 14 14 14 210 210 210 253 253 253 253 253 253
50303-253 253 253 253 253 253 253 253 253 253 253 253
50304-253 253 253 253 253 253 246 246 246 242 242 242
50305-253 253 253 253 253 253 253 253 253 253 253 253
50306-253 253 253 253 253 253 253 253 253 253 253 253
50307-253 253 253 253 253 253 253 253 253 253 253 253
50308-253 253 253 253 253 253 253 253 253 253 253 253
50309-253 253 253 253 253 253 144 144 144 2 2 6
50310- 2 2 6 2 2 6 2 2 6 46 46 46
50311- 2 2 6 2 2 6 2 2 6 2 2 6
50312- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 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- 6 6 6 14 14 14 42 42 42 90 90 90
50321- 26 26 26 6 6 6 42 42 42 2 2 6
50322- 74 74 74 250 250 250 253 253 253 253 253 253
50323-253 253 253 253 253 253 253 253 253 253 253 253
50324-253 253 253 253 253 253 242 242 242 242 242 242
50325-253 253 253 253 253 253 253 253 253 253 253 253
50326-253 253 253 253 253 253 253 253 253 253 253 253
50327-253 253 253 253 253 253 253 253 253 253 253 253
50328-253 253 253 253 253 253 253 253 253 253 253 253
50329-253 253 253 253 253 253 182 182 182 2 2 6
50330- 2 2 6 2 2 6 2 2 6 46 46 46
50331- 2 2 6 2 2 6 2 2 6 2 2 6
50332- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0 0 0 0 0
50337- 0 0 0 0 0 0 0 0 0 0 0 0
50338- 0 0 0 0 0 0 0 0 0 0 0 0
50339- 0 0 0 0 0 0 0 0 0 0 0 0
50340- 10 10 10 26 26 26 66 66 66 82 82 82
50341- 2 2 6 22 22 22 18 18 18 2 2 6
50342-149 149 149 253 253 253 253 253 253 253 253 253
50343-253 253 253 253 253 253 253 253 253 253 253 253
50344-253 253 253 253 253 253 234 234 234 242 242 242
50345-253 253 253 253 253 253 253 253 253 253 253 253
50346-253 253 253 253 253 253 253 253 253 253 253 253
50347-253 253 253 253 253 253 253 253 253 253 253 253
50348-253 253 253 253 253 253 253 253 253 253 253 253
50349-253 253 253 253 253 253 206 206 206 2 2 6
50350- 2 2 6 2 2 6 2 2 6 38 38 38
50351- 2 2 6 2 2 6 2 2 6 2 2 6
50352- 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
50360- 18 18 18 46 46 46 86 86 86 18 18 18
50361- 2 2 6 34 34 34 10 10 10 6 6 6
50362-210 210 210 253 253 253 253 253 253 253 253 253
50363-253 253 253 253 253 253 253 253 253 253 253 253
50364-253 253 253 253 253 253 234 234 234 242 242 242
50365-253 253 253 253 253 253 253 253 253 253 253 253
50366-253 253 253 253 253 253 253 253 253 253 253 253
50367-253 253 253 253 253 253 253 253 253 253 253 253
50368-253 253 253 253 253 253 253 253 253 253 253 253
50369-253 253 253 253 253 253 221 221 221 6 6 6
50370- 2 2 6 2 2 6 6 6 6 30 30 30
50371- 2 2 6 2 2 6 2 2 6 2 2 6
50372- 2 2 6 82 82 82 54 54 54 18 18 18
50373- 6 6 6 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 0 0 0 0
50376- 0 0 0 0 0 0 0 0 0 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 10 10 10
50380- 26 26 26 66 66 66 62 62 62 2 2 6
50381- 2 2 6 38 38 38 10 10 10 26 26 26
50382-238 238 238 253 253 253 253 253 253 253 253 253
50383-253 253 253 253 253 253 253 253 253 253 253 253
50384-253 253 253 253 253 253 231 231 231 238 238 238
50385-253 253 253 253 253 253 253 253 253 253 253 253
50386-253 253 253 253 253 253 253 253 253 253 253 253
50387-253 253 253 253 253 253 253 253 253 253 253 253
50388-253 253 253 253 253 253 253 253 253 253 253 253
50389-253 253 253 253 253 253 231 231 231 6 6 6
50390- 2 2 6 2 2 6 10 10 10 30 30 30
50391- 2 2 6 2 2 6 2 2 6 2 2 6
50392- 2 2 6 66 66 66 58 58 58 22 22 22
50393- 6 6 6 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 10 10 10
50400- 38 38 38 78 78 78 6 6 6 2 2 6
50401- 2 2 6 46 46 46 14 14 14 42 42 42
50402-246 246 246 253 253 253 253 253 253 253 253 253
50403-253 253 253 253 253 253 253 253 253 253 253 253
50404-253 253 253 253 253 253 231 231 231 242 242 242
50405-253 253 253 253 253 253 253 253 253 253 253 253
50406-253 253 253 253 253 253 253 253 253 253 253 253
50407-253 253 253 253 253 253 253 253 253 253 253 253
50408-253 253 253 253 253 253 253 253 253 253 253 253
50409-253 253 253 253 253 253 234 234 234 10 10 10
50410- 2 2 6 2 2 6 22 22 22 14 14 14
50411- 2 2 6 2 2 6 2 2 6 2 2 6
50412- 2 2 6 66 66 66 62 62 62 22 22 22
50413- 6 6 6 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 0 0 0 0
50416- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
50420- 50 50 50 74 74 74 2 2 6 2 2 6
50421- 14 14 14 70 70 70 34 34 34 62 62 62
50422-250 250 250 253 253 253 253 253 253 253 253 253
50423-253 253 253 253 253 253 253 253 253 253 253 253
50424-253 253 253 253 253 253 231 231 231 246 246 246
50425-253 253 253 253 253 253 253 253 253 253 253 253
50426-253 253 253 253 253 253 253 253 253 253 253 253
50427-253 253 253 253 253 253 253 253 253 253 253 253
50428-253 253 253 253 253 253 253 253 253 253 253 253
50429-253 253 253 253 253 253 234 234 234 14 14 14
50430- 2 2 6 2 2 6 30 30 30 2 2 6
50431- 2 2 6 2 2 6 2 2 6 2 2 6
50432- 2 2 6 66 66 66 62 62 62 22 22 22
50433- 6 6 6 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 0 0 0 0
50436- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
50440- 54 54 54 62 62 62 2 2 6 2 2 6
50441- 2 2 6 30 30 30 46 46 46 70 70 70
50442-250 250 250 253 253 253 253 253 253 253 253 253
50443-253 253 253 253 253 253 253 253 253 253 253 253
50444-253 253 253 253 253 253 231 231 231 246 246 246
50445-253 253 253 253 253 253 253 253 253 253 253 253
50446-253 253 253 253 253 253 253 253 253 253 253 253
50447-253 253 253 253 253 253 253 253 253 253 253 253
50448-253 253 253 253 253 253 253 253 253 253 253 253
50449-253 253 253 253 253 253 226 226 226 10 10 10
50450- 2 2 6 6 6 6 30 30 30 2 2 6
50451- 2 2 6 2 2 6 2 2 6 2 2 6
50452- 2 2 6 66 66 66 58 58 58 22 22 22
50453- 6 6 6 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 0 0 0 0
50456- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22
50460- 58 58 58 62 62 62 2 2 6 2 2 6
50461- 2 2 6 2 2 6 30 30 30 78 78 78
50462-250 250 250 253 253 253 253 253 253 253 253 253
50463-253 253 253 253 253 253 253 253 253 253 253 253
50464-253 253 253 253 253 253 231 231 231 246 246 246
50465-253 253 253 253 253 253 253 253 253 253 253 253
50466-253 253 253 253 253 253 253 253 253 253 253 253
50467-253 253 253 253 253 253 253 253 253 253 253 253
50468-253 253 253 253 253 253 253 253 253 253 253 253
50469-253 253 253 253 253 253 206 206 206 2 2 6
50470- 22 22 22 34 34 34 18 14 6 22 22 22
50471- 26 26 26 18 18 18 6 6 6 2 2 6
50472- 2 2 6 82 82 82 54 54 54 18 18 18
50473- 6 6 6 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 6 6 6 26 26 26
50480- 62 62 62 106 106 106 74 54 14 185 133 11
50481-210 162 10 121 92 8 6 6 6 62 62 62
50482-238 238 238 253 253 253 253 253 253 253 253 253
50483-253 253 253 253 253 253 253 253 253 253 253 253
50484-253 253 253 253 253 253 231 231 231 246 246 246
50485-253 253 253 253 253 253 253 253 253 253 253 253
50486-253 253 253 253 253 253 253 253 253 253 253 253
50487-253 253 253 253 253 253 253 253 253 253 253 253
50488-253 253 253 253 253 253 253 253 253 253 253 253
50489-253 253 253 253 253 253 158 158 158 18 18 18
50490- 14 14 14 2 2 6 2 2 6 2 2 6
50491- 6 6 6 18 18 18 66 66 66 38 38 38
50492- 6 6 6 94 94 94 50 50 50 18 18 18
50493- 6 6 6 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 6 6 6
50499- 10 10 10 10 10 10 18 18 18 38 38 38
50500- 78 78 78 142 134 106 216 158 10 242 186 14
50501-246 190 14 246 190 14 156 118 10 10 10 10
50502- 90 90 90 238 238 238 253 253 253 253 253 253
50503-253 253 253 253 253 253 253 253 253 253 253 253
50504-253 253 253 253 253 253 231 231 231 250 250 250
50505-253 253 253 253 253 253 253 253 253 253 253 253
50506-253 253 253 253 253 253 253 253 253 253 253 253
50507-253 253 253 253 253 253 253 253 253 253 253 253
50508-253 253 253 253 253 253 253 253 253 246 230 190
50509-238 204 91 238 204 91 181 142 44 37 26 9
50510- 2 2 6 2 2 6 2 2 6 2 2 6
50511- 2 2 6 2 2 6 38 38 38 46 46 46
50512- 26 26 26 106 106 106 54 54 54 18 18 18
50513- 6 6 6 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 6 6 6 14 14 14 22 22 22
50519- 30 30 30 38 38 38 50 50 50 70 70 70
50520-106 106 106 190 142 34 226 170 11 242 186 14
50521-246 190 14 246 190 14 246 190 14 154 114 10
50522- 6 6 6 74 74 74 226 226 226 253 253 253
50523-253 253 253 253 253 253 253 253 253 253 253 253
50524-253 253 253 253 253 253 231 231 231 250 250 250
50525-253 253 253 253 253 253 253 253 253 253 253 253
50526-253 253 253 253 253 253 253 253 253 253 253 253
50527-253 253 253 253 253 253 253 253 253 253 253 253
50528-253 253 253 253 253 253 253 253 253 228 184 62
50529-241 196 14 241 208 19 232 195 16 38 30 10
50530- 2 2 6 2 2 6 2 2 6 2 2 6
50531- 2 2 6 6 6 6 30 30 30 26 26 26
50532-203 166 17 154 142 90 66 66 66 26 26 26
50533- 6 6 6 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- 6 6 6 18 18 18 38 38 38 58 58 58
50539- 78 78 78 86 86 86 101 101 101 123 123 123
50540-175 146 61 210 150 10 234 174 13 246 186 14
50541-246 190 14 246 190 14 246 190 14 238 190 10
50542-102 78 10 2 2 6 46 46 46 198 198 198
50543-253 253 253 253 253 253 253 253 253 253 253 253
50544-253 253 253 253 253 253 234 234 234 242 242 242
50545-253 253 253 253 253 253 253 253 253 253 253 253
50546-253 253 253 253 253 253 253 253 253 253 253 253
50547-253 253 253 253 253 253 253 253 253 253 253 253
50548-253 253 253 253 253 253 253 253 253 224 178 62
50549-242 186 14 241 196 14 210 166 10 22 18 6
50550- 2 2 6 2 2 6 2 2 6 2 2 6
50551- 2 2 6 2 2 6 6 6 6 121 92 8
50552-238 202 15 232 195 16 82 82 82 34 34 34
50553- 10 10 10 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- 14 14 14 38 38 38 70 70 70 154 122 46
50559-190 142 34 200 144 11 197 138 11 197 138 11
50560-213 154 11 226 170 11 242 186 14 246 190 14
50561-246 190 14 246 190 14 246 190 14 246 190 14
50562-225 175 15 46 32 6 2 2 6 22 22 22
50563-158 158 158 250 250 250 253 253 253 253 253 253
50564-253 253 253 253 253 253 253 253 253 253 253 253
50565-253 253 253 253 253 253 253 253 253 253 253 253
50566-253 253 253 253 253 253 253 253 253 253 253 253
50567-253 253 253 253 253 253 253 253 253 253 253 253
50568-253 253 253 250 250 250 242 242 242 224 178 62
50569-239 182 13 236 186 11 213 154 11 46 32 6
50570- 2 2 6 2 2 6 2 2 6 2 2 6
50571- 2 2 6 2 2 6 61 42 6 225 175 15
50572-238 190 10 236 186 11 112 100 78 42 42 42
50573- 14 14 14 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 6 6 6
50578- 22 22 22 54 54 54 154 122 46 213 154 11
50579-226 170 11 230 174 11 226 170 11 226 170 11
50580-236 178 12 242 186 14 246 190 14 246 190 14
50581-246 190 14 246 190 14 246 190 14 246 190 14
50582-241 196 14 184 144 12 10 10 10 2 2 6
50583- 6 6 6 116 116 116 242 242 242 253 253 253
50584-253 253 253 253 253 253 253 253 253 253 253 253
50585-253 253 253 253 253 253 253 253 253 253 253 253
50586-253 253 253 253 253 253 253 253 253 253 253 253
50587-253 253 253 253 253 253 253 253 253 253 253 253
50588-253 253 253 231 231 231 198 198 198 214 170 54
50589-236 178 12 236 178 12 210 150 10 137 92 6
50590- 18 14 6 2 2 6 2 2 6 2 2 6
50591- 6 6 6 70 47 6 200 144 11 236 178 12
50592-239 182 13 239 182 13 124 112 88 58 58 58
50593- 22 22 22 6 6 6 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 10 10 10
50598- 30 30 30 70 70 70 180 133 36 226 170 11
50599-239 182 13 242 186 14 242 186 14 246 186 14
50600-246 190 14 246 190 14 246 190 14 246 190 14
50601-246 190 14 246 190 14 246 190 14 246 190 14
50602-246 190 14 232 195 16 98 70 6 2 2 6
50603- 2 2 6 2 2 6 66 66 66 221 221 221
50604-253 253 253 253 253 253 253 253 253 253 253 253
50605-253 253 253 253 253 253 253 253 253 253 253 253
50606-253 253 253 253 253 253 253 253 253 253 253 253
50607-253 253 253 253 253 253 253 253 253 253 253 253
50608-253 253 253 206 206 206 198 198 198 214 166 58
50609-230 174 11 230 174 11 216 158 10 192 133 9
50610-163 110 8 116 81 8 102 78 10 116 81 8
50611-167 114 7 197 138 11 226 170 11 239 182 13
50612-242 186 14 242 186 14 162 146 94 78 78 78
50613- 34 34 34 14 14 14 6 6 6 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 6 6 6
50618- 30 30 30 78 78 78 190 142 34 226 170 11
50619-239 182 13 246 190 14 246 190 14 246 190 14
50620-246 190 14 246 190 14 246 190 14 246 190 14
50621-246 190 14 246 190 14 246 190 14 246 190 14
50622-246 190 14 241 196 14 203 166 17 22 18 6
50623- 2 2 6 2 2 6 2 2 6 38 38 38
50624-218 218 218 253 253 253 253 253 253 253 253 253
50625-253 253 253 253 253 253 253 253 253 253 253 253
50626-253 253 253 253 253 253 253 253 253 253 253 253
50627-253 253 253 253 253 253 253 253 253 253 253 253
50628-250 250 250 206 206 206 198 198 198 202 162 69
50629-226 170 11 236 178 12 224 166 10 210 150 10
50630-200 144 11 197 138 11 192 133 9 197 138 11
50631-210 150 10 226 170 11 242 186 14 246 190 14
50632-246 190 14 246 186 14 225 175 15 124 112 88
50633- 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
50638- 30 30 30 78 78 78 174 135 50 224 166 10
50639-239 182 13 246 190 14 246 190 14 246 190 14
50640-246 190 14 246 190 14 246 190 14 246 190 14
50641-246 190 14 246 190 14 246 190 14 246 190 14
50642-246 190 14 246 190 14 241 196 14 139 102 15
50643- 2 2 6 2 2 6 2 2 6 2 2 6
50644- 78 78 78 250 250 250 253 253 253 253 253 253
50645-253 253 253 253 253 253 253 253 253 253 253 253
50646-253 253 253 253 253 253 253 253 253 253 253 253
50647-253 253 253 253 253 253 253 253 253 253 253 253
50648-250 250 250 214 214 214 198 198 198 190 150 46
50649-219 162 10 236 178 12 234 174 13 224 166 10
50650-216 158 10 213 154 11 213 154 11 216 158 10
50651-226 170 11 239 182 13 246 190 14 246 190 14
50652-246 190 14 246 190 14 242 186 14 206 162 42
50653-101 101 101 58 58 58 30 30 30 14 14 14
50654- 6 6 6 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 10 10 10
50658- 30 30 30 74 74 74 174 135 50 216 158 10
50659-236 178 12 246 190 14 246 190 14 246 190 14
50660-246 190 14 246 190 14 246 190 14 246 190 14
50661-246 190 14 246 190 14 246 190 14 246 190 14
50662-246 190 14 246 190 14 241 196 14 226 184 13
50663- 61 42 6 2 2 6 2 2 6 2 2 6
50664- 22 22 22 238 238 238 253 253 253 253 253 253
50665-253 253 253 253 253 253 253 253 253 253 253 253
50666-253 253 253 253 253 253 253 253 253 253 253 253
50667-253 253 253 253 253 253 253 253 253 253 253 253
50668-253 253 253 226 226 226 187 187 187 180 133 36
50669-216 158 10 236 178 12 239 182 13 236 178 12
50670-230 174 11 226 170 11 226 170 11 230 174 11
50671-236 178 12 242 186 14 246 190 14 246 190 14
50672-246 190 14 246 190 14 246 186 14 239 182 13
50673-206 162 42 106 106 106 66 66 66 34 34 34
50674- 14 14 14 6 6 6 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 6 6 6
50678- 26 26 26 70 70 70 163 133 67 213 154 11
50679-236 178 12 246 190 14 246 190 14 246 190 14
50680-246 190 14 246 190 14 246 190 14 246 190 14
50681-246 190 14 246 190 14 246 190 14 246 190 14
50682-246 190 14 246 190 14 246 190 14 241 196 14
50683-190 146 13 18 14 6 2 2 6 2 2 6
50684- 46 46 46 246 246 246 253 253 253 253 253 253
50685-253 253 253 253 253 253 253 253 253 253 253 253
50686-253 253 253 253 253 253 253 253 253 253 253 253
50687-253 253 253 253 253 253 253 253 253 253 253 253
50688-253 253 253 221 221 221 86 86 86 156 107 11
50689-216 158 10 236 178 12 242 186 14 246 186 14
50690-242 186 14 239 182 13 239 182 13 242 186 14
50691-242 186 14 246 186 14 246 190 14 246 190 14
50692-246 190 14 246 190 14 246 190 14 246 190 14
50693-242 186 14 225 175 15 142 122 72 66 66 66
50694- 30 30 30 10 10 10 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 6 6 6
50698- 26 26 26 70 70 70 163 133 67 210 150 10
50699-236 178 12 246 190 14 246 190 14 246 190 14
50700-246 190 14 246 190 14 246 190 14 246 190 14
50701-246 190 14 246 190 14 246 190 14 246 190 14
50702-246 190 14 246 190 14 246 190 14 246 190 14
50703-232 195 16 121 92 8 34 34 34 106 106 106
50704-221 221 221 253 253 253 253 253 253 253 253 253
50705-253 253 253 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 253 253 253 253 253 253 253 253 253
50708-242 242 242 82 82 82 18 14 6 163 110 8
50709-216 158 10 236 178 12 242 186 14 246 190 14
50710-246 190 14 246 190 14 246 190 14 246 190 14
50711-246 190 14 246 190 14 246 190 14 246 190 14
50712-246 190 14 246 190 14 246 190 14 246 190 14
50713-246 190 14 246 190 14 242 186 14 163 133 67
50714- 46 46 46 18 18 18 6 6 6 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 10 10 10
50718- 30 30 30 78 78 78 163 133 67 210 150 10
50719-236 178 12 246 186 14 246 190 14 246 190 14
50720-246 190 14 246 190 14 246 190 14 246 190 14
50721-246 190 14 246 190 14 246 190 14 246 190 14
50722-246 190 14 246 190 14 246 190 14 246 190 14
50723-241 196 14 215 174 15 190 178 144 253 253 253
50724-253 253 253 253 253 253 253 253 253 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 253 253 253 253 253 253 218 218 218
50728- 58 58 58 2 2 6 22 18 6 167 114 7
50729-216 158 10 236 178 12 246 186 14 246 190 14
50730-246 190 14 246 190 14 246 190 14 246 190 14
50731-246 190 14 246 190 14 246 190 14 246 190 14
50732-246 190 14 246 190 14 246 190 14 246 190 14
50733-246 190 14 246 186 14 242 186 14 190 150 46
50734- 54 54 54 22 22 22 6 6 6 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 14 14 14
50738- 38 38 38 86 86 86 180 133 36 213 154 11
50739-236 178 12 246 186 14 246 190 14 246 190 14
50740-246 190 14 246 190 14 246 190 14 246 190 14
50741-246 190 14 246 190 14 246 190 14 246 190 14
50742-246 190 14 246 190 14 246 190 14 246 190 14
50743-246 190 14 232 195 16 190 146 13 214 214 214
50744-253 253 253 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 250 250 250 170 170 170 26 26 26
50748- 2 2 6 2 2 6 37 26 9 163 110 8
50749-219 162 10 239 182 13 246 186 14 246 190 14
50750-246 190 14 246 190 14 246 190 14 246 190 14
50751-246 190 14 246 190 14 246 190 14 246 190 14
50752-246 190 14 246 190 14 246 190 14 246 190 14
50753-246 186 14 236 178 12 224 166 10 142 122 72
50754- 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
50758- 50 50 50 109 106 95 192 133 9 224 166 10
50759-242 186 14 246 190 14 246 190 14 246 190 14
50760-246 190 14 246 190 14 246 190 14 246 190 14
50761-246 190 14 246 190 14 246 190 14 246 190 14
50762-246 190 14 246 190 14 246 190 14 246 190 14
50763-242 186 14 226 184 13 210 162 10 142 110 46
50764-226 226 226 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-198 198 198 66 66 66 2 2 6 2 2 6
50768- 2 2 6 2 2 6 50 34 6 156 107 11
50769-219 162 10 239 182 13 246 186 14 246 190 14
50770-246 190 14 246 190 14 246 190 14 246 190 14
50771-246 190 14 246 190 14 246 190 14 246 190 14
50772-246 190 14 246 190 14 246 190 14 242 186 14
50773-234 174 13 213 154 11 154 122 46 66 66 66
50774- 30 30 30 10 10 10 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 6 6 6 22 22 22
50778- 58 58 58 154 121 60 206 145 10 234 174 13
50779-242 186 14 246 186 14 246 190 14 246 190 14
50780-246 190 14 246 190 14 246 190 14 246 190 14
50781-246 190 14 246 190 14 246 190 14 246 190 14
50782-246 190 14 246 190 14 246 190 14 246 190 14
50783-246 186 14 236 178 12 210 162 10 163 110 8
50784- 61 42 6 138 138 138 218 218 218 250 250 250
50785-253 253 253 253 253 253 253 253 253 250 250 250
50786-242 242 242 210 210 210 144 144 144 66 66 66
50787- 6 6 6 2 2 6 2 2 6 2 2 6
50788- 2 2 6 2 2 6 61 42 6 163 110 8
50789-216 158 10 236 178 12 246 190 14 246 190 14
50790-246 190 14 246 190 14 246 190 14 246 190 14
50791-246 190 14 246 190 14 246 190 14 246 190 14
50792-246 190 14 239 182 13 230 174 11 216 158 10
50793-190 142 34 124 112 88 70 70 70 38 38 38
50794- 18 18 18 6 6 6 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 6 6 6 22 22 22
50798- 62 62 62 168 124 44 206 145 10 224 166 10
50799-236 178 12 239 182 13 242 186 14 242 186 14
50800-246 186 14 246 190 14 246 190 14 246 190 14
50801-246 190 14 246 190 14 246 190 14 246 190 14
50802-246 190 14 246 190 14 246 190 14 246 190 14
50803-246 190 14 236 178 12 216 158 10 175 118 6
50804- 80 54 7 2 2 6 6 6 6 30 30 30
50805- 54 54 54 62 62 62 50 50 50 38 38 38
50806- 14 14 14 2 2 6 2 2 6 2 2 6
50807- 2 2 6 2 2 6 2 2 6 2 2 6
50808- 2 2 6 6 6 6 80 54 7 167 114 7
50809-213 154 11 236 178 12 246 190 14 246 190 14
50810-246 190 14 246 190 14 246 190 14 246 190 14
50811-246 190 14 242 186 14 239 182 13 239 182 13
50812-230 174 11 210 150 10 174 135 50 124 112 88
50813- 82 82 82 54 54 54 34 34 34 18 18 18
50814- 6 6 6 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 6 6 6 18 18 18
50818- 50 50 50 158 118 36 192 133 9 200 144 11
50819-216 158 10 219 162 10 224 166 10 226 170 11
50820-230 174 11 236 178 12 239 182 13 239 182 13
50821-242 186 14 246 186 14 246 190 14 246 190 14
50822-246 190 14 246 190 14 246 190 14 246 190 14
50823-246 186 14 230 174 11 210 150 10 163 110 8
50824-104 69 6 10 10 10 2 2 6 2 2 6
50825- 2 2 6 2 2 6 2 2 6 2 2 6
50826- 2 2 6 2 2 6 2 2 6 2 2 6
50827- 2 2 6 2 2 6 2 2 6 2 2 6
50828- 2 2 6 6 6 6 91 60 6 167 114 7
50829-206 145 10 230 174 11 242 186 14 246 190 14
50830-246 190 14 246 190 14 246 186 14 242 186 14
50831-239 182 13 230 174 11 224 166 10 213 154 11
50832-180 133 36 124 112 88 86 86 86 58 58 58
50833- 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
50838- 34 34 34 70 70 70 138 110 50 158 118 36
50839-167 114 7 180 123 7 192 133 9 197 138 11
50840-200 144 11 206 145 10 213 154 11 219 162 10
50841-224 166 10 230 174 11 239 182 13 242 186 14
50842-246 186 14 246 186 14 246 186 14 246 186 14
50843-239 182 13 216 158 10 185 133 11 152 99 6
50844-104 69 6 18 14 6 2 2 6 2 2 6
50845- 2 2 6 2 2 6 2 2 6 2 2 6
50846- 2 2 6 2 2 6 2 2 6 2 2 6
50847- 2 2 6 2 2 6 2 2 6 2 2 6
50848- 2 2 6 6 6 6 80 54 7 152 99 6
50849-192 133 9 219 162 10 236 178 12 239 182 13
50850-246 186 14 242 186 14 239 182 13 236 178 12
50851-224 166 10 206 145 10 192 133 9 154 121 60
50852- 94 94 94 62 62 62 42 42 42 22 22 22
50853- 14 14 14 6 6 6 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 6 6 6
50858- 18 18 18 34 34 34 58 58 58 78 78 78
50859-101 98 89 124 112 88 142 110 46 156 107 11
50860-163 110 8 167 114 7 175 118 6 180 123 7
50861-185 133 11 197 138 11 210 150 10 219 162 10
50862-226 170 11 236 178 12 236 178 12 234 174 13
50863-219 162 10 197 138 11 163 110 8 130 83 6
50864- 91 60 6 10 10 10 2 2 6 2 2 6
50865- 18 18 18 38 38 38 38 38 38 38 38 38
50866- 38 38 38 38 38 38 38 38 38 38 38 38
50867- 38 38 38 38 38 38 26 26 26 2 2 6
50868- 2 2 6 6 6 6 70 47 6 137 92 6
50869-175 118 6 200 144 11 219 162 10 230 174 11
50870-234 174 13 230 174 11 219 162 10 210 150 10
50871-192 133 9 163 110 8 124 112 88 82 82 82
50872- 50 50 50 30 30 30 14 14 14 6 6 6
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- 6 6 6 14 14 14 22 22 22 34 34 34
50879- 42 42 42 58 58 58 74 74 74 86 86 86
50880-101 98 89 122 102 70 130 98 46 121 87 25
50881-137 92 6 152 99 6 163 110 8 180 123 7
50882-185 133 11 197 138 11 206 145 10 200 144 11
50883-180 123 7 156 107 11 130 83 6 104 69 6
50884- 50 34 6 54 54 54 110 110 110 101 98 89
50885- 86 86 86 82 82 82 78 78 78 78 78 78
50886- 78 78 78 78 78 78 78 78 78 78 78 78
50887- 78 78 78 82 82 82 86 86 86 94 94 94
50888-106 106 106 101 101 101 86 66 34 124 80 6
50889-156 107 11 180 123 7 192 133 9 200 144 11
50890-206 145 10 200 144 11 192 133 9 175 118 6
50891-139 102 15 109 106 95 70 70 70 42 42 42
50892- 22 22 22 10 10 10 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 6 6 6 10 10 10
50899- 14 14 14 22 22 22 30 30 30 38 38 38
50900- 50 50 50 62 62 62 74 74 74 90 90 90
50901-101 98 89 112 100 78 121 87 25 124 80 6
50902-137 92 6 152 99 6 152 99 6 152 99 6
50903-138 86 6 124 80 6 98 70 6 86 66 30
50904-101 98 89 82 82 82 58 58 58 46 46 46
50905- 38 38 38 34 34 34 34 34 34 34 34 34
50906- 34 34 34 34 34 34 34 34 34 34 34 34
50907- 34 34 34 34 34 34 38 38 38 42 42 42
50908- 54 54 54 82 82 82 94 86 76 91 60 6
50909-134 86 6 156 107 11 167 114 7 175 118 6
50910-175 118 6 167 114 7 152 99 6 121 87 25
50911-101 98 89 62 62 62 34 34 34 18 18 18
50912- 6 6 6 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 6 6 6 6 6 6 10 10 10
50920- 18 18 18 22 22 22 30 30 30 42 42 42
50921- 50 50 50 66 66 66 86 86 86 101 98 89
50922-106 86 58 98 70 6 104 69 6 104 69 6
50923-104 69 6 91 60 6 82 62 34 90 90 90
50924- 62 62 62 38 38 38 22 22 22 14 14 14
50925- 10 10 10 10 10 10 10 10 10 10 10 10
50926- 10 10 10 10 10 10 6 6 6 10 10 10
50927- 10 10 10 10 10 10 10 10 10 14 14 14
50928- 22 22 22 42 42 42 70 70 70 89 81 66
50929- 80 54 7 104 69 6 124 80 6 137 92 6
50930-134 86 6 116 81 8 100 82 52 86 86 86
50931- 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
50940- 0 0 0 6 6 6 10 10 10 14 14 14
50941- 18 18 18 26 26 26 38 38 38 54 54 54
50942- 70 70 70 86 86 86 94 86 76 89 81 66
50943- 89 81 66 86 86 86 74 74 74 50 50 50
50944- 30 30 30 14 14 14 6 6 6 0 0 0
50945- 0 0 0 0 0 0 0 0 0 0 0 0
50946- 0 0 0 0 0 0 0 0 0 0 0 0
50947- 0 0 0 0 0 0 0 0 0 0 0 0
50948- 6 6 6 18 18 18 34 34 34 58 58 58
50949- 82 82 82 89 81 66 89 81 66 89 81 66
50950- 94 86 66 94 86 76 74 74 74 50 50 50
50951- 26 26 26 14 14 14 6 6 6 0 0 0
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 0 0 0 0 0 0 0 0 0
50960- 0 0 0 0 0 0 0 0 0 0 0 0
50961- 6 6 6 6 6 6 14 14 14 18 18 18
50962- 30 30 30 38 38 38 46 46 46 54 54 54
50963- 50 50 50 42 42 42 30 30 30 18 18 18
50964- 10 10 10 0 0 0 0 0 0 0 0 0
50965- 0 0 0 0 0 0 0 0 0 0 0 0
50966- 0 0 0 0 0 0 0 0 0 0 0 0
50967- 0 0 0 0 0 0 0 0 0 0 0 0
50968- 0 0 0 6 6 6 14 14 14 26 26 26
50969- 38 38 38 50 50 50 58 58 58 58 58 58
50970- 54 54 54 42 42 42 30 30 30 18 18 18
50971- 10 10 10 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
50980- 0 0 0 0 0 0 0 0 0 0 0 0
50981- 0 0 0 0 0 0 0 0 0 6 6 6
50982- 6 6 6 10 10 10 14 14 14 18 18 18
50983- 18 18 18 14 14 14 10 10 10 6 6 6
50984- 0 0 0 0 0 0 0 0 0 0 0 0
50985- 0 0 0 0 0 0 0 0 0 0 0 0
50986- 0 0 0 0 0 0 0 0 0 0 0 0
50987- 0 0 0 0 0 0 0 0 0 0 0 0
50988- 0 0 0 0 0 0 0 0 0 6 6 6
50989- 14 14 14 18 18 18 22 22 22 22 22 22
50990- 18 18 18 14 14 14 10 10 10 6 6 6
50991- 0 0 0 0 0 0 0 0 0 0 0 0
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51009+4 4 4 4 4 4
51010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51023+4 4 4 4 4 4
51024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51037+4 4 4 4 4 4
51038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51051+4 4 4 4 4 4
51052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51065+4 4 4 4 4 4
51066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51079+4 4 4 4 4 4
51080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51084+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
51085+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
51086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51089+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
51090+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51091+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
51092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51093+4 4 4 4 4 4
51094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51098+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
51099+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
51100+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51103+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
51104+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
51105+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
51106+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51107+4 4 4 4 4 4
51108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51112+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
51113+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
51114+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51117+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
51118+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
51119+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
51120+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
51121+4 4 4 4 4 4
51122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51125+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
51126+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
51127+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
51128+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
51129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51130+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51131+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
51132+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
51133+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
51134+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
51135+4 4 4 4 4 4
51136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51139+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
51140+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
51141+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
51142+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
51143+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51144+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
51145+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
51146+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
51147+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
51148+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
51149+4 4 4 4 4 4
51150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51153+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
51154+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
51155+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
51156+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
51157+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51158+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
51159+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
51160+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
51161+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
51162+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
51163+4 4 4 4 4 4
51164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51166+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
51167+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
51168+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
51169+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
51170+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
51171+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
51172+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
51173+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
51174+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
51175+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
51176+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
51177+4 4 4 4 4 4
51178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51180+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
51181+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
51182+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
51183+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
51184+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
51185+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
51186+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
51187+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
51188+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
51189+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
51190+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
51191+4 4 4 4 4 4
51192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51194+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
51195+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
51196+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
51197+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
51198+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
51199+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
51200+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
51201+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
51202+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
51203+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
51204+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51205+4 4 4 4 4 4
51206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51208+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
51209+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
51210+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
51211+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
51212+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
51213+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
51214+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
51215+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
51216+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
51217+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
51218+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
51219+4 4 4 4 4 4
51220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51221+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
51222+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
51223+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
51224+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
51225+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
51226+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
51227+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
51228+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
51229+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
51230+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
51231+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
51232+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
51233+4 4 4 4 4 4
51234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51235+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
51236+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
51237+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
51238+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51239+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
51240+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
51241+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
51242+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
51243+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
51244+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
51245+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
51246+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
51247+0 0 0 4 4 4
51248+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51249+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
51250+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
51251+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
51252+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
51253+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
51254+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
51255+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
51256+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
51257+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
51258+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
51259+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
51260+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
51261+2 0 0 0 0 0
51262+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
51263+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
51264+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
51265+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
51266+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
51267+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
51268+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
51269+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
51270+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
51271+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
51272+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
51273+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
51274+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
51275+37 38 37 0 0 0
51276+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51277+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
51278+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
51279+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
51280+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
51281+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
51282+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
51283+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
51284+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
51285+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
51286+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
51287+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
51288+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
51289+85 115 134 4 0 0
51290+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
51291+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
51292+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
51293+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
51294+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
51295+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
51296+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
51297+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
51298+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
51299+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
51300+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
51301+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
51302+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
51303+60 73 81 4 0 0
51304+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
51305+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
51306+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
51307+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
51308+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
51309+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
51310+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
51311+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
51312+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
51313+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
51314+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
51315+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
51316+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
51317+16 19 21 4 0 0
51318+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51319+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51320+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51321+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51322+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51323+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51324+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51325+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51326+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51327+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51328+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51329+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51330+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51331+4 0 0 4 3 3
51332+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51333+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51334+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51336+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51337+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51338+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51339+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51340+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
51341+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
51342+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
51343+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
51344+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
51345+3 2 2 4 4 4
51346+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
51347+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
51348+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
51349+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51350+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
51351+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
51352+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
51353+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
51354+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
51355+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
51356+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
51357+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
51358+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
51359+4 4 4 4 4 4
51360+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
51361+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
51362+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
51363+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
51364+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
51365+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
51366+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
51367+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
51368+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
51369+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
51370+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
51371+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
51372+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
51373+4 4 4 4 4 4
51374+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
51375+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
51376+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
51377+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
51378+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
51379+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51380+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
51381+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
51382+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
51383+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
51384+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
51385+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
51386+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
51387+5 5 5 5 5 5
51388+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
51389+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
51390+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
51391+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
51392+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
51393+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51394+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
51395+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
51396+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
51397+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
51398+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
51399+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
51400+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51401+5 5 5 4 4 4
51402+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
51403+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
51404+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
51405+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
51406+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51407+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
51408+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
51409+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51410+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51411+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51412+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51413+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51415+4 4 4 4 4 4
51416+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51417+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51418+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51419+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51420+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51421+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51422+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51423+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51424+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51425+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51426+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51427+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51429+4 4 4 4 4 4
51430+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51431+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51432+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51433+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51434+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51435+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51436+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51437+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51438+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51439+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51440+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51443+4 4 4 4 4 4
51444+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51445+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51446+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51447+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51448+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51449+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51450+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51451+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51452+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51453+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51454+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51457+4 4 4 4 4 4
51458+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51459+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51460+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51461+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51462+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51463+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51464+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51465+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51466+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51467+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51468+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51471+4 4 4 4 4 4
51472+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51473+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51474+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51475+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51476+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51477+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51478+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51479+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51480+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51481+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51482+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51485+4 4 4 4 4 4
51486+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51487+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51488+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51489+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51490+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51491+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51492+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51493+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51494+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51495+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51496+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51499+4 4 4 4 4 4
51500+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51501+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51502+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51503+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51504+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51505+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51506+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51507+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51508+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51509+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51510+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51513+4 4 4 4 4 4
51514+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51515+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51516+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51517+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51518+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51519+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51520+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51521+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51522+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51523+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51524+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51527+4 4 4 4 4 4
51528+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51529+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51530+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51531+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51532+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51533+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51534+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51535+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51536+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51537+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51538+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51541+4 4 4 4 4 4
51542+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51543+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51544+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51545+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51546+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51547+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51548+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51549+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51550+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51551+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51552+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51555+4 4 4 4 4 4
51556+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51557+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51558+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51559+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51560+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51561+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51562+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51563+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51564+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51565+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51566+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51569+4 4 4 4 4 4
51570+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51571+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51572+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51573+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51574+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51575+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51576+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51577+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51578+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51579+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51580+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51583+4 4 4 4 4 4
51584+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51585+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51586+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51587+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51588+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51589+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51590+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51591+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51592+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51593+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51594+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51597+4 4 4 4 4 4
51598+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51599+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51600+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51601+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51602+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51603+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51604+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51605+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51606+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51607+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51608+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51611+4 4 4 4 4 4
51612+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51613+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51614+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51615+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51616+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51617+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51618+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51619+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51620+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51621+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51622+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51625+4 4 4 4 4 4
51626+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51627+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51628+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51629+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51630+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51631+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51632+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51633+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51634+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51635+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51636+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51639+4 4 4 4 4 4
51640+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51641+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51642+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51643+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51644+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51645+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51646+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51647+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51648+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51649+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51650+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51653+4 4 4 4 4 4
51654+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51655+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51656+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51657+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51658+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51659+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51660+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51661+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51662+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51663+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51664+0 0 0 3 3 3 5 5 5 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
51668+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51669+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51670+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51671+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51672+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51673+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51674+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51675+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51676+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51677+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51678+0 0 0 3 3 3 5 5 5 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
51682+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51683+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51684+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51685+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51686+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51687+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51688+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51689+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51690+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51691+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51692+0 0 0 3 3 3 5 5 5 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
51696+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51697+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51698+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51699+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51700+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51701+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51702+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51703+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51704+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51705+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51706+0 0 0 3 3 3 5 5 5 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
51710+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51711+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51712+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51713+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51714+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51715+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51716+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51717+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51718+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51719+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51720+0 0 0 3 3 3 5 5 5 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
51724+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51725+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51726+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51727+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51728+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51729+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51730+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51731+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51732+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51733+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51734+0 0 0 3 3 3 5 5 5 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
51738+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51739+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51740+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51741+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51742+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51743+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51744+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51745+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51746+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51747+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51748+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51751+4 4 4 4 4 4
51752+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51753+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51754+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51755+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51756+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51757+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51758+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51759+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51760+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51761+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51762+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51765+4 4 4 4 4 4
51766+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51767+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51768+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51769+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51770+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51771+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51772+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51773+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51774+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51775+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51776+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51779+4 4 4 4 4 4
51780+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51781+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51782+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51783+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51784+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51785+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51786+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51787+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51788+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51789+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51790+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51793+4 4 4 4 4 4
51794+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51795+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51796+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51797+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51798+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51799+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51800+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51801+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51802+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51803+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51804+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51807+4 4 4 4 4 4
51808+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51809+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51810+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51811+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51812+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51813+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51814+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51815+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51816+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51817+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51821+4 4 4 4 4 4
51822+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51823+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51824+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51825+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51826+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51827+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51828+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51829+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51830+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51831+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51835+4 4 4 4 4 4
51836+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51837+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51838+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51839+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51840+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51841+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51842+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51843+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51844+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51845+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51849+4 4 4 4 4 4
51850+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51851+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51852+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51853+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51854+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51855+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51856+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51857+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51858+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51859+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51863+4 4 4 4 4 4
51864+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51865+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51866+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51867+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51868+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51869+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51870+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51871+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51872+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51877+4 4 4 4 4 4
51878+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51879+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51880+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51881+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51882+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51883+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51884+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51885+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51886+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51891+4 4 4 4 4 4
51892+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51893+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51894+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51895+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51896+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51897+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51898+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51899+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51900+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51905+4 4 4 4 4 4
51906+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51907+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51908+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51909+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51910+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51911+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51912+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51913+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51919+4 4 4 4 4 4
51920+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51921+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51922+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51923+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51924+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51925+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51926+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51927+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51933+4 4 4 4 4 4
51934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51935+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51936+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51937+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51938+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51939+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51940+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51941+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51947+4 4 4 4 4 4
51948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51949+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51950+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51951+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51952+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51953+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51954+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51955+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51961+4 4 4 4 4 4
51962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51963+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51964+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51965+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51966+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51967+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51968+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51969+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51975+4 4 4 4 4 4
51976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51978+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51979+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51980+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51981+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51982+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51983+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51989+4 4 4 4 4 4
51990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51993+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51994+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51995+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51996+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52003+4 4 4 4 4 4
52004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52007+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52008+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52009+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
52010+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
52011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52017+4 4 4 4 4 4
52018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52021+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52022+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52023+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52024+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
52025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52031+4 4 4 4 4 4
52032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52035+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
52036+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
52037+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
52038+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
52039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52045+4 4 4 4 4 4
52046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52050+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
52051+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52052+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52059+4 4 4 4 4 4
52060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52064+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
52065+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
52066+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52073+4 4 4 4 4 4
52074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52078+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
52079+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
52080+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52087+4 4 4 4 4 4
52088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52092+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
52093+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
52094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
52102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52106+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52107+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
52108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52113+4 4 4 4 4 4 4 4 4 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
52116diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
52117index fe92eed..106e085 100644
52118--- a/drivers/video/mb862xx/mb862xxfb_accel.c
52119+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
52120@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52121 struct mb862xxfb_par *par = info->par;
52122
52123 if (info->var.bits_per_pixel == 32) {
52124- info->fbops->fb_fillrect = cfb_fillrect;
52125- info->fbops->fb_copyarea = cfb_copyarea;
52126- info->fbops->fb_imageblit = cfb_imageblit;
52127+ pax_open_kernel();
52128+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52129+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52130+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52131+ pax_close_kernel();
52132 } else {
52133 outreg(disp, GC_L0EM, 3);
52134- info->fbops->fb_fillrect = mb86290fb_fillrect;
52135- info->fbops->fb_copyarea = mb86290fb_copyarea;
52136- info->fbops->fb_imageblit = mb86290fb_imageblit;
52137+ pax_open_kernel();
52138+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52139+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52140+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52141+ pax_close_kernel();
52142 }
52143 outreg(draw, GDC_REG_DRAW_BASE, 0);
52144 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52145diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
52146index ff22871..b129bed 100644
52147--- a/drivers/video/nvidia/nvidia.c
52148+++ b/drivers/video/nvidia/nvidia.c
52149@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52150 info->fix.line_length = (info->var.xres_virtual *
52151 info->var.bits_per_pixel) >> 3;
52152 if (info->var.accel_flags) {
52153- info->fbops->fb_imageblit = nvidiafb_imageblit;
52154- info->fbops->fb_fillrect = nvidiafb_fillrect;
52155- info->fbops->fb_copyarea = nvidiafb_copyarea;
52156- info->fbops->fb_sync = nvidiafb_sync;
52157+ pax_open_kernel();
52158+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52159+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52160+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52161+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52162+ pax_close_kernel();
52163 info->pixmap.scan_align = 4;
52164 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52165 info->flags |= FBINFO_READS_FAST;
52166 NVResetGraphics(info);
52167 } else {
52168- info->fbops->fb_imageblit = cfb_imageblit;
52169- info->fbops->fb_fillrect = cfb_fillrect;
52170- info->fbops->fb_copyarea = cfb_copyarea;
52171- info->fbops->fb_sync = NULL;
52172+ pax_open_kernel();
52173+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52174+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52175+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52176+ *(void **)&info->fbops->fb_sync = NULL;
52177+ pax_close_kernel();
52178 info->pixmap.scan_align = 1;
52179 info->flags |= FBINFO_HWACCEL_DISABLED;
52180 info->flags &= ~FBINFO_READS_FAST;
52181@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52182 info->pixmap.size = 8 * 1024;
52183 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52184
52185- if (!hwcur)
52186- info->fbops->fb_cursor = NULL;
52187+ if (!hwcur) {
52188+ pax_open_kernel();
52189+ *(void **)&info->fbops->fb_cursor = NULL;
52190+ pax_close_kernel();
52191+ }
52192
52193 info->var.accel_flags = (!noaccel);
52194
52195diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
52196index 05c2dc3..ea1f391 100644
52197--- a/drivers/video/s1d13xxxfb.c
52198+++ b/drivers/video/s1d13xxxfb.c
52199@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52200
52201 switch(prod_id) {
52202 case S1D13506_PROD_ID: /* activate acceleration */
52203- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52204- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52205+ pax_open_kernel();
52206+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52207+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52208+ pax_close_kernel();
52209 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52210 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52211 break;
52212diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
52213index e188ada..aac63c8 100644
52214--- a/drivers/video/smscufx.c
52215+++ b/drivers/video/smscufx.c
52216@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52217 fb_deferred_io_cleanup(info);
52218 kfree(info->fbdefio);
52219 info->fbdefio = NULL;
52220- info->fbops->fb_mmap = ufx_ops_mmap;
52221+ pax_open_kernel();
52222+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52223+ pax_close_kernel();
52224 }
52225
52226 pr_debug("released /dev/fb%d user=%d count=%d",
52227diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
52228index d2e5bc3..4cb05d1 100644
52229--- a/drivers/video/udlfb.c
52230+++ b/drivers/video/udlfb.c
52231@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52232 dlfb_urb_completion(urb);
52233
52234 error:
52235- atomic_add(bytes_sent, &dev->bytes_sent);
52236- atomic_add(bytes_identical, &dev->bytes_identical);
52237- atomic_add(width*height*2, &dev->bytes_rendered);
52238+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52239+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52240+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52241 end_cycles = get_cycles();
52242- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52243+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52244 >> 10)), /* Kcycles */
52245 &dev->cpu_kcycles_used);
52246
52247@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52248 dlfb_urb_completion(urb);
52249
52250 error:
52251- atomic_add(bytes_sent, &dev->bytes_sent);
52252- atomic_add(bytes_identical, &dev->bytes_identical);
52253- atomic_add(bytes_rendered, &dev->bytes_rendered);
52254+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52255+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52256+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52257 end_cycles = get_cycles();
52258- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52259+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52260 >> 10)), /* Kcycles */
52261 &dev->cpu_kcycles_used);
52262 }
52263@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52264 fb_deferred_io_cleanup(info);
52265 kfree(info->fbdefio);
52266 info->fbdefio = NULL;
52267- info->fbops->fb_mmap = dlfb_ops_mmap;
52268+ pax_open_kernel();
52269+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52270+ pax_close_kernel();
52271 }
52272
52273 pr_warn("released /dev/fb%d user=%d count=%d\n",
52274@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52275 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52276 struct dlfb_data *dev = fb_info->par;
52277 return snprintf(buf, PAGE_SIZE, "%u\n",
52278- atomic_read(&dev->bytes_rendered));
52279+ atomic_read_unchecked(&dev->bytes_rendered));
52280 }
52281
52282 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52283@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52284 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52285 struct dlfb_data *dev = fb_info->par;
52286 return snprintf(buf, PAGE_SIZE, "%u\n",
52287- atomic_read(&dev->bytes_identical));
52288+ atomic_read_unchecked(&dev->bytes_identical));
52289 }
52290
52291 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52292@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52293 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52294 struct dlfb_data *dev = fb_info->par;
52295 return snprintf(buf, PAGE_SIZE, "%u\n",
52296- atomic_read(&dev->bytes_sent));
52297+ atomic_read_unchecked(&dev->bytes_sent));
52298 }
52299
52300 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52301@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52302 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52303 struct dlfb_data *dev = fb_info->par;
52304 return snprintf(buf, PAGE_SIZE, "%u\n",
52305- atomic_read(&dev->cpu_kcycles_used));
52306+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52307 }
52308
52309 static ssize_t edid_show(
52310@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52311 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52312 struct dlfb_data *dev = fb_info->par;
52313
52314- atomic_set(&dev->bytes_rendered, 0);
52315- atomic_set(&dev->bytes_identical, 0);
52316- atomic_set(&dev->bytes_sent, 0);
52317- atomic_set(&dev->cpu_kcycles_used, 0);
52318+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52319+ atomic_set_unchecked(&dev->bytes_identical, 0);
52320+ atomic_set_unchecked(&dev->bytes_sent, 0);
52321+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52322
52323 return count;
52324 }
52325diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
52326index 7aec6f3..e3b2d55 100644
52327--- a/drivers/video/uvesafb.c
52328+++ b/drivers/video/uvesafb.c
52329@@ -19,6 +19,7 @@
52330 #include <linux/io.h>
52331 #include <linux/mutex.h>
52332 #include <linux/slab.h>
52333+#include <linux/moduleloader.h>
52334 #include <video/edid.h>
52335 #include <video/uvesafb.h>
52336 #ifdef CONFIG_X86
52337@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52338 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52339 par->pmi_setpal = par->ypan = 0;
52340 } else {
52341+
52342+#ifdef CONFIG_PAX_KERNEXEC
52343+#ifdef CONFIG_MODULES
52344+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52345+#endif
52346+ if (!par->pmi_code) {
52347+ par->pmi_setpal = par->ypan = 0;
52348+ return 0;
52349+ }
52350+#endif
52351+
52352 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52353 + task->t.regs.edi);
52354+
52355+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52356+ pax_open_kernel();
52357+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52358+ pax_close_kernel();
52359+
52360+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52361+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52362+#else
52363 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52364 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52365+#endif
52366+
52367 printk(KERN_INFO "uvesafb: protected mode interface info at "
52368 "%04x:%04x\n",
52369 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52370@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52371 par->ypan = ypan;
52372
52373 if (par->pmi_setpal || par->ypan) {
52374+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52375 if (__supported_pte_mask & _PAGE_NX) {
52376 par->pmi_setpal = par->ypan = 0;
52377 printk(KERN_WARNING "uvesafb: NX protection is active, "
52378 "better not use the PMI.\n");
52379- } else {
52380+ } else
52381+#endif
52382 uvesafb_vbe_getpmi(task, par);
52383- }
52384 }
52385 #else
52386 /* The protected mode interface is not available on non-x86. */
52387@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52388 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52389
52390 /* Disable blanking if the user requested so. */
52391- if (!blank)
52392- info->fbops->fb_blank = NULL;
52393+ if (!blank) {
52394+ pax_open_kernel();
52395+ *(void **)&info->fbops->fb_blank = NULL;
52396+ pax_close_kernel();
52397+ }
52398
52399 /*
52400 * Find out how much IO memory is required for the mode with
52401@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52402 info->flags = FBINFO_FLAG_DEFAULT |
52403 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52404
52405- if (!par->ypan)
52406- info->fbops->fb_pan_display = NULL;
52407+ if (!par->ypan) {
52408+ pax_open_kernel();
52409+ *(void **)&info->fbops->fb_pan_display = NULL;
52410+ pax_close_kernel();
52411+ }
52412 }
52413
52414 static void uvesafb_init_mtrr(struct fb_info *info)
52415@@ -1796,6 +1826,11 @@ out:
52416 if (par->vbe_modes)
52417 kfree(par->vbe_modes);
52418
52419+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52420+ if (par->pmi_code)
52421+ module_free_exec(NULL, par->pmi_code);
52422+#endif
52423+
52424 framebuffer_release(info);
52425 return err;
52426 }
52427@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
52428 kfree(par->vbe_state_orig);
52429 if (par->vbe_state_saved)
52430 kfree(par->vbe_state_saved);
52431+
52432+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52433+ if (par->pmi_code)
52434+ module_free_exec(NULL, par->pmi_code);
52435+#endif
52436+
52437 }
52438
52439 framebuffer_release(info);
52440diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52441index bd83233..7d8a5aa 100644
52442--- a/drivers/video/vesafb.c
52443+++ b/drivers/video/vesafb.c
52444@@ -9,6 +9,7 @@
52445 */
52446
52447 #include <linux/module.h>
52448+#include <linux/moduleloader.h>
52449 #include <linux/kernel.h>
52450 #include <linux/errno.h>
52451 #include <linux/string.h>
52452@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
52453 static int vram_total; /* Set total amount of memory */
52454 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52455 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52456-static void (*pmi_start)(void) __read_mostly;
52457-static void (*pmi_pal) (void) __read_mostly;
52458+static void (*pmi_start)(void) __read_only;
52459+static void (*pmi_pal) (void) __read_only;
52460 static int depth __read_mostly;
52461 static int vga_compat __read_mostly;
52462 /* --------------------------------------------------------------------- */
52463@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
52464 unsigned int size_remap;
52465 unsigned int size_total;
52466 char *option = NULL;
52467+ void *pmi_code = NULL;
52468
52469 /* ignore error return of fb_get_options */
52470 fb_get_options("vesafb", &option);
52471@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
52472 size_remap = size_total;
52473 vesafb_fix.smem_len = size_remap;
52474
52475-#ifndef __i386__
52476- screen_info.vesapm_seg = 0;
52477-#endif
52478-
52479 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52480 printk(KERN_WARNING
52481 "vesafb: cannot reserve video memory at 0x%lx\n",
52482@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
52483 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52484 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52485
52486+#ifdef __i386__
52487+
52488+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52489+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52490+ if (!pmi_code)
52491+#elif !defined(CONFIG_PAX_KERNEXEC)
52492+ if (0)
52493+#endif
52494+
52495+#endif
52496+ screen_info.vesapm_seg = 0;
52497+
52498 if (screen_info.vesapm_seg) {
52499- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52500- screen_info.vesapm_seg,screen_info.vesapm_off);
52501+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52502+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52503 }
52504
52505 if (screen_info.vesapm_seg < 0xc000)
52506@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
52507
52508 if (ypan || pmi_setpal) {
52509 unsigned short *pmi_base;
52510+
52511 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52512- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52513- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52514+
52515+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52516+ pax_open_kernel();
52517+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52518+#else
52519+ pmi_code = pmi_base;
52520+#endif
52521+
52522+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52523+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52524+
52525+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52526+ pmi_start = ktva_ktla(pmi_start);
52527+ pmi_pal = ktva_ktla(pmi_pal);
52528+ pax_close_kernel();
52529+#endif
52530+
52531 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52532 if (pmi_base[3]) {
52533 printk(KERN_INFO "vesafb: pmi: ports = ");
52534@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
52535 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52536 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52537
52538- if (!ypan)
52539- info->fbops->fb_pan_display = NULL;
52540+ if (!ypan) {
52541+ pax_open_kernel();
52542+ *(void **)&info->fbops->fb_pan_display = NULL;
52543+ pax_close_kernel();
52544+ }
52545
52546 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52547 err = -ENOMEM;
52548@@ -493,6 +522,11 @@ static int vesafb_probe(struct platform_device *dev)
52549 info->node, info->fix.id);
52550 return 0;
52551 err:
52552+
52553+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52554+ module_free_exec(NULL, pmi_code);
52555+#endif
52556+
52557 if (info->screen_base)
52558 iounmap(info->screen_base);
52559 framebuffer_release(info);
52560diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52561index 88714ae..16c2e11 100644
52562--- a/drivers/video/via/via_clock.h
52563+++ b/drivers/video/via/via_clock.h
52564@@ -56,7 +56,7 @@ struct via_clock {
52565
52566 void (*set_engine_pll_state)(u8 state);
52567 void (*set_engine_pll)(struct via_pll_config config);
52568-};
52569+} __no_const;
52570
52571
52572 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52573diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52574index fef20db..d28b1ab 100644
52575--- a/drivers/xen/xenfs/xenstored.c
52576+++ b/drivers/xen/xenfs/xenstored.c
52577@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52578 static int xsd_kva_open(struct inode *inode, struct file *file)
52579 {
52580 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52581+#ifdef CONFIG_GRKERNSEC_HIDESYM
52582+ NULL);
52583+#else
52584 xen_store_interface);
52585+#endif
52586+
52587 if (!file->private_data)
52588 return -ENOMEM;
52589 return 0;
52590diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52591index 9ff073f..05cef23 100644
52592--- a/fs/9p/vfs_addr.c
52593+++ b/fs/9p/vfs_addr.c
52594@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52595
52596 retval = v9fs_file_write_internal(inode,
52597 v9inode->writeback_fid,
52598- (__force const char __user *)buffer,
52599+ (const char __force_user *)buffer,
52600 len, &offset, 0);
52601 if (retval > 0)
52602 retval = 0;
52603diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52604index 94de6d1..8d81256 100644
52605--- a/fs/9p/vfs_inode.c
52606+++ b/fs/9p/vfs_inode.c
52607@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52608 void
52609 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52610 {
52611- char *s = nd_get_link(nd);
52612+ const char *s = nd_get_link(nd);
52613
52614 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52615 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52616diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52617index 370b24c..ff0be7b 100644
52618--- a/fs/Kconfig.binfmt
52619+++ b/fs/Kconfig.binfmt
52620@@ -103,7 +103,7 @@ config HAVE_AOUT
52621
52622 config BINFMT_AOUT
52623 tristate "Kernel support for a.out and ECOFF binaries"
52624- depends on HAVE_AOUT
52625+ depends on HAVE_AOUT && BROKEN
52626 ---help---
52627 A.out (Assembler.OUTput) is a set of formats for libraries and
52628 executables used in the earliest versions of UNIX. Linux used
52629diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52630index 789bc25..fafaeea 100644
52631--- a/fs/afs/inode.c
52632+++ b/fs/afs/inode.c
52633@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52634 struct afs_vnode *vnode;
52635 struct super_block *sb;
52636 struct inode *inode;
52637- static atomic_t afs_autocell_ino;
52638+ static atomic_unchecked_t afs_autocell_ino;
52639
52640 _enter("{%x:%u},%*.*s,",
52641 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52642@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52643 data.fid.unique = 0;
52644 data.fid.vnode = 0;
52645
52646- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52647+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52648 afs_iget5_autocell_test, afs_iget5_set,
52649 &data);
52650 if (!inode) {
52651diff --git a/fs/aio.c b/fs/aio.c
52652index 067e3d3..634a850 100644
52653--- a/fs/aio.c
52654+++ b/fs/aio.c
52655@@ -280,7 +280,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52656 size += sizeof(struct io_event) * nr_events;
52657
52658 nr_pages = PFN_UP(size);
52659- if (nr_pages < 0)
52660+ if (nr_pages <= 0)
52661 return -EINVAL;
52662
52663 file = anon_inode_getfile_private("[aio]", &aio_ring_fops, ctx, O_RDWR);
52664diff --git a/fs/attr.c b/fs/attr.c
52665index 1449adb..a2038c2 100644
52666--- a/fs/attr.c
52667+++ b/fs/attr.c
52668@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52669 unsigned long limit;
52670
52671 limit = rlimit(RLIMIT_FSIZE);
52672+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52673 if (limit != RLIM_INFINITY && offset > limit)
52674 goto out_sig;
52675 if (offset > inode->i_sb->s_maxbytes)
52676diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52677index 689e40d..515cac5 100644
52678--- a/fs/autofs4/waitq.c
52679+++ b/fs/autofs4/waitq.c
52680@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52681 {
52682 unsigned long sigpipe, flags;
52683 mm_segment_t fs;
52684- const char *data = (const char *)addr;
52685+ const char __user *data = (const char __force_user *)addr;
52686 ssize_t wr = 0;
52687
52688 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52689@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52690 return 1;
52691 }
52692
52693+#ifdef CONFIG_GRKERNSEC_HIDESYM
52694+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52695+#endif
52696+
52697 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52698 enum autofs_notify notify)
52699 {
52700@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52701
52702 /* If this is a direct mount request create a dummy name */
52703 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52704+#ifdef CONFIG_GRKERNSEC_HIDESYM
52705+ /* this name does get written to userland via autofs4_write() */
52706+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52707+#else
52708 qstr.len = sprintf(name, "%p", dentry);
52709+#endif
52710 else {
52711 qstr.len = autofs4_getpath(sbi, dentry, &name);
52712 if (!qstr.len) {
52713diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52714index 2722387..56059b5 100644
52715--- a/fs/befs/endian.h
52716+++ b/fs/befs/endian.h
52717@@ -11,7 +11,7 @@
52718
52719 #include <asm/byteorder.h>
52720
52721-static inline u64
52722+static inline u64 __intentional_overflow(-1)
52723 fs64_to_cpu(const struct super_block *sb, fs64 n)
52724 {
52725 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52726@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52727 return (__force fs64)cpu_to_be64(n);
52728 }
52729
52730-static inline u32
52731+static inline u32 __intentional_overflow(-1)
52732 fs32_to_cpu(const struct super_block *sb, fs32 n)
52733 {
52734 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52735@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
52736 return (__force fs32)cpu_to_be32(n);
52737 }
52738
52739-static inline u16
52740+static inline u16 __intentional_overflow(-1)
52741 fs16_to_cpu(const struct super_block *sb, fs16 n)
52742 {
52743 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52744diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52745index e9c75e2..1baece1 100644
52746--- a/fs/befs/linuxvfs.c
52747+++ b/fs/befs/linuxvfs.c
52748@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52749 {
52750 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52751 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52752- char *link = nd_get_link(nd);
52753+ const char *link = nd_get_link(nd);
52754 if (!IS_ERR(link))
52755 kfree(link);
52756 }
52757diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52758index 89dec7f..361b0d75 100644
52759--- a/fs/binfmt_aout.c
52760+++ b/fs/binfmt_aout.c
52761@@ -16,6 +16,7 @@
52762 #include <linux/string.h>
52763 #include <linux/fs.h>
52764 #include <linux/file.h>
52765+#include <linux/security.h>
52766 #include <linux/stat.h>
52767 #include <linux/fcntl.h>
52768 #include <linux/ptrace.h>
52769@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52770 #endif
52771 # define START_STACK(u) ((void __user *)u.start_stack)
52772
52773+ memset(&dump, 0, sizeof(dump));
52774+
52775 fs = get_fs();
52776 set_fs(KERNEL_DS);
52777 has_dumped = 1;
52778@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52779
52780 /* If the size of the dump file exceeds the rlimit, then see what would happen
52781 if we wrote the stack, but not the data area. */
52782+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52783 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52784 dump.u_dsize = 0;
52785
52786 /* Make sure we have enough room to write the stack and data areas. */
52787+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52788 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52789 dump.u_ssize = 0;
52790
52791@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52792 rlim = rlimit(RLIMIT_DATA);
52793 if (rlim >= RLIM_INFINITY)
52794 rlim = ~0;
52795+
52796+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52797 if (ex.a_data + ex.a_bss > rlim)
52798 return -ENOMEM;
52799
52800@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52801
52802 install_exec_creds(bprm);
52803
52804+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52805+ current->mm->pax_flags = 0UL;
52806+#endif
52807+
52808+#ifdef CONFIG_PAX_PAGEEXEC
52809+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52810+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52811+
52812+#ifdef CONFIG_PAX_EMUTRAMP
52813+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52814+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52815+#endif
52816+
52817+#ifdef CONFIG_PAX_MPROTECT
52818+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52819+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52820+#endif
52821+
52822+ }
52823+#endif
52824+
52825 if (N_MAGIC(ex) == OMAGIC) {
52826 unsigned long text_addr, map_size;
52827 loff_t pos;
52828@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52829 }
52830
52831 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52832- PROT_READ | PROT_WRITE | PROT_EXEC,
52833+ PROT_READ | PROT_WRITE,
52834 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52835 fd_offset + ex.a_text);
52836 if (error != N_DATADDR(ex)) {
52837diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52838index 4c94a79..f428019 100644
52839--- a/fs/binfmt_elf.c
52840+++ b/fs/binfmt_elf.c
52841@@ -34,6 +34,7 @@
52842 #include <linux/utsname.h>
52843 #include <linux/coredump.h>
52844 #include <linux/sched.h>
52845+#include <linux/xattr.h>
52846 #include <asm/uaccess.h>
52847 #include <asm/param.h>
52848 #include <asm/page.h>
52849@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52850 #define elf_core_dump NULL
52851 #endif
52852
52853+#ifdef CONFIG_PAX_MPROTECT
52854+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52855+#endif
52856+
52857+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52858+static void elf_handle_mmap(struct file *file);
52859+#endif
52860+
52861 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52862 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52863 #else
52864@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52865 .load_binary = load_elf_binary,
52866 .load_shlib = load_elf_library,
52867 .core_dump = elf_core_dump,
52868+
52869+#ifdef CONFIG_PAX_MPROTECT
52870+ .handle_mprotect= elf_handle_mprotect,
52871+#endif
52872+
52873+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52874+ .handle_mmap = elf_handle_mmap,
52875+#endif
52876+
52877 .min_coredump = ELF_EXEC_PAGESIZE,
52878 };
52879
52880@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52881
52882 static int set_brk(unsigned long start, unsigned long end)
52883 {
52884+ unsigned long e = end;
52885+
52886 start = ELF_PAGEALIGN(start);
52887 end = ELF_PAGEALIGN(end);
52888 if (end > start) {
52889@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52890 if (BAD_ADDR(addr))
52891 return addr;
52892 }
52893- current->mm->start_brk = current->mm->brk = end;
52894+ current->mm->start_brk = current->mm->brk = e;
52895 return 0;
52896 }
52897
52898@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52899 elf_addr_t __user *u_rand_bytes;
52900 const char *k_platform = ELF_PLATFORM;
52901 const char *k_base_platform = ELF_BASE_PLATFORM;
52902- unsigned char k_rand_bytes[16];
52903+ u32 k_rand_bytes[4];
52904 int items;
52905 elf_addr_t *elf_info;
52906 int ei_index = 0;
52907 const struct cred *cred = current_cred();
52908 struct vm_area_struct *vma;
52909+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52910
52911 /*
52912 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52913@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52914 * Generate 16 random bytes for userspace PRNG seeding.
52915 */
52916 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52917- u_rand_bytes = (elf_addr_t __user *)
52918- STACK_ALLOC(p, sizeof(k_rand_bytes));
52919+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52920+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52921+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52922+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52923+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52924+ u_rand_bytes = (elf_addr_t __user *) p;
52925 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52926 return -EFAULT;
52927
52928@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52929 return -EFAULT;
52930 current->mm->env_end = p;
52931
52932+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52933+
52934 /* Put the elf_info on the stack in the right place. */
52935 sp = (elf_addr_t __user *)envp + 1;
52936- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52937+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52938 return -EFAULT;
52939 return 0;
52940 }
52941@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52942 an ELF header */
52943
52944 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52945- struct file *interpreter, unsigned long *interp_map_addr,
52946- unsigned long no_base)
52947+ struct file *interpreter, unsigned long no_base)
52948 {
52949 struct elf_phdr *elf_phdata;
52950 struct elf_phdr *eppnt;
52951- unsigned long load_addr = 0;
52952+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52953 int load_addr_set = 0;
52954 unsigned long last_bss = 0, elf_bss = 0;
52955- unsigned long error = ~0UL;
52956+ unsigned long error = -EINVAL;
52957 unsigned long total_size;
52958 int retval, i, size;
52959
52960@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52961 goto out_close;
52962 }
52963
52964+#ifdef CONFIG_PAX_SEGMEXEC
52965+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52966+ pax_task_size = SEGMEXEC_TASK_SIZE;
52967+#endif
52968+
52969 eppnt = elf_phdata;
52970 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52971 if (eppnt->p_type == PT_LOAD) {
52972@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52973 map_addr = elf_map(interpreter, load_addr + vaddr,
52974 eppnt, elf_prot, elf_type, total_size);
52975 total_size = 0;
52976- if (!*interp_map_addr)
52977- *interp_map_addr = map_addr;
52978 error = map_addr;
52979 if (BAD_ADDR(map_addr))
52980 goto out_close;
52981@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52982 k = load_addr + eppnt->p_vaddr;
52983 if (BAD_ADDR(k) ||
52984 eppnt->p_filesz > eppnt->p_memsz ||
52985- eppnt->p_memsz > TASK_SIZE ||
52986- TASK_SIZE - eppnt->p_memsz < k) {
52987+ eppnt->p_memsz > pax_task_size ||
52988+ pax_task_size - eppnt->p_memsz < k) {
52989 error = -ENOMEM;
52990 goto out_close;
52991 }
52992@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52993 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52994
52995 /* Map the last of the bss segment */
52996- error = vm_brk(elf_bss, last_bss - elf_bss);
52997- if (BAD_ADDR(error))
52998- goto out_close;
52999+ if (last_bss > elf_bss) {
53000+ error = vm_brk(elf_bss, last_bss - elf_bss);
53001+ if (BAD_ADDR(error))
53002+ goto out_close;
53003+ }
53004 }
53005
53006 error = load_addr;
53007@@ -538,6 +569,315 @@ out:
53008 return error;
53009 }
53010
53011+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53012+#ifdef CONFIG_PAX_SOFTMODE
53013+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
53014+{
53015+ unsigned long pax_flags = 0UL;
53016+
53017+#ifdef CONFIG_PAX_PAGEEXEC
53018+ if (elf_phdata->p_flags & PF_PAGEEXEC)
53019+ pax_flags |= MF_PAX_PAGEEXEC;
53020+#endif
53021+
53022+#ifdef CONFIG_PAX_SEGMEXEC
53023+ if (elf_phdata->p_flags & PF_SEGMEXEC)
53024+ pax_flags |= MF_PAX_SEGMEXEC;
53025+#endif
53026+
53027+#ifdef CONFIG_PAX_EMUTRAMP
53028+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53029+ pax_flags |= MF_PAX_EMUTRAMP;
53030+#endif
53031+
53032+#ifdef CONFIG_PAX_MPROTECT
53033+ if (elf_phdata->p_flags & PF_MPROTECT)
53034+ pax_flags |= MF_PAX_MPROTECT;
53035+#endif
53036+
53037+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53038+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
53039+ pax_flags |= MF_PAX_RANDMMAP;
53040+#endif
53041+
53042+ return pax_flags;
53043+}
53044+#endif
53045+
53046+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
53047+{
53048+ unsigned long pax_flags = 0UL;
53049+
53050+#ifdef CONFIG_PAX_PAGEEXEC
53051+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
53052+ pax_flags |= MF_PAX_PAGEEXEC;
53053+#endif
53054+
53055+#ifdef CONFIG_PAX_SEGMEXEC
53056+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
53057+ pax_flags |= MF_PAX_SEGMEXEC;
53058+#endif
53059+
53060+#ifdef CONFIG_PAX_EMUTRAMP
53061+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
53062+ pax_flags |= MF_PAX_EMUTRAMP;
53063+#endif
53064+
53065+#ifdef CONFIG_PAX_MPROTECT
53066+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
53067+ pax_flags |= MF_PAX_MPROTECT;
53068+#endif
53069+
53070+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53071+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
53072+ pax_flags |= MF_PAX_RANDMMAP;
53073+#endif
53074+
53075+ return pax_flags;
53076+}
53077+#endif
53078+
53079+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53080+#ifdef CONFIG_PAX_SOFTMODE
53081+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
53082+{
53083+ unsigned long pax_flags = 0UL;
53084+
53085+#ifdef CONFIG_PAX_PAGEEXEC
53086+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
53087+ pax_flags |= MF_PAX_PAGEEXEC;
53088+#endif
53089+
53090+#ifdef CONFIG_PAX_SEGMEXEC
53091+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
53092+ pax_flags |= MF_PAX_SEGMEXEC;
53093+#endif
53094+
53095+#ifdef CONFIG_PAX_EMUTRAMP
53096+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53097+ pax_flags |= MF_PAX_EMUTRAMP;
53098+#endif
53099+
53100+#ifdef CONFIG_PAX_MPROTECT
53101+ if (pax_flags_softmode & MF_PAX_MPROTECT)
53102+ pax_flags |= MF_PAX_MPROTECT;
53103+#endif
53104+
53105+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53106+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
53107+ pax_flags |= MF_PAX_RANDMMAP;
53108+#endif
53109+
53110+ return pax_flags;
53111+}
53112+#endif
53113+
53114+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
53115+{
53116+ unsigned long pax_flags = 0UL;
53117+
53118+#ifdef CONFIG_PAX_PAGEEXEC
53119+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
53120+ pax_flags |= MF_PAX_PAGEEXEC;
53121+#endif
53122+
53123+#ifdef CONFIG_PAX_SEGMEXEC
53124+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
53125+ pax_flags |= MF_PAX_SEGMEXEC;
53126+#endif
53127+
53128+#ifdef CONFIG_PAX_EMUTRAMP
53129+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
53130+ pax_flags |= MF_PAX_EMUTRAMP;
53131+#endif
53132+
53133+#ifdef CONFIG_PAX_MPROTECT
53134+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
53135+ pax_flags |= MF_PAX_MPROTECT;
53136+#endif
53137+
53138+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53139+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
53140+ pax_flags |= MF_PAX_RANDMMAP;
53141+#endif
53142+
53143+ return pax_flags;
53144+}
53145+#endif
53146+
53147+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53148+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
53149+{
53150+ unsigned long pax_flags = 0UL;
53151+
53152+#ifdef CONFIG_PAX_EI_PAX
53153+
53154+#ifdef CONFIG_PAX_PAGEEXEC
53155+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
53156+ pax_flags |= MF_PAX_PAGEEXEC;
53157+#endif
53158+
53159+#ifdef CONFIG_PAX_SEGMEXEC
53160+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
53161+ pax_flags |= MF_PAX_SEGMEXEC;
53162+#endif
53163+
53164+#ifdef CONFIG_PAX_EMUTRAMP
53165+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
53166+ pax_flags |= MF_PAX_EMUTRAMP;
53167+#endif
53168+
53169+#ifdef CONFIG_PAX_MPROTECT
53170+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
53171+ pax_flags |= MF_PAX_MPROTECT;
53172+#endif
53173+
53174+#ifdef CONFIG_PAX_ASLR
53175+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
53176+ pax_flags |= MF_PAX_RANDMMAP;
53177+#endif
53178+
53179+#else
53180+
53181+#ifdef CONFIG_PAX_PAGEEXEC
53182+ pax_flags |= MF_PAX_PAGEEXEC;
53183+#endif
53184+
53185+#ifdef CONFIG_PAX_SEGMEXEC
53186+ pax_flags |= MF_PAX_SEGMEXEC;
53187+#endif
53188+
53189+#ifdef CONFIG_PAX_MPROTECT
53190+ pax_flags |= MF_PAX_MPROTECT;
53191+#endif
53192+
53193+#ifdef CONFIG_PAX_RANDMMAP
53194+ if (randomize_va_space)
53195+ pax_flags |= MF_PAX_RANDMMAP;
53196+#endif
53197+
53198+#endif
53199+
53200+ return pax_flags;
53201+}
53202+
53203+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
53204+{
53205+
53206+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53207+ unsigned long i;
53208+
53209+ for (i = 0UL; i < elf_ex->e_phnum; i++)
53210+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
53211+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
53212+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
53213+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
53214+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
53215+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
53216+ return ~0UL;
53217+
53218+#ifdef CONFIG_PAX_SOFTMODE
53219+ if (pax_softmode)
53220+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
53221+ else
53222+#endif
53223+
53224+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
53225+ break;
53226+ }
53227+#endif
53228+
53229+ return ~0UL;
53230+}
53231+
53232+static unsigned long pax_parse_xattr_pax(struct file * const file)
53233+{
53234+
53235+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53236+ ssize_t xattr_size, i;
53237+ unsigned char xattr_value[sizeof("pemrs") - 1];
53238+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
53239+
53240+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
53241+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
53242+ return ~0UL;
53243+
53244+ for (i = 0; i < xattr_size; i++)
53245+ switch (xattr_value[i]) {
53246+ default:
53247+ return ~0UL;
53248+
53249+#define parse_flag(option1, option2, flag) \
53250+ case option1: \
53251+ if (pax_flags_hardmode & MF_PAX_##flag) \
53252+ return ~0UL; \
53253+ pax_flags_hardmode |= MF_PAX_##flag; \
53254+ break; \
53255+ case option2: \
53256+ if (pax_flags_softmode & MF_PAX_##flag) \
53257+ return ~0UL; \
53258+ pax_flags_softmode |= MF_PAX_##flag; \
53259+ break;
53260+
53261+ parse_flag('p', 'P', PAGEEXEC);
53262+ parse_flag('e', 'E', EMUTRAMP);
53263+ parse_flag('m', 'M', MPROTECT);
53264+ parse_flag('r', 'R', RANDMMAP);
53265+ parse_flag('s', 'S', SEGMEXEC);
53266+
53267+#undef parse_flag
53268+ }
53269+
53270+ if (pax_flags_hardmode & pax_flags_softmode)
53271+ return ~0UL;
53272+
53273+#ifdef CONFIG_PAX_SOFTMODE
53274+ if (pax_softmode)
53275+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
53276+ else
53277+#endif
53278+
53279+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
53280+#else
53281+ return ~0UL;
53282+#endif
53283+
53284+}
53285+
53286+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
53287+{
53288+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
53289+
53290+ pax_flags = pax_parse_ei_pax(elf_ex);
53291+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
53292+ xattr_pax_flags = pax_parse_xattr_pax(file);
53293+
53294+ if (pt_pax_flags == ~0UL)
53295+ pt_pax_flags = xattr_pax_flags;
53296+ else if (xattr_pax_flags == ~0UL)
53297+ xattr_pax_flags = pt_pax_flags;
53298+ if (pt_pax_flags != xattr_pax_flags)
53299+ return -EINVAL;
53300+ if (pt_pax_flags != ~0UL)
53301+ pax_flags = pt_pax_flags;
53302+
53303+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
53304+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53305+ if ((__supported_pte_mask & _PAGE_NX))
53306+ pax_flags &= ~MF_PAX_SEGMEXEC;
53307+ else
53308+ pax_flags &= ~MF_PAX_PAGEEXEC;
53309+ }
53310+#endif
53311+
53312+ if (0 > pax_check_flags(&pax_flags))
53313+ return -EINVAL;
53314+
53315+ current->mm->pax_flags = pax_flags;
53316+ return 0;
53317+}
53318+#endif
53319+
53320 /*
53321 * These are the functions used to load ELF style executables and shared
53322 * libraries. There is no binary dependent code anywhere else.
53323@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
53324 {
53325 unsigned int random_variable = 0;
53326
53327+#ifdef CONFIG_PAX_RANDUSTACK
53328+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
53329+ return stack_top - current->mm->delta_stack;
53330+#endif
53331+
53332 if ((current->flags & PF_RANDOMIZE) &&
53333 !(current->personality & ADDR_NO_RANDOMIZE)) {
53334 random_variable = get_random_int() & STACK_RND_MASK;
53335@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
53336 unsigned long load_addr = 0, load_bias = 0;
53337 int load_addr_set = 0;
53338 char * elf_interpreter = NULL;
53339- unsigned long error;
53340+ unsigned long error = 0;
53341 struct elf_phdr *elf_ppnt, *elf_phdata;
53342 unsigned long elf_bss, elf_brk;
53343 int retval, i;
53344@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
53345 unsigned long start_code, end_code, start_data, end_data;
53346 unsigned long reloc_func_desc __maybe_unused = 0;
53347 int executable_stack = EXSTACK_DEFAULT;
53348- unsigned long def_flags = 0;
53349 struct pt_regs *regs = current_pt_regs();
53350 struct {
53351 struct elfhdr elf_ex;
53352 struct elfhdr interp_elf_ex;
53353 } *loc;
53354+ unsigned long pax_task_size = TASK_SIZE;
53355
53356 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
53357 if (!loc) {
53358@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
53359 goto out_free_dentry;
53360
53361 /* OK, This is the point of no return */
53362- current->mm->def_flags = def_flags;
53363+
53364+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53365+ current->mm->pax_flags = 0UL;
53366+#endif
53367+
53368+#ifdef CONFIG_PAX_DLRESOLVE
53369+ current->mm->call_dl_resolve = 0UL;
53370+#endif
53371+
53372+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
53373+ current->mm->call_syscall = 0UL;
53374+#endif
53375+
53376+#ifdef CONFIG_PAX_ASLR
53377+ current->mm->delta_mmap = 0UL;
53378+ current->mm->delta_stack = 0UL;
53379+#endif
53380+
53381+ current->mm->def_flags = 0;
53382+
53383+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53384+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
53385+ send_sig(SIGKILL, current, 0);
53386+ goto out_free_dentry;
53387+ }
53388+#endif
53389+
53390+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53391+ pax_set_initial_flags(bprm);
53392+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
53393+ if (pax_set_initial_flags_func)
53394+ (pax_set_initial_flags_func)(bprm);
53395+#endif
53396+
53397+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53398+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
53399+ current->mm->context.user_cs_limit = PAGE_SIZE;
53400+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53401+ }
53402+#endif
53403+
53404+#ifdef CONFIG_PAX_SEGMEXEC
53405+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53406+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53407+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53408+ pax_task_size = SEGMEXEC_TASK_SIZE;
53409+ current->mm->def_flags |= VM_NOHUGEPAGE;
53410+ }
53411+#endif
53412+
53413+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53414+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53415+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53416+ put_cpu();
53417+ }
53418+#endif
53419
53420 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53421 may depend on the personality. */
53422 SET_PERSONALITY(loc->elf_ex);
53423+
53424+#ifdef CONFIG_PAX_ASLR
53425+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53426+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53427+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53428+ }
53429+#endif
53430+
53431+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53432+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53433+ executable_stack = EXSTACK_DISABLE_X;
53434+ current->personality &= ~READ_IMPLIES_EXEC;
53435+ } else
53436+#endif
53437+
53438 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53439 current->personality |= READ_IMPLIES_EXEC;
53440
53441@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53442 #else
53443 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53444 #endif
53445+
53446+#ifdef CONFIG_PAX_RANDMMAP
53447+ /* PaX: randomize base address at the default exe base if requested */
53448+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53449+#ifdef CONFIG_SPARC64
53450+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53451+#else
53452+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53453+#endif
53454+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53455+ elf_flags |= MAP_FIXED;
53456+ }
53457+#endif
53458+
53459 }
53460
53461 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53462@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53463 * allowed task size. Note that p_filesz must always be
53464 * <= p_memsz so it is only necessary to check p_memsz.
53465 */
53466- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53467- elf_ppnt->p_memsz > TASK_SIZE ||
53468- TASK_SIZE - elf_ppnt->p_memsz < k) {
53469+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53470+ elf_ppnt->p_memsz > pax_task_size ||
53471+ pax_task_size - elf_ppnt->p_memsz < k) {
53472 /* set_brk can never work. Avoid overflows. */
53473 send_sig(SIGKILL, current, 0);
53474 retval = -EINVAL;
53475@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53476 goto out_free_dentry;
53477 }
53478 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53479- send_sig(SIGSEGV, current, 0);
53480- retval = -EFAULT; /* Nobody gets to see this, but.. */
53481- goto out_free_dentry;
53482+ /*
53483+ * This bss-zeroing can fail if the ELF
53484+ * file specifies odd protections. So
53485+ * we don't check the return value
53486+ */
53487 }
53488
53489+#ifdef CONFIG_PAX_RANDMMAP
53490+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53491+ unsigned long start, size, flags;
53492+ vm_flags_t vm_flags;
53493+
53494+ start = ELF_PAGEALIGN(elf_brk);
53495+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53496+ flags = MAP_FIXED | MAP_PRIVATE;
53497+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53498+
53499+ down_write(&current->mm->mmap_sem);
53500+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53501+ retval = -ENOMEM;
53502+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53503+// if (current->personality & ADDR_NO_RANDOMIZE)
53504+// vm_flags |= VM_READ | VM_MAYREAD;
53505+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53506+ retval = IS_ERR_VALUE(start) ? start : 0;
53507+ }
53508+ up_write(&current->mm->mmap_sem);
53509+ if (retval == 0)
53510+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53511+ if (retval < 0) {
53512+ send_sig(SIGKILL, current, 0);
53513+ goto out_free_dentry;
53514+ }
53515+ }
53516+#endif
53517+
53518 if (elf_interpreter) {
53519- unsigned long interp_map_addr = 0;
53520-
53521 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53522 interpreter,
53523- &interp_map_addr,
53524 load_bias);
53525 if (!IS_ERR((void *)elf_entry)) {
53526 /*
53527@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53528 * Decide what to dump of a segment, part, all or none.
53529 */
53530 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53531- unsigned long mm_flags)
53532+ unsigned long mm_flags, long signr)
53533 {
53534 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53535
53536@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53537 if (vma->vm_file == NULL)
53538 return 0;
53539
53540- if (FILTER(MAPPED_PRIVATE))
53541+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53542 goto whole;
53543
53544 /*
53545@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53546 {
53547 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53548 int i = 0;
53549- do
53550+ do {
53551 i += 2;
53552- while (auxv[i - 2] != AT_NULL);
53553+ } while (auxv[i - 2] != AT_NULL);
53554 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53555 }
53556
53557@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53558 {
53559 mm_segment_t old_fs = get_fs();
53560 set_fs(KERNEL_DS);
53561- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53562+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53563 set_fs(old_fs);
53564 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53565 }
53566@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53567 }
53568
53569 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53570- unsigned long mm_flags)
53571+ struct coredump_params *cprm)
53572 {
53573 struct vm_area_struct *vma;
53574 size_t size = 0;
53575
53576 for (vma = first_vma(current, gate_vma); vma != NULL;
53577 vma = next_vma(vma, gate_vma))
53578- size += vma_dump_size(vma, mm_flags);
53579+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53580 return size;
53581 }
53582
53583@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53584
53585 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53586
53587- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53588+ offset += elf_core_vma_data_size(gate_vma, cprm);
53589 offset += elf_core_extra_data_size();
53590 e_shoff = offset;
53591
53592@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53593 offset = dataoff;
53594
53595 size += sizeof(*elf);
53596+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53597 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53598 goto end_coredump;
53599
53600 size += sizeof(*phdr4note);
53601+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53602 if (size > cprm->limit
53603 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53604 goto end_coredump;
53605@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53606 phdr.p_offset = offset;
53607 phdr.p_vaddr = vma->vm_start;
53608 phdr.p_paddr = 0;
53609- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53610+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53611 phdr.p_memsz = vma->vm_end - vma->vm_start;
53612 offset += phdr.p_filesz;
53613 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53614@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53615 phdr.p_align = ELF_EXEC_PAGESIZE;
53616
53617 size += sizeof(phdr);
53618+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53619 if (size > cprm->limit
53620 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53621 goto end_coredump;
53622@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53623 unsigned long addr;
53624 unsigned long end;
53625
53626- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53627+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53628
53629 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53630 struct page *page;
53631@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53632 page = get_dump_page(addr);
53633 if (page) {
53634 void *kaddr = kmap(page);
53635+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53636 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53637 !dump_write(cprm->file, kaddr,
53638 PAGE_SIZE);
53639@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53640
53641 if (e_phnum == PN_XNUM) {
53642 size += sizeof(*shdr4extnum);
53643+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53644 if (size > cprm->limit
53645 || !dump_write(cprm->file, shdr4extnum,
53646 sizeof(*shdr4extnum)))
53647@@ -2235,6 +2697,167 @@ out:
53648
53649 #endif /* CONFIG_ELF_CORE */
53650
53651+#ifdef CONFIG_PAX_MPROTECT
53652+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53653+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53654+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53655+ *
53656+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53657+ * basis because we want to allow the common case and not the special ones.
53658+ */
53659+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53660+{
53661+ struct elfhdr elf_h;
53662+ struct elf_phdr elf_p;
53663+ unsigned long i;
53664+ unsigned long oldflags;
53665+ bool is_textrel_rw, is_textrel_rx, is_relro;
53666+
53667+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53668+ return;
53669+
53670+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53671+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53672+
53673+#ifdef CONFIG_PAX_ELFRELOCS
53674+ /* possible TEXTREL */
53675+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53676+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53677+#else
53678+ is_textrel_rw = false;
53679+ is_textrel_rx = false;
53680+#endif
53681+
53682+ /* possible RELRO */
53683+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53684+
53685+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53686+ return;
53687+
53688+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53689+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53690+
53691+#ifdef CONFIG_PAX_ETEXECRELOCS
53692+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53693+#else
53694+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53695+#endif
53696+
53697+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53698+ !elf_check_arch(&elf_h) ||
53699+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53700+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53701+ return;
53702+
53703+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53704+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53705+ return;
53706+ switch (elf_p.p_type) {
53707+ case PT_DYNAMIC:
53708+ if (!is_textrel_rw && !is_textrel_rx)
53709+ continue;
53710+ i = 0UL;
53711+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53712+ elf_dyn dyn;
53713+
53714+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53715+ break;
53716+ if (dyn.d_tag == DT_NULL)
53717+ break;
53718+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53719+ gr_log_textrel(vma);
53720+ if (is_textrel_rw)
53721+ vma->vm_flags |= VM_MAYWRITE;
53722+ else
53723+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53724+ vma->vm_flags &= ~VM_MAYWRITE;
53725+ break;
53726+ }
53727+ i++;
53728+ }
53729+ is_textrel_rw = false;
53730+ is_textrel_rx = false;
53731+ continue;
53732+
53733+ case PT_GNU_RELRO:
53734+ if (!is_relro)
53735+ continue;
53736+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53737+ vma->vm_flags &= ~VM_MAYWRITE;
53738+ is_relro = false;
53739+ continue;
53740+
53741+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53742+ case PT_PAX_FLAGS: {
53743+ const char *msg_mprotect = "", *msg_emutramp = "";
53744+ char *buffer_lib, *buffer_exe;
53745+
53746+ if (elf_p.p_flags & PF_NOMPROTECT)
53747+ msg_mprotect = "MPROTECT disabled";
53748+
53749+#ifdef CONFIG_PAX_EMUTRAMP
53750+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53751+ msg_emutramp = "EMUTRAMP enabled";
53752+#endif
53753+
53754+ if (!msg_mprotect[0] && !msg_emutramp[0])
53755+ continue;
53756+
53757+ if (!printk_ratelimit())
53758+ continue;
53759+
53760+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53761+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53762+ if (buffer_lib && buffer_exe) {
53763+ char *path_lib, *path_exe;
53764+
53765+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53766+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53767+
53768+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53769+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53770+
53771+ }
53772+ free_page((unsigned long)buffer_exe);
53773+ free_page((unsigned long)buffer_lib);
53774+ continue;
53775+ }
53776+#endif
53777+
53778+ }
53779+ }
53780+}
53781+#endif
53782+
53783+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53784+
53785+extern int grsec_enable_log_rwxmaps;
53786+
53787+static void elf_handle_mmap(struct file *file)
53788+{
53789+ struct elfhdr elf_h;
53790+ struct elf_phdr elf_p;
53791+ unsigned long i;
53792+
53793+ if (!grsec_enable_log_rwxmaps)
53794+ return;
53795+
53796+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53797+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53798+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53799+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53800+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53801+ return;
53802+
53803+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53804+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53805+ return;
53806+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53807+ gr_log_ptgnustack(file);
53808+ }
53809+}
53810+#endif
53811+
53812 static int __init init_elf_binfmt(void)
53813 {
53814 register_binfmt(&elf_format);
53815diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53816index d50bbe5..af3b649 100644
53817--- a/fs/binfmt_flat.c
53818+++ b/fs/binfmt_flat.c
53819@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53820 realdatastart = (unsigned long) -ENOMEM;
53821 printk("Unable to allocate RAM for process data, errno %d\n",
53822 (int)-realdatastart);
53823+ down_write(&current->mm->mmap_sem);
53824 vm_munmap(textpos, text_len);
53825+ up_write(&current->mm->mmap_sem);
53826 ret = realdatastart;
53827 goto err;
53828 }
53829@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53830 }
53831 if (IS_ERR_VALUE(result)) {
53832 printk("Unable to read data+bss, errno %d\n", (int)-result);
53833+ down_write(&current->mm->mmap_sem);
53834 vm_munmap(textpos, text_len);
53835 vm_munmap(realdatastart, len);
53836+ up_write(&current->mm->mmap_sem);
53837 ret = result;
53838 goto err;
53839 }
53840@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53841 }
53842 if (IS_ERR_VALUE(result)) {
53843 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53844+ down_write(&current->mm->mmap_sem);
53845 vm_munmap(textpos, text_len + data_len + extra +
53846 MAX_SHARED_LIBS * sizeof(unsigned long));
53847+ up_write(&current->mm->mmap_sem);
53848 ret = result;
53849 goto err;
53850 }
53851diff --git a/fs/bio.c b/fs/bio.c
53852index ea5035d..a2932eb 100644
53853--- a/fs/bio.c
53854+++ b/fs/bio.c
53855@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53856 /*
53857 * Overflow, abort
53858 */
53859- if (end < start)
53860+ if (end < start || end - start > INT_MAX - nr_pages)
53861 return ERR_PTR(-EINVAL);
53862
53863 nr_pages += end - start;
53864@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53865 /*
53866 * Overflow, abort
53867 */
53868- if (end < start)
53869+ if (end < start || end - start > INT_MAX - nr_pages)
53870 return ERR_PTR(-EINVAL);
53871
53872 nr_pages += end - start;
53873@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53874 const int read = bio_data_dir(bio) == READ;
53875 struct bio_map_data *bmd = bio->bi_private;
53876 int i;
53877- char *p = bmd->sgvecs[0].iov_base;
53878+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53879
53880 bio_for_each_segment_all(bvec, bio, i) {
53881 char *addr = page_address(bvec->bv_page);
53882diff --git a/fs/block_dev.c b/fs/block_dev.c
53883index 1e86823..8e34695 100644
53884--- a/fs/block_dev.c
53885+++ b/fs/block_dev.c
53886@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53887 else if (bdev->bd_contains == bdev)
53888 return true; /* is a whole device which isn't held */
53889
53890- else if (whole->bd_holder == bd_may_claim)
53891+ else if (whole->bd_holder == (void *)bd_may_claim)
53892 return true; /* is a partition of a device that is being partitioned */
53893 else if (whole->bd_holder != NULL)
53894 return false; /* is a partition of a held device */
53895diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53896index 61b5bcd..7eeede8 100644
53897--- a/fs/btrfs/ctree.c
53898+++ b/fs/btrfs/ctree.c
53899@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53900 free_extent_buffer(buf);
53901 add_root_to_dirty_list(root);
53902 } else {
53903- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53904- parent_start = parent->start;
53905- else
53906+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53907+ if (parent)
53908+ parent_start = parent->start;
53909+ else
53910+ parent_start = 0;
53911+ } else
53912 parent_start = 0;
53913
53914 WARN_ON(trans->transid != btrfs_header_generation(parent));
53915diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53916index cbd9523..5cca781 100644
53917--- a/fs/btrfs/delayed-inode.c
53918+++ b/fs/btrfs/delayed-inode.c
53919@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53920
53921 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53922 {
53923- int seq = atomic_inc_return(&delayed_root->items_seq);
53924+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53925 if ((atomic_dec_return(&delayed_root->items) <
53926 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53927 waitqueue_active(&delayed_root->wait))
53928@@ -1378,7 +1378,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53929 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53930 int seq, int count)
53931 {
53932- int val = atomic_read(&delayed_root->items_seq);
53933+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53934
53935 if (val < seq || val >= seq + count)
53936 return 1;
53937@@ -1395,7 +1395,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53938 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53939 return;
53940
53941- seq = atomic_read(&delayed_root->items_seq);
53942+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53943
53944 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53945 int ret;
53946diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53947index a4b38f9..f86a509 100644
53948--- a/fs/btrfs/delayed-inode.h
53949+++ b/fs/btrfs/delayed-inode.h
53950@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53951 */
53952 struct list_head prepare_list;
53953 atomic_t items; /* for delayed items */
53954- atomic_t items_seq; /* for delayed items */
53955+ atomic_unchecked_t items_seq; /* for delayed items */
53956 int nodes; /* for delayed nodes */
53957 wait_queue_head_t wait;
53958 };
53959@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53960 struct btrfs_delayed_root *delayed_root)
53961 {
53962 atomic_set(&delayed_root->items, 0);
53963- atomic_set(&delayed_root->items_seq, 0);
53964+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53965 delayed_root->nodes = 0;
53966 spin_lock_init(&delayed_root->lock);
53967 init_waitqueue_head(&delayed_root->wait);
53968diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53969index 9d46f60..a8f09eb 100644
53970--- a/fs/btrfs/ioctl.c
53971+++ b/fs/btrfs/ioctl.c
53972@@ -3464,9 +3464,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53973 for (i = 0; i < num_types; i++) {
53974 struct btrfs_space_info *tmp;
53975
53976+ /* Don't copy in more than we allocated */
53977 if (!slot_count)
53978 break;
53979
53980+ slot_count--;
53981+
53982 info = NULL;
53983 rcu_read_lock();
53984 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53985@@ -3488,10 +3491,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53986 memcpy(dest, &space, sizeof(space));
53987 dest++;
53988 space_args.total_spaces++;
53989- slot_count--;
53990 }
53991- if (!slot_count)
53992- break;
53993 }
53994 up_read(&info->groups_sem);
53995 }
53996diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53997index e913328..a34fb36 100644
53998--- a/fs/btrfs/super.c
53999+++ b/fs/btrfs/super.c
54000@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
54001 function, line, errstr);
54002 return;
54003 }
54004- ACCESS_ONCE(trans->transaction->aborted) = errno;
54005+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
54006 /* Wake up anybody who may be waiting on this transaction */
54007 wake_up(&root->fs_info->transaction_wait);
54008 wake_up(&root->fs_info->transaction_blocked_wait);
54009diff --git a/fs/buffer.c b/fs/buffer.c
54010index 6024877..7bd000a 100644
54011--- a/fs/buffer.c
54012+++ b/fs/buffer.c
54013@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
54014 bh_cachep = kmem_cache_create("buffer_head",
54015 sizeof(struct buffer_head), 0,
54016 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
54017- SLAB_MEM_SPREAD),
54018+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
54019 NULL);
54020
54021 /*
54022diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
54023index 622f469..e8d2d55 100644
54024--- a/fs/cachefiles/bind.c
54025+++ b/fs/cachefiles/bind.c
54026@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
54027 args);
54028
54029 /* start by checking things over */
54030- ASSERT(cache->fstop_percent >= 0 &&
54031- cache->fstop_percent < cache->fcull_percent &&
54032+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
54033 cache->fcull_percent < cache->frun_percent &&
54034 cache->frun_percent < 100);
54035
54036- ASSERT(cache->bstop_percent >= 0 &&
54037- cache->bstop_percent < cache->bcull_percent &&
54038+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
54039 cache->bcull_percent < cache->brun_percent &&
54040 cache->brun_percent < 100);
54041
54042diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
54043index 0a1467b..6a53245 100644
54044--- a/fs/cachefiles/daemon.c
54045+++ b/fs/cachefiles/daemon.c
54046@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
54047 if (n > buflen)
54048 return -EMSGSIZE;
54049
54050- if (copy_to_user(_buffer, buffer, n) != 0)
54051+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
54052 return -EFAULT;
54053
54054 return n;
54055@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
54056 if (test_bit(CACHEFILES_DEAD, &cache->flags))
54057 return -EIO;
54058
54059- if (datalen < 0 || datalen > PAGE_SIZE - 1)
54060+ if (datalen > PAGE_SIZE - 1)
54061 return -EOPNOTSUPP;
54062
54063 /* drag the command string into the kernel so we can parse it */
54064@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
54065 if (args[0] != '%' || args[1] != '\0')
54066 return -EINVAL;
54067
54068- if (fstop < 0 || fstop >= cache->fcull_percent)
54069+ if (fstop >= cache->fcull_percent)
54070 return cachefiles_daemon_range_error(cache, args);
54071
54072 cache->fstop_percent = fstop;
54073@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
54074 if (args[0] != '%' || args[1] != '\0')
54075 return -EINVAL;
54076
54077- if (bstop < 0 || bstop >= cache->bcull_percent)
54078+ if (bstop >= cache->bcull_percent)
54079 return cachefiles_daemon_range_error(cache, args);
54080
54081 cache->bstop_percent = bstop;
54082diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
54083index 5349473..d6c0b93 100644
54084--- a/fs/cachefiles/internal.h
54085+++ b/fs/cachefiles/internal.h
54086@@ -59,7 +59,7 @@ struct cachefiles_cache {
54087 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
54088 struct rb_root active_nodes; /* active nodes (can't be culled) */
54089 rwlock_t active_lock; /* lock for active_nodes */
54090- atomic_t gravecounter; /* graveyard uniquifier */
54091+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
54092 unsigned frun_percent; /* when to stop culling (% files) */
54093 unsigned fcull_percent; /* when to start culling (% files) */
54094 unsigned fstop_percent; /* when to stop allocating (% files) */
54095@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
54096 * proc.c
54097 */
54098 #ifdef CONFIG_CACHEFILES_HISTOGRAM
54099-extern atomic_t cachefiles_lookup_histogram[HZ];
54100-extern atomic_t cachefiles_mkdir_histogram[HZ];
54101-extern atomic_t cachefiles_create_histogram[HZ];
54102+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54103+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54104+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
54105
54106 extern int __init cachefiles_proc_init(void);
54107 extern void cachefiles_proc_cleanup(void);
54108 static inline
54109-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
54110+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
54111 {
54112 unsigned long jif = jiffies - start_jif;
54113 if (jif >= HZ)
54114 jif = HZ - 1;
54115- atomic_inc(&histogram[jif]);
54116+ atomic_inc_unchecked(&histogram[jif]);
54117 }
54118
54119 #else
54120diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
54121index f4a08d7..5aa4599 100644
54122--- a/fs/cachefiles/namei.c
54123+++ b/fs/cachefiles/namei.c
54124@@ -317,7 +317,7 @@ try_again:
54125 /* first step is to make up a grave dentry in the graveyard */
54126 sprintf(nbuffer, "%08x%08x",
54127 (uint32_t) get_seconds(),
54128- (uint32_t) atomic_inc_return(&cache->gravecounter));
54129+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
54130
54131 /* do the multiway lock magic */
54132 trap = lock_rename(cache->graveyard, dir);
54133diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
54134index eccd339..4c1d995 100644
54135--- a/fs/cachefiles/proc.c
54136+++ b/fs/cachefiles/proc.c
54137@@ -14,9 +14,9 @@
54138 #include <linux/seq_file.h>
54139 #include "internal.h"
54140
54141-atomic_t cachefiles_lookup_histogram[HZ];
54142-atomic_t cachefiles_mkdir_histogram[HZ];
54143-atomic_t cachefiles_create_histogram[HZ];
54144+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54145+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54146+atomic_unchecked_t cachefiles_create_histogram[HZ];
54147
54148 /*
54149 * display the latency histogram
54150@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
54151 return 0;
54152 default:
54153 index = (unsigned long) v - 3;
54154- x = atomic_read(&cachefiles_lookup_histogram[index]);
54155- y = atomic_read(&cachefiles_mkdir_histogram[index]);
54156- z = atomic_read(&cachefiles_create_histogram[index]);
54157+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
54158+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
54159+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
54160 if (x == 0 && y == 0 && z == 0)
54161 return 0;
54162
54163diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
54164index ebaff36..7e3ea26 100644
54165--- a/fs/cachefiles/rdwr.c
54166+++ b/fs/cachefiles/rdwr.c
54167@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
54168 old_fs = get_fs();
54169 set_fs(KERNEL_DS);
54170 ret = file->f_op->write(
54171- file, (const void __user *) data, len, &pos);
54172+ file, (const void __force_user *) data, len, &pos);
54173 set_fs(old_fs);
54174 kunmap(page);
54175 file_end_write(file);
54176diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
54177index 868b61d..58835a5 100644
54178--- a/fs/ceph/dir.c
54179+++ b/fs/ceph/dir.c
54180@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
54181 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
54182 struct ceph_mds_client *mdsc = fsc->mdsc;
54183 unsigned frag = fpos_frag(ctx->pos);
54184- int off = fpos_off(ctx->pos);
54185+ unsigned int off = fpos_off(ctx->pos);
54186 int err;
54187 u32 ftype;
54188 struct ceph_mds_reply_info_parsed *rinfo;
54189diff --git a/fs/ceph/super.c b/fs/ceph/super.c
54190index 6a0951e..03fac6d 100644
54191--- a/fs/ceph/super.c
54192+++ b/fs/ceph/super.c
54193@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
54194 /*
54195 * construct our own bdi so we can control readahead, etc.
54196 */
54197-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
54198+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
54199
54200 static int ceph_register_bdi(struct super_block *sb,
54201 struct ceph_fs_client *fsc)
54202@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
54203 default_backing_dev_info.ra_pages;
54204
54205 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
54206- atomic_long_inc_return(&bdi_seq));
54207+ atomic_long_inc_return_unchecked(&bdi_seq));
54208 if (!err)
54209 sb->s_bdi = &fsc->backing_dev_info;
54210 return err;
54211diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
54212index f3ac415..3d2420c 100644
54213--- a/fs/cifs/cifs_debug.c
54214+++ b/fs/cifs/cifs_debug.c
54215@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54216
54217 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
54218 #ifdef CONFIG_CIFS_STATS2
54219- atomic_set(&totBufAllocCount, 0);
54220- atomic_set(&totSmBufAllocCount, 0);
54221+ atomic_set_unchecked(&totBufAllocCount, 0);
54222+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54223 #endif /* CONFIG_CIFS_STATS2 */
54224 spin_lock(&cifs_tcp_ses_lock);
54225 list_for_each(tmp1, &cifs_tcp_ses_list) {
54226@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54227 tcon = list_entry(tmp3,
54228 struct cifs_tcon,
54229 tcon_list);
54230- atomic_set(&tcon->num_smbs_sent, 0);
54231+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
54232 if (server->ops->clear_stats)
54233 server->ops->clear_stats(tcon);
54234 }
54235@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54236 smBufAllocCount.counter, cifs_min_small);
54237 #ifdef CONFIG_CIFS_STATS2
54238 seq_printf(m, "Total Large %d Small %d Allocations\n",
54239- atomic_read(&totBufAllocCount),
54240- atomic_read(&totSmBufAllocCount));
54241+ atomic_read_unchecked(&totBufAllocCount),
54242+ atomic_read_unchecked(&totSmBufAllocCount));
54243 #endif /* CONFIG_CIFS_STATS2 */
54244
54245 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
54246@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54247 if (tcon->need_reconnect)
54248 seq_puts(m, "\tDISCONNECTED ");
54249 seq_printf(m, "\nSMBs: %d",
54250- atomic_read(&tcon->num_smbs_sent));
54251+ atomic_read_unchecked(&tcon->num_smbs_sent));
54252 if (server->ops->print_stats)
54253 server->ops->print_stats(m, tcon);
54254 }
54255diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
54256index 77fc5e1..e3d13e6 100644
54257--- a/fs/cifs/cifsfs.c
54258+++ b/fs/cifs/cifsfs.c
54259@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
54260 */
54261 cifs_req_cachep = kmem_cache_create("cifs_request",
54262 CIFSMaxBufSize + max_hdr_size, 0,
54263- SLAB_HWCACHE_ALIGN, NULL);
54264+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
54265 if (cifs_req_cachep == NULL)
54266 return -ENOMEM;
54267
54268@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
54269 efficient to alloc 1 per page off the slab compared to 17K (5page)
54270 alloc of large cifs buffers even when page debugging is on */
54271 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
54272- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
54273+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
54274 NULL);
54275 if (cifs_sm_req_cachep == NULL) {
54276 mempool_destroy(cifs_req_poolp);
54277@@ -1168,8 +1168,8 @@ init_cifs(void)
54278 atomic_set(&bufAllocCount, 0);
54279 atomic_set(&smBufAllocCount, 0);
54280 #ifdef CONFIG_CIFS_STATS2
54281- atomic_set(&totBufAllocCount, 0);
54282- atomic_set(&totSmBufAllocCount, 0);
54283+ atomic_set_unchecked(&totBufAllocCount, 0);
54284+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54285 #endif /* CONFIG_CIFS_STATS2 */
54286
54287 atomic_set(&midCount, 0);
54288diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
54289index 52b6f6c..68db1f4 100644
54290--- a/fs/cifs/cifsglob.h
54291+++ b/fs/cifs/cifsglob.h
54292@@ -758,35 +758,35 @@ struct cifs_tcon {
54293 __u16 Flags; /* optional support bits */
54294 enum statusEnum tidStatus;
54295 #ifdef CONFIG_CIFS_STATS
54296- atomic_t num_smbs_sent;
54297+ atomic_unchecked_t num_smbs_sent;
54298 union {
54299 struct {
54300- atomic_t num_writes;
54301- atomic_t num_reads;
54302- atomic_t num_flushes;
54303- atomic_t num_oplock_brks;
54304- atomic_t num_opens;
54305- atomic_t num_closes;
54306- atomic_t num_deletes;
54307- atomic_t num_mkdirs;
54308- atomic_t num_posixopens;
54309- atomic_t num_posixmkdirs;
54310- atomic_t num_rmdirs;
54311- atomic_t num_renames;
54312- atomic_t num_t2renames;
54313- atomic_t num_ffirst;
54314- atomic_t num_fnext;
54315- atomic_t num_fclose;
54316- atomic_t num_hardlinks;
54317- atomic_t num_symlinks;
54318- atomic_t num_locks;
54319- atomic_t num_acl_get;
54320- atomic_t num_acl_set;
54321+ atomic_unchecked_t num_writes;
54322+ atomic_unchecked_t num_reads;
54323+ atomic_unchecked_t num_flushes;
54324+ atomic_unchecked_t num_oplock_brks;
54325+ atomic_unchecked_t num_opens;
54326+ atomic_unchecked_t num_closes;
54327+ atomic_unchecked_t num_deletes;
54328+ atomic_unchecked_t num_mkdirs;
54329+ atomic_unchecked_t num_posixopens;
54330+ atomic_unchecked_t num_posixmkdirs;
54331+ atomic_unchecked_t num_rmdirs;
54332+ atomic_unchecked_t num_renames;
54333+ atomic_unchecked_t num_t2renames;
54334+ atomic_unchecked_t num_ffirst;
54335+ atomic_unchecked_t num_fnext;
54336+ atomic_unchecked_t num_fclose;
54337+ atomic_unchecked_t num_hardlinks;
54338+ atomic_unchecked_t num_symlinks;
54339+ atomic_unchecked_t num_locks;
54340+ atomic_unchecked_t num_acl_get;
54341+ atomic_unchecked_t num_acl_set;
54342 } cifs_stats;
54343 #ifdef CONFIG_CIFS_SMB2
54344 struct {
54345- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54346- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54347+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54348+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54349 } smb2_stats;
54350 #endif /* CONFIG_CIFS_SMB2 */
54351 } stats;
54352@@ -1111,7 +1111,7 @@ convert_delimiter(char *path, char delim)
54353 }
54354
54355 #ifdef CONFIG_CIFS_STATS
54356-#define cifs_stats_inc atomic_inc
54357+#define cifs_stats_inc atomic_inc_unchecked
54358
54359 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
54360 unsigned int bytes)
54361@@ -1477,8 +1477,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
54362 /* Various Debug counters */
54363 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
54364 #ifdef CONFIG_CIFS_STATS2
54365-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
54366-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
54367+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
54368+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
54369 #endif
54370 GLOBAL_EXTERN atomic_t smBufAllocCount;
54371 GLOBAL_EXTERN atomic_t midCount;
54372diff --git a/fs/cifs/link.c b/fs/cifs/link.c
54373index 7e36ceb..109252f 100644
54374--- a/fs/cifs/link.c
54375+++ b/fs/cifs/link.c
54376@@ -624,7 +624,7 @@ symlink_exit:
54377
54378 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
54379 {
54380- char *p = nd_get_link(nd);
54381+ const char *p = nd_get_link(nd);
54382 if (!IS_ERR(p))
54383 kfree(p);
54384 }
54385diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
54386index 138a011..cf9e13a 100644
54387--- a/fs/cifs/misc.c
54388+++ b/fs/cifs/misc.c
54389@@ -170,7 +170,7 @@ cifs_buf_get(void)
54390 memset(ret_buf, 0, buf_size + 3);
54391 atomic_inc(&bufAllocCount);
54392 #ifdef CONFIG_CIFS_STATS2
54393- atomic_inc(&totBufAllocCount);
54394+ atomic_inc_unchecked(&totBufAllocCount);
54395 #endif /* CONFIG_CIFS_STATS2 */
54396 }
54397
54398@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
54399 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
54400 atomic_inc(&smBufAllocCount);
54401 #ifdef CONFIG_CIFS_STATS2
54402- atomic_inc(&totSmBufAllocCount);
54403+ atomic_inc_unchecked(&totSmBufAllocCount);
54404 #endif /* CONFIG_CIFS_STATS2 */
54405
54406 }
54407diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54408index 8233b17..2b83e95 100644
54409--- a/fs/cifs/smb1ops.c
54410+++ b/fs/cifs/smb1ops.c
54411@@ -590,27 +590,27 @@ static void
54412 cifs_clear_stats(struct cifs_tcon *tcon)
54413 {
54414 #ifdef CONFIG_CIFS_STATS
54415- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54416- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54417- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54418- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54419- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54420- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54421- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54422- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54423- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54424- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54425- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54426- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54427- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54428- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54429- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54430- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54431- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54432- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54433- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54434- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54435- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54436+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54437+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54438+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54439+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54440+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54441+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54442+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54443+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54444+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54445+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54446+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54447+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54448+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54449+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54450+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54451+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54452+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54453+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54454+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54455+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54456+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54457 #endif
54458 }
54459
54460@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54461 {
54462 #ifdef CONFIG_CIFS_STATS
54463 seq_printf(m, " Oplocks breaks: %d",
54464- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54465+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54466 seq_printf(m, "\nReads: %d Bytes: %llu",
54467- atomic_read(&tcon->stats.cifs_stats.num_reads),
54468+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54469 (long long)(tcon->bytes_read));
54470 seq_printf(m, "\nWrites: %d Bytes: %llu",
54471- atomic_read(&tcon->stats.cifs_stats.num_writes),
54472+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54473 (long long)(tcon->bytes_written));
54474 seq_printf(m, "\nFlushes: %d",
54475- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54476+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54477 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54478- atomic_read(&tcon->stats.cifs_stats.num_locks),
54479- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54480- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54481+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54482+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54483+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54484 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54485- atomic_read(&tcon->stats.cifs_stats.num_opens),
54486- atomic_read(&tcon->stats.cifs_stats.num_closes),
54487- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54488+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54489+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54490+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54491 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54492- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54493- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54494+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54495+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54496 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54497- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54498- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54499+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54500+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54501 seq_printf(m, "\nRenames: %d T2 Renames %d",
54502- atomic_read(&tcon->stats.cifs_stats.num_renames),
54503- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54504+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54505+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54506 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54507- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54508- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54509- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54510+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54511+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54512+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54513 #endif
54514 }
54515
54516diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54517index 861b332..5506392 100644
54518--- a/fs/cifs/smb2ops.c
54519+++ b/fs/cifs/smb2ops.c
54520@@ -282,8 +282,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54521 #ifdef CONFIG_CIFS_STATS
54522 int i;
54523 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54524- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54525- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54526+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54527+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54528 }
54529 #endif
54530 }
54531@@ -311,65 +311,65 @@ static void
54532 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54533 {
54534 #ifdef CONFIG_CIFS_STATS
54535- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54536- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54537+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54538+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54539 seq_printf(m, "\nNegotiates: %d sent %d failed",
54540- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54541- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54542+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54543+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54544 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54545- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54546- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54547+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54548+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54549 seq_printf(m, "\nLogoffs: %d sent %d failed",
54550- atomic_read(&sent[SMB2_LOGOFF_HE]),
54551- atomic_read(&failed[SMB2_LOGOFF_HE]));
54552+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54553+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54554 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54555- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54556- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54557+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54558+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54559 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54560- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54561- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54562+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54563+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54564 seq_printf(m, "\nCreates: %d sent %d failed",
54565- atomic_read(&sent[SMB2_CREATE_HE]),
54566- atomic_read(&failed[SMB2_CREATE_HE]));
54567+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54568+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54569 seq_printf(m, "\nCloses: %d sent %d failed",
54570- atomic_read(&sent[SMB2_CLOSE_HE]),
54571- atomic_read(&failed[SMB2_CLOSE_HE]));
54572+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54573+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54574 seq_printf(m, "\nFlushes: %d sent %d failed",
54575- atomic_read(&sent[SMB2_FLUSH_HE]),
54576- atomic_read(&failed[SMB2_FLUSH_HE]));
54577+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54578+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54579 seq_printf(m, "\nReads: %d sent %d failed",
54580- atomic_read(&sent[SMB2_READ_HE]),
54581- atomic_read(&failed[SMB2_READ_HE]));
54582+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54583+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54584 seq_printf(m, "\nWrites: %d sent %d failed",
54585- atomic_read(&sent[SMB2_WRITE_HE]),
54586- atomic_read(&failed[SMB2_WRITE_HE]));
54587+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54588+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54589 seq_printf(m, "\nLocks: %d sent %d failed",
54590- atomic_read(&sent[SMB2_LOCK_HE]),
54591- atomic_read(&failed[SMB2_LOCK_HE]));
54592+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54593+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54594 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54595- atomic_read(&sent[SMB2_IOCTL_HE]),
54596- atomic_read(&failed[SMB2_IOCTL_HE]));
54597+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54598+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54599 seq_printf(m, "\nCancels: %d sent %d failed",
54600- atomic_read(&sent[SMB2_CANCEL_HE]),
54601- atomic_read(&failed[SMB2_CANCEL_HE]));
54602+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54603+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54604 seq_printf(m, "\nEchos: %d sent %d failed",
54605- atomic_read(&sent[SMB2_ECHO_HE]),
54606- atomic_read(&failed[SMB2_ECHO_HE]));
54607+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54608+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54609 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54610- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54611- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54612+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54613+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54614 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54615- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54616- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54617+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54618+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54619 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54620- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54621- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54622+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54623+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54624 seq_printf(m, "\nSetInfos: %d sent %d failed",
54625- atomic_read(&sent[SMB2_SET_INFO_HE]),
54626- atomic_read(&failed[SMB2_SET_INFO_HE]));
54627+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54628+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54629 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54630- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54631- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54632+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54633+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54634 #endif
54635 }
54636
54637diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54638index edccb52..16bc6db 100644
54639--- a/fs/cifs/smb2pdu.c
54640+++ b/fs/cifs/smb2pdu.c
54641@@ -1957,8 +1957,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54642 default:
54643 cifs_dbg(VFS, "info level %u isn't supported\n",
54644 srch_inf->info_level);
54645- rc = -EINVAL;
54646- goto qdir_exit;
54647+ return -EINVAL;
54648 }
54649
54650 req->FileIndex = cpu_to_le32(index);
54651diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54652index 1da168c..8bc7ff6 100644
54653--- a/fs/coda/cache.c
54654+++ b/fs/coda/cache.c
54655@@ -24,7 +24,7 @@
54656 #include "coda_linux.h"
54657 #include "coda_cache.h"
54658
54659-static atomic_t permission_epoch = ATOMIC_INIT(0);
54660+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54661
54662 /* replace or extend an acl cache hit */
54663 void coda_cache_enter(struct inode *inode, int mask)
54664@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54665 struct coda_inode_info *cii = ITOC(inode);
54666
54667 spin_lock(&cii->c_lock);
54668- cii->c_cached_epoch = atomic_read(&permission_epoch);
54669+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54670 if (!uid_eq(cii->c_uid, current_fsuid())) {
54671 cii->c_uid = current_fsuid();
54672 cii->c_cached_perm = mask;
54673@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54674 {
54675 struct coda_inode_info *cii = ITOC(inode);
54676 spin_lock(&cii->c_lock);
54677- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54678+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54679 spin_unlock(&cii->c_lock);
54680 }
54681
54682 /* remove all acl caches */
54683 void coda_cache_clear_all(struct super_block *sb)
54684 {
54685- atomic_inc(&permission_epoch);
54686+ atomic_inc_unchecked(&permission_epoch);
54687 }
54688
54689
54690@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54691 spin_lock(&cii->c_lock);
54692 hit = (mask & cii->c_cached_perm) == mask &&
54693 uid_eq(cii->c_uid, current_fsuid()) &&
54694- cii->c_cached_epoch == atomic_read(&permission_epoch);
54695+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54696 spin_unlock(&cii->c_lock);
54697
54698 return hit;
54699diff --git a/fs/compat.c b/fs/compat.c
54700index 6af20de..fec3fbb 100644
54701--- a/fs/compat.c
54702+++ b/fs/compat.c
54703@@ -54,7 +54,7 @@
54704 #include <asm/ioctls.h>
54705 #include "internal.h"
54706
54707-int compat_log = 1;
54708+int compat_log = 0;
54709
54710 int compat_printk(const char *fmt, ...)
54711 {
54712@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54713
54714 set_fs(KERNEL_DS);
54715 /* The __user pointer cast is valid because of the set_fs() */
54716- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54717+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54718 set_fs(oldfs);
54719 /* truncating is ok because it's a user address */
54720 if (!ret)
54721@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54722 goto out;
54723
54724 ret = -EINVAL;
54725- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54726+ if (nr_segs > UIO_MAXIOV)
54727 goto out;
54728 if (nr_segs > fast_segs) {
54729 ret = -ENOMEM;
54730@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54731 struct compat_readdir_callback {
54732 struct dir_context ctx;
54733 struct compat_old_linux_dirent __user *dirent;
54734+ struct file * file;
54735 int result;
54736 };
54737
54738@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54739 buf->result = -EOVERFLOW;
54740 return -EOVERFLOW;
54741 }
54742+
54743+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54744+ return 0;
54745+
54746 buf->result++;
54747 dirent = buf->dirent;
54748 if (!access_ok(VERIFY_WRITE, dirent,
54749@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54750 if (!f.file)
54751 return -EBADF;
54752
54753+ buf.file = f.file;
54754 error = iterate_dir(f.file, &buf.ctx);
54755 if (buf.result)
54756 error = buf.result;
54757@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54758 struct dir_context ctx;
54759 struct compat_linux_dirent __user *current_dir;
54760 struct compat_linux_dirent __user *previous;
54761+ struct file * file;
54762 int count;
54763 int error;
54764 };
54765@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54766 buf->error = -EOVERFLOW;
54767 return -EOVERFLOW;
54768 }
54769+
54770+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54771+ return 0;
54772+
54773 dirent = buf->previous;
54774 if (dirent) {
54775 if (__put_user(offset, &dirent->d_off))
54776@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54777 if (!f.file)
54778 return -EBADF;
54779
54780+ buf.file = f.file;
54781 error = iterate_dir(f.file, &buf.ctx);
54782 if (error >= 0)
54783 error = buf.error;
54784@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54785 struct dir_context ctx;
54786 struct linux_dirent64 __user *current_dir;
54787 struct linux_dirent64 __user *previous;
54788+ struct file * file;
54789 int count;
54790 int error;
54791 };
54792@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54793 buf->error = -EINVAL; /* only used if we fail.. */
54794 if (reclen > buf->count)
54795 return -EINVAL;
54796+
54797+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54798+ return 0;
54799+
54800 dirent = buf->previous;
54801
54802 if (dirent) {
54803@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54804 if (!f.file)
54805 return -EBADF;
54806
54807+ buf.file = f.file;
54808 error = iterate_dir(f.file, &buf.ctx);
54809 if (error >= 0)
54810 error = buf.error;
54811diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54812index a81147e..20bf2b5 100644
54813--- a/fs/compat_binfmt_elf.c
54814+++ b/fs/compat_binfmt_elf.c
54815@@ -30,11 +30,13 @@
54816 #undef elf_phdr
54817 #undef elf_shdr
54818 #undef elf_note
54819+#undef elf_dyn
54820 #undef elf_addr_t
54821 #define elfhdr elf32_hdr
54822 #define elf_phdr elf32_phdr
54823 #define elf_shdr elf32_shdr
54824 #define elf_note elf32_note
54825+#define elf_dyn Elf32_Dyn
54826 #define elf_addr_t Elf32_Addr
54827
54828 /*
54829diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54830index 5d19acf..9ab093b 100644
54831--- a/fs/compat_ioctl.c
54832+++ b/fs/compat_ioctl.c
54833@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54834 return -EFAULT;
54835 if (__get_user(udata, &ss32->iomem_base))
54836 return -EFAULT;
54837- ss.iomem_base = compat_ptr(udata);
54838+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54839 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54840 __get_user(ss.port_high, &ss32->port_high))
54841 return -EFAULT;
54842@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54843 for (i = 0; i < nmsgs; i++) {
54844 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54845 return -EFAULT;
54846- if (get_user(datap, &umsgs[i].buf) ||
54847- put_user(compat_ptr(datap), &tmsgs[i].buf))
54848+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54849+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54850 return -EFAULT;
54851 }
54852 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54853@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54854 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54855 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54856 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54857- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54858+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54859 return -EFAULT;
54860
54861 return ioctl_preallocate(file, p);
54862@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54863 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54864 {
54865 unsigned int a, b;
54866- a = *(unsigned int *)p;
54867- b = *(unsigned int *)q;
54868+ a = *(const unsigned int *)p;
54869+ b = *(const unsigned int *)q;
54870 if (a > b)
54871 return 1;
54872 if (a < b)
54873diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54874index 511d415..319d0e5 100644
54875--- a/fs/configfs/dir.c
54876+++ b/fs/configfs/dir.c
54877@@ -1558,7 +1558,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54878 }
54879 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54880 struct configfs_dirent *next;
54881- const char *name;
54882+ const unsigned char * name;
54883+ char d_name[sizeof(next->s_dentry->d_iname)];
54884 int len;
54885 struct inode *inode = NULL;
54886
54887@@ -1567,7 +1568,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54888 continue;
54889
54890 name = configfs_get_name(next);
54891- len = strlen(name);
54892+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54893+ len = next->s_dentry->d_name.len;
54894+ memcpy(d_name, name, len);
54895+ name = d_name;
54896+ } else
54897+ len = strlen(name);
54898
54899 /*
54900 * We'll have a dentry and an inode for
54901diff --git a/fs/coredump.c b/fs/coredump.c
54902index 9bdeca1..2247b92 100644
54903--- a/fs/coredump.c
54904+++ b/fs/coredump.c
54905@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
54906 struct pipe_inode_info *pipe = file->private_data;
54907
54908 pipe_lock(pipe);
54909- pipe->readers++;
54910- pipe->writers--;
54911+ atomic_inc(&pipe->readers);
54912+ atomic_dec(&pipe->writers);
54913 wake_up_interruptible_sync(&pipe->wait);
54914 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54915 pipe_unlock(pipe);
54916@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
54917 * We actually want wait_event_freezable() but then we need
54918 * to clear TIF_SIGPENDING and improve dump_interrupted().
54919 */
54920- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54921+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54922
54923 pipe_lock(pipe);
54924- pipe->readers--;
54925- pipe->writers++;
54926+ atomic_dec(&pipe->readers);
54927+ atomic_inc(&pipe->writers);
54928 pipe_unlock(pipe);
54929 }
54930
54931@@ -499,7 +499,8 @@ void do_coredump(siginfo_t *siginfo)
54932 struct files_struct *displaced;
54933 bool need_nonrelative = false;
54934 bool core_dumped = false;
54935- static atomic_t core_dump_count = ATOMIC_INIT(0);
54936+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54937+ long signr = siginfo->si_signo;
54938 struct coredump_params cprm = {
54939 .siginfo = siginfo,
54940 .regs = signal_pt_regs(),
54941@@ -512,7 +513,10 @@ void do_coredump(siginfo_t *siginfo)
54942 .mm_flags = mm->flags,
54943 };
54944
54945- audit_core_dumps(siginfo->si_signo);
54946+ audit_core_dumps(signr);
54947+
54948+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54949+ gr_handle_brute_attach(cprm.mm_flags);
54950
54951 binfmt = mm->binfmt;
54952 if (!binfmt || !binfmt->core_dump)
54953@@ -536,7 +540,7 @@ void do_coredump(siginfo_t *siginfo)
54954 need_nonrelative = true;
54955 }
54956
54957- retval = coredump_wait(siginfo->si_signo, &core_state);
54958+ retval = coredump_wait(signr, &core_state);
54959 if (retval < 0)
54960 goto fail_creds;
54961
54962@@ -579,7 +583,7 @@ void do_coredump(siginfo_t *siginfo)
54963 }
54964 cprm.limit = RLIM_INFINITY;
54965
54966- dump_count = atomic_inc_return(&core_dump_count);
54967+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54968 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54969 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54970 task_tgid_vnr(current), current->comm);
54971@@ -611,6 +615,8 @@ void do_coredump(siginfo_t *siginfo)
54972 } else {
54973 struct inode *inode;
54974
54975+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54976+
54977 if (cprm.limit < binfmt->min_coredump)
54978 goto fail_unlock;
54979
54980@@ -669,7 +675,7 @@ close_fail:
54981 filp_close(cprm.file, NULL);
54982 fail_dropcount:
54983 if (ispipe)
54984- atomic_dec(&core_dump_count);
54985+ atomic_dec_unchecked(&core_dump_count);
54986 fail_unlock:
54987 kfree(cn.corename);
54988 coredump_finish(mm, core_dumped);
54989@@ -689,7 +695,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54990 {
54991 return !dump_interrupted() &&
54992 access_ok(VERIFY_READ, addr, nr) &&
54993- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54994+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54995 }
54996 EXPORT_SYMBOL(dump_write);
54997
54998diff --git a/fs/dcache.c b/fs/dcache.c
54999index 89f9671..5977a84 100644
55000--- a/fs/dcache.c
55001+++ b/fs/dcache.c
55002@@ -2893,6 +2893,7 @@ static int prepend_path(const struct path *path,
55003 restart:
55004 bptr = *buffer;
55005 blen = *buflen;
55006+ error = 0;
55007 dentry = path->dentry;
55008 vfsmnt = path->mnt;
55009 mnt = real_mount(vfsmnt);
55010@@ -3432,7 +3433,8 @@ void __init vfs_caches_init(unsigned long mempages)
55011 mempages -= reserve;
55012
55013 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
55014- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
55015+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
55016+ SLAB_NO_SANITIZE, NULL);
55017
55018 dcache_init();
55019 inode_init();
55020diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
55021index c7c83ff..bda9461 100644
55022--- a/fs/debugfs/inode.c
55023+++ b/fs/debugfs/inode.c
55024@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
55025 */
55026 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
55027 {
55028+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55029+ return __create_file(name, S_IFDIR | S_IRWXU,
55030+#else
55031 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
55032+#endif
55033 parent, NULL, NULL);
55034 }
55035 EXPORT_SYMBOL_GPL(debugfs_create_dir);
55036diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
55037index 67e9b63..a9adb68 100644
55038--- a/fs/ecryptfs/inode.c
55039+++ b/fs/ecryptfs/inode.c
55040@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
55041 old_fs = get_fs();
55042 set_fs(get_ds());
55043 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
55044- (char __user *)lower_buf,
55045+ (char __force_user *)lower_buf,
55046 PATH_MAX);
55047 set_fs(old_fs);
55048 if (rc < 0)
55049@@ -706,7 +706,7 @@ out:
55050 static void
55051 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
55052 {
55053- char *buf = nd_get_link(nd);
55054+ const char *buf = nd_get_link(nd);
55055 if (!IS_ERR(buf)) {
55056 /* Free the char* */
55057 kfree(buf);
55058diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
55059index e4141f2..d8263e8 100644
55060--- a/fs/ecryptfs/miscdev.c
55061+++ b/fs/ecryptfs/miscdev.c
55062@@ -304,7 +304,7 @@ check_list:
55063 goto out_unlock_msg_ctx;
55064 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
55065 if (msg_ctx->msg) {
55066- if (copy_to_user(&buf[i], packet_length, packet_length_size))
55067+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
55068 goto out_unlock_msg_ctx;
55069 i += packet_length_size;
55070 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
55071diff --git a/fs/exec.c b/fs/exec.c
55072index bb8afc1..2f5087e 100644
55073--- a/fs/exec.c
55074+++ b/fs/exec.c
55075@@ -55,8 +55,20 @@
55076 #include <linux/pipe_fs_i.h>
55077 #include <linux/oom.h>
55078 #include <linux/compat.h>
55079+#include <linux/random.h>
55080+#include <linux/seq_file.h>
55081+#include <linux/coredump.h>
55082+#include <linux/mman.h>
55083+
55084+#ifdef CONFIG_PAX_REFCOUNT
55085+#include <linux/kallsyms.h>
55086+#include <linux/kdebug.h>
55087+#endif
55088+
55089+#include <trace/events/fs.h>
55090
55091 #include <asm/uaccess.h>
55092+#include <asm/sections.h>
55093 #include <asm/mmu_context.h>
55094 #include <asm/tlb.h>
55095
55096@@ -66,19 +78,34 @@
55097
55098 #include <trace/events/sched.h>
55099
55100+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55101+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
55102+{
55103+ 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");
55104+}
55105+#endif
55106+
55107+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
55108+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
55109+EXPORT_SYMBOL(pax_set_initial_flags_func);
55110+#endif
55111+
55112 int suid_dumpable = 0;
55113
55114 static LIST_HEAD(formats);
55115 static DEFINE_RWLOCK(binfmt_lock);
55116
55117+extern int gr_process_kernel_exec_ban(void);
55118+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
55119+
55120 void __register_binfmt(struct linux_binfmt * fmt, int insert)
55121 {
55122 BUG_ON(!fmt);
55123 if (WARN_ON(!fmt->load_binary))
55124 return;
55125 write_lock(&binfmt_lock);
55126- insert ? list_add(&fmt->lh, &formats) :
55127- list_add_tail(&fmt->lh, &formats);
55128+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
55129+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
55130 write_unlock(&binfmt_lock);
55131 }
55132
55133@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
55134 void unregister_binfmt(struct linux_binfmt * fmt)
55135 {
55136 write_lock(&binfmt_lock);
55137- list_del(&fmt->lh);
55138+ pax_list_del((struct list_head *)&fmt->lh);
55139 write_unlock(&binfmt_lock);
55140 }
55141
55142@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55143 int write)
55144 {
55145 struct page *page;
55146- int ret;
55147
55148-#ifdef CONFIG_STACK_GROWSUP
55149- if (write) {
55150- ret = expand_downwards(bprm->vma, pos);
55151- if (ret < 0)
55152- return NULL;
55153- }
55154-#endif
55155- ret = get_user_pages(current, bprm->mm, pos,
55156- 1, write, 1, &page, NULL);
55157- if (ret <= 0)
55158+ if (0 > expand_downwards(bprm->vma, pos))
55159+ return NULL;
55160+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
55161 return NULL;
55162
55163 if (write) {
55164@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55165 if (size <= ARG_MAX)
55166 return page;
55167
55168+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55169+ // only allow 512KB for argv+env on suid/sgid binaries
55170+ // to prevent easy ASLR exhaustion
55171+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
55172+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
55173+ (size > (512 * 1024))) {
55174+ put_page(page);
55175+ return NULL;
55176+ }
55177+#endif
55178+
55179 /*
55180 * Limit to 1/4-th the stack size for the argv+env strings.
55181 * This ensures that:
55182@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55183 vma->vm_end = STACK_TOP_MAX;
55184 vma->vm_start = vma->vm_end - PAGE_SIZE;
55185 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
55186+
55187+#ifdef CONFIG_PAX_SEGMEXEC
55188+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
55189+#endif
55190+
55191 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
55192 INIT_LIST_HEAD(&vma->anon_vma_chain);
55193
55194@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55195 mm->stack_vm = mm->total_vm = 1;
55196 up_write(&mm->mmap_sem);
55197 bprm->p = vma->vm_end - sizeof(void *);
55198+
55199+#ifdef CONFIG_PAX_RANDUSTACK
55200+ if (randomize_va_space)
55201+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
55202+#endif
55203+
55204 return 0;
55205 err:
55206 up_write(&mm->mmap_sem);
55207@@ -399,7 +440,7 @@ struct user_arg_ptr {
55208 } ptr;
55209 };
55210
55211-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55212+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55213 {
55214 const char __user *native;
55215
55216@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55217 compat_uptr_t compat;
55218
55219 if (get_user(compat, argv.ptr.compat + nr))
55220- return ERR_PTR(-EFAULT);
55221+ return (const char __force_user *)ERR_PTR(-EFAULT);
55222
55223 return compat_ptr(compat);
55224 }
55225 #endif
55226
55227 if (get_user(native, argv.ptr.native + nr))
55228- return ERR_PTR(-EFAULT);
55229+ return (const char __force_user *)ERR_PTR(-EFAULT);
55230
55231 return native;
55232 }
55233@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
55234 if (!p)
55235 break;
55236
55237- if (IS_ERR(p))
55238+ if (IS_ERR((const char __force_kernel *)p))
55239 return -EFAULT;
55240
55241 if (i >= max)
55242@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
55243
55244 ret = -EFAULT;
55245 str = get_user_arg_ptr(argv, argc);
55246- if (IS_ERR(str))
55247+ if (IS_ERR((const char __force_kernel *)str))
55248 goto out;
55249
55250 len = strnlen_user(str, MAX_ARG_STRLEN);
55251@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
55252 int r;
55253 mm_segment_t oldfs = get_fs();
55254 struct user_arg_ptr argv = {
55255- .ptr.native = (const char __user *const __user *)__argv,
55256+ .ptr.native = (const char __force_user * const __force_user *)__argv,
55257 };
55258
55259 set_fs(KERNEL_DS);
55260@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55261 unsigned long new_end = old_end - shift;
55262 struct mmu_gather tlb;
55263
55264- BUG_ON(new_start > new_end);
55265+ if (new_start >= new_end || new_start < mmap_min_addr)
55266+ return -ENOMEM;
55267
55268 /*
55269 * ensure there are no vmas between where we want to go
55270@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55271 if (vma != find_vma(mm, new_start))
55272 return -EFAULT;
55273
55274+#ifdef CONFIG_PAX_SEGMEXEC
55275+ BUG_ON(pax_find_mirror_vma(vma));
55276+#endif
55277+
55278 /*
55279 * cover the whole range: [new_start, old_end)
55280 */
55281@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55282 stack_top = arch_align_stack(stack_top);
55283 stack_top = PAGE_ALIGN(stack_top);
55284
55285- if (unlikely(stack_top < mmap_min_addr) ||
55286- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
55287- return -ENOMEM;
55288-
55289 stack_shift = vma->vm_end - stack_top;
55290
55291 bprm->p -= stack_shift;
55292@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
55293 bprm->exec -= stack_shift;
55294
55295 down_write(&mm->mmap_sem);
55296+
55297+ /* Move stack pages down in memory. */
55298+ if (stack_shift) {
55299+ ret = shift_arg_pages(vma, stack_shift);
55300+ if (ret)
55301+ goto out_unlock;
55302+ }
55303+
55304 vm_flags = VM_STACK_FLAGS;
55305
55306+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55307+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55308+ vm_flags &= ~VM_EXEC;
55309+
55310+#ifdef CONFIG_PAX_MPROTECT
55311+ if (mm->pax_flags & MF_PAX_MPROTECT)
55312+ vm_flags &= ~VM_MAYEXEC;
55313+#endif
55314+
55315+ }
55316+#endif
55317+
55318 /*
55319 * Adjust stack execute permissions; explicitly enable for
55320 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
55321@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55322 goto out_unlock;
55323 BUG_ON(prev != vma);
55324
55325- /* Move stack pages down in memory. */
55326- if (stack_shift) {
55327- ret = shift_arg_pages(vma, stack_shift);
55328- if (ret)
55329- goto out_unlock;
55330- }
55331-
55332 /* mprotect_fixup is overkill to remove the temporary stack flags */
55333 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
55334
55335@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
55336 #endif
55337 current->mm->start_stack = bprm->p;
55338 ret = expand_stack(vma, stack_base);
55339+
55340+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
55341+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
55342+ unsigned long size;
55343+ vm_flags_t vm_flags;
55344+
55345+ size = STACK_TOP - vma->vm_end;
55346+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
55347+
55348+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
55349+
55350+#ifdef CONFIG_X86
55351+ if (!ret) {
55352+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
55353+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
55354+ }
55355+#endif
55356+
55357+ }
55358+#endif
55359+
55360 if (ret)
55361 ret = -EFAULT;
55362
55363@@ -776,6 +852,8 @@ struct file *open_exec(const char *name)
55364
55365 fsnotify_open(file);
55366
55367+ trace_open_exec(name);
55368+
55369 err = deny_write_access(file);
55370 if (err)
55371 goto exit;
55372@@ -799,7 +877,7 @@ int kernel_read(struct file *file, loff_t offset,
55373 old_fs = get_fs();
55374 set_fs(get_ds());
55375 /* The cast to a user pointer is valid due to the set_fs() */
55376- result = vfs_read(file, (void __user *)addr, count, &pos);
55377+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
55378 set_fs(old_fs);
55379 return result;
55380 }
55381@@ -1255,7 +1333,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
55382 }
55383 rcu_read_unlock();
55384
55385- if (p->fs->users > n_fs) {
55386+ if (atomic_read(&p->fs->users) > n_fs) {
55387 bprm->unsafe |= LSM_UNSAFE_SHARE;
55388 } else {
55389 res = -EAGAIN;
55390@@ -1451,6 +1529,31 @@ static int exec_binprm(struct linux_binprm *bprm)
55391 return ret;
55392 }
55393
55394+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55395+static DEFINE_PER_CPU(u64, exec_counter);
55396+static int __init init_exec_counters(void)
55397+{
55398+ unsigned int cpu;
55399+
55400+ for_each_possible_cpu(cpu) {
55401+ per_cpu(exec_counter, cpu) = (u64)cpu;
55402+ }
55403+
55404+ return 0;
55405+}
55406+early_initcall(init_exec_counters);
55407+static inline void increment_exec_counter(void)
55408+{
55409+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
55410+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55411+}
55412+#else
55413+static inline void increment_exec_counter(void) {}
55414+#endif
55415+
55416+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55417+ struct user_arg_ptr argv);
55418+
55419 /*
55420 * sys_execve() executes a new program.
55421 */
55422@@ -1458,12 +1561,19 @@ static int do_execve_common(const char *filename,
55423 struct user_arg_ptr argv,
55424 struct user_arg_ptr envp)
55425 {
55426+#ifdef CONFIG_GRKERNSEC
55427+ struct file *old_exec_file;
55428+ struct acl_subject_label *old_acl;
55429+ struct rlimit old_rlim[RLIM_NLIMITS];
55430+#endif
55431 struct linux_binprm *bprm;
55432 struct file *file;
55433 struct files_struct *displaced;
55434 bool clear_in_exec;
55435 int retval;
55436
55437+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
55438+
55439 /*
55440 * We move the actual failure in case of RLIMIT_NPROC excess from
55441 * set*uid() to execve() because too many poorly written programs
55442@@ -1504,12 +1614,22 @@ static int do_execve_common(const char *filename,
55443 if (IS_ERR(file))
55444 goto out_unmark;
55445
55446+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55447+ retval = -EPERM;
55448+ goto out_file;
55449+ }
55450+
55451 sched_exec();
55452
55453 bprm->file = file;
55454 bprm->filename = filename;
55455 bprm->interp = filename;
55456
55457+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55458+ retval = -EACCES;
55459+ goto out_file;
55460+ }
55461+
55462 retval = bprm_mm_init(bprm);
55463 if (retval)
55464 goto out_file;
55465@@ -1526,24 +1646,70 @@ static int do_execve_common(const char *filename,
55466 if (retval < 0)
55467 goto out;
55468
55469+#ifdef CONFIG_GRKERNSEC
55470+ old_acl = current->acl;
55471+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55472+ old_exec_file = current->exec_file;
55473+ get_file(file);
55474+ current->exec_file = file;
55475+#endif
55476+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55477+ /* limit suid stack to 8MB
55478+ * we saved the old limits above and will restore them if this exec fails
55479+ */
55480+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55481+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55482+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55483+#endif
55484+
55485+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55486+ retval = -EPERM;
55487+ goto out_fail;
55488+ }
55489+
55490+ if (!gr_tpe_allow(file)) {
55491+ retval = -EACCES;
55492+ goto out_fail;
55493+ }
55494+
55495+ if (gr_check_crash_exec(file)) {
55496+ retval = -EACCES;
55497+ goto out_fail;
55498+ }
55499+
55500+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55501+ bprm->unsafe);
55502+ if (retval < 0)
55503+ goto out_fail;
55504+
55505 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55506 if (retval < 0)
55507- goto out;
55508+ goto out_fail;
55509
55510 bprm->exec = bprm->p;
55511 retval = copy_strings(bprm->envc, envp, bprm);
55512 if (retval < 0)
55513- goto out;
55514+ goto out_fail;
55515
55516 retval = copy_strings(bprm->argc, argv, bprm);
55517 if (retval < 0)
55518- goto out;
55519+ goto out_fail;
55520+
55521+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55522+
55523+ gr_handle_exec_args(bprm, argv);
55524
55525 retval = exec_binprm(bprm);
55526 if (retval < 0)
55527- goto out;
55528+ goto out_fail;
55529+#ifdef CONFIG_GRKERNSEC
55530+ if (old_exec_file)
55531+ fput(old_exec_file);
55532+#endif
55533
55534 /* execve succeeded */
55535+
55536+ increment_exec_counter();
55537 current->fs->in_exec = 0;
55538 current->in_execve = 0;
55539 acct_update_integrals(current);
55540@@ -1552,6 +1718,14 @@ static int do_execve_common(const char *filename,
55541 put_files_struct(displaced);
55542 return retval;
55543
55544+out_fail:
55545+#ifdef CONFIG_GRKERNSEC
55546+ current->acl = old_acl;
55547+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55548+ fput(current->exec_file);
55549+ current->exec_file = old_exec_file;
55550+#endif
55551+
55552 out:
55553 if (bprm->mm) {
55554 acct_arg_size(bprm, 0);
55555@@ -1706,3 +1880,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55556 return error;
55557 }
55558 #endif
55559+
55560+int pax_check_flags(unsigned long *flags)
55561+{
55562+ int retval = 0;
55563+
55564+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55565+ if (*flags & MF_PAX_SEGMEXEC)
55566+ {
55567+ *flags &= ~MF_PAX_SEGMEXEC;
55568+ retval = -EINVAL;
55569+ }
55570+#endif
55571+
55572+ if ((*flags & MF_PAX_PAGEEXEC)
55573+
55574+#ifdef CONFIG_PAX_PAGEEXEC
55575+ && (*flags & MF_PAX_SEGMEXEC)
55576+#endif
55577+
55578+ )
55579+ {
55580+ *flags &= ~MF_PAX_PAGEEXEC;
55581+ retval = -EINVAL;
55582+ }
55583+
55584+ if ((*flags & MF_PAX_MPROTECT)
55585+
55586+#ifdef CONFIG_PAX_MPROTECT
55587+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55588+#endif
55589+
55590+ )
55591+ {
55592+ *flags &= ~MF_PAX_MPROTECT;
55593+ retval = -EINVAL;
55594+ }
55595+
55596+ if ((*flags & MF_PAX_EMUTRAMP)
55597+
55598+#ifdef CONFIG_PAX_EMUTRAMP
55599+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55600+#endif
55601+
55602+ )
55603+ {
55604+ *flags &= ~MF_PAX_EMUTRAMP;
55605+ retval = -EINVAL;
55606+ }
55607+
55608+ return retval;
55609+}
55610+
55611+EXPORT_SYMBOL(pax_check_flags);
55612+
55613+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55614+char *pax_get_path(const struct path *path, char *buf, int buflen)
55615+{
55616+ char *pathname = d_path(path, buf, buflen);
55617+
55618+ if (IS_ERR(pathname))
55619+ goto toolong;
55620+
55621+ pathname = mangle_path(buf, pathname, "\t\n\\");
55622+ if (!pathname)
55623+ goto toolong;
55624+
55625+ *pathname = 0;
55626+ return buf;
55627+
55628+toolong:
55629+ return "<path too long>";
55630+}
55631+EXPORT_SYMBOL(pax_get_path);
55632+
55633+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55634+{
55635+ struct task_struct *tsk = current;
55636+ struct mm_struct *mm = current->mm;
55637+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55638+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55639+ char *path_exec = NULL;
55640+ char *path_fault = NULL;
55641+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55642+ siginfo_t info = { };
55643+
55644+ if (buffer_exec && buffer_fault) {
55645+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55646+
55647+ down_read(&mm->mmap_sem);
55648+ vma = mm->mmap;
55649+ while (vma && (!vma_exec || !vma_fault)) {
55650+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55651+ vma_exec = vma;
55652+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55653+ vma_fault = vma;
55654+ vma = vma->vm_next;
55655+ }
55656+ if (vma_exec)
55657+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55658+ if (vma_fault) {
55659+ start = vma_fault->vm_start;
55660+ end = vma_fault->vm_end;
55661+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55662+ if (vma_fault->vm_file)
55663+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55664+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55665+ path_fault = "<heap>";
55666+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55667+ path_fault = "<stack>";
55668+ else
55669+ path_fault = "<anonymous mapping>";
55670+ }
55671+ up_read(&mm->mmap_sem);
55672+ }
55673+ if (tsk->signal->curr_ip)
55674+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55675+ else
55676+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55677+ 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),
55678+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55679+ free_page((unsigned long)buffer_exec);
55680+ free_page((unsigned long)buffer_fault);
55681+ pax_report_insns(regs, pc, sp);
55682+ info.si_signo = SIGKILL;
55683+ info.si_errno = 0;
55684+ info.si_code = SI_KERNEL;
55685+ info.si_pid = 0;
55686+ info.si_uid = 0;
55687+ do_coredump(&info);
55688+}
55689+#endif
55690+
55691+#ifdef CONFIG_PAX_REFCOUNT
55692+void pax_report_refcount_overflow(struct pt_regs *regs)
55693+{
55694+ if (current->signal->curr_ip)
55695+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55696+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55697+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55698+ else
55699+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55700+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55701+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55702+ preempt_disable();
55703+ show_regs(regs);
55704+ preempt_enable();
55705+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55706+}
55707+#endif
55708+
55709+#ifdef CONFIG_PAX_USERCOPY
55710+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55711+static noinline int check_stack_object(const void *obj, unsigned long len)
55712+{
55713+ const void * const stack = task_stack_page(current);
55714+ const void * const stackend = stack + THREAD_SIZE;
55715+
55716+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55717+ const void *frame = NULL;
55718+ const void *oldframe;
55719+#endif
55720+
55721+ if (obj + len < obj)
55722+ return -1;
55723+
55724+ if (obj + len <= stack || stackend <= obj)
55725+ return 0;
55726+
55727+ if (obj < stack || stackend < obj + len)
55728+ return -1;
55729+
55730+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55731+ oldframe = __builtin_frame_address(1);
55732+ if (oldframe)
55733+ frame = __builtin_frame_address(2);
55734+ /*
55735+ low ----------------------------------------------> high
55736+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55737+ ^----------------^
55738+ allow copies only within here
55739+ */
55740+ while (stack <= frame && frame < stackend) {
55741+ /* if obj + len extends past the last frame, this
55742+ check won't pass and the next frame will be 0,
55743+ causing us to bail out and correctly report
55744+ the copy as invalid
55745+ */
55746+ if (obj + len <= frame)
55747+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55748+ oldframe = frame;
55749+ frame = *(const void * const *)frame;
55750+ }
55751+ return -1;
55752+#else
55753+ return 1;
55754+#endif
55755+}
55756+
55757+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55758+{
55759+ if (current->signal->curr_ip)
55760+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55761+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55762+ else
55763+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55764+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55765+ dump_stack();
55766+ gr_handle_kernel_exploit();
55767+ do_group_exit(SIGKILL);
55768+}
55769+#endif
55770+
55771+#ifdef CONFIG_PAX_USERCOPY
55772+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55773+{
55774+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55775+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55776+#ifdef CONFIG_MODULES
55777+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55778+#else
55779+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55780+#endif
55781+
55782+#else
55783+ unsigned long textlow = (unsigned long)_stext;
55784+ unsigned long texthigh = (unsigned long)_etext;
55785+
55786+#ifdef CONFIG_X86_64
55787+ /* check against linear mapping as well */
55788+ if (high > (unsigned long)__va(__pa(textlow)) &&
55789+ low <= (unsigned long)__va(__pa(texthigh)))
55790+ return true;
55791+#endif
55792+
55793+#endif
55794+
55795+ if (high <= textlow || low > texthigh)
55796+ return false;
55797+ else
55798+ return true;
55799+}
55800+#endif
55801+
55802+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55803+{
55804+
55805+#ifdef CONFIG_PAX_USERCOPY
55806+ const char *type;
55807+
55808+ if (!n)
55809+ return;
55810+
55811+ type = check_heap_object(ptr, n);
55812+ if (!type) {
55813+ int ret = check_stack_object(ptr, n);
55814+ if (ret == 1 || ret == 2)
55815+ return;
55816+ if (ret == 0) {
55817+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55818+ type = "<kernel text>";
55819+ else
55820+ return;
55821+ } else
55822+ type = "<process stack>";
55823+ }
55824+
55825+ pax_report_usercopy(ptr, n, to_user, type);
55826+#endif
55827+
55828+}
55829+EXPORT_SYMBOL(__check_object_size);
55830+
55831+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55832+void pax_track_stack(void)
55833+{
55834+ unsigned long sp = (unsigned long)&sp;
55835+ if (sp < current_thread_info()->lowest_stack &&
55836+ sp > (unsigned long)task_stack_page(current))
55837+ current_thread_info()->lowest_stack = sp;
55838+}
55839+EXPORT_SYMBOL(pax_track_stack);
55840+#endif
55841+
55842+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55843+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55844+{
55845+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55846+ dump_stack();
55847+ do_group_exit(SIGKILL);
55848+}
55849+EXPORT_SYMBOL(report_size_overflow);
55850+#endif
55851diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55852index 9f9992b..8b59411 100644
55853--- a/fs/ext2/balloc.c
55854+++ b/fs/ext2/balloc.c
55855@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55856
55857 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55858 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55859- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55860+ if (free_blocks < root_blocks + 1 &&
55861 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55862 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55863- !in_group_p (sbi->s_resgid))) {
55864+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55865 return 0;
55866 }
55867 return 1;
55868diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
55869index 2d7557d..14e38f94 100644
55870--- a/fs/ext2/xattr.c
55871+++ b/fs/ext2/xattr.c
55872@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
55873 struct buffer_head *bh = NULL;
55874 struct ext2_xattr_entry *entry;
55875 char *end;
55876- size_t rest = buffer_size;
55877+ size_t rest = buffer_size, total_size = 0;
55878 int error;
55879
55880 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
55881@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
55882 buffer += size;
55883 }
55884 rest -= size;
55885+ total_size += size;
55886 }
55887 }
55888- error = buffer_size - rest; /* total size */
55889+ error = total_size;
55890
55891 cleanup:
55892 brelse(bh);
55893diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55894index 22548f5..41521d8 100644
55895--- a/fs/ext3/balloc.c
55896+++ b/fs/ext3/balloc.c
55897@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55898
55899 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55900 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55901- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55902+ if (free_blocks < root_blocks + 1 &&
55903 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55904 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55905- !in_group_p (sbi->s_resgid))) {
55906+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55907 return 0;
55908 }
55909 return 1;
55910diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
55911index b1fc963..881228c 100644
55912--- a/fs/ext3/xattr.c
55913+++ b/fs/ext3/xattr.c
55914@@ -330,7 +330,7 @@ static int
55915 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
55916 char *buffer, size_t buffer_size)
55917 {
55918- size_t rest = buffer_size;
55919+ size_t rest = buffer_size, total_size = 0;
55920
55921 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
55922 const struct xattr_handler *handler =
55923@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
55924 buffer += size;
55925 }
55926 rest -= size;
55927+ total_size += size;
55928 }
55929 }
55930- return buffer_size - rest;
55931+ return total_size;
55932 }
55933
55934 static int
55935diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55936index dc5d572..4c21f8e 100644
55937--- a/fs/ext4/balloc.c
55938+++ b/fs/ext4/balloc.c
55939@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55940 /* Hm, nope. Are (enough) root reserved clusters available? */
55941 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55942 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55943- capable(CAP_SYS_RESOURCE) ||
55944- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55945+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55946+ capable_nolog(CAP_SYS_RESOURCE)) {
55947
55948 if (free_clusters >= (nclusters + dirty_clusters +
55949 resv_clusters))
55950diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55951index af815ea..99294a6 100644
55952--- a/fs/ext4/ext4.h
55953+++ b/fs/ext4/ext4.h
55954@@ -1256,19 +1256,19 @@ struct ext4_sb_info {
55955 unsigned long s_mb_last_start;
55956
55957 /* stats for buddy allocator */
55958- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55959- atomic_t s_bal_success; /* we found long enough chunks */
55960- atomic_t s_bal_allocated; /* in blocks */
55961- atomic_t s_bal_ex_scanned; /* total extents scanned */
55962- atomic_t s_bal_goals; /* goal hits */
55963- atomic_t s_bal_breaks; /* too long searches */
55964- atomic_t s_bal_2orders; /* 2^order hits */
55965+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55966+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55967+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55968+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55969+ atomic_unchecked_t s_bal_goals; /* goal hits */
55970+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55971+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55972 spinlock_t s_bal_lock;
55973 unsigned long s_mb_buddies_generated;
55974 unsigned long long s_mb_generation_time;
55975- atomic_t s_mb_lost_chunks;
55976- atomic_t s_mb_preallocated;
55977- atomic_t s_mb_discarded;
55978+ atomic_unchecked_t s_mb_lost_chunks;
55979+ atomic_unchecked_t s_mb_preallocated;
55980+ atomic_unchecked_t s_mb_discarded;
55981 atomic_t s_lock_busy;
55982
55983 /* locality groups */
55984diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55985index a41e3ba..e574a00 100644
55986--- a/fs/ext4/mballoc.c
55987+++ b/fs/ext4/mballoc.c
55988@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55989 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55990
55991 if (EXT4_SB(sb)->s_mb_stats)
55992- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55993+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55994
55995 break;
55996 }
55997@@ -2189,7 +2189,7 @@ repeat:
55998 ac->ac_status = AC_STATUS_CONTINUE;
55999 ac->ac_flags |= EXT4_MB_HINT_FIRST;
56000 cr = 3;
56001- atomic_inc(&sbi->s_mb_lost_chunks);
56002+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
56003 goto repeat;
56004 }
56005 }
56006@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
56007 if (sbi->s_mb_stats) {
56008 ext4_msg(sb, KERN_INFO,
56009 "mballoc: %u blocks %u reqs (%u success)",
56010- atomic_read(&sbi->s_bal_allocated),
56011- atomic_read(&sbi->s_bal_reqs),
56012- atomic_read(&sbi->s_bal_success));
56013+ atomic_read_unchecked(&sbi->s_bal_allocated),
56014+ atomic_read_unchecked(&sbi->s_bal_reqs),
56015+ atomic_read_unchecked(&sbi->s_bal_success));
56016 ext4_msg(sb, KERN_INFO,
56017 "mballoc: %u extents scanned, %u goal hits, "
56018 "%u 2^N hits, %u breaks, %u lost",
56019- atomic_read(&sbi->s_bal_ex_scanned),
56020- atomic_read(&sbi->s_bal_goals),
56021- atomic_read(&sbi->s_bal_2orders),
56022- atomic_read(&sbi->s_bal_breaks),
56023- atomic_read(&sbi->s_mb_lost_chunks));
56024+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
56025+ atomic_read_unchecked(&sbi->s_bal_goals),
56026+ atomic_read_unchecked(&sbi->s_bal_2orders),
56027+ atomic_read_unchecked(&sbi->s_bal_breaks),
56028+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
56029 ext4_msg(sb, KERN_INFO,
56030 "mballoc: %lu generated and it took %Lu",
56031 sbi->s_mb_buddies_generated,
56032 sbi->s_mb_generation_time);
56033 ext4_msg(sb, KERN_INFO,
56034 "mballoc: %u preallocated, %u discarded",
56035- atomic_read(&sbi->s_mb_preallocated),
56036- atomic_read(&sbi->s_mb_discarded));
56037+ atomic_read_unchecked(&sbi->s_mb_preallocated),
56038+ atomic_read_unchecked(&sbi->s_mb_discarded));
56039 }
56040
56041 free_percpu(sbi->s_locality_groups);
56042@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
56043 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
56044
56045 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
56046- atomic_inc(&sbi->s_bal_reqs);
56047- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56048+ atomic_inc_unchecked(&sbi->s_bal_reqs);
56049+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56050 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
56051- atomic_inc(&sbi->s_bal_success);
56052- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
56053+ atomic_inc_unchecked(&sbi->s_bal_success);
56054+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
56055 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
56056 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
56057- atomic_inc(&sbi->s_bal_goals);
56058+ atomic_inc_unchecked(&sbi->s_bal_goals);
56059 if (ac->ac_found > sbi->s_mb_max_to_scan)
56060- atomic_inc(&sbi->s_bal_breaks);
56061+ atomic_inc_unchecked(&sbi->s_bal_breaks);
56062 }
56063
56064 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
56065@@ -3578,7 +3578,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
56066 trace_ext4_mb_new_inode_pa(ac, pa);
56067
56068 ext4_mb_use_inode_pa(ac, pa);
56069- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
56070+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
56071
56072 ei = EXT4_I(ac->ac_inode);
56073 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56074@@ -3638,7 +3638,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
56075 trace_ext4_mb_new_group_pa(ac, pa);
56076
56077 ext4_mb_use_group_pa(ac, pa);
56078- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56079+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56080
56081 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56082 lg = ac->ac_lg;
56083@@ -3727,7 +3727,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
56084 * from the bitmap and continue.
56085 */
56086 }
56087- atomic_add(free, &sbi->s_mb_discarded);
56088+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
56089
56090 return err;
56091 }
56092@@ -3745,7 +3745,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
56093 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
56094 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
56095 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
56096- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56097+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56098 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
56099
56100 return 0;
56101diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
56102index 214461e..3614c89 100644
56103--- a/fs/ext4/mmp.c
56104+++ b/fs/ext4/mmp.c
56105@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
56106 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
56107 const char *function, unsigned int line, const char *msg)
56108 {
56109- __ext4_warning(sb, function, line, msg);
56110+ __ext4_warning(sb, function, line, "%s", msg);
56111 __ext4_warning(sb, function, line,
56112 "MMP failure info: last update time: %llu, last update "
56113 "node: %s, last update device: %s\n",
56114diff --git a/fs/ext4/super.c b/fs/ext4/super.c
56115index 2c2e6cb..7c3ee62 100644
56116--- a/fs/ext4/super.c
56117+++ b/fs/ext4/super.c
56118@@ -1251,7 +1251,7 @@ static ext4_fsblk_t get_sb_block(void **data)
56119 }
56120
56121 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
56122-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56123+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56124 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
56125
56126 #ifdef CONFIG_QUOTA
56127@@ -2431,7 +2431,7 @@ struct ext4_attr {
56128 int offset;
56129 int deprecated_val;
56130 } u;
56131-};
56132+} __do_const;
56133
56134 static int parse_strtoull(const char *buf,
56135 unsigned long long max, unsigned long long *value)
56136diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
56137index 03e9beb..e86ce98 100644
56138--- a/fs/ext4/xattr.c
56139+++ b/fs/ext4/xattr.c
56140@@ -381,7 +381,7 @@ static int
56141 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56142 char *buffer, size_t buffer_size)
56143 {
56144- size_t rest = buffer_size;
56145+ size_t rest = buffer_size, total_size = 0;
56146
56147 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
56148 const struct xattr_handler *handler =
56149@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56150 buffer += size;
56151 }
56152 rest -= size;
56153+ total_size += size;
56154 }
56155 }
56156- return buffer_size - rest;
56157+ return total_size;
56158 }
56159
56160 static int
56161diff --git a/fs/fcntl.c b/fs/fcntl.c
56162index 65343c3..9969dcf 100644
56163--- a/fs/fcntl.c
56164+++ b/fs/fcntl.c
56165@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
56166 if (err)
56167 return err;
56168
56169+ if (gr_handle_chroot_fowner(pid, type))
56170+ return -ENOENT;
56171+ if (gr_check_protected_task_fowner(pid, type))
56172+ return -EACCES;
56173+
56174 f_modown(filp, pid, type, force);
56175 return 0;
56176 }
56177diff --git a/fs/fhandle.c b/fs/fhandle.c
56178index 999ff5c..41f4109 100644
56179--- a/fs/fhandle.c
56180+++ b/fs/fhandle.c
56181@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
56182 } else
56183 retval = 0;
56184 /* copy the mount id */
56185- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
56186- sizeof(*mnt_id)) ||
56187+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
56188 copy_to_user(ufh, handle,
56189 sizeof(struct file_handle) + handle_bytes))
56190 retval = -EFAULT;
56191diff --git a/fs/file.c b/fs/file.c
56192index 4a78f98..9447397 100644
56193--- a/fs/file.c
56194+++ b/fs/file.c
56195@@ -16,6 +16,7 @@
56196 #include <linux/slab.h>
56197 #include <linux/vmalloc.h>
56198 #include <linux/file.h>
56199+#include <linux/security.h>
56200 #include <linux/fdtable.h>
56201 #include <linux/bitops.h>
56202 #include <linux/interrupt.h>
56203@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
56204 if (!file)
56205 return __close_fd(files, fd);
56206
56207+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
56208 if (fd >= rlimit(RLIMIT_NOFILE))
56209 return -EBADF;
56210
56211@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
56212 if (unlikely(oldfd == newfd))
56213 return -EINVAL;
56214
56215+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
56216 if (newfd >= rlimit(RLIMIT_NOFILE))
56217 return -EBADF;
56218
56219@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
56220 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
56221 {
56222 int err;
56223+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
56224 if (from >= rlimit(RLIMIT_NOFILE))
56225 return -EINVAL;
56226 err = alloc_fd(from, flags);
56227diff --git a/fs/filesystems.c b/fs/filesystems.c
56228index 92567d9..fcd8cbf 100644
56229--- a/fs/filesystems.c
56230+++ b/fs/filesystems.c
56231@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
56232 int len = dot ? dot - name : strlen(name);
56233
56234 fs = __get_fs_type(name, len);
56235+#ifdef CONFIG_GRKERNSEC_MODHARDEN
56236+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
56237+#else
56238 if (!fs && (request_module("fs-%.*s", len, name) == 0))
56239+#endif
56240 fs = __get_fs_type(name, len);
56241
56242 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
56243diff --git a/fs/fs_struct.c b/fs/fs_struct.c
56244index d8ac61d..79a36f0 100644
56245--- a/fs/fs_struct.c
56246+++ b/fs/fs_struct.c
56247@@ -4,6 +4,7 @@
56248 #include <linux/path.h>
56249 #include <linux/slab.h>
56250 #include <linux/fs_struct.h>
56251+#include <linux/grsecurity.h>
56252 #include "internal.h"
56253
56254 /*
56255@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
56256 write_seqcount_begin(&fs->seq);
56257 old_root = fs->root;
56258 fs->root = *path;
56259+ gr_set_chroot_entries(current, path);
56260 write_seqcount_end(&fs->seq);
56261 spin_unlock(&fs->lock);
56262 if (old_root.dentry)
56263@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
56264 int hits = 0;
56265 spin_lock(&fs->lock);
56266 write_seqcount_begin(&fs->seq);
56267+ /* this root replacement is only done by pivot_root,
56268+ leave grsec's chroot tagging alone for this task
56269+ so that a pivoted root isn't treated as a chroot
56270+ */
56271 hits += replace_path(&fs->root, old_root, new_root);
56272 hits += replace_path(&fs->pwd, old_root, new_root);
56273 write_seqcount_end(&fs->seq);
56274@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
56275 task_lock(tsk);
56276 spin_lock(&fs->lock);
56277 tsk->fs = NULL;
56278- kill = !--fs->users;
56279+ gr_clear_chroot_entries(tsk);
56280+ kill = !atomic_dec_return(&fs->users);
56281 spin_unlock(&fs->lock);
56282 task_unlock(tsk);
56283 if (kill)
56284@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56285 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
56286 /* We don't need to lock fs - think why ;-) */
56287 if (fs) {
56288- fs->users = 1;
56289+ atomic_set(&fs->users, 1);
56290 fs->in_exec = 0;
56291 spin_lock_init(&fs->lock);
56292 seqcount_init(&fs->seq);
56293@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56294 spin_lock(&old->lock);
56295 fs->root = old->root;
56296 path_get(&fs->root);
56297+ /* instead of calling gr_set_chroot_entries here,
56298+ we call it from every caller of this function
56299+ */
56300 fs->pwd = old->pwd;
56301 path_get(&fs->pwd);
56302 spin_unlock(&old->lock);
56303@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
56304
56305 task_lock(current);
56306 spin_lock(&fs->lock);
56307- kill = !--fs->users;
56308+ kill = !atomic_dec_return(&fs->users);
56309 current->fs = new_fs;
56310+ gr_set_chroot_entries(current, &new_fs->root);
56311 spin_unlock(&fs->lock);
56312 task_unlock(current);
56313
56314@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
56315
56316 int current_umask(void)
56317 {
56318- return current->fs->umask;
56319+ return current->fs->umask | gr_acl_umask();
56320 }
56321 EXPORT_SYMBOL(current_umask);
56322
56323 /* to be mentioned only in INIT_TASK */
56324 struct fs_struct init_fs = {
56325- .users = 1,
56326+ .users = ATOMIC_INIT(1),
56327 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
56328 .seq = SEQCNT_ZERO,
56329 .umask = 0022,
56330diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
56331index b2a86e3..37f425a 100644
56332--- a/fs/fscache/cookie.c
56333+++ b/fs/fscache/cookie.c
56334@@ -19,7 +19,7 @@
56335
56336 struct kmem_cache *fscache_cookie_jar;
56337
56338-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
56339+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
56340
56341 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
56342 static int fscache_alloc_object(struct fscache_cache *cache,
56343@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
56344 parent ? (char *) parent->def->name : "<no-parent>",
56345 def->name, netfs_data);
56346
56347- fscache_stat(&fscache_n_acquires);
56348+ fscache_stat_unchecked(&fscache_n_acquires);
56349
56350 /* if there's no parent cookie, then we don't create one here either */
56351 if (!parent) {
56352- fscache_stat(&fscache_n_acquires_null);
56353+ fscache_stat_unchecked(&fscache_n_acquires_null);
56354 _leave(" [no parent]");
56355 return NULL;
56356 }
56357@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
56358 /* allocate and initialise a cookie */
56359 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
56360 if (!cookie) {
56361- fscache_stat(&fscache_n_acquires_oom);
56362+ fscache_stat_unchecked(&fscache_n_acquires_oom);
56363 _leave(" [ENOMEM]");
56364 return NULL;
56365 }
56366@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56367
56368 switch (cookie->def->type) {
56369 case FSCACHE_COOKIE_TYPE_INDEX:
56370- fscache_stat(&fscache_n_cookie_index);
56371+ fscache_stat_unchecked(&fscache_n_cookie_index);
56372 break;
56373 case FSCACHE_COOKIE_TYPE_DATAFILE:
56374- fscache_stat(&fscache_n_cookie_data);
56375+ fscache_stat_unchecked(&fscache_n_cookie_data);
56376 break;
56377 default:
56378- fscache_stat(&fscache_n_cookie_special);
56379+ fscache_stat_unchecked(&fscache_n_cookie_special);
56380 break;
56381 }
56382
56383@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56384 if (fscache_acquire_non_index_cookie(cookie) < 0) {
56385 atomic_dec(&parent->n_children);
56386 __fscache_cookie_put(cookie);
56387- fscache_stat(&fscache_n_acquires_nobufs);
56388+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
56389 _leave(" = NULL");
56390 return NULL;
56391 }
56392 }
56393
56394- fscache_stat(&fscache_n_acquires_ok);
56395+ fscache_stat_unchecked(&fscache_n_acquires_ok);
56396 _leave(" = %p", cookie);
56397 return cookie;
56398 }
56399@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
56400 cache = fscache_select_cache_for_object(cookie->parent);
56401 if (!cache) {
56402 up_read(&fscache_addremove_sem);
56403- fscache_stat(&fscache_n_acquires_no_cache);
56404+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
56405 _leave(" = -ENOMEDIUM [no cache]");
56406 return -ENOMEDIUM;
56407 }
56408@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
56409 object = cache->ops->alloc_object(cache, cookie);
56410 fscache_stat_d(&fscache_n_cop_alloc_object);
56411 if (IS_ERR(object)) {
56412- fscache_stat(&fscache_n_object_no_alloc);
56413+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
56414 ret = PTR_ERR(object);
56415 goto error;
56416 }
56417
56418- fscache_stat(&fscache_n_object_alloc);
56419+ fscache_stat_unchecked(&fscache_n_object_alloc);
56420
56421- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
56422+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
56423
56424 _debug("ALLOC OBJ%x: %s {%lx}",
56425 object->debug_id, cookie->def->name, object->events);
56426@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
56427
56428 _enter("{%s}", cookie->def->name);
56429
56430- fscache_stat(&fscache_n_invalidates);
56431+ fscache_stat_unchecked(&fscache_n_invalidates);
56432
56433 /* Only permit invalidation of data files. Invalidating an index will
56434 * require the caller to release all its attachments to the tree rooted
56435@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
56436 {
56437 struct fscache_object *object;
56438
56439- fscache_stat(&fscache_n_updates);
56440+ fscache_stat_unchecked(&fscache_n_updates);
56441
56442 if (!cookie) {
56443- fscache_stat(&fscache_n_updates_null);
56444+ fscache_stat_unchecked(&fscache_n_updates_null);
56445 _leave(" [no cookie]");
56446 return;
56447 }
56448@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56449 {
56450 struct fscache_object *object;
56451
56452- fscache_stat(&fscache_n_relinquishes);
56453+ fscache_stat_unchecked(&fscache_n_relinquishes);
56454 if (retire)
56455- fscache_stat(&fscache_n_relinquishes_retire);
56456+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
56457
56458 if (!cookie) {
56459- fscache_stat(&fscache_n_relinquishes_null);
56460+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
56461 _leave(" [no cookie]");
56462 return;
56463 }
56464@@ -598,7 +598,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
56465 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
56466 goto inconsistent;
56467
56468- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
56469+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56470
56471 atomic_inc(&cookie->n_active);
56472 if (fscache_submit_op(object, op) < 0)
56473diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
56474index 4226f66..0fb3f45 100644
56475--- a/fs/fscache/internal.h
56476+++ b/fs/fscache/internal.h
56477@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
56478 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
56479 extern int fscache_wait_for_operation_activation(struct fscache_object *,
56480 struct fscache_operation *,
56481- atomic_t *,
56482- atomic_t *,
56483+ atomic_unchecked_t *,
56484+ atomic_unchecked_t *,
56485 void (*)(struct fscache_operation *));
56486 extern void fscache_invalidate_writes(struct fscache_cookie *);
56487
56488@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
56489 * stats.c
56490 */
56491 #ifdef CONFIG_FSCACHE_STATS
56492-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56493-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56494+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56495+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56496
56497-extern atomic_t fscache_n_op_pend;
56498-extern atomic_t fscache_n_op_run;
56499-extern atomic_t fscache_n_op_enqueue;
56500-extern atomic_t fscache_n_op_deferred_release;
56501-extern atomic_t fscache_n_op_release;
56502-extern atomic_t fscache_n_op_gc;
56503-extern atomic_t fscache_n_op_cancelled;
56504-extern atomic_t fscache_n_op_rejected;
56505+extern atomic_unchecked_t fscache_n_op_pend;
56506+extern atomic_unchecked_t fscache_n_op_run;
56507+extern atomic_unchecked_t fscache_n_op_enqueue;
56508+extern atomic_unchecked_t fscache_n_op_deferred_release;
56509+extern atomic_unchecked_t fscache_n_op_release;
56510+extern atomic_unchecked_t fscache_n_op_gc;
56511+extern atomic_unchecked_t fscache_n_op_cancelled;
56512+extern atomic_unchecked_t fscache_n_op_rejected;
56513
56514-extern atomic_t fscache_n_attr_changed;
56515-extern atomic_t fscache_n_attr_changed_ok;
56516-extern atomic_t fscache_n_attr_changed_nobufs;
56517-extern atomic_t fscache_n_attr_changed_nomem;
56518-extern atomic_t fscache_n_attr_changed_calls;
56519+extern atomic_unchecked_t fscache_n_attr_changed;
56520+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56521+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56522+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56523+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56524
56525-extern atomic_t fscache_n_allocs;
56526-extern atomic_t fscache_n_allocs_ok;
56527-extern atomic_t fscache_n_allocs_wait;
56528-extern atomic_t fscache_n_allocs_nobufs;
56529-extern atomic_t fscache_n_allocs_intr;
56530-extern atomic_t fscache_n_allocs_object_dead;
56531-extern atomic_t fscache_n_alloc_ops;
56532-extern atomic_t fscache_n_alloc_op_waits;
56533+extern atomic_unchecked_t fscache_n_allocs;
56534+extern atomic_unchecked_t fscache_n_allocs_ok;
56535+extern atomic_unchecked_t fscache_n_allocs_wait;
56536+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56537+extern atomic_unchecked_t fscache_n_allocs_intr;
56538+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56539+extern atomic_unchecked_t fscache_n_alloc_ops;
56540+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56541
56542-extern atomic_t fscache_n_retrievals;
56543-extern atomic_t fscache_n_retrievals_ok;
56544-extern atomic_t fscache_n_retrievals_wait;
56545-extern atomic_t fscache_n_retrievals_nodata;
56546-extern atomic_t fscache_n_retrievals_nobufs;
56547-extern atomic_t fscache_n_retrievals_intr;
56548-extern atomic_t fscache_n_retrievals_nomem;
56549-extern atomic_t fscache_n_retrievals_object_dead;
56550-extern atomic_t fscache_n_retrieval_ops;
56551-extern atomic_t fscache_n_retrieval_op_waits;
56552+extern atomic_unchecked_t fscache_n_retrievals;
56553+extern atomic_unchecked_t fscache_n_retrievals_ok;
56554+extern atomic_unchecked_t fscache_n_retrievals_wait;
56555+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56556+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56557+extern atomic_unchecked_t fscache_n_retrievals_intr;
56558+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56559+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56560+extern atomic_unchecked_t fscache_n_retrieval_ops;
56561+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56562
56563-extern atomic_t fscache_n_stores;
56564-extern atomic_t fscache_n_stores_ok;
56565-extern atomic_t fscache_n_stores_again;
56566-extern atomic_t fscache_n_stores_nobufs;
56567-extern atomic_t fscache_n_stores_oom;
56568-extern atomic_t fscache_n_store_ops;
56569-extern atomic_t fscache_n_store_calls;
56570-extern atomic_t fscache_n_store_pages;
56571-extern atomic_t fscache_n_store_radix_deletes;
56572-extern atomic_t fscache_n_store_pages_over_limit;
56573+extern atomic_unchecked_t fscache_n_stores;
56574+extern atomic_unchecked_t fscache_n_stores_ok;
56575+extern atomic_unchecked_t fscache_n_stores_again;
56576+extern atomic_unchecked_t fscache_n_stores_nobufs;
56577+extern atomic_unchecked_t fscache_n_stores_oom;
56578+extern atomic_unchecked_t fscache_n_store_ops;
56579+extern atomic_unchecked_t fscache_n_store_calls;
56580+extern atomic_unchecked_t fscache_n_store_pages;
56581+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56582+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56583
56584-extern atomic_t fscache_n_store_vmscan_not_storing;
56585-extern atomic_t fscache_n_store_vmscan_gone;
56586-extern atomic_t fscache_n_store_vmscan_busy;
56587-extern atomic_t fscache_n_store_vmscan_cancelled;
56588-extern atomic_t fscache_n_store_vmscan_wait;
56589+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56590+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56591+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56592+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56593+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56594
56595-extern atomic_t fscache_n_marks;
56596-extern atomic_t fscache_n_uncaches;
56597+extern atomic_unchecked_t fscache_n_marks;
56598+extern atomic_unchecked_t fscache_n_uncaches;
56599
56600-extern atomic_t fscache_n_acquires;
56601-extern atomic_t fscache_n_acquires_null;
56602-extern atomic_t fscache_n_acquires_no_cache;
56603-extern atomic_t fscache_n_acquires_ok;
56604-extern atomic_t fscache_n_acquires_nobufs;
56605-extern atomic_t fscache_n_acquires_oom;
56606+extern atomic_unchecked_t fscache_n_acquires;
56607+extern atomic_unchecked_t fscache_n_acquires_null;
56608+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56609+extern atomic_unchecked_t fscache_n_acquires_ok;
56610+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56611+extern atomic_unchecked_t fscache_n_acquires_oom;
56612
56613-extern atomic_t fscache_n_invalidates;
56614-extern atomic_t fscache_n_invalidates_run;
56615+extern atomic_unchecked_t fscache_n_invalidates;
56616+extern atomic_unchecked_t fscache_n_invalidates_run;
56617
56618-extern atomic_t fscache_n_updates;
56619-extern atomic_t fscache_n_updates_null;
56620-extern atomic_t fscache_n_updates_run;
56621+extern atomic_unchecked_t fscache_n_updates;
56622+extern atomic_unchecked_t fscache_n_updates_null;
56623+extern atomic_unchecked_t fscache_n_updates_run;
56624
56625-extern atomic_t fscache_n_relinquishes;
56626-extern atomic_t fscache_n_relinquishes_null;
56627-extern atomic_t fscache_n_relinquishes_waitcrt;
56628-extern atomic_t fscache_n_relinquishes_retire;
56629+extern atomic_unchecked_t fscache_n_relinquishes;
56630+extern atomic_unchecked_t fscache_n_relinquishes_null;
56631+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56632+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56633
56634-extern atomic_t fscache_n_cookie_index;
56635-extern atomic_t fscache_n_cookie_data;
56636-extern atomic_t fscache_n_cookie_special;
56637+extern atomic_unchecked_t fscache_n_cookie_index;
56638+extern atomic_unchecked_t fscache_n_cookie_data;
56639+extern atomic_unchecked_t fscache_n_cookie_special;
56640
56641-extern atomic_t fscache_n_object_alloc;
56642-extern atomic_t fscache_n_object_no_alloc;
56643-extern atomic_t fscache_n_object_lookups;
56644-extern atomic_t fscache_n_object_lookups_negative;
56645-extern atomic_t fscache_n_object_lookups_positive;
56646-extern atomic_t fscache_n_object_lookups_timed_out;
56647-extern atomic_t fscache_n_object_created;
56648-extern atomic_t fscache_n_object_avail;
56649-extern atomic_t fscache_n_object_dead;
56650+extern atomic_unchecked_t fscache_n_object_alloc;
56651+extern atomic_unchecked_t fscache_n_object_no_alloc;
56652+extern atomic_unchecked_t fscache_n_object_lookups;
56653+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56654+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56655+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56656+extern atomic_unchecked_t fscache_n_object_created;
56657+extern atomic_unchecked_t fscache_n_object_avail;
56658+extern atomic_unchecked_t fscache_n_object_dead;
56659
56660-extern atomic_t fscache_n_checkaux_none;
56661-extern atomic_t fscache_n_checkaux_okay;
56662-extern atomic_t fscache_n_checkaux_update;
56663-extern atomic_t fscache_n_checkaux_obsolete;
56664+extern atomic_unchecked_t fscache_n_checkaux_none;
56665+extern atomic_unchecked_t fscache_n_checkaux_okay;
56666+extern atomic_unchecked_t fscache_n_checkaux_update;
56667+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56668
56669 extern atomic_t fscache_n_cop_alloc_object;
56670 extern atomic_t fscache_n_cop_lookup_object;
56671@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
56672 atomic_inc(stat);
56673 }
56674
56675+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56676+{
56677+ atomic_inc_unchecked(stat);
56678+}
56679+
56680 static inline void fscache_stat_d(atomic_t *stat)
56681 {
56682 atomic_dec(stat);
56683@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
56684
56685 #define __fscache_stat(stat) (NULL)
56686 #define fscache_stat(stat) do {} while (0)
56687+#define fscache_stat_unchecked(stat) do {} while (0)
56688 #define fscache_stat_d(stat) do {} while (0)
56689 #endif
56690
56691diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56692index 86d75a6..5f3d7a0 100644
56693--- a/fs/fscache/object.c
56694+++ b/fs/fscache/object.c
56695@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56696 _debug("LOOKUP \"%s\" in \"%s\"",
56697 cookie->def->name, object->cache->tag->name);
56698
56699- fscache_stat(&fscache_n_object_lookups);
56700+ fscache_stat_unchecked(&fscache_n_object_lookups);
56701 fscache_stat(&fscache_n_cop_lookup_object);
56702 ret = object->cache->ops->lookup_object(object);
56703 fscache_stat_d(&fscache_n_cop_lookup_object);
56704@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56705 if (ret == -ETIMEDOUT) {
56706 /* probably stuck behind another object, so move this one to
56707 * the back of the queue */
56708- fscache_stat(&fscache_n_object_lookups_timed_out);
56709+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56710 _leave(" [timeout]");
56711 return NO_TRANSIT;
56712 }
56713@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56714 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56715
56716 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56717- fscache_stat(&fscache_n_object_lookups_negative);
56718+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56719
56720 /* Allow write requests to begin stacking up and read requests to begin
56721 * returning ENODATA.
56722@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56723 /* if we were still looking up, then we must have a positive lookup
56724 * result, in which case there may be data available */
56725 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56726- fscache_stat(&fscache_n_object_lookups_positive);
56727+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56728
56729 /* We do (presumably) have data */
56730 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56731@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56732 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56733 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56734 } else {
56735- fscache_stat(&fscache_n_object_created);
56736+ fscache_stat_unchecked(&fscache_n_object_created);
56737 }
56738
56739 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56740@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56741 fscache_stat_d(&fscache_n_cop_lookup_complete);
56742
56743 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56744- fscache_stat(&fscache_n_object_avail);
56745+ fscache_stat_unchecked(&fscache_n_object_avail);
56746
56747 _leave("");
56748 return transit_to(JUMPSTART_DEPS);
56749@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56750
56751 /* this just shifts the object release to the work processor */
56752 fscache_put_object(object);
56753- fscache_stat(&fscache_n_object_dead);
56754+ fscache_stat_unchecked(&fscache_n_object_dead);
56755
56756 _leave("");
56757 return transit_to(OBJECT_DEAD);
56758@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56759 enum fscache_checkaux result;
56760
56761 if (!object->cookie->def->check_aux) {
56762- fscache_stat(&fscache_n_checkaux_none);
56763+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56764 return FSCACHE_CHECKAUX_OKAY;
56765 }
56766
56767@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56768 switch (result) {
56769 /* entry okay as is */
56770 case FSCACHE_CHECKAUX_OKAY:
56771- fscache_stat(&fscache_n_checkaux_okay);
56772+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56773 break;
56774
56775 /* entry requires update */
56776 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56777- fscache_stat(&fscache_n_checkaux_update);
56778+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56779 break;
56780
56781 /* entry requires deletion */
56782 case FSCACHE_CHECKAUX_OBSOLETE:
56783- fscache_stat(&fscache_n_checkaux_obsolete);
56784+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56785 break;
56786
56787 default:
56788@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56789 {
56790 const struct fscache_state *s;
56791
56792- fscache_stat(&fscache_n_invalidates_run);
56793+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56794 fscache_stat(&fscache_n_cop_invalidate_object);
56795 s = _fscache_invalidate_object(object, event);
56796 fscache_stat_d(&fscache_n_cop_invalidate_object);
56797@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56798 {
56799 _enter("{OBJ%x},%d", object->debug_id, event);
56800
56801- fscache_stat(&fscache_n_updates_run);
56802+ fscache_stat_unchecked(&fscache_n_updates_run);
56803 fscache_stat(&fscache_n_cop_update_object);
56804 object->cache->ops->update_object(object);
56805 fscache_stat_d(&fscache_n_cop_update_object);
56806diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56807index 318071a..379938b 100644
56808--- a/fs/fscache/operation.c
56809+++ b/fs/fscache/operation.c
56810@@ -17,7 +17,7 @@
56811 #include <linux/slab.h>
56812 #include "internal.h"
56813
56814-atomic_t fscache_op_debug_id;
56815+atomic_unchecked_t fscache_op_debug_id;
56816 EXPORT_SYMBOL(fscache_op_debug_id);
56817
56818 /**
56819@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56820 ASSERTCMP(atomic_read(&op->usage), >, 0);
56821 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56822
56823- fscache_stat(&fscache_n_op_enqueue);
56824+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56825 switch (op->flags & FSCACHE_OP_TYPE) {
56826 case FSCACHE_OP_ASYNC:
56827 _debug("queue async");
56828@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56829 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56830 if (op->processor)
56831 fscache_enqueue_operation(op);
56832- fscache_stat(&fscache_n_op_run);
56833+ fscache_stat_unchecked(&fscache_n_op_run);
56834 }
56835
56836 /*
56837@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56838 if (object->n_in_progress > 0) {
56839 atomic_inc(&op->usage);
56840 list_add_tail(&op->pend_link, &object->pending_ops);
56841- fscache_stat(&fscache_n_op_pend);
56842+ fscache_stat_unchecked(&fscache_n_op_pend);
56843 } else if (!list_empty(&object->pending_ops)) {
56844 atomic_inc(&op->usage);
56845 list_add_tail(&op->pend_link, &object->pending_ops);
56846- fscache_stat(&fscache_n_op_pend);
56847+ fscache_stat_unchecked(&fscache_n_op_pend);
56848 fscache_start_operations(object);
56849 } else {
56850 ASSERTCMP(object->n_in_progress, ==, 0);
56851@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56852 object->n_exclusive++; /* reads and writes must wait */
56853 atomic_inc(&op->usage);
56854 list_add_tail(&op->pend_link, &object->pending_ops);
56855- fscache_stat(&fscache_n_op_pend);
56856+ fscache_stat_unchecked(&fscache_n_op_pend);
56857 ret = 0;
56858 } else {
56859 /* If we're in any other state, there must have been an I/O
56860@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56861 if (object->n_exclusive > 0) {
56862 atomic_inc(&op->usage);
56863 list_add_tail(&op->pend_link, &object->pending_ops);
56864- fscache_stat(&fscache_n_op_pend);
56865+ fscache_stat_unchecked(&fscache_n_op_pend);
56866 } else if (!list_empty(&object->pending_ops)) {
56867 atomic_inc(&op->usage);
56868 list_add_tail(&op->pend_link, &object->pending_ops);
56869- fscache_stat(&fscache_n_op_pend);
56870+ fscache_stat_unchecked(&fscache_n_op_pend);
56871 fscache_start_operations(object);
56872 } else {
56873 ASSERTCMP(object->n_exclusive, ==, 0);
56874@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56875 object->n_ops++;
56876 atomic_inc(&op->usage);
56877 list_add_tail(&op->pend_link, &object->pending_ops);
56878- fscache_stat(&fscache_n_op_pend);
56879+ fscache_stat_unchecked(&fscache_n_op_pend);
56880 ret = 0;
56881 } else if (fscache_object_is_dying(object)) {
56882- fscache_stat(&fscache_n_op_rejected);
56883+ fscache_stat_unchecked(&fscache_n_op_rejected);
56884 op->state = FSCACHE_OP_ST_CANCELLED;
56885 ret = -ENOBUFS;
56886 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56887@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56888 ret = -EBUSY;
56889 if (op->state == FSCACHE_OP_ST_PENDING) {
56890 ASSERT(!list_empty(&op->pend_link));
56891- fscache_stat(&fscache_n_op_cancelled);
56892+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56893 list_del_init(&op->pend_link);
56894 if (do_cancel)
56895 do_cancel(op);
56896@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56897 while (!list_empty(&object->pending_ops)) {
56898 op = list_entry(object->pending_ops.next,
56899 struct fscache_operation, pend_link);
56900- fscache_stat(&fscache_n_op_cancelled);
56901+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56902 list_del_init(&op->pend_link);
56903
56904 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56905@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56906 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56907 op->state = FSCACHE_OP_ST_DEAD;
56908
56909- fscache_stat(&fscache_n_op_release);
56910+ fscache_stat_unchecked(&fscache_n_op_release);
56911
56912 if (op->release) {
56913 op->release(op);
56914@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56915 * lock, and defer it otherwise */
56916 if (!spin_trylock(&object->lock)) {
56917 _debug("defer put");
56918- fscache_stat(&fscache_n_op_deferred_release);
56919+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56920
56921 cache = object->cache;
56922 spin_lock(&cache->op_gc_list_lock);
56923@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56924
56925 _debug("GC DEFERRED REL OBJ%x OP%x",
56926 object->debug_id, op->debug_id);
56927- fscache_stat(&fscache_n_op_gc);
56928+ fscache_stat_unchecked(&fscache_n_op_gc);
56929
56930 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56931 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56932diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56933index 73899c1..ae40c58 100644
56934--- a/fs/fscache/page.c
56935+++ b/fs/fscache/page.c
56936@@ -61,7 +61,7 @@ try_again:
56937 val = radix_tree_lookup(&cookie->stores, page->index);
56938 if (!val) {
56939 rcu_read_unlock();
56940- fscache_stat(&fscache_n_store_vmscan_not_storing);
56941+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56942 __fscache_uncache_page(cookie, page);
56943 return true;
56944 }
56945@@ -91,11 +91,11 @@ try_again:
56946 spin_unlock(&cookie->stores_lock);
56947
56948 if (xpage) {
56949- fscache_stat(&fscache_n_store_vmscan_cancelled);
56950- fscache_stat(&fscache_n_store_radix_deletes);
56951+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56952+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56953 ASSERTCMP(xpage, ==, page);
56954 } else {
56955- fscache_stat(&fscache_n_store_vmscan_gone);
56956+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56957 }
56958
56959 wake_up_bit(&cookie->flags, 0);
56960@@ -110,11 +110,11 @@ page_busy:
56961 * sleeping on memory allocation, so we may need to impose a timeout
56962 * too. */
56963 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56964- fscache_stat(&fscache_n_store_vmscan_busy);
56965+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56966 return false;
56967 }
56968
56969- fscache_stat(&fscache_n_store_vmscan_wait);
56970+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56971 __fscache_wait_on_page_write(cookie, page);
56972 gfp &= ~__GFP_WAIT;
56973 goto try_again;
56974@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56975 FSCACHE_COOKIE_STORING_TAG);
56976 if (!radix_tree_tag_get(&cookie->stores, page->index,
56977 FSCACHE_COOKIE_PENDING_TAG)) {
56978- fscache_stat(&fscache_n_store_radix_deletes);
56979+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56980 xpage = radix_tree_delete(&cookie->stores, page->index);
56981 }
56982 spin_unlock(&cookie->stores_lock);
56983@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56984
56985 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56986
56987- fscache_stat(&fscache_n_attr_changed_calls);
56988+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56989
56990 if (fscache_object_is_active(object) &&
56991 fscache_use_cookie(object)) {
56992@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56993
56994 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56995
56996- fscache_stat(&fscache_n_attr_changed);
56997+ fscache_stat_unchecked(&fscache_n_attr_changed);
56998
56999 op = kzalloc(sizeof(*op), GFP_KERNEL);
57000 if (!op) {
57001- fscache_stat(&fscache_n_attr_changed_nomem);
57002+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
57003 _leave(" = -ENOMEM");
57004 return -ENOMEM;
57005 }
57006@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57007 if (fscache_submit_exclusive_op(object, op) < 0)
57008 goto nobufs;
57009 spin_unlock(&cookie->lock);
57010- fscache_stat(&fscache_n_attr_changed_ok);
57011+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
57012 fscache_put_operation(op);
57013 _leave(" = 0");
57014 return 0;
57015@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57016 nobufs:
57017 spin_unlock(&cookie->lock);
57018 kfree(op);
57019- fscache_stat(&fscache_n_attr_changed_nobufs);
57020+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
57021 _leave(" = %d", -ENOBUFS);
57022 return -ENOBUFS;
57023 }
57024@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
57025 /* allocate a retrieval operation and attempt to submit it */
57026 op = kzalloc(sizeof(*op), GFP_NOIO);
57027 if (!op) {
57028- fscache_stat(&fscache_n_retrievals_nomem);
57029+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57030 return NULL;
57031 }
57032
57033@@ -289,13 +289,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
57034 return 0;
57035 }
57036
57037- fscache_stat(&fscache_n_retrievals_wait);
57038+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
57039
57040 jif = jiffies;
57041 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
57042 fscache_wait_bit_interruptible,
57043 TASK_INTERRUPTIBLE) != 0) {
57044- fscache_stat(&fscache_n_retrievals_intr);
57045+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57046 _leave(" = -ERESTARTSYS");
57047 return -ERESTARTSYS;
57048 }
57049@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
57050 */
57051 int fscache_wait_for_operation_activation(struct fscache_object *object,
57052 struct fscache_operation *op,
57053- atomic_t *stat_op_waits,
57054- atomic_t *stat_object_dead,
57055+ atomic_unchecked_t *stat_op_waits,
57056+ atomic_unchecked_t *stat_object_dead,
57057 void (*do_cancel)(struct fscache_operation *))
57058 {
57059 int ret;
57060@@ -335,7 +335,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57061
57062 _debug(">>> WT");
57063 if (stat_op_waits)
57064- fscache_stat(stat_op_waits);
57065+ fscache_stat_unchecked(stat_op_waits);
57066 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
57067 fscache_wait_bit_interruptible,
57068 TASK_INTERRUPTIBLE) != 0) {
57069@@ -353,7 +353,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57070 check_if_dead:
57071 if (op->state == FSCACHE_OP_ST_CANCELLED) {
57072 if (stat_object_dead)
57073- fscache_stat(stat_object_dead);
57074+ fscache_stat_unchecked(stat_object_dead);
57075 _leave(" = -ENOBUFS [cancelled]");
57076 return -ENOBUFS;
57077 }
57078@@ -361,7 +361,7 @@ check_if_dead:
57079 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
57080 fscache_cancel_op(op, do_cancel);
57081 if (stat_object_dead)
57082- fscache_stat(stat_object_dead);
57083+ fscache_stat_unchecked(stat_object_dead);
57084 return -ENOBUFS;
57085 }
57086 return 0;
57087@@ -388,7 +388,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57088
57089 _enter("%p,%p,,,", cookie, page);
57090
57091- fscache_stat(&fscache_n_retrievals);
57092+ fscache_stat_unchecked(&fscache_n_retrievals);
57093
57094 if (hlist_empty(&cookie->backing_objects))
57095 goto nobufs;
57096@@ -428,7 +428,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57097 goto nobufs_unlock_dec;
57098 spin_unlock(&cookie->lock);
57099
57100- fscache_stat(&fscache_n_retrieval_ops);
57101+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57102
57103 /* pin the netfs read context in case we need to do the actual netfs
57104 * read because we've encountered a cache read failure */
57105@@ -459,15 +459,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57106
57107 error:
57108 if (ret == -ENOMEM)
57109- fscache_stat(&fscache_n_retrievals_nomem);
57110+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57111 else if (ret == -ERESTARTSYS)
57112- fscache_stat(&fscache_n_retrievals_intr);
57113+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57114 else if (ret == -ENODATA)
57115- fscache_stat(&fscache_n_retrievals_nodata);
57116+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57117 else if (ret < 0)
57118- fscache_stat(&fscache_n_retrievals_nobufs);
57119+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57120 else
57121- fscache_stat(&fscache_n_retrievals_ok);
57122+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57123
57124 fscache_put_retrieval(op);
57125 _leave(" = %d", ret);
57126@@ -480,7 +480,7 @@ nobufs_unlock:
57127 atomic_dec(&cookie->n_active);
57128 kfree(op);
57129 nobufs:
57130- fscache_stat(&fscache_n_retrievals_nobufs);
57131+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57132 _leave(" = -ENOBUFS");
57133 return -ENOBUFS;
57134 }
57135@@ -518,7 +518,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57136
57137 _enter("%p,,%d,,,", cookie, *nr_pages);
57138
57139- fscache_stat(&fscache_n_retrievals);
57140+ fscache_stat_unchecked(&fscache_n_retrievals);
57141
57142 if (hlist_empty(&cookie->backing_objects))
57143 goto nobufs;
57144@@ -554,7 +554,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57145 goto nobufs_unlock_dec;
57146 spin_unlock(&cookie->lock);
57147
57148- fscache_stat(&fscache_n_retrieval_ops);
57149+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57150
57151 /* pin the netfs read context in case we need to do the actual netfs
57152 * read because we've encountered a cache read failure */
57153@@ -585,15 +585,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57154
57155 error:
57156 if (ret == -ENOMEM)
57157- fscache_stat(&fscache_n_retrievals_nomem);
57158+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57159 else if (ret == -ERESTARTSYS)
57160- fscache_stat(&fscache_n_retrievals_intr);
57161+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57162 else if (ret == -ENODATA)
57163- fscache_stat(&fscache_n_retrievals_nodata);
57164+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57165 else if (ret < 0)
57166- fscache_stat(&fscache_n_retrievals_nobufs);
57167+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57168 else
57169- fscache_stat(&fscache_n_retrievals_ok);
57170+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57171
57172 fscache_put_retrieval(op);
57173 _leave(" = %d", ret);
57174@@ -606,7 +606,7 @@ nobufs_unlock:
57175 atomic_dec(&cookie->n_active);
57176 kfree(op);
57177 nobufs:
57178- fscache_stat(&fscache_n_retrievals_nobufs);
57179+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57180 _leave(" = -ENOBUFS");
57181 return -ENOBUFS;
57182 }
57183@@ -630,7 +630,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57184
57185 _enter("%p,%p,,,", cookie, page);
57186
57187- fscache_stat(&fscache_n_allocs);
57188+ fscache_stat_unchecked(&fscache_n_allocs);
57189
57190 if (hlist_empty(&cookie->backing_objects))
57191 goto nobufs;
57192@@ -662,7 +662,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57193 goto nobufs_unlock;
57194 spin_unlock(&cookie->lock);
57195
57196- fscache_stat(&fscache_n_alloc_ops);
57197+ fscache_stat_unchecked(&fscache_n_alloc_ops);
57198
57199 ret = fscache_wait_for_operation_activation(
57200 object, &op->op,
57201@@ -679,11 +679,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57202
57203 error:
57204 if (ret == -ERESTARTSYS)
57205- fscache_stat(&fscache_n_allocs_intr);
57206+ fscache_stat_unchecked(&fscache_n_allocs_intr);
57207 else if (ret < 0)
57208- fscache_stat(&fscache_n_allocs_nobufs);
57209+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57210 else
57211- fscache_stat(&fscache_n_allocs_ok);
57212+ fscache_stat_unchecked(&fscache_n_allocs_ok);
57213
57214 fscache_put_retrieval(op);
57215 _leave(" = %d", ret);
57216@@ -694,7 +694,7 @@ nobufs_unlock:
57217 atomic_dec(&cookie->n_active);
57218 kfree(op);
57219 nobufs:
57220- fscache_stat(&fscache_n_allocs_nobufs);
57221+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57222 _leave(" = -ENOBUFS");
57223 return -ENOBUFS;
57224 }
57225@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57226
57227 spin_lock(&cookie->stores_lock);
57228
57229- fscache_stat(&fscache_n_store_calls);
57230+ fscache_stat_unchecked(&fscache_n_store_calls);
57231
57232 /* find a page to store */
57233 page = NULL;
57234@@ -781,7 +781,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57235 page = results[0];
57236 _debug("gang %d [%lx]", n, page->index);
57237 if (page->index > op->store_limit) {
57238- fscache_stat(&fscache_n_store_pages_over_limit);
57239+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
57240 goto superseded;
57241 }
57242
57243@@ -793,7 +793,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57244 spin_unlock(&cookie->stores_lock);
57245 spin_unlock(&object->lock);
57246
57247- fscache_stat(&fscache_n_store_pages);
57248+ fscache_stat_unchecked(&fscache_n_store_pages);
57249 fscache_stat(&fscache_n_cop_write_page);
57250 ret = object->cache->ops->write_page(op, page);
57251 fscache_stat_d(&fscache_n_cop_write_page);
57252@@ -896,7 +896,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57253 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57254 ASSERT(PageFsCache(page));
57255
57256- fscache_stat(&fscache_n_stores);
57257+ fscache_stat_unchecked(&fscache_n_stores);
57258
57259 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
57260 _leave(" = -ENOBUFS [invalidating]");
57261@@ -954,7 +954,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57262 spin_unlock(&cookie->stores_lock);
57263 spin_unlock(&object->lock);
57264
57265- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
57266+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57267 op->store_limit = object->store_limit;
57268
57269 atomic_inc(&cookie->n_active);
57270@@ -963,8 +963,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57271
57272 spin_unlock(&cookie->lock);
57273 radix_tree_preload_end();
57274- fscache_stat(&fscache_n_store_ops);
57275- fscache_stat(&fscache_n_stores_ok);
57276+ fscache_stat_unchecked(&fscache_n_store_ops);
57277+ fscache_stat_unchecked(&fscache_n_stores_ok);
57278
57279 /* the work queue now carries its own ref on the object */
57280 fscache_put_operation(&op->op);
57281@@ -972,14 +972,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57282 return 0;
57283
57284 already_queued:
57285- fscache_stat(&fscache_n_stores_again);
57286+ fscache_stat_unchecked(&fscache_n_stores_again);
57287 already_pending:
57288 spin_unlock(&cookie->stores_lock);
57289 spin_unlock(&object->lock);
57290 spin_unlock(&cookie->lock);
57291 radix_tree_preload_end();
57292 kfree(op);
57293- fscache_stat(&fscache_n_stores_ok);
57294+ fscache_stat_unchecked(&fscache_n_stores_ok);
57295 _leave(" = 0");
57296 return 0;
57297
57298@@ -999,14 +999,14 @@ nobufs:
57299 spin_unlock(&cookie->lock);
57300 radix_tree_preload_end();
57301 kfree(op);
57302- fscache_stat(&fscache_n_stores_nobufs);
57303+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
57304 _leave(" = -ENOBUFS");
57305 return -ENOBUFS;
57306
57307 nomem_free:
57308 kfree(op);
57309 nomem:
57310- fscache_stat(&fscache_n_stores_oom);
57311+ fscache_stat_unchecked(&fscache_n_stores_oom);
57312 _leave(" = -ENOMEM");
57313 return -ENOMEM;
57314 }
57315@@ -1024,7 +1024,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
57316 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57317 ASSERTCMP(page, !=, NULL);
57318
57319- fscache_stat(&fscache_n_uncaches);
57320+ fscache_stat_unchecked(&fscache_n_uncaches);
57321
57322 /* cache withdrawal may beat us to it */
57323 if (!PageFsCache(page))
57324@@ -1075,7 +1075,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
57325 struct fscache_cookie *cookie = op->op.object->cookie;
57326
57327 #ifdef CONFIG_FSCACHE_STATS
57328- atomic_inc(&fscache_n_marks);
57329+ atomic_inc_unchecked(&fscache_n_marks);
57330 #endif
57331
57332 _debug("- mark %p{%lx}", page, page->index);
57333diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
57334index 40d13c7..ddf52b9 100644
57335--- a/fs/fscache/stats.c
57336+++ b/fs/fscache/stats.c
57337@@ -18,99 +18,99 @@
57338 /*
57339 * operation counters
57340 */
57341-atomic_t fscache_n_op_pend;
57342-atomic_t fscache_n_op_run;
57343-atomic_t fscache_n_op_enqueue;
57344-atomic_t fscache_n_op_requeue;
57345-atomic_t fscache_n_op_deferred_release;
57346-atomic_t fscache_n_op_release;
57347-atomic_t fscache_n_op_gc;
57348-atomic_t fscache_n_op_cancelled;
57349-atomic_t fscache_n_op_rejected;
57350+atomic_unchecked_t fscache_n_op_pend;
57351+atomic_unchecked_t fscache_n_op_run;
57352+atomic_unchecked_t fscache_n_op_enqueue;
57353+atomic_unchecked_t fscache_n_op_requeue;
57354+atomic_unchecked_t fscache_n_op_deferred_release;
57355+atomic_unchecked_t fscache_n_op_release;
57356+atomic_unchecked_t fscache_n_op_gc;
57357+atomic_unchecked_t fscache_n_op_cancelled;
57358+atomic_unchecked_t fscache_n_op_rejected;
57359
57360-atomic_t fscache_n_attr_changed;
57361-atomic_t fscache_n_attr_changed_ok;
57362-atomic_t fscache_n_attr_changed_nobufs;
57363-atomic_t fscache_n_attr_changed_nomem;
57364-atomic_t fscache_n_attr_changed_calls;
57365+atomic_unchecked_t fscache_n_attr_changed;
57366+atomic_unchecked_t fscache_n_attr_changed_ok;
57367+atomic_unchecked_t fscache_n_attr_changed_nobufs;
57368+atomic_unchecked_t fscache_n_attr_changed_nomem;
57369+atomic_unchecked_t fscache_n_attr_changed_calls;
57370
57371-atomic_t fscache_n_allocs;
57372-atomic_t fscache_n_allocs_ok;
57373-atomic_t fscache_n_allocs_wait;
57374-atomic_t fscache_n_allocs_nobufs;
57375-atomic_t fscache_n_allocs_intr;
57376-atomic_t fscache_n_allocs_object_dead;
57377-atomic_t fscache_n_alloc_ops;
57378-atomic_t fscache_n_alloc_op_waits;
57379+atomic_unchecked_t fscache_n_allocs;
57380+atomic_unchecked_t fscache_n_allocs_ok;
57381+atomic_unchecked_t fscache_n_allocs_wait;
57382+atomic_unchecked_t fscache_n_allocs_nobufs;
57383+atomic_unchecked_t fscache_n_allocs_intr;
57384+atomic_unchecked_t fscache_n_allocs_object_dead;
57385+atomic_unchecked_t fscache_n_alloc_ops;
57386+atomic_unchecked_t fscache_n_alloc_op_waits;
57387
57388-atomic_t fscache_n_retrievals;
57389-atomic_t fscache_n_retrievals_ok;
57390-atomic_t fscache_n_retrievals_wait;
57391-atomic_t fscache_n_retrievals_nodata;
57392-atomic_t fscache_n_retrievals_nobufs;
57393-atomic_t fscache_n_retrievals_intr;
57394-atomic_t fscache_n_retrievals_nomem;
57395-atomic_t fscache_n_retrievals_object_dead;
57396-atomic_t fscache_n_retrieval_ops;
57397-atomic_t fscache_n_retrieval_op_waits;
57398+atomic_unchecked_t fscache_n_retrievals;
57399+atomic_unchecked_t fscache_n_retrievals_ok;
57400+atomic_unchecked_t fscache_n_retrievals_wait;
57401+atomic_unchecked_t fscache_n_retrievals_nodata;
57402+atomic_unchecked_t fscache_n_retrievals_nobufs;
57403+atomic_unchecked_t fscache_n_retrievals_intr;
57404+atomic_unchecked_t fscache_n_retrievals_nomem;
57405+atomic_unchecked_t fscache_n_retrievals_object_dead;
57406+atomic_unchecked_t fscache_n_retrieval_ops;
57407+atomic_unchecked_t fscache_n_retrieval_op_waits;
57408
57409-atomic_t fscache_n_stores;
57410-atomic_t fscache_n_stores_ok;
57411-atomic_t fscache_n_stores_again;
57412-atomic_t fscache_n_stores_nobufs;
57413-atomic_t fscache_n_stores_oom;
57414-atomic_t fscache_n_store_ops;
57415-atomic_t fscache_n_store_calls;
57416-atomic_t fscache_n_store_pages;
57417-atomic_t fscache_n_store_radix_deletes;
57418-atomic_t fscache_n_store_pages_over_limit;
57419+atomic_unchecked_t fscache_n_stores;
57420+atomic_unchecked_t fscache_n_stores_ok;
57421+atomic_unchecked_t fscache_n_stores_again;
57422+atomic_unchecked_t fscache_n_stores_nobufs;
57423+atomic_unchecked_t fscache_n_stores_oom;
57424+atomic_unchecked_t fscache_n_store_ops;
57425+atomic_unchecked_t fscache_n_store_calls;
57426+atomic_unchecked_t fscache_n_store_pages;
57427+atomic_unchecked_t fscache_n_store_radix_deletes;
57428+atomic_unchecked_t fscache_n_store_pages_over_limit;
57429
57430-atomic_t fscache_n_store_vmscan_not_storing;
57431-atomic_t fscache_n_store_vmscan_gone;
57432-atomic_t fscache_n_store_vmscan_busy;
57433-atomic_t fscache_n_store_vmscan_cancelled;
57434-atomic_t fscache_n_store_vmscan_wait;
57435+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57436+atomic_unchecked_t fscache_n_store_vmscan_gone;
57437+atomic_unchecked_t fscache_n_store_vmscan_busy;
57438+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57439+atomic_unchecked_t fscache_n_store_vmscan_wait;
57440
57441-atomic_t fscache_n_marks;
57442-atomic_t fscache_n_uncaches;
57443+atomic_unchecked_t fscache_n_marks;
57444+atomic_unchecked_t fscache_n_uncaches;
57445
57446-atomic_t fscache_n_acquires;
57447-atomic_t fscache_n_acquires_null;
57448-atomic_t fscache_n_acquires_no_cache;
57449-atomic_t fscache_n_acquires_ok;
57450-atomic_t fscache_n_acquires_nobufs;
57451-atomic_t fscache_n_acquires_oom;
57452+atomic_unchecked_t fscache_n_acquires;
57453+atomic_unchecked_t fscache_n_acquires_null;
57454+atomic_unchecked_t fscache_n_acquires_no_cache;
57455+atomic_unchecked_t fscache_n_acquires_ok;
57456+atomic_unchecked_t fscache_n_acquires_nobufs;
57457+atomic_unchecked_t fscache_n_acquires_oom;
57458
57459-atomic_t fscache_n_invalidates;
57460-atomic_t fscache_n_invalidates_run;
57461+atomic_unchecked_t fscache_n_invalidates;
57462+atomic_unchecked_t fscache_n_invalidates_run;
57463
57464-atomic_t fscache_n_updates;
57465-atomic_t fscache_n_updates_null;
57466-atomic_t fscache_n_updates_run;
57467+atomic_unchecked_t fscache_n_updates;
57468+atomic_unchecked_t fscache_n_updates_null;
57469+atomic_unchecked_t fscache_n_updates_run;
57470
57471-atomic_t fscache_n_relinquishes;
57472-atomic_t fscache_n_relinquishes_null;
57473-atomic_t fscache_n_relinquishes_waitcrt;
57474-atomic_t fscache_n_relinquishes_retire;
57475+atomic_unchecked_t fscache_n_relinquishes;
57476+atomic_unchecked_t fscache_n_relinquishes_null;
57477+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57478+atomic_unchecked_t fscache_n_relinquishes_retire;
57479
57480-atomic_t fscache_n_cookie_index;
57481-atomic_t fscache_n_cookie_data;
57482-atomic_t fscache_n_cookie_special;
57483+atomic_unchecked_t fscache_n_cookie_index;
57484+atomic_unchecked_t fscache_n_cookie_data;
57485+atomic_unchecked_t fscache_n_cookie_special;
57486
57487-atomic_t fscache_n_object_alloc;
57488-atomic_t fscache_n_object_no_alloc;
57489-atomic_t fscache_n_object_lookups;
57490-atomic_t fscache_n_object_lookups_negative;
57491-atomic_t fscache_n_object_lookups_positive;
57492-atomic_t fscache_n_object_lookups_timed_out;
57493-atomic_t fscache_n_object_created;
57494-atomic_t fscache_n_object_avail;
57495-atomic_t fscache_n_object_dead;
57496+atomic_unchecked_t fscache_n_object_alloc;
57497+atomic_unchecked_t fscache_n_object_no_alloc;
57498+atomic_unchecked_t fscache_n_object_lookups;
57499+atomic_unchecked_t fscache_n_object_lookups_negative;
57500+atomic_unchecked_t fscache_n_object_lookups_positive;
57501+atomic_unchecked_t fscache_n_object_lookups_timed_out;
57502+atomic_unchecked_t fscache_n_object_created;
57503+atomic_unchecked_t fscache_n_object_avail;
57504+atomic_unchecked_t fscache_n_object_dead;
57505
57506-atomic_t fscache_n_checkaux_none;
57507-atomic_t fscache_n_checkaux_okay;
57508-atomic_t fscache_n_checkaux_update;
57509-atomic_t fscache_n_checkaux_obsolete;
57510+atomic_unchecked_t fscache_n_checkaux_none;
57511+atomic_unchecked_t fscache_n_checkaux_okay;
57512+atomic_unchecked_t fscache_n_checkaux_update;
57513+atomic_unchecked_t fscache_n_checkaux_obsolete;
57514
57515 atomic_t fscache_n_cop_alloc_object;
57516 atomic_t fscache_n_cop_lookup_object;
57517@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57518 seq_puts(m, "FS-Cache statistics\n");
57519
57520 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57521- atomic_read(&fscache_n_cookie_index),
57522- atomic_read(&fscache_n_cookie_data),
57523- atomic_read(&fscache_n_cookie_special));
57524+ atomic_read_unchecked(&fscache_n_cookie_index),
57525+ atomic_read_unchecked(&fscache_n_cookie_data),
57526+ atomic_read_unchecked(&fscache_n_cookie_special));
57527
57528 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57529- atomic_read(&fscache_n_object_alloc),
57530- atomic_read(&fscache_n_object_no_alloc),
57531- atomic_read(&fscache_n_object_avail),
57532- atomic_read(&fscache_n_object_dead));
57533+ atomic_read_unchecked(&fscache_n_object_alloc),
57534+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57535+ atomic_read_unchecked(&fscache_n_object_avail),
57536+ atomic_read_unchecked(&fscache_n_object_dead));
57537 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57538- atomic_read(&fscache_n_checkaux_none),
57539- atomic_read(&fscache_n_checkaux_okay),
57540- atomic_read(&fscache_n_checkaux_update),
57541- atomic_read(&fscache_n_checkaux_obsolete));
57542+ atomic_read_unchecked(&fscache_n_checkaux_none),
57543+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57544+ atomic_read_unchecked(&fscache_n_checkaux_update),
57545+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57546
57547 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57548- atomic_read(&fscache_n_marks),
57549- atomic_read(&fscache_n_uncaches));
57550+ atomic_read_unchecked(&fscache_n_marks),
57551+ atomic_read_unchecked(&fscache_n_uncaches));
57552
57553 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57554 " oom=%u\n",
57555- atomic_read(&fscache_n_acquires),
57556- atomic_read(&fscache_n_acquires_null),
57557- atomic_read(&fscache_n_acquires_no_cache),
57558- atomic_read(&fscache_n_acquires_ok),
57559- atomic_read(&fscache_n_acquires_nobufs),
57560- atomic_read(&fscache_n_acquires_oom));
57561+ atomic_read_unchecked(&fscache_n_acquires),
57562+ atomic_read_unchecked(&fscache_n_acquires_null),
57563+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57564+ atomic_read_unchecked(&fscache_n_acquires_ok),
57565+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57566+ atomic_read_unchecked(&fscache_n_acquires_oom));
57567
57568 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57569- atomic_read(&fscache_n_object_lookups),
57570- atomic_read(&fscache_n_object_lookups_negative),
57571- atomic_read(&fscache_n_object_lookups_positive),
57572- atomic_read(&fscache_n_object_created),
57573- atomic_read(&fscache_n_object_lookups_timed_out));
57574+ atomic_read_unchecked(&fscache_n_object_lookups),
57575+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57576+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57577+ atomic_read_unchecked(&fscache_n_object_created),
57578+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57579
57580 seq_printf(m, "Invals : n=%u run=%u\n",
57581- atomic_read(&fscache_n_invalidates),
57582- atomic_read(&fscache_n_invalidates_run));
57583+ atomic_read_unchecked(&fscache_n_invalidates),
57584+ atomic_read_unchecked(&fscache_n_invalidates_run));
57585
57586 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57587- atomic_read(&fscache_n_updates),
57588- atomic_read(&fscache_n_updates_null),
57589- atomic_read(&fscache_n_updates_run));
57590+ atomic_read_unchecked(&fscache_n_updates),
57591+ atomic_read_unchecked(&fscache_n_updates_null),
57592+ atomic_read_unchecked(&fscache_n_updates_run));
57593
57594 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57595- atomic_read(&fscache_n_relinquishes),
57596- atomic_read(&fscache_n_relinquishes_null),
57597- atomic_read(&fscache_n_relinquishes_waitcrt),
57598- atomic_read(&fscache_n_relinquishes_retire));
57599+ atomic_read_unchecked(&fscache_n_relinquishes),
57600+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57601+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57602+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57603
57604 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57605- atomic_read(&fscache_n_attr_changed),
57606- atomic_read(&fscache_n_attr_changed_ok),
57607- atomic_read(&fscache_n_attr_changed_nobufs),
57608- atomic_read(&fscache_n_attr_changed_nomem),
57609- atomic_read(&fscache_n_attr_changed_calls));
57610+ atomic_read_unchecked(&fscache_n_attr_changed),
57611+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57612+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57613+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57614+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57615
57616 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57617- atomic_read(&fscache_n_allocs),
57618- atomic_read(&fscache_n_allocs_ok),
57619- atomic_read(&fscache_n_allocs_wait),
57620- atomic_read(&fscache_n_allocs_nobufs),
57621- atomic_read(&fscache_n_allocs_intr));
57622+ atomic_read_unchecked(&fscache_n_allocs),
57623+ atomic_read_unchecked(&fscache_n_allocs_ok),
57624+ atomic_read_unchecked(&fscache_n_allocs_wait),
57625+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57626+ atomic_read_unchecked(&fscache_n_allocs_intr));
57627 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57628- atomic_read(&fscache_n_alloc_ops),
57629- atomic_read(&fscache_n_alloc_op_waits),
57630- atomic_read(&fscache_n_allocs_object_dead));
57631+ atomic_read_unchecked(&fscache_n_alloc_ops),
57632+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57633+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57634
57635 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57636 " int=%u oom=%u\n",
57637- atomic_read(&fscache_n_retrievals),
57638- atomic_read(&fscache_n_retrievals_ok),
57639- atomic_read(&fscache_n_retrievals_wait),
57640- atomic_read(&fscache_n_retrievals_nodata),
57641- atomic_read(&fscache_n_retrievals_nobufs),
57642- atomic_read(&fscache_n_retrievals_intr),
57643- atomic_read(&fscache_n_retrievals_nomem));
57644+ atomic_read_unchecked(&fscache_n_retrievals),
57645+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57646+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57647+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57648+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57649+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57650+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57651 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57652- atomic_read(&fscache_n_retrieval_ops),
57653- atomic_read(&fscache_n_retrieval_op_waits),
57654- atomic_read(&fscache_n_retrievals_object_dead));
57655+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57656+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57657+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57658
57659 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57660- atomic_read(&fscache_n_stores),
57661- atomic_read(&fscache_n_stores_ok),
57662- atomic_read(&fscache_n_stores_again),
57663- atomic_read(&fscache_n_stores_nobufs),
57664- atomic_read(&fscache_n_stores_oom));
57665+ atomic_read_unchecked(&fscache_n_stores),
57666+ atomic_read_unchecked(&fscache_n_stores_ok),
57667+ atomic_read_unchecked(&fscache_n_stores_again),
57668+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57669+ atomic_read_unchecked(&fscache_n_stores_oom));
57670 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57671- atomic_read(&fscache_n_store_ops),
57672- atomic_read(&fscache_n_store_calls),
57673- atomic_read(&fscache_n_store_pages),
57674- atomic_read(&fscache_n_store_radix_deletes),
57675- atomic_read(&fscache_n_store_pages_over_limit));
57676+ atomic_read_unchecked(&fscache_n_store_ops),
57677+ atomic_read_unchecked(&fscache_n_store_calls),
57678+ atomic_read_unchecked(&fscache_n_store_pages),
57679+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57680+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57681
57682 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57683- atomic_read(&fscache_n_store_vmscan_not_storing),
57684- atomic_read(&fscache_n_store_vmscan_gone),
57685- atomic_read(&fscache_n_store_vmscan_busy),
57686- atomic_read(&fscache_n_store_vmscan_cancelled),
57687- atomic_read(&fscache_n_store_vmscan_wait));
57688+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57689+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57690+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57691+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57692+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57693
57694 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57695- atomic_read(&fscache_n_op_pend),
57696- atomic_read(&fscache_n_op_run),
57697- atomic_read(&fscache_n_op_enqueue),
57698- atomic_read(&fscache_n_op_cancelled),
57699- atomic_read(&fscache_n_op_rejected));
57700+ atomic_read_unchecked(&fscache_n_op_pend),
57701+ atomic_read_unchecked(&fscache_n_op_run),
57702+ atomic_read_unchecked(&fscache_n_op_enqueue),
57703+ atomic_read_unchecked(&fscache_n_op_cancelled),
57704+ atomic_read_unchecked(&fscache_n_op_rejected));
57705 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57706- atomic_read(&fscache_n_op_deferred_release),
57707- atomic_read(&fscache_n_op_release),
57708- atomic_read(&fscache_n_op_gc));
57709+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57710+ atomic_read_unchecked(&fscache_n_op_release),
57711+ atomic_read_unchecked(&fscache_n_op_gc));
57712
57713 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57714 atomic_read(&fscache_n_cop_alloc_object),
57715diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57716index adbfd66..4b25822 100644
57717--- a/fs/fuse/cuse.c
57718+++ b/fs/fuse/cuse.c
57719@@ -603,10 +603,12 @@ static int __init cuse_init(void)
57720 INIT_LIST_HEAD(&cuse_conntbl[i]);
57721
57722 /* inherit and extend fuse_dev_operations */
57723- cuse_channel_fops = fuse_dev_operations;
57724- cuse_channel_fops.owner = THIS_MODULE;
57725- cuse_channel_fops.open = cuse_channel_open;
57726- cuse_channel_fops.release = cuse_channel_release;
57727+ pax_open_kernel();
57728+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57729+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57730+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57731+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57732+ pax_close_kernel();
57733
57734 cuse_class = class_create(THIS_MODULE, "cuse");
57735 if (IS_ERR(cuse_class))
57736diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57737index ef74ad5..c9ac759e 100644
57738--- a/fs/fuse/dev.c
57739+++ b/fs/fuse/dev.c
57740@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57741 ret = 0;
57742 pipe_lock(pipe);
57743
57744- if (!pipe->readers) {
57745+ if (!atomic_read(&pipe->readers)) {
57746 send_sig(SIGPIPE, current, 0);
57747 if (!ret)
57748 ret = -EPIPE;
57749@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57750 page_nr++;
57751 ret += buf->len;
57752
57753- if (pipe->files)
57754+ if (atomic_read(&pipe->files))
57755 do_wakeup = 1;
57756 }
57757
57758diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57759index b7989f2..1f72ec4 100644
57760--- a/fs/fuse/dir.c
57761+++ b/fs/fuse/dir.c
57762@@ -1438,7 +1438,7 @@ static char *read_link(struct dentry *dentry)
57763 return link;
57764 }
57765
57766-static void free_link(char *link)
57767+static void free_link(const char *link)
57768 {
57769 if (!IS_ERR(link))
57770 free_page((unsigned long) link);
57771diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57772index 968d4c56..54a398d 100644
57773--- a/fs/gfs2/inode.c
57774+++ b/fs/gfs2/inode.c
57775@@ -1512,7 +1512,7 @@ out:
57776
57777 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57778 {
57779- char *s = nd_get_link(nd);
57780+ const char *s = nd_get_link(nd);
57781 if (!IS_ERR(s))
57782 kfree(s);
57783 }
57784diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
57785index 2543728..14d7bd4 100644
57786--- a/fs/hostfs/hostfs_kern.c
57787+++ b/fs/hostfs/hostfs_kern.c
57788@@ -904,7 +904,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
57789
57790 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
57791 {
57792- char *s = nd_get_link(nd);
57793+ const char *s = nd_get_link(nd);
57794 if (!IS_ERR(s))
57795 __putname(s);
57796 }
57797diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57798index d19b30a..ef89c36 100644
57799--- a/fs/hugetlbfs/inode.c
57800+++ b/fs/hugetlbfs/inode.c
57801@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57802 struct mm_struct *mm = current->mm;
57803 struct vm_area_struct *vma;
57804 struct hstate *h = hstate_file(file);
57805+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57806 struct vm_unmapped_area_info info;
57807
57808 if (len & ~huge_page_mask(h))
57809@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57810 return addr;
57811 }
57812
57813+#ifdef CONFIG_PAX_RANDMMAP
57814+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57815+#endif
57816+
57817 if (addr) {
57818 addr = ALIGN(addr, huge_page_size(h));
57819 vma = find_vma(mm, addr);
57820- if (TASK_SIZE - len >= addr &&
57821- (!vma || addr + len <= vma->vm_start))
57822+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57823 return addr;
57824 }
57825
57826 info.flags = 0;
57827 info.length = len;
57828 info.low_limit = TASK_UNMAPPED_BASE;
57829+
57830+#ifdef CONFIG_PAX_RANDMMAP
57831+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57832+ info.low_limit += mm->delta_mmap;
57833+#endif
57834+
57835 info.high_limit = TASK_SIZE;
57836 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57837 info.align_offset = 0;
57838@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57839 };
57840 MODULE_ALIAS_FS("hugetlbfs");
57841
57842-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57843+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57844
57845 static int can_do_hugetlb_shm(void)
57846 {
57847diff --git a/fs/inode.c b/fs/inode.c
57848index b33ba8e..3c79a47 100644
57849--- a/fs/inode.c
57850+++ b/fs/inode.c
57851@@ -849,8 +849,8 @@ unsigned int get_next_ino(void)
57852
57853 #ifdef CONFIG_SMP
57854 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57855- static atomic_t shared_last_ino;
57856- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57857+ static atomic_unchecked_t shared_last_ino;
57858+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57859
57860 res = next - LAST_INO_BATCH;
57861 }
57862diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57863index 4a6cf28..d3a29d3 100644
57864--- a/fs/jffs2/erase.c
57865+++ b/fs/jffs2/erase.c
57866@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57867 struct jffs2_unknown_node marker = {
57868 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57869 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57870- .totlen = cpu_to_je32(c->cleanmarker_size)
57871+ .totlen = cpu_to_je32(c->cleanmarker_size),
57872+ .hdr_crc = cpu_to_je32(0)
57873 };
57874
57875 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57876diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57877index a6597d6..41b30ec 100644
57878--- a/fs/jffs2/wbuf.c
57879+++ b/fs/jffs2/wbuf.c
57880@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57881 {
57882 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57883 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57884- .totlen = constant_cpu_to_je32(8)
57885+ .totlen = constant_cpu_to_je32(8),
57886+ .hdr_crc = constant_cpu_to_je32(0)
57887 };
57888
57889 /*
57890diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57891index 6669aa2..36b033d 100644
57892--- a/fs/jfs/super.c
57893+++ b/fs/jfs/super.c
57894@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57895
57896 jfs_inode_cachep =
57897 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57898- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57899+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57900 init_once);
57901 if (jfs_inode_cachep == NULL)
57902 return -ENOMEM;
57903diff --git a/fs/libfs.c b/fs/libfs.c
57904index 3a3a9b5..3a9b074 100644
57905--- a/fs/libfs.c
57906+++ b/fs/libfs.c
57907@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57908
57909 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57910 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57911+ char d_name[sizeof(next->d_iname)];
57912+ const unsigned char *name;
57913+
57914 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57915 if (!simple_positive(next)) {
57916 spin_unlock(&next->d_lock);
57917@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57918
57919 spin_unlock(&next->d_lock);
57920 spin_unlock(&dentry->d_lock);
57921- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57922+ name = next->d_name.name;
57923+ if (name == next->d_iname) {
57924+ memcpy(d_name, name, next->d_name.len);
57925+ name = d_name;
57926+ }
57927+ if (!dir_emit(ctx, name, next->d_name.len,
57928 next->d_inode->i_ino, dt_type(next->d_inode)))
57929 return 0;
57930 spin_lock(&dentry->d_lock);
57931diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57932index acd3947..1f896e2 100644
57933--- a/fs/lockd/clntproc.c
57934+++ b/fs/lockd/clntproc.c
57935@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57936 /*
57937 * Cookie counter for NLM requests
57938 */
57939-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57940+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57941
57942 void nlmclnt_next_cookie(struct nlm_cookie *c)
57943 {
57944- u32 cookie = atomic_inc_return(&nlm_cookie);
57945+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57946
57947 memcpy(c->data, &cookie, 4);
57948 c->len=4;
57949diff --git a/fs/locks.c b/fs/locks.c
57950index b27a300..4156d0b 100644
57951--- a/fs/locks.c
57952+++ b/fs/locks.c
57953@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57954 return;
57955
57956 if (filp->f_op && filp->f_op->flock) {
57957- struct file_lock fl = {
57958+ struct file_lock flock = {
57959 .fl_pid = current->tgid,
57960 .fl_file = filp,
57961 .fl_flags = FL_FLOCK,
57962 .fl_type = F_UNLCK,
57963 .fl_end = OFFSET_MAX,
57964 };
57965- filp->f_op->flock(filp, F_SETLKW, &fl);
57966- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57967- fl.fl_ops->fl_release_private(&fl);
57968+ filp->f_op->flock(filp, F_SETLKW, &flock);
57969+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57970+ flock.fl_ops->fl_release_private(&flock);
57971 }
57972
57973 spin_lock(&inode->i_lock);
57974diff --git a/fs/namei.c b/fs/namei.c
57975index caa2805..c9d3edc 100644
57976--- a/fs/namei.c
57977+++ b/fs/namei.c
57978@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57979 if (ret != -EACCES)
57980 return ret;
57981
57982+#ifdef CONFIG_GRKERNSEC
57983+ /* we'll block if we have to log due to a denied capability use */
57984+ if (mask & MAY_NOT_BLOCK)
57985+ return -ECHILD;
57986+#endif
57987+
57988 if (S_ISDIR(inode->i_mode)) {
57989 /* DACs are overridable for directories */
57990- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57991- return 0;
57992 if (!(mask & MAY_WRITE))
57993- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57994+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57995+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57996 return 0;
57997+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57998+ return 0;
57999 return -EACCES;
58000 }
58001 /*
58002+ * Searching includes executable on directories, else just read.
58003+ */
58004+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58005+ if (mask == MAY_READ)
58006+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58007+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58008+ return 0;
58009+
58010+ /*
58011 * Read/write DACs are always overridable.
58012 * Executable DACs are overridable when there is
58013 * at least one exec bit set.
58014@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
58015 if (inode_capable(inode, CAP_DAC_OVERRIDE))
58016 return 0;
58017
58018- /*
58019- * Searching includes executable on directories, else just read.
58020- */
58021- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58022- if (mask == MAY_READ)
58023- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58024- return 0;
58025-
58026 return -EACCES;
58027 }
58028
58029@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58030 {
58031 struct dentry *dentry = link->dentry;
58032 int error;
58033- char *s;
58034+ const char *s;
58035
58036 BUG_ON(nd->flags & LOOKUP_RCU);
58037
58038@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58039 if (error)
58040 goto out_put_nd_path;
58041
58042+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
58043+ dentry->d_inode, dentry, nd->path.mnt)) {
58044+ error = -EACCES;
58045+ goto out_put_nd_path;
58046+ }
58047+
58048 nd->last_type = LAST_BIND;
58049 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
58050 error = PTR_ERR(*p);
58051@@ -1602,6 +1616,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
58052 if (res)
58053 break;
58054 res = walk_component(nd, path, LOOKUP_FOLLOW);
58055+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
58056+ res = -EACCES;
58057 put_link(nd, &link, cookie);
58058 } while (res > 0);
58059
58060@@ -1700,7 +1716,7 @@ EXPORT_SYMBOL(full_name_hash);
58061 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
58062 {
58063 unsigned long a, b, adata, bdata, mask, hash, len;
58064- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58065+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58066
58067 hash = a = 0;
58068 len = -sizeof(unsigned long);
58069@@ -1981,6 +1997,8 @@ static int path_lookupat(int dfd, const char *name,
58070 if (err)
58071 break;
58072 err = lookup_last(nd, &path);
58073+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
58074+ err = -EACCES;
58075 put_link(nd, &link, cookie);
58076 }
58077 }
58078@@ -1988,6 +2006,13 @@ static int path_lookupat(int dfd, const char *name,
58079 if (!err)
58080 err = complete_walk(nd);
58081
58082+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
58083+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58084+ path_put(&nd->path);
58085+ err = -ENOENT;
58086+ }
58087+ }
58088+
58089 if (!err && nd->flags & LOOKUP_DIRECTORY) {
58090 if (!can_lookup(nd->inode)) {
58091 path_put(&nd->path);
58092@@ -2015,8 +2040,15 @@ static int filename_lookup(int dfd, struct filename *name,
58093 retval = path_lookupat(dfd, name->name,
58094 flags | LOOKUP_REVAL, nd);
58095
58096- if (likely(!retval))
58097+ if (likely(!retval)) {
58098 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
58099+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
58100+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
58101+ path_put(&nd->path);
58102+ return -ENOENT;
58103+ }
58104+ }
58105+ }
58106 return retval;
58107 }
58108
58109@@ -2586,6 +2618,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
58110 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
58111 return -EPERM;
58112
58113+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
58114+ return -EPERM;
58115+ if (gr_handle_rawio(inode))
58116+ return -EPERM;
58117+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
58118+ return -EACCES;
58119+
58120 return 0;
58121 }
58122
58123@@ -2817,7 +2856,7 @@ looked_up:
58124 * cleared otherwise prior to returning.
58125 */
58126 static int lookup_open(struct nameidata *nd, struct path *path,
58127- struct file *file,
58128+ struct path *link, struct file *file,
58129 const struct open_flags *op,
58130 bool got_write, int *opened)
58131 {
58132@@ -2852,6 +2891,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58133 /* Negative dentry, just create the file */
58134 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
58135 umode_t mode = op->mode;
58136+
58137+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
58138+ error = -EACCES;
58139+ goto out_dput;
58140+ }
58141+
58142+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
58143+ error = -EACCES;
58144+ goto out_dput;
58145+ }
58146+
58147 if (!IS_POSIXACL(dir->d_inode))
58148 mode &= ~current_umask();
58149 /*
58150@@ -2873,6 +2923,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58151 nd->flags & LOOKUP_EXCL);
58152 if (error)
58153 goto out_dput;
58154+ else
58155+ gr_handle_create(dentry, nd->path.mnt);
58156 }
58157 out_no_open:
58158 path->dentry = dentry;
58159@@ -2887,7 +2939,7 @@ out_dput:
58160 /*
58161 * Handle the last step of open()
58162 */
58163-static int do_last(struct nameidata *nd, struct path *path,
58164+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
58165 struct file *file, const struct open_flags *op,
58166 int *opened, struct filename *name)
58167 {
58168@@ -2937,6 +2989,15 @@ static int do_last(struct nameidata *nd, struct path *path,
58169 if (error)
58170 return error;
58171
58172+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
58173+ error = -ENOENT;
58174+ goto out;
58175+ }
58176+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58177+ error = -EACCES;
58178+ goto out;
58179+ }
58180+
58181 audit_inode(name, dir, LOOKUP_PARENT);
58182 error = -EISDIR;
58183 /* trailing slashes? */
58184@@ -2956,7 +3017,7 @@ retry_lookup:
58185 */
58186 }
58187 mutex_lock(&dir->d_inode->i_mutex);
58188- error = lookup_open(nd, path, file, op, got_write, opened);
58189+ error = lookup_open(nd, path, link, file, op, got_write, opened);
58190 mutex_unlock(&dir->d_inode->i_mutex);
58191
58192 if (error <= 0) {
58193@@ -2980,11 +3041,28 @@ retry_lookup:
58194 goto finish_open_created;
58195 }
58196
58197+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
58198+ error = -ENOENT;
58199+ goto exit_dput;
58200+ }
58201+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
58202+ error = -EACCES;
58203+ goto exit_dput;
58204+ }
58205+
58206 /*
58207 * create/update audit record if it already exists.
58208 */
58209- if (path->dentry->d_inode)
58210+ if (path->dentry->d_inode) {
58211+ /* only check if O_CREAT is specified, all other checks need to go
58212+ into may_open */
58213+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
58214+ error = -EACCES;
58215+ goto exit_dput;
58216+ }
58217+
58218 audit_inode(name, path->dentry, 0);
58219+ }
58220
58221 /*
58222 * If atomic_open() acquired write access it is dropped now due to
58223@@ -3025,6 +3103,11 @@ finish_lookup:
58224 }
58225 }
58226 BUG_ON(inode != path->dentry->d_inode);
58227+ /* if we're resolving a symlink to another symlink */
58228+ if (link && gr_handle_symlink_owner(link, inode)) {
58229+ error = -EACCES;
58230+ goto out;
58231+ }
58232 return 1;
58233 }
58234
58235@@ -3034,7 +3117,6 @@ finish_lookup:
58236 save_parent.dentry = nd->path.dentry;
58237 save_parent.mnt = mntget(path->mnt);
58238 nd->path.dentry = path->dentry;
58239-
58240 }
58241 nd->inode = inode;
58242 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
58243@@ -3044,7 +3126,18 @@ finish_open:
58244 path_put(&save_parent);
58245 return error;
58246 }
58247+
58248+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58249+ error = -ENOENT;
58250+ goto out;
58251+ }
58252+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58253+ error = -EACCES;
58254+ goto out;
58255+ }
58256+
58257 audit_inode(name, nd->path.dentry, 0);
58258+
58259 error = -EISDIR;
58260 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
58261 goto out;
58262@@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58263 if (unlikely(error))
58264 goto out;
58265
58266- error = do_last(nd, &path, file, op, &opened, pathname);
58267+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
58268 while (unlikely(error > 0)) { /* trailing symlink */
58269 struct path link = path;
58270 void *cookie;
58271@@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58272 error = follow_link(&link, nd, &cookie);
58273 if (unlikely(error))
58274 break;
58275- error = do_last(nd, &path, file, op, &opened, pathname);
58276+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
58277 put_link(nd, &link, cookie);
58278 }
58279 out:
58280@@ -3325,8 +3418,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
58281 goto unlock;
58282
58283 error = -EEXIST;
58284- if (dentry->d_inode)
58285+ if (dentry->d_inode) {
58286+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
58287+ error = -ENOENT;
58288+ }
58289 goto fail;
58290+ }
58291 /*
58292 * Special case - lookup gave negative, but... we had foo/bar/
58293 * From the vfs_mknod() POV we just have a negative dentry -
58294@@ -3378,6 +3475,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
58295 }
58296 EXPORT_SYMBOL(user_path_create);
58297
58298+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
58299+{
58300+ struct filename *tmp = getname(pathname);
58301+ struct dentry *res;
58302+ if (IS_ERR(tmp))
58303+ return ERR_CAST(tmp);
58304+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
58305+ if (IS_ERR(res))
58306+ putname(tmp);
58307+ else
58308+ *to = tmp;
58309+ return res;
58310+}
58311+
58312 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
58313 {
58314 int error = may_create(dir, dentry);
58315@@ -3440,6 +3551,17 @@ retry:
58316
58317 if (!IS_POSIXACL(path.dentry->d_inode))
58318 mode &= ~current_umask();
58319+
58320+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
58321+ error = -EPERM;
58322+ goto out;
58323+ }
58324+
58325+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
58326+ error = -EACCES;
58327+ goto out;
58328+ }
58329+
58330 error = security_path_mknod(&path, dentry, mode, dev);
58331 if (error)
58332 goto out;
58333@@ -3456,6 +3578,8 @@ retry:
58334 break;
58335 }
58336 out:
58337+ if (!error)
58338+ gr_handle_create(dentry, path.mnt);
58339 done_path_create(&path, dentry);
58340 if (retry_estale(error, lookup_flags)) {
58341 lookup_flags |= LOOKUP_REVAL;
58342@@ -3508,9 +3632,16 @@ retry:
58343
58344 if (!IS_POSIXACL(path.dentry->d_inode))
58345 mode &= ~current_umask();
58346+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
58347+ error = -EACCES;
58348+ goto out;
58349+ }
58350 error = security_path_mkdir(&path, dentry, mode);
58351 if (!error)
58352 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
58353+ if (!error)
58354+ gr_handle_create(dentry, path.mnt);
58355+out:
58356 done_path_create(&path, dentry);
58357 if (retry_estale(error, lookup_flags)) {
58358 lookup_flags |= LOOKUP_REVAL;
58359@@ -3591,6 +3722,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
58360 struct filename *name;
58361 struct dentry *dentry;
58362 struct nameidata nd;
58363+ ino_t saved_ino = 0;
58364+ dev_t saved_dev = 0;
58365 unsigned int lookup_flags = 0;
58366 retry:
58367 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58368@@ -3623,10 +3756,21 @@ retry:
58369 error = -ENOENT;
58370 goto exit3;
58371 }
58372+
58373+ saved_ino = dentry->d_inode->i_ino;
58374+ saved_dev = gr_get_dev_from_dentry(dentry);
58375+
58376+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
58377+ error = -EACCES;
58378+ goto exit3;
58379+ }
58380+
58381 error = security_path_rmdir(&nd.path, dentry);
58382 if (error)
58383 goto exit3;
58384 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
58385+ if (!error && (saved_dev || saved_ino))
58386+ gr_handle_delete(saved_ino, saved_dev);
58387 exit3:
58388 dput(dentry);
58389 exit2:
58390@@ -3692,6 +3836,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
58391 struct dentry *dentry;
58392 struct nameidata nd;
58393 struct inode *inode = NULL;
58394+ ino_t saved_ino = 0;
58395+ dev_t saved_dev = 0;
58396 unsigned int lookup_flags = 0;
58397 retry:
58398 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58399@@ -3718,10 +3864,22 @@ retry:
58400 if (!inode)
58401 goto slashes;
58402 ihold(inode);
58403+
58404+ if (inode->i_nlink <= 1) {
58405+ saved_ino = inode->i_ino;
58406+ saved_dev = gr_get_dev_from_dentry(dentry);
58407+ }
58408+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
58409+ error = -EACCES;
58410+ goto exit2;
58411+ }
58412+
58413 error = security_path_unlink(&nd.path, dentry);
58414 if (error)
58415 goto exit2;
58416 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
58417+ if (!error && (saved_ino || saved_dev))
58418+ gr_handle_delete(saved_ino, saved_dev);
58419 exit2:
58420 dput(dentry);
58421 }
58422@@ -3799,9 +3957,17 @@ retry:
58423 if (IS_ERR(dentry))
58424 goto out_putname;
58425
58426+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
58427+ error = -EACCES;
58428+ goto out;
58429+ }
58430+
58431 error = security_path_symlink(&path, dentry, from->name);
58432 if (!error)
58433 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
58434+ if (!error)
58435+ gr_handle_create(dentry, path.mnt);
58436+out:
58437 done_path_create(&path, dentry);
58438 if (retry_estale(error, lookup_flags)) {
58439 lookup_flags |= LOOKUP_REVAL;
58440@@ -3881,6 +4047,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
58441 {
58442 struct dentry *new_dentry;
58443 struct path old_path, new_path;
58444+ struct filename *to = NULL;
58445 int how = 0;
58446 int error;
58447
58448@@ -3904,7 +4071,7 @@ retry:
58449 if (error)
58450 return error;
58451
58452- new_dentry = user_path_create(newdfd, newname, &new_path,
58453+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
58454 (how & LOOKUP_REVAL));
58455 error = PTR_ERR(new_dentry);
58456 if (IS_ERR(new_dentry))
58457@@ -3916,11 +4083,28 @@ retry:
58458 error = may_linkat(&old_path);
58459 if (unlikely(error))
58460 goto out_dput;
58461+
58462+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
58463+ old_path.dentry->d_inode,
58464+ old_path.dentry->d_inode->i_mode, to)) {
58465+ error = -EACCES;
58466+ goto out_dput;
58467+ }
58468+
58469+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
58470+ old_path.dentry, old_path.mnt, to)) {
58471+ error = -EACCES;
58472+ goto out_dput;
58473+ }
58474+
58475 error = security_path_link(old_path.dentry, &new_path, new_dentry);
58476 if (error)
58477 goto out_dput;
58478 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
58479+ if (!error)
58480+ gr_handle_create(new_dentry, new_path.mnt);
58481 out_dput:
58482+ putname(to);
58483 done_path_create(&new_path, new_dentry);
58484 if (retry_estale(error, how)) {
58485 how |= LOOKUP_REVAL;
58486@@ -4166,12 +4350,21 @@ retry:
58487 if (new_dentry == trap)
58488 goto exit5;
58489
58490+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
58491+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
58492+ to);
58493+ if (error)
58494+ goto exit5;
58495+
58496 error = security_path_rename(&oldnd.path, old_dentry,
58497 &newnd.path, new_dentry);
58498 if (error)
58499 goto exit5;
58500 error = vfs_rename(old_dir->d_inode, old_dentry,
58501 new_dir->d_inode, new_dentry);
58502+ if (!error)
58503+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
58504+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
58505 exit5:
58506 dput(new_dentry);
58507 exit4:
58508@@ -4203,6 +4396,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
58509
58510 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
58511 {
58512+ char tmpbuf[64];
58513+ const char *newlink;
58514 int len;
58515
58516 len = PTR_ERR(link);
58517@@ -4212,7 +4407,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
58518 len = strlen(link);
58519 if (len > (unsigned) buflen)
58520 len = buflen;
58521- if (copy_to_user(buffer, link, len))
58522+
58523+ if (len < sizeof(tmpbuf)) {
58524+ memcpy(tmpbuf, link, len);
58525+ newlink = tmpbuf;
58526+ } else
58527+ newlink = link;
58528+
58529+ if (copy_to_user(buffer, newlink, len))
58530 len = -EFAULT;
58531 out:
58532 return len;
58533diff --git a/fs/namespace.c b/fs/namespace.c
58534index da5c494..a755a54 100644
58535--- a/fs/namespace.c
58536+++ b/fs/namespace.c
58537@@ -1268,6 +1268,9 @@ static int do_umount(struct mount *mnt, int flags)
58538 if (!(sb->s_flags & MS_RDONLY))
58539 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58540 up_write(&sb->s_umount);
58541+
58542+ gr_log_remount(mnt->mnt_devname, retval);
58543+
58544 return retval;
58545 }
58546
58547@@ -1286,6 +1289,9 @@ static int do_umount(struct mount *mnt, int flags)
58548 }
58549 br_write_unlock(&vfsmount_lock);
58550 namespace_unlock();
58551+
58552+ gr_log_unmount(mnt->mnt_devname, retval);
58553+
58554 return retval;
58555 }
58556
58557@@ -1305,7 +1311,7 @@ static inline bool may_mount(void)
58558 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58559 */
58560
58561-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58562+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58563 {
58564 struct path path;
58565 struct mount *mnt;
58566@@ -1347,7 +1353,7 @@ out:
58567 /*
58568 * The 2.0 compatible umount. No flags.
58569 */
58570-SYSCALL_DEFINE1(oldumount, char __user *, name)
58571+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58572 {
58573 return sys_umount(name, 0);
58574 }
58575@@ -2358,6 +2364,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58576 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58577 MS_STRICTATIME);
58578
58579+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58580+ retval = -EPERM;
58581+ goto dput_out;
58582+ }
58583+
58584+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58585+ retval = -EPERM;
58586+ goto dput_out;
58587+ }
58588+
58589 if (flags & MS_REMOUNT)
58590 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58591 data_page);
58592@@ -2372,6 +2388,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58593 dev_name, data_page);
58594 dput_out:
58595 path_put(&path);
58596+
58597+ gr_log_mount(dev_name, dir_name, retval);
58598+
58599 return retval;
58600 }
58601
58602@@ -2389,7 +2408,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58603 * number incrementing at 10Ghz will take 12,427 years to wrap which
58604 * is effectively never, so we can ignore the possibility.
58605 */
58606-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58607+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58608
58609 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58610 {
58611@@ -2404,7 +2423,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58612 kfree(new_ns);
58613 return ERR_PTR(ret);
58614 }
58615- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58616+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58617 atomic_set(&new_ns->count, 1);
58618 new_ns->root = NULL;
58619 INIT_LIST_HEAD(&new_ns->list);
58620@@ -2418,7 +2437,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58621 * Allocate a new namespace structure and populate it with contents
58622 * copied from the namespace of the passed in task structure.
58623 */
58624-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58625+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58626 struct user_namespace *user_ns, struct fs_struct *fs)
58627 {
58628 struct mnt_namespace *new_ns;
58629@@ -2549,8 +2568,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58630 }
58631 EXPORT_SYMBOL(mount_subtree);
58632
58633-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58634- char __user *, type, unsigned long, flags, void __user *, data)
58635+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58636+ const char __user *, type, unsigned long, flags, void __user *, data)
58637 {
58638 int ret;
58639 char *kernel_type;
58640@@ -2663,6 +2682,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58641 if (error)
58642 goto out2;
58643
58644+ if (gr_handle_chroot_pivot()) {
58645+ error = -EPERM;
58646+ goto out2;
58647+ }
58648+
58649 get_fs_root(current->fs, &root);
58650 old_mp = lock_mount(&old);
58651 error = PTR_ERR(old_mp);
58652@@ -2932,7 +2956,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58653 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
58654 return -EPERM;
58655
58656- if (fs->users != 1)
58657+ if (atomic_read(&fs->users) != 1)
58658 return -EINVAL;
58659
58660 get_mnt_ns(mnt_ns);
58661diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58662index f4ccfe6..a5cf064 100644
58663--- a/fs/nfs/callback_xdr.c
58664+++ b/fs/nfs/callback_xdr.c
58665@@ -51,7 +51,7 @@ struct callback_op {
58666 callback_decode_arg_t decode_args;
58667 callback_encode_res_t encode_res;
58668 long res_maxsize;
58669-};
58670+} __do_const;
58671
58672 static struct callback_op callback_ops[];
58673
58674diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58675index eda8879..bfc6837 100644
58676--- a/fs/nfs/inode.c
58677+++ b/fs/nfs/inode.c
58678@@ -1150,16 +1150,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58679 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58680 }
58681
58682-static atomic_long_t nfs_attr_generation_counter;
58683+static atomic_long_unchecked_t nfs_attr_generation_counter;
58684
58685 static unsigned long nfs_read_attr_generation_counter(void)
58686 {
58687- return atomic_long_read(&nfs_attr_generation_counter);
58688+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58689 }
58690
58691 unsigned long nfs_inc_attr_generation_counter(void)
58692 {
58693- return atomic_long_inc_return(&nfs_attr_generation_counter);
58694+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58695 }
58696
58697 void nfs_fattr_init(struct nfs_fattr *fattr)
58698diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58699index 419572f..5414a23 100644
58700--- a/fs/nfsd/nfs4proc.c
58701+++ b/fs/nfsd/nfs4proc.c
58702@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58703 nfsd4op_rsize op_rsize_bop;
58704 stateid_getter op_get_currentstateid;
58705 stateid_setter op_set_currentstateid;
58706-};
58707+} __do_const;
58708
58709 static struct nfsd4_operation nfsd4_ops[];
58710
58711diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58712index ecc735e..79b2d31 100644
58713--- a/fs/nfsd/nfs4xdr.c
58714+++ b/fs/nfsd/nfs4xdr.c
58715@@ -1500,7 +1500,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58716
58717 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58718
58719-static nfsd4_dec nfsd4_dec_ops[] = {
58720+static const nfsd4_dec nfsd4_dec_ops[] = {
58721 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58722 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58723 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58724@@ -1540,7 +1540,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58725 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58726 };
58727
58728-static nfsd4_dec nfsd41_dec_ops[] = {
58729+static const nfsd4_dec nfsd41_dec_ops[] = {
58730 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58731 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58732 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58733@@ -1602,7 +1602,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58734 };
58735
58736 struct nfsd4_minorversion_ops {
58737- nfsd4_dec *decoders;
58738+ const nfsd4_dec *decoders;
58739 int nops;
58740 };
58741
58742diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58743index 9186c7c..3fdde3e 100644
58744--- a/fs/nfsd/nfscache.c
58745+++ b/fs/nfsd/nfscache.c
58746@@ -540,14 +540,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58747 {
58748 struct svc_cacherep *rp = rqstp->rq_cacherep;
58749 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58750- int len;
58751+ long len;
58752 size_t bufsize = 0;
58753
58754 if (!rp)
58755 return;
58756
58757- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58758- len >>= 2;
58759+ if (statp) {
58760+ len = (char*)statp - (char*)resv->iov_base;
58761+ len = resv->iov_len - len;
58762+ len >>= 2;
58763+ }
58764
58765 /* Don't cache excessive amounts of data and XDR failures */
58766 if (!statp || len > (256 >> 2)) {
58767diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58768index 72cb28e..5b5f87d 100644
58769--- a/fs/nfsd/vfs.c
58770+++ b/fs/nfsd/vfs.c
58771@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58772 } else {
58773 oldfs = get_fs();
58774 set_fs(KERNEL_DS);
58775- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58776+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58777 set_fs(oldfs);
58778 }
58779
58780@@ -1080,7 +1080,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58781
58782 /* Write the data. */
58783 oldfs = get_fs(); set_fs(KERNEL_DS);
58784- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58785+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58786 set_fs(oldfs);
58787 if (host_err < 0)
58788 goto out_nfserr;
58789@@ -1626,7 +1626,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58790 */
58791
58792 oldfs = get_fs(); set_fs(KERNEL_DS);
58793- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58794+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58795 set_fs(oldfs);
58796
58797 if (host_err < 0)
58798diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58799index fea6bd5..8ee9d81 100644
58800--- a/fs/nls/nls_base.c
58801+++ b/fs/nls/nls_base.c
58802@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58803
58804 int register_nls(struct nls_table * nls)
58805 {
58806- struct nls_table ** tmp = &tables;
58807+ struct nls_table *tmp = tables;
58808
58809 if (nls->next)
58810 return -EBUSY;
58811
58812 spin_lock(&nls_lock);
58813- while (*tmp) {
58814- if (nls == *tmp) {
58815+ while (tmp) {
58816+ if (nls == tmp) {
58817 spin_unlock(&nls_lock);
58818 return -EBUSY;
58819 }
58820- tmp = &(*tmp)->next;
58821+ tmp = tmp->next;
58822 }
58823- nls->next = tables;
58824+ pax_open_kernel();
58825+ *(struct nls_table **)&nls->next = tables;
58826+ pax_close_kernel();
58827 tables = nls;
58828 spin_unlock(&nls_lock);
58829 return 0;
58830@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58831
58832 int unregister_nls(struct nls_table * nls)
58833 {
58834- struct nls_table ** tmp = &tables;
58835+ struct nls_table * const * tmp = &tables;
58836
58837 spin_lock(&nls_lock);
58838 while (*tmp) {
58839 if (nls == *tmp) {
58840- *tmp = nls->next;
58841+ pax_open_kernel();
58842+ *(struct nls_table **)tmp = nls->next;
58843+ pax_close_kernel();
58844 spin_unlock(&nls_lock);
58845 return 0;
58846 }
58847diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58848index 7424929..35f6be5 100644
58849--- a/fs/nls/nls_euc-jp.c
58850+++ b/fs/nls/nls_euc-jp.c
58851@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58852 p_nls = load_nls("cp932");
58853
58854 if (p_nls) {
58855- table.charset2upper = p_nls->charset2upper;
58856- table.charset2lower = p_nls->charset2lower;
58857+ pax_open_kernel();
58858+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58859+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58860+ pax_close_kernel();
58861 return register_nls(&table);
58862 }
58863
58864diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58865index e7bc1d7..06bd4bb 100644
58866--- a/fs/nls/nls_koi8-ru.c
58867+++ b/fs/nls/nls_koi8-ru.c
58868@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58869 p_nls = load_nls("koi8-u");
58870
58871 if (p_nls) {
58872- table.charset2upper = p_nls->charset2upper;
58873- table.charset2lower = p_nls->charset2lower;
58874+ pax_open_kernel();
58875+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58876+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58877+ pax_close_kernel();
58878 return register_nls(&table);
58879 }
58880
58881diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58882index e44cb64..4807084 100644
58883--- a/fs/notify/fanotify/fanotify_user.c
58884+++ b/fs/notify/fanotify/fanotify_user.c
58885@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58886
58887 fd = fanotify_event_metadata.fd;
58888 ret = -EFAULT;
58889- if (copy_to_user(buf, &fanotify_event_metadata,
58890- fanotify_event_metadata.event_len))
58891+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58892+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58893 goto out_close_fd;
58894
58895 ret = prepare_for_access_response(group, event, fd);
58896diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58897index 7b51b05..5ea5ef6 100644
58898--- a/fs/notify/notification.c
58899+++ b/fs/notify/notification.c
58900@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58901 * get set to 0 so it will never get 'freed'
58902 */
58903 static struct fsnotify_event *q_overflow_event;
58904-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58905+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58906
58907 /**
58908 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58909@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58910 */
58911 u32 fsnotify_get_cookie(void)
58912 {
58913- return atomic_inc_return(&fsnotify_sync_cookie);
58914+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58915 }
58916 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58917
58918diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58919index 9e38daf..5727cae 100644
58920--- a/fs/ntfs/dir.c
58921+++ b/fs/ntfs/dir.c
58922@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58923 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58924 ~(s64)(ndir->itype.index.block_size - 1)));
58925 /* Bounds checks. */
58926- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58927+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58928 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58929 "inode 0x%lx or driver bug.", vdir->i_ino);
58930 goto err_out;
58931diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58932index ea4ba9d..1e13d34 100644
58933--- a/fs/ntfs/file.c
58934+++ b/fs/ntfs/file.c
58935@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58936 char *addr;
58937 size_t total = 0;
58938 unsigned len;
58939- int left;
58940+ unsigned left;
58941
58942 do {
58943 len = PAGE_CACHE_SIZE - ofs;
58944diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58945index 82650d5..db37dcf 100644
58946--- a/fs/ntfs/super.c
58947+++ b/fs/ntfs/super.c
58948@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58949 if (!silent)
58950 ntfs_error(sb, "Primary boot sector is invalid.");
58951 } else if (!silent)
58952- ntfs_error(sb, read_err_str, "primary");
58953+ ntfs_error(sb, read_err_str, "%s", "primary");
58954 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58955 if (bh_primary)
58956 brelse(bh_primary);
58957@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58958 goto hotfix_primary_boot_sector;
58959 brelse(bh_backup);
58960 } else if (!silent)
58961- ntfs_error(sb, read_err_str, "backup");
58962+ ntfs_error(sb, read_err_str, "%s", "backup");
58963 /* Try to read NT3.51- backup boot sector. */
58964 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58965 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58966@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58967 "sector.");
58968 brelse(bh_backup);
58969 } else if (!silent)
58970- ntfs_error(sb, read_err_str, "backup");
58971+ ntfs_error(sb, read_err_str, "%s", "backup");
58972 /* We failed. Cleanup and return. */
58973 if (bh_primary)
58974 brelse(bh_primary);
58975diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58976index cd5496b..26a1055 100644
58977--- a/fs/ocfs2/localalloc.c
58978+++ b/fs/ocfs2/localalloc.c
58979@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58980 goto bail;
58981 }
58982
58983- atomic_inc(&osb->alloc_stats.moves);
58984+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58985
58986 bail:
58987 if (handle)
58988diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58989index 3a90347..c40bef8 100644
58990--- a/fs/ocfs2/ocfs2.h
58991+++ b/fs/ocfs2/ocfs2.h
58992@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58993
58994 struct ocfs2_alloc_stats
58995 {
58996- atomic_t moves;
58997- atomic_t local_data;
58998- atomic_t bitmap_data;
58999- atomic_t bg_allocs;
59000- atomic_t bg_extends;
59001+ atomic_unchecked_t moves;
59002+ atomic_unchecked_t local_data;
59003+ atomic_unchecked_t bitmap_data;
59004+ atomic_unchecked_t bg_allocs;
59005+ atomic_unchecked_t bg_extends;
59006 };
59007
59008 enum ocfs2_local_alloc_state
59009diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
59010index 5397c07..54afc55 100644
59011--- a/fs/ocfs2/suballoc.c
59012+++ b/fs/ocfs2/suballoc.c
59013@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
59014 mlog_errno(status);
59015 goto bail;
59016 }
59017- atomic_inc(&osb->alloc_stats.bg_extends);
59018+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
59019
59020 /* You should never ask for this much metadata */
59021 BUG_ON(bits_wanted >
59022@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
59023 mlog_errno(status);
59024 goto bail;
59025 }
59026- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59027+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59028
59029 *suballoc_loc = res.sr_bg_blkno;
59030 *suballoc_bit_start = res.sr_bit_offset;
59031@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
59032 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
59033 res->sr_bits);
59034
59035- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59036+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59037
59038 BUG_ON(res->sr_bits != 1);
59039
59040@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
59041 mlog_errno(status);
59042 goto bail;
59043 }
59044- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59045+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59046
59047 BUG_ON(res.sr_bits != 1);
59048
59049@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59050 cluster_start,
59051 num_clusters);
59052 if (!status)
59053- atomic_inc(&osb->alloc_stats.local_data);
59054+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
59055 } else {
59056 if (min_clusters > (osb->bitmap_cpg - 1)) {
59057 /* The only paths asking for contiguousness
59058@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59059 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
59060 res.sr_bg_blkno,
59061 res.sr_bit_offset);
59062- atomic_inc(&osb->alloc_stats.bitmap_data);
59063+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
59064 *num_clusters = res.sr_bits;
59065 }
59066 }
59067diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
59068index d4e81e4..ad89f5f 100644
59069--- a/fs/ocfs2/super.c
59070+++ b/fs/ocfs2/super.c
59071@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
59072 "%10s => GlobalAllocs: %d LocalAllocs: %d "
59073 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
59074 "Stats",
59075- atomic_read(&osb->alloc_stats.bitmap_data),
59076- atomic_read(&osb->alloc_stats.local_data),
59077- atomic_read(&osb->alloc_stats.bg_allocs),
59078- atomic_read(&osb->alloc_stats.moves),
59079- atomic_read(&osb->alloc_stats.bg_extends));
59080+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
59081+ atomic_read_unchecked(&osb->alloc_stats.local_data),
59082+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
59083+ atomic_read_unchecked(&osb->alloc_stats.moves),
59084+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
59085
59086 out += snprintf(buf + out, len - out,
59087 "%10s => State: %u Descriptor: %llu Size: %u bits "
59088@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
59089 spin_lock_init(&osb->osb_xattr_lock);
59090 ocfs2_init_steal_slots(osb);
59091
59092- atomic_set(&osb->alloc_stats.moves, 0);
59093- atomic_set(&osb->alloc_stats.local_data, 0);
59094- atomic_set(&osb->alloc_stats.bitmap_data, 0);
59095- atomic_set(&osb->alloc_stats.bg_allocs, 0);
59096- atomic_set(&osb->alloc_stats.bg_extends, 0);
59097+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
59098+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
59099+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
59100+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
59101+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
59102
59103 /* Copy the blockcheck stats from the superblock probe */
59104 osb->osb_ecc_stats = *stats;
59105diff --git a/fs/open.c b/fs/open.c
59106index d420331..2dbb3fd 100644
59107--- a/fs/open.c
59108+++ b/fs/open.c
59109@@ -32,6 +32,8 @@
59110 #include <linux/dnotify.h>
59111 #include <linux/compat.h>
59112
59113+#define CREATE_TRACE_POINTS
59114+#include <trace/events/fs.h>
59115 #include "internal.h"
59116
59117 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
59118@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
59119 error = locks_verify_truncate(inode, NULL, length);
59120 if (!error)
59121 error = security_path_truncate(path);
59122+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
59123+ error = -EACCES;
59124 if (!error)
59125 error = do_truncate(path->dentry, length, 0, NULL);
59126
59127@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
59128 error = locks_verify_truncate(inode, f.file, length);
59129 if (!error)
59130 error = security_path_truncate(&f.file->f_path);
59131+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
59132+ error = -EACCES;
59133 if (!error)
59134 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
59135 sb_end_write(inode->i_sb);
59136@@ -360,6 +366,9 @@ retry:
59137 if (__mnt_is_readonly(path.mnt))
59138 res = -EROFS;
59139
59140+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
59141+ res = -EACCES;
59142+
59143 out_path_release:
59144 path_put(&path);
59145 if (retry_estale(res, lookup_flags)) {
59146@@ -391,6 +400,8 @@ retry:
59147 if (error)
59148 goto dput_and_out;
59149
59150+ gr_log_chdir(path.dentry, path.mnt);
59151+
59152 set_fs_pwd(current->fs, &path);
59153
59154 dput_and_out:
59155@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
59156 goto out_putf;
59157
59158 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
59159+
59160+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
59161+ error = -EPERM;
59162+
59163+ if (!error)
59164+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
59165+
59166 if (!error)
59167 set_fs_pwd(current->fs, &f.file->f_path);
59168 out_putf:
59169@@ -449,7 +467,13 @@ retry:
59170 if (error)
59171 goto dput_and_out;
59172
59173+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
59174+ goto dput_and_out;
59175+
59176 set_fs_root(current->fs, &path);
59177+
59178+ gr_handle_chroot_chdir(&path);
59179+
59180 error = 0;
59181 dput_and_out:
59182 path_put(&path);
59183@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
59184 if (error)
59185 return error;
59186 mutex_lock(&inode->i_mutex);
59187+
59188+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
59189+ error = -EACCES;
59190+ goto out_unlock;
59191+ }
59192+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
59193+ error = -EACCES;
59194+ goto out_unlock;
59195+ }
59196+
59197 error = security_path_chmod(path, mode);
59198 if (error)
59199 goto out_unlock;
59200@@ -530,6 +564,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
59201 uid = make_kuid(current_user_ns(), user);
59202 gid = make_kgid(current_user_ns(), group);
59203
59204+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
59205+ return -EACCES;
59206+
59207 newattrs.ia_valid = ATTR_CTIME;
59208 if (user != (uid_t) -1) {
59209 if (!uid_valid(uid))
59210@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
59211 } else {
59212 fsnotify_open(f);
59213 fd_install(fd, f);
59214+ trace_do_sys_open(tmp->name, flags, mode);
59215 }
59216 }
59217 putname(tmp);
59218diff --git a/fs/pipe.c b/fs/pipe.c
59219index d2c45e1..009fe1c 100644
59220--- a/fs/pipe.c
59221+++ b/fs/pipe.c
59222@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
59223
59224 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
59225 {
59226- if (pipe->files)
59227+ if (atomic_read(&pipe->files))
59228 mutex_lock_nested(&pipe->mutex, subclass);
59229 }
59230
59231@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
59232
59233 void pipe_unlock(struct pipe_inode_info *pipe)
59234 {
59235- if (pipe->files)
59236+ if (atomic_read(&pipe->files))
59237 mutex_unlock(&pipe->mutex);
59238 }
59239 EXPORT_SYMBOL(pipe_unlock);
59240@@ -449,9 +449,9 @@ redo:
59241 }
59242 if (bufs) /* More to do? */
59243 continue;
59244- if (!pipe->writers)
59245+ if (!atomic_read(&pipe->writers))
59246 break;
59247- if (!pipe->waiting_writers) {
59248+ if (!atomic_read(&pipe->waiting_writers)) {
59249 /* syscall merging: Usually we must not sleep
59250 * if O_NONBLOCK is set, or if we got some data.
59251 * But if a writer sleeps in kernel space, then
59252@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
59253 ret = 0;
59254 __pipe_lock(pipe);
59255
59256- if (!pipe->readers) {
59257+ if (!atomic_read(&pipe->readers)) {
59258 send_sig(SIGPIPE, current, 0);
59259 ret = -EPIPE;
59260 goto out;
59261@@ -562,7 +562,7 @@ redo1:
59262 for (;;) {
59263 int bufs;
59264
59265- if (!pipe->readers) {
59266+ if (!atomic_read(&pipe->readers)) {
59267 send_sig(SIGPIPE, current, 0);
59268 if (!ret)
59269 ret = -EPIPE;
59270@@ -653,9 +653,9 @@ redo2:
59271 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59272 do_wakeup = 0;
59273 }
59274- pipe->waiting_writers++;
59275+ atomic_inc(&pipe->waiting_writers);
59276 pipe_wait(pipe);
59277- pipe->waiting_writers--;
59278+ atomic_dec(&pipe->waiting_writers);
59279 }
59280 out:
59281 __pipe_unlock(pipe);
59282@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59283 mask = 0;
59284 if (filp->f_mode & FMODE_READ) {
59285 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
59286- if (!pipe->writers && filp->f_version != pipe->w_counter)
59287+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
59288 mask |= POLLHUP;
59289 }
59290
59291@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59292 * Most Unices do not set POLLERR for FIFOs but on Linux they
59293 * behave exactly like pipes for poll().
59294 */
59295- if (!pipe->readers)
59296+ if (!atomic_read(&pipe->readers))
59297 mask |= POLLERR;
59298 }
59299
59300@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
59301
59302 __pipe_lock(pipe);
59303 if (file->f_mode & FMODE_READ)
59304- pipe->readers--;
59305+ atomic_dec(&pipe->readers);
59306 if (file->f_mode & FMODE_WRITE)
59307- pipe->writers--;
59308+ atomic_dec(&pipe->writers);
59309
59310- if (pipe->readers || pipe->writers) {
59311+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
59312 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
59313 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59314 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
59315 }
59316 spin_lock(&inode->i_lock);
59317- if (!--pipe->files) {
59318+ if (atomic_dec_and_test(&pipe->files)) {
59319 inode->i_pipe = NULL;
59320 kill = 1;
59321 }
59322@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
59323 kfree(pipe);
59324 }
59325
59326-static struct vfsmount *pipe_mnt __read_mostly;
59327+struct vfsmount *pipe_mnt __read_mostly;
59328
59329 /*
59330 * pipefs_dname() is called from d_path().
59331@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
59332 goto fail_iput;
59333
59334 inode->i_pipe = pipe;
59335- pipe->files = 2;
59336- pipe->readers = pipe->writers = 1;
59337+ atomic_set(&pipe->files, 2);
59338+ atomic_set(&pipe->readers, 1);
59339+ atomic_set(&pipe->writers, 1);
59340 inode->i_fop = &pipefifo_fops;
59341
59342 /*
59343@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
59344 spin_lock(&inode->i_lock);
59345 if (inode->i_pipe) {
59346 pipe = inode->i_pipe;
59347- pipe->files++;
59348+ atomic_inc(&pipe->files);
59349 spin_unlock(&inode->i_lock);
59350 } else {
59351 spin_unlock(&inode->i_lock);
59352 pipe = alloc_pipe_info();
59353 if (!pipe)
59354 return -ENOMEM;
59355- pipe->files = 1;
59356+ atomic_set(&pipe->files, 1);
59357 spin_lock(&inode->i_lock);
59358 if (unlikely(inode->i_pipe)) {
59359- inode->i_pipe->files++;
59360+ atomic_inc(&inode->i_pipe->files);
59361 spin_unlock(&inode->i_lock);
59362 free_pipe_info(pipe);
59363 pipe = inode->i_pipe;
59364@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
59365 * opened, even when there is no process writing the FIFO.
59366 */
59367 pipe->r_counter++;
59368- if (pipe->readers++ == 0)
59369+ if (atomic_inc_return(&pipe->readers) == 1)
59370 wake_up_partner(pipe);
59371
59372- if (!is_pipe && !pipe->writers) {
59373+ if (!is_pipe && !atomic_read(&pipe->writers)) {
59374 if ((filp->f_flags & O_NONBLOCK)) {
59375 /* suppress POLLHUP until we have
59376 * seen a writer */
59377@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
59378 * errno=ENXIO when there is no process reading the FIFO.
59379 */
59380 ret = -ENXIO;
59381- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
59382+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
59383 goto err;
59384
59385 pipe->w_counter++;
59386- if (!pipe->writers++)
59387+ if (atomic_inc_return(&pipe->writers) == 1)
59388 wake_up_partner(pipe);
59389
59390- if (!is_pipe && !pipe->readers) {
59391+ if (!is_pipe && !atomic_read(&pipe->readers)) {
59392 if (wait_for_partner(pipe, &pipe->r_counter))
59393 goto err_wr;
59394 }
59395@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
59396 * the process can at least talk to itself.
59397 */
59398
59399- pipe->readers++;
59400- pipe->writers++;
59401+ atomic_inc(&pipe->readers);
59402+ atomic_inc(&pipe->writers);
59403 pipe->r_counter++;
59404 pipe->w_counter++;
59405- if (pipe->readers == 1 || pipe->writers == 1)
59406+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
59407 wake_up_partner(pipe);
59408 break;
59409
59410@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
59411 return 0;
59412
59413 err_rd:
59414- if (!--pipe->readers)
59415+ if (atomic_dec_and_test(&pipe->readers))
59416 wake_up_interruptible(&pipe->wait);
59417 ret = -ERESTARTSYS;
59418 goto err;
59419
59420 err_wr:
59421- if (!--pipe->writers)
59422+ if (atomic_dec_and_test(&pipe->writers))
59423 wake_up_interruptible(&pipe->wait);
59424 ret = -ERESTARTSYS;
59425 goto err;
59426
59427 err:
59428 spin_lock(&inode->i_lock);
59429- if (!--pipe->files) {
59430+ if (atomic_dec_and_test(&pipe->files)) {
59431 inode->i_pipe = NULL;
59432 kill = 1;
59433 }
59434diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
59435index 15af622..0e9f4467 100644
59436--- a/fs/proc/Kconfig
59437+++ b/fs/proc/Kconfig
59438@@ -30,12 +30,12 @@ config PROC_FS
59439
59440 config PROC_KCORE
59441 bool "/proc/kcore support" if !ARM
59442- depends on PROC_FS && MMU
59443+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
59444
59445 config PROC_VMCORE
59446 bool "/proc/vmcore support"
59447- depends on PROC_FS && CRASH_DUMP
59448- default y
59449+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
59450+ default n
59451 help
59452 Exports the dump image of crashed kernel in ELF format.
59453
59454@@ -59,8 +59,8 @@ config PROC_SYSCTL
59455 limited in memory.
59456
59457 config PROC_PAGE_MONITOR
59458- default y
59459- depends on PROC_FS && MMU
59460+ default n
59461+ depends on PROC_FS && MMU && !GRKERNSEC
59462 bool "Enable /proc page monitoring" if EXPERT
59463 help
59464 Various /proc files exist to monitor process memory utilization:
59465diff --git a/fs/proc/array.c b/fs/proc/array.c
59466index cbd0f1b..adec3f0 100644
59467--- a/fs/proc/array.c
59468+++ b/fs/proc/array.c
59469@@ -60,6 +60,7 @@
59470 #include <linux/tty.h>
59471 #include <linux/string.h>
59472 #include <linux/mman.h>
59473+#include <linux/grsecurity.h>
59474 #include <linux/proc_fs.h>
59475 #include <linux/ioport.h>
59476 #include <linux/uaccess.h>
59477@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
59478 seq_putc(m, '\n');
59479 }
59480
59481+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59482+static inline void task_pax(struct seq_file *m, struct task_struct *p)
59483+{
59484+ if (p->mm)
59485+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
59486+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
59487+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
59488+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
59489+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
59490+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
59491+ else
59492+ seq_printf(m, "PaX:\t-----\n");
59493+}
59494+#endif
59495+
59496 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59497 struct pid *pid, struct task_struct *task)
59498 {
59499@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59500 task_cpus_allowed(m, task);
59501 cpuset_task_status_allowed(m, task);
59502 task_context_switch_counts(m, task);
59503+
59504+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59505+ task_pax(m, task);
59506+#endif
59507+
59508+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
59509+ task_grsec_rbac(m, task);
59510+#endif
59511+
59512 return 0;
59513 }
59514
59515+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59516+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59517+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59518+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59519+#endif
59520+
59521 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59522 struct pid *pid, struct task_struct *task, int whole)
59523 {
59524@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59525 char tcomm[sizeof(task->comm)];
59526 unsigned long flags;
59527
59528+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59529+ if (current->exec_id != m->exec_id) {
59530+ gr_log_badprocpid("stat");
59531+ return 0;
59532+ }
59533+#endif
59534+
59535 state = *get_task_state(task);
59536 vsize = eip = esp = 0;
59537 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59538@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59539 gtime = task_gtime(task);
59540 }
59541
59542+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59543+ if (PAX_RAND_FLAGS(mm)) {
59544+ eip = 0;
59545+ esp = 0;
59546+ wchan = 0;
59547+ }
59548+#endif
59549+#ifdef CONFIG_GRKERNSEC_HIDESYM
59550+ wchan = 0;
59551+ eip =0;
59552+ esp =0;
59553+#endif
59554+
59555 /* scale priority and nice values from timeslices to -20..20 */
59556 /* to make it look like a "normal" Unix priority/nice value */
59557 priority = task_prio(task);
59558@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59559 seq_put_decimal_ull(m, ' ', vsize);
59560 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
59561 seq_put_decimal_ull(m, ' ', rsslim);
59562+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59563+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59564+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59565+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59566+#else
59567 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59568 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59569 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59570+#endif
59571 seq_put_decimal_ull(m, ' ', esp);
59572 seq_put_decimal_ull(m, ' ', eip);
59573 /* The signal information here is obsolete.
59574@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59575 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59576 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59577
59578- if (mm && permitted) {
59579+ if (mm && permitted
59580+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59581+ && !PAX_RAND_FLAGS(mm)
59582+#endif
59583+ ) {
59584 seq_put_decimal_ull(m, ' ', mm->start_data);
59585 seq_put_decimal_ull(m, ' ', mm->end_data);
59586 seq_put_decimal_ull(m, ' ', mm->start_brk);
59587@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59588 struct pid *pid, struct task_struct *task)
59589 {
59590 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59591- struct mm_struct *mm = get_task_mm(task);
59592+ struct mm_struct *mm;
59593
59594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59595+ if (current->exec_id != m->exec_id) {
59596+ gr_log_badprocpid("statm");
59597+ return 0;
59598+ }
59599+#endif
59600+ mm = get_task_mm(task);
59601 if (mm) {
59602 size = task_statm(mm, &shared, &text, &data, &resident);
59603 mmput(mm);
59604@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59605 return 0;
59606 }
59607
59608+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59609+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59610+{
59611+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59612+}
59613+#endif
59614+
59615 #ifdef CONFIG_CHECKPOINT_RESTORE
59616 static struct pid *
59617 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59618diff --git a/fs/proc/base.c b/fs/proc/base.c
59619index 1485e38..8ad4236 100644
59620--- a/fs/proc/base.c
59621+++ b/fs/proc/base.c
59622@@ -113,6 +113,14 @@ struct pid_entry {
59623 union proc_op op;
59624 };
59625
59626+struct getdents_callback {
59627+ struct linux_dirent __user * current_dir;
59628+ struct linux_dirent __user * previous;
59629+ struct file * file;
59630+ int count;
59631+ int error;
59632+};
59633+
59634 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59635 .name = (NAME), \
59636 .len = sizeof(NAME) - 1, \
59637@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59638 if (!mm->arg_end)
59639 goto out_mm; /* Shh! No looking before we're done */
59640
59641+ if (gr_acl_handle_procpidmem(task))
59642+ goto out_mm;
59643+
59644 len = mm->arg_end - mm->arg_start;
59645
59646 if (len > PAGE_SIZE)
59647@@ -237,12 +248,28 @@ out:
59648 return res;
59649 }
59650
59651+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59652+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59653+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59654+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59655+#endif
59656+
59657 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59658 {
59659 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59660 int res = PTR_ERR(mm);
59661 if (mm && !IS_ERR(mm)) {
59662 unsigned int nwords = 0;
59663+
59664+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59665+ /* allow if we're currently ptracing this task */
59666+ if (PAX_RAND_FLAGS(mm) &&
59667+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59668+ mmput(mm);
59669+ return 0;
59670+ }
59671+#endif
59672+
59673 do {
59674 nwords += 2;
59675 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59676@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59677 }
59678
59679
59680-#ifdef CONFIG_KALLSYMS
59681+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59682 /*
59683 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59684 * Returns the resolved symbol. If that fails, simply return the address.
59685@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59686 mutex_unlock(&task->signal->cred_guard_mutex);
59687 }
59688
59689-#ifdef CONFIG_STACKTRACE
59690+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59691
59692 #define MAX_STACK_TRACE_DEPTH 64
59693
59694@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59695 return count;
59696 }
59697
59698-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59699+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59700 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59701 {
59702 long nr;
59703@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59704 /************************************************************************/
59705
59706 /* permission checks */
59707-static int proc_fd_access_allowed(struct inode *inode)
59708+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59709 {
59710 struct task_struct *task;
59711 int allowed = 0;
59712@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59713 */
59714 task = get_proc_task(inode);
59715 if (task) {
59716- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59717+ if (log)
59718+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59719+ else
59720+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59721 put_task_struct(task);
59722 }
59723 return allowed;
59724@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59725 struct task_struct *task,
59726 int hide_pid_min)
59727 {
59728+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59729+ return false;
59730+
59731+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59732+ rcu_read_lock();
59733+ {
59734+ const struct cred *tmpcred = current_cred();
59735+ const struct cred *cred = __task_cred(task);
59736+
59737+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59738+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59739+ || in_group_p(grsec_proc_gid)
59740+#endif
59741+ ) {
59742+ rcu_read_unlock();
59743+ return true;
59744+ }
59745+ }
59746+ rcu_read_unlock();
59747+
59748+ if (!pid->hide_pid)
59749+ return false;
59750+#endif
59751+
59752 if (pid->hide_pid < hide_pid_min)
59753 return true;
59754 if (in_group_p(pid->pid_gid))
59755 return true;
59756+
59757 return ptrace_may_access(task, PTRACE_MODE_READ);
59758 }
59759
59760@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59761 put_task_struct(task);
59762
59763 if (!has_perms) {
59764+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59765+ {
59766+#else
59767 if (pid->hide_pid == 2) {
59768+#endif
59769 /*
59770 * Let's make getdents(), stat(), and open()
59771 * consistent with each other. If a process
59772@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59773 if (!task)
59774 return -ESRCH;
59775
59776+ if (gr_acl_handle_procpidmem(task)) {
59777+ put_task_struct(task);
59778+ return -EPERM;
59779+ }
59780+
59781 mm = mm_access(task, mode);
59782 put_task_struct(task);
59783
59784@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59785
59786 file->private_data = mm;
59787
59788+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59789+ file->f_version = current->exec_id;
59790+#endif
59791+
59792 return 0;
59793 }
59794
59795@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59796 ssize_t copied;
59797 char *page;
59798
59799+#ifdef CONFIG_GRKERNSEC
59800+ if (write)
59801+ return -EPERM;
59802+#endif
59803+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59804+ if (file->f_version != current->exec_id) {
59805+ gr_log_badprocpid("mem");
59806+ return 0;
59807+ }
59808+#endif
59809+
59810 if (!mm)
59811 return 0;
59812
59813@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59814 goto free;
59815
59816 while (count > 0) {
59817- int this_len = min_t(int, count, PAGE_SIZE);
59818+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59819
59820 if (write && copy_from_user(page, buf, this_len)) {
59821 copied = -EFAULT;
59822@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59823 if (!mm)
59824 return 0;
59825
59826+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59827+ if (file->f_version != current->exec_id) {
59828+ gr_log_badprocpid("environ");
59829+ return 0;
59830+ }
59831+#endif
59832+
59833 page = (char *)__get_free_page(GFP_TEMPORARY);
59834 if (!page)
59835 return -ENOMEM;
59836@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59837 goto free;
59838 while (count > 0) {
59839 size_t this_len, max_len;
59840- int retval;
59841+ ssize_t retval;
59842
59843 if (src >= (mm->env_end - mm->env_start))
59844 break;
59845@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59846 int error = -EACCES;
59847
59848 /* Are we allowed to snoop on the tasks file descriptors? */
59849- if (!proc_fd_access_allowed(inode))
59850+ if (!proc_fd_access_allowed(inode, 0))
59851 goto out;
59852
59853 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59854@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59855 struct path path;
59856
59857 /* Are we allowed to snoop on the tasks file descriptors? */
59858- if (!proc_fd_access_allowed(inode))
59859- goto out;
59860+ /* logging this is needed for learning on chromium to work properly,
59861+ but we don't want to flood the logs from 'ps' which does a readlink
59862+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59863+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59864+ */
59865+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59866+ if (!proc_fd_access_allowed(inode,0))
59867+ goto out;
59868+ } else {
59869+ if (!proc_fd_access_allowed(inode,1))
59870+ goto out;
59871+ }
59872
59873 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59874 if (error)
59875@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59876 rcu_read_lock();
59877 cred = __task_cred(task);
59878 inode->i_uid = cred->euid;
59879+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59880+ inode->i_gid = grsec_proc_gid;
59881+#else
59882 inode->i_gid = cred->egid;
59883+#endif
59884 rcu_read_unlock();
59885 }
59886 security_task_to_inode(task, inode);
59887@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59888 return -ENOENT;
59889 }
59890 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59891+#ifdef CONFIG_GRKERNSEC_PROC_USER
59892+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59893+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59894+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59895+#endif
59896 task_dumpable(task)) {
59897 cred = __task_cred(task);
59898 stat->uid = cred->euid;
59899+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59900+ stat->gid = grsec_proc_gid;
59901+#else
59902 stat->gid = cred->egid;
59903+#endif
59904 }
59905 }
59906 rcu_read_unlock();
59907@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59908
59909 if (task) {
59910 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59911+#ifdef CONFIG_GRKERNSEC_PROC_USER
59912+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59913+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59914+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59915+#endif
59916 task_dumpable(task)) {
59917 rcu_read_lock();
59918 cred = __task_cred(task);
59919 inode->i_uid = cred->euid;
59920+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59921+ inode->i_gid = grsec_proc_gid;
59922+#else
59923 inode->i_gid = cred->egid;
59924+#endif
59925 rcu_read_unlock();
59926 } else {
59927 inode->i_uid = GLOBAL_ROOT_UID;
59928@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59929 if (!task)
59930 goto out_no_task;
59931
59932+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59933+ goto out;
59934+
59935 /*
59936 * Yes, it does not scale. And it should not. Don't add
59937 * new entries into /proc/<tgid>/ without very good reasons.
59938@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59939 if (!task)
59940 return -ENOENT;
59941
59942+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59943+ goto out;
59944+
59945 if (!dir_emit_dots(file, ctx))
59946 goto out;
59947
59948@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59949 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59950 #endif
59951 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59952-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59953+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59954 INF("syscall", S_IRUGO, proc_pid_syscall),
59955 #endif
59956 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59957@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59958 #ifdef CONFIG_SECURITY
59959 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59960 #endif
59961-#ifdef CONFIG_KALLSYMS
59962+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59963 INF("wchan", S_IRUGO, proc_pid_wchan),
59964 #endif
59965-#ifdef CONFIG_STACKTRACE
59966+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59967 ONE("stack", S_IRUGO, proc_pid_stack),
59968 #endif
59969 #ifdef CONFIG_SCHEDSTATS
59970@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59971 #ifdef CONFIG_HARDWALL
59972 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59973 #endif
59974+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59975+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59976+#endif
59977 #ifdef CONFIG_USER_NS
59978 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59979 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59980@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59981 if (!inode)
59982 goto out;
59983
59984+#ifdef CONFIG_GRKERNSEC_PROC_USER
59985+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59986+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59987+ inode->i_gid = grsec_proc_gid;
59988+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59989+#else
59990 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59991+#endif
59992 inode->i_op = &proc_tgid_base_inode_operations;
59993 inode->i_fop = &proc_tgid_base_operations;
59994 inode->i_flags|=S_IMMUTABLE;
59995@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59996 if (!task)
59997 goto out;
59998
59999+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60000+ goto out_put_task;
60001+
60002 result = proc_pid_instantiate(dir, dentry, task, NULL);
60003+out_put_task:
60004 put_task_struct(task);
60005 out:
60006 return ERR_PTR(result);
60007@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
60008 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
60009 #endif
60010 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60011-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60012+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60013 INF("syscall", S_IRUGO, proc_pid_syscall),
60014 #endif
60015 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60016@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
60017 #ifdef CONFIG_SECURITY
60018 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60019 #endif
60020-#ifdef CONFIG_KALLSYMS
60021+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60022 INF("wchan", S_IRUGO, proc_pid_wchan),
60023 #endif
60024-#ifdef CONFIG_STACKTRACE
60025+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60026 ONE("stack", S_IRUGO, proc_pid_stack),
60027 #endif
60028 #ifdef CONFIG_SCHEDSTATS
60029diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
60030index 82676e3..5f8518a 100644
60031--- a/fs/proc/cmdline.c
60032+++ b/fs/proc/cmdline.c
60033@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
60034
60035 static int __init proc_cmdline_init(void)
60036 {
60037+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60038+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
60039+#else
60040 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
60041+#endif
60042 return 0;
60043 }
60044 module_init(proc_cmdline_init);
60045diff --git a/fs/proc/devices.c b/fs/proc/devices.c
60046index b143471..bb105e5 100644
60047--- a/fs/proc/devices.c
60048+++ b/fs/proc/devices.c
60049@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
60050
60051 static int __init proc_devices_init(void)
60052 {
60053+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60054+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
60055+#else
60056 proc_create("devices", 0, NULL, &proc_devinfo_operations);
60057+#endif
60058 return 0;
60059 }
60060 module_init(proc_devices_init);
60061diff --git a/fs/proc/fd.c b/fs/proc/fd.c
60062index 985ea88..d118a0a 100644
60063--- a/fs/proc/fd.c
60064+++ b/fs/proc/fd.c
60065@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
60066 if (!task)
60067 return -ENOENT;
60068
60069- files = get_files_struct(task);
60070+ if (!gr_acl_handle_procpidmem(task))
60071+ files = get_files_struct(task);
60072 put_task_struct(task);
60073
60074 if (files) {
60075@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
60076 */
60077 int proc_fd_permission(struct inode *inode, int mask)
60078 {
60079+ struct task_struct *task;
60080 int rv = generic_permission(inode, mask);
60081- if (rv == 0)
60082- return 0;
60083+
60084 if (task_tgid(current) == proc_pid(inode))
60085 rv = 0;
60086+
60087+ task = get_proc_task(inode);
60088+ if (task == NULL)
60089+ return rv;
60090+
60091+ if (gr_acl_handle_procpidmem(task))
60092+ rv = -EACCES;
60093+
60094+ put_task_struct(task);
60095+
60096 return rv;
60097 }
60098
60099diff --git a/fs/proc/inode.c b/fs/proc/inode.c
60100index 8eaa1ba..cc6ff42 100644
60101--- a/fs/proc/inode.c
60102+++ b/fs/proc/inode.c
60103@@ -23,11 +23,17 @@
60104 #include <linux/slab.h>
60105 #include <linux/mount.h>
60106 #include <linux/magic.h>
60107+#include <linux/grsecurity.h>
60108
60109 #include <asm/uaccess.h>
60110
60111 #include "internal.h"
60112
60113+#ifdef CONFIG_PROC_SYSCTL
60114+extern const struct inode_operations proc_sys_inode_operations;
60115+extern const struct inode_operations proc_sys_dir_operations;
60116+#endif
60117+
60118 static void proc_evict_inode(struct inode *inode)
60119 {
60120 struct proc_dir_entry *de;
60121@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
60122 ns = PROC_I(inode)->ns.ns;
60123 if (ns_ops && ns)
60124 ns_ops->put(ns);
60125+
60126+#ifdef CONFIG_PROC_SYSCTL
60127+ if (inode->i_op == &proc_sys_inode_operations ||
60128+ inode->i_op == &proc_sys_dir_operations)
60129+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
60130+#endif
60131+
60132 }
60133
60134 static struct kmem_cache * proc_inode_cachep;
60135@@ -405,7 +418,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
60136 if (de->mode) {
60137 inode->i_mode = de->mode;
60138 inode->i_uid = de->uid;
60139+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60140+ inode->i_gid = grsec_proc_gid;
60141+#else
60142 inode->i_gid = de->gid;
60143+#endif
60144 }
60145 if (de->size)
60146 inode->i_size = de->size;
60147diff --git a/fs/proc/internal.h b/fs/proc/internal.h
60148index 651d09a..60c73ae 100644
60149--- a/fs/proc/internal.h
60150+++ b/fs/proc/internal.h
60151@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
60152 struct pid *, struct task_struct *);
60153 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
60154 struct pid *, struct task_struct *);
60155+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60156+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
60157+#endif
60158
60159 /*
60160 * base.c
60161diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
60162index 06ea155..9a798c7 100644
60163--- a/fs/proc/kcore.c
60164+++ b/fs/proc/kcore.c
60165@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60166 * the addresses in the elf_phdr on our list.
60167 */
60168 start = kc_offset_to_vaddr(*fpos - elf_buflen);
60169- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
60170+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
60171+ if (tsz > buflen)
60172 tsz = buflen;
60173-
60174+
60175 while (buflen) {
60176 struct kcore_list *m;
60177
60178@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60179 kfree(elf_buf);
60180 } else {
60181 if (kern_addr_valid(start)) {
60182- unsigned long n;
60183+ char *elf_buf;
60184+ mm_segment_t oldfs;
60185
60186- n = copy_to_user(buffer, (char *)start, tsz);
60187- /*
60188- * We cannot distinguish between fault on source
60189- * and fault on destination. When this happens
60190- * we clear too and hope it will trigger the
60191- * EFAULT again.
60192- */
60193- if (n) {
60194- if (clear_user(buffer + tsz - n,
60195- n))
60196+ elf_buf = kmalloc(tsz, GFP_KERNEL);
60197+ if (!elf_buf)
60198+ return -ENOMEM;
60199+ oldfs = get_fs();
60200+ set_fs(KERNEL_DS);
60201+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
60202+ set_fs(oldfs);
60203+ if (copy_to_user(buffer, elf_buf, tsz)) {
60204+ kfree(elf_buf);
60205 return -EFAULT;
60206+ }
60207 }
60208+ set_fs(oldfs);
60209+ kfree(elf_buf);
60210 } else {
60211 if (clear_user(buffer, tsz))
60212 return -EFAULT;
60213@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60214
60215 static int open_kcore(struct inode *inode, struct file *filp)
60216 {
60217+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
60218+ return -EPERM;
60219+#endif
60220 if (!capable(CAP_SYS_RAWIO))
60221 return -EPERM;
60222 if (kcore_need_update)
60223diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
60224index 59d85d6..ac6fc05 100644
60225--- a/fs/proc/meminfo.c
60226+++ b/fs/proc/meminfo.c
60227@@ -153,7 +153,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
60228 vmi.used >> 10,
60229 vmi.largest_chunk >> 10
60230 #ifdef CONFIG_MEMORY_FAILURE
60231- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60232+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60233 #endif
60234 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
60235 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
60236diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
60237index ccfd99b..1b7e255 100644
60238--- a/fs/proc/nommu.c
60239+++ b/fs/proc/nommu.c
60240@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
60241 if (len < 1)
60242 len = 1;
60243 seq_printf(m, "%*c", len, ' ');
60244- seq_path(m, &file->f_path, "");
60245+ seq_path(m, &file->f_path, "\n\\");
60246 }
60247
60248 seq_putc(m, '\n');
60249diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
60250index 4677bb7..408e936 100644
60251--- a/fs/proc/proc_net.c
60252+++ b/fs/proc/proc_net.c
60253@@ -23,6 +23,7 @@
60254 #include <linux/nsproxy.h>
60255 #include <net/net_namespace.h>
60256 #include <linux/seq_file.h>
60257+#include <linux/grsecurity.h>
60258
60259 #include "internal.h"
60260
60261@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
60262 struct task_struct *task;
60263 struct nsproxy *ns;
60264 struct net *net = NULL;
60265+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60266+ const struct cred *cred = current_cred();
60267+#endif
60268+
60269+#ifdef CONFIG_GRKERNSEC_PROC_USER
60270+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
60271+ return net;
60272+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60273+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
60274+ return net;
60275+#endif
60276
60277 rcu_read_lock();
60278 task = pid_task(proc_pid(dir), PIDTYPE_PID);
60279diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
60280index 7129046..6914844 100644
60281--- a/fs/proc/proc_sysctl.c
60282+++ b/fs/proc/proc_sysctl.c
60283@@ -11,13 +11,21 @@
60284 #include <linux/namei.h>
60285 #include <linux/mm.h>
60286 #include <linux/module.h>
60287+#include <linux/nsproxy.h>
60288+#ifdef CONFIG_GRKERNSEC
60289+#include <net/net_namespace.h>
60290+#endif
60291 #include "internal.h"
60292
60293+extern int gr_handle_chroot_sysctl(const int op);
60294+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
60295+ const int op);
60296+
60297 static const struct dentry_operations proc_sys_dentry_operations;
60298 static const struct file_operations proc_sys_file_operations;
60299-static const struct inode_operations proc_sys_inode_operations;
60300+const struct inode_operations proc_sys_inode_operations;
60301 static const struct file_operations proc_sys_dir_file_operations;
60302-static const struct inode_operations proc_sys_dir_operations;
60303+const struct inode_operations proc_sys_dir_operations;
60304
60305 void proc_sys_poll_notify(struct ctl_table_poll *poll)
60306 {
60307@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
60308
60309 err = NULL;
60310 d_set_d_op(dentry, &proc_sys_dentry_operations);
60311+
60312+ gr_handle_proc_create(dentry, inode);
60313+
60314 d_add(dentry, inode);
60315
60316 out:
60317@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
60318 struct inode *inode = file_inode(filp);
60319 struct ctl_table_header *head = grab_header(inode);
60320 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
60321+ int op = write ? MAY_WRITE : MAY_READ;
60322 ssize_t error;
60323 size_t res;
60324
60325@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
60326 * and won't be until we finish.
60327 */
60328 error = -EPERM;
60329- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
60330+ if (sysctl_perm(head, table, op))
60331 goto out;
60332
60333 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
60334@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
60335 if (!table->proc_handler)
60336 goto out;
60337
60338+#ifdef CONFIG_GRKERNSEC
60339+ error = -EPERM;
60340+ if (gr_handle_chroot_sysctl(op))
60341+ goto out;
60342+ dget(filp->f_path.dentry);
60343+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
60344+ dput(filp->f_path.dentry);
60345+ goto out;
60346+ }
60347+ dput(filp->f_path.dentry);
60348+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
60349+ goto out;
60350+ if (write) {
60351+ if (current->nsproxy->net_ns != table->extra2) {
60352+ if (!capable(CAP_SYS_ADMIN))
60353+ goto out;
60354+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
60355+ goto out;
60356+ }
60357+#endif
60358+
60359 /* careful: calling conventions are nasty here */
60360 res = count;
60361 error = table->proc_handler(table, write, buf, &res, ppos);
60362@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
60363 return false;
60364 } else {
60365 d_set_d_op(child, &proc_sys_dentry_operations);
60366+
60367+ gr_handle_proc_create(child, inode);
60368+
60369 d_add(child, inode);
60370 }
60371 } else {
60372@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
60373 if ((*pos)++ < ctx->pos)
60374 return true;
60375
60376+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
60377+ return 0;
60378+
60379 if (unlikely(S_ISLNK(table->mode)))
60380 res = proc_sys_link_fill_cache(file, ctx, head, table);
60381 else
60382@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
60383 if (IS_ERR(head))
60384 return PTR_ERR(head);
60385
60386+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
60387+ return -ENOENT;
60388+
60389 generic_fillattr(inode, stat);
60390 if (table)
60391 stat->mode = (stat->mode & S_IFMT) | table->mode;
60392@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
60393 .llseek = generic_file_llseek,
60394 };
60395
60396-static const struct inode_operations proc_sys_inode_operations = {
60397+const struct inode_operations proc_sys_inode_operations = {
60398 .permission = proc_sys_permission,
60399 .setattr = proc_sys_setattr,
60400 .getattr = proc_sys_getattr,
60401 };
60402
60403-static const struct inode_operations proc_sys_dir_operations = {
60404+const struct inode_operations proc_sys_dir_operations = {
60405 .lookup = proc_sys_lookup,
60406 .permission = proc_sys_permission,
60407 .setattr = proc_sys_setattr,
60408@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
60409 static struct ctl_dir *new_dir(struct ctl_table_set *set,
60410 const char *name, int namelen)
60411 {
60412- struct ctl_table *table;
60413+ ctl_table_no_const *table;
60414 struct ctl_dir *new;
60415 struct ctl_node *node;
60416 char *new_name;
60417@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
60418 return NULL;
60419
60420 node = (struct ctl_node *)(new + 1);
60421- table = (struct ctl_table *)(node + 1);
60422+ table = (ctl_table_no_const *)(node + 1);
60423 new_name = (char *)(table + 2);
60424 memcpy(new_name, name, namelen);
60425 new_name[namelen] = '\0';
60426@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
60427 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
60428 struct ctl_table_root *link_root)
60429 {
60430- struct ctl_table *link_table, *entry, *link;
60431+ ctl_table_no_const *link_table, *link;
60432+ struct ctl_table *entry;
60433 struct ctl_table_header *links;
60434 struct ctl_node *node;
60435 char *link_name;
60436@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
60437 return NULL;
60438
60439 node = (struct ctl_node *)(links + 1);
60440- link_table = (struct ctl_table *)(node + nr_entries);
60441+ link_table = (ctl_table_no_const *)(node + nr_entries);
60442 link_name = (char *)&link_table[nr_entries + 1];
60443
60444 for (link = link_table, entry = table; entry->procname; link++, entry++) {
60445@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60446 struct ctl_table_header ***subheader, struct ctl_table_set *set,
60447 struct ctl_table *table)
60448 {
60449- struct ctl_table *ctl_table_arg = NULL;
60450- struct ctl_table *entry, *files;
60451+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
60452+ struct ctl_table *entry;
60453 int nr_files = 0;
60454 int nr_dirs = 0;
60455 int err = -ENOMEM;
60456@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60457 nr_files++;
60458 }
60459
60460- files = table;
60461 /* If there are mixed files and directories we need a new table */
60462 if (nr_dirs && nr_files) {
60463- struct ctl_table *new;
60464+ ctl_table_no_const *new;
60465 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
60466 GFP_KERNEL);
60467 if (!files)
60468@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60469 /* Register everything except a directory full of subdirectories */
60470 if (nr_files || !nr_dirs) {
60471 struct ctl_table_header *header;
60472- header = __register_sysctl_table(set, path, files);
60473+ header = __register_sysctl_table(set, path, files ? files : table);
60474 if (!header) {
60475 kfree(ctl_table_arg);
60476 goto out;
60477diff --git a/fs/proc/root.c b/fs/proc/root.c
60478index 87dbcbe..55e1b4d 100644
60479--- a/fs/proc/root.c
60480+++ b/fs/proc/root.c
60481@@ -186,7 +186,15 @@ void __init proc_root_init(void)
60482 #ifdef CONFIG_PROC_DEVICETREE
60483 proc_device_tree_init();
60484 #endif
60485+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60486+#ifdef CONFIG_GRKERNSEC_PROC_USER
60487+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
60488+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60489+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
60490+#endif
60491+#else
60492 proc_mkdir("bus", NULL);
60493+#endif
60494 proc_sys_init();
60495 }
60496
60497diff --git a/fs/proc/self.c b/fs/proc/self.c
60498index 6b6a993..807cccc 100644
60499--- a/fs/proc/self.c
60500+++ b/fs/proc/self.c
60501@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
60502 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
60503 void *cookie)
60504 {
60505- char *s = nd_get_link(nd);
60506+ const char *s = nd_get_link(nd);
60507 if (!IS_ERR(s))
60508 kfree(s);
60509 }
60510diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
60511index 390bdab..83c1e8a 100644
60512--- a/fs/proc/task_mmu.c
60513+++ b/fs/proc/task_mmu.c
60514@@ -12,12 +12,19 @@
60515 #include <linux/swap.h>
60516 #include <linux/swapops.h>
60517 #include <linux/mmu_notifier.h>
60518+#include <linux/grsecurity.h>
60519
60520 #include <asm/elf.h>
60521 #include <asm/uaccess.h>
60522 #include <asm/tlbflush.h>
60523 #include "internal.h"
60524
60525+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60526+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60527+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60528+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60529+#endif
60530+
60531 void task_mem(struct seq_file *m, struct mm_struct *mm)
60532 {
60533 unsigned long data, text, lib, swap;
60534@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60535 "VmExe:\t%8lu kB\n"
60536 "VmLib:\t%8lu kB\n"
60537 "VmPTE:\t%8lu kB\n"
60538- "VmSwap:\t%8lu kB\n",
60539- hiwater_vm << (PAGE_SHIFT-10),
60540+ "VmSwap:\t%8lu kB\n"
60541+
60542+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60543+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
60544+#endif
60545+
60546+ ,hiwater_vm << (PAGE_SHIFT-10),
60547 total_vm << (PAGE_SHIFT-10),
60548 mm->locked_vm << (PAGE_SHIFT-10),
60549 mm->pinned_vm << (PAGE_SHIFT-10),
60550@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60551 data << (PAGE_SHIFT-10),
60552 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
60553 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
60554- swap << (PAGE_SHIFT-10));
60555+ swap << (PAGE_SHIFT-10)
60556+
60557+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60558+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60559+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
60560+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
60561+#else
60562+ , mm->context.user_cs_base
60563+ , mm->context.user_cs_limit
60564+#endif
60565+#endif
60566+
60567+ );
60568 }
60569
60570 unsigned long task_vsize(struct mm_struct *mm)
60571@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60572 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60573 }
60574
60575- /* We don't show the stack guard page in /proc/maps */
60576+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60577+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60578+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60579+#else
60580 start = vma->vm_start;
60581- if (stack_guard_page_start(vma, start))
60582- start += PAGE_SIZE;
60583 end = vma->vm_end;
60584- if (stack_guard_page_end(vma, end))
60585- end -= PAGE_SIZE;
60586+#endif
60587
60588 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60589 start,
60590@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60591 flags & VM_WRITE ? 'w' : '-',
60592 flags & VM_EXEC ? 'x' : '-',
60593 flags & VM_MAYSHARE ? 's' : 'p',
60594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60595+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60596+#else
60597 pgoff,
60598+#endif
60599 MAJOR(dev), MINOR(dev), ino, &len);
60600
60601 /*
60602@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60603 */
60604 if (file) {
60605 pad_len_spaces(m, len);
60606- seq_path(m, &file->f_path, "\n");
60607+ seq_path(m, &file->f_path, "\n\\");
60608 goto done;
60609 }
60610
60611@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60612 * Thread stack in /proc/PID/task/TID/maps or
60613 * the main process stack.
60614 */
60615- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60616- vma->vm_end >= mm->start_stack)) {
60617+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60618+ (vma->vm_start <= mm->start_stack &&
60619+ vma->vm_end >= mm->start_stack)) {
60620 name = "[stack]";
60621 } else {
60622 /* Thread stack in /proc/PID/maps */
60623@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60624 struct proc_maps_private *priv = m->private;
60625 struct task_struct *task = priv->task;
60626
60627+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60628+ if (current->exec_id != m->exec_id) {
60629+ gr_log_badprocpid("maps");
60630+ return 0;
60631+ }
60632+#endif
60633+
60634 show_map_vma(m, vma, is_pid);
60635
60636 if (m->count < m->size) /* vma is copied successfully */
60637@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60638 .private = &mss,
60639 };
60640
60641+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60642+ if (current->exec_id != m->exec_id) {
60643+ gr_log_badprocpid("smaps");
60644+ return 0;
60645+ }
60646+#endif
60647 memset(&mss, 0, sizeof mss);
60648- mss.vma = vma;
60649- /* mmap_sem is held in m_start */
60650- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60651- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60652-
60653+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60654+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60655+#endif
60656+ mss.vma = vma;
60657+ /* mmap_sem is held in m_start */
60658+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60659+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60660+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60661+ }
60662+#endif
60663 show_map_vma(m, vma, is_pid);
60664
60665 seq_printf(m,
60666@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60667 "KernelPageSize: %8lu kB\n"
60668 "MMUPageSize: %8lu kB\n"
60669 "Locked: %8lu kB\n",
60670+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60671+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60672+#else
60673 (vma->vm_end - vma->vm_start) >> 10,
60674+#endif
60675 mss.resident >> 10,
60676 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60677 mss.shared_clean >> 10,
60678@@ -1390,6 +1441,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60679 int n;
60680 char buffer[50];
60681
60682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60683+ if (current->exec_id != m->exec_id) {
60684+ gr_log_badprocpid("numa_maps");
60685+ return 0;
60686+ }
60687+#endif
60688+
60689 if (!mm)
60690 return 0;
60691
60692@@ -1409,11 +1467,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60693 if (n < 0)
60694 return n;
60695
60696+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60697+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60698+#else
60699 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60700+#endif
60701
60702 if (file) {
60703 seq_printf(m, " file=");
60704- seq_path(m, &file->f_path, "\n\t= ");
60705+ seq_path(m, &file->f_path, "\n\t\\= ");
60706 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60707 seq_printf(m, " heap");
60708 } else {
60709diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60710index 56123a6..5a2f6ec 100644
60711--- a/fs/proc/task_nommu.c
60712+++ b/fs/proc/task_nommu.c
60713@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60714 else
60715 bytes += kobjsize(mm);
60716
60717- if (current->fs && current->fs->users > 1)
60718+ if (current->fs && atomic_read(&current->fs->users) > 1)
60719 sbytes += kobjsize(current->fs);
60720 else
60721 bytes += kobjsize(current->fs);
60722@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60723
60724 if (file) {
60725 pad_len_spaces(m, len);
60726- seq_path(m, &file->f_path, "");
60727+ seq_path(m, &file->f_path, "\n\\");
60728 } else if (mm) {
60729 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60730
60731diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60732index 9100d69..f1f9fc9 100644
60733--- a/fs/proc/vmcore.c
60734+++ b/fs/proc/vmcore.c
60735@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60736 nr_bytes = count;
60737
60738 /* If pfn is not ram, return zeros for sparse dump files */
60739- if (pfn_is_ram(pfn) == 0)
60740- memset(buf, 0, nr_bytes);
60741- else {
60742+ if (pfn_is_ram(pfn) == 0) {
60743+ if (userbuf) {
60744+ if (clear_user((char __force_user *)buf, nr_bytes))
60745+ return -EFAULT;
60746+ } else
60747+ memset(buf, 0, nr_bytes);
60748+ } else {
60749 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60750 offset, userbuf);
60751 if (tmp < 0)
60752@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
60753 if (*fpos < m->offset + m->size) {
60754 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60755 start = m->paddr + *fpos - m->offset;
60756- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
60757+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
60758 if (tmp < 0)
60759 return tmp;
60760 buflen -= tsz;
60761diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60762index b00fcc9..e0c6381 100644
60763--- a/fs/qnx6/qnx6.h
60764+++ b/fs/qnx6/qnx6.h
60765@@ -74,7 +74,7 @@ enum {
60766 BYTESEX_BE,
60767 };
60768
60769-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60770+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60771 {
60772 if (sbi->s_bytesex == BYTESEX_LE)
60773 return le64_to_cpu((__force __le64)n);
60774@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60775 return (__force __fs64)cpu_to_be64(n);
60776 }
60777
60778-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60779+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60780 {
60781 if (sbi->s_bytesex == BYTESEX_LE)
60782 return le32_to_cpu((__force __le32)n);
60783diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60784index 16e8abb..2dcf914 100644
60785--- a/fs/quota/netlink.c
60786+++ b/fs/quota/netlink.c
60787@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60788 void quota_send_warning(struct kqid qid, dev_t dev,
60789 const char warntype)
60790 {
60791- static atomic_t seq;
60792+ static atomic_unchecked_t seq;
60793 struct sk_buff *skb;
60794 void *msg_head;
60795 int ret;
60796@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60797 "VFS: Not enough memory to send quota warning.\n");
60798 return;
60799 }
60800- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60801+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60802 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60803 if (!msg_head) {
60804 printk(KERN_ERR
60805diff --git a/fs/read_write.c b/fs/read_write.c
60806index e3cd280..a378473 100644
60807--- a/fs/read_write.c
60808+++ b/fs/read_write.c
60809@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60810
60811 old_fs = get_fs();
60812 set_fs(get_ds());
60813- p = (__force const char __user *)buf;
60814+ p = (const char __force_user *)buf;
60815 if (count > MAX_RW_COUNT)
60816 count = MAX_RW_COUNT;
60817 if (file->f_op->write)
60818diff --git a/fs/readdir.c b/fs/readdir.c
60819index 93d71e5..6a14be8 100644
60820--- a/fs/readdir.c
60821+++ b/fs/readdir.c
60822@@ -17,6 +17,7 @@
60823 #include <linux/security.h>
60824 #include <linux/syscalls.h>
60825 #include <linux/unistd.h>
60826+#include <linux/namei.h>
60827
60828 #include <asm/uaccess.h>
60829
60830@@ -69,6 +70,7 @@ struct old_linux_dirent {
60831 struct readdir_callback {
60832 struct dir_context ctx;
60833 struct old_linux_dirent __user * dirent;
60834+ struct file * file;
60835 int result;
60836 };
60837
60838@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60839 buf->result = -EOVERFLOW;
60840 return -EOVERFLOW;
60841 }
60842+
60843+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60844+ return 0;
60845+
60846 buf->result++;
60847 dirent = buf->dirent;
60848 if (!access_ok(VERIFY_WRITE, dirent,
60849@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60850 if (!f.file)
60851 return -EBADF;
60852
60853+ buf.file = f.file;
60854 error = iterate_dir(f.file, &buf.ctx);
60855 if (buf.result)
60856 error = buf.result;
60857@@ -142,6 +149,7 @@ struct getdents_callback {
60858 struct dir_context ctx;
60859 struct linux_dirent __user * current_dir;
60860 struct linux_dirent __user * previous;
60861+ struct file * file;
60862 int count;
60863 int error;
60864 };
60865@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60866 buf->error = -EOVERFLOW;
60867 return -EOVERFLOW;
60868 }
60869+
60870+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60871+ return 0;
60872+
60873 dirent = buf->previous;
60874 if (dirent) {
60875 if (__put_user(offset, &dirent->d_off))
60876@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60877 if (!f.file)
60878 return -EBADF;
60879
60880+ buf.file = f.file;
60881 error = iterate_dir(f.file, &buf.ctx);
60882 if (error >= 0)
60883 error = buf.error;
60884@@ -226,6 +239,7 @@ struct getdents_callback64 {
60885 struct dir_context ctx;
60886 struct linux_dirent64 __user * current_dir;
60887 struct linux_dirent64 __user * previous;
60888+ struct file *file;
60889 int count;
60890 int error;
60891 };
60892@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60893 buf->error = -EINVAL; /* only used if we fail.. */
60894 if (reclen > buf->count)
60895 return -EINVAL;
60896+
60897+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60898+ return 0;
60899+
60900 dirent = buf->previous;
60901 if (dirent) {
60902 if (__put_user(offset, &dirent->d_off))
60903@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60904 if (!f.file)
60905 return -EBADF;
60906
60907+ buf.file = f.file;
60908 error = iterate_dir(f.file, &buf.ctx);
60909 if (error >= 0)
60910 error = buf.error;
60911diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60912index 2b7882b..1c5ef48 100644
60913--- a/fs/reiserfs/do_balan.c
60914+++ b/fs/reiserfs/do_balan.c
60915@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60916 return;
60917 }
60918
60919- atomic_inc(&(fs_generation(tb->tb_sb)));
60920+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60921 do_balance_starts(tb);
60922
60923 /* balance leaf returns 0 except if combining L R and S into
60924diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60925index a958444..42b2323 100644
60926--- a/fs/reiserfs/procfs.c
60927+++ b/fs/reiserfs/procfs.c
60928@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60929 "SMALL_TAILS " : "NO_TAILS ",
60930 replay_only(sb) ? "REPLAY_ONLY " : "",
60931 convert_reiserfs(sb) ? "CONV " : "",
60932- atomic_read(&r->s_generation_counter),
60933+ atomic_read_unchecked(&r->s_generation_counter),
60934 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60935 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60936 SF(s_good_search_by_key_reada), SF(s_bmaps),
60937diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60938index f8adaee..0eeeeca 100644
60939--- a/fs/reiserfs/reiserfs.h
60940+++ b/fs/reiserfs/reiserfs.h
60941@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60942 /* Comment? -Hans */
60943 wait_queue_head_t s_wait;
60944 /* To be obsoleted soon by per buffer seals.. -Hans */
60945- atomic_t s_generation_counter; // increased by one every time the
60946+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60947 // tree gets re-balanced
60948 unsigned long s_properties; /* File system properties. Currently holds
60949 on-disk FS format */
60950@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60951 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60952
60953 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60954-#define get_generation(s) atomic_read (&fs_generation(s))
60955+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60956 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60957 #define __fs_changed(gen,s) (gen != get_generation (s))
60958 #define fs_changed(gen,s) \
60959diff --git a/fs/select.c b/fs/select.c
60960index dfd5cb1..1754d57 100644
60961--- a/fs/select.c
60962+++ b/fs/select.c
60963@@ -20,6 +20,7 @@
60964 #include <linux/export.h>
60965 #include <linux/slab.h>
60966 #include <linux/poll.h>
60967+#include <linux/security.h>
60968 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60969 #include <linux/file.h>
60970 #include <linux/fdtable.h>
60971@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60972 struct poll_list *walk = head;
60973 unsigned long todo = nfds;
60974
60975+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60976 if (nfds > rlimit(RLIMIT_NOFILE))
60977 return -EINVAL;
60978
60979diff --git a/fs/seq_file.c b/fs/seq_file.c
60980index a290157..ec3211a 100644
60981--- a/fs/seq_file.c
60982+++ b/fs/seq_file.c
60983@@ -10,6 +10,7 @@
60984 #include <linux/seq_file.h>
60985 #include <linux/slab.h>
60986 #include <linux/cred.h>
60987+#include <linux/sched.h>
60988
60989 #include <asm/uaccess.h>
60990 #include <asm/page.h>
60991@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60992 #ifdef CONFIG_USER_NS
60993 p->user_ns = file->f_cred->user_ns;
60994 #endif
60995+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60996+ p->exec_id = current->exec_id;
60997+#endif
60998
60999 /*
61000 * Wrappers around seq_open(e.g. swaps_open) need to be
61001@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61002 return 0;
61003 }
61004 if (!m->buf) {
61005- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61006+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61007 if (!m->buf)
61008 return -ENOMEM;
61009 }
61010@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61011 Eoverflow:
61012 m->op->stop(m, p);
61013 kfree(m->buf);
61014- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61015+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61016 return !m->buf ? -ENOMEM : -EAGAIN;
61017 }
61018
61019@@ -152,7 +156,7 @@ Eoverflow:
61020 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61021 {
61022 struct seq_file *m = file->private_data;
61023- size_t copied = 0;
61024+ ssize_t copied = 0;
61025 loff_t pos;
61026 size_t n;
61027 void *p;
61028@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61029
61030 /* grab buffer if we didn't have one */
61031 if (!m->buf) {
61032- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61033+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61034 if (!m->buf)
61035 goto Enomem;
61036 }
61037@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61038 goto Fill;
61039 m->op->stop(m, p);
61040 kfree(m->buf);
61041- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61042+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61043 if (!m->buf)
61044 goto Enomem;
61045 m->count = 0;
61046@@ -583,7 +587,7 @@ static void single_stop(struct seq_file *p, void *v)
61047 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
61048 void *data)
61049 {
61050- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
61051+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
61052 int res = -ENOMEM;
61053
61054 if (op) {
61055diff --git a/fs/splice.c b/fs/splice.c
61056index 3b7ee65..87fc2e4 100644
61057--- a/fs/splice.c
61058+++ b/fs/splice.c
61059@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61060 pipe_lock(pipe);
61061
61062 for (;;) {
61063- if (!pipe->readers) {
61064+ if (!atomic_read(&pipe->readers)) {
61065 send_sig(SIGPIPE, current, 0);
61066 if (!ret)
61067 ret = -EPIPE;
61068@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61069 page_nr++;
61070 ret += buf->len;
61071
61072- if (pipe->files)
61073+ if (atomic_read(&pipe->files))
61074 do_wakeup = 1;
61075
61076 if (!--spd->nr_pages)
61077@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61078 do_wakeup = 0;
61079 }
61080
61081- pipe->waiting_writers++;
61082+ atomic_inc(&pipe->waiting_writers);
61083 pipe_wait(pipe);
61084- pipe->waiting_writers--;
61085+ atomic_dec(&pipe->waiting_writers);
61086 }
61087
61088 pipe_unlock(pipe);
61089@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
61090 old_fs = get_fs();
61091 set_fs(get_ds());
61092 /* The cast to a user pointer is valid due to the set_fs() */
61093- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
61094+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
61095 set_fs(old_fs);
61096
61097 return res;
61098@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
61099 old_fs = get_fs();
61100 set_fs(get_ds());
61101 /* The cast to a user pointer is valid due to the set_fs() */
61102- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
61103+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
61104 set_fs(old_fs);
61105
61106 return res;
61107@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
61108 goto err;
61109
61110 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
61111- vec[i].iov_base = (void __user *) page_address(page);
61112+ vec[i].iov_base = (void __force_user *) page_address(page);
61113 vec[i].iov_len = this_len;
61114 spd.pages[i] = page;
61115 spd.nr_pages++;
61116@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
61117 ops->release(pipe, buf);
61118 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
61119 pipe->nrbufs--;
61120- if (pipe->files)
61121+ if (atomic_read(&pipe->files))
61122 sd->need_wakeup = true;
61123 }
61124
61125@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
61126 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
61127 {
61128 while (!pipe->nrbufs) {
61129- if (!pipe->writers)
61130+ if (!atomic_read(&pipe->writers))
61131 return 0;
61132
61133- if (!pipe->waiting_writers && sd->num_spliced)
61134+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
61135 return 0;
61136
61137 if (sd->flags & SPLICE_F_NONBLOCK)
61138@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
61139 * out of the pipe right after the splice_to_pipe(). So set
61140 * PIPE_READERS appropriately.
61141 */
61142- pipe->readers = 1;
61143+ atomic_set(&pipe->readers, 1);
61144
61145 current->splice_pipe = pipe;
61146 }
61147@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
61148
61149 partial[buffers].offset = off;
61150 partial[buffers].len = plen;
61151+ partial[buffers].private = 0;
61152
61153 off = 0;
61154 len -= plen;
61155@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61156 ret = -ERESTARTSYS;
61157 break;
61158 }
61159- if (!pipe->writers)
61160+ if (!atomic_read(&pipe->writers))
61161 break;
61162- if (!pipe->waiting_writers) {
61163+ if (!atomic_read(&pipe->waiting_writers)) {
61164 if (flags & SPLICE_F_NONBLOCK) {
61165 ret = -EAGAIN;
61166 break;
61167@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61168 pipe_lock(pipe);
61169
61170 while (pipe->nrbufs >= pipe->buffers) {
61171- if (!pipe->readers) {
61172+ if (!atomic_read(&pipe->readers)) {
61173 send_sig(SIGPIPE, current, 0);
61174 ret = -EPIPE;
61175 break;
61176@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61177 ret = -ERESTARTSYS;
61178 break;
61179 }
61180- pipe->waiting_writers++;
61181+ atomic_inc(&pipe->waiting_writers);
61182 pipe_wait(pipe);
61183- pipe->waiting_writers--;
61184+ atomic_dec(&pipe->waiting_writers);
61185 }
61186
61187 pipe_unlock(pipe);
61188@@ -1862,14 +1863,14 @@ retry:
61189 pipe_double_lock(ipipe, opipe);
61190
61191 do {
61192- if (!opipe->readers) {
61193+ if (!atomic_read(&opipe->readers)) {
61194 send_sig(SIGPIPE, current, 0);
61195 if (!ret)
61196 ret = -EPIPE;
61197 break;
61198 }
61199
61200- if (!ipipe->nrbufs && !ipipe->writers)
61201+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
61202 break;
61203
61204 /*
61205@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61206 pipe_double_lock(ipipe, opipe);
61207
61208 do {
61209- if (!opipe->readers) {
61210+ if (!atomic_read(&opipe->readers)) {
61211 send_sig(SIGPIPE, current, 0);
61212 if (!ret)
61213 ret = -EPIPE;
61214@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61215 * return EAGAIN if we have the potential of some data in the
61216 * future, otherwise just return 0
61217 */
61218- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
61219+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
61220 ret = -EAGAIN;
61221
61222 pipe_unlock(ipipe);
61223diff --git a/fs/stat.c b/fs/stat.c
61224index d0ea7ef..f463f9d 100644
61225--- a/fs/stat.c
61226+++ b/fs/stat.c
61227@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
61228 stat->gid = inode->i_gid;
61229 stat->rdev = inode->i_rdev;
61230 stat->size = i_size_read(inode);
61231- stat->atime = inode->i_atime;
61232- stat->mtime = inode->i_mtime;
61233+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61234+ stat->atime = inode->i_ctime;
61235+ stat->mtime = inode->i_ctime;
61236+ } else {
61237+ stat->atime = inode->i_atime;
61238+ stat->mtime = inode->i_mtime;
61239+ }
61240 stat->ctime = inode->i_ctime;
61241 stat->blksize = (1 << inode->i_blkbits);
61242 stat->blocks = inode->i_blocks;
61243@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
61244 if (retval)
61245 return retval;
61246
61247- if (inode->i_op->getattr)
61248- return inode->i_op->getattr(path->mnt, path->dentry, stat);
61249+ if (inode->i_op->getattr) {
61250+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
61251+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61252+ stat->atime = stat->ctime;
61253+ stat->mtime = stat->ctime;
61254+ }
61255+ return retval;
61256+ }
61257
61258 generic_fillattr(inode, stat);
61259 return 0;
61260diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
61261index c590cab..6dfd6fc 100644
61262--- a/fs/sysfs/bin.c
61263+++ b/fs/sysfs/bin.c
61264@@ -234,13 +234,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
61265 return ret;
61266 }
61267
61268-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
61269- void *buf, int len, int write)
61270+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
61271+ void *buf, size_t len, int write)
61272 {
61273 struct file *file = vma->vm_file;
61274 struct bin_buffer *bb = file->private_data;
61275 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
61276- int ret;
61277+ ssize_t ret;
61278
61279 if (!bb->vm_ops)
61280 return -EINVAL;
61281diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
61282index 4d83ced..049dc45 100644
61283--- a/fs/sysfs/dir.c
61284+++ b/fs/sysfs/dir.c
61285@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
61286 *
61287 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61288 */
61289-static unsigned int sysfs_name_hash(const void *ns, const char *name)
61290+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
61291 {
61292 unsigned long hash = init_name_hash();
61293 unsigned int len = strlen(name);
61294@@ -675,6 +675,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
61295 struct sysfs_dirent *sd;
61296 int rc;
61297
61298+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61299+ const char *parent_name = parent_sd->s_name;
61300+
61301+ mode = S_IFDIR | S_IRWXU;
61302+
61303+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
61304+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
61305+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
61306+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
61307+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
61308+#endif
61309+
61310 /* allocate */
61311 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
61312 if (!sd)
61313diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
61314index 15ef5eb..e474372 100644
61315--- a/fs/sysfs/file.c
61316+++ b/fs/sysfs/file.c
61317@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
61318
61319 struct sysfs_open_dirent {
61320 atomic_t refcnt;
61321- atomic_t event;
61322+ atomic_unchecked_t event;
61323 wait_queue_head_t poll;
61324 struct list_head buffers; /* goes through sysfs_buffer.list */
61325 };
61326@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
61327 if (!sysfs_get_active(attr_sd))
61328 return -ENODEV;
61329
61330- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
61331+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
61332 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
61333
61334 sysfs_put_active(attr_sd);
61335@@ -284,7 +284,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
61336 return -ENOMEM;
61337
61338 atomic_set(&new_od->refcnt, 0);
61339- atomic_set(&new_od->event, 1);
61340+ atomic_set_unchecked(&new_od->event, 1);
61341 init_waitqueue_head(&new_od->poll);
61342 INIT_LIST_HEAD(&new_od->buffers);
61343 goto retry;
61344@@ -430,7 +430,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
61345
61346 sysfs_put_active(attr_sd);
61347
61348- if (buffer->event != atomic_read(&od->event))
61349+ if (buffer->event != atomic_read_unchecked(&od->event))
61350 goto trigger;
61351
61352 return DEFAULT_POLLMASK;
61353@@ -450,7 +450,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
61354 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
61355 od = sd->s_attr.open;
61356 if (od) {
61357- atomic_inc(&od->event);
61358+ atomic_inc_unchecked(&od->event);
61359 wake_up_interruptible(&od->poll);
61360 }
61361 }
61362diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
61363index 2dd4507..62a215a 100644
61364--- a/fs/sysfs/symlink.c
61365+++ b/fs/sysfs/symlink.c
61366@@ -308,7 +308,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61367 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
61368 void *cookie)
61369 {
61370- char *page = nd_get_link(nd);
61371+ const char *page = nd_get_link(nd);
61372 if (!IS_ERR(page))
61373 free_page((unsigned long)page);
61374 }
61375diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
61376index 69d4889..a810bd4 100644
61377--- a/fs/sysv/sysv.h
61378+++ b/fs/sysv/sysv.h
61379@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
61380 #endif
61381 }
61382
61383-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
61384+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
61385 {
61386 if (sbi->s_bytesex == BYTESEX_PDP)
61387 return PDP_swab((__force __u32)n);
61388diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
61389index e18b988..f1d4ad0f 100644
61390--- a/fs/ubifs/io.c
61391+++ b/fs/ubifs/io.c
61392@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
61393 return err;
61394 }
61395
61396-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
61397+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
61398 {
61399 int err;
61400
61401diff --git a/fs/udf/misc.c b/fs/udf/misc.c
61402index c175b4d..8f36a16 100644
61403--- a/fs/udf/misc.c
61404+++ b/fs/udf/misc.c
61405@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
61406
61407 u8 udf_tag_checksum(const struct tag *t)
61408 {
61409- u8 *data = (u8 *)t;
61410+ const u8 *data = (const u8 *)t;
61411 u8 checksum = 0;
61412 int i;
61413 for (i = 0; i < sizeof(struct tag); ++i)
61414diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
61415index 8d974c4..b82f6ec 100644
61416--- a/fs/ufs/swab.h
61417+++ b/fs/ufs/swab.h
61418@@ -22,7 +22,7 @@ enum {
61419 BYTESEX_BE
61420 };
61421
61422-static inline u64
61423+static inline u64 __intentional_overflow(-1)
61424 fs64_to_cpu(struct super_block *sbp, __fs64 n)
61425 {
61426 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
61427@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
61428 return (__force __fs64)cpu_to_be64(n);
61429 }
61430
61431-static inline u32
61432+static inline u32 __intentional_overflow(-1)
61433 fs32_to_cpu(struct super_block *sbp, __fs32 n)
61434 {
61435 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
61436diff --git a/fs/utimes.c b/fs/utimes.c
61437index f4fb7ec..3fe03c0 100644
61438--- a/fs/utimes.c
61439+++ b/fs/utimes.c
61440@@ -1,6 +1,7 @@
61441 #include <linux/compiler.h>
61442 #include <linux/file.h>
61443 #include <linux/fs.h>
61444+#include <linux/security.h>
61445 #include <linux/linkage.h>
61446 #include <linux/mount.h>
61447 #include <linux/namei.h>
61448@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
61449 goto mnt_drop_write_and_out;
61450 }
61451 }
61452+
61453+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
61454+ error = -EACCES;
61455+ goto mnt_drop_write_and_out;
61456+ }
61457+
61458 mutex_lock(&inode->i_mutex);
61459 error = notify_change(path->dentry, &newattrs);
61460 mutex_unlock(&inode->i_mutex);
61461diff --git a/fs/xattr.c b/fs/xattr.c
61462index 3377dff..4d074d9 100644
61463--- a/fs/xattr.c
61464+++ b/fs/xattr.c
61465@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
61466 return rc;
61467 }
61468
61469+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
61470+ssize_t
61471+pax_getxattr(struct dentry *dentry, void *value, size_t size)
61472+{
61473+ struct inode *inode = dentry->d_inode;
61474+ ssize_t error;
61475+
61476+ error = inode_permission(inode, MAY_EXEC);
61477+ if (error)
61478+ return error;
61479+
61480+ if (inode->i_op->getxattr)
61481+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
61482+ else
61483+ error = -EOPNOTSUPP;
61484+
61485+ return error;
61486+}
61487+EXPORT_SYMBOL(pax_getxattr);
61488+#endif
61489+
61490 ssize_t
61491 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
61492 {
61493@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
61494 * Extended attribute SET operations
61495 */
61496 static long
61497-setxattr(struct dentry *d, const char __user *name, const void __user *value,
61498+setxattr(struct path *path, const char __user *name, const void __user *value,
61499 size_t size, int flags)
61500 {
61501 int error;
61502@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
61503 posix_acl_fix_xattr_from_user(kvalue, size);
61504 }
61505
61506- error = vfs_setxattr(d, kname, kvalue, size, flags);
61507+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
61508+ error = -EACCES;
61509+ goto out;
61510+ }
61511+
61512+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
61513 out:
61514 if (vvalue)
61515 vfree(vvalue);
61516@@ -377,7 +403,7 @@ retry:
61517 return error;
61518 error = mnt_want_write(path.mnt);
61519 if (!error) {
61520- error = setxattr(path.dentry, name, value, size, flags);
61521+ error = setxattr(&path, name, value, size, flags);
61522 mnt_drop_write(path.mnt);
61523 }
61524 path_put(&path);
61525@@ -401,7 +427,7 @@ retry:
61526 return error;
61527 error = mnt_want_write(path.mnt);
61528 if (!error) {
61529- error = setxattr(path.dentry, name, value, size, flags);
61530+ error = setxattr(&path, name, value, size, flags);
61531 mnt_drop_write(path.mnt);
61532 }
61533 path_put(&path);
61534@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
61535 const void __user *,value, size_t, size, int, flags)
61536 {
61537 struct fd f = fdget(fd);
61538- struct dentry *dentry;
61539 int error = -EBADF;
61540
61541 if (!f.file)
61542 return error;
61543- dentry = f.file->f_path.dentry;
61544- audit_inode(NULL, dentry, 0);
61545+ audit_inode(NULL, f.file->f_path.dentry, 0);
61546 error = mnt_want_write_file(f.file);
61547 if (!error) {
61548- error = setxattr(dentry, name, value, size, flags);
61549+ error = setxattr(&f.file->f_path, name, value, size, flags);
61550 mnt_drop_write_file(f.file);
61551 }
61552 fdput(f);
61553diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
61554index 9fbea87..6b19972 100644
61555--- a/fs/xattr_acl.c
61556+++ b/fs/xattr_acl.c
61557@@ -76,8 +76,8 @@ struct posix_acl *
61558 posix_acl_from_xattr(struct user_namespace *user_ns,
61559 const void *value, size_t size)
61560 {
61561- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
61562- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
61563+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
61564+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
61565 int count;
61566 struct posix_acl *acl;
61567 struct posix_acl_entry *acl_e;
61568diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
61569index f47e65c..e7125d9 100644
61570--- a/fs/xfs/xfs_bmap.c
61571+++ b/fs/xfs/xfs_bmap.c
61572@@ -586,7 +586,7 @@ xfs_bmap_validate_ret(
61573
61574 #else
61575 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
61576-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
61577+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
61578 #endif /* DEBUG */
61579
61580 /*
61581diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
61582index 8f84153..7ce60d0 100644
61583--- a/fs/xfs/xfs_dir2_readdir.c
61584+++ b/fs/xfs/xfs_dir2_readdir.c
61585@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
61586 ino = xfs_dir3_sfe_get_ino(mp, sfp, sfep);
61587 filetype = xfs_dir3_sfe_get_ftype(mp, sfp, sfep);
61588 ctx->pos = off & 0x7fffffff;
61589- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
61590+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61591+ char name[sfep->namelen];
61592+ memcpy(name, sfep->name, sfep->namelen);
61593+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
61594+ return 0;
61595+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
61596 xfs_dir3_get_dtype(mp, filetype)))
61597 return 0;
61598 sfep = xfs_dir3_sf_nextentry(mp, sfp, sfep);
61599diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61600index 668e8f4..9d38104 100644
61601--- a/fs/xfs/xfs_ioctl.c
61602+++ b/fs/xfs/xfs_ioctl.c
61603@@ -127,7 +127,7 @@ xfs_find_handle(
61604 }
61605
61606 error = -EFAULT;
61607- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61608+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61609 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61610 goto out_put;
61611
61612diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61613index 2b8952d..a60c6be 100644
61614--- a/fs/xfs/xfs_iops.c
61615+++ b/fs/xfs/xfs_iops.c
61616@@ -401,7 +401,7 @@ xfs_vn_put_link(
61617 struct nameidata *nd,
61618 void *p)
61619 {
61620- char *s = nd_get_link(nd);
61621+ const char *s = nd_get_link(nd);
61622
61623 if (!IS_ERR(s))
61624 kfree(s);
61625diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61626new file mode 100644
61627index 0000000..a78d810
61628--- /dev/null
61629+++ b/grsecurity/Kconfig
61630@@ -0,0 +1,1107 @@
61631+#
61632+# grecurity configuration
61633+#
61634+menu "Memory Protections"
61635+depends on GRKERNSEC
61636+
61637+config GRKERNSEC_KMEM
61638+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61639+ default y if GRKERNSEC_CONFIG_AUTO
61640+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61641+ help
61642+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61643+ be written to or read from to modify or leak the contents of the running
61644+ kernel. /dev/port will also not be allowed to be opened, and support
61645+ for /dev/cpu/*/msr and kexec will be removed. If you have module
61646+ support disabled, enabling this will close up six ways that are
61647+ currently used to insert malicious code into the running kernel.
61648+
61649+ Even with this feature enabled, we still highly recommend that
61650+ you use the RBAC system, as it is still possible for an attacker to
61651+ modify the running kernel through other more obscure methods.
61652+
61653+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61654+ from working.
61655+
61656+ It is highly recommended that you say Y here if you meet all the
61657+ conditions above.
61658+
61659+config GRKERNSEC_VM86
61660+ bool "Restrict VM86 mode"
61661+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61662+ depends on X86_32
61663+
61664+ help
61665+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61666+ make use of a special execution mode on 32bit x86 processors called
61667+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61668+ video cards and will still work with this option enabled. The purpose
61669+ of the option is to prevent exploitation of emulation errors in
61670+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61671+ Nearly all users should be able to enable this option.
61672+
61673+config GRKERNSEC_IO
61674+ bool "Disable privileged I/O"
61675+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61676+ depends on X86
61677+ select RTC_CLASS
61678+ select RTC_INTF_DEV
61679+ select RTC_DRV_CMOS
61680+
61681+ help
61682+ If you say Y here, all ioperm and iopl calls will return an error.
61683+ Ioperm and iopl can be used to modify the running kernel.
61684+ Unfortunately, some programs need this access to operate properly,
61685+ the most notable of which are XFree86 and hwclock. hwclock can be
61686+ remedied by having RTC support in the kernel, so real-time
61687+ clock support is enabled if this option is enabled, to ensure
61688+ that hwclock operates correctly.
61689+
61690+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
61691+ you may not be able to boot into a graphical environment with this
61692+ option enabled. In this case, you should use the RBAC system instead.
61693+
61694+config GRKERNSEC_JIT_HARDEN
61695+ bool "Harden BPF JIT against spray attacks"
61696+ default y if GRKERNSEC_CONFIG_AUTO
61697+ depends on BPF_JIT
61698+ help
61699+ If you say Y here, the native code generated by the kernel's Berkeley
61700+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61701+ attacks that attempt to fit attacker-beneficial instructions in
61702+ 32bit immediate fields of JIT-generated native instructions. The
61703+ attacker will generally aim to cause an unintended instruction sequence
61704+ of JIT-generated native code to execute by jumping into the middle of
61705+ a generated instruction. This feature effectively randomizes the 32bit
61706+ immediate constants present in the generated code to thwart such attacks.
61707+
61708+ If you're using KERNEXEC, it's recommended that you enable this option
61709+ to supplement the hardening of the kernel.
61710+
61711+config GRKERNSEC_PERF_HARDEN
61712+ bool "Disable unprivileged PERF_EVENTS usage by default"
61713+ default y if GRKERNSEC_CONFIG_AUTO
61714+ depends on PERF_EVENTS
61715+ help
61716+ If you say Y here, the range of acceptable values for the
61717+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61718+ default to a new value: 3. When the sysctl is set to this value, no
61719+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61720+
61721+ Though PERF_EVENTS can be used legitimately for performance monitoring
61722+ and low-level application profiling, it is forced on regardless of
61723+ configuration, has been at fault for several vulnerabilities, and
61724+ creates new opportunities for side channels and other information leaks.
61725+
61726+ This feature puts PERF_EVENTS into a secure default state and permits
61727+ the administrator to change out of it temporarily if unprivileged
61728+ application profiling is needed.
61729+
61730+config GRKERNSEC_RAND_THREADSTACK
61731+ bool "Insert random gaps between thread stacks"
61732+ default y if GRKERNSEC_CONFIG_AUTO
61733+ depends on PAX_RANDMMAP && !PPC
61734+ help
61735+ If you say Y here, a random-sized gap will be enforced between allocated
61736+ thread stacks. Glibc's NPTL and other threading libraries that
61737+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61738+ The implementation currently provides 8 bits of entropy for the gap.
61739+
61740+ Many distributions do not compile threaded remote services with the
61741+ -fstack-check argument to GCC, causing the variable-sized stack-based
61742+ allocator, alloca(), to not probe the stack on allocation. This
61743+ permits an unbounded alloca() to skip over any guard page and potentially
61744+ modify another thread's stack reliably. An enforced random gap
61745+ reduces the reliability of such an attack and increases the chance
61746+ that such a read/write to another thread's stack instead lands in
61747+ an unmapped area, causing a crash and triggering grsecurity's
61748+ anti-bruteforcing logic.
61749+
61750+config GRKERNSEC_PROC_MEMMAP
61751+ bool "Harden ASLR against information leaks and entropy reduction"
61752+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61753+ depends on PAX_NOEXEC || PAX_ASLR
61754+ help
61755+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61756+ give no information about the addresses of its mappings if
61757+ PaX features that rely on random addresses are enabled on the task.
61758+ In addition to sanitizing this information and disabling other
61759+ dangerous sources of information, this option causes reads of sensitive
61760+ /proc/<pid> entries where the file descriptor was opened in a different
61761+ task than the one performing the read. Such attempts are logged.
61762+ This option also limits argv/env strings for suid/sgid binaries
61763+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61764+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61765+ binaries to prevent alternative mmap layouts from being abused.
61766+
61767+ If you use PaX it is essential that you say Y here as it closes up
61768+ several holes that make full ASLR useless locally.
61769+
61770+config GRKERNSEC_BRUTE
61771+ bool "Deter exploit bruteforcing"
61772+ default y if GRKERNSEC_CONFIG_AUTO
61773+ help
61774+ If you say Y here, attempts to bruteforce exploits against forking
61775+ daemons such as apache or sshd, as well as against suid/sgid binaries
61776+ will be deterred. When a child of a forking daemon is killed by PaX
61777+ or crashes due to an illegal instruction or other suspicious signal,
61778+ the parent process will be delayed 30 seconds upon every subsequent
61779+ fork until the administrator is able to assess the situation and
61780+ restart the daemon.
61781+ In the suid/sgid case, the attempt is logged, the user has all their
61782+ existing instances of the suid/sgid binary terminated and will
61783+ be unable to execute any suid/sgid binaries for 15 minutes.
61784+
61785+ It is recommended that you also enable signal logging in the auditing
61786+ section so that logs are generated when a process triggers a suspicious
61787+ signal.
61788+ If the sysctl option is enabled, a sysctl option with name
61789+ "deter_bruteforce" is created.
61790+
61791+
61792+config GRKERNSEC_MODHARDEN
61793+ bool "Harden module auto-loading"
61794+ default y if GRKERNSEC_CONFIG_AUTO
61795+ depends on MODULES
61796+ help
61797+ If you say Y here, module auto-loading in response to use of some
61798+ feature implemented by an unloaded module will be restricted to
61799+ root users. Enabling this option helps defend against attacks
61800+ by unprivileged users who abuse the auto-loading behavior to
61801+ cause a vulnerable module to load that is then exploited.
61802+
61803+ If this option prevents a legitimate use of auto-loading for a
61804+ non-root user, the administrator can execute modprobe manually
61805+ with the exact name of the module mentioned in the alert log.
61806+ Alternatively, the administrator can add the module to the list
61807+ of modules loaded at boot by modifying init scripts.
61808+
61809+ Modification of init scripts will most likely be needed on
61810+ Ubuntu servers with encrypted home directory support enabled,
61811+ as the first non-root user logging in will cause the ecb(aes),
61812+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61813+
61814+config GRKERNSEC_HIDESYM
61815+ bool "Hide kernel symbols"
61816+ default y if GRKERNSEC_CONFIG_AUTO
61817+ select PAX_USERCOPY_SLABS
61818+ help
61819+ If you say Y here, getting information on loaded modules, and
61820+ displaying all kernel symbols through a syscall will be restricted
61821+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61822+ /proc/kallsyms will be restricted to the root user. The RBAC
61823+ system can hide that entry even from root.
61824+
61825+ This option also prevents leaking of kernel addresses through
61826+ several /proc entries.
61827+
61828+ Note that this option is only effective provided the following
61829+ conditions are met:
61830+ 1) The kernel using grsecurity is not precompiled by some distribution
61831+ 2) You have also enabled GRKERNSEC_DMESG
61832+ 3) You are using the RBAC system and hiding other files such as your
61833+ kernel image and System.map. Alternatively, enabling this option
61834+ causes the permissions on /boot, /lib/modules, and the kernel
61835+ source directory to change at compile time to prevent
61836+ reading by non-root users.
61837+ If the above conditions are met, this option will aid in providing a
61838+ useful protection against local kernel exploitation of overflows
61839+ and arbitrary read/write vulnerabilities.
61840+
61841+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61842+ in addition to this feature.
61843+
61844+config GRKERNSEC_KERN_LOCKOUT
61845+ bool "Active kernel exploit response"
61846+ default y if GRKERNSEC_CONFIG_AUTO
61847+ depends on X86 || ARM || PPC || SPARC
61848+ help
61849+ If you say Y here, when a PaX alert is triggered due to suspicious
61850+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61851+ or an OOPS occurs due to bad memory accesses, instead of just
61852+ terminating the offending process (and potentially allowing
61853+ a subsequent exploit from the same user), we will take one of two
61854+ actions:
61855+ If the user was root, we will panic the system
61856+ If the user was non-root, we will log the attempt, terminate
61857+ all processes owned by the user, then prevent them from creating
61858+ any new processes until the system is restarted
61859+ This deters repeated kernel exploitation/bruteforcing attempts
61860+ and is useful for later forensics.
61861+
61862+config GRKERNSEC_OLD_ARM_USERLAND
61863+ bool "Old ARM userland compatibility"
61864+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
61865+ help
61866+ If you say Y here, stubs of executable code to perform such operations
61867+ as "compare-exchange" will be placed at fixed locations in the ARM vector
61868+ table. This is unfortunately needed for old ARM userland meant to run
61869+ across a wide range of processors. Without this option enabled,
61870+ the get_tls and data memory barrier stubs will be emulated by the kernel,
61871+ which is enough for Linaro userlands or other userlands designed for v6
61872+ and newer ARM CPUs. It's recommended that you try without this option enabled
61873+ first, and only enable it if your userland does not boot (it will likely fail
61874+ at init time).
61875+
61876+endmenu
61877+menu "Role Based Access Control Options"
61878+depends on GRKERNSEC
61879+
61880+config GRKERNSEC_RBAC_DEBUG
61881+ bool
61882+
61883+config GRKERNSEC_NO_RBAC
61884+ bool "Disable RBAC system"
61885+ help
61886+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61887+ preventing the RBAC system from being enabled. You should only say Y
61888+ here if you have no intention of using the RBAC system, so as to prevent
61889+ an attacker with root access from misusing the RBAC system to hide files
61890+ and processes when loadable module support and /dev/[k]mem have been
61891+ locked down.
61892+
61893+config GRKERNSEC_ACL_HIDEKERN
61894+ bool "Hide kernel processes"
61895+ help
61896+ If you say Y here, all kernel threads will be hidden to all
61897+ processes but those whose subject has the "view hidden processes"
61898+ flag.
61899+
61900+config GRKERNSEC_ACL_MAXTRIES
61901+ int "Maximum tries before password lockout"
61902+ default 3
61903+ help
61904+ This option enforces the maximum number of times a user can attempt
61905+ to authorize themselves with the grsecurity RBAC system before being
61906+ denied the ability to attempt authorization again for a specified time.
61907+ The lower the number, the harder it will be to brute-force a password.
61908+
61909+config GRKERNSEC_ACL_TIMEOUT
61910+ int "Time to wait after max password tries, in seconds"
61911+ default 30
61912+ help
61913+ This option specifies the time the user must wait after attempting to
61914+ authorize to the RBAC system with the maximum number of invalid
61915+ passwords. The higher the number, the harder it will be to brute-force
61916+ a password.
61917+
61918+endmenu
61919+menu "Filesystem Protections"
61920+depends on GRKERNSEC
61921+
61922+config GRKERNSEC_PROC
61923+ bool "Proc restrictions"
61924+ default y if GRKERNSEC_CONFIG_AUTO
61925+ help
61926+ If you say Y here, the permissions of the /proc filesystem
61927+ will be altered to enhance system security and privacy. You MUST
61928+ choose either a user only restriction or a user and group restriction.
61929+ Depending upon the option you choose, you can either restrict users to
61930+ see only the processes they themselves run, or choose a group that can
61931+ view all processes and files normally restricted to root if you choose
61932+ the "restrict to user only" option. NOTE: If you're running identd or
61933+ ntpd as a non-root user, you will have to run it as the group you
61934+ specify here.
61935+
61936+config GRKERNSEC_PROC_USER
61937+ bool "Restrict /proc to user only"
61938+ depends on GRKERNSEC_PROC
61939+ help
61940+ If you say Y here, non-root users will only be able to view their own
61941+ processes, and restricts them from viewing network-related information,
61942+ and viewing kernel symbol and module information.
61943+
61944+config GRKERNSEC_PROC_USERGROUP
61945+ bool "Allow special group"
61946+ default y if GRKERNSEC_CONFIG_AUTO
61947+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61948+ help
61949+ If you say Y here, you will be able to select a group that will be
61950+ able to view all processes and network-related information. If you've
61951+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61952+ remain hidden. This option is useful if you want to run identd as
61953+ a non-root user. The group you select may also be chosen at boot time
61954+ via "grsec_proc_gid=" on the kernel commandline.
61955+
61956+config GRKERNSEC_PROC_GID
61957+ int "GID for special group"
61958+ depends on GRKERNSEC_PROC_USERGROUP
61959+ default 1001
61960+
61961+config GRKERNSEC_PROC_ADD
61962+ bool "Additional restrictions"
61963+ default y if GRKERNSEC_CONFIG_AUTO
61964+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61965+ help
61966+ If you say Y here, additional restrictions will be placed on
61967+ /proc that keep normal users from viewing device information and
61968+ slabinfo information that could be useful for exploits.
61969+
61970+config GRKERNSEC_LINK
61971+ bool "Linking restrictions"
61972+ default y if GRKERNSEC_CONFIG_AUTO
61973+ help
61974+ If you say Y here, /tmp race exploits will be prevented, since users
61975+ will no longer be able to follow symlinks owned by other users in
61976+ world-writable +t directories (e.g. /tmp), unless the owner of the
61977+ symlink is the owner of the directory. users will also not be
61978+ able to hardlink to files they do not own. If the sysctl option is
61979+ enabled, a sysctl option with name "linking_restrictions" is created.
61980+
61981+config GRKERNSEC_SYMLINKOWN
61982+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61983+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61984+ help
61985+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61986+ that prevents it from being used as a security feature. As Apache
61987+ verifies the symlink by performing a stat() against the target of
61988+ the symlink before it is followed, an attacker can setup a symlink
61989+ to point to a same-owned file, then replace the symlink with one
61990+ that targets another user's file just after Apache "validates" the
61991+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61992+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61993+ will be in place for the group you specify. If the sysctl option
61994+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61995+ created.
61996+
61997+config GRKERNSEC_SYMLINKOWN_GID
61998+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61999+ depends on GRKERNSEC_SYMLINKOWN
62000+ default 1006
62001+ help
62002+ Setting this GID determines what group kernel-enforced
62003+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
62004+ is enabled, a sysctl option with name "symlinkown_gid" is created.
62005+
62006+config GRKERNSEC_FIFO
62007+ bool "FIFO restrictions"
62008+ default y if GRKERNSEC_CONFIG_AUTO
62009+ help
62010+ If you say Y here, users will not be able to write to FIFOs they don't
62011+ own in world-writable +t directories (e.g. /tmp), unless the owner of
62012+ the FIFO is the same owner of the directory it's held in. If the sysctl
62013+ option is enabled, a sysctl option with name "fifo_restrictions" is
62014+ created.
62015+
62016+config GRKERNSEC_SYSFS_RESTRICT
62017+ bool "Sysfs/debugfs restriction"
62018+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62019+ depends on SYSFS
62020+ help
62021+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
62022+ any filesystem normally mounted under it (e.g. debugfs) will be
62023+ mostly accessible only by root. These filesystems generally provide access
62024+ to hardware and debug information that isn't appropriate for unprivileged
62025+ users of the system. Sysfs and debugfs have also become a large source
62026+ of new vulnerabilities, ranging from infoleaks to local compromise.
62027+ There has been very little oversight with an eye toward security involved
62028+ in adding new exporters of information to these filesystems, so their
62029+ use is discouraged.
62030+ For reasons of compatibility, a few directories have been whitelisted
62031+ for access by non-root users:
62032+ /sys/fs/selinux
62033+ /sys/fs/fuse
62034+ /sys/devices/system/cpu
62035+
62036+config GRKERNSEC_ROFS
62037+ bool "Runtime read-only mount protection"
62038+ depends on SYSCTL
62039+ help
62040+ If you say Y here, a sysctl option with name "romount_protect" will
62041+ be created. By setting this option to 1 at runtime, filesystems
62042+ will be protected in the following ways:
62043+ * No new writable mounts will be allowed
62044+ * Existing read-only mounts won't be able to be remounted read/write
62045+ * Write operations will be denied on all block devices
62046+ This option acts independently of grsec_lock: once it is set to 1,
62047+ it cannot be turned off. Therefore, please be mindful of the resulting
62048+ behavior if this option is enabled in an init script on a read-only
62049+ filesystem. This feature is mainly intended for secure embedded systems.
62050+
62051+config GRKERNSEC_DEVICE_SIDECHANNEL
62052+ bool "Eliminate stat/notify-based device sidechannels"
62053+ default y if GRKERNSEC_CONFIG_AUTO
62054+ help
62055+ If you say Y here, timing analyses on block or character
62056+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
62057+ will be thwarted for unprivileged users. If a process without
62058+ CAP_MKNOD stats such a device, the last access and last modify times
62059+ will match the device's create time. No access or modify events
62060+ will be triggered through inotify/dnotify/fanotify for such devices.
62061+ This feature will prevent attacks that may at a minimum
62062+ allow an attacker to determine the administrator's password length.
62063+
62064+config GRKERNSEC_CHROOT
62065+ bool "Chroot jail restrictions"
62066+ default y if GRKERNSEC_CONFIG_AUTO
62067+ help
62068+ If you say Y here, you will be able to choose several options that will
62069+ make breaking out of a chrooted jail much more difficult. If you
62070+ encounter no software incompatibilities with the following options, it
62071+ is recommended that you enable each one.
62072+
62073+config GRKERNSEC_CHROOT_MOUNT
62074+ bool "Deny mounts"
62075+ default y if GRKERNSEC_CONFIG_AUTO
62076+ depends on GRKERNSEC_CHROOT
62077+ help
62078+ If you say Y here, processes inside a chroot will not be able to
62079+ mount or remount filesystems. If the sysctl option is enabled, a
62080+ sysctl option with name "chroot_deny_mount" is created.
62081+
62082+config GRKERNSEC_CHROOT_DOUBLE
62083+ bool "Deny double-chroots"
62084+ default y if GRKERNSEC_CONFIG_AUTO
62085+ depends on GRKERNSEC_CHROOT
62086+ help
62087+ If you say Y here, processes inside a chroot will not be able to chroot
62088+ again outside the chroot. This is a widely used method of breaking
62089+ out of a chroot jail and should not be allowed. If the sysctl
62090+ option is enabled, a sysctl option with name
62091+ "chroot_deny_chroot" is created.
62092+
62093+config GRKERNSEC_CHROOT_PIVOT
62094+ bool "Deny pivot_root in chroot"
62095+ default y if GRKERNSEC_CONFIG_AUTO
62096+ depends on GRKERNSEC_CHROOT
62097+ help
62098+ If you say Y here, processes inside a chroot will not be able to use
62099+ a function called pivot_root() that was introduced in Linux 2.3.41. It
62100+ works similar to chroot in that it changes the root filesystem. This
62101+ function could be misused in a chrooted process to attempt to break out
62102+ of the chroot, and therefore should not be allowed. If the sysctl
62103+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
62104+ created.
62105+
62106+config GRKERNSEC_CHROOT_CHDIR
62107+ bool "Enforce chdir(\"/\") on all chroots"
62108+ default y if GRKERNSEC_CONFIG_AUTO
62109+ depends on GRKERNSEC_CHROOT
62110+ help
62111+ If you say Y here, the current working directory of all newly-chrooted
62112+ applications will be set to the the root directory of the chroot.
62113+ The man page on chroot(2) states:
62114+ Note that this call does not change the current working
62115+ directory, so that `.' can be outside the tree rooted at
62116+ `/'. In particular, the super-user can escape from a
62117+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
62118+
62119+ It is recommended that you say Y here, since it's not known to break
62120+ any software. If the sysctl option is enabled, a sysctl option with
62121+ name "chroot_enforce_chdir" is created.
62122+
62123+config GRKERNSEC_CHROOT_CHMOD
62124+ bool "Deny (f)chmod +s"
62125+ default y if GRKERNSEC_CONFIG_AUTO
62126+ depends on GRKERNSEC_CHROOT
62127+ help
62128+ If you say Y here, processes inside a chroot will not be able to chmod
62129+ or fchmod files to make them have suid or sgid bits. This protects
62130+ against another published method of breaking a chroot. If the sysctl
62131+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
62132+ created.
62133+
62134+config GRKERNSEC_CHROOT_FCHDIR
62135+ bool "Deny fchdir out of chroot"
62136+ default y if GRKERNSEC_CONFIG_AUTO
62137+ depends on GRKERNSEC_CHROOT
62138+ help
62139+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
62140+ to a file descriptor of the chrooting process that points to a directory
62141+ outside the filesystem will be stopped. If the sysctl option
62142+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
62143+
62144+config GRKERNSEC_CHROOT_MKNOD
62145+ bool "Deny mknod"
62146+ default y if GRKERNSEC_CONFIG_AUTO
62147+ depends on GRKERNSEC_CHROOT
62148+ help
62149+ If you say Y here, processes inside a chroot will not be allowed to
62150+ mknod. The problem with using mknod inside a chroot is that it
62151+ would allow an attacker to create a device entry that is the same
62152+ as one on the physical root of your system, which could range from
62153+ anything from the console device to a device for your harddrive (which
62154+ they could then use to wipe the drive or steal data). It is recommended
62155+ that you say Y here, unless you run into software incompatibilities.
62156+ If the sysctl option is enabled, a sysctl option with name
62157+ "chroot_deny_mknod" is created.
62158+
62159+config GRKERNSEC_CHROOT_SHMAT
62160+ bool "Deny shmat() out of chroot"
62161+ default y if GRKERNSEC_CONFIG_AUTO
62162+ depends on GRKERNSEC_CHROOT
62163+ help
62164+ If you say Y here, processes inside a chroot will not be able to attach
62165+ to shared memory segments that were created outside of the chroot jail.
62166+ It is recommended that you say Y here. If the sysctl option is enabled,
62167+ a sysctl option with name "chroot_deny_shmat" is created.
62168+
62169+config GRKERNSEC_CHROOT_UNIX
62170+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
62171+ default y if GRKERNSEC_CONFIG_AUTO
62172+ depends on GRKERNSEC_CHROOT
62173+ help
62174+ If you say Y here, processes inside a chroot will not be able to
62175+ connect to abstract (meaning not belonging to a filesystem) Unix
62176+ domain sockets that were bound outside of a chroot. It is recommended
62177+ that you say Y here. If the sysctl option is enabled, a sysctl option
62178+ with name "chroot_deny_unix" is created.
62179+
62180+config GRKERNSEC_CHROOT_FINDTASK
62181+ bool "Protect outside processes"
62182+ default y if GRKERNSEC_CONFIG_AUTO
62183+ depends on GRKERNSEC_CHROOT
62184+ help
62185+ If you say Y here, processes inside a chroot will not be able to
62186+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
62187+ getsid, or view any process outside of the chroot. If the sysctl
62188+ option is enabled, a sysctl option with name "chroot_findtask" is
62189+ created.
62190+
62191+config GRKERNSEC_CHROOT_NICE
62192+ bool "Restrict priority changes"
62193+ default y if GRKERNSEC_CONFIG_AUTO
62194+ depends on GRKERNSEC_CHROOT
62195+ help
62196+ If you say Y here, processes inside a chroot will not be able to raise
62197+ the priority of processes in the chroot, or alter the priority of
62198+ processes outside the chroot. This provides more security than simply
62199+ removing CAP_SYS_NICE from the process' capability set. If the
62200+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
62201+ is created.
62202+
62203+config GRKERNSEC_CHROOT_SYSCTL
62204+ bool "Deny sysctl writes"
62205+ default y if GRKERNSEC_CONFIG_AUTO
62206+ depends on GRKERNSEC_CHROOT
62207+ help
62208+ If you say Y here, an attacker in a chroot will not be able to
62209+ write to sysctl entries, either by sysctl(2) or through a /proc
62210+ interface. It is strongly recommended that you say Y here. If the
62211+ sysctl option is enabled, a sysctl option with name
62212+ "chroot_deny_sysctl" is created.
62213+
62214+config GRKERNSEC_CHROOT_CAPS
62215+ bool "Capability restrictions"
62216+ default y if GRKERNSEC_CONFIG_AUTO
62217+ depends on GRKERNSEC_CHROOT
62218+ help
62219+ If you say Y here, the capabilities on all processes within a
62220+ chroot jail will be lowered to stop module insertion, raw i/o,
62221+ system and net admin tasks, rebooting the system, modifying immutable
62222+ files, modifying IPC owned by another, and changing the system time.
62223+ This is left an option because it can break some apps. Disable this
62224+ if your chrooted apps are having problems performing those kinds of
62225+ tasks. If the sysctl option is enabled, a sysctl option with
62226+ name "chroot_caps" is created.
62227+
62228+config GRKERNSEC_CHROOT_INITRD
62229+ bool "Exempt initrd tasks from restrictions"
62230+ default y if GRKERNSEC_CONFIG_AUTO
62231+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
62232+ help
62233+ If you say Y here, tasks started prior to init will be exempted from
62234+ grsecurity's chroot restrictions. This option is mainly meant to
62235+ resolve Plymouth's performing privileged operations unnecessarily
62236+ in a chroot.
62237+
62238+endmenu
62239+menu "Kernel Auditing"
62240+depends on GRKERNSEC
62241+
62242+config GRKERNSEC_AUDIT_GROUP
62243+ bool "Single group for auditing"
62244+ help
62245+ If you say Y here, the exec and chdir logging features will only operate
62246+ on a group you specify. This option is recommended if you only want to
62247+ watch certain users instead of having a large amount of logs from the
62248+ entire system. If the sysctl option is enabled, a sysctl option with
62249+ name "audit_group" is created.
62250+
62251+config GRKERNSEC_AUDIT_GID
62252+ int "GID for auditing"
62253+ depends on GRKERNSEC_AUDIT_GROUP
62254+ default 1007
62255+
62256+config GRKERNSEC_EXECLOG
62257+ bool "Exec logging"
62258+ help
62259+ If you say Y here, all execve() calls will be logged (since the
62260+ other exec*() calls are frontends to execve(), all execution
62261+ will be logged). Useful for shell-servers that like to keep track
62262+ of their users. If the sysctl option is enabled, a sysctl option with
62263+ name "exec_logging" is created.
62264+ WARNING: This option when enabled will produce a LOT of logs, especially
62265+ on an active system.
62266+
62267+config GRKERNSEC_RESLOG
62268+ bool "Resource logging"
62269+ default y if GRKERNSEC_CONFIG_AUTO
62270+ help
62271+ If you say Y here, all attempts to overstep resource limits will
62272+ be logged with the resource name, the requested size, and the current
62273+ limit. It is highly recommended that you say Y here. If the sysctl
62274+ option is enabled, a sysctl option with name "resource_logging" is
62275+ created. If the RBAC system is enabled, the sysctl value is ignored.
62276+
62277+config GRKERNSEC_CHROOT_EXECLOG
62278+ bool "Log execs within chroot"
62279+ help
62280+ If you say Y here, all executions inside a chroot jail will be logged
62281+ to syslog. This can cause a large amount of logs if certain
62282+ applications (eg. djb's daemontools) are installed on the system, and
62283+ is therefore left as an option. If the sysctl option is enabled, a
62284+ sysctl option with name "chroot_execlog" is created.
62285+
62286+config GRKERNSEC_AUDIT_PTRACE
62287+ bool "Ptrace logging"
62288+ help
62289+ If you say Y here, all attempts to attach to a process via ptrace
62290+ will be logged. If the sysctl option is enabled, a sysctl option
62291+ with name "audit_ptrace" is created.
62292+
62293+config GRKERNSEC_AUDIT_CHDIR
62294+ bool "Chdir logging"
62295+ help
62296+ If you say Y here, all chdir() calls will be logged. If the sysctl
62297+ option is enabled, a sysctl option with name "audit_chdir" is created.
62298+
62299+config GRKERNSEC_AUDIT_MOUNT
62300+ bool "(Un)Mount logging"
62301+ help
62302+ If you say Y here, all mounts and unmounts will be logged. If the
62303+ sysctl option is enabled, a sysctl option with name "audit_mount" is
62304+ created.
62305+
62306+config GRKERNSEC_SIGNAL
62307+ bool "Signal logging"
62308+ default y if GRKERNSEC_CONFIG_AUTO
62309+ help
62310+ If you say Y here, certain important signals will be logged, such as
62311+ SIGSEGV, which will as a result inform you of when a error in a program
62312+ occurred, which in some cases could mean a possible exploit attempt.
62313+ If the sysctl option is enabled, a sysctl option with name
62314+ "signal_logging" is created.
62315+
62316+config GRKERNSEC_FORKFAIL
62317+ bool "Fork failure logging"
62318+ help
62319+ If you say Y here, all failed fork() attempts will be logged.
62320+ This could suggest a fork bomb, or someone attempting to overstep
62321+ their process limit. If the sysctl option is enabled, a sysctl option
62322+ with name "forkfail_logging" is created.
62323+
62324+config GRKERNSEC_TIME
62325+ bool "Time change logging"
62326+ default y if GRKERNSEC_CONFIG_AUTO
62327+ help
62328+ If you say Y here, any changes of the system clock will be logged.
62329+ If the sysctl option is enabled, a sysctl option with name
62330+ "timechange_logging" is created.
62331+
62332+config GRKERNSEC_PROC_IPADDR
62333+ bool "/proc/<pid>/ipaddr support"
62334+ default y if GRKERNSEC_CONFIG_AUTO
62335+ help
62336+ If you say Y here, a new entry will be added to each /proc/<pid>
62337+ directory that contains the IP address of the person using the task.
62338+ The IP is carried across local TCP and AF_UNIX stream sockets.
62339+ This information can be useful for IDS/IPSes to perform remote response
62340+ to a local attack. The entry is readable by only the owner of the
62341+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
62342+ the RBAC system), and thus does not create privacy concerns.
62343+
62344+config GRKERNSEC_RWXMAP_LOG
62345+ bool 'Denied RWX mmap/mprotect logging'
62346+ default y if GRKERNSEC_CONFIG_AUTO
62347+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
62348+ help
62349+ If you say Y here, calls to mmap() and mprotect() with explicit
62350+ usage of PROT_WRITE and PROT_EXEC together will be logged when
62351+ denied by the PAX_MPROTECT feature. This feature will also
62352+ log other problematic scenarios that can occur when PAX_MPROTECT
62353+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
62354+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
62355+ is created.
62356+
62357+endmenu
62358+
62359+menu "Executable Protections"
62360+depends on GRKERNSEC
62361+
62362+config GRKERNSEC_DMESG
62363+ bool "Dmesg(8) restriction"
62364+ default y if GRKERNSEC_CONFIG_AUTO
62365+ help
62366+ If you say Y here, non-root users will not be able to use dmesg(8)
62367+ to view the contents of the kernel's circular log buffer.
62368+ The kernel's log buffer often contains kernel addresses and other
62369+ identifying information useful to an attacker in fingerprinting a
62370+ system for a targeted exploit.
62371+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
62372+ created.
62373+
62374+config GRKERNSEC_HARDEN_PTRACE
62375+ bool "Deter ptrace-based process snooping"
62376+ default y if GRKERNSEC_CONFIG_AUTO
62377+ help
62378+ If you say Y here, TTY sniffers and other malicious monitoring
62379+ programs implemented through ptrace will be defeated. If you
62380+ have been using the RBAC system, this option has already been
62381+ enabled for several years for all users, with the ability to make
62382+ fine-grained exceptions.
62383+
62384+ This option only affects the ability of non-root users to ptrace
62385+ processes that are not a descendent of the ptracing process.
62386+ This means that strace ./binary and gdb ./binary will still work,
62387+ but attaching to arbitrary processes will not. If the sysctl
62388+ option is enabled, a sysctl option with name "harden_ptrace" is
62389+ created.
62390+
62391+config GRKERNSEC_PTRACE_READEXEC
62392+ bool "Require read access to ptrace sensitive binaries"
62393+ default y if GRKERNSEC_CONFIG_AUTO
62394+ help
62395+ If you say Y here, unprivileged users will not be able to ptrace unreadable
62396+ binaries. This option is useful in environments that
62397+ remove the read bits (e.g. file mode 4711) from suid binaries to
62398+ prevent infoleaking of their contents. This option adds
62399+ consistency to the use of that file mode, as the binary could normally
62400+ be read out when run without privileges while ptracing.
62401+
62402+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
62403+ is created.
62404+
62405+config GRKERNSEC_SETXID
62406+ bool "Enforce consistent multithreaded privileges"
62407+ default y if GRKERNSEC_CONFIG_AUTO
62408+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
62409+ help
62410+ If you say Y here, a change from a root uid to a non-root uid
62411+ in a multithreaded application will cause the resulting uids,
62412+ gids, supplementary groups, and capabilities in that thread
62413+ to be propagated to the other threads of the process. In most
62414+ cases this is unnecessary, as glibc will emulate this behavior
62415+ on behalf of the application. Other libcs do not act in the
62416+ same way, allowing the other threads of the process to continue
62417+ running with root privileges. If the sysctl option is enabled,
62418+ a sysctl option with name "consistent_setxid" is created.
62419+
62420+config GRKERNSEC_HARDEN_IPC
62421+ bool "Disallow access to world-accessible IPC objects"
62422+ default y if GRKERNSEC_CONFIG_AUTO
62423+ depends on SYSVIPC
62424+ help
62425+ If you say Y here, access to overly-permissive IPC (shared memory,
62426+ message queues, and semaphores) will be denied for processes whose
62427+ effective user or group would not grant them permission. It's a
62428+ common error to grant too much permission to these objects, with
62429+ impact ranging from denial of service and information leaking to
62430+ privilege escalation. This feature was developed in response to
62431+ research by Tim Brown:
62432+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
62433+ who found hundreds of such insecure usages. Processes with
62434+ CAP_IPC_OWNER are still permitted to access these IPC objects.
62435+ If the sysctl option is enabled, a sysctl option with name
62436+ "harden_ipc" is created.
62437+
62438+config GRKERNSEC_TPE
62439+ bool "Trusted Path Execution (TPE)"
62440+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
62441+ help
62442+ If you say Y here, you will be able to choose a gid to add to the
62443+ supplementary groups of users you want to mark as "untrusted."
62444+ These users will not be able to execute any files that are not in
62445+ root-owned directories writable only by root. If the sysctl option
62446+ is enabled, a sysctl option with name "tpe" is created.
62447+
62448+config GRKERNSEC_TPE_ALL
62449+ bool "Partially restrict all non-root users"
62450+ depends on GRKERNSEC_TPE
62451+ help
62452+ If you say Y here, all non-root users will be covered under
62453+ a weaker TPE restriction. This is separate from, and in addition to,
62454+ the main TPE options that you have selected elsewhere. Thus, if a
62455+ "trusted" GID is chosen, this restriction applies to even that GID.
62456+ Under this restriction, all non-root users will only be allowed to
62457+ execute files in directories they own that are not group or
62458+ world-writable, or in directories owned by root and writable only by
62459+ root. If the sysctl option is enabled, a sysctl option with name
62460+ "tpe_restrict_all" is created.
62461+
62462+config GRKERNSEC_TPE_INVERT
62463+ bool "Invert GID option"
62464+ depends on GRKERNSEC_TPE
62465+ help
62466+ If you say Y here, the group you specify in the TPE configuration will
62467+ decide what group TPE restrictions will be *disabled* for. This
62468+ option is useful if you want TPE restrictions to be applied to most
62469+ users on the system. If the sysctl option is enabled, a sysctl option
62470+ with name "tpe_invert" is created. Unlike other sysctl options, this
62471+ entry will default to on for backward-compatibility.
62472+
62473+config GRKERNSEC_TPE_GID
62474+ int
62475+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
62476+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
62477+
62478+config GRKERNSEC_TPE_UNTRUSTED_GID
62479+ int "GID for TPE-untrusted users"
62480+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
62481+ default 1005
62482+ help
62483+ Setting this GID determines what group TPE restrictions will be
62484+ *enabled* for. If the sysctl option is enabled, a sysctl option
62485+ with name "tpe_gid" is created.
62486+
62487+config GRKERNSEC_TPE_TRUSTED_GID
62488+ int "GID for TPE-trusted users"
62489+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
62490+ default 1005
62491+ help
62492+ Setting this GID determines what group TPE restrictions will be
62493+ *disabled* for. If the sysctl option is enabled, a sysctl option
62494+ with name "tpe_gid" is created.
62495+
62496+endmenu
62497+menu "Network Protections"
62498+depends on GRKERNSEC
62499+
62500+config GRKERNSEC_RANDNET
62501+ bool "Larger entropy pools"
62502+ default y if GRKERNSEC_CONFIG_AUTO
62503+ help
62504+ If you say Y here, the entropy pools used for many features of Linux
62505+ and grsecurity will be doubled in size. Since several grsecurity
62506+ features use additional randomness, it is recommended that you say Y
62507+ here. Saying Y here has a similar effect as modifying
62508+ /proc/sys/kernel/random/poolsize.
62509+
62510+config GRKERNSEC_BLACKHOLE
62511+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
62512+ default y if GRKERNSEC_CONFIG_AUTO
62513+ depends on NET
62514+ help
62515+ If you say Y here, neither TCP resets nor ICMP
62516+ destination-unreachable packets will be sent in response to packets
62517+ sent to ports for which no associated listening process exists.
62518+ This feature supports both IPV4 and IPV6 and exempts the
62519+ loopback interface from blackholing. Enabling this feature
62520+ makes a host more resilient to DoS attacks and reduces network
62521+ visibility against scanners.
62522+
62523+ The blackhole feature as-implemented is equivalent to the FreeBSD
62524+ blackhole feature, as it prevents RST responses to all packets, not
62525+ just SYNs. Under most application behavior this causes no
62526+ problems, but applications (like haproxy) may not close certain
62527+ connections in a way that cleanly terminates them on the remote
62528+ end, leaving the remote host in LAST_ACK state. Because of this
62529+ side-effect and to prevent intentional LAST_ACK DoSes, this
62530+ feature also adds automatic mitigation against such attacks.
62531+ The mitigation drastically reduces the amount of time a socket
62532+ can spend in LAST_ACK state. If you're using haproxy and not
62533+ all servers it connects to have this option enabled, consider
62534+ disabling this feature on the haproxy host.
62535+
62536+ If the sysctl option is enabled, two sysctl options with names
62537+ "ip_blackhole" and "lastack_retries" will be created.
62538+ While "ip_blackhole" takes the standard zero/non-zero on/off
62539+ toggle, "lastack_retries" uses the same kinds of values as
62540+ "tcp_retries1" and "tcp_retries2". The default value of 4
62541+ prevents a socket from lasting more than 45 seconds in LAST_ACK
62542+ state.
62543+
62544+config GRKERNSEC_NO_SIMULT_CONNECT
62545+ bool "Disable TCP Simultaneous Connect"
62546+ default y if GRKERNSEC_CONFIG_AUTO
62547+ depends on NET
62548+ help
62549+ If you say Y here, a feature by Willy Tarreau will be enabled that
62550+ removes a weakness in Linux's strict implementation of TCP that
62551+ allows two clients to connect to each other without either entering
62552+ a listening state. The weakness allows an attacker to easily prevent
62553+ a client from connecting to a known server provided the source port
62554+ for the connection is guessed correctly.
62555+
62556+ As the weakness could be used to prevent an antivirus or IPS from
62557+ fetching updates, or prevent an SSL gateway from fetching a CRL,
62558+ it should be eliminated by enabling this option. Though Linux is
62559+ one of few operating systems supporting simultaneous connect, it
62560+ has no legitimate use in practice and is rarely supported by firewalls.
62561+
62562+config GRKERNSEC_SOCKET
62563+ bool "Socket restrictions"
62564+ depends on NET
62565+ help
62566+ If you say Y here, you will be able to choose from several options.
62567+ If you assign a GID on your system and add it to the supplementary
62568+ groups of users you want to restrict socket access to, this patch
62569+ will perform up to three things, based on the option(s) you choose.
62570+
62571+config GRKERNSEC_SOCKET_ALL
62572+ bool "Deny any sockets to group"
62573+ depends on GRKERNSEC_SOCKET
62574+ help
62575+ If you say Y here, you will be able to choose a GID of whose users will
62576+ be unable to connect to other hosts from your machine or run server
62577+ applications from your machine. If the sysctl option is enabled, a
62578+ sysctl option with name "socket_all" is created.
62579+
62580+config GRKERNSEC_SOCKET_ALL_GID
62581+ int "GID to deny all sockets for"
62582+ depends on GRKERNSEC_SOCKET_ALL
62583+ default 1004
62584+ help
62585+ Here you can choose the GID to disable socket access for. Remember to
62586+ add the users you want socket access disabled for to the GID
62587+ specified here. If the sysctl option is enabled, a sysctl option
62588+ with name "socket_all_gid" is created.
62589+
62590+config GRKERNSEC_SOCKET_CLIENT
62591+ bool "Deny client sockets to group"
62592+ depends on GRKERNSEC_SOCKET
62593+ help
62594+ If you say Y here, you will be able to choose a GID of whose users will
62595+ be unable to connect to other hosts from your machine, but will be
62596+ able to run servers. If this option is enabled, all users in the group
62597+ you specify will have to use passive mode when initiating ftp transfers
62598+ from the shell on your machine. If the sysctl option is enabled, a
62599+ sysctl option with name "socket_client" is created.
62600+
62601+config GRKERNSEC_SOCKET_CLIENT_GID
62602+ int "GID to deny client sockets for"
62603+ depends on GRKERNSEC_SOCKET_CLIENT
62604+ default 1003
62605+ help
62606+ Here you can choose the GID to disable client socket access for.
62607+ Remember to add the users you want client socket access disabled for to
62608+ the GID specified here. If the sysctl option is enabled, a sysctl
62609+ option with name "socket_client_gid" is created.
62610+
62611+config GRKERNSEC_SOCKET_SERVER
62612+ bool "Deny server sockets to group"
62613+ depends on GRKERNSEC_SOCKET
62614+ help
62615+ If you say Y here, you will be able to choose a GID of whose users will
62616+ be unable to run server applications from your machine. If the sysctl
62617+ option is enabled, a sysctl option with name "socket_server" is created.
62618+
62619+config GRKERNSEC_SOCKET_SERVER_GID
62620+ int "GID to deny server sockets for"
62621+ depends on GRKERNSEC_SOCKET_SERVER
62622+ default 1002
62623+ help
62624+ Here you can choose the GID to disable server socket access for.
62625+ Remember to add the users you want server socket access disabled for to
62626+ the GID specified here. If the sysctl option is enabled, a sysctl
62627+ option with name "socket_server_gid" is created.
62628+
62629+endmenu
62630+
62631+menu "Physical Protections"
62632+depends on GRKERNSEC
62633+
62634+config GRKERNSEC_DENYUSB
62635+ bool "Deny new USB connections after toggle"
62636+ default y if GRKERNSEC_CONFIG_AUTO
62637+ depends on SYSCTL && USB_SUPPORT
62638+ help
62639+ If you say Y here, a new sysctl option with name "deny_new_usb"
62640+ will be created. Setting its value to 1 will prevent any new
62641+ USB devices from being recognized by the OS. Any attempted USB
62642+ device insertion will be logged. This option is intended to be
62643+ used against custom USB devices designed to exploit vulnerabilities
62644+ in various USB device drivers.
62645+
62646+ For greatest effectiveness, this sysctl should be set after any
62647+ relevant init scripts. This option is safe to enable in distros
62648+ as each user can choose whether or not to toggle the sysctl.
62649+
62650+config GRKERNSEC_DENYUSB_FORCE
62651+ bool "Reject all USB devices not connected at boot"
62652+ select USB
62653+ depends on GRKERNSEC_DENYUSB
62654+ help
62655+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62656+ that doesn't involve a sysctl entry. This option should only be
62657+ enabled if you're sure you want to deny all new USB connections
62658+ at runtime and don't want to modify init scripts. This should not
62659+ be enabled by distros. It forces the core USB code to be built
62660+ into the kernel image so that all devices connected at boot time
62661+ can be recognized and new USB device connections can be prevented
62662+ prior to init running.
62663+
62664+endmenu
62665+
62666+menu "Sysctl Support"
62667+depends on GRKERNSEC && SYSCTL
62668+
62669+config GRKERNSEC_SYSCTL
62670+ bool "Sysctl support"
62671+ default y if GRKERNSEC_CONFIG_AUTO
62672+ help
62673+ If you say Y here, you will be able to change the options that
62674+ grsecurity runs with at bootup, without having to recompile your
62675+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62676+ to enable (1) or disable (0) various features. All the sysctl entries
62677+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62678+ All features enabled in the kernel configuration are disabled at boot
62679+ if you do not say Y to the "Turn on features by default" option.
62680+ All options should be set at startup, and the grsec_lock entry should
62681+ be set to a non-zero value after all the options are set.
62682+ *THIS IS EXTREMELY IMPORTANT*
62683+
62684+config GRKERNSEC_SYSCTL_DISTRO
62685+ bool "Extra sysctl support for distro makers (READ HELP)"
62686+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62687+ help
62688+ If you say Y here, additional sysctl options will be created
62689+ for features that affect processes running as root. Therefore,
62690+ it is critical when using this option that the grsec_lock entry be
62691+ enabled after boot. Only distros with prebuilt kernel packages
62692+ with this option enabled that can ensure grsec_lock is enabled
62693+ after boot should use this option.
62694+ *Failure to set grsec_lock after boot makes all grsec features
62695+ this option covers useless*
62696+
62697+ Currently this option creates the following sysctl entries:
62698+ "Disable Privileged I/O": "disable_priv_io"
62699+
62700+config GRKERNSEC_SYSCTL_ON
62701+ bool "Turn on features by default"
62702+ default y if GRKERNSEC_CONFIG_AUTO
62703+ depends on GRKERNSEC_SYSCTL
62704+ help
62705+ If you say Y here, instead of having all features enabled in the
62706+ kernel configuration disabled at boot time, the features will be
62707+ enabled at boot time. It is recommended you say Y here unless
62708+ there is some reason you would want all sysctl-tunable features to
62709+ be disabled by default. As mentioned elsewhere, it is important
62710+ to enable the grsec_lock entry once you have finished modifying
62711+ the sysctl entries.
62712+
62713+endmenu
62714+menu "Logging Options"
62715+depends on GRKERNSEC
62716+
62717+config GRKERNSEC_FLOODTIME
62718+ int "Seconds in between log messages (minimum)"
62719+ default 10
62720+ help
62721+ This option allows you to enforce the number of seconds between
62722+ grsecurity log messages. The default should be suitable for most
62723+ people, however, if you choose to change it, choose a value small enough
62724+ to allow informative logs to be produced, but large enough to
62725+ prevent flooding.
62726+
62727+config GRKERNSEC_FLOODBURST
62728+ int "Number of messages in a burst (maximum)"
62729+ default 6
62730+ help
62731+ This option allows you to choose the maximum number of messages allowed
62732+ within the flood time interval you chose in a separate option. The
62733+ default should be suitable for most people, however if you find that
62734+ many of your logs are being interpreted as flooding, you may want to
62735+ raise this value.
62736+
62737+endmenu
62738diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62739new file mode 100644
62740index 0000000..85beb79
62741--- /dev/null
62742+++ b/grsecurity/Makefile
62743@@ -0,0 +1,43 @@
62744+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62745+# during 2001-2009 it has been completely redesigned by Brad Spengler
62746+# into an RBAC system
62747+#
62748+# All code in this directory and various hooks inserted throughout the kernel
62749+# are copyright Brad Spengler - Open Source Security, Inc., and released
62750+# under the GPL v2 or higher
62751+
62752+KBUILD_CFLAGS += -Werror
62753+
62754+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62755+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62756+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62757+ grsec_usb.o grsec_ipc.o
62758+
62759+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62760+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62761+ gracl_learn.o grsec_log.o gracl_policy.o
62762+ifdef CONFIG_COMPAT
62763+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62764+endif
62765+
62766+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62767+
62768+ifdef CONFIG_NET
62769+obj-y += grsec_sock.o
62770+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62771+endif
62772+
62773+ifndef CONFIG_GRKERNSEC
62774+obj-y += grsec_disabled.o
62775+endif
62776+
62777+ifdef CONFIG_GRKERNSEC_HIDESYM
62778+extra-y := grsec_hidesym.o
62779+$(obj)/grsec_hidesym.o:
62780+ @-chmod -f 500 /boot
62781+ @-chmod -f 500 /lib/modules
62782+ @-chmod -f 500 /lib64/modules
62783+ @-chmod -f 500 /lib32/modules
62784+ @-chmod -f 700 .
62785+ @echo ' grsec: protected kernel image paths'
62786+endif
62787diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62788new file mode 100644
62789index 0000000..6affeea
62790--- /dev/null
62791+++ b/grsecurity/gracl.c
62792@@ -0,0 +1,2679 @@
62793+#include <linux/kernel.h>
62794+#include <linux/module.h>
62795+#include <linux/sched.h>
62796+#include <linux/mm.h>
62797+#include <linux/file.h>
62798+#include <linux/fs.h>
62799+#include <linux/namei.h>
62800+#include <linux/mount.h>
62801+#include <linux/tty.h>
62802+#include <linux/proc_fs.h>
62803+#include <linux/lglock.h>
62804+#include <linux/slab.h>
62805+#include <linux/vmalloc.h>
62806+#include <linux/types.h>
62807+#include <linux/sysctl.h>
62808+#include <linux/netdevice.h>
62809+#include <linux/ptrace.h>
62810+#include <linux/gracl.h>
62811+#include <linux/gralloc.h>
62812+#include <linux/security.h>
62813+#include <linux/grinternal.h>
62814+#include <linux/pid_namespace.h>
62815+#include <linux/stop_machine.h>
62816+#include <linux/fdtable.h>
62817+#include <linux/percpu.h>
62818+#include <linux/lglock.h>
62819+#include <linux/hugetlb.h>
62820+#include <linux/posix-timers.h>
62821+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62822+#include <linux/magic.h>
62823+#include <linux/pagemap.h>
62824+#include "../fs/btrfs/async-thread.h"
62825+#include "../fs/btrfs/ctree.h"
62826+#include "../fs/btrfs/btrfs_inode.h"
62827+#endif
62828+#include "../fs/mount.h"
62829+
62830+#include <asm/uaccess.h>
62831+#include <asm/errno.h>
62832+#include <asm/mman.h>
62833+
62834+#define FOR_EACH_ROLE_START(role) \
62835+ role = running_polstate.role_list; \
62836+ while (role) {
62837+
62838+#define FOR_EACH_ROLE_END(role) \
62839+ role = role->prev; \
62840+ }
62841+
62842+extern struct lglock vfsmount_lock;
62843+
62844+extern struct path gr_real_root;
62845+
62846+static struct gr_policy_state running_polstate;
62847+struct gr_policy_state *polstate = &running_polstate;
62848+extern struct gr_alloc_state *current_alloc_state;
62849+
62850+extern char *gr_shared_page[4];
62851+DEFINE_RWLOCK(gr_inode_lock);
62852+
62853+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62854+
62855+#ifdef CONFIG_NET
62856+extern struct vfsmount *sock_mnt;
62857+#endif
62858+
62859+extern struct vfsmount *pipe_mnt;
62860+extern struct vfsmount *shm_mnt;
62861+
62862+#ifdef CONFIG_HUGETLBFS
62863+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62864+#endif
62865+
62866+extern u16 acl_sp_role_value;
62867+extern struct acl_object_label *fakefs_obj_rw;
62868+extern struct acl_object_label *fakefs_obj_rwx;
62869+
62870+int gr_acl_is_enabled(void)
62871+{
62872+ return (gr_status & GR_READY);
62873+}
62874+
62875+void gr_enable_rbac_system(void)
62876+{
62877+ pax_open_kernel();
62878+ gr_status |= GR_READY;
62879+ pax_close_kernel();
62880+}
62881+
62882+int gr_rbac_disable(void *unused)
62883+{
62884+ pax_open_kernel();
62885+ gr_status &= ~GR_READY;
62886+ pax_close_kernel();
62887+
62888+ return 0;
62889+}
62890+
62891+static inline dev_t __get_dev(const struct dentry *dentry)
62892+{
62893+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62894+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62895+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62896+ else
62897+#endif
62898+ return dentry->d_sb->s_dev;
62899+}
62900+
62901+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62902+{
62903+ return __get_dev(dentry);
62904+}
62905+
62906+static char gr_task_roletype_to_char(struct task_struct *task)
62907+{
62908+ switch (task->role->roletype &
62909+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62910+ GR_ROLE_SPECIAL)) {
62911+ case GR_ROLE_DEFAULT:
62912+ return 'D';
62913+ case GR_ROLE_USER:
62914+ return 'U';
62915+ case GR_ROLE_GROUP:
62916+ return 'G';
62917+ case GR_ROLE_SPECIAL:
62918+ return 'S';
62919+ }
62920+
62921+ return 'X';
62922+}
62923+
62924+char gr_roletype_to_char(void)
62925+{
62926+ return gr_task_roletype_to_char(current);
62927+}
62928+
62929+__inline__ int
62930+gr_acl_tpe_check(void)
62931+{
62932+ if (unlikely(!(gr_status & GR_READY)))
62933+ return 0;
62934+ if (current->role->roletype & GR_ROLE_TPE)
62935+ return 1;
62936+ else
62937+ return 0;
62938+}
62939+
62940+int
62941+gr_handle_rawio(const struct inode *inode)
62942+{
62943+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62944+ if (inode && S_ISBLK(inode->i_mode) &&
62945+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62946+ !capable(CAP_SYS_RAWIO))
62947+ return 1;
62948+#endif
62949+ return 0;
62950+}
62951+
62952+int
62953+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62954+{
62955+ if (likely(lena != lenb))
62956+ return 0;
62957+
62958+ return !memcmp(a, b, lena);
62959+}
62960+
62961+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62962+{
62963+ *buflen -= namelen;
62964+ if (*buflen < 0)
62965+ return -ENAMETOOLONG;
62966+ *buffer -= namelen;
62967+ memcpy(*buffer, str, namelen);
62968+ return 0;
62969+}
62970+
62971+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62972+{
62973+ return prepend(buffer, buflen, name->name, name->len);
62974+}
62975+
62976+static int prepend_path(const struct path *path, struct path *root,
62977+ char **buffer, int *buflen)
62978+{
62979+ struct dentry *dentry = path->dentry;
62980+ struct vfsmount *vfsmnt = path->mnt;
62981+ struct mount *mnt = real_mount(vfsmnt);
62982+ bool slash = false;
62983+ int error = 0;
62984+
62985+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62986+ struct dentry * parent;
62987+
62988+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62989+ /* Global root? */
62990+ if (!mnt_has_parent(mnt)) {
62991+ goto out;
62992+ }
62993+ dentry = mnt->mnt_mountpoint;
62994+ mnt = mnt->mnt_parent;
62995+ vfsmnt = &mnt->mnt;
62996+ continue;
62997+ }
62998+ parent = dentry->d_parent;
62999+ prefetch(parent);
63000+ spin_lock(&dentry->d_lock);
63001+ error = prepend_name(buffer, buflen, &dentry->d_name);
63002+ spin_unlock(&dentry->d_lock);
63003+ if (!error)
63004+ error = prepend(buffer, buflen, "/", 1);
63005+ if (error)
63006+ break;
63007+
63008+ slash = true;
63009+ dentry = parent;
63010+ }
63011+
63012+out:
63013+ if (!error && !slash)
63014+ error = prepend(buffer, buflen, "/", 1);
63015+
63016+ return error;
63017+}
63018+
63019+/* this must be called with vfsmount_lock and rename_lock held */
63020+
63021+static char *__our_d_path(const struct path *path, struct path *root,
63022+ char *buf, int buflen)
63023+{
63024+ char *res = buf + buflen;
63025+ int error;
63026+
63027+ prepend(&res, &buflen, "\0", 1);
63028+ error = prepend_path(path, root, &res, &buflen);
63029+ if (error)
63030+ return ERR_PTR(error);
63031+
63032+ return res;
63033+}
63034+
63035+static char *
63036+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
63037+{
63038+ char *retval;
63039+
63040+ retval = __our_d_path(path, root, buf, buflen);
63041+ if (unlikely(IS_ERR(retval)))
63042+ retval = strcpy(buf, "<path too long>");
63043+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
63044+ retval[1] = '\0';
63045+
63046+ return retval;
63047+}
63048+
63049+static char *
63050+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63051+ char *buf, int buflen)
63052+{
63053+ struct path path;
63054+ char *res;
63055+
63056+ path.dentry = (struct dentry *)dentry;
63057+ path.mnt = (struct vfsmount *)vfsmnt;
63058+
63059+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
63060+ by the RBAC system */
63061+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
63062+
63063+ return res;
63064+}
63065+
63066+static char *
63067+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63068+ char *buf, int buflen)
63069+{
63070+ char *res;
63071+ struct path path;
63072+ struct path root;
63073+ struct task_struct *reaper = init_pid_ns.child_reaper;
63074+
63075+ path.dentry = (struct dentry *)dentry;
63076+ path.mnt = (struct vfsmount *)vfsmnt;
63077+
63078+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
63079+ get_fs_root(reaper->fs, &root);
63080+
63081+ br_read_lock(&vfsmount_lock);
63082+ write_seqlock(&rename_lock);
63083+ res = gen_full_path(&path, &root, buf, buflen);
63084+ write_sequnlock(&rename_lock);
63085+ br_read_unlock(&vfsmount_lock);
63086+
63087+ path_put(&root);
63088+ return res;
63089+}
63090+
63091+char *
63092+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63093+{
63094+ char *ret;
63095+ br_read_lock(&vfsmount_lock);
63096+ write_seqlock(&rename_lock);
63097+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63098+ PAGE_SIZE);
63099+ write_sequnlock(&rename_lock);
63100+ br_read_unlock(&vfsmount_lock);
63101+ return ret;
63102+}
63103+
63104+static char *
63105+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63106+{
63107+ char *ret;
63108+ char *buf;
63109+ int buflen;
63110+
63111+ br_read_lock(&vfsmount_lock);
63112+ write_seqlock(&rename_lock);
63113+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
63114+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
63115+ buflen = (int)(ret - buf);
63116+ if (buflen >= 5)
63117+ prepend(&ret, &buflen, "/proc", 5);
63118+ else
63119+ ret = strcpy(buf, "<path too long>");
63120+ write_sequnlock(&rename_lock);
63121+ br_read_unlock(&vfsmount_lock);
63122+ return ret;
63123+}
63124+
63125+char *
63126+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
63127+{
63128+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63129+ PAGE_SIZE);
63130+}
63131+
63132+char *
63133+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
63134+{
63135+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
63136+ PAGE_SIZE);
63137+}
63138+
63139+char *
63140+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
63141+{
63142+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
63143+ PAGE_SIZE);
63144+}
63145+
63146+char *
63147+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
63148+{
63149+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
63150+ PAGE_SIZE);
63151+}
63152+
63153+char *
63154+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
63155+{
63156+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
63157+ PAGE_SIZE);
63158+}
63159+
63160+__inline__ __u32
63161+to_gr_audit(const __u32 reqmode)
63162+{
63163+ /* masks off auditable permission flags, then shifts them to create
63164+ auditing flags, and adds the special case of append auditing if
63165+ we're requesting write */
63166+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
63167+}
63168+
63169+struct acl_role_label *
63170+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
63171+ const gid_t gid)
63172+{
63173+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
63174+ struct acl_role_label *match;
63175+ struct role_allowed_ip *ipp;
63176+ unsigned int x;
63177+ u32 curr_ip = task->signal->saved_ip;
63178+
63179+ match = state->acl_role_set.r_hash[index];
63180+
63181+ while (match) {
63182+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
63183+ for (x = 0; x < match->domain_child_num; x++) {
63184+ if (match->domain_children[x] == uid)
63185+ goto found;
63186+ }
63187+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
63188+ break;
63189+ match = match->next;
63190+ }
63191+found:
63192+ if (match == NULL) {
63193+ try_group:
63194+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
63195+ match = state->acl_role_set.r_hash[index];
63196+
63197+ while (match) {
63198+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
63199+ for (x = 0; x < match->domain_child_num; x++) {
63200+ if (match->domain_children[x] == gid)
63201+ goto found2;
63202+ }
63203+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
63204+ break;
63205+ match = match->next;
63206+ }
63207+found2:
63208+ if (match == NULL)
63209+ match = state->default_role;
63210+ if (match->allowed_ips == NULL)
63211+ return match;
63212+ else {
63213+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
63214+ if (likely
63215+ ((ntohl(curr_ip) & ipp->netmask) ==
63216+ (ntohl(ipp->addr) & ipp->netmask)))
63217+ return match;
63218+ }
63219+ match = state->default_role;
63220+ }
63221+ } else if (match->allowed_ips == NULL) {
63222+ return match;
63223+ } else {
63224+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
63225+ if (likely
63226+ ((ntohl(curr_ip) & ipp->netmask) ==
63227+ (ntohl(ipp->addr) & ipp->netmask)))
63228+ return match;
63229+ }
63230+ goto try_group;
63231+ }
63232+
63233+ return match;
63234+}
63235+
63236+static struct acl_role_label *
63237+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
63238+ const gid_t gid)
63239+{
63240+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
63241+}
63242+
63243+struct acl_subject_label *
63244+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
63245+ const struct acl_role_label *role)
63246+{
63247+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
63248+ struct acl_subject_label *match;
63249+
63250+ match = role->subj_hash[index];
63251+
63252+ while (match && (match->inode != ino || match->device != dev ||
63253+ (match->mode & GR_DELETED))) {
63254+ match = match->next;
63255+ }
63256+
63257+ if (match && !(match->mode & GR_DELETED))
63258+ return match;
63259+ else
63260+ return NULL;
63261+}
63262+
63263+struct acl_subject_label *
63264+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
63265+ const struct acl_role_label *role)
63266+{
63267+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
63268+ struct acl_subject_label *match;
63269+
63270+ match = role->subj_hash[index];
63271+
63272+ while (match && (match->inode != ino || match->device != dev ||
63273+ !(match->mode & GR_DELETED))) {
63274+ match = match->next;
63275+ }
63276+
63277+ if (match && (match->mode & GR_DELETED))
63278+ return match;
63279+ else
63280+ return NULL;
63281+}
63282+
63283+static struct acl_object_label *
63284+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
63285+ const struct acl_subject_label *subj)
63286+{
63287+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63288+ struct acl_object_label *match;
63289+
63290+ match = subj->obj_hash[index];
63291+
63292+ while (match && (match->inode != ino || match->device != dev ||
63293+ (match->mode & GR_DELETED))) {
63294+ match = match->next;
63295+ }
63296+
63297+ if (match && !(match->mode & GR_DELETED))
63298+ return match;
63299+ else
63300+ return NULL;
63301+}
63302+
63303+static struct acl_object_label *
63304+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
63305+ const struct acl_subject_label *subj)
63306+{
63307+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63308+ struct acl_object_label *match;
63309+
63310+ match = subj->obj_hash[index];
63311+
63312+ while (match && (match->inode != ino || match->device != dev ||
63313+ !(match->mode & GR_DELETED))) {
63314+ match = match->next;
63315+ }
63316+
63317+ if (match && (match->mode & GR_DELETED))
63318+ return match;
63319+
63320+ match = subj->obj_hash[index];
63321+
63322+ while (match && (match->inode != ino || match->device != dev ||
63323+ (match->mode & GR_DELETED))) {
63324+ match = match->next;
63325+ }
63326+
63327+ if (match && !(match->mode & GR_DELETED))
63328+ return match;
63329+ else
63330+ return NULL;
63331+}
63332+
63333+struct name_entry *
63334+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
63335+{
63336+ unsigned int len = strlen(name);
63337+ unsigned int key = full_name_hash(name, len);
63338+ unsigned int index = key % state->name_set.n_size;
63339+ struct name_entry *match;
63340+
63341+ match = state->name_set.n_hash[index];
63342+
63343+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
63344+ match = match->next;
63345+
63346+ return match;
63347+}
63348+
63349+static struct name_entry *
63350+lookup_name_entry(const char *name)
63351+{
63352+ return __lookup_name_entry(&running_polstate, name);
63353+}
63354+
63355+static struct name_entry *
63356+lookup_name_entry_create(const char *name)
63357+{
63358+ unsigned int len = strlen(name);
63359+ unsigned int key = full_name_hash(name, len);
63360+ unsigned int index = key % running_polstate.name_set.n_size;
63361+ struct name_entry *match;
63362+
63363+ match = running_polstate.name_set.n_hash[index];
63364+
63365+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63366+ !match->deleted))
63367+ match = match->next;
63368+
63369+ if (match && match->deleted)
63370+ return match;
63371+
63372+ match = running_polstate.name_set.n_hash[index];
63373+
63374+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63375+ match->deleted))
63376+ match = match->next;
63377+
63378+ if (match && !match->deleted)
63379+ return match;
63380+ else
63381+ return NULL;
63382+}
63383+
63384+static struct inodev_entry *
63385+lookup_inodev_entry(const ino_t ino, const dev_t dev)
63386+{
63387+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
63388+ struct inodev_entry *match;
63389+
63390+ match = running_polstate.inodev_set.i_hash[index];
63391+
63392+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
63393+ match = match->next;
63394+
63395+ return match;
63396+}
63397+
63398+void
63399+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
63400+{
63401+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
63402+ state->inodev_set.i_size);
63403+ struct inodev_entry **curr;
63404+
63405+ entry->prev = NULL;
63406+
63407+ curr = &state->inodev_set.i_hash[index];
63408+ if (*curr != NULL)
63409+ (*curr)->prev = entry;
63410+
63411+ entry->next = *curr;
63412+ *curr = entry;
63413+
63414+ return;
63415+}
63416+
63417+static void
63418+insert_inodev_entry(struct inodev_entry *entry)
63419+{
63420+ __insert_inodev_entry(&running_polstate, entry);
63421+}
63422+
63423+void
63424+insert_acl_obj_label(struct acl_object_label *obj,
63425+ struct acl_subject_label *subj)
63426+{
63427+ unsigned int index =
63428+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63429+ struct acl_object_label **curr;
63430+
63431+ obj->prev = NULL;
63432+
63433+ curr = &subj->obj_hash[index];
63434+ if (*curr != NULL)
63435+ (*curr)->prev = obj;
63436+
63437+ obj->next = *curr;
63438+ *curr = obj;
63439+
63440+ return;
63441+}
63442+
63443+void
63444+insert_acl_subj_label(struct acl_subject_label *obj,
63445+ struct acl_role_label *role)
63446+{
63447+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63448+ struct acl_subject_label **curr;
63449+
63450+ obj->prev = NULL;
63451+
63452+ curr = &role->subj_hash[index];
63453+ if (*curr != NULL)
63454+ (*curr)->prev = obj;
63455+
63456+ obj->next = *curr;
63457+ *curr = obj;
63458+
63459+ return;
63460+}
63461+
63462+/* derived from glibc fnmatch() 0: match, 1: no match*/
63463+
63464+static int
63465+glob_match(const char *p, const char *n)
63466+{
63467+ char c;
63468+
63469+ while ((c = *p++) != '\0') {
63470+ switch (c) {
63471+ case '?':
63472+ if (*n == '\0')
63473+ return 1;
63474+ else if (*n == '/')
63475+ return 1;
63476+ break;
63477+ case '\\':
63478+ if (*n != c)
63479+ return 1;
63480+ break;
63481+ case '*':
63482+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63483+ if (*n == '/')
63484+ return 1;
63485+ else if (c == '?') {
63486+ if (*n == '\0')
63487+ return 1;
63488+ else
63489+ ++n;
63490+ }
63491+ }
63492+ if (c == '\0') {
63493+ return 0;
63494+ } else {
63495+ const char *endp;
63496+
63497+ if ((endp = strchr(n, '/')) == NULL)
63498+ endp = n + strlen(n);
63499+
63500+ if (c == '[') {
63501+ for (--p; n < endp; ++n)
63502+ if (!glob_match(p, n))
63503+ return 0;
63504+ } else if (c == '/') {
63505+ while (*n != '\0' && *n != '/')
63506+ ++n;
63507+ if (*n == '/' && !glob_match(p, n + 1))
63508+ return 0;
63509+ } else {
63510+ for (--p; n < endp; ++n)
63511+ if (*n == c && !glob_match(p, n))
63512+ return 0;
63513+ }
63514+
63515+ return 1;
63516+ }
63517+ case '[':
63518+ {
63519+ int not;
63520+ char cold;
63521+
63522+ if (*n == '\0' || *n == '/')
63523+ return 1;
63524+
63525+ not = (*p == '!' || *p == '^');
63526+ if (not)
63527+ ++p;
63528+
63529+ c = *p++;
63530+ for (;;) {
63531+ unsigned char fn = (unsigned char)*n;
63532+
63533+ if (c == '\0')
63534+ return 1;
63535+ else {
63536+ if (c == fn)
63537+ goto matched;
63538+ cold = c;
63539+ c = *p++;
63540+
63541+ if (c == '-' && *p != ']') {
63542+ unsigned char cend = *p++;
63543+
63544+ if (cend == '\0')
63545+ return 1;
63546+
63547+ if (cold <= fn && fn <= cend)
63548+ goto matched;
63549+
63550+ c = *p++;
63551+ }
63552+ }
63553+
63554+ if (c == ']')
63555+ break;
63556+ }
63557+ if (!not)
63558+ return 1;
63559+ break;
63560+ matched:
63561+ while (c != ']') {
63562+ if (c == '\0')
63563+ return 1;
63564+
63565+ c = *p++;
63566+ }
63567+ if (not)
63568+ return 1;
63569+ }
63570+ break;
63571+ default:
63572+ if (c != *n)
63573+ return 1;
63574+ }
63575+
63576+ ++n;
63577+ }
63578+
63579+ if (*n == '\0')
63580+ return 0;
63581+
63582+ if (*n == '/')
63583+ return 0;
63584+
63585+ return 1;
63586+}
63587+
63588+static struct acl_object_label *
63589+chk_glob_label(struct acl_object_label *globbed,
63590+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63591+{
63592+ struct acl_object_label *tmp;
63593+
63594+ if (*path == NULL)
63595+ *path = gr_to_filename_nolock(dentry, mnt);
63596+
63597+ tmp = globbed;
63598+
63599+ while (tmp) {
63600+ if (!glob_match(tmp->filename, *path))
63601+ return tmp;
63602+ tmp = tmp->next;
63603+ }
63604+
63605+ return NULL;
63606+}
63607+
63608+static struct acl_object_label *
63609+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63610+ const ino_t curr_ino, const dev_t curr_dev,
63611+ const struct acl_subject_label *subj, char **path, const int checkglob)
63612+{
63613+ struct acl_subject_label *tmpsubj;
63614+ struct acl_object_label *retval;
63615+ struct acl_object_label *retval2;
63616+
63617+ tmpsubj = (struct acl_subject_label *) subj;
63618+ read_lock(&gr_inode_lock);
63619+ do {
63620+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
63621+ if (retval) {
63622+ if (checkglob && retval->globbed) {
63623+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
63624+ if (retval2)
63625+ retval = retval2;
63626+ }
63627+ break;
63628+ }
63629+ } while ((tmpsubj = tmpsubj->parent_subject));
63630+ read_unlock(&gr_inode_lock);
63631+
63632+ return retval;
63633+}
63634+
63635+static __inline__ struct acl_object_label *
63636+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63637+ struct dentry *curr_dentry,
63638+ const struct acl_subject_label *subj, char **path, const int checkglob)
63639+{
63640+ int newglob = checkglob;
63641+ ino_t inode;
63642+ dev_t device;
63643+
63644+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
63645+ as we don't want a / * rule to match instead of the / object
63646+ don't do this for create lookups that call this function though, since they're looking up
63647+ on the parent and thus need globbing checks on all paths
63648+ */
63649+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
63650+ newglob = GR_NO_GLOB;
63651+
63652+ spin_lock(&curr_dentry->d_lock);
63653+ inode = curr_dentry->d_inode->i_ino;
63654+ device = __get_dev(curr_dentry);
63655+ spin_unlock(&curr_dentry->d_lock);
63656+
63657+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
63658+}
63659+
63660+#ifdef CONFIG_HUGETLBFS
63661+static inline bool
63662+is_hugetlbfs_mnt(const struct vfsmount *mnt)
63663+{
63664+ int i;
63665+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
63666+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
63667+ return true;
63668+ }
63669+
63670+ return false;
63671+}
63672+#endif
63673+
63674+static struct acl_object_label *
63675+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63676+ const struct acl_subject_label *subj, char *path, const int checkglob)
63677+{
63678+ struct dentry *dentry = (struct dentry *) l_dentry;
63679+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63680+ struct mount *real_mnt = real_mount(mnt);
63681+ struct acl_object_label *retval;
63682+ struct dentry *parent;
63683+
63684+ br_read_lock(&vfsmount_lock);
63685+ write_seqlock(&rename_lock);
63686+
63687+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
63688+#ifdef CONFIG_NET
63689+ mnt == sock_mnt ||
63690+#endif
63691+#ifdef CONFIG_HUGETLBFS
63692+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
63693+#endif
63694+ /* ignore Eric Biederman */
63695+ IS_PRIVATE(l_dentry->d_inode))) {
63696+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
63697+ goto out;
63698+ }
63699+
63700+ for (;;) {
63701+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
63702+ break;
63703+
63704+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
63705+ if (!mnt_has_parent(real_mnt))
63706+ break;
63707+
63708+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63709+ if (retval != NULL)
63710+ goto out;
63711+
63712+ dentry = real_mnt->mnt_mountpoint;
63713+ real_mnt = real_mnt->mnt_parent;
63714+ mnt = &real_mnt->mnt;
63715+ continue;
63716+ }
63717+
63718+ parent = dentry->d_parent;
63719+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63720+ if (retval != NULL)
63721+ goto out;
63722+
63723+ dentry = parent;
63724+ }
63725+
63726+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63727+
63728+ /* gr_real_root is pinned so we don't have to hold a reference */
63729+ if (retval == NULL)
63730+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
63731+out:
63732+ write_sequnlock(&rename_lock);
63733+ br_read_unlock(&vfsmount_lock);
63734+
63735+ BUG_ON(retval == NULL);
63736+
63737+ return retval;
63738+}
63739+
63740+static __inline__ struct acl_object_label *
63741+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63742+ const struct acl_subject_label *subj)
63743+{
63744+ char *path = NULL;
63745+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
63746+}
63747+
63748+static __inline__ struct acl_object_label *
63749+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63750+ const struct acl_subject_label *subj)
63751+{
63752+ char *path = NULL;
63753+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
63754+}
63755+
63756+static __inline__ struct acl_object_label *
63757+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63758+ const struct acl_subject_label *subj, char *path)
63759+{
63760+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
63761+}
63762+
63763+struct acl_subject_label *
63764+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63765+ const struct acl_role_label *role)
63766+{
63767+ struct dentry *dentry = (struct dentry *) l_dentry;
63768+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63769+ struct mount *real_mnt = real_mount(mnt);
63770+ struct acl_subject_label *retval;
63771+ struct dentry *parent;
63772+
63773+ br_read_lock(&vfsmount_lock);
63774+ write_seqlock(&rename_lock);
63775+
63776+ for (;;) {
63777+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
63778+ break;
63779+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
63780+ if (!mnt_has_parent(real_mnt))
63781+ break;
63782+
63783+ spin_lock(&dentry->d_lock);
63784+ read_lock(&gr_inode_lock);
63785+ retval =
63786+ lookup_acl_subj_label(dentry->d_inode->i_ino,
63787+ __get_dev(dentry), role);
63788+ read_unlock(&gr_inode_lock);
63789+ spin_unlock(&dentry->d_lock);
63790+ if (retval != NULL)
63791+ goto out;
63792+
63793+ dentry = real_mnt->mnt_mountpoint;
63794+ real_mnt = real_mnt->mnt_parent;
63795+ mnt = &real_mnt->mnt;
63796+ continue;
63797+ }
63798+
63799+ spin_lock(&dentry->d_lock);
63800+ read_lock(&gr_inode_lock);
63801+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
63802+ __get_dev(dentry), role);
63803+ read_unlock(&gr_inode_lock);
63804+ parent = dentry->d_parent;
63805+ spin_unlock(&dentry->d_lock);
63806+
63807+ if (retval != NULL)
63808+ goto out;
63809+
63810+ dentry = parent;
63811+ }
63812+
63813+ spin_lock(&dentry->d_lock);
63814+ read_lock(&gr_inode_lock);
63815+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
63816+ __get_dev(dentry), role);
63817+ read_unlock(&gr_inode_lock);
63818+ spin_unlock(&dentry->d_lock);
63819+
63820+ if (unlikely(retval == NULL)) {
63821+ /* gr_real_root is pinned, we don't need to hold a reference */
63822+ read_lock(&gr_inode_lock);
63823+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
63824+ __get_dev(gr_real_root.dentry), role);
63825+ read_unlock(&gr_inode_lock);
63826+ }
63827+out:
63828+ write_sequnlock(&rename_lock);
63829+ br_read_unlock(&vfsmount_lock);
63830+
63831+ BUG_ON(retval == NULL);
63832+
63833+ return retval;
63834+}
63835+
63836+void
63837+assign_special_role(const char *rolename)
63838+{
63839+ struct acl_object_label *obj;
63840+ struct acl_role_label *r;
63841+ struct acl_role_label *assigned = NULL;
63842+ struct task_struct *tsk;
63843+ struct file *filp;
63844+
63845+ FOR_EACH_ROLE_START(r)
63846+ if (!strcmp(rolename, r->rolename) &&
63847+ (r->roletype & GR_ROLE_SPECIAL)) {
63848+ assigned = r;
63849+ break;
63850+ }
63851+ FOR_EACH_ROLE_END(r)
63852+
63853+ if (!assigned)
63854+ return;
63855+
63856+ read_lock(&tasklist_lock);
63857+ read_lock(&grsec_exec_file_lock);
63858+
63859+ tsk = current->real_parent;
63860+ if (tsk == NULL)
63861+ goto out_unlock;
63862+
63863+ filp = tsk->exec_file;
63864+ if (filp == NULL)
63865+ goto out_unlock;
63866+
63867+ tsk->is_writable = 0;
63868+ tsk->inherited = 0;
63869+
63870+ tsk->acl_sp_role = 1;
63871+ tsk->acl_role_id = ++acl_sp_role_value;
63872+ tsk->role = assigned;
63873+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
63874+
63875+ /* ignore additional mmap checks for processes that are writable
63876+ by the default ACL */
63877+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
63878+ if (unlikely(obj->mode & GR_WRITE))
63879+ tsk->is_writable = 1;
63880+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
63881+ if (unlikely(obj->mode & GR_WRITE))
63882+ tsk->is_writable = 1;
63883+
63884+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63885+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
63886+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
63887+#endif
63888+
63889+out_unlock:
63890+ read_unlock(&grsec_exec_file_lock);
63891+ read_unlock(&tasklist_lock);
63892+ return;
63893+}
63894+
63895+
63896+static void
63897+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
63898+{
63899+ struct task_struct *task = current;
63900+ const struct cred *cred = current_cred();
63901+
63902+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
63903+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63904+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63905+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
63906+
63907+ return;
63908+}
63909+
63910+static void
63911+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
63912+{
63913+ struct task_struct *task = current;
63914+ const struct cred *cred = current_cred();
63915+
63916+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
63917+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63918+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63919+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
63920+
63921+ return;
63922+}
63923+
63924+static void
63925+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
63926+{
63927+ struct task_struct *task = current;
63928+ const struct cred *cred = current_cred();
63929+
63930+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
63931+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63932+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63933+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
63934+
63935+ return;
63936+}
63937+
63938+static void
63939+gr_set_proc_res(struct task_struct *task)
63940+{
63941+ struct acl_subject_label *proc;
63942+ unsigned short i;
63943+
63944+ proc = task->acl;
63945+
63946+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
63947+ return;
63948+
63949+ for (i = 0; i < RLIM_NLIMITS; i++) {
63950+ if (!(proc->resmask & (1U << i)))
63951+ continue;
63952+
63953+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
63954+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
63955+
63956+ if (i == RLIMIT_CPU)
63957+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
63958+ }
63959+
63960+ return;
63961+}
63962+
63963+/* both of the below must be called with
63964+ rcu_read_lock();
63965+ read_lock(&tasklist_lock);
63966+ read_lock(&grsec_exec_file_lock);
63967+*/
63968+
63969+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
63970+{
63971+ char *tmpname;
63972+ struct acl_subject_label *tmpsubj;
63973+ struct file *filp;
63974+ struct name_entry *nmatch;
63975+
63976+ filp = task->exec_file;
63977+ if (filp == NULL)
63978+ return NULL;
63979+
63980+ /* the following is to apply the correct subject
63981+ on binaries running when the RBAC system
63982+ is enabled, when the binaries have been
63983+ replaced or deleted since their execution
63984+ -----
63985+ when the RBAC system starts, the inode/dev
63986+ from exec_file will be one the RBAC system
63987+ is unaware of. It only knows the inode/dev
63988+ of the present file on disk, or the absence
63989+ of it.
63990+ */
63991+
63992+ if (filename)
63993+ nmatch = __lookup_name_entry(state, filename);
63994+ else {
63995+ preempt_disable();
63996+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
63997+
63998+ nmatch = __lookup_name_entry(state, tmpname);
63999+ preempt_enable();
64000+ }
64001+ tmpsubj = NULL;
64002+ if (nmatch) {
64003+ if (nmatch->deleted)
64004+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
64005+ else
64006+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
64007+ }
64008+ /* this also works for the reload case -- if we don't match a potentially inherited subject
64009+ then we fall back to a normal lookup based on the binary's ino/dev
64010+ */
64011+ if (tmpsubj == NULL)
64012+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
64013+
64014+ return tmpsubj;
64015+}
64016+
64017+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
64018+{
64019+ return __gr_get_subject_for_task(&running_polstate, task, filename);
64020+}
64021+
64022+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
64023+{
64024+ struct acl_object_label *obj;
64025+ struct file *filp;
64026+
64027+ filp = task->exec_file;
64028+
64029+ task->acl = subj;
64030+ task->is_writable = 0;
64031+ /* ignore additional mmap checks for processes that are writable
64032+ by the default ACL */
64033+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
64034+ if (unlikely(obj->mode & GR_WRITE))
64035+ task->is_writable = 1;
64036+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64037+ if (unlikely(obj->mode & GR_WRITE))
64038+ task->is_writable = 1;
64039+
64040+ gr_set_proc_res(task);
64041+
64042+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64043+ 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);
64044+#endif
64045+}
64046+
64047+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
64048+{
64049+ __gr_apply_subject_to_task(&running_polstate, task, subj);
64050+}
64051+
64052+__u32
64053+gr_search_file(const struct dentry * dentry, const __u32 mode,
64054+ const struct vfsmount * mnt)
64055+{
64056+ __u32 retval = mode;
64057+ struct acl_subject_label *curracl;
64058+ struct acl_object_label *currobj;
64059+
64060+ if (unlikely(!(gr_status & GR_READY)))
64061+ return (mode & ~GR_AUDITS);
64062+
64063+ curracl = current->acl;
64064+
64065+ currobj = chk_obj_label(dentry, mnt, curracl);
64066+ retval = currobj->mode & mode;
64067+
64068+ /* if we're opening a specified transfer file for writing
64069+ (e.g. /dev/initctl), then transfer our role to init
64070+ */
64071+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64072+ current->role->roletype & GR_ROLE_PERSIST)) {
64073+ struct task_struct *task = init_pid_ns.child_reaper;
64074+
64075+ if (task->role != current->role) {
64076+ struct acl_subject_label *subj;
64077+
64078+ task->acl_sp_role = 0;
64079+ task->acl_role_id = current->acl_role_id;
64080+ task->role = current->role;
64081+ rcu_read_lock();
64082+ read_lock(&grsec_exec_file_lock);
64083+ subj = gr_get_subject_for_task(task, NULL);
64084+ gr_apply_subject_to_task(task, subj);
64085+ read_unlock(&grsec_exec_file_lock);
64086+ rcu_read_unlock();
64087+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64088+ }
64089+ }
64090+
64091+ if (unlikely
64092+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64093+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64094+ __u32 new_mode = mode;
64095+
64096+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64097+
64098+ retval = new_mode;
64099+
64100+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64101+ new_mode |= GR_INHERIT;
64102+
64103+ if (!(mode & GR_NOLEARN))
64104+ gr_log_learn(dentry, mnt, new_mode);
64105+ }
64106+
64107+ return retval;
64108+}
64109+
64110+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64111+ const struct dentry *parent,
64112+ const struct vfsmount *mnt)
64113+{
64114+ struct name_entry *match;
64115+ struct acl_object_label *matchpo;
64116+ struct acl_subject_label *curracl;
64117+ char *path;
64118+
64119+ if (unlikely(!(gr_status & GR_READY)))
64120+ return NULL;
64121+
64122+ preempt_disable();
64123+ path = gr_to_filename_rbac(new_dentry, mnt);
64124+ match = lookup_name_entry_create(path);
64125+
64126+ curracl = current->acl;
64127+
64128+ if (match) {
64129+ read_lock(&gr_inode_lock);
64130+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64131+ read_unlock(&gr_inode_lock);
64132+
64133+ if (matchpo) {
64134+ preempt_enable();
64135+ return matchpo;
64136+ }
64137+ }
64138+
64139+ // lookup parent
64140+
64141+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64142+
64143+ preempt_enable();
64144+ return matchpo;
64145+}
64146+
64147+__u32
64148+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64149+ const struct vfsmount * mnt, const __u32 mode)
64150+{
64151+ struct acl_object_label *matchpo;
64152+ __u32 retval;
64153+
64154+ if (unlikely(!(gr_status & GR_READY)))
64155+ return (mode & ~GR_AUDITS);
64156+
64157+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64158+
64159+ retval = matchpo->mode & mode;
64160+
64161+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64162+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64163+ __u32 new_mode = mode;
64164+
64165+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64166+
64167+ gr_log_learn(new_dentry, mnt, new_mode);
64168+ return new_mode;
64169+ }
64170+
64171+ return retval;
64172+}
64173+
64174+__u32
64175+gr_check_link(const struct dentry * new_dentry,
64176+ const struct dentry * parent_dentry,
64177+ const struct vfsmount * parent_mnt,
64178+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64179+{
64180+ struct acl_object_label *obj;
64181+ __u32 oldmode, newmode;
64182+ __u32 needmode;
64183+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64184+ GR_DELETE | GR_INHERIT;
64185+
64186+ if (unlikely(!(gr_status & GR_READY)))
64187+ return (GR_CREATE | GR_LINK);
64188+
64189+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64190+ oldmode = obj->mode;
64191+
64192+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64193+ newmode = obj->mode;
64194+
64195+ needmode = newmode & checkmodes;
64196+
64197+ // old name for hardlink must have at least the permissions of the new name
64198+ if ((oldmode & needmode) != needmode)
64199+ goto bad;
64200+
64201+ // if old name had restrictions/auditing, make sure the new name does as well
64202+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64203+
64204+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64205+ if (is_privileged_binary(old_dentry))
64206+ needmode |= GR_SETID;
64207+
64208+ if ((newmode & needmode) != needmode)
64209+ goto bad;
64210+
64211+ // enforce minimum permissions
64212+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64213+ return newmode;
64214+bad:
64215+ needmode = oldmode;
64216+ if (is_privileged_binary(old_dentry))
64217+ needmode |= GR_SETID;
64218+
64219+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64220+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64221+ return (GR_CREATE | GR_LINK);
64222+ } else if (newmode & GR_SUPPRESS)
64223+ return GR_SUPPRESS;
64224+ else
64225+ return 0;
64226+}
64227+
64228+int
64229+gr_check_hidden_task(const struct task_struct *task)
64230+{
64231+ if (unlikely(!(gr_status & GR_READY)))
64232+ return 0;
64233+
64234+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64235+ return 1;
64236+
64237+ return 0;
64238+}
64239+
64240+int
64241+gr_check_protected_task(const struct task_struct *task)
64242+{
64243+ if (unlikely(!(gr_status & GR_READY) || !task))
64244+ return 0;
64245+
64246+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64247+ task->acl != current->acl)
64248+ return 1;
64249+
64250+ return 0;
64251+}
64252+
64253+int
64254+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64255+{
64256+ struct task_struct *p;
64257+ int ret = 0;
64258+
64259+ if (unlikely(!(gr_status & GR_READY) || !pid))
64260+ return ret;
64261+
64262+ read_lock(&tasklist_lock);
64263+ do_each_pid_task(pid, type, p) {
64264+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64265+ p->acl != current->acl) {
64266+ ret = 1;
64267+ goto out;
64268+ }
64269+ } while_each_pid_task(pid, type, p);
64270+out:
64271+ read_unlock(&tasklist_lock);
64272+
64273+ return ret;
64274+}
64275+
64276+void
64277+gr_copy_label(struct task_struct *tsk)
64278+{
64279+ struct task_struct *p = current;
64280+
64281+ tsk->inherited = p->inherited;
64282+ tsk->acl_sp_role = 0;
64283+ tsk->acl_role_id = p->acl_role_id;
64284+ tsk->acl = p->acl;
64285+ tsk->role = p->role;
64286+ tsk->signal->used_accept = 0;
64287+ tsk->signal->curr_ip = p->signal->curr_ip;
64288+ tsk->signal->saved_ip = p->signal->saved_ip;
64289+ if (p->exec_file)
64290+ get_file(p->exec_file);
64291+ tsk->exec_file = p->exec_file;
64292+ tsk->is_writable = p->is_writable;
64293+ if (unlikely(p->signal->used_accept)) {
64294+ p->signal->curr_ip = 0;
64295+ p->signal->saved_ip = 0;
64296+ }
64297+
64298+ return;
64299+}
64300+
64301+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64302+
64303+int
64304+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64305+{
64306+ unsigned int i;
64307+ __u16 num;
64308+ uid_t *uidlist;
64309+ uid_t curuid;
64310+ int realok = 0;
64311+ int effectiveok = 0;
64312+ int fsok = 0;
64313+ uid_t globalreal, globaleffective, globalfs;
64314+
64315+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64316+ struct user_struct *user;
64317+
64318+ if (!uid_valid(real))
64319+ goto skipit;
64320+
64321+ /* find user based on global namespace */
64322+
64323+ globalreal = GR_GLOBAL_UID(real);
64324+
64325+ user = find_user(make_kuid(&init_user_ns, globalreal));
64326+ if (user == NULL)
64327+ goto skipit;
64328+
64329+ if (gr_process_kernel_setuid_ban(user)) {
64330+ /* for find_user */
64331+ free_uid(user);
64332+ return 1;
64333+ }
64334+
64335+ /* for find_user */
64336+ free_uid(user);
64337+
64338+skipit:
64339+#endif
64340+
64341+ if (unlikely(!(gr_status & GR_READY)))
64342+ return 0;
64343+
64344+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64345+ gr_log_learn_uid_change(real, effective, fs);
64346+
64347+ num = current->acl->user_trans_num;
64348+ uidlist = current->acl->user_transitions;
64349+
64350+ if (uidlist == NULL)
64351+ return 0;
64352+
64353+ if (!uid_valid(real)) {
64354+ realok = 1;
64355+ globalreal = (uid_t)-1;
64356+ } else {
64357+ globalreal = GR_GLOBAL_UID(real);
64358+ }
64359+ if (!uid_valid(effective)) {
64360+ effectiveok = 1;
64361+ globaleffective = (uid_t)-1;
64362+ } else {
64363+ globaleffective = GR_GLOBAL_UID(effective);
64364+ }
64365+ if (!uid_valid(fs)) {
64366+ fsok = 1;
64367+ globalfs = (uid_t)-1;
64368+ } else {
64369+ globalfs = GR_GLOBAL_UID(fs);
64370+ }
64371+
64372+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64373+ for (i = 0; i < num; i++) {
64374+ curuid = uidlist[i];
64375+ if (globalreal == curuid)
64376+ realok = 1;
64377+ if (globaleffective == curuid)
64378+ effectiveok = 1;
64379+ if (globalfs == curuid)
64380+ fsok = 1;
64381+ }
64382+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64383+ for (i = 0; i < num; i++) {
64384+ curuid = uidlist[i];
64385+ if (globalreal == curuid)
64386+ break;
64387+ if (globaleffective == curuid)
64388+ break;
64389+ if (globalfs == curuid)
64390+ break;
64391+ }
64392+ /* not in deny list */
64393+ if (i == num) {
64394+ realok = 1;
64395+ effectiveok = 1;
64396+ fsok = 1;
64397+ }
64398+ }
64399+
64400+ if (realok && effectiveok && fsok)
64401+ return 0;
64402+ else {
64403+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64404+ return 1;
64405+ }
64406+}
64407+
64408+int
64409+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64410+{
64411+ unsigned int i;
64412+ __u16 num;
64413+ gid_t *gidlist;
64414+ gid_t curgid;
64415+ int realok = 0;
64416+ int effectiveok = 0;
64417+ int fsok = 0;
64418+ gid_t globalreal, globaleffective, globalfs;
64419+
64420+ if (unlikely(!(gr_status & GR_READY)))
64421+ return 0;
64422+
64423+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64424+ gr_log_learn_gid_change(real, effective, fs);
64425+
64426+ num = current->acl->group_trans_num;
64427+ gidlist = current->acl->group_transitions;
64428+
64429+ if (gidlist == NULL)
64430+ return 0;
64431+
64432+ if (!gid_valid(real)) {
64433+ realok = 1;
64434+ globalreal = (gid_t)-1;
64435+ } else {
64436+ globalreal = GR_GLOBAL_GID(real);
64437+ }
64438+ if (!gid_valid(effective)) {
64439+ effectiveok = 1;
64440+ globaleffective = (gid_t)-1;
64441+ } else {
64442+ globaleffective = GR_GLOBAL_GID(effective);
64443+ }
64444+ if (!gid_valid(fs)) {
64445+ fsok = 1;
64446+ globalfs = (gid_t)-1;
64447+ } else {
64448+ globalfs = GR_GLOBAL_GID(fs);
64449+ }
64450+
64451+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64452+ for (i = 0; i < num; i++) {
64453+ curgid = gidlist[i];
64454+ if (globalreal == curgid)
64455+ realok = 1;
64456+ if (globaleffective == curgid)
64457+ effectiveok = 1;
64458+ if (globalfs == curgid)
64459+ fsok = 1;
64460+ }
64461+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64462+ for (i = 0; i < num; i++) {
64463+ curgid = gidlist[i];
64464+ if (globalreal == curgid)
64465+ break;
64466+ if (globaleffective == curgid)
64467+ break;
64468+ if (globalfs == curgid)
64469+ break;
64470+ }
64471+ /* not in deny list */
64472+ if (i == num) {
64473+ realok = 1;
64474+ effectiveok = 1;
64475+ fsok = 1;
64476+ }
64477+ }
64478+
64479+ if (realok && effectiveok && fsok)
64480+ return 0;
64481+ else {
64482+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64483+ return 1;
64484+ }
64485+}
64486+
64487+extern int gr_acl_is_capable(const int cap);
64488+
64489+void
64490+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64491+{
64492+ struct acl_role_label *role = task->role;
64493+ struct acl_subject_label *subj = NULL;
64494+ struct acl_object_label *obj;
64495+ struct file *filp;
64496+ uid_t uid;
64497+ gid_t gid;
64498+
64499+ if (unlikely(!(gr_status & GR_READY)))
64500+ return;
64501+
64502+ uid = GR_GLOBAL_UID(kuid);
64503+ gid = GR_GLOBAL_GID(kgid);
64504+
64505+ filp = task->exec_file;
64506+
64507+ /* kernel process, we'll give them the kernel role */
64508+ if (unlikely(!filp)) {
64509+ task->role = running_polstate.kernel_role;
64510+ task->acl = running_polstate.kernel_role->root_label;
64511+ return;
64512+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
64513+ /* save the current ip at time of role lookup so that the proper
64514+ IP will be learned for role_allowed_ip */
64515+ task->signal->saved_ip = task->signal->curr_ip;
64516+ role = lookup_acl_role_label(task, uid, gid);
64517+ }
64518+
64519+ /* don't change the role if we're not a privileged process */
64520+ if (role && task->role != role &&
64521+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64522+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64523+ return;
64524+
64525+ /* perform subject lookup in possibly new role
64526+ we can use this result below in the case where role == task->role
64527+ */
64528+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64529+
64530+ /* if we changed uid/gid, but result in the same role
64531+ and are using inheritance, don't lose the inherited subject
64532+ if current subject is other than what normal lookup
64533+ would result in, we arrived via inheritance, don't
64534+ lose subject
64535+ */
64536+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64537+ (subj == task->acl)))
64538+ task->acl = subj;
64539+
64540+ /* leave task->inherited unaffected */
64541+
64542+ task->role = role;
64543+
64544+ task->is_writable = 0;
64545+
64546+ /* ignore additional mmap checks for processes that are writable
64547+ by the default ACL */
64548+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
64549+ if (unlikely(obj->mode & GR_WRITE))
64550+ task->is_writable = 1;
64551+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64552+ if (unlikely(obj->mode & GR_WRITE))
64553+ task->is_writable = 1;
64554+
64555+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64556+ 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);
64557+#endif
64558+
64559+ gr_set_proc_res(task);
64560+
64561+ return;
64562+}
64563+
64564+int
64565+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64566+ const int unsafe_flags)
64567+{
64568+ struct task_struct *task = current;
64569+ struct acl_subject_label *newacl;
64570+ struct acl_object_label *obj;
64571+ __u32 retmode;
64572+
64573+ if (unlikely(!(gr_status & GR_READY)))
64574+ return 0;
64575+
64576+ newacl = chk_subj_label(dentry, mnt, task->role);
64577+
64578+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64579+ did an exec
64580+ */
64581+ rcu_read_lock();
64582+ read_lock(&tasklist_lock);
64583+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64584+ (task->parent->acl->mode & GR_POVERRIDE))) {
64585+ read_unlock(&tasklist_lock);
64586+ rcu_read_unlock();
64587+ goto skip_check;
64588+ }
64589+ read_unlock(&tasklist_lock);
64590+ rcu_read_unlock();
64591+
64592+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64593+ !(task->role->roletype & GR_ROLE_GOD) &&
64594+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64595+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64596+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64597+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64598+ else
64599+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64600+ return -EACCES;
64601+ }
64602+
64603+skip_check:
64604+
64605+ obj = chk_obj_label(dentry, mnt, task->acl);
64606+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64607+
64608+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64609+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64610+ if (obj->nested)
64611+ task->acl = obj->nested;
64612+ else
64613+ task->acl = newacl;
64614+ task->inherited = 0;
64615+ } else {
64616+ task->inherited = 1;
64617+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64618+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64619+ }
64620+
64621+ task->is_writable = 0;
64622+
64623+ /* ignore additional mmap checks for processes that are writable
64624+ by the default ACL */
64625+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
64626+ if (unlikely(obj->mode & GR_WRITE))
64627+ task->is_writable = 1;
64628+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64629+ if (unlikely(obj->mode & GR_WRITE))
64630+ task->is_writable = 1;
64631+
64632+ gr_set_proc_res(task);
64633+
64634+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64635+ 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);
64636+#endif
64637+ return 0;
64638+}
64639+
64640+/* always called with valid inodev ptr */
64641+static void
64642+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64643+{
64644+ struct acl_object_label *matchpo;
64645+ struct acl_subject_label *matchps;
64646+ struct acl_subject_label *subj;
64647+ struct acl_role_label *role;
64648+ unsigned int x;
64649+
64650+ FOR_EACH_ROLE_START(role)
64651+ FOR_EACH_SUBJECT_START(role, subj, x)
64652+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64653+ matchpo->mode |= GR_DELETED;
64654+ FOR_EACH_SUBJECT_END(subj,x)
64655+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64656+ /* nested subjects aren't in the role's subj_hash table */
64657+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64658+ matchpo->mode |= GR_DELETED;
64659+ FOR_EACH_NESTED_SUBJECT_END(subj)
64660+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64661+ matchps->mode |= GR_DELETED;
64662+ FOR_EACH_ROLE_END(role)
64663+
64664+ inodev->nentry->deleted = 1;
64665+
64666+ return;
64667+}
64668+
64669+void
64670+gr_handle_delete(const ino_t ino, const dev_t dev)
64671+{
64672+ struct inodev_entry *inodev;
64673+
64674+ if (unlikely(!(gr_status & GR_READY)))
64675+ return;
64676+
64677+ write_lock(&gr_inode_lock);
64678+ inodev = lookup_inodev_entry(ino, dev);
64679+ if (inodev != NULL)
64680+ do_handle_delete(inodev, ino, dev);
64681+ write_unlock(&gr_inode_lock);
64682+
64683+ return;
64684+}
64685+
64686+static void
64687+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64688+ const ino_t newinode, const dev_t newdevice,
64689+ struct acl_subject_label *subj)
64690+{
64691+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64692+ struct acl_object_label *match;
64693+
64694+ match = subj->obj_hash[index];
64695+
64696+ while (match && (match->inode != oldinode ||
64697+ match->device != olddevice ||
64698+ !(match->mode & GR_DELETED)))
64699+ match = match->next;
64700+
64701+ if (match && (match->inode == oldinode)
64702+ && (match->device == olddevice)
64703+ && (match->mode & GR_DELETED)) {
64704+ if (match->prev == NULL) {
64705+ subj->obj_hash[index] = match->next;
64706+ if (match->next != NULL)
64707+ match->next->prev = NULL;
64708+ } else {
64709+ match->prev->next = match->next;
64710+ if (match->next != NULL)
64711+ match->next->prev = match->prev;
64712+ }
64713+ match->prev = NULL;
64714+ match->next = NULL;
64715+ match->inode = newinode;
64716+ match->device = newdevice;
64717+ match->mode &= ~GR_DELETED;
64718+
64719+ insert_acl_obj_label(match, subj);
64720+ }
64721+
64722+ return;
64723+}
64724+
64725+static void
64726+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64727+ const ino_t newinode, const dev_t newdevice,
64728+ struct acl_role_label *role)
64729+{
64730+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64731+ struct acl_subject_label *match;
64732+
64733+ match = role->subj_hash[index];
64734+
64735+ while (match && (match->inode != oldinode ||
64736+ match->device != olddevice ||
64737+ !(match->mode & GR_DELETED)))
64738+ match = match->next;
64739+
64740+ if (match && (match->inode == oldinode)
64741+ && (match->device == olddevice)
64742+ && (match->mode & GR_DELETED)) {
64743+ if (match->prev == NULL) {
64744+ role->subj_hash[index] = match->next;
64745+ if (match->next != NULL)
64746+ match->next->prev = NULL;
64747+ } else {
64748+ match->prev->next = match->next;
64749+ if (match->next != NULL)
64750+ match->next->prev = match->prev;
64751+ }
64752+ match->prev = NULL;
64753+ match->next = NULL;
64754+ match->inode = newinode;
64755+ match->device = newdevice;
64756+ match->mode &= ~GR_DELETED;
64757+
64758+ insert_acl_subj_label(match, role);
64759+ }
64760+
64761+ return;
64762+}
64763+
64764+static void
64765+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64766+ const ino_t newinode, const dev_t newdevice)
64767+{
64768+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
64769+ struct inodev_entry *match;
64770+
64771+ match = running_polstate.inodev_set.i_hash[index];
64772+
64773+ while (match && (match->nentry->inode != oldinode ||
64774+ match->nentry->device != olddevice || !match->nentry->deleted))
64775+ match = match->next;
64776+
64777+ if (match && (match->nentry->inode == oldinode)
64778+ && (match->nentry->device == olddevice) &&
64779+ match->nentry->deleted) {
64780+ if (match->prev == NULL) {
64781+ running_polstate.inodev_set.i_hash[index] = match->next;
64782+ if (match->next != NULL)
64783+ match->next->prev = NULL;
64784+ } else {
64785+ match->prev->next = match->next;
64786+ if (match->next != NULL)
64787+ match->next->prev = match->prev;
64788+ }
64789+ match->prev = NULL;
64790+ match->next = NULL;
64791+ match->nentry->inode = newinode;
64792+ match->nentry->device = newdevice;
64793+ match->nentry->deleted = 0;
64794+
64795+ insert_inodev_entry(match);
64796+ }
64797+
64798+ return;
64799+}
64800+
64801+static void
64802+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
64803+{
64804+ struct acl_subject_label *subj;
64805+ struct acl_role_label *role;
64806+ unsigned int x;
64807+
64808+ FOR_EACH_ROLE_START(role)
64809+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
64810+
64811+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64812+ if ((subj->inode == ino) && (subj->device == dev)) {
64813+ subj->inode = ino;
64814+ subj->device = dev;
64815+ }
64816+ /* nested subjects aren't in the role's subj_hash table */
64817+ update_acl_obj_label(matchn->inode, matchn->device,
64818+ ino, dev, subj);
64819+ FOR_EACH_NESTED_SUBJECT_END(subj)
64820+ FOR_EACH_SUBJECT_START(role, subj, x)
64821+ update_acl_obj_label(matchn->inode, matchn->device,
64822+ ino, dev, subj);
64823+ FOR_EACH_SUBJECT_END(subj,x)
64824+ FOR_EACH_ROLE_END(role)
64825+
64826+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
64827+
64828+ return;
64829+}
64830+
64831+static void
64832+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
64833+ const struct vfsmount *mnt)
64834+{
64835+ ino_t ino = dentry->d_inode->i_ino;
64836+ dev_t dev = __get_dev(dentry);
64837+
64838+ __do_handle_create(matchn, ino, dev);
64839+
64840+ return;
64841+}
64842+
64843+void
64844+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64845+{
64846+ struct name_entry *matchn;
64847+
64848+ if (unlikely(!(gr_status & GR_READY)))
64849+ return;
64850+
64851+ preempt_disable();
64852+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
64853+
64854+ if (unlikely((unsigned long)matchn)) {
64855+ write_lock(&gr_inode_lock);
64856+ do_handle_create(matchn, dentry, mnt);
64857+ write_unlock(&gr_inode_lock);
64858+ }
64859+ preempt_enable();
64860+
64861+ return;
64862+}
64863+
64864+void
64865+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64866+{
64867+ struct name_entry *matchn;
64868+
64869+ if (unlikely(!(gr_status & GR_READY)))
64870+ return;
64871+
64872+ preempt_disable();
64873+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
64874+
64875+ if (unlikely((unsigned long)matchn)) {
64876+ write_lock(&gr_inode_lock);
64877+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
64878+ write_unlock(&gr_inode_lock);
64879+ }
64880+ preempt_enable();
64881+
64882+ return;
64883+}
64884+
64885+void
64886+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64887+ struct dentry *old_dentry,
64888+ struct dentry *new_dentry,
64889+ struct vfsmount *mnt, const __u8 replace)
64890+{
64891+ struct name_entry *matchn;
64892+ struct inodev_entry *inodev;
64893+ struct inode *inode = new_dentry->d_inode;
64894+ ino_t old_ino = old_dentry->d_inode->i_ino;
64895+ dev_t old_dev = __get_dev(old_dentry);
64896+
64897+ /* vfs_rename swaps the name and parent link for old_dentry and
64898+ new_dentry
64899+ at this point, old_dentry has the new name, parent link, and inode
64900+ for the renamed file
64901+ if a file is being replaced by a rename, new_dentry has the inode
64902+ and name for the replaced file
64903+ */
64904+
64905+ if (unlikely(!(gr_status & GR_READY)))
64906+ return;
64907+
64908+ preempt_disable();
64909+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
64910+
64911+ /* we wouldn't have to check d_inode if it weren't for
64912+ NFS silly-renaming
64913+ */
64914+
64915+ write_lock(&gr_inode_lock);
64916+ if (unlikely(replace && inode)) {
64917+ ino_t new_ino = inode->i_ino;
64918+ dev_t new_dev = __get_dev(new_dentry);
64919+
64920+ inodev = lookup_inodev_entry(new_ino, new_dev);
64921+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
64922+ do_handle_delete(inodev, new_ino, new_dev);
64923+ }
64924+
64925+ inodev = lookup_inodev_entry(old_ino, old_dev);
64926+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
64927+ do_handle_delete(inodev, old_ino, old_dev);
64928+
64929+ if (unlikely((unsigned long)matchn))
64930+ do_handle_create(matchn, old_dentry, mnt);
64931+
64932+ write_unlock(&gr_inode_lock);
64933+ preempt_enable();
64934+
64935+ return;
64936+}
64937+
64938+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
64939+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
64940+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
64941+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
64942+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
64943+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
64944+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
64945+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
64946+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
64947+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
64948+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
64949+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
64950+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
64951+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
64952+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
64953+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
64954+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
64955+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
64956+};
64957+
64958+void
64959+gr_learn_resource(const struct task_struct *task,
64960+ const int res, const unsigned long wanted, const int gt)
64961+{
64962+ struct acl_subject_label *acl;
64963+ const struct cred *cred;
64964+
64965+ if (unlikely((gr_status & GR_READY) &&
64966+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
64967+ goto skip_reslog;
64968+
64969+ gr_log_resource(task, res, wanted, gt);
64970+skip_reslog:
64971+
64972+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
64973+ return;
64974+
64975+ acl = task->acl;
64976+
64977+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
64978+ !(acl->resmask & (1U << (unsigned short) res))))
64979+ return;
64980+
64981+ if (wanted >= acl->res[res].rlim_cur) {
64982+ unsigned long res_add;
64983+
64984+ res_add = wanted + res_learn_bumps[res];
64985+
64986+ acl->res[res].rlim_cur = res_add;
64987+
64988+ if (wanted > acl->res[res].rlim_max)
64989+ acl->res[res].rlim_max = res_add;
64990+
64991+ /* only log the subject filename, since resource logging is supported for
64992+ single-subject learning only */
64993+ rcu_read_lock();
64994+ cred = __task_cred(task);
64995+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
64996+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
64997+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
64998+ "", (unsigned long) res, &task->signal->saved_ip);
64999+ rcu_read_unlock();
65000+ }
65001+
65002+ return;
65003+}
65004+EXPORT_SYMBOL(gr_learn_resource);
65005+#endif
65006+
65007+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65008+void
65009+pax_set_initial_flags(struct linux_binprm *bprm)
65010+{
65011+ struct task_struct *task = current;
65012+ struct acl_subject_label *proc;
65013+ unsigned long flags;
65014+
65015+ if (unlikely(!(gr_status & GR_READY)))
65016+ return;
65017+
65018+ flags = pax_get_flags(task);
65019+
65020+ proc = task->acl;
65021+
65022+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65023+ flags &= ~MF_PAX_PAGEEXEC;
65024+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65025+ flags &= ~MF_PAX_SEGMEXEC;
65026+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65027+ flags &= ~MF_PAX_RANDMMAP;
65028+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65029+ flags &= ~MF_PAX_EMUTRAMP;
65030+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65031+ flags &= ~MF_PAX_MPROTECT;
65032+
65033+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65034+ flags |= MF_PAX_PAGEEXEC;
65035+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65036+ flags |= MF_PAX_SEGMEXEC;
65037+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65038+ flags |= MF_PAX_RANDMMAP;
65039+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65040+ flags |= MF_PAX_EMUTRAMP;
65041+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65042+ flags |= MF_PAX_MPROTECT;
65043+
65044+ pax_set_flags(task, flags);
65045+
65046+ return;
65047+}
65048+#endif
65049+
65050+int
65051+gr_handle_proc_ptrace(struct task_struct *task)
65052+{
65053+ struct file *filp;
65054+ struct task_struct *tmp = task;
65055+ struct task_struct *curtemp = current;
65056+ __u32 retmode;
65057+
65058+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65059+ if (unlikely(!(gr_status & GR_READY)))
65060+ return 0;
65061+#endif
65062+
65063+ read_lock(&tasklist_lock);
65064+ read_lock(&grsec_exec_file_lock);
65065+ filp = task->exec_file;
65066+
65067+ while (task_pid_nr(tmp) > 0) {
65068+ if (tmp == curtemp)
65069+ break;
65070+ tmp = tmp->real_parent;
65071+ }
65072+
65073+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65074+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65075+ read_unlock(&grsec_exec_file_lock);
65076+ read_unlock(&tasklist_lock);
65077+ return 1;
65078+ }
65079+
65080+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65081+ if (!(gr_status & GR_READY)) {
65082+ read_unlock(&grsec_exec_file_lock);
65083+ read_unlock(&tasklist_lock);
65084+ return 0;
65085+ }
65086+#endif
65087+
65088+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65089+ read_unlock(&grsec_exec_file_lock);
65090+ read_unlock(&tasklist_lock);
65091+
65092+ if (retmode & GR_NOPTRACE)
65093+ return 1;
65094+
65095+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65096+ && (current->acl != task->acl || (current->acl != current->role->root_label
65097+ && task_pid_nr(current) != task_pid_nr(task))))
65098+ return 1;
65099+
65100+ return 0;
65101+}
65102+
65103+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65104+{
65105+ if (unlikely(!(gr_status & GR_READY)))
65106+ return;
65107+
65108+ if (!(current->role->roletype & GR_ROLE_GOD))
65109+ return;
65110+
65111+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65112+ p->role->rolename, gr_task_roletype_to_char(p),
65113+ p->acl->filename);
65114+}
65115+
65116+int
65117+gr_handle_ptrace(struct task_struct *task, const long request)
65118+{
65119+ struct task_struct *tmp = task;
65120+ struct task_struct *curtemp = current;
65121+ __u32 retmode;
65122+
65123+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65124+ if (unlikely(!(gr_status & GR_READY)))
65125+ return 0;
65126+#endif
65127+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65128+ read_lock(&tasklist_lock);
65129+ while (task_pid_nr(tmp) > 0) {
65130+ if (tmp == curtemp)
65131+ break;
65132+ tmp = tmp->real_parent;
65133+ }
65134+
65135+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65136+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65137+ read_unlock(&tasklist_lock);
65138+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65139+ return 1;
65140+ }
65141+ read_unlock(&tasklist_lock);
65142+ }
65143+
65144+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65145+ if (!(gr_status & GR_READY))
65146+ return 0;
65147+#endif
65148+
65149+ read_lock(&grsec_exec_file_lock);
65150+ if (unlikely(!task->exec_file)) {
65151+ read_unlock(&grsec_exec_file_lock);
65152+ return 0;
65153+ }
65154+
65155+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65156+ read_unlock(&grsec_exec_file_lock);
65157+
65158+ if (retmode & GR_NOPTRACE) {
65159+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65160+ return 1;
65161+ }
65162+
65163+ if (retmode & GR_PTRACERD) {
65164+ switch (request) {
65165+ case PTRACE_SEIZE:
65166+ case PTRACE_POKETEXT:
65167+ case PTRACE_POKEDATA:
65168+ case PTRACE_POKEUSR:
65169+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65170+ case PTRACE_SETREGS:
65171+ case PTRACE_SETFPREGS:
65172+#endif
65173+#ifdef CONFIG_X86
65174+ case PTRACE_SETFPXREGS:
65175+#endif
65176+#ifdef CONFIG_ALTIVEC
65177+ case PTRACE_SETVRREGS:
65178+#endif
65179+ return 1;
65180+ default:
65181+ return 0;
65182+ }
65183+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65184+ !(current->role->roletype & GR_ROLE_GOD) &&
65185+ (current->acl != task->acl)) {
65186+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65187+ return 1;
65188+ }
65189+
65190+ return 0;
65191+}
65192+
65193+static int is_writable_mmap(const struct file *filp)
65194+{
65195+ struct task_struct *task = current;
65196+ struct acl_object_label *obj, *obj2;
65197+
65198+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
65199+ !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))) {
65200+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
65201+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
65202+ task->role->root_label);
65203+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
65204+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
65205+ return 1;
65206+ }
65207+ }
65208+ return 0;
65209+}
65210+
65211+int
65212+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
65213+{
65214+ __u32 mode;
65215+
65216+ if (unlikely(!file || !(prot & PROT_EXEC)))
65217+ return 1;
65218+
65219+ if (is_writable_mmap(file))
65220+ return 0;
65221+
65222+ mode =
65223+ gr_search_file(file->f_path.dentry,
65224+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65225+ file->f_path.mnt);
65226+
65227+ if (!gr_tpe_allow(file))
65228+ return 0;
65229+
65230+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65231+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65232+ return 0;
65233+ } else if (unlikely(!(mode & GR_EXEC))) {
65234+ return 0;
65235+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65236+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65237+ return 1;
65238+ }
65239+
65240+ return 1;
65241+}
65242+
65243+int
65244+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
65245+{
65246+ __u32 mode;
65247+
65248+ if (unlikely(!file || !(prot & PROT_EXEC)))
65249+ return 1;
65250+
65251+ if (is_writable_mmap(file))
65252+ return 0;
65253+
65254+ mode =
65255+ gr_search_file(file->f_path.dentry,
65256+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65257+ file->f_path.mnt);
65258+
65259+ if (!gr_tpe_allow(file))
65260+ return 0;
65261+
65262+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65263+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65264+ return 0;
65265+ } else if (unlikely(!(mode & GR_EXEC))) {
65266+ return 0;
65267+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65268+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65269+ return 1;
65270+ }
65271+
65272+ return 1;
65273+}
65274+
65275+void
65276+gr_acl_handle_psacct(struct task_struct *task, const long code)
65277+{
65278+ unsigned long runtime;
65279+ unsigned long cputime;
65280+ unsigned int wday, cday;
65281+ __u8 whr, chr;
65282+ __u8 wmin, cmin;
65283+ __u8 wsec, csec;
65284+ struct timespec timeval;
65285+
65286+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
65287+ !(task->acl->mode & GR_PROCACCT)))
65288+ return;
65289+
65290+ do_posix_clock_monotonic_gettime(&timeval);
65291+ runtime = timeval.tv_sec - task->start_time.tv_sec;
65292+ wday = runtime / (3600 * 24);
65293+ runtime -= wday * (3600 * 24);
65294+ whr = runtime / 3600;
65295+ runtime -= whr * 3600;
65296+ wmin = runtime / 60;
65297+ runtime -= wmin * 60;
65298+ wsec = runtime;
65299+
65300+ cputime = (task->utime + task->stime) / HZ;
65301+ cday = cputime / (3600 * 24);
65302+ cputime -= cday * (3600 * 24);
65303+ chr = cputime / 3600;
65304+ cputime -= chr * 3600;
65305+ cmin = cputime / 60;
65306+ cputime -= cmin * 60;
65307+ csec = cputime;
65308+
65309+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
65310+
65311+ return;
65312+}
65313+
65314+#ifdef CONFIG_TASKSTATS
65315+int gr_is_taskstats_denied(int pid)
65316+{
65317+ struct task_struct *task;
65318+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65319+ const struct cred *cred;
65320+#endif
65321+ int ret = 0;
65322+
65323+ /* restrict taskstats viewing to un-chrooted root users
65324+ who have the 'view' subject flag if the RBAC system is enabled
65325+ */
65326+
65327+ rcu_read_lock();
65328+ read_lock(&tasklist_lock);
65329+ task = find_task_by_vpid(pid);
65330+ if (task) {
65331+#ifdef CONFIG_GRKERNSEC_CHROOT
65332+ if (proc_is_chrooted(task))
65333+ ret = -EACCES;
65334+#endif
65335+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65336+ cred = __task_cred(task);
65337+#ifdef CONFIG_GRKERNSEC_PROC_USER
65338+ if (gr_is_global_nonroot(cred->uid))
65339+ ret = -EACCES;
65340+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65341+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
65342+ ret = -EACCES;
65343+#endif
65344+#endif
65345+ if (gr_status & GR_READY) {
65346+ if (!(task->acl->mode & GR_VIEW))
65347+ ret = -EACCES;
65348+ }
65349+ } else
65350+ ret = -ENOENT;
65351+
65352+ read_unlock(&tasklist_lock);
65353+ rcu_read_unlock();
65354+
65355+ return ret;
65356+}
65357+#endif
65358+
65359+/* AUXV entries are filled via a descendant of search_binary_handler
65360+ after we've already applied the subject for the target
65361+*/
65362+int gr_acl_enable_at_secure(void)
65363+{
65364+ if (unlikely(!(gr_status & GR_READY)))
65365+ return 0;
65366+
65367+ if (current->acl->mode & GR_ATSECURE)
65368+ return 1;
65369+
65370+ return 0;
65371+}
65372+
65373+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
65374+{
65375+ struct task_struct *task = current;
65376+ struct dentry *dentry = file->f_path.dentry;
65377+ struct vfsmount *mnt = file->f_path.mnt;
65378+ struct acl_object_label *obj, *tmp;
65379+ struct acl_subject_label *subj;
65380+ unsigned int bufsize;
65381+ int is_not_root;
65382+ char *path;
65383+ dev_t dev = __get_dev(dentry);
65384+
65385+ if (unlikely(!(gr_status & GR_READY)))
65386+ return 1;
65387+
65388+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65389+ return 1;
65390+
65391+ /* ignore Eric Biederman */
65392+ if (IS_PRIVATE(dentry->d_inode))
65393+ return 1;
65394+
65395+ subj = task->acl;
65396+ read_lock(&gr_inode_lock);
65397+ do {
65398+ obj = lookup_acl_obj_label(ino, dev, subj);
65399+ if (obj != NULL) {
65400+ read_unlock(&gr_inode_lock);
65401+ return (obj->mode & GR_FIND) ? 1 : 0;
65402+ }
65403+ } while ((subj = subj->parent_subject));
65404+ read_unlock(&gr_inode_lock);
65405+
65406+ /* this is purely an optimization since we're looking for an object
65407+ for the directory we're doing a readdir on
65408+ if it's possible for any globbed object to match the entry we're
65409+ filling into the directory, then the object we find here will be
65410+ an anchor point with attached globbed objects
65411+ */
65412+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
65413+ if (obj->globbed == NULL)
65414+ return (obj->mode & GR_FIND) ? 1 : 0;
65415+
65416+ is_not_root = ((obj->filename[0] == '/') &&
65417+ (obj->filename[1] == '\0')) ? 0 : 1;
65418+ bufsize = PAGE_SIZE - namelen - is_not_root;
65419+
65420+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
65421+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
65422+ return 1;
65423+
65424+ preempt_disable();
65425+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65426+ bufsize);
65427+
65428+ bufsize = strlen(path);
65429+
65430+ /* if base is "/", don't append an additional slash */
65431+ if (is_not_root)
65432+ *(path + bufsize) = '/';
65433+ memcpy(path + bufsize + is_not_root, name, namelen);
65434+ *(path + bufsize + namelen + is_not_root) = '\0';
65435+
65436+ tmp = obj->globbed;
65437+ while (tmp) {
65438+ if (!glob_match(tmp->filename, path)) {
65439+ preempt_enable();
65440+ return (tmp->mode & GR_FIND) ? 1 : 0;
65441+ }
65442+ tmp = tmp->next;
65443+ }
65444+ preempt_enable();
65445+ return (obj->mode & GR_FIND) ? 1 : 0;
65446+}
65447+
65448+void gr_put_exec_file(struct task_struct *task)
65449+{
65450+ struct file *filp;
65451+
65452+ write_lock(&grsec_exec_file_lock);
65453+ filp = task->exec_file;
65454+ task->exec_file = NULL;
65455+ write_unlock(&grsec_exec_file_lock);
65456+
65457+ if (filp)
65458+ fput(filp);
65459+
65460+ return;
65461+}
65462+
65463+
65464+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
65465+EXPORT_SYMBOL(gr_acl_is_enabled);
65466+#endif
65467+#ifdef CONFIG_SECURITY
65468+EXPORT_SYMBOL(gr_check_user_change);
65469+EXPORT_SYMBOL(gr_check_group_change);
65470+#endif
65471+
65472diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
65473new file mode 100644
65474index 0000000..18ffbbd
65475--- /dev/null
65476+++ b/grsecurity/gracl_alloc.c
65477@@ -0,0 +1,105 @@
65478+#include <linux/kernel.h>
65479+#include <linux/mm.h>
65480+#include <linux/slab.h>
65481+#include <linux/vmalloc.h>
65482+#include <linux/gracl.h>
65483+#include <linux/grsecurity.h>
65484+
65485+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
65486+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
65487+
65488+static __inline__ int
65489+alloc_pop(void)
65490+{
65491+ if (current_alloc_state->alloc_stack_next == 1)
65492+ return 0;
65493+
65494+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
65495+
65496+ current_alloc_state->alloc_stack_next--;
65497+
65498+ return 1;
65499+}
65500+
65501+static __inline__ int
65502+alloc_push(void *buf)
65503+{
65504+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
65505+ return 1;
65506+
65507+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
65508+
65509+ current_alloc_state->alloc_stack_next++;
65510+
65511+ return 0;
65512+}
65513+
65514+void *
65515+acl_alloc(unsigned long len)
65516+{
65517+ void *ret = NULL;
65518+
65519+ if (!len || len > PAGE_SIZE)
65520+ goto out;
65521+
65522+ ret = kmalloc(len, GFP_KERNEL);
65523+
65524+ if (ret) {
65525+ if (alloc_push(ret)) {
65526+ kfree(ret);
65527+ ret = NULL;
65528+ }
65529+ }
65530+
65531+out:
65532+ return ret;
65533+}
65534+
65535+void *
65536+acl_alloc_num(unsigned long num, unsigned long len)
65537+{
65538+ if (!len || (num > (PAGE_SIZE / len)))
65539+ return NULL;
65540+
65541+ return acl_alloc(num * len);
65542+}
65543+
65544+void
65545+acl_free_all(void)
65546+{
65547+ if (!current_alloc_state->alloc_stack)
65548+ return;
65549+
65550+ while (alloc_pop()) ;
65551+
65552+ if (current_alloc_state->alloc_stack) {
65553+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
65554+ kfree(current_alloc_state->alloc_stack);
65555+ else
65556+ vfree(current_alloc_state->alloc_stack);
65557+ }
65558+
65559+ current_alloc_state->alloc_stack = NULL;
65560+ current_alloc_state->alloc_stack_size = 1;
65561+ current_alloc_state->alloc_stack_next = 1;
65562+
65563+ return;
65564+}
65565+
65566+int
65567+acl_alloc_stack_init(unsigned long size)
65568+{
65569+ if ((size * sizeof (void *)) <= PAGE_SIZE)
65570+ current_alloc_state->alloc_stack =
65571+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
65572+ else
65573+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
65574+
65575+ current_alloc_state->alloc_stack_size = size;
65576+ current_alloc_state->alloc_stack_next = 1;
65577+
65578+ if (!current_alloc_state->alloc_stack)
65579+ return 0;
65580+ else
65581+ return 1;
65582+}
65583diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
65584new file mode 100644
65585index 0000000..bdd51ea
65586--- /dev/null
65587+++ b/grsecurity/gracl_cap.c
65588@@ -0,0 +1,110 @@
65589+#include <linux/kernel.h>
65590+#include <linux/module.h>
65591+#include <linux/sched.h>
65592+#include <linux/gracl.h>
65593+#include <linux/grsecurity.h>
65594+#include <linux/grinternal.h>
65595+
65596+extern const char *captab_log[];
65597+extern int captab_log_entries;
65598+
65599+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65600+{
65601+ struct acl_subject_label *curracl;
65602+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
65603+ kernel_cap_t cap_audit = __cap_empty_set;
65604+
65605+ if (!gr_acl_is_enabled())
65606+ return 1;
65607+
65608+ curracl = task->acl;
65609+
65610+ cap_drop = curracl->cap_lower;
65611+ cap_mask = curracl->cap_mask;
65612+ cap_audit = curracl->cap_invert_audit;
65613+
65614+ while ((curracl = curracl->parent_subject)) {
65615+ /* if the cap isn't specified in the current computed mask but is specified in the
65616+ current level subject, and is lowered in the current level subject, then add
65617+ it to the set of dropped capabilities
65618+ otherwise, add the current level subject's mask to the current computed mask
65619+ */
65620+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
65621+ cap_raise(cap_mask, cap);
65622+ if (cap_raised(curracl->cap_lower, cap))
65623+ cap_raise(cap_drop, cap);
65624+ if (cap_raised(curracl->cap_invert_audit, cap))
65625+ cap_raise(cap_audit, cap);
65626+ }
65627+ }
65628+
65629+ if (!cap_raised(cap_drop, cap)) {
65630+ if (cap_raised(cap_audit, cap))
65631+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
65632+ return 1;
65633+ }
65634+
65635+ curracl = task->acl;
65636+
65637+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
65638+ && cap_raised(cred->cap_effective, cap)) {
65639+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65640+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
65641+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
65642+ gr_to_filename(task->exec_file->f_path.dentry,
65643+ task->exec_file->f_path.mnt) : curracl->filename,
65644+ curracl->filename, 0UL,
65645+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
65646+ return 1;
65647+ }
65648+
65649+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
65650+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
65651+
65652+ return 0;
65653+}
65654+
65655+int
65656+gr_acl_is_capable(const int cap)
65657+{
65658+ return gr_task_acl_is_capable(current, current_cred(), cap);
65659+}
65660+
65661+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
65662+{
65663+ struct acl_subject_label *curracl;
65664+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
65665+
65666+ if (!gr_acl_is_enabled())
65667+ return 1;
65668+
65669+ curracl = task->acl;
65670+
65671+ cap_drop = curracl->cap_lower;
65672+ cap_mask = curracl->cap_mask;
65673+
65674+ while ((curracl = curracl->parent_subject)) {
65675+ /* if the cap isn't specified in the current computed mask but is specified in the
65676+ current level subject, and is lowered in the current level subject, then add
65677+ it to the set of dropped capabilities
65678+ otherwise, add the current level subject's mask to the current computed mask
65679+ */
65680+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
65681+ cap_raise(cap_mask, cap);
65682+ if (cap_raised(curracl->cap_lower, cap))
65683+ cap_raise(cap_drop, cap);
65684+ }
65685+ }
65686+
65687+ if (!cap_raised(cap_drop, cap))
65688+ return 1;
65689+
65690+ return 0;
65691+}
65692+
65693+int
65694+gr_acl_is_capable_nolog(const int cap)
65695+{
65696+ return gr_task_acl_is_capable_nolog(current, cap);
65697+}
65698+
65699diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
65700new file mode 100644
65701index 0000000..ca25605
65702--- /dev/null
65703+++ b/grsecurity/gracl_compat.c
65704@@ -0,0 +1,270 @@
65705+#include <linux/kernel.h>
65706+#include <linux/gracl.h>
65707+#include <linux/compat.h>
65708+#include <linux/gracl_compat.h>
65709+
65710+#include <asm/uaccess.h>
65711+
65712+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
65713+{
65714+ struct gr_arg_wrapper_compat uwrapcompat;
65715+
65716+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
65717+ return -EFAULT;
65718+
65719+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
65720+ (uwrapcompat.version != 0x2901)) ||
65721+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
65722+ return -EINVAL;
65723+
65724+ uwrap->arg = compat_ptr(uwrapcompat.arg);
65725+ uwrap->version = uwrapcompat.version;
65726+ uwrap->size = sizeof(struct gr_arg);
65727+
65728+ return 0;
65729+}
65730+
65731+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
65732+{
65733+ struct gr_arg_compat argcompat;
65734+
65735+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
65736+ return -EFAULT;
65737+
65738+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
65739+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
65740+ arg->role_db.num_roles = argcompat.role_db.num_roles;
65741+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
65742+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
65743+ arg->role_db.num_objects = argcompat.role_db.num_objects;
65744+
65745+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
65746+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
65747+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
65748+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
65749+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
65750+ arg->segv_device = argcompat.segv_device;
65751+ arg->segv_inode = argcompat.segv_inode;
65752+ arg->segv_uid = argcompat.segv_uid;
65753+ arg->num_sprole_pws = argcompat.num_sprole_pws;
65754+ arg->mode = argcompat.mode;
65755+
65756+ return 0;
65757+}
65758+
65759+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
65760+{
65761+ struct acl_object_label_compat objcompat;
65762+
65763+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
65764+ return -EFAULT;
65765+
65766+ obj->filename = compat_ptr(objcompat.filename);
65767+ obj->inode = objcompat.inode;
65768+ obj->device = objcompat.device;
65769+ obj->mode = objcompat.mode;
65770+
65771+ obj->nested = compat_ptr(objcompat.nested);
65772+ obj->globbed = compat_ptr(objcompat.globbed);
65773+
65774+ obj->prev = compat_ptr(objcompat.prev);
65775+ obj->next = compat_ptr(objcompat.next);
65776+
65777+ return 0;
65778+}
65779+
65780+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
65781+{
65782+ unsigned int i;
65783+ struct acl_subject_label_compat subjcompat;
65784+
65785+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
65786+ return -EFAULT;
65787+
65788+ subj->filename = compat_ptr(subjcompat.filename);
65789+ subj->inode = subjcompat.inode;
65790+ subj->device = subjcompat.device;
65791+ subj->mode = subjcompat.mode;
65792+ subj->cap_mask = subjcompat.cap_mask;
65793+ subj->cap_lower = subjcompat.cap_lower;
65794+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
65795+
65796+ for (i = 0; i < GR_NLIMITS; i++) {
65797+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
65798+ subj->res[i].rlim_cur = RLIM_INFINITY;
65799+ else
65800+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
65801+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
65802+ subj->res[i].rlim_max = RLIM_INFINITY;
65803+ else
65804+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
65805+ }
65806+ subj->resmask = subjcompat.resmask;
65807+
65808+ subj->user_trans_type = subjcompat.user_trans_type;
65809+ subj->group_trans_type = subjcompat.group_trans_type;
65810+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
65811+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
65812+ subj->user_trans_num = subjcompat.user_trans_num;
65813+ subj->group_trans_num = subjcompat.group_trans_num;
65814+
65815+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
65816+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
65817+ subj->ip_type = subjcompat.ip_type;
65818+ subj->ips = compat_ptr(subjcompat.ips);
65819+ subj->ip_num = subjcompat.ip_num;
65820+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
65821+
65822+ subj->crashes = subjcompat.crashes;
65823+ subj->expires = subjcompat.expires;
65824+
65825+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
65826+ subj->hash = compat_ptr(subjcompat.hash);
65827+ subj->prev = compat_ptr(subjcompat.prev);
65828+ subj->next = compat_ptr(subjcompat.next);
65829+
65830+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
65831+ subj->obj_hash_size = subjcompat.obj_hash_size;
65832+ subj->pax_flags = subjcompat.pax_flags;
65833+
65834+ return 0;
65835+}
65836+
65837+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
65838+{
65839+ struct acl_role_label_compat rolecompat;
65840+
65841+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
65842+ return -EFAULT;
65843+
65844+ role->rolename = compat_ptr(rolecompat.rolename);
65845+ role->uidgid = rolecompat.uidgid;
65846+ role->roletype = rolecompat.roletype;
65847+
65848+ role->auth_attempts = rolecompat.auth_attempts;
65849+ role->expires = rolecompat.expires;
65850+
65851+ role->root_label = compat_ptr(rolecompat.root_label);
65852+ role->hash = compat_ptr(rolecompat.hash);
65853+
65854+ role->prev = compat_ptr(rolecompat.prev);
65855+ role->next = compat_ptr(rolecompat.next);
65856+
65857+ role->transitions = compat_ptr(rolecompat.transitions);
65858+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
65859+ role->domain_children = compat_ptr(rolecompat.domain_children);
65860+ role->domain_child_num = rolecompat.domain_child_num;
65861+
65862+ role->umask = rolecompat.umask;
65863+
65864+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
65865+ role->subj_hash_size = rolecompat.subj_hash_size;
65866+
65867+ return 0;
65868+}
65869+
65870+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
65871+{
65872+ struct role_allowed_ip_compat roleip_compat;
65873+
65874+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
65875+ return -EFAULT;
65876+
65877+ roleip->addr = roleip_compat.addr;
65878+ roleip->netmask = roleip_compat.netmask;
65879+
65880+ roleip->prev = compat_ptr(roleip_compat.prev);
65881+ roleip->next = compat_ptr(roleip_compat.next);
65882+
65883+ return 0;
65884+}
65885+
65886+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
65887+{
65888+ struct role_transition_compat trans_compat;
65889+
65890+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
65891+ return -EFAULT;
65892+
65893+ trans->rolename = compat_ptr(trans_compat.rolename);
65894+
65895+ trans->prev = compat_ptr(trans_compat.prev);
65896+ trans->next = compat_ptr(trans_compat.next);
65897+
65898+ return 0;
65899+
65900+}
65901+
65902+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
65903+{
65904+ struct gr_hash_struct_compat hash_compat;
65905+
65906+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
65907+ return -EFAULT;
65908+
65909+ hash->table = compat_ptr(hash_compat.table);
65910+ hash->nametable = compat_ptr(hash_compat.nametable);
65911+ hash->first = compat_ptr(hash_compat.first);
65912+
65913+ hash->table_size = hash_compat.table_size;
65914+ hash->used_size = hash_compat.used_size;
65915+
65916+ hash->type = hash_compat.type;
65917+
65918+ return 0;
65919+}
65920+
65921+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
65922+{
65923+ compat_uptr_t ptrcompat;
65924+
65925+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
65926+ return -EFAULT;
65927+
65928+ *(void **)ptr = compat_ptr(ptrcompat);
65929+
65930+ return 0;
65931+}
65932+
65933+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
65934+{
65935+ struct acl_ip_label_compat ip_compat;
65936+
65937+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
65938+ return -EFAULT;
65939+
65940+ ip->iface = compat_ptr(ip_compat.iface);
65941+ ip->addr = ip_compat.addr;
65942+ ip->netmask = ip_compat.netmask;
65943+ ip->low = ip_compat.low;
65944+ ip->high = ip_compat.high;
65945+ ip->mode = ip_compat.mode;
65946+ ip->type = ip_compat.type;
65947+
65948+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
65949+
65950+ ip->prev = compat_ptr(ip_compat.prev);
65951+ ip->next = compat_ptr(ip_compat.next);
65952+
65953+ return 0;
65954+}
65955+
65956+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
65957+{
65958+ struct sprole_pw_compat pw_compat;
65959+
65960+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
65961+ return -EFAULT;
65962+
65963+ pw->rolename = compat_ptr(pw_compat.rolename);
65964+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
65965+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
65966+
65967+ return 0;
65968+}
65969+
65970+size_t get_gr_arg_wrapper_size_compat(void)
65971+{
65972+ return sizeof(struct gr_arg_wrapper_compat);
65973+}
65974+
65975diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
65976new file mode 100644
65977index 0000000..a340c17
65978--- /dev/null
65979+++ b/grsecurity/gracl_fs.c
65980@@ -0,0 +1,431 @@
65981+#include <linux/kernel.h>
65982+#include <linux/sched.h>
65983+#include <linux/types.h>
65984+#include <linux/fs.h>
65985+#include <linux/file.h>
65986+#include <linux/stat.h>
65987+#include <linux/grsecurity.h>
65988+#include <linux/grinternal.h>
65989+#include <linux/gracl.h>
65990+
65991+umode_t
65992+gr_acl_umask(void)
65993+{
65994+ if (unlikely(!gr_acl_is_enabled()))
65995+ return 0;
65996+
65997+ return current->role->umask;
65998+}
65999+
66000+__u32
66001+gr_acl_handle_hidden_file(const struct dentry * dentry,
66002+ const struct vfsmount * mnt)
66003+{
66004+ __u32 mode;
66005+
66006+ if (unlikely(!dentry->d_inode))
66007+ return GR_FIND;
66008+
66009+ mode =
66010+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66011+
66012+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66013+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66014+ return mode;
66015+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66016+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66017+ return 0;
66018+ } else if (unlikely(!(mode & GR_FIND)))
66019+ return 0;
66020+
66021+ return GR_FIND;
66022+}
66023+
66024+__u32
66025+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66026+ int acc_mode)
66027+{
66028+ __u32 reqmode = GR_FIND;
66029+ __u32 mode;
66030+
66031+ if (unlikely(!dentry->d_inode))
66032+ return reqmode;
66033+
66034+ if (acc_mode & MAY_APPEND)
66035+ reqmode |= GR_APPEND;
66036+ else if (acc_mode & MAY_WRITE)
66037+ reqmode |= GR_WRITE;
66038+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66039+ reqmode |= GR_READ;
66040+
66041+ mode =
66042+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66043+ mnt);
66044+
66045+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66046+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66047+ reqmode & GR_READ ? " reading" : "",
66048+ reqmode & GR_WRITE ? " writing" : reqmode &
66049+ GR_APPEND ? " appending" : "");
66050+ return reqmode;
66051+ } else
66052+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66053+ {
66054+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66055+ reqmode & GR_READ ? " reading" : "",
66056+ reqmode & GR_WRITE ? " writing" : reqmode &
66057+ GR_APPEND ? " appending" : "");
66058+ return 0;
66059+ } else if (unlikely((mode & reqmode) != reqmode))
66060+ return 0;
66061+
66062+ return reqmode;
66063+}
66064+
66065+__u32
66066+gr_acl_handle_creat(const struct dentry * dentry,
66067+ const struct dentry * p_dentry,
66068+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66069+ const int imode)
66070+{
66071+ __u32 reqmode = GR_WRITE | GR_CREATE;
66072+ __u32 mode;
66073+
66074+ if (acc_mode & MAY_APPEND)
66075+ reqmode |= GR_APPEND;
66076+ // if a directory was required or the directory already exists, then
66077+ // don't count this open as a read
66078+ if ((acc_mode & MAY_READ) &&
66079+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66080+ reqmode |= GR_READ;
66081+ if ((open_flags & O_CREAT) &&
66082+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66083+ reqmode |= GR_SETID;
66084+
66085+ mode =
66086+ gr_check_create(dentry, p_dentry, p_mnt,
66087+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66088+
66089+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66090+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66091+ reqmode & GR_READ ? " reading" : "",
66092+ reqmode & GR_WRITE ? " writing" : reqmode &
66093+ GR_APPEND ? " appending" : "");
66094+ return reqmode;
66095+ } else
66096+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66097+ {
66098+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66099+ reqmode & GR_READ ? " reading" : "",
66100+ reqmode & GR_WRITE ? " writing" : reqmode &
66101+ GR_APPEND ? " appending" : "");
66102+ return 0;
66103+ } else if (unlikely((mode & reqmode) != reqmode))
66104+ return 0;
66105+
66106+ return reqmode;
66107+}
66108+
66109+__u32
66110+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66111+ const int fmode)
66112+{
66113+ __u32 mode, reqmode = GR_FIND;
66114+
66115+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66116+ reqmode |= GR_EXEC;
66117+ if (fmode & S_IWOTH)
66118+ reqmode |= GR_WRITE;
66119+ if (fmode & S_IROTH)
66120+ reqmode |= GR_READ;
66121+
66122+ mode =
66123+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66124+ mnt);
66125+
66126+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66127+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66128+ reqmode & GR_READ ? " reading" : "",
66129+ reqmode & GR_WRITE ? " writing" : "",
66130+ reqmode & GR_EXEC ? " executing" : "");
66131+ return reqmode;
66132+ } else
66133+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66134+ {
66135+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66136+ reqmode & GR_READ ? " reading" : "",
66137+ reqmode & GR_WRITE ? " writing" : "",
66138+ reqmode & GR_EXEC ? " executing" : "");
66139+ return 0;
66140+ } else if (unlikely((mode & reqmode) != reqmode))
66141+ return 0;
66142+
66143+ return reqmode;
66144+}
66145+
66146+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66147+{
66148+ __u32 mode;
66149+
66150+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66151+
66152+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66153+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66154+ return mode;
66155+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66156+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66157+ return 0;
66158+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66159+ return 0;
66160+
66161+ return (reqmode);
66162+}
66163+
66164+__u32
66165+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66166+{
66167+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66168+}
66169+
66170+__u32
66171+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66172+{
66173+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66174+}
66175+
66176+__u32
66177+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66178+{
66179+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
66180+}
66181+
66182+__u32
66183+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
66184+{
66185+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
66186+}
66187+
66188+__u32
66189+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
66190+ umode_t *modeptr)
66191+{
66192+ umode_t mode;
66193+
66194+ *modeptr &= ~gr_acl_umask();
66195+ mode = *modeptr;
66196+
66197+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
66198+ return 1;
66199+
66200+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
66201+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
66202+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
66203+ GR_CHMOD_ACL_MSG);
66204+ } else {
66205+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
66206+ }
66207+}
66208+
66209+__u32
66210+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
66211+{
66212+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
66213+}
66214+
66215+__u32
66216+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
66217+{
66218+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
66219+}
66220+
66221+__u32
66222+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
66223+{
66224+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
66225+}
66226+
66227+__u32
66228+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
66229+{
66230+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
66231+ GR_UNIXCONNECT_ACL_MSG);
66232+}
66233+
66234+/* hardlinks require at minimum create and link permission,
66235+ any additional privilege required is based on the
66236+ privilege of the file being linked to
66237+*/
66238+__u32
66239+gr_acl_handle_link(const struct dentry * new_dentry,
66240+ const struct dentry * parent_dentry,
66241+ const struct vfsmount * parent_mnt,
66242+ const struct dentry * old_dentry,
66243+ const struct vfsmount * old_mnt, const struct filename *to)
66244+{
66245+ __u32 mode;
66246+ __u32 needmode = GR_CREATE | GR_LINK;
66247+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
66248+
66249+ mode =
66250+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
66251+ old_mnt);
66252+
66253+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
66254+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66255+ return mode;
66256+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66257+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66258+ return 0;
66259+ } else if (unlikely((mode & needmode) != needmode))
66260+ return 0;
66261+
66262+ return 1;
66263+}
66264+
66265+__u32
66266+gr_acl_handle_symlink(const struct dentry * new_dentry,
66267+ const struct dentry * parent_dentry,
66268+ const struct vfsmount * parent_mnt, const struct filename *from)
66269+{
66270+ __u32 needmode = GR_WRITE | GR_CREATE;
66271+ __u32 mode;
66272+
66273+ mode =
66274+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
66275+ GR_CREATE | GR_AUDIT_CREATE |
66276+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
66277+
66278+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
66279+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
66280+ return mode;
66281+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66282+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
66283+ return 0;
66284+ } else if (unlikely((mode & needmode) != needmode))
66285+ return 0;
66286+
66287+ return (GR_WRITE | GR_CREATE);
66288+}
66289+
66290+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)
66291+{
66292+ __u32 mode;
66293+
66294+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66295+
66296+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66297+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
66298+ return mode;
66299+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66300+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
66301+ return 0;
66302+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66303+ return 0;
66304+
66305+ return (reqmode);
66306+}
66307+
66308+__u32
66309+gr_acl_handle_mknod(const struct dentry * new_dentry,
66310+ const struct dentry * parent_dentry,
66311+ const struct vfsmount * parent_mnt,
66312+ const int mode)
66313+{
66314+ __u32 reqmode = GR_WRITE | GR_CREATE;
66315+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66316+ reqmode |= GR_SETID;
66317+
66318+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
66319+ reqmode, GR_MKNOD_ACL_MSG);
66320+}
66321+
66322+__u32
66323+gr_acl_handle_mkdir(const struct dentry *new_dentry,
66324+ const struct dentry *parent_dentry,
66325+ const struct vfsmount *parent_mnt)
66326+{
66327+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
66328+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
66329+}
66330+
66331+#define RENAME_CHECK_SUCCESS(old, new) \
66332+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
66333+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
66334+
66335+int
66336+gr_acl_handle_rename(struct dentry *new_dentry,
66337+ struct dentry *parent_dentry,
66338+ const struct vfsmount *parent_mnt,
66339+ struct dentry *old_dentry,
66340+ struct inode *old_parent_inode,
66341+ struct vfsmount *old_mnt, const struct filename *newname)
66342+{
66343+ __u32 comp1, comp2;
66344+ int error = 0;
66345+
66346+ if (unlikely(!gr_acl_is_enabled()))
66347+ return 0;
66348+
66349+ if (!new_dentry->d_inode) {
66350+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
66351+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
66352+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
66353+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
66354+ GR_DELETE | GR_AUDIT_DELETE |
66355+ GR_AUDIT_READ | GR_AUDIT_WRITE |
66356+ GR_SUPPRESS, old_mnt);
66357+ } else {
66358+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
66359+ GR_CREATE | GR_DELETE |
66360+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
66361+ GR_AUDIT_READ | GR_AUDIT_WRITE |
66362+ GR_SUPPRESS, parent_mnt);
66363+ comp2 =
66364+ gr_search_file(old_dentry,
66365+ GR_READ | GR_WRITE | GR_AUDIT_READ |
66366+ GR_DELETE | GR_AUDIT_DELETE |
66367+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
66368+ }
66369+
66370+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
66371+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
66372+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
66373+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
66374+ && !(comp2 & GR_SUPPRESS)) {
66375+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
66376+ error = -EACCES;
66377+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
66378+ error = -EACCES;
66379+
66380+ return error;
66381+}
66382+
66383+void
66384+gr_acl_handle_exit(void)
66385+{
66386+ u16 id;
66387+ char *rolename;
66388+
66389+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
66390+ !(current->role->roletype & GR_ROLE_PERSIST))) {
66391+ id = current->acl_role_id;
66392+ rolename = current->role->rolename;
66393+ gr_set_acls(1);
66394+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
66395+ }
66396+
66397+ gr_put_exec_file(current);
66398+ return;
66399+}
66400+
66401+int
66402+gr_acl_handle_procpidmem(const struct task_struct *task)
66403+{
66404+ if (unlikely(!gr_acl_is_enabled()))
66405+ return 0;
66406+
66407+ if (task != current && task->acl->mode & GR_PROTPROCFD)
66408+ return -EACCES;
66409+
66410+ return 0;
66411+}
66412diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
66413new file mode 100644
66414index 0000000..f056b81
66415--- /dev/null
66416+++ b/grsecurity/gracl_ip.c
66417@@ -0,0 +1,386 @@
66418+#include <linux/kernel.h>
66419+#include <asm/uaccess.h>
66420+#include <asm/errno.h>
66421+#include <net/sock.h>
66422+#include <linux/file.h>
66423+#include <linux/fs.h>
66424+#include <linux/net.h>
66425+#include <linux/in.h>
66426+#include <linux/skbuff.h>
66427+#include <linux/ip.h>
66428+#include <linux/udp.h>
66429+#include <linux/types.h>
66430+#include <linux/sched.h>
66431+#include <linux/netdevice.h>
66432+#include <linux/inetdevice.h>
66433+#include <linux/gracl.h>
66434+#include <linux/grsecurity.h>
66435+#include <linux/grinternal.h>
66436+
66437+#define GR_BIND 0x01
66438+#define GR_CONNECT 0x02
66439+#define GR_INVERT 0x04
66440+#define GR_BINDOVERRIDE 0x08
66441+#define GR_CONNECTOVERRIDE 0x10
66442+#define GR_SOCK_FAMILY 0x20
66443+
66444+static const char * gr_protocols[IPPROTO_MAX] = {
66445+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
66446+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
66447+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
66448+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
66449+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
66450+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
66451+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
66452+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
66453+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
66454+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
66455+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
66456+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
66457+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
66458+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
66459+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
66460+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
66461+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
66462+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
66463+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
66464+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
66465+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
66466+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
66467+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
66468+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
66469+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
66470+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
66471+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
66472+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
66473+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
66474+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
66475+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
66476+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
66477+ };
66478+
66479+static const char * gr_socktypes[SOCK_MAX] = {
66480+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
66481+ "unknown:7", "unknown:8", "unknown:9", "packet"
66482+ };
66483+
66484+static const char * gr_sockfamilies[AF_MAX+1] = {
66485+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
66486+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
66487+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
66488+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
66489+ };
66490+
66491+const char *
66492+gr_proto_to_name(unsigned char proto)
66493+{
66494+ return gr_protocols[proto];
66495+}
66496+
66497+const char *
66498+gr_socktype_to_name(unsigned char type)
66499+{
66500+ return gr_socktypes[type];
66501+}
66502+
66503+const char *
66504+gr_sockfamily_to_name(unsigned char family)
66505+{
66506+ return gr_sockfamilies[family];
66507+}
66508+
66509+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
66510+
66511+int
66512+gr_search_socket(const int domain, const int type, const int protocol)
66513+{
66514+ struct acl_subject_label *curr;
66515+ const struct cred *cred = current_cred();
66516+
66517+ if (unlikely(!gr_acl_is_enabled()))
66518+ goto exit;
66519+
66520+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
66521+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
66522+ goto exit; // let the kernel handle it
66523+
66524+ curr = current->acl;
66525+
66526+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
66527+ /* the family is allowed, if this is PF_INET allow it only if
66528+ the extra sock type/protocol checks pass */
66529+ if (domain == PF_INET)
66530+ goto inet_check;
66531+ goto exit;
66532+ } else {
66533+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66534+ __u32 fakeip = 0;
66535+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66536+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66537+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66538+ gr_to_filename(current->exec_file->f_path.dentry,
66539+ current->exec_file->f_path.mnt) :
66540+ curr->filename, curr->filename,
66541+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
66542+ &current->signal->saved_ip);
66543+ goto exit;
66544+ }
66545+ goto exit_fail;
66546+ }
66547+
66548+inet_check:
66549+ /* the rest of this checking is for IPv4 only */
66550+ if (!curr->ips)
66551+ goto exit;
66552+
66553+ if ((curr->ip_type & (1U << type)) &&
66554+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
66555+ goto exit;
66556+
66557+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66558+ /* we don't place acls on raw sockets , and sometimes
66559+ dgram/ip sockets are opened for ioctl and not
66560+ bind/connect, so we'll fake a bind learn log */
66561+ if (type == SOCK_RAW || type == SOCK_PACKET) {
66562+ __u32 fakeip = 0;
66563+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66564+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66565+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66566+ gr_to_filename(current->exec_file->f_path.dentry,
66567+ current->exec_file->f_path.mnt) :
66568+ curr->filename, curr->filename,
66569+ &fakeip, 0, type,
66570+ protocol, GR_CONNECT, &current->signal->saved_ip);
66571+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
66572+ __u32 fakeip = 0;
66573+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66574+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66575+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66576+ gr_to_filename(current->exec_file->f_path.dentry,
66577+ current->exec_file->f_path.mnt) :
66578+ curr->filename, curr->filename,
66579+ &fakeip, 0, type,
66580+ protocol, GR_BIND, &current->signal->saved_ip);
66581+ }
66582+ /* we'll log when they use connect or bind */
66583+ goto exit;
66584+ }
66585+
66586+exit_fail:
66587+ if (domain == PF_INET)
66588+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
66589+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
66590+ else if (rcu_access_pointer(net_families[domain]) != NULL)
66591+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
66592+ gr_socktype_to_name(type), protocol);
66593+
66594+ return 0;
66595+exit:
66596+ return 1;
66597+}
66598+
66599+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)
66600+{
66601+ if ((ip->mode & mode) &&
66602+ (ip_port >= ip->low) &&
66603+ (ip_port <= ip->high) &&
66604+ ((ntohl(ip_addr) & our_netmask) ==
66605+ (ntohl(our_addr) & our_netmask))
66606+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
66607+ && (ip->type & (1U << type))) {
66608+ if (ip->mode & GR_INVERT)
66609+ return 2; // specifically denied
66610+ else
66611+ return 1; // allowed
66612+ }
66613+
66614+ return 0; // not specifically allowed, may continue parsing
66615+}
66616+
66617+static int
66618+gr_search_connectbind(const int full_mode, struct sock *sk,
66619+ struct sockaddr_in *addr, const int type)
66620+{
66621+ char iface[IFNAMSIZ] = {0};
66622+ struct acl_subject_label *curr;
66623+ struct acl_ip_label *ip;
66624+ struct inet_sock *isk;
66625+ struct net_device *dev;
66626+ struct in_device *idev;
66627+ unsigned long i;
66628+ int ret;
66629+ int mode = full_mode & (GR_BIND | GR_CONNECT);
66630+ __u32 ip_addr = 0;
66631+ __u32 our_addr;
66632+ __u32 our_netmask;
66633+ char *p;
66634+ __u16 ip_port = 0;
66635+ const struct cred *cred = current_cred();
66636+
66637+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
66638+ return 0;
66639+
66640+ curr = current->acl;
66641+ isk = inet_sk(sk);
66642+
66643+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
66644+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
66645+ addr->sin_addr.s_addr = curr->inaddr_any_override;
66646+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
66647+ struct sockaddr_in saddr;
66648+ int err;
66649+
66650+ saddr.sin_family = AF_INET;
66651+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
66652+ saddr.sin_port = isk->inet_sport;
66653+
66654+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
66655+ if (err)
66656+ return err;
66657+
66658+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
66659+ if (err)
66660+ return err;
66661+ }
66662+
66663+ if (!curr->ips)
66664+ return 0;
66665+
66666+ ip_addr = addr->sin_addr.s_addr;
66667+ ip_port = ntohs(addr->sin_port);
66668+
66669+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66670+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66671+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66672+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66673+ gr_to_filename(current->exec_file->f_path.dentry,
66674+ current->exec_file->f_path.mnt) :
66675+ curr->filename, curr->filename,
66676+ &ip_addr, ip_port, type,
66677+ sk->sk_protocol, mode, &current->signal->saved_ip);
66678+ return 0;
66679+ }
66680+
66681+ for (i = 0; i < curr->ip_num; i++) {
66682+ ip = *(curr->ips + i);
66683+ if (ip->iface != NULL) {
66684+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
66685+ p = strchr(iface, ':');
66686+ if (p != NULL)
66687+ *p = '\0';
66688+ dev = dev_get_by_name(sock_net(sk), iface);
66689+ if (dev == NULL)
66690+ continue;
66691+ idev = in_dev_get(dev);
66692+ if (idev == NULL) {
66693+ dev_put(dev);
66694+ continue;
66695+ }
66696+ rcu_read_lock();
66697+ for_ifa(idev) {
66698+ if (!strcmp(ip->iface, ifa->ifa_label)) {
66699+ our_addr = ifa->ifa_address;
66700+ our_netmask = 0xffffffff;
66701+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
66702+ if (ret == 1) {
66703+ rcu_read_unlock();
66704+ in_dev_put(idev);
66705+ dev_put(dev);
66706+ return 0;
66707+ } else if (ret == 2) {
66708+ rcu_read_unlock();
66709+ in_dev_put(idev);
66710+ dev_put(dev);
66711+ goto denied;
66712+ }
66713+ }
66714+ } endfor_ifa(idev);
66715+ rcu_read_unlock();
66716+ in_dev_put(idev);
66717+ dev_put(dev);
66718+ } else {
66719+ our_addr = ip->addr;
66720+ our_netmask = ip->netmask;
66721+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
66722+ if (ret == 1)
66723+ return 0;
66724+ else if (ret == 2)
66725+ goto denied;
66726+ }
66727+ }
66728+
66729+denied:
66730+ if (mode == GR_BIND)
66731+ 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));
66732+ else if (mode == GR_CONNECT)
66733+ 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));
66734+
66735+ return -EACCES;
66736+}
66737+
66738+int
66739+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
66740+{
66741+ /* always allow disconnection of dgram sockets with connect */
66742+ if (addr->sin_family == AF_UNSPEC)
66743+ return 0;
66744+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
66745+}
66746+
66747+int
66748+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
66749+{
66750+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
66751+}
66752+
66753+int gr_search_listen(struct socket *sock)
66754+{
66755+ struct sock *sk = sock->sk;
66756+ struct sockaddr_in addr;
66757+
66758+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
66759+ addr.sin_port = inet_sk(sk)->inet_sport;
66760+
66761+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
66762+}
66763+
66764+int gr_search_accept(struct socket *sock)
66765+{
66766+ struct sock *sk = sock->sk;
66767+ struct sockaddr_in addr;
66768+
66769+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
66770+ addr.sin_port = inet_sk(sk)->inet_sport;
66771+
66772+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
66773+}
66774+
66775+int
66776+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
66777+{
66778+ if (addr)
66779+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
66780+ else {
66781+ struct sockaddr_in sin;
66782+ const struct inet_sock *inet = inet_sk(sk);
66783+
66784+ sin.sin_addr.s_addr = inet->inet_daddr;
66785+ sin.sin_port = inet->inet_dport;
66786+
66787+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
66788+ }
66789+}
66790+
66791+int
66792+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
66793+{
66794+ struct sockaddr_in sin;
66795+
66796+ if (unlikely(skb->len < sizeof (struct udphdr)))
66797+ return 0; // skip this packet
66798+
66799+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
66800+ sin.sin_port = udp_hdr(skb)->source;
66801+
66802+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
66803+}
66804diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
66805new file mode 100644
66806index 0000000..25f54ef
66807--- /dev/null
66808+++ b/grsecurity/gracl_learn.c
66809@@ -0,0 +1,207 @@
66810+#include <linux/kernel.h>
66811+#include <linux/mm.h>
66812+#include <linux/sched.h>
66813+#include <linux/poll.h>
66814+#include <linux/string.h>
66815+#include <linux/file.h>
66816+#include <linux/types.h>
66817+#include <linux/vmalloc.h>
66818+#include <linux/grinternal.h>
66819+
66820+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
66821+ size_t count, loff_t *ppos);
66822+extern int gr_acl_is_enabled(void);
66823+
66824+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
66825+static int gr_learn_attached;
66826+
66827+/* use a 512k buffer */
66828+#define LEARN_BUFFER_SIZE (512 * 1024)
66829+
66830+static DEFINE_SPINLOCK(gr_learn_lock);
66831+static DEFINE_MUTEX(gr_learn_user_mutex);
66832+
66833+/* we need to maintain two buffers, so that the kernel context of grlearn
66834+ uses a semaphore around the userspace copying, and the other kernel contexts
66835+ use a spinlock when copying into the buffer, since they cannot sleep
66836+*/
66837+static char *learn_buffer;
66838+static char *learn_buffer_user;
66839+static int learn_buffer_len;
66840+static int learn_buffer_user_len;
66841+
66842+static ssize_t
66843+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
66844+{
66845+ DECLARE_WAITQUEUE(wait, current);
66846+ ssize_t retval = 0;
66847+
66848+ add_wait_queue(&learn_wait, &wait);
66849+ set_current_state(TASK_INTERRUPTIBLE);
66850+ do {
66851+ mutex_lock(&gr_learn_user_mutex);
66852+ spin_lock(&gr_learn_lock);
66853+ if (learn_buffer_len)
66854+ break;
66855+ spin_unlock(&gr_learn_lock);
66856+ mutex_unlock(&gr_learn_user_mutex);
66857+ if (file->f_flags & O_NONBLOCK) {
66858+ retval = -EAGAIN;
66859+ goto out;
66860+ }
66861+ if (signal_pending(current)) {
66862+ retval = -ERESTARTSYS;
66863+ goto out;
66864+ }
66865+
66866+ schedule();
66867+ } while (1);
66868+
66869+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
66870+ learn_buffer_user_len = learn_buffer_len;
66871+ retval = learn_buffer_len;
66872+ learn_buffer_len = 0;
66873+
66874+ spin_unlock(&gr_learn_lock);
66875+
66876+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
66877+ retval = -EFAULT;
66878+
66879+ mutex_unlock(&gr_learn_user_mutex);
66880+out:
66881+ set_current_state(TASK_RUNNING);
66882+ remove_wait_queue(&learn_wait, &wait);
66883+ return retval;
66884+}
66885+
66886+static unsigned int
66887+poll_learn(struct file * file, poll_table * wait)
66888+{
66889+ poll_wait(file, &learn_wait, wait);
66890+
66891+ if (learn_buffer_len)
66892+ return (POLLIN | POLLRDNORM);
66893+
66894+ return 0;
66895+}
66896+
66897+void
66898+gr_clear_learn_entries(void)
66899+{
66900+ char *tmp;
66901+
66902+ mutex_lock(&gr_learn_user_mutex);
66903+ spin_lock(&gr_learn_lock);
66904+ tmp = learn_buffer;
66905+ learn_buffer = NULL;
66906+ spin_unlock(&gr_learn_lock);
66907+ if (tmp)
66908+ vfree(tmp);
66909+ if (learn_buffer_user != NULL) {
66910+ vfree(learn_buffer_user);
66911+ learn_buffer_user = NULL;
66912+ }
66913+ learn_buffer_len = 0;
66914+ mutex_unlock(&gr_learn_user_mutex);
66915+
66916+ return;
66917+}
66918+
66919+void
66920+gr_add_learn_entry(const char *fmt, ...)
66921+{
66922+ va_list args;
66923+ unsigned int len;
66924+
66925+ if (!gr_learn_attached)
66926+ return;
66927+
66928+ spin_lock(&gr_learn_lock);
66929+
66930+ /* leave a gap at the end so we know when it's "full" but don't have to
66931+ compute the exact length of the string we're trying to append
66932+ */
66933+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
66934+ spin_unlock(&gr_learn_lock);
66935+ wake_up_interruptible(&learn_wait);
66936+ return;
66937+ }
66938+ if (learn_buffer == NULL) {
66939+ spin_unlock(&gr_learn_lock);
66940+ return;
66941+ }
66942+
66943+ va_start(args, fmt);
66944+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
66945+ va_end(args);
66946+
66947+ learn_buffer_len += len + 1;
66948+
66949+ spin_unlock(&gr_learn_lock);
66950+ wake_up_interruptible(&learn_wait);
66951+
66952+ return;
66953+}
66954+
66955+static int
66956+open_learn(struct inode *inode, struct file *file)
66957+{
66958+ if (file->f_mode & FMODE_READ && gr_learn_attached)
66959+ return -EBUSY;
66960+ if (file->f_mode & FMODE_READ) {
66961+ int retval = 0;
66962+ mutex_lock(&gr_learn_user_mutex);
66963+ if (learn_buffer == NULL)
66964+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
66965+ if (learn_buffer_user == NULL)
66966+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
66967+ if (learn_buffer == NULL) {
66968+ retval = -ENOMEM;
66969+ goto out_error;
66970+ }
66971+ if (learn_buffer_user == NULL) {
66972+ retval = -ENOMEM;
66973+ goto out_error;
66974+ }
66975+ learn_buffer_len = 0;
66976+ learn_buffer_user_len = 0;
66977+ gr_learn_attached = 1;
66978+out_error:
66979+ mutex_unlock(&gr_learn_user_mutex);
66980+ return retval;
66981+ }
66982+ return 0;
66983+}
66984+
66985+static int
66986+close_learn(struct inode *inode, struct file *file)
66987+{
66988+ if (file->f_mode & FMODE_READ) {
66989+ char *tmp = NULL;
66990+ mutex_lock(&gr_learn_user_mutex);
66991+ spin_lock(&gr_learn_lock);
66992+ tmp = learn_buffer;
66993+ learn_buffer = NULL;
66994+ spin_unlock(&gr_learn_lock);
66995+ if (tmp)
66996+ vfree(tmp);
66997+ if (learn_buffer_user != NULL) {
66998+ vfree(learn_buffer_user);
66999+ learn_buffer_user = NULL;
67000+ }
67001+ learn_buffer_len = 0;
67002+ learn_buffer_user_len = 0;
67003+ gr_learn_attached = 0;
67004+ mutex_unlock(&gr_learn_user_mutex);
67005+ }
67006+
67007+ return 0;
67008+}
67009+
67010+const struct file_operations grsec_fops = {
67011+ .read = read_learn,
67012+ .write = write_grsec_handler,
67013+ .open = open_learn,
67014+ .release = close_learn,
67015+ .poll = poll_learn,
67016+};
67017diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
67018new file mode 100644
67019index 0000000..36e293f
67020--- /dev/null
67021+++ b/grsecurity/gracl_policy.c
67022@@ -0,0 +1,1777 @@
67023+#include <linux/kernel.h>
67024+#include <linux/module.h>
67025+#include <linux/sched.h>
67026+#include <linux/mm.h>
67027+#include <linux/file.h>
67028+#include <linux/fs.h>
67029+#include <linux/namei.h>
67030+#include <linux/mount.h>
67031+#include <linux/tty.h>
67032+#include <linux/proc_fs.h>
67033+#include <linux/lglock.h>
67034+#include <linux/slab.h>
67035+#include <linux/vmalloc.h>
67036+#include <linux/types.h>
67037+#include <linux/sysctl.h>
67038+#include <linux/netdevice.h>
67039+#include <linux/ptrace.h>
67040+#include <linux/gracl.h>
67041+#include <linux/gralloc.h>
67042+#include <linux/security.h>
67043+#include <linux/grinternal.h>
67044+#include <linux/pid_namespace.h>
67045+#include <linux/stop_machine.h>
67046+#include <linux/fdtable.h>
67047+#include <linux/percpu.h>
67048+#include <linux/lglock.h>
67049+#include <linux/hugetlb.h>
67050+#include <linux/posix-timers.h>
67051+#include "../fs/mount.h"
67052+
67053+#include <asm/uaccess.h>
67054+#include <asm/errno.h>
67055+#include <asm/mman.h>
67056+
67057+extern struct gr_policy_state *polstate;
67058+
67059+#define FOR_EACH_ROLE_START(role) \
67060+ role = polstate->role_list; \
67061+ while (role) {
67062+
67063+#define FOR_EACH_ROLE_END(role) \
67064+ role = role->prev; \
67065+ }
67066+
67067+struct path gr_real_root;
67068+
67069+extern struct gr_alloc_state *current_alloc_state;
67070+
67071+u16 acl_sp_role_value;
67072+
67073+static DEFINE_MUTEX(gr_dev_mutex);
67074+
67075+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
67076+extern void gr_clear_learn_entries(void);
67077+
67078+static struct gr_arg gr_usermode;
67079+static unsigned char gr_system_salt[GR_SALT_LEN];
67080+static unsigned char gr_system_sum[GR_SHA_LEN];
67081+
67082+static unsigned int gr_auth_attempts = 0;
67083+static unsigned long gr_auth_expires = 0UL;
67084+
67085+struct acl_object_label *fakefs_obj_rw;
67086+struct acl_object_label *fakefs_obj_rwx;
67087+
67088+extern int gr_init_uidset(void);
67089+extern void gr_free_uidset(void);
67090+extern void gr_remove_uid(uid_t uid);
67091+extern int gr_find_uid(uid_t uid);
67092+
67093+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
67094+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
67095+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
67096+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
67097+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);
67098+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
67099+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
67100+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
67101+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
67102+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
67103+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
67104+extern void assign_special_role(const char *rolename);
67105+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
67106+extern int gr_rbac_disable(void *unused);
67107+extern void gr_enable_rbac_system(void);
67108+
67109+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
67110+{
67111+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
67112+ return -EFAULT;
67113+
67114+ return 0;
67115+}
67116+
67117+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
67118+{
67119+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
67120+ return -EFAULT;
67121+
67122+ return 0;
67123+}
67124+
67125+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
67126+{
67127+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
67128+ return -EFAULT;
67129+
67130+ return 0;
67131+}
67132+
67133+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
67134+{
67135+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
67136+ return -EFAULT;
67137+
67138+ return 0;
67139+}
67140+
67141+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
67142+{
67143+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
67144+ return -EFAULT;
67145+
67146+ return 0;
67147+}
67148+
67149+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
67150+{
67151+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
67152+ return -EFAULT;
67153+
67154+ return 0;
67155+}
67156+
67157+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
67158+{
67159+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
67160+ return -EFAULT;
67161+
67162+ return 0;
67163+}
67164+
67165+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
67166+{
67167+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
67168+ return -EFAULT;
67169+
67170+ return 0;
67171+}
67172+
67173+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
67174+{
67175+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
67176+ return -EFAULT;
67177+
67178+ return 0;
67179+}
67180+
67181+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
67182+{
67183+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
67184+ return -EFAULT;
67185+
67186+ if (((uwrap->version != GRSECURITY_VERSION) &&
67187+ (uwrap->version != 0x2901)) ||
67188+ (uwrap->size != sizeof(struct gr_arg)))
67189+ return -EINVAL;
67190+
67191+ return 0;
67192+}
67193+
67194+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
67195+{
67196+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
67197+ return -EFAULT;
67198+
67199+ return 0;
67200+}
67201+
67202+static size_t get_gr_arg_wrapper_size_normal(void)
67203+{
67204+ return sizeof(struct gr_arg_wrapper);
67205+}
67206+
67207+#ifdef CONFIG_COMPAT
67208+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
67209+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
67210+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
67211+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
67212+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
67213+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
67214+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
67215+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
67216+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
67217+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
67218+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
67219+extern size_t get_gr_arg_wrapper_size_compat(void);
67220+
67221+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
67222+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
67223+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
67224+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
67225+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
67226+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
67227+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
67228+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
67229+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
67230+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
67231+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
67232+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
67233+
67234+#else
67235+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
67236+#define copy_gr_arg copy_gr_arg_normal
67237+#define copy_gr_hash_struct copy_gr_hash_struct_normal
67238+#define copy_acl_object_label copy_acl_object_label_normal
67239+#define copy_acl_subject_label copy_acl_subject_label_normal
67240+#define copy_acl_role_label copy_acl_role_label_normal
67241+#define copy_acl_ip_label copy_acl_ip_label_normal
67242+#define copy_pointer_from_array copy_pointer_from_array_normal
67243+#define copy_sprole_pw copy_sprole_pw_normal
67244+#define copy_role_transition copy_role_transition_normal
67245+#define copy_role_allowed_ip copy_role_allowed_ip_normal
67246+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
67247+#endif
67248+
67249+static struct acl_subject_label *
67250+lookup_subject_map(const struct acl_subject_label *userp)
67251+{
67252+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
67253+ struct subject_map *match;
67254+
67255+ match = polstate->subj_map_set.s_hash[index];
67256+
67257+ while (match && match->user != userp)
67258+ match = match->next;
67259+
67260+ if (match != NULL)
67261+ return match->kernel;
67262+ else
67263+ return NULL;
67264+}
67265+
67266+static void
67267+insert_subj_map_entry(struct subject_map *subjmap)
67268+{
67269+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
67270+ struct subject_map **curr;
67271+
67272+ subjmap->prev = NULL;
67273+
67274+ curr = &polstate->subj_map_set.s_hash[index];
67275+ if (*curr != NULL)
67276+ (*curr)->prev = subjmap;
67277+
67278+ subjmap->next = *curr;
67279+ *curr = subjmap;
67280+
67281+ return;
67282+}
67283+
67284+static void
67285+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
67286+{
67287+ unsigned int index =
67288+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
67289+ struct acl_role_label **curr;
67290+ struct acl_role_label *tmp, *tmp2;
67291+
67292+ curr = &polstate->acl_role_set.r_hash[index];
67293+
67294+ /* simple case, slot is empty, just set it to our role */
67295+ if (*curr == NULL) {
67296+ *curr = role;
67297+ } else {
67298+ /* example:
67299+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
67300+ 2 -> 3
67301+ */
67302+ /* first check to see if we can already be reached via this slot */
67303+ tmp = *curr;
67304+ while (tmp && tmp != role)
67305+ tmp = tmp->next;
67306+ if (tmp == role) {
67307+ /* we don't need to add ourselves to this slot's chain */
67308+ return;
67309+ }
67310+ /* we need to add ourselves to this chain, two cases */
67311+ if (role->next == NULL) {
67312+ /* simple case, append the current chain to our role */
67313+ role->next = *curr;
67314+ *curr = role;
67315+ } else {
67316+ /* 1 -> 2 -> 3 -> 4
67317+ 2 -> 3 -> 4
67318+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
67319+ */
67320+ /* trickier case: walk our role's chain until we find
67321+ the role for the start of the current slot's chain */
67322+ tmp = role;
67323+ tmp2 = *curr;
67324+ while (tmp->next && tmp->next != tmp2)
67325+ tmp = tmp->next;
67326+ if (tmp->next == tmp2) {
67327+ /* from example above, we found 3, so just
67328+ replace this slot's chain with ours */
67329+ *curr = role;
67330+ } else {
67331+ /* we didn't find a subset of our role's chain
67332+ in the current slot's chain, so append their
67333+ chain to ours, and set us as the first role in
67334+ the slot's chain
67335+
67336+ we could fold this case with the case above,
67337+ but making it explicit for clarity
67338+ */
67339+ tmp->next = tmp2;
67340+ *curr = role;
67341+ }
67342+ }
67343+ }
67344+
67345+ return;
67346+}
67347+
67348+static void
67349+insert_acl_role_label(struct acl_role_label *role)
67350+{
67351+ int i;
67352+
67353+ if (polstate->role_list == NULL) {
67354+ polstate->role_list = role;
67355+ role->prev = NULL;
67356+ } else {
67357+ role->prev = polstate->role_list;
67358+ polstate->role_list = role;
67359+ }
67360+
67361+ /* used for hash chains */
67362+ role->next = NULL;
67363+
67364+ if (role->roletype & GR_ROLE_DOMAIN) {
67365+ for (i = 0; i < role->domain_child_num; i++)
67366+ __insert_acl_role_label(role, role->domain_children[i]);
67367+ } else
67368+ __insert_acl_role_label(role, role->uidgid);
67369+}
67370+
67371+static int
67372+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
67373+{
67374+ struct name_entry **curr, *nentry;
67375+ struct inodev_entry *ientry;
67376+ unsigned int len = strlen(name);
67377+ unsigned int key = full_name_hash(name, len);
67378+ unsigned int index = key % polstate->name_set.n_size;
67379+
67380+ curr = &polstate->name_set.n_hash[index];
67381+
67382+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
67383+ curr = &((*curr)->next);
67384+
67385+ if (*curr != NULL)
67386+ return 1;
67387+
67388+ nentry = acl_alloc(sizeof (struct name_entry));
67389+ if (nentry == NULL)
67390+ return 0;
67391+ ientry = acl_alloc(sizeof (struct inodev_entry));
67392+ if (ientry == NULL)
67393+ return 0;
67394+ ientry->nentry = nentry;
67395+
67396+ nentry->key = key;
67397+ nentry->name = name;
67398+ nentry->inode = inode;
67399+ nentry->device = device;
67400+ nentry->len = len;
67401+ nentry->deleted = deleted;
67402+
67403+ nentry->prev = NULL;
67404+ curr = &polstate->name_set.n_hash[index];
67405+ if (*curr != NULL)
67406+ (*curr)->prev = nentry;
67407+ nentry->next = *curr;
67408+ *curr = nentry;
67409+
67410+ /* insert us into the table searchable by inode/dev */
67411+ __insert_inodev_entry(polstate, ientry);
67412+
67413+ return 1;
67414+}
67415+
67416+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
67417+
67418+static void *
67419+create_table(__u32 * len, int elementsize)
67420+{
67421+ unsigned int table_sizes[] = {
67422+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
67423+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
67424+ 4194301, 8388593, 16777213, 33554393, 67108859
67425+ };
67426+ void *newtable = NULL;
67427+ unsigned int pwr = 0;
67428+
67429+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
67430+ table_sizes[pwr] <= *len)
67431+ pwr++;
67432+
67433+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
67434+ return newtable;
67435+
67436+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
67437+ newtable =
67438+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
67439+ else
67440+ newtable = vmalloc(table_sizes[pwr] * elementsize);
67441+
67442+ *len = table_sizes[pwr];
67443+
67444+ return newtable;
67445+}
67446+
67447+static int
67448+init_variables(const struct gr_arg *arg, bool reload)
67449+{
67450+ struct task_struct *reaper = init_pid_ns.child_reaper;
67451+ unsigned int stacksize;
67452+
67453+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
67454+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
67455+ polstate->name_set.n_size = arg->role_db.num_objects;
67456+ polstate->inodev_set.i_size = arg->role_db.num_objects;
67457+
67458+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
67459+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
67460+ return 1;
67461+
67462+ if (!reload) {
67463+ if (!gr_init_uidset())
67464+ return 1;
67465+ }
67466+
67467+ /* set up the stack that holds allocation info */
67468+
67469+ stacksize = arg->role_db.num_pointers + 5;
67470+
67471+ if (!acl_alloc_stack_init(stacksize))
67472+ return 1;
67473+
67474+ if (!reload) {
67475+ /* grab reference for the real root dentry and vfsmount */
67476+ get_fs_root(reaper->fs, &gr_real_root);
67477+
67478+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67479+ 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);
67480+#endif
67481+
67482+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
67483+ if (fakefs_obj_rw == NULL)
67484+ return 1;
67485+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
67486+
67487+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
67488+ if (fakefs_obj_rwx == NULL)
67489+ return 1;
67490+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
67491+ }
67492+
67493+ polstate->subj_map_set.s_hash =
67494+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
67495+ polstate->acl_role_set.r_hash =
67496+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
67497+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
67498+ polstate->inodev_set.i_hash =
67499+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
67500+
67501+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
67502+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
67503+ return 1;
67504+
67505+ memset(polstate->subj_map_set.s_hash, 0,
67506+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
67507+ memset(polstate->acl_role_set.r_hash, 0,
67508+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
67509+ memset(polstate->name_set.n_hash, 0,
67510+ sizeof (struct name_entry *) * polstate->name_set.n_size);
67511+ memset(polstate->inodev_set.i_hash, 0,
67512+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
67513+
67514+ return 0;
67515+}
67516+
67517+/* free information not needed after startup
67518+ currently contains user->kernel pointer mappings for subjects
67519+*/
67520+
67521+static void
67522+free_init_variables(void)
67523+{
67524+ __u32 i;
67525+
67526+ if (polstate->subj_map_set.s_hash) {
67527+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
67528+ if (polstate->subj_map_set.s_hash[i]) {
67529+ kfree(polstate->subj_map_set.s_hash[i]);
67530+ polstate->subj_map_set.s_hash[i] = NULL;
67531+ }
67532+ }
67533+
67534+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
67535+ PAGE_SIZE)
67536+ kfree(polstate->subj_map_set.s_hash);
67537+ else
67538+ vfree(polstate->subj_map_set.s_hash);
67539+ }
67540+
67541+ return;
67542+}
67543+
67544+static void
67545+free_variables(bool reload)
67546+{
67547+ struct acl_subject_label *s;
67548+ struct acl_role_label *r;
67549+ struct task_struct *task, *task2;
67550+ unsigned int x;
67551+
67552+ if (!reload) {
67553+ gr_clear_learn_entries();
67554+
67555+ read_lock(&tasklist_lock);
67556+ do_each_thread(task2, task) {
67557+ task->acl_sp_role = 0;
67558+ task->acl_role_id = 0;
67559+ task->inherited = 0;
67560+ task->acl = NULL;
67561+ task->role = NULL;
67562+ } while_each_thread(task2, task);
67563+ read_unlock(&tasklist_lock);
67564+
67565+ /* release the reference to the real root dentry and vfsmount */
67566+ path_put(&gr_real_root);
67567+ memset(&gr_real_root, 0, sizeof(gr_real_root));
67568+ }
67569+
67570+ /* free all object hash tables */
67571+
67572+ FOR_EACH_ROLE_START(r)
67573+ if (r->subj_hash == NULL)
67574+ goto next_role;
67575+ FOR_EACH_SUBJECT_START(r, s, x)
67576+ if (s->obj_hash == NULL)
67577+ break;
67578+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
67579+ kfree(s->obj_hash);
67580+ else
67581+ vfree(s->obj_hash);
67582+ FOR_EACH_SUBJECT_END(s, x)
67583+ FOR_EACH_NESTED_SUBJECT_START(r, s)
67584+ if (s->obj_hash == NULL)
67585+ break;
67586+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
67587+ kfree(s->obj_hash);
67588+ else
67589+ vfree(s->obj_hash);
67590+ FOR_EACH_NESTED_SUBJECT_END(s)
67591+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
67592+ kfree(r->subj_hash);
67593+ else
67594+ vfree(r->subj_hash);
67595+ r->subj_hash = NULL;
67596+next_role:
67597+ FOR_EACH_ROLE_END(r)
67598+
67599+ acl_free_all();
67600+
67601+ if (polstate->acl_role_set.r_hash) {
67602+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
67603+ PAGE_SIZE)
67604+ kfree(polstate->acl_role_set.r_hash);
67605+ else
67606+ vfree(polstate->acl_role_set.r_hash);
67607+ }
67608+ if (polstate->name_set.n_hash) {
67609+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
67610+ PAGE_SIZE)
67611+ kfree(polstate->name_set.n_hash);
67612+ else
67613+ vfree(polstate->name_set.n_hash);
67614+ }
67615+
67616+ if (polstate->inodev_set.i_hash) {
67617+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
67618+ PAGE_SIZE)
67619+ kfree(polstate->inodev_set.i_hash);
67620+ else
67621+ vfree(polstate->inodev_set.i_hash);
67622+ }
67623+
67624+ if (!reload)
67625+ gr_free_uidset();
67626+
67627+ memset(&polstate->name_set, 0, sizeof (struct name_db));
67628+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
67629+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
67630+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
67631+
67632+ polstate->default_role = NULL;
67633+ polstate->kernel_role = NULL;
67634+ polstate->role_list = NULL;
67635+
67636+ return;
67637+}
67638+
67639+static struct acl_subject_label *
67640+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
67641+
67642+static int alloc_and_copy_string(char **name, unsigned int maxlen)
67643+{
67644+ unsigned int len = strnlen_user(*name, maxlen);
67645+ char *tmp;
67646+
67647+ if (!len || len >= maxlen)
67648+ return -EINVAL;
67649+
67650+ if ((tmp = (char *) acl_alloc(len)) == NULL)
67651+ return -ENOMEM;
67652+
67653+ if (copy_from_user(tmp, *name, len))
67654+ return -EFAULT;
67655+
67656+ tmp[len-1] = '\0';
67657+ *name = tmp;
67658+
67659+ return 0;
67660+}
67661+
67662+static int
67663+copy_user_glob(struct acl_object_label *obj)
67664+{
67665+ struct acl_object_label *g_tmp, **guser;
67666+ int error;
67667+
67668+ if (obj->globbed == NULL)
67669+ return 0;
67670+
67671+ guser = &obj->globbed;
67672+ while (*guser) {
67673+ g_tmp = (struct acl_object_label *)
67674+ acl_alloc(sizeof (struct acl_object_label));
67675+ if (g_tmp == NULL)
67676+ return -ENOMEM;
67677+
67678+ if (copy_acl_object_label(g_tmp, *guser))
67679+ return -EFAULT;
67680+
67681+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
67682+ if (error)
67683+ return error;
67684+
67685+ *guser = g_tmp;
67686+ guser = &(g_tmp->next);
67687+ }
67688+
67689+ return 0;
67690+}
67691+
67692+static int
67693+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
67694+ struct acl_role_label *role)
67695+{
67696+ struct acl_object_label *o_tmp;
67697+ int ret;
67698+
67699+ while (userp) {
67700+ if ((o_tmp = (struct acl_object_label *)
67701+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
67702+ return -ENOMEM;
67703+
67704+ if (copy_acl_object_label(o_tmp, userp))
67705+ return -EFAULT;
67706+
67707+ userp = o_tmp->prev;
67708+
67709+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
67710+ if (ret)
67711+ return ret;
67712+
67713+ insert_acl_obj_label(o_tmp, subj);
67714+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
67715+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
67716+ return -ENOMEM;
67717+
67718+ ret = copy_user_glob(o_tmp);
67719+ if (ret)
67720+ return ret;
67721+
67722+ if (o_tmp->nested) {
67723+ int already_copied;
67724+
67725+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
67726+ if (IS_ERR(o_tmp->nested))
67727+ return PTR_ERR(o_tmp->nested);
67728+
67729+ /* insert into nested subject list if we haven't copied this one yet
67730+ to prevent duplicate entries */
67731+ if (!already_copied) {
67732+ o_tmp->nested->next = role->hash->first;
67733+ role->hash->first = o_tmp->nested;
67734+ }
67735+ }
67736+ }
67737+
67738+ return 0;
67739+}
67740+
67741+static __u32
67742+count_user_subjs(struct acl_subject_label *userp)
67743+{
67744+ struct acl_subject_label s_tmp;
67745+ __u32 num = 0;
67746+
67747+ while (userp) {
67748+ if (copy_acl_subject_label(&s_tmp, userp))
67749+ break;
67750+
67751+ userp = s_tmp.prev;
67752+ }
67753+
67754+ return num;
67755+}
67756+
67757+static int
67758+copy_user_allowedips(struct acl_role_label *rolep)
67759+{
67760+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
67761+
67762+ ruserip = rolep->allowed_ips;
67763+
67764+ while (ruserip) {
67765+ rlast = rtmp;
67766+
67767+ if ((rtmp = (struct role_allowed_ip *)
67768+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
67769+ return -ENOMEM;
67770+
67771+ if (copy_role_allowed_ip(rtmp, ruserip))
67772+ return -EFAULT;
67773+
67774+ ruserip = rtmp->prev;
67775+
67776+ if (!rlast) {
67777+ rtmp->prev = NULL;
67778+ rolep->allowed_ips = rtmp;
67779+ } else {
67780+ rlast->next = rtmp;
67781+ rtmp->prev = rlast;
67782+ }
67783+
67784+ if (!ruserip)
67785+ rtmp->next = NULL;
67786+ }
67787+
67788+ return 0;
67789+}
67790+
67791+static int
67792+copy_user_transitions(struct acl_role_label *rolep)
67793+{
67794+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
67795+ int error;
67796+
67797+ rusertp = rolep->transitions;
67798+
67799+ while (rusertp) {
67800+ rlast = rtmp;
67801+
67802+ if ((rtmp = (struct role_transition *)
67803+ acl_alloc(sizeof (struct role_transition))) == NULL)
67804+ return -ENOMEM;
67805+
67806+ if (copy_role_transition(rtmp, rusertp))
67807+ return -EFAULT;
67808+
67809+ rusertp = rtmp->prev;
67810+
67811+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
67812+ if (error)
67813+ return error;
67814+
67815+ if (!rlast) {
67816+ rtmp->prev = NULL;
67817+ rolep->transitions = rtmp;
67818+ } else {
67819+ rlast->next = rtmp;
67820+ rtmp->prev = rlast;
67821+ }
67822+
67823+ if (!rusertp)
67824+ rtmp->next = NULL;
67825+ }
67826+
67827+ return 0;
67828+}
67829+
67830+static __u32 count_user_objs(const struct acl_object_label __user *userp)
67831+{
67832+ struct acl_object_label o_tmp;
67833+ __u32 num = 0;
67834+
67835+ while (userp) {
67836+ if (copy_acl_object_label(&o_tmp, userp))
67837+ break;
67838+
67839+ userp = o_tmp.prev;
67840+ num++;
67841+ }
67842+
67843+ return num;
67844+}
67845+
67846+static struct acl_subject_label *
67847+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
67848+{
67849+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
67850+ __u32 num_objs;
67851+ struct acl_ip_label **i_tmp, *i_utmp2;
67852+ struct gr_hash_struct ghash;
67853+ struct subject_map *subjmap;
67854+ unsigned int i_num;
67855+ int err;
67856+
67857+ if (already_copied != NULL)
67858+ *already_copied = 0;
67859+
67860+ s_tmp = lookup_subject_map(userp);
67861+
67862+ /* we've already copied this subject into the kernel, just return
67863+ the reference to it, and don't copy it over again
67864+ */
67865+ if (s_tmp) {
67866+ if (already_copied != NULL)
67867+ *already_copied = 1;
67868+ return(s_tmp);
67869+ }
67870+
67871+ if ((s_tmp = (struct acl_subject_label *)
67872+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
67873+ return ERR_PTR(-ENOMEM);
67874+
67875+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
67876+ if (subjmap == NULL)
67877+ return ERR_PTR(-ENOMEM);
67878+
67879+ subjmap->user = userp;
67880+ subjmap->kernel = s_tmp;
67881+ insert_subj_map_entry(subjmap);
67882+
67883+ if (copy_acl_subject_label(s_tmp, userp))
67884+ return ERR_PTR(-EFAULT);
67885+
67886+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
67887+ if (err)
67888+ return ERR_PTR(err);
67889+
67890+ if (!strcmp(s_tmp->filename, "/"))
67891+ role->root_label = s_tmp;
67892+
67893+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
67894+ return ERR_PTR(-EFAULT);
67895+
67896+ /* copy user and group transition tables */
67897+
67898+ if (s_tmp->user_trans_num) {
67899+ uid_t *uidlist;
67900+
67901+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
67902+ if (uidlist == NULL)
67903+ return ERR_PTR(-ENOMEM);
67904+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
67905+ return ERR_PTR(-EFAULT);
67906+
67907+ s_tmp->user_transitions = uidlist;
67908+ }
67909+
67910+ if (s_tmp->group_trans_num) {
67911+ gid_t *gidlist;
67912+
67913+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
67914+ if (gidlist == NULL)
67915+ return ERR_PTR(-ENOMEM);
67916+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
67917+ return ERR_PTR(-EFAULT);
67918+
67919+ s_tmp->group_transitions = gidlist;
67920+ }
67921+
67922+ /* set up object hash table */
67923+ num_objs = count_user_objs(ghash.first);
67924+
67925+ s_tmp->obj_hash_size = num_objs;
67926+ s_tmp->obj_hash =
67927+ (struct acl_object_label **)
67928+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
67929+
67930+ if (!s_tmp->obj_hash)
67931+ return ERR_PTR(-ENOMEM);
67932+
67933+ memset(s_tmp->obj_hash, 0,
67934+ s_tmp->obj_hash_size *
67935+ sizeof (struct acl_object_label *));
67936+
67937+ /* add in objects */
67938+ err = copy_user_objs(ghash.first, s_tmp, role);
67939+
67940+ if (err)
67941+ return ERR_PTR(err);
67942+
67943+ /* set pointer for parent subject */
67944+ if (s_tmp->parent_subject) {
67945+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
67946+
67947+ if (IS_ERR(s_tmp2))
67948+ return s_tmp2;
67949+
67950+ s_tmp->parent_subject = s_tmp2;
67951+ }
67952+
67953+ /* add in ip acls */
67954+
67955+ if (!s_tmp->ip_num) {
67956+ s_tmp->ips = NULL;
67957+ goto insert;
67958+ }
67959+
67960+ i_tmp =
67961+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
67962+ sizeof (struct acl_ip_label *));
67963+
67964+ if (!i_tmp)
67965+ return ERR_PTR(-ENOMEM);
67966+
67967+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
67968+ *(i_tmp + i_num) =
67969+ (struct acl_ip_label *)
67970+ acl_alloc(sizeof (struct acl_ip_label));
67971+ if (!*(i_tmp + i_num))
67972+ return ERR_PTR(-ENOMEM);
67973+
67974+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
67975+ return ERR_PTR(-EFAULT);
67976+
67977+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
67978+ return ERR_PTR(-EFAULT);
67979+
67980+ if ((*(i_tmp + i_num))->iface == NULL)
67981+ continue;
67982+
67983+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
67984+ if (err)
67985+ return ERR_PTR(err);
67986+ }
67987+
67988+ s_tmp->ips = i_tmp;
67989+
67990+insert:
67991+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
67992+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
67993+ return ERR_PTR(-ENOMEM);
67994+
67995+ return s_tmp;
67996+}
67997+
67998+static int
67999+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
68000+{
68001+ struct acl_subject_label s_pre;
68002+ struct acl_subject_label * ret;
68003+ int err;
68004+
68005+ while (userp) {
68006+ if (copy_acl_subject_label(&s_pre, userp))
68007+ return -EFAULT;
68008+
68009+ ret = do_copy_user_subj(userp, role, NULL);
68010+
68011+ err = PTR_ERR(ret);
68012+ if (IS_ERR(ret))
68013+ return err;
68014+
68015+ insert_acl_subj_label(ret, role);
68016+
68017+ userp = s_pre.prev;
68018+ }
68019+
68020+ return 0;
68021+}
68022+
68023+static int
68024+copy_user_acl(struct gr_arg *arg)
68025+{
68026+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
68027+ struct acl_subject_label *subj_list;
68028+ struct sprole_pw *sptmp;
68029+ struct gr_hash_struct *ghash;
68030+ uid_t *domainlist;
68031+ unsigned int r_num;
68032+ int err = 0;
68033+ __u16 i;
68034+ __u32 num_subjs;
68035+
68036+ /* we need a default and kernel role */
68037+ if (arg->role_db.num_roles < 2)
68038+ return -EINVAL;
68039+
68040+ /* copy special role authentication info from userspace */
68041+
68042+ polstate->num_sprole_pws = arg->num_sprole_pws;
68043+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
68044+
68045+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
68046+ return -ENOMEM;
68047+
68048+ for (i = 0; i < polstate->num_sprole_pws; i++) {
68049+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
68050+ if (!sptmp)
68051+ return -ENOMEM;
68052+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
68053+ return -EFAULT;
68054+
68055+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
68056+ if (err)
68057+ return err;
68058+
68059+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68060+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
68061+#endif
68062+
68063+ polstate->acl_special_roles[i] = sptmp;
68064+ }
68065+
68066+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
68067+
68068+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
68069+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
68070+
68071+ if (!r_tmp)
68072+ return -ENOMEM;
68073+
68074+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
68075+ return -EFAULT;
68076+
68077+ if (copy_acl_role_label(r_tmp, r_utmp2))
68078+ return -EFAULT;
68079+
68080+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
68081+ if (err)
68082+ return err;
68083+
68084+ if (!strcmp(r_tmp->rolename, "default")
68085+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
68086+ polstate->default_role = r_tmp;
68087+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
68088+ polstate->kernel_role = r_tmp;
68089+ }
68090+
68091+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
68092+ return -ENOMEM;
68093+
68094+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
68095+ return -EFAULT;
68096+
68097+ r_tmp->hash = ghash;
68098+
68099+ num_subjs = count_user_subjs(r_tmp->hash->first);
68100+
68101+ r_tmp->subj_hash_size = num_subjs;
68102+ r_tmp->subj_hash =
68103+ (struct acl_subject_label **)
68104+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
68105+
68106+ if (!r_tmp->subj_hash)
68107+ return -ENOMEM;
68108+
68109+ err = copy_user_allowedips(r_tmp);
68110+ if (err)
68111+ return err;
68112+
68113+ /* copy domain info */
68114+ if (r_tmp->domain_children != NULL) {
68115+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
68116+ if (domainlist == NULL)
68117+ return -ENOMEM;
68118+
68119+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
68120+ return -EFAULT;
68121+
68122+ r_tmp->domain_children = domainlist;
68123+ }
68124+
68125+ err = copy_user_transitions(r_tmp);
68126+ if (err)
68127+ return err;
68128+
68129+ memset(r_tmp->subj_hash, 0,
68130+ r_tmp->subj_hash_size *
68131+ sizeof (struct acl_subject_label *));
68132+
68133+ /* acquire the list of subjects, then NULL out
68134+ the list prior to parsing the subjects for this role,
68135+ as during this parsing the list is replaced with a list
68136+ of *nested* subjects for the role
68137+ */
68138+ subj_list = r_tmp->hash->first;
68139+
68140+ /* set nested subject list to null */
68141+ r_tmp->hash->first = NULL;
68142+
68143+ err = copy_user_subjs(subj_list, r_tmp);
68144+
68145+ if (err)
68146+ return err;
68147+
68148+ insert_acl_role_label(r_tmp);
68149+ }
68150+
68151+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
68152+ return -EINVAL;
68153+
68154+ return err;
68155+}
68156+
68157+static int gracl_reload_apply_policies(void *reload)
68158+{
68159+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
68160+ struct task_struct *task, *task2;
68161+ struct acl_role_label *role, *rtmp;
68162+ struct acl_subject_label *subj;
68163+ const struct cred *cred;
68164+ int role_applied;
68165+ int ret = 0;
68166+
68167+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
68168+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
68169+
68170+ /* first make sure we'll be able to apply the new policy cleanly */
68171+ do_each_thread(task2, task) {
68172+ if (task->exec_file == NULL)
68173+ continue;
68174+ role_applied = 0;
68175+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
68176+ /* preserve special roles */
68177+ FOR_EACH_ROLE_START(role)
68178+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
68179+ rtmp = task->role;
68180+ task->role = role;
68181+ role_applied = 1;
68182+ break;
68183+ }
68184+ FOR_EACH_ROLE_END(role)
68185+ }
68186+ if (!role_applied) {
68187+ cred = __task_cred(task);
68188+ rtmp = task->role;
68189+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
68190+ }
68191+ /* this handles non-nested inherited subjects, nested subjects will still
68192+ be dropped currently */
68193+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
68194+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
68195+ /* change the role back so that we've made no modifications to the policy */
68196+ task->role = rtmp;
68197+
68198+ if (subj == NULL || task->tmpacl == NULL) {
68199+ ret = -EINVAL;
68200+ goto out;
68201+ }
68202+ } while_each_thread(task2, task);
68203+
68204+ /* now actually apply the policy */
68205+
68206+ do_each_thread(task2, task) {
68207+ if (task->exec_file) {
68208+ role_applied = 0;
68209+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
68210+ /* preserve special roles */
68211+ FOR_EACH_ROLE_START(role)
68212+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
68213+ task->role = role;
68214+ role_applied = 1;
68215+ break;
68216+ }
68217+ FOR_EACH_ROLE_END(role)
68218+ }
68219+ if (!role_applied) {
68220+ cred = __task_cred(task);
68221+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
68222+ }
68223+ /* this handles non-nested inherited subjects, nested subjects will still
68224+ be dropped currently */
68225+ if (!reload_state->oldmode && task->inherited)
68226+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
68227+ else {
68228+ /* looked up and tagged to the task previously */
68229+ subj = task->tmpacl;
68230+ }
68231+ /* subj will be non-null */
68232+ __gr_apply_subject_to_task(polstate, task, subj);
68233+ if (reload_state->oldmode) {
68234+ task->acl_role_id = 0;
68235+ task->acl_sp_role = 0;
68236+ task->inherited = 0;
68237+ }
68238+ } else {
68239+ // it's a kernel process
68240+ task->role = polstate->kernel_role;
68241+ task->acl = polstate->kernel_role->root_label;
68242+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
68243+ task->acl->mode &= ~GR_PROCFIND;
68244+#endif
68245+ }
68246+ } while_each_thread(task2, task);
68247+
68248+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
68249+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
68250+
68251+out:
68252+
68253+ return ret;
68254+}
68255+
68256+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
68257+{
68258+ struct gr_reload_state new_reload_state = { };
68259+ int err;
68260+
68261+ new_reload_state.oldpolicy_ptr = polstate;
68262+ new_reload_state.oldalloc_ptr = current_alloc_state;
68263+ new_reload_state.oldmode = oldmode;
68264+
68265+ current_alloc_state = &new_reload_state.newalloc;
68266+ polstate = &new_reload_state.newpolicy;
68267+
68268+ /* everything relevant is now saved off, copy in the new policy */
68269+ if (init_variables(args, true)) {
68270+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
68271+ err = -ENOMEM;
68272+ goto error;
68273+ }
68274+
68275+ err = copy_user_acl(args);
68276+ free_init_variables();
68277+ if (err)
68278+ goto error;
68279+ /* the new policy is copied in, with the old policy available via saved_state
68280+ first go through applying roles, making sure to preserve special roles
68281+ then apply new subjects, making sure to preserve inherited and nested subjects,
68282+ though currently only inherited subjects will be preserved
68283+ */
68284+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
68285+ if (err)
68286+ goto error;
68287+
68288+ /* we've now applied the new policy, so restore the old policy state to free it */
68289+ polstate = &new_reload_state.oldpolicy;
68290+ current_alloc_state = &new_reload_state.oldalloc;
68291+ free_variables(true);
68292+
68293+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
68294+ to running_polstate/current_alloc_state inside stop_machine
68295+ */
68296+ err = 0;
68297+ goto out;
68298+error:
68299+ /* on error of loading the new policy, we'll just keep the previous
68300+ policy set around
68301+ */
68302+ free_variables(true);
68303+
68304+ /* doesn't affect runtime, but maintains consistent state */
68305+out:
68306+ polstate = new_reload_state.oldpolicy_ptr;
68307+ current_alloc_state = new_reload_state.oldalloc_ptr;
68308+
68309+ return err;
68310+}
68311+
68312+static int
68313+gracl_init(struct gr_arg *args)
68314+{
68315+ int error = 0;
68316+
68317+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
68318+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
68319+
68320+ if (init_variables(args, false)) {
68321+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
68322+ error = -ENOMEM;
68323+ goto out;
68324+ }
68325+
68326+ error = copy_user_acl(args);
68327+ free_init_variables();
68328+ if (error)
68329+ goto out;
68330+
68331+ error = gr_set_acls(0);
68332+ if (error)
68333+ goto out;
68334+
68335+ gr_enable_rbac_system();
68336+
68337+ return 0;
68338+
68339+out:
68340+ free_variables(false);
68341+ return error;
68342+}
68343+
68344+static int
68345+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
68346+ unsigned char **sum)
68347+{
68348+ struct acl_role_label *r;
68349+ struct role_allowed_ip *ipp;
68350+ struct role_transition *trans;
68351+ unsigned int i;
68352+ int found = 0;
68353+ u32 curr_ip = current->signal->curr_ip;
68354+
68355+ current->signal->saved_ip = curr_ip;
68356+
68357+ /* check transition table */
68358+
68359+ for (trans = current->role->transitions; trans; trans = trans->next) {
68360+ if (!strcmp(rolename, trans->rolename)) {
68361+ found = 1;
68362+ break;
68363+ }
68364+ }
68365+
68366+ if (!found)
68367+ return 0;
68368+
68369+ /* handle special roles that do not require authentication
68370+ and check ip */
68371+
68372+ FOR_EACH_ROLE_START(r)
68373+ if (!strcmp(rolename, r->rolename) &&
68374+ (r->roletype & GR_ROLE_SPECIAL)) {
68375+ found = 0;
68376+ if (r->allowed_ips != NULL) {
68377+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
68378+ if ((ntohl(curr_ip) & ipp->netmask) ==
68379+ (ntohl(ipp->addr) & ipp->netmask))
68380+ found = 1;
68381+ }
68382+ } else
68383+ found = 2;
68384+ if (!found)
68385+ return 0;
68386+
68387+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
68388+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
68389+ *salt = NULL;
68390+ *sum = NULL;
68391+ return 1;
68392+ }
68393+ }
68394+ FOR_EACH_ROLE_END(r)
68395+
68396+ for (i = 0; i < polstate->num_sprole_pws; i++) {
68397+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
68398+ *salt = polstate->acl_special_roles[i]->salt;
68399+ *sum = polstate->acl_special_roles[i]->sum;
68400+ return 1;
68401+ }
68402+ }
68403+
68404+ return 0;
68405+}
68406+
68407+int gr_check_secure_terminal(struct task_struct *task)
68408+{
68409+ struct task_struct *p, *p2, *p3;
68410+ struct files_struct *files;
68411+ struct fdtable *fdt;
68412+ struct file *our_file = NULL, *file;
68413+ int i;
68414+
68415+ if (task->signal->tty == NULL)
68416+ return 1;
68417+
68418+ files = get_files_struct(task);
68419+ if (files != NULL) {
68420+ rcu_read_lock();
68421+ fdt = files_fdtable(files);
68422+ for (i=0; i < fdt->max_fds; i++) {
68423+ file = fcheck_files(files, i);
68424+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
68425+ get_file(file);
68426+ our_file = file;
68427+ }
68428+ }
68429+ rcu_read_unlock();
68430+ put_files_struct(files);
68431+ }
68432+
68433+ if (our_file == NULL)
68434+ return 1;
68435+
68436+ read_lock(&tasklist_lock);
68437+ do_each_thread(p2, p) {
68438+ files = get_files_struct(p);
68439+ if (files == NULL ||
68440+ (p->signal && p->signal->tty == task->signal->tty)) {
68441+ if (files != NULL)
68442+ put_files_struct(files);
68443+ continue;
68444+ }
68445+ rcu_read_lock();
68446+ fdt = files_fdtable(files);
68447+ for (i=0; i < fdt->max_fds; i++) {
68448+ file = fcheck_files(files, i);
68449+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
68450+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
68451+ p3 = task;
68452+ while (task_pid_nr(p3) > 0) {
68453+ if (p3 == p)
68454+ break;
68455+ p3 = p3->real_parent;
68456+ }
68457+ if (p3 == p)
68458+ break;
68459+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
68460+ gr_handle_alertkill(p);
68461+ rcu_read_unlock();
68462+ put_files_struct(files);
68463+ read_unlock(&tasklist_lock);
68464+ fput(our_file);
68465+ return 0;
68466+ }
68467+ }
68468+ rcu_read_unlock();
68469+ put_files_struct(files);
68470+ } while_each_thread(p2, p);
68471+ read_unlock(&tasklist_lock);
68472+
68473+ fput(our_file);
68474+ return 1;
68475+}
68476+
68477+ssize_t
68478+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
68479+{
68480+ struct gr_arg_wrapper uwrap;
68481+ unsigned char *sprole_salt = NULL;
68482+ unsigned char *sprole_sum = NULL;
68483+ int error = 0;
68484+ int error2 = 0;
68485+ size_t req_count = 0;
68486+ unsigned char oldmode = 0;
68487+
68488+ mutex_lock(&gr_dev_mutex);
68489+
68490+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
68491+ error = -EPERM;
68492+ goto out;
68493+ }
68494+
68495+#ifdef CONFIG_COMPAT
68496+ pax_open_kernel();
68497+ if (is_compat_task()) {
68498+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
68499+ copy_gr_arg = &copy_gr_arg_compat;
68500+ copy_acl_object_label = &copy_acl_object_label_compat;
68501+ copy_acl_subject_label = &copy_acl_subject_label_compat;
68502+ copy_acl_role_label = &copy_acl_role_label_compat;
68503+ copy_acl_ip_label = &copy_acl_ip_label_compat;
68504+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
68505+ copy_role_transition = &copy_role_transition_compat;
68506+ copy_sprole_pw = &copy_sprole_pw_compat;
68507+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
68508+ copy_pointer_from_array = &copy_pointer_from_array_compat;
68509+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
68510+ } else {
68511+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
68512+ copy_gr_arg = &copy_gr_arg_normal;
68513+ copy_acl_object_label = &copy_acl_object_label_normal;
68514+ copy_acl_subject_label = &copy_acl_subject_label_normal;
68515+ copy_acl_role_label = &copy_acl_role_label_normal;
68516+ copy_acl_ip_label = &copy_acl_ip_label_normal;
68517+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
68518+ copy_role_transition = &copy_role_transition_normal;
68519+ copy_sprole_pw = &copy_sprole_pw_normal;
68520+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
68521+ copy_pointer_from_array = &copy_pointer_from_array_normal;
68522+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
68523+ }
68524+ pax_close_kernel();
68525+#endif
68526+
68527+ req_count = get_gr_arg_wrapper_size();
68528+
68529+ if (count != req_count) {
68530+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
68531+ error = -EINVAL;
68532+ goto out;
68533+ }
68534+
68535+
68536+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
68537+ gr_auth_expires = 0;
68538+ gr_auth_attempts = 0;
68539+ }
68540+
68541+ error = copy_gr_arg_wrapper(buf, &uwrap);
68542+ if (error)
68543+ goto out;
68544+
68545+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
68546+ if (error)
68547+ goto out;
68548+
68549+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
68550+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
68551+ time_after(gr_auth_expires, get_seconds())) {
68552+ error = -EBUSY;
68553+ goto out;
68554+ }
68555+
68556+ /* if non-root trying to do anything other than use a special role,
68557+ do not attempt authentication, do not count towards authentication
68558+ locking
68559+ */
68560+
68561+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
68562+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
68563+ gr_is_global_nonroot(current_uid())) {
68564+ error = -EPERM;
68565+ goto out;
68566+ }
68567+
68568+ /* ensure pw and special role name are null terminated */
68569+
68570+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
68571+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
68572+
68573+ /* Okay.
68574+ * We have our enough of the argument structure..(we have yet
68575+ * to copy_from_user the tables themselves) . Copy the tables
68576+ * only if we need them, i.e. for loading operations. */
68577+
68578+ switch (gr_usermode.mode) {
68579+ case GR_STATUS:
68580+ if (gr_acl_is_enabled()) {
68581+ error = 1;
68582+ if (!gr_check_secure_terminal(current))
68583+ error = 3;
68584+ } else
68585+ error = 2;
68586+ goto out;
68587+ case GR_SHUTDOWN:
68588+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
68589+ stop_machine(gr_rbac_disable, NULL, NULL);
68590+ free_variables(false);
68591+ memset(&gr_usermode, 0, sizeof(gr_usermode));
68592+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
68593+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
68594+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
68595+ } else if (gr_acl_is_enabled()) {
68596+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
68597+ error = -EPERM;
68598+ } else {
68599+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
68600+ error = -EAGAIN;
68601+ }
68602+ break;
68603+ case GR_ENABLE:
68604+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
68605+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
68606+ else {
68607+ if (gr_acl_is_enabled())
68608+ error = -EAGAIN;
68609+ else
68610+ error = error2;
68611+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
68612+ }
68613+ break;
68614+ case GR_OLDRELOAD:
68615+ oldmode = 1;
68616+ case GR_RELOAD:
68617+ if (!gr_acl_is_enabled()) {
68618+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
68619+ error = -EAGAIN;
68620+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
68621+ error2 = gracl_reload(&gr_usermode, oldmode);
68622+ if (!error2)
68623+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
68624+ else {
68625+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
68626+ error = error2;
68627+ }
68628+ } else {
68629+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
68630+ error = -EPERM;
68631+ }
68632+ break;
68633+ case GR_SEGVMOD:
68634+ if (unlikely(!gr_acl_is_enabled())) {
68635+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
68636+ error = -EAGAIN;
68637+ break;
68638+ }
68639+
68640+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
68641+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
68642+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
68643+ struct acl_subject_label *segvacl;
68644+ segvacl =
68645+ lookup_acl_subj_label(gr_usermode.segv_inode,
68646+ gr_usermode.segv_device,
68647+ current->role);
68648+ if (segvacl) {
68649+ segvacl->crashes = 0;
68650+ segvacl->expires = 0;
68651+ }
68652+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
68653+ gr_remove_uid(gr_usermode.segv_uid);
68654+ }
68655+ } else {
68656+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
68657+ error = -EPERM;
68658+ }
68659+ break;
68660+ case GR_SPROLE:
68661+ case GR_SPROLEPAM:
68662+ if (unlikely(!gr_acl_is_enabled())) {
68663+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
68664+ error = -EAGAIN;
68665+ break;
68666+ }
68667+
68668+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
68669+ current->role->expires = 0;
68670+ current->role->auth_attempts = 0;
68671+ }
68672+
68673+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
68674+ time_after(current->role->expires, get_seconds())) {
68675+ error = -EBUSY;
68676+ goto out;
68677+ }
68678+
68679+ if (lookup_special_role_auth
68680+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
68681+ && ((!sprole_salt && !sprole_sum)
68682+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
68683+ char *p = "";
68684+ assign_special_role(gr_usermode.sp_role);
68685+ read_lock(&tasklist_lock);
68686+ if (current->real_parent)
68687+ p = current->real_parent->role->rolename;
68688+ read_unlock(&tasklist_lock);
68689+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
68690+ p, acl_sp_role_value);
68691+ } else {
68692+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
68693+ error = -EPERM;
68694+ if(!(current->role->auth_attempts++))
68695+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
68696+
68697+ goto out;
68698+ }
68699+ break;
68700+ case GR_UNSPROLE:
68701+ if (unlikely(!gr_acl_is_enabled())) {
68702+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
68703+ error = -EAGAIN;
68704+ break;
68705+ }
68706+
68707+ if (current->role->roletype & GR_ROLE_SPECIAL) {
68708+ char *p = "";
68709+ int i = 0;
68710+
68711+ read_lock(&tasklist_lock);
68712+ if (current->real_parent) {
68713+ p = current->real_parent->role->rolename;
68714+ i = current->real_parent->acl_role_id;
68715+ }
68716+ read_unlock(&tasklist_lock);
68717+
68718+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
68719+ gr_set_acls(1);
68720+ } else {
68721+ error = -EPERM;
68722+ goto out;
68723+ }
68724+ break;
68725+ default:
68726+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
68727+ error = -EINVAL;
68728+ break;
68729+ }
68730+
68731+ if (error != -EPERM)
68732+ goto out;
68733+
68734+ if(!(gr_auth_attempts++))
68735+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
68736+
68737+ out:
68738+ mutex_unlock(&gr_dev_mutex);
68739+
68740+ if (!error)
68741+ error = req_count;
68742+
68743+ return error;
68744+}
68745+
68746+int
68747+gr_set_acls(const int type)
68748+{
68749+ struct task_struct *task, *task2;
68750+ struct acl_role_label *role = current->role;
68751+ struct acl_subject_label *subj;
68752+ __u16 acl_role_id = current->acl_role_id;
68753+ const struct cred *cred;
68754+ int ret;
68755+
68756+ rcu_read_lock();
68757+ read_lock(&tasklist_lock);
68758+ read_lock(&grsec_exec_file_lock);
68759+ do_each_thread(task2, task) {
68760+ /* check to see if we're called from the exit handler,
68761+ if so, only replace ACLs that have inherited the admin
68762+ ACL */
68763+
68764+ if (type && (task->role != role ||
68765+ task->acl_role_id != acl_role_id))
68766+ continue;
68767+
68768+ task->acl_role_id = 0;
68769+ task->acl_sp_role = 0;
68770+ task->inherited = 0;
68771+
68772+ if (task->exec_file) {
68773+ cred = __task_cred(task);
68774+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
68775+ subj = __gr_get_subject_for_task(polstate, task, NULL);
68776+ if (subj == NULL) {
68777+ ret = -EINVAL;
68778+ read_unlock(&grsec_exec_file_lock);
68779+ read_unlock(&tasklist_lock);
68780+ rcu_read_unlock();
68781+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
68782+ return ret;
68783+ }
68784+ __gr_apply_subject_to_task(polstate, task, subj);
68785+ } else {
68786+ // it's a kernel process
68787+ task->role = polstate->kernel_role;
68788+ task->acl = polstate->kernel_role->root_label;
68789+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
68790+ task->acl->mode &= ~GR_PROCFIND;
68791+#endif
68792+ }
68793+ } while_each_thread(task2, task);
68794+ read_unlock(&grsec_exec_file_lock);
68795+ read_unlock(&tasklist_lock);
68796+ rcu_read_unlock();
68797+
68798+ return 0;
68799+}
68800diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
68801new file mode 100644
68802index 0000000..39645c9
68803--- /dev/null
68804+++ b/grsecurity/gracl_res.c
68805@@ -0,0 +1,68 @@
68806+#include <linux/kernel.h>
68807+#include <linux/sched.h>
68808+#include <linux/gracl.h>
68809+#include <linux/grinternal.h>
68810+
68811+static const char *restab_log[] = {
68812+ [RLIMIT_CPU] = "RLIMIT_CPU",
68813+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
68814+ [RLIMIT_DATA] = "RLIMIT_DATA",
68815+ [RLIMIT_STACK] = "RLIMIT_STACK",
68816+ [RLIMIT_CORE] = "RLIMIT_CORE",
68817+ [RLIMIT_RSS] = "RLIMIT_RSS",
68818+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
68819+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
68820+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
68821+ [RLIMIT_AS] = "RLIMIT_AS",
68822+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
68823+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
68824+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
68825+ [RLIMIT_NICE] = "RLIMIT_NICE",
68826+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
68827+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
68828+ [GR_CRASH_RES] = "RLIMIT_CRASH"
68829+};
68830+
68831+void
68832+gr_log_resource(const struct task_struct *task,
68833+ const int res, const unsigned long wanted, const int gt)
68834+{
68835+ const struct cred *cred;
68836+ unsigned long rlim;
68837+
68838+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
68839+ return;
68840+
68841+ // not yet supported resource
68842+ if (unlikely(!restab_log[res]))
68843+ return;
68844+
68845+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
68846+ rlim = task_rlimit_max(task, res);
68847+ else
68848+ rlim = task_rlimit(task, res);
68849+
68850+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
68851+ return;
68852+
68853+ rcu_read_lock();
68854+ cred = __task_cred(task);
68855+
68856+ if (res == RLIMIT_NPROC &&
68857+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
68858+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
68859+ goto out_rcu_unlock;
68860+ else if (res == RLIMIT_MEMLOCK &&
68861+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
68862+ goto out_rcu_unlock;
68863+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
68864+ goto out_rcu_unlock;
68865+ rcu_read_unlock();
68866+
68867+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
68868+
68869+ return;
68870+out_rcu_unlock:
68871+ rcu_read_unlock();
68872+ return;
68873+}
68874diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
68875new file mode 100644
68876index 0000000..2040e61
68877--- /dev/null
68878+++ b/grsecurity/gracl_segv.c
68879@@ -0,0 +1,313 @@
68880+#include <linux/kernel.h>
68881+#include <linux/mm.h>
68882+#include <asm/uaccess.h>
68883+#include <asm/errno.h>
68884+#include <asm/mman.h>
68885+#include <net/sock.h>
68886+#include <linux/file.h>
68887+#include <linux/fs.h>
68888+#include <linux/net.h>
68889+#include <linux/in.h>
68890+#include <linux/slab.h>
68891+#include <linux/types.h>
68892+#include <linux/sched.h>
68893+#include <linux/timer.h>
68894+#include <linux/gracl.h>
68895+#include <linux/grsecurity.h>
68896+#include <linux/grinternal.h>
68897+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68898+#include <linux/magic.h>
68899+#include <linux/pagemap.h>
68900+#include "../fs/btrfs/async-thread.h"
68901+#include "../fs/btrfs/ctree.h"
68902+#include "../fs/btrfs/btrfs_inode.h"
68903+#endif
68904+
68905+static struct crash_uid *uid_set;
68906+static unsigned short uid_used;
68907+static DEFINE_SPINLOCK(gr_uid_lock);
68908+extern rwlock_t gr_inode_lock;
68909+extern struct acl_subject_label *
68910+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68911+ struct acl_role_label *role);
68912+
68913+static inline dev_t __get_dev(const struct dentry *dentry)
68914+{
68915+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68916+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68917+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68918+ else
68919+#endif
68920+ return dentry->d_sb->s_dev;
68921+}
68922+
68923+int
68924+gr_init_uidset(void)
68925+{
68926+ uid_set =
68927+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68928+ uid_used = 0;
68929+
68930+ return uid_set ? 1 : 0;
68931+}
68932+
68933+void
68934+gr_free_uidset(void)
68935+{
68936+ if (uid_set) {
68937+ struct crash_uid *tmpset;
68938+ spin_lock(&gr_uid_lock);
68939+ tmpset = uid_set;
68940+ uid_set = NULL;
68941+ uid_used = 0;
68942+ spin_unlock(&gr_uid_lock);
68943+ if (tmpset)
68944+ kfree(tmpset);
68945+ }
68946+
68947+ return;
68948+}
68949+
68950+int
68951+gr_find_uid(const uid_t uid)
68952+{
68953+ struct crash_uid *tmp = uid_set;
68954+ uid_t buid;
68955+ int low = 0, high = uid_used - 1, mid;
68956+
68957+ while (high >= low) {
68958+ mid = (low + high) >> 1;
68959+ buid = tmp[mid].uid;
68960+ if (buid == uid)
68961+ return mid;
68962+ if (buid > uid)
68963+ high = mid - 1;
68964+ if (buid < uid)
68965+ low = mid + 1;
68966+ }
68967+
68968+ return -1;
68969+}
68970+
68971+static __inline__ void
68972+gr_insertsort(void)
68973+{
68974+ unsigned short i, j;
68975+ struct crash_uid index;
68976+
68977+ for (i = 1; i < uid_used; i++) {
68978+ index = uid_set[i];
68979+ j = i;
68980+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68981+ uid_set[j] = uid_set[j - 1];
68982+ j--;
68983+ }
68984+ uid_set[j] = index;
68985+ }
68986+
68987+ return;
68988+}
68989+
68990+static __inline__ void
68991+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68992+{
68993+ int loc;
68994+ uid_t uid = GR_GLOBAL_UID(kuid);
68995+
68996+ if (uid_used == GR_UIDTABLE_MAX)
68997+ return;
68998+
68999+ loc = gr_find_uid(uid);
69000+
69001+ if (loc >= 0) {
69002+ uid_set[loc].expires = expires;
69003+ return;
69004+ }
69005+
69006+ uid_set[uid_used].uid = uid;
69007+ uid_set[uid_used].expires = expires;
69008+ uid_used++;
69009+
69010+ gr_insertsort();
69011+
69012+ return;
69013+}
69014+
69015+void
69016+gr_remove_uid(const unsigned short loc)
69017+{
69018+ unsigned short i;
69019+
69020+ for (i = loc + 1; i < uid_used; i++)
69021+ uid_set[i - 1] = uid_set[i];
69022+
69023+ uid_used--;
69024+
69025+ return;
69026+}
69027+
69028+int
69029+gr_check_crash_uid(const kuid_t kuid)
69030+{
69031+ int loc;
69032+ int ret = 0;
69033+ uid_t uid;
69034+
69035+ if (unlikely(!gr_acl_is_enabled()))
69036+ return 0;
69037+
69038+ uid = GR_GLOBAL_UID(kuid);
69039+
69040+ spin_lock(&gr_uid_lock);
69041+ loc = gr_find_uid(uid);
69042+
69043+ if (loc < 0)
69044+ goto out_unlock;
69045+
69046+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
69047+ gr_remove_uid(loc);
69048+ else
69049+ ret = 1;
69050+
69051+out_unlock:
69052+ spin_unlock(&gr_uid_lock);
69053+ return ret;
69054+}
69055+
69056+static __inline__ int
69057+proc_is_setxid(const struct cred *cred)
69058+{
69059+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
69060+ !uid_eq(cred->uid, cred->fsuid))
69061+ return 1;
69062+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
69063+ !gid_eq(cred->gid, cred->fsgid))
69064+ return 1;
69065+
69066+ return 0;
69067+}
69068+
69069+extern int gr_fake_force_sig(int sig, struct task_struct *t);
69070+
69071+void
69072+gr_handle_crash(struct task_struct *task, const int sig)
69073+{
69074+ struct acl_subject_label *curr;
69075+ struct task_struct *tsk, *tsk2;
69076+ const struct cred *cred;
69077+ const struct cred *cred2;
69078+
69079+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
69080+ return;
69081+
69082+ if (unlikely(!gr_acl_is_enabled()))
69083+ return;
69084+
69085+ curr = task->acl;
69086+
69087+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
69088+ return;
69089+
69090+ if (time_before_eq(curr->expires, get_seconds())) {
69091+ curr->expires = 0;
69092+ curr->crashes = 0;
69093+ }
69094+
69095+ curr->crashes++;
69096+
69097+ if (!curr->expires)
69098+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
69099+
69100+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69101+ time_after(curr->expires, get_seconds())) {
69102+ rcu_read_lock();
69103+ cred = __task_cred(task);
69104+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
69105+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69106+ spin_lock(&gr_uid_lock);
69107+ gr_insert_uid(cred->uid, curr->expires);
69108+ spin_unlock(&gr_uid_lock);
69109+ curr->expires = 0;
69110+ curr->crashes = 0;
69111+ read_lock(&tasklist_lock);
69112+ do_each_thread(tsk2, tsk) {
69113+ cred2 = __task_cred(tsk);
69114+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
69115+ gr_fake_force_sig(SIGKILL, tsk);
69116+ } while_each_thread(tsk2, tsk);
69117+ read_unlock(&tasklist_lock);
69118+ } else {
69119+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69120+ read_lock(&tasklist_lock);
69121+ read_lock(&grsec_exec_file_lock);
69122+ do_each_thread(tsk2, tsk) {
69123+ if (likely(tsk != task)) {
69124+ // if this thread has the same subject as the one that triggered
69125+ // RES_CRASH and it's the same binary, kill it
69126+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
69127+ gr_fake_force_sig(SIGKILL, tsk);
69128+ }
69129+ } while_each_thread(tsk2, tsk);
69130+ read_unlock(&grsec_exec_file_lock);
69131+ read_unlock(&tasklist_lock);
69132+ }
69133+ rcu_read_unlock();
69134+ }
69135+
69136+ return;
69137+}
69138+
69139+int
69140+gr_check_crash_exec(const struct file *filp)
69141+{
69142+ struct acl_subject_label *curr;
69143+
69144+ if (unlikely(!gr_acl_is_enabled()))
69145+ return 0;
69146+
69147+ read_lock(&gr_inode_lock);
69148+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
69149+ __get_dev(filp->f_path.dentry),
69150+ current->role);
69151+ read_unlock(&gr_inode_lock);
69152+
69153+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
69154+ (!curr->crashes && !curr->expires))
69155+ return 0;
69156+
69157+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69158+ time_after(curr->expires, get_seconds()))
69159+ return 1;
69160+ else if (time_before_eq(curr->expires, get_seconds())) {
69161+ curr->crashes = 0;
69162+ curr->expires = 0;
69163+ }
69164+
69165+ return 0;
69166+}
69167+
69168+void
69169+gr_handle_alertkill(struct task_struct *task)
69170+{
69171+ struct acl_subject_label *curracl;
69172+ __u32 curr_ip;
69173+ struct task_struct *p, *p2;
69174+
69175+ if (unlikely(!gr_acl_is_enabled()))
69176+ return;
69177+
69178+ curracl = task->acl;
69179+ curr_ip = task->signal->curr_ip;
69180+
69181+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
69182+ read_lock(&tasklist_lock);
69183+ do_each_thread(p2, p) {
69184+ if (p->signal->curr_ip == curr_ip)
69185+ gr_fake_force_sig(SIGKILL, p);
69186+ } while_each_thread(p2, p);
69187+ read_unlock(&tasklist_lock);
69188+ } else if (curracl->mode & GR_KILLPROC)
69189+ gr_fake_force_sig(SIGKILL, task);
69190+
69191+ return;
69192+}
69193diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
69194new file mode 100644
69195index 0000000..98011b0
69196--- /dev/null
69197+++ b/grsecurity/gracl_shm.c
69198@@ -0,0 +1,40 @@
69199+#include <linux/kernel.h>
69200+#include <linux/mm.h>
69201+#include <linux/sched.h>
69202+#include <linux/file.h>
69203+#include <linux/ipc.h>
69204+#include <linux/gracl.h>
69205+#include <linux/grsecurity.h>
69206+#include <linux/grinternal.h>
69207+
69208+int
69209+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69210+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69211+{
69212+ struct task_struct *task;
69213+
69214+ if (!gr_acl_is_enabled())
69215+ return 1;
69216+
69217+ rcu_read_lock();
69218+ read_lock(&tasklist_lock);
69219+
69220+ task = find_task_by_vpid(shm_cprid);
69221+
69222+ if (unlikely(!task))
69223+ task = find_task_by_vpid(shm_lapid);
69224+
69225+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
69226+ (task_pid_nr(task) == shm_lapid)) &&
69227+ (task->acl->mode & GR_PROTSHM) &&
69228+ (task->acl != current->acl))) {
69229+ read_unlock(&tasklist_lock);
69230+ rcu_read_unlock();
69231+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
69232+ return 0;
69233+ }
69234+ read_unlock(&tasklist_lock);
69235+ rcu_read_unlock();
69236+
69237+ return 1;
69238+}
69239diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
69240new file mode 100644
69241index 0000000..bc0be01
69242--- /dev/null
69243+++ b/grsecurity/grsec_chdir.c
69244@@ -0,0 +1,19 @@
69245+#include <linux/kernel.h>
69246+#include <linux/sched.h>
69247+#include <linux/fs.h>
69248+#include <linux/file.h>
69249+#include <linux/grsecurity.h>
69250+#include <linux/grinternal.h>
69251+
69252+void
69253+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
69254+{
69255+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69256+ if ((grsec_enable_chdir && grsec_enable_group &&
69257+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
69258+ !grsec_enable_group)) {
69259+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
69260+ }
69261+#endif
69262+ return;
69263+}
69264diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
69265new file mode 100644
69266index 0000000..e10b319
69267--- /dev/null
69268+++ b/grsecurity/grsec_chroot.c
69269@@ -0,0 +1,370 @@
69270+#include <linux/kernel.h>
69271+#include <linux/module.h>
69272+#include <linux/sched.h>
69273+#include <linux/file.h>
69274+#include <linux/fs.h>
69275+#include <linux/mount.h>
69276+#include <linux/types.h>
69277+#include "../fs/mount.h"
69278+#include <linux/grsecurity.h>
69279+#include <linux/grinternal.h>
69280+
69281+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69282+int gr_init_ran;
69283+#endif
69284+
69285+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
69286+{
69287+#ifdef CONFIG_GRKERNSEC
69288+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
69289+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
69290+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69291+ && gr_init_ran
69292+#endif
69293+ )
69294+ task->gr_is_chrooted = 1;
69295+ else {
69296+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69297+ if (task_pid_nr(task) == 1 && !gr_init_ran)
69298+ gr_init_ran = 1;
69299+#endif
69300+ task->gr_is_chrooted = 0;
69301+ }
69302+
69303+ task->gr_chroot_dentry = path->dentry;
69304+#endif
69305+ return;
69306+}
69307+
69308+void gr_clear_chroot_entries(struct task_struct *task)
69309+{
69310+#ifdef CONFIG_GRKERNSEC
69311+ task->gr_is_chrooted = 0;
69312+ task->gr_chroot_dentry = NULL;
69313+#endif
69314+ return;
69315+}
69316+
69317+int
69318+gr_handle_chroot_unix(const pid_t pid)
69319+{
69320+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69321+ struct task_struct *p;
69322+
69323+ if (unlikely(!grsec_enable_chroot_unix))
69324+ return 1;
69325+
69326+ if (likely(!proc_is_chrooted(current)))
69327+ return 1;
69328+
69329+ rcu_read_lock();
69330+ read_lock(&tasklist_lock);
69331+ p = find_task_by_vpid_unrestricted(pid);
69332+ if (unlikely(p && !have_same_root(current, p))) {
69333+ read_unlock(&tasklist_lock);
69334+ rcu_read_unlock();
69335+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
69336+ return 0;
69337+ }
69338+ read_unlock(&tasklist_lock);
69339+ rcu_read_unlock();
69340+#endif
69341+ return 1;
69342+}
69343+
69344+int
69345+gr_handle_chroot_nice(void)
69346+{
69347+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69348+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
69349+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
69350+ return -EPERM;
69351+ }
69352+#endif
69353+ return 0;
69354+}
69355+
69356+int
69357+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
69358+{
69359+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69360+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
69361+ && proc_is_chrooted(current)) {
69362+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
69363+ return -EACCES;
69364+ }
69365+#endif
69366+ return 0;
69367+}
69368+
69369+int
69370+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
69371+{
69372+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69373+ struct task_struct *p;
69374+ int ret = 0;
69375+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
69376+ return ret;
69377+
69378+ read_lock(&tasklist_lock);
69379+ do_each_pid_task(pid, type, p) {
69380+ if (!have_same_root(current, p)) {
69381+ ret = 1;
69382+ goto out;
69383+ }
69384+ } while_each_pid_task(pid, type, p);
69385+out:
69386+ read_unlock(&tasklist_lock);
69387+ return ret;
69388+#endif
69389+ return 0;
69390+}
69391+
69392+int
69393+gr_pid_is_chrooted(struct task_struct *p)
69394+{
69395+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69396+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
69397+ return 0;
69398+
69399+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
69400+ !have_same_root(current, p)) {
69401+ return 1;
69402+ }
69403+#endif
69404+ return 0;
69405+}
69406+
69407+EXPORT_SYMBOL(gr_pid_is_chrooted);
69408+
69409+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
69410+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
69411+{
69412+ struct path path, currentroot;
69413+ int ret = 0;
69414+
69415+ path.dentry = (struct dentry *)u_dentry;
69416+ path.mnt = (struct vfsmount *)u_mnt;
69417+ get_fs_root(current->fs, &currentroot);
69418+ if (path_is_under(&path, &currentroot))
69419+ ret = 1;
69420+ path_put(&currentroot);
69421+
69422+ return ret;
69423+}
69424+#endif
69425+
69426+int
69427+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
69428+{
69429+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69430+ if (!grsec_enable_chroot_fchdir)
69431+ return 1;
69432+
69433+ if (!proc_is_chrooted(current))
69434+ return 1;
69435+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
69436+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
69437+ return 0;
69438+ }
69439+#endif
69440+ return 1;
69441+}
69442+
69443+int
69444+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69445+ const time_t shm_createtime)
69446+{
69447+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69448+ struct task_struct *p;
69449+ time_t starttime;
69450+
69451+ if (unlikely(!grsec_enable_chroot_shmat))
69452+ return 1;
69453+
69454+ if (likely(!proc_is_chrooted(current)))
69455+ return 1;
69456+
69457+ rcu_read_lock();
69458+ read_lock(&tasklist_lock);
69459+
69460+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
69461+ starttime = p->start_time.tv_sec;
69462+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
69463+ if (have_same_root(current, p)) {
69464+ goto allow;
69465+ } else {
69466+ read_unlock(&tasklist_lock);
69467+ rcu_read_unlock();
69468+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69469+ return 0;
69470+ }
69471+ }
69472+ /* creator exited, pid reuse, fall through to next check */
69473+ }
69474+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
69475+ if (unlikely(!have_same_root(current, p))) {
69476+ read_unlock(&tasklist_lock);
69477+ rcu_read_unlock();
69478+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69479+ return 0;
69480+ }
69481+ }
69482+
69483+allow:
69484+ read_unlock(&tasklist_lock);
69485+ rcu_read_unlock();
69486+#endif
69487+ return 1;
69488+}
69489+
69490+void
69491+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
69492+{
69493+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69494+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
69495+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
69496+#endif
69497+ return;
69498+}
69499+
69500+int
69501+gr_handle_chroot_mknod(const struct dentry *dentry,
69502+ const struct vfsmount *mnt, const int mode)
69503+{
69504+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69505+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
69506+ proc_is_chrooted(current)) {
69507+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
69508+ return -EPERM;
69509+ }
69510+#endif
69511+ return 0;
69512+}
69513+
69514+int
69515+gr_handle_chroot_mount(const struct dentry *dentry,
69516+ const struct vfsmount *mnt, const char *dev_name)
69517+{
69518+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69519+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
69520+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
69521+ return -EPERM;
69522+ }
69523+#endif
69524+ return 0;
69525+}
69526+
69527+int
69528+gr_handle_chroot_pivot(void)
69529+{
69530+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69531+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
69532+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
69533+ return -EPERM;
69534+ }
69535+#endif
69536+ return 0;
69537+}
69538+
69539+int
69540+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
69541+{
69542+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69543+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
69544+ !gr_is_outside_chroot(dentry, mnt)) {
69545+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
69546+ return -EPERM;
69547+ }
69548+#endif
69549+ return 0;
69550+}
69551+
69552+extern const char *captab_log[];
69553+extern int captab_log_entries;
69554+
69555+int
69556+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69557+{
69558+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69559+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69560+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69561+ if (cap_raised(chroot_caps, cap)) {
69562+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
69563+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
69564+ }
69565+ return 0;
69566+ }
69567+ }
69568+#endif
69569+ return 1;
69570+}
69571+
69572+int
69573+gr_chroot_is_capable(const int cap)
69574+{
69575+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69576+ return gr_task_chroot_is_capable(current, current_cred(), cap);
69577+#endif
69578+ return 1;
69579+}
69580+
69581+int
69582+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
69583+{
69584+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69585+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69586+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69587+ if (cap_raised(chroot_caps, cap)) {
69588+ return 0;
69589+ }
69590+ }
69591+#endif
69592+ return 1;
69593+}
69594+
69595+int
69596+gr_chroot_is_capable_nolog(const int cap)
69597+{
69598+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69599+ return gr_task_chroot_is_capable_nolog(current, cap);
69600+#endif
69601+ return 1;
69602+}
69603+
69604+int
69605+gr_handle_chroot_sysctl(const int op)
69606+{
69607+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69608+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
69609+ proc_is_chrooted(current))
69610+ return -EACCES;
69611+#endif
69612+ return 0;
69613+}
69614+
69615+void
69616+gr_handle_chroot_chdir(const struct path *path)
69617+{
69618+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69619+ if (grsec_enable_chroot_chdir)
69620+ set_fs_pwd(current->fs, path);
69621+#endif
69622+ return;
69623+}
69624+
69625+int
69626+gr_handle_chroot_chmod(const struct dentry *dentry,
69627+ const struct vfsmount *mnt, const int mode)
69628+{
69629+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69630+ /* allow chmod +s on directories, but not files */
69631+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
69632+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
69633+ proc_is_chrooted(current)) {
69634+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
69635+ return -EPERM;
69636+ }
69637+#endif
69638+ return 0;
69639+}
69640diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
69641new file mode 100644
69642index 0000000..0866ab2
69643--- /dev/null
69644+++ b/grsecurity/grsec_disabled.c
69645@@ -0,0 +1,427 @@
69646+#include <linux/kernel.h>
69647+#include <linux/module.h>
69648+#include <linux/sched.h>
69649+#include <linux/file.h>
69650+#include <linux/fs.h>
69651+#include <linux/kdev_t.h>
69652+#include <linux/net.h>
69653+#include <linux/in.h>
69654+#include <linux/ip.h>
69655+#include <linux/skbuff.h>
69656+#include <linux/sysctl.h>
69657+
69658+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69659+void
69660+pax_set_initial_flags(struct linux_binprm *bprm)
69661+{
69662+ return;
69663+}
69664+#endif
69665+
69666+#ifdef CONFIG_SYSCTL
69667+__u32
69668+gr_handle_sysctl(const struct ctl_table * table, const int op)
69669+{
69670+ return 0;
69671+}
69672+#endif
69673+
69674+#ifdef CONFIG_TASKSTATS
69675+int gr_is_taskstats_denied(int pid)
69676+{
69677+ return 0;
69678+}
69679+#endif
69680+
69681+int
69682+gr_acl_is_enabled(void)
69683+{
69684+ return 0;
69685+}
69686+
69687+void
69688+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69689+{
69690+ return;
69691+}
69692+
69693+int
69694+gr_handle_rawio(const struct inode *inode)
69695+{
69696+ return 0;
69697+}
69698+
69699+void
69700+gr_acl_handle_psacct(struct task_struct *task, const long code)
69701+{
69702+ return;
69703+}
69704+
69705+int
69706+gr_handle_ptrace(struct task_struct *task, const long request)
69707+{
69708+ return 0;
69709+}
69710+
69711+int
69712+gr_handle_proc_ptrace(struct task_struct *task)
69713+{
69714+ return 0;
69715+}
69716+
69717+int
69718+gr_set_acls(const int type)
69719+{
69720+ return 0;
69721+}
69722+
69723+int
69724+gr_check_hidden_task(const struct task_struct *tsk)
69725+{
69726+ return 0;
69727+}
69728+
69729+int
69730+gr_check_protected_task(const struct task_struct *task)
69731+{
69732+ return 0;
69733+}
69734+
69735+int
69736+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
69737+{
69738+ return 0;
69739+}
69740+
69741+void
69742+gr_copy_label(struct task_struct *tsk)
69743+{
69744+ return;
69745+}
69746+
69747+void
69748+gr_set_pax_flags(struct task_struct *task)
69749+{
69750+ return;
69751+}
69752+
69753+int
69754+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69755+ const int unsafe_share)
69756+{
69757+ return 0;
69758+}
69759+
69760+void
69761+gr_handle_delete(const ino_t ino, const dev_t dev)
69762+{
69763+ return;
69764+}
69765+
69766+void
69767+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69768+{
69769+ return;
69770+}
69771+
69772+void
69773+gr_handle_crash(struct task_struct *task, const int sig)
69774+{
69775+ return;
69776+}
69777+
69778+int
69779+gr_check_crash_exec(const struct file *filp)
69780+{
69781+ return 0;
69782+}
69783+
69784+int
69785+gr_check_crash_uid(const kuid_t uid)
69786+{
69787+ return 0;
69788+}
69789+
69790+void
69791+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69792+ struct dentry *old_dentry,
69793+ struct dentry *new_dentry,
69794+ struct vfsmount *mnt, const __u8 replace)
69795+{
69796+ return;
69797+}
69798+
69799+int
69800+gr_search_socket(const int family, const int type, const int protocol)
69801+{
69802+ return 1;
69803+}
69804+
69805+int
69806+gr_search_connectbind(const int mode, const struct socket *sock,
69807+ const struct sockaddr_in *addr)
69808+{
69809+ return 0;
69810+}
69811+
69812+void
69813+gr_handle_alertkill(struct task_struct *task)
69814+{
69815+ return;
69816+}
69817+
69818+__u32
69819+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
69820+{
69821+ return 1;
69822+}
69823+
69824+__u32
69825+gr_acl_handle_hidden_file(const struct dentry * dentry,
69826+ const struct vfsmount * mnt)
69827+{
69828+ return 1;
69829+}
69830+
69831+__u32
69832+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69833+ int acc_mode)
69834+{
69835+ return 1;
69836+}
69837+
69838+__u32
69839+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69840+{
69841+ return 1;
69842+}
69843+
69844+__u32
69845+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
69846+{
69847+ return 1;
69848+}
69849+
69850+int
69851+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
69852+ unsigned int *vm_flags)
69853+{
69854+ return 1;
69855+}
69856+
69857+__u32
69858+gr_acl_handle_truncate(const struct dentry * dentry,
69859+ const struct vfsmount * mnt)
69860+{
69861+ return 1;
69862+}
69863+
69864+__u32
69865+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
69866+{
69867+ return 1;
69868+}
69869+
69870+__u32
69871+gr_acl_handle_access(const struct dentry * dentry,
69872+ const struct vfsmount * mnt, const int fmode)
69873+{
69874+ return 1;
69875+}
69876+
69877+__u32
69878+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
69879+ umode_t *mode)
69880+{
69881+ return 1;
69882+}
69883+
69884+__u32
69885+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
69886+{
69887+ return 1;
69888+}
69889+
69890+__u32
69891+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
69892+{
69893+ return 1;
69894+}
69895+
69896+void
69897+grsecurity_init(void)
69898+{
69899+ return;
69900+}
69901+
69902+umode_t gr_acl_umask(void)
69903+{
69904+ return 0;
69905+}
69906+
69907+__u32
69908+gr_acl_handle_mknod(const struct dentry * new_dentry,
69909+ const struct dentry * parent_dentry,
69910+ const struct vfsmount * parent_mnt,
69911+ const int mode)
69912+{
69913+ return 1;
69914+}
69915+
69916+__u32
69917+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69918+ const struct dentry * parent_dentry,
69919+ const struct vfsmount * parent_mnt)
69920+{
69921+ return 1;
69922+}
69923+
69924+__u32
69925+gr_acl_handle_symlink(const struct dentry * new_dentry,
69926+ const struct dentry * parent_dentry,
69927+ const struct vfsmount * parent_mnt, const struct filename *from)
69928+{
69929+ return 1;
69930+}
69931+
69932+__u32
69933+gr_acl_handle_link(const struct dentry * new_dentry,
69934+ const struct dentry * parent_dentry,
69935+ const struct vfsmount * parent_mnt,
69936+ const struct dentry * old_dentry,
69937+ const struct vfsmount * old_mnt, const struct filename *to)
69938+{
69939+ return 1;
69940+}
69941+
69942+int
69943+gr_acl_handle_rename(const struct dentry *new_dentry,
69944+ const struct dentry *parent_dentry,
69945+ const struct vfsmount *parent_mnt,
69946+ const struct dentry *old_dentry,
69947+ const struct inode *old_parent_inode,
69948+ const struct vfsmount *old_mnt, const struct filename *newname)
69949+{
69950+ return 0;
69951+}
69952+
69953+int
69954+gr_acl_handle_filldir(const struct file *file, const char *name,
69955+ const int namelen, const ino_t ino)
69956+{
69957+ return 1;
69958+}
69959+
69960+int
69961+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69962+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69963+{
69964+ return 1;
69965+}
69966+
69967+int
69968+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69969+{
69970+ return 0;
69971+}
69972+
69973+int
69974+gr_search_accept(const struct socket *sock)
69975+{
69976+ return 0;
69977+}
69978+
69979+int
69980+gr_search_listen(const struct socket *sock)
69981+{
69982+ return 0;
69983+}
69984+
69985+int
69986+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69987+{
69988+ return 0;
69989+}
69990+
69991+__u32
69992+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69993+{
69994+ return 1;
69995+}
69996+
69997+__u32
69998+gr_acl_handle_creat(const struct dentry * dentry,
69999+ const struct dentry * p_dentry,
70000+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70001+ const int imode)
70002+{
70003+ return 1;
70004+}
70005+
70006+void
70007+gr_acl_handle_exit(void)
70008+{
70009+ return;
70010+}
70011+
70012+int
70013+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
70014+{
70015+ return 1;
70016+}
70017+
70018+void
70019+gr_set_role_label(const kuid_t uid, const kgid_t gid)
70020+{
70021+ return;
70022+}
70023+
70024+int
70025+gr_acl_handle_procpidmem(const struct task_struct *task)
70026+{
70027+ return 0;
70028+}
70029+
70030+int
70031+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
70032+{
70033+ return 0;
70034+}
70035+
70036+int
70037+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
70038+{
70039+ return 0;
70040+}
70041+
70042+int
70043+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70044+{
70045+ return 0;
70046+}
70047+
70048+int
70049+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70050+{
70051+ return 0;
70052+}
70053+
70054+int gr_acl_enable_at_secure(void)
70055+{
70056+ return 0;
70057+}
70058+
70059+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70060+{
70061+ return dentry->d_sb->s_dev;
70062+}
70063+
70064+void gr_put_exec_file(struct task_struct *task)
70065+{
70066+ return;
70067+}
70068+
70069+#ifdef CONFIG_SECURITY
70070+EXPORT_SYMBOL(gr_check_user_change);
70071+EXPORT_SYMBOL(gr_check_group_change);
70072+#endif
70073diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
70074new file mode 100644
70075index 0000000..387032b
70076--- /dev/null
70077+++ b/grsecurity/grsec_exec.c
70078@@ -0,0 +1,187 @@
70079+#include <linux/kernel.h>
70080+#include <linux/sched.h>
70081+#include <linux/file.h>
70082+#include <linux/binfmts.h>
70083+#include <linux/fs.h>
70084+#include <linux/types.h>
70085+#include <linux/grdefs.h>
70086+#include <linux/grsecurity.h>
70087+#include <linux/grinternal.h>
70088+#include <linux/capability.h>
70089+#include <linux/module.h>
70090+#include <linux/compat.h>
70091+
70092+#include <asm/uaccess.h>
70093+
70094+#ifdef CONFIG_GRKERNSEC_EXECLOG
70095+static char gr_exec_arg_buf[132];
70096+static DEFINE_MUTEX(gr_exec_arg_mutex);
70097+#endif
70098+
70099+struct user_arg_ptr {
70100+#ifdef CONFIG_COMPAT
70101+ bool is_compat;
70102+#endif
70103+ union {
70104+ const char __user *const __user *native;
70105+#ifdef CONFIG_COMPAT
70106+ const compat_uptr_t __user *compat;
70107+#endif
70108+ } ptr;
70109+};
70110+
70111+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
70112+
70113+void
70114+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
70115+{
70116+#ifdef CONFIG_GRKERNSEC_EXECLOG
70117+ char *grarg = gr_exec_arg_buf;
70118+ unsigned int i, x, execlen = 0;
70119+ char c;
70120+
70121+ if (!((grsec_enable_execlog && grsec_enable_group &&
70122+ in_group_p(grsec_audit_gid))
70123+ || (grsec_enable_execlog && !grsec_enable_group)))
70124+ return;
70125+
70126+ mutex_lock(&gr_exec_arg_mutex);
70127+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
70128+
70129+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
70130+ const char __user *p;
70131+ unsigned int len;
70132+
70133+ p = get_user_arg_ptr(argv, i);
70134+ if (IS_ERR(p))
70135+ goto log;
70136+
70137+ len = strnlen_user(p, 128 - execlen);
70138+ if (len > 128 - execlen)
70139+ len = 128 - execlen;
70140+ else if (len > 0)
70141+ len--;
70142+ if (copy_from_user(grarg + execlen, p, len))
70143+ goto log;
70144+
70145+ /* rewrite unprintable characters */
70146+ for (x = 0; x < len; x++) {
70147+ c = *(grarg + execlen + x);
70148+ if (c < 32 || c > 126)
70149+ *(grarg + execlen + x) = ' ';
70150+ }
70151+
70152+ execlen += len;
70153+ *(grarg + execlen) = ' ';
70154+ *(grarg + execlen + 1) = '\0';
70155+ execlen++;
70156+ }
70157+
70158+ log:
70159+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
70160+ bprm->file->f_path.mnt, grarg);
70161+ mutex_unlock(&gr_exec_arg_mutex);
70162+#endif
70163+ return;
70164+}
70165+
70166+#ifdef CONFIG_GRKERNSEC
70167+extern int gr_acl_is_capable(const int cap);
70168+extern int gr_acl_is_capable_nolog(const int cap);
70169+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70170+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
70171+extern int gr_chroot_is_capable(const int cap);
70172+extern int gr_chroot_is_capable_nolog(const int cap);
70173+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70174+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
70175+#endif
70176+
70177+const char *captab_log[] = {
70178+ "CAP_CHOWN",
70179+ "CAP_DAC_OVERRIDE",
70180+ "CAP_DAC_READ_SEARCH",
70181+ "CAP_FOWNER",
70182+ "CAP_FSETID",
70183+ "CAP_KILL",
70184+ "CAP_SETGID",
70185+ "CAP_SETUID",
70186+ "CAP_SETPCAP",
70187+ "CAP_LINUX_IMMUTABLE",
70188+ "CAP_NET_BIND_SERVICE",
70189+ "CAP_NET_BROADCAST",
70190+ "CAP_NET_ADMIN",
70191+ "CAP_NET_RAW",
70192+ "CAP_IPC_LOCK",
70193+ "CAP_IPC_OWNER",
70194+ "CAP_SYS_MODULE",
70195+ "CAP_SYS_RAWIO",
70196+ "CAP_SYS_CHROOT",
70197+ "CAP_SYS_PTRACE",
70198+ "CAP_SYS_PACCT",
70199+ "CAP_SYS_ADMIN",
70200+ "CAP_SYS_BOOT",
70201+ "CAP_SYS_NICE",
70202+ "CAP_SYS_RESOURCE",
70203+ "CAP_SYS_TIME",
70204+ "CAP_SYS_TTY_CONFIG",
70205+ "CAP_MKNOD",
70206+ "CAP_LEASE",
70207+ "CAP_AUDIT_WRITE",
70208+ "CAP_AUDIT_CONTROL",
70209+ "CAP_SETFCAP",
70210+ "CAP_MAC_OVERRIDE",
70211+ "CAP_MAC_ADMIN",
70212+ "CAP_SYSLOG",
70213+ "CAP_WAKE_ALARM"
70214+};
70215+
70216+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
70217+
70218+int gr_is_capable(const int cap)
70219+{
70220+#ifdef CONFIG_GRKERNSEC
70221+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
70222+ return 1;
70223+ return 0;
70224+#else
70225+ return 1;
70226+#endif
70227+}
70228+
70229+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70230+{
70231+#ifdef CONFIG_GRKERNSEC
70232+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
70233+ return 1;
70234+ return 0;
70235+#else
70236+ return 1;
70237+#endif
70238+}
70239+
70240+int gr_is_capable_nolog(const int cap)
70241+{
70242+#ifdef CONFIG_GRKERNSEC
70243+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
70244+ return 1;
70245+ return 0;
70246+#else
70247+ return 1;
70248+#endif
70249+}
70250+
70251+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
70252+{
70253+#ifdef CONFIG_GRKERNSEC
70254+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
70255+ return 1;
70256+ return 0;
70257+#else
70258+ return 1;
70259+#endif
70260+}
70261+
70262+EXPORT_SYMBOL(gr_is_capable);
70263+EXPORT_SYMBOL(gr_is_capable_nolog);
70264+EXPORT_SYMBOL(gr_task_is_capable);
70265+EXPORT_SYMBOL(gr_task_is_capable_nolog);
70266diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
70267new file mode 100644
70268index 0000000..06cc6ea
70269--- /dev/null
70270+++ b/grsecurity/grsec_fifo.c
70271@@ -0,0 +1,24 @@
70272+#include <linux/kernel.h>
70273+#include <linux/sched.h>
70274+#include <linux/fs.h>
70275+#include <linux/file.h>
70276+#include <linux/grinternal.h>
70277+
70278+int
70279+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
70280+ const struct dentry *dir, const int flag, const int acc_mode)
70281+{
70282+#ifdef CONFIG_GRKERNSEC_FIFO
70283+ const struct cred *cred = current_cred();
70284+
70285+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
70286+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
70287+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
70288+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
70289+ if (!inode_permission(dentry->d_inode, acc_mode))
70290+ 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));
70291+ return -EACCES;
70292+ }
70293+#endif
70294+ return 0;
70295+}
70296diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
70297new file mode 100644
70298index 0000000..8ca18bf
70299--- /dev/null
70300+++ b/grsecurity/grsec_fork.c
70301@@ -0,0 +1,23 @@
70302+#include <linux/kernel.h>
70303+#include <linux/sched.h>
70304+#include <linux/grsecurity.h>
70305+#include <linux/grinternal.h>
70306+#include <linux/errno.h>
70307+
70308+void
70309+gr_log_forkfail(const int retval)
70310+{
70311+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70312+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
70313+ switch (retval) {
70314+ case -EAGAIN:
70315+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
70316+ break;
70317+ case -ENOMEM:
70318+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
70319+ break;
70320+ }
70321+ }
70322+#endif
70323+ return;
70324+}
70325diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
70326new file mode 100644
70327index 0000000..a88e901
70328--- /dev/null
70329+++ b/grsecurity/grsec_init.c
70330@@ -0,0 +1,272 @@
70331+#include <linux/kernel.h>
70332+#include <linux/sched.h>
70333+#include <linux/mm.h>
70334+#include <linux/gracl.h>
70335+#include <linux/slab.h>
70336+#include <linux/vmalloc.h>
70337+#include <linux/percpu.h>
70338+#include <linux/module.h>
70339+
70340+int grsec_enable_ptrace_readexec;
70341+int grsec_enable_setxid;
70342+int grsec_enable_symlinkown;
70343+kgid_t grsec_symlinkown_gid;
70344+int grsec_enable_brute;
70345+int grsec_enable_link;
70346+int grsec_enable_dmesg;
70347+int grsec_enable_harden_ptrace;
70348+int grsec_enable_harden_ipc;
70349+int grsec_enable_fifo;
70350+int grsec_enable_execlog;
70351+int grsec_enable_signal;
70352+int grsec_enable_forkfail;
70353+int grsec_enable_audit_ptrace;
70354+int grsec_enable_time;
70355+int grsec_enable_group;
70356+kgid_t grsec_audit_gid;
70357+int grsec_enable_chdir;
70358+int grsec_enable_mount;
70359+int grsec_enable_rofs;
70360+int grsec_deny_new_usb;
70361+int grsec_enable_chroot_findtask;
70362+int grsec_enable_chroot_mount;
70363+int grsec_enable_chroot_shmat;
70364+int grsec_enable_chroot_fchdir;
70365+int grsec_enable_chroot_double;
70366+int grsec_enable_chroot_pivot;
70367+int grsec_enable_chroot_chdir;
70368+int grsec_enable_chroot_chmod;
70369+int grsec_enable_chroot_mknod;
70370+int grsec_enable_chroot_nice;
70371+int grsec_enable_chroot_execlog;
70372+int grsec_enable_chroot_caps;
70373+int grsec_enable_chroot_sysctl;
70374+int grsec_enable_chroot_unix;
70375+int grsec_enable_tpe;
70376+kgid_t grsec_tpe_gid;
70377+int grsec_enable_blackhole;
70378+#ifdef CONFIG_IPV6_MODULE
70379+EXPORT_SYMBOL(grsec_enable_blackhole);
70380+#endif
70381+int grsec_lastack_retries;
70382+int grsec_enable_tpe_all;
70383+int grsec_enable_tpe_invert;
70384+int grsec_enable_socket_all;
70385+kgid_t grsec_socket_all_gid;
70386+int grsec_enable_socket_client;
70387+kgid_t grsec_socket_client_gid;
70388+int grsec_enable_socket_server;
70389+kgid_t grsec_socket_server_gid;
70390+int grsec_resource_logging;
70391+int grsec_disable_privio;
70392+int grsec_enable_log_rwxmaps;
70393+int grsec_lock;
70394+
70395+DEFINE_SPINLOCK(grsec_alert_lock);
70396+unsigned long grsec_alert_wtime = 0;
70397+unsigned long grsec_alert_fyet = 0;
70398+
70399+DEFINE_SPINLOCK(grsec_audit_lock);
70400+
70401+DEFINE_RWLOCK(grsec_exec_file_lock);
70402+
70403+char *gr_shared_page[4];
70404+
70405+char *gr_alert_log_fmt;
70406+char *gr_audit_log_fmt;
70407+char *gr_alert_log_buf;
70408+char *gr_audit_log_buf;
70409+
70410+void __init
70411+grsecurity_init(void)
70412+{
70413+ int j;
70414+ /* create the per-cpu shared pages */
70415+
70416+#ifdef CONFIG_X86
70417+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
70418+#endif
70419+
70420+ for (j = 0; j < 4; j++) {
70421+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
70422+ if (gr_shared_page[j] == NULL) {
70423+ panic("Unable to allocate grsecurity shared page");
70424+ return;
70425+ }
70426+ }
70427+
70428+ /* allocate log buffers */
70429+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
70430+ if (!gr_alert_log_fmt) {
70431+ panic("Unable to allocate grsecurity alert log format buffer");
70432+ return;
70433+ }
70434+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
70435+ if (!gr_audit_log_fmt) {
70436+ panic("Unable to allocate grsecurity audit log format buffer");
70437+ return;
70438+ }
70439+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70440+ if (!gr_alert_log_buf) {
70441+ panic("Unable to allocate grsecurity alert log buffer");
70442+ return;
70443+ }
70444+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70445+ if (!gr_audit_log_buf) {
70446+ panic("Unable to allocate grsecurity audit log buffer");
70447+ return;
70448+ }
70449+
70450+#ifdef CONFIG_GRKERNSEC_IO
70451+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
70452+ grsec_disable_privio = 1;
70453+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70454+ grsec_disable_privio = 1;
70455+#else
70456+ grsec_disable_privio = 0;
70457+#endif
70458+#endif
70459+
70460+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
70461+ /* for backward compatibility, tpe_invert always defaults to on if
70462+ enabled in the kernel
70463+ */
70464+ grsec_enable_tpe_invert = 1;
70465+#endif
70466+
70467+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70468+#ifndef CONFIG_GRKERNSEC_SYSCTL
70469+ grsec_lock = 1;
70470+#endif
70471+
70472+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70473+ grsec_enable_log_rwxmaps = 1;
70474+#endif
70475+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
70476+ grsec_enable_group = 1;
70477+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
70478+#endif
70479+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70480+ grsec_enable_ptrace_readexec = 1;
70481+#endif
70482+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70483+ grsec_enable_chdir = 1;
70484+#endif
70485+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
70486+ grsec_enable_harden_ptrace = 1;
70487+#endif
70488+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
70489+ grsec_enable_harden_ipc = 1;
70490+#endif
70491+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70492+ grsec_enable_mount = 1;
70493+#endif
70494+#ifdef CONFIG_GRKERNSEC_LINK
70495+ grsec_enable_link = 1;
70496+#endif
70497+#ifdef CONFIG_GRKERNSEC_BRUTE
70498+ grsec_enable_brute = 1;
70499+#endif
70500+#ifdef CONFIG_GRKERNSEC_DMESG
70501+ grsec_enable_dmesg = 1;
70502+#endif
70503+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70504+ grsec_enable_blackhole = 1;
70505+ grsec_lastack_retries = 4;
70506+#endif
70507+#ifdef CONFIG_GRKERNSEC_FIFO
70508+ grsec_enable_fifo = 1;
70509+#endif
70510+#ifdef CONFIG_GRKERNSEC_EXECLOG
70511+ grsec_enable_execlog = 1;
70512+#endif
70513+#ifdef CONFIG_GRKERNSEC_SETXID
70514+ grsec_enable_setxid = 1;
70515+#endif
70516+#ifdef CONFIG_GRKERNSEC_SIGNAL
70517+ grsec_enable_signal = 1;
70518+#endif
70519+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70520+ grsec_enable_forkfail = 1;
70521+#endif
70522+#ifdef CONFIG_GRKERNSEC_TIME
70523+ grsec_enable_time = 1;
70524+#endif
70525+#ifdef CONFIG_GRKERNSEC_RESLOG
70526+ grsec_resource_logging = 1;
70527+#endif
70528+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70529+ grsec_enable_chroot_findtask = 1;
70530+#endif
70531+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70532+ grsec_enable_chroot_unix = 1;
70533+#endif
70534+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70535+ grsec_enable_chroot_mount = 1;
70536+#endif
70537+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70538+ grsec_enable_chroot_fchdir = 1;
70539+#endif
70540+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70541+ grsec_enable_chroot_shmat = 1;
70542+#endif
70543+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70544+ grsec_enable_audit_ptrace = 1;
70545+#endif
70546+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70547+ grsec_enable_chroot_double = 1;
70548+#endif
70549+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70550+ grsec_enable_chroot_pivot = 1;
70551+#endif
70552+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70553+ grsec_enable_chroot_chdir = 1;
70554+#endif
70555+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70556+ grsec_enable_chroot_chmod = 1;
70557+#endif
70558+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70559+ grsec_enable_chroot_mknod = 1;
70560+#endif
70561+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70562+ grsec_enable_chroot_nice = 1;
70563+#endif
70564+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70565+ grsec_enable_chroot_execlog = 1;
70566+#endif
70567+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70568+ grsec_enable_chroot_caps = 1;
70569+#endif
70570+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70571+ grsec_enable_chroot_sysctl = 1;
70572+#endif
70573+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70574+ grsec_enable_symlinkown = 1;
70575+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
70576+#endif
70577+#ifdef CONFIG_GRKERNSEC_TPE
70578+ grsec_enable_tpe = 1;
70579+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
70580+#ifdef CONFIG_GRKERNSEC_TPE_ALL
70581+ grsec_enable_tpe_all = 1;
70582+#endif
70583+#endif
70584+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70585+ grsec_enable_socket_all = 1;
70586+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
70587+#endif
70588+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70589+ grsec_enable_socket_client = 1;
70590+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
70591+#endif
70592+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70593+ grsec_enable_socket_server = 1;
70594+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
70595+#endif
70596+#endif
70597+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
70598+ grsec_deny_new_usb = 1;
70599+#endif
70600+
70601+ return;
70602+}
70603diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
70604new file mode 100644
70605index 0000000..f365de0
70606--- /dev/null
70607+++ b/grsecurity/grsec_ipc.c
70608@@ -0,0 +1,22 @@
70609+#include <linux/kernel.h>
70610+#include <linux/mm.h>
70611+#include <linux/sched.h>
70612+#include <linux/file.h>
70613+#include <linux/ipc.h>
70614+#include <linux/ipc_namespace.h>
70615+#include <linux/grsecurity.h>
70616+#include <linux/grinternal.h>
70617+
70618+int
70619+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
70620+{
70621+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
70622+ int write = (requested_mode & 00002);
70623+
70624+ if (grsec_enable_harden_ipc && !(requested_mode & ~granted_mode & 0007) && !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
70625+ gr_log_str2_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", write ? "writ" : "read", GR_GLOBAL_UID(ipcp->cuid));
70626+ return 0;
70627+ }
70628+#endif
70629+ return 1;
70630+}
70631diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
70632new file mode 100644
70633index 0000000..5e05e20
70634--- /dev/null
70635+++ b/grsecurity/grsec_link.c
70636@@ -0,0 +1,58 @@
70637+#include <linux/kernel.h>
70638+#include <linux/sched.h>
70639+#include <linux/fs.h>
70640+#include <linux/file.h>
70641+#include <linux/grinternal.h>
70642+
70643+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
70644+{
70645+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70646+ const struct inode *link_inode = link->dentry->d_inode;
70647+
70648+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
70649+ /* ignore root-owned links, e.g. /proc/self */
70650+ gr_is_global_nonroot(link_inode->i_uid) && target &&
70651+ !uid_eq(link_inode->i_uid, target->i_uid)) {
70652+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
70653+ return 1;
70654+ }
70655+#endif
70656+ return 0;
70657+}
70658+
70659+int
70660+gr_handle_follow_link(const struct inode *parent,
70661+ const struct inode *inode,
70662+ const struct dentry *dentry, const struct vfsmount *mnt)
70663+{
70664+#ifdef CONFIG_GRKERNSEC_LINK
70665+ const struct cred *cred = current_cred();
70666+
70667+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
70668+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
70669+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
70670+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
70671+ return -EACCES;
70672+ }
70673+#endif
70674+ return 0;
70675+}
70676+
70677+int
70678+gr_handle_hardlink(const struct dentry *dentry,
70679+ const struct vfsmount *mnt,
70680+ struct inode *inode, const int mode, const struct filename *to)
70681+{
70682+#ifdef CONFIG_GRKERNSEC_LINK
70683+ const struct cred *cred = current_cred();
70684+
70685+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
70686+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
70687+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
70688+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
70689+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
70690+ return -EPERM;
70691+ }
70692+#endif
70693+ return 0;
70694+}
70695diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
70696new file mode 100644
70697index 0000000..dbe0a6b
70698--- /dev/null
70699+++ b/grsecurity/grsec_log.c
70700@@ -0,0 +1,341 @@
70701+#include <linux/kernel.h>
70702+#include <linux/sched.h>
70703+#include <linux/file.h>
70704+#include <linux/tty.h>
70705+#include <linux/fs.h>
70706+#include <linux/mm.h>
70707+#include <linux/grinternal.h>
70708+
70709+#ifdef CONFIG_TREE_PREEMPT_RCU
70710+#define DISABLE_PREEMPT() preempt_disable()
70711+#define ENABLE_PREEMPT() preempt_enable()
70712+#else
70713+#define DISABLE_PREEMPT()
70714+#define ENABLE_PREEMPT()
70715+#endif
70716+
70717+#define BEGIN_LOCKS(x) \
70718+ DISABLE_PREEMPT(); \
70719+ rcu_read_lock(); \
70720+ read_lock(&tasklist_lock); \
70721+ read_lock(&grsec_exec_file_lock); \
70722+ if (x != GR_DO_AUDIT) \
70723+ spin_lock(&grsec_alert_lock); \
70724+ else \
70725+ spin_lock(&grsec_audit_lock)
70726+
70727+#define END_LOCKS(x) \
70728+ if (x != GR_DO_AUDIT) \
70729+ spin_unlock(&grsec_alert_lock); \
70730+ else \
70731+ spin_unlock(&grsec_audit_lock); \
70732+ read_unlock(&grsec_exec_file_lock); \
70733+ read_unlock(&tasklist_lock); \
70734+ rcu_read_unlock(); \
70735+ ENABLE_PREEMPT(); \
70736+ if (x == GR_DONT_AUDIT) \
70737+ gr_handle_alertkill(current)
70738+
70739+enum {
70740+ FLOODING,
70741+ NO_FLOODING
70742+};
70743+
70744+extern char *gr_alert_log_fmt;
70745+extern char *gr_audit_log_fmt;
70746+extern char *gr_alert_log_buf;
70747+extern char *gr_audit_log_buf;
70748+
70749+static int gr_log_start(int audit)
70750+{
70751+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
70752+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
70753+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70754+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
70755+ unsigned long curr_secs = get_seconds();
70756+
70757+ if (audit == GR_DO_AUDIT)
70758+ goto set_fmt;
70759+
70760+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
70761+ grsec_alert_wtime = curr_secs;
70762+ grsec_alert_fyet = 0;
70763+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
70764+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
70765+ grsec_alert_fyet++;
70766+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
70767+ grsec_alert_wtime = curr_secs;
70768+ grsec_alert_fyet++;
70769+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
70770+ return FLOODING;
70771+ }
70772+ else return FLOODING;
70773+
70774+set_fmt:
70775+#endif
70776+ memset(buf, 0, PAGE_SIZE);
70777+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
70778+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
70779+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70780+ } else if (current->signal->curr_ip) {
70781+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
70782+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
70783+ } else if (gr_acl_is_enabled()) {
70784+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
70785+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70786+ } else {
70787+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
70788+ strcpy(buf, fmt);
70789+ }
70790+
70791+ return NO_FLOODING;
70792+}
70793+
70794+static void gr_log_middle(int audit, const char *msg, va_list ap)
70795+ __attribute__ ((format (printf, 2, 0)));
70796+
70797+static void gr_log_middle(int audit, const char *msg, va_list ap)
70798+{
70799+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70800+ unsigned int len = strlen(buf);
70801+
70802+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70803+
70804+ return;
70805+}
70806+
70807+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70808+ __attribute__ ((format (printf, 2, 3)));
70809+
70810+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70811+{
70812+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70813+ unsigned int len = strlen(buf);
70814+ va_list ap;
70815+
70816+ va_start(ap, msg);
70817+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70818+ va_end(ap);
70819+
70820+ return;
70821+}
70822+
70823+static void gr_log_end(int audit, int append_default)
70824+{
70825+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70826+ if (append_default) {
70827+ struct task_struct *task = current;
70828+ struct task_struct *parent = task->real_parent;
70829+ const struct cred *cred = __task_cred(task);
70830+ const struct cred *pcred = __task_cred(parent);
70831+ unsigned int len = strlen(buf);
70832+
70833+ 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));
70834+ }
70835+
70836+ printk("%s\n", buf);
70837+
70838+ return;
70839+}
70840+
70841+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
70842+{
70843+ int logtype;
70844+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
70845+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
70846+ void *voidptr = NULL;
70847+ int num1 = 0, num2 = 0;
70848+ unsigned long ulong1 = 0, ulong2 = 0;
70849+ struct dentry *dentry = NULL;
70850+ struct vfsmount *mnt = NULL;
70851+ struct file *file = NULL;
70852+ struct task_struct *task = NULL;
70853+ struct vm_area_struct *vma = NULL;
70854+ const struct cred *cred, *pcred;
70855+ va_list ap;
70856+
70857+ BEGIN_LOCKS(audit);
70858+ logtype = gr_log_start(audit);
70859+ if (logtype == FLOODING) {
70860+ END_LOCKS(audit);
70861+ return;
70862+ }
70863+ va_start(ap, argtypes);
70864+ switch (argtypes) {
70865+ case GR_TTYSNIFF:
70866+ task = va_arg(ap, struct task_struct *);
70867+ 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));
70868+ break;
70869+ case GR_SYSCTL_HIDDEN:
70870+ str1 = va_arg(ap, char *);
70871+ gr_log_middle_varargs(audit, msg, result, str1);
70872+ break;
70873+ case GR_RBAC:
70874+ dentry = va_arg(ap, struct dentry *);
70875+ mnt = va_arg(ap, struct vfsmount *);
70876+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
70877+ break;
70878+ case GR_RBAC_STR:
70879+ dentry = va_arg(ap, struct dentry *);
70880+ mnt = va_arg(ap, struct vfsmount *);
70881+ str1 = va_arg(ap, char *);
70882+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
70883+ break;
70884+ case GR_STR_RBAC:
70885+ str1 = va_arg(ap, char *);
70886+ dentry = va_arg(ap, struct dentry *);
70887+ mnt = va_arg(ap, struct vfsmount *);
70888+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
70889+ break;
70890+ case GR_RBAC_MODE2:
70891+ dentry = va_arg(ap, struct dentry *);
70892+ mnt = va_arg(ap, struct vfsmount *);
70893+ str1 = va_arg(ap, char *);
70894+ str2 = va_arg(ap, char *);
70895+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
70896+ break;
70897+ case GR_RBAC_MODE3:
70898+ dentry = va_arg(ap, struct dentry *);
70899+ mnt = va_arg(ap, struct vfsmount *);
70900+ str1 = va_arg(ap, char *);
70901+ str2 = va_arg(ap, char *);
70902+ str3 = va_arg(ap, char *);
70903+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
70904+ break;
70905+ case GR_FILENAME:
70906+ dentry = va_arg(ap, struct dentry *);
70907+ mnt = va_arg(ap, struct vfsmount *);
70908+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
70909+ break;
70910+ case GR_STR_FILENAME:
70911+ str1 = va_arg(ap, char *);
70912+ dentry = va_arg(ap, struct dentry *);
70913+ mnt = va_arg(ap, struct vfsmount *);
70914+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70915+ break;
70916+ case GR_FILENAME_STR:
70917+ dentry = va_arg(ap, struct dentry *);
70918+ mnt = va_arg(ap, struct vfsmount *);
70919+ str1 = va_arg(ap, char *);
70920+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70921+ break;
70922+ case GR_FILENAME_TWO_INT:
70923+ dentry = va_arg(ap, struct dentry *);
70924+ mnt = va_arg(ap, struct vfsmount *);
70925+ num1 = va_arg(ap, int);
70926+ num2 = va_arg(ap, int);
70927+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70928+ break;
70929+ case GR_FILENAME_TWO_INT_STR:
70930+ dentry = va_arg(ap, struct dentry *);
70931+ mnt = va_arg(ap, struct vfsmount *);
70932+ num1 = va_arg(ap, int);
70933+ num2 = va_arg(ap, int);
70934+ str1 = va_arg(ap, char *);
70935+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70936+ break;
70937+ case GR_TEXTREL:
70938+ file = va_arg(ap, struct file *);
70939+ ulong1 = va_arg(ap, unsigned long);
70940+ ulong2 = va_arg(ap, unsigned long);
70941+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70942+ break;
70943+ case GR_PTRACE:
70944+ task = va_arg(ap, struct task_struct *);
70945+ 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));
70946+ break;
70947+ case GR_RESOURCE:
70948+ task = va_arg(ap, struct task_struct *);
70949+ cred = __task_cred(task);
70950+ pcred = __task_cred(task->real_parent);
70951+ ulong1 = va_arg(ap, unsigned long);
70952+ str1 = va_arg(ap, char *);
70953+ ulong2 = va_arg(ap, unsigned long);
70954+ 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));
70955+ break;
70956+ case GR_CAP:
70957+ task = va_arg(ap, struct task_struct *);
70958+ cred = __task_cred(task);
70959+ pcred = __task_cred(task->real_parent);
70960+ str1 = va_arg(ap, char *);
70961+ 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));
70962+ break;
70963+ case GR_SIG:
70964+ str1 = va_arg(ap, char *);
70965+ voidptr = va_arg(ap, void *);
70966+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70967+ break;
70968+ case GR_SIG2:
70969+ task = va_arg(ap, struct task_struct *);
70970+ cred = __task_cred(task);
70971+ pcred = __task_cred(task->real_parent);
70972+ num1 = va_arg(ap, int);
70973+ 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));
70974+ break;
70975+ case GR_CRASH1:
70976+ task = va_arg(ap, struct task_struct *);
70977+ cred = __task_cred(task);
70978+ pcred = __task_cred(task->real_parent);
70979+ ulong1 = va_arg(ap, unsigned long);
70980+ 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);
70981+ break;
70982+ case GR_CRASH2:
70983+ task = va_arg(ap, struct task_struct *);
70984+ cred = __task_cred(task);
70985+ pcred = __task_cred(task->real_parent);
70986+ ulong1 = va_arg(ap, unsigned long);
70987+ 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);
70988+ break;
70989+ case GR_RWXMAP:
70990+ file = va_arg(ap, struct file *);
70991+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70992+ break;
70993+ case GR_RWXMAPVMA:
70994+ vma = va_arg(ap, struct vm_area_struct *);
70995+ if (vma->vm_file)
70996+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70997+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70998+ str1 = "<stack>";
70999+ else if (vma->vm_start <= current->mm->brk &&
71000+ vma->vm_end >= current->mm->start_brk)
71001+ str1 = "<heap>";
71002+ else
71003+ str1 = "<anonymous mapping>";
71004+ gr_log_middle_varargs(audit, msg, str1);
71005+ break;
71006+ case GR_PSACCT:
71007+ {
71008+ unsigned int wday, cday;
71009+ __u8 whr, chr;
71010+ __u8 wmin, cmin;
71011+ __u8 wsec, csec;
71012+ char cur_tty[64] = { 0 };
71013+ char parent_tty[64] = { 0 };
71014+
71015+ task = va_arg(ap, struct task_struct *);
71016+ wday = va_arg(ap, unsigned int);
71017+ cday = va_arg(ap, unsigned int);
71018+ whr = va_arg(ap, int);
71019+ chr = va_arg(ap, int);
71020+ wmin = va_arg(ap, int);
71021+ cmin = va_arg(ap, int);
71022+ wsec = va_arg(ap, int);
71023+ csec = va_arg(ap, int);
71024+ ulong1 = va_arg(ap, unsigned long);
71025+ cred = __task_cred(task);
71026+ pcred = __task_cred(task->real_parent);
71027+
71028+ 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));
71029+ }
71030+ break;
71031+ default:
71032+ gr_log_middle(audit, msg, ap);
71033+ }
71034+ va_end(ap);
71035+ // these don't need DEFAULTSECARGS printed on the end
71036+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
71037+ gr_log_end(audit, 0);
71038+ else
71039+ gr_log_end(audit, 1);
71040+ END_LOCKS(audit);
71041+}
71042diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
71043new file mode 100644
71044index 0000000..f536303
71045--- /dev/null
71046+++ b/grsecurity/grsec_mem.c
71047@@ -0,0 +1,40 @@
71048+#include <linux/kernel.h>
71049+#include <linux/sched.h>
71050+#include <linux/mm.h>
71051+#include <linux/mman.h>
71052+#include <linux/grinternal.h>
71053+
71054+void
71055+gr_handle_ioperm(void)
71056+{
71057+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
71058+ return;
71059+}
71060+
71061+void
71062+gr_handle_iopl(void)
71063+{
71064+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
71065+ return;
71066+}
71067+
71068+void
71069+gr_handle_mem_readwrite(u64 from, u64 to)
71070+{
71071+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
71072+ return;
71073+}
71074+
71075+void
71076+gr_handle_vm86(void)
71077+{
71078+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
71079+ return;
71080+}
71081+
71082+void
71083+gr_log_badprocpid(const char *entry)
71084+{
71085+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
71086+ return;
71087+}
71088diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
71089new file mode 100644
71090index 0000000..2131422
71091--- /dev/null
71092+++ b/grsecurity/grsec_mount.c
71093@@ -0,0 +1,62 @@
71094+#include <linux/kernel.h>
71095+#include <linux/sched.h>
71096+#include <linux/mount.h>
71097+#include <linux/grsecurity.h>
71098+#include <linux/grinternal.h>
71099+
71100+void
71101+gr_log_remount(const char *devname, const int retval)
71102+{
71103+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71104+ if (grsec_enable_mount && (retval >= 0))
71105+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
71106+#endif
71107+ return;
71108+}
71109+
71110+void
71111+gr_log_unmount(const char *devname, const int retval)
71112+{
71113+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71114+ if (grsec_enable_mount && (retval >= 0))
71115+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
71116+#endif
71117+ return;
71118+}
71119+
71120+void
71121+gr_log_mount(const char *from, const char *to, const int retval)
71122+{
71123+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71124+ if (grsec_enable_mount && (retval >= 0))
71125+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
71126+#endif
71127+ return;
71128+}
71129+
71130+int
71131+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
71132+{
71133+#ifdef CONFIG_GRKERNSEC_ROFS
71134+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
71135+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
71136+ return -EPERM;
71137+ } else
71138+ return 0;
71139+#endif
71140+ return 0;
71141+}
71142+
71143+int
71144+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
71145+{
71146+#ifdef CONFIG_GRKERNSEC_ROFS
71147+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
71148+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
71149+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
71150+ return -EPERM;
71151+ } else
71152+ return 0;
71153+#endif
71154+ return 0;
71155+}
71156diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
71157new file mode 100644
71158index 0000000..6ee9d50
71159--- /dev/null
71160+++ b/grsecurity/grsec_pax.c
71161@@ -0,0 +1,45 @@
71162+#include <linux/kernel.h>
71163+#include <linux/sched.h>
71164+#include <linux/mm.h>
71165+#include <linux/file.h>
71166+#include <linux/grinternal.h>
71167+#include <linux/grsecurity.h>
71168+
71169+void
71170+gr_log_textrel(struct vm_area_struct * vma)
71171+{
71172+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71173+ if (grsec_enable_log_rwxmaps)
71174+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
71175+#endif
71176+ return;
71177+}
71178+
71179+void gr_log_ptgnustack(struct file *file)
71180+{
71181+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71182+ if (grsec_enable_log_rwxmaps)
71183+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
71184+#endif
71185+ return;
71186+}
71187+
71188+void
71189+gr_log_rwxmmap(struct file *file)
71190+{
71191+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71192+ if (grsec_enable_log_rwxmaps)
71193+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
71194+#endif
71195+ return;
71196+}
71197+
71198+void
71199+gr_log_rwxmprotect(struct vm_area_struct *vma)
71200+{
71201+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71202+ if (grsec_enable_log_rwxmaps)
71203+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
71204+#endif
71205+ return;
71206+}
71207diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
71208new file mode 100644
71209index 0000000..f7f29aa
71210--- /dev/null
71211+++ b/grsecurity/grsec_ptrace.c
71212@@ -0,0 +1,30 @@
71213+#include <linux/kernel.h>
71214+#include <linux/sched.h>
71215+#include <linux/grinternal.h>
71216+#include <linux/security.h>
71217+
71218+void
71219+gr_audit_ptrace(struct task_struct *task)
71220+{
71221+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71222+ if (grsec_enable_audit_ptrace)
71223+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
71224+#endif
71225+ return;
71226+}
71227+
71228+int
71229+gr_ptrace_readexec(struct file *file, int unsafe_flags)
71230+{
71231+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71232+ const struct dentry *dentry = file->f_path.dentry;
71233+ const struct vfsmount *mnt = file->f_path.mnt;
71234+
71235+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
71236+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
71237+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
71238+ return -EACCES;
71239+ }
71240+#endif
71241+ return 0;
71242+}
71243diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
71244new file mode 100644
71245index 0000000..4e29cc7
71246--- /dev/null
71247+++ b/grsecurity/grsec_sig.c
71248@@ -0,0 +1,246 @@
71249+#include <linux/kernel.h>
71250+#include <linux/sched.h>
71251+#include <linux/fs.h>
71252+#include <linux/delay.h>
71253+#include <linux/grsecurity.h>
71254+#include <linux/grinternal.h>
71255+#include <linux/hardirq.h>
71256+
71257+char *signames[] = {
71258+ [SIGSEGV] = "Segmentation fault",
71259+ [SIGILL] = "Illegal instruction",
71260+ [SIGABRT] = "Abort",
71261+ [SIGBUS] = "Invalid alignment/Bus error"
71262+};
71263+
71264+void
71265+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
71266+{
71267+#ifdef CONFIG_GRKERNSEC_SIGNAL
71268+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
71269+ (sig == SIGABRT) || (sig == SIGBUS))) {
71270+ if (task_pid_nr(t) == task_pid_nr(current)) {
71271+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
71272+ } else {
71273+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
71274+ }
71275+ }
71276+#endif
71277+ return;
71278+}
71279+
71280+int
71281+gr_handle_signal(const struct task_struct *p, const int sig)
71282+{
71283+#ifdef CONFIG_GRKERNSEC
71284+ /* ignore the 0 signal for protected task checks */
71285+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
71286+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
71287+ return -EPERM;
71288+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
71289+ return -EPERM;
71290+ }
71291+#endif
71292+ return 0;
71293+}
71294+
71295+#ifdef CONFIG_GRKERNSEC
71296+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
71297+
71298+int gr_fake_force_sig(int sig, struct task_struct *t)
71299+{
71300+ unsigned long int flags;
71301+ int ret, blocked, ignored;
71302+ struct k_sigaction *action;
71303+
71304+ spin_lock_irqsave(&t->sighand->siglock, flags);
71305+ action = &t->sighand->action[sig-1];
71306+ ignored = action->sa.sa_handler == SIG_IGN;
71307+ blocked = sigismember(&t->blocked, sig);
71308+ if (blocked || ignored) {
71309+ action->sa.sa_handler = SIG_DFL;
71310+ if (blocked) {
71311+ sigdelset(&t->blocked, sig);
71312+ recalc_sigpending_and_wake(t);
71313+ }
71314+ }
71315+ if (action->sa.sa_handler == SIG_DFL)
71316+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
71317+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
71318+
71319+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
71320+
71321+ return ret;
71322+}
71323+#endif
71324+
71325+#ifdef CONFIG_GRKERNSEC_BRUTE
71326+#define GR_USER_BAN_TIME (15 * 60)
71327+#define GR_DAEMON_BRUTE_TIME (30 * 60)
71328+
71329+static int __get_dumpable(unsigned long mm_flags)
71330+{
71331+ int ret;
71332+
71333+ ret = mm_flags & MMF_DUMPABLE_MASK;
71334+ return (ret >= 2) ? 2 : ret;
71335+}
71336+#endif
71337+
71338+void gr_handle_brute_attach(unsigned long mm_flags)
71339+{
71340+#ifdef CONFIG_GRKERNSEC_BRUTE
71341+ struct task_struct *p = current;
71342+ kuid_t uid = GLOBAL_ROOT_UID;
71343+ int daemon = 0;
71344+
71345+ if (!grsec_enable_brute)
71346+ return;
71347+
71348+ rcu_read_lock();
71349+ read_lock(&tasklist_lock);
71350+ read_lock(&grsec_exec_file_lock);
71351+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
71352+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
71353+ p->real_parent->brute = 1;
71354+ daemon = 1;
71355+ } else {
71356+ const struct cred *cred = __task_cred(p), *cred2;
71357+ struct task_struct *tsk, *tsk2;
71358+
71359+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
71360+ struct user_struct *user;
71361+
71362+ uid = cred->uid;
71363+
71364+ /* this is put upon execution past expiration */
71365+ user = find_user(uid);
71366+ if (user == NULL)
71367+ goto unlock;
71368+ user->suid_banned = 1;
71369+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
71370+ if (user->suid_ban_expires == ~0UL)
71371+ user->suid_ban_expires--;
71372+
71373+ /* only kill other threads of the same binary, from the same user */
71374+ do_each_thread(tsk2, tsk) {
71375+ cred2 = __task_cred(tsk);
71376+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
71377+ gr_fake_force_sig(SIGKILL, tsk);
71378+ } while_each_thread(tsk2, tsk);
71379+ }
71380+ }
71381+unlock:
71382+ read_unlock(&grsec_exec_file_lock);
71383+ read_unlock(&tasklist_lock);
71384+ rcu_read_unlock();
71385+
71386+ if (gr_is_global_nonroot(uid))
71387+ 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);
71388+ else if (daemon)
71389+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
71390+
71391+#endif
71392+ return;
71393+}
71394+
71395+void gr_handle_brute_check(void)
71396+{
71397+#ifdef CONFIG_GRKERNSEC_BRUTE
71398+ struct task_struct *p = current;
71399+
71400+ if (unlikely(p->brute)) {
71401+ if (!grsec_enable_brute)
71402+ p->brute = 0;
71403+ else if (time_before(get_seconds(), p->brute_expires))
71404+ msleep(30 * 1000);
71405+ }
71406+#endif
71407+ return;
71408+}
71409+
71410+void gr_handle_kernel_exploit(void)
71411+{
71412+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71413+ const struct cred *cred;
71414+ struct task_struct *tsk, *tsk2;
71415+ struct user_struct *user;
71416+ kuid_t uid;
71417+
71418+ if (in_irq() || in_serving_softirq() || in_nmi())
71419+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
71420+
71421+ uid = current_uid();
71422+
71423+ if (gr_is_global_root(uid))
71424+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
71425+ else {
71426+ /* kill all the processes of this user, hold a reference
71427+ to their creds struct, and prevent them from creating
71428+ another process until system reset
71429+ */
71430+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
71431+ GR_GLOBAL_UID(uid));
71432+ /* we intentionally leak this ref */
71433+ user = get_uid(current->cred->user);
71434+ if (user)
71435+ user->kernel_banned = 1;
71436+
71437+ /* kill all processes of this user */
71438+ read_lock(&tasklist_lock);
71439+ do_each_thread(tsk2, tsk) {
71440+ cred = __task_cred(tsk);
71441+ if (uid_eq(cred->uid, uid))
71442+ gr_fake_force_sig(SIGKILL, tsk);
71443+ } while_each_thread(tsk2, tsk);
71444+ read_unlock(&tasklist_lock);
71445+ }
71446+#endif
71447+}
71448+
71449+#ifdef CONFIG_GRKERNSEC_BRUTE
71450+static bool suid_ban_expired(struct user_struct *user)
71451+{
71452+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
71453+ user->suid_banned = 0;
71454+ user->suid_ban_expires = 0;
71455+ free_uid(user);
71456+ return true;
71457+ }
71458+
71459+ return false;
71460+}
71461+#endif
71462+
71463+int gr_process_kernel_exec_ban(void)
71464+{
71465+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71466+ if (unlikely(current->cred->user->kernel_banned))
71467+ return -EPERM;
71468+#endif
71469+ return 0;
71470+}
71471+
71472+int gr_process_kernel_setuid_ban(struct user_struct *user)
71473+{
71474+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71475+ if (unlikely(user->kernel_banned))
71476+ gr_fake_force_sig(SIGKILL, current);
71477+#endif
71478+ return 0;
71479+}
71480+
71481+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
71482+{
71483+#ifdef CONFIG_GRKERNSEC_BRUTE
71484+ struct user_struct *user = current->cred->user;
71485+ if (unlikely(user->suid_banned)) {
71486+ if (suid_ban_expired(user))
71487+ return 0;
71488+ /* disallow execution of suid binaries only */
71489+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
71490+ return -EPERM;
71491+ }
71492+#endif
71493+ return 0;
71494+}
71495diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
71496new file mode 100644
71497index 0000000..4030d57
71498--- /dev/null
71499+++ b/grsecurity/grsec_sock.c
71500@@ -0,0 +1,244 @@
71501+#include <linux/kernel.h>
71502+#include <linux/module.h>
71503+#include <linux/sched.h>
71504+#include <linux/file.h>
71505+#include <linux/net.h>
71506+#include <linux/in.h>
71507+#include <linux/ip.h>
71508+#include <net/sock.h>
71509+#include <net/inet_sock.h>
71510+#include <linux/grsecurity.h>
71511+#include <linux/grinternal.h>
71512+#include <linux/gracl.h>
71513+
71514+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
71515+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
71516+
71517+EXPORT_SYMBOL(gr_search_udp_recvmsg);
71518+EXPORT_SYMBOL(gr_search_udp_sendmsg);
71519+
71520+#ifdef CONFIG_UNIX_MODULE
71521+EXPORT_SYMBOL(gr_acl_handle_unix);
71522+EXPORT_SYMBOL(gr_acl_handle_mknod);
71523+EXPORT_SYMBOL(gr_handle_chroot_unix);
71524+EXPORT_SYMBOL(gr_handle_create);
71525+#endif
71526+
71527+#ifdef CONFIG_GRKERNSEC
71528+#define gr_conn_table_size 32749
71529+struct conn_table_entry {
71530+ struct conn_table_entry *next;
71531+ struct signal_struct *sig;
71532+};
71533+
71534+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
71535+DEFINE_SPINLOCK(gr_conn_table_lock);
71536+
71537+extern const char * gr_socktype_to_name(unsigned char type);
71538+extern const char * gr_proto_to_name(unsigned char proto);
71539+extern const char * gr_sockfamily_to_name(unsigned char family);
71540+
71541+static __inline__ int
71542+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
71543+{
71544+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
71545+}
71546+
71547+static __inline__ int
71548+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
71549+ __u16 sport, __u16 dport)
71550+{
71551+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
71552+ sig->gr_sport == sport && sig->gr_dport == dport))
71553+ return 1;
71554+ else
71555+ return 0;
71556+}
71557+
71558+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
71559+{
71560+ struct conn_table_entry **match;
71561+ unsigned int index;
71562+
71563+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71564+ sig->gr_sport, sig->gr_dport,
71565+ gr_conn_table_size);
71566+
71567+ newent->sig = sig;
71568+
71569+ match = &gr_conn_table[index];
71570+ newent->next = *match;
71571+ *match = newent;
71572+
71573+ return;
71574+}
71575+
71576+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
71577+{
71578+ struct conn_table_entry *match, *last = NULL;
71579+ unsigned int index;
71580+
71581+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71582+ sig->gr_sport, sig->gr_dport,
71583+ gr_conn_table_size);
71584+
71585+ match = gr_conn_table[index];
71586+ while (match && !conn_match(match->sig,
71587+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
71588+ sig->gr_dport)) {
71589+ last = match;
71590+ match = match->next;
71591+ }
71592+
71593+ if (match) {
71594+ if (last)
71595+ last->next = match->next;
71596+ else
71597+ gr_conn_table[index] = NULL;
71598+ kfree(match);
71599+ }
71600+
71601+ return;
71602+}
71603+
71604+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
71605+ __u16 sport, __u16 dport)
71606+{
71607+ struct conn_table_entry *match;
71608+ unsigned int index;
71609+
71610+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
71611+
71612+ match = gr_conn_table[index];
71613+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
71614+ match = match->next;
71615+
71616+ if (match)
71617+ return match->sig;
71618+ else
71619+ return NULL;
71620+}
71621+
71622+#endif
71623+
71624+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
71625+{
71626+#ifdef CONFIG_GRKERNSEC
71627+ struct signal_struct *sig = task->signal;
71628+ struct conn_table_entry *newent;
71629+
71630+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
71631+ if (newent == NULL)
71632+ return;
71633+ /* no bh lock needed since we are called with bh disabled */
71634+ spin_lock(&gr_conn_table_lock);
71635+ gr_del_task_from_ip_table_nolock(sig);
71636+ sig->gr_saddr = inet->inet_rcv_saddr;
71637+ sig->gr_daddr = inet->inet_daddr;
71638+ sig->gr_sport = inet->inet_sport;
71639+ sig->gr_dport = inet->inet_dport;
71640+ gr_add_to_task_ip_table_nolock(sig, newent);
71641+ spin_unlock(&gr_conn_table_lock);
71642+#endif
71643+ return;
71644+}
71645+
71646+void gr_del_task_from_ip_table(struct task_struct *task)
71647+{
71648+#ifdef CONFIG_GRKERNSEC
71649+ spin_lock_bh(&gr_conn_table_lock);
71650+ gr_del_task_from_ip_table_nolock(task->signal);
71651+ spin_unlock_bh(&gr_conn_table_lock);
71652+#endif
71653+ return;
71654+}
71655+
71656+void
71657+gr_attach_curr_ip(const struct sock *sk)
71658+{
71659+#ifdef CONFIG_GRKERNSEC
71660+ struct signal_struct *p, *set;
71661+ const struct inet_sock *inet = inet_sk(sk);
71662+
71663+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
71664+ return;
71665+
71666+ set = current->signal;
71667+
71668+ spin_lock_bh(&gr_conn_table_lock);
71669+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
71670+ inet->inet_dport, inet->inet_sport);
71671+ if (unlikely(p != NULL)) {
71672+ set->curr_ip = p->curr_ip;
71673+ set->used_accept = 1;
71674+ gr_del_task_from_ip_table_nolock(p);
71675+ spin_unlock_bh(&gr_conn_table_lock);
71676+ return;
71677+ }
71678+ spin_unlock_bh(&gr_conn_table_lock);
71679+
71680+ set->curr_ip = inet->inet_daddr;
71681+ set->used_accept = 1;
71682+#endif
71683+ return;
71684+}
71685+
71686+int
71687+gr_handle_sock_all(const int family, const int type, const int protocol)
71688+{
71689+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71690+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
71691+ (family != AF_UNIX)) {
71692+ if (family == AF_INET)
71693+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
71694+ else
71695+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
71696+ return -EACCES;
71697+ }
71698+#endif
71699+ return 0;
71700+}
71701+
71702+int
71703+gr_handle_sock_server(const struct sockaddr *sck)
71704+{
71705+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71706+ if (grsec_enable_socket_server &&
71707+ in_group_p(grsec_socket_server_gid) &&
71708+ sck && (sck->sa_family != AF_UNIX) &&
71709+ (sck->sa_family != AF_LOCAL)) {
71710+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
71711+ return -EACCES;
71712+ }
71713+#endif
71714+ return 0;
71715+}
71716+
71717+int
71718+gr_handle_sock_server_other(const struct sock *sck)
71719+{
71720+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71721+ if (grsec_enable_socket_server &&
71722+ in_group_p(grsec_socket_server_gid) &&
71723+ sck && (sck->sk_family != AF_UNIX) &&
71724+ (sck->sk_family != AF_LOCAL)) {
71725+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
71726+ return -EACCES;
71727+ }
71728+#endif
71729+ return 0;
71730+}
71731+
71732+int
71733+gr_handle_sock_client(const struct sockaddr *sck)
71734+{
71735+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71736+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
71737+ sck && (sck->sa_family != AF_UNIX) &&
71738+ (sck->sa_family != AF_LOCAL)) {
71739+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
71740+ return -EACCES;
71741+ }
71742+#endif
71743+ return 0;
71744+}
71745diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
71746new file mode 100644
71747index 0000000..8159888
71748--- /dev/null
71749+++ b/grsecurity/grsec_sysctl.c
71750@@ -0,0 +1,479 @@
71751+#include <linux/kernel.h>
71752+#include <linux/sched.h>
71753+#include <linux/sysctl.h>
71754+#include <linux/grsecurity.h>
71755+#include <linux/grinternal.h>
71756+
71757+int
71758+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
71759+{
71760+#ifdef CONFIG_GRKERNSEC_SYSCTL
71761+ if (dirname == NULL || name == NULL)
71762+ return 0;
71763+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
71764+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
71765+ return -EACCES;
71766+ }
71767+#endif
71768+ return 0;
71769+}
71770+
71771+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
71772+static int __maybe_unused __read_only one = 1;
71773+#endif
71774+
71775+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
71776+ defined(CONFIG_GRKERNSEC_DENYUSB)
71777+struct ctl_table grsecurity_table[] = {
71778+#ifdef CONFIG_GRKERNSEC_SYSCTL
71779+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
71780+#ifdef CONFIG_GRKERNSEC_IO
71781+ {
71782+ .procname = "disable_priv_io",
71783+ .data = &grsec_disable_privio,
71784+ .maxlen = sizeof(int),
71785+ .mode = 0600,
71786+ .proc_handler = &proc_dointvec,
71787+ },
71788+#endif
71789+#endif
71790+#ifdef CONFIG_GRKERNSEC_LINK
71791+ {
71792+ .procname = "linking_restrictions",
71793+ .data = &grsec_enable_link,
71794+ .maxlen = sizeof(int),
71795+ .mode = 0600,
71796+ .proc_handler = &proc_dointvec,
71797+ },
71798+#endif
71799+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71800+ {
71801+ .procname = "enforce_symlinksifowner",
71802+ .data = &grsec_enable_symlinkown,
71803+ .maxlen = sizeof(int),
71804+ .mode = 0600,
71805+ .proc_handler = &proc_dointvec,
71806+ },
71807+ {
71808+ .procname = "symlinkown_gid",
71809+ .data = &grsec_symlinkown_gid,
71810+ .maxlen = sizeof(int),
71811+ .mode = 0600,
71812+ .proc_handler = &proc_dointvec,
71813+ },
71814+#endif
71815+#ifdef CONFIG_GRKERNSEC_BRUTE
71816+ {
71817+ .procname = "deter_bruteforce",
71818+ .data = &grsec_enable_brute,
71819+ .maxlen = sizeof(int),
71820+ .mode = 0600,
71821+ .proc_handler = &proc_dointvec,
71822+ },
71823+#endif
71824+#ifdef CONFIG_GRKERNSEC_FIFO
71825+ {
71826+ .procname = "fifo_restrictions",
71827+ .data = &grsec_enable_fifo,
71828+ .maxlen = sizeof(int),
71829+ .mode = 0600,
71830+ .proc_handler = &proc_dointvec,
71831+ },
71832+#endif
71833+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71834+ {
71835+ .procname = "ptrace_readexec",
71836+ .data = &grsec_enable_ptrace_readexec,
71837+ .maxlen = sizeof(int),
71838+ .mode = 0600,
71839+ .proc_handler = &proc_dointvec,
71840+ },
71841+#endif
71842+#ifdef CONFIG_GRKERNSEC_SETXID
71843+ {
71844+ .procname = "consistent_setxid",
71845+ .data = &grsec_enable_setxid,
71846+ .maxlen = sizeof(int),
71847+ .mode = 0600,
71848+ .proc_handler = &proc_dointvec,
71849+ },
71850+#endif
71851+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71852+ {
71853+ .procname = "ip_blackhole",
71854+ .data = &grsec_enable_blackhole,
71855+ .maxlen = sizeof(int),
71856+ .mode = 0600,
71857+ .proc_handler = &proc_dointvec,
71858+ },
71859+ {
71860+ .procname = "lastack_retries",
71861+ .data = &grsec_lastack_retries,
71862+ .maxlen = sizeof(int),
71863+ .mode = 0600,
71864+ .proc_handler = &proc_dointvec,
71865+ },
71866+#endif
71867+#ifdef CONFIG_GRKERNSEC_EXECLOG
71868+ {
71869+ .procname = "exec_logging",
71870+ .data = &grsec_enable_execlog,
71871+ .maxlen = sizeof(int),
71872+ .mode = 0600,
71873+ .proc_handler = &proc_dointvec,
71874+ },
71875+#endif
71876+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71877+ {
71878+ .procname = "rwxmap_logging",
71879+ .data = &grsec_enable_log_rwxmaps,
71880+ .maxlen = sizeof(int),
71881+ .mode = 0600,
71882+ .proc_handler = &proc_dointvec,
71883+ },
71884+#endif
71885+#ifdef CONFIG_GRKERNSEC_SIGNAL
71886+ {
71887+ .procname = "signal_logging",
71888+ .data = &grsec_enable_signal,
71889+ .maxlen = sizeof(int),
71890+ .mode = 0600,
71891+ .proc_handler = &proc_dointvec,
71892+ },
71893+#endif
71894+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71895+ {
71896+ .procname = "forkfail_logging",
71897+ .data = &grsec_enable_forkfail,
71898+ .maxlen = sizeof(int),
71899+ .mode = 0600,
71900+ .proc_handler = &proc_dointvec,
71901+ },
71902+#endif
71903+#ifdef CONFIG_GRKERNSEC_TIME
71904+ {
71905+ .procname = "timechange_logging",
71906+ .data = &grsec_enable_time,
71907+ .maxlen = sizeof(int),
71908+ .mode = 0600,
71909+ .proc_handler = &proc_dointvec,
71910+ },
71911+#endif
71912+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71913+ {
71914+ .procname = "chroot_deny_shmat",
71915+ .data = &grsec_enable_chroot_shmat,
71916+ .maxlen = sizeof(int),
71917+ .mode = 0600,
71918+ .proc_handler = &proc_dointvec,
71919+ },
71920+#endif
71921+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71922+ {
71923+ .procname = "chroot_deny_unix",
71924+ .data = &grsec_enable_chroot_unix,
71925+ .maxlen = sizeof(int),
71926+ .mode = 0600,
71927+ .proc_handler = &proc_dointvec,
71928+ },
71929+#endif
71930+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71931+ {
71932+ .procname = "chroot_deny_mount",
71933+ .data = &grsec_enable_chroot_mount,
71934+ .maxlen = sizeof(int),
71935+ .mode = 0600,
71936+ .proc_handler = &proc_dointvec,
71937+ },
71938+#endif
71939+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71940+ {
71941+ .procname = "chroot_deny_fchdir",
71942+ .data = &grsec_enable_chroot_fchdir,
71943+ .maxlen = sizeof(int),
71944+ .mode = 0600,
71945+ .proc_handler = &proc_dointvec,
71946+ },
71947+#endif
71948+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71949+ {
71950+ .procname = "chroot_deny_chroot",
71951+ .data = &grsec_enable_chroot_double,
71952+ .maxlen = sizeof(int),
71953+ .mode = 0600,
71954+ .proc_handler = &proc_dointvec,
71955+ },
71956+#endif
71957+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71958+ {
71959+ .procname = "chroot_deny_pivot",
71960+ .data = &grsec_enable_chroot_pivot,
71961+ .maxlen = sizeof(int),
71962+ .mode = 0600,
71963+ .proc_handler = &proc_dointvec,
71964+ },
71965+#endif
71966+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71967+ {
71968+ .procname = "chroot_enforce_chdir",
71969+ .data = &grsec_enable_chroot_chdir,
71970+ .maxlen = sizeof(int),
71971+ .mode = 0600,
71972+ .proc_handler = &proc_dointvec,
71973+ },
71974+#endif
71975+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71976+ {
71977+ .procname = "chroot_deny_chmod",
71978+ .data = &grsec_enable_chroot_chmod,
71979+ .maxlen = sizeof(int),
71980+ .mode = 0600,
71981+ .proc_handler = &proc_dointvec,
71982+ },
71983+#endif
71984+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71985+ {
71986+ .procname = "chroot_deny_mknod",
71987+ .data = &grsec_enable_chroot_mknod,
71988+ .maxlen = sizeof(int),
71989+ .mode = 0600,
71990+ .proc_handler = &proc_dointvec,
71991+ },
71992+#endif
71993+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71994+ {
71995+ .procname = "chroot_restrict_nice",
71996+ .data = &grsec_enable_chroot_nice,
71997+ .maxlen = sizeof(int),
71998+ .mode = 0600,
71999+ .proc_handler = &proc_dointvec,
72000+ },
72001+#endif
72002+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72003+ {
72004+ .procname = "chroot_execlog",
72005+ .data = &grsec_enable_chroot_execlog,
72006+ .maxlen = sizeof(int),
72007+ .mode = 0600,
72008+ .proc_handler = &proc_dointvec,
72009+ },
72010+#endif
72011+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72012+ {
72013+ .procname = "chroot_caps",
72014+ .data = &grsec_enable_chroot_caps,
72015+ .maxlen = sizeof(int),
72016+ .mode = 0600,
72017+ .proc_handler = &proc_dointvec,
72018+ },
72019+#endif
72020+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72021+ {
72022+ .procname = "chroot_deny_sysctl",
72023+ .data = &grsec_enable_chroot_sysctl,
72024+ .maxlen = sizeof(int),
72025+ .mode = 0600,
72026+ .proc_handler = &proc_dointvec,
72027+ },
72028+#endif
72029+#ifdef CONFIG_GRKERNSEC_TPE
72030+ {
72031+ .procname = "tpe",
72032+ .data = &grsec_enable_tpe,
72033+ .maxlen = sizeof(int),
72034+ .mode = 0600,
72035+ .proc_handler = &proc_dointvec,
72036+ },
72037+ {
72038+ .procname = "tpe_gid",
72039+ .data = &grsec_tpe_gid,
72040+ .maxlen = sizeof(int),
72041+ .mode = 0600,
72042+ .proc_handler = &proc_dointvec,
72043+ },
72044+#endif
72045+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72046+ {
72047+ .procname = "tpe_invert",
72048+ .data = &grsec_enable_tpe_invert,
72049+ .maxlen = sizeof(int),
72050+ .mode = 0600,
72051+ .proc_handler = &proc_dointvec,
72052+ },
72053+#endif
72054+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72055+ {
72056+ .procname = "tpe_restrict_all",
72057+ .data = &grsec_enable_tpe_all,
72058+ .maxlen = sizeof(int),
72059+ .mode = 0600,
72060+ .proc_handler = &proc_dointvec,
72061+ },
72062+#endif
72063+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72064+ {
72065+ .procname = "socket_all",
72066+ .data = &grsec_enable_socket_all,
72067+ .maxlen = sizeof(int),
72068+ .mode = 0600,
72069+ .proc_handler = &proc_dointvec,
72070+ },
72071+ {
72072+ .procname = "socket_all_gid",
72073+ .data = &grsec_socket_all_gid,
72074+ .maxlen = sizeof(int),
72075+ .mode = 0600,
72076+ .proc_handler = &proc_dointvec,
72077+ },
72078+#endif
72079+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72080+ {
72081+ .procname = "socket_client",
72082+ .data = &grsec_enable_socket_client,
72083+ .maxlen = sizeof(int),
72084+ .mode = 0600,
72085+ .proc_handler = &proc_dointvec,
72086+ },
72087+ {
72088+ .procname = "socket_client_gid",
72089+ .data = &grsec_socket_client_gid,
72090+ .maxlen = sizeof(int),
72091+ .mode = 0600,
72092+ .proc_handler = &proc_dointvec,
72093+ },
72094+#endif
72095+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72096+ {
72097+ .procname = "socket_server",
72098+ .data = &grsec_enable_socket_server,
72099+ .maxlen = sizeof(int),
72100+ .mode = 0600,
72101+ .proc_handler = &proc_dointvec,
72102+ },
72103+ {
72104+ .procname = "socket_server_gid",
72105+ .data = &grsec_socket_server_gid,
72106+ .maxlen = sizeof(int),
72107+ .mode = 0600,
72108+ .proc_handler = &proc_dointvec,
72109+ },
72110+#endif
72111+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72112+ {
72113+ .procname = "audit_group",
72114+ .data = &grsec_enable_group,
72115+ .maxlen = sizeof(int),
72116+ .mode = 0600,
72117+ .proc_handler = &proc_dointvec,
72118+ },
72119+ {
72120+ .procname = "audit_gid",
72121+ .data = &grsec_audit_gid,
72122+ .maxlen = sizeof(int),
72123+ .mode = 0600,
72124+ .proc_handler = &proc_dointvec,
72125+ },
72126+#endif
72127+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72128+ {
72129+ .procname = "audit_chdir",
72130+ .data = &grsec_enable_chdir,
72131+ .maxlen = sizeof(int),
72132+ .mode = 0600,
72133+ .proc_handler = &proc_dointvec,
72134+ },
72135+#endif
72136+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72137+ {
72138+ .procname = "audit_mount",
72139+ .data = &grsec_enable_mount,
72140+ .maxlen = sizeof(int),
72141+ .mode = 0600,
72142+ .proc_handler = &proc_dointvec,
72143+ },
72144+#endif
72145+#ifdef CONFIG_GRKERNSEC_DMESG
72146+ {
72147+ .procname = "dmesg",
72148+ .data = &grsec_enable_dmesg,
72149+ .maxlen = sizeof(int),
72150+ .mode = 0600,
72151+ .proc_handler = &proc_dointvec,
72152+ },
72153+#endif
72154+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72155+ {
72156+ .procname = "chroot_findtask",
72157+ .data = &grsec_enable_chroot_findtask,
72158+ .maxlen = sizeof(int),
72159+ .mode = 0600,
72160+ .proc_handler = &proc_dointvec,
72161+ },
72162+#endif
72163+#ifdef CONFIG_GRKERNSEC_RESLOG
72164+ {
72165+ .procname = "resource_logging",
72166+ .data = &grsec_resource_logging,
72167+ .maxlen = sizeof(int),
72168+ .mode = 0600,
72169+ .proc_handler = &proc_dointvec,
72170+ },
72171+#endif
72172+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72173+ {
72174+ .procname = "audit_ptrace",
72175+ .data = &grsec_enable_audit_ptrace,
72176+ .maxlen = sizeof(int),
72177+ .mode = 0600,
72178+ .proc_handler = &proc_dointvec,
72179+ },
72180+#endif
72181+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72182+ {
72183+ .procname = "harden_ptrace",
72184+ .data = &grsec_enable_harden_ptrace,
72185+ .maxlen = sizeof(int),
72186+ .mode = 0600,
72187+ .proc_handler = &proc_dointvec,
72188+ },
72189+#endif
72190+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
72191+ {
72192+ .procname = "harden_ipc",
72193+ .data = &grsec_enable_harden_ipc,
72194+ .maxlen = sizeof(int),
72195+ .mode = 0600,
72196+ .proc_handler = &proc_dointvec,
72197+ },
72198+#endif
72199+ {
72200+ .procname = "grsec_lock",
72201+ .data = &grsec_lock,
72202+ .maxlen = sizeof(int),
72203+ .mode = 0600,
72204+ .proc_handler = &proc_dointvec,
72205+ },
72206+#endif
72207+#ifdef CONFIG_GRKERNSEC_ROFS
72208+ {
72209+ .procname = "romount_protect",
72210+ .data = &grsec_enable_rofs,
72211+ .maxlen = sizeof(int),
72212+ .mode = 0600,
72213+ .proc_handler = &proc_dointvec_minmax,
72214+ .extra1 = &one,
72215+ .extra2 = &one,
72216+ },
72217+#endif
72218+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
72219+ {
72220+ .procname = "deny_new_usb",
72221+ .data = &grsec_deny_new_usb,
72222+ .maxlen = sizeof(int),
72223+ .mode = 0600,
72224+ .proc_handler = &proc_dointvec,
72225+ },
72226+#endif
72227+ { }
72228+};
72229+#endif
72230diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
72231new file mode 100644
72232index 0000000..0dc13c3
72233--- /dev/null
72234+++ b/grsecurity/grsec_time.c
72235@@ -0,0 +1,16 @@
72236+#include <linux/kernel.h>
72237+#include <linux/sched.h>
72238+#include <linux/grinternal.h>
72239+#include <linux/module.h>
72240+
72241+void
72242+gr_log_timechange(void)
72243+{
72244+#ifdef CONFIG_GRKERNSEC_TIME
72245+ if (grsec_enable_time)
72246+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
72247+#endif
72248+ return;
72249+}
72250+
72251+EXPORT_SYMBOL(gr_log_timechange);
72252diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
72253new file mode 100644
72254index 0000000..ee57dcf
72255--- /dev/null
72256+++ b/grsecurity/grsec_tpe.c
72257@@ -0,0 +1,73 @@
72258+#include <linux/kernel.h>
72259+#include <linux/sched.h>
72260+#include <linux/file.h>
72261+#include <linux/fs.h>
72262+#include <linux/grinternal.h>
72263+
72264+extern int gr_acl_tpe_check(void);
72265+
72266+int
72267+gr_tpe_allow(const struct file *file)
72268+{
72269+#ifdef CONFIG_GRKERNSEC
72270+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
72271+ const struct cred *cred = current_cred();
72272+ char *msg = NULL;
72273+ char *msg2 = NULL;
72274+
72275+ // never restrict root
72276+ if (gr_is_global_root(cred->uid))
72277+ return 1;
72278+
72279+ if (grsec_enable_tpe) {
72280+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72281+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
72282+ msg = "not being in trusted group";
72283+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
72284+ msg = "being in untrusted group";
72285+#else
72286+ if (in_group_p(grsec_tpe_gid))
72287+ msg = "being in untrusted group";
72288+#endif
72289+ }
72290+ if (!msg && gr_acl_tpe_check())
72291+ msg = "being in untrusted role";
72292+
72293+ // not in any affected group/role
72294+ if (!msg)
72295+ goto next_check;
72296+
72297+ if (gr_is_global_nonroot(inode->i_uid))
72298+ msg2 = "file in non-root-owned directory";
72299+ else if (inode->i_mode & S_IWOTH)
72300+ msg2 = "file in world-writable directory";
72301+ else if (inode->i_mode & S_IWGRP)
72302+ msg2 = "file in group-writable directory";
72303+
72304+ if (msg && msg2) {
72305+ char fullmsg[70] = {0};
72306+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
72307+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
72308+ return 0;
72309+ }
72310+ msg = NULL;
72311+next_check:
72312+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72313+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
72314+ return 1;
72315+
72316+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
72317+ msg = "directory not owned by user";
72318+ else if (inode->i_mode & S_IWOTH)
72319+ msg = "file in world-writable directory";
72320+ else if (inode->i_mode & S_IWGRP)
72321+ msg = "file in group-writable directory";
72322+
72323+ if (msg) {
72324+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
72325+ return 0;
72326+ }
72327+#endif
72328+#endif
72329+ return 1;
72330+}
72331diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
72332new file mode 100644
72333index 0000000..ae02d8e
72334--- /dev/null
72335+++ b/grsecurity/grsec_usb.c
72336@@ -0,0 +1,15 @@
72337+#include <linux/kernel.h>
72338+#include <linux/grinternal.h>
72339+#include <linux/module.h>
72340+
72341+int gr_handle_new_usb(void)
72342+{
72343+#ifdef CONFIG_GRKERNSEC_DENYUSB
72344+ if (grsec_deny_new_usb) {
72345+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
72346+ return 1;
72347+ }
72348+#endif
72349+ return 0;
72350+}
72351+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
72352diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
72353new file mode 100644
72354index 0000000..9f7b1ac
72355--- /dev/null
72356+++ b/grsecurity/grsum.c
72357@@ -0,0 +1,61 @@
72358+#include <linux/err.h>
72359+#include <linux/kernel.h>
72360+#include <linux/sched.h>
72361+#include <linux/mm.h>
72362+#include <linux/scatterlist.h>
72363+#include <linux/crypto.h>
72364+#include <linux/gracl.h>
72365+
72366+
72367+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
72368+#error "crypto and sha256 must be built into the kernel"
72369+#endif
72370+
72371+int
72372+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
72373+{
72374+ char *p;
72375+ struct crypto_hash *tfm;
72376+ struct hash_desc desc;
72377+ struct scatterlist sg;
72378+ unsigned char temp_sum[GR_SHA_LEN];
72379+ volatile int retval = 0;
72380+ volatile int dummy = 0;
72381+ unsigned int i;
72382+
72383+ sg_init_table(&sg, 1);
72384+
72385+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
72386+ if (IS_ERR(tfm)) {
72387+ /* should never happen, since sha256 should be built in */
72388+ return 1;
72389+ }
72390+
72391+ desc.tfm = tfm;
72392+ desc.flags = 0;
72393+
72394+ crypto_hash_init(&desc);
72395+
72396+ p = salt;
72397+ sg_set_buf(&sg, p, GR_SALT_LEN);
72398+ crypto_hash_update(&desc, &sg, sg.length);
72399+
72400+ p = entry->pw;
72401+ sg_set_buf(&sg, p, strlen(p));
72402+
72403+ crypto_hash_update(&desc, &sg, sg.length);
72404+
72405+ crypto_hash_final(&desc, temp_sum);
72406+
72407+ memset(entry->pw, 0, GR_PW_LEN);
72408+
72409+ for (i = 0; i < GR_SHA_LEN; i++)
72410+ if (sum[i] != temp_sum[i])
72411+ retval = 1;
72412+ else
72413+ dummy = 1; // waste a cycle
72414+
72415+ crypto_free_hash(tfm);
72416+
72417+ return retval;
72418+}
72419diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
72420index 77ff547..181834f 100644
72421--- a/include/asm-generic/4level-fixup.h
72422+++ b/include/asm-generic/4level-fixup.h
72423@@ -13,8 +13,10 @@
72424 #define pmd_alloc(mm, pud, address) \
72425 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
72426 NULL: pmd_offset(pud, address))
72427+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
72428
72429 #define pud_alloc(mm, pgd, address) (pgd)
72430+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
72431 #define pud_offset(pgd, start) (pgd)
72432 #define pud_none(pud) 0
72433 #define pud_bad(pud) 0
72434diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
72435index b7babf0..04ad282 100644
72436--- a/include/asm-generic/atomic-long.h
72437+++ b/include/asm-generic/atomic-long.h
72438@@ -22,6 +22,12 @@
72439
72440 typedef atomic64_t atomic_long_t;
72441
72442+#ifdef CONFIG_PAX_REFCOUNT
72443+typedef atomic64_unchecked_t atomic_long_unchecked_t;
72444+#else
72445+typedef atomic64_t atomic_long_unchecked_t;
72446+#endif
72447+
72448 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
72449
72450 static inline long atomic_long_read(atomic_long_t *l)
72451@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72452 return (long)atomic64_read(v);
72453 }
72454
72455+#ifdef CONFIG_PAX_REFCOUNT
72456+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72457+{
72458+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72459+
72460+ return (long)atomic64_read_unchecked(v);
72461+}
72462+#endif
72463+
72464 static inline void atomic_long_set(atomic_long_t *l, long i)
72465 {
72466 atomic64_t *v = (atomic64_t *)l;
72467@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72468 atomic64_set(v, i);
72469 }
72470
72471+#ifdef CONFIG_PAX_REFCOUNT
72472+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72473+{
72474+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72475+
72476+ atomic64_set_unchecked(v, i);
72477+}
72478+#endif
72479+
72480 static inline void atomic_long_inc(atomic_long_t *l)
72481 {
72482 atomic64_t *v = (atomic64_t *)l;
72483@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72484 atomic64_inc(v);
72485 }
72486
72487+#ifdef CONFIG_PAX_REFCOUNT
72488+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72489+{
72490+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72491+
72492+ atomic64_inc_unchecked(v);
72493+}
72494+#endif
72495+
72496 static inline void atomic_long_dec(atomic_long_t *l)
72497 {
72498 atomic64_t *v = (atomic64_t *)l;
72499@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72500 atomic64_dec(v);
72501 }
72502
72503+#ifdef CONFIG_PAX_REFCOUNT
72504+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72505+{
72506+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72507+
72508+ atomic64_dec_unchecked(v);
72509+}
72510+#endif
72511+
72512 static inline void atomic_long_add(long i, atomic_long_t *l)
72513 {
72514 atomic64_t *v = (atomic64_t *)l;
72515@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72516 atomic64_add(i, v);
72517 }
72518
72519+#ifdef CONFIG_PAX_REFCOUNT
72520+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72521+{
72522+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72523+
72524+ atomic64_add_unchecked(i, v);
72525+}
72526+#endif
72527+
72528 static inline void atomic_long_sub(long i, atomic_long_t *l)
72529 {
72530 atomic64_t *v = (atomic64_t *)l;
72531@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
72532 atomic64_sub(i, v);
72533 }
72534
72535+#ifdef CONFIG_PAX_REFCOUNT
72536+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
72537+{
72538+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72539+
72540+ atomic64_sub_unchecked(i, v);
72541+}
72542+#endif
72543+
72544 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72545 {
72546 atomic64_t *v = (atomic64_t *)l;
72547@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
72548 return (long)atomic64_add_return(i, v);
72549 }
72550
72551+#ifdef CONFIG_PAX_REFCOUNT
72552+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
72553+{
72554+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72555+
72556+ return (long)atomic64_add_return_unchecked(i, v);
72557+}
72558+#endif
72559+
72560 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
72561 {
72562 atomic64_t *v = (atomic64_t *)l;
72563@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
72564 return (long)atomic64_inc_return(v);
72565 }
72566
72567+#ifdef CONFIG_PAX_REFCOUNT
72568+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
72569+{
72570+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72571+
72572+ return (long)atomic64_inc_return_unchecked(v);
72573+}
72574+#endif
72575+
72576 static inline long atomic_long_dec_return(atomic_long_t *l)
72577 {
72578 atomic64_t *v = (atomic64_t *)l;
72579@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
72580
72581 typedef atomic_t atomic_long_t;
72582
72583+#ifdef CONFIG_PAX_REFCOUNT
72584+typedef atomic_unchecked_t atomic_long_unchecked_t;
72585+#else
72586+typedef atomic_t atomic_long_unchecked_t;
72587+#endif
72588+
72589 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
72590 static inline long atomic_long_read(atomic_long_t *l)
72591 {
72592@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72593 return (long)atomic_read(v);
72594 }
72595
72596+#ifdef CONFIG_PAX_REFCOUNT
72597+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72598+{
72599+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72600+
72601+ return (long)atomic_read_unchecked(v);
72602+}
72603+#endif
72604+
72605 static inline void atomic_long_set(atomic_long_t *l, long i)
72606 {
72607 atomic_t *v = (atomic_t *)l;
72608@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72609 atomic_set(v, i);
72610 }
72611
72612+#ifdef CONFIG_PAX_REFCOUNT
72613+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72614+{
72615+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72616+
72617+ atomic_set_unchecked(v, i);
72618+}
72619+#endif
72620+
72621 static inline void atomic_long_inc(atomic_long_t *l)
72622 {
72623 atomic_t *v = (atomic_t *)l;
72624@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72625 atomic_inc(v);
72626 }
72627
72628+#ifdef CONFIG_PAX_REFCOUNT
72629+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72630+{
72631+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72632+
72633+ atomic_inc_unchecked(v);
72634+}
72635+#endif
72636+
72637 static inline void atomic_long_dec(atomic_long_t *l)
72638 {
72639 atomic_t *v = (atomic_t *)l;
72640@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72641 atomic_dec(v);
72642 }
72643
72644+#ifdef CONFIG_PAX_REFCOUNT
72645+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72646+{
72647+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72648+
72649+ atomic_dec_unchecked(v);
72650+}
72651+#endif
72652+
72653 static inline void atomic_long_add(long i, atomic_long_t *l)
72654 {
72655 atomic_t *v = (atomic_t *)l;
72656@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72657 atomic_add(i, v);
72658 }
72659
72660+#ifdef CONFIG_PAX_REFCOUNT
72661+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72662+{
72663+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72664+
72665+ atomic_add_unchecked(i, v);
72666+}
72667+#endif
72668+
72669 static inline void atomic_long_sub(long i, atomic_long_t *l)
72670 {
72671 atomic_t *v = (atomic_t *)l;
72672@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
72673 atomic_sub(i, v);
72674 }
72675
72676+#ifdef CONFIG_PAX_REFCOUNT
72677+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
72678+{
72679+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72680+
72681+ atomic_sub_unchecked(i, v);
72682+}
72683+#endif
72684+
72685 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72686 {
72687 atomic_t *v = (atomic_t *)l;
72688@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
72689 return (long)atomic_add_return(i, v);
72690 }
72691
72692+#ifdef CONFIG_PAX_REFCOUNT
72693+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
72694+{
72695+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72696+
72697+ return (long)atomic_add_return_unchecked(i, v);
72698+}
72699+
72700+#endif
72701+
72702 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
72703 {
72704 atomic_t *v = (atomic_t *)l;
72705@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
72706 return (long)atomic_inc_return(v);
72707 }
72708
72709+#ifdef CONFIG_PAX_REFCOUNT
72710+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
72711+{
72712+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72713+
72714+ return (long)atomic_inc_return_unchecked(v);
72715+}
72716+#endif
72717+
72718 static inline long atomic_long_dec_return(atomic_long_t *l)
72719 {
72720 atomic_t *v = (atomic_t *)l;
72721@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
72722
72723 #endif /* BITS_PER_LONG == 64 */
72724
72725+#ifdef CONFIG_PAX_REFCOUNT
72726+static inline void pax_refcount_needs_these_functions(void)
72727+{
72728+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
72729+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
72730+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
72731+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
72732+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
72733+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
72734+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
72735+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
72736+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
72737+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
72738+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
72739+#ifdef CONFIG_X86
72740+ atomic_clear_mask_unchecked(0, NULL);
72741+ atomic_set_mask_unchecked(0, NULL);
72742+#endif
72743+
72744+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
72745+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
72746+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
72747+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
72748+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
72749+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
72750+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
72751+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
72752+}
72753+#else
72754+#define atomic_read_unchecked(v) atomic_read(v)
72755+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
72756+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
72757+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
72758+#define atomic_inc_unchecked(v) atomic_inc(v)
72759+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
72760+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
72761+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
72762+#define atomic_dec_unchecked(v) atomic_dec(v)
72763+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
72764+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
72765+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
72766+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
72767+
72768+#define atomic_long_read_unchecked(v) atomic_long_read(v)
72769+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
72770+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
72771+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
72772+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
72773+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
72774+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
72775+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
72776+#endif
72777+
72778 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
72779diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
72780index 33bd2de..f31bff97 100644
72781--- a/include/asm-generic/atomic.h
72782+++ b/include/asm-generic/atomic.h
72783@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
72784 * Atomically clears the bits set in @mask from @v
72785 */
72786 #ifndef atomic_clear_mask
72787-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
72788+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
72789 {
72790 unsigned long flags;
72791
72792diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
72793index b18ce4f..2ee2843 100644
72794--- a/include/asm-generic/atomic64.h
72795+++ b/include/asm-generic/atomic64.h
72796@@ -16,6 +16,8 @@ typedef struct {
72797 long long counter;
72798 } atomic64_t;
72799
72800+typedef atomic64_t atomic64_unchecked_t;
72801+
72802 #define ATOMIC64_INIT(i) { (i) }
72803
72804 extern long long atomic64_read(const atomic64_t *v);
72805@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
72806 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
72807 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
72808
72809+#define atomic64_read_unchecked(v) atomic64_read(v)
72810+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
72811+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
72812+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
72813+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
72814+#define atomic64_inc_unchecked(v) atomic64_inc(v)
72815+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
72816+#define atomic64_dec_unchecked(v) atomic64_dec(v)
72817+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
72818+
72819 #endif /* _ASM_GENERIC_ATOMIC64_H */
72820diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
72821index 1bfcfe5..e04c5c9 100644
72822--- a/include/asm-generic/cache.h
72823+++ b/include/asm-generic/cache.h
72824@@ -6,7 +6,7 @@
72825 * cache lines need to provide their own cache.h.
72826 */
72827
72828-#define L1_CACHE_SHIFT 5
72829-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
72830+#define L1_CACHE_SHIFT 5UL
72831+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
72832
72833 #endif /* __ASM_GENERIC_CACHE_H */
72834diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
72835index 0d68a1e..b74a761 100644
72836--- a/include/asm-generic/emergency-restart.h
72837+++ b/include/asm-generic/emergency-restart.h
72838@@ -1,7 +1,7 @@
72839 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
72840 #define _ASM_GENERIC_EMERGENCY_RESTART_H
72841
72842-static inline void machine_emergency_restart(void)
72843+static inline __noreturn void machine_emergency_restart(void)
72844 {
72845 machine_restart(NULL);
72846 }
72847diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
72848index 90f99c7..00ce236 100644
72849--- a/include/asm-generic/kmap_types.h
72850+++ b/include/asm-generic/kmap_types.h
72851@@ -2,9 +2,9 @@
72852 #define _ASM_GENERIC_KMAP_TYPES_H
72853
72854 #ifdef __WITH_KM_FENCE
72855-# define KM_TYPE_NR 41
72856+# define KM_TYPE_NR 42
72857 #else
72858-# define KM_TYPE_NR 20
72859+# define KM_TYPE_NR 21
72860 #endif
72861
72862 #endif
72863diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
72864index 9ceb03b..62b0b8f 100644
72865--- a/include/asm-generic/local.h
72866+++ b/include/asm-generic/local.h
72867@@ -23,24 +23,37 @@ typedef struct
72868 atomic_long_t a;
72869 } local_t;
72870
72871+typedef struct {
72872+ atomic_long_unchecked_t a;
72873+} local_unchecked_t;
72874+
72875 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
72876
72877 #define local_read(l) atomic_long_read(&(l)->a)
72878+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
72879 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
72880+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
72881 #define local_inc(l) atomic_long_inc(&(l)->a)
72882+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
72883 #define local_dec(l) atomic_long_dec(&(l)->a)
72884+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
72885 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
72886+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
72887 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
72888+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
72889
72890 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
72891 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
72892 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
72893 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
72894 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
72895+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
72896 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
72897 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
72898+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
72899
72900 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72901+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72902 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
72903 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
72904 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
72905diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
72906index 725612b..9cc513a 100644
72907--- a/include/asm-generic/pgtable-nopmd.h
72908+++ b/include/asm-generic/pgtable-nopmd.h
72909@@ -1,14 +1,19 @@
72910 #ifndef _PGTABLE_NOPMD_H
72911 #define _PGTABLE_NOPMD_H
72912
72913-#ifndef __ASSEMBLY__
72914-
72915 #include <asm-generic/pgtable-nopud.h>
72916
72917-struct mm_struct;
72918-
72919 #define __PAGETABLE_PMD_FOLDED
72920
72921+#define PMD_SHIFT PUD_SHIFT
72922+#define PTRS_PER_PMD 1
72923+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72924+#define PMD_MASK (~(PMD_SIZE-1))
72925+
72926+#ifndef __ASSEMBLY__
72927+
72928+struct mm_struct;
72929+
72930 /*
72931 * Having the pmd type consist of a pud gets the size right, and allows
72932 * us to conceptually access the pud entry that this pmd is folded into
72933@@ -16,11 +21,6 @@ struct mm_struct;
72934 */
72935 typedef struct { pud_t pud; } pmd_t;
72936
72937-#define PMD_SHIFT PUD_SHIFT
72938-#define PTRS_PER_PMD 1
72939-#define PMD_SIZE (1UL << PMD_SHIFT)
72940-#define PMD_MASK (~(PMD_SIZE-1))
72941-
72942 /*
72943 * The "pud_xxx()" functions here are trivial for a folded two-level
72944 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72945diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72946index 810431d..0ec4804f 100644
72947--- a/include/asm-generic/pgtable-nopud.h
72948+++ b/include/asm-generic/pgtable-nopud.h
72949@@ -1,10 +1,15 @@
72950 #ifndef _PGTABLE_NOPUD_H
72951 #define _PGTABLE_NOPUD_H
72952
72953-#ifndef __ASSEMBLY__
72954-
72955 #define __PAGETABLE_PUD_FOLDED
72956
72957+#define PUD_SHIFT PGDIR_SHIFT
72958+#define PTRS_PER_PUD 1
72959+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72960+#define PUD_MASK (~(PUD_SIZE-1))
72961+
72962+#ifndef __ASSEMBLY__
72963+
72964 /*
72965 * Having the pud type consist of a pgd gets the size right, and allows
72966 * us to conceptually access the pgd entry that this pud is folded into
72967@@ -12,11 +17,6 @@
72968 */
72969 typedef struct { pgd_t pgd; } pud_t;
72970
72971-#define PUD_SHIFT PGDIR_SHIFT
72972-#define PTRS_PER_PUD 1
72973-#define PUD_SIZE (1UL << PUD_SHIFT)
72974-#define PUD_MASK (~(PUD_SIZE-1))
72975-
72976 /*
72977 * The "pgd_xxx()" functions here are trivial for a folded two-level
72978 * setup: the pud is never bad, and a pud always exists (as it's folded
72979@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72980 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72981
72982 #define pgd_populate(mm, pgd, pud) do { } while (0)
72983+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72984 /*
72985 * (puds are folded into pgds so this doesn't get actually called,
72986 * but the define is needed for a generic inline function.)
72987diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72988index f330d28..83ce28f 100644
72989--- a/include/asm-generic/pgtable.h
72990+++ b/include/asm-generic/pgtable.h
72991@@ -737,6 +737,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72992 }
72993 #endif /* CONFIG_NUMA_BALANCING */
72994
72995+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72996+#ifdef CONFIG_PAX_KERNEXEC
72997+#error KERNEXEC requires pax_open_kernel
72998+#else
72999+static inline unsigned long pax_open_kernel(void) { return 0; }
73000+#endif
73001+#endif
73002+
73003+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
73004+#ifdef CONFIG_PAX_KERNEXEC
73005+#error KERNEXEC requires pax_close_kernel
73006+#else
73007+static inline unsigned long pax_close_kernel(void) { return 0; }
73008+#endif
73009+#endif
73010+
73011 #endif /* CONFIG_MMU */
73012
73013 #endif /* !__ASSEMBLY__ */
73014diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
73015index dc1269c..48a4f51 100644
73016--- a/include/asm-generic/uaccess.h
73017+++ b/include/asm-generic/uaccess.h
73018@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
73019 return __clear_user(to, n);
73020 }
73021
73022+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
73023+#ifdef CONFIG_PAX_MEMORY_UDEREF
73024+#error UDEREF requires pax_open_userland
73025+#else
73026+static inline unsigned long pax_open_userland(void) { return 0; }
73027+#endif
73028+#endif
73029+
73030+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
73031+#ifdef CONFIG_PAX_MEMORY_UDEREF
73032+#error UDEREF requires pax_close_userland
73033+#else
73034+static inline unsigned long pax_close_userland(void) { return 0; }
73035+#endif
73036+#endif
73037+
73038 #endif /* __ASM_GENERIC_UACCESS_H */
73039diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
73040index 83e2c31..eeb4a04 100644
73041--- a/include/asm-generic/vmlinux.lds.h
73042+++ b/include/asm-generic/vmlinux.lds.h
73043@@ -232,6 +232,7 @@
73044 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
73045 VMLINUX_SYMBOL(__start_rodata) = .; \
73046 *(.rodata) *(.rodata.*) \
73047+ *(.data..read_only) \
73048 *(__vermagic) /* Kernel version magic */ \
73049 . = ALIGN(8); \
73050 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
73051@@ -715,17 +716,18 @@
73052 * section in the linker script will go there too. @phdr should have
73053 * a leading colon.
73054 *
73055- * Note that this macros defines __per_cpu_load as an absolute symbol.
73056+ * Note that this macros defines per_cpu_load as an absolute symbol.
73057 * If there is no need to put the percpu section at a predetermined
73058 * address, use PERCPU_SECTION.
73059 */
73060 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
73061- VMLINUX_SYMBOL(__per_cpu_load) = .; \
73062- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
73063+ per_cpu_load = .; \
73064+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
73065 - LOAD_OFFSET) { \
73066+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
73067 PERCPU_INPUT(cacheline) \
73068 } phdr \
73069- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
73070+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
73071
73072 /**
73073 * PERCPU_SECTION - define output section for percpu area, simple version
73074diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
73075index 418d270..bfd2794 100644
73076--- a/include/crypto/algapi.h
73077+++ b/include/crypto/algapi.h
73078@@ -34,7 +34,7 @@ struct crypto_type {
73079 unsigned int maskclear;
73080 unsigned int maskset;
73081 unsigned int tfmsize;
73082-};
73083+} __do_const;
73084
73085 struct crypto_instance {
73086 struct crypto_alg alg;
73087diff --git a/include/drm/drmP.h b/include/drm/drmP.h
73088index b46fb45..b30d6d5 100644
73089--- a/include/drm/drmP.h
73090+++ b/include/drm/drmP.h
73091@@ -66,6 +66,7 @@
73092 #include <linux/workqueue.h>
73093 #include <linux/poll.h>
73094 #include <asm/pgalloc.h>
73095+#include <asm/local.h>
73096 #include <drm/drm.h>
73097 #include <drm/drm_sarea.h>
73098 #include <drm/drm_vma_manager.h>
73099@@ -277,10 +278,12 @@ do { \
73100 * \param cmd command.
73101 * \param arg argument.
73102 */
73103-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
73104+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
73105+ struct drm_file *file_priv);
73106+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
73107 struct drm_file *file_priv);
73108
73109-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73110+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
73111 unsigned long arg);
73112
73113 #define DRM_IOCTL_NR(n) _IOC_NR(n)
73114@@ -296,10 +299,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73115 struct drm_ioctl_desc {
73116 unsigned int cmd;
73117 int flags;
73118- drm_ioctl_t *func;
73119+ drm_ioctl_t func;
73120 unsigned int cmd_drv;
73121 const char *name;
73122-};
73123+} __do_const;
73124
73125 /**
73126 * Creates a driver or general drm_ioctl_desc array entry for the given
73127@@ -1027,7 +1030,7 @@ struct drm_info_list {
73128 int (*show)(struct seq_file*, void*); /** show callback */
73129 u32 driver_features; /**< Required driver features for this entry */
73130 void *data;
73131-};
73132+} __do_const;
73133
73134 /**
73135 * debugfs node structure. This structure represents a debugfs file.
73136@@ -1098,7 +1101,7 @@ struct drm_device {
73137
73138 /** \name Usage Counters */
73139 /*@{ */
73140- int open_count; /**< Outstanding files open */
73141+ local_t open_count; /**< Outstanding files open */
73142 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
73143 atomic_t vma_count; /**< Outstanding vma areas open */
73144 int buf_use; /**< Buffers in use -- cannot alloc */
73145@@ -1109,7 +1112,7 @@ struct drm_device {
73146 /*@{ */
73147 unsigned long counters;
73148 enum drm_stat_type types[15];
73149- atomic_t counts[15];
73150+ atomic_unchecked_t counts[15];
73151 /*@} */
73152
73153 struct list_head filelist;
73154diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
73155index f43d556..94d9343 100644
73156--- a/include/drm/drm_crtc_helper.h
73157+++ b/include/drm/drm_crtc_helper.h
73158@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
73159 struct drm_connector *connector);
73160 /* disable encoder when not in use - more explicit than dpms off */
73161 void (*disable)(struct drm_encoder *encoder);
73162-};
73163+} __no_const;
73164
73165 /**
73166 * drm_connector_helper_funcs - helper operations for connectors
73167diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
73168index 8a10f5c..5de7f5c 100644
73169--- a/include/drm/i915_pciids.h
73170+++ b/include/drm/i915_pciids.h
73171@@ -37,7 +37,7 @@
73172 */
73173 #define INTEL_VGA_DEVICE(id, info) { \
73174 0x8086, id, \
73175- ~0, ~0, \
73176+ PCI_ANY_ID, PCI_ANY_ID, \
73177 0x030000, 0xff0000, \
73178 (unsigned long) info }
73179
73180diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
73181index 72dcbe8..8db58d7 100644
73182--- a/include/drm/ttm/ttm_memory.h
73183+++ b/include/drm/ttm/ttm_memory.h
73184@@ -48,7 +48,7 @@
73185
73186 struct ttm_mem_shrink {
73187 int (*do_shrink) (struct ttm_mem_shrink *);
73188-};
73189+} __no_const;
73190
73191 /**
73192 * struct ttm_mem_global - Global memory accounting structure.
73193diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
73194index 4b840e8..155d235 100644
73195--- a/include/keys/asymmetric-subtype.h
73196+++ b/include/keys/asymmetric-subtype.h
73197@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
73198 /* Verify the signature on a key of this subtype (optional) */
73199 int (*verify_signature)(const struct key *key,
73200 const struct public_key_signature *sig);
73201-};
73202+} __do_const;
73203
73204 /**
73205 * asymmetric_key_subtype - Get the subtype from an asymmetric key
73206diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
73207index c1da539..1dcec55 100644
73208--- a/include/linux/atmdev.h
73209+++ b/include/linux/atmdev.h
73210@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
73211 #endif
73212
73213 struct k_atm_aal_stats {
73214-#define __HANDLE_ITEM(i) atomic_t i
73215+#define __HANDLE_ITEM(i) atomic_unchecked_t i
73216 __AAL_STAT_ITEMS
73217 #undef __HANDLE_ITEM
73218 };
73219@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
73220 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
73221 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
73222 struct module *owner;
73223-};
73224+} __do_const ;
73225
73226 struct atmphy_ops {
73227 int (*start)(struct atm_dev *dev);
73228diff --git a/include/linux/audit.h b/include/linux/audit.h
73229index 729a4d1..9b304ae 100644
73230--- a/include/linux/audit.h
73231+++ b/include/linux/audit.h
73232@@ -193,7 +193,7 @@ static inline void audit_ptrace(struct task_struct *t)
73233 extern unsigned int audit_serial(void);
73234 extern int auditsc_get_stamp(struct audit_context *ctx,
73235 struct timespec *t, unsigned int *serial);
73236-extern int audit_set_loginuid(kuid_t loginuid);
73237+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
73238
73239 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
73240 {
73241diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
73242index 7554fd4..0f86379 100644
73243--- a/include/linux/binfmts.h
73244+++ b/include/linux/binfmts.h
73245@@ -73,8 +73,10 @@ struct linux_binfmt {
73246 int (*load_binary)(struct linux_binprm *);
73247 int (*load_shlib)(struct file *);
73248 int (*core_dump)(struct coredump_params *cprm);
73249+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
73250+ void (*handle_mmap)(struct file *);
73251 unsigned long min_coredump; /* minimal dump size */
73252-};
73253+} __do_const;
73254
73255 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
73256
73257diff --git a/include/linux/bitops.h b/include/linux/bitops.h
73258index a3b6b82..cd8f69c 100644
73259--- a/include/linux/bitops.h
73260+++ b/include/linux/bitops.h
73261@@ -91,7 +91,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
73262 * @word: value to rotate
73263 * @shift: bits to roll
73264 */
73265-static inline __u32 rol32(__u32 word, unsigned int shift)
73266+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
73267 {
73268 return (word << shift) | (word >> (32 - shift));
73269 }
73270@@ -101,7 +101,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
73271 * @word: value to rotate
73272 * @shift: bits to roll
73273 */
73274-static inline __u32 ror32(__u32 word, unsigned int shift)
73275+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
73276 {
73277 return (word >> shift) | (word << (32 - shift));
73278 }
73279diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
73280index 0e6f765..885bb2b 100644
73281--- a/include/linux/blkdev.h
73282+++ b/include/linux/blkdev.h
73283@@ -1537,7 +1537,7 @@ struct block_device_operations {
73284 /* this callback is with swap_lock and sometimes page table lock held */
73285 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
73286 struct module *owner;
73287-};
73288+} __do_const;
73289
73290 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
73291 unsigned long);
73292diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
73293index 7c2e030..b72475d 100644
73294--- a/include/linux/blktrace_api.h
73295+++ b/include/linux/blktrace_api.h
73296@@ -23,7 +23,7 @@ struct blk_trace {
73297 struct dentry *dir;
73298 struct dentry *dropped_file;
73299 struct dentry *msg_file;
73300- atomic_t dropped;
73301+ atomic_unchecked_t dropped;
73302 };
73303
73304 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
73305diff --git a/include/linux/cache.h b/include/linux/cache.h
73306index 4c57065..40346da 100644
73307--- a/include/linux/cache.h
73308+++ b/include/linux/cache.h
73309@@ -16,6 +16,14 @@
73310 #define __read_mostly
73311 #endif
73312
73313+#ifndef __read_only
73314+#ifdef CONFIG_PAX_KERNEXEC
73315+#error KERNEXEC requires __read_only
73316+#else
73317+#define __read_only __read_mostly
73318+#endif
73319+#endif
73320+
73321 #ifndef ____cacheline_aligned
73322 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
73323 #endif
73324diff --git a/include/linux/capability.h b/include/linux/capability.h
73325index a6ee1f9..e1ca49d 100644
73326--- a/include/linux/capability.h
73327+++ b/include/linux/capability.h
73328@@ -212,8 +212,13 @@ extern bool capable(int cap);
73329 extern bool ns_capable(struct user_namespace *ns, int cap);
73330 extern bool inode_capable(const struct inode *inode, int cap);
73331 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
73332+extern bool capable_nolog(int cap);
73333+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
73334+extern bool inode_capable_nolog(const struct inode *inode, int cap);
73335
73336 /* audit system wants to get cap info from files as well */
73337 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
73338
73339+extern int is_privileged_binary(const struct dentry *dentry);
73340+
73341 #endif /* !_LINUX_CAPABILITY_H */
73342diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
73343index 8609d57..86e4d79 100644
73344--- a/include/linux/cdrom.h
73345+++ b/include/linux/cdrom.h
73346@@ -87,7 +87,6 @@ struct cdrom_device_ops {
73347
73348 /* driver specifications */
73349 const int capability; /* capability flags */
73350- int n_minors; /* number of active minor devices */
73351 /* handle uniform packets for scsi type devices (scsi,atapi) */
73352 int (*generic_packet) (struct cdrom_device_info *,
73353 struct packet_command *);
73354diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
73355index 4ce9056..86caac6 100644
73356--- a/include/linux/cleancache.h
73357+++ b/include/linux/cleancache.h
73358@@ -31,7 +31,7 @@ struct cleancache_ops {
73359 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
73360 void (*invalidate_inode)(int, struct cleancache_filekey);
73361 void (*invalidate_fs)(int);
73362-};
73363+} __no_const;
73364
73365 extern struct cleancache_ops *
73366 cleancache_register_ops(struct cleancache_ops *ops);
73367diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
73368index 73bdb69..d66d47a 100644
73369--- a/include/linux/clk-provider.h
73370+++ b/include/linux/clk-provider.h
73371@@ -141,6 +141,7 @@ struct clk_ops {
73372 unsigned long);
73373 void (*init)(struct clk_hw *hw);
73374 };
73375+typedef struct clk_ops __no_const clk_ops_no_const;
73376
73377 /**
73378 * struct clk_init_data - holds init data that's common to all clocks and is
73379diff --git a/include/linux/compat.h b/include/linux/compat.h
73380index 345da00..b6eff26 100644
73381--- a/include/linux/compat.h
73382+++ b/include/linux/compat.h
73383@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
73384 compat_size_t __user *len_ptr);
73385
73386 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
73387-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
73388+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
73389 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
73390 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
73391 compat_ssize_t msgsz, int msgflg);
73392@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
73393 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
73394 compat_ulong_t addr, compat_ulong_t data);
73395 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73396- compat_long_t addr, compat_long_t data);
73397+ compat_ulong_t addr, compat_ulong_t data);
73398
73399 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
73400 /*
73401diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
73402index ded4299..da50e3b 100644
73403--- a/include/linux/compiler-gcc4.h
73404+++ b/include/linux/compiler-gcc4.h
73405@@ -39,9 +39,29 @@
73406 # define __compiletime_warning(message) __attribute__((warning(message)))
73407 # define __compiletime_error(message) __attribute__((error(message)))
73408 #endif /* __CHECKER__ */
73409+
73410+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
73411+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
73412+#define __bos0(ptr) __bos((ptr), 0)
73413+#define __bos1(ptr) __bos((ptr), 1)
73414 #endif /* GCC_VERSION >= 40300 */
73415
73416 #if GCC_VERSION >= 40500
73417+
73418+#ifdef CONSTIFY_PLUGIN
73419+#define __no_const __attribute__((no_const))
73420+#define __do_const __attribute__((do_const))
73421+#endif
73422+
73423+#ifdef SIZE_OVERFLOW_PLUGIN
73424+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
73425+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
73426+#endif
73427+
73428+#ifdef LATENT_ENTROPY_PLUGIN
73429+#define __latent_entropy __attribute__((latent_entropy))
73430+#endif
73431+
73432 /*
73433 * Mark a position in code as unreachable. This can be used to
73434 * suppress control flow warnings after asm blocks that transfer
73435diff --git a/include/linux/compiler.h b/include/linux/compiler.h
73436index 92669cd..1771a15 100644
73437--- a/include/linux/compiler.h
73438+++ b/include/linux/compiler.h
73439@@ -5,11 +5,14 @@
73440
73441 #ifdef __CHECKER__
73442 # define __user __attribute__((noderef, address_space(1)))
73443+# define __force_user __force __user
73444 # define __kernel __attribute__((address_space(0)))
73445+# define __force_kernel __force __kernel
73446 # define __safe __attribute__((safe))
73447 # define __force __attribute__((force))
73448 # define __nocast __attribute__((nocast))
73449 # define __iomem __attribute__((noderef, address_space(2)))
73450+# define __force_iomem __force __iomem
73451 # define __must_hold(x) __attribute__((context(x,1,1)))
73452 # define __acquires(x) __attribute__((context(x,0,1)))
73453 # define __releases(x) __attribute__((context(x,1,0)))
73454@@ -17,20 +20,37 @@
73455 # define __release(x) __context__(x,-1)
73456 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
73457 # define __percpu __attribute__((noderef, address_space(3)))
73458+# define __force_percpu __force __percpu
73459 #ifdef CONFIG_SPARSE_RCU_POINTER
73460 # define __rcu __attribute__((noderef, address_space(4)))
73461+# define __force_rcu __force __rcu
73462 #else
73463 # define __rcu
73464+# define __force_rcu
73465 #endif
73466 extern void __chk_user_ptr(const volatile void __user *);
73467 extern void __chk_io_ptr(const volatile void __iomem *);
73468 #else
73469-# define __user
73470-# define __kernel
73471+# ifdef CHECKER_PLUGIN
73472+//# define __user
73473+//# define __force_user
73474+//# define __kernel
73475+//# define __force_kernel
73476+# else
73477+# ifdef STRUCTLEAK_PLUGIN
73478+# define __user __attribute__((user))
73479+# else
73480+# define __user
73481+# endif
73482+# define __force_user
73483+# define __kernel
73484+# define __force_kernel
73485+# endif
73486 # define __safe
73487 # define __force
73488 # define __nocast
73489 # define __iomem
73490+# define __force_iomem
73491 # define __chk_user_ptr(x) (void)0
73492 # define __chk_io_ptr(x) (void)0
73493 # define __builtin_warning(x, y...) (1)
73494@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
73495 # define __release(x) (void)0
73496 # define __cond_lock(x,c) (c)
73497 # define __percpu
73498+# define __force_percpu
73499 # define __rcu
73500+# define __force_rcu
73501 #endif
73502
73503 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
73504@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73505 # define __attribute_const__ /* unimplemented */
73506 #endif
73507
73508+#ifndef __no_const
73509+# define __no_const
73510+#endif
73511+
73512+#ifndef __do_const
73513+# define __do_const
73514+#endif
73515+
73516+#ifndef __size_overflow
73517+# define __size_overflow(...)
73518+#endif
73519+
73520+#ifndef __intentional_overflow
73521+# define __intentional_overflow(...)
73522+#endif
73523+
73524+#ifndef __latent_entropy
73525+# define __latent_entropy
73526+#endif
73527+
73528 /*
73529 * Tell gcc if a function is cold. The compiler will assume any path
73530 * directly leading to the call is unlikely.
73531@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73532 #define __cold
73533 #endif
73534
73535+#ifndef __alloc_size
73536+#define __alloc_size(...)
73537+#endif
73538+
73539+#ifndef __bos
73540+#define __bos(ptr, arg)
73541+#endif
73542+
73543+#ifndef __bos0
73544+#define __bos0(ptr)
73545+#endif
73546+
73547+#ifndef __bos1
73548+#define __bos1(ptr)
73549+#endif
73550+
73551 /* Simple shorthand for a section definition */
73552 #ifndef __section
73553 # define __section(S) __attribute__ ((__section__(#S)))
73554@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73555 * use is to mediate communication between process-level code and irq/NMI
73556 * handlers, all running on the same CPU.
73557 */
73558-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
73559+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
73560+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
73561
73562 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
73563 #ifdef CONFIG_KPROBES
73564diff --git a/include/linux/completion.h b/include/linux/completion.h
73565index 3cd574d..240dcb0 100644
73566--- a/include/linux/completion.h
73567+++ b/include/linux/completion.h
73568@@ -78,16 +78,16 @@ static inline void init_completion(struct completion *x)
73569
73570 extern void wait_for_completion(struct completion *);
73571 extern void wait_for_completion_io(struct completion *);
73572-extern int wait_for_completion_interruptible(struct completion *x);
73573-extern int wait_for_completion_killable(struct completion *x);
73574+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
73575+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
73576 extern unsigned long wait_for_completion_timeout(struct completion *x,
73577- unsigned long timeout);
73578+ unsigned long timeout) __intentional_overflow(-1);
73579 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
73580- unsigned long timeout);
73581+ unsigned long timeout) __intentional_overflow(-1);
73582 extern long wait_for_completion_interruptible_timeout(
73583- struct completion *x, unsigned long timeout);
73584+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73585 extern long wait_for_completion_killable_timeout(
73586- struct completion *x, unsigned long timeout);
73587+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73588 extern bool try_wait_for_completion(struct completion *x);
73589 extern bool completion_done(struct completion *x);
73590
73591diff --git a/include/linux/configfs.h b/include/linux/configfs.h
73592index 34025df..d94bbbc 100644
73593--- a/include/linux/configfs.h
73594+++ b/include/linux/configfs.h
73595@@ -125,7 +125,7 @@ struct configfs_attribute {
73596 const char *ca_name;
73597 struct module *ca_owner;
73598 umode_t ca_mode;
73599-};
73600+} __do_const;
73601
73602 /*
73603 * Users often need to create attribute structures for their configurable
73604diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
73605index fcabc42..cba5d93 100644
73606--- a/include/linux/cpufreq.h
73607+++ b/include/linux/cpufreq.h
73608@@ -167,6 +167,7 @@ struct global_attr {
73609 ssize_t (*store)(struct kobject *a, struct attribute *b,
73610 const char *c, size_t count);
73611 };
73612+typedef struct global_attr __no_const global_attr_no_const;
73613
73614 #define define_one_global_ro(_name) \
73615 static struct global_attr _name = \
73616@@ -208,7 +209,7 @@ struct cpufreq_driver {
73617 int (*suspend) (struct cpufreq_policy *policy);
73618 int (*resume) (struct cpufreq_policy *policy);
73619 struct freq_attr **attr;
73620-};
73621+} __do_const;
73622
73623 /* flags */
73624 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
73625diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
73626index 781addc..d1e1fe6 100644
73627--- a/include/linux/cpuidle.h
73628+++ b/include/linux/cpuidle.h
73629@@ -50,7 +50,8 @@ struct cpuidle_state {
73630 int index);
73631
73632 int (*enter_dead) (struct cpuidle_device *dev, int index);
73633-};
73634+} __do_const;
73635+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
73636
73637 /* Idle State Flags */
73638 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
73639@@ -192,7 +193,7 @@ struct cpuidle_governor {
73640 void (*reflect) (struct cpuidle_device *dev, int index);
73641
73642 struct module *owner;
73643-};
73644+} __do_const;
73645
73646 #ifdef CONFIG_CPU_IDLE
73647
73648diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
73649index d08e4d2..95fad61 100644
73650--- a/include/linux/cpumask.h
73651+++ b/include/linux/cpumask.h
73652@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73653 }
73654
73655 /* Valid inputs for n are -1 and 0. */
73656-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73657+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73658 {
73659 return n+1;
73660 }
73661
73662-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73663+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73664 {
73665 return n+1;
73666 }
73667
73668-static inline unsigned int cpumask_next_and(int n,
73669+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
73670 const struct cpumask *srcp,
73671 const struct cpumask *andp)
73672 {
73673@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73674 *
73675 * Returns >= nr_cpu_ids if no further cpus set.
73676 */
73677-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73678+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73679 {
73680 /* -1 is a legal arg here. */
73681 if (n != -1)
73682@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73683 *
73684 * Returns >= nr_cpu_ids if no further cpus unset.
73685 */
73686-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73687+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73688 {
73689 /* -1 is a legal arg here. */
73690 if (n != -1)
73691@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73692 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
73693 }
73694
73695-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
73696+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
73697 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
73698
73699 /**
73700diff --git a/include/linux/cred.h b/include/linux/cred.h
73701index 04421e8..6bce4ef 100644
73702--- a/include/linux/cred.h
73703+++ b/include/linux/cred.h
73704@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
73705 static inline void validate_process_creds(void)
73706 {
73707 }
73708+static inline void validate_task_creds(struct task_struct *task)
73709+{
73710+}
73711 #endif
73712
73713 /**
73714diff --git a/include/linux/crypto.h b/include/linux/crypto.h
73715index b92eadf..b4ecdc1 100644
73716--- a/include/linux/crypto.h
73717+++ b/include/linux/crypto.h
73718@@ -373,7 +373,7 @@ struct cipher_tfm {
73719 const u8 *key, unsigned int keylen);
73720 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
73721 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
73722-};
73723+} __no_const;
73724
73725 struct hash_tfm {
73726 int (*init)(struct hash_desc *desc);
73727@@ -394,13 +394,13 @@ struct compress_tfm {
73728 int (*cot_decompress)(struct crypto_tfm *tfm,
73729 const u8 *src, unsigned int slen,
73730 u8 *dst, unsigned int *dlen);
73731-};
73732+} __no_const;
73733
73734 struct rng_tfm {
73735 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
73736 unsigned int dlen);
73737 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
73738-};
73739+} __no_const;
73740
73741 #define crt_ablkcipher crt_u.ablkcipher
73742 #define crt_aead crt_u.aead
73743diff --git a/include/linux/ctype.h b/include/linux/ctype.h
73744index 653589e..4ef254a 100644
73745--- a/include/linux/ctype.h
73746+++ b/include/linux/ctype.h
73747@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
73748 * Fast implementation of tolower() for internal usage. Do not use in your
73749 * code.
73750 */
73751-static inline char _tolower(const char c)
73752+static inline unsigned char _tolower(const unsigned char c)
73753 {
73754 return c | 0x20;
73755 }
73756diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
73757index 7925bf0..d5143d2 100644
73758--- a/include/linux/decompress/mm.h
73759+++ b/include/linux/decompress/mm.h
73760@@ -77,7 +77,7 @@ static void free(void *where)
73761 * warnings when not needed (indeed large_malloc / large_free are not
73762 * needed by inflate */
73763
73764-#define malloc(a) kmalloc(a, GFP_KERNEL)
73765+#define malloc(a) kmalloc((a), GFP_KERNEL)
73766 #define free(a) kfree(a)
73767
73768 #define large_malloc(a) vmalloc(a)
73769diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
73770index 5f1ab92..39c35ae 100644
73771--- a/include/linux/devfreq.h
73772+++ b/include/linux/devfreq.h
73773@@ -114,7 +114,7 @@ struct devfreq_governor {
73774 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
73775 int (*event_handler)(struct devfreq *devfreq,
73776 unsigned int event, void *data);
73777-};
73778+} __do_const;
73779
73780 /**
73781 * struct devfreq - Device devfreq structure
73782diff --git a/include/linux/device.h b/include/linux/device.h
73783index 2a9d6ed..d14551e3 100644
73784--- a/include/linux/device.h
73785+++ b/include/linux/device.h
73786@@ -313,7 +313,7 @@ struct subsys_interface {
73787 struct list_head node;
73788 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
73789 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
73790-};
73791+} __do_const;
73792
73793 int subsys_interface_register(struct subsys_interface *sif);
73794 void subsys_interface_unregister(struct subsys_interface *sif);
73795@@ -501,7 +501,7 @@ struct device_type {
73796 void (*release)(struct device *dev);
73797
73798 const struct dev_pm_ops *pm;
73799-};
73800+} __do_const;
73801
73802 /* interface for exporting device attributes */
73803 struct device_attribute {
73804@@ -511,11 +511,12 @@ struct device_attribute {
73805 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
73806 const char *buf, size_t count);
73807 };
73808+typedef struct device_attribute __no_const device_attribute_no_const;
73809
73810 struct dev_ext_attribute {
73811 struct device_attribute attr;
73812 void *var;
73813-};
73814+} __do_const;
73815
73816 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
73817 char *buf);
73818diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
73819index 3a8d0a2..c762be2 100644
73820--- a/include/linux/dma-mapping.h
73821+++ b/include/linux/dma-mapping.h
73822@@ -54,7 +54,7 @@ struct dma_map_ops {
73823 u64 (*get_required_mask)(struct device *dev);
73824 #endif
73825 int is_phys;
73826-};
73827+} __do_const;
73828
73829 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
73830
73831diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
73832index 0bc7275..4ccbf11 100644
73833--- a/include/linux/dmaengine.h
73834+++ b/include/linux/dmaengine.h
73835@@ -1078,9 +1078,9 @@ struct dma_pinned_list {
73836 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
73837 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
73838
73839-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73840+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73841 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
73842-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73843+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73844 struct dma_pinned_list *pinned_list, struct page *page,
73845 unsigned int offset, size_t len);
73846
73847diff --git a/include/linux/efi.h b/include/linux/efi.h
73848index 5f8f176..62a0556 100644
73849--- a/include/linux/efi.h
73850+++ b/include/linux/efi.h
73851@@ -745,6 +745,7 @@ struct efivar_operations {
73852 efi_set_variable_t *set_variable;
73853 efi_query_variable_store_t *query_variable_store;
73854 };
73855+typedef struct efivar_operations __no_const efivar_operations_no_const;
73856
73857 struct efivars {
73858 /*
73859diff --git a/include/linux/elf.h b/include/linux/elf.h
73860index 40a3c0e..4c45a38 100644
73861--- a/include/linux/elf.h
73862+++ b/include/linux/elf.h
73863@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
73864 #define elf_note elf32_note
73865 #define elf_addr_t Elf32_Off
73866 #define Elf_Half Elf32_Half
73867+#define elf_dyn Elf32_Dyn
73868
73869 #else
73870
73871@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
73872 #define elf_note elf64_note
73873 #define elf_addr_t Elf64_Off
73874 #define Elf_Half Elf64_Half
73875+#define elf_dyn Elf64_Dyn
73876
73877 #endif
73878
73879diff --git a/include/linux/err.h b/include/linux/err.h
73880index 15f92e0..e825a8e 100644
73881--- a/include/linux/err.h
73882+++ b/include/linux/err.h
73883@@ -19,12 +19,12 @@
73884
73885 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
73886
73887-static inline void * __must_check ERR_PTR(long error)
73888+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
73889 {
73890 return (void *) error;
73891 }
73892
73893-static inline long __must_check PTR_ERR(__force const void *ptr)
73894+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
73895 {
73896 return (long) ptr;
73897 }
73898diff --git a/include/linux/extcon.h b/include/linux/extcon.h
73899index fcb51c8..bdafcf6 100644
73900--- a/include/linux/extcon.h
73901+++ b/include/linux/extcon.h
73902@@ -134,7 +134,7 @@ struct extcon_dev {
73903 /* /sys/class/extcon/.../mutually_exclusive/... */
73904 struct attribute_group attr_g_muex;
73905 struct attribute **attrs_muex;
73906- struct device_attribute *d_attrs_muex;
73907+ device_attribute_no_const *d_attrs_muex;
73908 };
73909
73910 /**
73911diff --git a/include/linux/fb.h b/include/linux/fb.h
73912index ffac70a..ca3e711 100644
73913--- a/include/linux/fb.h
73914+++ b/include/linux/fb.h
73915@@ -304,7 +304,7 @@ struct fb_ops {
73916 /* called at KDB enter and leave time to prepare the console */
73917 int (*fb_debug_enter)(struct fb_info *info);
73918 int (*fb_debug_leave)(struct fb_info *info);
73919-};
73920+} __do_const;
73921
73922 #ifdef CONFIG_FB_TILEBLITTING
73923 #define FB_TILE_CURSOR_NONE 0
73924diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
73925index 085197b..0fa6f0b 100644
73926--- a/include/linux/fdtable.h
73927+++ b/include/linux/fdtable.h
73928@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
73929 void put_files_struct(struct files_struct *fs);
73930 void reset_files_struct(struct files_struct *);
73931 int unshare_files(struct files_struct **);
73932-struct files_struct *dup_fd(struct files_struct *, int *);
73933+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
73934 void do_close_on_exec(struct files_struct *);
73935 int iterate_fd(struct files_struct *, unsigned,
73936 int (*)(const void *, struct file *, unsigned),
73937diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
73938index 8293262..2b3b8bd 100644
73939--- a/include/linux/frontswap.h
73940+++ b/include/linux/frontswap.h
73941@@ -11,7 +11,7 @@ struct frontswap_ops {
73942 int (*load)(unsigned, pgoff_t, struct page *);
73943 void (*invalidate_page)(unsigned, pgoff_t);
73944 void (*invalidate_area)(unsigned);
73945-};
73946+} __no_const;
73947
73948 extern bool frontswap_enabled;
73949 extern struct frontswap_ops *
73950diff --git a/include/linux/fs.h b/include/linux/fs.h
73951index 3f40547..46f76eb 100644
73952--- a/include/linux/fs.h
73953+++ b/include/linux/fs.h
73954@@ -1552,7 +1552,8 @@ struct file_operations {
73955 long (*fallocate)(struct file *file, int mode, loff_t offset,
73956 loff_t len);
73957 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73958-};
73959+} __do_const;
73960+typedef struct file_operations __no_const file_operations_no_const;
73961
73962 struct inode_operations {
73963 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73964@@ -2745,4 +2746,14 @@ static inline bool dir_relax(struct inode *inode)
73965 return !IS_DEADDIR(inode);
73966 }
73967
73968+static inline bool is_sidechannel_device(const struct inode *inode)
73969+{
73970+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73971+ umode_t mode = inode->i_mode;
73972+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73973+#else
73974+ return false;
73975+#endif
73976+}
73977+
73978 #endif /* _LINUX_FS_H */
73979diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73980index 0efc3e6..e0e1e5f 100644
73981--- a/include/linux/fs_struct.h
73982+++ b/include/linux/fs_struct.h
73983@@ -6,7 +6,7 @@
73984 #include <linux/seqlock.h>
73985
73986 struct fs_struct {
73987- int users;
73988+ atomic_t users;
73989 spinlock_t lock;
73990 seqcount_t seq;
73991 int umask;
73992diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73993index 7823e9e..56b6f2f 100644
73994--- a/include/linux/fscache-cache.h
73995+++ b/include/linux/fscache-cache.h
73996@@ -113,7 +113,7 @@ struct fscache_operation {
73997 fscache_operation_release_t release;
73998 };
73999
74000-extern atomic_t fscache_op_debug_id;
74001+extern atomic_unchecked_t fscache_op_debug_id;
74002 extern void fscache_op_work_func(struct work_struct *work);
74003
74004 extern void fscache_enqueue_operation(struct fscache_operation *);
74005@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
74006 INIT_WORK(&op->work, fscache_op_work_func);
74007 atomic_set(&op->usage, 1);
74008 op->state = FSCACHE_OP_ST_INITIALISED;
74009- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
74010+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
74011 op->processor = processor;
74012 op->release = release;
74013 INIT_LIST_HEAD(&op->pend_link);
74014diff --git a/include/linux/fscache.h b/include/linux/fscache.h
74015index 19b4645..3b73dfc 100644
74016--- a/include/linux/fscache.h
74017+++ b/include/linux/fscache.h
74018@@ -152,7 +152,7 @@ struct fscache_cookie_def {
74019 * - this is mandatory for any object that may have data
74020 */
74021 void (*now_uncached)(void *cookie_netfs_data);
74022-};
74023+} __do_const;
74024
74025 /*
74026 * fscache cached network filesystem type
74027diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
74028index 1c804b0..1432c2b 100644
74029--- a/include/linux/fsnotify.h
74030+++ b/include/linux/fsnotify.h
74031@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
74032 struct inode *inode = file_inode(file);
74033 __u32 mask = FS_ACCESS;
74034
74035+ if (is_sidechannel_device(inode))
74036+ return;
74037+
74038 if (S_ISDIR(inode->i_mode))
74039 mask |= FS_ISDIR;
74040
74041@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
74042 struct inode *inode = file_inode(file);
74043 __u32 mask = FS_MODIFY;
74044
74045+ if (is_sidechannel_device(inode))
74046+ return;
74047+
74048 if (S_ISDIR(inode->i_mode))
74049 mask |= FS_ISDIR;
74050
74051@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
74052 */
74053 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
74054 {
74055- return kstrdup(name, GFP_KERNEL);
74056+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
74057 }
74058
74059 /*
74060diff --git a/include/linux/genhd.h b/include/linux/genhd.h
74061index 9f3c275..8bdff5d 100644
74062--- a/include/linux/genhd.h
74063+++ b/include/linux/genhd.h
74064@@ -194,7 +194,7 @@ struct gendisk {
74065 struct kobject *slave_dir;
74066
74067 struct timer_rand_state *random;
74068- atomic_t sync_io; /* RAID */
74069+ atomic_unchecked_t sync_io; /* RAID */
74070 struct disk_events *ev;
74071 #ifdef CONFIG_BLK_DEV_INTEGRITY
74072 struct blk_integrity *integrity;
74073@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
74074 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
74075
74076 /* drivers/char/random.c */
74077-extern void add_disk_randomness(struct gendisk *disk);
74078+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
74079 extern void rand_initialize_disk(struct gendisk *disk);
74080
74081 static inline sector_t get_start_sect(struct block_device *bdev)
74082diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
74083index 023bc34..b02b46a 100644
74084--- a/include/linux/genl_magic_func.h
74085+++ b/include/linux/genl_magic_func.h
74086@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
74087 },
74088
74089 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
74090-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
74091+static struct genl_ops ZZZ_genl_ops[] = {
74092 #include GENL_MAGIC_INCLUDE_FILE
74093 };
74094
74095diff --git a/include/linux/gfp.h b/include/linux/gfp.h
74096index 9b4dd49..61fd41d 100644
74097--- a/include/linux/gfp.h
74098+++ b/include/linux/gfp.h
74099@@ -35,6 +35,13 @@ struct vm_area_struct;
74100 #define ___GFP_NO_KSWAPD 0x400000u
74101 #define ___GFP_OTHER_NODE 0x800000u
74102 #define ___GFP_WRITE 0x1000000u
74103+
74104+#ifdef CONFIG_PAX_USERCOPY_SLABS
74105+#define ___GFP_USERCOPY 0x2000000u
74106+#else
74107+#define ___GFP_USERCOPY 0
74108+#endif
74109+
74110 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
74111
74112 /*
74113@@ -92,6 +99,7 @@ struct vm_area_struct;
74114 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
74115 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
74116 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
74117+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
74118
74119 /*
74120 * This may seem redundant, but it's a way of annotating false positives vs.
74121@@ -99,7 +107,7 @@ struct vm_area_struct;
74122 */
74123 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
74124
74125-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
74126+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
74127 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
74128
74129 /* This equals 0, but use constants in case they ever change */
74130@@ -153,6 +161,8 @@ struct vm_area_struct;
74131 /* 4GB DMA on some platforms */
74132 #define GFP_DMA32 __GFP_DMA32
74133
74134+#define GFP_USERCOPY __GFP_USERCOPY
74135+
74136 /* Convert GFP flags to their corresponding migrate type */
74137 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
74138 {
74139diff --git a/include/linux/gracl.h b/include/linux/gracl.h
74140new file mode 100644
74141index 0000000..edb2cb6
74142--- /dev/null
74143+++ b/include/linux/gracl.h
74144@@ -0,0 +1,340 @@
74145+#ifndef GR_ACL_H
74146+#define GR_ACL_H
74147+
74148+#include <linux/grdefs.h>
74149+#include <linux/resource.h>
74150+#include <linux/capability.h>
74151+#include <linux/dcache.h>
74152+#include <asm/resource.h>
74153+
74154+/* Major status information */
74155+
74156+#define GR_VERSION "grsecurity 3.0"
74157+#define GRSECURITY_VERSION 0x3000
74158+
74159+enum {
74160+ GR_SHUTDOWN = 0,
74161+ GR_ENABLE = 1,
74162+ GR_SPROLE = 2,
74163+ GR_OLDRELOAD = 3,
74164+ GR_SEGVMOD = 4,
74165+ GR_STATUS = 5,
74166+ GR_UNSPROLE = 6,
74167+ GR_PASSSET = 7,
74168+ GR_SPROLEPAM = 8,
74169+ GR_RELOAD = 9,
74170+};
74171+
74172+/* Password setup definitions
74173+ * kernel/grhash.c */
74174+enum {
74175+ GR_PW_LEN = 128,
74176+ GR_SALT_LEN = 16,
74177+ GR_SHA_LEN = 32,
74178+};
74179+
74180+enum {
74181+ GR_SPROLE_LEN = 64,
74182+};
74183+
74184+enum {
74185+ GR_NO_GLOB = 0,
74186+ GR_REG_GLOB,
74187+ GR_CREATE_GLOB
74188+};
74189+
74190+#define GR_NLIMITS 32
74191+
74192+/* Begin Data Structures */
74193+
74194+struct sprole_pw {
74195+ unsigned char *rolename;
74196+ unsigned char salt[GR_SALT_LEN];
74197+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
74198+};
74199+
74200+struct name_entry {
74201+ __u32 key;
74202+ ino_t inode;
74203+ dev_t device;
74204+ char *name;
74205+ __u16 len;
74206+ __u8 deleted;
74207+ struct name_entry *prev;
74208+ struct name_entry *next;
74209+};
74210+
74211+struct inodev_entry {
74212+ struct name_entry *nentry;
74213+ struct inodev_entry *prev;
74214+ struct inodev_entry *next;
74215+};
74216+
74217+struct acl_role_db {
74218+ struct acl_role_label **r_hash;
74219+ __u32 r_size;
74220+};
74221+
74222+struct inodev_db {
74223+ struct inodev_entry **i_hash;
74224+ __u32 i_size;
74225+};
74226+
74227+struct name_db {
74228+ struct name_entry **n_hash;
74229+ __u32 n_size;
74230+};
74231+
74232+struct crash_uid {
74233+ uid_t uid;
74234+ unsigned long expires;
74235+};
74236+
74237+struct gr_hash_struct {
74238+ void **table;
74239+ void **nametable;
74240+ void *first;
74241+ __u32 table_size;
74242+ __u32 used_size;
74243+ int type;
74244+};
74245+
74246+/* Userspace Grsecurity ACL data structures */
74247+
74248+struct acl_subject_label {
74249+ char *filename;
74250+ ino_t inode;
74251+ dev_t device;
74252+ __u32 mode;
74253+ kernel_cap_t cap_mask;
74254+ kernel_cap_t cap_lower;
74255+ kernel_cap_t cap_invert_audit;
74256+
74257+ struct rlimit res[GR_NLIMITS];
74258+ __u32 resmask;
74259+
74260+ __u8 user_trans_type;
74261+ __u8 group_trans_type;
74262+ uid_t *user_transitions;
74263+ gid_t *group_transitions;
74264+ __u16 user_trans_num;
74265+ __u16 group_trans_num;
74266+
74267+ __u32 sock_families[2];
74268+ __u32 ip_proto[8];
74269+ __u32 ip_type;
74270+ struct acl_ip_label **ips;
74271+ __u32 ip_num;
74272+ __u32 inaddr_any_override;
74273+
74274+ __u32 crashes;
74275+ unsigned long expires;
74276+
74277+ struct acl_subject_label *parent_subject;
74278+ struct gr_hash_struct *hash;
74279+ struct acl_subject_label *prev;
74280+ struct acl_subject_label *next;
74281+
74282+ struct acl_object_label **obj_hash;
74283+ __u32 obj_hash_size;
74284+ __u16 pax_flags;
74285+};
74286+
74287+struct role_allowed_ip {
74288+ __u32 addr;
74289+ __u32 netmask;
74290+
74291+ struct role_allowed_ip *prev;
74292+ struct role_allowed_ip *next;
74293+};
74294+
74295+struct role_transition {
74296+ char *rolename;
74297+
74298+ struct role_transition *prev;
74299+ struct role_transition *next;
74300+};
74301+
74302+struct acl_role_label {
74303+ char *rolename;
74304+ uid_t uidgid;
74305+ __u16 roletype;
74306+
74307+ __u16 auth_attempts;
74308+ unsigned long expires;
74309+
74310+ struct acl_subject_label *root_label;
74311+ struct gr_hash_struct *hash;
74312+
74313+ struct acl_role_label *prev;
74314+ struct acl_role_label *next;
74315+
74316+ struct role_transition *transitions;
74317+ struct role_allowed_ip *allowed_ips;
74318+ uid_t *domain_children;
74319+ __u16 domain_child_num;
74320+
74321+ umode_t umask;
74322+
74323+ struct acl_subject_label **subj_hash;
74324+ __u32 subj_hash_size;
74325+};
74326+
74327+struct user_acl_role_db {
74328+ struct acl_role_label **r_table;
74329+ __u32 num_pointers; /* Number of allocations to track */
74330+ __u32 num_roles; /* Number of roles */
74331+ __u32 num_domain_children; /* Number of domain children */
74332+ __u32 num_subjects; /* Number of subjects */
74333+ __u32 num_objects; /* Number of objects */
74334+};
74335+
74336+struct acl_object_label {
74337+ char *filename;
74338+ ino_t inode;
74339+ dev_t device;
74340+ __u32 mode;
74341+
74342+ struct acl_subject_label *nested;
74343+ struct acl_object_label *globbed;
74344+
74345+ /* next two structures not used */
74346+
74347+ struct acl_object_label *prev;
74348+ struct acl_object_label *next;
74349+};
74350+
74351+struct acl_ip_label {
74352+ char *iface;
74353+ __u32 addr;
74354+ __u32 netmask;
74355+ __u16 low, high;
74356+ __u8 mode;
74357+ __u32 type;
74358+ __u32 proto[8];
74359+
74360+ /* next two structures not used */
74361+
74362+ struct acl_ip_label *prev;
74363+ struct acl_ip_label *next;
74364+};
74365+
74366+struct gr_arg {
74367+ struct user_acl_role_db role_db;
74368+ unsigned char pw[GR_PW_LEN];
74369+ unsigned char salt[GR_SALT_LEN];
74370+ unsigned char sum[GR_SHA_LEN];
74371+ unsigned char sp_role[GR_SPROLE_LEN];
74372+ struct sprole_pw *sprole_pws;
74373+ dev_t segv_device;
74374+ ino_t segv_inode;
74375+ uid_t segv_uid;
74376+ __u16 num_sprole_pws;
74377+ __u16 mode;
74378+};
74379+
74380+struct gr_arg_wrapper {
74381+ struct gr_arg *arg;
74382+ __u32 version;
74383+ __u32 size;
74384+};
74385+
74386+struct subject_map {
74387+ struct acl_subject_label *user;
74388+ struct acl_subject_label *kernel;
74389+ struct subject_map *prev;
74390+ struct subject_map *next;
74391+};
74392+
74393+struct acl_subj_map_db {
74394+ struct subject_map **s_hash;
74395+ __u32 s_size;
74396+};
74397+
74398+struct gr_policy_state {
74399+ struct sprole_pw **acl_special_roles;
74400+ __u16 num_sprole_pws;
74401+ struct acl_role_label *kernel_role;
74402+ struct acl_role_label *role_list;
74403+ struct acl_role_label *default_role;
74404+ struct acl_role_db acl_role_set;
74405+ struct acl_subj_map_db subj_map_set;
74406+ struct name_db name_set;
74407+ struct inodev_db inodev_set;
74408+};
74409+
74410+struct gr_alloc_state {
74411+ unsigned long alloc_stack_next;
74412+ unsigned long alloc_stack_size;
74413+ void **alloc_stack;
74414+};
74415+
74416+struct gr_reload_state {
74417+ struct gr_policy_state oldpolicy;
74418+ struct gr_alloc_state oldalloc;
74419+ struct gr_policy_state newpolicy;
74420+ struct gr_alloc_state newalloc;
74421+ struct gr_policy_state *oldpolicy_ptr;
74422+ struct gr_alloc_state *oldalloc_ptr;
74423+ unsigned char oldmode;
74424+};
74425+
74426+/* End Data Structures Section */
74427+
74428+/* Hash functions generated by empirical testing by Brad Spengler
74429+ Makes good use of the low bits of the inode. Generally 0-1 times
74430+ in loop for successful match. 0-3 for unsuccessful match.
74431+ Shift/add algorithm with modulus of table size and an XOR*/
74432+
74433+static __inline__ unsigned int
74434+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
74435+{
74436+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
74437+}
74438+
74439+ static __inline__ unsigned int
74440+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
74441+{
74442+ return ((const unsigned long)userp % sz);
74443+}
74444+
74445+static __inline__ unsigned int
74446+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
74447+{
74448+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
74449+}
74450+
74451+static __inline__ unsigned int
74452+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
74453+{
74454+ return full_name_hash((const unsigned char *)name, len) % sz;
74455+}
74456+
74457+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
74458+ subj = NULL; \
74459+ iter = 0; \
74460+ while (iter < role->subj_hash_size) { \
74461+ if (subj == NULL) \
74462+ subj = role->subj_hash[iter]; \
74463+ if (subj == NULL) { \
74464+ iter++; \
74465+ continue; \
74466+ }
74467+
74468+#define FOR_EACH_SUBJECT_END(subj,iter) \
74469+ subj = subj->next; \
74470+ if (subj == NULL) \
74471+ iter++; \
74472+ }
74473+
74474+
74475+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
74476+ subj = role->hash->first; \
74477+ while (subj != NULL) {
74478+
74479+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
74480+ subj = subj->next; \
74481+ }
74482+
74483+#endif
74484+
74485diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
74486new file mode 100644
74487index 0000000..33ebd1f
74488--- /dev/null
74489+++ b/include/linux/gracl_compat.h
74490@@ -0,0 +1,156 @@
74491+#ifndef GR_ACL_COMPAT_H
74492+#define GR_ACL_COMPAT_H
74493+
74494+#include <linux/resource.h>
74495+#include <asm/resource.h>
74496+
74497+struct sprole_pw_compat {
74498+ compat_uptr_t rolename;
74499+ unsigned char salt[GR_SALT_LEN];
74500+ unsigned char sum[GR_SHA_LEN];
74501+};
74502+
74503+struct gr_hash_struct_compat {
74504+ compat_uptr_t table;
74505+ compat_uptr_t nametable;
74506+ compat_uptr_t first;
74507+ __u32 table_size;
74508+ __u32 used_size;
74509+ int type;
74510+};
74511+
74512+struct acl_subject_label_compat {
74513+ compat_uptr_t filename;
74514+ compat_ino_t inode;
74515+ __u32 device;
74516+ __u32 mode;
74517+ kernel_cap_t cap_mask;
74518+ kernel_cap_t cap_lower;
74519+ kernel_cap_t cap_invert_audit;
74520+
74521+ struct compat_rlimit res[GR_NLIMITS];
74522+ __u32 resmask;
74523+
74524+ __u8 user_trans_type;
74525+ __u8 group_trans_type;
74526+ compat_uptr_t user_transitions;
74527+ compat_uptr_t group_transitions;
74528+ __u16 user_trans_num;
74529+ __u16 group_trans_num;
74530+
74531+ __u32 sock_families[2];
74532+ __u32 ip_proto[8];
74533+ __u32 ip_type;
74534+ compat_uptr_t ips;
74535+ __u32 ip_num;
74536+ __u32 inaddr_any_override;
74537+
74538+ __u32 crashes;
74539+ compat_ulong_t expires;
74540+
74541+ compat_uptr_t parent_subject;
74542+ compat_uptr_t hash;
74543+ compat_uptr_t prev;
74544+ compat_uptr_t next;
74545+
74546+ compat_uptr_t obj_hash;
74547+ __u32 obj_hash_size;
74548+ __u16 pax_flags;
74549+};
74550+
74551+struct role_allowed_ip_compat {
74552+ __u32 addr;
74553+ __u32 netmask;
74554+
74555+ compat_uptr_t prev;
74556+ compat_uptr_t next;
74557+};
74558+
74559+struct role_transition_compat {
74560+ compat_uptr_t rolename;
74561+
74562+ compat_uptr_t prev;
74563+ compat_uptr_t next;
74564+};
74565+
74566+struct acl_role_label_compat {
74567+ compat_uptr_t rolename;
74568+ uid_t uidgid;
74569+ __u16 roletype;
74570+
74571+ __u16 auth_attempts;
74572+ compat_ulong_t expires;
74573+
74574+ compat_uptr_t root_label;
74575+ compat_uptr_t hash;
74576+
74577+ compat_uptr_t prev;
74578+ compat_uptr_t next;
74579+
74580+ compat_uptr_t transitions;
74581+ compat_uptr_t allowed_ips;
74582+ compat_uptr_t domain_children;
74583+ __u16 domain_child_num;
74584+
74585+ umode_t umask;
74586+
74587+ compat_uptr_t subj_hash;
74588+ __u32 subj_hash_size;
74589+};
74590+
74591+struct user_acl_role_db_compat {
74592+ compat_uptr_t r_table;
74593+ __u32 num_pointers;
74594+ __u32 num_roles;
74595+ __u32 num_domain_children;
74596+ __u32 num_subjects;
74597+ __u32 num_objects;
74598+};
74599+
74600+struct acl_object_label_compat {
74601+ compat_uptr_t filename;
74602+ compat_ino_t inode;
74603+ __u32 device;
74604+ __u32 mode;
74605+
74606+ compat_uptr_t nested;
74607+ compat_uptr_t globbed;
74608+
74609+ compat_uptr_t prev;
74610+ compat_uptr_t next;
74611+};
74612+
74613+struct acl_ip_label_compat {
74614+ compat_uptr_t iface;
74615+ __u32 addr;
74616+ __u32 netmask;
74617+ __u16 low, high;
74618+ __u8 mode;
74619+ __u32 type;
74620+ __u32 proto[8];
74621+
74622+ compat_uptr_t prev;
74623+ compat_uptr_t next;
74624+};
74625+
74626+struct gr_arg_compat {
74627+ struct user_acl_role_db_compat role_db;
74628+ unsigned char pw[GR_PW_LEN];
74629+ unsigned char salt[GR_SALT_LEN];
74630+ unsigned char sum[GR_SHA_LEN];
74631+ unsigned char sp_role[GR_SPROLE_LEN];
74632+ compat_uptr_t sprole_pws;
74633+ __u32 segv_device;
74634+ compat_ino_t segv_inode;
74635+ uid_t segv_uid;
74636+ __u16 num_sprole_pws;
74637+ __u16 mode;
74638+};
74639+
74640+struct gr_arg_wrapper_compat {
74641+ compat_uptr_t arg;
74642+ __u32 version;
74643+ __u32 size;
74644+};
74645+
74646+#endif
74647diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
74648new file mode 100644
74649index 0000000..323ecf2
74650--- /dev/null
74651+++ b/include/linux/gralloc.h
74652@@ -0,0 +1,9 @@
74653+#ifndef __GRALLOC_H
74654+#define __GRALLOC_H
74655+
74656+void acl_free_all(void);
74657+int acl_alloc_stack_init(unsigned long size);
74658+void *acl_alloc(unsigned long len);
74659+void *acl_alloc_num(unsigned long num, unsigned long len);
74660+
74661+#endif
74662diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
74663new file mode 100644
74664index 0000000..be66033
74665--- /dev/null
74666+++ b/include/linux/grdefs.h
74667@@ -0,0 +1,140 @@
74668+#ifndef GRDEFS_H
74669+#define GRDEFS_H
74670+
74671+/* Begin grsecurity status declarations */
74672+
74673+enum {
74674+ GR_READY = 0x01,
74675+ GR_STATUS_INIT = 0x00 // disabled state
74676+};
74677+
74678+/* Begin ACL declarations */
74679+
74680+/* Role flags */
74681+
74682+enum {
74683+ GR_ROLE_USER = 0x0001,
74684+ GR_ROLE_GROUP = 0x0002,
74685+ GR_ROLE_DEFAULT = 0x0004,
74686+ GR_ROLE_SPECIAL = 0x0008,
74687+ GR_ROLE_AUTH = 0x0010,
74688+ GR_ROLE_NOPW = 0x0020,
74689+ GR_ROLE_GOD = 0x0040,
74690+ GR_ROLE_LEARN = 0x0080,
74691+ GR_ROLE_TPE = 0x0100,
74692+ GR_ROLE_DOMAIN = 0x0200,
74693+ GR_ROLE_PAM = 0x0400,
74694+ GR_ROLE_PERSIST = 0x0800
74695+};
74696+
74697+/* ACL Subject and Object mode flags */
74698+enum {
74699+ GR_DELETED = 0x80000000
74700+};
74701+
74702+/* ACL Object-only mode flags */
74703+enum {
74704+ GR_READ = 0x00000001,
74705+ GR_APPEND = 0x00000002,
74706+ GR_WRITE = 0x00000004,
74707+ GR_EXEC = 0x00000008,
74708+ GR_FIND = 0x00000010,
74709+ GR_INHERIT = 0x00000020,
74710+ GR_SETID = 0x00000040,
74711+ GR_CREATE = 0x00000080,
74712+ GR_DELETE = 0x00000100,
74713+ GR_LINK = 0x00000200,
74714+ GR_AUDIT_READ = 0x00000400,
74715+ GR_AUDIT_APPEND = 0x00000800,
74716+ GR_AUDIT_WRITE = 0x00001000,
74717+ GR_AUDIT_EXEC = 0x00002000,
74718+ GR_AUDIT_FIND = 0x00004000,
74719+ GR_AUDIT_INHERIT= 0x00008000,
74720+ GR_AUDIT_SETID = 0x00010000,
74721+ GR_AUDIT_CREATE = 0x00020000,
74722+ GR_AUDIT_DELETE = 0x00040000,
74723+ GR_AUDIT_LINK = 0x00080000,
74724+ GR_PTRACERD = 0x00100000,
74725+ GR_NOPTRACE = 0x00200000,
74726+ GR_SUPPRESS = 0x00400000,
74727+ GR_NOLEARN = 0x00800000,
74728+ GR_INIT_TRANSFER= 0x01000000
74729+};
74730+
74731+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
74732+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
74733+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
74734+
74735+/* ACL subject-only mode flags */
74736+enum {
74737+ GR_KILL = 0x00000001,
74738+ GR_VIEW = 0x00000002,
74739+ GR_PROTECTED = 0x00000004,
74740+ GR_LEARN = 0x00000008,
74741+ GR_OVERRIDE = 0x00000010,
74742+ /* just a placeholder, this mode is only used in userspace */
74743+ GR_DUMMY = 0x00000020,
74744+ GR_PROTSHM = 0x00000040,
74745+ GR_KILLPROC = 0x00000080,
74746+ GR_KILLIPPROC = 0x00000100,
74747+ /* just a placeholder, this mode is only used in userspace */
74748+ GR_NOTROJAN = 0x00000200,
74749+ GR_PROTPROCFD = 0x00000400,
74750+ GR_PROCACCT = 0x00000800,
74751+ GR_RELAXPTRACE = 0x00001000,
74752+ //GR_NESTED = 0x00002000,
74753+ GR_INHERITLEARN = 0x00004000,
74754+ GR_PROCFIND = 0x00008000,
74755+ GR_POVERRIDE = 0x00010000,
74756+ GR_KERNELAUTH = 0x00020000,
74757+ GR_ATSECURE = 0x00040000,
74758+ GR_SHMEXEC = 0x00080000
74759+};
74760+
74761+enum {
74762+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
74763+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
74764+ GR_PAX_ENABLE_MPROTECT = 0x0004,
74765+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
74766+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
74767+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
74768+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
74769+ GR_PAX_DISABLE_MPROTECT = 0x0400,
74770+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
74771+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
74772+};
74773+
74774+enum {
74775+ GR_ID_USER = 0x01,
74776+ GR_ID_GROUP = 0x02,
74777+};
74778+
74779+enum {
74780+ GR_ID_ALLOW = 0x01,
74781+ GR_ID_DENY = 0x02,
74782+};
74783+
74784+#define GR_CRASH_RES 31
74785+#define GR_UIDTABLE_MAX 500
74786+
74787+/* begin resource learning section */
74788+enum {
74789+ GR_RLIM_CPU_BUMP = 60,
74790+ GR_RLIM_FSIZE_BUMP = 50000,
74791+ GR_RLIM_DATA_BUMP = 10000,
74792+ GR_RLIM_STACK_BUMP = 1000,
74793+ GR_RLIM_CORE_BUMP = 10000,
74794+ GR_RLIM_RSS_BUMP = 500000,
74795+ GR_RLIM_NPROC_BUMP = 1,
74796+ GR_RLIM_NOFILE_BUMP = 5,
74797+ GR_RLIM_MEMLOCK_BUMP = 50000,
74798+ GR_RLIM_AS_BUMP = 500000,
74799+ GR_RLIM_LOCKS_BUMP = 2,
74800+ GR_RLIM_SIGPENDING_BUMP = 5,
74801+ GR_RLIM_MSGQUEUE_BUMP = 10000,
74802+ GR_RLIM_NICE_BUMP = 1,
74803+ GR_RLIM_RTPRIO_BUMP = 1,
74804+ GR_RLIM_RTTIME_BUMP = 1000000
74805+};
74806+
74807+#endif
74808diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
74809new file mode 100644
74810index 0000000..d25522e
74811--- /dev/null
74812+++ b/include/linux/grinternal.h
74813@@ -0,0 +1,229 @@
74814+#ifndef __GRINTERNAL_H
74815+#define __GRINTERNAL_H
74816+
74817+#ifdef CONFIG_GRKERNSEC
74818+
74819+#include <linux/fs.h>
74820+#include <linux/mnt_namespace.h>
74821+#include <linux/nsproxy.h>
74822+#include <linux/gracl.h>
74823+#include <linux/grdefs.h>
74824+#include <linux/grmsg.h>
74825+
74826+void gr_add_learn_entry(const char *fmt, ...)
74827+ __attribute__ ((format (printf, 1, 2)));
74828+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
74829+ const struct vfsmount *mnt);
74830+__u32 gr_check_create(const struct dentry *new_dentry,
74831+ const struct dentry *parent,
74832+ const struct vfsmount *mnt, const __u32 mode);
74833+int gr_check_protected_task(const struct task_struct *task);
74834+__u32 to_gr_audit(const __u32 reqmode);
74835+int gr_set_acls(const int type);
74836+int gr_acl_is_enabled(void);
74837+char gr_roletype_to_char(void);
74838+
74839+void gr_handle_alertkill(struct task_struct *task);
74840+char *gr_to_filename(const struct dentry *dentry,
74841+ const struct vfsmount *mnt);
74842+char *gr_to_filename1(const struct dentry *dentry,
74843+ const struct vfsmount *mnt);
74844+char *gr_to_filename2(const struct dentry *dentry,
74845+ const struct vfsmount *mnt);
74846+char *gr_to_filename3(const struct dentry *dentry,
74847+ const struct vfsmount *mnt);
74848+
74849+extern int grsec_enable_ptrace_readexec;
74850+extern int grsec_enable_harden_ptrace;
74851+extern int grsec_enable_link;
74852+extern int grsec_enable_fifo;
74853+extern int grsec_enable_execve;
74854+extern int grsec_enable_shm;
74855+extern int grsec_enable_execlog;
74856+extern int grsec_enable_signal;
74857+extern int grsec_enable_audit_ptrace;
74858+extern int grsec_enable_forkfail;
74859+extern int grsec_enable_time;
74860+extern int grsec_enable_rofs;
74861+extern int grsec_deny_new_usb;
74862+extern int grsec_enable_chroot_shmat;
74863+extern int grsec_enable_chroot_mount;
74864+extern int grsec_enable_chroot_double;
74865+extern int grsec_enable_chroot_pivot;
74866+extern int grsec_enable_chroot_chdir;
74867+extern int grsec_enable_chroot_chmod;
74868+extern int grsec_enable_chroot_mknod;
74869+extern int grsec_enable_chroot_fchdir;
74870+extern int grsec_enable_chroot_nice;
74871+extern int grsec_enable_chroot_execlog;
74872+extern int grsec_enable_chroot_caps;
74873+extern int grsec_enable_chroot_sysctl;
74874+extern int grsec_enable_chroot_unix;
74875+extern int grsec_enable_symlinkown;
74876+extern kgid_t grsec_symlinkown_gid;
74877+extern int grsec_enable_tpe;
74878+extern kgid_t grsec_tpe_gid;
74879+extern int grsec_enable_tpe_all;
74880+extern int grsec_enable_tpe_invert;
74881+extern int grsec_enable_socket_all;
74882+extern kgid_t grsec_socket_all_gid;
74883+extern int grsec_enable_socket_client;
74884+extern kgid_t grsec_socket_client_gid;
74885+extern int grsec_enable_socket_server;
74886+extern kgid_t grsec_socket_server_gid;
74887+extern kgid_t grsec_audit_gid;
74888+extern int grsec_enable_group;
74889+extern int grsec_enable_log_rwxmaps;
74890+extern int grsec_enable_mount;
74891+extern int grsec_enable_chdir;
74892+extern int grsec_resource_logging;
74893+extern int grsec_enable_blackhole;
74894+extern int grsec_lastack_retries;
74895+extern int grsec_enable_brute;
74896+extern int grsec_enable_harden_ipc;
74897+extern int grsec_lock;
74898+
74899+extern spinlock_t grsec_alert_lock;
74900+extern unsigned long grsec_alert_wtime;
74901+extern unsigned long grsec_alert_fyet;
74902+
74903+extern spinlock_t grsec_audit_lock;
74904+
74905+extern rwlock_t grsec_exec_file_lock;
74906+
74907+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
74908+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
74909+ (tsk)->exec_file->f_path.mnt) : "/")
74910+
74911+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
74912+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
74913+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74914+
74915+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
74916+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
74917+ (tsk)->exec_file->f_path.mnt) : "/")
74918+
74919+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
74920+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
74921+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74922+
74923+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
74924+
74925+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
74926+
74927+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
74928+{
74929+ if (file1 && file2) {
74930+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
74931+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
74932+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
74933+ return true;
74934+ }
74935+
74936+ return false;
74937+}
74938+
74939+#define GR_CHROOT_CAPS {{ \
74940+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
74941+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
74942+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
74943+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
74944+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
74945+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
74946+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
74947+
74948+#define security_learn(normal_msg,args...) \
74949+({ \
74950+ read_lock(&grsec_exec_file_lock); \
74951+ gr_add_learn_entry(normal_msg "\n", ## args); \
74952+ read_unlock(&grsec_exec_file_lock); \
74953+})
74954+
74955+enum {
74956+ GR_DO_AUDIT,
74957+ GR_DONT_AUDIT,
74958+ /* used for non-audit messages that we shouldn't kill the task on */
74959+ GR_DONT_AUDIT_GOOD
74960+};
74961+
74962+enum {
74963+ GR_TTYSNIFF,
74964+ GR_RBAC,
74965+ GR_RBAC_STR,
74966+ GR_STR_RBAC,
74967+ GR_RBAC_MODE2,
74968+ GR_RBAC_MODE3,
74969+ GR_FILENAME,
74970+ GR_SYSCTL_HIDDEN,
74971+ GR_NOARGS,
74972+ GR_ONE_INT,
74973+ GR_ONE_INT_TWO_STR,
74974+ GR_ONE_STR,
74975+ GR_STR_INT,
74976+ GR_TWO_STR_INT,
74977+ GR_TWO_INT,
74978+ GR_TWO_U64,
74979+ GR_THREE_INT,
74980+ GR_FIVE_INT_TWO_STR,
74981+ GR_TWO_STR,
74982+ GR_THREE_STR,
74983+ GR_FOUR_STR,
74984+ GR_STR_FILENAME,
74985+ GR_FILENAME_STR,
74986+ GR_FILENAME_TWO_INT,
74987+ GR_FILENAME_TWO_INT_STR,
74988+ GR_TEXTREL,
74989+ GR_PTRACE,
74990+ GR_RESOURCE,
74991+ GR_CAP,
74992+ GR_SIG,
74993+ GR_SIG2,
74994+ GR_CRASH1,
74995+ GR_CRASH2,
74996+ GR_PSACCT,
74997+ GR_RWXMAP,
74998+ GR_RWXMAPVMA
74999+};
75000+
75001+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
75002+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
75003+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
75004+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
75005+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
75006+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
75007+#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)
75008+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
75009+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
75010+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
75011+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
75012+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
75013+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
75014+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
75015+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
75016+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
75017+#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)
75018+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
75019+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
75020+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
75021+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
75022+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
75023+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
75024+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
75025+#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)
75026+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
75027+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
75028+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
75029+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
75030+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
75031+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
75032+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
75033+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
75034+#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)
75035+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
75036+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
75037+
75038+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
75039+
75040+#endif
75041+
75042+#endif
75043diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
75044new file mode 100644
75045index 0000000..378a81a
75046--- /dev/null
75047+++ b/include/linux/grmsg.h
75048@@ -0,0 +1,114 @@
75049+#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"
75050+#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"
75051+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
75052+#define GR_STOPMOD_MSG "denied modification of module state by "
75053+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
75054+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
75055+#define GR_IOPERM_MSG "denied use of ioperm() by "
75056+#define GR_IOPL_MSG "denied use of iopl() by "
75057+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
75058+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
75059+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
75060+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
75061+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
75062+#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"
75063+#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"
75064+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
75065+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
75066+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
75067+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
75068+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
75069+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
75070+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
75071+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
75072+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
75073+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
75074+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
75075+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
75076+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
75077+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
75078+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
75079+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
75080+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
75081+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
75082+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
75083+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
75084+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
75085+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
75086+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
75087+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
75088+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
75089+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
75090+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
75091+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
75092+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
75093+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
75094+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
75095+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
75096+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
75097+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
75098+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
75099+#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"
75100+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
75101+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
75102+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
75103+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
75104+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
75105+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
75106+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
75107+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
75108+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
75109+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
75110+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
75111+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
75112+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
75113+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
75114+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
75115+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
75116+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
75117+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
75118+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
75119+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
75120+#define GR_FAILFORK_MSG "failed fork with errno %s by "
75121+#define GR_NICE_CHROOT_MSG "denied priority change by "
75122+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
75123+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
75124+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
75125+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
75126+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
75127+#define GR_TIME_MSG "time set by "
75128+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
75129+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
75130+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
75131+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
75132+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
75133+#define GR_BIND_MSG "denied bind() by "
75134+#define GR_CONNECT_MSG "denied connect() by "
75135+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
75136+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
75137+#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"
75138+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
75139+#define GR_CAP_ACL_MSG "use of %s denied for "
75140+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
75141+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
75142+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
75143+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
75144+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
75145+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
75146+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
75147+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
75148+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
75149+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
75150+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
75151+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
75152+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
75153+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
75154+#define GR_VM86_MSG "denied use of vm86 by "
75155+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
75156+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
75157+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
75158+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
75159+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
75160+#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 "
75161+#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 "
75162+#define GR_IPC_DENIED_MSG "denied %s of globally-%sable IPC with creator uid %u by "
75163diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
75164new file mode 100644
75165index 0000000..b2edfb1
75166--- /dev/null
75167+++ b/include/linux/grsecurity.h
75168@@ -0,0 +1,243 @@
75169+#ifndef GR_SECURITY_H
75170+#define GR_SECURITY_H
75171+#include <linux/fs.h>
75172+#include <linux/fs_struct.h>
75173+#include <linux/binfmts.h>
75174+#include <linux/gracl.h>
75175+
75176+/* notify of brain-dead configs */
75177+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75178+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
75179+#endif
75180+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
75181+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
75182+#endif
75183+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
75184+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
75185+#endif
75186+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
75187+#error "CONFIG_PAX enabled, but no PaX options are enabled."
75188+#endif
75189+
75190+int gr_handle_new_usb(void);
75191+
75192+void gr_handle_brute_attach(unsigned long mm_flags);
75193+void gr_handle_brute_check(void);
75194+void gr_handle_kernel_exploit(void);
75195+
75196+char gr_roletype_to_char(void);
75197+
75198+int gr_acl_enable_at_secure(void);
75199+
75200+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
75201+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
75202+
75203+void gr_del_task_from_ip_table(struct task_struct *p);
75204+
75205+int gr_pid_is_chrooted(struct task_struct *p);
75206+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
75207+int gr_handle_chroot_nice(void);
75208+int gr_handle_chroot_sysctl(const int op);
75209+int gr_handle_chroot_setpriority(struct task_struct *p,
75210+ const int niceval);
75211+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
75212+int gr_handle_chroot_chroot(const struct dentry *dentry,
75213+ const struct vfsmount *mnt);
75214+void gr_handle_chroot_chdir(const struct path *path);
75215+int gr_handle_chroot_chmod(const struct dentry *dentry,
75216+ const struct vfsmount *mnt, const int mode);
75217+int gr_handle_chroot_mknod(const struct dentry *dentry,
75218+ const struct vfsmount *mnt, const int mode);
75219+int gr_handle_chroot_mount(const struct dentry *dentry,
75220+ const struct vfsmount *mnt,
75221+ const char *dev_name);
75222+int gr_handle_chroot_pivot(void);
75223+int gr_handle_chroot_unix(const pid_t pid);
75224+
75225+int gr_handle_rawio(const struct inode *inode);
75226+
75227+void gr_handle_ioperm(void);
75228+void gr_handle_iopl(void);
75229+
75230+umode_t gr_acl_umask(void);
75231+
75232+int gr_tpe_allow(const struct file *file);
75233+
75234+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
75235+void gr_clear_chroot_entries(struct task_struct *task);
75236+
75237+void gr_log_forkfail(const int retval);
75238+void gr_log_timechange(void);
75239+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
75240+void gr_log_chdir(const struct dentry *dentry,
75241+ const struct vfsmount *mnt);
75242+void gr_log_chroot_exec(const struct dentry *dentry,
75243+ const struct vfsmount *mnt);
75244+void gr_log_remount(const char *devname, const int retval);
75245+void gr_log_unmount(const char *devname, const int retval);
75246+void gr_log_mount(const char *from, const char *to, const int retval);
75247+void gr_log_textrel(struct vm_area_struct *vma);
75248+void gr_log_ptgnustack(struct file *file);
75249+void gr_log_rwxmmap(struct file *file);
75250+void gr_log_rwxmprotect(struct vm_area_struct *vma);
75251+
75252+int gr_handle_follow_link(const struct inode *parent,
75253+ const struct inode *inode,
75254+ const struct dentry *dentry,
75255+ const struct vfsmount *mnt);
75256+int gr_handle_fifo(const struct dentry *dentry,
75257+ const struct vfsmount *mnt,
75258+ const struct dentry *dir, const int flag,
75259+ const int acc_mode);
75260+int gr_handle_hardlink(const struct dentry *dentry,
75261+ const struct vfsmount *mnt,
75262+ struct inode *inode,
75263+ const int mode, const struct filename *to);
75264+
75265+int gr_is_capable(const int cap);
75266+int gr_is_capable_nolog(const int cap);
75267+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
75268+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
75269+
75270+void gr_copy_label(struct task_struct *tsk);
75271+void gr_handle_crash(struct task_struct *task, const int sig);
75272+int gr_handle_signal(const struct task_struct *p, const int sig);
75273+int gr_check_crash_uid(const kuid_t uid);
75274+int gr_check_protected_task(const struct task_struct *task);
75275+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
75276+int gr_acl_handle_mmap(const struct file *file,
75277+ const unsigned long prot);
75278+int gr_acl_handle_mprotect(const struct file *file,
75279+ const unsigned long prot);
75280+int gr_check_hidden_task(const struct task_struct *tsk);
75281+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
75282+ const struct vfsmount *mnt);
75283+__u32 gr_acl_handle_utime(const struct dentry *dentry,
75284+ const struct vfsmount *mnt);
75285+__u32 gr_acl_handle_access(const struct dentry *dentry,
75286+ const struct vfsmount *mnt, const int fmode);
75287+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
75288+ const struct vfsmount *mnt, umode_t *mode);
75289+__u32 gr_acl_handle_chown(const struct dentry *dentry,
75290+ const struct vfsmount *mnt);
75291+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
75292+ const struct vfsmount *mnt);
75293+int gr_handle_ptrace(struct task_struct *task, const long request);
75294+int gr_handle_proc_ptrace(struct task_struct *task);
75295+__u32 gr_acl_handle_execve(const struct dentry *dentry,
75296+ const struct vfsmount *mnt);
75297+int gr_check_crash_exec(const struct file *filp);
75298+int gr_acl_is_enabled(void);
75299+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
75300+ const kgid_t gid);
75301+int gr_set_proc_label(const struct dentry *dentry,
75302+ const struct vfsmount *mnt,
75303+ const int unsafe_flags);
75304+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
75305+ const struct vfsmount *mnt);
75306+__u32 gr_acl_handle_open(const struct dentry *dentry,
75307+ const struct vfsmount *mnt, int acc_mode);
75308+__u32 gr_acl_handle_creat(const struct dentry *dentry,
75309+ const struct dentry *p_dentry,
75310+ const struct vfsmount *p_mnt,
75311+ int open_flags, int acc_mode, const int imode);
75312+void gr_handle_create(const struct dentry *dentry,
75313+ const struct vfsmount *mnt);
75314+void gr_handle_proc_create(const struct dentry *dentry,
75315+ const struct inode *inode);
75316+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
75317+ const struct dentry *parent_dentry,
75318+ const struct vfsmount *parent_mnt,
75319+ const int mode);
75320+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
75321+ const struct dentry *parent_dentry,
75322+ const struct vfsmount *parent_mnt);
75323+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
75324+ const struct vfsmount *mnt);
75325+void gr_handle_delete(const ino_t ino, const dev_t dev);
75326+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
75327+ const struct vfsmount *mnt);
75328+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
75329+ const struct dentry *parent_dentry,
75330+ const struct vfsmount *parent_mnt,
75331+ const struct filename *from);
75332+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
75333+ const struct dentry *parent_dentry,
75334+ const struct vfsmount *parent_mnt,
75335+ const struct dentry *old_dentry,
75336+ const struct vfsmount *old_mnt, const struct filename *to);
75337+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
75338+int gr_acl_handle_rename(struct dentry *new_dentry,
75339+ struct dentry *parent_dentry,
75340+ const struct vfsmount *parent_mnt,
75341+ struct dentry *old_dentry,
75342+ struct inode *old_parent_inode,
75343+ struct vfsmount *old_mnt, const struct filename *newname);
75344+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
75345+ struct dentry *old_dentry,
75346+ struct dentry *new_dentry,
75347+ struct vfsmount *mnt, const __u8 replace);
75348+__u32 gr_check_link(const struct dentry *new_dentry,
75349+ const struct dentry *parent_dentry,
75350+ const struct vfsmount *parent_mnt,
75351+ const struct dentry *old_dentry,
75352+ const struct vfsmount *old_mnt);
75353+int gr_acl_handle_filldir(const struct file *file, const char *name,
75354+ const unsigned int namelen, const ino_t ino);
75355+
75356+__u32 gr_acl_handle_unix(const struct dentry *dentry,
75357+ const struct vfsmount *mnt);
75358+void gr_acl_handle_exit(void);
75359+void gr_acl_handle_psacct(struct task_struct *task, const long code);
75360+int gr_acl_handle_procpidmem(const struct task_struct *task);
75361+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
75362+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
75363+void gr_audit_ptrace(struct task_struct *task);
75364+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
75365+void gr_put_exec_file(struct task_struct *task);
75366+
75367+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
75368+
75369+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
75370+extern void gr_learn_resource(const struct task_struct *task, const int res,
75371+ const unsigned long wanted, const int gt);
75372+#else
75373+static inline void gr_learn_resource(const struct task_struct *task, const int res,
75374+ const unsigned long wanted, const int gt)
75375+{
75376+}
75377+#endif
75378+
75379+#ifdef CONFIG_GRKERNSEC_RESLOG
75380+extern void gr_log_resource(const struct task_struct *task, const int res,
75381+ const unsigned long wanted, const int gt);
75382+#else
75383+static inline void gr_log_resource(const struct task_struct *task, const int res,
75384+ const unsigned long wanted, const int gt)
75385+{
75386+}
75387+#endif
75388+
75389+#ifdef CONFIG_GRKERNSEC
75390+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
75391+void gr_handle_vm86(void);
75392+void gr_handle_mem_readwrite(u64 from, u64 to);
75393+
75394+void gr_log_badprocpid(const char *entry);
75395+
75396+extern int grsec_enable_dmesg;
75397+extern int grsec_disable_privio;
75398+
75399+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75400+extern kgid_t grsec_proc_gid;
75401+#endif
75402+
75403+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75404+extern int grsec_enable_chroot_findtask;
75405+#endif
75406+#ifdef CONFIG_GRKERNSEC_SETXID
75407+extern int grsec_enable_setxid;
75408+#endif
75409+#endif
75410+
75411+#endif
75412diff --git a/include/linux/grsock.h b/include/linux/grsock.h
75413new file mode 100644
75414index 0000000..e7ffaaf
75415--- /dev/null
75416+++ b/include/linux/grsock.h
75417@@ -0,0 +1,19 @@
75418+#ifndef __GRSOCK_H
75419+#define __GRSOCK_H
75420+
75421+extern void gr_attach_curr_ip(const struct sock *sk);
75422+extern int gr_handle_sock_all(const int family, const int type,
75423+ const int protocol);
75424+extern int gr_handle_sock_server(const struct sockaddr *sck);
75425+extern int gr_handle_sock_server_other(const struct sock *sck);
75426+extern int gr_handle_sock_client(const struct sockaddr *sck);
75427+extern int gr_search_connect(struct socket * sock,
75428+ struct sockaddr_in * addr);
75429+extern int gr_search_bind(struct socket * sock,
75430+ struct sockaddr_in * addr);
75431+extern int gr_search_listen(struct socket * sock);
75432+extern int gr_search_accept(struct socket * sock);
75433+extern int gr_search_socket(const int domain, const int type,
75434+ const int protocol);
75435+
75436+#endif
75437diff --git a/include/linux/highmem.h b/include/linux/highmem.h
75438index 7fb31da..08b5114 100644
75439--- a/include/linux/highmem.h
75440+++ b/include/linux/highmem.h
75441@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
75442 kunmap_atomic(kaddr);
75443 }
75444
75445+static inline void sanitize_highpage(struct page *page)
75446+{
75447+ void *kaddr;
75448+ unsigned long flags;
75449+
75450+ local_irq_save(flags);
75451+ kaddr = kmap_atomic(page);
75452+ clear_page(kaddr);
75453+ kunmap_atomic(kaddr);
75454+ local_irq_restore(flags);
75455+}
75456+
75457 static inline void zero_user_segments(struct page *page,
75458 unsigned start1, unsigned end1,
75459 unsigned start2, unsigned end2)
75460diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
75461index 1c7b89a..7dda400 100644
75462--- a/include/linux/hwmon-sysfs.h
75463+++ b/include/linux/hwmon-sysfs.h
75464@@ -25,7 +25,8 @@
75465 struct sensor_device_attribute{
75466 struct device_attribute dev_attr;
75467 int index;
75468-};
75469+} __do_const;
75470+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
75471 #define to_sensor_dev_attr(_dev_attr) \
75472 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
75473
75474@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
75475 struct device_attribute dev_attr;
75476 u8 index;
75477 u8 nr;
75478-};
75479+} __do_const;
75480+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
75481 #define to_sensor_dev_attr_2(_dev_attr) \
75482 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
75483
75484diff --git a/include/linux/i2c.h b/include/linux/i2c.h
75485index 2ab11dc..663a3f2 100644
75486--- a/include/linux/i2c.h
75487+++ b/include/linux/i2c.h
75488@@ -366,6 +366,7 @@ struct i2c_algorithm {
75489 /* To determine what the adapter supports */
75490 u32 (*functionality) (struct i2c_adapter *);
75491 };
75492+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
75493
75494 /**
75495 * struct i2c_bus_recovery_info - I2C bus recovery information
75496diff --git a/include/linux/i2o.h b/include/linux/i2o.h
75497index d23c3c2..eb63c81 100644
75498--- a/include/linux/i2o.h
75499+++ b/include/linux/i2o.h
75500@@ -565,7 +565,7 @@ struct i2o_controller {
75501 struct i2o_device *exec; /* Executive */
75502 #if BITS_PER_LONG == 64
75503 spinlock_t context_list_lock; /* lock for context_list */
75504- atomic_t context_list_counter; /* needed for unique contexts */
75505+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
75506 struct list_head context_list; /* list of context id's
75507 and pointers */
75508 #endif
75509diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
75510index aff7ad8..3942bbd 100644
75511--- a/include/linux/if_pppox.h
75512+++ b/include/linux/if_pppox.h
75513@@ -76,7 +76,7 @@ struct pppox_proto {
75514 int (*ioctl)(struct socket *sock, unsigned int cmd,
75515 unsigned long arg);
75516 struct module *owner;
75517-};
75518+} __do_const;
75519
75520 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
75521 extern void unregister_pppox_proto(int proto_num);
75522diff --git a/include/linux/init.h b/include/linux/init.h
75523index f1c27a71..7d6010e 100644
75524--- a/include/linux/init.h
75525+++ b/include/linux/init.h
75526@@ -39,9 +39,17 @@
75527 * Also note, that this data cannot be "const".
75528 */
75529
75530+#define add_init_latent_entropy __latent_entropy
75531+
75532+#ifdef CONFIG_MEMORY_HOTPLUG
75533+#define add_meminit_latent_entropy
75534+#else
75535+#define add_meminit_latent_entropy __latent_entropy
75536+#endif
75537+
75538 /* These are for everybody (although not all archs will actually
75539 discard it in modules) */
75540-#define __init __section(.init.text) __cold notrace
75541+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
75542 #define __initdata __section(.init.data)
75543 #define __initconst __constsection(.init.rodata)
75544 #define __exitdata __section(.exit.data)
75545@@ -102,7 +110,7 @@
75546 #define __cpuexitconst
75547
75548 /* Used for MEMORY_HOTPLUG */
75549-#define __meminit __section(.meminit.text) __cold notrace
75550+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
75551 #define __meminitdata __section(.meminit.data)
75552 #define __meminitconst __constsection(.meminit.rodata)
75553 #define __memexit __section(.memexit.text) __exitused __cold notrace
75554diff --git a/include/linux/init_task.h b/include/linux/init_task.h
75555index 5cd0f09..c9f67cc 100644
75556--- a/include/linux/init_task.h
75557+++ b/include/linux/init_task.h
75558@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
75559
75560 #define INIT_TASK_COMM "swapper"
75561
75562+#ifdef CONFIG_X86
75563+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
75564+#else
75565+#define INIT_TASK_THREAD_INFO
75566+#endif
75567+
75568 /*
75569 * INIT_TASK is used to set up the first task table, touch at
75570 * your own risk!. Base=0, limit=0x1fffff (=2MB)
75571@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
75572 RCU_POINTER_INITIALIZER(cred, &init_cred), \
75573 .comm = INIT_TASK_COMM, \
75574 .thread = INIT_THREAD, \
75575+ INIT_TASK_THREAD_INFO \
75576 .fs = &init_fs, \
75577 .files = &init_files, \
75578 .signal = &init_signals, \
75579diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
75580index 5e865b5..71bd258 100644
75581--- a/include/linux/interrupt.h
75582+++ b/include/linux/interrupt.h
75583@@ -361,7 +361,7 @@ enum
75584 /* map softirq index to softirq name. update 'softirq_to_name' in
75585 * kernel/softirq.c when adding a new softirq.
75586 */
75587-extern char *softirq_to_name[NR_SOFTIRQS];
75588+extern const char * const softirq_to_name[NR_SOFTIRQS];
75589
75590 /* softirq mask and active fields moved to irq_cpustat_t in
75591 * asm/hardirq.h to get better cache usage. KAO
75592@@ -369,12 +369,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
75593
75594 struct softirq_action
75595 {
75596- void (*action)(struct softirq_action *);
75597-};
75598+ void (*action)(void);
75599+} __no_const;
75600
75601 asmlinkage void do_softirq(void);
75602 asmlinkage void __do_softirq(void);
75603-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
75604+extern void open_softirq(int nr, void (*action)(void));
75605 extern void softirq_init(void);
75606 extern void __raise_softirq_irqoff(unsigned int nr);
75607
75608diff --git a/include/linux/iommu.h b/include/linux/iommu.h
75609index 7ea319e..f9e971d 100644
75610--- a/include/linux/iommu.h
75611+++ b/include/linux/iommu.h
75612@@ -129,7 +129,7 @@ struct iommu_ops {
75613 u32 (*domain_get_windows)(struct iommu_domain *domain);
75614
75615 unsigned long pgsize_bitmap;
75616-};
75617+} __do_const;
75618
75619 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
75620 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
75621diff --git a/include/linux/ioport.h b/include/linux/ioport.h
75622index 89b7c24..382af74 100644
75623--- a/include/linux/ioport.h
75624+++ b/include/linux/ioport.h
75625@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
75626 int adjust_resource(struct resource *res, resource_size_t start,
75627 resource_size_t size);
75628 resource_size_t resource_alignment(struct resource *res);
75629-static inline resource_size_t resource_size(const struct resource *res)
75630+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
75631 {
75632 return res->end - res->start + 1;
75633 }
75634diff --git a/include/linux/irq.h b/include/linux/irq.h
75635index 56bb0dc..8ae94d62 100644
75636--- a/include/linux/irq.h
75637+++ b/include/linux/irq.h
75638@@ -333,7 +333,8 @@ struct irq_chip {
75639 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
75640
75641 unsigned long flags;
75642-};
75643+} __do_const;
75644+typedef struct irq_chip __no_const irq_chip_no_const;
75645
75646 /*
75647 * irq_chip specific flags
75648diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
75649index 0e5d9ec..46acb3a 100644
75650--- a/include/linux/irqchip/arm-gic.h
75651+++ b/include/linux/irqchip/arm-gic.h
75652@@ -59,9 +59,11 @@
75653
75654 #ifndef __ASSEMBLY__
75655
75656+#include <linux/irq.h>
75657+
75658 struct device_node;
75659
75660-extern struct irq_chip gic_arch_extn;
75661+extern irq_chip_no_const gic_arch_extn;
75662
75663 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
75664 u32 offset, struct device_node *);
75665diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
75666index d235e88..8ccbe74 100644
75667--- a/include/linux/jiffies.h
75668+++ b/include/linux/jiffies.h
75669@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
75670 /*
75671 * Convert various time units to each other:
75672 */
75673-extern unsigned int jiffies_to_msecs(const unsigned long j);
75674-extern unsigned int jiffies_to_usecs(const unsigned long j);
75675-extern unsigned long msecs_to_jiffies(const unsigned int m);
75676-extern unsigned long usecs_to_jiffies(const unsigned int u);
75677-extern unsigned long timespec_to_jiffies(const struct timespec *value);
75678+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
75679+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
75680+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
75681+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
75682+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
75683 extern void jiffies_to_timespec(const unsigned long jiffies,
75684 struct timespec *value);
75685-extern unsigned long timeval_to_jiffies(const struct timeval *value);
75686+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
75687 extern void jiffies_to_timeval(const unsigned long jiffies,
75688 struct timeval *value);
75689
75690diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
75691index 6883e19..e854fcb 100644
75692--- a/include/linux/kallsyms.h
75693+++ b/include/linux/kallsyms.h
75694@@ -15,7 +15,8 @@
75695
75696 struct module;
75697
75698-#ifdef CONFIG_KALLSYMS
75699+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
75700+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75701 /* Lookup the address for a symbol. Returns 0 if not found. */
75702 unsigned long kallsyms_lookup_name(const char *name);
75703
75704@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
75705 /* Stupid that this does nothing, but I didn't create this mess. */
75706 #define __print_symbol(fmt, addr)
75707 #endif /*CONFIG_KALLSYMS*/
75708+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
75709+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
75710+extern unsigned long kallsyms_lookup_name(const char *name);
75711+extern void __print_symbol(const char *fmt, unsigned long address);
75712+extern int sprint_backtrace(char *buffer, unsigned long address);
75713+extern int sprint_symbol(char *buffer, unsigned long address);
75714+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
75715+const char *kallsyms_lookup(unsigned long addr,
75716+ unsigned long *symbolsize,
75717+ unsigned long *offset,
75718+ char **modname, char *namebuf);
75719+extern int kallsyms_lookup_size_offset(unsigned long addr,
75720+ unsigned long *symbolsize,
75721+ unsigned long *offset);
75722+#endif
75723
75724 /* This macro allows us to keep printk typechecking */
75725 static __printf(1, 2)
75726diff --git a/include/linux/key-type.h b/include/linux/key-type.h
75727index 518a53a..5e28358 100644
75728--- a/include/linux/key-type.h
75729+++ b/include/linux/key-type.h
75730@@ -125,7 +125,7 @@ struct key_type {
75731 /* internal fields */
75732 struct list_head link; /* link in types list */
75733 struct lock_class_key lock_class; /* key->sem lock class */
75734-};
75735+} __do_const;
75736
75737 extern struct key_type key_type_keyring;
75738
75739diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
75740index c6e091b..a940adf 100644
75741--- a/include/linux/kgdb.h
75742+++ b/include/linux/kgdb.h
75743@@ -52,7 +52,7 @@ extern int kgdb_connected;
75744 extern int kgdb_io_module_registered;
75745
75746 extern atomic_t kgdb_setting_breakpoint;
75747-extern atomic_t kgdb_cpu_doing_single_step;
75748+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
75749
75750 extern struct task_struct *kgdb_usethread;
75751 extern struct task_struct *kgdb_contthread;
75752@@ -254,7 +254,7 @@ struct kgdb_arch {
75753 void (*correct_hw_break)(void);
75754
75755 void (*enable_nmi)(bool on);
75756-};
75757+} __do_const;
75758
75759 /**
75760 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
75761@@ -279,7 +279,7 @@ struct kgdb_io {
75762 void (*pre_exception) (void);
75763 void (*post_exception) (void);
75764 int is_console;
75765-};
75766+} __do_const;
75767
75768 extern struct kgdb_arch arch_kgdb_ops;
75769
75770diff --git a/include/linux/kmod.h b/include/linux/kmod.h
75771index 0555cc6..40116ce 100644
75772--- a/include/linux/kmod.h
75773+++ b/include/linux/kmod.h
75774@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
75775 * usually useless though. */
75776 extern __printf(2, 3)
75777 int __request_module(bool wait, const char *name, ...);
75778+extern __printf(3, 4)
75779+int ___request_module(bool wait, char *param_name, const char *name, ...);
75780 #define request_module(mod...) __request_module(true, mod)
75781 #define request_module_nowait(mod...) __request_module(false, mod)
75782 #define try_then_request_module(x, mod...) \
75783@@ -57,6 +59,9 @@ struct subprocess_info {
75784 struct work_struct work;
75785 struct completion *complete;
75786 char *path;
75787+#ifdef CONFIG_GRKERNSEC
75788+ char *origpath;
75789+#endif
75790 char **argv;
75791 char **envp;
75792 int wait;
75793diff --git a/include/linux/kobject.h b/include/linux/kobject.h
75794index de6dcbcc..4735f88 100644
75795--- a/include/linux/kobject.h
75796+++ b/include/linux/kobject.h
75797@@ -115,7 +115,7 @@ struct kobj_type {
75798 struct attribute **default_attrs;
75799 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
75800 const void *(*namespace)(struct kobject *kobj);
75801-};
75802+} __do_const;
75803
75804 struct kobj_uevent_env {
75805 char *envp[UEVENT_NUM_ENVP];
75806@@ -138,6 +138,7 @@ struct kobj_attribute {
75807 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
75808 const char *buf, size_t count);
75809 };
75810+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
75811
75812 extern const struct sysfs_ops kobj_sysfs_ops;
75813
75814diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
75815index df32d25..fb52e27 100644
75816--- a/include/linux/kobject_ns.h
75817+++ b/include/linux/kobject_ns.h
75818@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
75819 const void *(*netlink_ns)(struct sock *sk);
75820 const void *(*initial_ns)(void);
75821 void (*drop_ns)(void *);
75822-};
75823+} __do_const;
75824
75825 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
75826 int kobj_ns_type_registered(enum kobj_ns_type type);
75827diff --git a/include/linux/kref.h b/include/linux/kref.h
75828index 484604d..0f6c5b6 100644
75829--- a/include/linux/kref.h
75830+++ b/include/linux/kref.h
75831@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
75832 static inline int kref_sub(struct kref *kref, unsigned int count,
75833 void (*release)(struct kref *kref))
75834 {
75835- WARN_ON(release == NULL);
75836+ BUG_ON(release == NULL);
75837
75838 if (atomic_sub_and_test((int) count, &kref->refcount)) {
75839 release(kref);
75840diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
75841index 0fbbc7a..db081e3 100644
75842--- a/include/linux/kvm_host.h
75843+++ b/include/linux/kvm_host.h
75844@@ -458,7 +458,7 @@ static inline void kvm_irqfd_exit(void)
75845 {
75846 }
75847 #endif
75848-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
75849+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
75850 struct module *module);
75851 void kvm_exit(void);
75852
75853@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
75854 struct kvm_guest_debug *dbg);
75855 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
75856
75857-int kvm_arch_init(void *opaque);
75858+int kvm_arch_init(const void *opaque);
75859 void kvm_arch_exit(void);
75860
75861 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
75862diff --git a/include/linux/libata.h b/include/linux/libata.h
75863index 0e23c26..6ad8c33 100644
75864--- a/include/linux/libata.h
75865+++ b/include/linux/libata.h
75866@@ -972,7 +972,7 @@ struct ata_port_operations {
75867 * fields must be pointers.
75868 */
75869 const struct ata_port_operations *inherits;
75870-};
75871+} __do_const;
75872
75873 struct ata_port_info {
75874 unsigned long flags;
75875diff --git a/include/linux/linkage.h b/include/linux/linkage.h
75876index d3e8ad2..a949f68 100644
75877--- a/include/linux/linkage.h
75878+++ b/include/linux/linkage.h
75879@@ -31,6 +31,7 @@
75880 #endif
75881
75882 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
75883+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
75884 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
75885
75886 /*
75887diff --git a/include/linux/list.h b/include/linux/list.h
75888index f4d8a2f..38e6e46 100644
75889--- a/include/linux/list.h
75890+++ b/include/linux/list.h
75891@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
75892 extern void list_del(struct list_head *entry);
75893 #endif
75894
75895+extern void __pax_list_add(struct list_head *new,
75896+ struct list_head *prev,
75897+ struct list_head *next);
75898+static inline void pax_list_add(struct list_head *new, struct list_head *head)
75899+{
75900+ __pax_list_add(new, head, head->next);
75901+}
75902+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
75903+{
75904+ __pax_list_add(new, head->prev, head);
75905+}
75906+extern void pax_list_del(struct list_head *entry);
75907+
75908 /**
75909 * list_replace - replace old entry by new one
75910 * @old : the element to be replaced
75911@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
75912 INIT_LIST_HEAD(entry);
75913 }
75914
75915+extern void pax_list_del_init(struct list_head *entry);
75916+
75917 /**
75918 * list_move - delete from one list and add as another's head
75919 * @list: the entry to move
75920diff --git a/include/linux/math64.h b/include/linux/math64.h
75921index 69ed5f5..243ed51 100644
75922--- a/include/linux/math64.h
75923+++ b/include/linux/math64.h
75924@@ -15,7 +15,7 @@
75925 * This is commonly provided by 32bit archs to provide an optimized 64bit
75926 * divide.
75927 */
75928-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75929+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75930 {
75931 *remainder = dividend % divisor;
75932 return dividend / divisor;
75933@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
75934 /**
75935 * div64_u64 - unsigned 64bit divide with 64bit divisor
75936 */
75937-static inline u64 div64_u64(u64 dividend, u64 divisor)
75938+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
75939 {
75940 return dividend / divisor;
75941 }
75942@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
75943 #define div64_ul(x, y) div_u64((x), (y))
75944
75945 #ifndef div_u64_rem
75946-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75947+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75948 {
75949 *remainder = do_div(dividend, divisor);
75950 return dividend;
75951@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
75952 #endif
75953
75954 #ifndef div64_u64
75955-extern u64 div64_u64(u64 dividend, u64 divisor);
75956+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
75957 #endif
75958
75959 #ifndef div64_s64
75960@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
75961 * divide.
75962 */
75963 #ifndef div_u64
75964-static inline u64 div_u64(u64 dividend, u32 divisor)
75965+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
75966 {
75967 u32 remainder;
75968 return div_u64_rem(dividend, divisor, &remainder);
75969diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
75970index da6716b..2e31db3 100644
75971--- a/include/linux/mempolicy.h
75972+++ b/include/linux/mempolicy.h
75973@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
75974 }
75975
75976 #define vma_policy(vma) ((vma)->vm_policy)
75977+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
75978+{
75979+ vma->vm_policy = pol;
75980+}
75981
75982 static inline void mpol_get(struct mempolicy *pol)
75983 {
75984@@ -240,6 +244,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
75985 }
75986
75987 #define vma_policy(vma) NULL
75988+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
75989+{
75990+}
75991
75992 static inline int
75993 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
75994diff --git a/include/linux/mm.h b/include/linux/mm.h
75995index 8b6e55e..c4edf39 100644
75996--- a/include/linux/mm.h
75997+++ b/include/linux/mm.h
75998@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
75999 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
76000 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
76001 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
76002+
76003+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76004+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
76005+#endif
76006+
76007 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
76008
76009 #ifdef CONFIG_MEM_SOFT_DIRTY
76010@@ -215,8 +220,8 @@ struct vm_operations_struct {
76011 /* called by access_process_vm when get_user_pages() fails, typically
76012 * for use by special VMAs that can switch between memory and hardware
76013 */
76014- int (*access)(struct vm_area_struct *vma, unsigned long addr,
76015- void *buf, int len, int write);
76016+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
76017+ void *buf, size_t len, int write);
76018 #ifdef CONFIG_NUMA
76019 /*
76020 * set_policy() op must add a reference to any non-NULL @new mempolicy
76021@@ -246,6 +251,7 @@ struct vm_operations_struct {
76022 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
76023 unsigned long size, pgoff_t pgoff);
76024 };
76025+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
76026
76027 struct mmu_gather;
76028 struct inode;
76029@@ -977,8 +983,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
76030 unsigned long *pfn);
76031 int follow_phys(struct vm_area_struct *vma, unsigned long address,
76032 unsigned int flags, unsigned long *prot, resource_size_t *phys);
76033-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76034- void *buf, int len, int write);
76035+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76036+ void *buf, size_t len, int write);
76037
76038 static inline void unmap_shared_mapping_range(struct address_space *mapping,
76039 loff_t const holebegin, loff_t const holelen)
76040@@ -1017,9 +1023,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
76041 }
76042 #endif
76043
76044-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
76045-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
76046- void *buf, int len, int write);
76047+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
76048+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
76049+ void *buf, size_t len, int write);
76050
76051 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76052 unsigned long start, unsigned long nr_pages,
76053@@ -1051,34 +1057,6 @@ int set_page_dirty(struct page *page);
76054 int set_page_dirty_lock(struct page *page);
76055 int clear_page_dirty_for_io(struct page *page);
76056
76057-/* Is the vma a continuation of the stack vma above it? */
76058-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
76059-{
76060- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
76061-}
76062-
76063-static inline int stack_guard_page_start(struct vm_area_struct *vma,
76064- unsigned long addr)
76065-{
76066- return (vma->vm_flags & VM_GROWSDOWN) &&
76067- (vma->vm_start == addr) &&
76068- !vma_growsdown(vma->vm_prev, addr);
76069-}
76070-
76071-/* Is the vma a continuation of the stack vma below it? */
76072-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
76073-{
76074- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
76075-}
76076-
76077-static inline int stack_guard_page_end(struct vm_area_struct *vma,
76078- unsigned long addr)
76079-{
76080- return (vma->vm_flags & VM_GROWSUP) &&
76081- (vma->vm_end == addr) &&
76082- !vma_growsup(vma->vm_next, addr);
76083-}
76084-
76085 extern pid_t
76086 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
76087
76088@@ -1178,6 +1156,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
76089 }
76090 #endif
76091
76092+#ifdef CONFIG_MMU
76093+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
76094+#else
76095+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76096+{
76097+ return __pgprot(0);
76098+}
76099+#endif
76100+
76101 int vma_wants_writenotify(struct vm_area_struct *vma);
76102
76103 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
76104@@ -1196,8 +1183,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
76105 {
76106 return 0;
76107 }
76108+
76109+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
76110+ unsigned long address)
76111+{
76112+ return 0;
76113+}
76114 #else
76115 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76116+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76117 #endif
76118
76119 #ifdef __PAGETABLE_PMD_FOLDED
76120@@ -1206,8 +1200,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
76121 {
76122 return 0;
76123 }
76124+
76125+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
76126+ unsigned long address)
76127+{
76128+ return 0;
76129+}
76130 #else
76131 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
76132+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
76133 #endif
76134
76135 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
76136@@ -1225,11 +1226,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
76137 NULL: pud_offset(pgd, address);
76138 }
76139
76140+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76141+{
76142+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
76143+ NULL: pud_offset(pgd, address);
76144+}
76145+
76146 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76147 {
76148 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
76149 NULL: pmd_offset(pud, address);
76150 }
76151+
76152+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76153+{
76154+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
76155+ NULL: pmd_offset(pud, address);
76156+}
76157 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
76158
76159 #if USE_SPLIT_PTLOCKS
76160@@ -1517,7 +1530,7 @@ extern int install_special_mapping(struct mm_struct *mm,
76161 unsigned long addr, unsigned long len,
76162 unsigned long flags, struct page **pages);
76163
76164-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
76165+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
76166
76167 extern unsigned long mmap_region(struct file *file, unsigned long addr,
76168 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
76169@@ -1525,6 +1538,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76170 unsigned long len, unsigned long prot, unsigned long flags,
76171 unsigned long pgoff, unsigned long *populate);
76172 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
76173+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
76174
76175 #ifdef CONFIG_MMU
76176 extern int __mm_populate(unsigned long addr, unsigned long len,
76177@@ -1553,10 +1567,11 @@ struct vm_unmapped_area_info {
76178 unsigned long high_limit;
76179 unsigned long align_mask;
76180 unsigned long align_offset;
76181+ unsigned long threadstack_offset;
76182 };
76183
76184-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
76185-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76186+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
76187+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
76188
76189 /*
76190 * Search for an unmapped address range.
76191@@ -1568,7 +1583,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76192 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
76193 */
76194 static inline unsigned long
76195-vm_unmapped_area(struct vm_unmapped_area_info *info)
76196+vm_unmapped_area(const struct vm_unmapped_area_info *info)
76197 {
76198 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
76199 return unmapped_area(info);
76200@@ -1631,6 +1646,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
76201 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
76202 struct vm_area_struct **pprev);
76203
76204+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
76205+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
76206+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
76207+
76208 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
76209 NULL if none. Assume start_addr < end_addr. */
76210 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
76211@@ -1659,15 +1678,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
76212 return vma;
76213 }
76214
76215-#ifdef CONFIG_MMU
76216-pgprot_t vm_get_page_prot(unsigned long vm_flags);
76217-#else
76218-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
76219-{
76220- return __pgprot(0);
76221-}
76222-#endif
76223-
76224 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
76225 unsigned long change_prot_numa(struct vm_area_struct *vma,
76226 unsigned long start, unsigned long end);
76227@@ -1719,6 +1729,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
76228 static inline void vm_stat_account(struct mm_struct *mm,
76229 unsigned long flags, struct file *file, long pages)
76230 {
76231+
76232+#ifdef CONFIG_PAX_RANDMMAP
76233+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
76234+#endif
76235+
76236 mm->total_vm += pages;
76237 }
76238 #endif /* CONFIG_PROC_FS */
76239@@ -1800,7 +1815,7 @@ extern int unpoison_memory(unsigned long pfn);
76240 extern int sysctl_memory_failure_early_kill;
76241 extern int sysctl_memory_failure_recovery;
76242 extern void shake_page(struct page *p, int access);
76243-extern atomic_long_t num_poisoned_pages;
76244+extern atomic_long_unchecked_t num_poisoned_pages;
76245 extern int soft_offline_page(struct page *page, int flags);
76246
76247 extern void dump_page(struct page *page);
76248@@ -1837,5 +1852,11 @@ void __init setup_nr_node_ids(void);
76249 static inline void setup_nr_node_ids(void) {}
76250 #endif
76251
76252+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76253+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
76254+#else
76255+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
76256+#endif
76257+
76258 #endif /* __KERNEL__ */
76259 #endif /* _LINUX_MM_H */
76260diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
76261index d9851ee..619492d 100644
76262--- a/include/linux/mm_types.h
76263+++ b/include/linux/mm_types.h
76264@@ -289,6 +289,8 @@ struct vm_area_struct {
76265 #ifdef CONFIG_NUMA
76266 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
76267 #endif
76268+
76269+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
76270 };
76271
76272 struct core_thread {
76273@@ -436,6 +438,24 @@ struct mm_struct {
76274 int first_nid;
76275 #endif
76276 struct uprobes_state uprobes_state;
76277+
76278+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76279+ unsigned long pax_flags;
76280+#endif
76281+
76282+#ifdef CONFIG_PAX_DLRESOLVE
76283+ unsigned long call_dl_resolve;
76284+#endif
76285+
76286+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
76287+ unsigned long call_syscall;
76288+#endif
76289+
76290+#ifdef CONFIG_PAX_ASLR
76291+ unsigned long delta_mmap; /* randomized offset */
76292+ unsigned long delta_stack; /* randomized offset */
76293+#endif
76294+
76295 };
76296
76297 /* first nid will either be a valid NID or one of these values */
76298diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
76299index c5d5278..f0b68c8 100644
76300--- a/include/linux/mmiotrace.h
76301+++ b/include/linux/mmiotrace.h
76302@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
76303 /* Called from ioremap.c */
76304 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
76305 void __iomem *addr);
76306-extern void mmiotrace_iounmap(volatile void __iomem *addr);
76307+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
76308
76309 /* For anyone to insert markers. Remember trailing newline. */
76310 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
76311@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
76312 {
76313 }
76314
76315-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
76316+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
76317 {
76318 }
76319
76320diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
76321index bd791e4..8617c34f 100644
76322--- a/include/linux/mmzone.h
76323+++ b/include/linux/mmzone.h
76324@@ -396,7 +396,7 @@ struct zone {
76325 unsigned long flags; /* zone flags, see below */
76326
76327 /* Zone statistics */
76328- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76329+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76330
76331 /*
76332 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
76333diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
76334index 45e9214..a7227d6 100644
76335--- a/include/linux/mod_devicetable.h
76336+++ b/include/linux/mod_devicetable.h
76337@@ -13,7 +13,7 @@
76338 typedef unsigned long kernel_ulong_t;
76339 #endif
76340
76341-#define PCI_ANY_ID (~0)
76342+#define PCI_ANY_ID ((__u16)~0)
76343
76344 struct pci_device_id {
76345 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
76346@@ -139,7 +139,7 @@ struct usb_device_id {
76347 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
76348 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
76349
76350-#define HID_ANY_ID (~0)
76351+#define HID_ANY_ID (~0U)
76352 #define HID_BUS_ANY 0xffff
76353 #define HID_GROUP_ANY 0x0000
76354
76355@@ -467,7 +467,7 @@ struct dmi_system_id {
76356 const char *ident;
76357 struct dmi_strmatch matches[4];
76358 void *driver_data;
76359-};
76360+} __do_const;
76361 /*
76362 * struct dmi_device_id appears during expansion of
76363 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
76364diff --git a/include/linux/module.h b/include/linux/module.h
76365index 05f2447..2aee07c 100644
76366--- a/include/linux/module.h
76367+++ b/include/linux/module.h
76368@@ -17,9 +17,11 @@
76369 #include <linux/moduleparam.h>
76370 #include <linux/tracepoint.h>
76371 #include <linux/export.h>
76372+#include <linux/fs.h>
76373
76374 #include <linux/percpu.h>
76375 #include <asm/module.h>
76376+#include <asm/pgtable.h>
76377
76378 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
76379 #define MODULE_SIG_STRING "~Module signature appended~\n"
76380@@ -55,12 +57,13 @@ struct module_attribute {
76381 int (*test)(struct module *);
76382 void (*free)(struct module *);
76383 };
76384+typedef struct module_attribute __no_const module_attribute_no_const;
76385
76386 struct module_version_attribute {
76387 struct module_attribute mattr;
76388 const char *module_name;
76389 const char *version;
76390-} __attribute__ ((__aligned__(sizeof(void *))));
76391+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
76392
76393 extern ssize_t __modver_version_show(struct module_attribute *,
76394 struct module_kobject *, char *);
76395@@ -238,7 +241,7 @@ struct module
76396
76397 /* Sysfs stuff. */
76398 struct module_kobject mkobj;
76399- struct module_attribute *modinfo_attrs;
76400+ module_attribute_no_const *modinfo_attrs;
76401 const char *version;
76402 const char *srcversion;
76403 struct kobject *holders_dir;
76404@@ -287,19 +290,16 @@ struct module
76405 int (*init)(void);
76406
76407 /* If this is non-NULL, vfree after init() returns */
76408- void *module_init;
76409+ void *module_init_rx, *module_init_rw;
76410
76411 /* Here is the actual code + data, vfree'd on unload. */
76412- void *module_core;
76413+ void *module_core_rx, *module_core_rw;
76414
76415 /* Here are the sizes of the init and core sections */
76416- unsigned int init_size, core_size;
76417+ unsigned int init_size_rw, core_size_rw;
76418
76419 /* The size of the executable code in each section. */
76420- unsigned int init_text_size, core_text_size;
76421-
76422- /* Size of RO sections of the module (text+rodata) */
76423- unsigned int init_ro_size, core_ro_size;
76424+ unsigned int init_size_rx, core_size_rx;
76425
76426 /* Arch-specific module values */
76427 struct mod_arch_specific arch;
76428@@ -355,6 +355,10 @@ struct module
76429 #ifdef CONFIG_EVENT_TRACING
76430 struct ftrace_event_call **trace_events;
76431 unsigned int num_trace_events;
76432+ struct file_operations trace_id;
76433+ struct file_operations trace_enable;
76434+ struct file_operations trace_format;
76435+ struct file_operations trace_filter;
76436 #endif
76437 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
76438 unsigned int num_ftrace_callsites;
76439@@ -402,16 +406,46 @@ bool is_module_address(unsigned long addr);
76440 bool is_module_percpu_address(unsigned long addr);
76441 bool is_module_text_address(unsigned long addr);
76442
76443+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
76444+{
76445+
76446+#ifdef CONFIG_PAX_KERNEXEC
76447+ if (ktla_ktva(addr) >= (unsigned long)start &&
76448+ ktla_ktva(addr) < (unsigned long)start + size)
76449+ return 1;
76450+#endif
76451+
76452+ return ((void *)addr >= start && (void *)addr < start + size);
76453+}
76454+
76455+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
76456+{
76457+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
76458+}
76459+
76460+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
76461+{
76462+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
76463+}
76464+
76465+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
76466+{
76467+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
76468+}
76469+
76470+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
76471+{
76472+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
76473+}
76474+
76475 static inline int within_module_core(unsigned long addr, const struct module *mod)
76476 {
76477- return (unsigned long)mod->module_core <= addr &&
76478- addr < (unsigned long)mod->module_core + mod->core_size;
76479+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
76480 }
76481
76482 static inline int within_module_init(unsigned long addr, const struct module *mod)
76483 {
76484- return (unsigned long)mod->module_init <= addr &&
76485- addr < (unsigned long)mod->module_init + mod->init_size;
76486+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
76487 }
76488
76489 /* Search for module by name: must hold module_mutex. */
76490diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
76491index 560ca53..ef621ef 100644
76492--- a/include/linux/moduleloader.h
76493+++ b/include/linux/moduleloader.h
76494@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
76495 sections. Returns NULL on failure. */
76496 void *module_alloc(unsigned long size);
76497
76498+#ifdef CONFIG_PAX_KERNEXEC
76499+void *module_alloc_exec(unsigned long size);
76500+#else
76501+#define module_alloc_exec(x) module_alloc(x)
76502+#endif
76503+
76504 /* Free memory returned from module_alloc. */
76505 void module_free(struct module *mod, void *module_region);
76506
76507+#ifdef CONFIG_PAX_KERNEXEC
76508+void module_free_exec(struct module *mod, void *module_region);
76509+#else
76510+#define module_free_exec(x, y) module_free((x), (y))
76511+#endif
76512+
76513 /*
76514 * Apply the given relocation to the (simplified) ELF. Return -error
76515 * or 0.
76516@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
76517 unsigned int relsec,
76518 struct module *me)
76519 {
76520+#ifdef CONFIG_MODULES
76521 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76522+#endif
76523 return -ENOEXEC;
76524 }
76525 #endif
76526@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
76527 unsigned int relsec,
76528 struct module *me)
76529 {
76530+#ifdef CONFIG_MODULES
76531 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76532+#endif
76533 return -ENOEXEC;
76534 }
76535 #endif
76536diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
76537index c3eb102..073c4a6 100644
76538--- a/include/linux/moduleparam.h
76539+++ b/include/linux/moduleparam.h
76540@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
76541 * @len is usually just sizeof(string).
76542 */
76543 #define module_param_string(name, string, len, perm) \
76544- static const struct kparam_string __param_string_##name \
76545+ static const struct kparam_string __param_string_##name __used \
76546 = { len, string }; \
76547 __module_param_call(MODULE_PARAM_PREFIX, name, \
76548 &param_ops_string, \
76549@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
76550 */
76551 #define module_param_array_named(name, array, type, nump, perm) \
76552 param_check_##type(name, &(array)[0]); \
76553- static const struct kparam_array __param_arr_##name \
76554+ static const struct kparam_array __param_arr_##name __used \
76555 = { .max = ARRAY_SIZE(array), .num = nump, \
76556 .ops = &param_ops_##type, \
76557 .elemsize = sizeof(array[0]), .elem = array }; \
76558diff --git a/include/linux/namei.h b/include/linux/namei.h
76559index 8e47bc7..c70fd73 100644
76560--- a/include/linux/namei.h
76561+++ b/include/linux/namei.h
76562@@ -19,7 +19,7 @@ struct nameidata {
76563 unsigned seq;
76564 int last_type;
76565 unsigned depth;
76566- char *saved_names[MAX_NESTED_LINKS + 1];
76567+ const char *saved_names[MAX_NESTED_LINKS + 1];
76568 };
76569
76570 /*
76571@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
76572
76573 extern void nd_jump_link(struct nameidata *nd, struct path *path);
76574
76575-static inline void nd_set_link(struct nameidata *nd, char *path)
76576+static inline void nd_set_link(struct nameidata *nd, const char *path)
76577 {
76578 nd->saved_names[nd->depth] = path;
76579 }
76580
76581-static inline char *nd_get_link(struct nameidata *nd)
76582+static inline const char *nd_get_link(const struct nameidata *nd)
76583 {
76584 return nd->saved_names[nd->depth];
76585 }
76586diff --git a/include/linux/net.h b/include/linux/net.h
76587index 4f27575..fc8a65f 100644
76588--- a/include/linux/net.h
76589+++ b/include/linux/net.h
76590@@ -183,7 +183,7 @@ struct net_proto_family {
76591 int (*create)(struct net *net, struct socket *sock,
76592 int protocol, int kern);
76593 struct module *owner;
76594-};
76595+} __do_const;
76596
76597 struct iovec;
76598 struct kvec;
76599diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
76600index 25f5d2d1..5cf2120 100644
76601--- a/include/linux/netdevice.h
76602+++ b/include/linux/netdevice.h
76603@@ -1098,6 +1098,7 @@ struct net_device_ops {
76604 sa_family_t sa_family,
76605 __be16 port);
76606 };
76607+typedef struct net_device_ops __no_const net_device_ops_no_const;
76608
76609 /*
76610 * The DEVICE structure.
76611@@ -1169,7 +1170,7 @@ struct net_device {
76612 int iflink;
76613
76614 struct net_device_stats stats;
76615- atomic_long_t rx_dropped; /* dropped packets by core network
76616+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
76617 * Do not use this in drivers.
76618 */
76619
76620diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
76621index 708fe72ab9..77084a3 100644
76622--- a/include/linux/netfilter.h
76623+++ b/include/linux/netfilter.h
76624@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
76625 #endif
76626 /* Use the module struct to lock set/get code in place */
76627 struct module *owner;
76628-};
76629+} __do_const;
76630
76631 /* Function to register/unregister hook points. */
76632 int nf_register_hook(struct nf_hook_ops *reg);
76633diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
76634index 9ac9fbd..f92edb4 100644
76635--- a/include/linux/netfilter/ipset/ip_set.h
76636+++ b/include/linux/netfilter/ipset/ip_set.h
76637@@ -124,7 +124,7 @@ struct ip_set_type_variant {
76638 /* Return true if "b" set is the same as "a"
76639 * according to the create set parameters */
76640 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
76641-};
76642+} __do_const;
76643
76644 /* The core set type structure */
76645 struct ip_set_type {
76646diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
76647index cadb740..d7c37c0 100644
76648--- a/include/linux/netfilter/nfnetlink.h
76649+++ b/include/linux/netfilter/nfnetlink.h
76650@@ -16,7 +16,7 @@ struct nfnl_callback {
76651 const struct nlattr * const cda[]);
76652 const struct nla_policy *policy; /* netlink attribute policy */
76653 const u_int16_t attr_count; /* number of nlattr's */
76654-};
76655+} __do_const;
76656
76657 struct nfnetlink_subsystem {
76658 const char *name;
76659diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
76660new file mode 100644
76661index 0000000..33f4af8
76662--- /dev/null
76663+++ b/include/linux/netfilter/xt_gradm.h
76664@@ -0,0 +1,9 @@
76665+#ifndef _LINUX_NETFILTER_XT_GRADM_H
76666+#define _LINUX_NETFILTER_XT_GRADM_H 1
76667+
76668+struct xt_gradm_mtinfo {
76669+ __u16 flags;
76670+ __u16 invflags;
76671+};
76672+
76673+#endif
76674diff --git a/include/linux/nls.h b/include/linux/nls.h
76675index 5dc635f..35f5e11 100644
76676--- a/include/linux/nls.h
76677+++ b/include/linux/nls.h
76678@@ -31,7 +31,7 @@ struct nls_table {
76679 const unsigned char *charset2upper;
76680 struct module *owner;
76681 struct nls_table *next;
76682-};
76683+} __do_const;
76684
76685 /* this value hold the maximum octet of charset */
76686 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
76687diff --git a/include/linux/notifier.h b/include/linux/notifier.h
76688index d14a4c3..a078786 100644
76689--- a/include/linux/notifier.h
76690+++ b/include/linux/notifier.h
76691@@ -54,7 +54,8 @@ struct notifier_block {
76692 notifier_fn_t notifier_call;
76693 struct notifier_block __rcu *next;
76694 int priority;
76695-};
76696+} __do_const;
76697+typedef struct notifier_block __no_const notifier_block_no_const;
76698
76699 struct atomic_notifier_head {
76700 spinlock_t lock;
76701diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
76702index b2a0f15..4d7da32 100644
76703--- a/include/linux/oprofile.h
76704+++ b/include/linux/oprofile.h
76705@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
76706 int oprofilefs_create_ro_ulong(struct dentry * root,
76707 char const * name, ulong * val);
76708
76709-/** Create a file for read-only access to an atomic_t. */
76710+/** Create a file for read-only access to an atomic_unchecked_t. */
76711 int oprofilefs_create_ro_atomic(struct dentry * root,
76712- char const * name, atomic_t * val);
76713+ char const * name, atomic_unchecked_t * val);
76714
76715 /** create a directory */
76716 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
76717diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
76718index 430dd96..544e26e 100644
76719--- a/include/linux/pci_hotplug.h
76720+++ b/include/linux/pci_hotplug.h
76721@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
76722 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
76723 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
76724 int (*reset_slot) (struct hotplug_slot *slot, int probe);
76725-};
76726+} __do_const;
76727+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
76728
76729 /**
76730 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
76731diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
76732index c8ba627..24bdfa8 100644
76733--- a/include/linux/perf_event.h
76734+++ b/include/linux/perf_event.h
76735@@ -327,8 +327,8 @@ struct perf_event {
76736
76737 enum perf_event_active_state state;
76738 unsigned int attach_state;
76739- local64_t count;
76740- atomic64_t child_count;
76741+ local64_t count; /* PaX: fix it one day */
76742+ atomic64_unchecked_t child_count;
76743
76744 /*
76745 * These are the total time in nanoseconds that the event
76746@@ -379,8 +379,8 @@ struct perf_event {
76747 * These accumulate total time (in nanoseconds) that children
76748 * events have been enabled and running, respectively.
76749 */
76750- atomic64_t child_total_time_enabled;
76751- atomic64_t child_total_time_running;
76752+ atomic64_unchecked_t child_total_time_enabled;
76753+ atomic64_unchecked_t child_total_time_running;
76754
76755 /*
76756 * Protect attach/detach and child_list:
76757@@ -702,7 +702,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
76758 entry->ip[entry->nr++] = ip;
76759 }
76760
76761-extern int sysctl_perf_event_paranoid;
76762+extern int sysctl_perf_event_legitimately_concerned;
76763 extern int sysctl_perf_event_mlock;
76764 extern int sysctl_perf_event_sample_rate;
76765 extern int sysctl_perf_cpu_time_max_percent;
76766@@ -717,19 +717,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
76767 loff_t *ppos);
76768
76769
76770+static inline bool perf_paranoid_any(void)
76771+{
76772+ return sysctl_perf_event_legitimately_concerned > 2;
76773+}
76774+
76775 static inline bool perf_paranoid_tracepoint_raw(void)
76776 {
76777- return sysctl_perf_event_paranoid > -1;
76778+ return sysctl_perf_event_legitimately_concerned > -1;
76779 }
76780
76781 static inline bool perf_paranoid_cpu(void)
76782 {
76783- return sysctl_perf_event_paranoid > 0;
76784+ return sysctl_perf_event_legitimately_concerned > 0;
76785 }
76786
76787 static inline bool perf_paranoid_kernel(void)
76788 {
76789- return sysctl_perf_event_paranoid > 1;
76790+ return sysctl_perf_event_legitimately_concerned > 1;
76791 }
76792
76793 extern void perf_event_init(void);
76794@@ -845,7 +850,7 @@ struct perf_pmu_events_attr {
76795 struct device_attribute attr;
76796 u64 id;
76797 const char *event_str;
76798-};
76799+} __do_const;
76800
76801 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
76802 static struct perf_pmu_events_attr _var = { \
76803diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
76804index b8809fe..ae4ccd0 100644
76805--- a/include/linux/pipe_fs_i.h
76806+++ b/include/linux/pipe_fs_i.h
76807@@ -47,10 +47,10 @@ struct pipe_inode_info {
76808 struct mutex mutex;
76809 wait_queue_head_t wait;
76810 unsigned int nrbufs, curbuf, buffers;
76811- unsigned int readers;
76812- unsigned int writers;
76813- unsigned int files;
76814- unsigned int waiting_writers;
76815+ atomic_t readers;
76816+ atomic_t writers;
76817+ atomic_t files;
76818+ atomic_t waiting_writers;
76819 unsigned int r_counter;
76820 unsigned int w_counter;
76821 struct page *tmp_page;
76822diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
76823index 5f28cae..3d23723 100644
76824--- a/include/linux/platform_data/usb-ehci-s5p.h
76825+++ b/include/linux/platform_data/usb-ehci-s5p.h
76826@@ -14,7 +14,7 @@
76827 struct s5p_ehci_platdata {
76828 int (*phy_init)(struct platform_device *pdev, int type);
76829 int (*phy_exit)(struct platform_device *pdev, int type);
76830-};
76831+} __no_const;
76832
76833 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
76834
76835diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
76836index c256c59..8ea94c7 100644
76837--- a/include/linux/platform_data/usb-ohci-exynos.h
76838+++ b/include/linux/platform_data/usb-ohci-exynos.h
76839@@ -14,7 +14,7 @@
76840 struct exynos4_ohci_platdata {
76841 int (*phy_init)(struct platform_device *pdev, int type);
76842 int (*phy_exit)(struct platform_device *pdev, int type);
76843-};
76844+} __no_const;
76845
76846 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
76847
76848diff --git a/include/linux/pm.h b/include/linux/pm.h
76849index a224c7f..92d8a97 100644
76850--- a/include/linux/pm.h
76851+++ b/include/linux/pm.h
76852@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
76853 struct dev_pm_domain {
76854 struct dev_pm_ops ops;
76855 };
76856+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
76857
76858 /*
76859 * The PM_EVENT_ messages are also used by drivers implementing the legacy
76860diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
76861index 7c1d252..c5c773e 100644
76862--- a/include/linux/pm_domain.h
76863+++ b/include/linux/pm_domain.h
76864@@ -48,7 +48,7 @@ struct gpd_dev_ops {
76865
76866 struct gpd_cpu_data {
76867 unsigned int saved_exit_latency;
76868- struct cpuidle_state *idle_state;
76869+ cpuidle_state_no_const *idle_state;
76870 };
76871
76872 struct generic_pm_domain {
76873diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
76874index 6fa7cea..7bf6415 100644
76875--- a/include/linux/pm_runtime.h
76876+++ b/include/linux/pm_runtime.h
76877@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
76878
76879 static inline void pm_runtime_mark_last_busy(struct device *dev)
76880 {
76881- ACCESS_ONCE(dev->power.last_busy) = jiffies;
76882+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
76883 }
76884
76885 #else /* !CONFIG_PM_RUNTIME */
76886diff --git a/include/linux/pnp.h b/include/linux/pnp.h
76887index 195aafc..49a7bc2 100644
76888--- a/include/linux/pnp.h
76889+++ b/include/linux/pnp.h
76890@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
76891 struct pnp_fixup {
76892 char id[7];
76893 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
76894-};
76895+} __do_const;
76896
76897 /* config parameters */
76898 #define PNP_CONFIG_NORMAL 0x0001
76899diff --git a/include/linux/poison.h b/include/linux/poison.h
76900index 2110a81..13a11bb 100644
76901--- a/include/linux/poison.h
76902+++ b/include/linux/poison.h
76903@@ -19,8 +19,8 @@
76904 * under normal circumstances, used to verify that nobody uses
76905 * non-initialized list entries.
76906 */
76907-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
76908-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
76909+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
76910+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
76911
76912 /********** include/linux/timer.h **********/
76913 /*
76914diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
76915index d8b187c3..9a9257a 100644
76916--- a/include/linux/power/smartreflex.h
76917+++ b/include/linux/power/smartreflex.h
76918@@ -238,7 +238,7 @@ struct omap_sr_class_data {
76919 int (*notify)(struct omap_sr *sr, u32 status);
76920 u8 notify_flags;
76921 u8 class_type;
76922-};
76923+} __do_const;
76924
76925 /**
76926 * struct omap_sr_nvalue_table - Smartreflex n-target value info
76927diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
76928index 4ea1d37..80f4b33 100644
76929--- a/include/linux/ppp-comp.h
76930+++ b/include/linux/ppp-comp.h
76931@@ -84,7 +84,7 @@ struct compressor {
76932 struct module *owner;
76933 /* Extra skb space needed by the compressor algorithm */
76934 unsigned int comp_extra;
76935-};
76936+} __do_const;
76937
76938 /*
76939 * The return value from decompress routine is the length of the
76940diff --git a/include/linux/preempt.h b/include/linux/preempt.h
76941index f5d4723..a6ea2fa 100644
76942--- a/include/linux/preempt.h
76943+++ b/include/linux/preempt.h
76944@@ -18,8 +18,13 @@
76945 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76946 #endif
76947
76948+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
76949+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76950+
76951 #define inc_preempt_count() add_preempt_count(1)
76952+#define raw_inc_preempt_count() raw_add_preempt_count(1)
76953 #define dec_preempt_count() sub_preempt_count(1)
76954+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
76955
76956 #define preempt_count() (current_thread_info()->preempt_count)
76957
76958@@ -64,6 +69,12 @@ do { \
76959 barrier(); \
76960 } while (0)
76961
76962+#define raw_preempt_disable() \
76963+do { \
76964+ raw_inc_preempt_count(); \
76965+ barrier(); \
76966+} while (0)
76967+
76968 #define sched_preempt_enable_no_resched() \
76969 do { \
76970 barrier(); \
76971@@ -72,6 +83,12 @@ do { \
76972
76973 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
76974
76975+#define raw_preempt_enable_no_resched() \
76976+do { \
76977+ barrier(); \
76978+ raw_dec_preempt_count(); \
76979+} while (0)
76980+
76981 #define preempt_enable() \
76982 do { \
76983 preempt_enable_no_resched(); \
76984@@ -116,8 +133,10 @@ do { \
76985 * region.
76986 */
76987 #define preempt_disable() barrier()
76988+#define raw_preempt_disable() barrier()
76989 #define sched_preempt_enable_no_resched() barrier()
76990 #define preempt_enable_no_resched() barrier()
76991+#define raw_preempt_enable_no_resched() barrier()
76992 #define preempt_enable() barrier()
76993
76994 #define preempt_disable_notrace() barrier()
76995diff --git a/include/linux/printk.h b/include/linux/printk.h
76996index e6131a78..8e9fb61 100644
76997--- a/include/linux/printk.h
76998+++ b/include/linux/printk.h
76999@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
77000 void early_printk(const char *s, ...) { }
77001 #endif
77002
77003+extern int kptr_restrict;
77004+
77005 #ifdef CONFIG_PRINTK
77006 asmlinkage __printf(5, 0)
77007 int vprintk_emit(int facility, int level,
77008@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
77009
77010 extern int printk_delay_msec;
77011 extern int dmesg_restrict;
77012-extern int kptr_restrict;
77013
77014 extern void wake_up_klogd(void);
77015
77016diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
77017index 608e60a..c26f864 100644
77018--- a/include/linux/proc_fs.h
77019+++ b/include/linux/proc_fs.h
77020@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
77021 return proc_create_data(name, mode, parent, proc_fops, NULL);
77022 }
77023
77024+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
77025+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
77026+{
77027+#ifdef CONFIG_GRKERNSEC_PROC_USER
77028+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
77029+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77030+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
77031+#else
77032+ return proc_create_data(name, mode, parent, proc_fops, NULL);
77033+#endif
77034+}
77035+
77036+
77037 extern void proc_set_size(struct proc_dir_entry *, loff_t);
77038 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
77039 extern void *PDE_DATA(const struct inode *);
77040diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
77041index 34a1e10..03a6d03 100644
77042--- a/include/linux/proc_ns.h
77043+++ b/include/linux/proc_ns.h
77044@@ -14,7 +14,7 @@ struct proc_ns_operations {
77045 void (*put)(void *ns);
77046 int (*install)(struct nsproxy *nsproxy, void *ns);
77047 unsigned int (*inum)(void *ns);
77048-};
77049+} __do_const;
77050
77051 struct proc_ns {
77052 void *ns;
77053diff --git a/include/linux/quota.h b/include/linux/quota.h
77054index cc7494a..1e27036 100644
77055--- a/include/linux/quota.h
77056+++ b/include/linux/quota.h
77057@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
77058
77059 extern bool qid_eq(struct kqid left, struct kqid right);
77060 extern bool qid_lt(struct kqid left, struct kqid right);
77061-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
77062+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
77063 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
77064 extern bool qid_valid(struct kqid qid);
77065
77066diff --git a/include/linux/random.h b/include/linux/random.h
77067index 6312dd9..2561947 100644
77068--- a/include/linux/random.h
77069+++ b/include/linux/random.h
77070@@ -10,9 +10,19 @@
77071
77072
77073 extern void add_device_randomness(const void *, unsigned int);
77074+
77075+static inline void add_latent_entropy(void)
77076+{
77077+
77078+#ifdef LATENT_ENTROPY_PLUGIN
77079+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
77080+#endif
77081+
77082+}
77083+
77084 extern void add_input_randomness(unsigned int type, unsigned int code,
77085- unsigned int value);
77086-extern void add_interrupt_randomness(int irq, int irq_flags);
77087+ unsigned int value) __latent_entropy;
77088+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
77089
77090 extern void get_random_bytes(void *buf, int nbytes);
77091 extern void get_random_bytes_arch(void *buf, int nbytes);
77092@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
77093 u32 prandom_u32_state(struct rnd_state *);
77094 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
77095
77096+static inline unsigned long pax_get_random_long(void)
77097+{
77098+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
77099+}
77100+
77101 /*
77102 * Handle minimum values for seeds
77103 */
77104diff --git a/include/linux/rculist.h b/include/linux/rculist.h
77105index 4106721..132d42c 100644
77106--- a/include/linux/rculist.h
77107+++ b/include/linux/rculist.h
77108@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
77109 struct list_head *prev, struct list_head *next);
77110 #endif
77111
77112+extern void __pax_list_add_rcu(struct list_head *new,
77113+ struct list_head *prev, struct list_head *next);
77114+
77115 /**
77116 * list_add_rcu - add a new entry to rcu-protected list
77117 * @new: new entry to be added
77118@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
77119 __list_add_rcu(new, head, head->next);
77120 }
77121
77122+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
77123+{
77124+ __pax_list_add_rcu(new, head, head->next);
77125+}
77126+
77127 /**
77128 * list_add_tail_rcu - add a new entry to rcu-protected list
77129 * @new: new entry to be added
77130@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
77131 __list_add_rcu(new, head->prev, head);
77132 }
77133
77134+static inline void pax_list_add_tail_rcu(struct list_head *new,
77135+ struct list_head *head)
77136+{
77137+ __pax_list_add_rcu(new, head->prev, head);
77138+}
77139+
77140 /**
77141 * list_del_rcu - deletes entry from list without re-initialization
77142 * @entry: the element to delete from the list.
77143@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
77144 entry->prev = LIST_POISON2;
77145 }
77146
77147+extern void pax_list_del_rcu(struct list_head *entry);
77148+
77149 /**
77150 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
77151 * @n: the element to delete from the hash list.
77152diff --git a/include/linux/reboot.h b/include/linux/reboot.h
77153index 8e00f9f..9449b55 100644
77154--- a/include/linux/reboot.h
77155+++ b/include/linux/reboot.h
77156@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
77157 * Architecture-specific implementations of sys_reboot commands.
77158 */
77159
77160-extern void machine_restart(char *cmd);
77161-extern void machine_halt(void);
77162-extern void machine_power_off(void);
77163+extern void machine_restart(char *cmd) __noreturn;
77164+extern void machine_halt(void) __noreturn;
77165+extern void machine_power_off(void) __noreturn;
77166
77167 extern void machine_shutdown(void);
77168 struct pt_regs;
77169@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
77170 */
77171
77172 extern void kernel_restart_prepare(char *cmd);
77173-extern void kernel_restart(char *cmd);
77174-extern void kernel_halt(void);
77175-extern void kernel_power_off(void);
77176+extern void kernel_restart(char *cmd) __noreturn;
77177+extern void kernel_halt(void) __noreturn;
77178+extern void kernel_power_off(void) __noreturn;
77179
77180 extern int C_A_D; /* for sysctl */
77181 void ctrl_alt_del(void);
77182@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
77183 * Emergency restart, callable from an interrupt handler.
77184 */
77185
77186-extern void emergency_restart(void);
77187+extern void emergency_restart(void) __noreturn;
77188 #include <asm/emergency-restart.h>
77189
77190 #endif /* _LINUX_REBOOT_H */
77191diff --git a/include/linux/regset.h b/include/linux/regset.h
77192index 8e0c9fe..ac4d221 100644
77193--- a/include/linux/regset.h
77194+++ b/include/linux/regset.h
77195@@ -161,7 +161,8 @@ struct user_regset {
77196 unsigned int align;
77197 unsigned int bias;
77198 unsigned int core_note_type;
77199-};
77200+} __do_const;
77201+typedef struct user_regset __no_const user_regset_no_const;
77202
77203 /**
77204 * struct user_regset_view - available regsets
77205diff --git a/include/linux/relay.h b/include/linux/relay.h
77206index d7c8359..818daf5 100644
77207--- a/include/linux/relay.h
77208+++ b/include/linux/relay.h
77209@@ -157,7 +157,7 @@ struct rchan_callbacks
77210 * The callback should return 0 if successful, negative if not.
77211 */
77212 int (*remove_buf_file)(struct dentry *dentry);
77213-};
77214+} __no_const;
77215
77216 /*
77217 * CONFIG_RELAY kernel API, kernel/relay.c
77218diff --git a/include/linux/rio.h b/include/linux/rio.h
77219index b71d573..2f940bd 100644
77220--- a/include/linux/rio.h
77221+++ b/include/linux/rio.h
77222@@ -355,7 +355,7 @@ struct rio_ops {
77223 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
77224 u64 rstart, u32 size, u32 flags);
77225 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
77226-};
77227+} __no_const;
77228
77229 #define RIO_RESOURCE_MEM 0x00000100
77230 #define RIO_RESOURCE_DOORBELL 0x00000200
77231diff --git a/include/linux/rmap.h b/include/linux/rmap.h
77232index 6dacb93..6174423 100644
77233--- a/include/linux/rmap.h
77234+++ b/include/linux/rmap.h
77235@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
77236 void anon_vma_init(void); /* create anon_vma_cachep */
77237 int anon_vma_prepare(struct vm_area_struct *);
77238 void unlink_anon_vmas(struct vm_area_struct *);
77239-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
77240-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
77241+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
77242+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
77243
77244 static inline void anon_vma_merge(struct vm_area_struct *vma,
77245 struct vm_area_struct *next)
77246diff --git a/include/linux/sched.h b/include/linux/sched.h
77247index b1e963e..114b8fd 100644
77248--- a/include/linux/sched.h
77249+++ b/include/linux/sched.h
77250@@ -62,6 +62,7 @@ struct bio_list;
77251 struct fs_struct;
77252 struct perf_event_context;
77253 struct blk_plug;
77254+struct linux_binprm;
77255
77256 /*
77257 * List of flags we want to share for kernel threads,
77258@@ -295,7 +296,7 @@ extern char __sched_text_start[], __sched_text_end[];
77259 extern int in_sched_functions(unsigned long addr);
77260
77261 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
77262-extern signed long schedule_timeout(signed long timeout);
77263+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
77264 extern signed long schedule_timeout_interruptible(signed long timeout);
77265 extern signed long schedule_timeout_killable(signed long timeout);
77266 extern signed long schedule_timeout_uninterruptible(signed long timeout);
77267@@ -306,6 +307,19 @@ struct nsproxy;
77268 struct user_namespace;
77269
77270 #ifdef CONFIG_MMU
77271+
77272+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
77273+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
77274+#else
77275+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
77276+{
77277+ return 0;
77278+}
77279+#endif
77280+
77281+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
77282+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
77283+
77284 extern void arch_pick_mmap_layout(struct mm_struct *mm);
77285 extern unsigned long
77286 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
77287@@ -585,6 +599,17 @@ struct signal_struct {
77288 #ifdef CONFIG_TASKSTATS
77289 struct taskstats *stats;
77290 #endif
77291+
77292+#ifdef CONFIG_GRKERNSEC
77293+ u32 curr_ip;
77294+ u32 saved_ip;
77295+ u32 gr_saddr;
77296+ u32 gr_daddr;
77297+ u16 gr_sport;
77298+ u16 gr_dport;
77299+ u8 used_accept:1;
77300+#endif
77301+
77302 #ifdef CONFIG_AUDIT
77303 unsigned audit_tty;
77304 unsigned audit_tty_log_passwd;
77305@@ -665,6 +690,14 @@ struct user_struct {
77306 struct key *session_keyring; /* UID's default session keyring */
77307 #endif
77308
77309+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77310+ unsigned char kernel_banned;
77311+#endif
77312+#ifdef CONFIG_GRKERNSEC_BRUTE
77313+ unsigned char suid_banned;
77314+ unsigned long suid_ban_expires;
77315+#endif
77316+
77317 /* Hash table maintenance information */
77318 struct hlist_node uidhash_node;
77319 kuid_t uid;
77320@@ -1150,8 +1183,8 @@ struct task_struct {
77321 struct list_head thread_group;
77322
77323 struct completion *vfork_done; /* for vfork() */
77324- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
77325- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77326+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
77327+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77328
77329 cputime_t utime, stime, utimescaled, stimescaled;
77330 cputime_t gtime;
77331@@ -1176,11 +1209,6 @@ struct task_struct {
77332 struct task_cputime cputime_expires;
77333 struct list_head cpu_timers[3];
77334
77335-/* process credentials */
77336- const struct cred __rcu *real_cred; /* objective and real subjective task
77337- * credentials (COW) */
77338- const struct cred __rcu *cred; /* effective (overridable) subjective task
77339- * credentials (COW) */
77340 char comm[TASK_COMM_LEN]; /* executable name excluding path
77341 - access with [gs]et_task_comm (which lock
77342 it with task_lock())
77343@@ -1197,6 +1225,10 @@ struct task_struct {
77344 #endif
77345 /* CPU-specific state of this task */
77346 struct thread_struct thread;
77347+/* thread_info moved to task_struct */
77348+#ifdef CONFIG_X86
77349+ struct thread_info tinfo;
77350+#endif
77351 /* filesystem information */
77352 struct fs_struct *fs;
77353 /* open file information */
77354@@ -1270,6 +1302,10 @@ struct task_struct {
77355 gfp_t lockdep_reclaim_gfp;
77356 #endif
77357
77358+/* process credentials */
77359+ const struct cred __rcu *real_cred; /* objective and real subjective task
77360+ * credentials (COW) */
77361+
77362 /* journalling filesystem info */
77363 void *journal_info;
77364
77365@@ -1308,6 +1344,10 @@ struct task_struct {
77366 /* cg_list protected by css_set_lock and tsk->alloc_lock */
77367 struct list_head cg_list;
77368 #endif
77369+
77370+ const struct cred __rcu *cred; /* effective (overridable) subjective task
77371+ * credentials (COW) */
77372+
77373 #ifdef CONFIG_FUTEX
77374 struct robust_list_head __user *robust_list;
77375 #ifdef CONFIG_COMPAT
77376@@ -1411,8 +1451,78 @@ struct task_struct {
77377 unsigned int sequential_io;
77378 unsigned int sequential_io_avg;
77379 #endif
77380+
77381+#ifdef CONFIG_GRKERNSEC
77382+ /* grsecurity */
77383+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77384+ u64 exec_id;
77385+#endif
77386+#ifdef CONFIG_GRKERNSEC_SETXID
77387+ const struct cred *delayed_cred;
77388+#endif
77389+ struct dentry *gr_chroot_dentry;
77390+ struct acl_subject_label *acl;
77391+ struct acl_subject_label *tmpacl;
77392+ struct acl_role_label *role;
77393+ struct file *exec_file;
77394+ unsigned long brute_expires;
77395+ u16 acl_role_id;
77396+ u8 inherited;
77397+ /* is this the task that authenticated to the special role */
77398+ u8 acl_sp_role;
77399+ u8 is_writable;
77400+ u8 brute;
77401+ u8 gr_is_chrooted;
77402+#endif
77403+
77404 };
77405
77406+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
77407+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
77408+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
77409+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
77410+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
77411+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
77412+
77413+#ifdef CONFIG_PAX_SOFTMODE
77414+extern int pax_softmode;
77415+#endif
77416+
77417+extern int pax_check_flags(unsigned long *);
77418+
77419+/* if tsk != current then task_lock must be held on it */
77420+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
77421+static inline unsigned long pax_get_flags(struct task_struct *tsk)
77422+{
77423+ if (likely(tsk->mm))
77424+ return tsk->mm->pax_flags;
77425+ else
77426+ return 0UL;
77427+}
77428+
77429+/* if tsk != current then task_lock must be held on it */
77430+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
77431+{
77432+ if (likely(tsk->mm)) {
77433+ tsk->mm->pax_flags = flags;
77434+ return 0;
77435+ }
77436+ return -EINVAL;
77437+}
77438+#endif
77439+
77440+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77441+extern void pax_set_initial_flags(struct linux_binprm *bprm);
77442+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
77443+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
77444+#endif
77445+
77446+struct path;
77447+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
77448+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
77449+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
77450+extern void pax_report_refcount_overflow(struct pt_regs *regs);
77451+
77452 /* Future-safe accessor for struct task_struct's cpus_allowed. */
77453 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
77454
77455@@ -1471,7 +1581,7 @@ struct pid_namespace;
77456 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
77457 struct pid_namespace *ns);
77458
77459-static inline pid_t task_pid_nr(struct task_struct *tsk)
77460+static inline pid_t task_pid_nr(const struct task_struct *tsk)
77461 {
77462 return tsk->pid;
77463 }
77464@@ -1921,7 +2031,9 @@ void yield(void);
77465 extern struct exec_domain default_exec_domain;
77466
77467 union thread_union {
77468+#ifndef CONFIG_X86
77469 struct thread_info thread_info;
77470+#endif
77471 unsigned long stack[THREAD_SIZE/sizeof(long)];
77472 };
77473
77474@@ -1954,6 +2066,7 @@ extern struct pid_namespace init_pid_ns;
77475 */
77476
77477 extern struct task_struct *find_task_by_vpid(pid_t nr);
77478+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
77479 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
77480 struct pid_namespace *ns);
77481
77482@@ -2118,7 +2231,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
77483 extern void exit_itimers(struct signal_struct *);
77484 extern void flush_itimer_signals(void);
77485
77486-extern void do_group_exit(int);
77487+extern __noreturn void do_group_exit(int);
77488
77489 extern int allow_signal(int);
77490 extern int disallow_signal(int);
77491@@ -2309,9 +2422,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
77492
77493 #endif
77494
77495-static inline int object_is_on_stack(void *obj)
77496+static inline int object_starts_on_stack(void *obj)
77497 {
77498- void *stack = task_stack_page(current);
77499+ const void *stack = task_stack_page(current);
77500
77501 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
77502 }
77503diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
77504index bf8086b..962b035 100644
77505--- a/include/linux/sched/sysctl.h
77506+++ b/include/linux/sched/sysctl.h
77507@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
77508 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
77509
77510 extern int sysctl_max_map_count;
77511+extern unsigned long sysctl_heap_stack_gap;
77512
77513 extern unsigned int sysctl_sched_latency;
77514 extern unsigned int sysctl_sched_min_granularity;
77515diff --git a/include/linux/security.h b/include/linux/security.h
77516index 9d37e2b..43368e4 100644
77517--- a/include/linux/security.h
77518+++ b/include/linux/security.h
77519@@ -27,6 +27,7 @@
77520 #include <linux/slab.h>
77521 #include <linux/err.h>
77522 #include <linux/string.h>
77523+#include <linux/grsecurity.h>
77524
77525 struct linux_binprm;
77526 struct cred;
77527@@ -116,8 +117,6 @@ struct seq_file;
77528
77529 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
77530
77531-void reset_security_ops(void);
77532-
77533 #ifdef CONFIG_MMU
77534 extern unsigned long mmap_min_addr;
77535 extern unsigned long dac_mmap_min_addr;
77536diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
77537index dc368b8..e895209 100644
77538--- a/include/linux/semaphore.h
77539+++ b/include/linux/semaphore.h
77540@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
77541 }
77542
77543 extern void down(struct semaphore *sem);
77544-extern int __must_check down_interruptible(struct semaphore *sem);
77545+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
77546 extern int __must_check down_killable(struct semaphore *sem);
77547 extern int __must_check down_trylock(struct semaphore *sem);
77548 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
77549diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
77550index 4e32edc..f8f2d18 100644
77551--- a/include/linux/seq_file.h
77552+++ b/include/linux/seq_file.h
77553@@ -26,6 +26,9 @@ struct seq_file {
77554 struct mutex lock;
77555 const struct seq_operations *op;
77556 int poll_event;
77557+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77558+ u64 exec_id;
77559+#endif
77560 #ifdef CONFIG_USER_NS
77561 struct user_namespace *user_ns;
77562 #endif
77563@@ -38,6 +41,7 @@ struct seq_operations {
77564 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
77565 int (*show) (struct seq_file *m, void *v);
77566 };
77567+typedef struct seq_operations __no_const seq_operations_no_const;
77568
77569 #define SEQ_SKIP 1
77570
77571diff --git a/include/linux/shm.h b/include/linux/shm.h
77572index 429c199..4d42e38 100644
77573--- a/include/linux/shm.h
77574+++ b/include/linux/shm.h
77575@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
77576
77577 /* The task created the shm object. NULL if the task is dead. */
77578 struct task_struct *shm_creator;
77579+#ifdef CONFIG_GRKERNSEC
77580+ time_t shm_createtime;
77581+ pid_t shm_lapid;
77582+#endif
77583 };
77584
77585 /* shm_mode upper byte flags */
77586diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
77587index c2d8933..b2b4ed6 100644
77588--- a/include/linux/skbuff.h
77589+++ b/include/linux/skbuff.h
77590@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
77591 extern struct sk_buff *__alloc_skb(unsigned int size,
77592 gfp_t priority, int flags, int node);
77593 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
77594-static inline struct sk_buff *alloc_skb(unsigned int size,
77595+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
77596 gfp_t priority)
77597 {
77598 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
77599@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
77600 */
77601 static inline int skb_queue_empty(const struct sk_buff_head *list)
77602 {
77603- return list->next == (struct sk_buff *)list;
77604+ return list->next == (const struct sk_buff *)list;
77605 }
77606
77607 /**
77608@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
77609 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77610 const struct sk_buff *skb)
77611 {
77612- return skb->next == (struct sk_buff *)list;
77613+ return skb->next == (const struct sk_buff *)list;
77614 }
77615
77616 /**
77617@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77618 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
77619 const struct sk_buff *skb)
77620 {
77621- return skb->prev == (struct sk_buff *)list;
77622+ return skb->prev == (const struct sk_buff *)list;
77623 }
77624
77625 /**
77626@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
77627 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
77628 */
77629 #ifndef NET_SKB_PAD
77630-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
77631+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
77632 #endif
77633
77634 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
77635@@ -2348,7 +2348,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
77636 int noblock, int *err);
77637 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
77638 struct poll_table_struct *wait);
77639-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
77640+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
77641 int offset, struct iovec *to,
77642 int size);
77643 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
77644@@ -2643,6 +2643,9 @@ static inline void nf_reset(struct sk_buff *skb)
77645 nf_bridge_put(skb->nf_bridge);
77646 skb->nf_bridge = NULL;
77647 #endif
77648+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
77649+ skb->nf_trace = 0;
77650+#endif
77651 }
77652
77653 static inline void nf_reset_trace(struct sk_buff *skb)
77654diff --git a/include/linux/slab.h b/include/linux/slab.h
77655index 74f1058..914b7da 100644
77656--- a/include/linux/slab.h
77657+++ b/include/linux/slab.h
77658@@ -14,15 +14,29 @@
77659 #include <linux/gfp.h>
77660 #include <linux/types.h>
77661 #include <linux/workqueue.h>
77662-
77663+#include <linux/err.h>
77664
77665 /*
77666 * Flags to pass to kmem_cache_create().
77667 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
77668 */
77669 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
77670+
77671+#ifdef CONFIG_PAX_USERCOPY_SLABS
77672+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
77673+#else
77674+#define SLAB_USERCOPY 0x00000000UL
77675+#endif
77676+
77677 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
77678 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
77679+
77680+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77681+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
77682+#else
77683+#define SLAB_NO_SANITIZE 0x00000000UL
77684+#endif
77685+
77686 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
77687 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
77688 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
77689@@ -91,10 +105,13 @@
77690 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
77691 * Both make kfree a no-op.
77692 */
77693-#define ZERO_SIZE_PTR ((void *)16)
77694+#define ZERO_SIZE_PTR \
77695+({ \
77696+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
77697+ (void *)(-MAX_ERRNO-1L); \
77698+})
77699
77700-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
77701- (unsigned long)ZERO_SIZE_PTR)
77702+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
77703
77704 #include <linux/kmemleak.h>
77705
77706@@ -135,6 +152,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
77707 void kfree(const void *);
77708 void kzfree(const void *);
77709 size_t ksize(const void *);
77710+const char *check_heap_object(const void *ptr, unsigned long n);
77711+bool is_usercopy_object(const void *ptr);
77712
77713 /*
77714 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
77715@@ -167,7 +186,7 @@ struct kmem_cache {
77716 unsigned int align; /* Alignment as calculated */
77717 unsigned long flags; /* Active flags on the slab */
77718 const char *name; /* Slab name for sysfs */
77719- int refcount; /* Use counter */
77720+ atomic_t refcount; /* Use counter */
77721 void (*ctor)(void *); /* Called on object slot creation */
77722 struct list_head list; /* List of all slab caches on the system */
77723 };
77724@@ -241,6 +260,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
77725 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77726 #endif
77727
77728+#ifdef CONFIG_PAX_USERCOPY_SLABS
77729+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
77730+#endif
77731+
77732 /*
77733 * Figure out which kmalloc slab an allocation of a certain size
77734 * belongs to.
77735@@ -249,7 +272,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77736 * 2 = 120 .. 192 bytes
77737 * n = 2^(n-1) .. 2^n -1
77738 */
77739-static __always_inline int kmalloc_index(size_t size)
77740+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
77741 {
77742 if (!size)
77743 return 0;
77744@@ -292,11 +315,11 @@ static __always_inline int kmalloc_index(size_t size)
77745 }
77746 #endif /* !CONFIG_SLOB */
77747
77748-void *__kmalloc(size_t size, gfp_t flags);
77749+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
77750 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
77751
77752 #ifdef CONFIG_NUMA
77753-void *__kmalloc_node(size_t size, gfp_t flags, int node);
77754+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
77755 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
77756 #else
77757 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
77758diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
77759index e9346b4..1494959 100644
77760--- a/include/linux/slab_def.h
77761+++ b/include/linux/slab_def.h
77762@@ -36,7 +36,7 @@ struct kmem_cache {
77763 /* 4) cache creation/removal */
77764 const char *name;
77765 struct list_head list;
77766- int refcount;
77767+ atomic_t refcount;
77768 int object_size;
77769 int align;
77770
77771@@ -52,10 +52,14 @@ struct kmem_cache {
77772 unsigned long node_allocs;
77773 unsigned long node_frees;
77774 unsigned long node_overflow;
77775- atomic_t allochit;
77776- atomic_t allocmiss;
77777- atomic_t freehit;
77778- atomic_t freemiss;
77779+ atomic_unchecked_t allochit;
77780+ atomic_unchecked_t allocmiss;
77781+ atomic_unchecked_t freehit;
77782+ atomic_unchecked_t freemiss;
77783+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77784+ atomic_unchecked_t sanitized;
77785+ atomic_unchecked_t not_sanitized;
77786+#endif
77787
77788 /*
77789 * If debugging is enabled, then the allocator can add additional
77790diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
77791index cc0b67e..a0329b1 100644
77792--- a/include/linux/slub_def.h
77793+++ b/include/linux/slub_def.h
77794@@ -74,7 +74,7 @@ struct kmem_cache {
77795 struct kmem_cache_order_objects max;
77796 struct kmem_cache_order_objects min;
77797 gfp_t allocflags; /* gfp flags to use on each alloc */
77798- int refcount; /* Refcount for slab cache destroy */
77799+ atomic_t refcount; /* Refcount for slab cache destroy */
77800 void (*ctor)(void *);
77801 int inuse; /* Offset to metadata */
77802 int align; /* Alignment */
77803diff --git a/include/linux/smp.h b/include/linux/smp.h
77804index 731f523..3340268 100644
77805--- a/include/linux/smp.h
77806+++ b/include/linux/smp.h
77807@@ -186,7 +186,9 @@ static inline void __smp_call_function_single(int cpuid,
77808 #endif
77809
77810 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
77811+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
77812 #define put_cpu() preempt_enable()
77813+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
77814
77815 /*
77816 * Callback to arch code if there's nosmp or maxcpus=0 on the
77817diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
77818index 54f91d3..be2c379 100644
77819--- a/include/linux/sock_diag.h
77820+++ b/include/linux/sock_diag.h
77821@@ -11,7 +11,7 @@ struct sock;
77822 struct sock_diag_handler {
77823 __u8 family;
77824 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
77825-};
77826+} __do_const;
77827
77828 int sock_diag_register(const struct sock_diag_handler *h);
77829 void sock_diag_unregister(const struct sock_diag_handler *h);
77830diff --git a/include/linux/sonet.h b/include/linux/sonet.h
77831index 680f9a3..f13aeb0 100644
77832--- a/include/linux/sonet.h
77833+++ b/include/linux/sonet.h
77834@@ -7,7 +7,7 @@
77835 #include <uapi/linux/sonet.h>
77836
77837 struct k_sonet_stats {
77838-#define __HANDLE_ITEM(i) atomic_t i
77839+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77840 __SONET_ITEMS
77841 #undef __HANDLE_ITEM
77842 };
77843diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
77844index 07d8e53..dc934c9 100644
77845--- a/include/linux/sunrpc/addr.h
77846+++ b/include/linux/sunrpc/addr.h
77847@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
77848 {
77849 switch (sap->sa_family) {
77850 case AF_INET:
77851- return ntohs(((struct sockaddr_in *)sap)->sin_port);
77852+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
77853 case AF_INET6:
77854- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
77855+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
77856 }
77857 return 0;
77858 }
77859@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
77860 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
77861 const struct sockaddr *src)
77862 {
77863- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
77864+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
77865 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
77866
77867 dsin->sin_family = ssin->sin_family;
77868@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
77869 if (sa->sa_family != AF_INET6)
77870 return 0;
77871
77872- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
77873+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
77874 }
77875
77876 #endif /* _LINUX_SUNRPC_ADDR_H */
77877diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
77878index 6740801..c535f27 100644
77879--- a/include/linux/sunrpc/clnt.h
77880+++ b/include/linux/sunrpc/clnt.h
77881@@ -96,7 +96,7 @@ struct rpc_procinfo {
77882 unsigned int p_timer; /* Which RTT timer to use */
77883 u32 p_statidx; /* Which procedure to account */
77884 const char * p_name; /* name of procedure */
77885-};
77886+} __do_const;
77887
77888 #ifdef __KERNEL__
77889
77890diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
77891index 6eecfc2..7ada79d 100644
77892--- a/include/linux/sunrpc/svc.h
77893+++ b/include/linux/sunrpc/svc.h
77894@@ -410,7 +410,7 @@ struct svc_procedure {
77895 unsigned int pc_count; /* call count */
77896 unsigned int pc_cachetype; /* cache info (NFS) */
77897 unsigned int pc_xdrressize; /* maximum size of XDR reply */
77898-};
77899+} __do_const;
77900
77901 /*
77902 * Function prototypes.
77903diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
77904index 0b8e3e6..33e0a01 100644
77905--- a/include/linux/sunrpc/svc_rdma.h
77906+++ b/include/linux/sunrpc/svc_rdma.h
77907@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
77908 extern unsigned int svcrdma_max_requests;
77909 extern unsigned int svcrdma_max_req_size;
77910
77911-extern atomic_t rdma_stat_recv;
77912-extern atomic_t rdma_stat_read;
77913-extern atomic_t rdma_stat_write;
77914-extern atomic_t rdma_stat_sq_starve;
77915-extern atomic_t rdma_stat_rq_starve;
77916-extern atomic_t rdma_stat_rq_poll;
77917-extern atomic_t rdma_stat_rq_prod;
77918-extern atomic_t rdma_stat_sq_poll;
77919-extern atomic_t rdma_stat_sq_prod;
77920+extern atomic_unchecked_t rdma_stat_recv;
77921+extern atomic_unchecked_t rdma_stat_read;
77922+extern atomic_unchecked_t rdma_stat_write;
77923+extern atomic_unchecked_t rdma_stat_sq_starve;
77924+extern atomic_unchecked_t rdma_stat_rq_starve;
77925+extern atomic_unchecked_t rdma_stat_rq_poll;
77926+extern atomic_unchecked_t rdma_stat_rq_prod;
77927+extern atomic_unchecked_t rdma_stat_sq_poll;
77928+extern atomic_unchecked_t rdma_stat_sq_prod;
77929
77930 #define RPCRDMA_VERSION 1
77931
77932diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
77933index 8d71d65..f79586e 100644
77934--- a/include/linux/sunrpc/svcauth.h
77935+++ b/include/linux/sunrpc/svcauth.h
77936@@ -120,7 +120,7 @@ struct auth_ops {
77937 int (*release)(struct svc_rqst *rq);
77938 void (*domain_release)(struct auth_domain *);
77939 int (*set_client)(struct svc_rqst *rq);
77940-};
77941+} __do_const;
77942
77943 #define SVC_GARBAGE 1
77944 #define SVC_SYSERR 2
77945diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
77946index a5ffd32..0935dea 100644
77947--- a/include/linux/swiotlb.h
77948+++ b/include/linux/swiotlb.h
77949@@ -60,7 +60,8 @@ extern void
77950
77951 extern void
77952 swiotlb_free_coherent(struct device *hwdev, size_t size,
77953- void *vaddr, dma_addr_t dma_handle);
77954+ void *vaddr, dma_addr_t dma_handle,
77955+ struct dma_attrs *attrs);
77956
77957 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77958 unsigned long offset, size_t size,
77959diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77960index 7fac04e..de57300 100644
77961--- a/include/linux/syscalls.h
77962+++ b/include/linux/syscalls.h
77963@@ -97,8 +97,14 @@ struct sigaltstack;
77964 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77965
77966 #define __SC_DECL(t, a) t a
77967+#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))
77968 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77969-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77970+#define __SC_LONG(t, a) __typeof( \
77971+ __builtin_choose_expr( \
77972+ sizeof(t) > sizeof(int), \
77973+ (t) 0, \
77974+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77975+ )) a
77976 #define __SC_CAST(t, a) (t) a
77977 #define __SC_ARGS(t, a) a
77978 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77979@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
77980 asmlinkage long sys_fsync(unsigned int fd);
77981 asmlinkage long sys_fdatasync(unsigned int fd);
77982 asmlinkage long sys_bdflush(int func, long data);
77983-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77984- char __user *type, unsigned long flags,
77985+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77986+ const char __user *type, unsigned long flags,
77987 void __user *data);
77988-asmlinkage long sys_umount(char __user *name, int flags);
77989-asmlinkage long sys_oldumount(char __user *name);
77990+asmlinkage long sys_umount(const char __user *name, int flags);
77991+asmlinkage long sys_oldumount(const char __user *name);
77992 asmlinkage long sys_truncate(const char __user *path, long length);
77993 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77994 asmlinkage long sys_stat(const char __user *filename,
77995@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77996 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77997 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77998 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77999- struct sockaddr __user *, int);
78000+ struct sockaddr __user *, int) __intentional_overflow(0);
78001 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
78002 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
78003 unsigned int vlen, unsigned flags);
78004diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
78005index 27b3b0b..e093dd9 100644
78006--- a/include/linux/syscore_ops.h
78007+++ b/include/linux/syscore_ops.h
78008@@ -16,7 +16,7 @@ struct syscore_ops {
78009 int (*suspend)(void);
78010 void (*resume)(void);
78011 void (*shutdown)(void);
78012-};
78013+} __do_const;
78014
78015 extern void register_syscore_ops(struct syscore_ops *ops);
78016 extern void unregister_syscore_ops(struct syscore_ops *ops);
78017diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
78018index 14a8ff2..af52bad 100644
78019--- a/include/linux/sysctl.h
78020+++ b/include/linux/sysctl.h
78021@@ -34,13 +34,13 @@ struct ctl_table_root;
78022 struct ctl_table_header;
78023 struct ctl_dir;
78024
78025-typedef struct ctl_table ctl_table;
78026-
78027 typedef int proc_handler (struct ctl_table *ctl, int write,
78028 void __user *buffer, size_t *lenp, loff_t *ppos);
78029
78030 extern int proc_dostring(struct ctl_table *, int,
78031 void __user *, size_t *, loff_t *);
78032+extern int proc_dostring_modpriv(struct ctl_table *, int,
78033+ void __user *, size_t *, loff_t *);
78034 extern int proc_dointvec(struct ctl_table *, int,
78035 void __user *, size_t *, loff_t *);
78036 extern int proc_dointvec_minmax(struct ctl_table *, int,
78037@@ -115,7 +115,9 @@ struct ctl_table
78038 struct ctl_table_poll *poll;
78039 void *extra1;
78040 void *extra2;
78041-};
78042+} __do_const;
78043+typedef struct ctl_table __no_const ctl_table_no_const;
78044+typedef struct ctl_table ctl_table;
78045
78046 struct ctl_node {
78047 struct rb_node node;
78048diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
78049index 11baec7..706f99f 100644
78050--- a/include/linux/sysfs.h
78051+++ b/include/linux/sysfs.h
78052@@ -33,7 +33,8 @@ struct attribute {
78053 struct lock_class_key *key;
78054 struct lock_class_key skey;
78055 #endif
78056-};
78057+} __do_const;
78058+typedef struct attribute __no_const attribute_no_const;
78059
78060 /**
78061 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
78062@@ -62,7 +63,8 @@ struct attribute_group {
78063 struct attribute *, int);
78064 struct attribute **attrs;
78065 struct bin_attribute **bin_attrs;
78066-};
78067+} __do_const;
78068+typedef struct attribute_group __no_const attribute_group_no_const;
78069
78070 /**
78071 * Use these macros to make defining attributes easier. See include/linux/device.h
78072@@ -126,7 +128,8 @@ struct bin_attribute {
78073 char *, loff_t, size_t);
78074 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
78075 struct vm_area_struct *vma);
78076-};
78077+} __do_const;
78078+typedef struct bin_attribute __no_const bin_attribute_no_const;
78079
78080 /**
78081 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
78082diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
78083index 7faf933..9b85a0c 100644
78084--- a/include/linux/sysrq.h
78085+++ b/include/linux/sysrq.h
78086@@ -16,6 +16,7 @@
78087
78088 #include <linux/errno.h>
78089 #include <linux/types.h>
78090+#include <linux/compiler.h>
78091
78092 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
78093 #define SYSRQ_DEFAULT_ENABLE 1
78094@@ -36,7 +37,7 @@ struct sysrq_key_op {
78095 char *help_msg;
78096 char *action_msg;
78097 int enable_mask;
78098-};
78099+} __do_const;
78100
78101 #ifdef CONFIG_MAGIC_SYSRQ
78102
78103diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
78104index 4ae6f32..425d3e1 100644
78105--- a/include/linux/thread_info.h
78106+++ b/include/linux/thread_info.h
78107@@ -150,6 +150,15 @@ static inline bool test_and_clear_restore_sigmask(void)
78108 #error "no set_restore_sigmask() provided and default one won't work"
78109 #endif
78110
78111+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
78112+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
78113+{
78114+#ifndef CONFIG_PAX_USERCOPY_DEBUG
78115+ if (!__builtin_constant_p(n))
78116+#endif
78117+ __check_object_size(ptr, n, to_user);
78118+}
78119+
78120 #endif /* __KERNEL__ */
78121
78122 #endif /* _LINUX_THREAD_INFO_H */
78123diff --git a/include/linux/tty.h b/include/linux/tty.h
78124index 64f8646..1515fc7 100644
78125--- a/include/linux/tty.h
78126+++ b/include/linux/tty.h
78127@@ -197,7 +197,7 @@ struct tty_port {
78128 const struct tty_port_operations *ops; /* Port operations */
78129 spinlock_t lock; /* Lock protecting tty field */
78130 int blocked_open; /* Waiting to open */
78131- int count; /* Usage count */
78132+ atomic_t count; /* Usage count */
78133 wait_queue_head_t open_wait; /* Open waiters */
78134 wait_queue_head_t close_wait; /* Close waiters */
78135 wait_queue_head_t delta_msr_wait; /* Modem status change */
78136@@ -546,7 +546,7 @@ extern int tty_port_open(struct tty_port *port,
78137 struct tty_struct *tty, struct file *filp);
78138 static inline int tty_port_users(struct tty_port *port)
78139 {
78140- return port->count + port->blocked_open;
78141+ return atomic_read(&port->count) + port->blocked_open;
78142 }
78143
78144 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
78145diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
78146index 756a609..b302dd6 100644
78147--- a/include/linux/tty_driver.h
78148+++ b/include/linux/tty_driver.h
78149@@ -285,7 +285,7 @@ struct tty_operations {
78150 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
78151 #endif
78152 const struct file_operations *proc_fops;
78153-};
78154+} __do_const;
78155
78156 struct tty_driver {
78157 int magic; /* magic number for this structure */
78158diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
78159index f15c898..207b7d1 100644
78160--- a/include/linux/tty_ldisc.h
78161+++ b/include/linux/tty_ldisc.h
78162@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
78163
78164 struct module *owner;
78165
78166- int refcount;
78167+ atomic_t refcount;
78168 };
78169
78170 struct tty_ldisc {
78171diff --git a/include/linux/types.h b/include/linux/types.h
78172index 4d118ba..c3ee9bf 100644
78173--- a/include/linux/types.h
78174+++ b/include/linux/types.h
78175@@ -176,10 +176,26 @@ typedef struct {
78176 int counter;
78177 } atomic_t;
78178
78179+#ifdef CONFIG_PAX_REFCOUNT
78180+typedef struct {
78181+ int counter;
78182+} atomic_unchecked_t;
78183+#else
78184+typedef atomic_t atomic_unchecked_t;
78185+#endif
78186+
78187 #ifdef CONFIG_64BIT
78188 typedef struct {
78189 long counter;
78190 } atomic64_t;
78191+
78192+#ifdef CONFIG_PAX_REFCOUNT
78193+typedef struct {
78194+ long counter;
78195+} atomic64_unchecked_t;
78196+#else
78197+typedef atomic64_t atomic64_unchecked_t;
78198+#endif
78199 #endif
78200
78201 struct list_head {
78202diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
78203index 5ca0951..ab496a5 100644
78204--- a/include/linux/uaccess.h
78205+++ b/include/linux/uaccess.h
78206@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
78207 long ret; \
78208 mm_segment_t old_fs = get_fs(); \
78209 \
78210- set_fs(KERNEL_DS); \
78211 pagefault_disable(); \
78212- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
78213- pagefault_enable(); \
78214+ set_fs(KERNEL_DS); \
78215+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
78216 set_fs(old_fs); \
78217+ pagefault_enable(); \
78218 ret; \
78219 })
78220
78221diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
78222index 8e522cbc..aa8572d 100644
78223--- a/include/linux/uidgid.h
78224+++ b/include/linux/uidgid.h
78225@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
78226
78227 #endif /* CONFIG_USER_NS */
78228
78229+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
78230+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
78231+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
78232+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
78233+
78234 #endif /* _LINUX_UIDGID_H */
78235diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
78236index 99c1b4d..562e6f3 100644
78237--- a/include/linux/unaligned/access_ok.h
78238+++ b/include/linux/unaligned/access_ok.h
78239@@ -4,34 +4,34 @@
78240 #include <linux/kernel.h>
78241 #include <asm/byteorder.h>
78242
78243-static inline u16 get_unaligned_le16(const void *p)
78244+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
78245 {
78246- return le16_to_cpup((__le16 *)p);
78247+ return le16_to_cpup((const __le16 *)p);
78248 }
78249
78250-static inline u32 get_unaligned_le32(const void *p)
78251+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
78252 {
78253- return le32_to_cpup((__le32 *)p);
78254+ return le32_to_cpup((const __le32 *)p);
78255 }
78256
78257-static inline u64 get_unaligned_le64(const void *p)
78258+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
78259 {
78260- return le64_to_cpup((__le64 *)p);
78261+ return le64_to_cpup((const __le64 *)p);
78262 }
78263
78264-static inline u16 get_unaligned_be16(const void *p)
78265+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
78266 {
78267- return be16_to_cpup((__be16 *)p);
78268+ return be16_to_cpup((const __be16 *)p);
78269 }
78270
78271-static inline u32 get_unaligned_be32(const void *p)
78272+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
78273 {
78274- return be32_to_cpup((__be32 *)p);
78275+ return be32_to_cpup((const __be32 *)p);
78276 }
78277
78278-static inline u64 get_unaligned_be64(const void *p)
78279+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
78280 {
78281- return be64_to_cpup((__be64 *)p);
78282+ return be64_to_cpup((const __be64 *)p);
78283 }
78284
78285 static inline void put_unaligned_le16(u16 val, void *p)
78286diff --git a/include/linux/usb.h b/include/linux/usb.h
78287index 39cfa0a..d45fa38 100644
78288--- a/include/linux/usb.h
78289+++ b/include/linux/usb.h
78290@@ -563,7 +563,7 @@ struct usb_device {
78291 int maxchild;
78292
78293 u32 quirks;
78294- atomic_t urbnum;
78295+ atomic_unchecked_t urbnum;
78296
78297 unsigned long active_duration;
78298
78299@@ -1637,7 +1637,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
78300
78301 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
78302 __u8 request, __u8 requesttype, __u16 value, __u16 index,
78303- void *data, __u16 size, int timeout);
78304+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
78305 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
78306 void *data, int len, int *actual_length, int timeout);
78307 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
78308diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
78309index e452ba6..78f8e80 100644
78310--- a/include/linux/usb/renesas_usbhs.h
78311+++ b/include/linux/usb/renesas_usbhs.h
78312@@ -39,7 +39,7 @@ enum {
78313 */
78314 struct renesas_usbhs_driver_callback {
78315 int (*notify_hotplug)(struct platform_device *pdev);
78316-};
78317+} __no_const;
78318
78319 /*
78320 * callback functions for platform
78321diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
78322index 6f8fbcf..8259001 100644
78323--- a/include/linux/vermagic.h
78324+++ b/include/linux/vermagic.h
78325@@ -25,9 +25,35 @@
78326 #define MODULE_ARCH_VERMAGIC ""
78327 #endif
78328
78329+#ifdef CONFIG_PAX_REFCOUNT
78330+#define MODULE_PAX_REFCOUNT "REFCOUNT "
78331+#else
78332+#define MODULE_PAX_REFCOUNT ""
78333+#endif
78334+
78335+#ifdef CONSTIFY_PLUGIN
78336+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
78337+#else
78338+#define MODULE_CONSTIFY_PLUGIN ""
78339+#endif
78340+
78341+#ifdef STACKLEAK_PLUGIN
78342+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
78343+#else
78344+#define MODULE_STACKLEAK_PLUGIN ""
78345+#endif
78346+
78347+#ifdef CONFIG_GRKERNSEC
78348+#define MODULE_GRSEC "GRSEC "
78349+#else
78350+#define MODULE_GRSEC ""
78351+#endif
78352+
78353 #define VERMAGIC_STRING \
78354 UTS_RELEASE " " \
78355 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
78356 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
78357- MODULE_ARCH_VERMAGIC
78358+ MODULE_ARCH_VERMAGIC \
78359+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
78360+ MODULE_GRSEC
78361
78362diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
78363index 502073a..a7de024 100644
78364--- a/include/linux/vga_switcheroo.h
78365+++ b/include/linux/vga_switcheroo.h
78366@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
78367
78368 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
78369
78370-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
78371-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
78372+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
78373+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
78374 #else
78375
78376 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
78377@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
78378
78379 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
78380
78381-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
78382-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
78383+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
78384+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
78385
78386 #endif
78387 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
78388diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
78389index 4b8a891..cc929b4 100644
78390--- a/include/linux/vmalloc.h
78391+++ b/include/linux/vmalloc.h
78392@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
78393 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
78394 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
78395 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
78396+
78397+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78398+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
78399+#endif
78400+
78401 /* bits [20..32] reserved for arch specific ioremap internals */
78402
78403 /*
78404@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
78405 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
78406 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
78407 unsigned long start, unsigned long end, gfp_t gfp_mask,
78408- pgprot_t prot, int node, const void *caller);
78409+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
78410 extern void vfree(const void *addr);
78411
78412 extern void *vmap(struct page **pages, unsigned int count,
78413@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
78414
78415 /* for /dev/kmem */
78416 extern long vread(char *buf, char *addr, unsigned long count);
78417-extern long vwrite(char *buf, char *addr, unsigned long count);
78418+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
78419
78420 /*
78421 * Internals. Dont't use..
78422diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
78423index e4b9480..b96d5ab 100644
78424--- a/include/linux/vmstat.h
78425+++ b/include/linux/vmstat.h
78426@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
78427 /*
78428 * Zone based page accounting with per cpu differentials.
78429 */
78430-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78431+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78432
78433 static inline void zone_page_state_add(long x, struct zone *zone,
78434 enum zone_stat_item item)
78435 {
78436- atomic_long_add(x, &zone->vm_stat[item]);
78437- atomic_long_add(x, &vm_stat[item]);
78438+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
78439+ atomic_long_add_unchecked(x, &vm_stat[item]);
78440 }
78441
78442 static inline unsigned long global_page_state(enum zone_stat_item item)
78443 {
78444- long x = atomic_long_read(&vm_stat[item]);
78445+ long x = atomic_long_read_unchecked(&vm_stat[item]);
78446 #ifdef CONFIG_SMP
78447 if (x < 0)
78448 x = 0;
78449@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
78450 static inline unsigned long zone_page_state(struct zone *zone,
78451 enum zone_stat_item item)
78452 {
78453- long x = atomic_long_read(&zone->vm_stat[item]);
78454+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78455 #ifdef CONFIG_SMP
78456 if (x < 0)
78457 x = 0;
78458@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
78459 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
78460 enum zone_stat_item item)
78461 {
78462- long x = atomic_long_read(&zone->vm_stat[item]);
78463+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78464
78465 #ifdef CONFIG_SMP
78466 int cpu;
78467@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
78468
78469 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
78470 {
78471- atomic_long_inc(&zone->vm_stat[item]);
78472- atomic_long_inc(&vm_stat[item]);
78473+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
78474+ atomic_long_inc_unchecked(&vm_stat[item]);
78475 }
78476
78477 static inline void __inc_zone_page_state(struct page *page,
78478@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
78479
78480 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
78481 {
78482- atomic_long_dec(&zone->vm_stat[item]);
78483- atomic_long_dec(&vm_stat[item]);
78484+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
78485+ atomic_long_dec_unchecked(&vm_stat[item]);
78486 }
78487
78488 static inline void __dec_zone_page_state(struct page *page,
78489diff --git a/include/linux/xattr.h b/include/linux/xattr.h
78490index 91b0a68..0e9adf6 100644
78491--- a/include/linux/xattr.h
78492+++ b/include/linux/xattr.h
78493@@ -28,7 +28,7 @@ struct xattr_handler {
78494 size_t size, int handler_flags);
78495 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
78496 size_t size, int flags, int handler_flags);
78497-};
78498+} __do_const;
78499
78500 struct xattr {
78501 const char *name;
78502@@ -37,6 +37,9 @@ struct xattr {
78503 };
78504
78505 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
78506+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78507+ssize_t pax_getxattr(struct dentry *, void *, size_t);
78508+#endif
78509 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
78510 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
78511 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
78512diff --git a/include/linux/zlib.h b/include/linux/zlib.h
78513index 9c5a6b4..09c9438 100644
78514--- a/include/linux/zlib.h
78515+++ b/include/linux/zlib.h
78516@@ -31,6 +31,7 @@
78517 #define _ZLIB_H
78518
78519 #include <linux/zconf.h>
78520+#include <linux/compiler.h>
78521
78522 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
78523 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
78524@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
78525
78526 /* basic functions */
78527
78528-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
78529+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
78530 /*
78531 Returns the number of bytes that needs to be allocated for a per-
78532 stream workspace with the specified parameters. A pointer to this
78533diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
78534index c768c9f..bdcaa5a 100644
78535--- a/include/media/v4l2-dev.h
78536+++ b/include/media/v4l2-dev.h
78537@@ -76,7 +76,7 @@ struct v4l2_file_operations {
78538 int (*mmap) (struct file *, struct vm_area_struct *);
78539 int (*open) (struct file *);
78540 int (*release) (struct file *);
78541-};
78542+} __do_const;
78543
78544 /*
78545 * Newer version of video_device, handled by videodev2.c
78546diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
78547index c9b1593..a572459 100644
78548--- a/include/media/v4l2-device.h
78549+++ b/include/media/v4l2-device.h
78550@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
78551 this function returns 0. If the name ends with a digit (e.g. cx18),
78552 then the name will be set to cx18-0 since cx180 looks really odd. */
78553 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
78554- atomic_t *instance);
78555+ atomic_unchecked_t *instance);
78556
78557 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
78558 Since the parent disappears this ensures that v4l2_dev doesn't have an
78559diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
78560index 9a36d92..0aafe2a 100644
78561--- a/include/net/9p/transport.h
78562+++ b/include/net/9p/transport.h
78563@@ -60,7 +60,7 @@ struct p9_trans_module {
78564 int (*cancel) (struct p9_client *, struct p9_req_t *req);
78565 int (*zc_request)(struct p9_client *, struct p9_req_t *,
78566 char *, char *, int , int, int, int);
78567-};
78568+} __do_const;
78569
78570 void v9fs_register_trans(struct p9_trans_module *m);
78571 void v9fs_unregister_trans(struct p9_trans_module *m);
78572diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
78573index 1a966af..2767cf6 100644
78574--- a/include/net/bluetooth/l2cap.h
78575+++ b/include/net/bluetooth/l2cap.h
78576@@ -551,7 +551,7 @@ struct l2cap_ops {
78577 void (*defer) (struct l2cap_chan *chan);
78578 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
78579 unsigned long len, int nb);
78580-};
78581+} __do_const;
78582
78583 struct l2cap_conn {
78584 struct hci_conn *hcon;
78585diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
78586index f2ae33d..c457cf0 100644
78587--- a/include/net/caif/cfctrl.h
78588+++ b/include/net/caif/cfctrl.h
78589@@ -52,7 +52,7 @@ struct cfctrl_rsp {
78590 void (*radioset_rsp)(void);
78591 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
78592 struct cflayer *client_layer);
78593-};
78594+} __no_const;
78595
78596 /* Link Setup Parameters for CAIF-Links. */
78597 struct cfctrl_link_param {
78598@@ -101,8 +101,8 @@ struct cfctrl_request_info {
78599 struct cfctrl {
78600 struct cfsrvl serv;
78601 struct cfctrl_rsp res;
78602- atomic_t req_seq_no;
78603- atomic_t rsp_seq_no;
78604+ atomic_unchecked_t req_seq_no;
78605+ atomic_unchecked_t rsp_seq_no;
78606 struct list_head list;
78607 /* Protects from simultaneous access to first_req list */
78608 spinlock_t info_list_lock;
78609diff --git a/include/net/flow.h b/include/net/flow.h
78610index 628e11b..4c475df 100644
78611--- a/include/net/flow.h
78612+++ b/include/net/flow.h
78613@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
78614
78615 extern void flow_cache_flush(void);
78616 extern void flow_cache_flush_deferred(void);
78617-extern atomic_t flow_cache_genid;
78618+extern atomic_unchecked_t flow_cache_genid;
78619
78620 #endif
78621diff --git a/include/net/genetlink.h b/include/net/genetlink.h
78622index 8e0b6c8..73cf605 100644
78623--- a/include/net/genetlink.h
78624+++ b/include/net/genetlink.h
78625@@ -120,7 +120,7 @@ struct genl_ops {
78626 struct netlink_callback *cb);
78627 int (*done)(struct netlink_callback *cb);
78628 struct list_head ops_list;
78629-};
78630+} __do_const;
78631
78632 extern int __genl_register_family(struct genl_family *family);
78633
78634diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
78635index 734d9b5..48a9a4b 100644
78636--- a/include/net/gro_cells.h
78637+++ b/include/net/gro_cells.h
78638@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
78639 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
78640
78641 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
78642- atomic_long_inc(&dev->rx_dropped);
78643+ atomic_long_inc_unchecked(&dev->rx_dropped);
78644 kfree_skb(skb);
78645 return;
78646 }
78647diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
78648index de2c785..0588a6b 100644
78649--- a/include/net/inet_connection_sock.h
78650+++ b/include/net/inet_connection_sock.h
78651@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
78652 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
78653 int (*bind_conflict)(const struct sock *sk,
78654 const struct inet_bind_bucket *tb, bool relax);
78655-};
78656+} __do_const;
78657
78658 /** inet_connection_sock - INET connection oriented sock
78659 *
78660diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
78661index 53f464d..0bd0b49 100644
78662--- a/include/net/inetpeer.h
78663+++ b/include/net/inetpeer.h
78664@@ -47,8 +47,8 @@ struct inet_peer {
78665 */
78666 union {
78667 struct {
78668- atomic_t rid; /* Frag reception counter */
78669- atomic_t ip_id_count; /* IP ID for the next packet */
78670+ atomic_unchecked_t rid; /* Frag reception counter */
78671+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
78672 };
78673 struct rcu_head rcu;
78674 struct inet_peer *gc_next;
78675@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
78676 /* can be called with or without local BH being disabled */
78677 static inline int inet_getid(struct inet_peer *p, int more)
78678 {
78679- int old, new;
78680+ int id;
78681 more++;
78682 inet_peer_refcheck(p);
78683- do {
78684- old = atomic_read(&p->ip_id_count);
78685- new = old + more;
78686- if (!new)
78687- new = 1;
78688- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
78689- return new;
78690+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
78691+ if (!id)
78692+ id = atomic_inc_return_unchecked(&p->ip_id_count);
78693+ return id;
78694 }
78695
78696 #endif /* _NET_INETPEER_H */
78697diff --git a/include/net/ip.h b/include/net/ip.h
78698index 5e52688..f181e95 100644
78699--- a/include/net/ip.h
78700+++ b/include/net/ip.h
78701@@ -212,7 +212,7 @@ extern struct local_ports {
78702 } sysctl_local_ports;
78703 extern void inet_get_local_port_range(int *low, int *high);
78704
78705-extern unsigned long *sysctl_local_reserved_ports;
78706+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
78707 static inline int inet_is_reserved_local_port(int port)
78708 {
78709 return test_bit(port, sysctl_local_reserved_ports);
78710diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
78711index cbf2be3..3683f6d 100644
78712--- a/include/net/ip_fib.h
78713+++ b/include/net/ip_fib.h
78714@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
78715
78716 #define FIB_RES_SADDR(net, res) \
78717 ((FIB_RES_NH(res).nh_saddr_genid == \
78718- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
78719+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
78720 FIB_RES_NH(res).nh_saddr : \
78721 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
78722 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
78723diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
78724index 9c4d37e..eed6d41 100644
78725--- a/include/net/ip_vs.h
78726+++ b/include/net/ip_vs.h
78727@@ -588,7 +588,7 @@ struct ip_vs_conn {
78728 struct ip_vs_conn *control; /* Master control connection */
78729 atomic_t n_control; /* Number of controlled ones */
78730 struct ip_vs_dest *dest; /* real server */
78731- atomic_t in_pkts; /* incoming packet counter */
78732+ atomic_unchecked_t in_pkts; /* incoming packet counter */
78733
78734 /* packet transmitter for different forwarding methods. If it
78735 mangles the packet, it must return NF_DROP or better NF_STOLEN,
78736@@ -735,7 +735,7 @@ struct ip_vs_dest {
78737 __be16 port; /* port number of the server */
78738 union nf_inet_addr addr; /* IP address of the server */
78739 volatile unsigned int flags; /* dest status flags */
78740- atomic_t conn_flags; /* flags to copy to conn */
78741+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
78742 atomic_t weight; /* server weight */
78743
78744 atomic_t refcnt; /* reference counter */
78745@@ -990,11 +990,11 @@ struct netns_ipvs {
78746 /* ip_vs_lblc */
78747 int sysctl_lblc_expiration;
78748 struct ctl_table_header *lblc_ctl_header;
78749- struct ctl_table *lblc_ctl_table;
78750+ ctl_table_no_const *lblc_ctl_table;
78751 /* ip_vs_lblcr */
78752 int sysctl_lblcr_expiration;
78753 struct ctl_table_header *lblcr_ctl_header;
78754- struct ctl_table *lblcr_ctl_table;
78755+ ctl_table_no_const *lblcr_ctl_table;
78756 /* ip_vs_est */
78757 struct list_head est_list; /* estimator list */
78758 spinlock_t est_lock;
78759diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
78760index 80ffde3..968b0f4 100644
78761--- a/include/net/irda/ircomm_tty.h
78762+++ b/include/net/irda/ircomm_tty.h
78763@@ -35,6 +35,7 @@
78764 #include <linux/termios.h>
78765 #include <linux/timer.h>
78766 #include <linux/tty.h> /* struct tty_struct */
78767+#include <asm/local.h>
78768
78769 #include <net/irda/irias_object.h>
78770 #include <net/irda/ircomm_core.h>
78771diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
78772index 714cc9a..ea05f3e 100644
78773--- a/include/net/iucv/af_iucv.h
78774+++ b/include/net/iucv/af_iucv.h
78775@@ -149,7 +149,7 @@ struct iucv_skb_cb {
78776 struct iucv_sock_list {
78777 struct hlist_head head;
78778 rwlock_t lock;
78779- atomic_t autobind_name;
78780+ atomic_unchecked_t autobind_name;
78781 };
78782
78783 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
78784diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
78785index df83f69..9b640b8 100644
78786--- a/include/net/llc_c_ac.h
78787+++ b/include/net/llc_c_ac.h
78788@@ -87,7 +87,7 @@
78789 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
78790 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
78791
78792-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
78793+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
78794
78795 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
78796 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
78797diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
78798index 6ca3113..f8026dd 100644
78799--- a/include/net/llc_c_ev.h
78800+++ b/include/net/llc_c_ev.h
78801@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
78802 return (struct llc_conn_state_ev *)skb->cb;
78803 }
78804
78805-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
78806-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
78807+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
78808+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
78809
78810 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
78811 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
78812diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
78813index 0e79cfb..f46db31 100644
78814--- a/include/net/llc_c_st.h
78815+++ b/include/net/llc_c_st.h
78816@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
78817 u8 next_state;
78818 llc_conn_ev_qfyr_t *ev_qualifiers;
78819 llc_conn_action_t *ev_actions;
78820-};
78821+} __do_const;
78822
78823 struct llc_conn_state {
78824 u8 current_state;
78825diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
78826index 37a3bbd..55a4241 100644
78827--- a/include/net/llc_s_ac.h
78828+++ b/include/net/llc_s_ac.h
78829@@ -23,7 +23,7 @@
78830 #define SAP_ACT_TEST_IND 9
78831
78832 /* All action functions must look like this */
78833-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
78834+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
78835
78836 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
78837 struct sk_buff *skb);
78838diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
78839index 567c681..cd73ac0 100644
78840--- a/include/net/llc_s_st.h
78841+++ b/include/net/llc_s_st.h
78842@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
78843 llc_sap_ev_t ev;
78844 u8 next_state;
78845 llc_sap_action_t *ev_actions;
78846-};
78847+} __do_const;
78848
78849 struct llc_sap_state {
78850 u8 curr_state;
78851diff --git a/include/net/mac80211.h b/include/net/mac80211.h
78852index cc6035f..a8406fc 100644
78853--- a/include/net/mac80211.h
78854+++ b/include/net/mac80211.h
78855@@ -4361,7 +4361,7 @@ struct rate_control_ops {
78856 void (*add_sta_debugfs)(void *priv, void *priv_sta,
78857 struct dentry *dir);
78858 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
78859-};
78860+} __do_const;
78861
78862 static inline int rate_supported(struct ieee80211_sta *sta,
78863 enum ieee80211_band band,
78864diff --git a/include/net/neighbour.h b/include/net/neighbour.h
78865index 536501a..7c6193c 100644
78866--- a/include/net/neighbour.h
78867+++ b/include/net/neighbour.h
78868@@ -123,7 +123,7 @@ struct neigh_ops {
78869 void (*error_report)(struct neighbour *, struct sk_buff *);
78870 int (*output)(struct neighbour *, struct sk_buff *);
78871 int (*connected_output)(struct neighbour *, struct sk_buff *);
78872-};
78873+} __do_const;
78874
78875 struct pneigh_entry {
78876 struct pneigh_entry *next;
78877diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
78878index 9d22f08..980fbf8 100644
78879--- a/include/net/net_namespace.h
78880+++ b/include/net/net_namespace.h
78881@@ -120,7 +120,7 @@ struct net {
78882 struct netns_ipvs *ipvs;
78883 #endif
78884 struct sock *diag_nlsk;
78885- atomic_t fnhe_genid;
78886+ atomic_unchecked_t fnhe_genid;
78887 };
78888
78889 /*
78890@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
78891 #define __net_init __init
78892 #define __net_exit __exit_refok
78893 #define __net_initdata __initdata
78894+#ifdef CONSTIFY_PLUGIN
78895 #define __net_initconst __initconst
78896+#else
78897+#define __net_initconst __initdata
78898+#endif
78899 #endif
78900
78901 struct pernet_operations {
78902@@ -287,7 +291,7 @@ struct pernet_operations {
78903 void (*exit_batch)(struct list_head *net_exit_list);
78904 int *id;
78905 size_t size;
78906-};
78907+} __do_const;
78908
78909 /*
78910 * Use these carefully. If you implement a network device and it
78911@@ -335,23 +339,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
78912
78913 static inline int rt_genid_ipv4(struct net *net)
78914 {
78915- return atomic_read(&net->ipv4.rt_genid);
78916+ return atomic_read_unchecked(&net->ipv4.rt_genid);
78917 }
78918
78919 static inline void rt_genid_bump_ipv4(struct net *net)
78920 {
78921- atomic_inc(&net->ipv4.rt_genid);
78922+ atomic_inc_unchecked(&net->ipv4.rt_genid);
78923 }
78924
78925 #if IS_ENABLED(CONFIG_IPV6)
78926 static inline int rt_genid_ipv6(struct net *net)
78927 {
78928- return atomic_read(&net->ipv6.rt_genid);
78929+ return atomic_read_unchecked(&net->ipv6.rt_genid);
78930 }
78931
78932 static inline void rt_genid_bump_ipv6(struct net *net)
78933 {
78934- atomic_inc(&net->ipv6.rt_genid);
78935+ atomic_inc_unchecked(&net->ipv6.rt_genid);
78936 }
78937 #else
78938 static inline int rt_genid_ipv6(struct net *net)
78939@@ -373,12 +377,12 @@ static inline void rt_genid_bump_all(struct net *net)
78940
78941 static inline int fnhe_genid(struct net *net)
78942 {
78943- return atomic_read(&net->fnhe_genid);
78944+ return atomic_read_unchecked(&net->fnhe_genid);
78945 }
78946
78947 static inline void fnhe_genid_bump(struct net *net)
78948 {
78949- atomic_inc(&net->fnhe_genid);
78950+ atomic_inc_unchecked(&net->fnhe_genid);
78951 }
78952
78953 #endif /* __NET_NET_NAMESPACE_H */
78954diff --git a/include/net/netdma.h b/include/net/netdma.h
78955index 8ba8ce2..99b7fff 100644
78956--- a/include/net/netdma.h
78957+++ b/include/net/netdma.h
78958@@ -24,7 +24,7 @@
78959 #include <linux/dmaengine.h>
78960 #include <linux/skbuff.h>
78961
78962-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78963+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78964 struct sk_buff *skb, int offset, struct iovec *to,
78965 size_t len, struct dma_pinned_list *pinned_list);
78966
78967diff --git a/include/net/netlink.h b/include/net/netlink.h
78968index 9690b0f..87aded7 100644
78969--- a/include/net/netlink.h
78970+++ b/include/net/netlink.h
78971@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
78972 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
78973 {
78974 if (mark)
78975- skb_trim(skb, (unsigned char *) mark - skb->data);
78976+ skb_trim(skb, (const unsigned char *) mark - skb->data);
78977 }
78978
78979 /**
78980diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
78981index c9c0c53..53f24c3 100644
78982--- a/include/net/netns/conntrack.h
78983+++ b/include/net/netns/conntrack.h
78984@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
78985 struct nf_proto_net {
78986 #ifdef CONFIG_SYSCTL
78987 struct ctl_table_header *ctl_table_header;
78988- struct ctl_table *ctl_table;
78989+ ctl_table_no_const *ctl_table;
78990 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
78991 struct ctl_table_header *ctl_compat_header;
78992- struct ctl_table *ctl_compat_table;
78993+ ctl_table_no_const *ctl_compat_table;
78994 #endif
78995 #endif
78996 unsigned int users;
78997@@ -58,7 +58,7 @@ struct nf_ip_net {
78998 struct nf_icmp_net icmpv6;
78999 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
79000 struct ctl_table_header *ctl_table_header;
79001- struct ctl_table *ctl_table;
79002+ ctl_table_no_const *ctl_table;
79003 #endif
79004 };
79005
79006diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
79007index bf2ec22..5e7f9d9 100644
79008--- a/include/net/netns/ipv4.h
79009+++ b/include/net/netns/ipv4.h
79010@@ -67,7 +67,7 @@ struct netns_ipv4 {
79011 kgid_t sysctl_ping_group_range[2];
79012 long sysctl_tcp_mem[3];
79013
79014- atomic_t dev_addr_genid;
79015+ atomic_unchecked_t dev_addr_genid;
79016
79017 #ifdef CONFIG_IP_MROUTE
79018 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
79019@@ -77,6 +77,6 @@ struct netns_ipv4 {
79020 struct fib_rules_ops *mr_rules_ops;
79021 #endif
79022 #endif
79023- atomic_t rt_genid;
79024+ atomic_unchecked_t rt_genid;
79025 };
79026 #endif
79027diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
79028index 0fb2401..477d81c 100644
79029--- a/include/net/netns/ipv6.h
79030+++ b/include/net/netns/ipv6.h
79031@@ -71,8 +71,8 @@ struct netns_ipv6 {
79032 struct fib_rules_ops *mr6_rules_ops;
79033 #endif
79034 #endif
79035- atomic_t dev_addr_genid;
79036- atomic_t rt_genid;
79037+ atomic_unchecked_t dev_addr_genid;
79038+ atomic_unchecked_t rt_genid;
79039 };
79040
79041 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
79042diff --git a/include/net/ping.h b/include/net/ping.h
79043index 5db0224..0d65365 100644
79044--- a/include/net/ping.h
79045+++ b/include/net/ping.h
79046@@ -55,7 +55,7 @@ struct ping_iter_state {
79047 extern struct proto ping_prot;
79048 extern struct ping_table ping_table;
79049 #if IS_ENABLED(CONFIG_IPV6)
79050-extern struct pingv6_ops pingv6_ops;
79051+extern struct pingv6_ops *pingv6_ops;
79052 #endif
79053
79054 struct pingfakehdr {
79055diff --git a/include/net/protocol.h b/include/net/protocol.h
79056index 047c047..b9dad15 100644
79057--- a/include/net/protocol.h
79058+++ b/include/net/protocol.h
79059@@ -44,7 +44,7 @@ struct net_protocol {
79060 void (*err_handler)(struct sk_buff *skb, u32 info);
79061 unsigned int no_policy:1,
79062 netns_ok:1;
79063-};
79064+} __do_const;
79065
79066 #if IS_ENABLED(CONFIG_IPV6)
79067 struct inet6_protocol {
79068@@ -57,7 +57,7 @@ struct inet6_protocol {
79069 u8 type, u8 code, int offset,
79070 __be32 info);
79071 unsigned int flags; /* INET6_PROTO_xxx */
79072-};
79073+} __do_const;
79074
79075 #define INET6_PROTO_NOPOLICY 0x1
79076 #define INET6_PROTO_FINAL 0x2
79077diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
79078index 7026648..584cc8c 100644
79079--- a/include/net/rtnetlink.h
79080+++ b/include/net/rtnetlink.h
79081@@ -81,7 +81,7 @@ struct rtnl_link_ops {
79082 const struct net_device *dev);
79083 unsigned int (*get_num_tx_queues)(void);
79084 unsigned int (*get_num_rx_queues)(void);
79085-};
79086+} __do_const;
79087
79088 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
79089 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
79090diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
79091index 4ef75af..5aa073a 100644
79092--- a/include/net/sctp/sm.h
79093+++ b/include/net/sctp/sm.h
79094@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
79095 typedef struct {
79096 sctp_state_fn_t *fn;
79097 const char *name;
79098-} sctp_sm_table_entry_t;
79099+} __do_const sctp_sm_table_entry_t;
79100
79101 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
79102 * currently in use.
79103@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
79104 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
79105
79106 /* Extern declarations for major data structures. */
79107-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79108+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79109
79110
79111 /* Get the size of a DATA chunk payload. */
79112diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
79113index 2174d8d..71d5257 100644
79114--- a/include/net/sctp/structs.h
79115+++ b/include/net/sctp/structs.h
79116@@ -508,7 +508,7 @@ struct sctp_pf {
79117 struct sctp_association *asoc);
79118 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
79119 struct sctp_af *af;
79120-};
79121+} __do_const;
79122
79123
79124 /* Structure to track chunk fragments that have been acked, but peer
79125diff --git a/include/net/sock.h b/include/net/sock.h
79126index 808cbc2..f6f6ac3 100644
79127--- a/include/net/sock.h
79128+++ b/include/net/sock.h
79129@@ -332,7 +332,7 @@ struct sock {
79130 unsigned int sk_napi_id;
79131 unsigned int sk_ll_usec;
79132 #endif
79133- atomic_t sk_drops;
79134+ atomic_unchecked_t sk_drops;
79135 int sk_rcvbuf;
79136
79137 struct sk_filter __rcu *sk_filter;
79138@@ -1821,7 +1821,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
79139 }
79140
79141 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
79142- char __user *from, char *to,
79143+ char __user *from, unsigned char *to,
79144 int copy, int offset)
79145 {
79146 if (skb->ip_summed == CHECKSUM_NONE) {
79147@@ -2083,7 +2083,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
79148 }
79149 }
79150
79151-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79152+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79153
79154 /**
79155 * sk_page_frag - return an appropriate page_frag
79156diff --git a/include/net/tcp.h b/include/net/tcp.h
79157index b1aa324..b8530ea 100644
79158--- a/include/net/tcp.h
79159+++ b/include/net/tcp.h
79160@@ -527,7 +527,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
79161 extern void tcp_xmit_retransmit_queue(struct sock *);
79162 extern void tcp_simple_retransmit(struct sock *);
79163 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
79164-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79165+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79166
79167 extern void tcp_send_probe0(struct sock *);
79168 extern void tcp_send_partial(struct sock *);
79169@@ -699,8 +699,8 @@ struct tcp_skb_cb {
79170 struct inet6_skb_parm h6;
79171 #endif
79172 } header; /* For incoming frames */
79173- __u32 seq; /* Starting sequence number */
79174- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
79175+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
79176+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
79177 __u32 when; /* used to compute rtt's */
79178 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
79179
79180@@ -714,7 +714,7 @@ struct tcp_skb_cb {
79181
79182 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
79183 /* 1 byte hole */
79184- __u32 ack_seq; /* Sequence number ACK'd */
79185+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
79186 };
79187
79188 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
79189diff --git a/include/net/xfrm.h b/include/net/xfrm.h
79190index e253bf0..2278b4b 100644
79191--- a/include/net/xfrm.h
79192+++ b/include/net/xfrm.h
79193@@ -287,7 +287,6 @@ struct xfrm_dst;
79194 struct xfrm_policy_afinfo {
79195 unsigned short family;
79196 struct dst_ops *dst_ops;
79197- void (*garbage_collect)(struct net *net);
79198 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
79199 const xfrm_address_t *saddr,
79200 const xfrm_address_t *daddr);
79201@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
79202 struct net_device *dev,
79203 const struct flowi *fl);
79204 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
79205-};
79206+} __do_const;
79207
79208 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
79209 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
79210@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
79211 int (*transport_finish)(struct sk_buff *skb,
79212 int async);
79213 void (*local_error)(struct sk_buff *skb, u32 mtu);
79214-};
79215+} __do_const;
79216
79217 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
79218 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
79219@@ -427,7 +426,7 @@ struct xfrm_mode {
79220 struct module *owner;
79221 unsigned int encap;
79222 int flags;
79223-};
79224+} __do_const;
79225
79226 /* Flags for xfrm_mode. */
79227 enum {
79228@@ -524,7 +523,7 @@ struct xfrm_policy {
79229 struct timer_list timer;
79230
79231 struct flow_cache_object flo;
79232- atomic_t genid;
79233+ atomic_unchecked_t genid;
79234 u32 priority;
79235 u32 index;
79236 struct xfrm_mark mark;
79237@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
79238 }
79239
79240 extern void xfrm_garbage_collect(struct net *net);
79241+extern void xfrm_garbage_collect_deferred(struct net *net);
79242
79243 #else
79244
79245@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
79246 static inline void xfrm_garbage_collect(struct net *net)
79247 {
79248 }
79249+static inline void xfrm_garbage_collect_deferred(struct net *net)
79250+{
79251+}
79252 #endif
79253
79254 static __inline__
79255diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
79256index 1017e0b..227aa4d 100644
79257--- a/include/rdma/iw_cm.h
79258+++ b/include/rdma/iw_cm.h
79259@@ -122,7 +122,7 @@ struct iw_cm_verbs {
79260 int backlog);
79261
79262 int (*destroy_listen)(struct iw_cm_id *cm_id);
79263-};
79264+} __no_const;
79265
79266 /**
79267 * iw_create_cm_id - Create an IW CM identifier.
79268diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
79269index e1379b4..67eafbe 100644
79270--- a/include/scsi/libfc.h
79271+++ b/include/scsi/libfc.h
79272@@ -762,6 +762,7 @@ struct libfc_function_template {
79273 */
79274 void (*disc_stop_final) (struct fc_lport *);
79275 };
79276+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
79277
79278 /**
79279 * struct fc_disc - Discovery context
79280@@ -866,7 +867,7 @@ struct fc_lport {
79281 struct fc_vport *vport;
79282
79283 /* Operational Information */
79284- struct libfc_function_template tt;
79285+ libfc_function_template_no_const tt;
79286 u8 link_up;
79287 u8 qfull;
79288 enum fc_lport_state state;
79289diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
79290index d65fbec..f80fef2 100644
79291--- a/include/scsi/scsi_device.h
79292+++ b/include/scsi/scsi_device.h
79293@@ -180,9 +180,9 @@ struct scsi_device {
79294 unsigned int max_device_blocked; /* what device_blocked counts down from */
79295 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
79296
79297- atomic_t iorequest_cnt;
79298- atomic_t iodone_cnt;
79299- atomic_t ioerr_cnt;
79300+ atomic_unchecked_t iorequest_cnt;
79301+ atomic_unchecked_t iodone_cnt;
79302+ atomic_unchecked_t ioerr_cnt;
79303
79304 struct device sdev_gendev,
79305 sdev_dev;
79306diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
79307index b797e8f..8e2c3aa 100644
79308--- a/include/scsi/scsi_transport_fc.h
79309+++ b/include/scsi/scsi_transport_fc.h
79310@@ -751,7 +751,8 @@ struct fc_function_template {
79311 unsigned long show_host_system_hostname:1;
79312
79313 unsigned long disable_target_scan:1;
79314-};
79315+} __do_const;
79316+typedef struct fc_function_template __no_const fc_function_template_no_const;
79317
79318
79319 /**
79320diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
79321index ae6c3b8..fd748ac 100644
79322--- a/include/sound/compress_driver.h
79323+++ b/include/sound/compress_driver.h
79324@@ -128,7 +128,7 @@ struct snd_compr_ops {
79325 struct snd_compr_caps *caps);
79326 int (*get_codec_caps) (struct snd_compr_stream *stream,
79327 struct snd_compr_codec_caps *codec);
79328-};
79329+} __no_const;
79330
79331 /**
79332 * struct snd_compr: Compressed device
79333diff --git a/include/sound/soc.h b/include/sound/soc.h
79334index d22cb0a..c6ba150 100644
79335--- a/include/sound/soc.h
79336+++ b/include/sound/soc.h
79337@@ -780,7 +780,7 @@ struct snd_soc_codec_driver {
79338 /* probe ordering - for components with runtime dependencies */
79339 int probe_order;
79340 int remove_order;
79341-};
79342+} __do_const;
79343
79344 /* SoC platform interface */
79345 struct snd_soc_platform_driver {
79346@@ -826,7 +826,7 @@ struct snd_soc_platform_driver {
79347 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
79348 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
79349 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
79350-};
79351+} __do_const;
79352
79353 struct snd_soc_platform {
79354 const char *name;
79355diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
79356index 5bdb8b7..bb1096c 100644
79357--- a/include/target/target_core_base.h
79358+++ b/include/target/target_core_base.h
79359@@ -663,7 +663,7 @@ struct se_device {
79360 spinlock_t stats_lock;
79361 /* Active commands on this virtual SE device */
79362 atomic_t simple_cmds;
79363- atomic_t dev_ordered_id;
79364+ atomic_unchecked_t dev_ordered_id;
79365 atomic_t dev_ordered_sync;
79366 atomic_t dev_qf_count;
79367 int export_count;
79368diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
79369new file mode 100644
79370index 0000000..fb634b7
79371--- /dev/null
79372+++ b/include/trace/events/fs.h
79373@@ -0,0 +1,53 @@
79374+#undef TRACE_SYSTEM
79375+#define TRACE_SYSTEM fs
79376+
79377+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
79378+#define _TRACE_FS_H
79379+
79380+#include <linux/fs.h>
79381+#include <linux/tracepoint.h>
79382+
79383+TRACE_EVENT(do_sys_open,
79384+
79385+ TP_PROTO(const char *filename, int flags, int mode),
79386+
79387+ TP_ARGS(filename, flags, mode),
79388+
79389+ TP_STRUCT__entry(
79390+ __string( filename, filename )
79391+ __field( int, flags )
79392+ __field( int, mode )
79393+ ),
79394+
79395+ TP_fast_assign(
79396+ __assign_str(filename, filename);
79397+ __entry->flags = flags;
79398+ __entry->mode = mode;
79399+ ),
79400+
79401+ TP_printk("\"%s\" %x %o",
79402+ __get_str(filename), __entry->flags, __entry->mode)
79403+);
79404+
79405+TRACE_EVENT(open_exec,
79406+
79407+ TP_PROTO(const char *filename),
79408+
79409+ TP_ARGS(filename),
79410+
79411+ TP_STRUCT__entry(
79412+ __string( filename, filename )
79413+ ),
79414+
79415+ TP_fast_assign(
79416+ __assign_str(filename, filename);
79417+ ),
79418+
79419+ TP_printk("\"%s\"",
79420+ __get_str(filename))
79421+);
79422+
79423+#endif /* _TRACE_FS_H */
79424+
79425+/* This part must be outside protection */
79426+#include <trace/define_trace.h>
79427diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
79428index 1c09820..7f5ec79 100644
79429--- a/include/trace/events/irq.h
79430+++ b/include/trace/events/irq.h
79431@@ -36,7 +36,7 @@ struct softirq_action;
79432 */
79433 TRACE_EVENT(irq_handler_entry,
79434
79435- TP_PROTO(int irq, struct irqaction *action),
79436+ TP_PROTO(int irq, const struct irqaction *action),
79437
79438 TP_ARGS(irq, action),
79439
79440@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
79441 */
79442 TRACE_EVENT(irq_handler_exit,
79443
79444- TP_PROTO(int irq, struct irqaction *action, int ret),
79445+ TP_PROTO(int irq, const struct irqaction *action, int ret),
79446
79447 TP_ARGS(irq, action, ret),
79448
79449diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
79450index 7caf44c..23c6f27 100644
79451--- a/include/uapi/linux/a.out.h
79452+++ b/include/uapi/linux/a.out.h
79453@@ -39,6 +39,14 @@ enum machine_type {
79454 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
79455 };
79456
79457+/* Constants for the N_FLAGS field */
79458+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79459+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
79460+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
79461+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
79462+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79463+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79464+
79465 #if !defined (N_MAGIC)
79466 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
79467 #endif
79468diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
79469index d876736..ccce5c0 100644
79470--- a/include/uapi/linux/byteorder/little_endian.h
79471+++ b/include/uapi/linux/byteorder/little_endian.h
79472@@ -42,51 +42,51 @@
79473
79474 static inline __le64 __cpu_to_le64p(const __u64 *p)
79475 {
79476- return (__force __le64)*p;
79477+ return (__force const __le64)*p;
79478 }
79479-static inline __u64 __le64_to_cpup(const __le64 *p)
79480+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
79481 {
79482- return (__force __u64)*p;
79483+ return (__force const __u64)*p;
79484 }
79485 static inline __le32 __cpu_to_le32p(const __u32 *p)
79486 {
79487- return (__force __le32)*p;
79488+ return (__force const __le32)*p;
79489 }
79490 static inline __u32 __le32_to_cpup(const __le32 *p)
79491 {
79492- return (__force __u32)*p;
79493+ return (__force const __u32)*p;
79494 }
79495 static inline __le16 __cpu_to_le16p(const __u16 *p)
79496 {
79497- return (__force __le16)*p;
79498+ return (__force const __le16)*p;
79499 }
79500 static inline __u16 __le16_to_cpup(const __le16 *p)
79501 {
79502- return (__force __u16)*p;
79503+ return (__force const __u16)*p;
79504 }
79505 static inline __be64 __cpu_to_be64p(const __u64 *p)
79506 {
79507- return (__force __be64)__swab64p(p);
79508+ return (__force const __be64)__swab64p(p);
79509 }
79510 static inline __u64 __be64_to_cpup(const __be64 *p)
79511 {
79512- return __swab64p((__u64 *)p);
79513+ return __swab64p((const __u64 *)p);
79514 }
79515 static inline __be32 __cpu_to_be32p(const __u32 *p)
79516 {
79517- return (__force __be32)__swab32p(p);
79518+ return (__force const __be32)__swab32p(p);
79519 }
79520-static inline __u32 __be32_to_cpup(const __be32 *p)
79521+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
79522 {
79523- return __swab32p((__u32 *)p);
79524+ return __swab32p((const __u32 *)p);
79525 }
79526 static inline __be16 __cpu_to_be16p(const __u16 *p)
79527 {
79528- return (__force __be16)__swab16p(p);
79529+ return (__force const __be16)__swab16p(p);
79530 }
79531 static inline __u16 __be16_to_cpup(const __be16 *p)
79532 {
79533- return __swab16p((__u16 *)p);
79534+ return __swab16p((const __u16 *)p);
79535 }
79536 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
79537 #define __le64_to_cpus(x) do { (void)(x); } while (0)
79538diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
79539index ef6103b..d4e65dd 100644
79540--- a/include/uapi/linux/elf.h
79541+++ b/include/uapi/linux/elf.h
79542@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
79543 #define PT_GNU_EH_FRAME 0x6474e550
79544
79545 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
79546+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
79547+
79548+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
79549+
79550+/* Constants for the e_flags field */
79551+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79552+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
79553+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
79554+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
79555+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79556+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79557
79558 /*
79559 * Extended Numbering
79560@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
79561 #define DT_DEBUG 21
79562 #define DT_TEXTREL 22
79563 #define DT_JMPREL 23
79564+#define DT_FLAGS 30
79565+ #define DF_TEXTREL 0x00000004
79566 #define DT_ENCODING 32
79567 #define OLD_DT_LOOS 0x60000000
79568 #define DT_LOOS 0x6000000d
79569@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
79570 #define PF_W 0x2
79571 #define PF_X 0x1
79572
79573+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
79574+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
79575+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
79576+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
79577+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
79578+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
79579+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
79580+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
79581+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
79582+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
79583+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
79584+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
79585+
79586 typedef struct elf32_phdr{
79587 Elf32_Word p_type;
79588 Elf32_Off p_offset;
79589@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
79590 #define EI_OSABI 7
79591 #define EI_PAD 8
79592
79593+#define EI_PAX 14
79594+
79595 #define ELFMAG0 0x7f /* EI_MAG */
79596 #define ELFMAG1 'E'
79597 #define ELFMAG2 'L'
79598diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
79599index aa169c4..6a2771d 100644
79600--- a/include/uapi/linux/personality.h
79601+++ b/include/uapi/linux/personality.h
79602@@ -30,6 +30,7 @@ enum {
79603 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
79604 ADDR_NO_RANDOMIZE | \
79605 ADDR_COMPAT_LAYOUT | \
79606+ ADDR_LIMIT_3GB | \
79607 MMAP_PAGE_ZERO)
79608
79609 /*
79610diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
79611index 7530e74..e714828 100644
79612--- a/include/uapi/linux/screen_info.h
79613+++ b/include/uapi/linux/screen_info.h
79614@@ -43,7 +43,8 @@ struct screen_info {
79615 __u16 pages; /* 0x32 */
79616 __u16 vesa_attributes; /* 0x34 */
79617 __u32 capabilities; /* 0x36 */
79618- __u8 _reserved[6]; /* 0x3a */
79619+ __u16 vesapm_size; /* 0x3a */
79620+ __u8 _reserved[4]; /* 0x3c */
79621 } __attribute__((packed));
79622
79623 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
79624diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
79625index 0e011eb..82681b1 100644
79626--- a/include/uapi/linux/swab.h
79627+++ b/include/uapi/linux/swab.h
79628@@ -43,7 +43,7 @@
79629 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
79630 */
79631
79632-static inline __attribute_const__ __u16 __fswab16(__u16 val)
79633+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
79634 {
79635 #ifdef __HAVE_BUILTIN_BSWAP16__
79636 return __builtin_bswap16(val);
79637@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
79638 #endif
79639 }
79640
79641-static inline __attribute_const__ __u32 __fswab32(__u32 val)
79642+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
79643 {
79644 #ifdef __HAVE_BUILTIN_BSWAP32__
79645 return __builtin_bswap32(val);
79646@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
79647 #endif
79648 }
79649
79650-static inline __attribute_const__ __u64 __fswab64(__u64 val)
79651+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
79652 {
79653 #ifdef __HAVE_BUILTIN_BSWAP64__
79654 return __builtin_bswap64(val);
79655diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
79656index 6d67213..8dab561 100644
79657--- a/include/uapi/linux/sysctl.h
79658+++ b/include/uapi/linux/sysctl.h
79659@@ -155,7 +155,11 @@ enum
79660 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
79661 };
79662
79663-
79664+#ifdef CONFIG_PAX_SOFTMODE
79665+enum {
79666+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
79667+};
79668+#endif
79669
79670 /* CTL_VM names: */
79671 enum
79672diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
79673index e4629b9..6958086 100644
79674--- a/include/uapi/linux/xattr.h
79675+++ b/include/uapi/linux/xattr.h
79676@@ -63,5 +63,9 @@
79677 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
79678 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
79679
79680+/* User namespace */
79681+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
79682+#define XATTR_PAX_FLAGS_SUFFIX "flags"
79683+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
79684
79685 #endif /* _UAPI_LINUX_XATTR_H */
79686diff --git a/include/video/udlfb.h b/include/video/udlfb.h
79687index f9466fa..f4e2b81 100644
79688--- a/include/video/udlfb.h
79689+++ b/include/video/udlfb.h
79690@@ -53,10 +53,10 @@ struct dlfb_data {
79691 u32 pseudo_palette[256];
79692 int blank_mode; /*one of FB_BLANK_ */
79693 /* blit-only rendering path metrics, exposed through sysfs */
79694- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79695- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
79696- atomic_t bytes_sent; /* to usb, after compression including overhead */
79697- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
79698+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79699+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
79700+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
79701+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
79702 };
79703
79704 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
79705diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
79706index 30f5362..8ed8ac9 100644
79707--- a/include/video/uvesafb.h
79708+++ b/include/video/uvesafb.h
79709@@ -122,6 +122,7 @@ struct uvesafb_par {
79710 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
79711 u8 pmi_setpal; /* PMI for palette changes */
79712 u16 *pmi_base; /* protected mode interface location */
79713+ u8 *pmi_code; /* protected mode code location */
79714 void *pmi_start;
79715 void *pmi_pal;
79716 u8 *vbe_state_orig; /*
79717diff --git a/init/Kconfig b/init/Kconfig
79718index 3ecd8a1..627843f 100644
79719--- a/init/Kconfig
79720+++ b/init/Kconfig
79721@@ -1086,6 +1086,7 @@ endif # CGROUPS
79722
79723 config CHECKPOINT_RESTORE
79724 bool "Checkpoint/restore support" if EXPERT
79725+ depends on !GRKERNSEC
79726 default n
79727 help
79728 Enables additional kernel features in a sake of checkpoint/restore.
79729@@ -1557,7 +1558,7 @@ config SLUB_DEBUG
79730
79731 config COMPAT_BRK
79732 bool "Disable heap randomization"
79733- default y
79734+ default n
79735 help
79736 Randomizing heap placement makes heap exploits harder, but it
79737 also breaks ancient binaries (including anything libc5 based).
79738@@ -1832,7 +1833,7 @@ config INIT_ALL_POSSIBLE
79739 config STOP_MACHINE
79740 bool
79741 default y
79742- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
79743+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
79744 help
79745 Need stop_machine() primitive.
79746
79747diff --git a/init/Makefile b/init/Makefile
79748index 7bc47ee..6da2dc7 100644
79749--- a/init/Makefile
79750+++ b/init/Makefile
79751@@ -2,6 +2,9 @@
79752 # Makefile for the linux kernel.
79753 #
79754
79755+ccflags-y := $(GCC_PLUGINS_CFLAGS)
79756+asflags-y := $(GCC_PLUGINS_AFLAGS)
79757+
79758 obj-y := main.o version.o mounts.o
79759 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
79760 obj-y += noinitramfs.o
79761diff --git a/init/do_mounts.c b/init/do_mounts.c
79762index a51cddc..25c2768 100644
79763--- a/init/do_mounts.c
79764+++ b/init/do_mounts.c
79765@@ -357,11 +357,11 @@ static void __init get_fs_names(char *page)
79766 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
79767 {
79768 struct super_block *s;
79769- int err = sys_mount(name, "/root", fs, flags, data);
79770+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
79771 if (err)
79772 return err;
79773
79774- sys_chdir("/root");
79775+ sys_chdir((const char __force_user *)"/root");
79776 s = current->fs->pwd.dentry->d_sb;
79777 ROOT_DEV = s->s_dev;
79778 printk(KERN_INFO
79779@@ -482,18 +482,18 @@ void __init change_floppy(char *fmt, ...)
79780 va_start(args, fmt);
79781 vsprintf(buf, fmt, args);
79782 va_end(args);
79783- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
79784+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
79785 if (fd >= 0) {
79786 sys_ioctl(fd, FDEJECT, 0);
79787 sys_close(fd);
79788 }
79789 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
79790- fd = sys_open("/dev/console", O_RDWR, 0);
79791+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
79792 if (fd >= 0) {
79793 sys_ioctl(fd, TCGETS, (long)&termios);
79794 termios.c_lflag &= ~ICANON;
79795 sys_ioctl(fd, TCSETSF, (long)&termios);
79796- sys_read(fd, &c, 1);
79797+ sys_read(fd, (char __user *)&c, 1);
79798 termios.c_lflag |= ICANON;
79799 sys_ioctl(fd, TCSETSF, (long)&termios);
79800 sys_close(fd);
79801@@ -587,8 +587,8 @@ void __init prepare_namespace(void)
79802 mount_root();
79803 out:
79804 devtmpfs_mount("dev");
79805- sys_mount(".", "/", NULL, MS_MOVE, NULL);
79806- sys_chroot(".");
79807+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
79808+ sys_chroot((const char __force_user *)".");
79809 }
79810
79811 static bool is_tmpfs;
79812diff --git a/init/do_mounts.h b/init/do_mounts.h
79813index f5b978a..69dbfe8 100644
79814--- a/init/do_mounts.h
79815+++ b/init/do_mounts.h
79816@@ -15,15 +15,15 @@ extern int root_mountflags;
79817
79818 static inline int create_dev(char *name, dev_t dev)
79819 {
79820- sys_unlink(name);
79821- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
79822+ sys_unlink((char __force_user *)name);
79823+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
79824 }
79825
79826 #if BITS_PER_LONG == 32
79827 static inline u32 bstat(char *name)
79828 {
79829 struct stat64 stat;
79830- if (sys_stat64(name, &stat) != 0)
79831+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
79832 return 0;
79833 if (!S_ISBLK(stat.st_mode))
79834 return 0;
79835@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
79836 static inline u32 bstat(char *name)
79837 {
79838 struct stat stat;
79839- if (sys_newstat(name, &stat) != 0)
79840+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
79841 return 0;
79842 if (!S_ISBLK(stat.st_mode))
79843 return 0;
79844diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
79845index 3e0878e..8a9d7a0 100644
79846--- a/init/do_mounts_initrd.c
79847+++ b/init/do_mounts_initrd.c
79848@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
79849 {
79850 sys_unshare(CLONE_FS | CLONE_FILES);
79851 /* stdin/stdout/stderr for /linuxrc */
79852- sys_open("/dev/console", O_RDWR, 0);
79853+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
79854 sys_dup(0);
79855 sys_dup(0);
79856 /* move initrd over / and chdir/chroot in initrd root */
79857- sys_chdir("/root");
79858- sys_mount(".", "/", NULL, MS_MOVE, NULL);
79859- sys_chroot(".");
79860+ sys_chdir((const char __force_user *)"/root");
79861+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
79862+ sys_chroot((const char __force_user *)".");
79863 sys_setsid();
79864 return 0;
79865 }
79866@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
79867 create_dev("/dev/root.old", Root_RAM0);
79868 /* mount initrd on rootfs' /root */
79869 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
79870- sys_mkdir("/old", 0700);
79871- sys_chdir("/old");
79872+ sys_mkdir((const char __force_user *)"/old", 0700);
79873+ sys_chdir((const char __force_user *)"/old");
79874
79875 /* try loading default modules from initrd */
79876 load_default_modules();
79877@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
79878 current->flags &= ~PF_FREEZER_SKIP;
79879
79880 /* move initrd to rootfs' /old */
79881- sys_mount("..", ".", NULL, MS_MOVE, NULL);
79882+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
79883 /* switch root and cwd back to / of rootfs */
79884- sys_chroot("..");
79885+ sys_chroot((const char __force_user *)"..");
79886
79887 if (new_decode_dev(real_root_dev) == Root_RAM0) {
79888- sys_chdir("/old");
79889+ sys_chdir((const char __force_user *)"/old");
79890 return;
79891 }
79892
79893- sys_chdir("/");
79894+ sys_chdir((const char __force_user *)"/");
79895 ROOT_DEV = new_decode_dev(real_root_dev);
79896 mount_root();
79897
79898 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
79899- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
79900+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
79901 if (!error)
79902 printk("okay\n");
79903 else {
79904- int fd = sys_open("/dev/root.old", O_RDWR, 0);
79905+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
79906 if (error == -ENOENT)
79907 printk("/initrd does not exist. Ignored.\n");
79908 else
79909 printk("failed\n");
79910 printk(KERN_NOTICE "Unmounting old root\n");
79911- sys_umount("/old", MNT_DETACH);
79912+ sys_umount((char __force_user *)"/old", MNT_DETACH);
79913 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
79914 if (fd < 0) {
79915 error = fd;
79916@@ -127,11 +127,11 @@ int __init initrd_load(void)
79917 * mounted in the normal path.
79918 */
79919 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
79920- sys_unlink("/initrd.image");
79921+ sys_unlink((const char __force_user *)"/initrd.image");
79922 handle_initrd();
79923 return 1;
79924 }
79925 }
79926- sys_unlink("/initrd.image");
79927+ sys_unlink((const char __force_user *)"/initrd.image");
79928 return 0;
79929 }
79930diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
79931index 8cb6db5..d729f50 100644
79932--- a/init/do_mounts_md.c
79933+++ b/init/do_mounts_md.c
79934@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
79935 partitioned ? "_d" : "", minor,
79936 md_setup_args[ent].device_names);
79937
79938- fd = sys_open(name, 0, 0);
79939+ fd = sys_open((char __force_user *)name, 0, 0);
79940 if (fd < 0) {
79941 printk(KERN_ERR "md: open failed - cannot start "
79942 "array %s\n", name);
79943@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
79944 * array without it
79945 */
79946 sys_close(fd);
79947- fd = sys_open(name, 0, 0);
79948+ fd = sys_open((char __force_user *)name, 0, 0);
79949 sys_ioctl(fd, BLKRRPART, 0);
79950 }
79951 sys_close(fd);
79952@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
79953
79954 wait_for_device_probe();
79955
79956- fd = sys_open("/dev/md0", 0, 0);
79957+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
79958 if (fd >= 0) {
79959 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
79960 sys_close(fd);
79961diff --git a/init/init_task.c b/init/init_task.c
79962index ba0a7f36..2bcf1d5 100644
79963--- a/init/init_task.c
79964+++ b/init/init_task.c
79965@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
79966 * Initial thread structure. Alignment of this is handled by a special
79967 * linker map entry.
79968 */
79969+#ifdef CONFIG_X86
79970+union thread_union init_thread_union __init_task_data;
79971+#else
79972 union thread_union init_thread_union __init_task_data =
79973 { INIT_THREAD_INFO(init_task) };
79974+#endif
79975diff --git a/init/initramfs.c b/init/initramfs.c
79976index a67ef9d..2d17ed9 100644
79977--- a/init/initramfs.c
79978+++ b/init/initramfs.c
79979@@ -84,7 +84,7 @@ static void __init free_hash(void)
79980 }
79981 }
79982
79983-static long __init do_utime(char *filename, time_t mtime)
79984+static long __init do_utime(char __force_user *filename, time_t mtime)
79985 {
79986 struct timespec t[2];
79987
79988@@ -119,7 +119,7 @@ static void __init dir_utime(void)
79989 struct dir_entry *de, *tmp;
79990 list_for_each_entry_safe(de, tmp, &dir_list, list) {
79991 list_del(&de->list);
79992- do_utime(de->name, de->mtime);
79993+ do_utime((char __force_user *)de->name, de->mtime);
79994 kfree(de->name);
79995 kfree(de);
79996 }
79997@@ -281,7 +281,7 @@ static int __init maybe_link(void)
79998 if (nlink >= 2) {
79999 char *old = find_link(major, minor, ino, mode, collected);
80000 if (old)
80001- return (sys_link(old, collected) < 0) ? -1 : 1;
80002+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
80003 }
80004 return 0;
80005 }
80006@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
80007 {
80008 struct stat st;
80009
80010- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
80011+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
80012 if (S_ISDIR(st.st_mode))
80013- sys_rmdir(path);
80014+ sys_rmdir((char __force_user *)path);
80015 else
80016- sys_unlink(path);
80017+ sys_unlink((char __force_user *)path);
80018 }
80019 }
80020
80021@@ -315,7 +315,7 @@ static int __init do_name(void)
80022 int openflags = O_WRONLY|O_CREAT;
80023 if (ml != 1)
80024 openflags |= O_TRUNC;
80025- wfd = sys_open(collected, openflags, mode);
80026+ wfd = sys_open((char __force_user *)collected, openflags, mode);
80027
80028 if (wfd >= 0) {
80029 sys_fchown(wfd, uid, gid);
80030@@ -327,17 +327,17 @@ static int __init do_name(void)
80031 }
80032 }
80033 } else if (S_ISDIR(mode)) {
80034- sys_mkdir(collected, mode);
80035- sys_chown(collected, uid, gid);
80036- sys_chmod(collected, mode);
80037+ sys_mkdir((char __force_user *)collected, mode);
80038+ sys_chown((char __force_user *)collected, uid, gid);
80039+ sys_chmod((char __force_user *)collected, mode);
80040 dir_add(collected, mtime);
80041 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
80042 S_ISFIFO(mode) || S_ISSOCK(mode)) {
80043 if (maybe_link() == 0) {
80044- sys_mknod(collected, mode, rdev);
80045- sys_chown(collected, uid, gid);
80046- sys_chmod(collected, mode);
80047- do_utime(collected, mtime);
80048+ sys_mknod((char __force_user *)collected, mode, rdev);
80049+ sys_chown((char __force_user *)collected, uid, gid);
80050+ sys_chmod((char __force_user *)collected, mode);
80051+ do_utime((char __force_user *)collected, mtime);
80052 }
80053 }
80054 return 0;
80055@@ -346,15 +346,15 @@ static int __init do_name(void)
80056 static int __init do_copy(void)
80057 {
80058 if (count >= body_len) {
80059- sys_write(wfd, victim, body_len);
80060+ sys_write(wfd, (char __force_user *)victim, body_len);
80061 sys_close(wfd);
80062- do_utime(vcollected, mtime);
80063+ do_utime((char __force_user *)vcollected, mtime);
80064 kfree(vcollected);
80065 eat(body_len);
80066 state = SkipIt;
80067 return 0;
80068 } else {
80069- sys_write(wfd, victim, count);
80070+ sys_write(wfd, (char __force_user *)victim, count);
80071 body_len -= count;
80072 eat(count);
80073 return 1;
80074@@ -365,9 +365,9 @@ static int __init do_symlink(void)
80075 {
80076 collected[N_ALIGN(name_len) + body_len] = '\0';
80077 clean_path(collected, 0);
80078- sys_symlink(collected + N_ALIGN(name_len), collected);
80079- sys_lchown(collected, uid, gid);
80080- do_utime(collected, mtime);
80081+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
80082+ sys_lchown((char __force_user *)collected, uid, gid);
80083+ do_utime((char __force_user *)collected, mtime);
80084 state = SkipIt;
80085 next_state = Reset;
80086 return 0;
80087@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
80088 {
80089 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
80090 if (err)
80091- panic(err); /* Failed to decompress INTERNAL initramfs */
80092+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
80093 if (initrd_start) {
80094 #ifdef CONFIG_BLK_DEV_RAM
80095 int fd;
80096diff --git a/init/main.c b/init/main.c
80097index 63d3e8f..50bd5f8 100644
80098--- a/init/main.c
80099+++ b/init/main.c
80100@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
80101 extern void tc_init(void);
80102 #endif
80103
80104+extern void grsecurity_init(void);
80105+
80106 /*
80107 * Debug helper: via this flag we know that we are in 'early bootup code'
80108 * where only the boot processor is running with IRQ disabled. This means
80109@@ -156,6 +158,75 @@ static int __init set_reset_devices(char *str)
80110
80111 __setup("reset_devices", set_reset_devices);
80112
80113+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80114+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
80115+static int __init setup_grsec_proc_gid(char *str)
80116+{
80117+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
80118+ return 1;
80119+}
80120+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
80121+#endif
80122+
80123+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
80124+unsigned long pax_user_shadow_base __read_only;
80125+EXPORT_SYMBOL(pax_user_shadow_base);
80126+extern char pax_enter_kernel_user[];
80127+extern char pax_exit_kernel_user[];
80128+#endif
80129+
80130+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
80131+static int __init setup_pax_nouderef(char *str)
80132+{
80133+#ifdef CONFIG_X86_32
80134+ unsigned int cpu;
80135+ struct desc_struct *gdt;
80136+
80137+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
80138+ gdt = get_cpu_gdt_table(cpu);
80139+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
80140+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
80141+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
80142+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
80143+ }
80144+ loadsegment(ds, __KERNEL_DS);
80145+ loadsegment(es, __KERNEL_DS);
80146+ loadsegment(ss, __KERNEL_DS);
80147+#else
80148+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
80149+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
80150+ clone_pgd_mask = ~(pgdval_t)0UL;
80151+ pax_user_shadow_base = 0UL;
80152+ setup_clear_cpu_cap(X86_FEATURE_PCID);
80153+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
80154+#endif
80155+
80156+ return 0;
80157+}
80158+early_param("pax_nouderef", setup_pax_nouderef);
80159+
80160+#ifdef CONFIG_X86_64
80161+static int __init setup_pax_weakuderef(char *str)
80162+{
80163+ if (clone_pgd_mask != ~(pgdval_t)0UL)
80164+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
80165+ return 1;
80166+}
80167+__setup("pax_weakuderef", setup_pax_weakuderef);
80168+#endif
80169+#endif
80170+
80171+#ifdef CONFIG_PAX_SOFTMODE
80172+int pax_softmode;
80173+
80174+static int __init setup_pax_softmode(char *str)
80175+{
80176+ get_option(&str, &pax_softmode);
80177+ return 1;
80178+}
80179+__setup("pax_softmode=", setup_pax_softmode);
80180+#endif
80181+
80182 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
80183 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
80184 static const char *panic_later, *panic_param;
80185@@ -682,25 +753,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
80186 {
80187 int count = preempt_count();
80188 int ret;
80189- char msgbuf[64];
80190+ const char *msg1 = "", *msg2 = "";
80191
80192 if (initcall_debug)
80193 ret = do_one_initcall_debug(fn);
80194 else
80195 ret = fn();
80196
80197- msgbuf[0] = 0;
80198-
80199 if (preempt_count() != count) {
80200- sprintf(msgbuf, "preemption imbalance ");
80201+ msg1 = " preemption imbalance";
80202 preempt_count() = count;
80203 }
80204 if (irqs_disabled()) {
80205- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
80206+ msg2 = " disabled interrupts";
80207 local_irq_enable();
80208 }
80209- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
80210+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
80211
80212+ add_latent_entropy();
80213 return ret;
80214 }
80215
80216@@ -807,10 +877,14 @@ static int run_init_process(const char *init_filename)
80217 {
80218 argv_init[0] = init_filename;
80219 return do_execve(init_filename,
80220- (const char __user *const __user *)argv_init,
80221- (const char __user *const __user *)envp_init);
80222+ (const char __user *const __force_user *)argv_init,
80223+ (const char __user *const __force_user *)envp_init);
80224 }
80225
80226+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
80227+extern int gr_init_ran;
80228+#endif
80229+
80230 static noinline void __init kernel_init_freeable(void);
80231
80232 static int __ref kernel_init(void *unused)
80233@@ -831,6 +905,11 @@ static int __ref kernel_init(void *unused)
80234 pr_err("Failed to execute %s\n", ramdisk_execute_command);
80235 }
80236
80237+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
80238+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
80239+ gr_init_ran = 1;
80240+#endif
80241+
80242 /*
80243 * We try each of these until one succeeds.
80244 *
80245@@ -885,7 +964,7 @@ static noinline void __init kernel_init_freeable(void)
80246 do_basic_setup();
80247
80248 /* Open the /dev/console on the rootfs, this should never fail */
80249- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
80250+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
80251 pr_err("Warning: unable to open an initial console.\n");
80252
80253 (void) sys_dup(0);
80254@@ -898,11 +977,13 @@ static noinline void __init kernel_init_freeable(void)
80255 if (!ramdisk_execute_command)
80256 ramdisk_execute_command = "/init";
80257
80258- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
80259+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
80260 ramdisk_execute_command = NULL;
80261 prepare_namespace();
80262 }
80263
80264+ grsecurity_init();
80265+
80266 /*
80267 * Ok, we have completed the initial bootup, and
80268 * we're essentially up and running. Get rid of the
80269diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
80270index b0e99de..09f385c 100644
80271--- a/ipc/ipc_sysctl.c
80272+++ b/ipc/ipc_sysctl.c
80273@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
80274 static int proc_ipc_dointvec(ctl_table *table, int write,
80275 void __user *buffer, size_t *lenp, loff_t *ppos)
80276 {
80277- struct ctl_table ipc_table;
80278+ ctl_table_no_const ipc_table;
80279
80280 memcpy(&ipc_table, table, sizeof(ipc_table));
80281 ipc_table.data = get_ipc(table);
80282@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
80283 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
80284 void __user *buffer, size_t *lenp, loff_t *ppos)
80285 {
80286- struct ctl_table ipc_table;
80287+ ctl_table_no_const ipc_table;
80288
80289 memcpy(&ipc_table, table, sizeof(ipc_table));
80290 ipc_table.data = get_ipc(table);
80291@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
80292 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
80293 void __user *buffer, size_t *lenp, loff_t *ppos)
80294 {
80295- struct ctl_table ipc_table;
80296+ ctl_table_no_const ipc_table;
80297 size_t lenp_bef = *lenp;
80298 int rc;
80299
80300@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
80301 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
80302 void __user *buffer, size_t *lenp, loff_t *ppos)
80303 {
80304- struct ctl_table ipc_table;
80305+ ctl_table_no_const ipc_table;
80306 memcpy(&ipc_table, table, sizeof(ipc_table));
80307 ipc_table.data = get_ipc(table);
80308
80309@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
80310 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
80311 void __user *buffer, size_t *lenp, loff_t *ppos)
80312 {
80313- struct ctl_table ipc_table;
80314+ ctl_table_no_const ipc_table;
80315 size_t lenp_bef = *lenp;
80316 int oldval;
80317 int rc;
80318diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
80319index 383d638..943fdbb 100644
80320--- a/ipc/mq_sysctl.c
80321+++ b/ipc/mq_sysctl.c
80322@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
80323 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
80324 void __user *buffer, size_t *lenp, loff_t *ppos)
80325 {
80326- struct ctl_table mq_table;
80327+ ctl_table_no_const mq_table;
80328 memcpy(&mq_table, table, sizeof(mq_table));
80329 mq_table.data = get_mq(table);
80330
80331diff --git a/ipc/mqueue.c b/ipc/mqueue.c
80332index ae1996d..a35f2cc 100644
80333--- a/ipc/mqueue.c
80334+++ b/ipc/mqueue.c
80335@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
80336 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
80337 info->attr.mq_msgsize);
80338
80339+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
80340 spin_lock(&mq_lock);
80341 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
80342 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
80343diff --git a/ipc/msg.c b/ipc/msg.c
80344index 558aa91..359e718 100644
80345--- a/ipc/msg.c
80346+++ b/ipc/msg.c
80347@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
80348 return security_msg_queue_associate(msq, msgflg);
80349 }
80350
80351+static struct ipc_ops msg_ops = {
80352+ .getnew = newque,
80353+ .associate = msg_security,
80354+ .more_checks = NULL
80355+};
80356+
80357 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
80358 {
80359 struct ipc_namespace *ns;
80360- struct ipc_ops msg_ops;
80361 struct ipc_params msg_params;
80362
80363 ns = current->nsproxy->ipc_ns;
80364
80365- msg_ops.getnew = newque;
80366- msg_ops.associate = msg_security;
80367- msg_ops.more_checks = NULL;
80368-
80369 msg_params.key = key;
80370 msg_params.flg = msgflg;
80371
80372diff --git a/ipc/sem.c b/ipc/sem.c
80373index db9d241..bc8427c 100644
80374--- a/ipc/sem.c
80375+++ b/ipc/sem.c
80376@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
80377 return 0;
80378 }
80379
80380+static struct ipc_ops sem_ops = {
80381+ .getnew = newary,
80382+ .associate = sem_security,
80383+ .more_checks = sem_more_checks
80384+};
80385+
80386 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80387 {
80388 struct ipc_namespace *ns;
80389- struct ipc_ops sem_ops;
80390 struct ipc_params sem_params;
80391
80392 ns = current->nsproxy->ipc_ns;
80393@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80394 if (nsems < 0 || nsems > ns->sc_semmsl)
80395 return -EINVAL;
80396
80397- sem_ops.getnew = newary;
80398- sem_ops.associate = sem_security;
80399- sem_ops.more_checks = sem_more_checks;
80400-
80401 sem_params.key = key;
80402 sem_params.flg = semflg;
80403 sem_params.u.nsems = nsems;
80404diff --git a/ipc/shm.c b/ipc/shm.c
80405index 7a51443..3a257d8 100644
80406--- a/ipc/shm.c
80407+++ b/ipc/shm.c
80408@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
80409 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
80410 #endif
80411
80412+#ifdef CONFIG_GRKERNSEC
80413+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80414+ const time_t shm_createtime, const kuid_t cuid,
80415+ const int shmid);
80416+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80417+ const time_t shm_createtime);
80418+#endif
80419+
80420 void shm_init_ns(struct ipc_namespace *ns)
80421 {
80422 ns->shm_ctlmax = SHMMAX;
80423@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
80424 shp->shm_lprid = 0;
80425 shp->shm_atim = shp->shm_dtim = 0;
80426 shp->shm_ctim = get_seconds();
80427+#ifdef CONFIG_GRKERNSEC
80428+ {
80429+ struct timespec timeval;
80430+ do_posix_clock_monotonic_gettime(&timeval);
80431+
80432+ shp->shm_createtime = timeval.tv_sec;
80433+ }
80434+#endif
80435 shp->shm_segsz = size;
80436 shp->shm_nattch = 0;
80437 shp->shm_file = file;
80438@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
80439 return 0;
80440 }
80441
80442+static struct ipc_ops shm_ops = {
80443+ .getnew = newseg,
80444+ .associate = shm_security,
80445+ .more_checks = shm_more_checks
80446+};
80447+
80448 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
80449 {
80450 struct ipc_namespace *ns;
80451- struct ipc_ops shm_ops;
80452 struct ipc_params shm_params;
80453
80454 ns = current->nsproxy->ipc_ns;
80455
80456- shm_ops.getnew = newseg;
80457- shm_ops.associate = shm_security;
80458- shm_ops.more_checks = shm_more_checks;
80459-
80460 shm_params.key = key;
80461 shm_params.flg = shmflg;
80462 shm_params.u.size = size;
80463@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80464 f_mode = FMODE_READ | FMODE_WRITE;
80465 }
80466 if (shmflg & SHM_EXEC) {
80467+
80468+#ifdef CONFIG_PAX_MPROTECT
80469+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
80470+ goto out;
80471+#endif
80472+
80473 prot |= PROT_EXEC;
80474 acc_mode |= S_IXUGO;
80475 }
80476@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80477 if (err)
80478 goto out_unlock;
80479
80480+#ifdef CONFIG_GRKERNSEC
80481+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
80482+ shp->shm_perm.cuid, shmid) ||
80483+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
80484+ err = -EACCES;
80485+ goto out_unlock;
80486+ }
80487+#endif
80488+
80489 ipc_lock_object(&shp->shm_perm);
80490
80491 /* check if shm_destroy() is tearing down shp */
80492@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80493 path = shp->shm_file->f_path;
80494 path_get(&path);
80495 shp->shm_nattch++;
80496+#ifdef CONFIG_GRKERNSEC
80497+ shp->shm_lapid = current->pid;
80498+#endif
80499 size = i_size_read(path.dentry->d_inode);
80500 ipc_unlock_object(&shp->shm_perm);
80501 rcu_read_unlock();
80502diff --git a/ipc/util.c b/ipc/util.c
80503index 7684f41..f7da711 100644
80504--- a/ipc/util.c
80505+++ b/ipc/util.c
80506@@ -71,6 +71,8 @@ struct ipc_proc_iface {
80507 int (*show)(struct seq_file *, void *);
80508 };
80509
80510+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
80511+
80512 static void ipc_memory_notifier(struct work_struct *work)
80513 {
80514 ipcns_notify(IPCNS_MEMCHANGED);
80515@@ -560,6 +562,9 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
80516 granted_mode >>= 6;
80517 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
80518 granted_mode >>= 3;
80519+ else if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
80520+ return -1;
80521+
80522 /* is there some bit set in requested_mode but not in granted_mode? */
80523 if ((requested_mode & ~granted_mode & 0007) &&
80524 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
80525diff --git a/kernel/acct.c b/kernel/acct.c
80526index 8d6e145..33e0b1e 100644
80527--- a/kernel/acct.c
80528+++ b/kernel/acct.c
80529@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
80530 */
80531 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
80532 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
80533- file->f_op->write(file, (char *)&ac,
80534+ file->f_op->write(file, (char __force_user *)&ac,
80535 sizeof(acct_t), &file->f_pos);
80536 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
80537 set_fs(fs);
80538diff --git a/kernel/audit.c b/kernel/audit.c
80539index 7b0e23a..f4d172f 100644
80540--- a/kernel/audit.c
80541+++ b/kernel/audit.c
80542@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
80543 3) suppressed due to audit_rate_limit
80544 4) suppressed due to audit_backlog_limit
80545 */
80546-static atomic_t audit_lost = ATOMIC_INIT(0);
80547+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
80548
80549 /* The netlink socket. */
80550 static struct sock *audit_sock;
80551@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
80552 unsigned long now;
80553 int print;
80554
80555- atomic_inc(&audit_lost);
80556+ atomic_inc_unchecked(&audit_lost);
80557
80558 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
80559
80560@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
80561 printk(KERN_WARNING
80562 "audit: audit_lost=%d audit_rate_limit=%d "
80563 "audit_backlog_limit=%d\n",
80564- atomic_read(&audit_lost),
80565+ atomic_read_unchecked(&audit_lost),
80566 audit_rate_limit,
80567 audit_backlog_limit);
80568 audit_panic(message);
80569@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80570
80571 switch (msg_type) {
80572 case AUDIT_GET:
80573+ status_set.mask = 0;
80574 status_set.enabled = audit_enabled;
80575 status_set.failure = audit_failure;
80576 status_set.pid = audit_pid;
80577 status_set.rate_limit = audit_rate_limit;
80578 status_set.backlog_limit = audit_backlog_limit;
80579- status_set.lost = atomic_read(&audit_lost);
80580+ status_set.lost = atomic_read_unchecked(&audit_lost);
80581 status_set.backlog = skb_queue_len(&audit_skb_queue);
80582 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
80583 &status_set, sizeof(status_set));
80584 break;
80585 case AUDIT_SET:
80586- if (nlh->nlmsg_len < sizeof(struct audit_status))
80587+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
80588 return -EINVAL;
80589 status_get = (struct audit_status *)data;
80590 if (status_get->mask & AUDIT_STATUS_ENABLED) {
80591@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80592
80593 memset(&s, 0, sizeof(s));
80594 /* guard against past and future API changes */
80595- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
80596+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
80597 if ((s.enabled != 0 && s.enabled != 1) ||
80598 (s.log_passwd != 0 && s.log_passwd != 1))
80599 return -EINVAL;
80600@@ -1251,7 +1252,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
80601 int i, avail, new_len;
80602 unsigned char *ptr;
80603 struct sk_buff *skb;
80604- static const unsigned char *hex = "0123456789ABCDEF";
80605+ static const unsigned char hex[] = "0123456789ABCDEF";
80606
80607 if (!ab)
80608 return;
80609diff --git a/kernel/auditsc.c b/kernel/auditsc.c
80610index 9845cb3..3ec9369 100644
80611--- a/kernel/auditsc.c
80612+++ b/kernel/auditsc.c
80613@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
80614 }
80615
80616 /* global counter which is incremented every time something logs in */
80617-static atomic_t session_id = ATOMIC_INIT(0);
80618+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
80619
80620 /**
80621 * audit_set_loginuid - set current task's audit_context loginuid
80622@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
80623 return -EPERM;
80624 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
80625
80626- sessionid = atomic_inc_return(&session_id);
80627+ sessionid = atomic_inc_return_unchecked(&session_id);
80628 if (context && context->in_syscall) {
80629 struct audit_buffer *ab;
80630
80631diff --git a/kernel/capability.c b/kernel/capability.c
80632index 4e66bf9..cdccecf 100644
80633--- a/kernel/capability.c
80634+++ b/kernel/capability.c
80635@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
80636 * before modification is attempted and the application
80637 * fails.
80638 */
80639+ if (tocopy > ARRAY_SIZE(kdata))
80640+ return -EFAULT;
80641+
80642 if (copy_to_user(dataptr, kdata, tocopy
80643 * sizeof(struct __user_cap_data_struct))) {
80644 return -EFAULT;
80645@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
80646 int ret;
80647
80648 rcu_read_lock();
80649- ret = security_capable(__task_cred(t), ns, cap);
80650+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
80651+ gr_task_is_capable(t, __task_cred(t), cap);
80652 rcu_read_unlock();
80653
80654- return (ret == 0);
80655+ return ret;
80656 }
80657
80658 /**
80659@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
80660 int ret;
80661
80662 rcu_read_lock();
80663- ret = security_capable_noaudit(__task_cred(t), ns, cap);
80664+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
80665 rcu_read_unlock();
80666
80667- return (ret == 0);
80668+ return ret;
80669 }
80670
80671 /**
80672@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
80673 BUG();
80674 }
80675
80676- if (security_capable(current_cred(), ns, cap) == 0) {
80677+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
80678 current->flags |= PF_SUPERPRIV;
80679 return true;
80680 }
80681@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
80682 }
80683 EXPORT_SYMBOL(ns_capable);
80684
80685+bool ns_capable_nolog(struct user_namespace *ns, int cap)
80686+{
80687+ if (unlikely(!cap_valid(cap))) {
80688+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
80689+ BUG();
80690+ }
80691+
80692+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
80693+ current->flags |= PF_SUPERPRIV;
80694+ return true;
80695+ }
80696+ return false;
80697+}
80698+EXPORT_SYMBOL(ns_capable_nolog);
80699+
80700 /**
80701 * file_ns_capable - Determine if the file's opener had a capability in effect
80702 * @file: The file we want to check
80703@@ -432,6 +451,12 @@ bool capable(int cap)
80704 }
80705 EXPORT_SYMBOL(capable);
80706
80707+bool capable_nolog(int cap)
80708+{
80709+ return ns_capable_nolog(&init_user_ns, cap);
80710+}
80711+EXPORT_SYMBOL(capable_nolog);
80712+
80713 /**
80714 * inode_capable - Check superior capability over inode
80715 * @inode: The inode in question
80716@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
80717 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80718 }
80719 EXPORT_SYMBOL(inode_capable);
80720+
80721+bool inode_capable_nolog(const struct inode *inode, int cap)
80722+{
80723+ struct user_namespace *ns = current_user_ns();
80724+
80725+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80726+}
80727+EXPORT_SYMBOL(inode_capable_nolog);
80728diff --git a/kernel/cgroup.c b/kernel/cgroup.c
80729index 8bd9cfd..9faf120 100644
80730--- a/kernel/cgroup.c
80731+++ b/kernel/cgroup.c
80732@@ -5817,7 +5817,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
80733 struct css_set *cset = link->cset;
80734 struct task_struct *task;
80735 int count = 0;
80736- seq_printf(seq, "css_set %p\n", cset);
80737+ seq_printf(seq, "css_set %pK\n", cset);
80738 list_for_each_entry(task, &cset->tasks, cg_list) {
80739 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
80740 seq_puts(seq, " ...\n");
80741diff --git a/kernel/compat.c b/kernel/compat.c
80742index 0a09e48..f44f3f0 100644
80743--- a/kernel/compat.c
80744+++ b/kernel/compat.c
80745@@ -13,6 +13,7 @@
80746
80747 #include <linux/linkage.h>
80748 #include <linux/compat.h>
80749+#include <linux/module.h>
80750 #include <linux/errno.h>
80751 #include <linux/time.h>
80752 #include <linux/signal.h>
80753@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
80754 mm_segment_t oldfs;
80755 long ret;
80756
80757- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
80758+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
80759 oldfs = get_fs();
80760 set_fs(KERNEL_DS);
80761 ret = hrtimer_nanosleep_restart(restart);
80762@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
80763 oldfs = get_fs();
80764 set_fs(KERNEL_DS);
80765 ret = hrtimer_nanosleep(&tu,
80766- rmtp ? (struct timespec __user *)&rmt : NULL,
80767+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
80768 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
80769 set_fs(oldfs);
80770
80771@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
80772 mm_segment_t old_fs = get_fs();
80773
80774 set_fs(KERNEL_DS);
80775- ret = sys_sigpending((old_sigset_t __user *) &s);
80776+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
80777 set_fs(old_fs);
80778 if (ret == 0)
80779 ret = put_user(s, set);
80780@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
80781 mm_segment_t old_fs = get_fs();
80782
80783 set_fs(KERNEL_DS);
80784- ret = sys_old_getrlimit(resource, &r);
80785+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
80786 set_fs(old_fs);
80787
80788 if (!ret) {
80789@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
80790 set_fs (KERNEL_DS);
80791 ret = sys_wait4(pid,
80792 (stat_addr ?
80793- (unsigned int __user *) &status : NULL),
80794- options, (struct rusage __user *) &r);
80795+ (unsigned int __force_user *) &status : NULL),
80796+ options, (struct rusage __force_user *) &r);
80797 set_fs (old_fs);
80798
80799 if (ret > 0) {
80800@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
80801 memset(&info, 0, sizeof(info));
80802
80803 set_fs(KERNEL_DS);
80804- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
80805- uru ? (struct rusage __user *)&ru : NULL);
80806+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
80807+ uru ? (struct rusage __force_user *)&ru : NULL);
80808 set_fs(old_fs);
80809
80810 if ((ret < 0) || (info.si_signo == 0))
80811@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
80812 oldfs = get_fs();
80813 set_fs(KERNEL_DS);
80814 err = sys_timer_settime(timer_id, flags,
80815- (struct itimerspec __user *) &newts,
80816- (struct itimerspec __user *) &oldts);
80817+ (struct itimerspec __force_user *) &newts,
80818+ (struct itimerspec __force_user *) &oldts);
80819 set_fs(oldfs);
80820 if (!err && old && put_compat_itimerspec(old, &oldts))
80821 return -EFAULT;
80822@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
80823 oldfs = get_fs();
80824 set_fs(KERNEL_DS);
80825 err = sys_timer_gettime(timer_id,
80826- (struct itimerspec __user *) &ts);
80827+ (struct itimerspec __force_user *) &ts);
80828 set_fs(oldfs);
80829 if (!err && put_compat_itimerspec(setting, &ts))
80830 return -EFAULT;
80831@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
80832 oldfs = get_fs();
80833 set_fs(KERNEL_DS);
80834 err = sys_clock_settime(which_clock,
80835- (struct timespec __user *) &ts);
80836+ (struct timespec __force_user *) &ts);
80837 set_fs(oldfs);
80838 return err;
80839 }
80840@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
80841 oldfs = get_fs();
80842 set_fs(KERNEL_DS);
80843 err = sys_clock_gettime(which_clock,
80844- (struct timespec __user *) &ts);
80845+ (struct timespec __force_user *) &ts);
80846 set_fs(oldfs);
80847 if (!err && put_compat_timespec(&ts, tp))
80848 return -EFAULT;
80849@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
80850
80851 oldfs = get_fs();
80852 set_fs(KERNEL_DS);
80853- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
80854+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
80855 set_fs(oldfs);
80856
80857 err = compat_put_timex(utp, &txc);
80858@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
80859 oldfs = get_fs();
80860 set_fs(KERNEL_DS);
80861 err = sys_clock_getres(which_clock,
80862- (struct timespec __user *) &ts);
80863+ (struct timespec __force_user *) &ts);
80864 set_fs(oldfs);
80865 if (!err && tp && put_compat_timespec(&ts, tp))
80866 return -EFAULT;
80867@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
80868 long err;
80869 mm_segment_t oldfs;
80870 struct timespec tu;
80871- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
80872+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
80873
80874- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
80875+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
80876 oldfs = get_fs();
80877 set_fs(KERNEL_DS);
80878 err = clock_nanosleep_restart(restart);
80879@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
80880 oldfs = get_fs();
80881 set_fs(KERNEL_DS);
80882 err = sys_clock_nanosleep(which_clock, flags,
80883- (struct timespec __user *) &in,
80884- (struct timespec __user *) &out);
80885+ (struct timespec __force_user *) &in,
80886+ (struct timespec __force_user *) &out);
80887 set_fs(oldfs);
80888
80889 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
80890diff --git a/kernel/configs.c b/kernel/configs.c
80891index c18b1f1..b9a0132 100644
80892--- a/kernel/configs.c
80893+++ b/kernel/configs.c
80894@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
80895 struct proc_dir_entry *entry;
80896
80897 /* create the current config file */
80898+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
80899+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
80900+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
80901+ &ikconfig_file_ops);
80902+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80903+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
80904+ &ikconfig_file_ops);
80905+#endif
80906+#else
80907 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
80908 &ikconfig_file_ops);
80909+#endif
80910+
80911 if (!entry)
80912 return -ENOMEM;
80913
80914diff --git a/kernel/cred.c b/kernel/cred.c
80915index e0573a4..3874e41 100644
80916--- a/kernel/cred.c
80917+++ b/kernel/cred.c
80918@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
80919 validate_creds(cred);
80920 alter_cred_subscribers(cred, -1);
80921 put_cred(cred);
80922+
80923+#ifdef CONFIG_GRKERNSEC_SETXID
80924+ cred = (struct cred *) tsk->delayed_cred;
80925+ if (cred != NULL) {
80926+ tsk->delayed_cred = NULL;
80927+ validate_creds(cred);
80928+ alter_cred_subscribers(cred, -1);
80929+ put_cred(cred);
80930+ }
80931+#endif
80932 }
80933
80934 /**
80935@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
80936 * Always returns 0 thus allowing this function to be tail-called at the end
80937 * of, say, sys_setgid().
80938 */
80939-int commit_creds(struct cred *new)
80940+static int __commit_creds(struct cred *new)
80941 {
80942 struct task_struct *task = current;
80943 const struct cred *old = task->real_cred;
80944@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
80945
80946 get_cred(new); /* we will require a ref for the subj creds too */
80947
80948+ gr_set_role_label(task, new->uid, new->gid);
80949+
80950 /* dumpability changes */
80951 if (!uid_eq(old->euid, new->euid) ||
80952 !gid_eq(old->egid, new->egid) ||
80953@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
80954 put_cred(old);
80955 return 0;
80956 }
80957+#ifdef CONFIG_GRKERNSEC_SETXID
80958+extern int set_user(struct cred *new);
80959+
80960+void gr_delayed_cred_worker(void)
80961+{
80962+ const struct cred *new = current->delayed_cred;
80963+ struct cred *ncred;
80964+
80965+ current->delayed_cred = NULL;
80966+
80967+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
80968+ // from doing get_cred on it when queueing this
80969+ put_cred(new);
80970+ return;
80971+ } else if (new == NULL)
80972+ return;
80973+
80974+ ncred = prepare_creds();
80975+ if (!ncred)
80976+ goto die;
80977+ // uids
80978+ ncred->uid = new->uid;
80979+ ncred->euid = new->euid;
80980+ ncred->suid = new->suid;
80981+ ncred->fsuid = new->fsuid;
80982+ // gids
80983+ ncred->gid = new->gid;
80984+ ncred->egid = new->egid;
80985+ ncred->sgid = new->sgid;
80986+ ncred->fsgid = new->fsgid;
80987+ // groups
80988+ if (set_groups(ncred, new->group_info) < 0) {
80989+ abort_creds(ncred);
80990+ goto die;
80991+ }
80992+ // caps
80993+ ncred->securebits = new->securebits;
80994+ ncred->cap_inheritable = new->cap_inheritable;
80995+ ncred->cap_permitted = new->cap_permitted;
80996+ ncred->cap_effective = new->cap_effective;
80997+ ncred->cap_bset = new->cap_bset;
80998+
80999+ if (set_user(ncred)) {
81000+ abort_creds(ncred);
81001+ goto die;
81002+ }
81003+
81004+ // from doing get_cred on it when queueing this
81005+ put_cred(new);
81006+
81007+ __commit_creds(ncred);
81008+ return;
81009+die:
81010+ // from doing get_cred on it when queueing this
81011+ put_cred(new);
81012+ do_group_exit(SIGKILL);
81013+}
81014+#endif
81015+
81016+int commit_creds(struct cred *new)
81017+{
81018+#ifdef CONFIG_GRKERNSEC_SETXID
81019+ int ret;
81020+ int schedule_it = 0;
81021+ struct task_struct *t;
81022+
81023+ /* we won't get called with tasklist_lock held for writing
81024+ and interrupts disabled as the cred struct in that case is
81025+ init_cred
81026+ */
81027+ if (grsec_enable_setxid && !current_is_single_threaded() &&
81028+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
81029+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
81030+ schedule_it = 1;
81031+ }
81032+ ret = __commit_creds(new);
81033+ if (schedule_it) {
81034+ rcu_read_lock();
81035+ read_lock(&tasklist_lock);
81036+ for (t = next_thread(current); t != current;
81037+ t = next_thread(t)) {
81038+ if (t->delayed_cred == NULL) {
81039+ t->delayed_cred = get_cred(new);
81040+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
81041+ set_tsk_need_resched(t);
81042+ }
81043+ }
81044+ read_unlock(&tasklist_lock);
81045+ rcu_read_unlock();
81046+ }
81047+ return ret;
81048+#else
81049+ return __commit_creds(new);
81050+#endif
81051+}
81052+
81053 EXPORT_SYMBOL(commit_creds);
81054
81055 /**
81056diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
81057index 0506d44..2c20034 100644
81058--- a/kernel/debug/debug_core.c
81059+++ b/kernel/debug/debug_core.c
81060@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
81061 */
81062 static atomic_t masters_in_kgdb;
81063 static atomic_t slaves_in_kgdb;
81064-static atomic_t kgdb_break_tasklet_var;
81065+static atomic_unchecked_t kgdb_break_tasklet_var;
81066 atomic_t kgdb_setting_breakpoint;
81067
81068 struct task_struct *kgdb_usethread;
81069@@ -133,7 +133,7 @@ int kgdb_single_step;
81070 static pid_t kgdb_sstep_pid;
81071
81072 /* to keep track of the CPU which is doing the single stepping*/
81073-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81074+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81075
81076 /*
81077 * If you are debugging a problem where roundup (the collection of
81078@@ -541,7 +541,7 @@ return_normal:
81079 * kernel will only try for the value of sstep_tries before
81080 * giving up and continuing on.
81081 */
81082- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
81083+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
81084 (kgdb_info[cpu].task &&
81085 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
81086 atomic_set(&kgdb_active, -1);
81087@@ -635,8 +635,8 @@ cpu_master_loop:
81088 }
81089
81090 kgdb_restore:
81091- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
81092- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
81093+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
81094+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
81095 if (kgdb_info[sstep_cpu].task)
81096 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
81097 else
81098@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
81099 static void kgdb_tasklet_bpt(unsigned long ing)
81100 {
81101 kgdb_breakpoint();
81102- atomic_set(&kgdb_break_tasklet_var, 0);
81103+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
81104 }
81105
81106 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
81107
81108 void kgdb_schedule_breakpoint(void)
81109 {
81110- if (atomic_read(&kgdb_break_tasklet_var) ||
81111+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
81112 atomic_read(&kgdb_active) != -1 ||
81113 atomic_read(&kgdb_setting_breakpoint))
81114 return;
81115- atomic_inc(&kgdb_break_tasklet_var);
81116+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
81117 tasklet_schedule(&kgdb_tasklet_breakpoint);
81118 }
81119 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
81120diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
81121index 00eb8f7..d7e3244 100644
81122--- a/kernel/debug/kdb/kdb_main.c
81123+++ b/kernel/debug/kdb/kdb_main.c
81124@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
81125 continue;
81126
81127 kdb_printf("%-20s%8u 0x%p ", mod->name,
81128- mod->core_size, (void *)mod);
81129+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
81130 #ifdef CONFIG_MODULE_UNLOAD
81131 kdb_printf("%4ld ", module_refcount(mod));
81132 #endif
81133@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
81134 kdb_printf(" (Loading)");
81135 else
81136 kdb_printf(" (Live)");
81137- kdb_printf(" 0x%p", mod->module_core);
81138+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
81139
81140 #ifdef CONFIG_MODULE_UNLOAD
81141 {
81142diff --git a/kernel/events/core.c b/kernel/events/core.c
81143index 953c143..5646bb1 100644
81144--- a/kernel/events/core.c
81145+++ b/kernel/events/core.c
81146@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
81147 * 0 - disallow raw tracepoint access for unpriv
81148 * 1 - disallow cpu events for unpriv
81149 * 2 - disallow kernel profiling for unpriv
81150+ * 3 - disallow all unpriv perf event use
81151 */
81152-int sysctl_perf_event_paranoid __read_mostly = 1;
81153+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81154+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
81155+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
81156+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
81157+#else
81158+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
81159+#endif
81160
81161 /* Minimum for 512 kiB + 1 user control page */
81162 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
81163@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
81164 update_perf_cpu_limits();
81165 }
81166
81167-static atomic64_t perf_event_id;
81168+static atomic64_unchecked_t perf_event_id;
81169
81170 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
81171 enum event_type_t event_type);
81172@@ -2940,7 +2947,7 @@ static void __perf_event_read(void *info)
81173
81174 static inline u64 perf_event_count(struct perf_event *event)
81175 {
81176- return local64_read(&event->count) + atomic64_read(&event->child_count);
81177+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
81178 }
81179
81180 static u64 perf_event_read(struct perf_event *event)
81181@@ -3308,9 +3315,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
81182 mutex_lock(&event->child_mutex);
81183 total += perf_event_read(event);
81184 *enabled += event->total_time_enabled +
81185- atomic64_read(&event->child_total_time_enabled);
81186+ atomic64_read_unchecked(&event->child_total_time_enabled);
81187 *running += event->total_time_running +
81188- atomic64_read(&event->child_total_time_running);
81189+ atomic64_read_unchecked(&event->child_total_time_running);
81190
81191 list_for_each_entry(child, &event->child_list, child_list) {
81192 total += perf_event_read(child);
81193@@ -3725,10 +3732,10 @@ void perf_event_update_userpage(struct perf_event *event)
81194 userpg->offset -= local64_read(&event->hw.prev_count);
81195
81196 userpg->time_enabled = enabled +
81197- atomic64_read(&event->child_total_time_enabled);
81198+ atomic64_read_unchecked(&event->child_total_time_enabled);
81199
81200 userpg->time_running = running +
81201- atomic64_read(&event->child_total_time_running);
81202+ atomic64_read_unchecked(&event->child_total_time_running);
81203
81204 arch_perf_update_userpage(userpg, now);
81205
81206@@ -4279,7 +4286,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
81207
81208 /* Data. */
81209 sp = perf_user_stack_pointer(regs);
81210- rem = __output_copy_user(handle, (void *) sp, dump_size);
81211+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
81212 dyn_size = dump_size - rem;
81213
81214 perf_output_skip(handle, rem);
81215@@ -4370,11 +4377,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
81216 values[n++] = perf_event_count(event);
81217 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
81218 values[n++] = enabled +
81219- atomic64_read(&event->child_total_time_enabled);
81220+ atomic64_read_unchecked(&event->child_total_time_enabled);
81221 }
81222 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
81223 values[n++] = running +
81224- atomic64_read(&event->child_total_time_running);
81225+ atomic64_read_unchecked(&event->child_total_time_running);
81226 }
81227 if (read_format & PERF_FORMAT_ID)
81228 values[n++] = primary_event_id(event);
81229@@ -5112,12 +5119,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
81230 * need to add enough zero bytes after the string to handle
81231 * the 64bit alignment we do later.
81232 */
81233- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
81234+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
81235 if (!buf) {
81236 name = strncpy(tmp, "//enomem", sizeof(tmp));
81237 goto got_name;
81238 }
81239- name = d_path(&file->f_path, buf, PATH_MAX);
81240+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
81241 if (IS_ERR(name)) {
81242 name = strncpy(tmp, "//toolong", sizeof(tmp));
81243 goto got_name;
81244@@ -6639,7 +6646,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
81245 event->parent = parent_event;
81246
81247 event->ns = get_pid_ns(task_active_pid_ns(current));
81248- event->id = atomic64_inc_return(&perf_event_id);
81249+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
81250
81251 event->state = PERF_EVENT_STATE_INACTIVE;
81252
81253@@ -6938,6 +6945,11 @@ SYSCALL_DEFINE5(perf_event_open,
81254 if (flags & ~PERF_FLAG_ALL)
81255 return -EINVAL;
81256
81257+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81258+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
81259+ return -EACCES;
81260+#endif
81261+
81262 err = perf_copy_attr(attr_uptr, &attr);
81263 if (err)
81264 return err;
81265@@ -7271,10 +7283,10 @@ static void sync_child_event(struct perf_event *child_event,
81266 /*
81267 * Add back the child's count to the parent's count:
81268 */
81269- atomic64_add(child_val, &parent_event->child_count);
81270- atomic64_add(child_event->total_time_enabled,
81271+ atomic64_add_unchecked(child_val, &parent_event->child_count);
81272+ atomic64_add_unchecked(child_event->total_time_enabled,
81273 &parent_event->child_total_time_enabled);
81274- atomic64_add(child_event->total_time_running,
81275+ atomic64_add_unchecked(child_event->total_time_running,
81276 &parent_event->child_total_time_running);
81277
81278 /*
81279diff --git a/kernel/events/internal.h b/kernel/events/internal.h
81280index ca65997..60df03d 100644
81281--- a/kernel/events/internal.h
81282+++ b/kernel/events/internal.h
81283@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
81284 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
81285 }
81286
81287-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
81288-static inline unsigned int \
81289+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
81290+static inline unsigned long \
81291 func_name(struct perf_output_handle *handle, \
81292- const void *buf, unsigned int len) \
81293+ const void user *buf, unsigned long len) \
81294 { \
81295 unsigned long size, written; \
81296 \
81297@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
81298 return n;
81299 }
81300
81301-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
81302+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
81303
81304 #define MEMCPY_SKIP(dst, src, n) (n)
81305
81306-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
81307+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
81308
81309 #ifndef arch_perf_out_copy_user
81310 #define arch_perf_out_copy_user __copy_from_user_inatomic
81311 #endif
81312
81313-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
81314+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
81315
81316 /* Callchain handling */
81317 extern struct perf_callchain_entry *
81318diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
81319index ad8e1bd..fed7ba9 100644
81320--- a/kernel/events/uprobes.c
81321+++ b/kernel/events/uprobes.c
81322@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
81323 {
81324 struct page *page;
81325 uprobe_opcode_t opcode;
81326- int result;
81327+ long result;
81328
81329 pagefault_disable();
81330 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
81331diff --git a/kernel/exit.c b/kernel/exit.c
81332index a949819..a5f127d 100644
81333--- a/kernel/exit.c
81334+++ b/kernel/exit.c
81335@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
81336 struct task_struct *leader;
81337 int zap_leader;
81338 repeat:
81339+#ifdef CONFIG_NET
81340+ gr_del_task_from_ip_table(p);
81341+#endif
81342+
81343 /* don't need to get the RCU readlock here - the process is dead and
81344 * can't be modifying its own credentials. But shut RCU-lockdep up */
81345 rcu_read_lock();
81346@@ -329,7 +333,7 @@ int allow_signal(int sig)
81347 * know it'll be handled, so that they don't get converted to
81348 * SIGKILL or just silently dropped.
81349 */
81350- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
81351+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
81352 recalc_sigpending();
81353 spin_unlock_irq(&current->sighand->siglock);
81354 return 0;
81355@@ -698,6 +702,8 @@ void do_exit(long code)
81356 struct task_struct *tsk = current;
81357 int group_dead;
81358
81359+ set_fs(USER_DS);
81360+
81361 profile_task_exit(tsk);
81362
81363 WARN_ON(blk_needs_flush_plug(tsk));
81364@@ -714,7 +720,6 @@ void do_exit(long code)
81365 * mm_release()->clear_child_tid() from writing to a user-controlled
81366 * kernel address.
81367 */
81368- set_fs(USER_DS);
81369
81370 ptrace_event(PTRACE_EVENT_EXIT, code);
81371
81372@@ -773,6 +778,9 @@ void do_exit(long code)
81373 tsk->exit_code = code;
81374 taskstats_exit(tsk, group_dead);
81375
81376+ gr_acl_handle_psacct(tsk, code);
81377+ gr_acl_handle_exit();
81378+
81379 exit_mm(tsk);
81380
81381 if (group_dead)
81382@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
81383 * Take down every thread in the group. This is called by fatal signals
81384 * as well as by sys_exit_group (below).
81385 */
81386-void
81387+__noreturn void
81388 do_group_exit(int exit_code)
81389 {
81390 struct signal_struct *sig = current->signal;
81391diff --git a/kernel/fork.c b/kernel/fork.c
81392index 086fe73..72c1122 100644
81393--- a/kernel/fork.c
81394+++ b/kernel/fork.c
81395@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
81396 *stackend = STACK_END_MAGIC; /* for overflow detection */
81397
81398 #ifdef CONFIG_CC_STACKPROTECTOR
81399- tsk->stack_canary = get_random_int();
81400+ tsk->stack_canary = pax_get_random_long();
81401 #endif
81402
81403 /*
81404@@ -345,12 +345,80 @@ free_tsk:
81405 }
81406
81407 #ifdef CONFIG_MMU
81408-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81409+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
81410+{
81411+ struct vm_area_struct *tmp;
81412+ unsigned long charge;
81413+ struct file *file;
81414+ int retval;
81415+
81416+ charge = 0;
81417+ if (mpnt->vm_flags & VM_ACCOUNT) {
81418+ unsigned long len = vma_pages(mpnt);
81419+
81420+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81421+ goto fail_nomem;
81422+ charge = len;
81423+ }
81424+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81425+ if (!tmp)
81426+ goto fail_nomem;
81427+ *tmp = *mpnt;
81428+ tmp->vm_mm = mm;
81429+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
81430+ retval = vma_dup_policy(mpnt, tmp);
81431+ if (retval)
81432+ goto fail_nomem_policy;
81433+ if (anon_vma_fork(tmp, mpnt))
81434+ goto fail_nomem_anon_vma_fork;
81435+ tmp->vm_flags &= ~VM_LOCKED;
81436+ tmp->vm_next = tmp->vm_prev = NULL;
81437+ tmp->vm_mirror = NULL;
81438+ file = tmp->vm_file;
81439+ if (file) {
81440+ struct inode *inode = file_inode(file);
81441+ struct address_space *mapping = file->f_mapping;
81442+
81443+ get_file(file);
81444+ if (tmp->vm_flags & VM_DENYWRITE)
81445+ atomic_dec(&inode->i_writecount);
81446+ mutex_lock(&mapping->i_mmap_mutex);
81447+ if (tmp->vm_flags & VM_SHARED)
81448+ mapping->i_mmap_writable++;
81449+ flush_dcache_mmap_lock(mapping);
81450+ /* insert tmp into the share list, just after mpnt */
81451+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81452+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
81453+ else
81454+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
81455+ flush_dcache_mmap_unlock(mapping);
81456+ mutex_unlock(&mapping->i_mmap_mutex);
81457+ }
81458+
81459+ /*
81460+ * Clear hugetlb-related page reserves for children. This only
81461+ * affects MAP_PRIVATE mappings. Faults generated by the child
81462+ * are not guaranteed to succeed, even if read-only
81463+ */
81464+ if (is_vm_hugetlb_page(tmp))
81465+ reset_vma_resv_huge_pages(tmp);
81466+
81467+ return tmp;
81468+
81469+fail_nomem_anon_vma_fork:
81470+ mpol_put(vma_policy(tmp));
81471+fail_nomem_policy:
81472+ kmem_cache_free(vm_area_cachep, tmp);
81473+fail_nomem:
81474+ vm_unacct_memory(charge);
81475+ return NULL;
81476+}
81477+
81478+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81479 {
81480 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
81481 struct rb_node **rb_link, *rb_parent;
81482 int retval;
81483- unsigned long charge;
81484
81485 uprobe_start_dup_mmap();
81486 down_write(&oldmm->mmap_sem);
81487@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81488
81489 prev = NULL;
81490 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
81491- struct file *file;
81492-
81493 if (mpnt->vm_flags & VM_DONTCOPY) {
81494 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
81495 -vma_pages(mpnt));
81496 continue;
81497 }
81498- charge = 0;
81499- if (mpnt->vm_flags & VM_ACCOUNT) {
81500- unsigned long len = vma_pages(mpnt);
81501-
81502- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81503- goto fail_nomem;
81504- charge = len;
81505- }
81506- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81507- if (!tmp)
81508- goto fail_nomem;
81509- *tmp = *mpnt;
81510- INIT_LIST_HEAD(&tmp->anon_vma_chain);
81511- retval = vma_dup_policy(mpnt, tmp);
81512- if (retval)
81513- goto fail_nomem_policy;
81514- tmp->vm_mm = mm;
81515- if (anon_vma_fork(tmp, mpnt))
81516- goto fail_nomem_anon_vma_fork;
81517- tmp->vm_flags &= ~VM_LOCKED;
81518- tmp->vm_next = tmp->vm_prev = NULL;
81519- file = tmp->vm_file;
81520- if (file) {
81521- struct inode *inode = file_inode(file);
81522- struct address_space *mapping = file->f_mapping;
81523-
81524- get_file(file);
81525- if (tmp->vm_flags & VM_DENYWRITE)
81526- atomic_dec(&inode->i_writecount);
81527- mutex_lock(&mapping->i_mmap_mutex);
81528- if (tmp->vm_flags & VM_SHARED)
81529- mapping->i_mmap_writable++;
81530- flush_dcache_mmap_lock(mapping);
81531- /* insert tmp into the share list, just after mpnt */
81532- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81533- vma_nonlinear_insert(tmp,
81534- &mapping->i_mmap_nonlinear);
81535- else
81536- vma_interval_tree_insert_after(tmp, mpnt,
81537- &mapping->i_mmap);
81538- flush_dcache_mmap_unlock(mapping);
81539- mutex_unlock(&mapping->i_mmap_mutex);
81540+ tmp = dup_vma(mm, oldmm, mpnt);
81541+ if (!tmp) {
81542+ retval = -ENOMEM;
81543+ goto out;
81544 }
81545
81546 /*
81547@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81548 if (retval)
81549 goto out;
81550 }
81551+
81552+#ifdef CONFIG_PAX_SEGMEXEC
81553+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
81554+ struct vm_area_struct *mpnt_m;
81555+
81556+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
81557+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
81558+
81559+ if (!mpnt->vm_mirror)
81560+ continue;
81561+
81562+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
81563+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
81564+ mpnt->vm_mirror = mpnt_m;
81565+ } else {
81566+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
81567+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
81568+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
81569+ mpnt->vm_mirror->vm_mirror = mpnt;
81570+ }
81571+ }
81572+ BUG_ON(mpnt_m);
81573+ }
81574+#endif
81575+
81576 /* a new mm has just been created */
81577 arch_dup_mmap(oldmm, mm);
81578 retval = 0;
81579@@ -468,14 +521,6 @@ out:
81580 up_write(&oldmm->mmap_sem);
81581 uprobe_end_dup_mmap();
81582 return retval;
81583-fail_nomem_anon_vma_fork:
81584- mpol_put(vma_policy(tmp));
81585-fail_nomem_policy:
81586- kmem_cache_free(vm_area_cachep, tmp);
81587-fail_nomem:
81588- retval = -ENOMEM;
81589- vm_unacct_memory(charge);
81590- goto out;
81591 }
81592
81593 static inline int mm_alloc_pgd(struct mm_struct *mm)
81594@@ -688,8 +733,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
81595 return ERR_PTR(err);
81596
81597 mm = get_task_mm(task);
81598- if (mm && mm != current->mm &&
81599- !ptrace_may_access(task, mode)) {
81600+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
81601+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
81602 mmput(mm);
81603 mm = ERR_PTR(-EACCES);
81604 }
81605@@ -911,13 +956,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
81606 spin_unlock(&fs->lock);
81607 return -EAGAIN;
81608 }
81609- fs->users++;
81610+ atomic_inc(&fs->users);
81611 spin_unlock(&fs->lock);
81612 return 0;
81613 }
81614 tsk->fs = copy_fs_struct(fs);
81615 if (!tsk->fs)
81616 return -ENOMEM;
81617+ /* Carry through gr_chroot_dentry and is_chrooted instead
81618+ of recomputing it here. Already copied when the task struct
81619+ is duplicated. This allows pivot_root to not be treated as
81620+ a chroot
81621+ */
81622+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
81623+
81624 return 0;
81625 }
81626
81627@@ -1128,7 +1180,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
81628 * parts of the process environment (as per the clone
81629 * flags). The actual kick-off is left to the caller.
81630 */
81631-static struct task_struct *copy_process(unsigned long clone_flags,
81632+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
81633 unsigned long stack_start,
81634 unsigned long stack_size,
81635 int __user *child_tidptr,
81636@@ -1200,6 +1252,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81637 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
81638 #endif
81639 retval = -EAGAIN;
81640+
81641+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
81642+
81643 if (atomic_read(&p->real_cred->user->processes) >=
81644 task_rlimit(p, RLIMIT_NPROC)) {
81645 if (p->real_cred->user != INIT_USER &&
81646@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81647 goto bad_fork_free_pid;
81648 }
81649
81650+ /* synchronizes with gr_set_acls()
81651+ we need to call this past the point of no return for fork()
81652+ */
81653+ gr_copy_label(p);
81654+
81655 if (likely(p->pid)) {
81656 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
81657
81658@@ -1534,6 +1594,8 @@ bad_fork_cleanup_count:
81659 bad_fork_free:
81660 free_task(p);
81661 fork_out:
81662+ gr_log_forkfail(retval);
81663+
81664 return ERR_PTR(retval);
81665 }
81666
81667@@ -1595,6 +1657,7 @@ long do_fork(unsigned long clone_flags,
81668
81669 p = copy_process(clone_flags, stack_start, stack_size,
81670 child_tidptr, NULL, trace);
81671+ add_latent_entropy();
81672 /*
81673 * Do this prior waking up the new thread - the thread pointer
81674 * might get invalid after that point, if the thread exits quickly.
81675@@ -1609,6 +1672,8 @@ long do_fork(unsigned long clone_flags,
81676 if (clone_flags & CLONE_PARENT_SETTID)
81677 put_user(nr, parent_tidptr);
81678
81679+ gr_handle_brute_check();
81680+
81681 if (clone_flags & CLONE_VFORK) {
81682 p->vfork_done = &vfork;
81683 init_completion(&vfork);
81684@@ -1725,7 +1790,7 @@ void __init proc_caches_init(void)
81685 mm_cachep = kmem_cache_create("mm_struct",
81686 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
81687 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
81688- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
81689+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
81690 mmap_init();
81691 nsproxy_cache_init();
81692 }
81693@@ -1765,7 +1830,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
81694 return 0;
81695
81696 /* don't need lock here; in the worst case we'll do useless copy */
81697- if (fs->users == 1)
81698+ if (atomic_read(&fs->users) == 1)
81699 return 0;
81700
81701 *new_fsp = copy_fs_struct(fs);
81702@@ -1872,7 +1937,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
81703 fs = current->fs;
81704 spin_lock(&fs->lock);
81705 current->fs = new_fs;
81706- if (--fs->users)
81707+ gr_set_chroot_entries(current, &current->fs->root);
81708+ if (atomic_dec_return(&fs->users))
81709 new_fs = NULL;
81710 else
81711 new_fs = fs;
81712diff --git a/kernel/futex.c b/kernel/futex.c
81713index c3a1a55..e32b4a98 100644
81714--- a/kernel/futex.c
81715+++ b/kernel/futex.c
81716@@ -54,6 +54,7 @@
81717 #include <linux/mount.h>
81718 #include <linux/pagemap.h>
81719 #include <linux/syscalls.h>
81720+#include <linux/ptrace.h>
81721 #include <linux/signal.h>
81722 #include <linux/export.h>
81723 #include <linux/magic.h>
81724@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
81725 struct page *page, *page_head;
81726 int err, ro = 0;
81727
81728+#ifdef CONFIG_PAX_SEGMEXEC
81729+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
81730+ return -EFAULT;
81731+#endif
81732+
81733 /*
81734 * The futex address must be "naturally" aligned.
81735 */
81736@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
81737
81738 static int get_futex_value_locked(u32 *dest, u32 __user *from)
81739 {
81740- int ret;
81741+ unsigned long ret;
81742
81743 pagefault_disable();
81744 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
81745@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
81746 {
81747 u32 curval;
81748 int i;
81749+ mm_segment_t oldfs;
81750
81751 /*
81752 * This will fail and we want it. Some arch implementations do
81753@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
81754 * implementation, the non-functional ones will return
81755 * -ENOSYS.
81756 */
81757+ oldfs = get_fs();
81758+ set_fs(USER_DS);
81759 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
81760 futex_cmpxchg_enabled = 1;
81761+ set_fs(oldfs);
81762
81763 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
81764 plist_head_init(&futex_queues[i].chain);
81765diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
81766index f9f44fd..29885e4 100644
81767--- a/kernel/futex_compat.c
81768+++ b/kernel/futex_compat.c
81769@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
81770 return 0;
81771 }
81772
81773-static void __user *futex_uaddr(struct robust_list __user *entry,
81774+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
81775 compat_long_t futex_offset)
81776 {
81777 compat_uptr_t base = ptr_to_compat(entry);
81778diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
81779index 9b22d03..6295b62 100644
81780--- a/kernel/gcov/base.c
81781+++ b/kernel/gcov/base.c
81782@@ -102,11 +102,6 @@ void gcov_enable_events(void)
81783 }
81784
81785 #ifdef CONFIG_MODULES
81786-static inline int within(void *addr, void *start, unsigned long size)
81787-{
81788- return ((addr >= start) && (addr < start + size));
81789-}
81790-
81791 /* Update list and generate events when modules are unloaded. */
81792 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
81793 void *data)
81794@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
81795 prev = NULL;
81796 /* Remove entries located in module from linked list. */
81797 for (info = gcov_info_head; info; info = info->next) {
81798- if (within(info, mod->module_core, mod->core_size)) {
81799+ if (within_module_core_rw((unsigned long)info, mod)) {
81800 if (prev)
81801 prev->next = info->next;
81802 else
81803diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
81804index 383319b..56ebb13 100644
81805--- a/kernel/hrtimer.c
81806+++ b/kernel/hrtimer.c
81807@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
81808 local_irq_restore(flags);
81809 }
81810
81811-static void run_hrtimer_softirq(struct softirq_action *h)
81812+static __latent_entropy void run_hrtimer_softirq(void)
81813 {
81814 hrtimer_peek_ahead_timers();
81815 }
81816diff --git a/kernel/irq_work.c b/kernel/irq_work.c
81817index 55fcce6..0e4cf34 100644
81818--- a/kernel/irq_work.c
81819+++ b/kernel/irq_work.c
81820@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
81821 return NOTIFY_OK;
81822 }
81823
81824-static struct notifier_block cpu_notify;
81825+static struct notifier_block cpu_notify = {
81826+ .notifier_call = irq_work_cpu_notify,
81827+ .priority = 0,
81828+};
81829
81830 static __init int irq_work_init_cpu_notifier(void)
81831 {
81832- cpu_notify.notifier_call = irq_work_cpu_notify;
81833- cpu_notify.priority = 0;
81834 register_cpu_notifier(&cpu_notify);
81835 return 0;
81836 }
81837diff --git a/kernel/jump_label.c b/kernel/jump_label.c
81838index 297a924..7290070 100644
81839--- a/kernel/jump_label.c
81840+++ b/kernel/jump_label.c
81841@@ -14,6 +14,7 @@
81842 #include <linux/err.h>
81843 #include <linux/static_key.h>
81844 #include <linux/jump_label_ratelimit.h>
81845+#include <linux/mm.h>
81846
81847 #ifdef HAVE_JUMP_LABEL
81848
81849@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
81850
81851 size = (((unsigned long)stop - (unsigned long)start)
81852 / sizeof(struct jump_entry));
81853+ pax_open_kernel();
81854 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
81855+ pax_close_kernel();
81856 }
81857
81858 static void jump_label_update(struct static_key *key, int enable);
81859@@ -358,10 +361,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
81860 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
81861 struct jump_entry *iter;
81862
81863+ pax_open_kernel();
81864 for (iter = iter_start; iter < iter_stop; iter++) {
81865 if (within_module_init(iter->code, mod))
81866 iter->code = 0;
81867 }
81868+ pax_close_kernel();
81869 }
81870
81871 static int
81872diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
81873index 3127ad5..159d880 100644
81874--- a/kernel/kallsyms.c
81875+++ b/kernel/kallsyms.c
81876@@ -11,6 +11,9 @@
81877 * Changed the compression method from stem compression to "table lookup"
81878 * compression (see scripts/kallsyms.c for a more complete description)
81879 */
81880+#ifdef CONFIG_GRKERNSEC_HIDESYM
81881+#define __INCLUDED_BY_HIDESYM 1
81882+#endif
81883 #include <linux/kallsyms.h>
81884 #include <linux/module.h>
81885 #include <linux/init.h>
81886@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
81887
81888 static inline int is_kernel_inittext(unsigned long addr)
81889 {
81890+ if (system_state != SYSTEM_BOOTING)
81891+ return 0;
81892+
81893 if (addr >= (unsigned long)_sinittext
81894 && addr <= (unsigned long)_einittext)
81895 return 1;
81896 return 0;
81897 }
81898
81899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81900+#ifdef CONFIG_MODULES
81901+static inline int is_module_text(unsigned long addr)
81902+{
81903+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
81904+ return 1;
81905+
81906+ addr = ktla_ktva(addr);
81907+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
81908+}
81909+#else
81910+static inline int is_module_text(unsigned long addr)
81911+{
81912+ return 0;
81913+}
81914+#endif
81915+#endif
81916+
81917 static inline int is_kernel_text(unsigned long addr)
81918 {
81919 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
81920@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
81921
81922 static inline int is_kernel(unsigned long addr)
81923 {
81924+
81925+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81926+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
81927+ return 1;
81928+
81929+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
81930+#else
81931 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
81932+#endif
81933+
81934 return 1;
81935 return in_gate_area_no_mm(addr);
81936 }
81937
81938 static int is_ksym_addr(unsigned long addr)
81939 {
81940+
81941+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81942+ if (is_module_text(addr))
81943+ return 0;
81944+#endif
81945+
81946 if (all_var)
81947 return is_kernel(addr);
81948
81949@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
81950
81951 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
81952 {
81953- iter->name[0] = '\0';
81954 iter->nameoff = get_symbol_offset(new_pos);
81955 iter->pos = new_pos;
81956 }
81957@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
81958 {
81959 struct kallsym_iter *iter = m->private;
81960
81961+#ifdef CONFIG_GRKERNSEC_HIDESYM
81962+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
81963+ return 0;
81964+#endif
81965+
81966 /* Some debugging symbols have no name. Ignore them. */
81967 if (!iter->name[0])
81968 return 0;
81969@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
81970 */
81971 type = iter->exported ? toupper(iter->type) :
81972 tolower(iter->type);
81973+
81974 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
81975 type, iter->name, iter->module_name);
81976 } else
81977@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
81978 struct kallsym_iter *iter;
81979 int ret;
81980
81981- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
81982+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
81983 if (!iter)
81984 return -ENOMEM;
81985 reset_iter(iter, 0);
81986diff --git a/kernel/kcmp.c b/kernel/kcmp.c
81987index e30ac0f..3528cac 100644
81988--- a/kernel/kcmp.c
81989+++ b/kernel/kcmp.c
81990@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
81991 struct task_struct *task1, *task2;
81992 int ret;
81993
81994+#ifdef CONFIG_GRKERNSEC
81995+ return -ENOSYS;
81996+#endif
81997+
81998 rcu_read_lock();
81999
82000 /*
82001diff --git a/kernel/kexec.c b/kernel/kexec.c
82002index 2a74f30..d139351 100644
82003--- a/kernel/kexec.c
82004+++ b/kernel/kexec.c
82005@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
82006 unsigned long flags)
82007 {
82008 struct compat_kexec_segment in;
82009- struct kexec_segment out, __user *ksegments;
82010+ struct kexec_segment out;
82011+ struct kexec_segment __user *ksegments;
82012 unsigned long i, result;
82013
82014 /* Don't allow clients that don't understand the native
82015diff --git a/kernel/kmod.c b/kernel/kmod.c
82016index b086006..6d2e579 100644
82017--- a/kernel/kmod.c
82018+++ b/kernel/kmod.c
82019@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
82020 kfree(info->argv);
82021 }
82022
82023-static int call_modprobe(char *module_name, int wait)
82024+static int call_modprobe(char *module_name, char *module_param, int wait)
82025 {
82026 struct subprocess_info *info;
82027 static char *envp[] = {
82028@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
82029 NULL
82030 };
82031
82032- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
82033+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
82034 if (!argv)
82035 goto out;
82036
82037@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
82038 argv[1] = "-q";
82039 argv[2] = "--";
82040 argv[3] = module_name; /* check free_modprobe_argv() */
82041- argv[4] = NULL;
82042+ argv[4] = module_param;
82043+ argv[5] = NULL;
82044
82045 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
82046 NULL, free_modprobe_argv, NULL);
82047@@ -129,9 +130,8 @@ out:
82048 * If module auto-loading support is disabled then this function
82049 * becomes a no-operation.
82050 */
82051-int __request_module(bool wait, const char *fmt, ...)
82052+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
82053 {
82054- va_list args;
82055 char module_name[MODULE_NAME_LEN];
82056 unsigned int max_modprobes;
82057 int ret;
82058@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
82059 if (!modprobe_path[0])
82060 return 0;
82061
82062- va_start(args, fmt);
82063- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
82064- va_end(args);
82065+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
82066 if (ret >= MODULE_NAME_LEN)
82067 return -ENAMETOOLONG;
82068
82069@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
82070 if (ret)
82071 return ret;
82072
82073+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82074+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82075+ /* hack to workaround consolekit/udisks stupidity */
82076+ read_lock(&tasklist_lock);
82077+ if (!strcmp(current->comm, "mount") &&
82078+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
82079+ read_unlock(&tasklist_lock);
82080+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
82081+ return -EPERM;
82082+ }
82083+ read_unlock(&tasklist_lock);
82084+ }
82085+#endif
82086+
82087 /* If modprobe needs a service that is in a module, we get a recursive
82088 * loop. Limit the number of running kmod threads to max_threads/2 or
82089 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
82090@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
82091
82092 trace_module_request(module_name, wait, _RET_IP_);
82093
82094- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82095+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82096
82097 atomic_dec(&kmod_concurrent);
82098 return ret;
82099 }
82100+
82101+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
82102+{
82103+ va_list args;
82104+ int ret;
82105+
82106+ va_start(args, fmt);
82107+ ret = ____request_module(wait, module_param, fmt, args);
82108+ va_end(args);
82109+
82110+ return ret;
82111+}
82112+
82113+int __request_module(bool wait, const char *fmt, ...)
82114+{
82115+ va_list args;
82116+ int ret;
82117+
82118+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82119+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82120+ char module_param[MODULE_NAME_LEN];
82121+
82122+ memset(module_param, 0, sizeof(module_param));
82123+
82124+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
82125+
82126+ va_start(args, fmt);
82127+ ret = ____request_module(wait, module_param, fmt, args);
82128+ va_end(args);
82129+
82130+ return ret;
82131+ }
82132+#endif
82133+
82134+ va_start(args, fmt);
82135+ ret = ____request_module(wait, NULL, fmt, args);
82136+ va_end(args);
82137+
82138+ return ret;
82139+}
82140+
82141 EXPORT_SYMBOL(__request_module);
82142 #endif /* CONFIG_MODULES */
82143
82144@@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
82145 */
82146 set_user_nice(current, 0);
82147
82148+#ifdef CONFIG_GRKERNSEC
82149+ /* this is race-free as far as userland is concerned as we copied
82150+ out the path to be used prior to this point and are now operating
82151+ on that copy
82152+ */
82153+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
82154+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
82155+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
82156+ retval = -EPERM;
82157+ goto fail;
82158+ }
82159+#endif
82160+
82161 retval = -ENOMEM;
82162 new = prepare_kernel_cred(current);
82163 if (!new)
82164@@ -260,6 +326,10 @@ static int call_helper(void *data)
82165
82166 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
82167 {
82168+#ifdef CONFIG_GRKERNSEC
82169+ kfree(info->path);
82170+ info->path = info->origpath;
82171+#endif
82172 if (info->cleanup)
82173 (*info->cleanup)(info);
82174 kfree(info);
82175@@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
82176 *
82177 * Thus the __user pointer cast is valid here.
82178 */
82179- sys_wait4(pid, (int __user *)&ret, 0, NULL);
82180+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
82181
82182 /*
82183 * If ret is 0, either ____call_usermodehelper failed and the
82184@@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
82185 goto out;
82186
82187 INIT_WORK(&sub_info->work, __call_usermodehelper);
82188+#ifdef CONFIG_GRKERNSEC
82189+ sub_info->origpath = path;
82190+ sub_info->path = kstrdup(path, gfp_mask);
82191+#else
82192 sub_info->path = path;
82193+#endif
82194 sub_info->argv = argv;
82195 sub_info->envp = envp;
82196
82197@@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
82198 static int proc_cap_handler(struct ctl_table *table, int write,
82199 void __user *buffer, size_t *lenp, loff_t *ppos)
82200 {
82201- struct ctl_table t;
82202+ ctl_table_no_const t;
82203 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
82204 kernel_cap_t new_cap;
82205 int err, i;
82206diff --git a/kernel/kprobes.c b/kernel/kprobes.c
82207index a0d367a..11c18b6 100644
82208--- a/kernel/kprobes.c
82209+++ b/kernel/kprobes.c
82210@@ -31,6 +31,9 @@
82211 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
82212 * <prasanna@in.ibm.com> added function-return probes.
82213 */
82214+#ifdef CONFIG_GRKERNSEC_HIDESYM
82215+#define __INCLUDED_BY_HIDESYM 1
82216+#endif
82217 #include <linux/kprobes.h>
82218 #include <linux/hash.h>
82219 #include <linux/init.h>
82220@@ -135,12 +138,12 @@ enum kprobe_slot_state {
82221
82222 static void *alloc_insn_page(void)
82223 {
82224- return module_alloc(PAGE_SIZE);
82225+ return module_alloc_exec(PAGE_SIZE);
82226 }
82227
82228 static void free_insn_page(void *page)
82229 {
82230- module_free(NULL, page);
82231+ module_free_exec(NULL, page);
82232 }
82233
82234 struct kprobe_insn_cache kprobe_insn_slots = {
82235@@ -2066,7 +2069,7 @@ static int __init init_kprobes(void)
82236 {
82237 int i, err = 0;
82238 unsigned long offset = 0, size = 0;
82239- char *modname, namebuf[128];
82240+ char *modname, namebuf[KSYM_NAME_LEN];
82241 const char *symbol_name;
82242 void *addr;
82243 struct kprobe_blackpoint *kb;
82244@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
82245 kprobe_type = "k";
82246
82247 if (sym)
82248- seq_printf(pi, "%p %s %s+0x%x %s ",
82249+ seq_printf(pi, "%pK %s %s+0x%x %s ",
82250 p->addr, kprobe_type, sym, offset,
82251 (modname ? modname : " "));
82252 else
82253- seq_printf(pi, "%p %s %p ",
82254+ seq_printf(pi, "%pK %s %pK ",
82255 p->addr, kprobe_type, p->addr);
82256
82257 if (!pp)
82258@@ -2192,7 +2195,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
82259 const char *sym = NULL;
82260 unsigned int i = *(loff_t *) v;
82261 unsigned long offset = 0;
82262- char *modname, namebuf[128];
82263+ char *modname, namebuf[KSYM_NAME_LEN];
82264
82265 head = &kprobe_table[i];
82266 preempt_disable();
82267diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
82268index 9659d38..bffd520 100644
82269--- a/kernel/ksysfs.c
82270+++ b/kernel/ksysfs.c
82271@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
82272 {
82273 if (count+1 > UEVENT_HELPER_PATH_LEN)
82274 return -ENOENT;
82275+ if (!capable(CAP_SYS_ADMIN))
82276+ return -EPERM;
82277 memcpy(uevent_helper, buf, count);
82278 uevent_helper[count] = '\0';
82279 if (count && uevent_helper[count-1] == '\n')
82280@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
82281 return count;
82282 }
82283
82284-static struct bin_attribute notes_attr = {
82285+static bin_attribute_no_const notes_attr __read_only = {
82286 .attr = {
82287 .name = "notes",
82288 .mode = S_IRUGO,
82289diff --git a/kernel/lockdep.c b/kernel/lockdep.c
82290index e16c45b..6f49c48 100644
82291--- a/kernel/lockdep.c
82292+++ b/kernel/lockdep.c
82293@@ -596,6 +596,10 @@ static int static_obj(void *obj)
82294 end = (unsigned long) &_end,
82295 addr = (unsigned long) obj;
82296
82297+#ifdef CONFIG_PAX_KERNEXEC
82298+ start = ktla_ktva(start);
82299+#endif
82300+
82301 /*
82302 * static variable?
82303 */
82304@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
82305 if (!static_obj(lock->key)) {
82306 debug_locks_off();
82307 printk("INFO: trying to register non-static key.\n");
82308+ printk("lock:%pS key:%pS.\n", lock, lock->key);
82309 printk("the code is fine but needs lockdep annotation.\n");
82310 printk("turning off the locking correctness validator.\n");
82311 dump_stack();
82312@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
82313 if (!class)
82314 return 0;
82315 }
82316- atomic_inc((atomic_t *)&class->ops);
82317+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
82318 if (very_verbose(class)) {
82319 printk("\nacquire class [%p] %s", class->key, class->name);
82320 if (class->name_version > 1)
82321diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
82322index b2c71c5..7b88d63 100644
82323--- a/kernel/lockdep_proc.c
82324+++ b/kernel/lockdep_proc.c
82325@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
82326 return 0;
82327 }
82328
82329- seq_printf(m, "%p", class->key);
82330+ seq_printf(m, "%pK", class->key);
82331 #ifdef CONFIG_DEBUG_LOCKDEP
82332 seq_printf(m, " OPS:%8ld", class->ops);
82333 #endif
82334@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
82335
82336 list_for_each_entry(entry, &class->locks_after, entry) {
82337 if (entry->distance == 1) {
82338- seq_printf(m, " -> [%p] ", entry->class->key);
82339+ seq_printf(m, " -> [%pK] ", entry->class->key);
82340 print_name(m, entry->class);
82341 seq_puts(m, "\n");
82342 }
82343@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
82344 if (!class->key)
82345 continue;
82346
82347- seq_printf(m, "[%p] ", class->key);
82348+ seq_printf(m, "[%pK] ", class->key);
82349 print_name(m, class);
82350 seq_puts(m, "\n");
82351 }
82352@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82353 if (!i)
82354 seq_line(m, '-', 40-namelen, namelen);
82355
82356- snprintf(ip, sizeof(ip), "[<%p>]",
82357+ snprintf(ip, sizeof(ip), "[<%pK>]",
82358 (void *)class->contention_point[i]);
82359 seq_printf(m, "%40s %14lu %29s %pS\n",
82360 name, stats->contention_point[i],
82361@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82362 if (!i)
82363 seq_line(m, '-', 40-namelen, namelen);
82364
82365- snprintf(ip, sizeof(ip), "[<%p>]",
82366+ snprintf(ip, sizeof(ip), "[<%pK>]",
82367 (void *)class->contending_point[i]);
82368 seq_printf(m, "%40s %14lu %29s %pS\n",
82369 name, stats->contending_point[i],
82370diff --git a/kernel/module.c b/kernel/module.c
82371index dc58274..3ddfa55 100644
82372--- a/kernel/module.c
82373+++ b/kernel/module.c
82374@@ -61,6 +61,7 @@
82375 #include <linux/pfn.h>
82376 #include <linux/bsearch.h>
82377 #include <linux/fips.h>
82378+#include <linux/grsecurity.h>
82379 #include <uapi/linux/module.h>
82380 #include "module-internal.h"
82381
82382@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
82383
82384 /* Bounds of module allocation, for speeding __module_address.
82385 * Protected by module_mutex. */
82386-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
82387+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
82388+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
82389
82390 int register_module_notifier(struct notifier_block * nb)
82391 {
82392@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82393 return true;
82394
82395 list_for_each_entry_rcu(mod, &modules, list) {
82396- struct symsearch arr[] = {
82397+ struct symsearch modarr[] = {
82398 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
82399 NOT_GPL_ONLY, false },
82400 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
82401@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82402 if (mod->state == MODULE_STATE_UNFORMED)
82403 continue;
82404
82405- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
82406+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
82407 return true;
82408 }
82409 return false;
82410@@ -491,7 +493,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
82411 if (!pcpusec->sh_size)
82412 return 0;
82413
82414- if (align > PAGE_SIZE) {
82415+ if (align-1 >= PAGE_SIZE) {
82416 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
82417 mod->name, align, PAGE_SIZE);
82418 align = PAGE_SIZE;
82419@@ -1097,7 +1099,7 @@ struct module_attribute module_uevent =
82420 static ssize_t show_coresize(struct module_attribute *mattr,
82421 struct module_kobject *mk, char *buffer)
82422 {
82423- return sprintf(buffer, "%u\n", mk->mod->core_size);
82424+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
82425 }
82426
82427 static struct module_attribute modinfo_coresize =
82428@@ -1106,7 +1108,7 @@ static struct module_attribute modinfo_coresize =
82429 static ssize_t show_initsize(struct module_attribute *mattr,
82430 struct module_kobject *mk, char *buffer)
82431 {
82432- return sprintf(buffer, "%u\n", mk->mod->init_size);
82433+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
82434 }
82435
82436 static struct module_attribute modinfo_initsize =
82437@@ -1321,7 +1323,7 @@ resolve_symbol_wait(struct module *mod,
82438 */
82439 #ifdef CONFIG_SYSFS
82440
82441-#ifdef CONFIG_KALLSYMS
82442+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82443 static inline bool sect_empty(const Elf_Shdr *sect)
82444 {
82445 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
82446@@ -1461,7 +1463,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
82447 {
82448 unsigned int notes, loaded, i;
82449 struct module_notes_attrs *notes_attrs;
82450- struct bin_attribute *nattr;
82451+ bin_attribute_no_const *nattr;
82452
82453 /* failed to create section attributes, so can't create notes */
82454 if (!mod->sect_attrs)
82455@@ -1573,7 +1575,7 @@ static void del_usage_links(struct module *mod)
82456 static int module_add_modinfo_attrs(struct module *mod)
82457 {
82458 struct module_attribute *attr;
82459- struct module_attribute *temp_attr;
82460+ module_attribute_no_const *temp_attr;
82461 int error = 0;
82462 int i;
82463
82464@@ -1795,21 +1797,21 @@ static void set_section_ro_nx(void *base,
82465
82466 static void unset_module_core_ro_nx(struct module *mod)
82467 {
82468- set_page_attributes(mod->module_core + mod->core_text_size,
82469- mod->module_core + mod->core_size,
82470+ set_page_attributes(mod->module_core_rw,
82471+ mod->module_core_rw + mod->core_size_rw,
82472 set_memory_x);
82473- set_page_attributes(mod->module_core,
82474- mod->module_core + mod->core_ro_size,
82475+ set_page_attributes(mod->module_core_rx,
82476+ mod->module_core_rx + mod->core_size_rx,
82477 set_memory_rw);
82478 }
82479
82480 static void unset_module_init_ro_nx(struct module *mod)
82481 {
82482- set_page_attributes(mod->module_init + mod->init_text_size,
82483- mod->module_init + mod->init_size,
82484+ set_page_attributes(mod->module_init_rw,
82485+ mod->module_init_rw + mod->init_size_rw,
82486 set_memory_x);
82487- set_page_attributes(mod->module_init,
82488- mod->module_init + mod->init_ro_size,
82489+ set_page_attributes(mod->module_init_rx,
82490+ mod->module_init_rx + mod->init_size_rx,
82491 set_memory_rw);
82492 }
82493
82494@@ -1822,14 +1824,14 @@ void set_all_modules_text_rw(void)
82495 list_for_each_entry_rcu(mod, &modules, list) {
82496 if (mod->state == MODULE_STATE_UNFORMED)
82497 continue;
82498- if ((mod->module_core) && (mod->core_text_size)) {
82499- set_page_attributes(mod->module_core,
82500- mod->module_core + mod->core_text_size,
82501+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82502+ set_page_attributes(mod->module_core_rx,
82503+ mod->module_core_rx + mod->core_size_rx,
82504 set_memory_rw);
82505 }
82506- if ((mod->module_init) && (mod->init_text_size)) {
82507- set_page_attributes(mod->module_init,
82508- mod->module_init + mod->init_text_size,
82509+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82510+ set_page_attributes(mod->module_init_rx,
82511+ mod->module_init_rx + mod->init_size_rx,
82512 set_memory_rw);
82513 }
82514 }
82515@@ -1845,14 +1847,14 @@ void set_all_modules_text_ro(void)
82516 list_for_each_entry_rcu(mod, &modules, list) {
82517 if (mod->state == MODULE_STATE_UNFORMED)
82518 continue;
82519- if ((mod->module_core) && (mod->core_text_size)) {
82520- set_page_attributes(mod->module_core,
82521- mod->module_core + mod->core_text_size,
82522+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82523+ set_page_attributes(mod->module_core_rx,
82524+ mod->module_core_rx + mod->core_size_rx,
82525 set_memory_ro);
82526 }
82527- if ((mod->module_init) && (mod->init_text_size)) {
82528- set_page_attributes(mod->module_init,
82529- mod->module_init + mod->init_text_size,
82530+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82531+ set_page_attributes(mod->module_init_rx,
82532+ mod->module_init_rx + mod->init_size_rx,
82533 set_memory_ro);
82534 }
82535 }
82536@@ -1903,16 +1905,19 @@ static void free_module(struct module *mod)
82537
82538 /* This may be NULL, but that's OK */
82539 unset_module_init_ro_nx(mod);
82540- module_free(mod, mod->module_init);
82541+ module_free(mod, mod->module_init_rw);
82542+ module_free_exec(mod, mod->module_init_rx);
82543 kfree(mod->args);
82544 percpu_modfree(mod);
82545
82546 /* Free lock-classes: */
82547- lockdep_free_key_range(mod->module_core, mod->core_size);
82548+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
82549+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
82550
82551 /* Finally, free the core (containing the module structure) */
82552 unset_module_core_ro_nx(mod);
82553- module_free(mod, mod->module_core);
82554+ module_free_exec(mod, mod->module_core_rx);
82555+ module_free(mod, mod->module_core_rw);
82556
82557 #ifdef CONFIG_MPU
82558 update_protections(current->mm);
82559@@ -1982,9 +1987,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82560 int ret = 0;
82561 const struct kernel_symbol *ksym;
82562
82563+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82564+ int is_fs_load = 0;
82565+ int register_filesystem_found = 0;
82566+ char *p;
82567+
82568+ p = strstr(mod->args, "grsec_modharden_fs");
82569+ if (p) {
82570+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
82571+ /* copy \0 as well */
82572+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
82573+ is_fs_load = 1;
82574+ }
82575+#endif
82576+
82577 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
82578 const char *name = info->strtab + sym[i].st_name;
82579
82580+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82581+ /* it's a real shame this will never get ripped and copied
82582+ upstream! ;(
82583+ */
82584+ if (is_fs_load && !strcmp(name, "register_filesystem"))
82585+ register_filesystem_found = 1;
82586+#endif
82587+
82588 switch (sym[i].st_shndx) {
82589 case SHN_COMMON:
82590 /* We compiled with -fno-common. These are not
82591@@ -2005,7 +2032,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82592 ksym = resolve_symbol_wait(mod, info, name);
82593 /* Ok if resolved. */
82594 if (ksym && !IS_ERR(ksym)) {
82595+ pax_open_kernel();
82596 sym[i].st_value = ksym->value;
82597+ pax_close_kernel();
82598 break;
82599 }
82600
82601@@ -2024,11 +2053,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82602 secbase = (unsigned long)mod_percpu(mod);
82603 else
82604 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
82605+ pax_open_kernel();
82606 sym[i].st_value += secbase;
82607+ pax_close_kernel();
82608 break;
82609 }
82610 }
82611
82612+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82613+ if (is_fs_load && !register_filesystem_found) {
82614+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
82615+ ret = -EPERM;
82616+ }
82617+#endif
82618+
82619 return ret;
82620 }
82621
82622@@ -2112,22 +2150,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
82623 || s->sh_entsize != ~0UL
82624 || strstarts(sname, ".init"))
82625 continue;
82626- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
82627+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82628+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
82629+ else
82630+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
82631 pr_debug("\t%s\n", sname);
82632 }
82633- switch (m) {
82634- case 0: /* executable */
82635- mod->core_size = debug_align(mod->core_size);
82636- mod->core_text_size = mod->core_size;
82637- break;
82638- case 1: /* RO: text and ro-data */
82639- mod->core_size = debug_align(mod->core_size);
82640- mod->core_ro_size = mod->core_size;
82641- break;
82642- case 3: /* whole core */
82643- mod->core_size = debug_align(mod->core_size);
82644- break;
82645- }
82646 }
82647
82648 pr_debug("Init section allocation order:\n");
82649@@ -2141,23 +2169,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
82650 || s->sh_entsize != ~0UL
82651 || !strstarts(sname, ".init"))
82652 continue;
82653- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
82654- | INIT_OFFSET_MASK);
82655+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82656+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
82657+ else
82658+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
82659+ s->sh_entsize |= INIT_OFFSET_MASK;
82660 pr_debug("\t%s\n", sname);
82661 }
82662- switch (m) {
82663- case 0: /* executable */
82664- mod->init_size = debug_align(mod->init_size);
82665- mod->init_text_size = mod->init_size;
82666- break;
82667- case 1: /* RO: text and ro-data */
82668- mod->init_size = debug_align(mod->init_size);
82669- mod->init_ro_size = mod->init_size;
82670- break;
82671- case 3: /* whole init */
82672- mod->init_size = debug_align(mod->init_size);
82673- break;
82674- }
82675 }
82676 }
82677
82678@@ -2330,7 +2348,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82679
82680 /* Put symbol section at end of init part of module. */
82681 symsect->sh_flags |= SHF_ALLOC;
82682- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
82683+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
82684 info->index.sym) | INIT_OFFSET_MASK;
82685 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
82686
82687@@ -2347,13 +2365,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82688 }
82689
82690 /* Append room for core symbols at end of core part. */
82691- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
82692- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
82693- mod->core_size += strtab_size;
82694+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
82695+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
82696+ mod->core_size_rx += strtab_size;
82697
82698 /* Put string table section at end of init part of module. */
82699 strsect->sh_flags |= SHF_ALLOC;
82700- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
82701+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
82702 info->index.str) | INIT_OFFSET_MASK;
82703 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
82704 }
82705@@ -2371,12 +2389,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82706 /* Make sure we get permanent strtab: don't use info->strtab. */
82707 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
82708
82709+ pax_open_kernel();
82710+
82711 /* Set types up while we still have access to sections. */
82712 for (i = 0; i < mod->num_symtab; i++)
82713 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
82714
82715- mod->core_symtab = dst = mod->module_core + info->symoffs;
82716- mod->core_strtab = s = mod->module_core + info->stroffs;
82717+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
82718+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
82719 src = mod->symtab;
82720 for (ndst = i = 0; i < mod->num_symtab; i++) {
82721 if (i == 0 ||
82722@@ -2388,6 +2408,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82723 }
82724 }
82725 mod->core_num_syms = ndst;
82726+
82727+ pax_close_kernel();
82728 }
82729 #else
82730 static inline void layout_symtab(struct module *mod, struct load_info *info)
82731@@ -2421,17 +2443,33 @@ void * __weak module_alloc(unsigned long size)
82732 return vmalloc_exec(size);
82733 }
82734
82735-static void *module_alloc_update_bounds(unsigned long size)
82736+static void *module_alloc_update_bounds_rw(unsigned long size)
82737 {
82738 void *ret = module_alloc(size);
82739
82740 if (ret) {
82741 mutex_lock(&module_mutex);
82742 /* Update module bounds. */
82743- if ((unsigned long)ret < module_addr_min)
82744- module_addr_min = (unsigned long)ret;
82745- if ((unsigned long)ret + size > module_addr_max)
82746- module_addr_max = (unsigned long)ret + size;
82747+ if ((unsigned long)ret < module_addr_min_rw)
82748+ module_addr_min_rw = (unsigned long)ret;
82749+ if ((unsigned long)ret + size > module_addr_max_rw)
82750+ module_addr_max_rw = (unsigned long)ret + size;
82751+ mutex_unlock(&module_mutex);
82752+ }
82753+ return ret;
82754+}
82755+
82756+static void *module_alloc_update_bounds_rx(unsigned long size)
82757+{
82758+ void *ret = module_alloc_exec(size);
82759+
82760+ if (ret) {
82761+ mutex_lock(&module_mutex);
82762+ /* Update module bounds. */
82763+ if ((unsigned long)ret < module_addr_min_rx)
82764+ module_addr_min_rx = (unsigned long)ret;
82765+ if ((unsigned long)ret + size > module_addr_max_rx)
82766+ module_addr_max_rx = (unsigned long)ret + size;
82767 mutex_unlock(&module_mutex);
82768 }
82769 return ret;
82770@@ -2706,8 +2744,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
82771 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82772 {
82773 const char *modmagic = get_modinfo(info, "vermagic");
82774+ const char *license = get_modinfo(info, "license");
82775 int err;
82776
82777+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
82778+ if (!license || !license_is_gpl_compatible(license))
82779+ return -ENOEXEC;
82780+#endif
82781+
82782 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
82783 modmagic = NULL;
82784
82785@@ -2733,7 +2777,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82786 }
82787
82788 /* Set up license info based on the info section */
82789- set_license(mod, get_modinfo(info, "license"));
82790+ set_license(mod, license);
82791
82792 return 0;
82793 }
82794@@ -2814,7 +2858,7 @@ static int move_module(struct module *mod, struct load_info *info)
82795 void *ptr;
82796
82797 /* Do the allocs. */
82798- ptr = module_alloc_update_bounds(mod->core_size);
82799+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
82800 /*
82801 * The pointer to this block is stored in the module structure
82802 * which is inside the block. Just mark it as not being a
82803@@ -2824,11 +2868,11 @@ static int move_module(struct module *mod, struct load_info *info)
82804 if (!ptr)
82805 return -ENOMEM;
82806
82807- memset(ptr, 0, mod->core_size);
82808- mod->module_core = ptr;
82809+ memset(ptr, 0, mod->core_size_rw);
82810+ mod->module_core_rw = ptr;
82811
82812- if (mod->init_size) {
82813- ptr = module_alloc_update_bounds(mod->init_size);
82814+ if (mod->init_size_rw) {
82815+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
82816 /*
82817 * The pointer to this block is stored in the module structure
82818 * which is inside the block. This block doesn't need to be
82819@@ -2837,13 +2881,45 @@ static int move_module(struct module *mod, struct load_info *info)
82820 */
82821 kmemleak_ignore(ptr);
82822 if (!ptr) {
82823- module_free(mod, mod->module_core);
82824+ module_free(mod, mod->module_core_rw);
82825 return -ENOMEM;
82826 }
82827- memset(ptr, 0, mod->init_size);
82828- mod->module_init = ptr;
82829+ memset(ptr, 0, mod->init_size_rw);
82830+ mod->module_init_rw = ptr;
82831 } else
82832- mod->module_init = NULL;
82833+ mod->module_init_rw = NULL;
82834+
82835+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
82836+ kmemleak_not_leak(ptr);
82837+ if (!ptr) {
82838+ if (mod->module_init_rw)
82839+ module_free(mod, mod->module_init_rw);
82840+ module_free(mod, mod->module_core_rw);
82841+ return -ENOMEM;
82842+ }
82843+
82844+ pax_open_kernel();
82845+ memset(ptr, 0, mod->core_size_rx);
82846+ pax_close_kernel();
82847+ mod->module_core_rx = ptr;
82848+
82849+ if (mod->init_size_rx) {
82850+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
82851+ kmemleak_ignore(ptr);
82852+ if (!ptr && mod->init_size_rx) {
82853+ module_free_exec(mod, mod->module_core_rx);
82854+ if (mod->module_init_rw)
82855+ module_free(mod, mod->module_init_rw);
82856+ module_free(mod, mod->module_core_rw);
82857+ return -ENOMEM;
82858+ }
82859+
82860+ pax_open_kernel();
82861+ memset(ptr, 0, mod->init_size_rx);
82862+ pax_close_kernel();
82863+ mod->module_init_rx = ptr;
82864+ } else
82865+ mod->module_init_rx = NULL;
82866
82867 /* Transfer each section which specifies SHF_ALLOC */
82868 pr_debug("final section addresses:\n");
82869@@ -2854,16 +2930,45 @@ static int move_module(struct module *mod, struct load_info *info)
82870 if (!(shdr->sh_flags & SHF_ALLOC))
82871 continue;
82872
82873- if (shdr->sh_entsize & INIT_OFFSET_MASK)
82874- dest = mod->module_init
82875- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
82876- else
82877- dest = mod->module_core + shdr->sh_entsize;
82878+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
82879+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
82880+ dest = mod->module_init_rw
82881+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
82882+ else
82883+ dest = mod->module_init_rx
82884+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
82885+ } else {
82886+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
82887+ dest = mod->module_core_rw + shdr->sh_entsize;
82888+ else
82889+ dest = mod->module_core_rx + shdr->sh_entsize;
82890+ }
82891+
82892+ if (shdr->sh_type != SHT_NOBITS) {
82893+
82894+#ifdef CONFIG_PAX_KERNEXEC
82895+#ifdef CONFIG_X86_64
82896+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
82897+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
82898+#endif
82899+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
82900+ pax_open_kernel();
82901+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
82902+ pax_close_kernel();
82903+ } else
82904+#endif
82905
82906- if (shdr->sh_type != SHT_NOBITS)
82907 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
82908+ }
82909 /* Update sh_addr to point to copy in image. */
82910- shdr->sh_addr = (unsigned long)dest;
82911+
82912+#ifdef CONFIG_PAX_KERNEXEC
82913+ if (shdr->sh_flags & SHF_EXECINSTR)
82914+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
82915+ else
82916+#endif
82917+
82918+ shdr->sh_addr = (unsigned long)dest;
82919 pr_debug("\t0x%lx %s\n",
82920 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
82921 }
82922@@ -2920,12 +3025,12 @@ static void flush_module_icache(const struct module *mod)
82923 * Do it before processing of module parameters, so the module
82924 * can provide parameter accessor functions of its own.
82925 */
82926- if (mod->module_init)
82927- flush_icache_range((unsigned long)mod->module_init,
82928- (unsigned long)mod->module_init
82929- + mod->init_size);
82930- flush_icache_range((unsigned long)mod->module_core,
82931- (unsigned long)mod->module_core + mod->core_size);
82932+ if (mod->module_init_rx)
82933+ flush_icache_range((unsigned long)mod->module_init_rx,
82934+ (unsigned long)mod->module_init_rx
82935+ + mod->init_size_rx);
82936+ flush_icache_range((unsigned long)mod->module_core_rx,
82937+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
82938
82939 set_fs(old_fs);
82940 }
82941@@ -2982,8 +3087,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
82942 static void module_deallocate(struct module *mod, struct load_info *info)
82943 {
82944 percpu_modfree(mod);
82945- module_free(mod, mod->module_init);
82946- module_free(mod, mod->module_core);
82947+ module_free_exec(mod, mod->module_init_rx);
82948+ module_free_exec(mod, mod->module_core_rx);
82949+ module_free(mod, mod->module_init_rw);
82950+ module_free(mod, mod->module_core_rw);
82951 }
82952
82953 int __weak module_finalize(const Elf_Ehdr *hdr,
82954@@ -2996,7 +3103,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
82955 static int post_relocation(struct module *mod, const struct load_info *info)
82956 {
82957 /* Sort exception table now relocations are done. */
82958+ pax_open_kernel();
82959 sort_extable(mod->extable, mod->extable + mod->num_exentries);
82960+ pax_close_kernel();
82961
82962 /* Copy relocated percpu area over. */
82963 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
82964@@ -3050,16 +3159,16 @@ static int do_init_module(struct module *mod)
82965 MODULE_STATE_COMING, mod);
82966
82967 /* Set RO and NX regions for core */
82968- set_section_ro_nx(mod->module_core,
82969- mod->core_text_size,
82970- mod->core_ro_size,
82971- mod->core_size);
82972+ set_section_ro_nx(mod->module_core_rx,
82973+ mod->core_size_rx,
82974+ mod->core_size_rx,
82975+ mod->core_size_rx);
82976
82977 /* Set RO and NX regions for init */
82978- set_section_ro_nx(mod->module_init,
82979- mod->init_text_size,
82980- mod->init_ro_size,
82981- mod->init_size);
82982+ set_section_ro_nx(mod->module_init_rx,
82983+ mod->init_size_rx,
82984+ mod->init_size_rx,
82985+ mod->init_size_rx);
82986
82987 do_mod_ctors(mod);
82988 /* Start the module */
82989@@ -3121,11 +3230,12 @@ static int do_init_module(struct module *mod)
82990 mod->strtab = mod->core_strtab;
82991 #endif
82992 unset_module_init_ro_nx(mod);
82993- module_free(mod, mod->module_init);
82994- mod->module_init = NULL;
82995- mod->init_size = 0;
82996- mod->init_ro_size = 0;
82997- mod->init_text_size = 0;
82998+ module_free(mod, mod->module_init_rw);
82999+ module_free_exec(mod, mod->module_init_rx);
83000+ mod->module_init_rw = NULL;
83001+ mod->module_init_rx = NULL;
83002+ mod->init_size_rw = 0;
83003+ mod->init_size_rx = 0;
83004 mutex_unlock(&module_mutex);
83005 wake_up_all(&module_wq);
83006
83007@@ -3269,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
83008 if (err)
83009 goto free_unload;
83010
83011+ /* Now copy in args */
83012+ mod->args = strndup_user(uargs, ~0UL >> 1);
83013+ if (IS_ERR(mod->args)) {
83014+ err = PTR_ERR(mod->args);
83015+ goto free_unload;
83016+ }
83017+
83018 /* Set up MODINFO_ATTR fields */
83019 setup_modinfo(mod, info);
83020
83021+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83022+ {
83023+ char *p, *p2;
83024+
83025+ if (strstr(mod->args, "grsec_modharden_netdev")) {
83026+ 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);
83027+ err = -EPERM;
83028+ goto free_modinfo;
83029+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
83030+ p += sizeof("grsec_modharden_normal") - 1;
83031+ p2 = strstr(p, "_");
83032+ if (p2) {
83033+ *p2 = '\0';
83034+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
83035+ *p2 = '_';
83036+ }
83037+ err = -EPERM;
83038+ goto free_modinfo;
83039+ }
83040+ }
83041+#endif
83042+
83043 /* Fix up syms, so that st_value is a pointer to location. */
83044 err = simplify_symbols(mod, info);
83045 if (err < 0)
83046@@ -3287,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
83047
83048 flush_module_icache(mod);
83049
83050- /* Now copy in args */
83051- mod->args = strndup_user(uargs, ~0UL >> 1);
83052- if (IS_ERR(mod->args)) {
83053- err = PTR_ERR(mod->args);
83054- goto free_arch_cleanup;
83055- }
83056-
83057 dynamic_debug_setup(info->debug, info->num_debug);
83058
83059 /* Finally it's fully formed, ready to start executing. */
83060@@ -3328,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
83061 ddebug_cleanup:
83062 dynamic_debug_remove(info->debug);
83063 synchronize_sched();
83064- kfree(mod->args);
83065- free_arch_cleanup:
83066 module_arch_cleanup(mod);
83067 free_modinfo:
83068 free_modinfo(mod);
83069+ kfree(mod->args);
83070 free_unload:
83071 module_unload_free(mod);
83072 unlink_mod:
83073@@ -3415,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
83074 unsigned long nextval;
83075
83076 /* At worse, next value is at end of module */
83077- if (within_module_init(addr, mod))
83078- nextval = (unsigned long)mod->module_init+mod->init_text_size;
83079+ if (within_module_init_rx(addr, mod))
83080+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
83081+ else if (within_module_init_rw(addr, mod))
83082+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
83083+ else if (within_module_core_rx(addr, mod))
83084+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
83085+ else if (within_module_core_rw(addr, mod))
83086+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
83087 else
83088- nextval = (unsigned long)mod->module_core+mod->core_text_size;
83089+ return NULL;
83090
83091 /* Scan for closest preceding symbol, and next symbol. (ELF
83092 starts real symbols at 1). */
83093@@ -3669,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
83094 return 0;
83095
83096 seq_printf(m, "%s %u",
83097- mod->name, mod->init_size + mod->core_size);
83098+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
83099 print_unload_info(m, mod);
83100
83101 /* Informative for users. */
83102@@ -3678,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
83103 mod->state == MODULE_STATE_COMING ? "Loading":
83104 "Live");
83105 /* Used by oprofile and other similar tools. */
83106- seq_printf(m, " 0x%pK", mod->module_core);
83107+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
83108
83109 /* Taints info */
83110 if (mod->taints)
83111@@ -3714,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
83112
83113 static int __init proc_modules_init(void)
83114 {
83115+#ifndef CONFIG_GRKERNSEC_HIDESYM
83116+#ifdef CONFIG_GRKERNSEC_PROC_USER
83117+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83118+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83119+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
83120+#else
83121 proc_create("modules", 0, NULL, &proc_modules_operations);
83122+#endif
83123+#else
83124+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83125+#endif
83126 return 0;
83127 }
83128 module_init(proc_modules_init);
83129@@ -3775,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
83130 {
83131 struct module *mod;
83132
83133- if (addr < module_addr_min || addr > module_addr_max)
83134+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
83135+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
83136 return NULL;
83137
83138 list_for_each_entry_rcu(mod, &modules, list) {
83139 if (mod->state == MODULE_STATE_UNFORMED)
83140 continue;
83141- if (within_module_core(addr, mod)
83142- || within_module_init(addr, mod))
83143+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
83144 return mod;
83145 }
83146 return NULL;
83147@@ -3817,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
83148 */
83149 struct module *__module_text_address(unsigned long addr)
83150 {
83151- struct module *mod = __module_address(addr);
83152+ struct module *mod;
83153+
83154+#ifdef CONFIG_X86_32
83155+ addr = ktla_ktva(addr);
83156+#endif
83157+
83158+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
83159+ return NULL;
83160+
83161+ mod = __module_address(addr);
83162+
83163 if (mod) {
83164 /* Make sure it's within the text section. */
83165- if (!within(addr, mod->module_init, mod->init_text_size)
83166- && !within(addr, mod->module_core, mod->core_text_size))
83167+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
83168 mod = NULL;
83169 }
83170 return mod;
83171diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
83172index 7e3443f..b2a1e6b 100644
83173--- a/kernel/mutex-debug.c
83174+++ b/kernel/mutex-debug.c
83175@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
83176 }
83177
83178 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83179- struct thread_info *ti)
83180+ struct task_struct *task)
83181 {
83182 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
83183
83184 /* Mark the current thread as blocked on the lock: */
83185- ti->task->blocked_on = waiter;
83186+ task->blocked_on = waiter;
83187 }
83188
83189 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83190- struct thread_info *ti)
83191+ struct task_struct *task)
83192 {
83193 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
83194- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
83195- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
83196- ti->task->blocked_on = NULL;
83197+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
83198+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
83199+ task->blocked_on = NULL;
83200
83201 list_del_init(&waiter->list);
83202 waiter->task = NULL;
83203diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
83204index 0799fd3..d06ae3b 100644
83205--- a/kernel/mutex-debug.h
83206+++ b/kernel/mutex-debug.h
83207@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
83208 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
83209 extern void debug_mutex_add_waiter(struct mutex *lock,
83210 struct mutex_waiter *waiter,
83211- struct thread_info *ti);
83212+ struct task_struct *task);
83213 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83214- struct thread_info *ti);
83215+ struct task_struct *task);
83216 extern void debug_mutex_unlock(struct mutex *lock);
83217 extern void debug_mutex_init(struct mutex *lock, const char *name,
83218 struct lock_class_key *key);
83219diff --git a/kernel/mutex.c b/kernel/mutex.c
83220index d24105b..15648eb 100644
83221--- a/kernel/mutex.c
83222+++ b/kernel/mutex.c
83223@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
83224 node->locked = 1;
83225 return;
83226 }
83227- ACCESS_ONCE(prev->next) = node;
83228+ ACCESS_ONCE_RW(prev->next) = node;
83229 smp_wmb();
83230 /* Wait until the lock holder passes the lock down */
83231 while (!ACCESS_ONCE(node->locked))
83232@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
83233 while (!(next = ACCESS_ONCE(node->next)))
83234 arch_mutex_cpu_relax();
83235 }
83236- ACCESS_ONCE(next->locked) = 1;
83237+ ACCESS_ONCE_RW(next->locked) = 1;
83238 smp_wmb();
83239 }
83240
83241@@ -520,7 +520,7 @@ slowpath:
83242 goto skip_wait;
83243
83244 debug_mutex_lock_common(lock, &waiter);
83245- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
83246+ debug_mutex_add_waiter(lock, &waiter, task);
83247
83248 /* add waiting tasks to the end of the waitqueue (FIFO): */
83249 list_add_tail(&waiter.list, &lock->wait_list);
83250@@ -564,7 +564,7 @@ slowpath:
83251 schedule_preempt_disabled();
83252 spin_lock_mutex(&lock->wait_lock, flags);
83253 }
83254- mutex_remove_waiter(lock, &waiter, current_thread_info());
83255+ mutex_remove_waiter(lock, &waiter, task);
83256 /* set it to 0 if there are no waiters left: */
83257 if (likely(list_empty(&lock->wait_list)))
83258 atomic_set(&lock->count, 0);
83259@@ -601,7 +601,7 @@ skip_wait:
83260 return 0;
83261
83262 err:
83263- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
83264+ mutex_remove_waiter(lock, &waiter, task);
83265 spin_unlock_mutex(&lock->wait_lock, flags);
83266 debug_mutex_free_waiter(&waiter);
83267 mutex_release(&lock->dep_map, 1, ip);
83268diff --git a/kernel/notifier.c b/kernel/notifier.c
83269index 2d5cc4c..d9ea600 100644
83270--- a/kernel/notifier.c
83271+++ b/kernel/notifier.c
83272@@ -5,6 +5,7 @@
83273 #include <linux/rcupdate.h>
83274 #include <linux/vmalloc.h>
83275 #include <linux/reboot.h>
83276+#include <linux/mm.h>
83277
83278 /*
83279 * Notifier list for kernel code which wants to be called
83280@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
83281 while ((*nl) != NULL) {
83282 if (n->priority > (*nl)->priority)
83283 break;
83284- nl = &((*nl)->next);
83285+ nl = (struct notifier_block **)&((*nl)->next);
83286 }
83287- n->next = *nl;
83288+ pax_open_kernel();
83289+ *(const void **)&n->next = *nl;
83290 rcu_assign_pointer(*nl, n);
83291+ pax_close_kernel();
83292 return 0;
83293 }
83294
83295@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
83296 return 0;
83297 if (n->priority > (*nl)->priority)
83298 break;
83299- nl = &((*nl)->next);
83300+ nl = (struct notifier_block **)&((*nl)->next);
83301 }
83302- n->next = *nl;
83303+ pax_open_kernel();
83304+ *(const void **)&n->next = *nl;
83305 rcu_assign_pointer(*nl, n);
83306+ pax_close_kernel();
83307 return 0;
83308 }
83309
83310@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
83311 {
83312 while ((*nl) != NULL) {
83313 if ((*nl) == n) {
83314+ pax_open_kernel();
83315 rcu_assign_pointer(*nl, n->next);
83316+ pax_close_kernel();
83317 return 0;
83318 }
83319- nl = &((*nl)->next);
83320+ nl = (struct notifier_block **)&((*nl)->next);
83321 }
83322 return -ENOENT;
83323 }
83324diff --git a/kernel/panic.c b/kernel/panic.c
83325index b6c482c..5578061 100644
83326--- a/kernel/panic.c
83327+++ b/kernel/panic.c
83328@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
83329 disable_trace_on_warning();
83330
83331 pr_warn("------------[ cut here ]------------\n");
83332- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
83333+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
83334 raw_smp_processor_id(), current->pid, file, line, caller);
83335
83336 if (args)
83337@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
83338 */
83339 void __stack_chk_fail(void)
83340 {
83341- panic("stack-protector: Kernel stack is corrupted in: %p\n",
83342+ dump_stack();
83343+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
83344 __builtin_return_address(0));
83345 }
83346 EXPORT_SYMBOL(__stack_chk_fail);
83347diff --git a/kernel/pid.c b/kernel/pid.c
83348index 9b9a266..c20ef80 100644
83349--- a/kernel/pid.c
83350+++ b/kernel/pid.c
83351@@ -33,6 +33,7 @@
83352 #include <linux/rculist.h>
83353 #include <linux/bootmem.h>
83354 #include <linux/hash.h>
83355+#include <linux/security.h>
83356 #include <linux/pid_namespace.h>
83357 #include <linux/init_task.h>
83358 #include <linux/syscalls.h>
83359@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
83360
83361 int pid_max = PID_MAX_DEFAULT;
83362
83363-#define RESERVED_PIDS 300
83364+#define RESERVED_PIDS 500
83365
83366 int pid_max_min = RESERVED_PIDS + 1;
83367 int pid_max_max = PID_MAX_LIMIT;
83368@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
83369 */
83370 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
83371 {
83372+ struct task_struct *task;
83373+
83374 rcu_lockdep_assert(rcu_read_lock_held(),
83375 "find_task_by_pid_ns() needs rcu_read_lock()"
83376 " protection");
83377- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83378+
83379+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83380+
83381+ if (gr_pid_is_chrooted(task))
83382+ return NULL;
83383+
83384+ return task;
83385 }
83386
83387 struct task_struct *find_task_by_vpid(pid_t vnr)
83388@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
83389 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
83390 }
83391
83392+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
83393+{
83394+ rcu_lockdep_assert(rcu_read_lock_held(),
83395+ "find_task_by_pid_ns() needs rcu_read_lock()"
83396+ " protection");
83397+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
83398+}
83399+
83400 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
83401 {
83402 struct pid *pid;
83403diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
83404index 4208655..19f36a5 100644
83405--- a/kernel/pid_namespace.c
83406+++ b/kernel/pid_namespace.c
83407@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
83408 void __user *buffer, size_t *lenp, loff_t *ppos)
83409 {
83410 struct pid_namespace *pid_ns = task_active_pid_ns(current);
83411- struct ctl_table tmp = *table;
83412+ ctl_table_no_const tmp = *table;
83413
83414 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
83415 return -EPERM;
83416diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
83417index c7f31aa..2b44977 100644
83418--- a/kernel/posix-cpu-timers.c
83419+++ b/kernel/posix-cpu-timers.c
83420@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
83421
83422 static __init int init_posix_cpu_timers(void)
83423 {
83424- struct k_clock process = {
83425+ static struct k_clock process = {
83426 .clock_getres = process_cpu_clock_getres,
83427 .clock_get = process_cpu_clock_get,
83428 .timer_create = process_cpu_timer_create,
83429 .nsleep = process_cpu_nsleep,
83430 .nsleep_restart = process_cpu_nsleep_restart,
83431 };
83432- struct k_clock thread = {
83433+ static struct k_clock thread = {
83434 .clock_getres = thread_cpu_clock_getres,
83435 .clock_get = thread_cpu_clock_get,
83436 .timer_create = thread_cpu_timer_create,
83437diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
83438index 424c2d4..679242f 100644
83439--- a/kernel/posix-timers.c
83440+++ b/kernel/posix-timers.c
83441@@ -43,6 +43,7 @@
83442 #include <linux/hash.h>
83443 #include <linux/posix-clock.h>
83444 #include <linux/posix-timers.h>
83445+#include <linux/grsecurity.h>
83446 #include <linux/syscalls.h>
83447 #include <linux/wait.h>
83448 #include <linux/workqueue.h>
83449@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
83450 * which we beg off on and pass to do_sys_settimeofday().
83451 */
83452
83453-static struct k_clock posix_clocks[MAX_CLOCKS];
83454+static struct k_clock *posix_clocks[MAX_CLOCKS];
83455
83456 /*
83457 * These ones are defined below.
83458@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
83459 */
83460 static __init int init_posix_timers(void)
83461 {
83462- struct k_clock clock_realtime = {
83463+ static struct k_clock clock_realtime = {
83464 .clock_getres = hrtimer_get_res,
83465 .clock_get = posix_clock_realtime_get,
83466 .clock_set = posix_clock_realtime_set,
83467@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
83468 .timer_get = common_timer_get,
83469 .timer_del = common_timer_del,
83470 };
83471- struct k_clock clock_monotonic = {
83472+ static struct k_clock clock_monotonic = {
83473 .clock_getres = hrtimer_get_res,
83474 .clock_get = posix_ktime_get_ts,
83475 .nsleep = common_nsleep,
83476@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
83477 .timer_get = common_timer_get,
83478 .timer_del = common_timer_del,
83479 };
83480- struct k_clock clock_monotonic_raw = {
83481+ static struct k_clock clock_monotonic_raw = {
83482 .clock_getres = hrtimer_get_res,
83483 .clock_get = posix_get_monotonic_raw,
83484 };
83485- struct k_clock clock_realtime_coarse = {
83486+ static struct k_clock clock_realtime_coarse = {
83487 .clock_getres = posix_get_coarse_res,
83488 .clock_get = posix_get_realtime_coarse,
83489 };
83490- struct k_clock clock_monotonic_coarse = {
83491+ static struct k_clock clock_monotonic_coarse = {
83492 .clock_getres = posix_get_coarse_res,
83493 .clock_get = posix_get_monotonic_coarse,
83494 };
83495- struct k_clock clock_tai = {
83496+ static struct k_clock clock_tai = {
83497 .clock_getres = hrtimer_get_res,
83498 .clock_get = posix_get_tai,
83499 .nsleep = common_nsleep,
83500@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
83501 .timer_get = common_timer_get,
83502 .timer_del = common_timer_del,
83503 };
83504- struct k_clock clock_boottime = {
83505+ static struct k_clock clock_boottime = {
83506 .clock_getres = hrtimer_get_res,
83507 .clock_get = posix_get_boottime,
83508 .nsleep = common_nsleep,
83509@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
83510 return;
83511 }
83512
83513- posix_clocks[clock_id] = *new_clock;
83514+ posix_clocks[clock_id] = new_clock;
83515 }
83516 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
83517
83518@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
83519 return (id & CLOCKFD_MASK) == CLOCKFD ?
83520 &clock_posix_dynamic : &clock_posix_cpu;
83521
83522- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
83523+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
83524 return NULL;
83525- return &posix_clocks[id];
83526+ return posix_clocks[id];
83527 }
83528
83529 static int common_timer_create(struct k_itimer *new_timer)
83530@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
83531 struct k_clock *kc = clockid_to_kclock(which_clock);
83532 struct k_itimer *new_timer;
83533 int error, new_timer_id;
83534- sigevent_t event;
83535+ sigevent_t event = { };
83536 int it_id_set = IT_ID_NOT_SET;
83537
83538 if (!kc)
83539@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
83540 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
83541 return -EFAULT;
83542
83543+ /* only the CLOCK_REALTIME clock can be set, all other clocks
83544+ have their clock_set fptr set to a nosettime dummy function
83545+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
83546+ call common_clock_set, which calls do_sys_settimeofday, which
83547+ we hook
83548+ */
83549+
83550 return kc->clock_set(which_clock, &new_tp);
83551 }
83552
83553diff --git a/kernel/power/process.c b/kernel/power/process.c
83554index 06ec886..9dba35e 100644
83555--- a/kernel/power/process.c
83556+++ b/kernel/power/process.c
83557@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
83558 unsigned int elapsed_msecs;
83559 bool wakeup = false;
83560 int sleep_usecs = USEC_PER_MSEC;
83561+ bool timedout = false;
83562
83563 do_gettimeofday(&start);
83564
83565@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
83566
83567 while (true) {
83568 todo = 0;
83569+ if (time_after(jiffies, end_time))
83570+ timedout = true;
83571 read_lock(&tasklist_lock);
83572 do_each_thread(g, p) {
83573 if (p == current || !freeze_task(p))
83574 continue;
83575
83576- if (!freezer_should_skip(p))
83577+ if (!freezer_should_skip(p)) {
83578 todo++;
83579+ if (timedout) {
83580+ printk(KERN_ERR "Task refusing to freeze:\n");
83581+ sched_show_task(p);
83582+ }
83583+ }
83584 } while_each_thread(g, p);
83585 read_unlock(&tasklist_lock);
83586
83587@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
83588 todo += wq_busy;
83589 }
83590
83591- if (!todo || time_after(jiffies, end_time))
83592+ if (!todo || timedout)
83593 break;
83594
83595 if (pm_wakeup_pending()) {
83596diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
83597index b4e8500..b457a6c 100644
83598--- a/kernel/printk/printk.c
83599+++ b/kernel/printk/printk.c
83600@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
83601 if (from_file && type != SYSLOG_ACTION_OPEN)
83602 return 0;
83603
83604+#ifdef CONFIG_GRKERNSEC_DMESG
83605+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
83606+ return -EPERM;
83607+#endif
83608+
83609 if (syslog_action_restricted(type)) {
83610 if (capable(CAP_SYSLOG))
83611 return 0;
83612diff --git a/kernel/profile.c b/kernel/profile.c
83613index 6631e1e..310c266 100644
83614--- a/kernel/profile.c
83615+++ b/kernel/profile.c
83616@@ -37,7 +37,7 @@ struct profile_hit {
83617 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
83618 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
83619
83620-static atomic_t *prof_buffer;
83621+static atomic_unchecked_t *prof_buffer;
83622 static unsigned long prof_len, prof_shift;
83623
83624 int prof_on __read_mostly;
83625@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
83626 hits[i].pc = 0;
83627 continue;
83628 }
83629- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83630+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83631 hits[i].hits = hits[i].pc = 0;
83632 }
83633 }
83634@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83635 * Add the current hit(s) and flush the write-queue out
83636 * to the global buffer:
83637 */
83638- atomic_add(nr_hits, &prof_buffer[pc]);
83639+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
83640 for (i = 0; i < NR_PROFILE_HIT; ++i) {
83641- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83642+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83643 hits[i].pc = hits[i].hits = 0;
83644 }
83645 out:
83646@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83647 {
83648 unsigned long pc;
83649 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
83650- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83651+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83652 }
83653 #endif /* !CONFIG_SMP */
83654
83655@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
83656 return -EFAULT;
83657 buf++; p++; count--; read++;
83658 }
83659- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
83660+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
83661 if (copy_to_user(buf, (void *)pnt, count))
83662 return -EFAULT;
83663 read += count;
83664@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
83665 }
83666 #endif
83667 profile_discard_flip_buffers();
83668- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
83669+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
83670 return count;
83671 }
83672
83673diff --git a/kernel/ptrace.c b/kernel/ptrace.c
83674index 1f4bcb3..99cf7ab 100644
83675--- a/kernel/ptrace.c
83676+++ b/kernel/ptrace.c
83677@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
83678 if (seize)
83679 flags |= PT_SEIZED;
83680 rcu_read_lock();
83681- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83682+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83683 flags |= PT_PTRACE_CAP;
83684 rcu_read_unlock();
83685 task->ptrace = flags;
83686@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
83687 break;
83688 return -EIO;
83689 }
83690- if (copy_to_user(dst, buf, retval))
83691+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
83692 return -EFAULT;
83693 copied += retval;
83694 src += retval;
83695@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
83696 bool seized = child->ptrace & PT_SEIZED;
83697 int ret = -EIO;
83698 siginfo_t siginfo, *si;
83699- void __user *datavp = (void __user *) data;
83700+ void __user *datavp = (__force void __user *) data;
83701 unsigned long __user *datalp = datavp;
83702 unsigned long flags;
83703
83704@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
83705 goto out;
83706 }
83707
83708+ if (gr_handle_ptrace(child, request)) {
83709+ ret = -EPERM;
83710+ goto out_put_task_struct;
83711+ }
83712+
83713 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83714 ret = ptrace_attach(child, request, addr, data);
83715 /*
83716 * Some architectures need to do book-keeping after
83717 * a ptrace attach.
83718 */
83719- if (!ret)
83720+ if (!ret) {
83721 arch_ptrace_attach(child);
83722+ gr_audit_ptrace(child);
83723+ }
83724 goto out_put_task_struct;
83725 }
83726
83727@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
83728 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
83729 if (copied != sizeof(tmp))
83730 return -EIO;
83731- return put_user(tmp, (unsigned long __user *)data);
83732+ return put_user(tmp, (__force unsigned long __user *)data);
83733 }
83734
83735 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
83736@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
83737 }
83738
83739 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83740- compat_long_t addr, compat_long_t data)
83741+ compat_ulong_t addr, compat_ulong_t data)
83742 {
83743 struct task_struct *child;
83744 long ret;
83745@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83746 goto out;
83747 }
83748
83749+ if (gr_handle_ptrace(child, request)) {
83750+ ret = -EPERM;
83751+ goto out_put_task_struct;
83752+ }
83753+
83754 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83755 ret = ptrace_attach(child, request, addr, data);
83756 /*
83757 * Some architectures need to do book-keeping after
83758 * a ptrace attach.
83759 */
83760- if (!ret)
83761+ if (!ret) {
83762 arch_ptrace_attach(child);
83763+ gr_audit_ptrace(child);
83764+ }
83765 goto out_put_task_struct;
83766 }
83767
83768diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
83769index b02a339..ce2d20c 100644
83770--- a/kernel/rcupdate.c
83771+++ b/kernel/rcupdate.c
83772@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
83773 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
83774 */
83775 if (till_stall_check < 3) {
83776- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
83777+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
83778 till_stall_check = 3;
83779 } else if (till_stall_check > 300) {
83780- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
83781+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
83782 till_stall_check = 300;
83783 }
83784 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
83785diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
83786index 9ed6075..c9e8a63 100644
83787--- a/kernel/rcutiny.c
83788+++ b/kernel/rcutiny.c
83789@@ -45,7 +45,7 @@
83790 /* Forward declarations for rcutiny_plugin.h. */
83791 struct rcu_ctrlblk;
83792 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
83793-static void rcu_process_callbacks(struct softirq_action *unused);
83794+static void rcu_process_callbacks(void);
83795 static void __call_rcu(struct rcu_head *head,
83796 void (*func)(struct rcu_head *rcu),
83797 struct rcu_ctrlblk *rcp);
83798@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
83799 false));
83800 }
83801
83802-static void rcu_process_callbacks(struct softirq_action *unused)
83803+static __latent_entropy void rcu_process_callbacks(void)
83804 {
83805 __rcu_process_callbacks(&rcu_sched_ctrlblk);
83806 __rcu_process_callbacks(&rcu_bh_ctrlblk);
83807diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
83808index be63101..05cf721 100644
83809--- a/kernel/rcutorture.c
83810+++ b/kernel/rcutorture.c
83811@@ -170,12 +170,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
83812 { 0 };
83813 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
83814 { 0 };
83815-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
83816-static atomic_t n_rcu_torture_alloc;
83817-static atomic_t n_rcu_torture_alloc_fail;
83818-static atomic_t n_rcu_torture_free;
83819-static atomic_t n_rcu_torture_mberror;
83820-static atomic_t n_rcu_torture_error;
83821+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
83822+static atomic_unchecked_t n_rcu_torture_alloc;
83823+static atomic_unchecked_t n_rcu_torture_alloc_fail;
83824+static atomic_unchecked_t n_rcu_torture_free;
83825+static atomic_unchecked_t n_rcu_torture_mberror;
83826+static atomic_unchecked_t n_rcu_torture_error;
83827 static long n_rcu_torture_barrier_error;
83828 static long n_rcu_torture_boost_ktrerror;
83829 static long n_rcu_torture_boost_rterror;
83830@@ -293,11 +293,11 @@ rcu_torture_alloc(void)
83831
83832 spin_lock_bh(&rcu_torture_lock);
83833 if (list_empty(&rcu_torture_freelist)) {
83834- atomic_inc(&n_rcu_torture_alloc_fail);
83835+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
83836 spin_unlock_bh(&rcu_torture_lock);
83837 return NULL;
83838 }
83839- atomic_inc(&n_rcu_torture_alloc);
83840+ atomic_inc_unchecked(&n_rcu_torture_alloc);
83841 p = rcu_torture_freelist.next;
83842 list_del_init(p);
83843 spin_unlock_bh(&rcu_torture_lock);
83844@@ -310,7 +310,7 @@ rcu_torture_alloc(void)
83845 static void
83846 rcu_torture_free(struct rcu_torture *p)
83847 {
83848- atomic_inc(&n_rcu_torture_free);
83849+ atomic_inc_unchecked(&n_rcu_torture_free);
83850 spin_lock_bh(&rcu_torture_lock);
83851 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
83852 spin_unlock_bh(&rcu_torture_lock);
83853@@ -431,7 +431,7 @@ rcu_torture_cb(struct rcu_head *p)
83854 i = rp->rtort_pipe_count;
83855 if (i > RCU_TORTURE_PIPE_LEN)
83856 i = RCU_TORTURE_PIPE_LEN;
83857- atomic_inc(&rcu_torture_wcount[i]);
83858+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
83859 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
83860 rp->rtort_mbtest = 0;
83861 rcu_torture_free(rp);
83862@@ -821,7 +821,7 @@ rcu_torture_writer(void *arg)
83863 i = old_rp->rtort_pipe_count;
83864 if (i > RCU_TORTURE_PIPE_LEN)
83865 i = RCU_TORTURE_PIPE_LEN;
83866- atomic_inc(&rcu_torture_wcount[i]);
83867+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
83868 old_rp->rtort_pipe_count++;
83869 if (gp_normal == gp_exp)
83870 exp = !!(rcu_random(&rand) & 0x80);
83871@@ -839,7 +839,7 @@ rcu_torture_writer(void *arg)
83872 i = rp->rtort_pipe_count;
83873 if (i > RCU_TORTURE_PIPE_LEN)
83874 i = RCU_TORTURE_PIPE_LEN;
83875- atomic_inc(&rcu_torture_wcount[i]);
83876+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
83877 if (++rp->rtort_pipe_count >=
83878 RCU_TORTURE_PIPE_LEN) {
83879 rp->rtort_mbtest = 0;
83880@@ -938,7 +938,7 @@ static void rcu_torture_timer(unsigned long unused)
83881 return;
83882 }
83883 if (p->rtort_mbtest == 0)
83884- atomic_inc(&n_rcu_torture_mberror);
83885+ atomic_inc_unchecked(&n_rcu_torture_mberror);
83886 spin_lock(&rand_lock);
83887 cur_ops->read_delay(&rand);
83888 n_rcu_torture_timers++;
83889@@ -1008,7 +1008,7 @@ rcu_torture_reader(void *arg)
83890 continue;
83891 }
83892 if (p->rtort_mbtest == 0)
83893- atomic_inc(&n_rcu_torture_mberror);
83894+ atomic_inc_unchecked(&n_rcu_torture_mberror);
83895 cur_ops->read_delay(&rand);
83896 preempt_disable();
83897 pipe_count = p->rtort_pipe_count;
83898@@ -1071,11 +1071,11 @@ rcu_torture_printk(char *page)
83899 rcu_torture_current,
83900 rcu_torture_current_version,
83901 list_empty(&rcu_torture_freelist),
83902- atomic_read(&n_rcu_torture_alloc),
83903- atomic_read(&n_rcu_torture_alloc_fail),
83904- atomic_read(&n_rcu_torture_free));
83905+ atomic_read_unchecked(&n_rcu_torture_alloc),
83906+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
83907+ atomic_read_unchecked(&n_rcu_torture_free));
83908 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
83909- atomic_read(&n_rcu_torture_mberror),
83910+ atomic_read_unchecked(&n_rcu_torture_mberror),
83911 n_rcu_torture_boost_ktrerror,
83912 n_rcu_torture_boost_rterror);
83913 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
83914@@ -1094,14 +1094,14 @@ rcu_torture_printk(char *page)
83915 n_barrier_attempts,
83916 n_rcu_torture_barrier_error);
83917 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
83918- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
83919+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
83920 n_rcu_torture_barrier_error != 0 ||
83921 n_rcu_torture_boost_ktrerror != 0 ||
83922 n_rcu_torture_boost_rterror != 0 ||
83923 n_rcu_torture_boost_failure != 0 ||
83924 i > 1) {
83925 cnt += sprintf(&page[cnt], "!!! ");
83926- atomic_inc(&n_rcu_torture_error);
83927+ atomic_inc_unchecked(&n_rcu_torture_error);
83928 WARN_ON_ONCE(1);
83929 }
83930 cnt += sprintf(&page[cnt], "Reader Pipe: ");
83931@@ -1115,7 +1115,7 @@ rcu_torture_printk(char *page)
83932 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
83933 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
83934 cnt += sprintf(&page[cnt], " %d",
83935- atomic_read(&rcu_torture_wcount[i]));
83936+ atomic_read_unchecked(&rcu_torture_wcount[i]));
83937 }
83938 cnt += sprintf(&page[cnt], "\n");
83939 if (cur_ops->stats)
83940@@ -1830,7 +1830,7 @@ rcu_torture_cleanup(void)
83941
83942 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
83943
83944- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
83945+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
83946 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
83947 else if (n_online_successes != n_online_attempts ||
83948 n_offline_successes != n_offline_attempts)
83949@@ -1952,18 +1952,18 @@ rcu_torture_init(void)
83950
83951 rcu_torture_current = NULL;
83952 rcu_torture_current_version = 0;
83953- atomic_set(&n_rcu_torture_alloc, 0);
83954- atomic_set(&n_rcu_torture_alloc_fail, 0);
83955- atomic_set(&n_rcu_torture_free, 0);
83956- atomic_set(&n_rcu_torture_mberror, 0);
83957- atomic_set(&n_rcu_torture_error, 0);
83958+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
83959+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
83960+ atomic_set_unchecked(&n_rcu_torture_free, 0);
83961+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
83962+ atomic_set_unchecked(&n_rcu_torture_error, 0);
83963 n_rcu_torture_barrier_error = 0;
83964 n_rcu_torture_boost_ktrerror = 0;
83965 n_rcu_torture_boost_rterror = 0;
83966 n_rcu_torture_boost_failure = 0;
83967 n_rcu_torture_boosts = 0;
83968 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
83969- atomic_set(&rcu_torture_wcount[i], 0);
83970+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
83971 for_each_possible_cpu(cpu) {
83972 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
83973 per_cpu(rcu_torture_count, cpu)[i] = 0;
83974diff --git a/kernel/rcutree.c b/kernel/rcutree.c
83975index 32618b3..c1fb822 100644
83976--- a/kernel/rcutree.c
83977+++ b/kernel/rcutree.c
83978@@ -382,9 +382,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
83979 rcu_prepare_for_idle(smp_processor_id());
83980 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
83981 smp_mb__before_atomic_inc(); /* See above. */
83982- atomic_inc(&rdtp->dynticks);
83983+ atomic_inc_unchecked(&rdtp->dynticks);
83984 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
83985- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
83986+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
83987
83988 /*
83989 * It is illegal to enter an extended quiescent state while
83990@@ -501,10 +501,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
83991 int user)
83992 {
83993 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
83994- atomic_inc(&rdtp->dynticks);
83995+ atomic_inc_unchecked(&rdtp->dynticks);
83996 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83997 smp_mb__after_atomic_inc(); /* See above. */
83998- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83999+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84000 rcu_cleanup_after_idle(smp_processor_id());
84001 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
84002 if (!user && !is_idle_task(current)) {
84003@@ -623,14 +623,14 @@ void rcu_nmi_enter(void)
84004 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
84005
84006 if (rdtp->dynticks_nmi_nesting == 0 &&
84007- (atomic_read(&rdtp->dynticks) & 0x1))
84008+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
84009 return;
84010 rdtp->dynticks_nmi_nesting++;
84011 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
84012- atomic_inc(&rdtp->dynticks);
84013+ atomic_inc_unchecked(&rdtp->dynticks);
84014 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84015 smp_mb__after_atomic_inc(); /* See above. */
84016- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84017+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84018 }
84019
84020 /**
84021@@ -649,9 +649,9 @@ void rcu_nmi_exit(void)
84022 return;
84023 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84024 smp_mb__before_atomic_inc(); /* See above. */
84025- atomic_inc(&rdtp->dynticks);
84026+ atomic_inc_unchecked(&rdtp->dynticks);
84027 smp_mb__after_atomic_inc(); /* Force delay to next write. */
84028- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84029+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84030 }
84031
84032 /**
84033@@ -665,7 +665,7 @@ int rcu_is_cpu_idle(void)
84034 int ret;
84035
84036 preempt_disable();
84037- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84038+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84039 preempt_enable();
84040 return ret;
84041 }
84042@@ -734,7 +734,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
84043 static int dyntick_save_progress_counter(struct rcu_data *rdp,
84044 bool *isidle, unsigned long *maxj)
84045 {
84046- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
84047+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84048 rcu_sysidle_check_cpu(rdp, isidle, maxj);
84049 return (rdp->dynticks_snap & 0x1) == 0;
84050 }
84051@@ -751,7 +751,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
84052 unsigned int curr;
84053 unsigned int snap;
84054
84055- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
84056+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84057 snap = (unsigned int)rdp->dynticks_snap;
84058
84059 /*
84060@@ -1341,9 +1341,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
84061 rdp = this_cpu_ptr(rsp->rda);
84062 rcu_preempt_check_blocked_tasks(rnp);
84063 rnp->qsmask = rnp->qsmaskinit;
84064- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
84065+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
84066 WARN_ON_ONCE(rnp->completed != rsp->completed);
84067- ACCESS_ONCE(rnp->completed) = rsp->completed;
84068+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
84069 if (rnp == rdp->mynode)
84070 __note_gp_changes(rsp, rnp, rdp);
84071 rcu_preempt_boost_start_gp(rnp);
84072@@ -1434,7 +1434,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
84073 */
84074 rcu_for_each_node_breadth_first(rsp, rnp) {
84075 raw_spin_lock_irq(&rnp->lock);
84076- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
84077+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
84078 rdp = this_cpu_ptr(rsp->rda);
84079 if (rnp == rdp->mynode)
84080 __note_gp_changes(rsp, rnp, rdp);
84081@@ -1766,7 +1766,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
84082 rsp->qlen += rdp->qlen;
84083 rdp->n_cbs_orphaned += rdp->qlen;
84084 rdp->qlen_lazy = 0;
84085- ACCESS_ONCE(rdp->qlen) = 0;
84086+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84087 }
84088
84089 /*
84090@@ -2012,7 +2012,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
84091 }
84092 smp_mb(); /* List handling before counting for rcu_barrier(). */
84093 rdp->qlen_lazy -= count_lazy;
84094- ACCESS_ONCE(rdp->qlen) -= count;
84095+ ACCESS_ONCE_RW(rdp->qlen) -= count;
84096 rdp->n_cbs_invoked += count;
84097
84098 /* Reinstate batch limit if we have worked down the excess. */
84099@@ -2209,7 +2209,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
84100 /*
84101 * Do RCU core processing for the current CPU.
84102 */
84103-static void rcu_process_callbacks(struct softirq_action *unused)
84104+static __latent_entropy void rcu_process_callbacks(void)
84105 {
84106 struct rcu_state *rsp;
84107
84108@@ -2316,7 +2316,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84109 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
84110 if (debug_rcu_head_queue(head)) {
84111 /* Probable double call_rcu(), so leak the callback. */
84112- ACCESS_ONCE(head->func) = rcu_leak_callback;
84113+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
84114 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
84115 return;
84116 }
84117@@ -2344,7 +2344,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84118 local_irq_restore(flags);
84119 return;
84120 }
84121- ACCESS_ONCE(rdp->qlen)++;
84122+ ACCESS_ONCE_RW(rdp->qlen)++;
84123 if (lazy)
84124 rdp->qlen_lazy++;
84125 else
84126@@ -2553,11 +2553,11 @@ void synchronize_sched_expedited(void)
84127 * counter wrap on a 32-bit system. Quite a few more CPUs would of
84128 * course be required on a 64-bit system.
84129 */
84130- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
84131+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
84132 (ulong)atomic_long_read(&rsp->expedited_done) +
84133 ULONG_MAX / 8)) {
84134 synchronize_sched();
84135- atomic_long_inc(&rsp->expedited_wrap);
84136+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
84137 return;
84138 }
84139
84140@@ -2565,7 +2565,7 @@ void synchronize_sched_expedited(void)
84141 * Take a ticket. Note that atomic_inc_return() implies a
84142 * full memory barrier.
84143 */
84144- snap = atomic_long_inc_return(&rsp->expedited_start);
84145+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
84146 firstsnap = snap;
84147 get_online_cpus();
84148 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
84149@@ -2578,14 +2578,14 @@ void synchronize_sched_expedited(void)
84150 synchronize_sched_expedited_cpu_stop,
84151 NULL) == -EAGAIN) {
84152 put_online_cpus();
84153- atomic_long_inc(&rsp->expedited_tryfail);
84154+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
84155
84156 /* Check to see if someone else did our work for us. */
84157 s = atomic_long_read(&rsp->expedited_done);
84158 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84159 /* ensure test happens before caller kfree */
84160 smp_mb__before_atomic_inc(); /* ^^^ */
84161- atomic_long_inc(&rsp->expedited_workdone1);
84162+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
84163 return;
84164 }
84165
84166@@ -2594,7 +2594,7 @@ void synchronize_sched_expedited(void)
84167 udelay(trycount * num_online_cpus());
84168 } else {
84169 wait_rcu_gp(call_rcu_sched);
84170- atomic_long_inc(&rsp->expedited_normal);
84171+ atomic_long_inc_unchecked(&rsp->expedited_normal);
84172 return;
84173 }
84174
84175@@ -2603,7 +2603,7 @@ void synchronize_sched_expedited(void)
84176 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84177 /* ensure test happens before caller kfree */
84178 smp_mb__before_atomic_inc(); /* ^^^ */
84179- atomic_long_inc(&rsp->expedited_workdone2);
84180+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
84181 return;
84182 }
84183
84184@@ -2615,10 +2615,10 @@ void synchronize_sched_expedited(void)
84185 * period works for us.
84186 */
84187 get_online_cpus();
84188- snap = atomic_long_read(&rsp->expedited_start);
84189+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
84190 smp_mb(); /* ensure read is before try_stop_cpus(). */
84191 }
84192- atomic_long_inc(&rsp->expedited_stoppedcpus);
84193+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
84194
84195 /*
84196 * Everyone up to our most recent fetch is covered by our grace
84197@@ -2627,16 +2627,16 @@ void synchronize_sched_expedited(void)
84198 * than we did already did their update.
84199 */
84200 do {
84201- atomic_long_inc(&rsp->expedited_done_tries);
84202+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
84203 s = atomic_long_read(&rsp->expedited_done);
84204 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
84205 /* ensure test happens before caller kfree */
84206 smp_mb__before_atomic_inc(); /* ^^^ */
84207- atomic_long_inc(&rsp->expedited_done_lost);
84208+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
84209 break;
84210 }
84211 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
84212- atomic_long_inc(&rsp->expedited_done_exit);
84213+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
84214
84215 put_online_cpus();
84216 }
84217@@ -2829,7 +2829,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84218 * ACCESS_ONCE() to prevent the compiler from speculating
84219 * the increment to precede the early-exit check.
84220 */
84221- ACCESS_ONCE(rsp->n_barrier_done)++;
84222+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84223 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
84224 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
84225 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
84226@@ -2879,7 +2879,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84227
84228 /* Increment ->n_barrier_done to prevent duplicate work. */
84229 smp_mb(); /* Keep increment after above mechanism. */
84230- ACCESS_ONCE(rsp->n_barrier_done)++;
84231+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84232 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
84233 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
84234 smp_mb(); /* Keep increment before caller's subsequent code. */
84235@@ -2924,10 +2924,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
84236 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
84237 init_callback_list(rdp);
84238 rdp->qlen_lazy = 0;
84239- ACCESS_ONCE(rdp->qlen) = 0;
84240+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84241 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
84242 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
84243- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
84244+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
84245 rdp->cpu = cpu;
84246 rdp->rsp = rsp;
84247 rcu_boot_init_nocb_percpu_data(rdp);
84248@@ -2961,8 +2961,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
84249 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
84250 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
84251 rcu_sysidle_init_percpu_data(rdp->dynticks);
84252- atomic_set(&rdp->dynticks->dynticks,
84253- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
84254+ atomic_set_unchecked(&rdp->dynticks->dynticks,
84255+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
84256 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
84257
84258 /* Add CPU to rcu_node bitmasks. */
84259diff --git a/kernel/rcutree.h b/kernel/rcutree.h
84260index 5f97eab..db8f687 100644
84261--- a/kernel/rcutree.h
84262+++ b/kernel/rcutree.h
84263@@ -87,11 +87,11 @@ struct rcu_dynticks {
84264 long long dynticks_nesting; /* Track irq/process nesting level. */
84265 /* Process level is worth LLONG_MAX/2. */
84266 int dynticks_nmi_nesting; /* Track NMI nesting level. */
84267- atomic_t dynticks; /* Even value for idle, else odd. */
84268+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
84269 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
84270 long long dynticks_idle_nesting;
84271 /* irq/process nesting level from idle. */
84272- atomic_t dynticks_idle; /* Even value for idle, else odd. */
84273+ atomic_unchecked_t dynticks_idle; /* Even value for idle, else odd. */
84274 /* "Idle" excludes userspace execution. */
84275 unsigned long dynticks_idle_jiffies;
84276 /* End of last non-NMI non-idle period. */
84277@@ -427,17 +427,17 @@ struct rcu_state {
84278 /* _rcu_barrier(). */
84279 /* End of fields guarded by barrier_mutex. */
84280
84281- atomic_long_t expedited_start; /* Starting ticket. */
84282- atomic_long_t expedited_done; /* Done ticket. */
84283- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
84284- atomic_long_t expedited_tryfail; /* # acquisition failures. */
84285- atomic_long_t expedited_workdone1; /* # done by others #1. */
84286- atomic_long_t expedited_workdone2; /* # done by others #2. */
84287- atomic_long_t expedited_normal; /* # fallbacks to normal. */
84288- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
84289- atomic_long_t expedited_done_tries; /* # tries to update _done. */
84290- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
84291- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
84292+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
84293+ atomic_long_t expedited_done; /* Done ticket. */
84294+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
84295+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
84296+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
84297+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
84298+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
84299+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
84300+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
84301+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
84302+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
84303
84304 unsigned long jiffies_force_qs; /* Time at which to invoke */
84305 /* force_quiescent_state(). */
84306diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
84307index 130c97b..33c0d3d 100644
84308--- a/kernel/rcutree_plugin.h
84309+++ b/kernel/rcutree_plugin.h
84310@@ -900,7 +900,7 @@ void synchronize_rcu_expedited(void)
84311
84312 /* Clean up and exit. */
84313 smp_mb(); /* ensure expedited GP seen before counter increment. */
84314- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
84315+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
84316 unlock_mb_ret:
84317 mutex_unlock(&sync_rcu_preempt_exp_mutex);
84318 mb_ret:
84319@@ -1474,7 +1474,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
84320 free_cpumask_var(cm);
84321 }
84322
84323-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
84324+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
84325 .store = &rcu_cpu_kthread_task,
84326 .thread_should_run = rcu_cpu_kthread_should_run,
84327 .thread_fn = rcu_cpu_kthread,
84328@@ -1939,7 +1939,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
84329 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
84330 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
84331 cpu, ticks_value, ticks_title,
84332- atomic_read(&rdtp->dynticks) & 0xfff,
84333+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
84334 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
84335 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
84336 fast_no_hz);
84337@@ -2102,7 +2102,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
84338
84339 /* Enqueue the callback on the nocb list and update counts. */
84340 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
84341- ACCESS_ONCE(*old_rhpp) = rhp;
84342+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
84343 atomic_long_add(rhcount, &rdp->nocb_q_count);
84344 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
84345
84346@@ -2242,12 +2242,12 @@ static int rcu_nocb_kthread(void *arg)
84347 * Extract queued callbacks, update counts, and wait
84348 * for a grace period to elapse.
84349 */
84350- ACCESS_ONCE(rdp->nocb_head) = NULL;
84351+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
84352 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
84353 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
84354 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
84355- ACCESS_ONCE(rdp->nocb_p_count) += c;
84356- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
84357+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
84358+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
84359 rcu_nocb_wait_gp(rdp);
84360
84361 /* Each pass through the following loop invokes a callback. */
84362@@ -2269,8 +2269,8 @@ static int rcu_nocb_kthread(void *arg)
84363 list = next;
84364 }
84365 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
84366- ACCESS_ONCE(rdp->nocb_p_count) -= c;
84367- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
84368+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
84369+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
84370 rdp->n_nocbs_invoked += c;
84371 }
84372 return 0;
84373@@ -2297,7 +2297,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
84374 t = kthread_run(rcu_nocb_kthread, rdp,
84375 "rcuo%c/%d", rsp->abbr, cpu);
84376 BUG_ON(IS_ERR(t));
84377- ACCESS_ONCE(rdp->nocb_kthread) = t;
84378+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
84379 }
84380 }
84381
84382@@ -2423,11 +2423,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
84383
84384 /* Record start of fully idle period. */
84385 j = jiffies;
84386- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
84387+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
84388 smp_mb__before_atomic_inc();
84389- atomic_inc(&rdtp->dynticks_idle);
84390+ atomic_inc_unchecked(&rdtp->dynticks_idle);
84391 smp_mb__after_atomic_inc();
84392- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
84393+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
84394 }
84395
84396 /*
84397@@ -2492,9 +2492,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
84398
84399 /* Record end of idle period. */
84400 smp_mb__before_atomic_inc();
84401- atomic_inc(&rdtp->dynticks_idle);
84402+ atomic_inc_unchecked(&rdtp->dynticks_idle);
84403 smp_mb__after_atomic_inc();
84404- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
84405+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
84406
84407 /*
84408 * If we are the timekeeping CPU, we are permitted to be non-idle
84409@@ -2535,7 +2535,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
84410 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
84411
84412 /* Pick up current idle and NMI-nesting counter and check. */
84413- cur = atomic_read(&rdtp->dynticks_idle);
84414+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
84415 if (cur & 0x1) {
84416 *isidle = false; /* We are not idle! */
84417 return;
84418@@ -2598,7 +2598,7 @@ static void rcu_sysidle(unsigned long j)
84419 case RCU_SYSIDLE_NOT:
84420
84421 /* First time all are idle, so note a short idle period. */
84422- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
84423+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
84424 break;
84425
84426 case RCU_SYSIDLE_SHORT:
84427@@ -2635,7 +2635,7 @@ static void rcu_sysidle(unsigned long j)
84428 static void rcu_sysidle_cancel(void)
84429 {
84430 smp_mb();
84431- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
84432+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
84433 }
84434
84435 /*
84436@@ -2683,7 +2683,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
84437 smp_mb(); /* grace period precedes setting inuse. */
84438
84439 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
84440- ACCESS_ONCE(rshp->inuse) = 0;
84441+ ACCESS_ONCE_RW(rshp->inuse) = 0;
84442 }
84443
84444 /*
84445diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
84446index cf6c174..a8f4b50 100644
84447--- a/kernel/rcutree_trace.c
84448+++ b/kernel/rcutree_trace.c
84449@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
84450 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
84451 rdp->passed_quiesce, rdp->qs_pending);
84452 seq_printf(m, " dt=%d/%llx/%d df=%lu",
84453- atomic_read(&rdp->dynticks->dynticks),
84454+ atomic_read_unchecked(&rdp->dynticks->dynticks),
84455 rdp->dynticks->dynticks_nesting,
84456 rdp->dynticks->dynticks_nmi_nesting,
84457 rdp->dynticks_fqs);
84458@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
84459 struct rcu_state *rsp = (struct rcu_state *)m->private;
84460
84461 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",
84462- atomic_long_read(&rsp->expedited_start),
84463+ atomic_long_read_unchecked(&rsp->expedited_start),
84464 atomic_long_read(&rsp->expedited_done),
84465- atomic_long_read(&rsp->expedited_wrap),
84466- atomic_long_read(&rsp->expedited_tryfail),
84467- atomic_long_read(&rsp->expedited_workdone1),
84468- atomic_long_read(&rsp->expedited_workdone2),
84469- atomic_long_read(&rsp->expedited_normal),
84470- atomic_long_read(&rsp->expedited_stoppedcpus),
84471- atomic_long_read(&rsp->expedited_done_tries),
84472- atomic_long_read(&rsp->expedited_done_lost),
84473- atomic_long_read(&rsp->expedited_done_exit));
84474+ atomic_long_read_unchecked(&rsp->expedited_wrap),
84475+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
84476+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
84477+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
84478+ atomic_long_read_unchecked(&rsp->expedited_normal),
84479+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
84480+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
84481+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
84482+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
84483 return 0;
84484 }
84485
84486diff --git a/kernel/resource.c b/kernel/resource.c
84487index 3f285dc..5755f62 100644
84488--- a/kernel/resource.c
84489+++ b/kernel/resource.c
84490@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
84491
84492 static int __init ioresources_init(void)
84493 {
84494+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84495+#ifdef CONFIG_GRKERNSEC_PROC_USER
84496+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
84497+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
84498+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84499+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
84500+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
84501+#endif
84502+#else
84503 proc_create("ioports", 0, NULL, &proc_ioports_operations);
84504 proc_create("iomem", 0, NULL, &proc_iomem_operations);
84505+#endif
84506 return 0;
84507 }
84508 __initcall(ioresources_init);
84509diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
84510index 1d96dd0..994ff19 100644
84511--- a/kernel/rtmutex-tester.c
84512+++ b/kernel/rtmutex-tester.c
84513@@ -22,7 +22,7 @@
84514 #define MAX_RT_TEST_MUTEXES 8
84515
84516 static spinlock_t rttest_lock;
84517-static atomic_t rttest_event;
84518+static atomic_unchecked_t rttest_event;
84519
84520 struct test_thread_data {
84521 int opcode;
84522@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84523
84524 case RTTEST_LOCKCONT:
84525 td->mutexes[td->opdata] = 1;
84526- td->event = atomic_add_return(1, &rttest_event);
84527+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84528 return 0;
84529
84530 case RTTEST_RESET:
84531@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84532 return 0;
84533
84534 case RTTEST_RESETEVENT:
84535- atomic_set(&rttest_event, 0);
84536+ atomic_set_unchecked(&rttest_event, 0);
84537 return 0;
84538
84539 default:
84540@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84541 return ret;
84542
84543 td->mutexes[id] = 1;
84544- td->event = atomic_add_return(1, &rttest_event);
84545+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84546 rt_mutex_lock(&mutexes[id]);
84547- td->event = atomic_add_return(1, &rttest_event);
84548+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84549 td->mutexes[id] = 4;
84550 return 0;
84551
84552@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84553 return ret;
84554
84555 td->mutexes[id] = 1;
84556- td->event = atomic_add_return(1, &rttest_event);
84557+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84558 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
84559- td->event = atomic_add_return(1, &rttest_event);
84560+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84561 td->mutexes[id] = ret ? 0 : 4;
84562 return ret ? -EINTR : 0;
84563
84564@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84565 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
84566 return ret;
84567
84568- td->event = atomic_add_return(1, &rttest_event);
84569+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84570 rt_mutex_unlock(&mutexes[id]);
84571- td->event = atomic_add_return(1, &rttest_event);
84572+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84573 td->mutexes[id] = 0;
84574 return 0;
84575
84576@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84577 break;
84578
84579 td->mutexes[dat] = 2;
84580- td->event = atomic_add_return(1, &rttest_event);
84581+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84582 break;
84583
84584 default:
84585@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84586 return;
84587
84588 td->mutexes[dat] = 3;
84589- td->event = atomic_add_return(1, &rttest_event);
84590+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84591 break;
84592
84593 case RTTEST_LOCKNOWAIT:
84594@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84595 return;
84596
84597 td->mutexes[dat] = 1;
84598- td->event = atomic_add_return(1, &rttest_event);
84599+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84600 return;
84601
84602 default:
84603diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
84604index 4a07353..66b5291 100644
84605--- a/kernel/sched/auto_group.c
84606+++ b/kernel/sched/auto_group.c
84607@@ -11,7 +11,7 @@
84608
84609 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
84610 static struct autogroup autogroup_default;
84611-static atomic_t autogroup_seq_nr;
84612+static atomic_unchecked_t autogroup_seq_nr;
84613
84614 void __init autogroup_init(struct task_struct *init_task)
84615 {
84616@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
84617
84618 kref_init(&ag->kref);
84619 init_rwsem(&ag->lock);
84620- ag->id = atomic_inc_return(&autogroup_seq_nr);
84621+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
84622 ag->tg = tg;
84623 #ifdef CONFIG_RT_GROUP_SCHED
84624 /*
84625diff --git a/kernel/sched/core.c b/kernel/sched/core.c
84626index 5ac63c9..d912786 100644
84627--- a/kernel/sched/core.c
84628+++ b/kernel/sched/core.c
84629@@ -2868,7 +2868,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
84630 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
84631 * or number of jiffies left till timeout) if completed.
84632 */
84633-long __sched
84634+long __sched __intentional_overflow(-1)
84635 wait_for_completion_interruptible_timeout(struct completion *x,
84636 unsigned long timeout)
84637 {
84638@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
84639 *
84640 * Return: -ERESTARTSYS if interrupted, 0 if completed.
84641 */
84642-int __sched wait_for_completion_killable(struct completion *x)
84643+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
84644 {
84645 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
84646 if (t == -ERESTARTSYS)
84647@@ -2906,7 +2906,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
84648 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
84649 * or number of jiffies left till timeout) if completed.
84650 */
84651-long __sched
84652+long __sched __intentional_overflow(-1)
84653 wait_for_completion_killable_timeout(struct completion *x,
84654 unsigned long timeout)
84655 {
84656@@ -3132,6 +3132,8 @@ int can_nice(const struct task_struct *p, const int nice)
84657 /* convert nice value [19,-20] to rlimit style value [1,40] */
84658 int nice_rlim = 20 - nice;
84659
84660+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
84661+
84662 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
84663 capable(CAP_SYS_NICE));
84664 }
84665@@ -3165,7 +3167,8 @@ SYSCALL_DEFINE1(nice, int, increment)
84666 if (nice > 19)
84667 nice = 19;
84668
84669- if (increment < 0 && !can_nice(current, nice))
84670+ if (increment < 0 && (!can_nice(current, nice) ||
84671+ gr_handle_chroot_nice()))
84672 return -EPERM;
84673
84674 retval = security_task_setnice(current, nice);
84675@@ -3327,6 +3330,7 @@ recheck:
84676 unsigned long rlim_rtprio =
84677 task_rlimit(p, RLIMIT_RTPRIO);
84678
84679+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
84680 /* can't set/change the rt policy */
84681 if (policy != p->policy && !rlim_rtprio)
84682 return -EPERM;
84683@@ -4456,7 +4460,7 @@ static void migrate_tasks(unsigned int dead_cpu)
84684
84685 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
84686
84687-static struct ctl_table sd_ctl_dir[] = {
84688+static ctl_table_no_const sd_ctl_dir[] __read_only = {
84689 {
84690 .procname = "sched_domain",
84691 .mode = 0555,
84692@@ -4473,17 +4477,17 @@ static struct ctl_table sd_ctl_root[] = {
84693 {}
84694 };
84695
84696-static struct ctl_table *sd_alloc_ctl_entry(int n)
84697+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
84698 {
84699- struct ctl_table *entry =
84700+ ctl_table_no_const *entry =
84701 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
84702
84703 return entry;
84704 }
84705
84706-static void sd_free_ctl_entry(struct ctl_table **tablep)
84707+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
84708 {
84709- struct ctl_table *entry;
84710+ ctl_table_no_const *entry;
84711
84712 /*
84713 * In the intermediate directories, both the child directory and
84714@@ -4491,22 +4495,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
84715 * will always be set. In the lowest directory the names are
84716 * static strings and all have proc handlers.
84717 */
84718- for (entry = *tablep; entry->mode; entry++) {
84719- if (entry->child)
84720- sd_free_ctl_entry(&entry->child);
84721+ for (entry = tablep; entry->mode; entry++) {
84722+ if (entry->child) {
84723+ sd_free_ctl_entry(entry->child);
84724+ pax_open_kernel();
84725+ entry->child = NULL;
84726+ pax_close_kernel();
84727+ }
84728 if (entry->proc_handler == NULL)
84729 kfree(entry->procname);
84730 }
84731
84732- kfree(*tablep);
84733- *tablep = NULL;
84734+ kfree(tablep);
84735 }
84736
84737 static int min_load_idx = 0;
84738 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
84739
84740 static void
84741-set_table_entry(struct ctl_table *entry,
84742+set_table_entry(ctl_table_no_const *entry,
84743 const char *procname, void *data, int maxlen,
84744 umode_t mode, proc_handler *proc_handler,
84745 bool load_idx)
84746@@ -4526,7 +4533,7 @@ set_table_entry(struct ctl_table *entry,
84747 static struct ctl_table *
84748 sd_alloc_ctl_domain_table(struct sched_domain *sd)
84749 {
84750- struct ctl_table *table = sd_alloc_ctl_entry(13);
84751+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
84752
84753 if (table == NULL)
84754 return NULL;
84755@@ -4561,9 +4568,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
84756 return table;
84757 }
84758
84759-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
84760+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
84761 {
84762- struct ctl_table *entry, *table;
84763+ ctl_table_no_const *entry, *table;
84764 struct sched_domain *sd;
84765 int domain_num = 0, i;
84766 char buf[32];
84767@@ -4590,11 +4597,13 @@ static struct ctl_table_header *sd_sysctl_header;
84768 static void register_sched_domain_sysctl(void)
84769 {
84770 int i, cpu_num = num_possible_cpus();
84771- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
84772+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
84773 char buf[32];
84774
84775 WARN_ON(sd_ctl_dir[0].child);
84776+ pax_open_kernel();
84777 sd_ctl_dir[0].child = entry;
84778+ pax_close_kernel();
84779
84780 if (entry == NULL)
84781 return;
84782@@ -4617,8 +4626,12 @@ static void unregister_sched_domain_sysctl(void)
84783 if (sd_sysctl_header)
84784 unregister_sysctl_table(sd_sysctl_header);
84785 sd_sysctl_header = NULL;
84786- if (sd_ctl_dir[0].child)
84787- sd_free_ctl_entry(&sd_ctl_dir[0].child);
84788+ if (sd_ctl_dir[0].child) {
84789+ sd_free_ctl_entry(sd_ctl_dir[0].child);
84790+ pax_open_kernel();
84791+ sd_ctl_dir[0].child = NULL;
84792+ pax_close_kernel();
84793+ }
84794 }
84795 #else
84796 static void register_sched_domain_sysctl(void)
84797diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
84798index 7c70201..23f52b6 100644
84799--- a/kernel/sched/fair.c
84800+++ b/kernel/sched/fair.c
84801@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
84802
84803 static void reset_ptenuma_scan(struct task_struct *p)
84804 {
84805- ACCESS_ONCE(p->mm->numa_scan_seq)++;
84806+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
84807 p->mm->numa_scan_offset = 0;
84808 }
84809
84810@@ -5838,7 +5838,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
84811 * run_rebalance_domains is triggered when needed from the scheduler tick.
84812 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
84813 */
84814-static void run_rebalance_domains(struct softirq_action *h)
84815+static __latent_entropy void run_rebalance_domains(void)
84816 {
84817 int this_cpu = smp_processor_id();
84818 struct rq *this_rq = cpu_rq(this_cpu);
84819diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
84820index b3c5653..a4d192a 100644
84821--- a/kernel/sched/sched.h
84822+++ b/kernel/sched/sched.h
84823@@ -1004,7 +1004,7 @@ struct sched_class {
84824 #ifdef CONFIG_FAIR_GROUP_SCHED
84825 void (*task_move_group) (struct task_struct *p, int on_rq);
84826 #endif
84827-};
84828+} __do_const;
84829
84830 #define sched_class_highest (&stop_sched_class)
84831 #define for_each_class(class) \
84832diff --git a/kernel/signal.c b/kernel/signal.c
84833index ded28b9..6886c08 100644
84834--- a/kernel/signal.c
84835+++ b/kernel/signal.c
84836@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
84837
84838 int print_fatal_signals __read_mostly;
84839
84840-static void __user *sig_handler(struct task_struct *t, int sig)
84841+static __sighandler_t sig_handler(struct task_struct *t, int sig)
84842 {
84843 return t->sighand->action[sig - 1].sa.sa_handler;
84844 }
84845
84846-static int sig_handler_ignored(void __user *handler, int sig)
84847+static int sig_handler_ignored(__sighandler_t handler, int sig)
84848 {
84849 /* Is it explicitly or implicitly ignored? */
84850 return handler == SIG_IGN ||
84851@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
84852
84853 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
84854 {
84855- void __user *handler;
84856+ __sighandler_t handler;
84857
84858 handler = sig_handler(t, sig);
84859
84860@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
84861 atomic_inc(&user->sigpending);
84862 rcu_read_unlock();
84863
84864+ if (!override_rlimit)
84865+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
84866+
84867 if (override_rlimit ||
84868 atomic_read(&user->sigpending) <=
84869 task_rlimit(t, RLIMIT_SIGPENDING)) {
84870@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
84871
84872 int unhandled_signal(struct task_struct *tsk, int sig)
84873 {
84874- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
84875+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
84876 if (is_global_init(tsk))
84877 return 1;
84878 if (handler != SIG_IGN && handler != SIG_DFL)
84879@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
84880 }
84881 }
84882
84883+ /* allow glibc communication via tgkill to other threads in our
84884+ thread group */
84885+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
84886+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
84887+ && gr_handle_signal(t, sig))
84888+ return -EPERM;
84889+
84890 return security_task_kill(t, info, sig, 0);
84891 }
84892
84893@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
84894 return send_signal(sig, info, p, 1);
84895 }
84896
84897-static int
84898+int
84899 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
84900 {
84901 return send_signal(sig, info, t, 0);
84902@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
84903 unsigned long int flags;
84904 int ret, blocked, ignored;
84905 struct k_sigaction *action;
84906+ int is_unhandled = 0;
84907
84908 spin_lock_irqsave(&t->sighand->siglock, flags);
84909 action = &t->sighand->action[sig-1];
84910@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
84911 }
84912 if (action->sa.sa_handler == SIG_DFL)
84913 t->signal->flags &= ~SIGNAL_UNKILLABLE;
84914+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
84915+ is_unhandled = 1;
84916 ret = specific_send_sig_info(sig, info, t);
84917 spin_unlock_irqrestore(&t->sighand->siglock, flags);
84918
84919+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
84920+ normal operation */
84921+ if (is_unhandled) {
84922+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
84923+ gr_handle_crash(t, sig);
84924+ }
84925+
84926 return ret;
84927 }
84928
84929@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
84930 ret = check_kill_permission(sig, info, p);
84931 rcu_read_unlock();
84932
84933- if (!ret && sig)
84934+ if (!ret && sig) {
84935 ret = do_send_sig_info(sig, info, p, true);
84936+ if (!ret)
84937+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
84938+ }
84939
84940 return ret;
84941 }
84942@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
84943 int error = -ESRCH;
84944
84945 rcu_read_lock();
84946- p = find_task_by_vpid(pid);
84947+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
84948+ /* allow glibc communication via tgkill to other threads in our
84949+ thread group */
84950+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
84951+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
84952+ p = find_task_by_vpid_unrestricted(pid);
84953+ else
84954+#endif
84955+ p = find_task_by_vpid(pid);
84956 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
84957 error = check_kill_permission(sig, info, p);
84958 /*
84959@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
84960 }
84961 seg = get_fs();
84962 set_fs(KERNEL_DS);
84963- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
84964- (stack_t __force __user *) &uoss,
84965+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
84966+ (stack_t __force_user *) &uoss,
84967 compat_user_stack_pointer());
84968 set_fs(seg);
84969 if (ret >= 0 && uoss_ptr) {
84970diff --git a/kernel/smpboot.c b/kernel/smpboot.c
84971index eb89e18..a4e6792 100644
84972--- a/kernel/smpboot.c
84973+++ b/kernel/smpboot.c
84974@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
84975 }
84976 smpboot_unpark_thread(plug_thread, cpu);
84977 }
84978- list_add(&plug_thread->list, &hotplug_threads);
84979+ pax_list_add(&plug_thread->list, &hotplug_threads);
84980 out:
84981 mutex_unlock(&smpboot_threads_lock);
84982 return ret;
84983@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
84984 {
84985 get_online_cpus();
84986 mutex_lock(&smpboot_threads_lock);
84987- list_del(&plug_thread->list);
84988+ pax_list_del(&plug_thread->list);
84989 smpboot_destroy_threads(plug_thread);
84990 mutex_unlock(&smpboot_threads_lock);
84991 put_online_cpus();
84992diff --git a/kernel/softirq.c b/kernel/softirq.c
84993index d7d498d..94fe0f7 100644
84994--- a/kernel/softirq.c
84995+++ b/kernel/softirq.c
84996@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
84997 EXPORT_SYMBOL(irq_stat);
84998 #endif
84999
85000-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
85001+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
85002
85003 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
85004
85005-char *softirq_to_name[NR_SOFTIRQS] = {
85006+const char * const softirq_to_name[NR_SOFTIRQS] = {
85007 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
85008 "TASKLET", "SCHED", "HRTIMER", "RCU"
85009 };
85010@@ -248,7 +248,7 @@ restart:
85011 kstat_incr_softirqs_this_cpu(vec_nr);
85012
85013 trace_softirq_entry(vec_nr);
85014- h->action(h);
85015+ h->action();
85016 trace_softirq_exit(vec_nr);
85017 if (unlikely(prev_count != preempt_count())) {
85018 printk(KERN_ERR "huh, entered softirq %u %s %p"
85019@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
85020 or_softirq_pending(1UL << nr);
85021 }
85022
85023-void open_softirq(int nr, void (*action)(struct softirq_action *))
85024+void __init open_softirq(int nr, void (*action)(void))
85025 {
85026 softirq_vec[nr].action = action;
85027 }
85028@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
85029
85030 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
85031
85032-static void tasklet_action(struct softirq_action *a)
85033+static __latent_entropy void tasklet_action(void)
85034 {
85035 struct tasklet_struct *list;
85036
85037@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
85038 }
85039 }
85040
85041-static void tasklet_hi_action(struct softirq_action *a)
85042+static __latent_entropy void tasklet_hi_action(void)
85043 {
85044 struct tasklet_struct *list;
85045
85046@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
85047 .notifier_call = cpu_callback
85048 };
85049
85050-static struct smp_hotplug_thread softirq_threads = {
85051+static struct smp_hotplug_thread softirq_threads __read_only = {
85052 .store = &ksoftirqd,
85053 .thread_should_run = ksoftirqd_should_run,
85054 .thread_fn = run_ksoftirqd,
85055diff --git a/kernel/srcu.c b/kernel/srcu.c
85056index 01d5ccb..cdcbee6 100644
85057--- a/kernel/srcu.c
85058+++ b/kernel/srcu.c
85059@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
85060
85061 idx = ACCESS_ONCE(sp->completed) & 0x1;
85062 preempt_disable();
85063- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85064+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85065 smp_mb(); /* B */ /* Avoid leaking the critical section. */
85066- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85067+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85068 preempt_enable();
85069 return idx;
85070 }
85071diff --git a/kernel/sys.c b/kernel/sys.c
85072index c18ecca..b3c2dd2 100644
85073--- a/kernel/sys.c
85074+++ b/kernel/sys.c
85075@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
85076 error = -EACCES;
85077 goto out;
85078 }
85079+
85080+ if (gr_handle_chroot_setpriority(p, niceval)) {
85081+ error = -EACCES;
85082+ goto out;
85083+ }
85084+
85085 no_nice = security_task_setnice(p, niceval);
85086 if (no_nice) {
85087 error = no_nice;
85088@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
85089 goto error;
85090 }
85091
85092+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
85093+ goto error;
85094+
85095 if (rgid != (gid_t) -1 ||
85096 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
85097 new->sgid = new->egid;
85098@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
85099 old = current_cred();
85100
85101 retval = -EPERM;
85102+
85103+ if (gr_check_group_change(kgid, kgid, kgid))
85104+ goto error;
85105+
85106 if (ns_capable(old->user_ns, CAP_SETGID))
85107 new->gid = new->egid = new->sgid = new->fsgid = kgid;
85108 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
85109@@ -404,7 +417,7 @@ error:
85110 /*
85111 * change the user struct in a credentials set to match the new UID
85112 */
85113-static int set_user(struct cred *new)
85114+int set_user(struct cred *new)
85115 {
85116 struct user_struct *new_user;
85117
85118@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
85119 goto error;
85120 }
85121
85122+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
85123+ goto error;
85124+
85125 if (!uid_eq(new->uid, old->uid)) {
85126 retval = set_user(new);
85127 if (retval < 0)
85128@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
85129 old = current_cred();
85130
85131 retval = -EPERM;
85132+
85133+ if (gr_check_crash_uid(kuid))
85134+ goto error;
85135+ if (gr_check_user_change(kuid, kuid, kuid))
85136+ goto error;
85137+
85138 if (ns_capable(old->user_ns, CAP_SETUID)) {
85139 new->suid = new->uid = kuid;
85140 if (!uid_eq(kuid, old->uid)) {
85141@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
85142 goto error;
85143 }
85144
85145+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
85146+ goto error;
85147+
85148 if (ruid != (uid_t) -1) {
85149 new->uid = kruid;
85150 if (!uid_eq(kruid, old->uid)) {
85151@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
85152 goto error;
85153 }
85154
85155+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
85156+ goto error;
85157+
85158 if (rgid != (gid_t) -1)
85159 new->gid = krgid;
85160 if (egid != (gid_t) -1)
85161@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
85162 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
85163 ns_capable(old->user_ns, CAP_SETUID)) {
85164 if (!uid_eq(kuid, old->fsuid)) {
85165+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
85166+ goto error;
85167+
85168 new->fsuid = kuid;
85169 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
85170 goto change_okay;
85171 }
85172 }
85173
85174+error:
85175 abort_creds(new);
85176 return old_fsuid;
85177
85178@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
85179 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
85180 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
85181 ns_capable(old->user_ns, CAP_SETGID)) {
85182+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
85183+ goto error;
85184+
85185 if (!gid_eq(kgid, old->fsgid)) {
85186 new->fsgid = kgid;
85187 goto change_okay;
85188 }
85189 }
85190
85191+error:
85192 abort_creds(new);
85193 return old_fsgid;
85194
85195@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
85196 return -EFAULT;
85197
85198 down_read(&uts_sem);
85199- error = __copy_to_user(&name->sysname, &utsname()->sysname,
85200+ error = __copy_to_user(name->sysname, &utsname()->sysname,
85201 __OLD_UTS_LEN);
85202 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
85203- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
85204+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
85205 __OLD_UTS_LEN);
85206 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
85207- error |= __copy_to_user(&name->release, &utsname()->release,
85208+ error |= __copy_to_user(name->release, &utsname()->release,
85209 __OLD_UTS_LEN);
85210 error |= __put_user(0, name->release + __OLD_UTS_LEN);
85211- error |= __copy_to_user(&name->version, &utsname()->version,
85212+ error |= __copy_to_user(name->version, &utsname()->version,
85213 __OLD_UTS_LEN);
85214 error |= __put_user(0, name->version + __OLD_UTS_LEN);
85215- error |= __copy_to_user(&name->machine, &utsname()->machine,
85216+ error |= __copy_to_user(name->machine, &utsname()->machine,
85217 __OLD_UTS_LEN);
85218 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
85219 up_read(&uts_sem);
85220@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
85221 */
85222 new_rlim->rlim_cur = 1;
85223 }
85224+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
85225+ is changed to a lower value. Since tasks can be created by the same
85226+ user in between this limit change and an execve by this task, force
85227+ a recheck only for this task by setting PF_NPROC_EXCEEDED
85228+ */
85229+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
85230+ tsk->flags |= PF_NPROC_EXCEEDED;
85231 }
85232 if (!retval) {
85233 if (old_rlim)
85234diff --git a/kernel/sysctl.c b/kernel/sysctl.c
85235index b2f06f3..e6354ab 100644
85236--- a/kernel/sysctl.c
85237+++ b/kernel/sysctl.c
85238@@ -93,7 +93,6 @@
85239
85240
85241 #if defined(CONFIG_SYSCTL)
85242-
85243 /* External variables not in a header file. */
85244 extern int sysctl_overcommit_memory;
85245 extern int sysctl_overcommit_ratio;
85246@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
85247
85248 /* Constants used for minimum and maximum */
85249 #ifdef CONFIG_LOCKUP_DETECTOR
85250-static int sixty = 60;
85251+static int sixty __read_only = 60;
85252 #endif
85253
85254-static int zero;
85255-static int __maybe_unused one = 1;
85256-static int __maybe_unused two = 2;
85257-static int __maybe_unused three = 3;
85258-static unsigned long one_ul = 1;
85259-static int one_hundred = 100;
85260+static int neg_one __read_only = -1;
85261+static int zero __read_only = 0;
85262+static int __maybe_unused one __read_only = 1;
85263+static int __maybe_unused two __read_only = 2;
85264+static int __maybe_unused three __read_only = 3;
85265+static unsigned long one_ul __read_only = 1;
85266+static int one_hundred __read_only = 100;
85267 #ifdef CONFIG_PRINTK
85268-static int ten_thousand = 10000;
85269+static int ten_thousand __read_only = 10000;
85270 #endif
85271
85272 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
85273@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
85274 void __user *buffer, size_t *lenp, loff_t *ppos);
85275 #endif
85276
85277-#ifdef CONFIG_PRINTK
85278 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85279 void __user *buffer, size_t *lenp, loff_t *ppos);
85280-#endif
85281
85282 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
85283 void __user *buffer, size_t *lenp, loff_t *ppos);
85284@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
85285
85286 #endif
85287
85288+extern struct ctl_table grsecurity_table[];
85289+
85290 static struct ctl_table kern_table[];
85291 static struct ctl_table vm_table[];
85292 static struct ctl_table fs_table[];
85293@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
85294 int sysctl_legacy_va_layout;
85295 #endif
85296
85297+#ifdef CONFIG_PAX_SOFTMODE
85298+static ctl_table pax_table[] = {
85299+ {
85300+ .procname = "softmode",
85301+ .data = &pax_softmode,
85302+ .maxlen = sizeof(unsigned int),
85303+ .mode = 0600,
85304+ .proc_handler = &proc_dointvec,
85305+ },
85306+
85307+ { }
85308+};
85309+#endif
85310+
85311 /* The default sysctl tables: */
85312
85313 static struct ctl_table sysctl_base_table[] = {
85314@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
85315 #endif
85316
85317 static struct ctl_table kern_table[] = {
85318+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
85319+ {
85320+ .procname = "grsecurity",
85321+ .mode = 0500,
85322+ .child = grsecurity_table,
85323+ },
85324+#endif
85325+
85326+#ifdef CONFIG_PAX_SOFTMODE
85327+ {
85328+ .procname = "pax",
85329+ .mode = 0500,
85330+ .child = pax_table,
85331+ },
85332+#endif
85333+
85334 {
85335 .procname = "sched_child_runs_first",
85336 .data = &sysctl_sched_child_runs_first,
85337@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
85338 .data = &modprobe_path,
85339 .maxlen = KMOD_PATH_LEN,
85340 .mode = 0644,
85341- .proc_handler = proc_dostring,
85342+ .proc_handler = proc_dostring_modpriv,
85343 },
85344 {
85345 .procname = "modules_disabled",
85346@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
85347 .extra1 = &zero,
85348 .extra2 = &one,
85349 },
85350+#endif
85351 {
85352 .procname = "kptr_restrict",
85353 .data = &kptr_restrict,
85354 .maxlen = sizeof(int),
85355 .mode = 0644,
85356 .proc_handler = proc_dointvec_minmax_sysadmin,
85357+#ifdef CONFIG_GRKERNSEC_HIDESYM
85358+ .extra1 = &two,
85359+#else
85360 .extra1 = &zero,
85361+#endif
85362 .extra2 = &two,
85363 },
85364-#endif
85365 {
85366 .procname = "ngroups_max",
85367 .data = &ngroups_max,
85368@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
85369 */
85370 {
85371 .procname = "perf_event_paranoid",
85372- .data = &sysctl_perf_event_paranoid,
85373- .maxlen = sizeof(sysctl_perf_event_paranoid),
85374+ .data = &sysctl_perf_event_legitimately_concerned,
85375+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
85376 .mode = 0644,
85377- .proc_handler = proc_dointvec,
85378+ /* go ahead, be a hero */
85379+ .proc_handler = proc_dointvec_minmax_sysadmin,
85380+ .extra1 = &neg_one,
85381+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85382+ .extra2 = &three,
85383+#else
85384+ .extra2 = &two,
85385+#endif
85386 },
85387 {
85388 .procname = "perf_event_mlock_kb",
85389@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
85390 .proc_handler = proc_dointvec_minmax,
85391 .extra1 = &zero,
85392 },
85393+ {
85394+ .procname = "heap_stack_gap",
85395+ .data = &sysctl_heap_stack_gap,
85396+ .maxlen = sizeof(sysctl_heap_stack_gap),
85397+ .mode = 0644,
85398+ .proc_handler = proc_doulongvec_minmax,
85399+ },
85400 #else
85401 {
85402 .procname = "nr_trim_pages",
85403@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
85404 buffer, lenp, ppos);
85405 }
85406
85407+int proc_dostring_modpriv(struct ctl_table *table, int write,
85408+ void __user *buffer, size_t *lenp, loff_t *ppos)
85409+{
85410+ if (write && !capable(CAP_SYS_MODULE))
85411+ return -EPERM;
85412+
85413+ return _proc_do_string(table->data, table->maxlen, write,
85414+ buffer, lenp, ppos);
85415+}
85416+
85417 static size_t proc_skip_spaces(char **buf)
85418 {
85419 size_t ret;
85420@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
85421 len = strlen(tmp);
85422 if (len > *size)
85423 len = *size;
85424+ if (len > sizeof(tmp))
85425+ len = sizeof(tmp);
85426 if (copy_to_user(*buf, tmp, len))
85427 return -EFAULT;
85428 *size -= len;
85429@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
85430 static int proc_taint(struct ctl_table *table, int write,
85431 void __user *buffer, size_t *lenp, loff_t *ppos)
85432 {
85433- struct ctl_table t;
85434+ ctl_table_no_const t;
85435 unsigned long tmptaint = get_taint();
85436 int err;
85437
85438@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
85439 return err;
85440 }
85441
85442-#ifdef CONFIG_PRINTK
85443 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85444 void __user *buffer, size_t *lenp, loff_t *ppos)
85445 {
85446@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85447
85448 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
85449 }
85450-#endif
85451
85452 struct do_proc_dointvec_minmax_conv_param {
85453 int *min;
85454@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
85455 *i = val;
85456 } else {
85457 val = convdiv * (*i) / convmul;
85458- if (!first)
85459+ if (!first) {
85460 err = proc_put_char(&buffer, &left, '\t');
85461+ if (err)
85462+ break;
85463+ }
85464 err = proc_put_long(&buffer, &left, val, false);
85465 if (err)
85466 break;
85467@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
85468 return -ENOSYS;
85469 }
85470
85471+int proc_dostring_modpriv(struct ctl_table *table, int write,
85472+ void __user *buffer, size_t *lenp, loff_t *ppos)
85473+{
85474+ return -ENOSYS;
85475+}
85476+
85477 int proc_dointvec(struct ctl_table *table, int write,
85478 void __user *buffer, size_t *lenp, loff_t *ppos)
85479 {
85480@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
85481 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
85482 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
85483 EXPORT_SYMBOL(proc_dostring);
85484+EXPORT_SYMBOL(proc_dostring_modpriv);
85485 EXPORT_SYMBOL(proc_doulongvec_minmax);
85486 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
85487diff --git a/kernel/taskstats.c b/kernel/taskstats.c
85488index 145bb4d..b2aa969 100644
85489--- a/kernel/taskstats.c
85490+++ b/kernel/taskstats.c
85491@@ -28,9 +28,12 @@
85492 #include <linux/fs.h>
85493 #include <linux/file.h>
85494 #include <linux/pid_namespace.h>
85495+#include <linux/grsecurity.h>
85496 #include <net/genetlink.h>
85497 #include <linux/atomic.h>
85498
85499+extern int gr_is_taskstats_denied(int pid);
85500+
85501 /*
85502 * Maximum length of a cpumask that can be specified in
85503 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
85504@@ -570,6 +573,9 @@ err:
85505
85506 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
85507 {
85508+ if (gr_is_taskstats_denied(current->pid))
85509+ return -EACCES;
85510+
85511 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
85512 return cmd_attr_register_cpumask(info);
85513 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
85514diff --git a/kernel/time.c b/kernel/time.c
85515index 7c7964c..2a0d412 100644
85516--- a/kernel/time.c
85517+++ b/kernel/time.c
85518@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
85519 return error;
85520
85521 if (tz) {
85522+ /* we log in do_settimeofday called below, so don't log twice
85523+ */
85524+ if (!tv)
85525+ gr_log_timechange();
85526+
85527 sys_tz = *tz;
85528 update_vsyscall_tz();
85529 if (firsttime) {
85530diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
85531index eec50fc..65e5df6 100644
85532--- a/kernel/time/alarmtimer.c
85533+++ b/kernel/time/alarmtimer.c
85534@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
85535 struct platform_device *pdev;
85536 int error = 0;
85537 int i;
85538- struct k_clock alarm_clock = {
85539+ static struct k_clock alarm_clock = {
85540 .clock_getres = alarm_clock_getres,
85541 .clock_get = alarm_clock_get,
85542 .timer_create = alarm_timer_create,
85543diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
85544index 947ba25..20cbade 100644
85545--- a/kernel/time/timekeeping.c
85546+++ b/kernel/time/timekeeping.c
85547@@ -15,6 +15,7 @@
85548 #include <linux/init.h>
85549 #include <linux/mm.h>
85550 #include <linux/sched.h>
85551+#include <linux/grsecurity.h>
85552 #include <linux/syscore_ops.h>
85553 #include <linux/clocksource.h>
85554 #include <linux/jiffies.h>
85555@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
85556 if (!timespec_valid_strict(tv))
85557 return -EINVAL;
85558
85559+ gr_log_timechange();
85560+
85561 raw_spin_lock_irqsave(&timekeeper_lock, flags);
85562 write_seqcount_begin(&timekeeper_seq);
85563
85564diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
85565index 61ed862..3b52c65 100644
85566--- a/kernel/time/timer_list.c
85567+++ b/kernel/time/timer_list.c
85568@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
85569
85570 static void print_name_offset(struct seq_file *m, void *sym)
85571 {
85572+#ifdef CONFIG_GRKERNSEC_HIDESYM
85573+ SEQ_printf(m, "<%p>", NULL);
85574+#else
85575 char symname[KSYM_NAME_LEN];
85576
85577 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
85578 SEQ_printf(m, "<%pK>", sym);
85579 else
85580 SEQ_printf(m, "%s", symname);
85581+#endif
85582 }
85583
85584 static void
85585@@ -119,7 +123,11 @@ next_one:
85586 static void
85587 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
85588 {
85589+#ifdef CONFIG_GRKERNSEC_HIDESYM
85590+ SEQ_printf(m, " .base: %p\n", NULL);
85591+#else
85592 SEQ_printf(m, " .base: %pK\n", base);
85593+#endif
85594 SEQ_printf(m, " .index: %d\n",
85595 base->index);
85596 SEQ_printf(m, " .resolution: %Lu nsecs\n",
85597@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
85598 {
85599 struct proc_dir_entry *pe;
85600
85601+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85602+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
85603+#else
85604 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
85605+#endif
85606 if (!pe)
85607 return -ENOMEM;
85608 return 0;
85609diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
85610index 0b537f2..40d6c20 100644
85611--- a/kernel/time/timer_stats.c
85612+++ b/kernel/time/timer_stats.c
85613@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
85614 static unsigned long nr_entries;
85615 static struct entry entries[MAX_ENTRIES];
85616
85617-static atomic_t overflow_count;
85618+static atomic_unchecked_t overflow_count;
85619
85620 /*
85621 * The entries are in a hash-table, for fast lookup:
85622@@ -140,7 +140,7 @@ static void reset_entries(void)
85623 nr_entries = 0;
85624 memset(entries, 0, sizeof(entries));
85625 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
85626- atomic_set(&overflow_count, 0);
85627+ atomic_set_unchecked(&overflow_count, 0);
85628 }
85629
85630 static struct entry *alloc_entry(void)
85631@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85632 if (likely(entry))
85633 entry->count++;
85634 else
85635- atomic_inc(&overflow_count);
85636+ atomic_inc_unchecked(&overflow_count);
85637
85638 out_unlock:
85639 raw_spin_unlock_irqrestore(lock, flags);
85640@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85641
85642 static void print_name_offset(struct seq_file *m, unsigned long addr)
85643 {
85644+#ifdef CONFIG_GRKERNSEC_HIDESYM
85645+ seq_printf(m, "<%p>", NULL);
85646+#else
85647 char symname[KSYM_NAME_LEN];
85648
85649 if (lookup_symbol_name(addr, symname) < 0)
85650- seq_printf(m, "<%p>", (void *)addr);
85651+ seq_printf(m, "<%pK>", (void *)addr);
85652 else
85653 seq_printf(m, "%s", symname);
85654+#endif
85655 }
85656
85657 static int tstats_show(struct seq_file *m, void *v)
85658@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
85659
85660 seq_puts(m, "Timer Stats Version: v0.2\n");
85661 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
85662- if (atomic_read(&overflow_count))
85663+ if (atomic_read_unchecked(&overflow_count))
85664 seq_printf(m, "Overflow: %d entries\n",
85665- atomic_read(&overflow_count));
85666+ atomic_read_unchecked(&overflow_count));
85667
85668 for (i = 0; i < nr_entries; i++) {
85669 entry = entries + i;
85670@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
85671 {
85672 struct proc_dir_entry *pe;
85673
85674+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85675+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
85676+#else
85677 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
85678+#endif
85679 if (!pe)
85680 return -ENOMEM;
85681 return 0;
85682diff --git a/kernel/timer.c b/kernel/timer.c
85683index 4296d13..0164b04 100644
85684--- a/kernel/timer.c
85685+++ b/kernel/timer.c
85686@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
85687 /*
85688 * This function runs timers and the timer-tq in bottom half context.
85689 */
85690-static void run_timer_softirq(struct softirq_action *h)
85691+static __latent_entropy void run_timer_softirq(void)
85692 {
85693 struct tvec_base *base = __this_cpu_read(tvec_bases);
85694
85695@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
85696 *
85697 * In all cases the return value is guaranteed to be non-negative.
85698 */
85699-signed long __sched schedule_timeout(signed long timeout)
85700+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
85701 {
85702 struct timer_list timer;
85703 unsigned long expire;
85704diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
85705index b8b8560..75b1a09 100644
85706--- a/kernel/trace/blktrace.c
85707+++ b/kernel/trace/blktrace.c
85708@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
85709 struct blk_trace *bt = filp->private_data;
85710 char buf[16];
85711
85712- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
85713+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
85714
85715 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
85716 }
85717@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
85718 return 1;
85719
85720 bt = buf->chan->private_data;
85721- atomic_inc(&bt->dropped);
85722+ atomic_inc_unchecked(&bt->dropped);
85723 return 0;
85724 }
85725
85726@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
85727
85728 bt->dir = dir;
85729 bt->dev = dev;
85730- atomic_set(&bt->dropped, 0);
85731+ atomic_set_unchecked(&bt->dropped, 0);
85732
85733 ret = -EIO;
85734 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
85735diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
85736index 03cf44a..3051c64 100644
85737--- a/kernel/trace/ftrace.c
85738+++ b/kernel/trace/ftrace.c
85739@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
85740 if (unlikely(ftrace_disabled))
85741 return 0;
85742
85743+ ret = ftrace_arch_code_modify_prepare();
85744+ FTRACE_WARN_ON(ret);
85745+ if (ret)
85746+ return 0;
85747+
85748 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
85749+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
85750 if (ret) {
85751 ftrace_bug(ret, ip);
85752- return 0;
85753 }
85754- return 1;
85755+ return ret ? 0 : 1;
85756 }
85757
85758 /*
85759@@ -4043,8 +4048,10 @@ static int ftrace_process_locs(struct module *mod,
85760 if (!count)
85761 return 0;
85762
85763+ pax_open_kernel();
85764 sort(start, count, sizeof(*start),
85765 ftrace_cmp_ips, ftrace_swap_ips);
85766+ pax_close_kernel();
85767
85768 start_pg = ftrace_allocate_pages(count);
85769 if (!start_pg)
85770@@ -4767,8 +4774,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
85771 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
85772
85773 static int ftrace_graph_active;
85774-static struct notifier_block ftrace_suspend_notifier;
85775-
85776 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
85777 {
85778 return 0;
85779@@ -4912,6 +4917,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
85780 return NOTIFY_DONE;
85781 }
85782
85783+static struct notifier_block ftrace_suspend_notifier = {
85784+ .notifier_call = ftrace_suspend_notifier_call
85785+};
85786+
85787 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
85788 trace_func_graph_ent_t entryfunc)
85789 {
85790@@ -4925,7 +4934,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
85791 goto out;
85792 }
85793
85794- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
85795 register_pm_notifier(&ftrace_suspend_notifier);
85796
85797 ftrace_graph_active++;
85798diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
85799index cc2f66f..05edd54 100644
85800--- a/kernel/trace/ring_buffer.c
85801+++ b/kernel/trace/ring_buffer.c
85802@@ -352,9 +352,9 @@ struct buffer_data_page {
85803 */
85804 struct buffer_page {
85805 struct list_head list; /* list of buffer pages */
85806- local_t write; /* index for next write */
85807+ local_unchecked_t write; /* index for next write */
85808 unsigned read; /* index for next read */
85809- local_t entries; /* entries on this page */
85810+ local_unchecked_t entries; /* entries on this page */
85811 unsigned long real_end; /* real end of data */
85812 struct buffer_data_page *page; /* Actual data page */
85813 };
85814@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
85815 unsigned long last_overrun;
85816 local_t entries_bytes;
85817 local_t entries;
85818- local_t overrun;
85819- local_t commit_overrun;
85820+ local_unchecked_t overrun;
85821+ local_unchecked_t commit_overrun;
85822 local_t dropped_events;
85823 local_t committing;
85824 local_t commits;
85825@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
85826 *
85827 * We add a counter to the write field to denote this.
85828 */
85829- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
85830- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
85831+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
85832+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
85833
85834 /*
85835 * Just make sure we have seen our old_write and synchronize
85836@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
85837 * cmpxchg to only update if an interrupt did not already
85838 * do it for us. If the cmpxchg fails, we don't care.
85839 */
85840- (void)local_cmpxchg(&next_page->write, old_write, val);
85841- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
85842+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
85843+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
85844
85845 /*
85846 * No need to worry about races with clearing out the commit.
85847@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
85848
85849 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
85850 {
85851- return local_read(&bpage->entries) & RB_WRITE_MASK;
85852+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
85853 }
85854
85855 static inline unsigned long rb_page_write(struct buffer_page *bpage)
85856 {
85857- return local_read(&bpage->write) & RB_WRITE_MASK;
85858+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
85859 }
85860
85861 static int
85862@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
85863 * bytes consumed in ring buffer from here.
85864 * Increment overrun to account for the lost events.
85865 */
85866- local_add(page_entries, &cpu_buffer->overrun);
85867+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
85868 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
85869 }
85870
85871@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
85872 * it is our responsibility to update
85873 * the counters.
85874 */
85875- local_add(entries, &cpu_buffer->overrun);
85876+ local_add_unchecked(entries, &cpu_buffer->overrun);
85877 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
85878
85879 /*
85880@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
85881 if (tail == BUF_PAGE_SIZE)
85882 tail_page->real_end = 0;
85883
85884- local_sub(length, &tail_page->write);
85885+ local_sub_unchecked(length, &tail_page->write);
85886 return;
85887 }
85888
85889@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
85890 rb_event_set_padding(event);
85891
85892 /* Set the write back to the previous setting */
85893- local_sub(length, &tail_page->write);
85894+ local_sub_unchecked(length, &tail_page->write);
85895 return;
85896 }
85897
85898@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
85899
85900 /* Set write to end of buffer */
85901 length = (tail + length) - BUF_PAGE_SIZE;
85902- local_sub(length, &tail_page->write);
85903+ local_sub_unchecked(length, &tail_page->write);
85904 }
85905
85906 /*
85907@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
85908 * about it.
85909 */
85910 if (unlikely(next_page == commit_page)) {
85911- local_inc(&cpu_buffer->commit_overrun);
85912+ local_inc_unchecked(&cpu_buffer->commit_overrun);
85913 goto out_reset;
85914 }
85915
85916@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
85917 cpu_buffer->tail_page) &&
85918 (cpu_buffer->commit_page ==
85919 cpu_buffer->reader_page))) {
85920- local_inc(&cpu_buffer->commit_overrun);
85921+ local_inc_unchecked(&cpu_buffer->commit_overrun);
85922 goto out_reset;
85923 }
85924 }
85925@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
85926 length += RB_LEN_TIME_EXTEND;
85927
85928 tail_page = cpu_buffer->tail_page;
85929- write = local_add_return(length, &tail_page->write);
85930+ write = local_add_return_unchecked(length, &tail_page->write);
85931
85932 /* set write to only the index of the write */
85933 write &= RB_WRITE_MASK;
85934@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
85935 kmemcheck_annotate_bitfield(event, bitfield);
85936 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
85937
85938- local_inc(&tail_page->entries);
85939+ local_inc_unchecked(&tail_page->entries);
85940
85941 /*
85942 * If this is the first commit on the page, then update
85943@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
85944
85945 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
85946 unsigned long write_mask =
85947- local_read(&bpage->write) & ~RB_WRITE_MASK;
85948+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
85949 unsigned long event_length = rb_event_length(event);
85950 /*
85951 * This is on the tail page. It is possible that
85952@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
85953 */
85954 old_index += write_mask;
85955 new_index += write_mask;
85956- index = local_cmpxchg(&bpage->write, old_index, new_index);
85957+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
85958 if (index == old_index) {
85959 /* update counters */
85960 local_sub(event_length, &cpu_buffer->entries_bytes);
85961@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
85962
85963 /* Do the likely case first */
85964 if (likely(bpage->page == (void *)addr)) {
85965- local_dec(&bpage->entries);
85966+ local_dec_unchecked(&bpage->entries);
85967 return;
85968 }
85969
85970@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
85971 start = bpage;
85972 do {
85973 if (bpage->page == (void *)addr) {
85974- local_dec(&bpage->entries);
85975+ local_dec_unchecked(&bpage->entries);
85976 return;
85977 }
85978 rb_inc_page(cpu_buffer, &bpage);
85979@@ -3139,7 +3139,7 @@ static inline unsigned long
85980 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
85981 {
85982 return local_read(&cpu_buffer->entries) -
85983- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
85984+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
85985 }
85986
85987 /**
85988@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
85989 return 0;
85990
85991 cpu_buffer = buffer->buffers[cpu];
85992- ret = local_read(&cpu_buffer->overrun);
85993+ ret = local_read_unchecked(&cpu_buffer->overrun);
85994
85995 return ret;
85996 }
85997@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
85998 return 0;
85999
86000 cpu_buffer = buffer->buffers[cpu];
86001- ret = local_read(&cpu_buffer->commit_overrun);
86002+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
86003
86004 return ret;
86005 }
86006@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
86007 /* if you care about this being correct, lock the buffer */
86008 for_each_buffer_cpu(buffer, cpu) {
86009 cpu_buffer = buffer->buffers[cpu];
86010- overruns += local_read(&cpu_buffer->overrun);
86011+ overruns += local_read_unchecked(&cpu_buffer->overrun);
86012 }
86013
86014 return overruns;
86015@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86016 /*
86017 * Reset the reader page to size zero.
86018 */
86019- local_set(&cpu_buffer->reader_page->write, 0);
86020- local_set(&cpu_buffer->reader_page->entries, 0);
86021+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86022+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86023 local_set(&cpu_buffer->reader_page->page->commit, 0);
86024 cpu_buffer->reader_page->real_end = 0;
86025
86026@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86027 * want to compare with the last_overrun.
86028 */
86029 smp_mb();
86030- overwrite = local_read(&(cpu_buffer->overrun));
86031+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
86032
86033 /*
86034 * Here's the tricky part.
86035@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86036
86037 cpu_buffer->head_page
86038 = list_entry(cpu_buffer->pages, struct buffer_page, list);
86039- local_set(&cpu_buffer->head_page->write, 0);
86040- local_set(&cpu_buffer->head_page->entries, 0);
86041+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
86042+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
86043 local_set(&cpu_buffer->head_page->page->commit, 0);
86044
86045 cpu_buffer->head_page->read = 0;
86046@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86047
86048 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
86049 INIT_LIST_HEAD(&cpu_buffer->new_pages);
86050- local_set(&cpu_buffer->reader_page->write, 0);
86051- local_set(&cpu_buffer->reader_page->entries, 0);
86052+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86053+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86054 local_set(&cpu_buffer->reader_page->page->commit, 0);
86055 cpu_buffer->reader_page->read = 0;
86056
86057 local_set(&cpu_buffer->entries_bytes, 0);
86058- local_set(&cpu_buffer->overrun, 0);
86059- local_set(&cpu_buffer->commit_overrun, 0);
86060+ local_set_unchecked(&cpu_buffer->overrun, 0);
86061+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
86062 local_set(&cpu_buffer->dropped_events, 0);
86063 local_set(&cpu_buffer->entries, 0);
86064 local_set(&cpu_buffer->committing, 0);
86065@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
86066 rb_init_page(bpage);
86067 bpage = reader->page;
86068 reader->page = *data_page;
86069- local_set(&reader->write, 0);
86070- local_set(&reader->entries, 0);
86071+ local_set_unchecked(&reader->write, 0);
86072+ local_set_unchecked(&reader->entries, 0);
86073 reader->read = 0;
86074 *data_page = bpage;
86075
86076diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
86077index b778e96..4e84621 100644
86078--- a/kernel/trace/trace.c
86079+++ b/kernel/trace/trace.c
86080@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
86081 return 0;
86082 }
86083
86084-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
86085+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
86086 {
86087 /* do nothing if flag is already set */
86088 if (!!(trace_flags & mask) == !!enabled)
86089diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
86090index 10c86fb..645ab0a 100644
86091--- a/kernel/trace/trace.h
86092+++ b/kernel/trace/trace.h
86093@@ -1029,7 +1029,7 @@ extern const char *__stop___tracepoint_str[];
86094 void trace_printk_init_buffers(void);
86095 void trace_printk_start_comm(void);
86096 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
86097-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
86098+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
86099
86100 /*
86101 * Normal trace_printk() and friends allocates special buffers
86102diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
86103index 26dc348..8708ca7 100644
86104--- a/kernel/trace/trace_clock.c
86105+++ b/kernel/trace/trace_clock.c
86106@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
86107 return now;
86108 }
86109
86110-static atomic64_t trace_counter;
86111+static atomic64_unchecked_t trace_counter;
86112
86113 /*
86114 * trace_clock_counter(): simply an atomic counter.
86115@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
86116 */
86117 u64 notrace trace_clock_counter(void)
86118 {
86119- return atomic64_add_return(1, &trace_counter);
86120+ return atomic64_inc_return_unchecked(&trace_counter);
86121 }
86122diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
86123index 368a4d5..7b6d1d5 100644
86124--- a/kernel/trace/trace_events.c
86125+++ b/kernel/trace/trace_events.c
86126@@ -1673,7 +1673,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
86127 return 0;
86128 }
86129
86130-struct ftrace_module_file_ops;
86131 static void __add_event_to_tracers(struct ftrace_event_call *call);
86132
86133 /* Add an additional event_call dynamically */
86134diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
86135index b3dcfb2..ebee344 100644
86136--- a/kernel/trace/trace_mmiotrace.c
86137+++ b/kernel/trace/trace_mmiotrace.c
86138@@ -24,7 +24,7 @@ struct header_iter {
86139 static struct trace_array *mmio_trace_array;
86140 static bool overrun_detected;
86141 static unsigned long prev_overruns;
86142-static atomic_t dropped_count;
86143+static atomic_unchecked_t dropped_count;
86144
86145 static void mmio_reset_data(struct trace_array *tr)
86146 {
86147@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
86148
86149 static unsigned long count_overruns(struct trace_iterator *iter)
86150 {
86151- unsigned long cnt = atomic_xchg(&dropped_count, 0);
86152+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
86153 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
86154
86155 if (over > prev_overruns)
86156@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
86157 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
86158 sizeof(*entry), 0, pc);
86159 if (!event) {
86160- atomic_inc(&dropped_count);
86161+ atomic_inc_unchecked(&dropped_count);
86162 return;
86163 }
86164 entry = ring_buffer_event_data(event);
86165@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
86166 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
86167 sizeof(*entry), 0, pc);
86168 if (!event) {
86169- atomic_inc(&dropped_count);
86170+ atomic_inc_unchecked(&dropped_count);
86171 return;
86172 }
86173 entry = ring_buffer_event_data(event);
86174diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
86175index 34e7cba..6f9a729 100644
86176--- a/kernel/trace/trace_output.c
86177+++ b/kernel/trace/trace_output.c
86178@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
86179
86180 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
86181 if (!IS_ERR(p)) {
86182- p = mangle_path(s->buffer + s->len, p, "\n");
86183+ p = mangle_path(s->buffer + s->len, p, "\n\\");
86184 if (p) {
86185 s->len = p - s->buffer;
86186 return 1;
86187@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
86188 goto out;
86189 }
86190
86191+ pax_open_kernel();
86192 if (event->funcs->trace == NULL)
86193- event->funcs->trace = trace_nop_print;
86194+ *(void **)&event->funcs->trace = trace_nop_print;
86195 if (event->funcs->raw == NULL)
86196- event->funcs->raw = trace_nop_print;
86197+ *(void **)&event->funcs->raw = trace_nop_print;
86198 if (event->funcs->hex == NULL)
86199- event->funcs->hex = trace_nop_print;
86200+ *(void **)&event->funcs->hex = trace_nop_print;
86201 if (event->funcs->binary == NULL)
86202- event->funcs->binary = trace_nop_print;
86203+ *(void **)&event->funcs->binary = trace_nop_print;
86204+ pax_close_kernel();
86205
86206 key = event->type & (EVENT_HASHSIZE - 1);
86207
86208diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
86209index b20428c..4845a10 100644
86210--- a/kernel/trace/trace_stack.c
86211+++ b/kernel/trace/trace_stack.c
86212@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
86213 return;
86214
86215 /* we do not handle interrupt stacks yet */
86216- if (!object_is_on_stack(stack))
86217+ if (!object_starts_on_stack(stack))
86218 return;
86219
86220 local_irq_save(flags);
86221diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
86222index 13fb113..a6ced3f 100644
86223--- a/kernel/user_namespace.c
86224+++ b/kernel/user_namespace.c
86225@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
86226 !kgid_has_mapping(parent_ns, group))
86227 return -EPERM;
86228
86229+#ifdef CONFIG_GRKERNSEC
86230+ /*
86231+ * This doesn't really inspire confidence:
86232+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
86233+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
86234+ * Increases kernel attack surface in areas developers
86235+ * previously cared little about ("low importance due
86236+ * to requiring "root" capability")
86237+ * To be removed when this code receives *proper* review
86238+ */
86239+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
86240+ !capable(CAP_SETGID))
86241+ return -EPERM;
86242+#endif
86243+
86244 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
86245 if (!ns)
86246 return -ENOMEM;
86247@@ -860,7 +875,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
86248 if (atomic_read(&current->mm->mm_users) > 1)
86249 return -EINVAL;
86250
86251- if (current->fs->users != 1)
86252+ if (atomic_read(&current->fs->users) != 1)
86253 return -EINVAL;
86254
86255 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
86256diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
86257index 4f69f9a..7c6f8f8 100644
86258--- a/kernel/utsname_sysctl.c
86259+++ b/kernel/utsname_sysctl.c
86260@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
86261 static int proc_do_uts_string(ctl_table *table, int write,
86262 void __user *buffer, size_t *lenp, loff_t *ppos)
86263 {
86264- struct ctl_table uts_table;
86265+ ctl_table_no_const uts_table;
86266 int r;
86267 memcpy(&uts_table, table, sizeof(uts_table));
86268 uts_table.data = get_uts(table, write);
86269diff --git a/kernel/watchdog.c b/kernel/watchdog.c
86270index 4431610..4265616 100644
86271--- a/kernel/watchdog.c
86272+++ b/kernel/watchdog.c
86273@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
86274 static void watchdog_nmi_disable(unsigned int cpu) { return; }
86275 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
86276
86277-static struct smp_hotplug_thread watchdog_threads = {
86278+static struct smp_hotplug_thread watchdog_threads __read_only = {
86279 .store = &softlockup_watchdog,
86280 .thread_should_run = watchdog_should_run,
86281 .thread_fn = watchdog,
86282diff --git a/kernel/workqueue.c b/kernel/workqueue.c
86283index 987293d..60b3043 100644
86284--- a/kernel/workqueue.c
86285+++ b/kernel/workqueue.c
86286@@ -4658,7 +4658,7 @@ static void rebind_workers(struct worker_pool *pool)
86287 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
86288 worker_flags |= WORKER_REBOUND;
86289 worker_flags &= ~WORKER_UNBOUND;
86290- ACCESS_ONCE(worker->flags) = worker_flags;
86291+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
86292 }
86293
86294 spin_unlock_irq(&pool->lock);
86295diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
86296index 094f315..244a824 100644
86297--- a/lib/Kconfig.debug
86298+++ b/lib/Kconfig.debug
86299@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
86300
86301 config DEBUG_WW_MUTEX_SLOWPATH
86302 bool "Wait/wound mutex debugging: Slowpath testing"
86303- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86304+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86305 select DEBUG_LOCK_ALLOC
86306 select DEBUG_SPINLOCK
86307 select DEBUG_MUTEXES
86308@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
86309
86310 config DEBUG_LOCK_ALLOC
86311 bool "Lock debugging: detect incorrect freeing of live locks"
86312- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86313+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86314 select DEBUG_SPINLOCK
86315 select DEBUG_MUTEXES
86316 select LOCKDEP
86317@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
86318
86319 config PROVE_LOCKING
86320 bool "Lock debugging: prove locking correctness"
86321- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86322+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86323 select LOCKDEP
86324 select DEBUG_SPINLOCK
86325 select DEBUG_MUTEXES
86326@@ -914,7 +914,7 @@ config LOCKDEP
86327
86328 config LOCK_STAT
86329 bool "Lock usage statistics"
86330- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86331+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86332 select LOCKDEP
86333 select DEBUG_SPINLOCK
86334 select DEBUG_MUTEXES
86335@@ -1376,6 +1376,7 @@ config LATENCYTOP
86336 depends on DEBUG_KERNEL
86337 depends on STACKTRACE_SUPPORT
86338 depends on PROC_FS
86339+ depends on !GRKERNSEC_HIDESYM
86340 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
86341 select KALLSYMS
86342 select KALLSYMS_ALL
86343@@ -1392,7 +1393,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86344 config DEBUG_STRICT_USER_COPY_CHECKS
86345 bool "Strict user copy size checks"
86346 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86347- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
86348+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
86349 help
86350 Enabling this option turns a certain set of sanity checks for user
86351 copy operations into compile time failures.
86352@@ -1502,7 +1503,7 @@ endmenu # runtime tests
86353
86354 config PROVIDE_OHCI1394_DMA_INIT
86355 bool "Remote debugging over FireWire early on boot"
86356- depends on PCI && X86
86357+ depends on PCI && X86 && !GRKERNSEC
86358 help
86359 If you want to debug problems which hang or crash the kernel early
86360 on boot and the crashing machine has a FireWire port, you can use
86361@@ -1531,7 +1532,7 @@ config PROVIDE_OHCI1394_DMA_INIT
86362
86363 config FIREWIRE_OHCI_REMOTE_DMA
86364 bool "Remote debugging over FireWire with firewire-ohci"
86365- depends on FIREWIRE_OHCI
86366+ depends on FIREWIRE_OHCI && !GRKERNSEC
86367 help
86368 This option lets you use the FireWire bus for remote debugging
86369 with help of the firewire-ohci driver. It enables unfiltered
86370diff --git a/lib/Makefile b/lib/Makefile
86371index f3bb2cb..b358ace 100644
86372--- a/lib/Makefile
86373+++ b/lib/Makefile
86374@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
86375
86376 obj-$(CONFIG_BTREE) += btree.o
86377 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
86378-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
86379+obj-y += list_debug.o
86380 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
86381
86382 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
86383diff --git a/lib/bitmap.c b/lib/bitmap.c
86384index 06f7e4f..f3cf2b0 100644
86385--- a/lib/bitmap.c
86386+++ b/lib/bitmap.c
86387@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
86388 {
86389 int c, old_c, totaldigits, ndigits, nchunks, nbits;
86390 u32 chunk;
86391- const char __user __force *ubuf = (const char __user __force *)buf;
86392+ const char __user *ubuf = (const char __force_user *)buf;
86393
86394 bitmap_zero(maskp, nmaskbits);
86395
86396@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
86397 {
86398 if (!access_ok(VERIFY_READ, ubuf, ulen))
86399 return -EFAULT;
86400- return __bitmap_parse((const char __force *)ubuf,
86401+ return __bitmap_parse((const char __force_kernel *)ubuf,
86402 ulen, 1, maskp, nmaskbits);
86403
86404 }
86405@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
86406 {
86407 unsigned a, b;
86408 int c, old_c, totaldigits;
86409- const char __user __force *ubuf = (const char __user __force *)buf;
86410+ const char __user *ubuf = (const char __force_user *)buf;
86411 int exp_digit, in_range;
86412
86413 totaldigits = c = 0;
86414@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
86415 {
86416 if (!access_ok(VERIFY_READ, ubuf, ulen))
86417 return -EFAULT;
86418- return __bitmap_parselist((const char __force *)ubuf,
86419+ return __bitmap_parselist((const char __force_kernel *)ubuf,
86420 ulen, 1, maskp, nmaskbits);
86421 }
86422 EXPORT_SYMBOL(bitmap_parselist_user);
86423diff --git a/lib/bug.c b/lib/bug.c
86424index 1686034..a9c00c8 100644
86425--- a/lib/bug.c
86426+++ b/lib/bug.c
86427@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
86428 return BUG_TRAP_TYPE_NONE;
86429
86430 bug = find_bug(bugaddr);
86431+ if (!bug)
86432+ return BUG_TRAP_TYPE_NONE;
86433
86434 file = NULL;
86435 line = 0;
86436diff --git a/lib/debugobjects.c b/lib/debugobjects.c
86437index bf2c8b1..1d00ccf 100644
86438--- a/lib/debugobjects.c
86439+++ b/lib/debugobjects.c
86440@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
86441 if (limit > 4)
86442 return;
86443
86444- is_on_stack = object_is_on_stack(addr);
86445+ is_on_stack = object_starts_on_stack(addr);
86446 if (is_on_stack == onstack)
86447 return;
86448
86449diff --git a/lib/devres.c b/lib/devres.c
86450index 8235331..5881053 100644
86451--- a/lib/devres.c
86452+++ b/lib/devres.c
86453@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
86454 void devm_iounmap(struct device *dev, void __iomem *addr)
86455 {
86456 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
86457- (void *)addr));
86458+ (void __force *)addr));
86459 iounmap(addr);
86460 }
86461 EXPORT_SYMBOL(devm_iounmap);
86462@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
86463 {
86464 ioport_unmap(addr);
86465 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
86466- devm_ioport_map_match, (void *)addr));
86467+ devm_ioport_map_match, (void __force *)addr));
86468 }
86469 EXPORT_SYMBOL(devm_ioport_unmap);
86470 #endif /* CONFIG_HAS_IOPORT */
86471diff --git a/lib/div64.c b/lib/div64.c
86472index 4382ad7..08aa558 100644
86473--- a/lib/div64.c
86474+++ b/lib/div64.c
86475@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
86476 EXPORT_SYMBOL(__div64_32);
86477
86478 #ifndef div_s64_rem
86479-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86480+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86481 {
86482 u64 quotient;
86483
86484@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
86485 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
86486 */
86487 #ifndef div64_u64
86488-u64 div64_u64(u64 dividend, u64 divisor)
86489+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
86490 {
86491 u32 high = divisor >> 32;
86492 u64 quot;
86493diff --git a/lib/dma-debug.c b/lib/dma-debug.c
86494index d87a17a..ac0d79a 100644
86495--- a/lib/dma-debug.c
86496+++ b/lib/dma-debug.c
86497@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
86498
86499 void dma_debug_add_bus(struct bus_type *bus)
86500 {
86501- struct notifier_block *nb;
86502+ notifier_block_no_const *nb;
86503
86504 if (global_disable)
86505 return;
86506@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
86507
86508 static void check_for_stack(struct device *dev, void *addr)
86509 {
86510- if (object_is_on_stack(addr))
86511+ if (object_starts_on_stack(addr))
86512 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
86513 "stack [addr=%p]\n", addr);
86514 }
86515diff --git a/lib/inflate.c b/lib/inflate.c
86516index 013a761..c28f3fc 100644
86517--- a/lib/inflate.c
86518+++ b/lib/inflate.c
86519@@ -269,7 +269,7 @@ static void free(void *where)
86520 malloc_ptr = free_mem_ptr;
86521 }
86522 #else
86523-#define malloc(a) kmalloc(a, GFP_KERNEL)
86524+#define malloc(a) kmalloc((a), GFP_KERNEL)
86525 #define free(a) kfree(a)
86526 #endif
86527
86528diff --git a/lib/ioremap.c b/lib/ioremap.c
86529index 0c9216c..863bd89 100644
86530--- a/lib/ioremap.c
86531+++ b/lib/ioremap.c
86532@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
86533 unsigned long next;
86534
86535 phys_addr -= addr;
86536- pmd = pmd_alloc(&init_mm, pud, addr);
86537+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
86538 if (!pmd)
86539 return -ENOMEM;
86540 do {
86541@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
86542 unsigned long next;
86543
86544 phys_addr -= addr;
86545- pud = pud_alloc(&init_mm, pgd, addr);
86546+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
86547 if (!pud)
86548 return -ENOMEM;
86549 do {
86550diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
86551index bd2bea9..6b3c95e 100644
86552--- a/lib/is_single_threaded.c
86553+++ b/lib/is_single_threaded.c
86554@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
86555 struct task_struct *p, *t;
86556 bool ret;
86557
86558+ if (!mm)
86559+ return true;
86560+
86561 if (atomic_read(&task->signal->live) != 1)
86562 return false;
86563
86564diff --git a/lib/kobject.c b/lib/kobject.c
86565index 084f7b1..d265b8a 100644
86566--- a/lib/kobject.c
86567+++ b/lib/kobject.c
86568@@ -875,9 +875,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
86569
86570
86571 static DEFINE_SPINLOCK(kobj_ns_type_lock);
86572-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
86573+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
86574
86575-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86576+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86577 {
86578 enum kobj_ns_type type = ops->type;
86579 int error;
86580diff --git a/lib/list_debug.c b/lib/list_debug.c
86581index c24c2f7..f0296f4 100644
86582--- a/lib/list_debug.c
86583+++ b/lib/list_debug.c
86584@@ -11,7 +11,9 @@
86585 #include <linux/bug.h>
86586 #include <linux/kernel.h>
86587 #include <linux/rculist.h>
86588+#include <linux/mm.h>
86589
86590+#ifdef CONFIG_DEBUG_LIST
86591 /*
86592 * Insert a new entry between two known consecutive entries.
86593 *
86594@@ -19,21 +21,40 @@
86595 * the prev/next entries already!
86596 */
86597
86598+static bool __list_add_debug(struct list_head *new,
86599+ struct list_head *prev,
86600+ struct list_head *next)
86601+{
86602+ if (unlikely(next->prev != prev)) {
86603+ printk(KERN_ERR "list_add corruption. next->prev should be "
86604+ "prev (%p), but was %p. (next=%p).\n",
86605+ prev, next->prev, next);
86606+ BUG();
86607+ return false;
86608+ }
86609+ if (unlikely(prev->next != next)) {
86610+ printk(KERN_ERR "list_add corruption. prev->next should be "
86611+ "next (%p), but was %p. (prev=%p).\n",
86612+ next, prev->next, prev);
86613+ BUG();
86614+ return false;
86615+ }
86616+ if (unlikely(new == prev || new == next)) {
86617+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
86618+ new, prev, next);
86619+ BUG();
86620+ return false;
86621+ }
86622+ return true;
86623+}
86624+
86625 void __list_add(struct list_head *new,
86626- struct list_head *prev,
86627- struct list_head *next)
86628+ struct list_head *prev,
86629+ struct list_head *next)
86630 {
86631- WARN(next->prev != prev,
86632- "list_add corruption. next->prev should be "
86633- "prev (%p), but was %p. (next=%p).\n",
86634- prev, next->prev, next);
86635- WARN(prev->next != next,
86636- "list_add corruption. prev->next should be "
86637- "next (%p), but was %p. (prev=%p).\n",
86638- next, prev->next, prev);
86639- WARN(new == prev || new == next,
86640- "list_add double add: new=%p, prev=%p, next=%p.\n",
86641- new, prev, next);
86642+ if (!__list_add_debug(new, prev, next))
86643+ return;
86644+
86645 next->prev = new;
86646 new->next = next;
86647 new->prev = prev;
86648@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
86649 }
86650 EXPORT_SYMBOL(__list_add);
86651
86652-void __list_del_entry(struct list_head *entry)
86653+static bool __list_del_entry_debug(struct list_head *entry)
86654 {
86655 struct list_head *prev, *next;
86656
86657 prev = entry->prev;
86658 next = entry->next;
86659
86660- if (WARN(next == LIST_POISON1,
86661- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
86662- entry, LIST_POISON1) ||
86663- WARN(prev == LIST_POISON2,
86664- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
86665- entry, LIST_POISON2) ||
86666- WARN(prev->next != entry,
86667- "list_del corruption. prev->next should be %p, "
86668- "but was %p\n", entry, prev->next) ||
86669- WARN(next->prev != entry,
86670- "list_del corruption. next->prev should be %p, "
86671- "but was %p\n", entry, next->prev))
86672+ if (unlikely(next == LIST_POISON1)) {
86673+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
86674+ entry, LIST_POISON1);
86675+ BUG();
86676+ return false;
86677+ }
86678+ if (unlikely(prev == LIST_POISON2)) {
86679+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
86680+ entry, LIST_POISON2);
86681+ BUG();
86682+ return false;
86683+ }
86684+ if (unlikely(entry->prev->next != entry)) {
86685+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
86686+ "but was %p\n", entry, prev->next);
86687+ BUG();
86688+ return false;
86689+ }
86690+ if (unlikely(entry->next->prev != entry)) {
86691+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
86692+ "but was %p\n", entry, next->prev);
86693+ BUG();
86694+ return false;
86695+ }
86696+ return true;
86697+}
86698+
86699+void __list_del_entry(struct list_head *entry)
86700+{
86701+ if (!__list_del_entry_debug(entry))
86702 return;
86703
86704- __list_del(prev, next);
86705+ __list_del(entry->prev, entry->next);
86706 }
86707 EXPORT_SYMBOL(__list_del_entry);
86708
86709@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
86710 void __list_add_rcu(struct list_head *new,
86711 struct list_head *prev, struct list_head *next)
86712 {
86713- WARN(next->prev != prev,
86714- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
86715- prev, next->prev, next);
86716- WARN(prev->next != next,
86717- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
86718- next, prev->next, prev);
86719+ if (!__list_add_debug(new, prev, next))
86720+ return;
86721+
86722 new->next = next;
86723 new->prev = prev;
86724 rcu_assign_pointer(list_next_rcu(prev), new);
86725 next->prev = new;
86726 }
86727 EXPORT_SYMBOL(__list_add_rcu);
86728+#endif
86729+
86730+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
86731+{
86732+#ifdef CONFIG_DEBUG_LIST
86733+ if (!__list_add_debug(new, prev, next))
86734+ return;
86735+#endif
86736+
86737+ pax_open_kernel();
86738+ next->prev = new;
86739+ new->next = next;
86740+ new->prev = prev;
86741+ prev->next = new;
86742+ pax_close_kernel();
86743+}
86744+EXPORT_SYMBOL(__pax_list_add);
86745+
86746+void pax_list_del(struct list_head *entry)
86747+{
86748+#ifdef CONFIG_DEBUG_LIST
86749+ if (!__list_del_entry_debug(entry))
86750+ return;
86751+#endif
86752+
86753+ pax_open_kernel();
86754+ __list_del(entry->prev, entry->next);
86755+ entry->next = LIST_POISON1;
86756+ entry->prev = LIST_POISON2;
86757+ pax_close_kernel();
86758+}
86759+EXPORT_SYMBOL(pax_list_del);
86760+
86761+void pax_list_del_init(struct list_head *entry)
86762+{
86763+ pax_open_kernel();
86764+ __list_del(entry->prev, entry->next);
86765+ INIT_LIST_HEAD(entry);
86766+ pax_close_kernel();
86767+}
86768+EXPORT_SYMBOL(pax_list_del_init);
86769+
86770+void __pax_list_add_rcu(struct list_head *new,
86771+ struct list_head *prev, struct list_head *next)
86772+{
86773+#ifdef CONFIG_DEBUG_LIST
86774+ if (!__list_add_debug(new, prev, next))
86775+ return;
86776+#endif
86777+
86778+ pax_open_kernel();
86779+ new->next = next;
86780+ new->prev = prev;
86781+ rcu_assign_pointer(list_next_rcu(prev), new);
86782+ next->prev = new;
86783+ pax_close_kernel();
86784+}
86785+EXPORT_SYMBOL(__pax_list_add_rcu);
86786+
86787+void pax_list_del_rcu(struct list_head *entry)
86788+{
86789+#ifdef CONFIG_DEBUG_LIST
86790+ if (!__list_del_entry_debug(entry))
86791+ return;
86792+#endif
86793+
86794+ pax_open_kernel();
86795+ __list_del(entry->prev, entry->next);
86796+ entry->next = LIST_POISON1;
86797+ entry->prev = LIST_POISON2;
86798+ pax_close_kernel();
86799+}
86800+EXPORT_SYMBOL(pax_list_del_rcu);
86801diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
86802index 1a53d49..ace934c 100644
86803--- a/lib/percpu-refcount.c
86804+++ b/lib/percpu-refcount.c
86805@@ -29,7 +29,7 @@
86806 * can't hit 0 before we've added up all the percpu refs.
86807 */
86808
86809-#define PCPU_COUNT_BIAS (1U << 31)
86810+#define PCPU_COUNT_BIAS (1U << 30)
86811
86812 /**
86813 * percpu_ref_init - initialize a percpu refcount
86814diff --git a/lib/radix-tree.c b/lib/radix-tree.c
86815index 7811ed3..f80ca19 100644
86816--- a/lib/radix-tree.c
86817+++ b/lib/radix-tree.c
86818@@ -93,7 +93,7 @@ struct radix_tree_preload {
86819 int nr;
86820 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
86821 };
86822-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
86823+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
86824
86825 static inline void *ptr_to_indirect(void *ptr)
86826 {
86827diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
86828index bb2b201..46abaf9 100644
86829--- a/lib/strncpy_from_user.c
86830+++ b/lib/strncpy_from_user.c
86831@@ -21,7 +21,7 @@
86832 */
86833 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
86834 {
86835- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86836+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86837 long res = 0;
86838
86839 /*
86840diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
86841index a28df52..3d55877 100644
86842--- a/lib/strnlen_user.c
86843+++ b/lib/strnlen_user.c
86844@@ -26,7 +26,7 @@
86845 */
86846 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
86847 {
86848- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86849+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86850 long align, res = 0;
86851 unsigned long c;
86852
86853diff --git a/lib/swiotlb.c b/lib/swiotlb.c
86854index 4e8686c..3e8c92f 100644
86855--- a/lib/swiotlb.c
86856+++ b/lib/swiotlb.c
86857@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
86858
86859 void
86860 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
86861- dma_addr_t dev_addr)
86862+ dma_addr_t dev_addr, struct dma_attrs *attrs)
86863 {
86864 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
86865
86866diff --git a/lib/usercopy.c b/lib/usercopy.c
86867index 4f5b1dd..7cab418 100644
86868--- a/lib/usercopy.c
86869+++ b/lib/usercopy.c
86870@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
86871 WARN(1, "Buffer overflow detected!\n");
86872 }
86873 EXPORT_SYMBOL(copy_from_user_overflow);
86874+
86875+void copy_to_user_overflow(void)
86876+{
86877+ WARN(1, "Buffer overflow detected!\n");
86878+}
86879+EXPORT_SYMBOL(copy_to_user_overflow);
86880diff --git a/lib/vsprintf.c b/lib/vsprintf.c
86881index 26559bd..ed614df 100644
86882--- a/lib/vsprintf.c
86883+++ b/lib/vsprintf.c
86884@@ -16,6 +16,9 @@
86885 * - scnprintf and vscnprintf
86886 */
86887
86888+#ifdef CONFIG_GRKERNSEC_HIDESYM
86889+#define __INCLUDED_BY_HIDESYM 1
86890+#endif
86891 #include <stdarg.h>
86892 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
86893 #include <linux/types.h>
86894@@ -1154,7 +1157,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
86895 return number(buf, end, *(const netdev_features_t *)addr, spec);
86896 }
86897
86898+#ifdef CONFIG_GRKERNSEC_HIDESYM
86899+int kptr_restrict __read_mostly = 2;
86900+#else
86901 int kptr_restrict __read_mostly;
86902+#endif
86903
86904 /*
86905 * Show a '%p' thing. A kernel extension is that the '%p' is followed
86906@@ -1167,6 +1174,7 @@ int kptr_restrict __read_mostly;
86907 * - 'f' For simple symbolic function names without offset
86908 * - 'S' For symbolic direct pointers with offset
86909 * - 's' For symbolic direct pointers without offset
86910+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
86911 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
86912 * - 'B' For backtraced symbolic direct pointers with offset
86913 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
86914@@ -1231,12 +1239,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86915
86916 if (!ptr && *fmt != 'K') {
86917 /*
86918- * Print (null) with the same width as a pointer so it makes
86919+ * Print (nil) with the same width as a pointer so it makes
86920 * tabular output look nice.
86921 */
86922 if (spec.field_width == -1)
86923 spec.field_width = default_width;
86924- return string(buf, end, "(null)", spec);
86925+ return string(buf, end, "(nil)", spec);
86926 }
86927
86928 switch (*fmt) {
86929@@ -1246,6 +1254,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86930 /* Fallthrough */
86931 case 'S':
86932 case 's':
86933+#ifdef CONFIG_GRKERNSEC_HIDESYM
86934+ break;
86935+#else
86936+ return symbol_string(buf, end, ptr, spec, fmt);
86937+#endif
86938+ case 'A':
86939 case 'B':
86940 return symbol_string(buf, end, ptr, spec, fmt);
86941 case 'R':
86942@@ -1301,6 +1315,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86943 va_end(va);
86944 return buf;
86945 }
86946+ case 'P':
86947+ break;
86948 case 'K':
86949 /*
86950 * %pK cannot be used in IRQ context because its test
86951@@ -1336,6 +1352,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86952 ((const struct file *)ptr)->f_path.dentry,
86953 spec, fmt);
86954 }
86955+
86956+#ifdef CONFIG_GRKERNSEC_HIDESYM
86957+ /* 'P' = approved pointers to copy to userland,
86958+ as in the /proc/kallsyms case, as we make it display nothing
86959+ for non-root users, and the real contents for root users
86960+ Also ignore 'K' pointers, since we force their NULLing for non-root users
86961+ above
86962+ */
86963+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
86964+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
86965+ dump_stack();
86966+ ptr = NULL;
86967+ }
86968+#endif
86969+
86970 spec.flags |= SMALL;
86971 if (spec.field_width == -1) {
86972 spec.field_width = default_width;
86973@@ -2059,11 +2090,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
86974 typeof(type) value; \
86975 if (sizeof(type) == 8) { \
86976 args = PTR_ALIGN(args, sizeof(u32)); \
86977- *(u32 *)&value = *(u32 *)args; \
86978- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
86979+ *(u32 *)&value = *(const u32 *)args; \
86980+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
86981 } else { \
86982 args = PTR_ALIGN(args, sizeof(type)); \
86983- value = *(typeof(type) *)args; \
86984+ value = *(const typeof(type) *)args; \
86985 } \
86986 args += sizeof(type); \
86987 value; \
86988@@ -2126,7 +2157,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
86989 case FORMAT_TYPE_STR: {
86990 const char *str_arg = args;
86991 args += strlen(str_arg) + 1;
86992- str = string(str, end, (char *)str_arg, spec);
86993+ str = string(str, end, str_arg, spec);
86994 break;
86995 }
86996
86997diff --git a/localversion-grsec b/localversion-grsec
86998new file mode 100644
86999index 0000000..7cd6065
87000--- /dev/null
87001+++ b/localversion-grsec
87002@@ -0,0 +1 @@
87003+-grsec
87004diff --git a/mm/Kconfig b/mm/Kconfig
87005index 394838f..0e5f816 100644
87006--- a/mm/Kconfig
87007+++ b/mm/Kconfig
87008@@ -317,10 +317,11 @@ config KSM
87009 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
87010
87011 config DEFAULT_MMAP_MIN_ADDR
87012- int "Low address space to protect from user allocation"
87013+ int "Low address space to protect from user allocation"
87014 depends on MMU
87015- default 4096
87016- help
87017+ default 32768 if ALPHA || ARM || PARISC || SPARC32
87018+ default 65536
87019+ help
87020 This is the portion of low virtual memory which should be protected
87021 from userspace allocation. Keeping a user from writing to low pages
87022 can help reduce the impact of kernel NULL pointer bugs.
87023@@ -351,7 +352,7 @@ config MEMORY_FAILURE
87024
87025 config HWPOISON_INJECT
87026 tristate "HWPoison pages injector"
87027- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
87028+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
87029 select PROC_PAGE_MONITOR
87030
87031 config NOMMU_INITIAL_TRIM_EXCESS
87032diff --git a/mm/backing-dev.c b/mm/backing-dev.c
87033index ce682f7..1fb54f9 100644
87034--- a/mm/backing-dev.c
87035+++ b/mm/backing-dev.c
87036@@ -12,7 +12,7 @@
87037 #include <linux/device.h>
87038 #include <trace/events/writeback.h>
87039
87040-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
87041+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
87042
87043 struct backing_dev_info default_backing_dev_info = {
87044 .name = "default",
87045@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
87046 return err;
87047
87048 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
87049- atomic_long_inc_return(&bdi_seq));
87050+ atomic_long_inc_return_unchecked(&bdi_seq));
87051 if (err) {
87052 bdi_destroy(bdi);
87053 return err;
87054diff --git a/mm/filemap.c b/mm/filemap.c
87055index ae4846f..b0acebe 100644
87056--- a/mm/filemap.c
87057+++ b/mm/filemap.c
87058@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
87059 struct address_space *mapping = file->f_mapping;
87060
87061 if (!mapping->a_ops->readpage)
87062- return -ENOEXEC;
87063+ return -ENODEV;
87064 file_accessed(file);
87065 vma->vm_ops = &generic_file_vm_ops;
87066 return 0;
87067@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
87068
87069 while (bytes) {
87070 char __user *buf = iov->iov_base + base;
87071- int copy = min(bytes, iov->iov_len - base);
87072+ size_t copy = min(bytes, iov->iov_len - base);
87073
87074 base = 0;
87075 left = __copy_from_user_inatomic(vaddr, buf, copy);
87076@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
87077 BUG_ON(!in_atomic());
87078 kaddr = kmap_atomic(page);
87079 if (likely(i->nr_segs == 1)) {
87080- int left;
87081+ size_t left;
87082 char __user *buf = i->iov->iov_base + i->iov_offset;
87083 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
87084 copied = bytes - left;
87085@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
87086
87087 kaddr = kmap(page);
87088 if (likely(i->nr_segs == 1)) {
87089- int left;
87090+ size_t left;
87091 char __user *buf = i->iov->iov_base + i->iov_offset;
87092 left = __copy_from_user(kaddr + offset, buf, bytes);
87093 copied = bytes - left;
87094@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
87095 * zero-length segments (without overruning the iovec).
87096 */
87097 while (bytes || unlikely(i->count && !iov->iov_len)) {
87098- int copy;
87099+ size_t copy;
87100
87101 copy = min(bytes, iov->iov_len - base);
87102 BUG_ON(!i->count || i->count < copy);
87103@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
87104 *pos = i_size_read(inode);
87105
87106 if (limit != RLIM_INFINITY) {
87107+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
87108 if (*pos >= limit) {
87109 send_sig(SIGXFSZ, current, 0);
87110 return -EFBIG;
87111diff --git a/mm/fremap.c b/mm/fremap.c
87112index 5bff081..d8189a9 100644
87113--- a/mm/fremap.c
87114+++ b/mm/fremap.c
87115@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
87116 retry:
87117 vma = find_vma(mm, start);
87118
87119+#ifdef CONFIG_PAX_SEGMEXEC
87120+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
87121+ goto out;
87122+#endif
87123+
87124 /*
87125 * Make sure the vma is shared, that it supports prefaulting,
87126 * and that the remapped range is valid and fully within
87127diff --git a/mm/highmem.c b/mm/highmem.c
87128index b32b70c..e512eb0 100644
87129--- a/mm/highmem.c
87130+++ b/mm/highmem.c
87131@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
87132 * So no dangers, even with speculative execution.
87133 */
87134 page = pte_page(pkmap_page_table[i]);
87135+ pax_open_kernel();
87136 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
87137-
87138+ pax_close_kernel();
87139 set_page_address(page, NULL);
87140 need_flush = 1;
87141 }
87142@@ -198,9 +199,11 @@ start:
87143 }
87144 }
87145 vaddr = PKMAP_ADDR(last_pkmap_nr);
87146+
87147+ pax_open_kernel();
87148 set_pte_at(&init_mm, vaddr,
87149 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
87150-
87151+ pax_close_kernel();
87152 pkmap_count[last_pkmap_nr] = 1;
87153 set_page_address(page, (void *)vaddr);
87154
87155diff --git a/mm/hugetlb.c b/mm/hugetlb.c
87156index 0b7656e..d21cefc 100644
87157--- a/mm/hugetlb.c
87158+++ b/mm/hugetlb.c
87159@@ -2094,15 +2094,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
87160 struct hstate *h = &default_hstate;
87161 unsigned long tmp;
87162 int ret;
87163+ ctl_table_no_const hugetlb_table;
87164
87165 tmp = h->max_huge_pages;
87166
87167 if (write && h->order >= MAX_ORDER)
87168 return -EINVAL;
87169
87170- table->data = &tmp;
87171- table->maxlen = sizeof(unsigned long);
87172- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87173+ hugetlb_table = *table;
87174+ hugetlb_table.data = &tmp;
87175+ hugetlb_table.maxlen = sizeof(unsigned long);
87176+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87177 if (ret)
87178 goto out;
87179
87180@@ -2147,15 +2149,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
87181 struct hstate *h = &default_hstate;
87182 unsigned long tmp;
87183 int ret;
87184+ ctl_table_no_const hugetlb_table;
87185
87186 tmp = h->nr_overcommit_huge_pages;
87187
87188 if (write && h->order >= MAX_ORDER)
87189 return -EINVAL;
87190
87191- table->data = &tmp;
87192- table->maxlen = sizeof(unsigned long);
87193- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87194+ hugetlb_table = *table;
87195+ hugetlb_table.data = &tmp;
87196+ hugetlb_table.maxlen = sizeof(unsigned long);
87197+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87198 if (ret)
87199 goto out;
87200
87201@@ -2605,6 +2609,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
87202 return 1;
87203 }
87204
87205+#ifdef CONFIG_PAX_SEGMEXEC
87206+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
87207+{
87208+ struct mm_struct *mm = vma->vm_mm;
87209+ struct vm_area_struct *vma_m;
87210+ unsigned long address_m;
87211+ pte_t *ptep_m;
87212+
87213+ vma_m = pax_find_mirror_vma(vma);
87214+ if (!vma_m)
87215+ return;
87216+
87217+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87218+ address_m = address + SEGMEXEC_TASK_SIZE;
87219+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
87220+ get_page(page_m);
87221+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
87222+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
87223+}
87224+#endif
87225+
87226 /*
87227 * Hugetlb_cow() should be called with page lock of the original hugepage held.
87228 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
87229@@ -2721,6 +2746,11 @@ retry_avoidcopy:
87230 make_huge_pte(vma, new_page, 1));
87231 page_remove_rmap(old_page);
87232 hugepage_add_new_anon_rmap(new_page, vma, address);
87233+
87234+#ifdef CONFIG_PAX_SEGMEXEC
87235+ pax_mirror_huge_pte(vma, address, new_page);
87236+#endif
87237+
87238 /* Make the old page be freed below */
87239 new_page = old_page;
87240 }
87241@@ -2883,6 +2913,10 @@ retry:
87242 && (vma->vm_flags & VM_SHARED)));
87243 set_huge_pte_at(mm, address, ptep, new_pte);
87244
87245+#ifdef CONFIG_PAX_SEGMEXEC
87246+ pax_mirror_huge_pte(vma, address, page);
87247+#endif
87248+
87249 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
87250 /* Optimization, do the COW without a second fault */
87251 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
87252@@ -2912,6 +2946,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87253 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
87254 struct hstate *h = hstate_vma(vma);
87255
87256+#ifdef CONFIG_PAX_SEGMEXEC
87257+ struct vm_area_struct *vma_m;
87258+#endif
87259+
87260 address &= huge_page_mask(h);
87261
87262 ptep = huge_pte_offset(mm, address);
87263@@ -2925,6 +2963,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87264 VM_FAULT_SET_HINDEX(hstate_index(h));
87265 }
87266
87267+#ifdef CONFIG_PAX_SEGMEXEC
87268+ vma_m = pax_find_mirror_vma(vma);
87269+ if (vma_m) {
87270+ unsigned long address_m;
87271+
87272+ if (vma->vm_start > vma_m->vm_start) {
87273+ address_m = address;
87274+ address -= SEGMEXEC_TASK_SIZE;
87275+ vma = vma_m;
87276+ h = hstate_vma(vma);
87277+ } else
87278+ address_m = address + SEGMEXEC_TASK_SIZE;
87279+
87280+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
87281+ return VM_FAULT_OOM;
87282+ address_m &= HPAGE_MASK;
87283+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
87284+ }
87285+#endif
87286+
87287 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
87288 if (!ptep)
87289 return VM_FAULT_OOM;
87290diff --git a/mm/internal.h b/mm/internal.h
87291index 684f7aa..9eb9edc 100644
87292--- a/mm/internal.h
87293+++ b/mm/internal.h
87294@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
87295 * in mm/page_alloc.c
87296 */
87297 extern void __free_pages_bootmem(struct page *page, unsigned int order);
87298+extern void free_compound_page(struct page *page);
87299 extern void prep_compound_page(struct page *page, unsigned long order);
87300 #ifdef CONFIG_MEMORY_FAILURE
87301 extern bool is_free_buddy_page(struct page *page);
87302@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
87303
87304 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
87305 unsigned long, unsigned long,
87306- unsigned long, unsigned long);
87307+ unsigned long, unsigned long) __intentional_overflow(-1);
87308
87309 extern void set_pageblock_order(void);
87310 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
87311diff --git a/mm/kmemleak.c b/mm/kmemleak.c
87312index e126b0e..e986018 100644
87313--- a/mm/kmemleak.c
87314+++ b/mm/kmemleak.c
87315@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
87316
87317 for (i = 0; i < object->trace_len; i++) {
87318 void *ptr = (void *)object->trace[i];
87319- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
87320+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
87321 }
87322 }
87323
87324@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
87325 return -ENOMEM;
87326 }
87327
87328- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
87329+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
87330 &kmemleak_fops);
87331 if (!dentry)
87332 pr_warning("Failed to create the debugfs kmemleak file\n");
87333diff --git a/mm/maccess.c b/mm/maccess.c
87334index d53adf9..03a24bf 100644
87335--- a/mm/maccess.c
87336+++ b/mm/maccess.c
87337@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
87338 set_fs(KERNEL_DS);
87339 pagefault_disable();
87340 ret = __copy_from_user_inatomic(dst,
87341- (__force const void __user *)src, size);
87342+ (const void __force_user *)src, size);
87343 pagefault_enable();
87344 set_fs(old_fs);
87345
87346@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
87347
87348 set_fs(KERNEL_DS);
87349 pagefault_disable();
87350- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
87351+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
87352 pagefault_enable();
87353 set_fs(old_fs);
87354
87355diff --git a/mm/madvise.c b/mm/madvise.c
87356index 539eeb9..e24a987 100644
87357--- a/mm/madvise.c
87358+++ b/mm/madvise.c
87359@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
87360 pgoff_t pgoff;
87361 unsigned long new_flags = vma->vm_flags;
87362
87363+#ifdef CONFIG_PAX_SEGMEXEC
87364+ struct vm_area_struct *vma_m;
87365+#endif
87366+
87367 switch (behavior) {
87368 case MADV_NORMAL:
87369 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
87370@@ -126,6 +130,13 @@ success:
87371 /*
87372 * vm_flags is protected by the mmap_sem held in write mode.
87373 */
87374+
87375+#ifdef CONFIG_PAX_SEGMEXEC
87376+ vma_m = pax_find_mirror_vma(vma);
87377+ if (vma_m)
87378+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
87379+#endif
87380+
87381 vma->vm_flags = new_flags;
87382
87383 out:
87384@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
87385 struct vm_area_struct **prev,
87386 unsigned long start, unsigned long end)
87387 {
87388+
87389+#ifdef CONFIG_PAX_SEGMEXEC
87390+ struct vm_area_struct *vma_m;
87391+#endif
87392+
87393 *prev = vma;
87394 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
87395 return -EINVAL;
87396@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
87397 zap_page_range(vma, start, end - start, &details);
87398 } else
87399 zap_page_range(vma, start, end - start, NULL);
87400+
87401+#ifdef CONFIG_PAX_SEGMEXEC
87402+ vma_m = pax_find_mirror_vma(vma);
87403+ if (vma_m) {
87404+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
87405+ struct zap_details details = {
87406+ .nonlinear_vma = vma_m,
87407+ .last_index = ULONG_MAX,
87408+ };
87409+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
87410+ } else
87411+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
87412+ }
87413+#endif
87414+
87415 return 0;
87416 }
87417
87418@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
87419 if (end < start)
87420 return error;
87421
87422+#ifdef CONFIG_PAX_SEGMEXEC
87423+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
87424+ if (end > SEGMEXEC_TASK_SIZE)
87425+ return error;
87426+ } else
87427+#endif
87428+
87429+ if (end > TASK_SIZE)
87430+ return error;
87431+
87432 error = 0;
87433 if (end == start)
87434 return error;
87435diff --git a/mm/memory-failure.c b/mm/memory-failure.c
87436index bf3351b..aea800d 100644
87437--- a/mm/memory-failure.c
87438+++ b/mm/memory-failure.c
87439@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
87440
87441 int sysctl_memory_failure_recovery __read_mostly = 1;
87442
87443-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87444+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87445
87446 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
87447
87448@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
87449 pfn, t->comm, t->pid);
87450 si.si_signo = SIGBUS;
87451 si.si_errno = 0;
87452- si.si_addr = (void *)addr;
87453+ si.si_addr = (void __user *)addr;
87454 #ifdef __ARCH_SI_TRAPNO
87455 si.si_trapno = trapno;
87456 #endif
87457@@ -762,7 +762,7 @@ static struct page_state {
87458 unsigned long res;
87459 char *msg;
87460 int (*action)(struct page *p, unsigned long pfn);
87461-} error_states[] = {
87462+} __do_const error_states[] = {
87463 { reserved, reserved, "reserved kernel", me_kernel },
87464 /*
87465 * free pages are specially detected outside this table:
87466@@ -1053,7 +1053,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87467 nr_pages = 1 << compound_order(hpage);
87468 else /* normal page or thp */
87469 nr_pages = 1;
87470- atomic_long_add(nr_pages, &num_poisoned_pages);
87471+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
87472
87473 /*
87474 * We need/can do nothing about count=0 pages.
87475@@ -1083,7 +1083,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87476 if (!PageHWPoison(hpage)
87477 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
87478 || (p != hpage && TestSetPageHWPoison(hpage))) {
87479- atomic_long_sub(nr_pages, &num_poisoned_pages);
87480+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87481 return 0;
87482 }
87483 set_page_hwpoison_huge_page(hpage);
87484@@ -1152,7 +1152,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87485 }
87486 if (hwpoison_filter(p)) {
87487 if (TestClearPageHWPoison(p))
87488- atomic_long_sub(nr_pages, &num_poisoned_pages);
87489+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87490 unlock_page(hpage);
87491 put_page(hpage);
87492 return 0;
87493@@ -1370,7 +1370,7 @@ int unpoison_memory(unsigned long pfn)
87494 return 0;
87495 }
87496 if (TestClearPageHWPoison(p))
87497- atomic_long_dec(&num_poisoned_pages);
87498+ atomic_long_dec_unchecked(&num_poisoned_pages);
87499 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
87500 return 0;
87501 }
87502@@ -1384,7 +1384,7 @@ int unpoison_memory(unsigned long pfn)
87503 */
87504 if (TestClearPageHWPoison(page)) {
87505 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
87506- atomic_long_sub(nr_pages, &num_poisoned_pages);
87507+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87508 freeit = 1;
87509 if (PageHuge(page))
87510 clear_page_hwpoison_huge_page(page);
87511@@ -1521,7 +1521,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
87512 } else {
87513 set_page_hwpoison_huge_page(hpage);
87514 dequeue_hwpoisoned_huge_page(hpage);
87515- atomic_long_add(1 << compound_order(hpage),
87516+ atomic_long_add_unchecked(1 << compound_order(hpage),
87517 &num_poisoned_pages);
87518 }
87519 return ret;
87520@@ -1560,7 +1560,7 @@ static int __soft_offline_page(struct page *page, int flags)
87521 put_page(page);
87522 pr_info("soft_offline: %#lx: invalidated\n", pfn);
87523 SetPageHWPoison(page);
87524- atomic_long_inc(&num_poisoned_pages);
87525+ atomic_long_inc_unchecked(&num_poisoned_pages);
87526 return 0;
87527 }
87528
87529@@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
87530 if (!is_free_buddy_page(page))
87531 pr_info("soft offline: %#lx: page leaked\n",
87532 pfn);
87533- atomic_long_inc(&num_poisoned_pages);
87534+ atomic_long_inc_unchecked(&num_poisoned_pages);
87535 }
87536 } else {
87537 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
87538@@ -1666,11 +1666,11 @@ int soft_offline_page(struct page *page, int flags)
87539 if (PageHuge(page)) {
87540 set_page_hwpoison_huge_page(hpage);
87541 dequeue_hwpoisoned_huge_page(hpage);
87542- atomic_long_add(1 << compound_order(hpage),
87543+ atomic_long_add_unchecked(1 << compound_order(hpage),
87544 &num_poisoned_pages);
87545 } else {
87546 SetPageHWPoison(page);
87547- atomic_long_inc(&num_poisoned_pages);
87548+ atomic_long_inc_unchecked(&num_poisoned_pages);
87549 }
87550 }
87551 unset:
87552diff --git a/mm/memory.c b/mm/memory.c
87553index d176154..cd1b387 100644
87554--- a/mm/memory.c
87555+++ b/mm/memory.c
87556@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87557 free_pte_range(tlb, pmd, addr);
87558 } while (pmd++, addr = next, addr != end);
87559
87560+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
87561 start &= PUD_MASK;
87562 if (start < floor)
87563 return;
87564@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87565 pmd = pmd_offset(pud, start);
87566 pud_clear(pud);
87567 pmd_free_tlb(tlb, pmd, start);
87568+#endif
87569+
87570 }
87571
87572 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87573@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87574 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
87575 } while (pud++, addr = next, addr != end);
87576
87577+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
87578 start &= PGDIR_MASK;
87579 if (start < floor)
87580 return;
87581@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87582 pud = pud_offset(pgd, start);
87583 pgd_clear(pgd);
87584 pud_free_tlb(tlb, pud, start);
87585+#endif
87586+
87587 }
87588
87589 /*
87590@@ -1636,12 +1642,6 @@ no_page_table:
87591 return page;
87592 }
87593
87594-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
87595-{
87596- return stack_guard_page_start(vma, addr) ||
87597- stack_guard_page_end(vma, addr+PAGE_SIZE);
87598-}
87599-
87600 /**
87601 * __get_user_pages() - pin user pages in memory
87602 * @tsk: task_struct of target task
87603@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87604
87605 i = 0;
87606
87607- do {
87608+ while (nr_pages) {
87609 struct vm_area_struct *vma;
87610
87611- vma = find_extend_vma(mm, start);
87612+ vma = find_vma(mm, start);
87613 if (!vma && in_gate_area(mm, start)) {
87614 unsigned long pg = start & PAGE_MASK;
87615 pgd_t *pgd;
87616@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87617 goto next_page;
87618 }
87619
87620- if (!vma ||
87621+ if (!vma || start < vma->vm_start ||
87622 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
87623 !(vm_flags & vma->vm_flags))
87624 return i ? : -EFAULT;
87625@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87626 int ret;
87627 unsigned int fault_flags = 0;
87628
87629- /* For mlock, just skip the stack guard page. */
87630- if (foll_flags & FOLL_MLOCK) {
87631- if (stack_guard_page(vma, start))
87632- goto next_page;
87633- }
87634 if (foll_flags & FOLL_WRITE)
87635 fault_flags |= FAULT_FLAG_WRITE;
87636 if (nonblocking)
87637@@ -1893,7 +1888,7 @@ next_page:
87638 start += page_increm * PAGE_SIZE;
87639 nr_pages -= page_increm;
87640 } while (nr_pages && start < vma->vm_end);
87641- } while (nr_pages);
87642+ }
87643 return i;
87644 }
87645 EXPORT_SYMBOL(__get_user_pages);
87646@@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
87647 page_add_file_rmap(page);
87648 set_pte_at(mm, addr, pte, mk_pte(page, prot));
87649
87650+#ifdef CONFIG_PAX_SEGMEXEC
87651+ pax_mirror_file_pte(vma, addr, page, ptl);
87652+#endif
87653+
87654 retval = 0;
87655 pte_unmap_unlock(pte, ptl);
87656 return retval;
87657@@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
87658 if (!page_count(page))
87659 return -EINVAL;
87660 if (!(vma->vm_flags & VM_MIXEDMAP)) {
87661+
87662+#ifdef CONFIG_PAX_SEGMEXEC
87663+ struct vm_area_struct *vma_m;
87664+#endif
87665+
87666 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
87667 BUG_ON(vma->vm_flags & VM_PFNMAP);
87668 vma->vm_flags |= VM_MIXEDMAP;
87669+
87670+#ifdef CONFIG_PAX_SEGMEXEC
87671+ vma_m = pax_find_mirror_vma(vma);
87672+ if (vma_m)
87673+ vma_m->vm_flags |= VM_MIXEDMAP;
87674+#endif
87675+
87676 }
87677 return insert_page(vma, addr, page, vma->vm_page_prot);
87678 }
87679@@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
87680 unsigned long pfn)
87681 {
87682 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
87683+ BUG_ON(vma->vm_mirror);
87684
87685 if (addr < vma->vm_start || addr >= vma->vm_end)
87686 return -EFAULT;
87687@@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
87688
87689 BUG_ON(pud_huge(*pud));
87690
87691- pmd = pmd_alloc(mm, pud, addr);
87692+ pmd = (mm == &init_mm) ?
87693+ pmd_alloc_kernel(mm, pud, addr) :
87694+ pmd_alloc(mm, pud, addr);
87695 if (!pmd)
87696 return -ENOMEM;
87697 do {
87698@@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
87699 unsigned long next;
87700 int err;
87701
87702- pud = pud_alloc(mm, pgd, addr);
87703+ pud = (mm == &init_mm) ?
87704+ pud_alloc_kernel(mm, pgd, addr) :
87705+ pud_alloc(mm, pgd, addr);
87706 if (!pud)
87707 return -ENOMEM;
87708 do {
87709@@ -2584,6 +2600,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
87710 copy_user_highpage(dst, src, va, vma);
87711 }
87712
87713+#ifdef CONFIG_PAX_SEGMEXEC
87714+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
87715+{
87716+ struct mm_struct *mm = vma->vm_mm;
87717+ spinlock_t *ptl;
87718+ pte_t *pte, entry;
87719+
87720+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
87721+ entry = *pte;
87722+ if (!pte_present(entry)) {
87723+ if (!pte_none(entry)) {
87724+ BUG_ON(pte_file(entry));
87725+ free_swap_and_cache(pte_to_swp_entry(entry));
87726+ pte_clear_not_present_full(mm, address, pte, 0);
87727+ }
87728+ } else {
87729+ struct page *page;
87730+
87731+ flush_cache_page(vma, address, pte_pfn(entry));
87732+ entry = ptep_clear_flush(vma, address, pte);
87733+ BUG_ON(pte_dirty(entry));
87734+ page = vm_normal_page(vma, address, entry);
87735+ if (page) {
87736+ update_hiwater_rss(mm);
87737+ if (PageAnon(page))
87738+ dec_mm_counter_fast(mm, MM_ANONPAGES);
87739+ else
87740+ dec_mm_counter_fast(mm, MM_FILEPAGES);
87741+ page_remove_rmap(page);
87742+ page_cache_release(page);
87743+ }
87744+ }
87745+ pte_unmap_unlock(pte, ptl);
87746+}
87747+
87748+/* PaX: if vma is mirrored, synchronize the mirror's PTE
87749+ *
87750+ * the ptl of the lower mapped page is held on entry and is not released on exit
87751+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
87752+ */
87753+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87754+{
87755+ struct mm_struct *mm = vma->vm_mm;
87756+ unsigned long address_m;
87757+ spinlock_t *ptl_m;
87758+ struct vm_area_struct *vma_m;
87759+ pmd_t *pmd_m;
87760+ pte_t *pte_m, entry_m;
87761+
87762+ BUG_ON(!page_m || !PageAnon(page_m));
87763+
87764+ vma_m = pax_find_mirror_vma(vma);
87765+ if (!vma_m)
87766+ return;
87767+
87768+ BUG_ON(!PageLocked(page_m));
87769+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87770+ address_m = address + SEGMEXEC_TASK_SIZE;
87771+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87772+ pte_m = pte_offset_map(pmd_m, address_m);
87773+ ptl_m = pte_lockptr(mm, pmd_m);
87774+ if (ptl != ptl_m) {
87775+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87776+ if (!pte_none(*pte_m))
87777+ goto out;
87778+ }
87779+
87780+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
87781+ page_cache_get(page_m);
87782+ page_add_anon_rmap(page_m, vma_m, address_m);
87783+ inc_mm_counter_fast(mm, MM_ANONPAGES);
87784+ set_pte_at(mm, address_m, pte_m, entry_m);
87785+ update_mmu_cache(vma_m, address_m, pte_m);
87786+out:
87787+ if (ptl != ptl_m)
87788+ spin_unlock(ptl_m);
87789+ pte_unmap(pte_m);
87790+ unlock_page(page_m);
87791+}
87792+
87793+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87794+{
87795+ struct mm_struct *mm = vma->vm_mm;
87796+ unsigned long address_m;
87797+ spinlock_t *ptl_m;
87798+ struct vm_area_struct *vma_m;
87799+ pmd_t *pmd_m;
87800+ pte_t *pte_m, entry_m;
87801+
87802+ BUG_ON(!page_m || PageAnon(page_m));
87803+
87804+ vma_m = pax_find_mirror_vma(vma);
87805+ if (!vma_m)
87806+ return;
87807+
87808+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87809+ address_m = address + SEGMEXEC_TASK_SIZE;
87810+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87811+ pte_m = pte_offset_map(pmd_m, address_m);
87812+ ptl_m = pte_lockptr(mm, pmd_m);
87813+ if (ptl != ptl_m) {
87814+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87815+ if (!pte_none(*pte_m))
87816+ goto out;
87817+ }
87818+
87819+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
87820+ page_cache_get(page_m);
87821+ page_add_file_rmap(page_m);
87822+ inc_mm_counter_fast(mm, MM_FILEPAGES);
87823+ set_pte_at(mm, address_m, pte_m, entry_m);
87824+ update_mmu_cache(vma_m, address_m, pte_m);
87825+out:
87826+ if (ptl != ptl_m)
87827+ spin_unlock(ptl_m);
87828+ pte_unmap(pte_m);
87829+}
87830+
87831+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
87832+{
87833+ struct mm_struct *mm = vma->vm_mm;
87834+ unsigned long address_m;
87835+ spinlock_t *ptl_m;
87836+ struct vm_area_struct *vma_m;
87837+ pmd_t *pmd_m;
87838+ pte_t *pte_m, entry_m;
87839+
87840+ vma_m = pax_find_mirror_vma(vma);
87841+ if (!vma_m)
87842+ return;
87843+
87844+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87845+ address_m = address + SEGMEXEC_TASK_SIZE;
87846+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87847+ pte_m = pte_offset_map(pmd_m, address_m);
87848+ ptl_m = pte_lockptr(mm, pmd_m);
87849+ if (ptl != ptl_m) {
87850+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87851+ if (!pte_none(*pte_m))
87852+ goto out;
87853+ }
87854+
87855+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
87856+ set_pte_at(mm, address_m, pte_m, entry_m);
87857+out:
87858+ if (ptl != ptl_m)
87859+ spin_unlock(ptl_m);
87860+ pte_unmap(pte_m);
87861+}
87862+
87863+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
87864+{
87865+ struct page *page_m;
87866+ pte_t entry;
87867+
87868+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
87869+ goto out;
87870+
87871+ entry = *pte;
87872+ page_m = vm_normal_page(vma, address, entry);
87873+ if (!page_m)
87874+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
87875+ else if (PageAnon(page_m)) {
87876+ if (pax_find_mirror_vma(vma)) {
87877+ pte_unmap_unlock(pte, ptl);
87878+ lock_page(page_m);
87879+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
87880+ if (pte_same(entry, *pte))
87881+ pax_mirror_anon_pte(vma, address, page_m, ptl);
87882+ else
87883+ unlock_page(page_m);
87884+ }
87885+ } else
87886+ pax_mirror_file_pte(vma, address, page_m, ptl);
87887+
87888+out:
87889+ pte_unmap_unlock(pte, ptl);
87890+}
87891+#endif
87892+
87893 /*
87894 * This routine handles present pages, when users try to write
87895 * to a shared page. It is done by copying the page to a new address
87896@@ -2800,6 +2996,12 @@ gotten:
87897 */
87898 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
87899 if (likely(pte_same(*page_table, orig_pte))) {
87900+
87901+#ifdef CONFIG_PAX_SEGMEXEC
87902+ if (pax_find_mirror_vma(vma))
87903+ BUG_ON(!trylock_page(new_page));
87904+#endif
87905+
87906 if (old_page) {
87907 if (!PageAnon(old_page)) {
87908 dec_mm_counter_fast(mm, MM_FILEPAGES);
87909@@ -2851,6 +3053,10 @@ gotten:
87910 page_remove_rmap(old_page);
87911 }
87912
87913+#ifdef CONFIG_PAX_SEGMEXEC
87914+ pax_mirror_anon_pte(vma, address, new_page, ptl);
87915+#endif
87916+
87917 /* Free the old page.. */
87918 new_page = old_page;
87919 ret |= VM_FAULT_WRITE;
87920@@ -3128,6 +3334,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
87921 swap_free(entry);
87922 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
87923 try_to_free_swap(page);
87924+
87925+#ifdef CONFIG_PAX_SEGMEXEC
87926+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
87927+#endif
87928+
87929 unlock_page(page);
87930 if (page != swapcache) {
87931 /*
87932@@ -3151,6 +3362,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
87933
87934 /* No need to invalidate - it was non-present before */
87935 update_mmu_cache(vma, address, page_table);
87936+
87937+#ifdef CONFIG_PAX_SEGMEXEC
87938+ pax_mirror_anon_pte(vma, address, page, ptl);
87939+#endif
87940+
87941 unlock:
87942 pte_unmap_unlock(page_table, ptl);
87943 out:
87944@@ -3170,40 +3386,6 @@ out_release:
87945 }
87946
87947 /*
87948- * This is like a special single-page "expand_{down|up}wards()",
87949- * except we must first make sure that 'address{-|+}PAGE_SIZE'
87950- * doesn't hit another vma.
87951- */
87952-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
87953-{
87954- address &= PAGE_MASK;
87955- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
87956- struct vm_area_struct *prev = vma->vm_prev;
87957-
87958- /*
87959- * Is there a mapping abutting this one below?
87960- *
87961- * That's only ok if it's the same stack mapping
87962- * that has gotten split..
87963- */
87964- if (prev && prev->vm_end == address)
87965- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
87966-
87967- expand_downwards(vma, address - PAGE_SIZE);
87968- }
87969- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
87970- struct vm_area_struct *next = vma->vm_next;
87971-
87972- /* As VM_GROWSDOWN but s/below/above/ */
87973- if (next && next->vm_start == address + PAGE_SIZE)
87974- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
87975-
87976- expand_upwards(vma, address + PAGE_SIZE);
87977- }
87978- return 0;
87979-}
87980-
87981-/*
87982 * We enter with non-exclusive mmap_sem (to exclude vma changes,
87983 * but allow concurrent faults), and pte mapped but not yet locked.
87984 * We return with mmap_sem still held, but pte unmapped and unlocked.
87985@@ -3212,27 +3394,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
87986 unsigned long address, pte_t *page_table, pmd_t *pmd,
87987 unsigned int flags)
87988 {
87989- struct page *page;
87990+ struct page *page = NULL;
87991 spinlock_t *ptl;
87992 pte_t entry;
87993
87994- pte_unmap(page_table);
87995-
87996- /* Check if we need to add a guard page to the stack */
87997- if (check_stack_guard_page(vma, address) < 0)
87998- return VM_FAULT_SIGBUS;
87999-
88000- /* Use the zero-page for reads */
88001 if (!(flags & FAULT_FLAG_WRITE)) {
88002 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
88003 vma->vm_page_prot));
88004- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88005+ ptl = pte_lockptr(mm, pmd);
88006+ spin_lock(ptl);
88007 if (!pte_none(*page_table))
88008 goto unlock;
88009 goto setpte;
88010 }
88011
88012 /* Allocate our own private page. */
88013+ pte_unmap(page_table);
88014+
88015 if (unlikely(anon_vma_prepare(vma)))
88016 goto oom;
88017 page = alloc_zeroed_user_highpage_movable(vma, address);
88018@@ -3256,6 +3434,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88019 if (!pte_none(*page_table))
88020 goto release;
88021
88022+#ifdef CONFIG_PAX_SEGMEXEC
88023+ if (pax_find_mirror_vma(vma))
88024+ BUG_ON(!trylock_page(page));
88025+#endif
88026+
88027 inc_mm_counter_fast(mm, MM_ANONPAGES);
88028 page_add_new_anon_rmap(page, vma, address);
88029 setpte:
88030@@ -3263,6 +3446,12 @@ setpte:
88031
88032 /* No need to invalidate - it was non-present before */
88033 update_mmu_cache(vma, address, page_table);
88034+
88035+#ifdef CONFIG_PAX_SEGMEXEC
88036+ if (page)
88037+ pax_mirror_anon_pte(vma, address, page, ptl);
88038+#endif
88039+
88040 unlock:
88041 pte_unmap_unlock(page_table, ptl);
88042 return 0;
88043@@ -3406,6 +3595,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88044 */
88045 /* Only go through if we didn't race with anybody else... */
88046 if (likely(pte_same(*page_table, orig_pte))) {
88047+
88048+#ifdef CONFIG_PAX_SEGMEXEC
88049+ if (anon && pax_find_mirror_vma(vma))
88050+ BUG_ON(!trylock_page(page));
88051+#endif
88052+
88053 flush_icache_page(vma, page);
88054 entry = mk_pte(page, vma->vm_page_prot);
88055 if (flags & FAULT_FLAG_WRITE)
88056@@ -3427,6 +3622,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88057
88058 /* no need to invalidate: a not-present page won't be cached */
88059 update_mmu_cache(vma, address, page_table);
88060+
88061+#ifdef CONFIG_PAX_SEGMEXEC
88062+ if (anon)
88063+ pax_mirror_anon_pte(vma, address, page, ptl);
88064+ else
88065+ pax_mirror_file_pte(vma, address, page, ptl);
88066+#endif
88067+
88068 } else {
88069 if (cow_page)
88070 mem_cgroup_uncharge_page(cow_page);
88071@@ -3737,6 +3940,12 @@ static int handle_pte_fault(struct mm_struct *mm,
88072 if (flags & FAULT_FLAG_WRITE)
88073 flush_tlb_fix_spurious_fault(vma, address);
88074 }
88075+
88076+#ifdef CONFIG_PAX_SEGMEXEC
88077+ pax_mirror_pte(vma, address, pte, pmd, ptl);
88078+ return 0;
88079+#endif
88080+
88081 unlock:
88082 pte_unmap_unlock(pte, ptl);
88083 return 0;
88084@@ -3753,9 +3962,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88085 pmd_t *pmd;
88086 pte_t *pte;
88087
88088+#ifdef CONFIG_PAX_SEGMEXEC
88089+ struct vm_area_struct *vma_m;
88090+#endif
88091+
88092 if (unlikely(is_vm_hugetlb_page(vma)))
88093 return hugetlb_fault(mm, vma, address, flags);
88094
88095+#ifdef CONFIG_PAX_SEGMEXEC
88096+ vma_m = pax_find_mirror_vma(vma);
88097+ if (vma_m) {
88098+ unsigned long address_m;
88099+ pgd_t *pgd_m;
88100+ pud_t *pud_m;
88101+ pmd_t *pmd_m;
88102+
88103+ if (vma->vm_start > vma_m->vm_start) {
88104+ address_m = address;
88105+ address -= SEGMEXEC_TASK_SIZE;
88106+ vma = vma_m;
88107+ } else
88108+ address_m = address + SEGMEXEC_TASK_SIZE;
88109+
88110+ pgd_m = pgd_offset(mm, address_m);
88111+ pud_m = pud_alloc(mm, pgd_m, address_m);
88112+ if (!pud_m)
88113+ return VM_FAULT_OOM;
88114+ pmd_m = pmd_alloc(mm, pud_m, address_m);
88115+ if (!pmd_m)
88116+ return VM_FAULT_OOM;
88117+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
88118+ return VM_FAULT_OOM;
88119+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
88120+ }
88121+#endif
88122+
88123 retry:
88124 pgd = pgd_offset(mm, address);
88125 pud = pud_alloc(mm, pgd, address);
88126@@ -3894,6 +4135,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88127 spin_unlock(&mm->page_table_lock);
88128 return 0;
88129 }
88130+
88131+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88132+{
88133+ pud_t *new = pud_alloc_one(mm, address);
88134+ if (!new)
88135+ return -ENOMEM;
88136+
88137+ smp_wmb(); /* See comment in __pte_alloc */
88138+
88139+ spin_lock(&mm->page_table_lock);
88140+ if (pgd_present(*pgd)) /* Another has populated it */
88141+ pud_free(mm, new);
88142+ else
88143+ pgd_populate_kernel(mm, pgd, new);
88144+ spin_unlock(&mm->page_table_lock);
88145+ return 0;
88146+}
88147 #endif /* __PAGETABLE_PUD_FOLDED */
88148
88149 #ifndef __PAGETABLE_PMD_FOLDED
88150@@ -3924,6 +4182,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
88151 spin_unlock(&mm->page_table_lock);
88152 return 0;
88153 }
88154+
88155+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
88156+{
88157+ pmd_t *new = pmd_alloc_one(mm, address);
88158+ if (!new)
88159+ return -ENOMEM;
88160+
88161+ smp_wmb(); /* See comment in __pte_alloc */
88162+
88163+ spin_lock(&mm->page_table_lock);
88164+#ifndef __ARCH_HAS_4LEVEL_HACK
88165+ if (pud_present(*pud)) /* Another has populated it */
88166+ pmd_free(mm, new);
88167+ else
88168+ pud_populate_kernel(mm, pud, new);
88169+#else
88170+ if (pgd_present(*pud)) /* Another has populated it */
88171+ pmd_free(mm, new);
88172+ else
88173+ pgd_populate_kernel(mm, pud, new);
88174+#endif /* __ARCH_HAS_4LEVEL_HACK */
88175+ spin_unlock(&mm->page_table_lock);
88176+ return 0;
88177+}
88178 #endif /* __PAGETABLE_PMD_FOLDED */
88179
88180 #if !defined(__HAVE_ARCH_GATE_AREA)
88181@@ -3937,7 +4219,7 @@ static int __init gate_vma_init(void)
88182 gate_vma.vm_start = FIXADDR_USER_START;
88183 gate_vma.vm_end = FIXADDR_USER_END;
88184 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
88185- gate_vma.vm_page_prot = __P101;
88186+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
88187
88188 return 0;
88189 }
88190@@ -4071,8 +4353,8 @@ out:
88191 return ret;
88192 }
88193
88194-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88195- void *buf, int len, int write)
88196+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88197+ void *buf, size_t len, int write)
88198 {
88199 resource_size_t phys_addr;
88200 unsigned long prot = 0;
88201@@ -4098,8 +4380,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
88202 * Access another process' address space as given in mm. If non-NULL, use the
88203 * given task for page fault accounting.
88204 */
88205-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88206- unsigned long addr, void *buf, int len, int write)
88207+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88208+ unsigned long addr, void *buf, size_t len, int write)
88209 {
88210 struct vm_area_struct *vma;
88211 void *old_buf = buf;
88212@@ -4107,7 +4389,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88213 down_read(&mm->mmap_sem);
88214 /* ignore errors, just check how much was successfully transferred */
88215 while (len) {
88216- int bytes, ret, offset;
88217+ ssize_t bytes, ret, offset;
88218 void *maddr;
88219 struct page *page = NULL;
88220
88221@@ -4166,8 +4448,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88222 *
88223 * The caller must hold a reference on @mm.
88224 */
88225-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88226- void *buf, int len, int write)
88227+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88228+ void *buf, size_t len, int write)
88229 {
88230 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88231 }
88232@@ -4177,11 +4459,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88233 * Source/target buffer must be kernel space,
88234 * Do not walk the page table directly, use get_user_pages
88235 */
88236-int access_process_vm(struct task_struct *tsk, unsigned long addr,
88237- void *buf, int len, int write)
88238+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
88239+ void *buf, size_t len, int write)
88240 {
88241 struct mm_struct *mm;
88242- int ret;
88243+ ssize_t ret;
88244
88245 mm = get_task_mm(tsk);
88246 if (!mm)
88247diff --git a/mm/mempolicy.c b/mm/mempolicy.c
88248index 0472964..7d5a0ea 100644
88249--- a/mm/mempolicy.c
88250+++ b/mm/mempolicy.c
88251@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88252 unsigned long vmstart;
88253 unsigned long vmend;
88254
88255+#ifdef CONFIG_PAX_SEGMEXEC
88256+ struct vm_area_struct *vma_m;
88257+#endif
88258+
88259 vma = find_vma(mm, start);
88260 if (!vma || vma->vm_start > start)
88261 return -EFAULT;
88262@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88263 err = vma_replace_policy(vma, new_pol);
88264 if (err)
88265 goto out;
88266+
88267+#ifdef CONFIG_PAX_SEGMEXEC
88268+ vma_m = pax_find_mirror_vma(vma);
88269+ if (vma_m) {
88270+ err = vma_replace_policy(vma_m, new_pol);
88271+ if (err)
88272+ goto out;
88273+ }
88274+#endif
88275+
88276 }
88277
88278 out:
88279@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
88280
88281 if (end < start)
88282 return -EINVAL;
88283+
88284+#ifdef CONFIG_PAX_SEGMEXEC
88285+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88286+ if (end > SEGMEXEC_TASK_SIZE)
88287+ return -EINVAL;
88288+ } else
88289+#endif
88290+
88291+ if (end > TASK_SIZE)
88292+ return -EINVAL;
88293+
88294 if (end == start)
88295 return 0;
88296
88297@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88298 */
88299 tcred = __task_cred(task);
88300 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88301- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88302- !capable(CAP_SYS_NICE)) {
88303+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88304 rcu_read_unlock();
88305 err = -EPERM;
88306 goto out_put;
88307@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88308 goto out;
88309 }
88310
88311+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
88312+ if (mm != current->mm &&
88313+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
88314+ mmput(mm);
88315+ err = -EPERM;
88316+ goto out;
88317+ }
88318+#endif
88319+
88320 err = do_migrate_pages(mm, old, new,
88321 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
88322
88323diff --git a/mm/migrate.c b/mm/migrate.c
88324index c046927..6996b40 100644
88325--- a/mm/migrate.c
88326+++ b/mm/migrate.c
88327@@ -1404,8 +1404,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
88328 */
88329 tcred = __task_cred(task);
88330 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88331- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88332- !capable(CAP_SYS_NICE)) {
88333+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88334 rcu_read_unlock();
88335 err = -EPERM;
88336 goto out;
88337diff --git a/mm/mlock.c b/mm/mlock.c
88338index d480cd6..0f98458 100644
88339--- a/mm/mlock.c
88340+++ b/mm/mlock.c
88341@@ -14,6 +14,7 @@
88342 #include <linux/pagevec.h>
88343 #include <linux/mempolicy.h>
88344 #include <linux/syscalls.h>
88345+#include <linux/security.h>
88346 #include <linux/sched.h>
88347 #include <linux/export.h>
88348 #include <linux/rmap.h>
88349@@ -568,7 +569,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
88350 {
88351 unsigned long nstart, end, tmp;
88352 struct vm_area_struct * vma, * prev;
88353- int error;
88354+ int error = 0;
88355
88356 VM_BUG_ON(start & ~PAGE_MASK);
88357 VM_BUG_ON(len != PAGE_ALIGN(len));
88358@@ -577,6 +578,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
88359 return -EINVAL;
88360 if (end == start)
88361 return 0;
88362+ if (end > TASK_SIZE)
88363+ return -EINVAL;
88364+
88365 vma = find_vma(current->mm, start);
88366 if (!vma || vma->vm_start > start)
88367 return -ENOMEM;
88368@@ -588,6 +592,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
88369 for (nstart = start ; ; ) {
88370 vm_flags_t newflags;
88371
88372+#ifdef CONFIG_PAX_SEGMEXEC
88373+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88374+ break;
88375+#endif
88376+
88377 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
88378
88379 newflags = vma->vm_flags & ~VM_LOCKED;
88380@@ -700,6 +709,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
88381 lock_limit >>= PAGE_SHIFT;
88382
88383 /* check against resource limits */
88384+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
88385 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
88386 error = do_mlock(start, len, 1);
88387 up_write(&current->mm->mmap_sem);
88388@@ -734,6 +744,11 @@ static int do_mlockall(int flags)
88389 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
88390 vm_flags_t newflags;
88391
88392+#ifdef CONFIG_PAX_SEGMEXEC
88393+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88394+ break;
88395+#endif
88396+
88397 newflags = vma->vm_flags & ~VM_LOCKED;
88398 if (flags & MCL_CURRENT)
88399 newflags |= VM_LOCKED;
88400@@ -767,6 +782,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
88401 lock_limit >>= PAGE_SHIFT;
88402
88403 ret = -ENOMEM;
88404+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
88405 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
88406 capable(CAP_IPC_LOCK))
88407 ret = do_mlockall(flags);
88408diff --git a/mm/mmap.c b/mm/mmap.c
88409index 9d54851..e8c6035 100644
88410--- a/mm/mmap.c
88411+++ b/mm/mmap.c
88412@@ -36,6 +36,7 @@
88413 #include <linux/sched/sysctl.h>
88414 #include <linux/notifier.h>
88415 #include <linux/memory.h>
88416+#include <linux/random.h>
88417
88418 #include <asm/uaccess.h>
88419 #include <asm/cacheflush.h>
88420@@ -52,6 +53,16 @@
88421 #define arch_rebalance_pgtables(addr, len) (addr)
88422 #endif
88423
88424+static inline void verify_mm_writelocked(struct mm_struct *mm)
88425+{
88426+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
88427+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88428+ up_read(&mm->mmap_sem);
88429+ BUG();
88430+ }
88431+#endif
88432+}
88433+
88434 static void unmap_region(struct mm_struct *mm,
88435 struct vm_area_struct *vma, struct vm_area_struct *prev,
88436 unsigned long start, unsigned long end);
88437@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
88438 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
88439 *
88440 */
88441-pgprot_t protection_map[16] = {
88442+pgprot_t protection_map[16] __read_only = {
88443 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
88444 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
88445 };
88446
88447-pgprot_t vm_get_page_prot(unsigned long vm_flags)
88448+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
88449 {
88450- return __pgprot(pgprot_val(protection_map[vm_flags &
88451+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
88452 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
88453 pgprot_val(arch_vm_get_page_prot(vm_flags)));
88454+
88455+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88456+ if (!(__supported_pte_mask & _PAGE_NX) &&
88457+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
88458+ (vm_flags & (VM_READ | VM_WRITE)))
88459+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
88460+#endif
88461+
88462+ return prot;
88463 }
88464 EXPORT_SYMBOL(vm_get_page_prot);
88465
88466@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
88467 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
88468 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88469 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88470+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
88471 /*
88472 * Make sure vm_committed_as in one cacheline and not cacheline shared with
88473 * other variables. It can be updated by several CPUs frequently.
88474@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
88475 struct vm_area_struct *next = vma->vm_next;
88476
88477 might_sleep();
88478+ BUG_ON(vma->vm_mirror);
88479 if (vma->vm_ops && vma->vm_ops->close)
88480 vma->vm_ops->close(vma);
88481 if (vma->vm_file)
88482@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
88483 * not page aligned -Ram Gupta
88484 */
88485 rlim = rlimit(RLIMIT_DATA);
88486+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
88487 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
88488 (mm->end_data - mm->start_data) > rlim)
88489 goto out;
88490@@ -933,6 +956,12 @@ static int
88491 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
88492 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88493 {
88494+
88495+#ifdef CONFIG_PAX_SEGMEXEC
88496+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
88497+ return 0;
88498+#endif
88499+
88500 if (is_mergeable_vma(vma, file, vm_flags) &&
88501 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88502 if (vma->vm_pgoff == vm_pgoff)
88503@@ -952,6 +981,12 @@ static int
88504 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88505 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88506 {
88507+
88508+#ifdef CONFIG_PAX_SEGMEXEC
88509+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
88510+ return 0;
88511+#endif
88512+
88513 if (is_mergeable_vma(vma, file, vm_flags) &&
88514 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88515 pgoff_t vm_pglen;
88516@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88517 struct vm_area_struct *vma_merge(struct mm_struct *mm,
88518 struct vm_area_struct *prev, unsigned long addr,
88519 unsigned long end, unsigned long vm_flags,
88520- struct anon_vma *anon_vma, struct file *file,
88521+ struct anon_vma *anon_vma, struct file *file,
88522 pgoff_t pgoff, struct mempolicy *policy)
88523 {
88524 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
88525 struct vm_area_struct *area, *next;
88526 int err;
88527
88528+#ifdef CONFIG_PAX_SEGMEXEC
88529+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
88530+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
88531+
88532+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
88533+#endif
88534+
88535 /*
88536 * We later require that vma->vm_flags == vm_flags,
88537 * so this tests vma->vm_flags & VM_SPECIAL, too.
88538@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88539 if (next && next->vm_end == end) /* cases 6, 7, 8 */
88540 next = next->vm_next;
88541
88542+#ifdef CONFIG_PAX_SEGMEXEC
88543+ if (prev)
88544+ prev_m = pax_find_mirror_vma(prev);
88545+ if (area)
88546+ area_m = pax_find_mirror_vma(area);
88547+ if (next)
88548+ next_m = pax_find_mirror_vma(next);
88549+#endif
88550+
88551 /*
88552 * Can it merge with the predecessor?
88553 */
88554@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88555 /* cases 1, 6 */
88556 err = vma_adjust(prev, prev->vm_start,
88557 next->vm_end, prev->vm_pgoff, NULL);
88558- } else /* cases 2, 5, 7 */
88559+
88560+#ifdef CONFIG_PAX_SEGMEXEC
88561+ if (!err && prev_m)
88562+ err = vma_adjust(prev_m, prev_m->vm_start,
88563+ next_m->vm_end, prev_m->vm_pgoff, NULL);
88564+#endif
88565+
88566+ } else { /* cases 2, 5, 7 */
88567 err = vma_adjust(prev, prev->vm_start,
88568 end, prev->vm_pgoff, NULL);
88569+
88570+#ifdef CONFIG_PAX_SEGMEXEC
88571+ if (!err && prev_m)
88572+ err = vma_adjust(prev_m, prev_m->vm_start,
88573+ end_m, prev_m->vm_pgoff, NULL);
88574+#endif
88575+
88576+ }
88577 if (err)
88578 return NULL;
88579 khugepaged_enter_vma_merge(prev);
88580@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88581 mpol_equal(policy, vma_policy(next)) &&
88582 can_vma_merge_before(next, vm_flags,
88583 anon_vma, file, pgoff+pglen)) {
88584- if (prev && addr < prev->vm_end) /* case 4 */
88585+ if (prev && addr < prev->vm_end) { /* case 4 */
88586 err = vma_adjust(prev, prev->vm_start,
88587 addr, prev->vm_pgoff, NULL);
88588- else /* cases 3, 8 */
88589+
88590+#ifdef CONFIG_PAX_SEGMEXEC
88591+ if (!err && prev_m)
88592+ err = vma_adjust(prev_m, prev_m->vm_start,
88593+ addr_m, prev_m->vm_pgoff, NULL);
88594+#endif
88595+
88596+ } else { /* cases 3, 8 */
88597 err = vma_adjust(area, addr, next->vm_end,
88598 next->vm_pgoff - pglen, NULL);
88599+
88600+#ifdef CONFIG_PAX_SEGMEXEC
88601+ if (!err && area_m)
88602+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
88603+ next_m->vm_pgoff - pglen, NULL);
88604+#endif
88605+
88606+ }
88607 if (err)
88608 return NULL;
88609 khugepaged_enter_vma_merge(area);
88610@@ -1165,8 +1246,10 @@ none:
88611 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88612 struct file *file, long pages)
88613 {
88614- const unsigned long stack_flags
88615- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
88616+
88617+#ifdef CONFIG_PAX_RANDMMAP
88618+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88619+#endif
88620
88621 mm->total_vm += pages;
88622
88623@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88624 mm->shared_vm += pages;
88625 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
88626 mm->exec_vm += pages;
88627- } else if (flags & stack_flags)
88628+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
88629 mm->stack_vm += pages;
88630 }
88631 #endif /* CONFIG_PROC_FS */
88632@@ -1212,7 +1295,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88633 * (the exception is when the underlying filesystem is noexec
88634 * mounted, in which case we dont add PROT_EXEC.)
88635 */
88636- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88637+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88638 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
88639 prot |= PROT_EXEC;
88640
88641@@ -1238,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88642 /* Obtain the address to map to. we verify (or select) it and ensure
88643 * that it represents a valid section of the address space.
88644 */
88645- addr = get_unmapped_area(file, addr, len, pgoff, flags);
88646+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
88647 if (addr & ~PAGE_MASK)
88648 return addr;
88649
88650@@ -1249,6 +1332,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88651 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
88652 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
88653
88654+#ifdef CONFIG_PAX_MPROTECT
88655+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88656+
88657+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
88658+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
88659+ mm->binfmt->handle_mmap)
88660+ mm->binfmt->handle_mmap(file);
88661+#endif
88662+
88663+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88664+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
88665+ gr_log_rwxmmap(file);
88666+
88667+#ifdef CONFIG_PAX_EMUPLT
88668+ vm_flags &= ~VM_EXEC;
88669+#else
88670+ return -EPERM;
88671+#endif
88672+
88673+ }
88674+
88675+ if (!(vm_flags & VM_EXEC))
88676+ vm_flags &= ~VM_MAYEXEC;
88677+#else
88678+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88679+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88680+#endif
88681+ else
88682+ vm_flags &= ~VM_MAYWRITE;
88683+ }
88684+#endif
88685+
88686+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88687+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
88688+ vm_flags &= ~VM_PAGEEXEC;
88689+#endif
88690+
88691 if (flags & MAP_LOCKED)
88692 if (!can_do_mlock())
88693 return -EPERM;
88694@@ -1260,6 +1380,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88695 locked += mm->locked_vm;
88696 lock_limit = rlimit(RLIMIT_MEMLOCK);
88697 lock_limit >>= PAGE_SHIFT;
88698+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
88699 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
88700 return -EAGAIN;
88701 }
88702@@ -1344,6 +1465,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88703 vm_flags |= VM_NORESERVE;
88704 }
88705
88706+ if (!gr_acl_handle_mmap(file, prot))
88707+ return -EACCES;
88708+
88709 addr = mmap_region(file, addr, len, vm_flags, pgoff);
88710 if (!IS_ERR_VALUE(addr) &&
88711 ((vm_flags & VM_LOCKED) ||
88712@@ -1437,7 +1561,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
88713 vm_flags_t vm_flags = vma->vm_flags;
88714
88715 /* If it was private or non-writable, the write bit is already clear */
88716- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
88717+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
88718 return 0;
88719
88720 /* The backer wishes to know when pages are first written to? */
88721@@ -1483,7 +1607,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88722 struct rb_node **rb_link, *rb_parent;
88723 unsigned long charged = 0;
88724
88725+#ifdef CONFIG_PAX_SEGMEXEC
88726+ struct vm_area_struct *vma_m = NULL;
88727+#endif
88728+
88729+ /*
88730+ * mm->mmap_sem is required to protect against another thread
88731+ * changing the mappings in case we sleep.
88732+ */
88733+ verify_mm_writelocked(mm);
88734+
88735 /* Check against address space limit. */
88736+
88737+#ifdef CONFIG_PAX_RANDMMAP
88738+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88739+#endif
88740+
88741 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
88742 unsigned long nr_pages;
88743
88744@@ -1502,11 +1641,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88745
88746 /* Clear old maps */
88747 error = -ENOMEM;
88748-munmap_back:
88749 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88750 if (do_munmap(mm, addr, len))
88751 return -ENOMEM;
88752- goto munmap_back;
88753+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88754 }
88755
88756 /*
88757@@ -1537,6 +1675,16 @@ munmap_back:
88758 goto unacct_error;
88759 }
88760
88761+#ifdef CONFIG_PAX_SEGMEXEC
88762+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
88763+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88764+ if (!vma_m) {
88765+ error = -ENOMEM;
88766+ goto free_vma;
88767+ }
88768+ }
88769+#endif
88770+
88771 vma->vm_mm = mm;
88772 vma->vm_start = addr;
88773 vma->vm_end = addr + len;
88774@@ -1556,6 +1704,13 @@ munmap_back:
88775 if (error)
88776 goto unmap_and_free_vma;
88777
88778+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88779+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
88780+ vma->vm_flags |= VM_PAGEEXEC;
88781+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88782+ }
88783+#endif
88784+
88785 /* Can addr have changed??
88786 *
88787 * Answer: Yes, several device drivers can do it in their
88788@@ -1589,6 +1744,12 @@ munmap_back:
88789 }
88790
88791 vma_link(mm, vma, prev, rb_link, rb_parent);
88792+
88793+#ifdef CONFIG_PAX_SEGMEXEC
88794+ if (vma_m)
88795+ BUG_ON(pax_mirror_vma(vma_m, vma));
88796+#endif
88797+
88798 /* Once vma denies write, undo our temporary denial count */
88799 if (vm_flags & VM_DENYWRITE)
88800 allow_write_access(file);
88801@@ -1597,6 +1758,7 @@ out:
88802 perf_event_mmap(vma);
88803
88804 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
88805+ track_exec_limit(mm, addr, addr + len, vm_flags);
88806 if (vm_flags & VM_LOCKED) {
88807 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
88808 vma == get_gate_vma(current->mm)))
88809@@ -1629,6 +1791,12 @@ unmap_and_free_vma:
88810 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
88811 charged = 0;
88812 free_vma:
88813+
88814+#ifdef CONFIG_PAX_SEGMEXEC
88815+ if (vma_m)
88816+ kmem_cache_free(vm_area_cachep, vma_m);
88817+#endif
88818+
88819 kmem_cache_free(vm_area_cachep, vma);
88820 unacct_error:
88821 if (charged)
88822@@ -1636,7 +1804,63 @@ unacct_error:
88823 return error;
88824 }
88825
88826-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
88827+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
88828+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
88829+{
88830+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
88831+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
88832+
88833+ return 0;
88834+}
88835+#endif
88836+
88837+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
88838+{
88839+ if (!vma) {
88840+#ifdef CONFIG_STACK_GROWSUP
88841+ if (addr > sysctl_heap_stack_gap)
88842+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
88843+ else
88844+ vma = find_vma(current->mm, 0);
88845+ if (vma && (vma->vm_flags & VM_GROWSUP))
88846+ return false;
88847+#endif
88848+ return true;
88849+ }
88850+
88851+ if (addr + len > vma->vm_start)
88852+ return false;
88853+
88854+ if (vma->vm_flags & VM_GROWSDOWN)
88855+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
88856+#ifdef CONFIG_STACK_GROWSUP
88857+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
88858+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
88859+#endif
88860+ else if (offset)
88861+ return offset <= vma->vm_start - addr - len;
88862+
88863+ return true;
88864+}
88865+
88866+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
88867+{
88868+ if (vma->vm_start < len)
88869+ return -ENOMEM;
88870+
88871+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
88872+ if (offset <= vma->vm_start - len)
88873+ return vma->vm_start - len - offset;
88874+ else
88875+ return -ENOMEM;
88876+ }
88877+
88878+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
88879+ return vma->vm_start - len - sysctl_heap_stack_gap;
88880+ return -ENOMEM;
88881+}
88882+
88883+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
88884 {
88885 /*
88886 * We implement the search by looking for an rbtree node that
88887@@ -1684,11 +1908,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
88888 }
88889 }
88890
88891- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
88892+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
88893 check_current:
88894 /* Check if current node has a suitable gap */
88895 if (gap_start > high_limit)
88896 return -ENOMEM;
88897+
88898+ if (gap_end - gap_start > info->threadstack_offset)
88899+ gap_start += info->threadstack_offset;
88900+ else
88901+ gap_start = gap_end;
88902+
88903+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
88904+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88905+ gap_start += sysctl_heap_stack_gap;
88906+ else
88907+ gap_start = gap_end;
88908+ }
88909+ if (vma->vm_flags & VM_GROWSDOWN) {
88910+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88911+ gap_end -= sysctl_heap_stack_gap;
88912+ else
88913+ gap_end = gap_start;
88914+ }
88915 if (gap_end >= low_limit && gap_end - gap_start >= length)
88916 goto found;
88917
88918@@ -1738,7 +1980,7 @@ found:
88919 return gap_start;
88920 }
88921
88922-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
88923+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
88924 {
88925 struct mm_struct *mm = current->mm;
88926 struct vm_area_struct *vma;
88927@@ -1792,6 +2034,24 @@ check_current:
88928 gap_end = vma->vm_start;
88929 if (gap_end < low_limit)
88930 return -ENOMEM;
88931+
88932+ if (gap_end - gap_start > info->threadstack_offset)
88933+ gap_end -= info->threadstack_offset;
88934+ else
88935+ gap_end = gap_start;
88936+
88937+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
88938+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88939+ gap_start += sysctl_heap_stack_gap;
88940+ else
88941+ gap_start = gap_end;
88942+ }
88943+ if (vma->vm_flags & VM_GROWSDOWN) {
88944+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88945+ gap_end -= sysctl_heap_stack_gap;
88946+ else
88947+ gap_end = gap_start;
88948+ }
88949 if (gap_start <= high_limit && gap_end - gap_start >= length)
88950 goto found;
88951
88952@@ -1855,6 +2115,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
88953 struct mm_struct *mm = current->mm;
88954 struct vm_area_struct *vma;
88955 struct vm_unmapped_area_info info;
88956+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
88957
88958 if (len > TASK_SIZE)
88959 return -ENOMEM;
88960@@ -1862,19 +2123,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
88961 if (flags & MAP_FIXED)
88962 return addr;
88963
88964+#ifdef CONFIG_PAX_RANDMMAP
88965+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
88966+#endif
88967+
88968 if (addr) {
88969 addr = PAGE_ALIGN(addr);
88970 vma = find_vma(mm, addr);
88971- if (TASK_SIZE - len >= addr &&
88972- (!vma || addr + len <= vma->vm_start))
88973+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
88974 return addr;
88975 }
88976
88977 info.flags = 0;
88978 info.length = len;
88979 info.low_limit = TASK_UNMAPPED_BASE;
88980+
88981+#ifdef CONFIG_PAX_RANDMMAP
88982+ if (mm->pax_flags & MF_PAX_RANDMMAP)
88983+ info.low_limit += mm->delta_mmap;
88984+#endif
88985+
88986 info.high_limit = TASK_SIZE;
88987 info.align_mask = 0;
88988+ info.threadstack_offset = offset;
88989 return vm_unmapped_area(&info);
88990 }
88991 #endif
88992@@ -1893,6 +2164,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88993 struct mm_struct *mm = current->mm;
88994 unsigned long addr = addr0;
88995 struct vm_unmapped_area_info info;
88996+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
88997
88998 /* requested length too big for entire address space */
88999 if (len > TASK_SIZE)
89000@@ -1901,12 +2173,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89001 if (flags & MAP_FIXED)
89002 return addr;
89003
89004+#ifdef CONFIG_PAX_RANDMMAP
89005+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89006+#endif
89007+
89008 /* requesting a specific address */
89009 if (addr) {
89010 addr = PAGE_ALIGN(addr);
89011 vma = find_vma(mm, addr);
89012- if (TASK_SIZE - len >= addr &&
89013- (!vma || addr + len <= vma->vm_start))
89014+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
89015 return addr;
89016 }
89017
89018@@ -1915,6 +2190,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89019 info.low_limit = PAGE_SIZE;
89020 info.high_limit = mm->mmap_base;
89021 info.align_mask = 0;
89022+ info.threadstack_offset = offset;
89023 addr = vm_unmapped_area(&info);
89024
89025 /*
89026@@ -1927,6 +2203,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89027 VM_BUG_ON(addr != -ENOMEM);
89028 info.flags = 0;
89029 info.low_limit = TASK_UNMAPPED_BASE;
89030+
89031+#ifdef CONFIG_PAX_RANDMMAP
89032+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89033+ info.low_limit += mm->delta_mmap;
89034+#endif
89035+
89036 info.high_limit = TASK_SIZE;
89037 addr = vm_unmapped_area(&info);
89038 }
89039@@ -2028,6 +2310,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
89040 return vma;
89041 }
89042
89043+#ifdef CONFIG_PAX_SEGMEXEC
89044+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
89045+{
89046+ struct vm_area_struct *vma_m;
89047+
89048+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
89049+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
89050+ BUG_ON(vma->vm_mirror);
89051+ return NULL;
89052+ }
89053+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
89054+ vma_m = vma->vm_mirror;
89055+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
89056+ BUG_ON(vma->vm_file != vma_m->vm_file);
89057+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
89058+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
89059+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
89060+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
89061+ return vma_m;
89062+}
89063+#endif
89064+
89065 /*
89066 * Verify that the stack growth is acceptable and
89067 * update accounting. This is shared with both the
89068@@ -2044,6 +2348,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89069 return -ENOMEM;
89070
89071 /* Stack limit test */
89072+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
89073 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
89074 return -ENOMEM;
89075
89076@@ -2054,6 +2359,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89077 locked = mm->locked_vm + grow;
89078 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
89079 limit >>= PAGE_SHIFT;
89080+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89081 if (locked > limit && !capable(CAP_IPC_LOCK))
89082 return -ENOMEM;
89083 }
89084@@ -2083,37 +2389,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89085 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
89086 * vma is the last one with address > vma->vm_end. Have to extend vma.
89087 */
89088+#ifndef CONFIG_IA64
89089+static
89090+#endif
89091 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89092 {
89093 int error;
89094+ bool locknext;
89095
89096 if (!(vma->vm_flags & VM_GROWSUP))
89097 return -EFAULT;
89098
89099+ /* Also guard against wrapping around to address 0. */
89100+ if (address < PAGE_ALIGN(address+1))
89101+ address = PAGE_ALIGN(address+1);
89102+ else
89103+ return -ENOMEM;
89104+
89105 /*
89106 * We must make sure the anon_vma is allocated
89107 * so that the anon_vma locking is not a noop.
89108 */
89109 if (unlikely(anon_vma_prepare(vma)))
89110 return -ENOMEM;
89111+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
89112+ if (locknext && anon_vma_prepare(vma->vm_next))
89113+ return -ENOMEM;
89114 vma_lock_anon_vma(vma);
89115+ if (locknext)
89116+ vma_lock_anon_vma(vma->vm_next);
89117
89118 /*
89119 * vma->vm_start/vm_end cannot change under us because the caller
89120 * is required to hold the mmap_sem in read mode. We need the
89121- * anon_vma lock to serialize against concurrent expand_stacks.
89122- * Also guard against wrapping around to address 0.
89123+ * anon_vma locks to serialize against concurrent expand_stacks
89124+ * and expand_upwards.
89125 */
89126- if (address < PAGE_ALIGN(address+4))
89127- address = PAGE_ALIGN(address+4);
89128- else {
89129- vma_unlock_anon_vma(vma);
89130- return -ENOMEM;
89131- }
89132 error = 0;
89133
89134 /* Somebody else might have raced and expanded it already */
89135- if (address > vma->vm_end) {
89136+ 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)
89137+ error = -ENOMEM;
89138+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
89139 unsigned long size, grow;
89140
89141 size = address - vma->vm_start;
89142@@ -2148,6 +2465,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89143 }
89144 }
89145 }
89146+ if (locknext)
89147+ vma_unlock_anon_vma(vma->vm_next);
89148 vma_unlock_anon_vma(vma);
89149 khugepaged_enter_vma_merge(vma);
89150 validate_mm(vma->vm_mm);
89151@@ -2162,6 +2481,8 @@ int expand_downwards(struct vm_area_struct *vma,
89152 unsigned long address)
89153 {
89154 int error;
89155+ bool lockprev = false;
89156+ struct vm_area_struct *prev;
89157
89158 /*
89159 * We must make sure the anon_vma is allocated
89160@@ -2175,6 +2496,15 @@ int expand_downwards(struct vm_area_struct *vma,
89161 if (error)
89162 return error;
89163
89164+ prev = vma->vm_prev;
89165+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
89166+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
89167+#endif
89168+ if (lockprev && anon_vma_prepare(prev))
89169+ return -ENOMEM;
89170+ if (lockprev)
89171+ vma_lock_anon_vma(prev);
89172+
89173 vma_lock_anon_vma(vma);
89174
89175 /*
89176@@ -2184,9 +2514,17 @@ int expand_downwards(struct vm_area_struct *vma,
89177 */
89178
89179 /* Somebody else might have raced and expanded it already */
89180- if (address < vma->vm_start) {
89181+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
89182+ error = -ENOMEM;
89183+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
89184 unsigned long size, grow;
89185
89186+#ifdef CONFIG_PAX_SEGMEXEC
89187+ struct vm_area_struct *vma_m;
89188+
89189+ vma_m = pax_find_mirror_vma(vma);
89190+#endif
89191+
89192 size = vma->vm_end - address;
89193 grow = (vma->vm_start - address) >> PAGE_SHIFT;
89194
89195@@ -2211,13 +2549,27 @@ int expand_downwards(struct vm_area_struct *vma,
89196 vma->vm_pgoff -= grow;
89197 anon_vma_interval_tree_post_update_vma(vma);
89198 vma_gap_update(vma);
89199+
89200+#ifdef CONFIG_PAX_SEGMEXEC
89201+ if (vma_m) {
89202+ anon_vma_interval_tree_pre_update_vma(vma_m);
89203+ vma_m->vm_start -= grow << PAGE_SHIFT;
89204+ vma_m->vm_pgoff -= grow;
89205+ anon_vma_interval_tree_post_update_vma(vma_m);
89206+ vma_gap_update(vma_m);
89207+ }
89208+#endif
89209+
89210 spin_unlock(&vma->vm_mm->page_table_lock);
89211
89212+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
89213 perf_event_mmap(vma);
89214 }
89215 }
89216 }
89217 vma_unlock_anon_vma(vma);
89218+ if (lockprev)
89219+ vma_unlock_anon_vma(prev);
89220 khugepaged_enter_vma_merge(vma);
89221 validate_mm(vma->vm_mm);
89222 return error;
89223@@ -2315,6 +2667,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
89224 do {
89225 long nrpages = vma_pages(vma);
89226
89227+#ifdef CONFIG_PAX_SEGMEXEC
89228+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
89229+ vma = remove_vma(vma);
89230+ continue;
89231+ }
89232+#endif
89233+
89234 if (vma->vm_flags & VM_ACCOUNT)
89235 nr_accounted += nrpages;
89236 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
89237@@ -2359,6 +2718,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
89238 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
89239 vma->vm_prev = NULL;
89240 do {
89241+
89242+#ifdef CONFIG_PAX_SEGMEXEC
89243+ if (vma->vm_mirror) {
89244+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
89245+ vma->vm_mirror->vm_mirror = NULL;
89246+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
89247+ vma->vm_mirror = NULL;
89248+ }
89249+#endif
89250+
89251 vma_rb_erase(vma, &mm->mm_rb);
89252 mm->map_count--;
89253 tail_vma = vma;
89254@@ -2384,14 +2753,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89255 struct vm_area_struct *new;
89256 int err = -ENOMEM;
89257
89258+#ifdef CONFIG_PAX_SEGMEXEC
89259+ struct vm_area_struct *vma_m, *new_m = NULL;
89260+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
89261+#endif
89262+
89263 if (is_vm_hugetlb_page(vma) && (addr &
89264 ~(huge_page_mask(hstate_vma(vma)))))
89265 return -EINVAL;
89266
89267+#ifdef CONFIG_PAX_SEGMEXEC
89268+ vma_m = pax_find_mirror_vma(vma);
89269+#endif
89270+
89271 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89272 if (!new)
89273 goto out_err;
89274
89275+#ifdef CONFIG_PAX_SEGMEXEC
89276+ if (vma_m) {
89277+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89278+ if (!new_m) {
89279+ kmem_cache_free(vm_area_cachep, new);
89280+ goto out_err;
89281+ }
89282+ }
89283+#endif
89284+
89285 /* most fields are the same, copy all, and then fixup */
89286 *new = *vma;
89287
89288@@ -2404,6 +2792,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89289 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
89290 }
89291
89292+#ifdef CONFIG_PAX_SEGMEXEC
89293+ if (vma_m) {
89294+ *new_m = *vma_m;
89295+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
89296+ new_m->vm_mirror = new;
89297+ new->vm_mirror = new_m;
89298+
89299+ if (new_below)
89300+ new_m->vm_end = addr_m;
89301+ else {
89302+ new_m->vm_start = addr_m;
89303+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
89304+ }
89305+ }
89306+#endif
89307+
89308 err = vma_dup_policy(vma, new);
89309 if (err)
89310 goto out_free_vma;
89311@@ -2423,6 +2827,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89312 else
89313 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
89314
89315+#ifdef CONFIG_PAX_SEGMEXEC
89316+ if (!err && vma_m) {
89317+ struct mempolicy *pol = vma_policy(new);
89318+
89319+ if (anon_vma_clone(new_m, vma_m))
89320+ goto out_free_mpol;
89321+
89322+ mpol_get(pol);
89323+ set_vma_policy(new_m, pol);
89324+
89325+ if (new_m->vm_file)
89326+ get_file(new_m->vm_file);
89327+
89328+ if (new_m->vm_ops && new_m->vm_ops->open)
89329+ new_m->vm_ops->open(new_m);
89330+
89331+ if (new_below)
89332+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
89333+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
89334+ else
89335+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
89336+
89337+ if (err) {
89338+ if (new_m->vm_ops && new_m->vm_ops->close)
89339+ new_m->vm_ops->close(new_m);
89340+ if (new_m->vm_file)
89341+ fput(new_m->vm_file);
89342+ mpol_put(pol);
89343+ }
89344+ }
89345+#endif
89346+
89347 /* Success. */
89348 if (!err)
89349 return 0;
89350@@ -2432,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89351 new->vm_ops->close(new);
89352 if (new->vm_file)
89353 fput(new->vm_file);
89354- unlink_anon_vmas(new);
89355 out_free_mpol:
89356 mpol_put(vma_policy(new));
89357 out_free_vma:
89358+
89359+#ifdef CONFIG_PAX_SEGMEXEC
89360+ if (new_m) {
89361+ unlink_anon_vmas(new_m);
89362+ kmem_cache_free(vm_area_cachep, new_m);
89363+ }
89364+#endif
89365+
89366+ unlink_anon_vmas(new);
89367 kmem_cache_free(vm_area_cachep, new);
89368 out_err:
89369 return err;
89370@@ -2448,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89371 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89372 unsigned long addr, int new_below)
89373 {
89374+
89375+#ifdef CONFIG_PAX_SEGMEXEC
89376+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
89377+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
89378+ if (mm->map_count >= sysctl_max_map_count-1)
89379+ return -ENOMEM;
89380+ } else
89381+#endif
89382+
89383 if (mm->map_count >= sysctl_max_map_count)
89384 return -ENOMEM;
89385
89386@@ -2459,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89387 * work. This now handles partial unmappings.
89388 * Jeremy Fitzhardinge <jeremy@goop.org>
89389 */
89390+#ifdef CONFIG_PAX_SEGMEXEC
89391 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89392 {
89393+ int ret = __do_munmap(mm, start, len);
89394+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
89395+ return ret;
89396+
89397+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
89398+}
89399+
89400+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89401+#else
89402+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89403+#endif
89404+{
89405 unsigned long end;
89406 struct vm_area_struct *vma, *prev, *last;
89407
89408+ /*
89409+ * mm->mmap_sem is required to protect against another thread
89410+ * changing the mappings in case we sleep.
89411+ */
89412+ verify_mm_writelocked(mm);
89413+
89414 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
89415 return -EINVAL;
89416
89417@@ -2538,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89418 /* Fix up all other VM information */
89419 remove_vma_list(mm, vma);
89420
89421+ track_exec_limit(mm, start, end, 0UL);
89422+
89423 return 0;
89424 }
89425
89426@@ -2546,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
89427 int ret;
89428 struct mm_struct *mm = current->mm;
89429
89430+
89431+#ifdef CONFIG_PAX_SEGMEXEC
89432+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
89433+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
89434+ return -EINVAL;
89435+#endif
89436+
89437 down_write(&mm->mmap_sem);
89438 ret = do_munmap(mm, start, len);
89439 up_write(&mm->mmap_sem);
89440@@ -2559,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
89441 return vm_munmap(addr, len);
89442 }
89443
89444-static inline void verify_mm_writelocked(struct mm_struct *mm)
89445-{
89446-#ifdef CONFIG_DEBUG_VM
89447- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
89448- WARN_ON(1);
89449- up_read(&mm->mmap_sem);
89450- }
89451-#endif
89452-}
89453-
89454 /*
89455 * this is really a simplified "do_mmap". it only handles
89456 * anonymous maps. eventually we may be able to do some
89457@@ -2582,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89458 struct rb_node ** rb_link, * rb_parent;
89459 pgoff_t pgoff = addr >> PAGE_SHIFT;
89460 int error;
89461+ unsigned long charged;
89462
89463 len = PAGE_ALIGN(len);
89464 if (!len)
89465@@ -2589,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89466
89467 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
89468
89469+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
89470+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
89471+ flags &= ~VM_EXEC;
89472+
89473+#ifdef CONFIG_PAX_MPROTECT
89474+ if (mm->pax_flags & MF_PAX_MPROTECT)
89475+ flags &= ~VM_MAYEXEC;
89476+#endif
89477+
89478+ }
89479+#endif
89480+
89481 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
89482 if (error & ~PAGE_MASK)
89483 return error;
89484
89485+ charged = len >> PAGE_SHIFT;
89486+
89487 /*
89488 * mlock MCL_FUTURE?
89489 */
89490 if (mm->def_flags & VM_LOCKED) {
89491 unsigned long locked, lock_limit;
89492- locked = len >> PAGE_SHIFT;
89493+ locked = charged;
89494 locked += mm->locked_vm;
89495 lock_limit = rlimit(RLIMIT_MEMLOCK);
89496 lock_limit >>= PAGE_SHIFT;
89497@@ -2615,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89498 /*
89499 * Clear old maps. this also does some error checking for us
89500 */
89501- munmap_back:
89502 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
89503 if (do_munmap(mm, addr, len))
89504 return -ENOMEM;
89505- goto munmap_back;
89506+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
89507 }
89508
89509 /* Check against address space limits *after* clearing old maps... */
89510- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
89511+ if (!may_expand_vm(mm, charged))
89512 return -ENOMEM;
89513
89514 if (mm->map_count > sysctl_max_map_count)
89515 return -ENOMEM;
89516
89517- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
89518+ if (security_vm_enough_memory_mm(mm, charged))
89519 return -ENOMEM;
89520
89521 /* Can we just expand an old private anonymous mapping? */
89522@@ -2643,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89523 */
89524 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89525 if (!vma) {
89526- vm_unacct_memory(len >> PAGE_SHIFT);
89527+ vm_unacct_memory(charged);
89528 return -ENOMEM;
89529 }
89530
89531@@ -2657,10 +3142,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89532 vma_link(mm, vma, prev, rb_link, rb_parent);
89533 out:
89534 perf_event_mmap(vma);
89535- mm->total_vm += len >> PAGE_SHIFT;
89536+ mm->total_vm += charged;
89537 if (flags & VM_LOCKED)
89538- mm->locked_vm += (len >> PAGE_SHIFT);
89539+ mm->locked_vm += charged;
89540 vma->vm_flags |= VM_SOFTDIRTY;
89541+ track_exec_limit(mm, addr, addr + len, flags);
89542 return addr;
89543 }
89544
89545@@ -2722,6 +3208,7 @@ void exit_mmap(struct mm_struct *mm)
89546 while (vma) {
89547 if (vma->vm_flags & VM_ACCOUNT)
89548 nr_accounted += vma_pages(vma);
89549+ vma->vm_mirror = NULL;
89550 vma = remove_vma(vma);
89551 }
89552 vm_unacct_memory(nr_accounted);
89553@@ -2738,6 +3225,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89554 struct vm_area_struct *prev;
89555 struct rb_node **rb_link, *rb_parent;
89556
89557+#ifdef CONFIG_PAX_SEGMEXEC
89558+ struct vm_area_struct *vma_m = NULL;
89559+#endif
89560+
89561+ if (security_mmap_addr(vma->vm_start))
89562+ return -EPERM;
89563+
89564 /*
89565 * The vm_pgoff of a purely anonymous vma should be irrelevant
89566 * until its first write fault, when page's anon_vma and index
89567@@ -2761,7 +3255,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89568 security_vm_enough_memory_mm(mm, vma_pages(vma)))
89569 return -ENOMEM;
89570
89571+#ifdef CONFIG_PAX_SEGMEXEC
89572+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
89573+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89574+ if (!vma_m)
89575+ return -ENOMEM;
89576+ }
89577+#endif
89578+
89579 vma_link(mm, vma, prev, rb_link, rb_parent);
89580+
89581+#ifdef CONFIG_PAX_SEGMEXEC
89582+ if (vma_m)
89583+ BUG_ON(pax_mirror_vma(vma_m, vma));
89584+#endif
89585+
89586 return 0;
89587 }
89588
89589@@ -2780,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89590 struct rb_node **rb_link, *rb_parent;
89591 bool faulted_in_anon_vma = true;
89592
89593+ BUG_ON(vma->vm_mirror);
89594+
89595 /*
89596 * If anonymous vma has not yet been faulted, update new pgoff
89597 * to match new location, to increase its chance of merging.
89598@@ -2844,6 +3354,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89599 return NULL;
89600 }
89601
89602+#ifdef CONFIG_PAX_SEGMEXEC
89603+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
89604+{
89605+ struct vm_area_struct *prev_m;
89606+ struct rb_node **rb_link_m, *rb_parent_m;
89607+ struct mempolicy *pol_m;
89608+
89609+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
89610+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
89611+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
89612+ *vma_m = *vma;
89613+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
89614+ if (anon_vma_clone(vma_m, vma))
89615+ return -ENOMEM;
89616+ pol_m = vma_policy(vma_m);
89617+ mpol_get(pol_m);
89618+ set_vma_policy(vma_m, pol_m);
89619+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
89620+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
89621+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
89622+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
89623+ if (vma_m->vm_file)
89624+ get_file(vma_m->vm_file);
89625+ if (vma_m->vm_ops && vma_m->vm_ops->open)
89626+ vma_m->vm_ops->open(vma_m);
89627+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
89628+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
89629+ vma_m->vm_mirror = vma;
89630+ vma->vm_mirror = vma_m;
89631+ return 0;
89632+}
89633+#endif
89634+
89635 /*
89636 * Return true if the calling process may expand its vm space by the passed
89637 * number of pages
89638@@ -2855,6 +3398,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
89639
89640 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
89641
89642+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
89643 if (cur + npages > lim)
89644 return 0;
89645 return 1;
89646@@ -2925,6 +3469,22 @@ int install_special_mapping(struct mm_struct *mm,
89647 vma->vm_start = addr;
89648 vma->vm_end = addr + len;
89649
89650+#ifdef CONFIG_PAX_MPROTECT
89651+ if (mm->pax_flags & MF_PAX_MPROTECT) {
89652+#ifndef CONFIG_PAX_MPROTECT_COMPAT
89653+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
89654+ return -EPERM;
89655+ if (!(vm_flags & VM_EXEC))
89656+ vm_flags &= ~VM_MAYEXEC;
89657+#else
89658+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
89659+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
89660+#endif
89661+ else
89662+ vm_flags &= ~VM_MAYWRITE;
89663+ }
89664+#endif
89665+
89666 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
89667 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
89668
89669diff --git a/mm/mprotect.c b/mm/mprotect.c
89670index 412ba2b..cb41d42 100644
89671--- a/mm/mprotect.c
89672+++ b/mm/mprotect.c
89673@@ -23,10 +23,18 @@
89674 #include <linux/mmu_notifier.h>
89675 #include <linux/migrate.h>
89676 #include <linux/perf_event.h>
89677+#include <linux/sched/sysctl.h>
89678+
89679+#ifdef CONFIG_PAX_MPROTECT
89680+#include <linux/elf.h>
89681+#include <linux/binfmts.h>
89682+#endif
89683+
89684 #include <asm/uaccess.h>
89685 #include <asm/pgtable.h>
89686 #include <asm/cacheflush.h>
89687 #include <asm/tlbflush.h>
89688+#include <asm/mmu_context.h>
89689
89690 #ifndef pgprot_modify
89691 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
89692@@ -236,6 +244,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
89693 return pages;
89694 }
89695
89696+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
89697+/* called while holding the mmap semaphor for writing except stack expansion */
89698+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
89699+{
89700+ unsigned long oldlimit, newlimit = 0UL;
89701+
89702+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
89703+ return;
89704+
89705+ spin_lock(&mm->page_table_lock);
89706+ oldlimit = mm->context.user_cs_limit;
89707+ if ((prot & VM_EXEC) && oldlimit < end)
89708+ /* USER_CS limit moved up */
89709+ newlimit = end;
89710+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
89711+ /* USER_CS limit moved down */
89712+ newlimit = start;
89713+
89714+ if (newlimit) {
89715+ mm->context.user_cs_limit = newlimit;
89716+
89717+#ifdef CONFIG_SMP
89718+ wmb();
89719+ cpus_clear(mm->context.cpu_user_cs_mask);
89720+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
89721+#endif
89722+
89723+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
89724+ }
89725+ spin_unlock(&mm->page_table_lock);
89726+ if (newlimit == end) {
89727+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
89728+
89729+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
89730+ if (is_vm_hugetlb_page(vma))
89731+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
89732+ else
89733+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
89734+ }
89735+}
89736+#endif
89737+
89738 int
89739 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89740 unsigned long start, unsigned long end, unsigned long newflags)
89741@@ -248,11 +298,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89742 int error;
89743 int dirty_accountable = 0;
89744
89745+#ifdef CONFIG_PAX_SEGMEXEC
89746+ struct vm_area_struct *vma_m = NULL;
89747+ unsigned long start_m, end_m;
89748+
89749+ start_m = start + SEGMEXEC_TASK_SIZE;
89750+ end_m = end + SEGMEXEC_TASK_SIZE;
89751+#endif
89752+
89753 if (newflags == oldflags) {
89754 *pprev = vma;
89755 return 0;
89756 }
89757
89758+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
89759+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
89760+
89761+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
89762+ return -ENOMEM;
89763+
89764+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
89765+ return -ENOMEM;
89766+ }
89767+
89768 /*
89769 * If we make a private mapping writable we increase our commit;
89770 * but (without finer accounting) cannot reduce our commit if we
89771@@ -269,6 +337,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89772 }
89773 }
89774
89775+#ifdef CONFIG_PAX_SEGMEXEC
89776+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
89777+ if (start != vma->vm_start) {
89778+ error = split_vma(mm, vma, start, 1);
89779+ if (error)
89780+ goto fail;
89781+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
89782+ *pprev = (*pprev)->vm_next;
89783+ }
89784+
89785+ if (end != vma->vm_end) {
89786+ error = split_vma(mm, vma, end, 0);
89787+ if (error)
89788+ goto fail;
89789+ }
89790+
89791+ if (pax_find_mirror_vma(vma)) {
89792+ error = __do_munmap(mm, start_m, end_m - start_m);
89793+ if (error)
89794+ goto fail;
89795+ } else {
89796+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89797+ if (!vma_m) {
89798+ error = -ENOMEM;
89799+ goto fail;
89800+ }
89801+ vma->vm_flags = newflags;
89802+ error = pax_mirror_vma(vma_m, vma);
89803+ if (error) {
89804+ vma->vm_flags = oldflags;
89805+ goto fail;
89806+ }
89807+ }
89808+ }
89809+#endif
89810+
89811 /*
89812 * First try to merge with previous and/or next vma.
89813 */
89814@@ -299,9 +403,21 @@ success:
89815 * vm_flags and vm_page_prot are protected by the mmap_sem
89816 * held in write mode.
89817 */
89818+
89819+#ifdef CONFIG_PAX_SEGMEXEC
89820+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
89821+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
89822+#endif
89823+
89824 vma->vm_flags = newflags;
89825+
89826+#ifdef CONFIG_PAX_MPROTECT
89827+ if (mm->binfmt && mm->binfmt->handle_mprotect)
89828+ mm->binfmt->handle_mprotect(vma, newflags);
89829+#endif
89830+
89831 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
89832- vm_get_page_prot(newflags));
89833+ vm_get_page_prot(vma->vm_flags));
89834
89835 if (vma_wants_writenotify(vma)) {
89836 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
89837@@ -340,6 +456,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89838 end = start + len;
89839 if (end <= start)
89840 return -ENOMEM;
89841+
89842+#ifdef CONFIG_PAX_SEGMEXEC
89843+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
89844+ if (end > SEGMEXEC_TASK_SIZE)
89845+ return -EINVAL;
89846+ } else
89847+#endif
89848+
89849+ if (end > TASK_SIZE)
89850+ return -EINVAL;
89851+
89852 if (!arch_validate_prot(prot))
89853 return -EINVAL;
89854
89855@@ -347,7 +474,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89856 /*
89857 * Does the application expect PROT_READ to imply PROT_EXEC:
89858 */
89859- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
89860+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
89861 prot |= PROT_EXEC;
89862
89863 vm_flags = calc_vm_prot_bits(prot);
89864@@ -379,6 +506,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89865 if (start > vma->vm_start)
89866 prev = vma;
89867
89868+#ifdef CONFIG_PAX_MPROTECT
89869+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
89870+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
89871+#endif
89872+
89873 for (nstart = start ; ; ) {
89874 unsigned long newflags;
89875
89876@@ -389,6 +521,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89877
89878 /* newflags >> 4 shift VM_MAY% in place of VM_% */
89879 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
89880+ if (prot & (PROT_WRITE | PROT_EXEC))
89881+ gr_log_rwxmprotect(vma);
89882+
89883+ error = -EACCES;
89884+ goto out;
89885+ }
89886+
89887+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
89888 error = -EACCES;
89889 goto out;
89890 }
89891@@ -403,6 +543,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89892 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
89893 if (error)
89894 goto out;
89895+
89896+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
89897+
89898 nstart = tmp;
89899
89900 if (nstart < prev->vm_end)
89901diff --git a/mm/mremap.c b/mm/mremap.c
89902index 0843feb..4f5b2e6 100644
89903--- a/mm/mremap.c
89904+++ b/mm/mremap.c
89905@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
89906 continue;
89907 pte = ptep_get_and_clear(mm, old_addr, old_pte);
89908 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
89909+
89910+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
89911+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
89912+ pte = pte_exprotect(pte);
89913+#endif
89914+
89915 pte = move_soft_dirty_pte(pte);
89916 set_pte_at(mm, new_addr, new_pte, pte);
89917 }
89918@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
89919 if (is_vm_hugetlb_page(vma))
89920 goto Einval;
89921
89922+#ifdef CONFIG_PAX_SEGMEXEC
89923+ if (pax_find_mirror_vma(vma))
89924+ goto Einval;
89925+#endif
89926+
89927 /* We can't remap across vm area boundaries */
89928 if (old_len > vma->vm_end - addr)
89929 goto Efault;
89930@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
89931 unsigned long ret = -EINVAL;
89932 unsigned long charged = 0;
89933 unsigned long map_flags;
89934+ unsigned long pax_task_size = TASK_SIZE;
89935
89936 if (new_addr & ~PAGE_MASK)
89937 goto out;
89938
89939- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
89940+#ifdef CONFIG_PAX_SEGMEXEC
89941+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
89942+ pax_task_size = SEGMEXEC_TASK_SIZE;
89943+#endif
89944+
89945+ pax_task_size -= PAGE_SIZE;
89946+
89947+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
89948 goto out;
89949
89950 /* Check if the location we're moving into overlaps the
89951 * old location at all, and fail if it does.
89952 */
89953- if ((new_addr <= addr) && (new_addr+new_len) > addr)
89954- goto out;
89955-
89956- if ((addr <= new_addr) && (addr+old_len) > new_addr)
89957+ if (addr + old_len > new_addr && new_addr + new_len > addr)
89958 goto out;
89959
89960 ret = do_munmap(mm, new_addr, new_len);
89961@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89962 unsigned long ret = -EINVAL;
89963 unsigned long charged = 0;
89964 bool locked = false;
89965+ unsigned long pax_task_size = TASK_SIZE;
89966
89967 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
89968 return ret;
89969@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89970 if (!new_len)
89971 return ret;
89972
89973+#ifdef CONFIG_PAX_SEGMEXEC
89974+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
89975+ pax_task_size = SEGMEXEC_TASK_SIZE;
89976+#endif
89977+
89978+ pax_task_size -= PAGE_SIZE;
89979+
89980+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
89981+ old_len > pax_task_size || addr > pax_task_size-old_len)
89982+ return ret;
89983+
89984 down_write(&current->mm->mmap_sem);
89985
89986 if (flags & MREMAP_FIXED) {
89987@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89988 new_addr = addr;
89989 }
89990 ret = addr;
89991+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
89992 goto out;
89993 }
89994 }
89995@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89996 goto out;
89997 }
89998
89999+ map_flags = vma->vm_flags;
90000 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
90001+ if (!(ret & ~PAGE_MASK)) {
90002+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
90003+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
90004+ }
90005 }
90006 out:
90007 if (ret & ~PAGE_MASK)
90008diff --git a/mm/nommu.c b/mm/nommu.c
90009index ecd1f15..77039bd 100644
90010--- a/mm/nommu.c
90011+++ b/mm/nommu.c
90012@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
90013 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
90014 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
90015 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
90016-int heap_stack_gap = 0;
90017
90018 atomic_long_t mmap_pages_allocated;
90019
90020@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
90021 EXPORT_SYMBOL(find_vma);
90022
90023 /*
90024- * find a VMA
90025- * - we don't extend stack VMAs under NOMMU conditions
90026- */
90027-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
90028-{
90029- return find_vma(mm, addr);
90030-}
90031-
90032-/*
90033 * expand a stack to a given address
90034 * - not supported under NOMMU conditions
90035 */
90036@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90037
90038 /* most fields are the same, copy all, and then fixup */
90039 *new = *vma;
90040+ INIT_LIST_HEAD(&new->anon_vma_chain);
90041 *region = *vma->vm_region;
90042 new->vm_region = region;
90043
90044@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
90045 }
90046 EXPORT_SYMBOL(generic_file_remap_pages);
90047
90048-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90049- unsigned long addr, void *buf, int len, int write)
90050+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90051+ unsigned long addr, void *buf, size_t len, int write)
90052 {
90053 struct vm_area_struct *vma;
90054
90055@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90056 *
90057 * The caller must hold a reference on @mm.
90058 */
90059-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90060- void *buf, int len, int write)
90061+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
90062+ void *buf, size_t len, int write)
90063 {
90064 return __access_remote_vm(NULL, mm, addr, buf, len, write);
90065 }
90066@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90067 * Access another process' address space.
90068 * - source/target buffer must be kernel space
90069 */
90070-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
90071+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
90072 {
90073 struct mm_struct *mm;
90074
90075diff --git a/mm/page-writeback.c b/mm/page-writeback.c
90076index 6380758..4064aec 100644
90077--- a/mm/page-writeback.c
90078+++ b/mm/page-writeback.c
90079@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
90080 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
90081 * - the bdi dirty thresh drops quickly due to change of JBOD workload
90082 */
90083-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
90084+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
90085 unsigned long thresh,
90086 unsigned long bg_thresh,
90087 unsigned long dirty,
90088diff --git a/mm/page_alloc.c b/mm/page_alloc.c
90089index dd886fa..7686339 100644
90090--- a/mm/page_alloc.c
90091+++ b/mm/page_alloc.c
90092@@ -61,6 +61,7 @@
90093 #include <linux/page-debug-flags.h>
90094 #include <linux/hugetlb.h>
90095 #include <linux/sched/rt.h>
90096+#include <linux/random.h>
90097
90098 #include <asm/sections.h>
90099 #include <asm/tlbflush.h>
90100@@ -354,7 +355,7 @@ out:
90101 * This usage means that zero-order pages may not be compound.
90102 */
90103
90104-static void free_compound_page(struct page *page)
90105+void free_compound_page(struct page *page)
90106 {
90107 __free_pages_ok(page, compound_order(page));
90108 }
90109@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90110 int i;
90111 int bad = 0;
90112
90113+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90114+ unsigned long index = 1UL << order;
90115+#endif
90116+
90117 trace_mm_page_free(page, order);
90118 kmemcheck_free_shadow(page, order);
90119
90120@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90121 debug_check_no_obj_freed(page_address(page),
90122 PAGE_SIZE << order);
90123 }
90124+
90125+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90126+ for (; index; --index)
90127+ sanitize_highpage(page + index - 1);
90128+#endif
90129+
90130 arch_free_page(page, order);
90131 kernel_map_pages(page, 1 << order, 0);
90132
90133@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
90134 local_irq_restore(flags);
90135 }
90136
90137+#ifdef CONFIG_PAX_LATENT_ENTROPY
90138+bool __meminitdata extra_latent_entropy;
90139+
90140+static int __init setup_pax_extra_latent_entropy(char *str)
90141+{
90142+ extra_latent_entropy = true;
90143+ return 0;
90144+}
90145+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
90146+
90147+volatile u64 latent_entropy __latent_entropy;
90148+EXPORT_SYMBOL(latent_entropy);
90149+#endif
90150+
90151 void __init __free_pages_bootmem(struct page *page, unsigned int order)
90152 {
90153 unsigned int nr_pages = 1 << order;
90154@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
90155 __ClearPageReserved(p);
90156 set_page_count(p, 0);
90157
90158+#ifdef CONFIG_PAX_LATENT_ENTROPY
90159+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
90160+ u64 hash = 0;
90161+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
90162+ const u64 *data = lowmem_page_address(page);
90163+
90164+ for (index = 0; index < end; index++)
90165+ hash ^= hash + data[index];
90166+ latent_entropy ^= hash;
90167+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
90168+ }
90169+#endif
90170+
90171 page_zone(page)->managed_pages += nr_pages;
90172 set_page_refcounted(page);
90173 __free_pages(page, order);
90174@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
90175 arch_alloc_page(page, order);
90176 kernel_map_pages(page, 1 << order, 1);
90177
90178+#ifndef CONFIG_PAX_MEMORY_SANITIZE
90179 if (gfp_flags & __GFP_ZERO)
90180 prep_zero_page(page, order, gfp_flags);
90181+#endif
90182
90183 if (order && (gfp_flags & __GFP_COMP))
90184 prep_compound_page(page, order);
90185diff --git a/mm/page_io.c b/mm/page_io.c
90186index 8c79a47..a689e0d 100644
90187--- a/mm/page_io.c
90188+++ b/mm/page_io.c
90189@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
90190 struct file *swap_file = sis->swap_file;
90191 struct address_space *mapping = swap_file->f_mapping;
90192 struct iovec iov = {
90193- .iov_base = kmap(page),
90194+ .iov_base = (void __force_user *)kmap(page),
90195 .iov_len = PAGE_SIZE,
90196 };
90197
90198diff --git a/mm/percpu.c b/mm/percpu.c
90199index 8c8e08f..73a5cda 100644
90200--- a/mm/percpu.c
90201+++ b/mm/percpu.c
90202@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
90203 static unsigned int pcpu_high_unit_cpu __read_mostly;
90204
90205 /* the address of the first chunk which starts with the kernel static area */
90206-void *pcpu_base_addr __read_mostly;
90207+void *pcpu_base_addr __read_only;
90208 EXPORT_SYMBOL_GPL(pcpu_base_addr);
90209
90210 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
90211diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
90212index fd26d04..0cea1b0 100644
90213--- a/mm/process_vm_access.c
90214+++ b/mm/process_vm_access.c
90215@@ -13,6 +13,7 @@
90216 #include <linux/uio.h>
90217 #include <linux/sched.h>
90218 #include <linux/highmem.h>
90219+#include <linux/security.h>
90220 #include <linux/ptrace.h>
90221 #include <linux/slab.h>
90222 #include <linux/syscalls.h>
90223@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90224 size_t iov_l_curr_offset = 0;
90225 ssize_t iov_len;
90226
90227+ return -ENOSYS; // PaX: until properly audited
90228+
90229 /*
90230 * Work out how many pages of struct pages we're going to need
90231 * when eventually calling get_user_pages
90232 */
90233 for (i = 0; i < riovcnt; i++) {
90234 iov_len = rvec[i].iov_len;
90235- if (iov_len > 0) {
90236- nr_pages_iov = ((unsigned long)rvec[i].iov_base
90237- + iov_len)
90238- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
90239- / PAGE_SIZE + 1;
90240- nr_pages = max(nr_pages, nr_pages_iov);
90241- }
90242+ if (iov_len <= 0)
90243+ continue;
90244+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
90245+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
90246+ nr_pages = max(nr_pages, nr_pages_iov);
90247 }
90248
90249 if (nr_pages == 0)
90250@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90251 goto free_proc_pages;
90252 }
90253
90254+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
90255+ rc = -EPERM;
90256+ goto put_task_struct;
90257+ }
90258+
90259 mm = mm_access(task, PTRACE_MODE_ATTACH);
90260 if (!mm || IS_ERR(mm)) {
90261 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
90262diff --git a/mm/rmap.c b/mm/rmap.c
90263index fd3ee7a..3613079 100644
90264--- a/mm/rmap.c
90265+++ b/mm/rmap.c
90266@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90267 struct anon_vma *anon_vma = vma->anon_vma;
90268 struct anon_vma_chain *avc;
90269
90270+#ifdef CONFIG_PAX_SEGMEXEC
90271+ struct anon_vma_chain *avc_m = NULL;
90272+#endif
90273+
90274 might_sleep();
90275 if (unlikely(!anon_vma)) {
90276 struct mm_struct *mm = vma->vm_mm;
90277@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90278 if (!avc)
90279 goto out_enomem;
90280
90281+#ifdef CONFIG_PAX_SEGMEXEC
90282+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
90283+ if (!avc_m)
90284+ goto out_enomem_free_avc;
90285+#endif
90286+
90287 anon_vma = find_mergeable_anon_vma(vma);
90288 allocated = NULL;
90289 if (!anon_vma) {
90290@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90291 /* page_table_lock to protect against threads */
90292 spin_lock(&mm->page_table_lock);
90293 if (likely(!vma->anon_vma)) {
90294+
90295+#ifdef CONFIG_PAX_SEGMEXEC
90296+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
90297+
90298+ if (vma_m) {
90299+ BUG_ON(vma_m->anon_vma);
90300+ vma_m->anon_vma = anon_vma;
90301+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
90302+ avc_m = NULL;
90303+ }
90304+#endif
90305+
90306 vma->anon_vma = anon_vma;
90307 anon_vma_chain_link(vma, avc, anon_vma);
90308 allocated = NULL;
90309@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90310
90311 if (unlikely(allocated))
90312 put_anon_vma(allocated);
90313+
90314+#ifdef CONFIG_PAX_SEGMEXEC
90315+ if (unlikely(avc_m))
90316+ anon_vma_chain_free(avc_m);
90317+#endif
90318+
90319 if (unlikely(avc))
90320 anon_vma_chain_free(avc);
90321 }
90322 return 0;
90323
90324 out_enomem_free_avc:
90325+
90326+#ifdef CONFIG_PAX_SEGMEXEC
90327+ if (avc_m)
90328+ anon_vma_chain_free(avc_m);
90329+#endif
90330+
90331 anon_vma_chain_free(avc);
90332 out_enomem:
90333 return -ENOMEM;
90334@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
90335 * Attach the anon_vmas from src to dst.
90336 * Returns 0 on success, -ENOMEM on failure.
90337 */
90338-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90339+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
90340 {
90341 struct anon_vma_chain *avc, *pavc;
90342 struct anon_vma *root = NULL;
90343@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90344 * the corresponding VMA in the parent process is attached to.
90345 * Returns 0 on success, non-zero on failure.
90346 */
90347-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
90348+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
90349 {
90350 struct anon_vma_chain *avc;
90351 struct anon_vma *anon_vma;
90352@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
90353 void __init anon_vma_init(void)
90354 {
90355 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
90356- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
90357- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
90358+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
90359+ anon_vma_ctor);
90360+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
90361+ SLAB_PANIC|SLAB_NO_SANITIZE);
90362 }
90363
90364 /*
90365diff --git a/mm/shmem.c b/mm/shmem.c
90366index 8297623..6b9dfe9 100644
90367--- a/mm/shmem.c
90368+++ b/mm/shmem.c
90369@@ -33,7 +33,7 @@
90370 #include <linux/swap.h>
90371 #include <linux/aio.h>
90372
90373-static struct vfsmount *shm_mnt;
90374+struct vfsmount *shm_mnt;
90375
90376 #ifdef CONFIG_SHMEM
90377 /*
90378@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
90379 #define BOGO_DIRENT_SIZE 20
90380
90381 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
90382-#define SHORT_SYMLINK_LEN 128
90383+#define SHORT_SYMLINK_LEN 64
90384
90385 /*
90386 * shmem_fallocate and shmem_writepage communicate via inode->i_private
90387@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
90388 static int shmem_xattr_validate(const char *name)
90389 {
90390 struct { const char *prefix; size_t len; } arr[] = {
90391+
90392+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90393+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
90394+#endif
90395+
90396 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
90397 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
90398 };
90399@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
90400 if (err)
90401 return err;
90402
90403+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90404+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
90405+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
90406+ return -EOPNOTSUPP;
90407+ if (size > 8)
90408+ return -EINVAL;
90409+ }
90410+#endif
90411+
90412 return simple_xattr_set(&info->xattrs, name, value, size, flags);
90413 }
90414
90415@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
90416 int err = -ENOMEM;
90417
90418 /* Round up to L1_CACHE_BYTES to resist false sharing */
90419- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
90420- L1_CACHE_BYTES), GFP_KERNEL);
90421+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
90422 if (!sbinfo)
90423 return -ENOMEM;
90424
90425diff --git a/mm/slab.c b/mm/slab.c
90426index 2580db0..0523956 100644
90427--- a/mm/slab.c
90428+++ b/mm/slab.c
90429@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90430 if ((x)->max_freeable < i) \
90431 (x)->max_freeable = i; \
90432 } while (0)
90433-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
90434-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
90435-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
90436-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
90437+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
90438+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
90439+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
90440+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
90441+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
90442+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
90443 #else
90444 #define STATS_INC_ACTIVE(x) do { } while (0)
90445 #define STATS_DEC_ACTIVE(x) do { } while (0)
90446@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90447 #define STATS_INC_ALLOCMISS(x) do { } while (0)
90448 #define STATS_INC_FREEHIT(x) do { } while (0)
90449 #define STATS_INC_FREEMISS(x) do { } while (0)
90450+#define STATS_INC_SANITIZED(x) do { } while (0)
90451+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
90452 #endif
90453
90454 #if DEBUG
90455@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
90456 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
90457 */
90458 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
90459- const struct slab *slab, void *obj)
90460+ const struct slab *slab, const void *obj)
90461 {
90462 u32 offset = (obj - slab->s_mem);
90463 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
90464@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
90465 */
90466
90467 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
90468- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
90469+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90470
90471 if (INDEX_AC != INDEX_NODE)
90472 kmalloc_caches[INDEX_NODE] =
90473 create_kmalloc_cache("kmalloc-node",
90474- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
90475+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90476
90477 slab_early_init = 0;
90478
90479@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
90480 struct array_cache *ac = cpu_cache_get(cachep);
90481
90482 check_irq_off();
90483+
90484+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90485+ if (pax_sanitize_slab) {
90486+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
90487+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
90488+
90489+ if (cachep->ctor)
90490+ cachep->ctor(objp);
90491+
90492+ STATS_INC_SANITIZED(cachep);
90493+ } else
90494+ STATS_INC_NOT_SANITIZED(cachep);
90495+ }
90496+#endif
90497+
90498 kmemleak_free_recursive(objp, cachep->flags);
90499 objp = cache_free_debugcheck(cachep, objp, caller);
90500
90501@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
90502
90503 if (unlikely(ZERO_OR_NULL_PTR(objp)))
90504 return;
90505+ VM_BUG_ON(!virt_addr_valid(objp));
90506 local_irq_save(flags);
90507 kfree_debugcheck(objp);
90508 c = virt_to_cache(objp);
90509@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
90510 }
90511 /* cpu stats */
90512 {
90513- unsigned long allochit = atomic_read(&cachep->allochit);
90514- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
90515- unsigned long freehit = atomic_read(&cachep->freehit);
90516- unsigned long freemiss = atomic_read(&cachep->freemiss);
90517+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
90518+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
90519+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
90520+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
90521
90522 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
90523 allochit, allocmiss, freehit, freemiss);
90524 }
90525+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90526+ {
90527+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
90528+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
90529+
90530+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
90531+ }
90532+#endif
90533 #endif
90534 }
90535
90536@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
90537 static int __init slab_proc_init(void)
90538 {
90539 #ifdef CONFIG_DEBUG_SLAB_LEAK
90540- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
90541+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
90542 #endif
90543 return 0;
90544 }
90545 module_init(slab_proc_init);
90546 #endif
90547
90548+bool is_usercopy_object(const void *ptr)
90549+{
90550+ struct page *page;
90551+ struct kmem_cache *cachep;
90552+
90553+ if (ZERO_OR_NULL_PTR(ptr))
90554+ return false;
90555+
90556+ if (!slab_is_available())
90557+ return false;
90558+
90559+ if (!virt_addr_valid(ptr))
90560+ return false;
90561+
90562+ page = virt_to_head_page(ptr);
90563+
90564+ if (!PageSlab(page))
90565+ return false;
90566+
90567+ cachep = page->slab_cache;
90568+ return cachep->flags & SLAB_USERCOPY;
90569+}
90570+
90571+#ifdef CONFIG_PAX_USERCOPY
90572+const char *check_heap_object(const void *ptr, unsigned long n)
90573+{
90574+ struct page *page;
90575+ struct kmem_cache *cachep;
90576+ struct slab *slabp;
90577+ unsigned int objnr;
90578+ unsigned long offset;
90579+
90580+ if (ZERO_OR_NULL_PTR(ptr))
90581+ return "<null>";
90582+
90583+ if (!virt_addr_valid(ptr))
90584+ return NULL;
90585+
90586+ page = virt_to_head_page(ptr);
90587+
90588+ if (!PageSlab(page))
90589+ return NULL;
90590+
90591+ cachep = page->slab_cache;
90592+ if (!(cachep->flags & SLAB_USERCOPY))
90593+ return cachep->name;
90594+
90595+ slabp = page->slab_page;
90596+ objnr = obj_to_index(cachep, slabp, ptr);
90597+ BUG_ON(objnr >= cachep->num);
90598+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
90599+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
90600+ return NULL;
90601+
90602+ return cachep->name;
90603+}
90604+#endif
90605+
90606 /**
90607 * ksize - get the actual amount of memory allocated for a given object
90608 * @objp: Pointer to the object
90609diff --git a/mm/slab.h b/mm/slab.h
90610index a535033..2f98fe5 100644
90611--- a/mm/slab.h
90612+++ b/mm/slab.h
90613@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
90614 /* The slab cache that manages slab cache information */
90615 extern struct kmem_cache *kmem_cache;
90616
90617+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90618+#ifdef CONFIG_X86_64
90619+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
90620+#else
90621+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
90622+#endif
90623+extern bool pax_sanitize_slab;
90624+#endif
90625+
90626 unsigned long calculate_alignment(unsigned long flags,
90627 unsigned long align, unsigned long size);
90628
90629@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90630
90631 /* Legal flag mask for kmem_cache_create(), for various configurations */
90632 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
90633- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
90634+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
90635+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
90636
90637 #if defined(CONFIG_DEBUG_SLAB)
90638 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
90639@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
90640 return s;
90641
90642 page = virt_to_head_page(x);
90643+
90644+ BUG_ON(!PageSlab(page));
90645+
90646 cachep = page->slab_cache;
90647 if (slab_equal_or_root(cachep, s))
90648 return cachep;
90649diff --git a/mm/slab_common.c b/mm/slab_common.c
90650index e2e98af..3b1a163 100644
90651--- a/mm/slab_common.c
90652+++ b/mm/slab_common.c
90653@@ -23,11 +23,22 @@
90654
90655 #include "slab.h"
90656
90657-enum slab_state slab_state;
90658+enum slab_state slab_state __read_only;
90659 LIST_HEAD(slab_caches);
90660 DEFINE_MUTEX(slab_mutex);
90661 struct kmem_cache *kmem_cache;
90662
90663+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90664+bool pax_sanitize_slab __read_only = true;
90665+static int __init pax_sanitize_slab_setup(char *str)
90666+{
90667+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
90668+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
90669+ return 1;
90670+}
90671+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
90672+#endif
90673+
90674 #ifdef CONFIG_DEBUG_VM
90675 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
90676 size_t size)
90677@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
90678
90679 err = __kmem_cache_create(s, flags);
90680 if (!err) {
90681- s->refcount = 1;
90682+ atomic_set(&s->refcount, 1);
90683 list_add(&s->list, &slab_caches);
90684 memcg_cache_list_add(memcg, s);
90685 } else {
90686@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
90687
90688 get_online_cpus();
90689 mutex_lock(&slab_mutex);
90690- s->refcount--;
90691- if (!s->refcount) {
90692+ if (atomic_dec_and_test(&s->refcount)) {
90693 list_del(&s->list);
90694
90695 if (!__kmem_cache_shutdown(s)) {
90696@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
90697 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
90698 name, size, err);
90699
90700- s->refcount = -1; /* Exempt from merging for now */
90701+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
90702 }
90703
90704 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90705@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90706
90707 create_boot_cache(s, name, size, flags);
90708 list_add(&s->list, &slab_caches);
90709- s->refcount = 1;
90710+ atomic_set(&s->refcount, 1);
90711 return s;
90712 }
90713
90714@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
90715 EXPORT_SYMBOL(kmalloc_dma_caches);
90716 #endif
90717
90718+#ifdef CONFIG_PAX_USERCOPY_SLABS
90719+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
90720+EXPORT_SYMBOL(kmalloc_usercopy_caches);
90721+#endif
90722+
90723 /*
90724 * Conversion table for small slabs sizes / 8 to the index in the
90725 * kmalloc array. This is necessary for slabs < 192 since we have non power
90726@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
90727 return kmalloc_dma_caches[index];
90728
90729 #endif
90730+
90731+#ifdef CONFIG_PAX_USERCOPY_SLABS
90732+ if (unlikely((flags & GFP_USERCOPY)))
90733+ return kmalloc_usercopy_caches[index];
90734+
90735+#endif
90736+
90737 return kmalloc_caches[index];
90738 }
90739
90740@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
90741 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
90742 if (!kmalloc_caches[i]) {
90743 kmalloc_caches[i] = create_kmalloc_cache(NULL,
90744- 1 << i, flags);
90745+ 1 << i, SLAB_USERCOPY | flags);
90746 }
90747
90748 /*
90749@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
90750 * earlier power of two caches
90751 */
90752 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
90753- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
90754+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
90755
90756 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
90757- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
90758+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
90759 }
90760
90761 /* Kmalloc array is now usable */
90762@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
90763 }
90764 }
90765 #endif
90766+
90767+#ifdef CONFIG_PAX_USERCOPY_SLABS
90768+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
90769+ struct kmem_cache *s = kmalloc_caches[i];
90770+
90771+ if (s) {
90772+ int size = kmalloc_size(i);
90773+ char *n = kasprintf(GFP_NOWAIT,
90774+ "usercopy-kmalloc-%d", size);
90775+
90776+ BUG_ON(!n);
90777+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
90778+ size, SLAB_USERCOPY | flags);
90779+ }
90780+ }
90781+#endif
90782+
90783 }
90784 #endif /* !CONFIG_SLOB */
90785
90786@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
90787 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
90788 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
90789 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
90790+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90791+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
90792+#endif
90793 #endif
90794 seq_putc(m, '\n');
90795 }
90796diff --git a/mm/slob.c b/mm/slob.c
90797index 4bf8809..98a6914 100644
90798--- a/mm/slob.c
90799+++ b/mm/slob.c
90800@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
90801 /*
90802 * Return the size of a slob block.
90803 */
90804-static slobidx_t slob_units(slob_t *s)
90805+static slobidx_t slob_units(const slob_t *s)
90806 {
90807 if (s->units > 0)
90808 return s->units;
90809@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
90810 /*
90811 * Return the next free slob block pointer after this one.
90812 */
90813-static slob_t *slob_next(slob_t *s)
90814+static slob_t *slob_next(const slob_t *s)
90815 {
90816 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
90817 slobidx_t next;
90818@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
90819 /*
90820 * Returns true if s is the last free block in its page.
90821 */
90822-static int slob_last(slob_t *s)
90823+static int slob_last(const slob_t *s)
90824 {
90825 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
90826 }
90827
90828-static void *slob_new_pages(gfp_t gfp, int order, int node)
90829+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
90830 {
90831- void *page;
90832+ struct page *page;
90833
90834 #ifdef CONFIG_NUMA
90835 if (node != NUMA_NO_NODE)
90836@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
90837 if (!page)
90838 return NULL;
90839
90840- return page_address(page);
90841+ __SetPageSlab(page);
90842+ return page;
90843 }
90844
90845-static void slob_free_pages(void *b, int order)
90846+static void slob_free_pages(struct page *sp, int order)
90847 {
90848 if (current->reclaim_state)
90849 current->reclaim_state->reclaimed_slab += 1 << order;
90850- free_pages((unsigned long)b, order);
90851+ __ClearPageSlab(sp);
90852+ page_mapcount_reset(sp);
90853+ sp->private = 0;
90854+ __free_pages(sp, order);
90855 }
90856
90857 /*
90858@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
90859
90860 /* Not enough space: must allocate a new page */
90861 if (!b) {
90862- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
90863- if (!b)
90864+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
90865+ if (!sp)
90866 return NULL;
90867- sp = virt_to_page(b);
90868- __SetPageSlab(sp);
90869+ b = page_address(sp);
90870
90871 spin_lock_irqsave(&slob_lock, flags);
90872 sp->units = SLOB_UNITS(PAGE_SIZE);
90873 sp->freelist = b;
90874+ sp->private = 0;
90875 INIT_LIST_HEAD(&sp->list);
90876 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
90877 set_slob_page_free(sp, slob_list);
90878@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
90879 if (slob_page_free(sp))
90880 clear_slob_page_free(sp);
90881 spin_unlock_irqrestore(&slob_lock, flags);
90882- __ClearPageSlab(sp);
90883- page_mapcount_reset(sp);
90884- slob_free_pages(b, 0);
90885+ slob_free_pages(sp, 0);
90886 return;
90887 }
90888
90889+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90890+ if (pax_sanitize_slab)
90891+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
90892+#endif
90893+
90894 if (!slob_page_free(sp)) {
90895 /* This slob page is about to become partially free. Easy! */
90896 sp->units = units;
90897@@ -424,11 +431,10 @@ out:
90898 */
90899
90900 static __always_inline void *
90901-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
90902+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
90903 {
90904- unsigned int *m;
90905- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90906- void *ret;
90907+ slob_t *m;
90908+ void *ret = NULL;
90909
90910 gfp &= gfp_allowed_mask;
90911
90912@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
90913
90914 if (!m)
90915 return NULL;
90916- *m = size;
90917+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
90918+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
90919+ m[0].units = size;
90920+ m[1].units = align;
90921 ret = (void *)m + align;
90922
90923 trace_kmalloc_node(caller, ret,
90924 size, size + align, gfp, node);
90925 } else {
90926 unsigned int order = get_order(size);
90927+ struct page *page;
90928
90929 if (likely(order))
90930 gfp |= __GFP_COMP;
90931- ret = slob_new_pages(gfp, order, node);
90932+ page = slob_new_pages(gfp, order, node);
90933+ if (page) {
90934+ ret = page_address(page);
90935+ page->private = size;
90936+ }
90937
90938 trace_kmalloc_node(caller, ret,
90939 size, PAGE_SIZE << order, gfp, node);
90940 }
90941
90942- kmemleak_alloc(ret, size, 1, gfp);
90943+ return ret;
90944+}
90945+
90946+static __always_inline void *
90947+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
90948+{
90949+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90950+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
90951+
90952+ if (!ZERO_OR_NULL_PTR(ret))
90953+ kmemleak_alloc(ret, size, 1, gfp);
90954 return ret;
90955 }
90956
90957@@ -493,34 +517,112 @@ void kfree(const void *block)
90958 return;
90959 kmemleak_free(block);
90960
90961+ VM_BUG_ON(!virt_addr_valid(block));
90962 sp = virt_to_page(block);
90963- if (PageSlab(sp)) {
90964+ VM_BUG_ON(!PageSlab(sp));
90965+ if (!sp->private) {
90966 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90967- unsigned int *m = (unsigned int *)(block - align);
90968- slob_free(m, *m + align);
90969- } else
90970+ slob_t *m = (slob_t *)(block - align);
90971+ slob_free(m, m[0].units + align);
90972+ } else {
90973+ __ClearPageSlab(sp);
90974+ page_mapcount_reset(sp);
90975+ sp->private = 0;
90976 __free_pages(sp, compound_order(sp));
90977+ }
90978 }
90979 EXPORT_SYMBOL(kfree);
90980
90981+bool is_usercopy_object(const void *ptr)
90982+{
90983+ if (!slab_is_available())
90984+ return false;
90985+
90986+ // PAX: TODO
90987+
90988+ return false;
90989+}
90990+
90991+#ifdef CONFIG_PAX_USERCOPY
90992+const char *check_heap_object(const void *ptr, unsigned long n)
90993+{
90994+ struct page *page;
90995+ const slob_t *free;
90996+ const void *base;
90997+ unsigned long flags;
90998+
90999+ if (ZERO_OR_NULL_PTR(ptr))
91000+ return "<null>";
91001+
91002+ if (!virt_addr_valid(ptr))
91003+ return NULL;
91004+
91005+ page = virt_to_head_page(ptr);
91006+ if (!PageSlab(page))
91007+ return NULL;
91008+
91009+ if (page->private) {
91010+ base = page;
91011+ if (base <= ptr && n <= page->private - (ptr - base))
91012+ return NULL;
91013+ return "<slob>";
91014+ }
91015+
91016+ /* some tricky double walking to find the chunk */
91017+ spin_lock_irqsave(&slob_lock, flags);
91018+ base = (void *)((unsigned long)ptr & PAGE_MASK);
91019+ free = page->freelist;
91020+
91021+ while (!slob_last(free) && (void *)free <= ptr) {
91022+ base = free + slob_units(free);
91023+ free = slob_next(free);
91024+ }
91025+
91026+ while (base < (void *)free) {
91027+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
91028+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
91029+ int offset;
91030+
91031+ if (ptr < base + align)
91032+ break;
91033+
91034+ offset = ptr - base - align;
91035+ if (offset >= m) {
91036+ base += size;
91037+ continue;
91038+ }
91039+
91040+ if (n > m - offset)
91041+ break;
91042+
91043+ spin_unlock_irqrestore(&slob_lock, flags);
91044+ return NULL;
91045+ }
91046+
91047+ spin_unlock_irqrestore(&slob_lock, flags);
91048+ return "<slob>";
91049+}
91050+#endif
91051+
91052 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
91053 size_t ksize(const void *block)
91054 {
91055 struct page *sp;
91056 int align;
91057- unsigned int *m;
91058+ slob_t *m;
91059
91060 BUG_ON(!block);
91061 if (unlikely(block == ZERO_SIZE_PTR))
91062 return 0;
91063
91064 sp = virt_to_page(block);
91065- if (unlikely(!PageSlab(sp)))
91066- return PAGE_SIZE << compound_order(sp);
91067+ VM_BUG_ON(!PageSlab(sp));
91068+ if (sp->private)
91069+ return sp->private;
91070
91071 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91072- m = (unsigned int *)(block - align);
91073- return SLOB_UNITS(*m) * SLOB_UNIT;
91074+ m = (slob_t *)(block - align);
91075+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
91076 }
91077 EXPORT_SYMBOL(ksize);
91078
91079@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
91080
91081 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
91082 {
91083- void *b;
91084+ void *b = NULL;
91085
91086 flags &= gfp_allowed_mask;
91087
91088 lockdep_trace_alloc(flags);
91089
91090+#ifdef CONFIG_PAX_USERCOPY_SLABS
91091+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
91092+#else
91093 if (c->size < PAGE_SIZE) {
91094 b = slob_alloc(c->size, flags, c->align, node);
91095 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91096 SLOB_UNITS(c->size) * SLOB_UNIT,
91097 flags, node);
91098 } else {
91099- b = slob_new_pages(flags, get_order(c->size), node);
91100+ struct page *sp;
91101+
91102+ sp = slob_new_pages(flags, get_order(c->size), node);
91103+ if (sp) {
91104+ b = page_address(sp);
91105+ sp->private = c->size;
91106+ }
91107 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91108 PAGE_SIZE << get_order(c->size),
91109 flags, node);
91110 }
91111+#endif
91112
91113 if (b && c->ctor)
91114 c->ctor(b);
91115@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
91116
91117 static void __kmem_cache_free(void *b, int size)
91118 {
91119- if (size < PAGE_SIZE)
91120+ struct page *sp;
91121+
91122+ sp = virt_to_page(b);
91123+ BUG_ON(!PageSlab(sp));
91124+ if (!sp->private)
91125 slob_free(b, size);
91126 else
91127- slob_free_pages(b, get_order(size));
91128+ slob_free_pages(sp, get_order(size));
91129 }
91130
91131 static void kmem_rcu_free(struct rcu_head *head)
91132@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
91133
91134 void kmem_cache_free(struct kmem_cache *c, void *b)
91135 {
91136+ int size = c->size;
91137+
91138+#ifdef CONFIG_PAX_USERCOPY_SLABS
91139+ if (size + c->align < PAGE_SIZE) {
91140+ size += c->align;
91141+ b -= c->align;
91142+ }
91143+#endif
91144+
91145 kmemleak_free_recursive(b, c->flags);
91146 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
91147 struct slob_rcu *slob_rcu;
91148- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
91149- slob_rcu->size = c->size;
91150+ slob_rcu = b + (size - sizeof(struct slob_rcu));
91151+ slob_rcu->size = size;
91152 call_rcu(&slob_rcu->head, kmem_rcu_free);
91153 } else {
91154- __kmem_cache_free(b, c->size);
91155+ __kmem_cache_free(b, size);
91156 }
91157
91158+#ifdef CONFIG_PAX_USERCOPY_SLABS
91159+ trace_kfree(_RET_IP_, b);
91160+#else
91161 trace_kmem_cache_free(_RET_IP_, b);
91162+#endif
91163+
91164 }
91165 EXPORT_SYMBOL(kmem_cache_free);
91166
91167diff --git a/mm/slub.c b/mm/slub.c
91168index 96f2169..9111a59 100644
91169--- a/mm/slub.c
91170+++ b/mm/slub.c
91171@@ -207,7 +207,7 @@ struct track {
91172
91173 enum track_item { TRACK_ALLOC, TRACK_FREE };
91174
91175-#ifdef CONFIG_SYSFS
91176+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91177 static int sysfs_slab_add(struct kmem_cache *);
91178 static int sysfs_slab_alias(struct kmem_cache *, const char *);
91179 static void sysfs_slab_remove(struct kmem_cache *);
91180@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
91181 if (!t->addr)
91182 return;
91183
91184- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
91185+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
91186 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
91187 #ifdef CONFIG_STACKTRACE
91188 {
91189@@ -2616,6 +2616,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
91190
91191 slab_free_hook(s, x);
91192
91193+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91194+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
91195+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
91196+ if (s->ctor)
91197+ s->ctor(x);
91198+ }
91199+#endif
91200+
91201 redo:
91202 /*
91203 * Determine the currently cpus per cpu slab.
91204@@ -2683,7 +2691,7 @@ static int slub_min_objects;
91205 * Merge control. If this is set then no merging of slab caches will occur.
91206 * (Could be removed. This was introduced to pacify the merge skeptics.)
91207 */
91208-static int slub_nomerge;
91209+static int slub_nomerge = 1;
91210
91211 /*
91212 * Calculate the order of allocation given an slab object size.
91213@@ -2960,6 +2968,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
91214 s->inuse = size;
91215
91216 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
91217+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91218+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
91219+#endif
91220 s->ctor)) {
91221 /*
91222 * Relocate free pointer after the object if it is not
91223@@ -3305,6 +3316,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
91224 EXPORT_SYMBOL(__kmalloc_node);
91225 #endif
91226
91227+bool is_usercopy_object(const void *ptr)
91228+{
91229+ struct page *page;
91230+ struct kmem_cache *s;
91231+
91232+ if (ZERO_OR_NULL_PTR(ptr))
91233+ return false;
91234+
91235+ if (!slab_is_available())
91236+ return false;
91237+
91238+ if (!virt_addr_valid(ptr))
91239+ return false;
91240+
91241+ page = virt_to_head_page(ptr);
91242+
91243+ if (!PageSlab(page))
91244+ return false;
91245+
91246+ s = page->slab_cache;
91247+ return s->flags & SLAB_USERCOPY;
91248+}
91249+
91250+#ifdef CONFIG_PAX_USERCOPY
91251+const char *check_heap_object(const void *ptr, unsigned long n)
91252+{
91253+ struct page *page;
91254+ struct kmem_cache *s;
91255+ unsigned long offset;
91256+
91257+ if (ZERO_OR_NULL_PTR(ptr))
91258+ return "<null>";
91259+
91260+ if (!virt_addr_valid(ptr))
91261+ return NULL;
91262+
91263+ page = virt_to_head_page(ptr);
91264+
91265+ if (!PageSlab(page))
91266+ return NULL;
91267+
91268+ s = page->slab_cache;
91269+ if (!(s->flags & SLAB_USERCOPY))
91270+ return s->name;
91271+
91272+ offset = (ptr - page_address(page)) % s->size;
91273+ if (offset <= s->object_size && n <= s->object_size - offset)
91274+ return NULL;
91275+
91276+ return s->name;
91277+}
91278+#endif
91279+
91280 size_t ksize(const void *object)
91281 {
91282 struct page *page;
91283@@ -3333,6 +3397,7 @@ void kfree(const void *x)
91284 if (unlikely(ZERO_OR_NULL_PTR(x)))
91285 return;
91286
91287+ VM_BUG_ON(!virt_addr_valid(x));
91288 page = virt_to_head_page(x);
91289 if (unlikely(!PageSlab(page))) {
91290 BUG_ON(!PageCompound(page));
91291@@ -3638,7 +3703,7 @@ static int slab_unmergeable(struct kmem_cache *s)
91292 /*
91293 * We may have set a slab to be unmergeable during bootstrap.
91294 */
91295- if (s->refcount < 0)
91296+ if (atomic_read(&s->refcount) < 0)
91297 return 1;
91298
91299 return 0;
91300@@ -3696,7 +3761,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91301
91302 s = find_mergeable(memcg, size, align, flags, name, ctor);
91303 if (s) {
91304- s->refcount++;
91305+ atomic_inc(&s->refcount);
91306 /*
91307 * Adjust the object sizes so that we clear
91308 * the complete object on kzalloc.
91309@@ -3705,7 +3770,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91310 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
91311
91312 if (sysfs_slab_alias(s, name)) {
91313- s->refcount--;
91314+ atomic_dec(&s->refcount);
91315 s = NULL;
91316 }
91317 }
91318@@ -3825,7 +3890,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
91319 }
91320 #endif
91321
91322-#ifdef CONFIG_SYSFS
91323+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91324 static int count_inuse(struct page *page)
91325 {
91326 return page->inuse;
91327@@ -4214,12 +4279,12 @@ static void resiliency_test(void)
91328 validate_slab_cache(kmalloc_caches[9]);
91329 }
91330 #else
91331-#ifdef CONFIG_SYSFS
91332+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91333 static void resiliency_test(void) {};
91334 #endif
91335 #endif
91336
91337-#ifdef CONFIG_SYSFS
91338+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91339 enum slab_stat_type {
91340 SL_ALL, /* All slabs */
91341 SL_PARTIAL, /* Only partially allocated slabs */
91342@@ -4459,7 +4524,7 @@ SLAB_ATTR_RO(ctor);
91343
91344 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
91345 {
91346- return sprintf(buf, "%d\n", s->refcount - 1);
91347+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
91348 }
91349 SLAB_ATTR_RO(aliases);
91350
91351@@ -4547,6 +4612,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
91352 SLAB_ATTR_RO(cache_dma);
91353 #endif
91354
91355+#ifdef CONFIG_PAX_USERCOPY_SLABS
91356+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
91357+{
91358+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
91359+}
91360+SLAB_ATTR_RO(usercopy);
91361+#endif
91362+
91363 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
91364 {
91365 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
91366@@ -4881,6 +4954,9 @@ static struct attribute *slab_attrs[] = {
91367 #ifdef CONFIG_ZONE_DMA
91368 &cache_dma_attr.attr,
91369 #endif
91370+#ifdef CONFIG_PAX_USERCOPY_SLABS
91371+ &usercopy_attr.attr,
91372+#endif
91373 #ifdef CONFIG_NUMA
91374 &remote_node_defrag_ratio_attr.attr,
91375 #endif
91376@@ -5113,6 +5189,7 @@ static char *create_unique_id(struct kmem_cache *s)
91377 return name;
91378 }
91379
91380+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91381 static int sysfs_slab_add(struct kmem_cache *s)
91382 {
91383 int err;
91384@@ -5136,7 +5213,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
91385 }
91386
91387 s->kobj.kset = slab_kset;
91388- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
91389+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
91390 if (err) {
91391 kobject_put(&s->kobj);
91392 return err;
91393@@ -5170,6 +5247,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
91394 kobject_del(&s->kobj);
91395 kobject_put(&s->kobj);
91396 }
91397+#endif
91398
91399 /*
91400 * Need to buffer aliases during bootup until sysfs becomes
91401@@ -5183,6 +5261,7 @@ struct saved_alias {
91402
91403 static struct saved_alias *alias_list;
91404
91405+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91406 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91407 {
91408 struct saved_alias *al;
91409@@ -5205,6 +5284,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91410 alias_list = al;
91411 return 0;
91412 }
91413+#endif
91414
91415 static int __init slab_sysfs_init(void)
91416 {
91417diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
91418index 27eeab3..7c3f7f2 100644
91419--- a/mm/sparse-vmemmap.c
91420+++ b/mm/sparse-vmemmap.c
91421@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
91422 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91423 if (!p)
91424 return NULL;
91425- pud_populate(&init_mm, pud, p);
91426+ pud_populate_kernel(&init_mm, pud, p);
91427 }
91428 return pud;
91429 }
91430@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
91431 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91432 if (!p)
91433 return NULL;
91434- pgd_populate(&init_mm, pgd, p);
91435+ pgd_populate_kernel(&init_mm, pgd, p);
91436 }
91437 return pgd;
91438 }
91439diff --git a/mm/sparse.c b/mm/sparse.c
91440index 4ac1d7e..bbfcb1f 100644
91441--- a/mm/sparse.c
91442+++ b/mm/sparse.c
91443@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
91444
91445 for (i = 0; i < PAGES_PER_SECTION; i++) {
91446 if (PageHWPoison(&memmap[i])) {
91447- atomic_long_sub(1, &num_poisoned_pages);
91448+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
91449 ClearPageHWPoison(&memmap[i]);
91450 }
91451 }
91452diff --git a/mm/swap.c b/mm/swap.c
91453index 759c3ca..7c1a5b4 100644
91454--- a/mm/swap.c
91455+++ b/mm/swap.c
91456@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
91457
91458 __page_cache_release(page);
91459 dtor = get_compound_page_dtor(page);
91460+ if (!PageHuge(page))
91461+ BUG_ON(dtor != free_compound_page);
91462 (*dtor)(page);
91463 }
91464
91465diff --git a/mm/swapfile.c b/mm/swapfile.c
91466index de7c904..c84bf11 100644
91467--- a/mm/swapfile.c
91468+++ b/mm/swapfile.c
91469@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
91470
91471 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
91472 /* Activity counter to indicate that a swapon or swapoff has occurred */
91473-static atomic_t proc_poll_event = ATOMIC_INIT(0);
91474+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
91475
91476 static inline unsigned char swap_count(unsigned char ent)
91477 {
91478@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
91479 }
91480 filp_close(swap_file, NULL);
91481 err = 0;
91482- atomic_inc(&proc_poll_event);
91483+ atomic_inc_unchecked(&proc_poll_event);
91484 wake_up_interruptible(&proc_poll_wait);
91485
91486 out_dput:
91487@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
91488
91489 poll_wait(file, &proc_poll_wait, wait);
91490
91491- if (seq->poll_event != atomic_read(&proc_poll_event)) {
91492- seq->poll_event = atomic_read(&proc_poll_event);
91493+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
91494+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91495 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
91496 }
91497
91498@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
91499 return ret;
91500
91501 seq = file->private_data;
91502- seq->poll_event = atomic_read(&proc_poll_event);
91503+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91504 return 0;
91505 }
91506
91507@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
91508 (frontswap_map) ? "FS" : "");
91509
91510 mutex_unlock(&swapon_mutex);
91511- atomic_inc(&proc_poll_event);
91512+ atomic_inc_unchecked(&proc_poll_event);
91513 wake_up_interruptible(&proc_poll_wait);
91514
91515 if (S_ISREG(inode->i_mode))
91516diff --git a/mm/util.c b/mm/util.c
91517index eaf63fc2..32b2629 100644
91518--- a/mm/util.c
91519+++ b/mm/util.c
91520@@ -294,6 +294,12 @@ done:
91521 void arch_pick_mmap_layout(struct mm_struct *mm)
91522 {
91523 mm->mmap_base = TASK_UNMAPPED_BASE;
91524+
91525+#ifdef CONFIG_PAX_RANDMMAP
91526+ if (mm->pax_flags & MF_PAX_RANDMMAP)
91527+ mm->mmap_base += mm->delta_mmap;
91528+#endif
91529+
91530 mm->get_unmapped_area = arch_get_unmapped_area;
91531 }
91532 #endif
91533diff --git a/mm/vmalloc.c b/mm/vmalloc.c
91534index 1074543..136dbe0 100644
91535--- a/mm/vmalloc.c
91536+++ b/mm/vmalloc.c
91537@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
91538
91539 pte = pte_offset_kernel(pmd, addr);
91540 do {
91541- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91542- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91543+
91544+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91545+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
91546+ BUG_ON(!pte_exec(*pte));
91547+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
91548+ continue;
91549+ }
91550+#endif
91551+
91552+ {
91553+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91554+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91555+ }
91556 } while (pte++, addr += PAGE_SIZE, addr != end);
91557 }
91558
91559@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
91560 pte = pte_alloc_kernel(pmd, addr);
91561 if (!pte)
91562 return -ENOMEM;
91563+
91564+ pax_open_kernel();
91565 do {
91566 struct page *page = pages[*nr];
91567
91568- if (WARN_ON(!pte_none(*pte)))
91569+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91570+ if (pgprot_val(prot) & _PAGE_NX)
91571+#endif
91572+
91573+ if (!pte_none(*pte)) {
91574+ pax_close_kernel();
91575+ WARN_ON(1);
91576 return -EBUSY;
91577- if (WARN_ON(!page))
91578+ }
91579+ if (!page) {
91580+ pax_close_kernel();
91581+ WARN_ON(1);
91582 return -ENOMEM;
91583+ }
91584 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
91585 (*nr)++;
91586 } while (pte++, addr += PAGE_SIZE, addr != end);
91587+ pax_close_kernel();
91588 return 0;
91589 }
91590
91591@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
91592 pmd_t *pmd;
91593 unsigned long next;
91594
91595- pmd = pmd_alloc(&init_mm, pud, addr);
91596+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91597 if (!pmd)
91598 return -ENOMEM;
91599 do {
91600@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
91601 pud_t *pud;
91602 unsigned long next;
91603
91604- pud = pud_alloc(&init_mm, pgd, addr);
91605+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91606 if (!pud)
91607 return -ENOMEM;
91608 do {
91609@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
91610 if (addr >= MODULES_VADDR && addr < MODULES_END)
91611 return 1;
91612 #endif
91613+
91614+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91615+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
91616+ return 1;
91617+#endif
91618+
91619 return is_vmalloc_addr(x);
91620 }
91621
91622@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
91623
91624 if (!pgd_none(*pgd)) {
91625 pud_t *pud = pud_offset(pgd, addr);
91626+#ifdef CONFIG_X86
91627+ if (!pud_large(*pud))
91628+#endif
91629 if (!pud_none(*pud)) {
91630 pmd_t *pmd = pmd_offset(pud, addr);
91631+#ifdef CONFIG_X86
91632+ if (!pmd_large(*pmd))
91633+#endif
91634 if (!pmd_none(*pmd)) {
91635 pte_t *ptep, pte;
91636
91637@@ -1303,6 +1339,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
91638 struct vm_struct *area;
91639
91640 BUG_ON(in_interrupt());
91641+
91642+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91643+ if (flags & VM_KERNEXEC) {
91644+ if (start != VMALLOC_START || end != VMALLOC_END)
91645+ return NULL;
91646+ start = (unsigned long)MODULES_EXEC_VADDR;
91647+ end = (unsigned long)MODULES_EXEC_END;
91648+ }
91649+#endif
91650+
91651 if (flags & VM_IOREMAP)
91652 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
91653
91654@@ -1528,6 +1574,11 @@ void *vmap(struct page **pages, unsigned int count,
91655 if (count > totalram_pages)
91656 return NULL;
91657
91658+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91659+ if (!(pgprot_val(prot) & _PAGE_NX))
91660+ flags |= VM_KERNEXEC;
91661+#endif
91662+
91663 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
91664 __builtin_return_address(0));
91665 if (!area)
91666@@ -1629,6 +1680,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
91667 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
91668 goto fail;
91669
91670+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91671+ if (!(pgprot_val(prot) & _PAGE_NX))
91672+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
91673+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
91674+ else
91675+#endif
91676+
91677 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
91678 start, end, node, gfp_mask, caller);
91679 if (!area)
91680@@ -1805,10 +1863,9 @@ EXPORT_SYMBOL(vzalloc_node);
91681 * For tight control over page level allocator and protection flags
91682 * use __vmalloc() instead.
91683 */
91684-
91685 void *vmalloc_exec(unsigned long size)
91686 {
91687- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
91688+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
91689 NUMA_NO_NODE, __builtin_return_address(0));
91690 }
91691
91692@@ -2115,6 +2172,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
91693 {
91694 struct vm_struct *area;
91695
91696+ BUG_ON(vma->vm_mirror);
91697+
91698 size = PAGE_ALIGN(size);
91699
91700 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
91701@@ -2600,7 +2659,11 @@ static int s_show(struct seq_file *m, void *p)
91702 v->addr, v->addr + v->size, v->size);
91703
91704 if (v->caller)
91705+#ifdef CONFIG_GRKERNSEC_HIDESYM
91706+ seq_printf(m, " %pK", v->caller);
91707+#else
91708 seq_printf(m, " %pS", v->caller);
91709+#endif
91710
91711 if (v->nr_pages)
91712 seq_printf(m, " pages=%d", v->nr_pages);
91713diff --git a/mm/vmstat.c b/mm/vmstat.c
91714index 9bb3145..98e5f68 100644
91715--- a/mm/vmstat.c
91716+++ b/mm/vmstat.c
91717@@ -79,7 +79,7 @@ void vm_events_fold_cpu(int cpu)
91718 *
91719 * vm_stat contains the global counters
91720 */
91721-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
91722+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
91723 EXPORT_SYMBOL(vm_stat);
91724
91725 #ifdef CONFIG_SMP
91726@@ -423,7 +423,7 @@ static inline void fold_diff(int *diff)
91727
91728 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
91729 if (diff[i])
91730- atomic_long_add(diff[i], &vm_stat[i]);
91731+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
91732 }
91733
91734 /*
91735@@ -455,7 +455,7 @@ static void refresh_cpu_vm_stats(void)
91736 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
91737 if (v) {
91738
91739- atomic_long_add(v, &zone->vm_stat[i]);
91740+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
91741 global_diff[i] += v;
91742 #ifdef CONFIG_NUMA
91743 /* 3 seconds idle till flush */
91744@@ -517,7 +517,7 @@ void cpu_vm_stats_fold(int cpu)
91745
91746 v = p->vm_stat_diff[i];
91747 p->vm_stat_diff[i] = 0;
91748- atomic_long_add(v, &zone->vm_stat[i]);
91749+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
91750 global_diff[i] += v;
91751 }
91752 }
91753@@ -537,8 +537,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
91754 if (pset->vm_stat_diff[i]) {
91755 int v = pset->vm_stat_diff[i];
91756 pset->vm_stat_diff[i] = 0;
91757- atomic_long_add(v, &zone->vm_stat[i]);
91758- atomic_long_add(v, &vm_stat[i]);
91759+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
91760+ atomic_long_add_unchecked(v, &vm_stat[i]);
91761 }
91762 }
91763 #endif
91764@@ -1280,10 +1280,20 @@ static int __init setup_vmstat(void)
91765 start_cpu_timer(cpu);
91766 #endif
91767 #ifdef CONFIG_PROC_FS
91768- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
91769- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
91770- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
91771- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
91772+ {
91773+ mode_t gr_mode = S_IRUGO;
91774+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91775+ gr_mode = S_IRUSR;
91776+#endif
91777+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
91778+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
91779+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
91780+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
91781+#else
91782+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
91783+#endif
91784+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
91785+ }
91786 #endif
91787 return 0;
91788 }
91789diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
91790index 61fc573..b5e47d0 100644
91791--- a/net/8021q/vlan.c
91792+++ b/net/8021q/vlan.c
91793@@ -472,7 +472,7 @@ out:
91794 return NOTIFY_DONE;
91795 }
91796
91797-static struct notifier_block vlan_notifier_block __read_mostly = {
91798+static struct notifier_block vlan_notifier_block = {
91799 .notifier_call = vlan_device_event,
91800 };
91801
91802@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
91803 err = -EPERM;
91804 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
91805 break;
91806- if ((args.u.name_type >= 0) &&
91807- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
91808+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
91809 struct vlan_net *vn;
91810
91811 vn = net_generic(net, vlan_net_id);
91812diff --git a/net/9p/mod.c b/net/9p/mod.c
91813index 6ab36ae..6f1841b 100644
91814--- a/net/9p/mod.c
91815+++ b/net/9p/mod.c
91816@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
91817 void v9fs_register_trans(struct p9_trans_module *m)
91818 {
91819 spin_lock(&v9fs_trans_lock);
91820- list_add_tail(&m->list, &v9fs_trans_list);
91821+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
91822 spin_unlock(&v9fs_trans_lock);
91823 }
91824 EXPORT_SYMBOL(v9fs_register_trans);
91825@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
91826 void v9fs_unregister_trans(struct p9_trans_module *m)
91827 {
91828 spin_lock(&v9fs_trans_lock);
91829- list_del_init(&m->list);
91830+ pax_list_del_init((struct list_head *)&m->list);
91831 spin_unlock(&v9fs_trans_lock);
91832 }
91833 EXPORT_SYMBOL(v9fs_unregister_trans);
91834diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
91835index 3ffda1b..fceac96 100644
91836--- a/net/9p/trans_fd.c
91837+++ b/net/9p/trans_fd.c
91838@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
91839 oldfs = get_fs();
91840 set_fs(get_ds());
91841 /* The cast to a user pointer is valid due to the set_fs() */
91842- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
91843+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
91844 set_fs(oldfs);
91845
91846 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
91847diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
91848index 876fbe8..8bbea9f 100644
91849--- a/net/atm/atm_misc.c
91850+++ b/net/atm/atm_misc.c
91851@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
91852 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
91853 return 1;
91854 atm_return(vcc, truesize);
91855- atomic_inc(&vcc->stats->rx_drop);
91856+ atomic_inc_unchecked(&vcc->stats->rx_drop);
91857 return 0;
91858 }
91859 EXPORT_SYMBOL(atm_charge);
91860@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
91861 }
91862 }
91863 atm_return(vcc, guess);
91864- atomic_inc(&vcc->stats->rx_drop);
91865+ atomic_inc_unchecked(&vcc->stats->rx_drop);
91866 return NULL;
91867 }
91868 EXPORT_SYMBOL(atm_alloc_charge);
91869@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
91870
91871 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
91872 {
91873-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
91874+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
91875 __SONET_ITEMS
91876 #undef __HANDLE_ITEM
91877 }
91878@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
91879
91880 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
91881 {
91882-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
91883+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
91884 __SONET_ITEMS
91885 #undef __HANDLE_ITEM
91886 }
91887diff --git a/net/atm/lec.h b/net/atm/lec.h
91888index 4149db1..f2ab682 100644
91889--- a/net/atm/lec.h
91890+++ b/net/atm/lec.h
91891@@ -48,7 +48,7 @@ struct lane2_ops {
91892 const u8 *tlvs, u32 sizeoftlvs);
91893 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
91894 const u8 *tlvs, u32 sizeoftlvs);
91895-};
91896+} __no_const;
91897
91898 /*
91899 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
91900diff --git a/net/atm/proc.c b/net/atm/proc.c
91901index bbb6461..cf04016 100644
91902--- a/net/atm/proc.c
91903+++ b/net/atm/proc.c
91904@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
91905 const struct k_atm_aal_stats *stats)
91906 {
91907 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
91908- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
91909- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
91910- atomic_read(&stats->rx_drop));
91911+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
91912+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
91913+ atomic_read_unchecked(&stats->rx_drop));
91914 }
91915
91916 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
91917diff --git a/net/atm/resources.c b/net/atm/resources.c
91918index 0447d5d..3cf4728 100644
91919--- a/net/atm/resources.c
91920+++ b/net/atm/resources.c
91921@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
91922 static void copy_aal_stats(struct k_atm_aal_stats *from,
91923 struct atm_aal_stats *to)
91924 {
91925-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
91926+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
91927 __AAL_STAT_ITEMS
91928 #undef __HANDLE_ITEM
91929 }
91930@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
91931 static void subtract_aal_stats(struct k_atm_aal_stats *from,
91932 struct atm_aal_stats *to)
91933 {
91934-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
91935+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
91936 __AAL_STAT_ITEMS
91937 #undef __HANDLE_ITEM
91938 }
91939diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
91940index 919a5ce..cc6b444 100644
91941--- a/net/ax25/sysctl_net_ax25.c
91942+++ b/net/ax25/sysctl_net_ax25.c
91943@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
91944 {
91945 char path[sizeof("net/ax25/") + IFNAMSIZ];
91946 int k;
91947- struct ctl_table *table;
91948+ ctl_table_no_const *table;
91949
91950 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
91951 if (!table)
91952diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
91953index 0a8a80c..f7e89aa 100644
91954--- a/net/batman-adv/bat_iv_ogm.c
91955+++ b/net/batman-adv/bat_iv_ogm.c
91956@@ -121,7 +121,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
91957
91958 /* randomize initial seqno to avoid collision */
91959 get_random_bytes(&random_seqno, sizeof(random_seqno));
91960- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
91961+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
91962
91963 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
91964 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
91965@@ -703,9 +703,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
91966 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
91967
91968 /* change sequence number to network order */
91969- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
91970+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
91971 batadv_ogm_packet->seqno = htonl(seqno);
91972- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
91973+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
91974
91975 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
91976 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
91977@@ -1111,7 +1111,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
91978 return;
91979
91980 /* could be changed by schedule_own_packet() */
91981- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
91982+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
91983
91984 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
91985 has_directlink_flag = 1;
91986diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
91987index c478e6b..469fd2f 100644
91988--- a/net/batman-adv/hard-interface.c
91989+++ b/net/batman-adv/hard-interface.c
91990@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
91991 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
91992 dev_add_pack(&hard_iface->batman_adv_ptype);
91993
91994- atomic_set(&hard_iface->frag_seqno, 1);
91995+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
91996 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
91997 hard_iface->net_dev->name);
91998
91999diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
92000index 813db4e..847edac 100644
92001--- a/net/batman-adv/soft-interface.c
92002+++ b/net/batman-adv/soft-interface.c
92003@@ -263,7 +263,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
92004 primary_if->net_dev->dev_addr, ETH_ALEN);
92005
92006 /* set broadcast sequence number */
92007- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
92008+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
92009 bcast_packet->seqno = htonl(seqno);
92010
92011 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
92012@@ -483,7 +483,7 @@ static int batadv_softif_init_late(struct net_device *dev)
92013 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
92014
92015 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
92016- atomic_set(&bat_priv->bcast_seqno, 1);
92017+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
92018 atomic_set(&bat_priv->tt.vn, 0);
92019 atomic_set(&bat_priv->tt.local_changes, 0);
92020 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
92021diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
92022index b2c94e1..3d47e07 100644
92023--- a/net/batman-adv/types.h
92024+++ b/net/batman-adv/types.h
92025@@ -51,7 +51,7 @@
92026 struct batadv_hard_iface_bat_iv {
92027 unsigned char *ogm_buff;
92028 int ogm_buff_len;
92029- atomic_t ogm_seqno;
92030+ atomic_unchecked_t ogm_seqno;
92031 };
92032
92033 /**
92034@@ -76,7 +76,7 @@ struct batadv_hard_iface {
92035 int16_t if_num;
92036 char if_status;
92037 struct net_device *net_dev;
92038- atomic_t frag_seqno;
92039+ atomic_unchecked_t frag_seqno;
92040 uint8_t num_bcasts;
92041 struct kobject *hardif_obj;
92042 atomic_t refcount;
92043@@ -560,7 +560,7 @@ struct batadv_priv {
92044 #ifdef CONFIG_BATMAN_ADV_DEBUG
92045 atomic_t log_level;
92046 #endif
92047- atomic_t bcast_seqno;
92048+ atomic_unchecked_t bcast_seqno;
92049 atomic_t bcast_queue_left;
92050 atomic_t batman_queue_left;
92051 char num_ifaces;
92052diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
92053index 48b31d3..62a0bcb 100644
92054--- a/net/batman-adv/unicast.c
92055+++ b/net/batman-adv/unicast.c
92056@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
92057 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
92058 frag2->flags = large_tail;
92059
92060- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
92061+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
92062 frag1->seqno = htons(seqno - 1);
92063 frag2->seqno = htons(seqno);
92064
92065diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
92066index 9bd7d95..6c4884f 100644
92067--- a/net/bluetooth/hci_sock.c
92068+++ b/net/bluetooth/hci_sock.c
92069@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
92070 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
92071 }
92072
92073- len = min_t(unsigned int, len, sizeof(uf));
92074+ len = min((size_t)len, sizeof(uf));
92075 if (copy_from_user(&uf, optval, len)) {
92076 err = -EFAULT;
92077 break;
92078diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
92079index 63fa111..b166ec6 100644
92080--- a/net/bluetooth/l2cap_core.c
92081+++ b/net/bluetooth/l2cap_core.c
92082@@ -3511,8 +3511,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
92083 break;
92084
92085 case L2CAP_CONF_RFC:
92086- if (olen == sizeof(rfc))
92087- memcpy(&rfc, (void *)val, olen);
92088+ if (olen != sizeof(rfc))
92089+ break;
92090+
92091+ memcpy(&rfc, (void *)val, olen);
92092
92093 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
92094 rfc.mode != chan->mode)
92095diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
92096index 0098af8..fb5a31f 100644
92097--- a/net/bluetooth/l2cap_sock.c
92098+++ b/net/bluetooth/l2cap_sock.c
92099@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92100 struct sock *sk = sock->sk;
92101 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
92102 struct l2cap_options opts;
92103- int len, err = 0;
92104+ int err = 0;
92105+ size_t len = optlen;
92106 u32 opt;
92107
92108 BT_DBG("sk %p", sk);
92109@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92110 opts.max_tx = chan->max_tx;
92111 opts.txwin_size = chan->tx_win;
92112
92113- len = min_t(unsigned int, sizeof(opts), optlen);
92114+ len = min(sizeof(opts), len);
92115 if (copy_from_user((char *) &opts, optval, len)) {
92116 err = -EFAULT;
92117 break;
92118@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92119 struct bt_security sec;
92120 struct bt_power pwr;
92121 struct l2cap_conn *conn;
92122- int len, err = 0;
92123+ int err = 0;
92124+ size_t len = optlen;
92125 u32 opt;
92126
92127 BT_DBG("sk %p", sk);
92128@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92129
92130 sec.level = BT_SECURITY_LOW;
92131
92132- len = min_t(unsigned int, sizeof(sec), optlen);
92133+ len = min(sizeof(sec), len);
92134 if (copy_from_user((char *) &sec, optval, len)) {
92135 err = -EFAULT;
92136 break;
92137@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92138
92139 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
92140
92141- len = min_t(unsigned int, sizeof(pwr), optlen);
92142+ len = min(sizeof(pwr), len);
92143 if (copy_from_user((char *) &pwr, optval, len)) {
92144 err = -EFAULT;
92145 break;
92146diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
92147index 30b3721..c1bd0a0 100644
92148--- a/net/bluetooth/rfcomm/sock.c
92149+++ b/net/bluetooth/rfcomm/sock.c
92150@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92151 struct sock *sk = sock->sk;
92152 struct bt_security sec;
92153 int err = 0;
92154- size_t len;
92155+ size_t len = optlen;
92156 u32 opt;
92157
92158 BT_DBG("sk %p", sk);
92159@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92160
92161 sec.level = BT_SECURITY_LOW;
92162
92163- len = min_t(unsigned int, sizeof(sec), optlen);
92164+ len = min(sizeof(sec), len);
92165 if (copy_from_user((char *) &sec, optval, len)) {
92166 err = -EFAULT;
92167 break;
92168diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
92169index 84fcf9f..e389b27 100644
92170--- a/net/bluetooth/rfcomm/tty.c
92171+++ b/net/bluetooth/rfcomm/tty.c
92172@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
92173 BT_DBG("tty %p id %d", tty, tty->index);
92174
92175 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
92176- dev->channel, dev->port.count);
92177+ dev->channel, atomic_read(&dev->port.count));
92178
92179 err = tty_port_open(&dev->port, tty, filp);
92180 if (err)
92181@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
92182 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
92183
92184 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
92185- dev->port.count);
92186+ atomic_read(&dev->port.count));
92187
92188 tty_port_close(&dev->port, tty, filp);
92189 }
92190diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
92191index 5180938..7c470c3 100644
92192--- a/net/bridge/netfilter/ebt_ulog.c
92193+++ b/net/bridge/netfilter/ebt_ulog.c
92194@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
92195 ub->qlen++;
92196
92197 pm = nlmsg_data(nlh);
92198+ memset(pm, 0, sizeof(*pm));
92199
92200 /* Fill in the ulog data */
92201 pm->version = EBT_ULOG_VERSION;
92202@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
92203 pm->hook = hooknr;
92204 if (uloginfo->prefix != NULL)
92205 strcpy(pm->prefix, uloginfo->prefix);
92206- else
92207- *(pm->prefix) = '\0';
92208
92209 if (in) {
92210 strcpy(pm->physindev, in->name);
92211@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
92212 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
92213 else
92214 strcpy(pm->indev, in->name);
92215- } else
92216- pm->indev[0] = pm->physindev[0] = '\0';
92217+ }
92218
92219 if (out) {
92220 /* If out exists, then out is a bridge port */
92221 strcpy(pm->physoutdev, out->name);
92222 /* rcu_read_lock()ed by nf_hook_slow */
92223 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
92224- } else
92225- pm->outdev[0] = pm->physoutdev[0] = '\0';
92226+ }
92227
92228 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
92229 BUG();
92230diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
92231index ac78024..161a80c 100644
92232--- a/net/bridge/netfilter/ebtables.c
92233+++ b/net/bridge/netfilter/ebtables.c
92234@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92235 tmp.valid_hooks = t->table->valid_hooks;
92236 }
92237 mutex_unlock(&ebt_mutex);
92238- if (copy_to_user(user, &tmp, *len) != 0){
92239+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
92240 BUGPRINT("c2u Didn't work\n");
92241 ret = -EFAULT;
92242 break;
92243@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92244 goto out;
92245 tmp.valid_hooks = t->valid_hooks;
92246
92247- if (copy_to_user(user, &tmp, *len) != 0) {
92248+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92249 ret = -EFAULT;
92250 break;
92251 }
92252@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92253 tmp.entries_size = t->table->entries_size;
92254 tmp.valid_hooks = t->table->valid_hooks;
92255
92256- if (copy_to_user(user, &tmp, *len) != 0) {
92257+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92258 ret = -EFAULT;
92259 break;
92260 }
92261diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
92262index 0f45522..dab651f 100644
92263--- a/net/caif/cfctrl.c
92264+++ b/net/caif/cfctrl.c
92265@@ -10,6 +10,7 @@
92266 #include <linux/spinlock.h>
92267 #include <linux/slab.h>
92268 #include <linux/pkt_sched.h>
92269+#include <linux/sched.h>
92270 #include <net/caif/caif_layer.h>
92271 #include <net/caif/cfpkt.h>
92272 #include <net/caif/cfctrl.h>
92273@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
92274 memset(&dev_info, 0, sizeof(dev_info));
92275 dev_info.id = 0xff;
92276 cfsrvl_init(&this->serv, 0, &dev_info, false);
92277- atomic_set(&this->req_seq_no, 1);
92278- atomic_set(&this->rsp_seq_no, 1);
92279+ atomic_set_unchecked(&this->req_seq_no, 1);
92280+ atomic_set_unchecked(&this->rsp_seq_no, 1);
92281 this->serv.layer.receive = cfctrl_recv;
92282 sprintf(this->serv.layer.name, "ctrl");
92283 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
92284@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
92285 struct cfctrl_request_info *req)
92286 {
92287 spin_lock_bh(&ctrl->info_list_lock);
92288- atomic_inc(&ctrl->req_seq_no);
92289- req->sequence_no = atomic_read(&ctrl->req_seq_no);
92290+ atomic_inc_unchecked(&ctrl->req_seq_no);
92291+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
92292 list_add_tail(&req->list, &ctrl->list);
92293 spin_unlock_bh(&ctrl->info_list_lock);
92294 }
92295@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
92296 if (p != first)
92297 pr_warn("Requests are not received in order\n");
92298
92299- atomic_set(&ctrl->rsp_seq_no,
92300+ atomic_set_unchecked(&ctrl->rsp_seq_no,
92301 p->sequence_no);
92302 list_del(&p->list);
92303 goto out;
92304diff --git a/net/can/af_can.c b/net/can/af_can.c
92305index 3ab8dd2..b9aef13 100644
92306--- a/net/can/af_can.c
92307+++ b/net/can/af_can.c
92308@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
92309 };
92310
92311 /* notifier block for netdevice event */
92312-static struct notifier_block can_netdev_notifier __read_mostly = {
92313+static struct notifier_block can_netdev_notifier = {
92314 .notifier_call = can_notifier,
92315 };
92316
92317diff --git a/net/can/gw.c b/net/can/gw.c
92318index 3f9b0f3..fc6d4fa 100644
92319--- a/net/can/gw.c
92320+++ b/net/can/gw.c
92321@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
92322 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
92323
92324 static HLIST_HEAD(cgw_list);
92325-static struct notifier_block notifier;
92326
92327 static struct kmem_cache *cgw_cache __read_mostly;
92328
92329@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
92330 return err;
92331 }
92332
92333+static struct notifier_block notifier = {
92334+ .notifier_call = cgw_notifier
92335+};
92336+
92337 static __init int cgw_module_init(void)
92338 {
92339 /* sanitize given module parameter */
92340@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
92341 return -ENOMEM;
92342
92343 /* set notifier */
92344- notifier.notifier_call = cgw_notifier;
92345 register_netdevice_notifier(&notifier);
92346
92347 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
92348diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
92349index 4a5df7b..9ad1f1d 100644
92350--- a/net/ceph/messenger.c
92351+++ b/net/ceph/messenger.c
92352@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
92353 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
92354
92355 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
92356-static atomic_t addr_str_seq = ATOMIC_INIT(0);
92357+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
92358
92359 static struct page *zero_page; /* used in certain error cases */
92360
92361@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
92362 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
92363 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
92364
92365- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92366+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92367 s = addr_str[i];
92368
92369 switch (ss->ss_family) {
92370diff --git a/net/compat.c b/net/compat.c
92371index 8903258..24e30e5 100644
92372--- a/net/compat.c
92373+++ b/net/compat.c
92374@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
92375 return -EFAULT;
92376 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
92377 return -EINVAL;
92378- kmsg->msg_name = compat_ptr(tmp1);
92379- kmsg->msg_iov = compat_ptr(tmp2);
92380- kmsg->msg_control = compat_ptr(tmp3);
92381+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
92382+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
92383+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
92384 return 0;
92385 }
92386
92387@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92388
92389 if (kern_msg->msg_namelen) {
92390 if (mode == VERIFY_READ) {
92391- int err = move_addr_to_kernel(kern_msg->msg_name,
92392+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
92393 kern_msg->msg_namelen,
92394 kern_address);
92395 if (err < 0)
92396@@ -98,7 +98,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92397 kern_msg->msg_name = NULL;
92398
92399 tot_len = iov_from_user_compat_to_kern(kern_iov,
92400- (struct compat_iovec __user *)kern_msg->msg_iov,
92401+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
92402 kern_msg->msg_iovlen);
92403 if (tot_len >= 0)
92404 kern_msg->msg_iov = kern_iov;
92405@@ -118,20 +118,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92406
92407 #define CMSG_COMPAT_FIRSTHDR(msg) \
92408 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
92409- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
92410+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
92411 (struct compat_cmsghdr __user *)NULL)
92412
92413 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
92414 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
92415 (ucmlen) <= (unsigned long) \
92416 ((mhdr)->msg_controllen - \
92417- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
92418+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
92419
92420 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
92421 struct compat_cmsghdr __user *cmsg, int cmsg_len)
92422 {
92423 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
92424- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
92425+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
92426 msg->msg_controllen)
92427 return NULL;
92428 return (struct compat_cmsghdr __user *)ptr;
92429@@ -221,7 +221,7 @@ Efault:
92430
92431 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
92432 {
92433- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92434+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92435 struct compat_cmsghdr cmhdr;
92436 struct compat_timeval ctv;
92437 struct compat_timespec cts[3];
92438@@ -277,7 +277,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
92439
92440 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
92441 {
92442- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92443+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92444 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
92445 int fdnum = scm->fp->count;
92446 struct file **fp = scm->fp->fp;
92447@@ -365,7 +365,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
92448 return -EFAULT;
92449 old_fs = get_fs();
92450 set_fs(KERNEL_DS);
92451- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
92452+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
92453 set_fs(old_fs);
92454
92455 return err;
92456@@ -426,7 +426,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
92457 len = sizeof(ktime);
92458 old_fs = get_fs();
92459 set_fs(KERNEL_DS);
92460- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
92461+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
92462 set_fs(old_fs);
92463
92464 if (!err) {
92465@@ -569,7 +569,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92466 case MCAST_JOIN_GROUP:
92467 case MCAST_LEAVE_GROUP:
92468 {
92469- struct compat_group_req __user *gr32 = (void *)optval;
92470+ struct compat_group_req __user *gr32 = (void __user *)optval;
92471 struct group_req __user *kgr =
92472 compat_alloc_user_space(sizeof(struct group_req));
92473 u32 interface;
92474@@ -590,7 +590,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92475 case MCAST_BLOCK_SOURCE:
92476 case MCAST_UNBLOCK_SOURCE:
92477 {
92478- struct compat_group_source_req __user *gsr32 = (void *)optval;
92479+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
92480 struct group_source_req __user *kgsr = compat_alloc_user_space(
92481 sizeof(struct group_source_req));
92482 u32 interface;
92483@@ -611,7 +611,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92484 }
92485 case MCAST_MSFILTER:
92486 {
92487- struct compat_group_filter __user *gf32 = (void *)optval;
92488+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92489 struct group_filter __user *kgf;
92490 u32 interface, fmode, numsrc;
92491
92492@@ -649,7 +649,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
92493 char __user *optval, int __user *optlen,
92494 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
92495 {
92496- struct compat_group_filter __user *gf32 = (void *)optval;
92497+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92498 struct group_filter __user *kgf;
92499 int __user *koptlen;
92500 u32 interface, fmode, numsrc;
92501@@ -807,7 +807,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
92502
92503 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
92504 return -EINVAL;
92505- if (copy_from_user(a, args, nas[call]))
92506+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
92507 return -EFAULT;
92508 a0 = a[0];
92509 a1 = a[1];
92510diff --git a/net/core/datagram.c b/net/core/datagram.c
92511index af814e7..3d761de 100644
92512--- a/net/core/datagram.c
92513+++ b/net/core/datagram.c
92514@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
92515 }
92516
92517 kfree_skb(skb);
92518- atomic_inc(&sk->sk_drops);
92519+ atomic_inc_unchecked(&sk->sk_drops);
92520 sk_mem_reclaim_partial(sk);
92521
92522 return err;
92523diff --git a/net/core/dev.c b/net/core/dev.c
92524index 3430b1e..d6453ad 100644
92525--- a/net/core/dev.c
92526+++ b/net/core/dev.c
92527@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
92528 {
92529 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
92530 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
92531- atomic_long_inc(&dev->rx_dropped);
92532+ atomic_long_inc_unchecked(&dev->rx_dropped);
92533 kfree_skb(skb);
92534 return NET_RX_DROP;
92535 }
92536 }
92537
92538 if (unlikely(!is_skb_forwardable(dev, skb))) {
92539- atomic_long_inc(&dev->rx_dropped);
92540+ atomic_long_inc_unchecked(&dev->rx_dropped);
92541 kfree_skb(skb);
92542 return NET_RX_DROP;
92543 }
92544@@ -2432,7 +2432,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
92545
92546 struct dev_gso_cb {
92547 void (*destructor)(struct sk_buff *skb);
92548-};
92549+} __no_const;
92550
92551 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
92552
92553@@ -3207,7 +3207,7 @@ enqueue:
92554
92555 local_irq_restore(flags);
92556
92557- atomic_long_inc(&skb->dev->rx_dropped);
92558+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
92559 kfree_skb(skb);
92560 return NET_RX_DROP;
92561 }
92562@@ -3279,7 +3279,7 @@ int netif_rx_ni(struct sk_buff *skb)
92563 }
92564 EXPORT_SYMBOL(netif_rx_ni);
92565
92566-static void net_tx_action(struct softirq_action *h)
92567+static __latent_entropy void net_tx_action(void)
92568 {
92569 struct softnet_data *sd = &__get_cpu_var(softnet_data);
92570
92571@@ -3613,7 +3613,7 @@ ncls:
92572 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
92573 } else {
92574 drop:
92575- atomic_long_inc(&skb->dev->rx_dropped);
92576+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
92577 kfree_skb(skb);
92578 /* Jamal, now you will not able to escape explaining
92579 * me how you were going to use this. :-)
92580@@ -4273,7 +4273,7 @@ void netif_napi_del(struct napi_struct *napi)
92581 }
92582 EXPORT_SYMBOL(netif_napi_del);
92583
92584-static void net_rx_action(struct softirq_action *h)
92585+static __latent_entropy void net_rx_action(void)
92586 {
92587 struct softnet_data *sd = &__get_cpu_var(softnet_data);
92588 unsigned long time_limit = jiffies + 2;
92589@@ -5977,7 +5977,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
92590 } else {
92591 netdev_stats_to_stats64(storage, &dev->stats);
92592 }
92593- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
92594+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
92595 return storage;
92596 }
92597 EXPORT_SYMBOL(dev_get_stats);
92598diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
92599index 5b7d0e1..cb960fc 100644
92600--- a/net/core/dev_ioctl.c
92601+++ b/net/core/dev_ioctl.c
92602@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
92603 if (no_module && capable(CAP_NET_ADMIN))
92604 no_module = request_module("netdev-%s", name);
92605 if (no_module && capable(CAP_SYS_MODULE)) {
92606+#ifdef CONFIG_GRKERNSEC_MODHARDEN
92607+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
92608+#else
92609 if (!request_module("%s", name))
92610 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
92611 name);
92612+#endif
92613 }
92614 }
92615 EXPORT_SYMBOL(dev_load);
92616diff --git a/net/core/flow.c b/net/core/flow.c
92617index dfa602c..3103d88 100644
92618--- a/net/core/flow.c
92619+++ b/net/core/flow.c
92620@@ -61,7 +61,7 @@ struct flow_cache {
92621 struct timer_list rnd_timer;
92622 };
92623
92624-atomic_t flow_cache_genid = ATOMIC_INIT(0);
92625+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
92626 EXPORT_SYMBOL(flow_cache_genid);
92627 static struct flow_cache flow_cache_global;
92628 static struct kmem_cache *flow_cachep __read_mostly;
92629@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
92630
92631 static int flow_entry_valid(struct flow_cache_entry *fle)
92632 {
92633- if (atomic_read(&flow_cache_genid) != fle->genid)
92634+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
92635 return 0;
92636 if (fle->object && !fle->object->ops->check(fle->object))
92637 return 0;
92638@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
92639 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
92640 fcp->hash_count++;
92641 }
92642- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
92643+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
92644 flo = fle->object;
92645 if (!flo)
92646 goto ret_object;
92647@@ -279,7 +279,7 @@ nocache:
92648 }
92649 flo = resolver(net, key, family, dir, flo, ctx);
92650 if (fle) {
92651- fle->genid = atomic_read(&flow_cache_genid);
92652+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
92653 if (!IS_ERR(flo))
92654 fle->object = flo;
92655 else
92656diff --git a/net/core/iovec.c b/net/core/iovec.c
92657index b77eeec..2890aca 100644
92658--- a/net/core/iovec.c
92659+++ b/net/core/iovec.c
92660@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
92661 if (m->msg_namelen) {
92662 if (mode == VERIFY_READ) {
92663 void __user *namep;
92664- namep = (void __user __force *) m->msg_name;
92665+ namep = (void __force_user *) m->msg_name;
92666 err = move_addr_to_kernel(namep, m->msg_namelen,
92667 address);
92668 if (err < 0)
92669@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
92670 }
92671
92672 size = m->msg_iovlen * sizeof(struct iovec);
92673- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
92674+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
92675 return -EFAULT;
92676
92677 m->msg_iov = iov;
92678diff --git a/net/core/neighbour.c b/net/core/neighbour.c
92679index 6072610..7374c18 100644
92680--- a/net/core/neighbour.c
92681+++ b/net/core/neighbour.c
92682@@ -2774,7 +2774,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
92683 void __user *buffer, size_t *lenp, loff_t *ppos)
92684 {
92685 int size, ret;
92686- struct ctl_table tmp = *ctl;
92687+ ctl_table_no_const tmp = *ctl;
92688
92689 tmp.extra1 = &zero;
92690 tmp.extra2 = &unres_qlen_max;
92691diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
92692index 2bf8329..7960607 100644
92693--- a/net/core/net-procfs.c
92694+++ b/net/core/net-procfs.c
92695@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
92696 else
92697 seq_printf(seq, "%04x", ntohs(pt->type));
92698
92699+#ifdef CONFIG_GRKERNSEC_HIDESYM
92700+ seq_printf(seq, " %-8s %pf\n",
92701+ pt->dev ? pt->dev->name : "", NULL);
92702+#else
92703 seq_printf(seq, " %-8s %pf\n",
92704 pt->dev ? pt->dev->name : "", pt->func);
92705+#endif
92706 }
92707
92708 return 0;
92709diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
92710index d954b56..b0a0f7a 100644
92711--- a/net/core/net-sysfs.c
92712+++ b/net/core/net-sysfs.c
92713@@ -1356,7 +1356,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
92714 }
92715 EXPORT_SYMBOL(netdev_class_remove_file);
92716
92717-int netdev_kobject_init(void)
92718+int __init netdev_kobject_init(void)
92719 {
92720 kobj_ns_type_register(&net_ns_type_operations);
92721 return class_register(&net_class);
92722diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
92723index 81d3a9a..a0bd7a8 100644
92724--- a/net/core/net_namespace.c
92725+++ b/net/core/net_namespace.c
92726@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
92727 int error;
92728 LIST_HEAD(net_exit_list);
92729
92730- list_add_tail(&ops->list, list);
92731+ pax_list_add_tail((struct list_head *)&ops->list, list);
92732 if (ops->init || (ops->id && ops->size)) {
92733 for_each_net(net) {
92734 error = ops_init(ops, net);
92735@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
92736
92737 out_undo:
92738 /* If I have an error cleanup all namespaces I initialized */
92739- list_del(&ops->list);
92740+ pax_list_del((struct list_head *)&ops->list);
92741 ops_exit_list(ops, &net_exit_list);
92742 ops_free_list(ops, &net_exit_list);
92743 return error;
92744@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
92745 struct net *net;
92746 LIST_HEAD(net_exit_list);
92747
92748- list_del(&ops->list);
92749+ pax_list_del((struct list_head *)&ops->list);
92750 for_each_net(net)
92751 list_add_tail(&net->exit_list, &net_exit_list);
92752 ops_exit_list(ops, &net_exit_list);
92753@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
92754 mutex_lock(&net_mutex);
92755 error = register_pernet_operations(&pernet_list, ops);
92756 if (!error && (first_device == &pernet_list))
92757- first_device = &ops->list;
92758+ first_device = (struct list_head *)&ops->list;
92759 mutex_unlock(&net_mutex);
92760 return error;
92761 }
92762diff --git a/net/core/netpoll.c b/net/core/netpoll.c
92763index fc75c9e..8c8e9be 100644
92764--- a/net/core/netpoll.c
92765+++ b/net/core/netpoll.c
92766@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
92767 struct udphdr *udph;
92768 struct iphdr *iph;
92769 struct ethhdr *eth;
92770- static atomic_t ip_ident;
92771+ static atomic_unchecked_t ip_ident;
92772 struct ipv6hdr *ip6h;
92773
92774 udp_len = len + sizeof(*udph);
92775@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
92776 put_unaligned(0x45, (unsigned char *)iph);
92777 iph->tos = 0;
92778 put_unaligned(htons(ip_len), &(iph->tot_len));
92779- iph->id = htons(atomic_inc_return(&ip_ident));
92780+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
92781 iph->frag_off = 0;
92782 iph->ttl = 64;
92783 iph->protocol = IPPROTO_UDP;
92784diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
92785index 2a0e21d..6ad7642 100644
92786--- a/net/core/rtnetlink.c
92787+++ b/net/core/rtnetlink.c
92788@@ -58,7 +58,7 @@ struct rtnl_link {
92789 rtnl_doit_func doit;
92790 rtnl_dumpit_func dumpit;
92791 rtnl_calcit_func calcit;
92792-};
92793+} __no_const;
92794
92795 static DEFINE_MUTEX(rtnl_mutex);
92796
92797@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
92798 if (rtnl_link_ops_get(ops->kind))
92799 return -EEXIST;
92800
92801- if (!ops->dellink)
92802- ops->dellink = unregister_netdevice_queue;
92803+ if (!ops->dellink) {
92804+ pax_open_kernel();
92805+ *(void **)&ops->dellink = unregister_netdevice_queue;
92806+ pax_close_kernel();
92807+ }
92808
92809- list_add_tail(&ops->list, &link_ops);
92810+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
92811 return 0;
92812 }
92813 EXPORT_SYMBOL_GPL(__rtnl_link_register);
92814@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
92815 for_each_net(net) {
92816 __rtnl_kill_links(net, ops);
92817 }
92818- list_del(&ops->list);
92819+ pax_list_del((struct list_head *)&ops->list);
92820 }
92821 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
92822
92823diff --git a/net/core/scm.c b/net/core/scm.c
92824index b442e7e..6f5b5a2 100644
92825--- a/net/core/scm.c
92826+++ b/net/core/scm.c
92827@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
92828 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
92829 {
92830 struct cmsghdr __user *cm
92831- = (__force struct cmsghdr __user *)msg->msg_control;
92832+ = (struct cmsghdr __force_user *)msg->msg_control;
92833 struct cmsghdr cmhdr;
92834 int cmlen = CMSG_LEN(len);
92835 int err;
92836@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
92837 err = -EFAULT;
92838 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
92839 goto out;
92840- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
92841+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
92842 goto out;
92843 cmlen = CMSG_SPACE(len);
92844 if (msg->msg_controllen < cmlen)
92845@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
92846 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
92847 {
92848 struct cmsghdr __user *cm
92849- = (__force struct cmsghdr __user*)msg->msg_control;
92850+ = (struct cmsghdr __force_user *)msg->msg_control;
92851
92852 int fdmax = 0;
92853 int fdnum = scm->fp->count;
92854@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
92855 if (fdnum < fdmax)
92856 fdmax = fdnum;
92857
92858- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
92859+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
92860 i++, cmfptr++)
92861 {
92862 struct socket *sock;
92863diff --git a/net/core/skbuff.c b/net/core/skbuff.c
92864index d81cff1..e31f952 100644
92865--- a/net/core/skbuff.c
92866+++ b/net/core/skbuff.c
92867@@ -3082,13 +3082,15 @@ void __init skb_init(void)
92868 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
92869 sizeof(struct sk_buff),
92870 0,
92871- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
92872+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
92873+ SLAB_NO_SANITIZE,
92874 NULL);
92875 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
92876 (2*sizeof(struct sk_buff)) +
92877 sizeof(atomic_t),
92878 0,
92879- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
92880+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
92881+ SLAB_NO_SANITIZE,
92882 NULL);
92883 }
92884
92885diff --git a/net/core/sock.c b/net/core/sock.c
92886index 0b39e7a..5e9f91e 100644
92887--- a/net/core/sock.c
92888+++ b/net/core/sock.c
92889@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
92890 struct sk_buff_head *list = &sk->sk_receive_queue;
92891
92892 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
92893- atomic_inc(&sk->sk_drops);
92894+ atomic_inc_unchecked(&sk->sk_drops);
92895 trace_sock_rcvqueue_full(sk, skb);
92896 return -ENOMEM;
92897 }
92898@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
92899 return err;
92900
92901 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
92902- atomic_inc(&sk->sk_drops);
92903+ atomic_inc_unchecked(&sk->sk_drops);
92904 return -ENOBUFS;
92905 }
92906
92907@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
92908 skb_dst_force(skb);
92909
92910 spin_lock_irqsave(&list->lock, flags);
92911- skb->dropcount = atomic_read(&sk->sk_drops);
92912+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
92913 __skb_queue_tail(list, skb);
92914 spin_unlock_irqrestore(&list->lock, flags);
92915
92916@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
92917 skb->dev = NULL;
92918
92919 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
92920- atomic_inc(&sk->sk_drops);
92921+ atomic_inc_unchecked(&sk->sk_drops);
92922 goto discard_and_relse;
92923 }
92924 if (nested)
92925@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
92926 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
92927 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
92928 bh_unlock_sock(sk);
92929- atomic_inc(&sk->sk_drops);
92930+ atomic_inc_unchecked(&sk->sk_drops);
92931 goto discard_and_relse;
92932 }
92933
92934@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
92935 struct timeval tm;
92936 } v;
92937
92938- int lv = sizeof(int);
92939- int len;
92940+ unsigned int lv = sizeof(int);
92941+ unsigned int len;
92942
92943 if (get_user(len, optlen))
92944 return -EFAULT;
92945- if (len < 0)
92946+ if (len > INT_MAX)
92947 return -EINVAL;
92948
92949 memset(&v, 0, sizeof(v));
92950@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
92951
92952 case SO_PEERNAME:
92953 {
92954- char address[128];
92955+ char address[_K_SS_MAXSIZE];
92956
92957 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
92958 return -ENOTCONN;
92959- if (lv < len)
92960+ if (lv < len || sizeof address < len)
92961 return -EINVAL;
92962 if (copy_to_user(optval, address, len))
92963 return -EFAULT;
92964@@ -1183,7 +1183,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
92965
92966 if (len > lv)
92967 len = lv;
92968- if (copy_to_user(optval, &v, len))
92969+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
92970 return -EFAULT;
92971 lenout:
92972 if (put_user(len, optlen))
92973@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
92974 */
92975 smp_wmb();
92976 atomic_set(&sk->sk_refcnt, 1);
92977- atomic_set(&sk->sk_drops, 0);
92978+ atomic_set_unchecked(&sk->sk_drops, 0);
92979 }
92980 EXPORT_SYMBOL(sock_init_data);
92981
92982@@ -2451,6 +2451,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
92983 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
92984 int level, int type)
92985 {
92986+ struct sock_extended_err ee;
92987 struct sock_exterr_skb *serr;
92988 struct sk_buff *skb, *skb2;
92989 int copied, err;
92990@@ -2472,7 +2473,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
92991 sock_recv_timestamp(msg, sk, skb);
92992
92993 serr = SKB_EXT_ERR(skb);
92994- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
92995+ ee = serr->ee;
92996+ put_cmsg(msg, level, type, sizeof ee, &ee);
92997
92998 msg->msg_flags |= MSG_ERRQUEUE;
92999 err = copied;
93000diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
93001index a0e9cf6..ef7f9ed 100644
93002--- a/net/core/sock_diag.c
93003+++ b/net/core/sock_diag.c
93004@@ -9,26 +9,33 @@
93005 #include <linux/inet_diag.h>
93006 #include <linux/sock_diag.h>
93007
93008-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
93009+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
93010 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
93011 static DEFINE_MUTEX(sock_diag_table_mutex);
93012
93013 int sock_diag_check_cookie(void *sk, __u32 *cookie)
93014 {
93015+#ifndef CONFIG_GRKERNSEC_HIDESYM
93016 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
93017 cookie[1] != INET_DIAG_NOCOOKIE) &&
93018 ((u32)(unsigned long)sk != cookie[0] ||
93019 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
93020 return -ESTALE;
93021 else
93022+#endif
93023 return 0;
93024 }
93025 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
93026
93027 void sock_diag_save_cookie(void *sk, __u32 *cookie)
93028 {
93029+#ifdef CONFIG_GRKERNSEC_HIDESYM
93030+ cookie[0] = 0;
93031+ cookie[1] = 0;
93032+#else
93033 cookie[0] = (u32)(unsigned long)sk;
93034 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
93035+#endif
93036 }
93037 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
93038
93039@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
93040 mutex_lock(&sock_diag_table_mutex);
93041 if (sock_diag_handlers[hndl->family])
93042 err = -EBUSY;
93043- else
93044+ else {
93045+ pax_open_kernel();
93046 sock_diag_handlers[hndl->family] = hndl;
93047+ pax_close_kernel();
93048+ }
93049 mutex_unlock(&sock_diag_table_mutex);
93050
93051 return err;
93052@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
93053
93054 mutex_lock(&sock_diag_table_mutex);
93055 BUG_ON(sock_diag_handlers[family] != hnld);
93056+ pax_open_kernel();
93057 sock_diag_handlers[family] = NULL;
93058+ pax_close_kernel();
93059 mutex_unlock(&sock_diag_table_mutex);
93060 }
93061 EXPORT_SYMBOL_GPL(sock_diag_unregister);
93062diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
93063index cca4441..5e616de 100644
93064--- a/net/core/sysctl_net_core.c
93065+++ b/net/core/sysctl_net_core.c
93066@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
93067 {
93068 unsigned int orig_size, size;
93069 int ret, i;
93070- struct ctl_table tmp = {
93071+ ctl_table_no_const tmp = {
93072 .data = &size,
93073 .maxlen = sizeof(size),
93074 .mode = table->mode
93075@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
93076 void __user *buffer, size_t *lenp, loff_t *ppos)
93077 {
93078 char id[IFNAMSIZ];
93079- struct ctl_table tbl = {
93080+ ctl_table_no_const tbl = {
93081 .data = id,
93082 .maxlen = IFNAMSIZ,
93083 };
93084@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
93085
93086 static __net_init int sysctl_core_net_init(struct net *net)
93087 {
93088- struct ctl_table *tbl;
93089+ ctl_table_no_const *tbl = NULL;
93090
93091 net->core.sysctl_somaxconn = SOMAXCONN;
93092
93093- tbl = netns_core_table;
93094 if (!net_eq(net, &init_net)) {
93095- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
93096+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
93097 if (tbl == NULL)
93098 goto err_dup;
93099
93100@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
93101 if (net->user_ns != &init_user_ns) {
93102 tbl[0].procname = NULL;
93103 }
93104- }
93105-
93106- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93107+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93108+ } else
93109+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
93110 if (net->core.sysctl_hdr == NULL)
93111 goto err_reg;
93112
93113 return 0;
93114
93115 err_reg:
93116- if (tbl != netns_core_table)
93117- kfree(tbl);
93118+ kfree(tbl);
93119 err_dup:
93120 return -ENOMEM;
93121 }
93122@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
93123 kfree(tbl);
93124 }
93125
93126-static __net_initdata struct pernet_operations sysctl_core_ops = {
93127+static __net_initconst struct pernet_operations sysctl_core_ops = {
93128 .init = sysctl_core_net_init,
93129 .exit = sysctl_core_net_exit,
93130 };
93131diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
93132index dd4d506..fb2fb87 100644
93133--- a/net/decnet/af_decnet.c
93134+++ b/net/decnet/af_decnet.c
93135@@ -465,6 +465,7 @@ static struct proto dn_proto = {
93136 .sysctl_rmem = sysctl_decnet_rmem,
93137 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
93138 .obj_size = sizeof(struct dn_sock),
93139+ .slab_flags = SLAB_USERCOPY,
93140 };
93141
93142 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
93143diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
93144index 5325b54..a0d4d69 100644
93145--- a/net/decnet/sysctl_net_decnet.c
93146+++ b/net/decnet/sysctl_net_decnet.c
93147@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
93148
93149 if (len > *lenp) len = *lenp;
93150
93151- if (copy_to_user(buffer, addr, len))
93152+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
93153 return -EFAULT;
93154
93155 *lenp = len;
93156@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
93157
93158 if (len > *lenp) len = *lenp;
93159
93160- if (copy_to_user(buffer, devname, len))
93161+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
93162 return -EFAULT;
93163
93164 *lenp = len;
93165diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
93166index ff41b4d6..6125050 100644
93167--- a/net/ieee802154/6lowpan.c
93168+++ b/net/ieee802154/6lowpan.c
93169@@ -548,7 +548,7 @@ static int lowpan_header_create(struct sk_buff *skb,
93170 hc06_ptr += 3;
93171 } else {
93172 /* compress nothing */
93173- memcpy(hc06_ptr, &hdr, 4);
93174+ memcpy(hc06_ptr, hdr, 4);
93175 /* replace the top byte with new ECN | DSCP format */
93176 *hc06_ptr = tmp;
93177 hc06_ptr += 4;
93178diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
93179index cfeb85c..385989a 100644
93180--- a/net/ipv4/af_inet.c
93181+++ b/net/ipv4/af_inet.c
93182@@ -1675,13 +1675,9 @@ static int __init inet_init(void)
93183
93184 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
93185
93186- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
93187- if (!sysctl_local_reserved_ports)
93188- goto out;
93189-
93190 rc = proto_register(&tcp_prot, 1);
93191 if (rc)
93192- goto out_free_reserved_ports;
93193+ goto out;
93194
93195 rc = proto_register(&udp_prot, 1);
93196 if (rc)
93197@@ -1790,8 +1786,6 @@ out_unregister_udp_proto:
93198 proto_unregister(&udp_prot);
93199 out_unregister_tcp_proto:
93200 proto_unregister(&tcp_prot);
93201-out_free_reserved_ports:
93202- kfree(sysctl_local_reserved_ports);
93203 goto out;
93204 }
93205
93206diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
93207index b28e863..19e3637 100644
93208--- a/net/ipv4/datagram.c
93209+++ b/net/ipv4/datagram.c
93210@@ -57,7 +57,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
93211 if (IS_ERR(rt)) {
93212 err = PTR_ERR(rt);
93213 if (err == -ENETUNREACH)
93214- IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
93215+ IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
93216 goto out;
93217 }
93218
93219diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
93220index a1b5bcb..62ec5c6 100644
93221--- a/net/ipv4/devinet.c
93222+++ b/net/ipv4/devinet.c
93223@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
93224 idx = 0;
93225 head = &net->dev_index_head[h];
93226 rcu_read_lock();
93227- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93228+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93229 net->dev_base_seq;
93230 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93231 if (idx < s_idx)
93232@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
93233 idx = 0;
93234 head = &net->dev_index_head[h];
93235 rcu_read_lock();
93236- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93237+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93238 net->dev_base_seq;
93239 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93240 if (idx < s_idx)
93241@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
93242 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
93243 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
93244
93245-static struct devinet_sysctl_table {
93246+static const struct devinet_sysctl_table {
93247 struct ctl_table_header *sysctl_header;
93248 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
93249 } devinet_sysctl = {
93250@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
93251 int err;
93252 struct ipv4_devconf *all, *dflt;
93253 #ifdef CONFIG_SYSCTL
93254- struct ctl_table *tbl = ctl_forward_entry;
93255+ ctl_table_no_const *tbl = NULL;
93256 struct ctl_table_header *forw_hdr;
93257 #endif
93258
93259@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
93260 goto err_alloc_dflt;
93261
93262 #ifdef CONFIG_SYSCTL
93263- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
93264+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
93265 if (tbl == NULL)
93266 goto err_alloc_ctl;
93267
93268@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
93269 goto err_reg_dflt;
93270
93271 err = -ENOMEM;
93272- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93273+ if (!net_eq(net, &init_net))
93274+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93275+ else
93276+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
93277 if (forw_hdr == NULL)
93278 goto err_reg_ctl;
93279 net->ipv4.forw_hdr = forw_hdr;
93280@@ -2245,8 +2248,7 @@ err_reg_ctl:
93281 err_reg_dflt:
93282 __devinet_sysctl_unregister(all);
93283 err_reg_all:
93284- if (tbl != ctl_forward_entry)
93285- kfree(tbl);
93286+ kfree(tbl);
93287 err_alloc_ctl:
93288 #endif
93289 if (dflt != &ipv4_devconf_dflt)
93290diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
93291index b3f627a..b0f3e99 100644
93292--- a/net/ipv4/fib_frontend.c
93293+++ b/net/ipv4/fib_frontend.c
93294@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
93295 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93296 fib_sync_up(dev);
93297 #endif
93298- atomic_inc(&net->ipv4.dev_addr_genid);
93299+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93300 rt_cache_flush(dev_net(dev));
93301 break;
93302 case NETDEV_DOWN:
93303 fib_del_ifaddr(ifa, NULL);
93304- atomic_inc(&net->ipv4.dev_addr_genid);
93305+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93306 if (ifa->ifa_dev->ifa_list == NULL) {
93307 /* Last address was deleted from this interface.
93308 * Disable IP.
93309@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
93310 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93311 fib_sync_up(dev);
93312 #endif
93313- atomic_inc(&net->ipv4.dev_addr_genid);
93314+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93315 rt_cache_flush(net);
93316 break;
93317 case NETDEV_DOWN:
93318diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
93319index d5dbca5..6251d5f 100644
93320--- a/net/ipv4/fib_semantics.c
93321+++ b/net/ipv4/fib_semantics.c
93322@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
93323 nh->nh_saddr = inet_select_addr(nh->nh_dev,
93324 nh->nh_gw,
93325 nh->nh_parent->fib_scope);
93326- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
93327+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
93328
93329 return nh->nh_saddr;
93330 }
93331diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
93332index 6acb541..9ea617d 100644
93333--- a/net/ipv4/inet_connection_sock.c
93334+++ b/net/ipv4/inet_connection_sock.c
93335@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
93336 .range = { 32768, 61000 },
93337 };
93338
93339-unsigned long *sysctl_local_reserved_ports;
93340+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
93341 EXPORT_SYMBOL(sysctl_local_reserved_ports);
93342
93343 void inet_get_local_port_range(int *low, int *high)
93344diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
93345index 96da9c7..b956690 100644
93346--- a/net/ipv4/inet_hashtables.c
93347+++ b/net/ipv4/inet_hashtables.c
93348@@ -18,12 +18,15 @@
93349 #include <linux/sched.h>
93350 #include <linux/slab.h>
93351 #include <linux/wait.h>
93352+#include <linux/security.h>
93353
93354 #include <net/inet_connection_sock.h>
93355 #include <net/inet_hashtables.h>
93356 #include <net/secure_seq.h>
93357 #include <net/ip.h>
93358
93359+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
93360+
93361 /*
93362 * Allocate and initialize a new local port bind bucket.
93363 * The bindhash mutex for snum's hash chain must be held here.
93364@@ -554,6 +557,8 @@ ok:
93365 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
93366 spin_unlock(&head->lock);
93367
93368+ gr_update_task_in_ip_table(current, inet_sk(sk));
93369+
93370 if (tw) {
93371 inet_twsk_deschedule(tw, death_row);
93372 while (twrefcnt) {
93373diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
93374index 33d5537..da337a4 100644
93375--- a/net/ipv4/inetpeer.c
93376+++ b/net/ipv4/inetpeer.c
93377@@ -503,8 +503,8 @@ relookup:
93378 if (p) {
93379 p->daddr = *daddr;
93380 atomic_set(&p->refcnt, 1);
93381- atomic_set(&p->rid, 0);
93382- atomic_set(&p->ip_id_count,
93383+ atomic_set_unchecked(&p->rid, 0);
93384+ atomic_set_unchecked(&p->ip_id_count,
93385 (daddr->family == AF_INET) ?
93386 secure_ip_id(daddr->addr.a4) :
93387 secure_ipv6_id(daddr->addr.a6));
93388diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
93389index b66910a..cfe416e 100644
93390--- a/net/ipv4/ip_fragment.c
93391+++ b/net/ipv4/ip_fragment.c
93392@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
93393 return 0;
93394
93395 start = qp->rid;
93396- end = atomic_inc_return(&peer->rid);
93397+ end = atomic_inc_return_unchecked(&peer->rid);
93398 qp->rid = end;
93399
93400 rc = qp->q.fragments && (end - start) > max;
93401@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
93402
93403 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93404 {
93405- struct ctl_table *table;
93406+ ctl_table_no_const *table = NULL;
93407 struct ctl_table_header *hdr;
93408
93409- table = ip4_frags_ns_ctl_table;
93410 if (!net_eq(net, &init_net)) {
93411- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93412+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93413 if (table == NULL)
93414 goto err_alloc;
93415
93416@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93417 /* Don't export sysctls to unprivileged users */
93418 if (net->user_ns != &init_user_ns)
93419 table[0].procname = NULL;
93420- }
93421+ hdr = register_net_sysctl(net, "net/ipv4", table);
93422+ } else
93423+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
93424
93425- hdr = register_net_sysctl(net, "net/ipv4", table);
93426 if (hdr == NULL)
93427 goto err_reg;
93428
93429@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93430 return 0;
93431
93432 err_reg:
93433- if (!net_eq(net, &init_net))
93434- kfree(table);
93435+ kfree(table);
93436 err_alloc:
93437 return -ENOMEM;
93438 }
93439diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
93440index d7aea4c..a8ee872 100644
93441--- a/net/ipv4/ip_gre.c
93442+++ b/net/ipv4/ip_gre.c
93443@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
93444 module_param(log_ecn_error, bool, 0644);
93445 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
93446
93447-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
93448+static struct rtnl_link_ops ipgre_link_ops;
93449 static int ipgre_tunnel_init(struct net_device *dev);
93450
93451 static int ipgre_net_id __read_mostly;
93452@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
93453 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
93454 };
93455
93456-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
93457+static struct rtnl_link_ops ipgre_link_ops = {
93458 .kind = "gre",
93459 .maxtype = IFLA_GRE_MAX,
93460 .policy = ipgre_policy,
93461@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
93462 .fill_info = ipgre_fill_info,
93463 };
93464
93465-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
93466+static struct rtnl_link_ops ipgre_tap_ops = {
93467 .kind = "gretap",
93468 .maxtype = IFLA_GRE_MAX,
93469 .policy = ipgre_policy,
93470diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
93471index d9c4f11..02b82dbc 100644
93472--- a/net/ipv4/ip_sockglue.c
93473+++ b/net/ipv4/ip_sockglue.c
93474@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
93475 len = min_t(unsigned int, len, opt->optlen);
93476 if (put_user(len, optlen))
93477 return -EFAULT;
93478- if (copy_to_user(optval, opt->__data, len))
93479+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
93480+ copy_to_user(optval, opt->__data, len))
93481 return -EFAULT;
93482 return 0;
93483 }
93484@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
93485 if (sk->sk_type != SOCK_STREAM)
93486 return -ENOPROTOOPT;
93487
93488- msg.msg_control = optval;
93489+ msg.msg_control = (void __force_kernel *)optval;
93490 msg.msg_controllen = len;
93491 msg.msg_flags = flags;
93492
93493diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
93494index 6e87f85..2c28e240 100644
93495--- a/net/ipv4/ip_vti.c
93496+++ b/net/ipv4/ip_vti.c
93497@@ -44,7 +44,7 @@
93498 #include <net/net_namespace.h>
93499 #include <net/netns/generic.h>
93500
93501-static struct rtnl_link_ops vti_link_ops __read_mostly;
93502+static struct rtnl_link_ops vti_link_ops;
93503
93504 static int vti_net_id __read_mostly;
93505 static int vti_tunnel_init(struct net_device *dev);
93506@@ -424,7 +424,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
93507 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
93508 };
93509
93510-static struct rtnl_link_ops vti_link_ops __read_mostly = {
93511+static struct rtnl_link_ops vti_link_ops = {
93512 .kind = "vti",
93513 .maxtype = IFLA_VTI_MAX,
93514 .policy = vti_policy,
93515diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
93516index efa1138..20dbba0 100644
93517--- a/net/ipv4/ipconfig.c
93518+++ b/net/ipv4/ipconfig.c
93519@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
93520
93521 mm_segment_t oldfs = get_fs();
93522 set_fs(get_ds());
93523- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
93524+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
93525 set_fs(oldfs);
93526 return res;
93527 }
93528@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
93529
93530 mm_segment_t oldfs = get_fs();
93531 set_fs(get_ds());
93532- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
93533+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
93534 set_fs(oldfs);
93535 return res;
93536 }
93537@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
93538
93539 mm_segment_t oldfs = get_fs();
93540 set_fs(get_ds());
93541- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
93542+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
93543 set_fs(oldfs);
93544 return res;
93545 }
93546diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
93547index 7f80fb4..b0328f6 100644
93548--- a/net/ipv4/ipip.c
93549+++ b/net/ipv4/ipip.c
93550@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
93551 static int ipip_net_id __read_mostly;
93552
93553 static int ipip_tunnel_init(struct net_device *dev);
93554-static struct rtnl_link_ops ipip_link_ops __read_mostly;
93555+static struct rtnl_link_ops ipip_link_ops;
93556
93557 static int ipip_err(struct sk_buff *skb, u32 info)
93558 {
93559@@ -408,7 +408,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
93560 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
93561 };
93562
93563-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
93564+static struct rtnl_link_ops ipip_link_ops = {
93565 .kind = "ipip",
93566 .maxtype = IFLA_IPTUN_MAX,
93567 .policy = ipip_policy,
93568diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
93569index 85a4f21..1beb1f5 100644
93570--- a/net/ipv4/netfilter/arp_tables.c
93571+++ b/net/ipv4/netfilter/arp_tables.c
93572@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
93573 #endif
93574
93575 static int get_info(struct net *net, void __user *user,
93576- const int *len, int compat)
93577+ int len, int compat)
93578 {
93579 char name[XT_TABLE_MAXNAMELEN];
93580 struct xt_table *t;
93581 int ret;
93582
93583- if (*len != sizeof(struct arpt_getinfo)) {
93584- duprintf("length %u != %Zu\n", *len,
93585+ if (len != sizeof(struct arpt_getinfo)) {
93586+ duprintf("length %u != %Zu\n", len,
93587 sizeof(struct arpt_getinfo));
93588 return -EINVAL;
93589 }
93590@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
93591 info.size = private->size;
93592 strcpy(info.name, name);
93593
93594- if (copy_to_user(user, &info, *len) != 0)
93595+ if (copy_to_user(user, &info, len) != 0)
93596 ret = -EFAULT;
93597 else
93598 ret = 0;
93599@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
93600
93601 switch (cmd) {
93602 case ARPT_SO_GET_INFO:
93603- ret = get_info(sock_net(sk), user, len, 1);
93604+ ret = get_info(sock_net(sk), user, *len, 1);
93605 break;
93606 case ARPT_SO_GET_ENTRIES:
93607 ret = compat_get_entries(sock_net(sk), user, len);
93608@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
93609
93610 switch (cmd) {
93611 case ARPT_SO_GET_INFO:
93612- ret = get_info(sock_net(sk), user, len, 0);
93613+ ret = get_info(sock_net(sk), user, *len, 0);
93614 break;
93615
93616 case ARPT_SO_GET_ENTRIES:
93617diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
93618index d23118d..6ad7277 100644
93619--- a/net/ipv4/netfilter/ip_tables.c
93620+++ b/net/ipv4/netfilter/ip_tables.c
93621@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
93622 #endif
93623
93624 static int get_info(struct net *net, void __user *user,
93625- const int *len, int compat)
93626+ int len, int compat)
93627 {
93628 char name[XT_TABLE_MAXNAMELEN];
93629 struct xt_table *t;
93630 int ret;
93631
93632- if (*len != sizeof(struct ipt_getinfo)) {
93633- duprintf("length %u != %zu\n", *len,
93634+ if (len != sizeof(struct ipt_getinfo)) {
93635+ duprintf("length %u != %zu\n", len,
93636 sizeof(struct ipt_getinfo));
93637 return -EINVAL;
93638 }
93639@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
93640 info.size = private->size;
93641 strcpy(info.name, name);
93642
93643- if (copy_to_user(user, &info, *len) != 0)
93644+ if (copy_to_user(user, &info, len) != 0)
93645 ret = -EFAULT;
93646 else
93647 ret = 0;
93648@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93649
93650 switch (cmd) {
93651 case IPT_SO_GET_INFO:
93652- ret = get_info(sock_net(sk), user, len, 1);
93653+ ret = get_info(sock_net(sk), user, *len, 1);
93654 break;
93655 case IPT_SO_GET_ENTRIES:
93656 ret = compat_get_entries(sock_net(sk), user, len);
93657@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93658
93659 switch (cmd) {
93660 case IPT_SO_GET_INFO:
93661- ret = get_info(sock_net(sk), user, len, 0);
93662+ ret = get_info(sock_net(sk), user, *len, 0);
93663 break;
93664
93665 case IPT_SO_GET_ENTRIES:
93666diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
93667index cbc2215..9cb993c 100644
93668--- a/net/ipv4/netfilter/ipt_ULOG.c
93669+++ b/net/ipv4/netfilter/ipt_ULOG.c
93670@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
93671 ub->qlen++;
93672
93673 pm = nlmsg_data(nlh);
93674+ memset(pm, 0, sizeof(*pm));
93675
93676 /* We might not have a timestamp, get one */
93677 if (skb->tstamp.tv64 == 0)
93678@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
93679 }
93680 else if (loginfo->prefix[0] != '\0')
93681 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
93682- else
93683- *(pm->prefix) = '\0';
93684
93685 if (in && in->hard_header_len > 0 &&
93686 skb->mac_header != skb->network_header &&
93687@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
93688
93689 if (in)
93690 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
93691- else
93692- pm->indev_name[0] = '\0';
93693
93694 if (out)
93695 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
93696- else
93697- pm->outdev_name[0] = '\0';
93698
93699 /* copy_len <= skb->len, so can't fail. */
93700 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
93701diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
93702index d7d9882..d700c68 100644
93703--- a/net/ipv4/ping.c
93704+++ b/net/ipv4/ping.c
93705@@ -55,7 +55,7 @@
93706
93707
93708 struct ping_table ping_table;
93709-struct pingv6_ops pingv6_ops;
93710+struct pingv6_ops *pingv6_ops;
93711 EXPORT_SYMBOL_GPL(pingv6_ops);
93712
93713 static u16 ping_port_rover;
93714@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
93715 return -ENODEV;
93716 }
93717 }
93718- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
93719+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
93720 scoped);
93721 rcu_read_unlock();
93722
93723@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
93724 }
93725 #if IS_ENABLED(CONFIG_IPV6)
93726 } else if (skb->protocol == htons(ETH_P_IPV6)) {
93727- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
93728+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
93729 #endif
93730 }
93731
93732@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
93733 info, (u8 *)icmph);
93734 #if IS_ENABLED(CONFIG_IPV6)
93735 } else if (family == AF_INET6) {
93736- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
93737+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
93738 info, (u8 *)icmph);
93739 #endif
93740 }
93741@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93742 return ip_recv_error(sk, msg, len);
93743 #if IS_ENABLED(CONFIG_IPV6)
93744 } else if (family == AF_INET6) {
93745- return pingv6_ops.ipv6_recv_error(sk, msg, len);
93746+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
93747 #endif
93748 }
93749 }
93750@@ -874,11 +874,14 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93751
93752 /* Copy the address and add cmsg data. */
93753 if (family == AF_INET) {
93754- sin = (struct sockaddr_in *) msg->msg_name;
93755- sin->sin_family = AF_INET;
93756- sin->sin_port = 0 /* skb->h.uh->source */;
93757- sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
93758- memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
93759+ struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
93760+
93761+ if (sin) {
93762+ sin->sin_family = AF_INET;
93763+ sin->sin_port = 0 /* skb->h.uh->source */;
93764+ sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
93765+ memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
93766+ }
93767
93768 if (isk->cmsg_flags)
93769 ip_cmsg_recv(msg, skb);
93770@@ -887,20 +890,23 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93771 } else if (family == AF_INET6) {
93772 struct ipv6_pinfo *np = inet6_sk(sk);
93773 struct ipv6hdr *ip6 = ipv6_hdr(skb);
93774- sin6 = (struct sockaddr_in6 *) msg->msg_name;
93775- sin6->sin6_family = AF_INET6;
93776- sin6->sin6_port = 0;
93777- sin6->sin6_addr = ip6->saddr;
93778+ struct sockaddr_in6 *sin6 =
93779+ (struct sockaddr_in6 *)msg->msg_name;
93780
93781- sin6->sin6_flowinfo = 0;
93782- if (np->sndflow)
93783- sin6->sin6_flowinfo = ip6_flowinfo(ip6);
93784-
93785- sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
93786- IP6CB(skb)->iif);
93787+ if (sin6) {
93788+ sin6->sin6_family = AF_INET6;
93789+ sin6->sin6_port = 0;
93790+ sin6->sin6_addr = ip6->saddr;
93791+ sin6->sin6_flowinfo = 0;
93792+ if (np->sndflow)
93793+ sin6->sin6_flowinfo = ip6_flowinfo(ip6);
93794+ sin6->sin6_scope_id =
93795+ ipv6_iface_scope_id(&sin6->sin6_addr,
93796+ IP6CB(skb)->iif);
93797+ }
93798
93799 if (inet6_sk(sk)->rxopt.all)
93800- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
93801+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
93802 #endif
93803 } else {
93804 BUG();
93805@@ -1090,7 +1096,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
93806 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93807 0, sock_i_ino(sp),
93808 atomic_read(&sp->sk_refcnt), sp,
93809- atomic_read(&sp->sk_drops), len);
93810+ atomic_read_unchecked(&sp->sk_drops), len);
93811 }
93812
93813 static int ping_v4_seq_show(struct seq_file *seq, void *v)
93814diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
93815index 193db03..05ba36c 100644
93816--- a/net/ipv4/raw.c
93817+++ b/net/ipv4/raw.c
93818@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
93819 int raw_rcv(struct sock *sk, struct sk_buff *skb)
93820 {
93821 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
93822- atomic_inc(&sk->sk_drops);
93823+ atomic_inc_unchecked(&sk->sk_drops);
93824 kfree_skb(skb);
93825 return NET_RX_DROP;
93826 }
93827@@ -748,16 +748,20 @@ static int raw_init(struct sock *sk)
93828
93829 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
93830 {
93831+ struct icmp_filter filter;
93832+
93833 if (optlen > sizeof(struct icmp_filter))
93834 optlen = sizeof(struct icmp_filter);
93835- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
93836+ if (copy_from_user(&filter, optval, optlen))
93837 return -EFAULT;
93838+ raw_sk(sk)->filter = filter;
93839 return 0;
93840 }
93841
93842 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
93843 {
93844 int len, ret = -EFAULT;
93845+ struct icmp_filter filter;
93846
93847 if (get_user(len, optlen))
93848 goto out;
93849@@ -767,8 +771,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
93850 if (len > sizeof(struct icmp_filter))
93851 len = sizeof(struct icmp_filter);
93852 ret = -EFAULT;
93853- if (put_user(len, optlen) ||
93854- copy_to_user(optval, &raw_sk(sk)->filter, len))
93855+ filter = raw_sk(sk)->filter;
93856+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
93857 goto out;
93858 ret = 0;
93859 out: return ret;
93860@@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
93861 0, 0L, 0,
93862 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
93863 0, sock_i_ino(sp),
93864- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
93865+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
93866 }
93867
93868 static int raw_seq_show(struct seq_file *seq, void *v)
93869diff --git a/net/ipv4/route.c b/net/ipv4/route.c
93870index 6011615..f418576 100644
93871--- a/net/ipv4/route.c
93872+++ b/net/ipv4/route.c
93873@@ -2613,34 +2613,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
93874 .maxlen = sizeof(int),
93875 .mode = 0200,
93876 .proc_handler = ipv4_sysctl_rtcache_flush,
93877+ .extra1 = &init_net,
93878 },
93879 { },
93880 };
93881
93882 static __net_init int sysctl_route_net_init(struct net *net)
93883 {
93884- struct ctl_table *tbl;
93885+ ctl_table_no_const *tbl = NULL;
93886
93887- tbl = ipv4_route_flush_table;
93888 if (!net_eq(net, &init_net)) {
93889- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
93890+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
93891 if (tbl == NULL)
93892 goto err_dup;
93893
93894 /* Don't export sysctls to unprivileged users */
93895 if (net->user_ns != &init_user_ns)
93896 tbl[0].procname = NULL;
93897- }
93898- tbl[0].extra1 = net;
93899+ tbl[0].extra1 = net;
93900+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
93901+ } else
93902+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
93903
93904- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
93905 if (net->ipv4.route_hdr == NULL)
93906 goto err_reg;
93907 return 0;
93908
93909 err_reg:
93910- if (tbl != ipv4_route_flush_table)
93911- kfree(tbl);
93912+ kfree(tbl);
93913 err_dup:
93914 return -ENOMEM;
93915 }
93916@@ -2663,8 +2663,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
93917
93918 static __net_init int rt_genid_init(struct net *net)
93919 {
93920- atomic_set(&net->ipv4.rt_genid, 0);
93921- atomic_set(&net->fnhe_genid, 0);
93922+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
93923+ atomic_set_unchecked(&net->fnhe_genid, 0);
93924 get_random_bytes(&net->ipv4.dev_addr_genid,
93925 sizeof(net->ipv4.dev_addr_genid));
93926 return 0;
93927diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
93928index 540279f..9855b16 100644
93929--- a/net/ipv4/sysctl_net_ipv4.c
93930+++ b/net/ipv4/sysctl_net_ipv4.c
93931@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
93932 {
93933 int ret;
93934 int range[2];
93935- struct ctl_table tmp = {
93936+ ctl_table_no_const tmp = {
93937 .data = &range,
93938 .maxlen = sizeof(range),
93939 .mode = table->mode,
93940@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
93941 int ret;
93942 gid_t urange[2];
93943 kgid_t low, high;
93944- struct ctl_table tmp = {
93945+ ctl_table_no_const tmp = {
93946 .data = &urange,
93947 .maxlen = sizeof(urange),
93948 .mode = table->mode,
93949@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
93950 void __user *buffer, size_t *lenp, loff_t *ppos)
93951 {
93952 char val[TCP_CA_NAME_MAX];
93953- struct ctl_table tbl = {
93954+ ctl_table_no_const tbl = {
93955 .data = val,
93956 .maxlen = TCP_CA_NAME_MAX,
93957 };
93958@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
93959 void __user *buffer, size_t *lenp,
93960 loff_t *ppos)
93961 {
93962- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
93963+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
93964 int ret;
93965
93966 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
93967@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
93968 void __user *buffer, size_t *lenp,
93969 loff_t *ppos)
93970 {
93971- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
93972+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
93973 int ret;
93974
93975 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
93976@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
93977 struct mem_cgroup *memcg;
93978 #endif
93979
93980- struct ctl_table tmp = {
93981+ ctl_table_no_const tmp = {
93982 .data = &vec,
93983 .maxlen = sizeof(vec),
93984 .mode = ctl->mode,
93985 };
93986
93987 if (!write) {
93988- ctl->data = &net->ipv4.sysctl_tcp_mem;
93989- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
93990+ ctl_table_no_const tcp_mem = *ctl;
93991+
93992+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
93993+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
93994 }
93995
93996 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
93997@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
93998 void __user *buffer, size_t *lenp,
93999 loff_t *ppos)
94000 {
94001- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94002+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94003 struct tcp_fastopen_context *ctxt;
94004 int ret;
94005 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
94006@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
94007 },
94008 {
94009 .procname = "ip_local_reserved_ports",
94010- .data = NULL, /* initialized in sysctl_ipv4_init */
94011+ .data = sysctl_local_reserved_ports,
94012 .maxlen = 65536,
94013 .mode = 0644,
94014 .proc_handler = proc_do_large_bitmap,
94015@@ -864,11 +866,10 @@ static struct ctl_table ipv4_net_table[] = {
94016
94017 static __net_init int ipv4_sysctl_init_net(struct net *net)
94018 {
94019- struct ctl_table *table;
94020+ ctl_table_no_const *table = NULL;
94021
94022- table = ipv4_net_table;
94023 if (!net_eq(net, &init_net)) {
94024- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
94025+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
94026 if (table == NULL)
94027 goto err_alloc;
94028
94029@@ -903,15 +904,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
94030
94031 tcp_init_mem(net);
94032
94033- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94034+ if (!net_eq(net, &init_net))
94035+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94036+ else
94037+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
94038 if (net->ipv4.ipv4_hdr == NULL)
94039 goto err_reg;
94040
94041 return 0;
94042
94043 err_reg:
94044- if (!net_eq(net, &init_net))
94045- kfree(table);
94046+ kfree(table);
94047 err_alloc:
94048 return -ENOMEM;
94049 }
94050@@ -933,16 +936,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
94051 static __init int sysctl_ipv4_init(void)
94052 {
94053 struct ctl_table_header *hdr;
94054- struct ctl_table *i;
94055-
94056- for (i = ipv4_table; i->procname; i++) {
94057- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
94058- i->data = sysctl_local_reserved_ports;
94059- break;
94060- }
94061- }
94062- if (!i->procname)
94063- return -EINVAL;
94064
94065 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
94066 if (hdr == NULL)
94067diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
94068index 068c8fb..a755c52 100644
94069--- a/net/ipv4/tcp_input.c
94070+++ b/net/ipv4/tcp_input.c
94071@@ -4435,7 +4435,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
94072 * simplifies code)
94073 */
94074 static void
94075-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94076+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94077 struct sk_buff *head, struct sk_buff *tail,
94078 u32 start, u32 end)
94079 {
94080@@ -5520,6 +5520,7 @@ discard:
94081 tcp_paws_reject(&tp->rx_opt, 0))
94082 goto discard_and_undo;
94083
94084+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
94085 if (th->syn) {
94086 /* We see SYN without ACK. It is attempt of
94087 * simultaneous connect with crossed SYNs.
94088@@ -5570,6 +5571,7 @@ discard:
94089 goto discard;
94090 #endif
94091 }
94092+#endif
94093 /* "fifth, if neither of the SYN or RST bits is set then
94094 * drop the segment and return."
94095 */
94096@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
94097 goto discard;
94098
94099 if (th->syn) {
94100- if (th->fin)
94101+ if (th->fin || th->urg || th->psh)
94102 goto discard;
94103 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
94104 return 1;
94105diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
94106index b14266b..c5fe725 100644
94107--- a/net/ipv4/tcp_ipv4.c
94108+++ b/net/ipv4/tcp_ipv4.c
94109@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
94110 EXPORT_SYMBOL(sysctl_tcp_low_latency);
94111
94112
94113+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94114+extern int grsec_enable_blackhole;
94115+#endif
94116+
94117 #ifdef CONFIG_TCP_MD5SIG
94118 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
94119 __be32 daddr, __be32 saddr, const struct tcphdr *th);
94120@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
94121 return 0;
94122
94123 reset:
94124+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94125+ if (!grsec_enable_blackhole)
94126+#endif
94127 tcp_v4_send_reset(rsk, skb);
94128 discard:
94129 kfree_skb(skb);
94130@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
94131 TCP_SKB_CB(skb)->sacked = 0;
94132
94133 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94134- if (!sk)
94135+ if (!sk) {
94136+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94137+ ret = 1;
94138+#endif
94139 goto no_tcp_socket;
94140-
94141+ }
94142 process:
94143- if (sk->sk_state == TCP_TIME_WAIT)
94144+ if (sk->sk_state == TCP_TIME_WAIT) {
94145+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94146+ ret = 2;
94147+#endif
94148 goto do_time_wait;
94149+ }
94150
94151 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
94152 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
94153@@ -2033,6 +2047,10 @@ csum_error:
94154 bad_packet:
94155 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
94156 } else {
94157+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94158+ if (!grsec_enable_blackhole || (ret == 1 &&
94159+ (skb->dev->flags & IFF_LOOPBACK)))
94160+#endif
94161 tcp_v4_send_reset(NULL, skb);
94162 }
94163
94164diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
94165index 58a3e69..7f0626e 100644
94166--- a/net/ipv4/tcp_minisocks.c
94167+++ b/net/ipv4/tcp_minisocks.c
94168@@ -27,6 +27,10 @@
94169 #include <net/inet_common.h>
94170 #include <net/xfrm.h>
94171
94172+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94173+extern int grsec_enable_blackhole;
94174+#endif
94175+
94176 int sysctl_tcp_syncookies __read_mostly = 1;
94177 EXPORT_SYMBOL(sysctl_tcp_syncookies);
94178
94179@@ -711,7 +715,10 @@ embryonic_reset:
94180 * avoid becoming vulnerable to outside attack aiming at
94181 * resetting legit local connections.
94182 */
94183- req->rsk_ops->send_reset(sk, skb);
94184+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94185+ if (!grsec_enable_blackhole)
94186+#endif
94187+ req->rsk_ops->send_reset(sk, skb);
94188 } else if (fastopen) { /* received a valid RST pkt */
94189 reqsk_fastopen_remove(sk, req, true);
94190 tcp_reset(sk);
94191diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
94192index 611beab..c4b6e1d 100644
94193--- a/net/ipv4/tcp_probe.c
94194+++ b/net/ipv4/tcp_probe.c
94195@@ -245,7 +245,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
94196 if (cnt + width >= len)
94197 break;
94198
94199- if (copy_to_user(buf + cnt, tbuf, width))
94200+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
94201 return -EFAULT;
94202 cnt += width;
94203 }
94204diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
94205index 4b85e6f..22f9ac9 100644
94206--- a/net/ipv4/tcp_timer.c
94207+++ b/net/ipv4/tcp_timer.c
94208@@ -22,6 +22,10 @@
94209 #include <linux/gfp.h>
94210 #include <net/tcp.h>
94211
94212+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94213+extern int grsec_lastack_retries;
94214+#endif
94215+
94216 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
94217 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
94218 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
94219@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
94220 }
94221 }
94222
94223+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94224+ if ((sk->sk_state == TCP_LAST_ACK) &&
94225+ (grsec_lastack_retries > 0) &&
94226+ (grsec_lastack_retries < retry_until))
94227+ retry_until = grsec_lastack_retries;
94228+#endif
94229+
94230 if (retransmits_timed_out(sk, retry_until,
94231 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
94232 /* Has it gone just too far? */
94233diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
94234index 0ca44df..b5e4b11 100644
94235--- a/net/ipv4/udp.c
94236+++ b/net/ipv4/udp.c
94237@@ -87,6 +87,7 @@
94238 #include <linux/types.h>
94239 #include <linux/fcntl.h>
94240 #include <linux/module.h>
94241+#include <linux/security.h>
94242 #include <linux/socket.h>
94243 #include <linux/sockios.h>
94244 #include <linux/igmp.h>
94245@@ -112,6 +113,10 @@
94246 #include <net/busy_poll.h>
94247 #include "udp_impl.h"
94248
94249+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94250+extern int grsec_enable_blackhole;
94251+#endif
94252+
94253 struct udp_table udp_table __read_mostly;
94254 EXPORT_SYMBOL(udp_table);
94255
94256@@ -595,6 +600,9 @@ found:
94257 return s;
94258 }
94259
94260+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
94261+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
94262+
94263 /*
94264 * This routine is called by the ICMP module when it gets some
94265 * sort of error condition. If err < 0 then the socket should
94266@@ -892,9 +900,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94267 dport = usin->sin_port;
94268 if (dport == 0)
94269 return -EINVAL;
94270+
94271+ err = gr_search_udp_sendmsg(sk, usin);
94272+ if (err)
94273+ return err;
94274 } else {
94275 if (sk->sk_state != TCP_ESTABLISHED)
94276 return -EDESTADDRREQ;
94277+
94278+ err = gr_search_udp_sendmsg(sk, NULL);
94279+ if (err)
94280+ return err;
94281+
94282 daddr = inet->inet_daddr;
94283 dport = inet->inet_dport;
94284 /* Open fast path for connected socket.
94285@@ -1138,7 +1155,7 @@ static unsigned int first_packet_length(struct sock *sk)
94286 IS_UDPLITE(sk));
94287 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94288 IS_UDPLITE(sk));
94289- atomic_inc(&sk->sk_drops);
94290+ atomic_inc_unchecked(&sk->sk_drops);
94291 __skb_unlink(skb, rcvq);
94292 __skb_queue_tail(&list_kill, skb);
94293 }
94294@@ -1224,6 +1241,10 @@ try_again:
94295 if (!skb)
94296 goto out;
94297
94298+ err = gr_search_udp_recvmsg(sk, skb);
94299+ if (err)
94300+ goto out_free;
94301+
94302 ulen = skb->len - sizeof(struct udphdr);
94303 copied = len;
94304 if (copied > ulen)
94305@@ -1257,7 +1278,7 @@ try_again:
94306 if (unlikely(err)) {
94307 trace_kfree_skb(skb, udp_recvmsg);
94308 if (!peeked) {
94309- atomic_inc(&sk->sk_drops);
94310+ atomic_inc_unchecked(&sk->sk_drops);
94311 UDP_INC_STATS_USER(sock_net(sk),
94312 UDP_MIB_INERRORS, is_udplite);
94313 }
94314@@ -1544,7 +1565,7 @@ csum_error:
94315 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
94316 drop:
94317 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
94318- atomic_inc(&sk->sk_drops);
94319+ atomic_inc_unchecked(&sk->sk_drops);
94320 kfree_skb(skb);
94321 return -1;
94322 }
94323@@ -1563,7 +1584,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
94324 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
94325
94326 if (!skb1) {
94327- atomic_inc(&sk->sk_drops);
94328+ atomic_inc_unchecked(&sk->sk_drops);
94329 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
94330 IS_UDPLITE(sk));
94331 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94332@@ -1735,6 +1756,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
94333 goto csum_error;
94334
94335 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
94336+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94337+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
94338+#endif
94339 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
94340
94341 /*
94342@@ -2167,7 +2191,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
94343 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94344 0, sock_i_ino(sp),
94345 atomic_read(&sp->sk_refcnt), sp,
94346- atomic_read(&sp->sk_drops), len);
94347+ atomic_read_unchecked(&sp->sk_drops), len);
94348 }
94349
94350 int udp4_seq_show(struct seq_file *seq, void *v)
94351diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
94352index ccde542..eeb5ff7 100644
94353--- a/net/ipv4/xfrm4_policy.c
94354+++ b/net/ipv4/xfrm4_policy.c
94355@@ -182,11 +182,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
94356 fl4->flowi4_tos = iph->tos;
94357 }
94358
94359-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
94360+static int xfrm4_garbage_collect(struct dst_ops *ops)
94361 {
94362 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
94363
94364- xfrm4_policy_afinfo.garbage_collect(net);
94365+ xfrm_garbage_collect_deferred(net);
94366 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
94367 }
94368
94369@@ -265,19 +265,18 @@ static struct ctl_table xfrm4_policy_table[] = {
94370
94371 static int __net_init xfrm4_net_init(struct net *net)
94372 {
94373- struct ctl_table *table;
94374+ ctl_table_no_const *table = NULL;
94375 struct ctl_table_header *hdr;
94376
94377- table = xfrm4_policy_table;
94378 if (!net_eq(net, &init_net)) {
94379- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94380+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94381 if (!table)
94382 goto err_alloc;
94383
94384 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
94385- }
94386-
94387- hdr = register_net_sysctl(net, "net/ipv4", table);
94388+ hdr = register_net_sysctl(net, "net/ipv4", table);
94389+ } else
94390+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
94391 if (!hdr)
94392 goto err_reg;
94393
94394@@ -285,8 +284,7 @@ static int __net_init xfrm4_net_init(struct net *net)
94395 return 0;
94396
94397 err_reg:
94398- if (!net_eq(net, &init_net))
94399- kfree(table);
94400+ kfree(table);
94401 err_alloc:
94402 return -ENOMEM;
94403 }
94404diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
94405index cd3fb30..b7dfef7 100644
94406--- a/net/ipv6/addrconf.c
94407+++ b/net/ipv6/addrconf.c
94408@@ -586,7 +586,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
94409 idx = 0;
94410 head = &net->dev_index_head[h];
94411 rcu_read_lock();
94412- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
94413+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
94414 net->dev_base_seq;
94415 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94416 if (idx < s_idx)
94417@@ -2364,7 +2364,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
94418 p.iph.ihl = 5;
94419 p.iph.protocol = IPPROTO_IPV6;
94420 p.iph.ttl = 64;
94421- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
94422+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
94423
94424 if (ops->ndo_do_ioctl) {
94425 mm_segment_t oldfs = get_fs();
94426@@ -3977,7 +3977,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
94427 s_ip_idx = ip_idx = cb->args[2];
94428
94429 rcu_read_lock();
94430- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94431+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94432 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
94433 idx = 0;
94434 head = &net->dev_index_head[h];
94435@@ -4603,7 +4603,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
94436 dst_free(&ifp->rt->dst);
94437 break;
94438 }
94439- atomic_inc(&net->ipv6.dev_addr_genid);
94440+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
94441 rt_genid_bump_ipv6(net);
94442 }
94443
94444@@ -4624,7 +4624,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
94445 int *valp = ctl->data;
94446 int val = *valp;
94447 loff_t pos = *ppos;
94448- struct ctl_table lctl;
94449+ ctl_table_no_const lctl;
94450 int ret;
94451
94452 /*
94453@@ -4709,7 +4709,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
94454 int *valp = ctl->data;
94455 int val = *valp;
94456 loff_t pos = *ppos;
94457- struct ctl_table lctl;
94458+ ctl_table_no_const lctl;
94459 int ret;
94460
94461 /*
94462diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
94463index 7c96100..bfd994a 100644
94464--- a/net/ipv6/af_inet6.c
94465+++ b/net/ipv6/af_inet6.c
94466@@ -767,7 +767,7 @@ static int __net_init inet6_net_init(struct net *net)
94467
94468 net->ipv6.sysctl.bindv6only = 0;
94469 net->ipv6.sysctl.icmpv6_time = 1*HZ;
94470- atomic_set(&net->ipv6.rt_genid, 0);
94471+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
94472
94473 err = ipv6_init_mibs(net);
94474 if (err)
94475diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
94476index 48b6bd2..76d3458 100644
94477--- a/net/ipv6/datagram.c
94478+++ b/net/ipv6/datagram.c
94479@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
94480 0,
94481 sock_i_ino(sp),
94482 atomic_read(&sp->sk_refcnt), sp,
94483- atomic_read(&sp->sk_drops));
94484+ atomic_read_unchecked(&sp->sk_drops));
94485 }
94486diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
94487index eef8d94..cfa1852 100644
94488--- a/net/ipv6/icmp.c
94489+++ b/net/ipv6/icmp.c
94490@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
94491
94492 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
94493 {
94494- struct ctl_table *table;
94495+ ctl_table_no_const *table;
94496
94497 table = kmemdup(ipv6_icmp_table_template,
94498 sizeof(ipv6_icmp_table_template),
94499diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
94500index bf4a9a0..e5f6ac5 100644
94501--- a/net/ipv6/ip6_gre.c
94502+++ b/net/ipv6/ip6_gre.c
94503@@ -74,7 +74,7 @@ struct ip6gre_net {
94504 struct net_device *fb_tunnel_dev;
94505 };
94506
94507-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
94508+static struct rtnl_link_ops ip6gre_link_ops;
94509 static int ip6gre_tunnel_init(struct net_device *dev);
94510 static void ip6gre_tunnel_setup(struct net_device *dev);
94511 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
94512@@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
94513 }
94514
94515
94516-static struct inet6_protocol ip6gre_protocol __read_mostly = {
94517+static struct inet6_protocol ip6gre_protocol = {
94518 .handler = ip6gre_rcv,
94519 .err_handler = ip6gre_err,
94520 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
94521@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
94522 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
94523 };
94524
94525-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94526+static struct rtnl_link_ops ip6gre_link_ops = {
94527 .kind = "ip6gre",
94528 .maxtype = IFLA_GRE_MAX,
94529 .policy = ip6gre_policy,
94530@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94531 .fill_info = ip6gre_fill_info,
94532 };
94533
94534-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
94535+static struct rtnl_link_ops ip6gre_tap_ops = {
94536 .kind = "ip6gretap",
94537 .maxtype = IFLA_GRE_MAX,
94538 .policy = ip6gre_policy,
94539diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
94540index 583b77e..99522b8 100644
94541--- a/net/ipv6/ip6_tunnel.c
94542+++ b/net/ipv6/ip6_tunnel.c
94543@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
94544
94545 static int ip6_tnl_dev_init(struct net_device *dev);
94546 static void ip6_tnl_dev_setup(struct net_device *dev);
94547-static struct rtnl_link_ops ip6_link_ops __read_mostly;
94548+static struct rtnl_link_ops ip6_link_ops;
94549
94550 static int ip6_tnl_net_id __read_mostly;
94551 struct ip6_tnl_net {
94552@@ -1690,7 +1690,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
94553 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
94554 };
94555
94556-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
94557+static struct rtnl_link_ops ip6_link_ops = {
94558 .kind = "ip6tnl",
94559 .maxtype = IFLA_IPTUN_MAX,
94560 .policy = ip6_tnl_policy,
94561diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
94562index d1e2e8e..51c19ae 100644
94563--- a/net/ipv6/ipv6_sockglue.c
94564+++ b/net/ipv6/ipv6_sockglue.c
94565@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
94566 if (sk->sk_type != SOCK_STREAM)
94567 return -ENOPROTOOPT;
94568
94569- msg.msg_control = optval;
94570+ msg.msg_control = (void __force_kernel *)optval;
94571 msg.msg_controllen = len;
94572 msg.msg_flags = flags;
94573
94574diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
94575index 44400c2..8e11f52 100644
94576--- a/net/ipv6/netfilter/ip6_tables.c
94577+++ b/net/ipv6/netfilter/ip6_tables.c
94578@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
94579 #endif
94580
94581 static int get_info(struct net *net, void __user *user,
94582- const int *len, int compat)
94583+ int len, int compat)
94584 {
94585 char name[XT_TABLE_MAXNAMELEN];
94586 struct xt_table *t;
94587 int ret;
94588
94589- if (*len != sizeof(struct ip6t_getinfo)) {
94590- duprintf("length %u != %zu\n", *len,
94591+ if (len != sizeof(struct ip6t_getinfo)) {
94592+ duprintf("length %u != %zu\n", len,
94593 sizeof(struct ip6t_getinfo));
94594 return -EINVAL;
94595 }
94596@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
94597 info.size = private->size;
94598 strcpy(info.name, name);
94599
94600- if (copy_to_user(user, &info, *len) != 0)
94601+ if (copy_to_user(user, &info, len) != 0)
94602 ret = -EFAULT;
94603 else
94604 ret = 0;
94605@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94606
94607 switch (cmd) {
94608 case IP6T_SO_GET_INFO:
94609- ret = get_info(sock_net(sk), user, len, 1);
94610+ ret = get_info(sock_net(sk), user, *len, 1);
94611 break;
94612 case IP6T_SO_GET_ENTRIES:
94613 ret = compat_get_entries(sock_net(sk), user, len);
94614@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94615
94616 switch (cmd) {
94617 case IP6T_SO_GET_INFO:
94618- ret = get_info(sock_net(sk), user, len, 0);
94619+ ret = get_info(sock_net(sk), user, *len, 0);
94620 break;
94621
94622 case IP6T_SO_GET_ENTRIES:
94623diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
94624index dffdc1a..ccc6678 100644
94625--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
94626+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
94627@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
94628
94629 static int nf_ct_frag6_sysctl_register(struct net *net)
94630 {
94631- struct ctl_table *table;
94632+ ctl_table_no_const *table = NULL;
94633 struct ctl_table_header *hdr;
94634
94635- table = nf_ct_frag6_sysctl_table;
94636 if (!net_eq(net, &init_net)) {
94637- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
94638+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
94639 GFP_KERNEL);
94640 if (table == NULL)
94641 goto err_alloc;
94642@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
94643 table[0].data = &net->nf_frag.frags.timeout;
94644 table[1].data = &net->nf_frag.frags.low_thresh;
94645 table[2].data = &net->nf_frag.frags.high_thresh;
94646- }
94647-
94648- hdr = register_net_sysctl(net, "net/netfilter", table);
94649+ hdr = register_net_sysctl(net, "net/netfilter", table);
94650+ } else
94651+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
94652 if (hdr == NULL)
94653 goto err_reg;
94654
94655@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
94656 return 0;
94657
94658 err_reg:
94659- if (!net_eq(net, &init_net))
94660- kfree(table);
94661+ kfree(table);
94662 err_alloc:
94663 return -ENOMEM;
94664 }
94665diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
94666index 827f795..7e28e82 100644
94667--- a/net/ipv6/output_core.c
94668+++ b/net/ipv6/output_core.c
94669@@ -9,8 +9,8 @@
94670
94671 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
94672 {
94673- static atomic_t ipv6_fragmentation_id;
94674- int old, new;
94675+ static atomic_unchecked_t ipv6_fragmentation_id;
94676+ int id;
94677
94678 #if IS_ENABLED(CONFIG_IPV6)
94679 if (rt && !(rt->dst.flags & DST_NOPEER)) {
94680@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
94681 }
94682 }
94683 #endif
94684- do {
94685- old = atomic_read(&ipv6_fragmentation_id);
94686- new = old + 1;
94687- if (!new)
94688- new = 1;
94689- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
94690- fhdr->identification = htonl(new);
94691+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
94692+ if (!id)
94693+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
94694+ fhdr->identification = htonl(id);
94695 }
94696 EXPORT_SYMBOL(ipv6_select_ident);
94697
94698diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
94699index 18f19df..b46ada1 100644
94700--- a/net/ipv6/ping.c
94701+++ b/net/ipv6/ping.c
94702@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
94703 };
94704 #endif
94705
94706+static struct pingv6_ops real_pingv6_ops = {
94707+ .ipv6_recv_error = ipv6_recv_error,
94708+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
94709+ .icmpv6_err_convert = icmpv6_err_convert,
94710+ .ipv6_icmp_error = ipv6_icmp_error,
94711+ .ipv6_chk_addr = ipv6_chk_addr,
94712+};
94713+
94714+static struct pingv6_ops dummy_pingv6_ops = {
94715+ .ipv6_recv_error = dummy_ipv6_recv_error,
94716+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
94717+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
94718+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
94719+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
94720+};
94721+
94722 int __init pingv6_init(void)
94723 {
94724 #ifdef CONFIG_PROC_FS
94725@@ -252,11 +268,7 @@ int __init pingv6_init(void)
94726 if (ret)
94727 return ret;
94728 #endif
94729- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
94730- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
94731- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
94732- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
94733- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
94734+ pingv6_ops = &real_pingv6_ops;
94735 return inet6_register_protosw(&pingv6_protosw);
94736 }
94737
94738@@ -265,11 +277,7 @@ int __init pingv6_init(void)
94739 */
94740 void pingv6_exit(void)
94741 {
94742- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
94743- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
94744- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
94745- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
94746- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
94747+ pingv6_ops = &dummy_pingv6_ops;
94748 #ifdef CONFIG_PROC_FS
94749 unregister_pernet_subsys(&ping_v6_net_ops);
94750 #endif
94751diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
94752index a4ed241..8bf6277 100644
94753--- a/net/ipv6/raw.c
94754+++ b/net/ipv6/raw.c
94755@@ -385,7 +385,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
94756 {
94757 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
94758 skb_checksum_complete(skb)) {
94759- atomic_inc(&sk->sk_drops);
94760+ atomic_inc_unchecked(&sk->sk_drops);
94761 kfree_skb(skb);
94762 return NET_RX_DROP;
94763 }
94764@@ -413,7 +413,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
94765 struct raw6_sock *rp = raw6_sk(sk);
94766
94767 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
94768- atomic_inc(&sk->sk_drops);
94769+ atomic_inc_unchecked(&sk->sk_drops);
94770 kfree_skb(skb);
94771 return NET_RX_DROP;
94772 }
94773@@ -437,7 +437,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
94774
94775 if (inet->hdrincl) {
94776 if (skb_checksum_complete(skb)) {
94777- atomic_inc(&sk->sk_drops);
94778+ atomic_inc_unchecked(&sk->sk_drops);
94779 kfree_skb(skb);
94780 return NET_RX_DROP;
94781 }
94782@@ -609,7 +609,7 @@ out:
94783 return err;
94784 }
94785
94786-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
94787+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
94788 struct flowi6 *fl6, struct dst_entry **dstp,
94789 unsigned int flags)
94790 {
94791@@ -922,12 +922,15 @@ do_confirm:
94792 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
94793 char __user *optval, int optlen)
94794 {
94795+ struct icmp6_filter filter;
94796+
94797 switch (optname) {
94798 case ICMPV6_FILTER:
94799 if (optlen > sizeof(struct icmp6_filter))
94800 optlen = sizeof(struct icmp6_filter);
94801- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
94802+ if (copy_from_user(&filter, optval, optlen))
94803 return -EFAULT;
94804+ raw6_sk(sk)->filter = filter;
94805 return 0;
94806 default:
94807 return -ENOPROTOOPT;
94808@@ -940,6 +943,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
94809 char __user *optval, int __user *optlen)
94810 {
94811 int len;
94812+ struct icmp6_filter filter;
94813
94814 switch (optname) {
94815 case ICMPV6_FILTER:
94816@@ -951,7 +955,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
94817 len = sizeof(struct icmp6_filter);
94818 if (put_user(len, optlen))
94819 return -EFAULT;
94820- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
94821+ filter = raw6_sk(sk)->filter;
94822+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
94823 return -EFAULT;
94824 return 0;
94825 default:
94826diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
94827index 1aeb473..bea761c 100644
94828--- a/net/ipv6/reassembly.c
94829+++ b/net/ipv6/reassembly.c
94830@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
94831
94832 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
94833 {
94834- struct ctl_table *table;
94835+ ctl_table_no_const *table = NULL;
94836 struct ctl_table_header *hdr;
94837
94838- table = ip6_frags_ns_ctl_table;
94839 if (!net_eq(net, &init_net)) {
94840- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
94841+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
94842 if (table == NULL)
94843 goto err_alloc;
94844
94845@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
94846 /* Don't export sysctls to unprivileged users */
94847 if (net->user_ns != &init_user_ns)
94848 table[0].procname = NULL;
94849- }
94850+ hdr = register_net_sysctl(net, "net/ipv6", table);
94851+ } else
94852+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
94853
94854- hdr = register_net_sysctl(net, "net/ipv6", table);
94855 if (hdr == NULL)
94856 goto err_reg;
94857
94858@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
94859 return 0;
94860
94861 err_reg:
94862- if (!net_eq(net, &init_net))
94863- kfree(table);
94864+ kfree(table);
94865 err_alloc:
94866 return -ENOMEM;
94867 }
94868diff --git a/net/ipv6/route.c b/net/ipv6/route.c
94869index 04e17b3..83502e9 100644
94870--- a/net/ipv6/route.c
94871+++ b/net/ipv6/route.c
94872@@ -3006,7 +3006,7 @@ struct ctl_table ipv6_route_table_template[] = {
94873
94874 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
94875 {
94876- struct ctl_table *table;
94877+ ctl_table_no_const *table;
94878
94879 table = kmemdup(ipv6_route_table_template,
94880 sizeof(ipv6_route_table_template),
94881diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
94882index 1926945..30a1a57 100644
94883--- a/net/ipv6/sit.c
94884+++ b/net/ipv6/sit.c
94885@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
94886 static void ipip6_dev_free(struct net_device *dev);
94887 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
94888 __be32 *v4dst);
94889-static struct rtnl_link_ops sit_link_ops __read_mostly;
94890+static struct rtnl_link_ops sit_link_ops;
94891
94892 static int sit_net_id __read_mostly;
94893 struct sit_net {
94894@@ -1594,7 +1594,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
94895 #endif
94896 };
94897
94898-static struct rtnl_link_ops sit_link_ops __read_mostly = {
94899+static struct rtnl_link_ops sit_link_ops = {
94900 .kind = "sit",
94901 .maxtype = IFLA_IPTUN_MAX,
94902 .policy = ipip6_policy,
94903diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
94904index 107b2f1..72741a9 100644
94905--- a/net/ipv6/sysctl_net_ipv6.c
94906+++ b/net/ipv6/sysctl_net_ipv6.c
94907@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
94908
94909 static int __net_init ipv6_sysctl_net_init(struct net *net)
94910 {
94911- struct ctl_table *ipv6_table;
94912+ ctl_table_no_const *ipv6_table;
94913 struct ctl_table *ipv6_route_table;
94914 struct ctl_table *ipv6_icmp_table;
94915 int err;
94916diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
94917index 5c71501..7e8d5d3 100644
94918--- a/net/ipv6/tcp_ipv6.c
94919+++ b/net/ipv6/tcp_ipv6.c
94920@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
94921 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
94922 }
94923
94924+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94925+extern int grsec_enable_blackhole;
94926+#endif
94927+
94928 static void tcp_v6_hash(struct sock *sk)
94929 {
94930 if (sk->sk_state != TCP_CLOSE) {
94931@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
94932 return 0;
94933
94934 reset:
94935+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94936+ if (!grsec_enable_blackhole)
94937+#endif
94938 tcp_v6_send_reset(sk, skb);
94939 discard:
94940 if (opt_skb)
94941@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
94942 TCP_SKB_CB(skb)->sacked = 0;
94943
94944 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94945- if (!sk)
94946+ if (!sk) {
94947+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94948+ ret = 1;
94949+#endif
94950 goto no_tcp_socket;
94951+ }
94952
94953 process:
94954- if (sk->sk_state == TCP_TIME_WAIT)
94955+ if (sk->sk_state == TCP_TIME_WAIT) {
94956+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94957+ ret = 2;
94958+#endif
94959 goto do_time_wait;
94960+ }
94961
94962 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
94963 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
94964@@ -1536,6 +1551,10 @@ csum_error:
94965 bad_packet:
94966 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
94967 } else {
94968+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94969+ if (!grsec_enable_blackhole || (ret == 1 &&
94970+ (skb->dev->flags & IFF_LOOPBACK)))
94971+#endif
94972 tcp_v6_send_reset(NULL, skb);
94973 }
94974
94975diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
94976index 1878609..b48e1d4 100644
94977--- a/net/ipv6/udp.c
94978+++ b/net/ipv6/udp.c
94979@@ -53,6 +53,10 @@
94980 #include <trace/events/skb.h>
94981 #include "udp_impl.h"
94982
94983+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94984+extern int grsec_enable_blackhole;
94985+#endif
94986+
94987 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
94988 {
94989 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
94990@@ -420,7 +424,7 @@ try_again:
94991 if (unlikely(err)) {
94992 trace_kfree_skb(skb, udpv6_recvmsg);
94993 if (!peeked) {
94994- atomic_inc(&sk->sk_drops);
94995+ atomic_inc_unchecked(&sk->sk_drops);
94996 if (is_udp4)
94997 UDP_INC_STATS_USER(sock_net(sk),
94998 UDP_MIB_INERRORS,
94999@@ -668,7 +672,7 @@ csum_error:
95000 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
95001 drop:
95002 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
95003- atomic_inc(&sk->sk_drops);
95004+ atomic_inc_unchecked(&sk->sk_drops);
95005 kfree_skb(skb);
95006 return -1;
95007 }
95008@@ -726,7 +730,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
95009 if (likely(skb1 == NULL))
95010 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
95011 if (!skb1) {
95012- atomic_inc(&sk->sk_drops);
95013+ atomic_inc_unchecked(&sk->sk_drops);
95014 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
95015 IS_UDPLITE(sk));
95016 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95017@@ -866,6 +870,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
95018 goto csum_error;
95019
95020 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
95021+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95022+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
95023+#endif
95024 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
95025
95026 kfree_skb(skb);
95027diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
95028index 08ed277..80e4bc8 100644
95029--- a/net/ipv6/xfrm6_policy.c
95030+++ b/net/ipv6/xfrm6_policy.c
95031@@ -208,11 +208,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
95032 }
95033 }
95034
95035-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
95036+static int xfrm6_garbage_collect(struct dst_ops *ops)
95037 {
95038 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
95039
95040- xfrm6_policy_afinfo.garbage_collect(net);
95041+ xfrm_garbage_collect_deferred(net);
95042 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
95043 }
95044
95045@@ -325,19 +325,19 @@ static struct ctl_table xfrm6_policy_table[] = {
95046
95047 static int __net_init xfrm6_net_init(struct net *net)
95048 {
95049- struct ctl_table *table;
95050+ ctl_table_no_const *table = NULL;
95051 struct ctl_table_header *hdr;
95052
95053- table = xfrm6_policy_table;
95054 if (!net_eq(net, &init_net)) {
95055- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95056+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95057 if (!table)
95058 goto err_alloc;
95059
95060 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
95061- }
95062+ hdr = register_net_sysctl(net, "net/ipv6", table);
95063+ } else
95064+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
95065
95066- hdr = register_net_sysctl(net, "net/ipv6", table);
95067 if (!hdr)
95068 goto err_reg;
95069
95070@@ -345,8 +345,7 @@ static int __net_init xfrm6_net_init(struct net *net)
95071 return 0;
95072
95073 err_reg:
95074- if (!net_eq(net, &init_net))
95075- kfree(table);
95076+ kfree(table);
95077 err_alloc:
95078 return -ENOMEM;
95079 }
95080diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
95081index 41ac7938..75e3bb1 100644
95082--- a/net/irda/ircomm/ircomm_tty.c
95083+++ b/net/irda/ircomm/ircomm_tty.c
95084@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95085 add_wait_queue(&port->open_wait, &wait);
95086
95087 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
95088- __FILE__, __LINE__, tty->driver->name, port->count);
95089+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95090
95091 spin_lock_irqsave(&port->lock, flags);
95092 if (!tty_hung_up_p(filp))
95093- port->count--;
95094+ atomic_dec(&port->count);
95095 port->blocked_open++;
95096 spin_unlock_irqrestore(&port->lock, flags);
95097
95098@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95099 }
95100
95101 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
95102- __FILE__, __LINE__, tty->driver->name, port->count);
95103+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95104
95105 schedule();
95106 }
95107@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95108
95109 spin_lock_irqsave(&port->lock, flags);
95110 if (!tty_hung_up_p(filp))
95111- port->count++;
95112+ atomic_inc(&port->count);
95113 port->blocked_open--;
95114 spin_unlock_irqrestore(&port->lock, flags);
95115
95116 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
95117- __FILE__, __LINE__, tty->driver->name, port->count);
95118+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95119
95120 if (!retval)
95121 port->flags |= ASYNC_NORMAL_ACTIVE;
95122@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
95123
95124 /* ++ is not atomic, so this should be protected - Jean II */
95125 spin_lock_irqsave(&self->port.lock, flags);
95126- self->port.count++;
95127+ atomic_inc(&self->port.count);
95128 spin_unlock_irqrestore(&self->port.lock, flags);
95129 tty_port_tty_set(&self->port, tty);
95130
95131 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
95132- self->line, self->port.count);
95133+ self->line, atomic_read(&self->port.count));
95134
95135 /* Not really used by us, but lets do it anyway */
95136 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
95137@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
95138 tty_kref_put(port->tty);
95139 }
95140 port->tty = NULL;
95141- port->count = 0;
95142+ atomic_set(&port->count, 0);
95143 spin_unlock_irqrestore(&port->lock, flags);
95144
95145 wake_up_interruptible(&port->open_wait);
95146@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
95147 seq_putc(m, '\n');
95148
95149 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
95150- seq_printf(m, "Open count: %d\n", self->port.count);
95151+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
95152 seq_printf(m, "Max data size: %d\n", self->max_data_size);
95153 seq_printf(m, "Max header size: %d\n", self->max_header_size);
95154
95155diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
95156index 168aff5..9d43132 100644
95157--- a/net/iucv/af_iucv.c
95158+++ b/net/iucv/af_iucv.c
95159@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
95160
95161 write_lock_bh(&iucv_sk_list.lock);
95162
95163- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
95164+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95165 while (__iucv_get_sock_by_name(name)) {
95166 sprintf(name, "%08x",
95167- atomic_inc_return(&iucv_sk_list.autobind_name));
95168+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95169 }
95170
95171 write_unlock_bh(&iucv_sk_list.lock);
95172diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
95173index cd5b8ec..f205e6b 100644
95174--- a/net/iucv/iucv.c
95175+++ b/net/iucv/iucv.c
95176@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
95177 return NOTIFY_OK;
95178 }
95179
95180-static struct notifier_block __refdata iucv_cpu_notifier = {
95181+static struct notifier_block iucv_cpu_notifier = {
95182 .notifier_call = iucv_cpu_notify,
95183 };
95184
95185diff --git a/net/key/af_key.c b/net/key/af_key.c
95186index 911ef03..58f9c96 100644
95187--- a/net/key/af_key.c
95188+++ b/net/key/af_key.c
95189@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
95190 static u32 get_acqseq(void)
95191 {
95192 u32 res;
95193- static atomic_t acqseq;
95194+ static atomic_unchecked_t acqseq;
95195
95196 do {
95197- res = atomic_inc_return(&acqseq);
95198+ res = atomic_inc_return_unchecked(&acqseq);
95199 } while (!res);
95200 return res;
95201 }
95202diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
95203index 629dee7..4bdd2c8 100644
95204--- a/net/mac80211/cfg.c
95205+++ b/net/mac80211/cfg.c
95206@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
95207 ret = ieee80211_vif_use_channel(sdata, chandef,
95208 IEEE80211_CHANCTX_EXCLUSIVE);
95209 }
95210- } else if (local->open_count == local->monitors) {
95211+ } else if (local_read(&local->open_count) == local->monitors) {
95212 local->_oper_chandef = *chandef;
95213 ieee80211_hw_config(local, 0);
95214 }
95215@@ -3125,7 +3125,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
95216 else
95217 local->probe_req_reg--;
95218
95219- if (!local->open_count)
95220+ if (!local_read(&local->open_count))
95221 break;
95222
95223 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
95224@@ -3588,8 +3588,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
95225 if (chanctx_conf) {
95226 *chandef = chanctx_conf->def;
95227 ret = 0;
95228- } else if (local->open_count > 0 &&
95229- local->open_count == local->monitors &&
95230+ } else if (local_read(&local->open_count) > 0 &&
95231+ local_read(&local->open_count) == local->monitors &&
95232 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
95233 if (local->use_chanctx)
95234 *chandef = local->monitor_chandef;
95235diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
95236index 611abfc..8c2c7e4 100644
95237--- a/net/mac80211/ieee80211_i.h
95238+++ b/net/mac80211/ieee80211_i.h
95239@@ -28,6 +28,7 @@
95240 #include <net/ieee80211_radiotap.h>
95241 #include <net/cfg80211.h>
95242 #include <net/mac80211.h>
95243+#include <asm/local.h>
95244 #include "key.h"
95245 #include "sta_info.h"
95246 #include "debug.h"
95247@@ -945,7 +946,7 @@ struct ieee80211_local {
95248 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
95249 spinlock_t queue_stop_reason_lock;
95250
95251- int open_count;
95252+ local_t open_count;
95253 int monitors, cooked_mntrs;
95254 /* number of interfaces with corresponding FIF_ flags */
95255 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
95256diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
95257index fcecd63..a404454 100644
95258--- a/net/mac80211/iface.c
95259+++ b/net/mac80211/iface.c
95260@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95261 break;
95262 }
95263
95264- if (local->open_count == 0) {
95265+ if (local_read(&local->open_count) == 0) {
95266 res = drv_start(local);
95267 if (res)
95268 goto err_del_bss;
95269@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95270 res = drv_add_interface(local, sdata);
95271 if (res)
95272 goto err_stop;
95273- } else if (local->monitors == 0 && local->open_count == 0) {
95274+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
95275 res = ieee80211_add_virtual_monitor(local);
95276 if (res)
95277 goto err_stop;
95278@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95279 atomic_inc(&local->iff_promiscs);
95280
95281 if (coming_up)
95282- local->open_count++;
95283+ local_inc(&local->open_count);
95284
95285 if (hw_reconf_flags)
95286 ieee80211_hw_config(local, hw_reconf_flags);
95287@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95288 err_del_interface:
95289 drv_remove_interface(local, sdata);
95290 err_stop:
95291- if (!local->open_count)
95292+ if (!local_read(&local->open_count))
95293 drv_stop(local);
95294 err_del_bss:
95295 sdata->bss = NULL;
95296@@ -852,7 +852,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95297 }
95298
95299 if (going_down)
95300- local->open_count--;
95301+ local_dec(&local->open_count);
95302
95303 switch (sdata->vif.type) {
95304 case NL80211_IFTYPE_AP_VLAN:
95305@@ -919,7 +919,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95306 }
95307 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
95308
95309- if (local->open_count == 0)
95310+ if (local_read(&local->open_count) == 0)
95311 ieee80211_clear_tx_pending(local);
95312
95313 /*
95314@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95315
95316 ieee80211_recalc_ps(local, -1);
95317
95318- if (local->open_count == 0) {
95319+ if (local_read(&local->open_count) == 0) {
95320 ieee80211_stop_device(local);
95321
95322 /* no reconfiguring after stop! */
95323@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95324 ieee80211_configure_filter(local);
95325 ieee80211_hw_config(local, hw_reconf_flags);
95326
95327- if (local->monitors == local->open_count)
95328+ if (local->monitors == local_read(&local->open_count))
95329 ieee80211_add_virtual_monitor(local);
95330 }
95331
95332diff --git a/net/mac80211/main.c b/net/mac80211/main.c
95333index 21d5d44..4fee18a 100644
95334--- a/net/mac80211/main.c
95335+++ b/net/mac80211/main.c
95336@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
95337 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
95338 IEEE80211_CONF_CHANGE_POWER);
95339
95340- if (changed && local->open_count) {
95341+ if (changed && local_read(&local->open_count)) {
95342 ret = drv_config(local, changed);
95343 /*
95344 * Goal:
95345diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
95346index 3401262..d5cd68d 100644
95347--- a/net/mac80211/pm.c
95348+++ b/net/mac80211/pm.c
95349@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95350 struct ieee80211_sub_if_data *sdata;
95351 struct sta_info *sta;
95352
95353- if (!local->open_count)
95354+ if (!local_read(&local->open_count))
95355 goto suspend;
95356
95357 ieee80211_scan_cancel(local);
95358@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95359 cancel_work_sync(&local->dynamic_ps_enable_work);
95360 del_timer_sync(&local->dynamic_ps_timer);
95361
95362- local->wowlan = wowlan && local->open_count;
95363+ local->wowlan = wowlan && local_read(&local->open_count);
95364 if (local->wowlan) {
95365 int err = drv_suspend(local, wowlan);
95366 if (err < 0) {
95367@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95368 WARN_ON(!list_empty(&local->chanctx_list));
95369
95370 /* stop hardware - this must stop RX */
95371- if (local->open_count)
95372+ if (local_read(&local->open_count))
95373 ieee80211_stop_device(local);
95374
95375 suspend:
95376diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
95377index e126605..73d2c39 100644
95378--- a/net/mac80211/rate.c
95379+++ b/net/mac80211/rate.c
95380@@ -725,7 +725,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
95381
95382 ASSERT_RTNL();
95383
95384- if (local->open_count)
95385+ if (local_read(&local->open_count))
95386 return -EBUSY;
95387
95388 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
95389diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
95390index c97a065..ff61928 100644
95391--- a/net/mac80211/rc80211_pid_debugfs.c
95392+++ b/net/mac80211/rc80211_pid_debugfs.c
95393@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
95394
95395 spin_unlock_irqrestore(&events->lock, status);
95396
95397- if (copy_to_user(buf, pb, p))
95398+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
95399 return -EFAULT;
95400
95401 return p;
95402diff --git a/net/mac80211/util.c b/net/mac80211/util.c
95403index 69e4ef5..e8e4b92 100644
95404--- a/net/mac80211/util.c
95405+++ b/net/mac80211/util.c
95406@@ -1470,7 +1470,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95407 }
95408 #endif
95409 /* everything else happens only if HW was up & running */
95410- if (!local->open_count)
95411+ if (!local_read(&local->open_count))
95412 goto wake_up;
95413
95414 /*
95415@@ -1695,7 +1695,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95416 local->in_reconfig = false;
95417 barrier();
95418
95419- if (local->monitors == local->open_count && local->monitors > 0)
95420+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
95421 ieee80211_add_virtual_monitor(local);
95422
95423 /*
95424diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
95425index 6e839b6..002a233 100644
95426--- a/net/netfilter/Kconfig
95427+++ b/net/netfilter/Kconfig
95428@@ -950,6 +950,16 @@ config NETFILTER_XT_MATCH_ESP
95429
95430 To compile it as a module, choose M here. If unsure, say N.
95431
95432+config NETFILTER_XT_MATCH_GRADM
95433+ tristate '"gradm" match support'
95434+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
95435+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
95436+ ---help---
95437+ The gradm match allows to match on grsecurity RBAC being enabled.
95438+ It is useful when iptables rules are applied early on bootup to
95439+ prevent connections to the machine (except from a trusted host)
95440+ while the RBAC system is disabled.
95441+
95442 config NETFILTER_XT_MATCH_HASHLIMIT
95443 tristate '"hashlimit" match support'
95444 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
95445diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
95446index c3a0a12..90b587f 100644
95447--- a/net/netfilter/Makefile
95448+++ b/net/netfilter/Makefile
95449@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
95450 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
95451 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
95452 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
95453+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
95454 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
95455 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
95456 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
95457diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
95458index f2e30fb..f131862 100644
95459--- a/net/netfilter/ipset/ip_set_core.c
95460+++ b/net/netfilter/ipset/ip_set_core.c
95461@@ -1819,7 +1819,7 @@ done:
95462 return ret;
95463 }
95464
95465-static struct nf_sockopt_ops so_set __read_mostly = {
95466+static struct nf_sockopt_ops so_set = {
95467 .pf = PF_INET,
95468 .get_optmin = SO_IP_SET,
95469 .get_optmax = SO_IP_SET + 1,
95470diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
95471index 4c8e5c0..5a79b4d 100644
95472--- a/net/netfilter/ipvs/ip_vs_conn.c
95473+++ b/net/netfilter/ipvs/ip_vs_conn.c
95474@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
95475 /* Increase the refcnt counter of the dest */
95476 ip_vs_dest_hold(dest);
95477
95478- conn_flags = atomic_read(&dest->conn_flags);
95479+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
95480 if (cp->protocol != IPPROTO_UDP)
95481 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
95482 flags = cp->flags;
95483@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
95484
95485 cp->control = NULL;
95486 atomic_set(&cp->n_control, 0);
95487- atomic_set(&cp->in_pkts, 0);
95488+ atomic_set_unchecked(&cp->in_pkts, 0);
95489
95490 cp->packet_xmit = NULL;
95491 cp->app = NULL;
95492@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
95493
95494 /* Don't drop the entry if its number of incoming packets is not
95495 located in [0, 8] */
95496- i = atomic_read(&cp->in_pkts);
95497+ i = atomic_read_unchecked(&cp->in_pkts);
95498 if (i > 8 || i < 0) return 0;
95499
95500 if (!todrop_rate[i]) return 0;
95501diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
95502index 74fd00c..06e7ac7 100644
95503--- a/net/netfilter/ipvs/ip_vs_core.c
95504+++ b/net/netfilter/ipvs/ip_vs_core.c
95505@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
95506 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
95507 /* do not touch skb anymore */
95508
95509- atomic_inc(&cp->in_pkts);
95510+ atomic_inc_unchecked(&cp->in_pkts);
95511 ip_vs_conn_put(cp);
95512 return ret;
95513 }
95514@@ -1719,7 +1719,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
95515 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
95516 pkts = sysctl_sync_threshold(ipvs);
95517 else
95518- pkts = atomic_add_return(1, &cp->in_pkts);
95519+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95520
95521 if (ipvs->sync_state & IP_VS_STATE_MASTER)
95522 ip_vs_sync_conn(net, cp, pkts);
95523diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
95524index a3df9bd..895ae09 100644
95525--- a/net/netfilter/ipvs/ip_vs_ctl.c
95526+++ b/net/netfilter/ipvs/ip_vs_ctl.c
95527@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
95528 */
95529 ip_vs_rs_hash(ipvs, dest);
95530 }
95531- atomic_set(&dest->conn_flags, conn_flags);
95532+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
95533
95534 /* bind the service */
95535 old_svc = rcu_dereference_protected(dest->svc, 1);
95536@@ -1641,7 +1641,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
95537 * align with netns init in ip_vs_control_net_init()
95538 */
95539
95540-static struct ctl_table vs_vars[] = {
95541+static ctl_table_no_const vs_vars[] __read_only = {
95542 {
95543 .procname = "amemthresh",
95544 .maxlen = sizeof(int),
95545@@ -2062,7 +2062,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95546 " %-7s %-6d %-10d %-10d\n",
95547 &dest->addr.in6,
95548 ntohs(dest->port),
95549- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95550+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95551 atomic_read(&dest->weight),
95552 atomic_read(&dest->activeconns),
95553 atomic_read(&dest->inactconns));
95554@@ -2073,7 +2073,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95555 "%-7s %-6d %-10d %-10d\n",
95556 ntohl(dest->addr.ip),
95557 ntohs(dest->port),
95558- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95559+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95560 atomic_read(&dest->weight),
95561 atomic_read(&dest->activeconns),
95562 atomic_read(&dest->inactconns));
95563@@ -2551,7 +2551,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
95564
95565 entry.addr = dest->addr.ip;
95566 entry.port = dest->port;
95567- entry.conn_flags = atomic_read(&dest->conn_flags);
95568+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
95569 entry.weight = atomic_read(&dest->weight);
95570 entry.u_threshold = dest->u_threshold;
95571 entry.l_threshold = dest->l_threshold;
95572@@ -3094,7 +3094,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
95573 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
95574 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
95575 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
95576- (atomic_read(&dest->conn_flags) &
95577+ (atomic_read_unchecked(&dest->conn_flags) &
95578 IP_VS_CONN_F_FWD_MASK)) ||
95579 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
95580 atomic_read(&dest->weight)) ||
95581@@ -3684,7 +3684,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
95582 {
95583 int idx;
95584 struct netns_ipvs *ipvs = net_ipvs(net);
95585- struct ctl_table *tbl;
95586+ ctl_table_no_const *tbl;
95587
95588 atomic_set(&ipvs->dropentry, 0);
95589 spin_lock_init(&ipvs->dropentry_lock);
95590diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
95591index eff13c9..c1aab3e 100644
95592--- a/net/netfilter/ipvs/ip_vs_lblc.c
95593+++ b/net/netfilter/ipvs/ip_vs_lblc.c
95594@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
95595 * IPVS LBLC sysctl table
95596 */
95597 #ifdef CONFIG_SYSCTL
95598-static struct ctl_table vs_vars_table[] = {
95599+static ctl_table_no_const vs_vars_table[] __read_only = {
95600 {
95601 .procname = "lblc_expiration",
95602 .data = NULL,
95603diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
95604index 0b85500..8513fa5 100644
95605--- a/net/netfilter/ipvs/ip_vs_lblcr.c
95606+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
95607@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
95608 * IPVS LBLCR sysctl table
95609 */
95610
95611-static struct ctl_table vs_vars_table[] = {
95612+static ctl_table_no_const vs_vars_table[] __read_only = {
95613 {
95614 .procname = "lblcr_expiration",
95615 .data = NULL,
95616diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
95617index f448471..995f131 100644
95618--- a/net/netfilter/ipvs/ip_vs_sync.c
95619+++ b/net/netfilter/ipvs/ip_vs_sync.c
95620@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
95621 cp = cp->control;
95622 if (cp) {
95623 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
95624- pkts = atomic_add_return(1, &cp->in_pkts);
95625+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95626 else
95627 pkts = sysctl_sync_threshold(ipvs);
95628 ip_vs_sync_conn(net, cp->control, pkts);
95629@@ -771,7 +771,7 @@ control:
95630 if (!cp)
95631 return;
95632 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
95633- pkts = atomic_add_return(1, &cp->in_pkts);
95634+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95635 else
95636 pkts = sysctl_sync_threshold(ipvs);
95637 goto sloop;
95638@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
95639
95640 if (opt)
95641 memcpy(&cp->in_seq, opt, sizeof(*opt));
95642- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
95643+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
95644 cp->state = state;
95645 cp->old_state = cp->state;
95646 /*
95647diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
95648index c47444e..b0961c6 100644
95649--- a/net/netfilter/ipvs/ip_vs_xmit.c
95650+++ b/net/netfilter/ipvs/ip_vs_xmit.c
95651@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
95652 else
95653 rc = NF_ACCEPT;
95654 /* do not touch skb anymore */
95655- atomic_inc(&cp->in_pkts);
95656+ atomic_inc_unchecked(&cp->in_pkts);
95657 goto out;
95658 }
95659
95660@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
95661 else
95662 rc = NF_ACCEPT;
95663 /* do not touch skb anymore */
95664- atomic_inc(&cp->in_pkts);
95665+ atomic_inc_unchecked(&cp->in_pkts);
95666 goto out;
95667 }
95668
95669diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
95670index 2d3030a..7ba1c0a 100644
95671--- a/net/netfilter/nf_conntrack_acct.c
95672+++ b/net/netfilter/nf_conntrack_acct.c
95673@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
95674 #ifdef CONFIG_SYSCTL
95675 static int nf_conntrack_acct_init_sysctl(struct net *net)
95676 {
95677- struct ctl_table *table;
95678+ ctl_table_no_const *table;
95679
95680 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
95681 GFP_KERNEL);
95682diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
95683index 5d892fe..d2fc9d8 100644
95684--- a/net/netfilter/nf_conntrack_core.c
95685+++ b/net/netfilter/nf_conntrack_core.c
95686@@ -1600,6 +1600,10 @@ void nf_conntrack_init_end(void)
95687 #define DYING_NULLS_VAL ((1<<30)+1)
95688 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
95689
95690+#ifdef CONFIG_GRKERNSEC_HIDESYM
95691+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
95692+#endif
95693+
95694 int nf_conntrack_init_net(struct net *net)
95695 {
95696 int ret;
95697@@ -1614,7 +1618,11 @@ int nf_conntrack_init_net(struct net *net)
95698 goto err_stat;
95699 }
95700
95701+#ifdef CONFIG_GRKERNSEC_HIDESYM
95702+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
95703+#else
95704 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
95705+#endif
95706 if (!net->ct.slabname) {
95707 ret = -ENOMEM;
95708 goto err_slabname;
95709diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
95710index 1df1761..ce8b88a 100644
95711--- a/net/netfilter/nf_conntrack_ecache.c
95712+++ b/net/netfilter/nf_conntrack_ecache.c
95713@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
95714 #ifdef CONFIG_SYSCTL
95715 static int nf_conntrack_event_init_sysctl(struct net *net)
95716 {
95717- struct ctl_table *table;
95718+ ctl_table_no_const *table;
95719
95720 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
95721 GFP_KERNEL);
95722diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
95723index 974a2a4..52cc6ff 100644
95724--- a/net/netfilter/nf_conntrack_helper.c
95725+++ b/net/netfilter/nf_conntrack_helper.c
95726@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
95727
95728 static int nf_conntrack_helper_init_sysctl(struct net *net)
95729 {
95730- struct ctl_table *table;
95731+ ctl_table_no_const *table;
95732
95733 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
95734 GFP_KERNEL);
95735diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
95736index ce30041..3861b5d 100644
95737--- a/net/netfilter/nf_conntrack_proto.c
95738+++ b/net/netfilter/nf_conntrack_proto.c
95739@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
95740
95741 static void
95742 nf_ct_unregister_sysctl(struct ctl_table_header **header,
95743- struct ctl_table **table,
95744+ ctl_table_no_const **table,
95745 unsigned int users)
95746 {
95747 if (users > 0)
95748diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
95749index a99b6c3..cb372f9 100644
95750--- a/net/netfilter/nf_conntrack_proto_dccp.c
95751+++ b/net/netfilter/nf_conntrack_proto_dccp.c
95752@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
95753 const char *msg;
95754 u_int8_t state;
95755
95756- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
95757+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
95758 BUG_ON(dh == NULL);
95759
95760 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
95761@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
95762 out_invalid:
95763 if (LOG_INVALID(net, IPPROTO_DCCP))
95764 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
95765- NULL, msg);
95766+ NULL, "%s", msg);
95767 return false;
95768 }
95769
95770@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
95771 u_int8_t type, old_state, new_state;
95772 enum ct_dccp_roles role;
95773
95774- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
95775+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
95776 BUG_ON(dh == NULL);
95777 type = dh->dccph_type;
95778
95779@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
95780 unsigned int cscov;
95781 const char *msg;
95782
95783- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
95784+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
95785 if (dh == NULL) {
95786 msg = "nf_ct_dccp: short packet ";
95787 goto out_invalid;
95788@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
95789
95790 out_invalid:
95791 if (LOG_INVALID(net, IPPROTO_DCCP))
95792- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
95793+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
95794 return -NF_ACCEPT;
95795 }
95796
95797diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
95798index f641751..d3c5b51 100644
95799--- a/net/netfilter/nf_conntrack_standalone.c
95800+++ b/net/netfilter/nf_conntrack_standalone.c
95801@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
95802
95803 static int nf_conntrack_standalone_init_sysctl(struct net *net)
95804 {
95805- struct ctl_table *table;
95806+ ctl_table_no_const *table;
95807
95808 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
95809 GFP_KERNEL);
95810diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
95811index 902fb0a..87f7fdb 100644
95812--- a/net/netfilter/nf_conntrack_timestamp.c
95813+++ b/net/netfilter/nf_conntrack_timestamp.c
95814@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
95815 #ifdef CONFIG_SYSCTL
95816 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
95817 {
95818- struct ctl_table *table;
95819+ ctl_table_no_const *table;
95820
95821 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
95822 GFP_KERNEL);
95823diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
95824index 85296d4..8becdec 100644
95825--- a/net/netfilter/nf_log.c
95826+++ b/net/netfilter/nf_log.c
95827@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
95828
95829 #ifdef CONFIG_SYSCTL
95830 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
95831-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
95832+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
95833
95834 static int nf_log_proc_dostring(struct ctl_table *table, int write,
95835 void __user *buffer, size_t *lenp, loff_t *ppos)
95836@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
95837 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
95838 mutex_unlock(&nf_log_mutex);
95839 } else {
95840+ ctl_table_no_const nf_log_table = *table;
95841+
95842 mutex_lock(&nf_log_mutex);
95843 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
95844 lockdep_is_held(&nf_log_mutex));
95845 if (!logger)
95846- table->data = "NONE";
95847+ nf_log_table.data = "NONE";
95848 else
95849- table->data = logger->name;
95850- r = proc_dostring(table, write, buffer, lenp, ppos);
95851+ nf_log_table.data = logger->name;
95852+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
95853 mutex_unlock(&nf_log_mutex);
95854 }
95855
95856diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
95857index f042ae5..30ea486 100644
95858--- a/net/netfilter/nf_sockopt.c
95859+++ b/net/netfilter/nf_sockopt.c
95860@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
95861 }
95862 }
95863
95864- list_add(&reg->list, &nf_sockopts);
95865+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
95866 out:
95867 mutex_unlock(&nf_sockopt_mutex);
95868 return ret;
95869@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
95870 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
95871 {
95872 mutex_lock(&nf_sockopt_mutex);
95873- list_del(&reg->list);
95874+ pax_list_del((struct list_head *)&reg->list);
95875 mutex_unlock(&nf_sockopt_mutex);
95876 }
95877 EXPORT_SYMBOL(nf_unregister_sockopt);
95878diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
95879index d92cc31..e46f350 100644
95880--- a/net/netfilter/nfnetlink_log.c
95881+++ b/net/netfilter/nfnetlink_log.c
95882@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
95883 struct nfnl_log_net {
95884 spinlock_t instances_lock;
95885 struct hlist_head instance_table[INSTANCE_BUCKETS];
95886- atomic_t global_seq;
95887+ atomic_unchecked_t global_seq;
95888 };
95889
95890 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
95891@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
95892 /* global sequence number */
95893 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
95894 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
95895- htonl(atomic_inc_return(&log->global_seq))))
95896+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
95897 goto nla_put_failure;
95898
95899 if (data_len) {
95900diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
95901new file mode 100644
95902index 0000000..c566332
95903--- /dev/null
95904+++ b/net/netfilter/xt_gradm.c
95905@@ -0,0 +1,51 @@
95906+/*
95907+ * gradm match for netfilter
95908